Stress test with math on the GPU

master
Joey Pollack 3 years ago
parent 7f97bdae15
commit 96c404c11c

@ -57,6 +57,9 @@ namespace lunarium
mQuadData.mBufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 2 }); // Tex_coords
mQuadData.mBufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 4 }); // Color
mQuadData.mBufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::INT32, 1 }); // Texture Sampler Index
mQuadData.mBufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 3 }); // translation
mQuadData.mBufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 1 }); // angle
mQuadData.mBufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 3 }); // Scale
mQuadData.mVertexBuffer = VertexBuffer::Create(mQuadData.mBufferLayout, mQuadData.MaxVertices, nullptr, mQuadData.MaxIndices, indices);
// RAW VERTEX BUFFER
@ -215,61 +218,76 @@ namespace lunarium
// }
// }
float vertices[40];
unsigned char* vertices_wl = (unsigned char*)vertices; // vertices write location pointer
//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(quad.X, quad.Y, 0.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));
// glm::mat4 model = glm::mat4(1.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::scale(model, glm::vec3(quad.HalfWidth * 2, quad.HalfHeight * 2, 1.0f));
if (mQuadData.mRawBufferIndex + 4 > mQuadData.MaxVertices)
{
Flush();
}
// FIRST
QuadData::Vertex v1;
int vert_size = sizeof(QuadData::Vertex);
v1.pos = model * mQuadData.vert_pos[0];
v1.pos = /*model * */mQuadData.vert_pos[0];
v1.tex_coord = mQuadData.vert_tex[0];
v1.color = color;
v1.tex_slot = texture_slot;
memcpy(vertices_wl, &v1, vert_size);
vertices_wl += vert_size;
v1.translation = glm::vec3(quad.CenterPoint().x, quad.CenterPoint().y, 0.0f);
v1.angle = angle;
v1.scale = glm::vec3(quad.HalfWidth * 2, quad.HalfHeight * 2, 1.0f);
memcpy(&mQuadData.mRawVertexBuffer[mQuadData.mRawBufferIndex], &v1, vert_size);
mQuadData.mRawBufferIndex += 1;
// SECOND
QuadData::Vertex v2;
v2.pos = model * mQuadData.vert_pos[1];
v2.pos = /*model * */ mQuadData.vert_pos[1];
v2.tex_coord = mQuadData.vert_tex[1];
v2.color = color;
v2.tex_slot = texture_slot;
memcpy(vertices_wl, &v2, vert_size);
vertices_wl += vert_size;
v2.translation = glm::vec3(quad.CenterPoint().x, quad.CenterPoint().y, 0.0f);
v2.angle = angle;
v2.scale = glm::vec3(quad.HalfWidth * 2, quad.HalfHeight * 2, 1.0f);
memcpy(&mQuadData.mRawVertexBuffer[mQuadData.mRawBufferIndex], &v2, vert_size);
mQuadData.mRawBufferIndex += 1;
// THIRD
QuadData::Vertex v3;
v3.pos =model * mQuadData.vert_pos[2];
v3.pos = /*model * */ mQuadData.vert_pos[2];
v3.tex_coord = mQuadData.vert_tex[2];
v3.color = color;
v3.tex_slot = texture_slot;
memcpy(vertices_wl, &v3, vert_size);
vertices_wl += vert_size;
v3.translation = glm::vec3(quad.CenterPoint().x, quad.CenterPoint().y, 0.0f);
v3.angle = angle;
v3.scale = glm::vec3(quad.HalfWidth * 2, quad.HalfHeight * 2, 1.0f);
memcpy(&mQuadData.mRawVertexBuffer[mQuadData.mRawBufferIndex], &v3, vert_size);
mQuadData.mRawBufferIndex += 1;
// FOURTH
QuadData::Vertex v4;
v4.pos = model * mQuadData.vert_pos[3];
v4.pos = /*model * */ mQuadData.vert_pos[3];
v4.tex_coord = mQuadData.vert_tex[3];
v4.color = color;
v4.tex_slot = texture_slot;
memcpy(vertices_wl, &v4, vert_size);
v4.translation = glm::vec3(quad.CenterPoint().x, quad.CenterPoint().y, 0.0f);
v4.angle = angle;
v4.scale = glm::vec3(quad.HalfWidth * 2, quad.HalfHeight * 2, 1.0f);
memcpy(&mQuadData.mRawVertexBuffer[mQuadData.mRawBufferIndex], &v4, vert_size);
mQuadData.mRawBufferIndex += 1;
if (mQuadData.mRawBufferIndex + 4 > mQuadData.MaxVertices)
{
Flush();
}
memcpy(mQuadData.mRawVertexBuffer + mQuadData.mRawBufferIndex, vertices, sizeof(QuadData::Vertex) * 4);
mQuadData.mRawBufferIndex += 4;
// memcpy(mQuadData.mRawVertexBuffer + mQuadData.mRawBufferIndex, vertices, sizeof(QuadData::Vertex) * 4);
// mQuadData.mRawBufferIndex += 4;
// if (!mQuadData.mVertexBuffer->PushVertices(vertices, 4))
// {

@ -95,6 +95,9 @@ namespace lunarium
glm::vec2 tex_coord;
glm::vec4 color;
int tex_slot;
glm::vec3 translation;
float angle;
glm::vec3 scale;
};
//const u32 indices[6] = { 0, 1, 2, 0, 2, 3 };

@ -4,6 +4,9 @@ layout(location = 0) in vec3 pos;
layout(location = 1) in vec2 tex_coords;
layout(location = 2) in vec4 color;
layout(location = 3) in int tex_slot;
layout(location = 4) in vec3 translation;
layout(location = 5) in float angle;
layout(location = 6) in vec3 scale;
//out vec2 TexCoords;
out vec4 vert_color;
@ -13,5 +16,11 @@ uniform mat4 projview;
void main()
{
vert_color = color;
gl_Position = projview * vec4(pos, 1.0);
mat4 ModelTrans = mat4(
vec4( scale.x * cos(angle), scale.x * -sin(angle), 0.0, 0.0),
vec4( scale.y * sin(angle), scale.y * cos(angle), 0.0, 0.0),
vec4( 0.0, 0.0, scale.z, 0.0),
vec4( translation.xyz, 1.0)
);
gl_Position = projview * ModelTrans * vec4(pos, 1.0);
}
Loading…
Cancel
Save