gfx/drivers: drop dead prim_to_gl helpers in gl1/gl2/gl3

Companion to 1ee88d08de (the d3d helpers).  Each of gl1, gl2,
gl3 carries an identical gfx_display_prim_to_gl{1,,3}_enum helper
that maps GFX_DISPLAY_PRIM_TRIANGLESTRIP -> GL_TRIANGLE_STRIP and
GFX_DISPLAY_PRIM_TRIANGLES -> GL_TRIANGLES.  Same dead-code
argument as 1ee88d08de: every gfx_display_ctx_draw_t in the
codebase sets prim_type to GFX_DISPLAY_PRIM_TRIANGLESTRIP before
invoking dispctx->draw, all 15 "prim_type =" assignments under
gfx/, menu/, and gfx/widgets/ assign TRIANGLESTRIP, and every
local declaration assigns prim_type before the draw call.  The
TRIANGLES, NONE, and default arms are unreachable.

Unlike the d3d helpers (which mapped TRIANGLES to the wrong
primitive type and returned an illegal D3DPRIMITIVETYPE on the
default branch), the gl helpers were correct in their dead
branches -- TRIANGLES -> GL_TRIANGLES is the right mapping, and
the "return 0" default falls back to GL_POINTS, a valid (if
nonsensical for menu draws) GL enum.  So this is purely
dead-code removal, not a latent-bug fix.

Inline GL_TRIANGLE_STRIP at the glDrawArrays call site, drop the
helpers.  gl3 has two glDrawArrays sites (the chain.active branch
and the HAVE_SLANG else branch); both get the same treatment, and
the explicit switch on prim_type at the second site collapses to
a single glDrawArrays call as well.  Document at the call sites
that the constant assumes TRIANGLESTRIP.

Net -48 lines.  No behavioural change for any existing caller.
This commit is contained in:
U-DESKTOP-SPFP6AQ\twistedtechre committed 2026-04-30 02:05:06 +02:00
1 parent 1ee88d08de
commit 696efa0f3d
3 files changed
+21 -69

No files matched your search

+6 -19
View File
@@ -273,23 +273,6 @@ static void *gfx_display_gl1_get_default_mvp(void *data)
return &gl1->mvp_no_rot;
}
static GLenum gfx_display_prim_to_gl1_enum(
enum gfx_display_prim_type type)
{
switch (type)
{
case GFX_DISPLAY_PRIM_TRIANGLESTRIP:
return GL_TRIANGLE_STRIP;
case GFX_DISPLAY_PRIM_TRIANGLES:
return GL_TRIANGLES;
case GFX_DISPLAY_PRIM_NONE:
default:
break;
}
return 0;
}
static void gfx_display_gl1_blend_begin(void *data)
{
glEnable(GL_BLEND);
@@ -366,8 +349,12 @@ static void gfx_display_gl1_draw(gfx_display_ctx_draw_t *draw,
glColorPointer(4, GL_FLOAT, 0, draw->coords->color);
glTexCoordPointer(2, GL_FLOAT, 0, draw->coords->tex_coord);
glDrawArrays(gfx_display_prim_to_gl1_enum(
draw->prim_type), 0, draw->coords->vertices);
/* Every caller in the codebase sets draw->prim_type to
* GFX_DISPLAY_PRIM_TRIANGLESTRIP, so the per-call switch on the
* primitive type that used to live here was dead. Hard-code
* GL_TRIANGLE_STRIP; if a future caller passes TRIANGLES this
* will need to grow back into a switch. */
glDrawArrays(GL_TRIANGLE_STRIP, 0, draw->coords->vertices);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+6 -19
View File
@@ -511,23 +511,6 @@ static void *gfx_display_gl2_get_default_mvp(void *data)
return &gl->mvp_no_rot;
}
static GLenum gfx_display_prim_to_gl_enum(
enum gfx_display_prim_type type)
{
switch (type)
{
case GFX_DISPLAY_PRIM_TRIANGLESTRIP:
return GL_TRIANGLE_STRIP;
case GFX_DISPLAY_PRIM_TRIANGLES:
return GL_TRIANGLES;
case GFX_DISPLAY_PRIM_NONE:
default:
break;
}
return 0;
}
static void gfx_display_gl2_blend_begin(void *data)
{
gl2_t *gl = (gl2_t*)data;
@@ -650,8 +633,12 @@ static void gfx_display_gl2_draw(gfx_display_ctx_draw_t *draw,
: (math_matrix_4x4*)&gl->mvp_no_rot);
glDrawArrays(gfx_display_prim_to_gl_enum(
draw->prim_type), 0, draw->coords->vertices);
/* Every caller in the codebase sets draw->prim_type to
* GFX_DISPLAY_PRIM_TRIANGLESTRIP, so the per-call switch on the
* primitive type that used to live here was dead. Hard-code
* GL_TRIANGLE_STRIP; if a future caller passes TRIANGLES this
* will need to grow back into a switch. */
glDrawArrays(GL_TRIANGLE_STRIP, 0, draw->coords->vertices);
gl->coords.color = gl->white_color_ptr;
}
+9 -31
View File
@@ -651,23 +651,6 @@ static void gfx_display_gl3_draw_pipeline(
#endif
}
static GLenum gfx_display_prim_to_gl3_enum(
enum gfx_display_prim_type type)
{
switch (type)
{
case GFX_DISPLAY_PRIM_TRIANGLESTRIP:
return GL_TRIANGLE_STRIP;
case GFX_DISPLAY_PRIM_TRIANGLES:
return GL_TRIANGLES;
case GFX_DISPLAY_PRIM_NONE:
default:
break;
}
return 0;
}
static void gfx_display_gl3_draw(gfx_display_ctx_draw_t *draw,
void *data, unsigned video_width, unsigned video_height)
{
@@ -695,8 +678,12 @@ static void gfx_display_gl3_draw(gfx_display_ctx_draw_t *draw,
draw->matrix_data ? (math_matrix_4x4*)draw->matrix_data
: (math_matrix_4x4*)&gl->mvp_no_rot);
glDrawArrays(gfx_display_prim_to_gl3_enum(
draw->prim_type), 0, draw->coords->vertices);
/* Every caller in the codebase sets draw->prim_type to
* GFX_DISPLAY_PRIM_TRIANGLESTRIP, so the per-call switch on
* the primitive type that used to live here was dead.
* Hard-code GL_TRIANGLE_STRIP; if a future caller passes
* TRIANGLES this will need to grow back into a switch. */
glDrawArrays(GL_TRIANGLE_STRIP, 0, draw->coords->vertices);
}
#ifdef HAVE_SLANG
else
@@ -797,18 +784,9 @@ static void gfx_display_gl3_draw(gfx_display_ctx_draw_t *draw,
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE,
4 * sizeof(float), (void *)(uintptr_t)0);
switch (draw->prim_type)
{
case GFX_DISPLAY_PRIM_TRIANGLESTRIP:
glDrawArrays(GL_TRIANGLE_STRIP, 0, draw->coords->vertices);
break;
case GFX_DISPLAY_PRIM_TRIANGLES:
glDrawArrays(GL_TRIANGLES, 0, draw->coords->vertices);
break;
case GFX_DISPLAY_PRIM_NONE:
default:
break;
}
/* See the matching comment in the chain.active branch above:
* every caller passes TRIANGLESTRIP. */
glDrawArrays(GL_TRIANGLE_STRIP, 0, draw->coords->vertices);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);