Skip to content

fix(gles): 3D rendering — MappedAtCreation flush + depth fixes (#284) - #286

Merged
kolkov merged 4 commits into
mainfrom
fix/284-gles-3d-rendering
Jul 30, 2026
Merged

fix(gles): 3D rendering — MappedAtCreation flush + depth fixes (#284)#286
kolkov merged 4 commits into
mainfrom
fix/284-gles-3d-rendering

Conversation

@kolkov

@kolkov kolkov commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Three GLES HAL bugs causing invisible 3D geometry. Visually confirmed fixed on Windows (Intel Iris Xe, 60 FPS).

Root cause: MappedAtCreation buffer data silently discarded

UnmapBuffer guarded glBufferSubData flush with BufferUsageMapWrite check. Per WebGPU spec, MappedAtCreation does NOT require MapWrite usage. g3d uniform/vertex/index buffers (Uniform|CopyDst + MappedAtCreation) had data thrown away — zero MVP matrices, zero vertices → invisible.

Additional fixes

  • Depth/stencil attachment point by formatGL_DEPTH_ATTACHMENT for depth-only, GL_DEPTH_STENCIL_ATTACHMENT for combined (Rust wgpu-hal parity). Wrong attachment point caused FBO incomplete (0x506).
  • Depth clear maskglDepthMask(true) + glClearDepth(value) before glClear(GL_DEPTH_BUFFER_BIT). Stale mask from prior pipeline blocked depth clear.
  • Viewport depth rangeglDepthRange(minDepth, maxDepth) in SetViewportCommand (was ignoring depth range fields).
  • gl.Context wrappersClearDepth(), DepthRange() for Windows (syscall) and Linux (goffi/GLES).

Test plan

  • go build ./... — native
  • GOOS=js GOARCH=wasm go build . — browser
  • All tests pass
  • golangci-lint — 0 issues
  • Visual: GOGPU_GRAPHICS_API=gles go run g3d/examples/hello-cube/ — cube visible, rotating
  • Visual: GOGPU_GRAPHICS_API=gles go run g3d/examples/fullscreen-overlay/ — 3D cube + 2D overlay, 60 FPS

Fixes #284.

kolkov added 4 commits July 30, 2026 10:44
…ity)

v0.30.26 used GL_DEPTH_STENCIL_ATTACHMENT unconditionally — depth-only
formats (Depth24Plus, Depth32Float) made FBO incomplete → 0x506 on every
draw call → black screen.

Now selects attachment point by texture format (Rust wgpu-hal command.rs:577-580):
- depth-only → GL_DEPTH_ATTACHMENT
- stencil-only → GL_STENCIL_ATTACHMENT
- depth+stencil → GL_DEPTH_STENCIL_ATTACHMENT

Fixes both AttachDepthStencilToFBOCommand (surface) and
AttachDepthStencilCommand (offscreen). 2D overlay renders correctly.
3D rendering on GLES under separate investigation.
…rity)

Three GLES depth bugs causing invisible 3D geometry:

1. ClearDepthCommand: add glDepthMask(true) before clear — prevents stale
   DepthMask(false) from prior pipeline masking the depth clear. Add
   glClearDepth(value) to set clear value (was using GL default 1.0).
   Rust ref: queue.rs:1199-1205.

2. SetViewportCommand: add glDepthRange(minDepth, maxDepth) — was ignoring
   depth range entirely. Default maxDepth=0 caused all geometry to be clipped.
   Rust ref: queue.rs:1295-1296.

3. gl.Context: add ClearDepth() and DepthRange() wrappers for both Windows
   (syscall, double) and Linux (goffi, float32 for GLES / glClearDepthf /
   glDepthRangef). Function pointers were loaded but had no wrapper methods.

Root cause of invisible 3D cube: frame N 2D overlay sets DepthMask(false) →
frame N+1 depth clear silently masked → stale depth → cube fails depth test.

Confirmed by 3 parallel research agents + gg agent GL error trace.
#284)

UnmapBuffer guarded glBufferSubData with BufferUsageMapWrite check.
Per WebGPU spec, MappedAtCreation does NOT require MapWrite usage.
Buffers with Uniform|CopyDst + MappedAtCreation (standard g3d pattern)
had their shadow data silently discarded — zero MVP matrices, zero
vertices, zero indices → invisible 3D geometry.

Remove the MapWrite guard: if buf.mapped != nil && buf.id != 0,
always flush. Matches wgpu-core which calls queue.write_buffer on
unmap for non-MapWrite MappedAtCreation buffers.

Root cause of invisible 3D cube on GLES (g3d hello-cube, fullscreen-overlay).
@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@kolkov
kolkov merged commit d58070d into main Jul 30, 2026
15 checks passed
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.

bug(gles): depth/stencil not attached to swapchain FBO on surface render pass

1 participant