From 68816562f0b8cdd76d628288d438dbb52bc3f59b Mon Sep 17 00:00:00 2001 From: toming Date: Thu, 13 Aug 2026 16:53:34 +0900 Subject: [PATCH] fix: ysgl uniform type/value mismatches (sampler unit, fogEnabled, textureSampleCoeff) Three glUniform calls disagree with the shader-side declarations. On a conforming GL they raise an error and the assignment is dropped (or lands on an arbitrary target), so they only work because the intended value happens to coincide with what the uniform ends up holding: - ysglslbitmaprenderer.c RenderTexture2D: the sampler uniform was set to the texture object id (samplerIdent) instead of the texture-unit index. Depending on the id's value the call is either rejected (GL_INVALID_VALUE, uniform keeps its initial value 0 -- the unit all callers actually bind) or accepted and points the sampler at whatever unit shares that number. On WebGL this rendered every text bitmap (in-flight messages, console lines) as a solid black box. - ysglsl3ddrawing.c YsGLSL3DRendererInitializeUniform: fogEnabled is a float in every shader but was initialized with glUniform1i (GL_INVALID_OPERATION, dropped; the runtime setter YsGLSLSet3DRendererUniformFogEnabled already uses glUniform1f). - ysglsl3ddrawing.c YsGLSL3DRendererInitializeUniform: textureSampleCoeff is a vec3 but was initialized with glUniform1f (GL_INVALID_OPERATION, dropped; the runtime setter in YsGLSLSet3DRendererTextureType already uses glUniform3fv). No intended behavior change on desktop GL -- the fixes assign the same values the uniforms already held -- but the phantom GL errors disappear and stricter implementations (WebGL) render correctly. Measured on a desktop Linux gl2.0 build of YSFLIGHT (boot -> free flight): 16 GL errors from these call sites before, 0 after; in-flight message text renders identically. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01WuRxGPB4xoPDLzUBGdw5Fe --- src/ysgl/src/ysglsl3ddrawing.c | 7 +++++-- src/ysgl/src/ysglslbitmaprenderer.c | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ysgl/src/ysglsl3ddrawing.c b/src/ysgl/src/ysglsl3ddrawing.c index e96f8b20..a7cec5fe 100644 --- a/src/ysgl/src/ysglsl3ddrawing.c +++ b/src/ysgl/src/ysglsl3ddrawing.c @@ -1022,7 +1022,9 @@ static void YsGLSL3DRendererInitializeUniform(struct YsGLSL3DRenderer *renderer) } if(0<=renderer->uniformTextureSampleCoeff) { - glUniform1f(renderer->uniformTextureSampleCoeff,0); + /* textureSampleCoeff is a vec3 in the shaders. */ + const GLfloat zeroCoeff[3]={0,0,0}; + glUniform3fv(renderer->uniformTextureSampleCoeff,1,zeroCoeff); } if(0<=renderer->uniformUseNegativeOneToPositiveOnTexCoordPos) { @@ -1054,7 +1056,8 @@ static void YsGLSL3DRendererInitializeUniform(struct YsGLSL3DRenderer *renderer) if(0<=renderer->uniformFogEnabledPos) { - glUniform1i(renderer->uniformFogEnabledPos,0); + /* fogEnabled is a float in the shaders. */ + glUniform1f(renderer->uniformFogEnabledPos,0.0f); } if(0<=renderer->uniformFogDensityPos) { diff --git a/src/ysgl/src/ysglslbitmaprenderer.c b/src/ysgl/src/ysglslbitmaprenderer.c index 9c6091e1..32c49384 100644 --- a/src/ysgl/src/ysglslbitmaprenderer.c +++ b/src/ysgl/src/ysglslbitmaprenderer.c @@ -398,7 +398,9 @@ static void RenderTexture2D( } glUniform1i(renderer->transformationTypePos,1); - glUniform1i(renderer->texturePos,samplerIdent); + /* A sampler uniform takes a texture-unit index, not a texture object + id. All callers bind the texture on unit 0. */ + glUniform1i(renderer->texturePos,0); glVertexAttribPointer(renderer->vertexPos,4,GL_FLOAT,GL_FALSE,0,vertex); glVertexAttribPointer(renderer->offsetPos,2,GL_FLOAT,GL_FALSE,0,offset);