Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 18, 2025

WebGL2 applications calling gl.transformFeedbackVaryings() fail with "Not implemented" error, breaking conformance tests and libraries (Three.js, Babylon.js) that use transform feedback for GPU computation and particle systems.

Changes

Command buffer infrastructure (src/common/command_buffers/)

  • Added TRANSFORM_FEEDBACK_VARYINGS command type
  • Created TransformFeedbackVaryingsCommandBufferRequest with string array serialization

Client implementation (src/client/graphics/)

  • Added WebGL2Context::transformFeedbackVaryings() dispatcher
  • Validates program and sends command buffer request

JavaScript binding (src/client/script_bindings/webgl/)

  • Implemented WebGL2RenderingContext::TransformFeedbackVaryings()
  • Validates 3 required arguments (WebGLProgram, string[], GLenum)
  • Extracts varying names from JS array

Renderer handler (src/renderer/)

  • Implemented OnTransformFeedbackVaryings()
  • Converts C++ string vector to C-style char** array
  • Calls glTransformFeedbackVaryings() with proper error checking

Usage

const program = gl.createProgram();
// ... attach and link shaders ...

gl.transformFeedbackVaryings(
  program, 
  ['gl_Position', 'vColor'], 
  gl.INTERLEAVED_ATTRIBS
);

Conforms to WebGL 2.0 §5.19.3.

Original prompt

This section details on the original issue you should resolve

<issue_title>WebGL2: transformFeedbackVaryings API not implemented, breaks conformance and library support</issue_title>
<issue_description>## Background
When running WebGL2 code or Khronos conformance tests in JSAR Runtime, the following error is encountered:

Uncaught Error: Failed to execute 'transformFeedbackVaryings' on 'WebGL2RenderingContext': Not implemented

This occurs when JS/WebGL2 code calls the API:

gl.transformFeedbackVaryings(program, ['gl_Position'], gl.INTERLEAVED_ATTRIBS);

Impact

  • Standard conformance tests requiring transform feedback fail to run in JSAR
  • Popular libraries that use transform feedback (e.g., Three.js advanced rendering patterns, Babylon.js particle systems, GPU-based computation, etc.) fail or degrade
  • Both classic and XR spatial apps depending on this API are blocked

Web Standard Reference

Root Cause

  • The native C++ binding for WebGL2RenderingContext.transformFeedbackVaryings is missing or stubbed as "not implemented" in JSAR
  • No logic dispatching from JS layer to the actual OpenGL call (glTransformFeedbackVaryings)

Acceptance Criteria

  • Calling gl.transformFeedbackVaryings in JSAR WebGL2 context correctly dispatches to native and configures transform feedback as per spec
  • Conformance tests referencing this API pass
  • Popular libraries relying on transform feedback work (Three.js, Babylon.js examples)

Implementation Guidance (C++)

  • Add JS binding for transformFeedbackVaryings in WebGL2RenderingContext
  • Dispatch to corresponding OpenGL API:
void WebGL2RenderingContext::transformFeedbackVaryings(WebGLProgram* program, const std::vector<std::string>& varyings, GLenum bufferMode) {
    // Convert string array to C array
    std::vector<const char*> c_varyings;
    for (const auto& v : varyings) {
        c_varyings.push_back(v.c_str());
    }
    glTransformFeedbackVaryings(program->glObject(), c_varyings.size(), c_varyings.data(), bufferMode);
}
  • Update JS-to-native binding so the method is available on WebGL2RenderingContext
  • Fails gracefully (throws per spec) if invoked on invalid program object

Relevant code location to update:

  • src/client/builtin_scene/webgl_rendering_context.cpp

Supporting this API is required for WebGL2 spec conformance and ecosystem compatibility.</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.

Copilot AI self-assigned this Nov 18, 2025
Copilot AI and others added 2 commits November 18, 2025 03:23
- Add TRANSFORM_FEEDBACK_VARYINGS command buffer request type
- Implement TransformFeedbackVaryingsCommandBufferRequest structure
- Add transformFeedbackVaryings method to WebGL2Context class
- Update JavaScript binding to properly parse arguments and call native method
- All C++ code formatted with clang-format

Co-authored-by: EndlessJour9527 <155411404+EndlessJour9527@users.noreply.github.com>
- Implement OnTransformFeedbackVaryings handler in render_api_opengles.cpp
- Convert C++ string vector to C-style char* array for glTransformFeedbackVaryings
- Register handler with command buffer dispatcher
- Full end-to-end implementation from JavaScript to OpenGL now complete

Co-authored-by: EndlessJour9527 <155411404+EndlessJour9527@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement WebGL2 transformFeedbackVaryings API Implement WebGL2 transformFeedbackVaryings API Nov 18, 2025
Copilot finished work on behalf of EndlessJour9527 November 18, 2025 03:29
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: transformFeedbackVaryings API not implemented, breaks conformance and library support

2 participants