Skip to content

WebGL2 #394

@nkrisztian89

Description

@nkrisztian89

Grab a WebGL2 context if available

this.gl = this._canvas.getContext("webgl2", contextParameters);
if (this.gl) {
    this.isWebGL2 = true;
}

Instancing and depth textures extensions are part of WebGL2 core, so they don't need to be initialized (as well as sRGB textures if #202 is implemented and VAOs if #393 is)

areDepthTexturesAvailable() and isInstancingAvailable() should return true when using WebGL2.

For depth textures to work, the internalformat needs to be changed to e.g. DEPTH_COMPONENT16 (or another one with specific size):

context.gl.texImage2D(context.gl.TEXTURE_2D, 0, context.gl.DEPTH_COMPONENT16, this._width, this._height, 0, context.gl.DEPTH_COMPONENT, context.gl.UNSIGNED_SHORT, null);

For instancing, just use gl.drawArraysInstanced() and when using the extension with WebGL1, just set

this.gl.drawArraysInstanced = this.instancingExt.drawArraysInstancedANGLE;

For other useful things, see:
https://github.com/shrekshao/MoveWebGL1EngineToWebGL2/blob/master/Move-a-WebGL-1-Engine-To-WebGL-2-Blog-1.md
https://github.com/shrekshao/MoveWebGL1EngineToWebGL2/blob/master/Move-a-WebGL-1-Engine-To-WebGL-2-Blog-2.md
https://webgl2fundamentals.org/webgl/lessons/webgl1-to-webgl2.html

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions