Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 17, 2025

gl.getParameter(gl.UNIFORM_BUFFER_OFFSET_ALIGNMENT) returns undefined instead of the platform-specific alignment value (typically 256/512/1024). This breaks WebGL2 conformance tests and libraries using uniform buffer objects.

Changes

Backend (renderer)

  • Query GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT via glGetIntegerv() during WebGL2 context initialization
  • Pass value to client through WebGL2ContextInitCommandBufferResponse

Client (context)

  • Store alignment value in WebGL2Context::uniformBufferOffsetAlignment
  • Add kUniformBufferOffsetAlignment to WebGL2IntegerParameterName enum
  • Return stored value in getParameterV2() when requested

The constant was already exported to JavaScript bindings; only the query/storage path was missing.

Example Usage

const gl = canvas.getContext('webgl2');
const alignment = gl.getParameter(gl.UNIFORM_BUFFER_OFFSET_ALIGNMENT);
// Before: undefined
// After:  256 (or platform-specific value)

// Use for uniform buffer alignment
const offset = Math.ceil(size / alignment) * alignment;
Original prompt

This section details on the original issue you should resolve

<issue_title>WebGL2: gl.getParameter(gl.UNIFORM_BUFFER_OFFSET_ALIGNMENT) returns undefined instead of expected alignment value</issue_title>
<issue_description>## Background
When running the following test in JSAR Runtime (from Khronos or EndlessJour9527/WebGL's conformance suite):

var offset = gl.getParameter(gl.UNIFORM_BUFFER_OFFSET_ALIGNMENT);
// offset is expected to be a non-zero number, e.g. 256
// instead, JSAR returns 'undefined'.

This causes failures in conformance tests such as:

  • conformance-suites/2.0.0/conformance2/buffers/bound-buffer-size-change-test.html
  • Any test or library code requiring uniform buffer alignment (Three.js, Babylon.js, etc.)

Expected Behavior

According to WebGL 2.0 Spec §5.14.4 getParameter, and browser implementations (see Chromium/WebKit/Gecko), gl.getParameter(gl.UNIFORM_BUFFER_OFFSET_ALIGNMENT) must return the minimum required alignment for uniform buffer offsets. Typical values are 256, 512, or 1024 depending on platform and GL driver.

References:

Root Cause

  • The JSAR binding or backend does not implement the correct mapping for UNIFORM_BUFFER_OFFSET_ALIGNMENT, so getParameter returns undefined.
  • Native backend (C/C++) code likely missing or incorrectly implements querying the GL constant GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT via glGetIntegerv.
  • The value must be queried from GL on context init and exposed to JS correctly.

Acceptance Criteria

  • gl.getParameter(gl.UNIFORM_BUFFER_OFFSET_ALIGNMENT) returns a correct, non-zero integer value as per the platform/driver
  • Affects WebGL2 contexts only
  • Conformance tests using uniform buffer alignment (see above) pass

Implementation Guidance (C++)

  • Bind the constant UNIFORM_BUFFER_OFFSET_ALIGNMENT in JS
  • In native code:
// On WebGL2 context creation:
GLint alignment = 0;
glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &alignment);
// Store alignment value in context
// On getParameter call:
if (pname == GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT) {
    return JS::Number(alignment);
}
  • Test output for getParameter

Relevant locations to update

  • src/client/builtin_scene/webgl_rendering_context.cpp

Supporting this constant is required for WebGL2 native uniform buffer API compatibility and test suite coverage.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: EndlessJour9527 <155411404+EndlessJour9527@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix gl.getParameter returning undefined for UNIFORM_BUFFER_OFFSET_ALIGNMENT WebGL2: Implement gl.getParameter(gl.UNIFORM_BUFFER_OFFSET_ALIGNMENT) Nov 17, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements support for gl.getParameter(gl.UNIFORM_BUFFER_OFFSET_ALIGNMENT) in WebGL2 contexts, fixing a conformance issue where the method previously returned undefined instead of the platform-specific alignment value.

  • Queries the GL implementation for GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT during context initialization
  • Stores and returns the value through the existing parameter query infrastructure
  • Follows the established pattern used by other WebGL2 context parameters

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/renderer/render_api_opengles.cpp Added glGetIntegerv query for GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT during WebGL2 context initialization
src/common/command_buffers/details/webgl_context_init.hpp Added uniformBufferOffsetAlignment field to copy constructor and response structure
src/client/graphics/webgl_context.hpp Added enum entry kUniformBufferOffsetAlignment and member variable declaration
src/client/graphics/webgl_context.cpp Added initialization from response and return logic in getParameterV2()
src/client/script_bindings/webgl/webgl_rendering_context.cpp Added case handler for WEBGL2_UNIFORM_BUFFER_OFFSET_ALIGNMENT in parameter retrieval

@yorkie yorkie merged commit 95ec3da into main Nov 21, 2025
10 checks passed
@yorkie yorkie deleted the copilot/fix-getparameter-undefined branch November 21, 2025 06:43
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.

WebGL2: gl.getParameter(gl.UNIFORM_BUFFER_OFFSET_ALIGNMENT) returns undefined instead of expected alignment value

3 participants