Skip to content

WebGL2: gl.getAttribLocation for built-in attribute 'gl_VertexID' returns incorrect value (should be -1, got 0) #411

Description

@EndlessJour9527

Bug Description

Running Khronos/WebGL2 conformance test (active-built-in-attribs.html) in JSAR Runtime:

shouldBe('activeInfo.name', '"gl_VertexID"');
attribLoc = gl.getAttribLocation(prog, 'gl_VertexID');
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be able to request the location of a built-in.");
shouldBe('attribLoc', '-1');

Test fails: attribLoc should be -1. Was 0.

Spec Reference

Root Cause

  • JSAR currently returns 0 for built-in attribute names instead of -1, violating spec compliance.
  • Correct behavior: gl.getAttribLocation(program, 'gl_VertexID') MUST return -1, never a valid location.

Acceptance Criteria

  • getAttribLocation on any built-in attribute ('gl_VertexID', 'gl_InstanceID', 'gl_Position', 'gl_PointSize') MUST always return -1
  • The referenced conformance test passes

Implementation Guidance (C++)

  • Fix the attribute location query in WebGLRenderingContext/WebGL2RenderingContext
  • Check if the attribute name matches any of the built-in names, and always return -1
int WebGLRenderingContext::getAttribLocation(WebGLProgram* program, const std::string& name) {
    static const std::set<std::string> kBuiltInAttribs = {
        "gl_VertexID", "gl_InstanceID", "gl_Position", "gl_PointSize"
    };
    if (kBuiltInAttribs.count(name)) {
        return -1;
    }
    // ... normal lookup logic
}
  • Update error handling and unit tests for built-in attribute query

Impact

  • Strict compliance with WebGL2 specification
  • Enables all Khronos/WebGL2 tests for built-in attrib queries to pass

Relevant test HTML:

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Fields

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions