Skip to content
This repository was archived by the owner on Sep 29, 2025. It is now read-only.

Commit 4a1162c

Browse files
committed
RPI4/GLES: Workaround shader binding bug
(crossported from flycast)
1 parent 4b0fce2 commit 4a1162c

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

libswirl/rend/gles/gles.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ struct PipelineShader
2828
{
2929
GLuint program;
3030

31+
GLuint tex;
32+
GLuint fog_table;
33+
3134
GLuint scale,depth_scale;
3235
GLuint extra_depth_scale;
3336
GLuint pp_ClipTest,cp_AlphaTestValue;
@@ -93,6 +96,8 @@ struct gl_ctx
9396
const char *glsl_version_header;
9497
int gl_major;
9598
bool is_gles;
99+
bool rpi4_workaround;
100+
96101
GLuint fog_image_format;
97102
GLenum index_type;
98103
bool swap_buffer_not_preserved;

libswirl/rend/gles/glesdraw.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,22 @@ __forceinline
206206
ShaderUniforms.trilinear_alpha != 1.f);
207207

208208
glcache.UseProgram(CurrentShader->program);
209+
210+
if (gl.rpi4_workaround)
211+
{
212+
if (CurrentShader->tex != -1)
213+
{
214+
glUniform1i(CurrentShader->tex, 0);
215+
}
216+
217+
if (CurrentShader->fog_table != -1)
218+
{
219+
glUniform1i(CurrentShader->fog_table, 1);
220+
}
221+
222+
ShaderUniforms.Set(CurrentShader);
223+
}
224+
209225
if (CurrentShader->trilinear_alpha != -1)
210226
glUniform1f(CurrentShader->trilinear_alpha, ShaderUniforms.trilinear_alpha);
211227

libswirl/rend/gles/glesrend.cpp

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ static void gles_term()
467467
void findGLVersion()
468468
{
469469
gl.index_type = GL_UNSIGNED_INT;
470+
gl.rpi4_workaround = false;
470471

471472
while (true)
472473
if (glGetError() == GL_NO_ERROR)
@@ -519,6 +520,18 @@ void findGLVersion()
519520
gl.fog_image_format = GL_ALPHA;
520521
}
521522
}
523+
524+
525+
// workarounds
526+
527+
auto renderer = (const char*)glGetString(GL_RENDERER);
528+
529+
if (renderer && strstr(renderer, "V3D 4.2"))
530+
{
531+
printf("glesrend: Enabling rpi4_workaround\n");
532+
533+
gl.rpi4_workaround = true;
534+
}
522535
}
523536

524537
struct ShaderUniforms_t ShaderUniforms;
@@ -671,9 +684,18 @@ bool CompilePipelineShader( PipelineShader* s)
671684

672685

673686
//setup texture 0 as the input for the shader
674-
GLuint gu=glGetUniformLocation(s->program, "tex");
675-
if (s->pp_Texture==1)
676-
glUniform1i(gu,0);
687+
s->tex = glGetUniformLocation(s->program, "tex");
688+
if (s->pp_Texture == 1)
689+
{
690+
glUniform1i(s->tex, 0);
691+
}
692+
693+
// Setup texture 1 as the fog table
694+
s->fog_table = glGetUniformLocation(s->program, "fog_table");
695+
if (s->fog_table != -1)
696+
{
697+
glUniform1i(s->fog_table, 1);
698+
}
677699

678700
//get the uniform locations
679701
s->scale = glGetUniformLocation(s->program, "scale");
@@ -699,10 +721,7 @@ bool CompilePipelineShader( PipelineShader* s)
699721
{
700722
s->sp_FOG_COL_RAM=-1;
701723
}
702-
// Setup texture 1 as the fog table
703-
gu = glGetUniformLocation(s->program, "fog_table");
704-
if (gu != -1)
705-
glUniform1i(gu, 1);
724+
706725
s->trilinear_alpha = glGetUniformLocation(s->program, "trilinear_alpha");
707726

708727
if (s->fog_clamping)

0 commit comments

Comments
 (0)