Skip to content
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

Add all common parameters to context definition and make gl.getParameter support. #66

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions binding/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static napi_value InitBinding(napi_env env, napi_value exports) {
WebGLDebugRendererInfoExtension::Register(env, exports);
WebGLDepthTextureExtension::Register(env, exports);
WebGLLoseContextExtension::Register(env, exports);
WebGLDrawBuffersExtension::Register(env, exports);
WebGLRenderingContext::Register(env, exports);

napi_property_descriptor properties[] = {
Expand Down
6 changes: 6 additions & 0 deletions binding/egl_context_wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,12 @@ void EGLContextWrapper::BindProcAddresses() {
// ANGLE specific
glRequestExtensionANGLE = reinterpret_cast<PFNGLREQUESTEXTENSIONANGLEPROC>(
eglGetProcAddress("glRequestExtensionANGLE"));

// GL ES
glGetFloatv =
reinterpret_cast<PFNGLGETFLOATVPROC>(eglGetProcAddress("glGetFloatv"));
glGetBooleanv = reinterpret_cast<PFNGLGETBOOLEANVPROC>(
eglGetProcAddress("glGetBooleanv"));
}

void EGLContextWrapper::RefreshGLExtensions() {
Expand Down
4 changes: 4 additions & 0 deletions binding/egl_context_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ class EGLContextWrapper {
// ANGLE specific
PFNGLREQUESTEXTENSIONANGLEPROC glRequestExtensionANGLE;

// GL ES
PFNGLGETFLOATVPROC glGetFloatv;
PFNGLGETBOOLEANVPROC glGetBooleanv;

// Refreshes extensions list:
void RefreshGLExtensions();

Expand Down
52 changes: 52 additions & 0 deletions binding/webgl_extensions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -936,4 +936,56 @@ napi_value WebGLLoseContextExtension::RestoreContext(napi_env env,
return nullptr;
}

//==============================================================================
// WebGLDrawBuffersExtension

napi_ref WebGLDrawBuffersExtension::constructor_ref_;

WebGLDrawBuffersExtension::WebGLDrawBuffersExtension(napi_env env)
: GLExtensionBase(env) {}

/* static */
bool WebGLDrawBuffersExtension::IsSupported(
EGLContextWrapper* egl_context_wrapper) {
IS_EXTENSION_NAME_AVAILABLE("GL_EXT_draw_buffers");
}

/* static */
napi_status WebGLDrawBuffersExtension::Register(napi_env env,
napi_value exports) {
napi_status nstatus;

napi_property_descriptor properties[] = {
NapiDefineIntProperty(env, GL_MAX_COLOR_ATTACHMENTS,
"MAX_COLOR_ATTACHMENTS_WEBGL"),
NapiDefineIntProperty(env, GL_MAX_DRAW_BUFFERS, "MAX_DRAW_BUFFERS_WEBGL"),
};

napi_value ctor_value;
nstatus = napi_define_class(env, "WEBGL_draw_buffers", NAPI_AUTO_LENGTH,
GLExtensionBase::InitStubClass, nullptr,
ARRAY_SIZE(properties), properties, &ctor_value);
ENSURE_NAPI_OK_RETVAL(env, nstatus, nstatus);

nstatus = napi_create_reference(env, ctor_value, 1, &constructor_ref_);
ENSURE_NAPI_OK_RETVAL(env, nstatus, nstatus);

return napi_ok;
}

/* static */
napi_status WebGLDrawBuffersExtension::NewInstance(
napi_env env, napi_value* instance,
EGLContextWrapper* egl_context_wrapper) {
ENSURE_EXTENSION_IS_SUPPORTED

napi_status nstatus = NewInstanceBase(env, constructor_ref_, instance);
ENSURE_NAPI_OK_RETVAL(env, nstatus, nstatus);

egl_context_wrapper->glRequestExtensionANGLE("GL_EXT_draw_buffers");
egl_context_wrapper->RefreshGLExtensions();

return napi_ok;
}

} // namespace nodejsgl
10 changes: 10 additions & 0 deletions binding/webgl_extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,16 @@ class WebGLLoseContextExtension : public GLExtensionBase {
static void Cleanup(napi_env env, void* native, void* hint);
};

// Provides 'WEBGL_draw_buffers':
// https://www.khronos.org/registry/webgl/extensions/WEBGL_draw_buffers/
class WebGLDrawBuffersExtension : public GLExtensionBase {
NAPI_BOOTSTRAP_METHODS

protected:
WebGLDrawBuffersExtension(napi_env env);
virtual ~WebGLDrawBuffersExtension() {}
};

} // namespace nodejsgl

#endif // NODEJS_GL_WEBGL_EXTENSIONS_H_
Loading