| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
This is a part of Node3D project.
npm install @node-3d/webglTL;DR: For a quick start, use @node-3d/core or look at Examples.
import { webgl } from '@node-3d/webgl';Here webgl contains the WebGL/OpenGL API, like a WebGLRenderingContext instance would.
The main export is a singleton object shaped like a WebGL rendering context. It includes:
Important helpers:
The classes namespace exports the wrapper classes used by webgl. Most applications do not instantiate them directly, except when wrapping an existing native OpenGL resource ID.
To use browser WebGL libs, like three.js, several additional interfaces must also be provided to mimic the browser.
See this example using both GLFW and Image. The main idea being as follows:
import { Image } from '@node-3d/image';
import { webgl } from '@node-3d/webgl';
import { glfw } from '@node-3d/glfw';
const { Document } = glfw;
Document.setImage(image); // plug Image impl into the Document
Document.setWebgl(webgl); // plug WebGL impl into the Document
const doc = new Document({ width: 1600, height: 900, vsync: true });
...Similarly, these modules are utilized in @node-3d/core. Using @node-3d/core, you can skip setting up most environment features for those libs.
Examples that use @node-3d/image, @node-3d/glfw, or other Node3D packages should declare those dependencies where normal install flow provides them. The examples are checked as consumer-style code and should not be hidden from lint because dependencies are missing.
This is real native OpenGL, not ANGLE or anything else. You have direct access to GL resource IDs. Due to WebGL convention, resource IDs are wrapped in objects, such as WebGLBuffer. All of them contain raw IDs as obj._ - the _ property. You can also create such objects based on OpenGL IDs that are obtained elsewhere (e.g. from other separate C++ addons).
The JS API mostly maps the native OpenGL function calls. E.g.:
// gl.clear(target)
DBG_EXPORT JS_METHOD(clear) { NAPI_ENV;
REQ_INT32_ARG(0, target);
glClear(target);
RET_WEBGL_VOID;
}You can optionally call webgl.init() after the GL context becomes available - this translates into a glewInit() call. See GLEW docs for what it does and if you need it (probably "yes"?).
Some features may depend on OpenGL profile being used. Core profile is necessary for VAO and other OpenGL 3.2+ features. Depending on your windowing backend, set the OpenGL profile of your preference. In case @node-3d/glfw is used, the profile can be set through the Window/Document constructor or with glfw.windowHint calls.
Apple's OpenGL API is deprecated, so macOS builds can emit OpenGL deprecation warnings. Native sources define GL_SILENCE_DEPRECATION where needed to keep expected warnings from obscuring real build failures.
Release archives are built by this repository's public GitHub Actions workflows.
Attestations: https://github.com/node-3d/webgl/attestations
To verify a downloaded archive:
gh release download <tag> -R node-3d/webgl -p <platform>.gz
gh attestation verify <platform>.gz -R node-3d/webglThis addon is ABI-compatible across Node.js versions. There is no compilation during npm install.
| Back | FazBrowse Home | New Git URL |