OpenGL ES
Cheerp provides a GLES2 implementation based on WebGL which is designed to jump-start porting an existing GLES application/game to the browser.
genericjs onlyLike all browser APIs, GLES is supported in genericjs code only.
Usage
The GLES2 API is declared in the GLES2/gl2.h
header file, while webGLES specific methods are declared in the GLES2/webgles.h
header. webGLES needs to be initialized using the following function
which accept as the only argument the name of an existing HTML5 canvas element which should already exists at the time of webGLES initialization. An example HTML tag for such canvas:
Raw WebGL access
webGLESInit
creates a globally accessible WebGL context, you are free to use such context and you can mix and match between GLES and WebGL APIs. The context object is called webGLES
and is accessible by including the GLES2/webgles.h
header. For example:
Helpers methods are available to convert GLES2 resources id to resource objects as used by WebGL:
Although webGLES implement the glTexImage2D
API to load texture data, we only intend it to be used for data which is generated at run-time, like procedurally generated textures. We strongly advise using the WebGL provided texImage2D
to load image data in JPEG or PNG format since the browser can decompress the images natively.
Passing data to WebGL uniform*
APIs
uniform*
APIs and, more in general, WebGL APIs which expect buffers require typed arrays of a suitable type.
If you have data stored in a C/C++ array or std::vector
or any other contiguous memory storage, you can use cheerp::MakeTypedArray
to convert the data into a JS typed array object. Please note that the conversion happens without copying, so itβs very efficient.