a-game

2D platformer written from scratch.
git clone git://git.amin.space/a-game.git
Log | Files | Refs | README | LICENSE

commit 9c5a64c67702a8c2359b4c1fa2f5289c53c0fe6a
parent cf822b5b0ae2d9d7f4a63dc9135801d04bfd12e0
Author: amin <dev@aminmesbah.com>
Date:   Tue,  9 Jul 2019 00:33:29 +0000

Scissor non-debug rendering to main viewport

FossilOrigin-Name: c52e5fcee40f46ef139ddf1dbaec6572fd0bc6250217aa85dcc79eecfc1b1b91
Diffstat:
Msrc/game.c | 9++++++++-
Msrc/platform_linux.c | 1+
Msrc/platform_wasm.c | 1+
Msrc/platform_windows.c | 1+
Msrc/render.c | 17+++++++++++++++++
Msrc/render.h | 1+
6 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/src/game.c b/src/game.c @@ -256,6 +256,13 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga game_state->renderer.projection = math_projection_ortho(0.0f, framebuffer.width, 0.0f, framebuffer.height, -1.0f, 0.0f); } + glEnable(GL_SCISSOR_TEST); + glScissor( + viewport.min.x, + viewport.min.y, + viewport.max.x - viewport.min.x, + viewport.max.y - viewport.min.y); + v2i current_room_i = game_state->player.pos.room; struct Room *current_room = world_room_get(game_state->world, current_room_i); @@ -409,7 +416,7 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga // game_detect_collisions { -#if 0 +#if 1 #define RENDER_COLLISION_DEBUG_QUAD(r, c) renderer_debug_quad_draw(&game_state->renderer, (r), (c)); #else #define RENDER_COLLISION_DEBUG_QUAD(r, c) diff --git a/src/platform_linux.c b/src/platform_linux.c @@ -150,6 +150,7 @@ internal void error_callback(int error, const char *description) internal void framebuffer_size_callback(GLFWwindow *window, int width, int height) { + // TODO: get this out of the platform layer glViewport(0, 0, width, height); } diff --git a/src/platform_wasm.c b/src/platform_wasm.c @@ -84,6 +84,7 @@ void window_resize(int w, int h) { g_width = w; g_height = h; + // TODO: get this out of the platform layer glViewport(0, 0, g_width, g_height); } diff --git a/src/platform_windows.c b/src/platform_windows.c @@ -130,6 +130,7 @@ internal void error_callback(int error, const char *description) internal void framebuffer_size_callback(GLFWwindow *window, int width, int height) { + // TODO: get this out of the platform layer glViewport(0, 0, width, height); } diff --git a/src/render.c b/src/render.c @@ -77,7 +77,9 @@ internal void renderer_init(struct RendererState *renderer, struct Image *images internal void renderer_jobs_draw(struct RendererState *renderer) { glClearColor(0.1f, 0.1f, 0.1f, 1.0f); + glDisable(GL_SCISSOR_TEST); glClear(GL_COLOR_BUFFER_BIT); + glEnable(GL_SCISSOR_TEST); #if 0 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); @@ -94,6 +96,21 @@ internal void renderer_jobs_draw(struct RendererState *renderer) for (size_t i = 0; i < renderer->queue_count; i++) { struct RenderJob j = renderer->queue[i]; + + if (j.layer == RENDER_LAYER_DEBUG) + { + if (!renderer->scissor_test_is_disabled) + { + glDisable(GL_SCISSOR_TEST); + renderer->scissor_test_is_disabled = true; + } + } + else if (renderer->scissor_test_is_disabled) + { + glEnable(GL_SCISSOR_TEST); + renderer->scissor_test_is_disabled = false; + } + if (current_ebo != j.ebo) { current_ebo = j.ebo; diff --git a/src/render.h b/src/render.h @@ -30,4 +30,5 @@ struct RendererState struct Shader shader; struct RenderJob *queue; size_t queue_count; + bool scissor_test_is_disabled; };