Batch tiles to single vbo at render pass
This commit is contained in:
@@ -39,15 +39,21 @@ typedef struct Entity
|
||||
i32 currAnimIndex;
|
||||
} Entity;
|
||||
|
||||
INTERNAL inline v4 getEntityScreenRect(Entity entity)
|
||||
INTERNAL inline v4 getRect(v2 origin, v2 size)
|
||||
{
|
||||
v2 entityUpperLeftBound = v2_add(entity.pos, V2(0.0f, entity.size.y));
|
||||
v2 entityLowerRightBound = v2_add(entity.pos, V2(entity.size.x, 0.0f));
|
||||
v2 upperLeftBound = v2_add(origin, V2(0.0f, size.y));
|
||||
v2 lowerRightBound = v2_add(origin, V2(size.x, 0.0f));
|
||||
|
||||
v4 result = V4(entityUpperLeftBound.x, entityUpperLeftBound.y,
|
||||
entityLowerRightBound.x, entityLowerRightBound.y);
|
||||
v4 result = V4(upperLeftBound.x, upperLeftBound.y, lowerRightBound.x,
|
||||
lowerRightBound.y);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
INTERNAL inline v4 getEntityScreenRect(Entity entity)
|
||||
{
|
||||
v4 result = getRect(entity.pos, entity.size);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -10,12 +10,38 @@ typedef struct Renderer
|
||||
Shader *shader;
|
||||
GLuint vao;
|
||||
GLuint vbo;
|
||||
i32 numVertexesInVbo;
|
||||
} Renderer;
|
||||
|
||||
typedef struct RenderQuad
|
||||
{
|
||||
v4 vertex[4];
|
||||
} RenderQuad;
|
||||
|
||||
void renderer_entity(Renderer *renderer, Entity *entity, f32 rotate,
|
||||
v3 color);
|
||||
|
||||
void renderer_object(Renderer *renderer, v2 pos, v2 size, f32 rotate, v3 color,
|
||||
Texture *tex);
|
||||
|
||||
INTERNAL inline RenderQuad renderer_createQuad(v4 quadRectNdc, v4 texRectNdc)
|
||||
{
|
||||
// NOTE(doyle): Draws a series of triangles (three-sided polygons) using
|
||||
// vertices v0, v1, v2, then v2, v1, v3 (note the order)
|
||||
RenderQuad result = {0};
|
||||
result.vertex[0] = V4(quadRectNdc.x, quadRectNdc.y, texRectNdc.x, texRectNdc.y); // Top left
|
||||
result.vertex[1] = V4(quadRectNdc.x, quadRectNdc.w, texRectNdc.x, texRectNdc.w); // Bottom left
|
||||
result.vertex[2] = V4(quadRectNdc.z, quadRectNdc.y, texRectNdc.z, texRectNdc.y); // Top right
|
||||
result.vertex[3] = V4(quadRectNdc.z, quadRectNdc.w, texRectNdc.z, texRectNdc.w); // Bottom right
|
||||
return result;
|
||||
}
|
||||
|
||||
INTERNAL inline RenderQuad renderer_createDefaultQuad(v4 texRectNdc)
|
||||
{
|
||||
RenderQuad result = {0};
|
||||
v4 defaultVertices = V4(0.0f, 1.0f, 1.0f, 0.0f);
|
||||
result = renderer_createQuad(defaultVertices, texRectNdc);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user