Skip to content

Initial support for creating WebGL 2 contexts. #310

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

Merged
merged 1 commit into from
Apr 6, 2025

Conversation

null77
Copy link

@null77 null77 commented Jan 27, 2025

This support is very incomplete and only works for a bare minimum of functionality. It hasn't been tested against the WebGL 2 CTS. To create a WebGL 2 context, use the "createWebGL2Context" attribute in the creation options struct.

Implementation notes:

  • in native code, we use a single native class for both context types
  • we assign enum constants dynamically, so we replace gl.ENUM with this.ENUM in the context helper functions
  • only adds VAOs from the set of new WebGL 2 object types

This contribution is funded by https://higharc.com/

@dhritzkiv we're currently using this branch in our headless testing, and I can verify it works for the subset of functionality we have in our CI. At the moment this is the last of the work I had planned, but we'll probably need to add more support as we extend our testing coverage. One of the major hurdles would be migrating the gl-conformance library to run on top of the most recent CTS, and adding WebGL 2 CTS support.

@dhritzkiv
Copy link
Member

Would you be able to rebase this PR on the latest?

@null77 null77 force-pushed the webgl2-prototype branch from 9fe7d9d to 31bde7c Compare March 12, 2025 04:25
@null77
Copy link
Author

null77 commented Mar 12, 2025

Would you be able to rebase this PR on the latest?

Done, looks like it's passing.

Copy link
Member

@dhritzkiv dhritzkiv left a comment

Choose a reason for hiding this comment

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

Did an initial code review pass. Looks good. Thanks again for this effort

@@ -2878,14 +2943,22 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
data[0] = value[0]
return super.vertexAttrib4f(index | 0, +value[0], +value[1], +value[2], +value[3])
}

_isWebGL2 () {
Copy link
Member

Choose a reason for hiding this comment

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

Note to self: this is a good candidate for a getter

Copy link
Author

Choose a reason for hiding this comment

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

Do getters behave like normal functions in every other way? I wasn't sure if the other code that inherits properties and functions would be affected.

@@ -776,6 +836,15 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
return webGlTexture
}

createVertexArray () {
// TODO: do not expose VAO methods in WebGL 1
Copy link
Member

Choose a reason for hiding this comment

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

To resolve this TODO, should these method be declared only on WebGL2RenderingContext?

Or will it be tricky for devs to deal with the return type of createContext and having to check if the context is a WebGL2RenderingContext

Copy link
Author

Choose a reason for hiding this comment

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

I'm not entirely sure about this. I tried a variety of approaches for implementing the context types, and ended up with this approach because it works with the CTS and three.js. The first step would be to update the CTS integration to use the latest version, as mentioned in the other review.

@dhritzkiv
Copy link
Member

TODO for myself: update README with experimental WebGL 2 support section

This was linked to issues Mar 13, 2025
@null77 null77 force-pushed the webgl2-prototype branch from 31bde7c to 5796d1a Compare April 4, 2025 14:17
@null77
Copy link
Author

null77 commented Apr 4, 2025

@dhritzkiv I updated the code with fixed that you suggested, let me know of any need for further changes. (Sorry for the delayed response).

This support is very incomplete and only works for a bare minimum of
functionality. It hasn't been tested against the WebGL 2 CTS. To create
a WebGL 2 context, use the "createWebGL2Context" attribute in the
creation options struct.

Implementation notes:
 - in native code, we use a single native class for both context types
 - we assign enum constants dynamically, so we replace gl.ENUM with
   this.ENUM in the context helper functions
 - only adds VAOs from the set of new WebGL 2 object types

This contribution is funded by https://higharc.com/
@null77 null77 force-pushed the webgl2-prototype branch from 5796d1a to 61f02ce Compare April 4, 2025 14:19
@dhritzkiv dhritzkiv merged commit a35eeba into stackgl:master Apr 6, 2025
4 checks passed
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.

Supported open gl versions plans for webgl 2 support?
2 participants