webgl2

WebGL 2 externs
https://github.com/ibilon/webgl2/

To install, run:

haxelib install webgl2 1.2.0 

See using Haxelib in Haxelib documentation for more information.

README.md

WebGL2

Build Status Issue Count

Haxe WebGL 1 and 2 externs.

Requires Haxe 3.4.0 or above, compatible with Haxe 4.

How to get context

using js.webgl2.CanvasHelpers;

var gl1 = canvas.getWebGL();
var gl2 = canvas.getWebGL2();

Do not use getContextWebGL which will return you the haxe std externs instead of this.

Usage

gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);
gl.clearColor(0.9, 0.2, 0.1, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);

You use the constants directly on the gl object like in js, unlike in the haxe std externs.

Differences with raw js webgl

Constants in RenderingContext and RenderingContext2 don't have the Int type, but a more restrictive type from js.webgl2.constants.* to prevent at compile time most of the INVALID_ENUM errors. Since it can't be known at compile time if the context will actually be WebGL 1 the RenderingContext functions also accept the added value for the WebGL 2 context.

Some functions have type safe helpers when the return type depends on a parameter value, if possible. For instance: gl.getBufferParameter(target, gl.BUFFER_SIZE) : Any => gl.getBufferSize(target) : Int gl.getBufferParameter(target, gl.BUFFER_USAGE) : Any => gl.getBufferUsage(target) : BufferUsageEnum * getActiveUniforms(program, uniformIndices, pname) : Any => gl.getActiveUniformsInteger(program:Program, uniformIndices, pname) : Array<Int>

These can be used by adding a using js.webgl2.ContextHelpers;.

You can add the define -D webgl2_no_unsafe to hide the unsafe raw externs and prevent their (mis)use.

License

The code is released under the MIT license, see LICENSE.md.

The documentation is licensed under CC-BY-SA 2.5 by Mozilla Contributors.

The WebGL 2 API is by Khronos https://www.khronos.org/registry/webgl/specs/latest/2.0/.

Contributors
_ibilon
Version
1.2.0
Published
5 years ago
License
MIT

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub