Skip to content

fix: enable depth test at FsSetCameraPosition (gl2.0) - #8

Open
tomingtoming wants to merge 1 commit into
captainys:masterfrom
tomingtoming:upstream-fix/gl2-depth-test
Open

tomingtoming wants to merge 1 commit into
captainys:masterfrom
tomingtoming:upstream-fix/gl2-depth-test

Conversation

@tomingtoming

Copy link
Copy Markdown

In server mode, the network-standby aircraft chooser draws its 3D preview with the depth test disabled: triangles resolve in painter's order and the model renders inside-out / hollow. It never happens from the cold main menu — only after a simulation frame has run, which is the stale-state signature.

Cause: overlay passes (HUD glass, sky gradation, ...) call glDisable(GL_DEPTH_TEST) and do not restore it. FsSetCameraPosition is the gl2.0 driver's scene-start state-reset point — it already sets glDepthFunc/glDepthMask, clears Z and enables face culling — but it relies on GL_DEPTH_TEST having been left enabled by whoever drew before.

Fix: one glEnable(GL_DEPTH_TEST) at that reset point. glEnable is idempotent and every FsSetCameraPosition caller is a real 3D scene start, so the in-simulation paths that already run with the test enabled are unaffected.

Reproduction (stock desktop build, Linux, gl2.0)

  1. ./ysflight64_gl2 -server SMALL_MAP
  2. When the standby console prints Ready to go!, press A (Choose Airplane)
  3. The F-18E preview renders hollow — landing gear visible through the fuselage, back faces showing

With this one-line fix, the same steps render the model solid:

before/after

(full screenshots: before, after)

First found on the WebAssembly port (tomingtoming/ysflight-web#84), where per-draw GL instrumentation isolated the only state difference between the healthy path and the broken path to GL_DEPTH_TEST (healthy: enabled on every draw; after hosting: disabled on the chooser preview draws). The reproduction above confirms the same defect in the stock desktop gl2.0 build.

FsSetCameraPosition is the gl2.0 driver's scene-start state-reset point:
it already sets glDepthFunc/glDepthMask, clears Z, and enables face
culling -- but relied on GL_DEPTH_TEST being enabled by whoever drew
before.  Overlay passes (HUD glass, sky gradation) disable the depth test
without restoring it, so after a simulation frame has run, the
network-standby aircraft chooser drew its 3D preview with the depth test
still off: triangles resolved in draw order and the model rendered
inside-out / hollow (tomingtoming/ysflight-web#84 -- reproduced on both
server and client, never from the cold main menu, which is exactly the
stale-state signature).

glEnable is idempotent and every FsSetCameraPosition caller is a real 3D
scene start, so the enable is safe for the in-simulation paths that
already run with the test on.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UvHHZQtkJT6EyefM9o77Kx
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