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 is_running;
|
||||
bool resync_flag;
|
||||
|
||||
bool window_size_has_changed;
|
||||
} t_ctx;
|
||||
|
||||
extern t_ctx ctx;
|
||||
|
@ -54,7 +54,6 @@ struct action_hash_item {
|
||||
|
||||
struct input_state {
|
||||
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 */
|
||||
uint32_t mouse_state; /* SDL mouse button bitmask */
|
||||
t_vec2 mouse_window_position;
|
||||
|
@ -23,6 +23,8 @@
|
||||
static void poll_events(void) {
|
||||
SDL_Event e;
|
||||
|
||||
ctx.window_size_has_changed = false;
|
||||
|
||||
while (SDL_PollEvent(&e)) {
|
||||
switch (e.type) {
|
||||
case SDL_QUIT:
|
||||
@ -37,6 +39,7 @@ static void poll_events(void) {
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
ctx.window_w = e.window.data1;
|
||||
ctx.window_h = e.window.data2;
|
||||
ctx.window_size_has_changed = true;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -141,26 +141,27 @@ static void render_space(void) {
|
||||
void render(void) {
|
||||
textures_update_atlas(&ctx.texture_cache);
|
||||
|
||||
/* TODO: only do this when needed */
|
||||
/* fit rendering context onto the resizable screen */
|
||||
if ((float)ctx.window_w / (float)ctx.window_h > RENDER_BASE_RATIO) {
|
||||
float ratio = (float)ctx.window_h / (float)RENDER_BASE_HEIGHT;
|
||||
int w = (int)((float)RENDER_BASE_WIDTH * ratio);
|
||||
glViewport(
|
||||
ctx.window_w / 2 - w / 2,
|
||||
0,
|
||||
w,
|
||||
ctx.window_h
|
||||
);
|
||||
} else {
|
||||
float ratio = (float)ctx.window_w / (float)RENDER_BASE_WIDTH;
|
||||
int h = (int)((float)RENDER_BASE_HEIGHT * ratio);
|
||||
glViewport(
|
||||
0,
|
||||
ctx.window_h / 2 - h / 2,
|
||||
ctx.window_w,
|
||||
h
|
||||
);
|
||||
if (ctx.window_size_has_changed) {
|
||||
if ((float)ctx.window_w / (float)ctx.window_h > RENDER_BASE_RATIO) {
|
||||
float ratio = (float)ctx.window_h / (float)RENDER_BASE_HEIGHT;
|
||||
int w = (int)((float)RENDER_BASE_WIDTH * ratio);
|
||||
glViewport(
|
||||
ctx.window_w / 2 - w / 2,
|
||||
0,
|
||||
w,
|
||||
ctx.window_h
|
||||
);
|
||||
} else {
|
||||
float ratio = (float)ctx.window_w / (float)RENDER_BASE_WIDTH;
|
||||
int h = (int)((float)RENDER_BASE_HEIGHT * ratio);
|
||||
glViewport(
|
||||
0,
|
||||
ctx.window_h / 2 - h / 2,
|
||||
ctx.window_w,
|
||||
h
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
glClearColor((1.0f / 255) * 230,
|
||||
|
Loading…
Reference in New Issue
Block a user