Call renderer on tiles only-if tile on screen

OpenGL automatically clips objects outside of the view space but we were
still using up a lot of useless glDraw calls which impacts performance.
This change is temporary and will change when we get to scrolling the
world.
This commit is contained in:
Doyle Thai 2016-06-25 21:51:35 +10:00
parent e638724c75
commit fd3a353fdd

View File

@ -306,18 +306,22 @@ void worldTraveller_gameUpdateAndRender(GameState *state, const f32 dt)
TexAtlas *worldAtlas = asset_getTextureAtlas(world->texType); TexAtlas *worldAtlas = asset_getTextureAtlas(world->texType);
Texture *worldTex = asset_getTexture(world->texType); Texture *worldTex = asset_getTexture(world->texType);
f32 ndcFactor = 1.0f / CAST(f32)worldTex->width; f32 ndcFactor = 1.0f / CAST(f32) worldTex->width;
for (i32 i = 0; i < ARRAY_COUNT(world->tiles); i++) for (i32 i = 0; i < ARRAY_COUNT(world->tiles); i++)
{ {
Tile tile = world->tiles[i]; Tile tile = world->tiles[i];
v2 tileSize = V2(CAST(f32)state->tileSize, CAST(f32)state->tileSize); v2 tileSize = V2(CAST(f32)state->tileSize, CAST(f32)state->tileSize);
v2 tilePosInPixel = v2_scale(tile.pos, tileSize.x); v2 tilePosInPixel = v2_scale(tile.pos, tileSize.x);
v4 texNDC = if ((tilePosInPixel.x < state->width && tilePosInPixel.x >= 0) &&
v4_scale(worldAtlas->texRect[terraincoords_ground], ndcFactor); (tilePosInPixel.y < state->height && tilePosInPixel.y >= 0))
updateBufferObject(state->renderer.vbo, texNDC); {
renderer_object(&state->renderer, tilePosInPixel, tileSize, 0.0f, v4 texNDC =
V3(0, 0, 0), worldTex); v4_scale(worldAtlas->texRect[terraincoords_ground], ndcFactor);
updateBufferObject(state->renderer.vbo, texNDC);
renderer_object(&state->renderer, tilePosInPixel, tileSize, 0.0f,
V3(0, 0, 0), worldTex);
}
} }
// NOTE(doyle): Factor to normalise sprite sheet rect coords to -1, 1 // NOTE(doyle): Factor to normalise sprite sheet rect coords to -1, 1