diff --git a/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/Caches.h b/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/Caches.h index 87555ff92..cd0f395e7 100644 --- a/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/Caches.h +++ b/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/Caches.h @@ -97,6 +97,21 @@ class Caches { std::unique_ptr > WebGL2RenderingContextTmpl = std::unique_ptr>( nullptr); + std::unique_ptr > WebGLProgramTmpl = std::unique_ptr>( + nullptr); + + std::unique_ptr > WebGLShaderTmpl = std::unique_ptr>( + nullptr); + + std::unique_ptr > WebGLFramebufferTmpl = std::unique_ptr>( + nullptr); + + std::unique_ptr > WebGLRenderbufferTmpl = std::unique_ptr>( + nullptr); + + std::unique_ptr > WebGLTextureTmpl = std::unique_ptr>( + nullptr); + private: static std::shared_ptr GetCtor(v8::Isolate *isolate) { + auto cache = Caches::Get(isolate); + auto ctor = cache->WebGLFramebufferTmpl.get(); + if (ctor != nullptr) { + return ctor->Get(isolate); + } + + v8::Local ctorTmpl = v8::FunctionTemplate::New(isolate); + ctorTmpl->InstanceTemplate()->SetInternalFieldCount(1); + ctorTmpl->SetClassName(ConvertToV8String(isolate, "WebGLFramebuffer")); + + auto tmpl = ctorTmpl->InstanceTemplate(); + tmpl->SetInternalFieldCount(1); + + cache->WebGLFramebufferTmpl = + std::make_unique>(isolate, ctorTmpl); + return ctorTmpl; + } + + static WebGLFramebuffer *GetPointer(const v8::Local &object) { + auto ptr = object->GetInternalField(0).As()->Value(); + if (ptr == nullptr) { + return nullptr; + } + return static_cast(ptr); + } + + uint32_t GetFrameBuffer() { + return this->framebuffer_; + } -uint32_t GetFrameBuffer() { - return this->framebuffer_; -} private: -uint32_t framebuffer_; + uint32_t framebuffer_; }; diff --git a/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl/WebGLProgram.h b/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl/WebGLProgram.h index 9d5c1a616..ec7298828 100644 --- a/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl/WebGLProgram.h +++ b/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl/WebGLProgram.h @@ -6,11 +6,10 @@ #include "rust/cxx.h" #include "canvas-cxx/src/lib.rs.h" -#include "v8runtime/V8Runtime.h" +#include "Common.h" -using namespace facebook; -class WebGLProgram: public jsi::HostObject { +class WebGLProgram { public: WebGLProgram(uint32_t program) : program_(program) {} @@ -18,6 +17,33 @@ class WebGLProgram: public jsi::HostObject { return this->program_; } + static v8::Local GetCtor(v8::Isolate *isolate) { + auto cache = Caches::Get(isolate); + auto ctor = cache->WebGLProgramTmpl.get(); + if (ctor != nullptr) { + return ctor->Get(isolate); + } + + v8::Local ctorTmpl = v8::FunctionTemplate::New(isolate); + ctorTmpl->InstanceTemplate()->SetInternalFieldCount(1); + ctorTmpl->SetClassName(ConvertToV8String(isolate, "WebGLProgram")); + + auto tmpl = ctorTmpl->InstanceTemplate(); + tmpl->SetInternalFieldCount(1); + + cache->WebGLProgramTmpl = + std::make_unique>(isolate, ctorTmpl); + return ctorTmpl; + } + + static WebGLProgram *GetPointer(const v8::Local &object) { + auto ptr = object->GetInternalField(0).As()->Value(); + if (ptr == nullptr) { + return nullptr; + } + return static_cast(ptr); + } + private: uint32_t program_; }; diff --git a/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl/WebGLRenderbuffer.h b/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl/WebGLRenderbuffer.h index 6431a4913..15c8ffb6a 100644 --- a/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl/WebGLRenderbuffer.h +++ b/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl/WebGLRenderbuffer.h @@ -6,14 +6,39 @@ #include "rust/cxx.h" #include "canvas-cxx/src/lib.rs.h" -#include "v8runtime/V8Runtime.h" +#include "Helpers.h" -using namespace facebook; - -class JSI_EXPORT WebGLRenderbuffer : public jsi::HostObject { +class WebGLRenderbuffer { public: WebGLRenderbuffer(uint32_t renderbuffer) : renderbuffer_(renderbuffer) {} + static v8::Local GetCtor(v8::Isolate *isolate) { + auto cache = Caches::Get(isolate); + auto ctor = cache->WebGLRenderbufferTmpl.get(); + if (ctor != nullptr) { + return ctor->Get(isolate); + } + + v8::Local ctorTmpl = v8::FunctionTemplate::New(isolate); + ctorTmpl->InstanceTemplate()->SetInternalFieldCount(1); + ctorTmpl->SetClassName(ConvertToV8String(isolate, "WebGLRenderbuffer")); + + auto tmpl = ctorTmpl->InstanceTemplate(); + tmpl->SetInternalFieldCount(1); + + cache->WebGLRenderbufferTmpl = + std::make_unique>(isolate, ctorTmpl); + return ctorTmpl; + } + + static WebGLRenderbuffer *GetPointer(const v8::Local &object) { + auto ptr = object->GetInternalField(0).As()->Value(); + if (ptr == nullptr) { + return nullptr; + } + return static_cast(ptr); + } + uint32_t GetRenderBuffer() { return this->renderbuffer_; } diff --git a/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl/WebGLRenderingContext.cpp b/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl/WebGLRenderingContext.cpp index aa7f316b2..c94e9bc6f 100644 --- a/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl/WebGLRenderingContext.cpp +++ b/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl/WebGLRenderingContext.cpp @@ -3,6 +3,7 @@ // #include "WebGLRenderingContext.h" +#include "OneByteStringResource.h" WebGLRenderingContext::WebGLRenderingContext(rust::Box state) : WebGLRenderingContextBase( @@ -45,12 +46,12 @@ static WebGLRenderingContext *GetPointer(const v8::Local &object) { } +v8::Local WebGLRenderingContext::GetParameterInternal(v8::Isolate *isolate, + uint32_t pnameValue, + rust::Box result) { -v8::Local WebGLRenderingContext::GetParameterInternal(v8::Isolate * isolate, - uint32_t pnameValue, - rust::Box result) { - -v8::EscapableHandleScope scope(isolate); + auto context = isolate->GetCurrentContext(); + v8::EscapableHandleScope scope(isolate); switch (pnameValue) { case GL_ACTIVE_TEXTURE: case GL_ALPHA_BITS: @@ -118,52 +119,61 @@ v8::EscapableHandleScope scope(isolate); value == 0) { return scope.Escape(v8::Null(isolate)); } - return scope.Escape(v8::Number::New(isolate, (double )value)); + return scope.Escape(v8::Number::New(isolate, (double) value)); } case (uint32_t) GLConstants::UNPACK_COLORSPACE_CONVERSION_WEBGL: - return scope.Escape(v8::Number::New(isolate, (double )canvas_native_webgl_state_get_unpack_colorspace_conversion_webgl( - this->GetState()))); + return scope.Escape(v8::Number::New(isolate, + (double) canvas_native_webgl_state_get_unpack_colorspace_conversion_webgl( + this->GetState()))); case GL_ALIASED_LINE_WIDTH_RANGE: case GL_ALIASED_POINT_SIZE_RANGE: case GL_DEPTH_RANGE: { auto ret = canvas_native_webgl_result_get_f32_array(*result); auto buf = new VecMutableBuffer(std::move(ret)); - auto array = jsi::ArrayBuffer(runtime, buf); - auto Float32Array = runtime.global() - .getProperty(runtime, - "Float32Array") - .asObject(runtime) - .asFunction(runtime); + + auto store = v8::ArrayBuffer::NewBackingStore(buf->data(), buf->buffer_size(), + [](void *data, size_t length, + void *deleter_data) { + if (deleter_data != nullptr) { + delete (VecMutableBuffer *) deleter_data; + } + }, + buf); + + auto arraybuffer = v8::ArrayBuffer::New(isolate, std::move(store)); - return Float32Array.callAsConstructor( - runtime, array); + return scope.Escape(v8::Float32Array::New(arraybuffer, 0, buf->size())); } - break; case GL_BLEND_COLOR: case GL_COLOR_CLEAR_VALUE: { auto ret = canvas_native_webgl_result_get_f32_array(*result); auto buf = new VecMutableBuffer(std::move(ret)); - auto array = jsi::ArrayBuffer(runtime, buf); - auto Float32Array = runtime.global() - .getProperty(runtime, - "Float32Array") - .asObject(runtime) - .asFunction(runtime); + auto store = v8::ArrayBuffer::NewBackingStore(buf->data(), buf->buffer_size(), + [](void *data, size_t length, + void *deleter_data) { + if (deleter_data != nullptr) { + delete (VecMutableBuffer *) deleter_data; + } + }, + buf); + auto arraybuffer = v8::ArrayBuffer::New(isolate, std::move(store)); - return Float32Array.callAsConstructor( - runtime, array); + + return scope.Escape(v8::Float32Array::New(arraybuffer, 0, buf->size())); } - break; case (uint32_t) GLConstants::UNPACK_FLIP_Y_WEBGL: - return {canvas_native_webgl_state_get_flip_y(this->GetState())}; + return scope.Escape(v8::Boolean::New(isolate, canvas_native_webgl_state_get_flip_y( + this->GetState()))); case (uint32_t) GLConstants::UNPACK_PREMULTIPLY_ALPHA_WEBGL: - return {canvas_native_webgl_state_get_premultiplied_alpha(this->GetState())}; + return scope.Escape(v8::Boolean::New(isolate, + canvas_native_webgl_state_get_premultiplied_alpha( + this->GetState()))); case GL_BLEND: case GL_CULL_FACE: case GL_DEPTH_TEST: @@ -173,13 +183,15 @@ v8::EscapableHandleScope scope(isolate); case GL_SAMPLE_COVERAGE_INVERT: case GL_SCISSOR_TEST: case GL_STENCIL_TEST: - return {canvas_native_webgl_result_get_bool(*result)}; + return scope.Escape( + v8::Boolean::New(isolate, canvas_native_webgl_result_get_bool(*result))); case GL_COLOR_WRITEMASK: { auto ret = canvas_native_webgl_result_get_bool_array(*result); auto len = ret.size(); - auto array = jsi::Array(runtime, len); + auto array = v8::Array::New(isolate, (int) len); + for (int j = 0; j < len; ++j) { - array.setValueAtIndex(runtime, j, jsi::Value(ret[j] == 1)); + array->Set(context, j, v8::Boolean::New(isolate, ret[j] == 1)); } return array; } @@ -188,1606 +200,1554 @@ v8::EscapableHandleScope scope(isolate); case GL_SCISSOR_BOX: case GL_VIEWPORT: { auto ret = canvas_native_webgl_result_get_i32_array(*result); + auto buf = new VecMutableBuffer(std::move(ret)); - auto buf = std::make_shared>(std::move(ret)); - auto array = jsi::ArrayBuffer(runtime, buf); + auto store = v8::ArrayBuffer::NewBackingStore(buf->data(), buf->buffer_size(), + [](void *data, size_t length, + void *deleter_data) { + if (deleter_data != nullptr) { + delete (VecMutableBuffer *) deleter_data; + } + }, + buf); - auto Int32Array = runtime.global() - .getProperty(runtime, - "Int32Array") - .asObject(runtime) - .asFunction(runtime); + auto arraybuffer = v8::ArrayBuffer::New(isolate, std::move(store)); - return Int32Array.callAsConstructor( - runtime, array); + return scope.Escape(v8::Int32Array::New(arraybuffer, 0, buf->size())); } - break; case GL_DEPTH_CLEAR_VALUE: case GL_LINE_WIDTH: case GL_POLYGON_OFFSET_FACTOR: case GL_POLYGON_OFFSET_UNITS: case GL_SAMPLE_COVERAGE_VALUE: { - return {static_cast(canvas_native_webgl_result_get_f32(*result))}; + return scope.Escape(v8::Number::New(isolate, + static_cast(canvas_native_webgl_result_get_f32( + *result)))); } case GL_RENDERER: case GL_SHADING_LANGUAGE_VERSION: case GL_VENDOR: case GL_VERSION: { auto ret = canvas_native_webgl_result_get_string(*result); - return jsi::String::createFromAscii(runtime, ret.data(), ret.size()); + + + auto value = new OneByteStringResource(std::move(ret)); + return scope.Escape(v8::String::NewExternalOneByte(isolate, value).ToLocalChecked()); } default: - return jsi::Value::null(); + return scope.Escape(v8::Null(isolate)); } } -std::vector WebGLRenderingContext::getPropertyNames(jsi::Runtime &rt) { - std::vector ret; - ret.reserve(436); - ret.push_back(jsi::PropNameID::forUtf8(rt, "__resized")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "__startRaf")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "__stopRaf")); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("activeTexture"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("attachShader"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("bindAttribLocation"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("bindBuffer"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("bindFramebuffer"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("bindRenderbuffer"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("bindTexture"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("blendColor"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("blendEquationSeparate"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("blendEquation"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("blendFuncSeparate"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("blendFunc"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("bufferData"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("bufferSubData"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("checkFramebufferStatus"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("clearColor"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("clearDepth"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("clearStencil"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("clear"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("colorMask"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("commit"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("compileShader"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("compressedTexImage2D"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("compressedTexSubImage2D"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("copyTexImage2D"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("copyTexSubImage2D"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("createBuffer"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("createFramebuffer"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("createProgram"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("createRenderbuffer"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("createShader"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("createTexture"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("cullFace"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("deleteBuffer"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("deleteFramebuffer"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("deleteProgram"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("deleteRenderbuffer"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("deleteShader"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("deleteTexture"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("depthFunc"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("depthMask"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("depthRange"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("detachShader"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("disableVertexAttribArray"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("disable"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("drawArrays"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("drawElements"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("enableVertexAttribArray"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("enable"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("finish"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("flush"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("framebufferRenderbuffer"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("framebufferTexture2D"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("frontFace"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("generateMipmap"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getActiveAttrib"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getActiveUniform"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getAttachedShaders"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getAttribLocation"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getBufferParameter"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getContextAttributes"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getError"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getExtension"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getFramebufferAttachmentParameter"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getParameter"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getProgramInfoLog"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getProgramParameter"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getRenderbufferParameter"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getShaderInfoLog"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getShaderParameter"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getShaderPrecisionFormat"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getShaderSource"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getSupportedExtensions"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getTexParameter"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getUniformLocation"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getUniform"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getVertexAttribOffset"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getVertexAttrib"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("hint"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("isBuffer"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("isContextLost"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("isEnabled"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("isFramebuffer"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("isProgram"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("isRenderbuffer"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("isShader"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("isTexture"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("lineWidth"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("linkProgram"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("pixelStorei"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("polygonOffset"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("readPixels"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("renderbufferStorage"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("sampleCoverage"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("scissor"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("shaderSource"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("stencilFuncSeparate"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("stencilFunc"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("stencilMaskSeparate"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("stencilMask"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("stencilOpSeparate"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("stencilOp"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("texImage2D"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("texParameterf"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("texParameteri"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("texSubImage2D"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform1f"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform1iv"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform1fv"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform1i"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform2f"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform2iv"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform2fv"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform2i"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform3f"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform3iv"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform3fv"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform3i"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform4f"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform4iv"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform4fv"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform4i"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniformMatrix2fv"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniformMatrix3fv"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniformMatrix4fv"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("useProgram"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("validateProgram"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("vertexAttrib1f"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("vertexAttrib1fv"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("vertexAttrib2f"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("vertexAttrib2fv"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("vertexAttrib3f"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("vertexAttrib3fv"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("vertexAttrib4f"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("vertexAttrib4fv"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("vertexAttribPointer"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("viewport"))); - ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("__toDataURL"))); +void +WebGLRenderingContext::GetDrawingBufferWidth(v8::Local name, + const v8::PropertyCallbackInfo &info) { + auto ptr = GetPointer(info.This()); + if (ptr != nullptr) { + auto ret = canvas_native_webgl_state_get_drawing_buffer_width(ptr->GetState()); + info.GetReturnValue().Set(ret); + return; + } + info.GetReturnValue().Set(0); +} - ret.push_back(jsi::PropNameID::forUtf8(rt, "DEPTH_BUFFER_BIT")); +void +WebGLRenderingContext::GetFlipY(v8::Local name, + const v8::PropertyCallbackInfo &info) { + auto ptr = GetPointer(info.This()); + if (ptr != nullptr) { + auto ret = canvas_native_webgl_state_get_flip_y(ptr->GetState()); + info.GetReturnValue().Set(ret); + return; + } + info.GetReturnValue().Set(false); +} - ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_BUFFER_BIT")); +WebGLRenderingContext::GetDrawingBufferHeight(v8::Local +name, +const v8::PropertyCallbackInfo &info +) { +auto ptr = GetPointer(info.This()); +if (ptr != nullptr) { +auto ret = canvas_native_webgl_state_get_drawing_buffer_height(ptr->GetState()); +info. - ret.push_back(jsi::PropNameID::forUtf8(rt, "COLOR_BUFFER_BIT")); +GetReturnValue() - ret.push_back(jsi::PropNameID::forUtf8(rt, "POINTS")); +. +Set(ret); +return; +} +info. - ret.push_back(jsi::PropNameID::forUtf8(rt, "LINES")); +GetReturnValue() - ret.push_back(jsi::PropNameID::forUtf8(rt, "LINE_LOOP")); +.Set(0); +} - ret.push_back(jsi::PropNameID::forUtf8(rt, "LINE_STRIP")); +void WebGLRenderingContext::__Resized(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - ret.push_back(jsi::PropNameID::forUtf8(rt, "TRIANGLES")); + canvas_native_webgl_resized( + ptr->GetState()); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TRIANGLE_STRIP")); +} - ret.push_back(jsi::PropNameID::forUtf8(rt, "TRIANGLE_FAN")); +void WebGLRenderingContext::__StartRaf(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - ret.push_back(jsi::PropNameID::forUtf8(rt, "ZERO")); + ptr->StartRaf(); - ret.push_back(jsi::PropNameID::forUtf8(rt, "ONE")); +} - ret.push_back(jsi::PropNameID::forUtf8(rt, "SRC_COLOR")); +void WebGLRenderingContext::__StopRaf(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - ret.push_back(jsi::PropNameID::forUtf8(rt, "ONE_MINUS_SRC_COLOR")); + ptr->StopRaf(); - ret.push_back(jsi::PropNameID::forUtf8(rt, "SRC_ALPHA")); +} - ret.push_back(jsi::PropNameID::forUtf8(rt, "ONE_MINUS_SRC_ALPHA")); +void WebGLRenderingContext::ActiveTexture(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - ret.push_back(jsi::PropNameID::forUtf8(rt, "DST_ALPHA")); + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + auto texture = (uint32_t) args[0]->NumberValue(context).ToChecked(); + canvas_native_webgl_active_texture(texture, + this->GetState()); +} - ret.push_back(jsi::PropNameID::forUtf8(rt, "ONE_MINUS_DST_ALPHA")); +void WebGLRenderingContext::AttachShader(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - ret.push_back(jsi::PropNameID::forUtf8(rt, "DST_COLOR")); + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - ret.push_back(jsi::PropNameID::forUtf8(rt, "ONE_MINUS_DST_COLOR")); + auto programValue = args[0]; + auto shaderValue = args[1]; + if (programValue->IsObject() && shaderValue->IsObject()) { + WebGLProgram *program = nullptr; + WebGLShader *shader = nullptr; + if (GetNativeType(isolate, programValue.As()) == NativeType::WebGLProgram) { + program = WebGLProgram::GetPointer(programValue.As()); + } - ret.push_back(jsi::PropNameID::forUtf8(rt, "SRC_ALPHA_SATURATE")); + if (GetNativeType(isolate, shaderValue.As()) == NativeType::WebGLShader) { + shader = WebGLShader::GetPointer(shaderValue.As()); + } + if (program == nullptr) { + return; + } - ret.push_back(jsi::PropNameID::forUtf8(rt, "CONSTANT_COLOR")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "ONE_MINUS_CONSTANT_COLOR")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "CONSTANT_ALPHA")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "ONE_MINUS_CONSTANT_ALPHA")); + if (shader == nullptr) { + return; + } + canvas_native_webgl_attach_shader( + program->GetProgram(), + shader->GetShader(), + ptr->GetState() + ); - /* Blending equations */ + } +} - ret.push_back(jsi::PropNameID::forUtf8(rt, "FUNC_ADD")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "FUNC_SUBTRACT")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "FUNC_REVERSE_SUBTRACT")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "BLEND_EQUATION")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "BLEND_EQUATION_RGB")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "BLEND_EQUATION_ALPHA")); +void WebGLRenderingContext::BindAttribLocation(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - ret.push_back(jsi::PropNameID::forUtf8(rt, "BLEND_DST_RGB")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "BLEND_SRC_RGB")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "BLEND_DST_ALPHA")); + if (args.Length() > 2) { + auto programValue = args[0]; + if(programValue->IsObject()){ + auto type = GetNativeType(isolate, programValue.As()); + if(type == NativeType::WebGLProgram && args[1]->IsNumber() && + args[2]->IsString()){ + auto program = WebGLProgram::GetPointer(programValue.As()); - ret.push_back(jsi::PropNameID::forUtf8(rt, "BLEND_SRC_ALPHA")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "BLEND_COLOR")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "ARRAY_BUFFER_BINDING")); + auto index = (uint32_t) args[1]->NumberValue(context).ToChecked(); + auto name = ConvertFromV8String(isolate, args[2]); + canvas_native_webgl_bind_attrib_location( + program->GetProgram(), + index, + rust::Str(name.c_str()), + this->GetState() + ); + } + } + } +} - ret.push_back(jsi::PropNameID::forUtf8(rt, "ELEMENT_ARRAY_BUFFER_BINDING")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "LINE_WIDTH")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "ALIASED_POINT_SIZE_RANGE")); +void WebGLRenderingContext::BindBuffer(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - ret.push_back(jsi::PropNameID::forUtf8(rt, "ALIASED_LINE_WIDTH_RANGE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "CULL_FACE_MODE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "FRONT_FACE")); + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + if (args.Length() > 1) { + if (args[0]->IsNumber()) { + auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); + if (!args[1]->IsNull() && + args[1]->IsObject()) { + auto type = GetNativeType(isolate, args[1].As()); + if(type == NativeType::WebGLBuffer){ + auto buffer = WebGLBuffer::GetPointer(args[1].As()); + if (buffer == + nullptr) { return; } + canvas_native_webgl_bind_buffer( + target, + buffer->GetBuffer(), + ptr->GetState() + ); + } + + } else { + // unbind + // check for null or undefined ? + canvas_native_webgl_bind_buffer( + target, + 0, + ptr->GetState() + ); + } + } + } +} - ret.push_back(jsi::PropNameID::forUtf8(rt, "DEPTH_RANGE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "DEPTH_WRITEMASK")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "DEPTH_CLEAR_VALUE")); +void WebGLRenderingContext::BindFramebuffer(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - ret.push_back(jsi::PropNameID::forUtf8(rt, "DEPTH_FUNC")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_CLEAR_VALUE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_FUNC")); + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + if (args.Length() > 1) { + if (args[0]->IsNumber()) { + auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); + if (args[1]->IsObject()) { + auto type = GetNativeType(isolate, args[1].As()); + if(type == NativeType::WebGLFramebuffer){ + auto framebuffer = WebGLFramebuffer::GetPointer(args[1].As()); + canvas_native_webgl_bind_frame_buffer( + target, + framebuffer->GetFrameBuffer(), + ptr->GetState() + ); + } + } else { + // null value + // unbind + canvas_native_webgl_bind_frame_buffer( + target, + 0, + ptr->GetState() + ); + } + } + } +} - ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_FAIL")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_PASS_DEPTH_FAIL")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_PASS_DEPTH_PASS")); +void WebGLRenderingContext::BindRenderbuffer(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_REF")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_VALUE_MASK")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_WRITEMASK")); + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + if (args.Length() > 1) { + if (args[0]->IsNumber()) { + auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); + if (args[1]->IsObject()) { + auto type = GetNativeType(isolate, args[1].As()); + if(type == NativeType::WebGLRenderbuffer){ + auto renderbuffer = WebGLRenderbuffer::GetPointer(args[1].As()); + + if (renderbuffer == + nullptr) { return;} + canvas_native_webgl_bind_render_buffer( + target, + renderbuffer->GetRenderBuffer(), + ptr->GetState() + ); + } + } else { + canvas_native_webgl_bind_render_buffer( + target, + 0, + ptr->GetState() + ); + } + } + } +} - ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_BACK_FUNC")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_BACK_FAIL")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_BACK_PASS_DEPTH_FAIL")); +void WebGLRenderingContext::BindTexture(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_BACK_PASS_DEPTH_PASS")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_BACK_REF")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_BACK_VALUE_MASK")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_BACK_WRITEMASK")); + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + if (args.Length() > 1) { + if (args[0]->IsNumber()) { + auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); + if (args[1]->IsObject()) { + auto type = GetNativeType(isolate, args[1].As()); + if(type == NativeType::WebGLTexture){ + auto texture = WebGLTexture::GetPointer(args[1].As()); + canvas_native_webgl_bind_texture( + target, + texture->GetTexture(), + ptr->GetState() + ); + } + } else { + canvas_native_webgl_bind_texture( + target, + 0, + ptr->GetState() + ); + } + } + } +} - ret.push_back(jsi::PropNameID::forUtf8(rt, "VIEWPORT")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "SCISSOR_BOX")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "COLOR_CLEAR_VALUE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "COLOR_WRITEMASK")); +void WebGLRenderingContext::BlendColor(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - ret.push_back(jsi::PropNameID::forUtf8(rt, "UNPACK_ALIGNMENT")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "PACK_ALIGNMENT")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "MAX_TEXTURE_SIZE")); + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + if (args.Length() > 3) { + auto red = args[0]->NumberValue(context).ToChecked(); + auto green = args[1]->NumberValue(context).ToChecked(); + auto blue = args[2]->NumberValue(context).ToChecked(); + auto alpha = args[3]->NumberValue(context).ToChecked(); - ret.push_back(jsi::PropNameID::forUtf8(rt, "MAX_VIEWPORT_DIMS")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "SUBPIXEL_BITS")); + canvas_native_webgl_blend_color( + static_cast(red), + static_cast(green), + static_cast(blue), + static_cast(alpha), + ptr->GetState() + ); + } +} - ret.push_back(jsi::PropNameID::forUtf8(rt, "RED_BITS")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "GREEN_BITS")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "BLUE_BITS")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "ALPHA_BITS")); +void WebGLRenderingContext::BlendEquationSeparate(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_BITS")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "POLYGON_OFFSET_UNITS")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "POLYGON_OFFSET_FACTOR")); + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_BINDING_2D")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "SAMPLE_BUFFERS")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "SAMPLES")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "SAMPLE_COVERAGE_VALUE")); + if (args.Length() > 1) { + auto modeRGB = (uint32_t) args[0]->NumberValue(context).ToChecked(); + auto modeAlpha = (uint32_t) args[1]->NumberValue(context).ToChecked(); - ret.push_back(jsi::PropNameID::forUtf8(rt, "SAMPLE_COVERAGE_INVERT")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "COMPRESSED_TEXTURE_FORMATS")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "VENDOR")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "RENDERER")); + canvas_native_webgl_blend_equation_separate( + modeRGB, + modeAlpha, + ptr->GetState() + ); + } +} - ret.push_back(jsi::PropNameID::forUtf8(rt, "VERSION")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "IMPLEMENTATION_COLOR_READ_TYPE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "IMPLEMENTATION_COLOR_READ_FORMAT")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "BROWSER_DEFAULT_WEBGL")); +void WebGLRenderingContext::BlendEquation(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - ret.push_back(jsi::PropNameID::forUtf8(rt, "STATIC_DRAW")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "STREAM_DRAW")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "DYNAMIC_DRAW")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "ARRAY_BUFFER")); + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - ret.push_back(jsi::PropNameID::forUtf8(rt, "ELEMENT_ARRAY_BUFFER")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "BUFFER_SIZE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "BUFFER_USAGE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "CURRENT_VERTEX_ATTRIB")); + if (args.Length() > 0) { + auto mode = (uint32_t) args[0]->NumberValue(context).ToChecked(); + canvas_native_webgl_blend_equation( + mode, + ptr->GetState() + ); + } +} +void WebGLRenderingContext::BlendFuncSeparate(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - ret.push_back(jsi::PropNameID::forUtf8(rt, "VERTEX_ATTRIB_ARRAY_ENABLED")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "VERTEX_ATTRIB_ARRAY_SIZE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "VERTEX_ATTRIB_ARRAY_STRIDE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "VERTEX_ATTRIB_ARRAY_TYPE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "VERTEX_ATTRIB_ARRAY_NORMALIZED")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "VERTEX_ATTRIB_ARRAY_POINTER")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "VERTEX_ATTRIB_ARRAY_BUFFER_BINDING")); + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - ret.push_back(jsi::PropNameID::forUtf8(rt, "CULL_FACE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "FRONT")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "BACK")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "FRONT_AND_BACK")); + if (args.Length() > 3) { + auto srcRGB = (uint32_t) args[0]->NumberValue(context).ToChecked(); + auto dstRGB = (uint32_t) args[1]->NumberValue(context).ToChecked(); + auto srcAlpha = (uint32_t) args[2]->NumberValue(context).ToChecked(); + auto dstAlpha = (uint32_t) args[3]->NumberValue(context).ToChecked(); - ret.push_back(jsi::PropNameID::forUtf8(rt, "BLEND")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "DEPTH_TEST")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "DITHER")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "POLYGON_OFFSET_FILL")); + canvas_native_webgl_blend_func_separate( + srcRGB, + dstRGB, + srcAlpha, + dstAlpha, + ptr->GetState() + ); + } +} - ret.push_back(jsi::PropNameID::forUtf8(rt, "SAMPLE_ALPHA_TO_COVERAGE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "SAMPLE_COVERAGE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "SCISSOR_TEST")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_TEST")); +void WebGLRenderingContext::BlendFunc(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - /* Errors */ + if (args.Length() > 1) { + auto sfactor = (uint32_t) args[0]->NumberValue(context).ToChecked(); + auto dfactor = (uint32_t) args[1]->NumberValue(context).ToChecked(); - ret.push_back(jsi::PropNameID::forUtf8(rt, "NO_ERROR")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "INVALID_ENUM")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "INVALID_VALUE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "INVALID_OPERATION")); + canvas_native_webgl_blend_func( + sfactor, + dfactor, + ptr->GetState() + ); + } +} - ret.push_back(jsi::PropNameID::forUtf8(rt, "OUT_OF_MEMORY")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "CONTEXT_LOST_WEBGL")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "CW")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "CCW")); +void WebGLRenderingContext::BufferData(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - ret.push_back(jsi::PropNameID::forUtf8(rt, "DONT_CARE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "FASTEST")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "NICEST")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "GENERATE_MIPMAP_HINT")); + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + auto count = args.Length(); + + if (count == 2) { + auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); + auto usage = (uint32_t) args[1]->NumberValue(context).ToChecked(); + + canvas_native_webgl_buffer_data_none( + target, + 0, + usage, + ptr->GetState() + ); + } else if (count == 3) { + auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); + + auto usage = (uint32_t) args[2]->NumberValue(context).ToChecked(); + + if (args[1]->IsObject()) { + + auto sizeOrBuf = args[1]; + if (sizeOrBuf->IsArrayBufferView()) { + if (sizeOrBuf->IsUint16Array()) { + auto array = sizeOrBuf.As(); + auto buf = GetTypedArrayData(array); + + canvas_native_webgl_buffer_data_u16( + target, + buf, + usage, + ptr->GetState() + ); + } else if (sizeOrBuf->IsFloat32Array()) { + auto array = sizeOrBuf.As(); + auto buf = GetTypedArrayData(array); + canvas_native_webgl_buffer_data_f32( + target, + buf, + usage, + ptr->GetState() + ); + } else { + auto array = sizeOrBuf.As(); + auto buf = GetTypedArrayData(array); + canvas_native_webgl_buffer_data( + target, + buf, + usage, + ptr->GetState() + ); + } + } else if (sizeOrBuf->IsArrayBuffer()) { + auto buffer = sizeOrBuf.As(); + auto data = GetArrayBufferData(buffer); + canvas_native_webgl_buffer_data( + target, + data, + usage, + ptr->GetState() + ); + } + } else { + auto sizeOrBuf = args[1]->NumberValue(context).ToChecked(); + canvas_native_webgl_buffer_data_none( + target, + static_cast(sizeOrBuf), + usage, + ptr->GetState() + ); + } + } +} - ret.push_back(jsi::PropNameID::forUtf8(rt, "BYTE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "UNSIGNED_BYTE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "SHORT")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "UNSIGNED_SHORT")); +void WebGLRenderingContext::BufferSubData(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - ret.push_back(jsi::PropNameID::forUtf8(rt, "INT")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "UNSIGNED_INT")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "FLOAT")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "DEPTH_COMPONENT")); + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + auto count = args.Length(); + + if (count == 2) { + auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); + auto offset = args[1]->NumberValue(context).ToChecked(); + + canvas_native_webgl_buffer_sub_data_none( + target, + static_cast(offset), + ptr->GetState() + ); + } else if (count == 3) { + auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); + auto offset = args[1]->NumberValue(context).ToChecked(); + + if (args[2]->IsObject()) { + auto buf = args[2]; + + if (buf->IsTypedArray()) { + auto array = buf.As(); + auto buff = GetTypedArrayData(array); + canvas_native_webgl_buffer_sub_data( + target, + static_cast(offset), + buff, + ptr->GetState() + ); + } else if (buf->IsArrayBuffer()) { + auto arrayBuffer = buf.As(); + + auto data = GetArrayBufferData(arrayBuffer); + + canvas_native_webgl_buffer_sub_data( + target, + static_cast(offset), + data, + ptr->GetState() + ); + } - ret.push_back(jsi::PropNameID::forUtf8(rt, "ALPHA")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "RGB")); + } - /* Clearing buffers */ + } +} - ret.push_back(jsi::PropNameID::forUtf8(rt, "RGBA")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "LUMINANCE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "LUMINANCE_ALPHA")); +void WebGLRenderingContext::CheckFramebufferStatus(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - /* Clearing buffers */ + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - /* Rendering primitives */ + auto count = args.Length(); - ret.push_back(jsi::PropNameID::forUtf8(rt, "UNSIGNED_SHORT_4_4_4_4")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "UNSIGNED_SHORT_5_5_5_1")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "UNSIGNED_SHORT_5_6_5")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "FRAGMENT_SHADER")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "VERTEX_SHADER")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "COMPILE_STATUS")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "DELETE_STATUS")); + if (count > 0) { - /* Rendering primitives */ + if (args[0]->IsNumber()) { + auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); - /* Blending modes */ + auto ret = canvas_native_webgl_check_frame_buffer_status( + target, + ptr->GetState() + ); - ret.push_back(jsi::PropNameID::forUtf8(rt, "LINK_STATUS")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "VALIDATE_STATUS")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "ATTACHED_SHADERS")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "ACTIVE_ATTRIBUTES")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "ACTIVE_UNIFORMS")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "MAX_VERTEX_ATTRIBS")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "MAX_VERTEX_UNIFORM_VECTORS")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "MAX_VARYING_VECTORS")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "MAX_COMBINED_TEXTURE_IMAGE_UNITS")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "MAX_VERTEX_TEXTURE_IMAGE_UNITS")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "MAX_TEXTURE_IMAGE_UNITS")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "MAX_FRAGMENT_UNIFORM_VECTORS")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "SHADER_TYPE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "SHADING_LANGUAGE_VERSION")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "CURRENT_PROGRAM")); + args.GetReturnValue().Set((int32_t) ret); + return; + } + } - /* Blending modes */ + args.GetReturnValue().Set(0); +} - ret.push_back(jsi::PropNameID::forUtf8(rt, "NEVER")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "LESS")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "EQUAL")); +void WebGLRenderingContext::ClearColor(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - /* Blending equations */ + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - /* Getting GL parameter information */ + if (args.Length() > 3) { + auto red = args[0]->NumberValue(context).ToChecked(); + auto green = args[1]->NumberValue(context).ToChecked(); + auto blue = args[2]->NumberValue(context).ToChecked(); + auto alpha = args[3]->NumberValue(context).ToChecked(); - ret.push_back(jsi::PropNameID::forUtf8(rt, "LEQUAL")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "GREATER")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "NOTEQUAL")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "GEQUAL")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "ALWAYS")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "KEEP")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "REPLACE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "INCR")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "DECR")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "INVERT")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "INCR_WRAP")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "DECR_WRAP")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "NEAREST")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "LINEAR")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "NEAREST_MIPMAP_NEAREST")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "LINEAR_MIPMAP_NEAREST")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "NEAREST_MIPMAP_LINEAR")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "LINEAR_MIPMAP_LINEAR")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_MAG_FILTER")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_MIN_FILTER")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_WRAP_S")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_WRAP_T")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_2D")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_CUBE_MAP")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_BINDING_CUBE_MAP")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_CUBE_MAP_POSITIVE_X")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_CUBE_MAP_NEGATIVE_X")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_CUBE_MAP_POSITIVE_Y")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_CUBE_MAP_NEGATIVE_Y")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_CUBE_MAP_POSITIVE_Z")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_CUBE_MAP_NEGATIVE_Z")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "MAX_CUBE_MAP_TEXTURE_SIZE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE0")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE1")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE2")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE3")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE4")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE5")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE6")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE7")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE8")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE9")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE10")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE11")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE12")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE13")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE14")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE15")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE16")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE17")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE18")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE19")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE20")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE21")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE22")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE23")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE24")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE25")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE26")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE27")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE28")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE29")); + canvas_native_webgl_clear_color( + static_cast(red), + static_cast(green), + static_cast(blue), + static_cast(alpha), + ptr->GetState() + ); + } +} - /* Getting GL parameter information */ +void WebGLRenderingContext::ClearDepth(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - /* Buffers */ + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE30")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE31")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "ACTIVE_TEXTURE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "REPEAT")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "CLAMP_TO_EDGE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "MIRRORED_REPEAT")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "FLOAT_VEC2")); + if (args.Length() > 0) { + auto depth = args[0]->NumberValue(context).ToChecked(); - /* Buffers */ + canvas_native_webgl_clear_depth( + static_cast(depth), + ptr->GetState() + ); + } +} - /* Vertex attributes */ - - ret.push_back(jsi::PropNameID::forUtf8(rt, "FLOAT_VEC3")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "FLOAT_VEC4")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "INT_VEC2")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "INT_VEC3")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "INT_VEC4")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "BOOL")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "BOOL_VEC2")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "BOOL_VEC3")); - - /* Vertex attributes */ - - /* Culling */ - - ret.push_back(jsi::PropNameID::forUtf8(rt, "BOOL_VEC4")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "FLOAT_MAT2")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "FLOAT_MAT3")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "FLOAT_MAT4")); - - /* Culling */ - - /* Enabling and disabling */ - - ret.push_back(jsi::PropNameID::forUtf8(rt, "SAMPLER_2D")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "SAMPLER_CUBE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "LOW_FLOAT")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "MEDIUM_FLOAT")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "HIGH_FLOAT")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "LOW_INT")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "MEDIUM_INT")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "HIGH_INT")); - - /* Enabling and disabling */ - - ret.push_back(jsi::PropNameID::forUtf8(rt, "FRAMEBUFFER")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "RENDERBUFFER")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "RGBA4")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "RGB5_A1")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "RGB565")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "DEPTH_COMPONENT16")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_INDEX8")); - - /* Errors */ - - /* Front face directions */ - - ret.push_back(jsi::PropNameID::forUtf8(rt, "DEPTH_STENCIL")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "RENDERBUFFER_WIDTH")); - - /* Front face directions */ - - /* Hints */ - - ret.push_back(jsi::PropNameID::forUtf8(rt, "RENDERBUFFER_HEIGHT")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "RENDERBUFFER_INTERNAL_FORMAT")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "RENDERBUFFER_RED_SIZE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "RENDERBUFFER_GREEN_SIZE")); - - /* Hints */ - - /* Data types */ - - ret.push_back(jsi::PropNameID::forUtf8(rt, "RENDERBUFFER_BLUE_SIZE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "RENDERBUFFER_ALPHA_SIZE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "RENDERBUFFER_DEPTH_SIZE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "RENDERBUFFER_STENCIL_SIZE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "FRAMEBUFFER_ATTACHMENT_OBJECT_NAME")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL")); - - /* Data types */ - - /* Pixel formats */ - - ret.push_back(jsi::PropNameID::forUtf8(rt, "FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "COLOR_ATTACHMENT0")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "DEPTH_ATTACHMENT")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_ATTACHMENT")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "DEPTH_STENCIL_ATTACHMENT")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "NONE")); +void WebGLRenderingContext::ClearStencil(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - /* Pixel formats */ + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - /* Pixel types */ + if (args.Length() > 0) { + auto stencil = (int32_t) args[0]->NumberValue(context).ToChecked(); + canvas_native_webgl_clear_stencil( + stencil, + ptr->GetState() + ); + } +} - ret.push_back(jsi::PropNameID::forUtf8(rt, "FRAMEBUFFER_COMPLETE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "FRAMEBUFFER_INCOMPLETE_ATTACHMENT")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT")); +void WebGLRenderingContext::Clear(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - /* Pixel types */ + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - /* Shaders */ + //if (count > 0) { + auto mask = (uint32_t) args[0]->NumberValue(context).ToChecked(); - ret.push_back(jsi::PropNameID::forUtf8(rt, "FRAMEBUFFER_INCOMPLETE_DIMENSIONS")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "FRAMEBUFFER_UNSUPPORTED")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "FRAMEBUFFER_BINDING")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "RENDERBUFFER_BINDING")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "MAX_RENDERBUFFER_SIZE")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "INVALID_FRAMEBUFFER_OPERATION")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "UNPACK_FLIP_Y_WEBGL")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "UNPACK_PREMULTIPLY_ALPHA_WEBGL")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "UNPACK_COLORSPACE_CONVERSION_WEBGL")); + canvas_native_webgl_clear( + mask, + ptr->GetState() + ); - return ret; + this->UpdateInvalidateState(); + // } } -jsi::Value WebGLRenderingContext::get(jsi::Runtime &runtime, const jsi::PropNameID &name) { - auto methodName = name.utf8(runtime); - - auto prop_return = GetProperty(methodName); - - if (!prop_return.isUndefined()) { - return prop_return; - } - - if (methodName == "drawingBufferWidth") { - return {canvas_native_webgl_state_get_drawing_buffer_width(this->GetState())}; - } - if (methodName == "drawingBufferHeight") { - return {canvas_native_webgl_state_get_drawing_buffer_height(this->GetState())}; - } - if (methodName == "__flipY") { - return {canvas_native_webgl_state_get_flip_y(this->GetState())}; +void WebGLRenderingContext::ColorMask(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; } - if (methodName == "__resized") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 0, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { + auto isolate = args.GetIsolate(); - // auto width = args[0]; - // auto height = args[1]; - // width->NumberValue(context).FromMaybe(1) - // width->NumberValue(context).FromMaybe(1)) - canvas_native_webgl_resized( - this->GetState()); + if (args.Length() > 3) { + auto red = args[0]->BooleanValue(isolate); + auto green = args[1]->BooleanValue(isolate); + auto blue = args[2]->BooleanValue(isolate); + auto alpha = args[3]->BooleanValue(isolate); - return jsi::Value::undefined(); - } + canvas_native_webgl_color_mask( + red, + green, + blue, + alpha, + ptr->GetState() ); } +} - if (methodName == "__startRaf") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 0, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { - - this->StartRaf(); - - return jsi::Value::undefined(); - } - ); +void WebGLRenderingContext::Commit(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; } +} - if (methodName == "__stopRaf") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 0, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { - - this->StartRaf(); - - return jsi::Value::undefined(); - } - ); +void WebGLRenderingContext::CompileShader(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; } - if (methodName == "activeTexture") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 1, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { - + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - auto texture = (uint32_t) arguments[0].asNumber(); - canvas_native_webgl_active_texture(texture, - this->GetState()); + if (args.Length() > 0) { + auto shader = WebGLShader::GetPointer(args[0].As()); + if (shader != nullptr) { + canvas_native_webgl_compile_shader( + shader->GetShader(), + ptr->GetState() + ); + } + } +} - return jsi::Value::undefined(); - } - ); - } else if (methodName == "attachShader") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 1, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { +void WebGLRenderingContext::CompressedTexImage2D(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - auto program = arguments[0].asObject( - runtime).asHostObject( - runtime); - auto shader = arguments[1].asObject( - runtime).asHostObject( - runtime); + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + auto count = args.Length(); + + if (count == 6) { + auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); + auto level = (int32_t) args[1]->NumberValue(context).ToChecked(); + auto internalformat = (uint32_t) args[2]->NumberValue(context).ToChecked(); + auto width = (int32_t) args[3]->NumberValue(context).ToChecked(); + auto height = (int32_t) args[4]->NumberValue(context).ToChecked(); + auto border = (int32_t) args[5]->NumberValue(context).ToChecked(); + + canvas_native_webgl_compressed_tex_image2d_none( + target, + level, + internalformat, + width, + height, + border, + ptr->GetState() + ); + } else if (count > 6) { + auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); + auto level = (int32_t) args[1]->NumberValue(context).ToChecked(); + auto internalformat = (uint32_t) args[2]->NumberValue(context).ToChecked(); + auto width = (int32_t) args[3]->NumberValue(context).ToChecked(); + auto height = (int32_t) args[4]->NumberValue(context).ToChecked(); + auto border = (int32_t) args[5]->NumberValue(context).ToChecked(); + auto pixels = args[6]; + if (pixels->IsObject()) { + if (pixels->IsTypedArray()) { + auto array = pixels.As(); + auto buf = GetTypedArrayData(array); + canvas_native_webgl_compressed_tex_image2d( + target, + level, + internalformat, + width, + height, + border, + buf, + ptr->GetState() + ); + } else if (pixels->IsArrayBuffer()) { + auto ab = pixels.As(); + auto buf = GetArrayBufferData(ab); + + canvas_native_webgl_compressed_tex_image2d( + target, + level, + internalformat, + width, + height, + border, + buf, + ptr->GetState() + ); + } + } + } +} - if (program == nullptr) { - return jsi::Value::undefined(); - } +void WebGLRenderingContext::CompressedTexSubImage2D(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - if (shader == nullptr) { - return jsi::Value::undefined(); - } + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + auto count = args.Length(); + + + if (count > 7) { + auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); + auto level = (int32_t) args[1]->NumberValue(context).ToChecked(); + auto xoffset = (int32_t) args[2]->NumberValue(context).ToChecked(); + auto yoffset = (int32_t) args[3]->NumberValue(context).ToChecked(); + auto width = (int32_t) args[4]->NumberValue(context).ToChecked(); + auto height = (int32_t) args[5]->NumberValue(context).ToChecked(); + auto format = (uint32_t) args[6]->NumberValue(context).ToChecked(); + if (args[7]->IsObject()) { + auto pixels = args[7]; + if (pixels->IsTypedArray()) { + auto px = pixels.As(); + auto buf = GetTypedArrayData(px); + canvas_native_webgl_compressed_tex_sub_image2d( + target, + level, + xoffset, + yoffset, + width, + height, + format, + buf, + ptr->GetState() + ); + } else if (pixels->IsArrayBuffer()) { + auto buffer = pixels.As(); + auto buf = GetArrayBufferData(buffer); + + canvas_native_webgl_compressed_tex_sub_image2d( + target, + level, + xoffset, + yoffset, + width, + height, + format, + buf, + ptr->GetState() + ); + } + } + } - canvas_native_webgl_attach_shader( - program->GetProgram(), - shader->GetShader(), - this->GetState() - ); +} +void WebGLRenderingContext::CopyTexImage2D(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - return jsi::Value::undefined(); - } + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + auto count = args.Length(); + + + if (count > 7) { + auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); + auto level = (int32_t) args[1]->NumberValue(context).ToChecked(); + auto internalformat = (uint32_t) args[2]->NumberValue(context).ToChecked(); + auto x = (int32_t) args[3]->NumberValue(context).ToChecked(); + auto y = (int32_t) args[4]->NumberValue(context).ToChecked(); + auto width = (int32_t) args[5]->NumberValue(context).ToChecked(); + auto height = (int32_t) args[6]->NumberValue(context).ToChecked(); + auto border = (int32_t) args[7]->NumberValue(context).ToChecked(); + + canvas_native_webgl_copy_tex_image2d( + target, + level, + internalformat, + x, + y, + width, + height, + border, + ptr->GetState() ); - } else if (methodName == "bindAttribLocation") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 1, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { + } - if (count > 2) { - auto program = arguments[0].asObject( - runtime).asHostObject( - runtime); +} - if (program != nullptr && - arguments[1].isNumber() && - arguments[2].isString()) { - auto index = (uint32_t) arguments[1].asNumber(); - auto name = arguments[2].asString( - runtime).utf8(runtime); - canvas_native_webgl_bind_attrib_location( - program->GetProgram(), - index, - rust::Str(name.c_str()), - this->GetState() - ); - } - } +void WebGLRenderingContext::CopyTexSubImage2D(const v8::FunctionCallbackInfo &args) { + WebGLRenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - return jsi::Value::undefined(); - } + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + auto count = args.Length(); + + + if (count > 7) { + auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); + auto level = (int32_t) args[1]->NumberValue(context).ToChecked(); + auto xoffset = (int32_t) args[2]->NumberValue(context).ToChecked(); + auto yoffset = (int32_t) args[3]->NumberValue(context).ToChecked(); + auto x = (int32_t) args[4]->NumberValue(context).ToChecked(); + auto y = (int32_t) args[5]->NumberValue(context).ToChecked(); + auto width = (int32_t) args[6]->NumberValue(context).ToChecked(); + auto height = (int32_t) args[7]->NumberValue(context).ToChecked(); + + canvas_native_webgl_copy_tex_sub_image2d( + target, + level, + xoffset, + yoffset, + x, + y, + width, + height, + ptr->GetState() ); - } else if (methodName == "bindBuffer") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 2, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { + } - if (count > 1) { +} - if (arguments[0].isNumber()) { - auto target = (uint32_t) arguments[0].asNumber(); - if (!arguments[1].isNull() && - arguments[1].isObject()) { - auto buffer = arguments[1].asObject( - runtime).asHostObject( - runtime); - if (buffer == - nullptr) { return jsi::Value::undefined(); } - canvas_native_webgl_bind_buffer( - target, - buffer->GetBuffer(), - this->GetState() - ); - } else { - // unbind - // check for null or undefined ? - canvas_native_webgl_bind_buffer( - target, - 0, - this->GetState() - ); - } - } - } +std::vector WebGLRenderingContext::getPropertyNames(jsi::Runtime &rt) { + std::vector ret; + ret.reserve(436); - return jsi::Value::undefined(); - } - ); - } else if (methodName == "bindFramebuffer") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 2, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { + ret.push_back(jsi::PropNameID::forUtf8(rt, "__resized")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "__startRaf")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "__stopRaf")); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("activeTexture"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("attachShader"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("bindAttribLocation"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("bindBuffer"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("bindFramebuffer"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("bindRenderbuffer"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("bindTexture"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("blendColor"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("blendEquationSeparate"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("blendEquation"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("blendFuncSeparate"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("blendFunc"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("bufferData"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("bufferSubData"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("checkFramebufferStatus"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("clearColor"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("clearDepth"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("clearStencil"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("clear"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("colorMask"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("commit"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("compileShader"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("compressedTexImage2D"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("compressedTexSubImage2D"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("copyTexImage2D"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("copyTexSubImage2D"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("createBuffer"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("createFramebuffer"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("createProgram"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("createRenderbuffer"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("createShader"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("createTexture"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("cullFace"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("deleteBuffer"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("deleteFramebuffer"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("deleteProgram"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("deleteRenderbuffer"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("deleteShader"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("deleteTexture"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("depthFunc"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("depthMask"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("depthRange"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("detachShader"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("disableVertexAttribArray"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("disable"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("drawArrays"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("drawElements"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("enableVertexAttribArray"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("enable"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("finish"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("flush"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("framebufferRenderbuffer"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("framebufferTexture2D"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("frontFace"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("generateMipmap"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getActiveAttrib"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getActiveUniform"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getAttachedShaders"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getAttribLocation"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getBufferParameter"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getContextAttributes"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getError"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getExtension"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getFramebufferAttachmentParameter"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getParameter"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getProgramInfoLog"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getProgramParameter"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getRenderbufferParameter"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getShaderInfoLog"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getShaderParameter"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getShaderPrecisionFormat"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getShaderSource"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getSupportedExtensions"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getTexParameter"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getUniformLocation"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getUniform"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getVertexAttribOffset"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("getVertexAttrib"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("hint"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("isBuffer"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("isContextLost"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("isEnabled"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("isFramebuffer"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("isProgram"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("isRenderbuffer"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("isShader"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("isTexture"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("lineWidth"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("linkProgram"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("pixelStorei"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("polygonOffset"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("readPixels"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("renderbufferStorage"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("sampleCoverage"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("scissor"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("shaderSource"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("stencilFuncSeparate"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("stencilFunc"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("stencilMaskSeparate"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("stencilMask"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("stencilOpSeparate"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("stencilOp"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("texImage2D"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("texParameterf"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("texParameteri"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("texSubImage2D"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform1f"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform1iv"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform1fv"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform1i"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform2f"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform2iv"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform2fv"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform2i"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform3f"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform3iv"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform3fv"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform3i"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform4f"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform4iv"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform4fv"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniform4i"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniformMatrix2fv"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniformMatrix3fv"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("uniformMatrix4fv"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("useProgram"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("validateProgram"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("vertexAttrib1f"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("vertexAttrib1fv"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("vertexAttrib2f"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("vertexAttrib2fv"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("vertexAttrib3f"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("vertexAttrib3fv"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("vertexAttrib4f"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("vertexAttrib4fv"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("vertexAttribPointer"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("viewport"))); + ret.push_back(jsi::PropNameID::forUtf8(rt, std::string("__toDataURL"))); - if (count > 1) { + ret.push_back(jsi::PropNameID::forUtf8(rt, "DEPTH_BUFFER_BIT")); - if (arguments[0].isNumber()) { - auto target = (uint32_t) arguments[0].asNumber(); - if (arguments[1].isObject()) { - auto framebuffer = arguments[1].asObject( - runtime).asHostObject( - runtime); - canvas_native_webgl_bind_frame_buffer( - target, - framebuffer->GetFrameBuffer(), - this->GetState() - ); - } else { - // null value - // unbind - canvas_native_webgl_bind_frame_buffer( - target, - 0, - this->GetState() - ); - } - } - } + ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_BUFFER_BIT")); - return jsi::Value::undefined(); - } - ); - } else if (methodName == "bindRenderbuffer") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 2, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { + ret.push_back(jsi::PropNameID::forUtf8(rt, "COLOR_BUFFER_BIT")); - if (count > 1) { - if (arguments[0].isNumber()) { - auto target = (uint32_t) arguments[0].asNumber(); - if (arguments[1].isObject()) { - auto renderbuffer = arguments[1].asObject( - runtime).asHostObject( - runtime); + ret.push_back(jsi::PropNameID::forUtf8(rt, "POINTS")); - if (renderbuffer == - nullptr) { return jsi::Value::undefined(); } - canvas_native_webgl_bind_render_buffer( - target, - renderbuffer->GetRenderBuffer(), - this->GetState() - ); - } else { - canvas_native_webgl_bind_render_buffer( - target, - 0, - this->GetState() - ); - } - } - } + ret.push_back(jsi::PropNameID::forUtf8(rt, "LINES")); - return jsi::Value::undefined(); - } - ); - } else if (methodName == "bindTexture") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 2, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { + ret.push_back(jsi::PropNameID::forUtf8(rt, "LINE_LOOP")); - if (count > 1) { - if (arguments[0].isNumber()) { - auto target = (uint32_t) arguments[0].asNumber(); - if (arguments[1].isObject()) { - auto texture = arguments[1].asObject( - runtime).asHostObject( - runtime); - canvas_native_webgl_bind_texture( - target, - texture->GetTexture(), - this->GetState() - ); - } else { - canvas_native_webgl_bind_texture( - target, - 0, - this->GetState() - ); - } - } - } + ret.push_back(jsi::PropNameID::forUtf8(rt, "LINE_STRIP")); - return jsi::Value::undefined(); - } - ); - } else if (methodName == "blendColor") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 3, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { + ret.push_back(jsi::PropNameID::forUtf8(rt, "TRIANGLES")); - if (count > 3) { - auto red = arguments[0].asNumber(); - auto green = arguments[1].asNumber(); - auto blue = arguments[2].asNumber(); - auto alpha = arguments[3].asNumber(); - - canvas_native_webgl_blend_color( - static_cast(red), - static_cast(green), - static_cast(blue), - static_cast(alpha), - this->GetState() - ); - } + ret.push_back(jsi::PropNameID::forUtf8(rt, "TRIANGLE_STRIP")); - return jsi::Value::undefined(); - } - ); - } else if (methodName == "blendEquationSeparate") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 2, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { + ret.push_back(jsi::PropNameID::forUtf8(rt, "TRIANGLE_FAN")); - if (count > 1) { - auto modeRGB = (uint32_t) arguments[0].asNumber(); - auto modeAlpha = (uint32_t) arguments[1].asNumber(); + ret.push_back(jsi::PropNameID::forUtf8(rt, "ZERO")); - canvas_native_webgl_blend_equation_separate( - modeRGB, - modeAlpha, - this->GetState() - ); - } + ret.push_back(jsi::PropNameID::forUtf8(rt, "ONE")); - return jsi::Value::undefined(); - } - ); - } else if (methodName == "blendEquation") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 1, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { + ret.push_back(jsi::PropNameID::forUtf8(rt, "SRC_COLOR")); - if (count > 0) { - auto mode = (uint32_t) arguments[0].asNumber(); - canvas_native_webgl_blend_equation( - mode, - this->GetState() - ); - } + ret.push_back(jsi::PropNameID::forUtf8(rt, "ONE_MINUS_SRC_COLOR")); - return jsi::Value::undefined(); - } - ); - } else if (methodName == "blendFuncSeparate") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 4, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { + ret.push_back(jsi::PropNameID::forUtf8(rt, "SRC_ALPHA")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "ONE_MINUS_SRC_ALPHA")); - if (count > 3) { - auto srcRGB = (uint32_t) arguments[0].asNumber(); - auto dstRGB = (uint32_t) arguments[1].asNumber(); - auto srcAlpha = (uint32_t) arguments[2].asNumber(); - auto dstAlpha = (uint32_t) arguments[3].asNumber(); - - canvas_native_webgl_blend_func_separate( - srcRGB, - dstRGB, - srcAlpha, - dstAlpha, - this->GetState() - ); - } + ret.push_back(jsi::PropNameID::forUtf8(rt, "DST_ALPHA")); - return jsi::Value::undefined(); - } - ); - } else if (methodName == "blendFunc") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 2, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { + ret.push_back(jsi::PropNameID::forUtf8(rt, "ONE_MINUS_DST_ALPHA")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "DST_COLOR")); - if (count > 1) { - auto sfactor = (uint32_t) arguments[0].asNumber(); - auto dfactor = (uint32_t) arguments[1].asNumber(); + ret.push_back(jsi::PropNameID::forUtf8(rt, "ONE_MINUS_DST_COLOR")); - canvas_native_webgl_blend_func( - sfactor, - dfactor, - this->GetState() - ); - } + ret.push_back(jsi::PropNameID::forUtf8(rt, "SRC_ALPHA_SATURATE")); - return jsi::Value::undefined(); - } - ); - } else if (methodName == "bufferData") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 3, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { - if (count == 2) { - auto target = (uint32_t) arguments[0].asNumber(); - auto usage = (uint32_t) arguments[1].asNumber(); + ret.push_back(jsi::PropNameID::forUtf8(rt, "CONSTANT_COLOR")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "ONE_MINUS_CONSTANT_COLOR")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "CONSTANT_ALPHA")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "ONE_MINUS_CONSTANT_ALPHA")); - canvas_native_webgl_buffer_data_none( - target, - 0, - usage, - this->GetState() - ); - } else if (count == 3) { - auto target = (uint32_t) arguments[0].asNumber(); - auto usage = (uint32_t) arguments[2].asNumber(); + /* Blending equations */ - if (arguments[1].isObject()) { - auto sizeOrBuf = arguments[1].asObject( - runtime); - if (sizeOrBuf.isArrayBufferView( - runtime)) { - if (sizeOrBuf.isUint16Array( - runtime)) { - auto array = sizeOrBuf.getTypedArray( - runtime); - auto buf = GetTypedArrayData( - runtime, array); + ret.push_back(jsi::PropNameID::forUtf8(rt, "FUNC_ADD")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "FUNC_SUBTRACT")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "FUNC_REVERSE_SUBTRACT")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "BLEND_EQUATION")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "BLEND_EQUATION_RGB")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "BLEND_EQUATION_ALPHA")); - canvas_native_webgl_buffer_data_u16( - target, - buf, - usage, - this->GetState() - ); - } else if (sizeOrBuf.isFloat32Array( - runtime)) { - auto array = sizeOrBuf.getTypedArray( - runtime); - auto buf = GetTypedArrayData( - runtime, array); - canvas_native_webgl_buffer_data_f32( - target, - buf, - usage, - this->GetState() - ); - } else { - auto array = sizeOrBuf.getTypedArray( - runtime); - auto buf = GetTypedArrayData( - runtime, array); - canvas_native_webgl_buffer_data( - target, - buf, - usage, - this->GetState() - ); - } - } else if (sizeOrBuf.isArrayBuffer( - runtime)) { - auto buffer = sizeOrBuf.getArrayBuffer( - runtime); - auto data = buffer.data( - runtime); - auto size = buffer.size( - runtime); - rust::Slice buf( - data, size); - canvas_native_webgl_buffer_data( - target, - buf, - usage, - this->GetState() - ); - } - } else { - auto sizeOrBuf = arguments[1].asNumber(); - canvas_native_webgl_buffer_data_none( - target, - static_cast(sizeOrBuf), - usage, - this->GetState() - ); - } - } - return jsi::Value::undefined(); - } - ); - } else if (methodName == "bufferSubData") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 3, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { + ret.push_back(jsi::PropNameID::forUtf8(rt, "BLEND_DST_RGB")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "BLEND_SRC_RGB")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "BLEND_DST_ALPHA")); + + + ret.push_back(jsi::PropNameID::forUtf8(rt, "BLEND_SRC_ALPHA")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "BLEND_COLOR")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "ARRAY_BUFFER_BINDING")); + + + ret.push_back(jsi::PropNameID::forUtf8(rt, "ELEMENT_ARRAY_BUFFER_BINDING")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "LINE_WIDTH")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "ALIASED_POINT_SIZE_RANGE")); + + ret.push_back(jsi::PropNameID::forUtf8(rt, "ALIASED_LINE_WIDTH_RANGE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "CULL_FACE_MODE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "FRONT_FACE")); + + ret.push_back(jsi::PropNameID::forUtf8(rt, "DEPTH_RANGE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "DEPTH_WRITEMASK")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "DEPTH_CLEAR_VALUE")); + + ret.push_back(jsi::PropNameID::forUtf8(rt, "DEPTH_FUNC")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_CLEAR_VALUE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_FUNC")); + + ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_FAIL")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_PASS_DEPTH_FAIL")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_PASS_DEPTH_PASS")); + + ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_REF")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_VALUE_MASK")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_WRITEMASK")); + + ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_BACK_FUNC")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_BACK_FAIL")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_BACK_PASS_DEPTH_FAIL")); + + ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_BACK_PASS_DEPTH_PASS")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_BACK_REF")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_BACK_VALUE_MASK")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_BACK_WRITEMASK")); + + ret.push_back(jsi::PropNameID::forUtf8(rt, "VIEWPORT")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "SCISSOR_BOX")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "COLOR_CLEAR_VALUE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "COLOR_WRITEMASK")); + + ret.push_back(jsi::PropNameID::forUtf8(rt, "UNPACK_ALIGNMENT")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "PACK_ALIGNMENT")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "MAX_TEXTURE_SIZE")); + + + ret.push_back(jsi::PropNameID::forUtf8(rt, "MAX_VIEWPORT_DIMS")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "SUBPIXEL_BITS")); + + ret.push_back(jsi::PropNameID::forUtf8(rt, "RED_BITS")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "GREEN_BITS")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "BLUE_BITS")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "ALPHA_BITS")); + + ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_BITS")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "POLYGON_OFFSET_UNITS")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "POLYGON_OFFSET_FACTOR")); + + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_BINDING_2D")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "SAMPLE_BUFFERS")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "SAMPLES")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "SAMPLE_COVERAGE_VALUE")); + + ret.push_back(jsi::PropNameID::forUtf8(rt, "SAMPLE_COVERAGE_INVERT")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "COMPRESSED_TEXTURE_FORMATS")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "VENDOR")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "RENDERER")); + + ret.push_back(jsi::PropNameID::forUtf8(rt, "VERSION")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "IMPLEMENTATION_COLOR_READ_TYPE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "IMPLEMENTATION_COLOR_READ_FORMAT")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "BROWSER_DEFAULT_WEBGL")); + + ret.push_back(jsi::PropNameID::forUtf8(rt, "STATIC_DRAW")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "STREAM_DRAW")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "DYNAMIC_DRAW")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "ARRAY_BUFFER")); + + ret.push_back(jsi::PropNameID::forUtf8(rt, "ELEMENT_ARRAY_BUFFER")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "BUFFER_SIZE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "BUFFER_USAGE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "CURRENT_VERTEX_ATTRIB")); + + + ret.push_back(jsi::PropNameID::forUtf8(rt, "VERTEX_ATTRIB_ARRAY_ENABLED")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "VERTEX_ATTRIB_ARRAY_SIZE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "VERTEX_ATTRIB_ARRAY_STRIDE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "VERTEX_ATTRIB_ARRAY_TYPE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "VERTEX_ATTRIB_ARRAY_NORMALIZED")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "VERTEX_ATTRIB_ARRAY_POINTER")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "VERTEX_ATTRIB_ARRAY_BUFFER_BINDING")); + + ret.push_back(jsi::PropNameID::forUtf8(rt, "CULL_FACE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "FRONT")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "BACK")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "FRONT_AND_BACK")); + + ret.push_back(jsi::PropNameID::forUtf8(rt, "BLEND")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "DEPTH_TEST")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "DITHER")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "POLYGON_OFFSET_FILL")); + + ret.push_back(jsi::PropNameID::forUtf8(rt, "SAMPLE_ALPHA_TO_COVERAGE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "SAMPLE_COVERAGE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "SCISSOR_TEST")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_TEST")); + + + /* Errors */ + + ret.push_back(jsi::PropNameID::forUtf8(rt, "NO_ERROR")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "INVALID_ENUM")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "INVALID_VALUE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "INVALID_OPERATION")); + + ret.push_back(jsi::PropNameID::forUtf8(rt, "OUT_OF_MEMORY")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "CONTEXT_LOST_WEBGL")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "CW")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "CCW")); + + ret.push_back(jsi::PropNameID::forUtf8(rt, "DONT_CARE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "FASTEST")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "NICEST")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "GENERATE_MIPMAP_HINT")); + + ret.push_back(jsi::PropNameID::forUtf8(rt, "BYTE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "UNSIGNED_BYTE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "SHORT")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "UNSIGNED_SHORT")); + + ret.push_back(jsi::PropNameID::forUtf8(rt, "INT")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "UNSIGNED_INT")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "FLOAT")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "DEPTH_COMPONENT")); - if (count == 2) { - auto target = (uint32_t) arguments[0].asNumber(); - auto offset = arguments[1].asNumber(); + ret.push_back(jsi::PropNameID::forUtf8(rt, "ALPHA")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "RGB")); - canvas_native_webgl_buffer_sub_data_none( - target, - static_cast(offset), - this->GetState() - ); - } else if (count == 3) { - auto target = (uint32_t) arguments[0].asNumber(); - auto offset = arguments[1].asNumber(); + /* Clearing buffers */ - if (arguments[2].isObject()) { - auto buf = arguments[2].asObject( - runtime); + ret.push_back(jsi::PropNameID::forUtf8(rt, "RGBA")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "LUMINANCE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "LUMINANCE_ALPHA")); - if (buf.isTypedArray(runtime)) { - auto array = arguments[2].asObject( - runtime).getTypedArray( - runtime); - auto buff = GetTypedArrayData( - runtime, array); - canvas_native_webgl_buffer_sub_data( - target, - static_cast(offset), - buff, - this->GetState() - ); - } else if (buf.isArrayBuffer( - runtime)) { - auto arrayBuffer = buf.getArrayBuffer( - runtime); + /* Clearing buffers */ - auto store = arrayBuffer.data( - runtime); - auto size = arrayBuffer.size( - runtime); - rust::Slice data( - store, size); - canvas_native_webgl_buffer_sub_data( - target, - static_cast(offset), - data, - this->GetState() - ); - } + /* Rendering primitives */ - } + ret.push_back(jsi::PropNameID::forUtf8(rt, "UNSIGNED_SHORT_4_4_4_4")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "UNSIGNED_SHORT_5_5_5_1")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "UNSIGNED_SHORT_5_6_5")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "FRAGMENT_SHADER")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "VERTEX_SHADER")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "COMPILE_STATUS")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "DELETE_STATUS")); - } + /* Rendering primitives */ + /* Blending modes */ - return jsi::Value::undefined(); - } - ); - } else if (methodName == "checkFramebufferStatus") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 1, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { + ret.push_back(jsi::PropNameID::forUtf8(rt, "LINK_STATUS")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "VALIDATE_STATUS")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "ATTACHED_SHADERS")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "ACTIVE_ATTRIBUTES")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "ACTIVE_UNIFORMS")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "MAX_VERTEX_ATTRIBS")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "MAX_VERTEX_UNIFORM_VECTORS")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "MAX_VARYING_VECTORS")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "MAX_COMBINED_TEXTURE_IMAGE_UNITS")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "MAX_VERTEX_TEXTURE_IMAGE_UNITS")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "MAX_TEXTURE_IMAGE_UNITS")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "MAX_FRAGMENT_UNIFORM_VECTORS")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "SHADER_TYPE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "SHADING_LANGUAGE_VERSION")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "CURRENT_PROGRAM")); - if (count > 0) { + /* Blending modes */ - if (arguments[0].isNumber()) { - auto target = (uint32_t) arguments[0].asNumber(); + ret.push_back(jsi::PropNameID::forUtf8(rt, "NEVER")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "LESS")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "EQUAL")); - auto ret = canvas_native_webgl_check_frame_buffer_status( - target, - this->GetState() - ); - return {(int32_t) ret}; - } - } + /* Blending equations */ - return jsi::Value::undefined(); - } - ); - } else if (methodName == "clearColor") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 4, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { + /* Getting GL parameter information */ + + ret.push_back(jsi::PropNameID::forUtf8(rt, "LEQUAL")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "GREATER")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "NOTEQUAL")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "GEQUAL")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "ALWAYS")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "KEEP")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "REPLACE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "INCR")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "DECR")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "INVERT")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "INCR_WRAP")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "DECR_WRAP")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "NEAREST")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "LINEAR")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "NEAREST_MIPMAP_NEAREST")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "LINEAR_MIPMAP_NEAREST")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "NEAREST_MIPMAP_LINEAR")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "LINEAR_MIPMAP_LINEAR")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_MAG_FILTER")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_MIN_FILTER")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_WRAP_S")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_WRAP_T")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_2D")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_CUBE_MAP")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_BINDING_CUBE_MAP")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_CUBE_MAP_POSITIVE_X")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_CUBE_MAP_NEGATIVE_X")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_CUBE_MAP_POSITIVE_Y")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_CUBE_MAP_NEGATIVE_Y")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_CUBE_MAP_POSITIVE_Z")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE_CUBE_MAP_NEGATIVE_Z")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "MAX_CUBE_MAP_TEXTURE_SIZE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE0")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE1")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE2")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE3")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE4")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE5")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE6")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE7")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE8")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE9")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE10")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE11")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE12")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE13")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE14")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE15")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE16")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE17")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE18")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE19")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE20")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE21")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE22")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE23")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE24")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE25")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE26")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE27")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE28")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE29")); + /* Getting GL parameter information */ - if (count > 3) { - auto red = arguments[0].asNumber(); - auto green = arguments[1].asNumber(); - auto blue = arguments[2].asNumber(); - auto alpha = arguments[3].asNumber(); - - canvas_native_webgl_clear_color( - static_cast(red), - static_cast(green), - static_cast(blue), - static_cast(alpha), - this->GetState() - ); - } + /* Buffers */ - return jsi::Value::undefined(); - } - ); - } else if (methodName == "clearDepth") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 1, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE30")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "TEXTURE31")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "ACTIVE_TEXTURE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "REPEAT")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "CLAMP_TO_EDGE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "MIRRORED_REPEAT")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "FLOAT_VEC2")); - if (count > 0) { - auto depth = arguments[0].asNumber(); + /* Buffers */ - canvas_native_webgl_clear_depth( - static_cast(depth), - this->GetState() - ); - } + /* Vertex attributes */ - return jsi::Value::undefined(); - } - ); - } else if (methodName == "clearStencil") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 1, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { + ret.push_back(jsi::PropNameID::forUtf8(rt, "FLOAT_VEC3")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "FLOAT_VEC4")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "INT_VEC2")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "INT_VEC3")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "INT_VEC4")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "BOOL")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "BOOL_VEC2")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "BOOL_VEC3")); - if (count > 0) { - auto stencil = (int32_t) arguments[0].asNumber(); - canvas_native_webgl_clear_stencil( - stencil, - this->GetState() - ); - } + /* Vertex attributes */ - return jsi::Value::undefined(); - } - ); - } else if (methodName == "clear") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 1, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { + /* Culling */ + + ret.push_back(jsi::PropNameID::forUtf8(rt, "BOOL_VEC4")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "FLOAT_MAT2")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "FLOAT_MAT3")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "FLOAT_MAT4")); + + /* Culling */ + + /* Enabling and disabling */ + + ret.push_back(jsi::PropNameID::forUtf8(rt, "SAMPLER_2D")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "SAMPLER_CUBE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "LOW_FLOAT")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "MEDIUM_FLOAT")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "HIGH_FLOAT")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "LOW_INT")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "MEDIUM_INT")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "HIGH_INT")); + + /* Enabling and disabling */ + + ret.push_back(jsi::PropNameID::forUtf8(rt, "FRAMEBUFFER")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "RENDERBUFFER")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "RGBA4")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "RGB5_A1")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "RGB565")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "DEPTH_COMPONENT16")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_INDEX8")); + /* Errors */ - //if (count > 0) { - auto mask = (uint32_t) arguments[0].asNumber(); + /* Front face directions */ - canvas_native_webgl_clear( - mask, - this->GetState() - ); + ret.push_back(jsi::PropNameID::forUtf8(rt, "DEPTH_STENCIL")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "RENDERBUFFER_WIDTH")); - this->UpdateInvalidateState(); - // } + /* Front face directions */ - return jsi::Value::undefined(); - } - ); - } else if (methodName == "colorMask") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 4, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { + /* Hints */ - if (count > 3) { - auto red = arguments[0].asBool(); - auto green = arguments[1].asBool(); - auto blue = arguments[2].asBool(); - auto alpha = arguments[3].asBool(); - - canvas_native_webgl_color_mask( - red, - green, - blue, - alpha, - this->GetState() - ); - } + ret.push_back(jsi::PropNameID::forUtf8(rt, "RENDERBUFFER_HEIGHT")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "RENDERBUFFER_INTERNAL_FORMAT")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "RENDERBUFFER_RED_SIZE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "RENDERBUFFER_GREEN_SIZE")); - return jsi::Value::undefined(); - } - ); - } else if (methodName == "commit") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 1, - [](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { + /* Hints */ - return jsi::Value::undefined(); - } - ); - } else if (methodName == "compileShader") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 1, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { + /* Data types */ - if (count > 0) { - auto shader = arguments[0].asObject( - runtime).asHostObject( - runtime); - if (shader != nullptr) { - canvas_native_webgl_compile_shader( - shader->GetShader(), - this->GetState() - ); - } - } - return jsi::Value::undefined(); - } - ); - } else if (methodName == "compressedTexImage2D") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 7, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { + ret.push_back(jsi::PropNameID::forUtf8(rt, "RENDERBUFFER_BLUE_SIZE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "RENDERBUFFER_ALPHA_SIZE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "RENDERBUFFER_DEPTH_SIZE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "RENDERBUFFER_STENCIL_SIZE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "FRAMEBUFFER_ATTACHMENT_OBJECT_NAME")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL")); - if (count == 6) { - auto target = (uint32_t) arguments[0].asNumber(); - auto level = (int32_t) arguments[1].asNumber(); - auto internalformat = (uint32_t) arguments[2].asNumber(); - auto width = (int32_t) arguments[3].asNumber(); - auto height = (int32_t) arguments[4].asNumber(); - auto border = (int32_t) arguments[5].asNumber(); + /* Data types */ - canvas_native_webgl_compressed_tex_image2d_none( - target, - level, - internalformat, - width, - height, - border, - this->GetState() - ); - } else if (count > 6) { - auto target = (uint32_t) arguments[0].asNumber(); - auto level = (int32_t) arguments[1].asNumber(); - auto internalformat = (uint32_t) arguments[2].asNumber(); - auto width = (int32_t) arguments[3].asNumber(); - auto height = (int32_t) arguments[4].asNumber(); - auto border = (int32_t) arguments[5].asNumber(); - if (arguments[6].isObject()) { - auto pixels = arguments[6].asObject( - runtime); - if (pixels.isTypedArray(runtime)) { - auto array = pixels.getTypedArray( - runtime); - auto buf = GetTypedArrayData( - runtime, array); - canvas_native_webgl_compressed_tex_image2d( - target, - level, - internalformat, - width, - height, - border, - buf, - this->GetState() - ); - } else if (pixels.isArrayBuffer( - runtime)) { - auto ab = pixels.getArrayBuffer( - runtime); - auto size = ab.size(runtime); - auto data = ab.data(runtime); - rust::Slice buf( - data, size); + /* Pixel formats */ - canvas_native_webgl_compressed_tex_image2d( - target, - level, - internalformat, - width, - height, - border, - buf, - this->GetState() - ); - } - } - } + ret.push_back(jsi::PropNameID::forUtf8(rt, "FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "COLOR_ATTACHMENT0")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "DEPTH_ATTACHMENT")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_ATTACHMENT")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "DEPTH_STENCIL_ATTACHMENT")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "NONE")); - return jsi::Value::undefined(); - } - ); - } else if (methodName == "compressedTexSubImage2D") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 8, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { + /* Pixel formats */ + /* Pixel types */ - if (count > 7) { - auto target = (uint32_t) arguments[0].asNumber(); - auto level = (int32_t) arguments[1].asNumber(); - auto xoffset = (int32_t) arguments[2].asNumber(); - auto yoffset = (int32_t) arguments[3].asNumber(); - auto width = (int32_t) arguments[4].asNumber(); - auto height = (int32_t) arguments[5].asNumber(); - auto format = (uint32_t) arguments[6].asNumber(); + ret.push_back(jsi::PropNameID::forUtf8(rt, "FRAMEBUFFER_COMPLETE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "FRAMEBUFFER_INCOMPLETE_ATTACHMENT")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT")); - if (arguments[7].isObject()) { - auto pixels = arguments[7].asObject( - runtime); - if (pixels.isTypedArray(runtime)) { - auto px = pixels.getTypedArray( - runtime); - auto buf = GetTypedArrayData( - runtime, px); - canvas_native_webgl_compressed_tex_sub_image2d( - target, - level, - xoffset, - yoffset, - width, - height, - format, - buf, - this->GetState() - ); - } else if (pixels.isArrayBuffer( - runtime)) { - auto buffer = pixels.getArrayBuffer( - runtime); - auto size = buffer.size( - runtime); - auto data = buffer.data( - runtime); - rust::Slice buf( - data, size); + /* Pixel types */ - canvas_native_webgl_compressed_tex_sub_image2d( - target, - level, - xoffset, - yoffset, - width, - height, - format, - buf, - this->GetState() - ); - } - } - } + /* Shaders */ - return jsi::Value::undefined(); - } - ); - } else if (methodName == "copyTexImage2D") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 8, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { + ret.push_back(jsi::PropNameID::forUtf8(rt, "FRAMEBUFFER_INCOMPLETE_DIMENSIONS")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "FRAMEBUFFER_UNSUPPORTED")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "FRAMEBUFFER_BINDING")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "RENDERBUFFER_BINDING")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "MAX_RENDERBUFFER_SIZE")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "INVALID_FRAMEBUFFER_OPERATION")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "UNPACK_FLIP_Y_WEBGL")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "UNPACK_PREMULTIPLY_ALPHA_WEBGL")); + ret.push_back(jsi::PropNameID::forUtf8(rt, "UNPACK_COLORSPACE_CONVERSION_WEBGL")); - if (count > 7) { - auto target = (uint32_t) arguments[0].asNumber(); - auto level = (int32_t) arguments[1].asNumber(); - auto internalformat = (uint32_t) arguments[2].asNumber(); - auto x = (int32_t) arguments[3].asNumber(); - auto y = (int32_t) arguments[4].asNumber(); - auto width = (int32_t) arguments[5].asNumber(); - auto height = (int32_t) arguments[6].asNumber(); - auto border = (int32_t) arguments[7].asNumber(); - - canvas_native_webgl_copy_tex_image2d( - target, - level, - internalformat, - x, - y, - width, - height, - border, - this->GetState() - ); - } + return ret; +} - return jsi::Value::undefined(); - } - ); - } else if (methodName == "copyTexSubImage2D") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 8, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { +jsi::Value WebGLRenderingContext::get(jsi::Runtime &runtime, const jsi::PropNameID &name) { + auto methodName = name.utf8(runtime); - if (count > 7) { - auto target = (uint32_t) arguments[0].asNumber(); - auto level = (int32_t) arguments[1].asNumber(); - auto xoffset = (int32_t) arguments[2].asNumber(); - auto yoffset = (int32_t) arguments[3].asNumber(); - auto x = (int32_t) arguments[4].asNumber(); - auto y = (int32_t) arguments[5].asNumber(); - auto width = (int32_t) arguments[6].asNumber(); - auto height = (int32_t) arguments[7].asNumber(); + auto prop_return = GetProperty(methodName); - canvas_native_webgl_copy_tex_sub_image2d( - target, - level, - xoffset, - yoffset, - x, - y, - width, - height, - this->GetState() - ); - } + if (!prop_return.isUndefined()) { + return prop_return; + } - return jsi::Value::undefined(); - } - ); - } else if (methodName == "createBuffer") { + + if (methodName == "createBuffer") { return jsi::Function::createFromHostFunction(runtime, jsi::PropNameID::forAscii(runtime, methodName), 0, diff --git a/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl/WebGLRenderingContext.h b/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl/WebGLRenderingContext.h index 00dee784a..3460992cc 100644 --- a/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl/WebGLRenderingContext.h +++ b/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl/WebGLRenderingContext.h @@ -67,7 +67,6 @@ class WebGLRenderingContext : public WebGLRenderingContextBase { WebGLRenderingContext(rust::Box state, WebGLRenderingVersion version); - static v8::Local GetCtor(v8::Isolate *isolate); static WebGLRenderingContext *GetPointer(const v8::Local &object); @@ -76,7 +75,7 @@ class WebGLRenderingContext : public WebGLRenderingContextBase { std::vector getPropertyNames(jsi::Runtime &rt) override; - jsi::Value GetParameterInternal(jsi::Runtime &runtime, uint32_t pnameValue, + v8::Local GetParameterInternal(v8::Isolate * isolate, uint32_t pnameValue, rust::Box result); static inline jsi::Value GetProperty(const std::string &methodName) { diff --git a/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl/WebGLShader.h b/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl/WebGLShader.h index 9fc5902da..fee3e3b6e 100644 --- a/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl/WebGLShader.h +++ b/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl/WebGLShader.h @@ -6,14 +6,39 @@ #include "rust/cxx.h" #include "canvas-cxx/src/lib.rs.h" -#include "v8runtime/V8Runtime.h" +#include "Helpers.h" -using namespace facebook; - -class JSI_EXPORT WebGLShader : public jsi::HostObject { +class WebGLShader { public: WebGLShader(uint32_t shader) : shader_(shader) {} + static v8::Local GetCtor(v8::Isolate *isolate) { + auto cache = Caches::Get(isolate); + auto ctor = cache->WebGLShaderTmpl.get(); + if (ctor != nullptr) { + return ctor->Get(isolate); + } + + v8::Local ctorTmpl = v8::FunctionTemplate::New(isolate); + ctorTmpl->InstanceTemplate()->SetInternalFieldCount(1); + ctorTmpl->SetClassName(ConvertToV8String(isolate, "WebGLShader")); + + auto tmpl = ctorTmpl->InstanceTemplate(); + tmpl->SetInternalFieldCount(1); + + cache->WebGLShaderTmpl = + std::make_unique>(isolate, ctorTmpl); + return ctorTmpl; + } + + static WebGLShader *GetPointer(const v8::Local &object) { + auto ptr = object->GetInternalField(0).As()->Value(); + if (ptr == nullptr) { + return nullptr; + } + return static_cast(ptr); + } + uint32_t GetShader() { return this->shader_; } diff --git a/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl/WebGLTexture.h b/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl/WebGLTexture.h index 0991aefc9..585ab665f 100644 --- a/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl/WebGLTexture.h +++ b/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl/WebGLTexture.h @@ -6,14 +6,39 @@ #include "rust/cxx.h" #include "canvas-cxx/src/lib.rs.h" -#include "v8runtime/V8Runtime.h" +#include "Helpers.h" -using namespace facebook; - -class JSI_EXPORT WebGLTexture : public jsi::HostObject { +class WebGLTexture { public: WebGLTexture(uint32_t texture) : texture_(texture) {} + static v8::Local GetCtor(v8::Isolate *isolate) { + auto cache = Caches::Get(isolate); + auto ctor = cache->WebGLTextureTmpl.get(); + if (ctor != nullptr) { + return ctor->Get(isolate); + } + + v8::Local ctorTmpl = v8::FunctionTemplate::New(isolate); + ctorTmpl->InstanceTemplate()->SetInternalFieldCount(1); + ctorTmpl->SetClassName(ConvertToV8String(isolate, "WebGLTexture")); + + auto tmpl = ctorTmpl->InstanceTemplate(); + tmpl->SetInternalFieldCount(1); + + cache->WebGLTextureTmpl = + std::make_unique>(isolate, ctorTmpl); + return ctorTmpl; + } + + static WebGLTexture *GetPointer(const v8::Local &object) { + auto ptr = object->GetInternalField(0).As()->Value(); + if (ptr == nullptr) { + return nullptr; + } + return static_cast(ptr); + } + uint32_t GetTexture() { return this->texture_; }