|
|
|
@ -56,7 +56,7 @@ namespace lunarium
|
|
|
|
mQuadData.mBufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 3 }); // Position
|
|
|
|
mQuadData.mBufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 3 }); // Position
|
|
|
|
mQuadData.mBufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 2 }); // Tex_coords
|
|
|
|
mQuadData.mBufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 2 }); // Tex_coords
|
|
|
|
mQuadData.mBufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 4 }); // Color
|
|
|
|
mQuadData.mBufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 4 }); // Color
|
|
|
|
mQuadData.mBufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::INT32, 1 }); // Texture Sampler Index
|
|
|
|
mQuadData.mBufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 1 }); // Texture Sampler Index
|
|
|
|
mQuadData.mBufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 3 }); // translation
|
|
|
|
mQuadData.mBufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 3 }); // translation
|
|
|
|
mQuadData.mBufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 1 }); // angle
|
|
|
|
mQuadData.mBufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 1 }); // angle
|
|
|
|
mQuadData.mBufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 3 }); // Scale
|
|
|
|
mQuadData.mBufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 3 }); // Scale
|
|
|
|
@ -66,6 +66,14 @@ namespace lunarium
|
|
|
|
mQuadData.mRawVertexBuffer = new QuadData::Vertex[mQuadData.MaxVertices];
|
|
|
|
mQuadData.mRawVertexBuffer = new QuadData::Vertex[mQuadData.MaxVertices];
|
|
|
|
mQuadData.mRawBufferIndex = 0;
|
|
|
|
mQuadData.mRawBufferIndex = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int layout_size = mQuadData.mBufferLayout.GetLayoutSizeInBytes();
|
|
|
|
|
|
|
|
int struct_size = sizeof(QuadData::Vertex);
|
|
|
|
|
|
|
|
if (struct_size != layout_size)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Logger::Error(LogCategory::GRAPHICS,
|
|
|
|
|
|
|
|
"Quad::Vertex struct size does not match the vertex layout size! struct: %d, layout: %d", struct_size, layout_size);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//mQuadData.mIndexBuffer = new IndexBuffer(mQuadData.MaxIndices * sizeof(u32));
|
|
|
|
//mQuadData.mIndexBuffer = new IndexBuffer(mQuadData.MaxIndices * sizeof(u32));
|
|
|
|
|
|
|
|
|
|
|
|
std::string vert_source = File::ReadTextFile("quad.vert");
|
|
|
|
std::string vert_source = File::ReadTextFile("quad.vert");
|
|
|
|
@ -80,8 +88,9 @@ namespace lunarium
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: INIT DEBUG TEXTURE
|
|
|
|
// TODO: INIT DEBUG TEXTURE
|
|
|
|
u8 data[4] = {255, 128, 0, 0};
|
|
|
|
u8 data[4] = {255, 255, 255, 255};
|
|
|
|
mpDebugTexture = Texture::Create(data, 1, 1);
|
|
|
|
mpWhiteTexture = Texture::Create(data, 1, 1);
|
|
|
|
|
|
|
|
mLoadedTextures.push_back(mpWhiteTexture);
|
|
|
|
|
|
|
|
|
|
|
|
// DEBUG: INIT TEST DATA
|
|
|
|
// DEBUG: INIT TEST DATA
|
|
|
|
// mTestData.mBufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 2}); // Position
|
|
|
|
// mTestData.mBufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 2}); // Position
|
|
|
|
@ -171,52 +180,28 @@ namespace lunarium
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
void Renderer2D::DrawQuad(Rectangle quad, Color color, Texture* texture, float angle)
|
|
|
|
void Renderer2D::DrawQuad(Rectangle quad, Color color, Texture* texture, float angle)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
int texture_slot = -1;
|
|
|
|
mTestData.color = color;
|
|
|
|
if (texture)
|
|
|
|
//mTestData.mVertexBuffer->Bind();
|
|
|
|
{
|
|
|
|
mTestData.mQuadShader->Use();
|
|
|
|
for (int i = 0; i < mLoadedTextures.size(); i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
Uniform uni { "spriteColor", UniformType::F3, -1 };
|
|
|
|
if (texture == mLoadedTextures[i])
|
|
|
|
mTestData.mQuadShader->SetUniform(uni, color.arr).LogIfFailed(LogCategory::GRAPHICS, "Failed to set uniform for the test shader!");
|
|
|
|
{
|
|
|
|
|
|
|
|
texture_slot = i;
|
|
|
|
//glBindVertexArray(mTVAO);
|
|
|
|
break;
|
|
|
|
GLfloat vertices[6][2] = {
|
|
|
|
}
|
|
|
|
{ -0.5f, 0.5f, },
|
|
|
|
}
|
|
|
|
{ 0.5f, -0.5f, },
|
|
|
|
|
|
|
|
{ -0.5f, -0.5f, },
|
|
|
|
if (-1 == texture_slot)
|
|
|
|
|
|
|
|
{
|
|
|
|
{ -0.5f, 0.5f, },
|
|
|
|
mLoadedTextures.push_back(texture);
|
|
|
|
{ 0.5f, 0.5f, },
|
|
|
|
texture_slot = mLoadedTextures.size() - 1;
|
|
|
|
{ 0.5f, -0.5f, }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
mTestData.mVertexBuffer->PushVertices(vertices, 6);
|
|
|
|
else
|
|
|
|
mTestData.mVertexBuffer->Bind();
|
|
|
|
{
|
|
|
|
// mTestData.mIndexBuffer->Bind();
|
|
|
|
texture_slot = 0;
|
|
|
|
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr);
|
|
|
|
}
|
|
|
|
//glDrawArrays(GL_TRIANGLES, 0, 6);
|
|
|
|
|
|
|
|
mTestData.mVertexBuffer->Clear();
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int texture_slot = 0;
|
|
|
|
|
|
|
|
// int texture_slot = -1;
|
|
|
|
|
|
|
|
// if (texture)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// for (int i = 0; i < mLoadedTextures.size(); i++)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// if (texture == mLoadedTextures[i])
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// texture_slot = i;
|
|
|
|
|
|
|
|
// break;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (-1 == texture_slot)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// mLoadedTextures.push_back(texture);
|
|
|
|
|
|
|
|
// texture_slot = mLoadedTextures.size() - 1;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//unsigned char* vertices_wl = (unsigned char*)vertices; // vertices write location pointer
|
|
|
|
//unsigned char* vertices_wl = (unsigned char*)vertices; // vertices write location pointer
|
|
|
|
@ -228,7 +213,7 @@ namespace lunarium
|
|
|
|
// glm::mat4 model = glm::mat4(1.0f);
|
|
|
|
// glm::mat4 model = glm::mat4(1.0f);
|
|
|
|
// model = glm::translate(model, glm::vec3(quad.X, quad.Y, 0.0f));
|
|
|
|
// model = glm::translate(model, glm::vec3(quad.X, quad.Y, 0.0f));
|
|
|
|
// model = glm::rotate(model, angle, glm::vec3(0.0f, 0.0f, 1.0f));
|
|
|
|
// model = glm::rotate(model, angle, glm::vec3(0.0f, 0.0f, 1.0f));
|
|
|
|
// model = glm::scale(model, glm::vec3(quad.HalfWidth * 2, quad.HalfHeight * 2, 1.0f));
|
|
|
|
// model = glm::scale(model, glm::vec3(quad.HalfWidth * 2, quad.HalfHeight * 2, 1.0f));
|
|
|
|
|
|
|
|
|
|
|
|
if (mQuadData.mRawBufferIndex + 4 > mQuadData.MaxVertices)
|
|
|
|
if (mQuadData.mRawBufferIndex + 4 > mQuadData.MaxVertices)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -238,7 +223,7 @@ namespace lunarium
|
|
|
|
// FIRST
|
|
|
|
// FIRST
|
|
|
|
QuadData::Vertex v1;
|
|
|
|
QuadData::Vertex v1;
|
|
|
|
int vert_size = sizeof(QuadData::Vertex);
|
|
|
|
int vert_size = sizeof(QuadData::Vertex);
|
|
|
|
v1.pos = /*model * */mQuadData.vert_pos[0];
|
|
|
|
v1.pos = mQuadData.vert_pos[0];
|
|
|
|
v1.tex_coord = mQuadData.vert_tex[0];
|
|
|
|
v1.tex_coord = mQuadData.vert_tex[0];
|
|
|
|
v1.color = color;
|
|
|
|
v1.color = color;
|
|
|
|
v1.tex_slot = texture_slot;
|
|
|
|
v1.tex_slot = texture_slot;
|
|
|
|
@ -250,7 +235,7 @@ namespace lunarium
|
|
|
|
|
|
|
|
|
|
|
|
// SECOND
|
|
|
|
// SECOND
|
|
|
|
QuadData::Vertex v2;
|
|
|
|
QuadData::Vertex v2;
|
|
|
|
v2.pos = /*model * */ mQuadData.vert_pos[1];
|
|
|
|
v2.pos = mQuadData.vert_pos[1];
|
|
|
|
v2.tex_coord = mQuadData.vert_tex[1];
|
|
|
|
v2.tex_coord = mQuadData.vert_tex[1];
|
|
|
|
v2.color = color;
|
|
|
|
v2.color = color;
|
|
|
|
v2.tex_slot = texture_slot;
|
|
|
|
v2.tex_slot = texture_slot;
|
|
|
|
@ -262,7 +247,7 @@ namespace lunarium
|
|
|
|
|
|
|
|
|
|
|
|
// THIRD
|
|
|
|
// THIRD
|
|
|
|
QuadData::Vertex v3;
|
|
|
|
QuadData::Vertex v3;
|
|
|
|
v3.pos = /*model * */ mQuadData.vert_pos[2];
|
|
|
|
v3.pos = mQuadData.vert_pos[2];
|
|
|
|
v3.tex_coord = mQuadData.vert_tex[2];
|
|
|
|
v3.tex_coord = mQuadData.vert_tex[2];
|
|
|
|
v3.color = color;
|
|
|
|
v3.color = color;
|
|
|
|
v3.tex_slot = texture_slot;
|
|
|
|
v3.tex_slot = texture_slot;
|
|
|
|
@ -274,7 +259,7 @@ namespace lunarium
|
|
|
|
|
|
|
|
|
|
|
|
// FOURTH
|
|
|
|
// FOURTH
|
|
|
|
QuadData::Vertex v4;
|
|
|
|
QuadData::Vertex v4;
|
|
|
|
v4.pos = /*model * */ mQuadData.vert_pos[3];
|
|
|
|
v4.pos = mQuadData.vert_pos[3];
|
|
|
|
v4.tex_coord = mQuadData.vert_tex[3];
|
|
|
|
v4.tex_coord = mQuadData.vert_tex[3];
|
|
|
|
v4.color = color;
|
|
|
|
v4.color = color;
|
|
|
|
v4.tex_slot = texture_slot;
|
|
|
|
v4.tex_slot = texture_slot;
|
|
|
|
@ -309,81 +294,6 @@ namespace lunarium
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Renderer2D::DrawQuads(Rectangle* quads, u32 num_quads, Color* pColors)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for (int i = 0; i < num_quads; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
float vertices[40];
|
|
|
|
|
|
|
|
unsigned char* vertices_wl = (unsigned char*)vertices; // vertices write location pointer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// glm::mat4 model(1.0f);
|
|
|
|
|
|
|
|
// model = glm::translate(model, glm::vec3(quad.CenterPoint().x, quad.CenterPoint().y, 0.0f));
|
|
|
|
|
|
|
|
// model = glm::rotate(model, angle, glm::vec3(0.0f, 0.0f, 1.0f));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glm::mat4 model = glm::mat4(1.0f);
|
|
|
|
|
|
|
|
model = glm::translate(model, glm::vec3(quads[i].X, quads[i].Y, 0.0f));
|
|
|
|
|
|
|
|
model = glm::rotate(model, 1.0f, glm::vec3(0.0f, 0.0f, 1.0f));
|
|
|
|
|
|
|
|
model = glm::scale(model, glm::vec3(quads[i].HalfWidth * 2, quads[i].HalfHeight * 2, 1.0f));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FIRST
|
|
|
|
|
|
|
|
QuadData::Vertex v1;
|
|
|
|
|
|
|
|
int vert_size = sizeof(QuadData::Vertex);
|
|
|
|
|
|
|
|
v1.pos = model * mQuadData.vert_pos[0];
|
|
|
|
|
|
|
|
v1.tex_coord = mQuadData.vert_tex[0];
|
|
|
|
|
|
|
|
v1.color = pColors[i];
|
|
|
|
|
|
|
|
v1.tex_slot = 0;
|
|
|
|
|
|
|
|
memcpy(vertices_wl, &v1, vert_size);
|
|
|
|
|
|
|
|
vertices_wl += vert_size;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// SECOND
|
|
|
|
|
|
|
|
QuadData::Vertex v2;
|
|
|
|
|
|
|
|
v2.pos = model * mQuadData.vert_pos[1];
|
|
|
|
|
|
|
|
v2.tex_coord = mQuadData.vert_tex[1];
|
|
|
|
|
|
|
|
v2.color = pColors[i];
|
|
|
|
|
|
|
|
v2.tex_slot = 0;
|
|
|
|
|
|
|
|
memcpy(vertices_wl, &v2, vert_size);
|
|
|
|
|
|
|
|
vertices_wl += vert_size;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// THIRD
|
|
|
|
|
|
|
|
QuadData::Vertex v3;
|
|
|
|
|
|
|
|
v3.pos =model * mQuadData.vert_pos[2];
|
|
|
|
|
|
|
|
v3.tex_coord = mQuadData.vert_tex[2];
|
|
|
|
|
|
|
|
v3.color = pColors[i];
|
|
|
|
|
|
|
|
v3.tex_slot = 0;
|
|
|
|
|
|
|
|
memcpy(vertices_wl, &v3, vert_size);
|
|
|
|
|
|
|
|
vertices_wl += vert_size;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FOURTH
|
|
|
|
|
|
|
|
QuadData::Vertex v4;
|
|
|
|
|
|
|
|
v4.pos = model * mQuadData.vert_pos[3];
|
|
|
|
|
|
|
|
v4.tex_coord = mQuadData.vert_tex[3];
|
|
|
|
|
|
|
|
v4.color = pColors[i];
|
|
|
|
|
|
|
|
v4.tex_slot = 0;
|
|
|
|
|
|
|
|
memcpy(vertices_wl, &v4, vert_size);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!mQuadData.mVertexBuffer->PushVertices(vertices, 4))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//Logger::Info(LogCategory::GRAPHICS, "Quad VertexBuffer is full, flushing and retrying");
|
|
|
|
|
|
|
|
Flush();
|
|
|
|
|
|
|
|
i--;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// INDICES
|
|
|
|
|
|
|
|
// if (!mQuadData.mVertexBuffer->PushIndices(mQuadData.indices, 6))
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// Logger::Error(LogCategory::GRAPHICS, "Quad IndexBuffer is full - This shouldn't happen because the VertexBuffer should fill up first!");
|
|
|
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mQuadData.mNumQuads++;
|
|
|
|
|
|
|
|
mFrameStats.NumTris += 2;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Renderer2D::DrawSprite(Texture& image, glm::vec2 position, Color color, float angle)
|
|
|
|
void Renderer2D::DrawSprite(Texture& image, glm::vec2 position, Color color, float angle)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Logger::Warn(LogCategory::GRAPHICS, "Renderer2D::DrawSprite is not yet implemented");
|
|
|
|
Logger::Warn(LogCategory::GRAPHICS, "Renderer2D::DrawSprite is not yet implemented");
|
|
|
|
@ -467,7 +377,7 @@ namespace lunarium
|
|
|
|
//mQuadData.mQuadShader->SetUniform(umodel, (void*)glm::value_ptr(glm::mat4(1.0f))).LogIfFailed(LogCategory::GRAPHICS);
|
|
|
|
//mQuadData.mQuadShader->SetUniform(umodel, (void*)glm::value_ptr(glm::mat4(1.0f))).LogIfFailed(LogCategory::GRAPHICS);
|
|
|
|
mQuadData.mQuadShader->SetUniform(uprojview, (void*)glm::value_ptr(mpCamera->GetViewProjection())).LogIfFailed(LogCategory::GRAPHICS);
|
|
|
|
mQuadData.mQuadShader->SetUniform(uprojview, (void*)glm::value_ptr(mpCamera->GetViewProjection())).LogIfFailed(LogCategory::GRAPHICS);
|
|
|
|
|
|
|
|
|
|
|
|
Uniform uni { "spriteColor", UniformType::F3, -1 };
|
|
|
|
//Uniform uni { "spriteColor", UniformType::F3, -1 };
|
|
|
|
//Color c = ;
|
|
|
|
//Color c = ;
|
|
|
|
//mQuadData.mQuadShader->SetUniform(uni, Color::Red().arr).LogIfFailed(LogCategory::GRAPHICS, "Failed to set uniform for the test shader!");
|
|
|
|
//mQuadData.mQuadShader->SetUniform(uni, Color::Red().arr).LogIfFailed(LogCategory::GRAPHICS, "Failed to set uniform for the test shader!");
|
|
|
|
|
|
|
|
|
|
|
|
@ -477,13 +387,17 @@ namespace lunarium
|
|
|
|
mFrameStats.DrawCalls++;
|
|
|
|
mFrameStats.DrawCalls++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Reset drawing data
|
|
|
|
// Reset drawing data
|
|
|
|
|
|
|
|
for (int i = 0; i < mLoadedTextures.size(); i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mLoadedTextures[i]->Unbind();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mLoadedTextures.clear();
|
|
|
|
mLoadedTextures.clear();
|
|
|
|
mQuadData.mVertexBuffer->Clear();
|
|
|
|
mQuadData.mVertexBuffer->Clear();
|
|
|
|
//mQuadData.mIndexBuffer->Clear();
|
|
|
|
|
|
|
|
mQuadData.mNumQuads = 0;
|
|
|
|
mQuadData.mNumQuads = 0;
|
|
|
|
mQuadData.mRawBufferIndex = 0;
|
|
|
|
mQuadData.mRawBufferIndex = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Add the debug texture back to the map
|
|
|
|
// TODO: Add the debug texture back to the map
|
|
|
|
mLoadedTextures.push_back(mpDebugTexture);
|
|
|
|
mLoadedTextures.push_back(mpWhiteTexture);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|