diff options
author | 3gg <3gg@shellblade.net> | 2024-08-31 18:40:28 -0700 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2024-08-31 18:40:28 -0700 |
commit | 0a78a9d9c1ac2090da56f395d6f2394a8a210010 (patch) | |
tree | 81515eea1852dcff74038dd7024131ee8b0a84b6 | |
parent | cb9b2c2fe7b77b0b8a3826ad2846655133683dfe (diff) |
More viewport control.
-rw-r--r-- | game/src/game.c | 2 | ||||
-rw-r--r-- | gfx/include/gfx/core.h | 7 | ||||
-rw-r--r-- | gfx/src/core/core.c | 25 | ||||
-rw-r--r-- | gfx/src/core/core_impl.h | 2 | ||||
-rw-r--r-- | gfx/src/renderer/renderer.c | 4 |
5 files changed, 30 insertions, 10 deletions
diff --git a/game/src/game.c b/game/src/game.c index 10c69aa..dc2248b 100644 --- a/game/src/game.c +++ b/game/src/game.c | |||
@@ -215,7 +215,7 @@ static void Resize(Game* game, int width, int height) { | |||
215 | game->height = height; | 215 | game->height = height; |
216 | 216 | ||
217 | GfxCore* gfxcore = gfx_get_core(game->gfx); | 217 | GfxCore* gfxcore = gfx_get_core(game->gfx); |
218 | gfx_set_viewport(gfxcore, width, height); | 218 | gfx_set_viewport(gfxcore, 0, 0, width, height); |
219 | 219 | ||
220 | resize_plugin(game, width, height); | 220 | resize_plugin(game, width, height); |
221 | } | 221 | } |
diff --git a/gfx/include/gfx/core.h b/gfx/include/gfx/core.h index 7d31cca..44509c9 100644 --- a/gfx/include/gfx/core.h +++ b/gfx/include/gfx/core.h | |||
@@ -321,10 +321,13 @@ void gfx_start_frame(GfxCore*); | |||
321 | void gfx_end_frame(GfxCore*); | 321 | void gfx_end_frame(GfxCore*); |
322 | 322 | ||
323 | /// Set the render backend's viewport dimensions. | 323 | /// Set the render backend's viewport dimensions. |
324 | void gfx_set_viewport(GfxCore*, int width, int height); | 324 | void gfx_set_viewport(GfxCore*, int x, int y, int width, int height); |
325 | 325 | ||
326 | /// Get the render backend's viewport dimensions. | 326 | /// Get the render backend's viewport dimensions. |
327 | void gfx_get_viewport(GfxCore*, int* width, int* height); | 327 | void gfx_get_viewport(GfxCore*, int* x, int* y, int* width, int* height); |
328 | |||
329 | /// Clear the viewport. | ||
330 | void gfx_clear(GfxCore*, vec4 colour); | ||
328 | 331 | ||
329 | /// Set blending state. | 332 | /// Set blending state. |
330 | void gfx_set_blending(GfxCore*, bool enable); | 333 | void gfx_set_blending(GfxCore*, bool enable); |
diff --git a/gfx/src/core/core.c b/gfx/src/core/core.c index 7a6d9cc..90038c6 100644 --- a/gfx/src/core/core.c +++ b/gfx/src/core/core.c | |||
@@ -64,7 +64,9 @@ void gfx_del_gfxcore(GfxCore* gfxcore) { | |||
64 | void gfx_start_frame(GfxCore* gfxcore) { | 64 | void gfx_start_frame(GfxCore* gfxcore) { |
65 | assert(gfxcore); | 65 | assert(gfxcore); |
66 | 66 | ||
67 | glViewport(0, 0, gfxcore->viewport.width, gfxcore->viewport.height); | 67 | glViewport( |
68 | gfxcore->viewport.x, gfxcore->viewport.y, gfxcore->viewport.width, | ||
69 | gfxcore->viewport.height); | ||
68 | glClearColor(0, 0, 0, 0); | 70 | glClearColor(0, 0, 0, 0); |
69 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | 71 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
70 | 72 | ||
@@ -76,20 +78,33 @@ void gfx_end_frame(GfxCore* gfxcore) { | |||
76 | ASSERT_GL; | 78 | ASSERT_GL; |
77 | } | 79 | } |
78 | 80 | ||
79 | void gfx_set_viewport(GfxCore* gfxcore, int width, int height) { | 81 | void gfx_set_viewport(GfxCore* gfxcore, int x, int y, int width, int height) { |
80 | assert(gfxcore); | 82 | assert(gfxcore); |
81 | gfxcore->viewport.width = width; | 83 | gfxcore->viewport = |
82 | gfxcore->viewport.height = height; | 84 | (Viewport){.x = x, .y = y, .width = width, .height = height}; |
83 | } | 85 | } |
84 | 86 | ||
85 | void gfx_get_viewport(GfxCore* gfxcore, int* width, int* height) { | 87 | void gfx_get_viewport( |
88 | GfxCore* gfxcore, int* x, int* y, int* width, int* height) { | ||
86 | assert(gfxcore); | 89 | assert(gfxcore); |
90 | assert(x); | ||
91 | assert(y); | ||
87 | assert(width); | 92 | assert(width); |
88 | assert(height); | 93 | assert(height); |
94 | |||
95 | *x = gfxcore->viewport.x; | ||
96 | *y = gfxcore->viewport.y; | ||
89 | *width = gfxcore->viewport.width; | 97 | *width = gfxcore->viewport.width; |
90 | *height = gfxcore->viewport.height; | 98 | *height = gfxcore->viewport.height; |
91 | } | 99 | } |
92 | 100 | ||
101 | void gfx_clear(GfxCore* gfxcore, vec4 colour) { | ||
102 | assert(gfxcore); | ||
103 | |||
104 | glClearColor(colour.x, colour.y, colour.z, colour.w); | ||
105 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | ||
106 | } | ||
107 | |||
93 | void gfx_set_blending(GfxCore* gfxcore, bool enable) { | 108 | void gfx_set_blending(GfxCore* gfxcore, bool enable) { |
94 | assert(gfxcore); | 109 | assert(gfxcore); |
95 | if (enable) { | 110 | if (enable) { |
diff --git a/gfx/src/core/core_impl.h b/gfx/src/core/core_impl.h index e27c0f2..eefdfbe 100644 --- a/gfx/src/core/core_impl.h +++ b/gfx/src/core/core_impl.h | |||
@@ -40,6 +40,8 @@ DEF_MEMPOOL(ShaderCache, ShaderCacheEntry, GFX_MAX_NUM_SHADERS) | |||
40 | DEF_MEMPOOL(ProgramCache, ShaderProgramCacheEntry, GFX_MAX_NUM_SHADER_PROGRAMS) | 40 | DEF_MEMPOOL(ProgramCache, ShaderProgramCacheEntry, GFX_MAX_NUM_SHADER_PROGRAMS) |
41 | 41 | ||
42 | typedef struct { | 42 | typedef struct { |
43 | int x; | ||
44 | int y; | ||
43 | int width; | 45 | int width; |
44 | int height; | 46 | int height; |
45 | } Viewport; | 47 | } Viewport; |
diff --git a/gfx/src/renderer/renderer.c b/gfx/src/renderer/renderer.c index d615918..c2a7dda 100644 --- a/gfx/src/renderer/renderer.c +++ b/gfx/src/renderer/renderer.c | |||
@@ -341,8 +341,8 @@ void gfx_render_scene(Renderer* renderer, const RenderSceneParams* params) { | |||
341 | view_matrix = mat4_id(); | 341 | view_matrix = mat4_id(); |
342 | } | 342 | } |
343 | 343 | ||
344 | int width, height; | 344 | int x, y, width, height; |
345 | gfx_get_viewport(gfxcore, &width, &height); | 345 | gfx_get_viewport(gfxcore, &x, &y, &width, &height); |
346 | const float aspect = (float)width / (float)height; | 346 | const float aspect = (float)width / (float)height; |
347 | 347 | ||
348 | RenderState state = { | 348 | RenderState state = { |