Skip to content

Commit 4e3be96

Browse files
committed
(GL1) Fix on-screen overlay rendering
gl1_render_overlay was missing essentially all of the GL state setup needed to actually draw anything. Three issues, all fixed by mirroring the patterns already used in gfx_display_gl1_draw and gl1_raster_font_draw_vertices: 1. Client arrays were never enabled. The function assigned values to gl->coords.vertex/tex_coord/color, but those struct fields don't drive GL state — they need to be wired up via glEnableClientState plus glVertexPointer/glTexCoordPointer/glColorPointer pointing at the overlay coord buffers. Without them glDrawArrays runs with whatever client array state happened to be active from the previous draw, which generally meant nothing rendered. 2. The PROJECTION matrix was pushed but never popped, leaking a matrix-stack entry every frame. The MODELVIEW matrix was also never reset to identity. 3. The viewport size source was wrong. Callers pass video_width/ video_height from video_info, which in gl1 is the emulated core frame size (e.g. 256x224 for SNES, 320x240 default for the menu surface) — not the window size. Fullscreen overlays need the actual window viewport, so use gl->screen_width/height (set from the context driver's get_video_size) instead, with fallback to the passed-in width/height for safety. Same semantic mismatch fixed recently for the statistics font in commit 1224324. Additionally, the projection itself was loaded as identity, which gives clip space [-1,1] x [-1,1]. Overlay vertices are emitted in [0,1] UI space by gl1_overlay_vertex_geom, so an identity projection mapped them into the upper-right quadrant of the viewport instead of filling it. Load gl->mvp_no_rot — the pre-built ortho(0,1,0,1,-1,1) matrix — for the projection so [0,1] vertices map to the full viewport, matching what gl3 does with the same matrix in its shader uniform. With these changes overlays render at the correct full-screen size and position, matching the gl/glcore behaviour.
1 parent 2f4ce7b commit 4e3be96

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

gfx/drivers/gl1.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,17 @@ static void gl1_render_overlay(gl1_t *gl,
999999
{
10001000
int i;
10011001

1002+
/* gl1 reuses video_width/height for the emulated core frame size
1003+
* (e.g. 256x224 for SNES, 320x240 default for the menu surface),
1004+
* not the window size. Fullscreen overlays must be drawn into the
1005+
* actual window viewport, so use screen_width/height instead.
1006+
* Fall back to the passed-in width/height if the context driver
1007+
* has not reported a screen size yet. */
1008+
if (gl->screen_width)
1009+
width = gl->screen_width;
1010+
if (gl->screen_height)
1011+
height = gl->screen_height;
1012+
10021013
glEnable(GL_BLEND);
10031014

10041015
if (gl->flags & GL1_FLAG_OVERLAY_FULLSCREEN)
@@ -1009,16 +1020,46 @@ static void gl1_render_overlay(gl1_t *gl,
10091020
gl->coords.color = gl->overlay_color_coord;
10101021
gl->coords.vertices = 4 * gl->overlays;
10111022

1023+
/* Fixed-function pipeline draws need the projection set, the
1024+
* modelview reset to identity and the client arrays bound to the
1025+
* overlay coord buffers. Previously this function only assigned
1026+
* pointers to gl->coords (which is just a struct field, not GL
1027+
* state) and pushed PROJECTION without popping it — so glDrawArrays
1028+
* ran with whatever client array state happened to be active and
1029+
* nothing rendered. Match the pattern used in
1030+
* gfx_display_gl1_draw and gl1_raster_font_draw_vertices. */
10121031
glMatrixMode(GL_PROJECTION);
10131032
glPushMatrix();
1033+
glLoadMatrixf(gl->mvp_no_rot.data);
1034+
1035+
glMatrixMode(GL_MODELVIEW);
1036+
glPushMatrix();
10141037
glLoadIdentity();
10151038

1039+
glEnable(GL_TEXTURE_2D);
1040+
glEnableClientState(GL_VERTEX_ARRAY);
1041+
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1042+
glEnableClientState(GL_COLOR_ARRAY);
1043+
1044+
glVertexPointer(2, GL_FLOAT, 0, gl->overlay_vertex_coord);
1045+
glTexCoordPointer(2, GL_FLOAT, 0, gl->overlay_tex_coord);
1046+
glColorPointer(4, GL_FLOAT, 0, gl->overlay_color_coord);
1047+
10161048
for (i = 0; i < (int)gl->overlays; i++)
10171049
{
10181050
glBindTexture(GL_TEXTURE_2D, gl->overlay_tex[i]);
10191051
glDrawArrays(GL_TRIANGLE_STRIP, 4 * i, 4);
10201052
}
10211053

1054+
glDisableClientState(GL_COLOR_ARRAY);
1055+
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1056+
glDisableClientState(GL_VERTEX_ARRAY);
1057+
1058+
glMatrixMode(GL_MODELVIEW);
1059+
glPopMatrix();
1060+
glMatrixMode(GL_PROJECTION);
1061+
glPopMatrix();
1062+
10221063
glDisable(GL_BLEND);
10231064
gl->coords.vertex = gl->vertex_ptr;
10241065
gl->coords.tex_coord = gl->tex_info.coord;

0 commit comments

Comments
 (0)