rendering.c: only update opengl viewport once it's actually changed
This commit is contained in:
parent
79bc261ccd
commit
f5ba4a75bd
@ -62,6 +62,8 @@ typedef struct context {
|
|||||||
bool debug;
|
bool debug;
|
||||||
bool is_running;
|
bool is_running;
|
||||||
bool resync_flag;
|
bool resync_flag;
|
||||||
|
|
||||||
|
bool window_size_has_changed;
|
||||||
} t_ctx;
|
} t_ctx;
|
||||||
|
|
||||||
extern t_ctx ctx;
|
extern t_ctx ctx;
|
||||||
|
@ -54,7 +54,6 @@ struct action_hash_item {
|
|||||||
|
|
||||||
struct input_state {
|
struct input_state {
|
||||||
struct action_hash_item *action_hash;
|
struct action_hash_item *action_hash;
|
||||||
SDL_Renderer *renderer; /* some input relates to the screen in some way */
|
|
||||||
const uint8_t *keyboard_state; /* array of booleans indexed by scancode */
|
const uint8_t *keyboard_state; /* array of booleans indexed by scancode */
|
||||||
uint32_t mouse_state; /* SDL mouse button bitmask */
|
uint32_t mouse_state; /* SDL mouse button bitmask */
|
||||||
t_vec2 mouse_window_position;
|
t_vec2 mouse_window_position;
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
static void poll_events(void) {
|
static void poll_events(void) {
|
||||||
SDL_Event e;
|
SDL_Event e;
|
||||||
|
|
||||||
|
ctx.window_size_has_changed = false;
|
||||||
|
|
||||||
while (SDL_PollEvent(&e)) {
|
while (SDL_PollEvent(&e)) {
|
||||||
switch (e.type) {
|
switch (e.type) {
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
@ -37,6 +39,7 @@ static void poll_events(void) {
|
|||||||
case SDL_WINDOWEVENT_RESIZED:
|
case SDL_WINDOWEVENT_RESIZED:
|
||||||
ctx.window_w = e.window.data1;
|
ctx.window_w = e.window.data1;
|
||||||
ctx.window_h = e.window.data2;
|
ctx.window_h = e.window.data2;
|
||||||
|
ctx.window_size_has_changed = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,26 +141,27 @@ static void render_space(void) {
|
|||||||
void render(void) {
|
void render(void) {
|
||||||
textures_update_atlas(&ctx.texture_cache);
|
textures_update_atlas(&ctx.texture_cache);
|
||||||
|
|
||||||
/* TODO: only do this when needed */
|
|
||||||
/* fit rendering context onto the resizable screen */
|
/* fit rendering context onto the resizable screen */
|
||||||
if ((float)ctx.window_w / (float)ctx.window_h > RENDER_BASE_RATIO) {
|
if (ctx.window_size_has_changed) {
|
||||||
float ratio = (float)ctx.window_h / (float)RENDER_BASE_HEIGHT;
|
if ((float)ctx.window_w / (float)ctx.window_h > RENDER_BASE_RATIO) {
|
||||||
int w = (int)((float)RENDER_BASE_WIDTH * ratio);
|
float ratio = (float)ctx.window_h / (float)RENDER_BASE_HEIGHT;
|
||||||
glViewport(
|
int w = (int)((float)RENDER_BASE_WIDTH * ratio);
|
||||||
ctx.window_w / 2 - w / 2,
|
glViewport(
|
||||||
0,
|
ctx.window_w / 2 - w / 2,
|
||||||
w,
|
0,
|
||||||
ctx.window_h
|
w,
|
||||||
);
|
ctx.window_h
|
||||||
} else {
|
);
|
||||||
float ratio = (float)ctx.window_w / (float)RENDER_BASE_WIDTH;
|
} else {
|
||||||
int h = (int)((float)RENDER_BASE_HEIGHT * ratio);
|
float ratio = (float)ctx.window_w / (float)RENDER_BASE_WIDTH;
|
||||||
glViewport(
|
int h = (int)((float)RENDER_BASE_HEIGHT * ratio);
|
||||||
0,
|
glViewport(
|
||||||
ctx.window_h / 2 - h / 2,
|
0,
|
||||||
ctx.window_w,
|
ctx.window_h / 2 - h / 2,
|
||||||
h
|
ctx.window_w,
|
||||||
);
|
h
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glClearColor((1.0f / 255) * 230,
|
glClearColor((1.0f / 255) * 230,
|
||||||
|
Loading…
Reference in New Issue
Block a user