fix(gl): derive the GL index type from sizeof(ofIndexType) in indexed draws - #8526
Open
smeyfroi wants to merge 1 commit into
Open
fix(gl): derive the GL index type from sizeof(ofIndexType) in indexed draws#8526smeyfroi wants to merge 1 commit into
smeyfroi wants to merge 1 commit into
Conversation
… draws ofIndexType is tess2's TESSindex, and tesselator.h picks unsigned short whenever TARGET_OS_IPHONE is defined() — TargetConditionals.h defines it (as 0) on every Apple platform, so macOS builds get 16-bit indices when any Apple header precedes tesselator.h. The desktop branches of drawElements / drawElementsInstanced in both renderers hardcode GL_UNSIGNED_INT, so ofVbo uploads sizeof(ofIndexType)-sized indices and the draw reads twice as many bytes: out-of-range vertex fetches that render as garbage triangles or nothing at all, varying with GPU heap layout (non-deterministic across relinks and runs). Derive the type from sizeof(ofIndexType) at the five desktop call sites (the ES branches already match: every GLES platform lands in tess2's 16-bit branch). The ternary constant-folds; no runtime cost.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On current macOS nightlies (verified against of_v20260730, macOS 26 / Apple silicon), every indexed VBO draw silently reads the index buffer with the wrong GL type, and instanced indexed draws (
ofVbo::drawElementsInstanced) render garbage triangles or nothing at all, varying non-deterministically between launches and even between relinks of the same code.Cause
ofIndexTypeistypedef TESSindex ofIndexType(ofConstants.h), and the tess2 header shipped since apothecary #552 picks its width with#if defined(TARGET_OS_IPHONE) || …. Apple'sTargetConditionals.hdefines everyTARGET_OS_*macro on every Apple platform — as 1 or 0 — so on macOSTARGET_OS_IPHONEis defined as 0, thedefined()test is true, andTESSindex/ofIndexTypebecomesunsigned short. (Apothecary #558 later noticed Apple builds landing in the 16-bit branch, but guarded only the__arm__-family defines, which aren't defined on Apple arm64 — the actual trigger survived.)Meanwhile the desktop branches of
drawElements/drawElementsInstancedin both renderers hardcodeGL_UNSIGNED_INT.ofVbouploadssizeof(ofIndexType) × countbytes, so the draw reads 2× past the uploaded index buffer: the first indices are misparsed short-pairs (out of range of the mesh), the rest are whatever follows in GPU memory — out-of-range vertex fetches that render as giant garbage triangles or degenerate/invisible ones depending on heap layout. No GL error is raised.Fix
Derive the GL index type from the compiled index width at the five desktop call sites:
The ternary constant-folds, so there is no runtime cost, and the sites remain correct whatever width tess2 ends up giving
ofIndexType. The GLES branches are untouched: every GLES platform lands in tess2's 16-bit branch, so their hardcodedGL_UNSIGNED_SHORTalready matches.A companion apothecary PR fixes the root-cause condition in
tess2.patchitself: openframeworks/apothecary#561. Both fixes stand alone; this one keeps the renderers honest under either header, and the apothecary one also restores the full 32-bit index range for large meshes on macOS.Verification
GL_BUFFER_SIZE) drawn withGL_UNSIGNED_INTproduce garbage or missing geometry, flipping between relinks.GL_UNSIGNED_SHORT(0x1403), matching the uploads; the renderer output is correct and stable across relinks.ofIndexType) is unaffected by the patch: the ternary folds toGL_UNSIGNED_INTthere.