Skip to content

Fix in-game visual corruption and 640x480 resolution on iPhone - #20

Merged
matthewcodergamer merged 1 commit into
masterfrom
render360/iphone-baseline-lowmem
Oct 10, 2026
Merged

matthewcodergamer merged 1 commit into
masterfrom
render360/iphone-baseline-lowmem

Conversation

@matthewcodergamer

Copy link
Copy Markdown
Owner

What was wrong

In-game, the world rendered blown-out white with cyan/green noise, and props had garbage green/blue colors. WebGL can't map GPU buffers. Emscripten's emulation returns fresh, uninitialized memory on every map and uploads all of it on unmap, which broke three engine paths:

  • Lightmaps (world): lightmap pages are dynamic textures that stream through a mapped pixel buffer. Each re-lock of a page re-uploaded the whole page from garbage memory, wiping the surfaces written before it. On web, dynamic textures now keep a persistent, zero-initialized CPU backing store and upload only the locked region.
  • Static vertex/index buffers: bytes the engine didn't rewrite during a lock became garbage. On web the locked range is now staged in CPU memory that holds the buffer's current contents (read back with glGetBufferSubData only when D3D semantics require it) and uploaded on unlock.
  • Static prop lighting: prop color meshes shared one pooled vertex buffer that is locked for N vertices and then written past that range. Pooling is off on web, so each prop gets its own color mesh.

Also fixed

  • DXT decoding of tiny mips (2×2, 1×1) used the wrong row stride, and 2×2 DXT5 levels were mistaken for uncompressed data. This made distant surfaces sparkle.
  • -w/-h was clamped to a fixed 640×480 "display mode" in the browser, so the game still rendered stretched 4:3. The requested size is now kept.

Verification

  • em++ -fsyntax-only (Emscripten 4.0.9) on every touched file passes. I confirmed the check catches errors by injecting a deliberate typo.
  • Not tested on a device. It needs an on-phone check after the Pages deploy.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Qy5DKdwTqGQqScWvJyNcft


Generated by Claude Code

…n web

WebGL can't map GPU buffers. Emscripten's emulation hands back fresh,
uninitialized malloc memory on every map and uploads all of it on unmap,
which broke three paths in the browser:

- Lightmap pages are dynamic textures that stream through a mapped pixel
  buffer. Every re-lock of a page re-uploaded the whole page from garbage,
  wiping the surfaces written earlier: the world rendered blown-out white
  with cyan/green noise. On web, dynamic textures now keep a persistent CPU
  backing store (zero-initialized) and upload only the locked region.
- Static vertex/index buffer locks got uninitialized memory, so any bytes
  the engine didn't rewrite became garbage. On web the locked range is
  staged in CPU memory holding the buffer's current contents (read back
  with glGetBufferSubData when needed) and uploaded on unlock.
- Static prop color meshes shared one pooled vertex buffer that is locked
  for N vertices and then written past that range. Pooling is off on web,
  so every prop gets its own color mesh (green/cyan garbage on props).

Also:
- DXT decoding for tiny mips (2x2, 1x1) used the real width as the row
  stride and mistook 2x2 DXT5 for uncompressed data; decode into whole
  blocks and upload with the padded row length.
- The requested -w/-h was clamped to a fixed 640x480 "display mode" in
  the browser, so the game still ran stretched 4:3. Keep the requested size.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qy5DKdwTqGQqScWvJyNcft
@matthewcodergamer
matthewcodergamer merged commit 46e5b10 into master Oct 10, 2026
4 checks passed

This branch was successfully deployed

1 active deployment
portal-iphone-staging — 9445fb43 Deployed Oct 10, 2026 by matthewcodergamer via Deploy iPhone staging page #320
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.

2 participants