diff --git a/src/emulator.c b/src/emulator.c index 044d23d8..b55cfb59 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -85,8 +85,8 @@ static void emu_render_frame(struct emu *emu) { /* render the current render context to the video framebuffer */ framebuffer_handle_t original = r_get_framebuffer(r2); r_bind_framebuffer(r2, emu->video_fb); - tr_render_context(emu->tr, &emu->video_rc, emu->video_fb_width, - emu->video_fb_height); + r_viewport(emu->r, emu->video_fb_width, emu->video_fb_height); + tr_render_context(emu->tr, &emu->video_rc); r_bind_framebuffer(r2, original); /* insert fence for main thread to synchronize on in order to ensure that @@ -148,7 +148,7 @@ static void emu_paint(struct emu *emu) { nk_update_input(emu->nk); - r_clear_viewport(emu->r, width, height); + r_viewport(emu->r, emu->video_width, emu->video_height); /* present the latest frame from the video thread */ { diff --git a/src/hw/pvr/tr.c b/src/hw/pvr/tr.c index d4c94c89..3f2cd436 100644 --- a/src/hw/pvr/tr.c +++ b/src/hw/pvr/tr.c @@ -930,12 +930,9 @@ static void tr_render_list(struct tr *tr, const struct tr_context *rc, } } -void tr_render_context(struct tr *tr, const struct tr_context *rc, - int video_width, int video_height) { +void tr_render_context(struct tr *tr, const struct tr_context *rc) { PROF_ENTER("gpu", "tr_render_context"); - r_clear_viewport(tr->r, video_width, video_height); - r_begin_ta_surfaces(tr->r, rc->projection, rc->verts, rc->num_verts); tr_render_list(tr, rc, TA_LIST_OPAQUE); diff --git a/src/hw/pvr/tr.h b/src/hw/pvr/tr.h index 24f6974c..ee0130d3 100644 --- a/src/hw/pvr/tr.h +++ b/src/hw/pvr/tr.h @@ -88,7 +88,6 @@ void tr_destroy(struct tr *tr); void tr_parse_context(struct tr *tr, const struct tile_context *ctx, struct tr_context *rc); -void tr_render_context(struct tr *tr, const struct tr_context *rc, - int video_width, int video_height); +void tr_render_context(struct tr *tr, const struct tr_context *rc); #endif diff --git a/src/render/gl_backend.c b/src/render/gl_backend.c index 1b15c01e..5301220d 100644 --- a/src/render/gl_backend.c +++ b/src/render/gl_backend.c @@ -66,6 +66,8 @@ struct texture { struct render_backend { struct host *host; gl_context_t ctx; + int viewport_width; + int viewport_height; int debug_flags; /* default assets created during intitialization */ @@ -563,17 +565,14 @@ void r_begin_ui_surfaces(struct render_backend *r, const struct ui_vertex *verts, int num_verts, const uint16_t *indices, int num_indices) { /* setup projection matrix */ - int width = video_width(r->host); - int height = video_height(r->host); - float ortho[16]; - ortho[0] = 2.0f / (float)width; + ortho[0] = 2.0f / (float)r->viewport_width; ortho[4] = 0.0f; ortho[8] = 0.0f; ortho[12] = -1.0f; ortho[1] = 0.0f; - ortho[5] = -2.0f / (float)height; + ortho[5] = -2.0f / (float)r->viewport_height; ortho[9] = 0.0f; ortho[13] = 1.0f; @@ -612,9 +611,20 @@ void r_begin_ui_surfaces(struct render_backend *r, } } -void r_clear_viewport(struct render_backend *r, int width, int height) { +int r_viewport_height(struct render_backend *r) { + return r->viewport_height; +} + +int r_viewport_width(struct render_backend *r) { + return r->viewport_width; +} + +void r_viewport(struct render_backend *r, int width, int height) { + r->viewport_width = width; + r->viewport_height = height; + glDepthMask(1); - glViewport(0, 0, width, height); + glViewport(0, 0, r->viewport_width, r->viewport_height); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } @@ -815,14 +825,6 @@ void r_set_debug_flag(struct render_backend *r, int flag) { r->debug_flags |= flag; } -int r_video_height(struct render_backend *r) { - return video_height(r->host); -} - -int r_video_width(struct render_backend *r) { - return video_width(r->host); -} - void r_make_current(struct render_backend *r) { video_gl_make_current(r->host, r->ctx); } diff --git a/src/render/microprofile.cc b/src/render/microprofile.cc index 9fd1c38b..6b68d210 100644 --- a/src/render/microprofile.cc +++ b/src/render/microprofile.cc @@ -217,8 +217,8 @@ static void mp_draw_line(struct microprofile *mp, float *verts, int num_verts, void mp_render(struct microprofile *mp) { s_mp = mp; - int width = r_video_width(mp->r); - int height = r_video_height(mp->r); + int width = r_viewport_width(mp->r); + int height = r_viewport_height(mp->r); /* update draw surfaces */ MicroProfileDraw(width, height); diff --git a/src/render/nuklear.c b/src/render/nuklear.c index edfebb58..ea7f3508 100644 --- a/src/render/nuklear.c +++ b/src/render/nuklear.c @@ -17,7 +17,7 @@ #endif void nk_render(struct nuklear *nk) { - float height = (float)r_video_height(nk->r); + float height = (float)r_viewport_height(nk->r); /* convert draw list into vertex / element buffers */ static const struct nk_draw_vertex_layout_element vertex_layout[] = { diff --git a/src/render/render_backend.h b/src/render/render_backend.h index 6e3ccccf..6af8fafc 100644 --- a/src/render/render_backend.h +++ b/src/render/render_backend.h @@ -138,9 +138,6 @@ void r_destroy(struct render_backend *rc); void r_make_current(struct render_backend *r); -int r_video_width(struct render_backend *r); -int r_video_height(struct render_backend *r); - void r_set_debug_flag(struct render_backend *r, int flag); int r_get_debug_flag(struct render_backend *r, int flag); void r_clear_debug_flag(struct render_backend *r, int flag); @@ -165,7 +162,9 @@ sync_handle_t r_insert_sync(struct render_backend *r); void r_wait_sync(struct render_backend *r, sync_handle_t handle); void r_destroy_sync(struct render_backend *r, sync_handle_t handle); -void r_clear_viewport(struct render_backend *r, int width, int height); +void r_viewport(struct render_backend *r, int width, int height); +int r_viewport_width(struct render_backend *r); +int r_viewport_height(struct render_backend *r); void r_begin_ta_surfaces(struct render_backend *r, const float *projection, const struct ta_vertex *verts, int num_verts); diff --git a/src/tracer.c b/src/tracer.c index e2b4e493..776293dc 100644 --- a/src/tracer.c +++ b/src/tracer.c @@ -808,7 +808,7 @@ void tracer_run_frame(struct tracer *tracer) { int width = video_width(tracer->host); int height = video_height(tracer->host); - r_clear_viewport(tracer->r, width, height); + r_viewport(tracer->r, width, height); nk_update_input(tracer->nk);