Fix getAttribLocation to return -1 for built-in attributes per WebGL 2.0 spec#412
Fix getAttribLocation to return -1 for built-in attributes per WebGL 2.0 spec#412
Conversation
- Add check for built-in attribute names (gl_VertexID, gl_InstanceID, gl_Position, gl_PointSize) - Return -1 immediately for built-in attributes per WebGL 2.0 spec §5.18 - Add <set> include for std::set container - Complies with WebGL 2.0 specification requirement Co-authored-by: EndlessJour9527 <155411404+EndlessJour9527@users.noreply.github.com>
| // WebGL 2.0 spec §5.18: Built-in attributes always return -1 | ||
| static const std::set<string> kBuiltInAttribs = { | ||
| "gl_VertexID", "gl_InstanceID", "gl_Position", "gl_PointSize"}; | ||
| if (kBuiltInAttribs.count(name)) | ||
| { | ||
| info.GetReturnValue().Set(Number::New(isolate, -1)); | ||
| return; | ||
| } | ||
|
|
There was a problem hiding this comment.
Done! Moved the implementation to client/graphics/webgl_context.cpp in commit c135954. The built-in attribute check now happens at the graphics layer in WebGLContext::getAttribLocation(), which returns nullopt for built-in attributes. The script bindings layer correctly converts this to -1.
- Moved implementation from script bindings to WebGLContext::getAttribLocation - Returns nullopt for built-in attributes (gl_VertexID, gl_InstanceID, gl_Position, gl_PointSize) - Script bindings layer now correctly converts nullopt to -1 - Better architecture: centralizes logic at the graphics layer Addresses review feedback from @EndlessJour9527 Co-authored-by: EndlessJour9527 <155411404+EndlessJour9527@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR fixes WebGL 2.0 spec compliance for getAttribLocation() to correctly return -1 for built-in attributes (gl_VertexID, gl_InstanceID, gl_Position, gl_PointSize) instead of incorrectly returning 0. This resolves Khronos WebGL 2.0 conformance test failures.
Key Changes
- Added early return check in
WebGLContext::getAttribLocation()to detect built-in attribute names and returnnullopt(which the script bindings layer converts to-1) - Applied consistent C++ code formatting across multiple WebGL script binding files (removing extra spaces in closing namespace comments)
- Updated package-lock.json registry URLs from npmmirror.com to npmjs.org
Reviewed Changes
Copilot reviewed 1 out of 18 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/client/graphics/webgl_context.cpp | Added built-in attribute check with early return in getAttribLocation(), plus <set> include |
| src/client/script_bindings/webgl/*.{hpp,cpp} | Formatting fix: standardized namespace closing comment spacing |
| package-lock.json | Changed registry URLs from npmmirror.com to npmjs.org for all packages |
- Reverted registry URL changes from npmjs.org back to npmmirror.com - File restored to state before initial fix commit Addresses review feedback from @EndlessJour9527 Co-authored-by: EndlessJour9527 <155411404+EndlessJour9527@users.noreply.github.com>
|
@copilot 在 fixtures/html/webgl-conformance/ 下新增一个简化版测试页,例如: webgl2-getattriblocation-builtin-attribs.html js const fs = gl.createShader(gl.FRAGMENT_SHADER); const prog = gl.createProgram(); console.log(gl.getAttribLocation(prog, "gl_VertexID")); // expect -1 |
- Created webgl2-getattriblocation-builtin-attribs.html test file - Tests that getAttribLocation returns -1 for gl_VertexID, gl_InstanceID, gl_Position, gl_PointSize - Includes visual pass/fail indicators and console logging - Follows existing test file structure in fixtures/html/webgl-conformance/ Addresses request from @EndlessJour9527 Co-authored-by: EndlessJour9527 <155411404+EndlessJour9527@users.noreply.github.com>
Done! Created the test file |
Fix WebGL2 getAttribLocation for built-in attributes
Implementing fix for issue where
gl.getAttribLocationreturns incorrect value (0 instead of -1) for built-in attributes likegl_VertexID,gl_InstanceID,gl_Position, andgl_PointSize.Progress:
Changes Made:
Modified:
/home/runner/work/jsar-runtime/jsar-runtime/src/client/graphics/webgl_context.cpp<set>include for std::set containerWebGLContext::getAttribLocation():Added:
fixtures/html/webgl-conformance/webgl2-getattriblocation-builtin-attribs.htmlRestored: package-lock.json - Reverted to original state (no registry URL changes)
Validation:
Architecture Benefits:
Specification Reference:
WebGL 2.0 spec §5.18:
Impact:
✅ Strict compliance with WebGL2 specification
✅ Enables Khronos/WebGL2 conformance test
active-built-in-attribs.htmlto pass✅ Minimal surgical change at correct architectural layer
✅ Test file available for manual verification
✅ No breaking changes to existing functionality
Fixes WebGL2: gl.getAttribLocation for built-in attribute 'gl_VertexID' returns incorrect value (should be -1, got 0) #411
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.