|
|
|
|
@ -52,75 +52,10 @@ namespace lunarium
|
|
|
|
|
mFrameBufferTwo = FrameBuffer::Create(1024, 1024); //Core::Graphics().CreateRenderTexture(1024, 1024, 4);
|
|
|
|
|
|
|
|
|
|
// Load test image
|
|
|
|
|
int w, h, n;
|
|
|
|
|
stbi_set_flip_vertically_on_load(0);
|
|
|
|
|
unsigned char* buffer = stbi_load("LinkToThePast1_sized.png", &w, &h, &n, 0);
|
|
|
|
|
|
|
|
|
|
TextureFormat format = TextureFormat::RGBA;
|
|
|
|
|
if (n == 3)
|
|
|
|
|
{
|
|
|
|
|
format = TextureFormat::RGB;
|
|
|
|
|
}
|
|
|
|
|
mpTestImageLoad = Texture::Create(buffer, w, h, format, true);
|
|
|
|
|
mSrcWidth = w;
|
|
|
|
|
mSrcHeight = h;
|
|
|
|
|
|
|
|
|
|
delete[] buffer;
|
|
|
|
|
stbi_set_flip_vertically_on_load(0);
|
|
|
|
|
buffer = stbi_load("debug_texture.jpeg", &w, &h, &n, 0);
|
|
|
|
|
//buffer = stbi_load("lunarium_text_test.png", &w, &h, &n, 0);
|
|
|
|
|
LoadImages();
|
|
|
|
|
|
|
|
|
|
format = TextureFormat::RGBA;
|
|
|
|
|
if (n == 3)
|
|
|
|
|
{
|
|
|
|
|
format = TextureFormat::RGB;
|
|
|
|
|
}
|
|
|
|
|
else if (n == 1)
|
|
|
|
|
{
|
|
|
|
|
format = TextureFormat::RED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mpTestImageLoad2 = Texture::Create(buffer, w, h, format);
|
|
|
|
|
delete[] buffer;
|
|
|
|
|
|
|
|
|
|
stbi_set_flip_vertically_on_load(0);
|
|
|
|
|
buffer = stbi_load("lunarium_text_test.png", &w, &h, &n, 0);
|
|
|
|
|
|
|
|
|
|
format = TextureFormat::RGBA;
|
|
|
|
|
if (n == 3)
|
|
|
|
|
{
|
|
|
|
|
format = TextureFormat::RGB;
|
|
|
|
|
}
|
|
|
|
|
else if (n == 1)
|
|
|
|
|
{
|
|
|
|
|
format = TextureFormat::RED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mpTestImageLoad3 = Texture::Create(buffer, w, h, format);
|
|
|
|
|
delete[] buffer;
|
|
|
|
|
|
|
|
|
|
mQuads = new Rectangle[NUM_QUADS];
|
|
|
|
|
for (int i = 0; i < NUM_QUADS; i++)
|
|
|
|
|
{
|
|
|
|
|
float x = (rand() % 1000);
|
|
|
|
|
float y = (rand() % 600);
|
|
|
|
|
float w = (rand() % 200) + 10;
|
|
|
|
|
float h = (rand() % 200) + 10;
|
|
|
|
|
|
|
|
|
|
mQuads[i] = Rectangle(x, y, w, h);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mQuadColors = new Color[NUM_QUADS];
|
|
|
|
|
mQuadTexures = new Texture*[NUM_QUADS];
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < NUM_QUADS; i++)
|
|
|
|
|
{
|
|
|
|
|
mQuadTexures[i] = (i % 2 == 0) ? mpTestImageLoad : mpTestImageLoad2;
|
|
|
|
|
mQuadColors[i].R = ((float)(rand() % 10000)) / 10000.0f;
|
|
|
|
|
mQuadColors[i].G = ((float)(rand() % 10000)) / 10000.0f;
|
|
|
|
|
mQuadColors[i].B = ((float)(rand() % 10000)) / 10000.0f;
|
|
|
|
|
mQuadColors[i].A = 1.0f;
|
|
|
|
|
}
|
|
|
|
|
GenerateQuads();
|
|
|
|
|
GenerateLines();
|
|
|
|
|
|
|
|
|
|
angle = 0.0f;
|
|
|
|
|
box_angle = 0.0f;
|
|
|
|
|
@ -192,56 +127,9 @@ namespace lunarium
|
|
|
|
|
angle -= 0.1f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Core::Input().IsKeyPressed(KeyCode::TAB))
|
|
|
|
|
{
|
|
|
|
|
if (mTestMode == TestMode::Basic)
|
|
|
|
|
mTestMode = TestMode::Stress;
|
|
|
|
|
|
|
|
|
|
else if (mTestMode == TestMode::Stress)
|
|
|
|
|
{
|
|
|
|
|
mSubTex = Rectangle::MakeFromTopLeft(2858, 0, 32, 32);
|
|
|
|
|
mTestMode = TestMode::String;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (mTestMode == TestMode::String)
|
|
|
|
|
{
|
|
|
|
|
mTestMode = TestMode::Basic;
|
|
|
|
|
mSubTex = Rectangle::MakeFromTopLeft(0, 0, 256, 256);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Core::Input().IsKeyPressed(KeyCode::Q))
|
|
|
|
|
{
|
|
|
|
|
// Test writing out a rendered image with transparency
|
|
|
|
|
Renderer2D& g = Core::Graphics();
|
|
|
|
|
Color prev = g.GetClearColor();
|
|
|
|
|
g.SetClearColor(Color(0.0f, 0.0f, 0.0f, 0.0f));
|
|
|
|
|
mFrameBufferTwo->Bind();
|
|
|
|
|
OrthographicCamera cam(Vec2f{0.0f, 0.0f}, Sizef{(float)mFrameBufferTwo->GetTexture()->GetWidth(), (float)mFrameBufferTwo->GetTexture()->GetHeight()});
|
|
|
|
|
g.BeginDraw(&cam);
|
|
|
|
|
// if (Failed(result))
|
|
|
|
|
// {
|
|
|
|
|
// Logger::Warn(mLogCat, "Unable to render to texture: %s", result.Description.c_str());
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
Logger::Info(mLogCat, "Running transparent image test");
|
|
|
|
|
|
|
|
|
|
g.DrawQuad(Rectangle(500, 400, 300, 300), Color(0.5f, 0.0f, 0.75f, 1.0f));
|
|
|
|
|
g.DrawQuad(Rectangle(200, 300, 100, 100), Color(0.2f, 0.5f, 0.4f, 1.0f), nullptr, 45.0f);
|
|
|
|
|
g.DrawString("This is a test of rendering an image with transparency",
|
|
|
|
|
Rectangle::MakeFromTopLeft(50, 50, 600, 200), Color(0.0f, 1.0f, 0.2f, 1.0f), 0.5f);
|
|
|
|
|
|
|
|
|
|
g.EndDraw();
|
|
|
|
|
mpRenderedImage = mFrameBufferTwo->GetTexture();
|
|
|
|
|
mFrameBufferTwo->Unbind();
|
|
|
|
|
//mpRenderedImage = Core::GetInstance().EndRenderToTexture();
|
|
|
|
|
g.SetClearColor(prev);
|
|
|
|
|
|
|
|
|
|
stbi_flip_vertically_on_write(1);
|
|
|
|
|
stbi_write_png("lunarium_test_image.png", mpRenderedImage->GetWidth(), mpRenderedImage->GetHeight(), 4,
|
|
|
|
|
mpRenderedImage->GetPixels(), mpRenderedImage->GetWidth() * 4);
|
|
|
|
|
//Logger::Info(mLogCat, "")
|
|
|
|
|
DoFrameBufferSaveTest();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Core::Input().IsKeyPressed(KeyCode::T))
|
|
|
|
|
@ -291,6 +179,7 @@ namespace lunarium
|
|
|
|
|
case TestMode::Basic: RenderScene(Core::Graphics()); break;
|
|
|
|
|
case TestMode::Stress: RenderBatchStressTest(Core::Graphics()); break;
|
|
|
|
|
case TestMode::String: RenderStringTest(Core::Graphics()); break;
|
|
|
|
|
case TestMode::Shapes: RenderShapesTest(Core::Graphics()); break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -306,6 +195,9 @@ namespace lunarium
|
|
|
|
|
//std::this_thread::sleep_for (std::chrono::seconds(2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
// RENDER METHODS RENDER METHODS
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
void SimpleRenderScene::RenderScene(Renderer2D& g)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
@ -352,16 +244,32 @@ namespace lunarium
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SimpleRenderScene::RenderShapesTest(Renderer2D& g)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
g.DrawLine(glm::vec2(30.0f, 200.0f), glm::vec2(400.0f, 400.0f), Color::Green(), 3.0f);
|
|
|
|
|
|
|
|
|
|
for (auto iter = mLines.begin(); iter != mLines.end(); iter++)
|
|
|
|
|
{
|
|
|
|
|
g.DrawLine(iter->Position1, iter->Position2, iter->Color, iter->Thickness, iter->Angle);
|
|
|
|
|
iter->Angle += iter->RotSpeed;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
// GUI DRAWING GUI DRAWING
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
void SimpleRenderScene::DrawStatsGUI()
|
|
|
|
|
{
|
|
|
|
|
const char* mode_names[3] = { "Basic", "Stress", "String" };
|
|
|
|
|
const char* mode_names[4] = { "Basic", "Stress", "String", "Shapes" };
|
|
|
|
|
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_FirstUseEver);
|
|
|
|
|
ImGui::SetNextWindowSize(ImVec2(400, 800));
|
|
|
|
|
ImGui::Begin("RENDER INFO");
|
|
|
|
|
ImGui::BeginChild("Scene Info", ImVec2(ImGui::GetWindowSize().x - 15, ImGui::GetFrameHeightWithSpacing() * 3.5f), true);
|
|
|
|
|
ImGui::Text("Scene Info");
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
ImGui::Combo("Scene Mode", (int*)&mTestMode, mode_names, 3);
|
|
|
|
|
ImGui::Combo("Scene Mode", (int*)&mTestMode, mode_names, 4);
|
|
|
|
|
ImGui::EndChild();
|
|
|
|
|
ImGui::BeginChild("Per Frame", ImVec2(ImGui::GetWindowSize().x - 15, ImGui::GetFrameHeightWithSpacing() * 3.5f), true);
|
|
|
|
|
ImGui::Text("Per Frame");
|
|
|
|
|
@ -398,6 +306,15 @@ namespace lunarium
|
|
|
|
|
mSubTex = Rectangle::MakeFromTopLeft(0.0f, 0.0f, 256.0f, 256.0f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (mTestMode == TestMode::Shapes)
|
|
|
|
|
{
|
|
|
|
|
ImGui::DragInt("Number of Lines", &mNumLines);
|
|
|
|
|
if (ImGui::Button("Regenerate Shapes"))
|
|
|
|
|
{
|
|
|
|
|
GenerateLines();
|
|
|
|
|
GenerateEllipses();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImGui::EndChild();
|
|
|
|
|
@ -405,4 +322,153 @@ namespace lunarium
|
|
|
|
|
|
|
|
|
|
mNumQuadsToRender = Math::ClampI(mNumQuadsToRender, 0, NUM_QUADS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
// HELPERS HELPERS
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
void SimpleRenderScene::LoadImages()
|
|
|
|
|
{
|
|
|
|
|
// Test Image 1
|
|
|
|
|
int w, h, n;
|
|
|
|
|
stbi_set_flip_vertically_on_load(0);
|
|
|
|
|
unsigned char* buffer = stbi_load("LinkToThePast1_sized.png", &w, &h, &n, 0);
|
|
|
|
|
|
|
|
|
|
TextureFormat format = TextureFormat::RGBA;
|
|
|
|
|
if (n == 3)
|
|
|
|
|
{
|
|
|
|
|
format = TextureFormat::RGB;
|
|
|
|
|
}
|
|
|
|
|
mpTestImageLoad = Texture::Create(buffer, w, h, format, true);
|
|
|
|
|
mSrcWidth = w;
|
|
|
|
|
mSrcHeight = h;
|
|
|
|
|
|
|
|
|
|
delete[] buffer;
|
|
|
|
|
|
|
|
|
|
// Debug texture
|
|
|
|
|
stbi_set_flip_vertically_on_load(0);
|
|
|
|
|
buffer = stbi_load("debug_texture.jpeg", &w, &h, &n, 0);
|
|
|
|
|
|
|
|
|
|
format = TextureFormat::RGBA;
|
|
|
|
|
if (n == 3)
|
|
|
|
|
{
|
|
|
|
|
format = TextureFormat::RGB;
|
|
|
|
|
}
|
|
|
|
|
else if (n == 1)
|
|
|
|
|
{
|
|
|
|
|
format = TextureFormat::RED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mpTestImageLoad2 = Texture::Create(buffer, w, h, format);
|
|
|
|
|
delete[] buffer;
|
|
|
|
|
|
|
|
|
|
// Text testing texture
|
|
|
|
|
stbi_set_flip_vertically_on_load(0);
|
|
|
|
|
buffer = stbi_load("lunarium_text_test.png", &w, &h, &n, 0);
|
|
|
|
|
|
|
|
|
|
format = TextureFormat::RGBA;
|
|
|
|
|
if (n == 3)
|
|
|
|
|
{
|
|
|
|
|
format = TextureFormat::RGB;
|
|
|
|
|
}
|
|
|
|
|
else if (n == 1)
|
|
|
|
|
{
|
|
|
|
|
format = TextureFormat::RED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mpTestImageLoad3 = Texture::Create(buffer, w, h, format);
|
|
|
|
|
delete[] buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SimpleRenderScene::GenerateLines()
|
|
|
|
|
{
|
|
|
|
|
mLines.clear();
|
|
|
|
|
int window_width = 0;
|
|
|
|
|
int window_height = 0;
|
|
|
|
|
Core::MainWindow().GetFramebufferSize(&window_width, &window_height);
|
|
|
|
|
for (int i = 0; i < mNumLines; i++)
|
|
|
|
|
{
|
|
|
|
|
mLines.push_back(LineData
|
|
|
|
|
{
|
|
|
|
|
glm::vec2(rand() % window_width, rand() % window_height),
|
|
|
|
|
glm::vec2(rand() % window_width, rand() % window_height),
|
|
|
|
|
Color(((float)(rand() % 10000)) / 10000.0f,
|
|
|
|
|
((float)(rand() % 10000)) / 10000.0f,
|
|
|
|
|
((float)(rand() % 10000)) / 10000.0f,
|
|
|
|
|
1.0f),
|
|
|
|
|
((float)(rand() % 180)),
|
|
|
|
|
((float)(rand() % 100)) / 100.0f + 0.01f,
|
|
|
|
|
((float)(rand() % 100)) / 10.0f + 0.5f
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SimpleRenderScene::GenerateEllipses()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SimpleRenderScene::GenerateQuads()
|
|
|
|
|
{
|
|
|
|
|
mQuads = new Rectangle[NUM_QUADS];
|
|
|
|
|
for (int i = 0; i < NUM_QUADS; i++)
|
|
|
|
|
{
|
|
|
|
|
float x = (rand() % 1000);
|
|
|
|
|
float y = (rand() % 600);
|
|
|
|
|
float w = (rand() % 200) + 10;
|
|
|
|
|
float h = (rand() % 200) + 10;
|
|
|
|
|
|
|
|
|
|
mQuads[i] = Rectangle(x, y, w, h);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mQuadColors = new Color[NUM_QUADS];
|
|
|
|
|
mQuadTexures = new Texture*[NUM_QUADS];
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < NUM_QUADS; i++)
|
|
|
|
|
{
|
|
|
|
|
mQuadTexures[i] = (i % 2 == 0) ? mpTestImageLoad : mpTestImageLoad2;
|
|
|
|
|
mQuadColors[i].R = ((float)(rand() % 10000)) / 10000.0f;
|
|
|
|
|
mQuadColors[i].G = ((float)(rand() % 10000)) / 10000.0f;
|
|
|
|
|
mQuadColors[i].B = ((float)(rand() % 10000)) / 10000.0f;
|
|
|
|
|
mQuadColors[i].A = 1.0f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SimpleRenderScene::DoFrameBufferSaveTest()
|
|
|
|
|
{
|
|
|
|
|
// Test writing out a rendered image with transparency
|
|
|
|
|
Renderer2D& g = Core::Graphics();
|
|
|
|
|
Color prev = g.GetClearColor();
|
|
|
|
|
g.SetClearColor(Color(0.0f, 0.0f, 0.0f, 0.0f));
|
|
|
|
|
mFrameBufferTwo->Bind();
|
|
|
|
|
OrthographicCamera cam(Vec2f{0.0f, 0.0f}, Sizef{(float)mFrameBufferTwo->GetTexture()->GetWidth(), (float)mFrameBufferTwo->GetTexture()->GetHeight()});
|
|
|
|
|
g.BeginDraw(&cam);
|
|
|
|
|
// if (Failed(result))
|
|
|
|
|
// {
|
|
|
|
|
// Logger::Warn(mLogCat, "Unable to render to texture: %s", result.Description.c_str());
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
Logger::Info(mLogCat, "Running transparent image test");
|
|
|
|
|
|
|
|
|
|
g.DrawQuad(Rectangle(500, 400, 300, 300), Color(0.5f, 0.0f, 0.75f, 1.0f));
|
|
|
|
|
g.DrawQuad(Rectangle(200, 300, 100, 100), Color(0.2f, 0.5f, 0.4f, 1.0f), nullptr, 45.0f);
|
|
|
|
|
g.DrawString("This is a test of rendering an image with transparency",
|
|
|
|
|
Rectangle::MakeFromTopLeft(50, 50, 600, 200), Color(0.0f, 1.0f, 0.2f, 1.0f), 0.5f);
|
|
|
|
|
|
|
|
|
|
g.EndDraw();
|
|
|
|
|
mpRenderedImage = mFrameBufferTwo->GetTexture();
|
|
|
|
|
mFrameBufferTwo->Unbind();
|
|
|
|
|
//mpRenderedImage = Core::GetInstance().EndRenderToTexture();
|
|
|
|
|
g.SetClearColor(prev);
|
|
|
|
|
|
|
|
|
|
stbi_flip_vertically_on_write(1);
|
|
|
|
|
stbi_write_png("lunarium_test_image.png", mpRenderedImage->GetWidth(), mpRenderedImage->GetHeight(), 4,
|
|
|
|
|
mpRenderedImage->GetPixels(), mpRenderedImage->GetWidth() * 4);
|
|
|
|
|
//Logger::Info(mLogCat, "")
|
|
|
|
|
}
|
|
|
|
|
}
|