-
Notifications
You must be signed in to change notification settings - Fork 3
Fix WebGL2 getParameter() returning undefined for binding parameters #422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6b2b143
bc244e5
9fe79ac
5de9983
b864ea9
a0c62e9
bc47659
d5f4498
8770dbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>WebGL getParameter Binding Test</title> | ||
| <style> | ||
| body { font-family: Arial, sans-serif; margin: 20px; } | ||
| .pass { color: green; } | ||
| .fail { color: red; } | ||
| pre { background: #f5f5f5; padding: 10px; border-radius: 4px; } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <h1>WebGL getParameter Binding Test</h1> | ||
| <p>This test verifies that context.getParameter() returns null (not undefined) for binding parameters.</p> | ||
| <div id="results"></div> | ||
| <script> | ||
| const results = document.getElementById('results'); | ||
|
|
||
| function log(message, isPass) { | ||
| const div = document.createElement('div'); | ||
| div.className = isPass ? 'pass' : 'fail'; | ||
| div.textContent = (isPass ? '✓ ' : '✗ ') + message; | ||
| results.appendChild(div); | ||
| } | ||
|
|
||
| function testParameter(gl, paramName, paramValue) { | ||
| const result = gl.getParameter(paramValue); | ||
| const isNull = result === null; | ||
| const isUndefined = result === undefined; | ||
|
|
||
| if (isNull) { | ||
| log(`${paramName}: correctly returns null`, true); | ||
| return true; | ||
| } else if (isUndefined) { | ||
| log(`${paramName}: INCORRECTLY returns undefined (should be null)`, false); | ||
| return false; | ||
| } else { | ||
| log(`${paramName}: returns ${result} (expected null or object)`, true); | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| // Create WebGL2 context | ||
| const canvas2 = document.createElement('canvas'); | ||
| const gl2 = navigator.gl || canvas2.getContext('webgl2'); | ||
|
|
||
| if (gl2) { | ||
| results.innerHTML += '<h2>WebGL 2.0 Binding Parameters</h2>'; | ||
| testParameter(gl2, 'COPY_READ_BUFFER_BINDING', gl2.COPY_READ_BUFFER_BINDING); | ||
| testParameter(gl2, 'COPY_WRITE_BUFFER_BINDING', gl2.COPY_WRITE_BUFFER_BINDING); | ||
| testParameter(gl2, 'DRAW_FRAMEBUFFER_BINDING', gl2.DRAW_FRAMEBUFFER_BINDING); | ||
| testParameter(gl2, 'READ_FRAMEBUFFER_BINDING', gl2.READ_FRAMEBUFFER_BINDING); | ||
| testParameter(gl2, 'PIXEL_PACK_BUFFER_BINDING', gl2.PIXEL_PACK_BUFFER_BINDING); | ||
| testParameter(gl2, 'PIXEL_UNPACK_BUFFER_BINDING', gl2.PIXEL_UNPACK_BUFFER_BINDING); | ||
| testParameter(gl2, 'UNIFORM_BUFFER_BINDING', gl2.UNIFORM_BUFFER_BINDING); | ||
| testParameter(gl2, 'VERTEX_ARRAY_BINDING', gl2.VERTEX_ARRAY_BINDING); | ||
| testParameter(gl2, 'SAMPLER_BINDING', gl2.SAMPLER_BINDING); | ||
| testParameter(gl2, 'TRANSFORM_FEEDBACK_BINDING', gl2.TRANSFORM_FEEDBACK_BINDING); | ||
| testParameter(gl2, 'TRANSFORM_FEEDBACK_BUFFER_BINDING', gl2.TRANSFORM_FEEDBACK_BUFFER_BINDING); | ||
| testParameter(gl2, 'TEXTURE_BINDING_2D_ARRAY', gl2.TEXTURE_BINDING_2D_ARRAY); | ||
| testParameter(gl2, 'TEXTURE_BINDING_3D', gl2.TEXTURE_BINDING_3D); | ||
| } else { | ||
| log('WebGL 2.0 not supported', false); | ||
| } | ||
| </script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -219,6 +219,41 @@ namespace endor | |||||||||||||||
| kExtMaxViewsOvr = WEBGL2_EXT_MAX_VIEWS_OVR, | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| /** | ||||||||||||||||
| * Enum for buffer/object binding parameters that return WebGL objects. | ||||||||||||||||
| */ | ||||||||||||||||
| enum class WebGLBufferBindingParameterName | ||||||||||||||||
| { | ||||||||||||||||
| kArrayBufferBinding = WEBGL_ARRAY_BUFFER_BINDING, | ||||||||||||||||
| kElementArrayBufferBinding = WEBGL_ELEMENT_ARRAY_BUFFER_BINDING, | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| enum class WebGLObjectBindingParameterName | ||||||||||||||||
| { | ||||||||||||||||
| kCurrentProgram = WEBGL_CURRENT_PROGRAM, | ||||||||||||||||
| kFramebufferBinding = WEBGL_FRAMEBUFFER_BINDING, | ||||||||||||||||
| kRenderbufferBinding = WEBGL_RENDERBUFFER_BINDING, | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| enum class WebGL2BufferBindingParameterName | ||||||||||||||||
| { | ||||||||||||||||
| kCopyReadBufferBinding = WEBGL2_COPY_READ_BUFFER_BINDING, | ||||||||||||||||
| kCopyWriteBufferBinding = WEBGL2_COPY_WRITE_BUFFER_BINDING, | ||||||||||||||||
| kPixelPackBufferBinding = WEBGL2_PIXEL_PACK_BUFFER_BINDING, | ||||||||||||||||
| kPixelUnpackBufferBinding = WEBGL2_PIXEL_UNPACK_BUFFER_BINDING, | ||||||||||||||||
| kTransformFeedbackBufferBinding = WEBGL2_TRANSFORM_FEEDBACK_BUFFER_BINDING, | ||||||||||||||||
| kUniformBufferBinding = WEBGL2_UNIFORM_BUFFER_BINDING, | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| enum class WebGL2ObjectBindingParameterName | ||||||||||||||||
| { | ||||||||||||||||
| kDrawFramebufferBinding = WEBGL2_DRAW_FRAMEBUFFER_BINDING, | ||||||||||||||||
| kReadFramebufferBinding = WEBGL2_READ_FRAMEBUFFER_BINDING, | ||||||||||||||||
| kVertexArrayBinding = WEBGL2_VERTEX_ARRAY_BINDING, | ||||||||||||||||
| kSamplerBinding = WEBGL2_SAMPLER_BINDING, | ||||||||||||||||
| kTransformFeedbackBinding = WEBGL2_TRANSFORM_FEEDBACK_BINDING, | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| class ContextAttributes final | ||||||||||||||||
| { | ||||||||||||||||
| public: | ||||||||||||||||
|
|
@@ -464,6 +499,10 @@ namespace endor | |||||||||||||||
| bool getParameter(WebGLBooleanIndexedParameterName pname, int index); | ||||||||||||||||
| float getParameter(WebGLFloatArrayParameterName pname, int index); | ||||||||||||||||
| std::string getParameter(WebGLStringParameterName pname); | ||||||||||||||||
| std::shared_ptr<WebGLBuffer> getParameter(WebGLBufferBindingParameterName pname); | ||||||||||||||||
| std::shared_ptr<WebGLProgram> getParameterProgram(WebGLObjectBindingParameterName pname); | ||||||||||||||||
| std::shared_ptr<WebGLFramebuffer> getParameterFramebuffer(WebGLObjectBindingParameterName pname); | ||||||||||||||||
| std::shared_ptr<WebGLRenderbuffer> getParameterRenderbuffer(WebGLObjectBindingParameterName pname); | ||||||||||||||||
| WebGLShaderPrecisionFormat getShaderPrecisionFormat(int shadertype, int precisiontype); | ||||||||||||||||
| int getError(); | ||||||||||||||||
| std::vector<std::string> &getSupportedExtensions(); | ||||||||||||||||
|
|
@@ -728,7 +767,8 @@ namespace endor | |||||||||||||||
| /** | ||||||||||||||||
| * @returns the client state of the WebGL context. | ||||||||||||||||
| */ | ||||||||||||||||
|
||||||||||||||||
| */ | |
| */ | |
| // Non-const accessor | |
| WebGLState &clientState() | |
| { | |
| return clientState_; | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The switch statement lists all enum cases but includes a 'default' case that does the same thing as all listed cases. This pattern is confusing and makes it unclear if this is intentional (all return nullptr) or incomplete. Either remove the 'default' label and just have a single 'return nullptr;' after all cases, or explicitly document that these bindings are not yet implemented.