Skip to content

fix: ysgl uniform type/value mismatches (sampler unit, fogEnabled, textureSampleCoeff) - #12

Open
tomingtoming wants to merge 1 commit into
captainys:masterfrom
tomingtoming:upstream-fix/ysgl-uniform-types
Open

fix: ysgl uniform type/value mismatches (sampler unit, fogEnabled, textureSampleCoeff)#12
tomingtoming wants to merge 1 commit into
captainys:masterfrom
tomingtoming:upstream-fix/ysgl-uniform-types

Conversation

@tomingtoming

Copy link
Copy Markdown

Three glUniform calls in ysgl disagree with the shader-side declarations. On a conforming GL each one raises 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:

  1. 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. YSFLIGHT's own callers already treat the parameter as unit 0 — ysscenerygl2.0.cpp passes 0 with the comment // 0 for GL_TEXTURE0 apparently.

  2. ysglsl3ddrawing.c YsGLSL3DRendererInitializeUniformfogEnabled is a float in every shader but was initialized with glUniform1i (GL_INVALID_OPERATION, dropped). The runtime setter YsGLSLSet3DRendererUniformFogEnabled already uses glUniform1f; this makes the init site match it.

  3. ysglsl3ddrawing.c YsGLSL3DRendererInitializeUniformtextureSampleCoeff is a vec3 but was initialized with glUniform1f (GL_INVALID_OPERATION, dropped). The runtime path in YsGLSLSet3DRendererTextureType already uses glUniform3fv.

No intended behavior change on desktop GL — the fixes assign the same values the uniforms already held by accident — but the phantom GL errors disappear, and stricter implementations (WebGL) render correctly.

Verification (desktop Linux, gl2.0 build of YSFLIGHT)

Interposed glUniform1i/glUniform1f with an LD_PRELOAD shim that calls glGetError() after each real call, then ran the same scenario (boot → -freeflight → in-flight message) on binaries built from current master vs. master + this commit:

glUniform GL errors
master 16 (11× glUniform1i on the float fogEnabled inits, 5× glUniform1f on the vec3 textureSampleCoeff inits, all GL_INVALID_OPERATION)
with this fix 0

In-flight message text (the bitmap-renderer path of fix 1) renders identically before and after.

Found while porting YSFLIGHT to WebAssembly (ysflight-web), where fix 1 was the difference between readable messages and black boxes. Related YSFLIGHT-side fixes: captainys/YSFLIGHT#7, captainys/YSFLIGHT#8. As with those, no hurry at all!

…xtureSampleCoeff)

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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WuRxGPB4xoPDLzUBGdw5Fe
@tomingtoming
tomingtoming force-pushed the upstream-fix/ysgl-uniform-types branch from 4bbe9e7 to 6881656 Compare August 13, 2026 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant