From 2f17c6ffccc7a3d42579e9d7c207245740dd1737 Mon Sep 17 00:00:00 2001 From: Osei Fortune Date: Sun, 8 Oct 2023 06:17:10 -0400 Subject: [PATCH] chore: updates --- .../canvas/src/main/cpp/JSIRuntime.cpp | 4 +- .../canvas/src/main/cpp/JSIRuntime.h | 2 - .../cpp/webgl2/WebGL2RenderingContext.cpp | 5787 ++++++++--------- .../main/cpp/webgl2/WebGL2RenderingContext.h | 2 +- 4 files changed, 2658 insertions(+), 3137 deletions(-) diff --git a/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/JSIRuntime.cpp b/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/JSIRuntime.cpp index cf1afa12d..ee6442bf4 100644 --- a/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/JSIRuntime.cpp +++ b/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/JSIRuntime.cpp @@ -18,7 +18,5 @@ extern "C" void NSMain(const v8::FunctionCallbackInfo &args) { return; } - auto rt = std::make_shared(isolate); - CanvasJSIModule::install(*rt, isolate); - jsi_runtime = std::move(rt); + CanvasJSIModule::install(isolate); } diff --git a/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/JSIRuntime.h b/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/JSIRuntime.h index 39ee1cdba..d5fe732c9 100644 --- a/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/JSIRuntime.h +++ b/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/JSIRuntime.h @@ -4,6 +4,4 @@ #include "CanvasJSIModule.h" -std::shared_ptr jsi_runtime; - extern "C" void NSMain(const v8::FunctionCallbackInfo &args); diff --git a/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl2/WebGL2RenderingContext.cpp b/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl2/WebGL2RenderingContext.cpp index 5a07012a8..1616589e3 100644 --- a/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl2/WebGL2RenderingContext.cpp +++ b/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl2/WebGL2RenderingContext.cpp @@ -30,6 +30,7 @@ v8::Local WebGL2RenderingContext::GetCtor(v8::Isolate *iso tmpl->SetInternalFieldCount(1); WebGLRenderingContext::SetConstants(isolate, tmpl); SetConstants(isolate, tmpl); + SetMethods(isolate, tmpl); cache->WebGL2RenderingContextTmpl = std::make_unique>(isolate, ctorTmpl); return ctorTmpl; @@ -58,7 +59,7 @@ void WebGL2RenderingContext::BeginQuery(const v8::FunctionCallbackInfoNumberValue(context).ToChecked(); auto query = WebGLQuery::GetPointer(value.As()); - if(query != nullptr){ + if (query != nullptr) { canvas_native_webgl2_begin_query( target, query->GetQuery(), @@ -68,7 +69,8 @@ void WebGL2RenderingContext::BeginQuery(const v8::FunctionCallbackInfo &args) { +void +WebGL2RenderingContext::BeginTransformFeedback(const v8::FunctionCallbackInfo &args) { WebGL2RenderingContext *ptr = GetPointer(args.This()); if (ptr == nullptr) { return; @@ -164,7 +166,8 @@ void WebGL2RenderingContext::BindSampler(const v8::FunctionCallbackInfo &args) { +void +WebGL2RenderingContext::BindTransformFeedback(const v8::FunctionCallbackInfo &args) { WebGL2RenderingContext *ptr = GetPointer(args.This()); if (ptr == nullptr) { return; @@ -178,7 +181,8 @@ void WebGL2RenderingContext::BindTransformFeedback(const v8::FunctionCallbackInf if (type == NativeType::WebGLTransformFeedback) { auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); - auto transformFeedback = WebGLTransformFeedback::GetPointer(transformFeedbackValue.As()); + auto transformFeedback = WebGLTransformFeedback::GetPointer( + transformFeedbackValue.As()); canvas_native_webgl2_bind_transform_feedback( target, @@ -459,7 +463,7 @@ void WebGL2RenderingContext::ClientWaitSync(const v8::FunctionCallbackInfo 2 && type == NativeType::WebGLSync ) { + if (args.Length() > 2 && type == NativeType::WebGLSync) { auto sync = WebGLSyncImpl::GetPointer(syncValue.As()); if (sync != nullptr) { auto flags = (uint32_t) args[1]->NumberValue(context).ToChecked(); @@ -479,7 +483,8 @@ void WebGL2RenderingContext::ClientWaitSync(const v8::FunctionCallbackInfo &args) { +void +WebGL2RenderingContext::CompressedTexSubImage3D(const v8::FunctionCallbackInfo &args) { WebGL2RenderingContext *ptr = GetPointer(args.This()); if (ptr == nullptr) { return; @@ -511,7 +516,8 @@ void WebGL2RenderingContext::CompressedTexSubImage3D(const v8::FunctionCallbackI } size_t srcLengthOverride = 0; if (args[11]->IsNumber()) { - srcLengthOverride = static_cast(args[11]->NumberValue(context).ToChecked()); + srcLengthOverride = static_cast(args[11]->NumberValue( + context).ToChecked()); } @@ -649,7 +655,8 @@ void WebGL2RenderingContext::CreateSampler(const v8::FunctionCallbackInfo &args) { +void +WebGL2RenderingContext::CreateTransformFeedback(const v8::FunctionCallbackInfo &args) { WebGL2RenderingContext *ptr = GetPointer(args.This()); if (ptr == nullptr) { args.GetReturnValue().SetUndefined(); @@ -681,7 +688,8 @@ void WebGL2RenderingContext::CreateVertexArray(const v8::FunctionCallbackInfoGetState()); - auto vertexArrayObject = WebGLVertexArrayObject::NewInstance(isolate, new WebGLVertexArrayObject(ret)); + auto vertexArrayObject = WebGLVertexArrayObject::NewInstance(isolate, + new WebGLVertexArrayObject(ret)); args.GetReturnValue().Set(vertexArrayObject); } @@ -756,7 +764,8 @@ void WebGL2RenderingContext::DeleteSync(const v8::FunctionCallbackInfo &args) { +void +WebGL2RenderingContext::DeleteTransformFeedback(const v8::FunctionCallbackInfo &args) { WebGL2RenderingContext *ptr = GetPointer(args.This()); if (ptr == nullptr) { return; @@ -768,7 +777,8 @@ void WebGL2RenderingContext::DeleteTransformFeedback(const v8::FunctionCallbackI auto transformFeedbackValue = args[0]; auto type = GetNativeType(isolate, transformFeedbackValue); if (type == NativeType::WebGLTransformFeedback) { - auto transformFeedback = WebGLTransformFeedback::GetPointer(transformFeedbackValue.As()); + auto transformFeedback = WebGLTransformFeedback::GetPointer( + transformFeedbackValue.As()); if (transformFeedback != nullptr) { canvas_native_webgl2_delete_transform_feedback( @@ -857,7 +867,8 @@ void WebGL2RenderingContext::DrawBuffers(const v8::FunctionCallbackInfo &args) { +void +WebGL2RenderingContext::DrawElementsInstanced(const v8::FunctionCallbackInfo &args) { WebGL2RenderingContext *ptr = GetPointer(args.This()); if (ptr == nullptr) { return; @@ -968,7 +979,8 @@ void WebGL2RenderingContext::FenceSync(const v8::FunctionCallbackInfo } } -void WebGL2RenderingContext::FramebufferTextureLayer(const v8::FunctionCallbackInfo &args) { +void +WebGL2RenderingContext::FramebufferTextureLayer(const v8::FunctionCallbackInfo &args) { WebGL2RenderingContext *ptr = GetPointer(args.This()); if (ptr == nullptr) { args.GetReturnValue().SetUndefined(); @@ -1001,7 +1013,8 @@ void WebGL2RenderingContext::FramebufferTextureLayer(const v8::FunctionCallbackI } } -void WebGL2RenderingContext::GetActiveUniformBlockName(const v8::FunctionCallbackInfo &args) { +void +WebGL2RenderingContext::GetActiveUniformBlockName(const v8::FunctionCallbackInfo &args) { WebGL2RenderingContext *ptr = GetPointer(args.This()); if (ptr == nullptr) { args.GetReturnValue().SetEmptyString(); @@ -1031,7 +1044,8 @@ void WebGL2RenderingContext::GetActiveUniformBlockName(const v8::FunctionCallbac args.GetReturnValue().SetEmptyString(); } -void WebGL2RenderingContext::GetActiveUniformBlockParameter(const v8::FunctionCallbackInfo &args) { +void WebGL2RenderingContext::GetActiveUniformBlockParameter( + const v8::FunctionCallbackInfo &args) { WebGL2RenderingContext *ptr = GetPointer(args.This()); if (ptr == nullptr) { args.GetReturnValue().SetNull(); @@ -1072,12 +1086,11 @@ void WebGL2RenderingContext::GetActiveUniformBlockParameter(const v8::FunctionCa std::move(value)); - 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; + delete (VecMutableBuffer *) deleter_data; } }, buf); @@ -1143,7 +1156,7 @@ void WebGL2RenderingContext::GetActiveUniforms(const v8::FunctionCallbackInfoSet( context, j, v8::Number::New(isolate, - (double )item)); + (double) item)); } args.GetReturnValue().Set(array); return; @@ -1181,7 +1194,7 @@ void WebGL2RenderingContext::GetActiveUniforms(const v8::FunctionCallbackInfo WebGL2RenderingContext::getPropertyNames(jsi::Runtime &rt) { - std::vector ret; - - // gl2 + gl1 props - ret.reserve(353 + 434); - - // 351 - ret.push_back(jsi::PropNameID::forAscii(rt, "beginQuery")); - ret.push_back(jsi::PropNameID::forAscii(rt, "beginTransformFeedback")); - ret.push_back(jsi::PropNameID::forAscii(rt, "bindBufferBase")); - ret.push_back(jsi::PropNameID::forAscii(rt, "bindBufferRange")); - ret.push_back(jsi::PropNameID::forAscii(rt, "bindSampler")); - ret.push_back(jsi::PropNameID::forAscii(rt, "bindTransformFeedback")); - ret.push_back(jsi::PropNameID::forAscii(rt, "bindVertexArray")); - ret.push_back(jsi::PropNameID::forAscii(rt, "blitFramebuffer")); - ret.push_back(jsi::PropNameID::forAscii(rt, "clearBufferfi")); - ret.push_back(jsi::PropNameID::forAscii(rt, "clearBufferfv")); - ret.push_back(jsi::PropNameID::forAscii(rt, "clearBufferiv")); - ret.push_back(jsi::PropNameID::forAscii(rt, "clearBufferuiv")); - ret.push_back(jsi::PropNameID::forAscii(rt, "clientWaitSync")); - ret.push_back(jsi::PropNameID::forAscii(rt, "compressedTexSubImage3D")); - ret.push_back(jsi::PropNameID::forAscii(rt, "copyBufferSubData")); - ret.push_back(jsi::PropNameID::forAscii(rt, "copyTexSubImage3D")); - ret.push_back(jsi::PropNameID::forAscii(rt, "createQuery")); - ret.push_back(jsi::PropNameID::forAscii(rt, "createSampler")); - ret.push_back(jsi::PropNameID::forAscii(rt, "createTransformFeedback")); - ret.push_back(jsi::PropNameID::forAscii(rt, "createVertexArray")); - ret.push_back(jsi::PropNameID::forAscii(rt, "deleteQuery")); - ret.push_back(jsi::PropNameID::forAscii(rt, "deleteSampler")); - ret.push_back(jsi::PropNameID::forAscii(rt, "deleteSync")); - ret.push_back(jsi::PropNameID::forAscii(rt, "deleteTransformFeedback")); - ret.push_back(jsi::PropNameID::forAscii(rt, "deleteVertexArray")); - ret.push_back(jsi::PropNameID::forAscii(rt, "drawArraysInstanced")); - ret.push_back(jsi::PropNameID::forAscii(rt, "drawBuffers")); - ret.push_back(jsi::PropNameID::forAscii(rt, "drawElementsInstanced")); - ret.push_back(jsi::PropNameID::forAscii(rt, "drawRangeElements")); - ret.push_back(jsi::PropNameID::forAscii(rt, "endQuery")); - ret.push_back(jsi::PropNameID::forAscii(rt, "endTransformFeedback")); - ret.push_back(jsi::PropNameID::forAscii(rt, "fenceSync")); - ret.push_back(jsi::PropNameID::forAscii(rt, "framebufferTextureLayer")); - ret.push_back(jsi::PropNameID::forAscii(rt, "uniform1ui")); - ret.push_back(jsi::PropNameID::forAscii(rt, "uniform1uiv")); - ret.push_back(jsi::PropNameID::forAscii(rt, "uniform2ui")); - ret.push_back(jsi::PropNameID::forAscii(rt, "uniform2uiv")); - ret.push_back(jsi::PropNameID::forAscii(rt, "uniform3ui")); - ret.push_back(jsi::PropNameID::forAscii(rt, "uniform3uiv")); - ret.push_back(jsi::PropNameID::forAscii(rt, "uniform4ui")); - ret.push_back(jsi::PropNameID::forAscii(rt, "uniform4uiv")); - ret.push_back(jsi::PropNameID::forAscii(rt, "uniformBlockBinding")); - ret.push_back(jsi::PropNameID::forAscii(rt, "uniformMatrix2x3fv")); - ret.push_back(jsi::PropNameID::forAscii(rt, "uniformMatrix2x4fv")); - ret.push_back(jsi::PropNameID::forAscii(rt, "uniformMatrix3x2fv")); - ret.push_back(jsi::PropNameID::forAscii(rt, "uniformMatrix3x4fv")); - ret.push_back(jsi::PropNameID::forAscii(rt, "uniformMatrix4x2fv")); - ret.push_back(jsi::PropNameID::forAscii(rt, "uniformMatrix4x3fv")); - ret.push_back(jsi::PropNameID::forAscii(rt, "vertexAttribDivisor")); - ret.push_back(jsi::PropNameID::forAscii(rt, "vertexAttribI4i")); - ret.push_back(jsi::PropNameID::forAscii(rt, "vertexAttribI4iv")); - ret.push_back(jsi::PropNameID::forAscii(rt, "vertexAttribI4ui")); - ret.push_back(jsi::PropNameID::forAscii(rt, "vertexAttribI4uiv")); - ret.push_back(jsi::PropNameID::forAscii(rt, "getActiveUniformBlockName")); - ret.push_back(jsi::PropNameID::forAscii(rt, "getActiveUniformBlockParameter")); - ret.push_back(jsi::PropNameID::forAscii(rt, "getActiveUniforms")); - ret.push_back(jsi::PropNameID::forAscii(rt, "getBufferSubData")); - ret.push_back(jsi::PropNameID::forAscii(rt, "getFragDataLocation")); - ret.push_back(jsi::PropNameID::forAscii(rt, "getIndexedParameter")); - ret.push_back(jsi::PropNameID::forAscii(rt, "getInternalformatParameter")); - ret.push_back(jsi::PropNameID::forAscii(rt, "getParameter")); - ret.push_back(jsi::PropNameID::forAscii(rt, "getQueryParameter")); - ret.push_back(jsi::PropNameID::forAscii(rt, "getQuery")); - ret.push_back(jsi::PropNameID::forAscii(rt, "getSamplerParameter")); - ret.push_back(jsi::PropNameID::forAscii(rt, "getSyncParameter")); - ret.push_back(jsi::PropNameID::forAscii(rt, "getTransformFeedbackVarying")); - ret.push_back(jsi::PropNameID::forAscii(rt, "getUniformBlockIndex")); - ret.push_back(jsi::PropNameID::forAscii(rt, "getUniformIndices")); - ret.push_back(jsi::PropNameID::forAscii(rt, "invalidateFramebuffer")); - ret.push_back(jsi::PropNameID::forAscii(rt, "invalidateSubFramebuffer")); - ret.push_back(jsi::PropNameID::forAscii(rt, "isQuery")); - ret.push_back(jsi::PropNameID::forAscii(rt, "isSampler")); - ret.push_back(jsi::PropNameID::forAscii(rt, "isSync")); - ret.push_back(jsi::PropNameID::forAscii(rt, "isTransformFeedback")); - ret.push_back(jsi::PropNameID::forAscii(rt, "isVertexArray")); - ret.push_back(jsi::PropNameID::forAscii(rt, "pauseTransformFeedback")); - ret.push_back(jsi::PropNameID::forAscii(rt, "readBuffer")); - ret.push_back(jsi::PropNameID::forAscii(rt, "renderbufferStorageMultisample")); - ret.push_back(jsi::PropNameID::forAscii(rt, "resumeTransformFeedback")); - ret.push_back(jsi::PropNameID::forAscii(rt, "samplerParameterf")); - ret.push_back(jsi::PropNameID::forAscii(rt, "samplerParameteri")); - ret.push_back(jsi::PropNameID::forAscii(rt, "texImage3D")); - ret.push_back(jsi::PropNameID::forAscii(rt, "texStorage2D")); - ret.push_back(jsi::PropNameID::forAscii(rt, "texStorage3D")); - ret.push_back(jsi::PropNameID::forAscii(rt, "texSubImage3D")); - ret.push_back(jsi::PropNameID::forAscii(rt, "transformFeedbackVaryings")); - - - ret.push_back(jsi::PropNameID::forAscii(rt, "READ_BUFFER")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "UNPACK_ROW_LENGTH")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "UNPACK_SKIP_ROWS")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "UNPACK_SKIP_PIXELS")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "PACK_ROW_LENGTH")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "PACK_SKIP_ROWS")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "PACK_SKIP_PIXELS")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "TEXTURE_BINDING_3D")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "UNPACK_SKIP_IMAGES")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "UNPACK_IMAGE_HEIGHT")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_3D_TEXTURE_SIZE")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_ELEMENTS_VERTICES")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_ELEMENTS_INDICES")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_TEXTURE_LOD_BIAS")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_FRAGMENT_UNIFORM_COMPONENTS")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_VERTEX_UNIFORM_COMPONENTS")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_ARRAY_TEXTURE_LAYERS")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "MIN_PROGRAM_TEXEL_OFFSET")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_PROGRAM_TEXEL_OFFSET")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_VARYING_COMPONENTS")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "FRAGMENT_SHADER_DERIVATIVE_HINT")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "RASTERIZER_DISCARD")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "VERTEX_ARRAY_BINDING")); - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_VERTEX_OUTPUT_COMPONENTS")); - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_FRAGMENT_INPUT_COMPONENTS")); - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_SERVER_WAIT_TIMEOUT")); - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_ELEMENT_INDEX")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "RED")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RGB8")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RGBA8")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RGB10_A2")); - ret.push_back(jsi::PropNameID::forAscii(rt, "TEXTURE_3D")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "TEXTURE_WRAP_R")); - ret.push_back(jsi::PropNameID::forAscii(rt, "TEXTURE_MIN_LOD")); - ret.push_back(jsi::PropNameID::forAscii(rt, "TEXTURE_MAX_LOD")); - ret.push_back(jsi::PropNameID::forAscii(rt, "TEXTURE_BASE_LEVEL")); - ret.push_back(jsi::PropNameID::forAscii(rt, "TEXTURE_MAX_LEVEL")); - +void WebGL2RenderingContext::GetBufferSubData(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + args.GetReturnValue().SetNull(); + return; + } - ret.push_back(jsi::PropNameID::forAscii(rt, "TEXTURE_COMPARE_MODE")); - ret.push_back(jsi::PropNameID::forAscii(rt, "TEXTURE_COMPARE_FUNC")); - ret.push_back(jsi::PropNameID::forAscii(rt, "SRGB")); - ret.push_back(jsi::PropNameID::forAscii(rt, "SRGB8")); - ret.push_back(jsi::PropNameID::forAscii(rt, "SRGB8_ALPHA8")); + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - ret.push_back(jsi::PropNameID::forAscii(rt, "COMPARE_REF_TO_TEXTURE")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RGBA32F")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RGB32F")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RGBA16F")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RGB16F")); + auto dstDataObject = args[2]; + if (args.Length() >= 3 && + dstDataObject->IsObject()) { + auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); + auto srcByteOffset = args[1]->NumberValue(context).ToChecked(); - ret.push_back(jsi::PropNameID::forAscii(rt, "TEXTURE_2D_ARRAY")); - ret.push_back(jsi::PropNameID::forAscii(rt, "TEXTURE_BINDING_2D_ARRAY")); - ret.push_back(jsi::PropNameID::forAscii(rt, "R11F_G11F_B10F")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RGB9_E5")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RGBA32UI")); + if (dstDataObject->IsTypedArray()) { + auto array = dstDataObject.As(); + auto slice = GetTypedArrayData(array); - ret.push_back(jsi::PropNameID::forAscii(rt, "RGB32UI")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RGBA16UI")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RGB16UI")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RGBA8UI")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RGB8UI")); + auto BYTES_PER_ELEMENT = (ssize_t) array->Get( + context, + ConvertToV8String(isolate, "BYTES_PER_ELEMENT")).ToLocalChecked()->NumberValue( + context).ToChecked(); + ssize_t dstOffsetValue = 0; + if (args[3]->IsNumber()) { + dstOffsetValue = + static_cast(args[3]->NumberValue(context).ToChecked()) * + BYTES_PER_ELEMENT; + } - ret.push_back(jsi::PropNameID::forAscii(rt, "RGBA32I")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RGB32I")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RGBA16I")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RGB16I")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RGBA8I")); + ssize_t lengthValue = 0; + if (args[4]->IsNumber()) { + lengthValue = + static_cast(args[4]->NumberValue(context).ToChecked()) * + BYTES_PER_ELEMENT; + } + canvas_native_webgl2_get_buffer_sub_data( + target, + static_cast(srcByteOffset), + slice, + dstOffsetValue, + lengthValue, + ptr->GetState() + ); + } + } +} - ret.push_back(jsi::PropNameID::forAscii(rt, "RGB8I")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RED_INTEGER")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RGB_INTEGER")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RGBA_INTEGER")); - ret.push_back(jsi::PropNameID::forAscii(rt, "R8")); +void WebGL2RenderingContext::GetFragDataLocation(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + args.GetReturnValue().SetNull(); + return; + } + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - ret.push_back(jsi::PropNameID::forAscii(rt, "RG8")); - ret.push_back(jsi::PropNameID::forAscii(rt, "R16F")); - ret.push_back(jsi::PropNameID::forAscii(rt, "R32F")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RG16F")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RG32F")); + auto programValue = args[0]; + auto nameValue = args[1]; + auto type = GetNativeType(isolate, programValue); + if (type == NativeType::WebGLProgram && nameValue->IsString()) { + auto program = WebGLProgram::GetPointer(programValue.As()); + if (program != nullptr) { + auto name = ConvertFromV8String(isolate, nameValue); - ret.push_back(jsi::PropNameID::forAscii(rt, "R8I")); - ret.push_back(jsi::PropNameID::forAscii(rt, "R8UI")); - ret.push_back(jsi::PropNameID::forAscii(rt, "R16I")); - ret.push_back(jsi::PropNameID::forAscii(rt, "R16UI")); - ret.push_back(jsi::PropNameID::forAscii(rt, "R32I")); + auto ret = canvas_native_webgl2_get_frag_data_location( + program->GetProgram(), + rust::Str(name.c_str()), + ptr->GetState() + ); + args.GetReturnValue().Set(ret); - ret.push_back(jsi::PropNameID::forAscii(rt, "R32UI")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RG8I")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RG8UI")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RG16I")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RG16UI")); + return; + } + } + args.GetReturnValue().SetNull(); +} - ret.push_back(jsi::PropNameID::forAscii(rt, "RG32I")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RG32UI")); - ret.push_back(jsi::PropNameID::forAscii(rt, "R8_SNORM")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RG8_SNORM")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RGB8_SNORM")); +void WebGL2RenderingContext::GetIndexedParameter(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + args.GetReturnValue().SetNull(); + return; + } + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - ret.push_back(jsi::PropNameID::forAscii(rt, "RGBA8_SNORM")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RGB10_A2UI")); - ret.push_back(jsi::PropNameID::forAscii(rt, "TEXTURE_IMMUTABLE_FORMAT")); - ret.push_back(jsi::PropNameID::forAscii(rt, "TEXTURE_IMMUTABLE_LEVELS")); - ret.push_back(jsi::PropNameID::forAscii(rt, "UNSIGNED_INT_2_10_10_10_REV")); + if (args.Length() > 1) { + auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); + auto index = (uint32_t) args[1]->NumberValue(context).ToChecked(); + auto ret = canvas_native_webgl2_get_indexed_parameter( + target, + index, + ptr->GetState() + ); + switch (target) { + case GL_UNIFORM_BUFFER_BINDING: + case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: { + auto buffer = canvas_native_webgl2_indexed_parameter_get_buffer_value( + *ret); - ret.push_back(jsi::PropNameID::forAscii(rt, "UNSIGNED_INT_10F_11F_11F_REV")); - ret.push_back(jsi::PropNameID::forAscii(rt, "UNSIGNED_INT_5_9_9_9_REV")); - ret.push_back(jsi::PropNameID::forAscii(rt, "FLOAT_32_UNSIGNED_INT_24_8_REV")); - ret.push_back(jsi::PropNameID::forAscii(rt, "UNSIGNED_INT_24_8")); - ret.push_back(jsi::PropNameID::forAscii(rt, "HALF_FLOAT")); - - - ret.push_back(jsi::PropNameID::forAscii(rt, "RG")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RG_INTEGER")); - ret.push_back(jsi::PropNameID::forAscii(rt, "INT_2_10_10_10_REV")); - ret.push_back(jsi::PropNameID::forAscii(rt, "QUERY_RESULT_AVAILABLE")); - ret.push_back(jsi::PropNameID::forAscii(rt, "QUERY_RESULT")); + args.GetReturnValue().Set( + WebGLBuffer::NewInstance(isolate, new WebGLBuffer(buffer))); + } + return; + case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE: + case GL_TRANSFORM_FEEDBACK_BUFFER_START: + case GL_UNIFORM_BUFFER_SIZE: + case GL_UNIFORM_BUFFER_START: { + auto value = canvas_native_webgl2_indexed_parameter_get_value( + *ret); + args.GetReturnValue().Set(static_cast(value)); + return; + } + break; + default: + args.GetReturnValue().SetNull(); + return; + } + } + args.GetReturnValue().SetNull(); +} +void WebGL2RenderingContext::GetInternalformatParameter( + const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + args.GetReturnValue().SetNull(); + return; + } - ret.push_back(jsi::PropNameID::forAscii(rt, "CURRENT_QUERY")); - ret.push_back(jsi::PropNameID::forAscii(rt, "ANY_SAMPLES_PASSED")); - ret.push_back(jsi::PropNameID::forAscii(rt, "ANY_SAMPLES_PASSED_CONSERVATIVE")); - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_DRAW_BUFFERS")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "DRAW_BUFFER0")); - ret.push_back(jsi::PropNameID::forAscii(rt, "DRAW_BUFFER1")); - ret.push_back(jsi::PropNameID::forAscii(rt, "DRAW_BUFFER2")); - ret.push_back(jsi::PropNameID::forAscii(rt, "DRAW_BUFFER3)")); - ret.push_back(jsi::PropNameID::forAscii(rt, "DRAW_BUFFER4")); - ret.push_back(jsi::PropNameID::forAscii(rt, "DRAW_BUFFER5")); - ret.push_back(jsi::PropNameID::forAscii(rt, "DRAW_BUFFER6")); - ret.push_back(jsi::PropNameID::forAscii(rt, "DRAW_BUFFER7")); - ret.push_back(jsi::PropNameID::forAscii(rt, "DRAW_BUFFER8")); - ret.push_back(jsi::PropNameID::forAscii(rt, "DRAW_BUFFER9")); - ret.push_back(jsi::PropNameID::forAscii(rt, "DRAW_BUFFER10")); + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - /* Getting GL parameter information */ + if (args.Length() > 2) { + auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); + auto internalformat = (uint32_t) args[1]->NumberValue(context).ToChecked(); + auto pname = (uint32_t) args[2]->NumberValue(context).ToChecked(); + switch (internalformat) { + case GL_RGB: + case GL_RGBA: + case GL_R8UI: + case GL_R8I: + case GL_R16UI: + case GL_R16I: + case GL_R32UI: + case GL_R32I: + case GL_RG8UI: + case GL_RG8I: + case GL_RG16UI: + case GL_RG16I: + case GL_RG32UI: + case GL_RG32I: + case GL_RGBA8UI: + case GL_RGBA8I: + case GL_RGB10_A2UI: + case GL_RGBA16UI: + case GL_RGBA16I: + case GL_RGBA32UI: + case GL_RGBA32I: { + // empty + + auto value = rust::Vec(); + auto buf = new VecMutableBuffer( + std::move(value)); + + 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)); + args.GetReturnValue().Set(v8::Int32Array::New(arraybuffer, 0, buf->size())); + return; + } + case GL_R8: + case GL_RG8: + case GL_RGB565: + case GL_RGBA8: + case GL_SRGB8_ALPHA8: + case GL_RGB5_A1: + case GL_RGBA4: + case GL_RGB10_A2: + case GL_DEPTH_COMPONENT16: + case GL_DEPTH_COMPONENT24: + case GL_DEPTH_COMPONENT32F: + case GL_DEPTH24_STENCIL8: + case GL_DEPTH32F_STENCIL8: + case GL_STENCIL_INDEX8: + // noop + break; + case GL_R16F: + case GL_RG16F: + case GL_R32F: + case GL_RG32F: + case GL_RGBA32F: + case GL_R11F_G11F_B10F: + // noop + break; + default: + args.GetReturnValue().SetNull(); + return; + } - /* Textures */ - ret.push_back(jsi::PropNameID::forAscii(rt, "DRAW_BUFFER11")); - ret.push_back(jsi::PropNameID::forAscii(rt, "DRAW_BUFFER12")); - ret.push_back(jsi::PropNameID::forAscii(rt, "DRAW_BUFFER13")); - ret.push_back(jsi::PropNameID::forAscii(rt, "DRAW_BUFFER14")); - ret.push_back(jsi::PropNameID::forAscii(rt, "DRAW_BUFFER15")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_COLOR_ATTACHMENTS")); - ret.push_back(jsi::PropNameID::forAscii(rt, "COLOR_ATTACHMENT1")); - ret.push_back(jsi::PropNameID::forAscii(rt, "COLOR_ATTACHMENT2")); - ret.push_back(jsi::PropNameID::forAscii(rt, "COLOR_ATTACHMENT3")); - ret.push_back(jsi::PropNameID::forAscii(rt, "COLOR_ATTACHMENT4")); - ret.push_back(jsi::PropNameID::forAscii(rt, "COLOR_ATTACHMENT5")); - ret.push_back(jsi::PropNameID::forAscii(rt, "COLOR_ATTACHMENT6")); - ret.push_back(jsi::PropNameID::forAscii(rt, "COLOR_ATTACHMENT7")); - ret.push_back(jsi::PropNameID::forAscii(rt, "COLOR_ATTACHMENT8")); - ret.push_back(jsi::PropNameID::forAscii(rt, "COLOR_ATTACHMENT9")); - ret.push_back(jsi::PropNameID::forAscii(rt, "COLOR_ATTACHMENT10")); - ret.push_back(jsi::PropNameID::forAscii(rt, "COLOR_ATTACHMENT11")); - ret.push_back(jsi::PropNameID::forAscii(rt, "COLOR_ATTACHMENT12")); - ret.push_back(jsi::PropNameID::forAscii(rt, "COLOR_ATTACHMENT13")); - ret.push_back(jsi::PropNameID::forAscii(rt, "COLOR_ATTACHMENT14")); - ret.push_back(jsi::PropNameID::forAscii(rt, "COLOR_ATTACHMENT15")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "SAMPLER_3D")); - ret.push_back(jsi::PropNameID::forAscii(rt, "SAMPLER_2D_SHADOW")); - ret.push_back(jsi::PropNameID::forAscii(rt, "SAMPLER_2D_ARRAY")); - ret.push_back(jsi::PropNameID::forAscii(rt, "SAMPLER_2D_ARRAY_SHADOW")); - ret.push_back(jsi::PropNameID::forAscii(rt, "SAMPLER_CUBE_SHADOW")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "INT_SAMPLER_2D")); - ret.push_back(jsi::PropNameID::forAscii(rt, "INT_SAMPLER_3D")); - ret.push_back(jsi::PropNameID::forAscii(rt, "INT_SAMPLER_CUBE")); - ret.push_back(jsi::PropNameID::forAscii(rt, "INT_SAMPLER_2D_ARRAY")); - ret.push_back(jsi::PropNameID::forAscii(rt, "UNSIGNED_INT_SAMPLER_2D")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "UNSIGNED_INT_SAMPLER_3D")); - ret.push_back(jsi::PropNameID::forAscii(rt, "UNSIGNED_INT_SAMPLER_CUBE")); - ret.push_back(jsi::PropNameID::forAscii(rt, "UNSIGNED_INT_SAMPLER_2D_ARRAY")); - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_SAMPLES")); - ret.push_back(jsi::PropNameID::forAscii(rt, "SAMPLER_BINDING")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "PIXEL_PACK_BUFFER")); - ret.push_back(jsi::PropNameID::forAscii(rt, "PIXEL_UNPACK_BUFFER")); - ret.push_back(jsi::PropNameID::forAscii(rt, "PIXEL_PACK_BUFFER_BINDING")); - ret.push_back(jsi::PropNameID::forAscii(rt, "PIXEL_UNPACK_BUFFER_BINDING")); - ret.push_back(jsi::PropNameID::forAscii(rt, "COPY_READ_BUFFER")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "COPY_WRITE_BUFFER")); - ret.push_back(jsi::PropNameID::forAscii(rt, "COPY_READ_BUFFER_BINDING")); - ret.push_back(jsi::PropNameID::forAscii(rt, "COPY_WRITE_BUFFER_BINDING")); - ret.push_back(jsi::PropNameID::forAscii(rt, "FLOAT_MAT2x3")); - ret.push_back(jsi::PropNameID::forAscii(rt, "FLOAT_MAT2x4")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "FLOAT_MAT3x2")); - ret.push_back(jsi::PropNameID::forAscii(rt, "FLOAT_MAT3x4")); - ret.push_back(jsi::PropNameID::forAscii(rt, "FLOAT_MAT4x2")); - ret.push_back(jsi::PropNameID::forAscii(rt, "FLOAT_MAT4x3")); - ret.push_back(jsi::PropNameID::forAscii(rt, "UNSIGNED_INT_VEC2")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "UNSIGNED_INT_VEC3")); - ret.push_back(jsi::PropNameID::forAscii(rt, "UNSIGNED_INT_VEC4")); - ret.push_back(jsi::PropNameID::forAscii(rt, "UNSIGNED_NORMALIZED")); - ret.push_back(jsi::PropNameID::forAscii(rt, "SIGNED_NORMALIZED")); + auto ret = canvas_native_webgl2_get_internalformat_parameter( + target, + internalformat, + pname, + ptr->GetState() + ); - /* Vertex attributes */ + if (pname == GL_SAMPLES) { + auto value = canvas_native_webgl_result_get_i32_array( + *ret); - ret.push_back(jsi::PropNameID::forAscii(rt, "VERTEX_ATTRIB_ARRAY_INTEGER")); - ret.push_back(jsi::PropNameID::forAscii(rt, "VERTEX_ATTRIB_ARRAY_DIVISOR")); - ret.push_back(jsi::PropNameID::forAscii(rt, "TRANSFORM_FEEDBACK_BUFFER_MODE")); - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS")); - ret.push_back(jsi::PropNameID::forAscii(rt, "TRANSFORM_FEEDBACK_VARYINGS")); + auto buf = new VecMutableBuffer( + std::move(value)); - ret.push_back(jsi::PropNameID::forAscii(rt, "TRANSFORM_FEEDBACK_BUFFER_START")); - ret.push_back(jsi::PropNameID::forAscii(rt, "TRANSFORM_FEEDBACK_BUFFER_SIZE")); - ret.push_back(jsi::PropNameID::forAscii(rt, "TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN")); - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS")); + 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); - /* Textures */ + auto arraybuffer = v8::ArrayBuffer::New(isolate, std::move(store)); + args.GetReturnValue().Set(v8::Int32Array::New(arraybuffer, 0, buf->size())); - /* Pixel types */ + return; + } else { + args.GetReturnValue().SetNull(); + return; + } + } + args.GetReturnValue().SetNull(); +} - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS")); - ret.push_back(jsi::PropNameID::forAscii(rt, "INTERLEAVED_ATTRIBS")); - ret.push_back(jsi::PropNameID::forAscii(rt, "SEPARATE_ATTRIBS")); - ret.push_back(jsi::PropNameID::forAscii(rt, "TRANSFORM_FEEDBACK_BUFFER")); - ret.push_back(jsi::PropNameID::forAscii(rt, "TRANSFORM_FEEDBACK_BUFFER_BINDING")); +void WebGL2RenderingContext::GetParameter(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + args.GetReturnValue().SetNull(); + return; + } - ret.push_back(jsi::PropNameID::forAscii(rt, "TRANSFORM_FEEDBACK")); - ret.push_back(jsi::PropNameID::forAscii(rt, "TRANSFORM_FEEDBACK_PAUSED")); - ret.push_back(jsi::PropNameID::forAscii(rt, "TRANSFORM_FEEDBACK_ACTIVE")); - ret.push_back(jsi::PropNameID::forAscii(rt, "TRANSFORM_FEEDBACK_BINDING")); + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - /* Pixel types */ + if (args.Length() > 0) { + auto pname = (uint32_t) args[0]->NumberValue(context).ToChecked(); + auto result = canvas_native_webgl2_get_parameter( + pname, + ptr->GetState()); + switch (pname) { + case GL_COPY_READ_BUFFER_BINDING: + case GL_COPY_WRITE_BUFFER_BINDING: + case GL_DRAW_FRAMEBUFFER_BINDING: + args.GetReturnValue().Set(canvas_native_webgl_result_get_i32( + *result)); + return; + default: { + auto ret = ptr->GetParameterInternal( + isolate, pname, + std::move(result)); + + args.GetReturnValue().Set(ret); + return; + } + } + } - /* Queries */ + args.GetReturnValue().SetNull(); +} - ret.push_back(jsi::PropNameID::forAscii(rt, "FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING")); - ret.push_back(jsi::PropNameID::forAscii(rt, "FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE")); - ret.push_back(jsi::PropNameID::forAscii(rt, "FRAMEBUFFER_ATTACHMENT_RED_SIZE")); - ret.push_back(jsi::PropNameID::forAscii(rt, "FRAMEBUFFER_ATTACHMENT_GREEN_SIZE")); - ret.push_back(jsi::PropNameID::forAscii(rt, "FRAMEBUFFER_ATTACHMENT_BLUE_SIZE")); +void WebGL2RenderingContext::GetQueryParameter(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + args.GetReturnValue().SetNull(); + return; + } - /* Queries */ + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - /* Draw buffers */ + if (args.Length() > 1) { + auto queryValue = args[0]; + auto type = GetNativeType(isolate, queryValue); + if (type == NativeType::WebGLQuery) { + auto query = WebGLQuery::GetPointer(queryValue.As()); + if (query != nullptr) { + auto pname = (uint32_t) args[1]->NumberValue(context).ToChecked(); + + + auto ret = canvas_native_webgl2_get_query_parameter( + query->GetQuery(), + pname, + ptr->GetState()); + if (pname == GL_QUERY_RESULT) { + args.GetReturnValue().Set(canvas_native_webgl_result_get_bool( + *ret)); + return; + } else if (pname == + GL_QUERY_RESULT_AVAILABLE) { + args.GetReturnValue().Set((int32_t) canvas_native_webgl_result_get_u32( + *ret)); + return; + } + } + } - ret.push_back(jsi::PropNameID::forAscii(rt, "FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE")); - ret.push_back(jsi::PropNameID::forAscii(rt, "FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE")); - ret.push_back(jsi::PropNameID::forAscii(rt, "FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE")); - ret.push_back(jsi::PropNameID::forAscii(rt, "FRAMEBUFFER_DEFAULT")); - ret.push_back(jsi::PropNameID::forAscii(rt, "DEPTH_STENCIL_ATTACHMENT")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "DEPTH_STENCIL")); - ret.push_back(jsi::PropNameID::forAscii(rt, "DEPTH24_STENCIL8")); - ret.push_back(jsi::PropNameID::forAscii(rt, "DRAW_FRAMEBUFFER_BINDING")); - ret.push_back(jsi::PropNameID::forAscii(rt, "READ_FRAMEBUFFER")); - ret.push_back(jsi::PropNameID::forAscii(rt, "DRAW_FRAMEBUFFER")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "READ_FRAMEBUFFER_BINDING")); - ret.push_back(jsi::PropNameID::forAscii(rt, "RENDERBUFFER_SAMPLES")); - ret.push_back(jsi::PropNameID::forAscii(rt, "FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER")); - ret.push_back(jsi::PropNameID::forAscii(rt, "FRAMEBUFFER_INCOMPLETE_MULTISAMPLE")); - ret.push_back(jsi::PropNameID::forAscii(rt, "UNIFORM_BUFFER")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "UNIFORM_BUFFER_BINDING")); - ret.push_back(jsi::PropNameID::forAscii(rt, "UNIFORM_BUFFER_START")); - ret.push_back(jsi::PropNameID::forAscii(rt, "UNIFORM_BUFFER_SIZE")); - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_VERTEX_UNIFORM_BLOCKS")); - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_FRAGMENT_UNIFORM_BLOCKS")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_COMBINED_UNIFORM_BLOCKS")); - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_UNIFORM_BUFFER_BINDINGS")); - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_UNIFORM_BLOCK_SIZE")); - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS")); - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "UNIFORM_BUFFER_OFFSET_ALIGNMENT")); - ret.push_back(jsi::PropNameID::forAscii(rt, "ACTIVE_UNIFORM_BLOCKS")); - ret.push_back(jsi::PropNameID::forAscii(rt, "UNIFORM_TYPE")); - ret.push_back(jsi::PropNameID::forAscii(rt, "UNIFORM_SIZE")); - ret.push_back(jsi::PropNameID::forAscii(rt, "UNIFORM_BLOCK_INDEX")); - - ret.push_back(jsi::PropNameID::forAscii(rt, "UNIFORM_OFFSET")); - ret.push_back(jsi::PropNameID::forAscii(rt, "UNIFORM_ARRAY_STRIDE")); - ret.push_back(jsi::PropNameID::forAscii(rt, "UNIFORM_MATRIX_STRIDE")); + } - /* Draw buffers */ + args.GetReturnValue().SetNull(); +} - /* Samplers */ +void WebGL2RenderingContext::GetQuery(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + args.GetReturnValue().SetNull(); + return; + } - ret.push_back(jsi::PropNameID::forAscii(rt, "UNIFORM_IS_ROW_MAJOR")); - ret.push_back(jsi::PropNameID::forAscii(rt, "UNIFORM_BLOCK_BINDING")); - ret.push_back(jsi::PropNameID::forAscii(rt, "UNIFORM_BLOCK_DATA_SIZE")); - ret.push_back(jsi::PropNameID::forAscii(rt, "UNIFORM_BLOCK_ACTIVE_UNIFORMS")); - ret.push_back(jsi::PropNameID::forAscii(rt, "UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES")); + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - ret.push_back(jsi::PropNameID::forAscii(rt, "UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER")); - ret.push_back(jsi::PropNameID::forAscii(rt, "UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER")); - ret.push_back(jsi::PropNameID::forAscii(rt, "OBJECT_TYPE")); - ret.push_back(jsi::PropNameID::forAscii(rt, "SYNC_CONDITION")); - ret.push_back(jsi::PropNameID::forAscii(rt, "SYNC_STATUS")); + if (args.Length() > 1) { + auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); + auto pname = (uint32_t) args[1]->NumberValue(context).ToChecked(); + auto ret = canvas_native_webgl2_get_query( + target, + pname, + ptr->GetState()); + if (pname == GL_CURRENT_QUERY) { + args.GetReturnValue().Set(canvas_native_webgl_result_get_i32( + *ret)); + return; + } + } - ret.push_back(jsi::PropNameID::forAscii(rt, "SYNC_FLAGS")); - ret.push_back(jsi::PropNameID::forAscii(rt, "SYNC_FENCE")); - ret.push_back(jsi::PropNameID::forAscii(rt, "SYNC_GPU_COMMANDS_COMPLETE")); - ret.push_back(jsi::PropNameID::forAscii(rt, "UNSIGNALED")); - ret.push_back(jsi::PropNameID::forAscii(rt, "SIGNALED")); + args.GetReturnValue().SetNull(); +} - /* Samplers */ +void WebGL2RenderingContext::GetSamplerParameter(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + args.GetReturnValue().SetNull(); + return; + } - /* Buffers */ + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - ret.push_back(jsi::PropNameID::forAscii(rt, "ALREADY_SIGNALED")); - ret.push_back(jsi::PropNameID::forAscii(rt, "TIMEOUT_EXPIRED")); - ret.push_back(jsi::PropNameID::forAscii(rt, "CONDITION_SATISFIED")); - ret.push_back(jsi::PropNameID::forAscii(rt, "WAIT_FAILED")); - ret.push_back(jsi::PropNameID::forAscii(rt, "SYNC_FLUSH_COMMANDS_BIT")); + if (args.Length() > 1) { + auto samplerValue = args[0]; + auto type = GetNativeType(isolate, samplerValue); + if (type == NativeType::WebGLSampler) { + auto sampler = WebGLSampler::GetPointer(samplerValue.As()); + if (sampler != nullptr) { + auto pname = (uint32_t) args[1]->NumberValue(context).ToChecked(); + auto ret = canvas_native_webgl2_get_sampler_parameter( + sampler->GetSampler(), + pname, + ptr->GetState()); + + switch (pname) { + case GL_TEXTURE_MAX_LOD: + case GL_TEXTURE_MIN_LOD: + args.GetReturnValue().Set( + static_cast(canvas_native_webgl_result_get_f32( + *ret))); + return; + case GL_TEXTURE_COMPARE_FUNC: + case GL_TEXTURE_COMPARE_MODE: + case GL_TEXTURE_MAG_FILTER: + case GL_TEXTURE_MIN_FILTER: + case GL_TEXTURE_WRAP_R: + case GL_TEXTURE_WRAP_S: + case GL_TEXTURE_WRAP_T: + args.GetReturnValue().Set(canvas_native_webgl_result_get_i32( + *ret)); + return; + default: + args.GetReturnValue().SetNull(); + return; + } + } + } - ret.push_back(jsi::PropNameID::forAscii(rt, "COLOR")); - ret.push_back(jsi::PropNameID::forAscii(rt, "DEPTH")); - ret.push_back(jsi::PropNameID::forAscii(rt, "STENCIL")); + } - /* Buffers */ + args.GetReturnValue().SetNull(); +} - /* Data types */ +void WebGL2RenderingContext::GetSyncParameter(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + args.GetReturnValue().SetNull(); + return; + } - ret.push_back(jsi::PropNameID::forAscii(rt, "MIN")); - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX")); - ret.push_back(jsi::PropNameID::forAscii(rt, "DEPTH_COMPONENT24")); - ret.push_back(jsi::PropNameID::forAscii(rt, "STREAM_READ")); - ret.push_back(jsi::PropNameID::forAscii(rt, "STREAM_COPY")); + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - ret.push_back(jsi::PropNameID::forAscii(rt, "STATIC_READ")); - ret.push_back(jsi::PropNameID::forAscii(rt, "STATIC_COPY")); - ret.push_back(jsi::PropNameID::forAscii(rt, "DYNAMIC_READ")); - ret.push_back(jsi::PropNameID::forAscii(rt, "DYNAMIC_COPY")); - ret.push_back(jsi::PropNameID::forAscii(rt, "DEPTH_COMPONENT32F")); - ret.push_back(jsi::PropNameID::forAscii(rt, "DEPTH32F_STENCIL8")); + if (args.Length() > 1) { + auto syncValue = args[0]; + auto sync = WebGLSyncImpl::GetPointer(syncValue.As()); + if (sync != nullptr) { + auto pname = (uint32_t) args[1]->NumberValue(context).ToChecked(); + auto ret = canvas_native_webgl2_get_sync_parameter( + sync->GetSync(), + pname, + ptr->GetState()); - /* Data types */ + switch (pname) { + case GL_OBJECT_TYPE: + case GL_SYNC_STATUS: + case GL_SYNC_CONDITION: + case GL_SYNC_FLAGS: + args.GetReturnValue().Set(canvas_native_webgl_result_get_i32( + *ret)); + return; + default: + args.GetReturnValue().SetNull(); + return; + } + } + } - ret.push_back(jsi::PropNameID::forAscii(rt, "INVALID_INDEX")); - ret.push_back(jsi::PropNameID::forAscii(rt, "TIMEOUT_IGNORED")); + args.GetReturnValue().SetNull(); +} - /* Vertex attributes */ +void WebGL2RenderingContext::GetTransformFeedbackVarying( + const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + args.GetReturnValue().SetNull(); + return; + } - /* Transform feedback */ + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - ret.push_back(jsi::PropNameID::forAscii(rt, "MAX_CLIENT_WAIT_TIMEOUT_WEBGL")); + if (args.Length() > 1) { + auto programValue = args[0]; + auto type = GetNativeType(isolate, programValue); + if (type == NativeType::WebGLProgram) { + auto program = WebGLProgram::GetPointer(programValue.As()); + auto index = (uint32_t) args[1]->NumberValue(context).ToChecked(); + if (program != nullptr) { + auto ret = canvas_native_webgl2_get_transform_feedback_varying( + program->GetProgram(), + index, + ptr->GetState() + ); - /* Transform feedback */ + if (canvas_native_webgl_active_info_get_is_empty( + *ret)) { + args.GetReturnValue().SetNull(); + return; + } + auto info = WebGLActiveInfoImpl::NewInstance(isolate, new WebGLActiveInfoImpl( + std::move(ret))); + args.GetReturnValue().Set(info); + return; + } + } + } - /* GL 1 */ - - 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"))); - - ret.push_back(jsi::PropNameID::forUtf8(rt, "DEPTH_BUFFER_BIT")); - - ret.push_back(jsi::PropNameID::forUtf8(rt, "STENCIL_BUFFER_BIT")); - - ret.push_back(jsi::PropNameID::forUtf8(rt, "COLOR_BUFFER_BIT")); - - ret.push_back(jsi::PropNameID::forUtf8(rt, "POINTS")); - - ret.push_back(jsi::PropNameID::forUtf8(rt, "LINES")); - - ret.push_back(jsi::PropNameID::forUtf8(rt, "LINE_LOOP")); - - ret.push_back(jsi::PropNameID::forUtf8(rt, "LINE_STRIP")); - - ret.push_back(jsi::PropNameID::forUtf8(rt, "TRIANGLES")); - - ret.push_back(jsi::PropNameID::forUtf8(rt, "TRIANGLE_STRIP")); - - ret.push_back(jsi::PropNameID::forUtf8(rt, "TRIANGLE_FAN")); - - ret.push_back(jsi::PropNameID::forUtf8(rt, "ZERO")); - - ret.push_back(jsi::PropNameID::forUtf8(rt, "ONE")); - - ret.push_back(jsi::PropNameID::forUtf8(rt, "SRC_COLOR")); - - ret.push_back(jsi::PropNameID::forUtf8(rt, "ONE_MINUS_SRC_COLOR")); - - ret.push_back(jsi::PropNameID::forUtf8(rt, "SRC_ALPHA")); - - ret.push_back(jsi::PropNameID::forUtf8(rt, "ONE_MINUS_SRC_ALPHA")); - - ret.push_back(jsi::PropNameID::forUtf8(rt, "DST_ALPHA")); - - ret.push_back(jsi::PropNameID::forUtf8(rt, "ONE_MINUS_DST_ALPHA")); - - ret.push_back(jsi::PropNameID::forUtf8(rt, "DST_COLOR")); - - ret.push_back(jsi::PropNameID::forUtf8(rt, "ONE_MINUS_DST_COLOR")); - - ret.push_back(jsi::PropNameID::forUtf8(rt, "SRC_ALPHA_SATURATE")); - - - 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")); + args.GetReturnValue().SetNull(); +} +void WebGL2RenderingContext::GetUniformBlockIndex(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + args.GetReturnValue().SetNull(); + return; + } - /* Blending equations */ + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - 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")); + if (args.Length() > 1) { + auto programValue = args[0]; + auto type = GetNativeType(isolate, programValue); + if (type == NativeType::WebGLProgram) { + auto program = WebGLProgram::GetPointer(programValue.As()); + auto index = ConvertFromV8String(isolate, args[1]); + if (program != nullptr) { + auto ret = canvas_native_webgl2_get_uniform_block_index( + program->GetProgram(), + rust::Str(index.c_str()), + ptr->GetState()); + args.GetReturnValue().Set((int) ret); + return; + } + } + } - 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")); + args.GetReturnValue().SetNull(); +} +void WebGL2RenderingContext::GetUniformIndices(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + args.GetReturnValue().SetNull(); + return; + } - 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 isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + if (args.Length() > 1 && args[1]->IsObject()) { + auto programValue = args[0]; + auto type = GetNativeType(isolate, programValue); + if (type == NativeType::WebGLProgram) { + auto program = WebGLProgram::GetPointer(programValue.As()); + auto uniformNamesObject = args[1]; + if (program != nullptr && + uniformNamesObject->IsArray()) { + auto uniformNames = uniformNamesObject.As(); + auto len = uniformNames->Length(); + rust::Vec store; + store.reserve(len); + for (int j = 0; j < len; ++j) { + auto name = ConvertFromV8String(isolate, uniformNames->Get( + context, j).ToLocalChecked()); + rust::Str val(name.data(), + name.size()); + store.push_back(val); + } + rust::Slice slice( + store.data(), + store.size()); + auto ret = canvas_native_webgl2_get_uniform_indices( + program->GetProgram(), + slice, + ptr->GetState()); + + auto retSize = ret.size(); + auto result = v8::Array::New(isolate, (int) retSize); + for (int j = 0; j < retSize; ++j) { + auto item = ret[j]; + result->Set(context, + j, + v8::Number::New(isolate, + (int32_t) item)); + } - 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")); + args.GetReturnValue().Set(result); + 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")); + } - 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")); + args.GetReturnValue().SetNull(); +} - 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")); +void +WebGL2RenderingContext::InvalidateFramebuffer(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - 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")); + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - 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 attachments = args[1]; + if (args.Length() > 1 && attachments->IsObject()) { + auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); - 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")); + if (attachments->IsArray()) { + auto array = attachments.As(); + auto len = array->Length(); + rust::Vec buf; + buf.reserve(len); + for (int j = 0; j < len; ++j) { + auto item = (uint32_t) array->Get( + context, j).ToLocalChecked()->NumberValue(context).ToChecked(); + buf.push_back(item); + } - 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")); + rust::Slice slice( + buf.data(), buf.size()); + canvas_native_webgl2_invalidate_framebuffer( + target, slice, + 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 +WebGL2RenderingContext::InvalidateSubFramebuffer(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *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() > 5 && args[1]->IsObject()) { + auto attachments = args[1]; + if (attachments->IsArray()) { + auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); + auto x = (int32_t) args[2]->NumberValue(context).ToChecked(); + auto y = (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(); - ret.push_back(jsi::PropNameID::forUtf8(rt, "MAX_VIEWPORT_DIMS")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "SUBPIXEL_BITS")); + auto array = attachments.As(); + auto len = array->Length(); + rust::Vec buf; + buf.reserve(len); + for (int j = 0; j < len; ++j) { + auto item = (uint) array->Get( + context, j).ToLocalChecked()->NumberValue(context).ToChecked(); + buf.push_back(item); + } + rust::Slice slice( + buf.data(), buf.size()); - 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")); + canvas_native_webgl2_invalidate_sub_framebuffer( + target, + slice, + x, + y, + width, + height, + ptr->GetState()); + } + + + } +} + +void WebGL2RenderingContext::IsQuery(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + auto value = args[0]; + auto type = GetNativeType(isolate, value); + if (type == NativeType::WebGLQuery) { + auto query = WebGLQuery::GetPointer(value.As()); + if (query != nullptr) { + auto ret = canvas_native_webgl2_is_query( + query->GetQuery(), + ptr->GetState()); + args.GetReturnValue().Set(ret); + return; + } + } + // todo check return + args.GetReturnValue().Set(false); +} + +void WebGL2RenderingContext::IsSampler(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + auto value = args[0]; + auto type = GetNativeType(isolate, value); + if (type == NativeType::WebGLSampler) { + auto query = WebGLSampler::GetPointer(value.As()); + if (query != nullptr) { + auto ret = canvas_native_webgl2_is_sampler( + query->GetSampler(), + ptr->GetState()); + args.GetReturnValue().Set(ret); + return; + } + } + // todo check return + args.GetReturnValue().Set(false); +} + +void WebGL2RenderingContext::IsSync(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + auto value = args[0]; + auto type = GetNativeType(isolate, value); + if (type == NativeType::WebGLSync) { + auto query = WebGLSyncImpl::GetPointer(value.As()); + if (query != nullptr) { + auto ret = canvas_native_webgl2_is_sync( + query->GetSync(), + ptr->GetState()); + args.GetReturnValue().Set(ret); + return; + } + } + // todo check return + args.GetReturnValue().Set(false); +} + +void WebGL2RenderingContext::IsTransformFeedback(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + auto value = args[0]; + auto type = GetNativeType(isolate, value); + if (type == NativeType::WebGLTransformFeedback) { + auto query = WebGLTransformFeedback::GetPointer(value.As()); + if (query != nullptr) { + auto ret = canvas_native_webgl2_is_transform_feedback( + query->GetFeedback(), + ptr->GetState()); + args.GetReturnValue().Set(ret); + return; + } + } + // todo check return + args.GetReturnValue().Set(false); +} + +void WebGL2RenderingContext::IsVertexArray(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + auto value = args[0]; + auto type = GetNativeType(isolate, value); + if (type == NativeType::WebGLVertexArrayObject) { + auto query = WebGLVertexArrayObject::GetPointer(value.As()); + if (query != nullptr) { + auto ret = canvas_native_webgl2_is_vertex_array( + query->GetVertexArrayObject(), + ptr->GetState()); + args.GetReturnValue().Set(ret); + return; + } + } + // todo check return + args.GetReturnValue().Set(false); +} + +void +WebGL2RenderingContext::PauseTransformFeedback(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + canvas_native_webgl2_pause_transform_feedback( + ptr->GetState()); +} + +void WebGL2RenderingContext::ReadBuffer(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + if (args.Length() > 0) { + auto src = (uint32_t) args[0]->NumberValue(context).ToChecked(); + canvas_native_webgl2_read_buffer( + src, + ptr->GetState() + ); + } +} + +void WebGL2RenderingContext::RenderbufferStorageMultisample( + const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + if (args.Length() > 4) { + auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); + auto samples = (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(); + canvas_native_webgl2_renderbuffer_storage_multisample( + target, + samples, + internalFormat, + width, + height, + ptr->GetState() + ); + } +} + +void +WebGL2RenderingContext::ResumeTransformFeedback(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + canvas_native_webgl2_resume_transform_feedback( + ptr->GetState()); +} + +void WebGL2RenderingContext::SamplerParameterf(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + if (args.Length() > 2) { + auto samplerValue = args[0]; + auto type = GetNativeType(isolate, samplerValue); + if (type == NativeType::WebGLSampler) { + auto sampler = WebGLSampler::GetPointer(samplerValue.As()); + auto pname = (uint32_t) args[1]->NumberValue(context).ToChecked(); + auto param = args[2]->NumberValue(context).ToChecked(); + if (sampler != nullptr) { + canvas_native_webgl2_sampler_parameterf( + sampler->GetSampler(), + pname, + static_cast(param), + ptr->GetState()); + } + } + + } + +} + +void WebGL2RenderingContext::SamplerParameteri(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + if (args.Length() > 2) { + auto samplerValue = args[0]; + auto type = GetNativeType(isolate, samplerValue); + if (type == NativeType::WebGLSampler) { + auto sampler = WebGLSampler::GetPointer(samplerValue.As()); + auto pname = (uint32_t) args[1]->NumberValue(context).ToChecked(); + auto param = (int32_t) args[2]->NumberValue(context).ToChecked(); + if (sampler != nullptr) { + canvas_native_webgl2_sampler_parameteri( + sampler->GetSampler(), + pname, + param, + ptr->GetState()); + } + } + + } + +} + +void WebGL2RenderingContext::TexImage3D(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + auto count = args.Length(); + + + if (count == 10) { + auto target = (int32_t) args[0]->NumberValue( + context).ToChecked(); + auto level = (int32_t) args[1]->NumberValue( + context).ToChecked(); + auto internalformat = (int32_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 depth = (int32_t) args[5]->NumberValue( + context).ToChecked(); + auto border = (int32_t) args[6]->NumberValue( + context).ToChecked(); + auto format = (int32_t) args[7]->NumberValue( + context).ToChecked(); + auto type = (uint32_t) args[8]->NumberValue( + context).ToChecked(); + + auto imageOrPixelsOrOffset = args[9]; + + if (imageOrPixelsOrOffset->IsNumber()) { + auto offset = imageOrPixelsOrOffset->NumberValue( + context).ToChecked(); + canvas_native_webgl2_tex_image3d_none( + target, + level, + internalformat, + width, + height, + depth, + border, + format, + type, + static_cast(offset), + ptr->GetState() + ); + return; + } + + + if (imageOrPixelsOrOffset->IsTypedArray()) { + auto buf = imageOrPixelsOrOffset.As(); + auto slice = GetTypedArrayData(buf); + + + canvas_native_webgl2_tex_image3d( + target, + level, + internalformat, + width, + height, + depth, + border, + format, + type, + slice, + ptr->GetState() + ); + return; + } + + auto imageType = GetNativeType(isolate, imageOrPixelsOrOffset); + + switch (imageType) { + case NativeType::ImageAsset: { + auto image_asset = ImageAssetImpl::GetPointer( + imageOrPixelsOrOffset.As()); + if (image_asset != nullptr) { + canvas_native_webgl2_tex_image3d_asset( + target, + level, + internalformat, + width, + height, + depth, + border, + format, + type, + image_asset->GetImageAsset(), + ptr->GetState() + ); + + return; + } + return; + } + case NativeType::ImageBitmap: { + auto image_bitmap = ImageBitmapImpl::GetPointer( + imageOrPixelsOrOffset.As()); + if (image_bitmap != nullptr) { + canvas_native_webgl2_tex_image3d_asset( + target, + level, + internalformat, + width, + height, + depth, + border, + format, + type, + image_bitmap->GetImageAsset(), + ptr->GetState() + ); + + return; + } + return; + } + default: + return; + } + } else if (args.Length() > 10) { + + auto target = (int32_t) args[0]->NumberValue( + context).ToChecked(); + auto level = (int32_t) args[1]->NumberValue( + context).ToChecked(); + auto internalformat = (int32_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 depth = (int32_t) args[5]->NumberValue( + context).ToChecked(); + auto border = (int32_t) args[6]->NumberValue( + context).ToChecked(); + auto format = (int32_t) args[7]->NumberValue( + context).ToChecked(); + auto type = (uint32_t) args[8]->NumberValue( + context).ToChecked(); + + auto imageOrPixelsOrOffset = args[9]; + + size_t srcOffsetValue = 0; + if (args[9]->IsNumber()) { + srcOffsetValue = static_cast(args[9]->NumberValue( + context).ToChecked()); + } + + if (imageOrPixelsOrOffset->IsTypedArray()) { + auto buf = imageOrPixelsOrOffset.As(); + auto size = buf->Length(); + auto array = GetTypedArrayData(buf); + + srcOffsetValue = + srcOffsetValue * size; + if (srcOffsetValue > + size) { + return; + } + + canvas_native_webgl2_tex_image3d_offset( + target, + level, + internalformat, + width, + height, + depth, + border, + format, + type, + array, + srcOffsetValue, + ptr->GetState() + ); + return; + } + + } +} + +void WebGL2RenderingContext::TexStorage2D(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + if (args.Length() > 4) { + auto target = (uint32_t) args[0]->NumberValue( + context).ToChecked(); + auto levels = (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(); + canvas_native_webgl2_tex_storage2d( + target, + levels, + internalFormat, + width, + height, + ptr->GetState() + ); + } +} + +void WebGL2RenderingContext::TexStorage3D(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + if (args.Length() > 5) { + auto target = (uint32_t) args[0]->NumberValue( + context).ToChecked(); + auto levels = (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 depth = (int32_t) args[5]->NumberValue( + context).ToChecked(); + canvas_native_webgl2_tex_storage3d( + target, + levels, + internalFormat, + width, + height, + depth, + ptr->GetState() + ); + } +} + +void WebGL2RenderingContext::TexSubImage3D(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + auto count = args.Length(); + if (count == 11) { + 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 zoffset = (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 depth = (int32_t) args[7]->NumberValue( + context).ToChecked(); + auto format = (uint32_t) args[8]->NumberValue( + context).ToChecked(); + auto type = (int32_t) args[9]->NumberValue( + context).ToChecked(); + + if (args[10]->IsNumber()) { + auto imageOrPixelsOrOffset = args[10]->NumberValue( + context).ToChecked(); + canvas_native_webgl2_tex_sub_image3d_none( + target, + level, + xoffset, + yoffset, + zoffset, + width, + height, + depth, + format, + type, + static_cast(imageOrPixelsOrOffset), + ptr->GetState() + ); + return; + } + + auto imageOrPixelsOrOffsetObject = args[10]; + + if (imageOrPixelsOrOffsetObject->IsTypedArray()) { + auto array = imageOrPixelsOrOffsetObject.As(); + auto slice = GetTypedArrayData(array); + + canvas_native_webgl2_tex_sub_image3d( + target, + level, + xoffset, + yoffset, + zoffset, + width, + height, + depth, + format, + type, + slice, + ptr->GetState() + ); + + return; + } + + + auto imageType = GetNativeType(isolate, imageOrPixelsOrOffsetObject); + + if (imageType == NativeType::ImageAsset) { + auto asset = ImageAssetImpl::GetPointer(imageOrPixelsOrOffsetObject.As()); + if (asset != nullptr) { + + canvas_native_webgl2_tex_sub_image3d_asset( + target, + level, + xoffset, + yoffset, + zoffset, + width, + height, + depth, + format, + type, + asset->GetImageAsset(), + ptr->GetState() + ); + } + } + + } else if (count > 11) { + 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 zoffset = (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 depth = (int32_t) args[7]->NumberValue( + context).ToChecked(); + auto format = (uint32_t) args[8]->NumberValue( + context).ToChecked(); + auto type = (uint32_t) args[9]->NumberValue( + context).ToChecked(); + + size_t srcOffsetValue = 0; + + if (args[11]->IsNumber()) { + srcOffsetValue = static_cast(args[11]->NumberValue( + context).ToChecked()); + } + + auto imageOrPixelsOrOffsetObject = args[10]; + + + if (imageOrPixelsOrOffsetObject->IsTypedArray()) { + auto array = imageOrPixelsOrOffsetObject.As(); + auto buf = GetTypedArrayData(array); + auto size = array->Length(); + srcOffsetValue = + srcOffsetValue * size; + if (srcOffsetValue > size) { + return; + } + + rust::Slice slice( + buf.data(), + buf.size()); + + canvas_native_webgl2_tex_sub_image3d_offset( + target, + level, + xoffset, + yoffset, + zoffset, + width, + height, + depth, + format, + type, + slice, + srcOffsetValue, + ptr->GetState() + ); + } + } +} + +void +WebGL2RenderingContext::TransformFeedbackVaryings(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + auto programValue = args[0]; + auto type = GetNativeType(isolate, programValue); + if (args.Length() > 2 && type == NativeType::WebGLProgram) { + auto program = WebGLProgram::GetPointer(programValue.As()); + auto varyingsObject = args[1]; + auto bufferMode = (uint32_t) args[2]->NumberValue( + context).ToChecked(); + + if (program != nullptr && + varyingsObject->IsArray()) { + auto varyings = varyingsObject.As(); + auto len = varyings->Length(); + rust::Vec buf; + buf.reserve(len); + for (int j = 0; j < len; ++j) { + auto name = ConvertFromV8String(isolate, varyings->Get( + context, j).ToLocalChecked()); + rust::Str val(name.data(), + name.size()); + buf.emplace_back(val); + } + + rust::Slice slice( + buf.data(), buf.size()); + + canvas_native_webgl2_transform_feedback_varyings( + program->GetProgram(), + slice, + bufferMode, + ptr->GetState() + ); + } + } + +} + +void WebGL2RenderingContext::Uniform1ui(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + auto locationValue = args[0]; + auto type = GetNativeType(isolate, locationValue); + + if (args.Length() > 1 && + args[1]->IsNumber() && type == NativeType::WebGLUniformLocation) { + + auto location = WebGLUniformLocation::GetPointer(locationValue.As()); + auto v0 = (uint32_t) args[1]->NumberValue( + context).ToChecked(); + + if (location != nullptr) { + canvas_native_webgl2_uniform1ui( + location->GetUniformLocation(), + v0, + ptr->GetState() + ); + } + } + +} + +void WebGL2RenderingContext::Uniform2ui(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + auto locationValue = args[0]; + auto type = GetNativeType(isolate, locationValue); + + if (args.Length() > 2 && + args[1]->IsNumber() && type == NativeType::WebGLUniformLocation) { + + auto location = WebGLUniformLocation::GetPointer(locationValue.As()); + auto v0 = (uint32_t) args[1]->NumberValue( + context).ToChecked(); + auto v1 = (uint32_t) args[2]->NumberValue( + context).ToChecked(); + + if (location != nullptr) { + canvas_native_webgl2_uniform2ui( + location->GetUniformLocation(), + v0, + v1, + ptr->GetState() + ); + } + } + +} + +void WebGL2RenderingContext::Uniform3ui(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + auto locationValue = args[0]; + auto type = GetNativeType(isolate, locationValue); + + if (args.Length() > 3 && + args[1]->IsNumber() && type == NativeType::WebGLUniformLocation) { + + auto location = WebGLUniformLocation::GetPointer(locationValue.As()); + auto v0 = (uint32_t) args[1]->NumberValue( + context).ToChecked(); + + auto v1 = (uint32_t) args[2]->NumberValue( + context).ToChecked(); + + auto v2 = (uint32_t) args[3]->NumberValue( + context).ToChecked(); + + if (location != nullptr) { + canvas_native_webgl2_uniform3ui( + location->GetUniformLocation(), + v0, + v1, + v2, + ptr->GetState() + ); + } + } + +} + +void WebGL2RenderingContext::Uniform4ui(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + auto locationValue = args[0]; + auto type = GetNativeType(isolate, locationValue); + + if (args.Length() > 1 && + args[1]->IsNumber() && type == NativeType::WebGLUniformLocation) { + + auto location = WebGLUniformLocation::GetPointer(locationValue.As()); + auto v0 = (uint32_t) args[1]->NumberValue( + context).ToChecked(); + + auto v1 = (uint32_t) args[2]->NumberValue( + context).ToChecked(); + + auto v2 = (uint32_t) args[3]->NumberValue( + context).ToChecked(); + auto v3 = (uint32_t) args[4]->NumberValue( + context).ToChecked(); + + + if (location != nullptr) { + canvas_native_webgl2_uniform4ui( + location->GetUniformLocation(), + v0, + v1, + v2, + v3, + ptr->GetState() + ); + } + } + +} + +void WebGL2RenderingContext::Uniform1uiv(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + + auto locationValue = args[0]; + auto type = GetNativeType(isolate, locationValue); + + + if (args.Length() > 1 && + args[1]->IsObject() && type == NativeType::WebGLUniformLocation) { + auto location = WebGLUniformLocation::GetPointer(locationValue.As()); + auto data = args[1]; + if (location != nullptr && + data->IsUint32Array()) { + auto array = data.As(); + auto slice = GetTypedArrayData(array); + canvas_native_webgl2_uniform1uiv( + location->GetUniformLocation(), + slice, + ptr->GetState() + ); + } else { + rust::Vec buf; + auto array = data.As(); + auto len = array->Length(); + buf.reserve(len); + for (int i = 0; i < len; i++) { + auto item = (uint32_t) array->Get( + context, + i).ToLocalChecked()->NumberValue( + context).ToChecked(); + buf.push_back(item); + } + rust::Slice slice( + buf.data(), buf.size()); + canvas_native_webgl2_uniform1uiv( + location->GetUniformLocation(), + slice, + ptr->GetState() + ); + } + + + } + +} + +void WebGL2RenderingContext::Uniform2uiv(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + + auto locationValue = args[0]; + auto type = GetNativeType(isolate, locationValue); + + + if (args.Length() > 1 && + args[1]->IsObject() && type == NativeType::WebGLUniformLocation) { + auto location = WebGLUniformLocation::GetPointer(locationValue.As()); + auto data = args[1]; + if (location != nullptr && + data->IsUint32Array()) { + auto array = data.As(); + auto slice = GetTypedArrayData(array); + canvas_native_webgl2_uniform2uiv( + location->GetUniformLocation(), + slice, + ptr->GetState() + ); + } else { + rust::Vec buf; + auto array = data.As(); + auto len = array->Length(); + buf.reserve(len); + for (int i = 0; i < len; i++) { + auto item = (uint32_t) array->Get( + context, + i).ToLocalChecked()->NumberValue( + context).ToChecked(); + buf.push_back(item); + } + rust::Slice slice( + buf.data(), buf.size()); + canvas_native_webgl2_uniform2uiv( + location->GetUniformLocation(), + slice, + ptr->GetState() + ); + } + + + } + +} + +void WebGL2RenderingContext::Uniform3uiv(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + + auto locationValue = args[0]; + auto type = GetNativeType(isolate, locationValue); + + + if (args.Length() > 1 && + args[1]->IsObject() && type == NativeType::WebGLUniformLocation) { + auto location = WebGLUniformLocation::GetPointer(locationValue.As()); + auto data = args[1]; + if (location != nullptr && + data->IsUint32Array()) { + auto array = data.As(); + auto slice = GetTypedArrayData(array); + canvas_native_webgl2_uniform3uiv( + location->GetUniformLocation(), + slice, + ptr->GetState() + ); + } else { + rust::Vec buf; + auto array = data.As(); + auto len = array->Length(); + buf.reserve(len); + for (int i = 0; i < len; i++) { + auto item = (uint32_t) array->Get( + context, + i).ToLocalChecked()->NumberValue( + context).ToChecked(); + buf.push_back(item); + } + rust::Slice slice( + buf.data(), buf.size()); + canvas_native_webgl2_uniform3uiv( + location->GetUniformLocation(), + slice, + ptr->GetState() + ); + } + + + } + +} + +void WebGL2RenderingContext::Uniform4uiv(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + + auto locationValue = args[0]; + auto type = GetNativeType(isolate, locationValue); + + + if (args.Length() > 1 && + args[1]->IsObject() && type == NativeType::WebGLUniformLocation) { + auto location = WebGLUniformLocation::GetPointer(locationValue.As()); + auto data = args[1]; + if (location != nullptr && + data->IsUint32Array()) { + auto array = data.As(); + auto slice = GetTypedArrayData(array); + canvas_native_webgl2_uniform4uiv( + location->GetUniformLocation(), + slice, + ptr->GetState() + ); + } else { + rust::Vec buf; + auto array = data.As(); + auto len = array->Length(); + buf.reserve(len); + for (int i = 0; i < len; i++) { + auto item = (uint32_t) array->Get( + context, + i).ToLocalChecked()->NumberValue( + context).ToChecked(); + buf.push_back(item); + } + rust::Slice slice( + buf.data(), buf.size()); + canvas_native_webgl2_uniform4uiv( + location->GetUniformLocation(), + slice, + ptr->GetState() + ); + } + + } + +} + +void WebGL2RenderingContext::UniformBlockBinding(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + + auto programValue = args[0]; + auto type = GetNativeType(isolate, programValue); + if (args.Length() > 2 && type == NativeType::WebGLProgram) { + + auto program = WebGLProgram::GetPointer(programValue.As()); + auto uniformBlockIndex = args[1]->NumberValue( + context).ToChecked(); + auto uniformBlockBinding = args[2]->NumberValue( + context).ToChecked(); + + if (program != nullptr) { + canvas_native_webgl2_uniform_block_binding( + program->GetProgram(), + (uint32_t) uniformBlockIndex, + (uint32_t) uniformBlockBinding, + ptr->GetState() + ); + } + + } + +} + +void WebGL2RenderingContext::UniformMatrix2x3fv(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + + if (args.Length() > 2 && + args[2]->IsObject()) { + auto locationValue = args[0]; + auto type = GetNativeType(isolate, locationValue); + if (type == NativeType::WebGLUniformLocation) { + auto location = WebGLUniformLocation::GetPointer(locationValue.As()); + auto transpose = args[1]->BooleanValue(isolate); + auto data = args[2]; + + if (data->IsFloat32Array()) { + auto array = data.As(); + auto slice = GetTypedArrayData(array); + canvas_native_webgl2_uniform_matrix2x3fv( + location->GetUniformLocation(), + transpose, + slice, + ptr->GetState() + ); + } else if (data->IsArray()) { + rust::Vec buf; + auto array = data.As(); + auto len = array->Length(); + for (int i = 0; i < len; i++) { + auto item = array->Get( + context, i).ToLocalChecked(); + if (item->IsNumber()) { + buf.push_back( + static_cast(item->NumberValue( + context).ToChecked())); + } else { + buf.push_back( + std::nanf("")); + } + } - 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")); + rust::Slice slice( + buf.data(), buf.size()); - 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")); + canvas_native_webgl2_uniform_matrix2x3fv( + location->GetUniformLocation(), + transpose, + slice, + ptr->GetState() + ); + } + } - 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")); +void WebGL2RenderingContext::UniformMatrix2x4fv(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - 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")); + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - 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")); + if (args.Length() > 2 && + args[2]->IsObject()) { + auto locationValue = args[0]; + auto type = GetNativeType(isolate, locationValue); + if (type == NativeType::WebGLUniformLocation) { + auto location = WebGLUniformLocation::GetPointer(locationValue.As()); + auto transpose = args[1]->BooleanValue(isolate); + auto data = args[2]; + + if (data->IsFloat32Array()) { + auto array = data.As(); + auto slice = GetTypedArrayData(array); + canvas_native_webgl2_uniform_matrix2x4fv( + location->GetUniformLocation(), + transpose, + slice, + ptr->GetState() + ); + } else if (data->IsArray()) { + rust::Vec buf; + auto array = data.As(); + auto len = array->Length(); + for (int i = 0; i < len; i++) { + auto item = array->Get( + context, i).ToLocalChecked(); + if (item->IsNumber()) { + buf.push_back( + static_cast(item->NumberValue( + context).ToChecked())); + } else { + buf.push_back( + std::nanf("")); + } + } - 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")); + rust::Slice slice( + buf.data(), buf.size()); - 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_webgl2_uniform_matrix2x4fv( + location->GetUniformLocation(), + transpose, + slice, + 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")); - - - /* 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")); - - 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")); - - /* Clearing buffers */ - - /* 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 */ - - 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")); - - /* Blending modes */ + } - ret.push_back(jsi::PropNameID::forUtf8(rt, "NEVER")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "LESS")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "EQUAL")); +} - /* Blending equations */ +void WebGL2RenderingContext::UniformMatrix3x2fv(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - /* Getting GL parameter information */ + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - 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 (args.Length() > 2 && + args[2]->IsObject()) { + auto locationValue = args[0]; + auto type = GetNativeType(isolate, locationValue); + if (type == NativeType::WebGLUniformLocation) { + auto location = WebGLUniformLocation::GetPointer(locationValue.As()); + auto transpose = args[1]->BooleanValue(isolate); + auto data = args[2]; + + if (data->IsFloat32Array()) { + auto array = data.As(); + auto slice = GetTypedArrayData(array); + canvas_native_webgl2_uniform_matrix3x2fv( + location->GetUniformLocation(), + transpose, + slice, + ptr->GetState() + ); + } else if (data->IsArray()) { + rust::Vec buf; + auto array = data.As(); + auto len = array->Length(); + for (int i = 0; i < len; i++) { + auto item = array->Get( + context, i).ToLocalChecked(); + if (item->IsNumber()) { + buf.push_back( + static_cast(item->NumberValue( + context).ToChecked())); + } else { + buf.push_back( + std::nanf("")); + } + } - /* Buffers */ + rust::Slice slice( + buf.data(), buf.size()); - 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")); + canvas_native_webgl2_uniform_matrix3x2fv( + location->GetUniformLocation(), + transpose, + slice, + ptr->GetState() + ); + } + } - /* Buffers */ + } - /* 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")); +void WebGL2RenderingContext::UniformMatrix3x4fv(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - /* Vertex attributes */ + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - /* 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")); + if (args.Length() > 2 && + args[2]->IsObject()) { + auto locationValue = args[0]; + auto type = GetNativeType(isolate, locationValue); + if (type == NativeType::WebGLUniformLocation) { + auto location = WebGLUniformLocation::GetPointer(locationValue.As()); + auto transpose = args[1]->BooleanValue(isolate); + auto data = args[2]; + + if (data->IsFloat32Array()) { + auto array = data.As(); + auto slice = GetTypedArrayData(array); + canvas_native_webgl2_uniform_matrix3x4fv( + location->GetUniformLocation(), + transpose, + slice, + ptr->GetState() + ); + } else if (data->IsArray()) { + rust::Vec buf; + auto array = data.As(); + auto len = array->Length(); + for (int i = 0; i < len; i++) { + auto item = array->Get( + context, i).ToLocalChecked(); + if (item->IsNumber()) { + buf.push_back( + static_cast(item->NumberValue( + context).ToChecked())); + } else { + buf.push_back( + std::nanf("")); + } + } - /* Culling */ + rust::Slice slice( + buf.data(), buf.size()); - /* Enabling and disabling */ + canvas_native_webgl2_uniform_matrix3x4fv( + location->GetUniformLocation(), + transpose, + slice, + ptr->GetState() + ); + } + } - 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")); +void WebGL2RenderingContext::UniformMatrix4x2fv(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - /* Errors */ + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - /* Front face directions */ - ret.push_back(jsi::PropNameID::forUtf8(rt, "DEPTH_STENCIL")); - ret.push_back(jsi::PropNameID::forUtf8(rt, "RENDERBUFFER_WIDTH")); + if (args.Length() > 2 && + args[2]->IsObject()) { + auto locationValue = args[0]; + auto type = GetNativeType(isolate, locationValue); + if (type == NativeType::WebGLUniformLocation) { + auto location = WebGLUniformLocation::GetPointer(locationValue.As()); + auto transpose = args[1]->BooleanValue(isolate); + auto data = args[2]; + + if (data->IsFloat32Array()) { + auto array = data.As(); + auto slice = GetTypedArrayData(array); + canvas_native_webgl2_uniform_matrix4x2fv( + location->GetUniformLocation(), + transpose, + slice, + ptr->GetState() + ); + } else if (data->IsArray()) { + rust::Vec buf; + auto array = data.As(); + auto len = array->Length(); + for (int i = 0; i < len; i++) { + auto item = array->Get( + context, i).ToLocalChecked(); + if (item->IsNumber()) { + buf.push_back( + static_cast(item->NumberValue( + context).ToChecked())); + } else { + buf.push_back( + std::nanf("")); + } + } - /* Front face directions */ + rust::Slice slice( + buf.data(), buf.size()); - /* Hints */ + canvas_native_webgl2_uniform_matrix4x2fv( + location->GetUniformLocation(), + transpose, + slice, + ptr->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")); + } - /* Hints */ +} - /* Data types */ +void WebGL2RenderingContext::UniformMatrix4x3fv(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - 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")); + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - /* Data types */ - /* Pixel formats */ + if (args.Length() > 2 && + args[2]->IsObject()) { + auto locationValue = args[0]; + auto type = GetNativeType(isolate, locationValue); + if (type == NativeType::WebGLUniformLocation) { + auto location = WebGLUniformLocation::GetPointer(locationValue.As()); + auto transpose = args[1]->BooleanValue(isolate); + auto data = args[2]; + + if (data->IsFloat32Array()) { + auto array = data.As(); + auto slice = GetTypedArrayData(array); + canvas_native_webgl2_uniform_matrix4x3fv( + location->GetUniformLocation(), + transpose, + slice, + ptr->GetState() + ); + } else if (data->IsArray()) { + rust::Vec buf; + auto array = data.As(); + auto len = array->Length(); + for (int i = 0; i < len; i++) { + auto item = array->Get( + context, i).ToLocalChecked(); + if (item->IsNumber()) { + buf.push_back( + static_cast(item->NumberValue( + context).ToChecked())); + } else { + buf.push_back( + std::nanf("")); + } + } - 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")); + rust::Slice slice( + buf.data(), buf.size()); - /* Pixel formats */ + canvas_native_webgl2_uniform_matrix4x3fv( + location->GetUniformLocation(), + transpose, + slice, + ptr->GetState() + ); + } + } - /* Pixel types */ + } - 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")); +} - /* Pixel types */ +void WebGL2RenderingContext::VertexAttribDivisor(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - /* Shaders */ + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); - 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 (args.Length() > 1) { + auto index = args[0]->NumberValue( + context).ToChecked(); + auto divisor = args[1]->NumberValue( + context).ToChecked(); + canvas_native_webgl2_vertex_attrib_divisor( + (uint32_t) index, + (uint32_t) divisor, + ptr->GetState() + ); + } - /* GL 1 */ +} +void WebGL2RenderingContext::VertexAttribI4i(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } - return ret; -} + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); -jsi::Value WebGL2RenderingContext::get(jsi::Runtime &runtime, const jsi::PropNameID &name) { - auto methodName = name.utf8(runtime); - - auto prop = GetProperty(methodName); - - - if (methodName == "getBufferSubData") { - 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 { - - - if (count >= 3 && - args[2]->IsObject()) { - auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); - auto srcByteOffset = args[1]->NumberValue(context).ToChecked(); - auto dstDataObject = args[2].asObject( - runtime); - - if (dstDataObject.isTypedArray( - runtime)) { - - auto array = dstDataObject.getTypedArray( - runtime); - auto slice = GetTypedArrayData( - runtime, array); - - auto BYTES_PER_ELEMENT = (ssize_t) array.getProperty( - runtime, - "BYTES_PER_ELEMENT")->NumberValue(context).ToChecked(); - - ssize_t dstOffsetValue = 0; - if (args[3]->IsNumber()) { - dstOffsetValue = - static_cast(args[3]->NumberValue(context).ToChecked()) * - BYTES_PER_ELEMENT; - } - - ssize_t lengthValue = 0; - if (args[4]->IsNumber()) { - lengthValue = - static_cast(args[4]->NumberValue(context).ToChecked()) * - BYTES_PER_ELEMENT; - } - - canvas_native_webgl2_get_buffer_sub_data( - target, - static_cast(srcByteOffset), - slice, - dstOffsetValue, - lengthValue, - ptr->GetState() - ); - } - } - - return jsi::Value::undefined(); - } - ); - } else if (methodName == "getFragDataLocation") { - 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 && args[1].isString()) { - auto program = getHostObject( - runtime, args[0]); - - if (program != nullptr) { - auto name = args[1].asString( - runtime).utf8(runtime); - - auto ret = canvas_native_webgl2_get_frag_data_location( - program->GetProgram(), - rust::Str(name.c_str()), - ptr->GetState() - ); - - return {ret}; - } - } - - return jsi::Value::null(); - } - ); - } else if (methodName == "getIndexedParameter") { - 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) { - auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); - auto index = (uint32_t) args[1]->NumberValue(context).ToChecked(); - auto ret = canvas_native_webgl2_get_indexed_parameter( - target, - index, - ptr->GetState() - ); - - switch (target) { - case GL_UNIFORM_BUFFER_BINDING: - case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: { - auto buffer = canvas_native_webgl2_indexed_parameter_get_buffer_value( - *ret); - return jsi::Object::createFromHostObject( - runtime, - std::make_shared( - buffer)); - } - break; - case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE: - case GL_TRANSFORM_FEEDBACK_BUFFER_START: - case GL_UNIFORM_BUFFER_SIZE: - case GL_UNIFORM_BUFFER_START: { - auto value = canvas_native_webgl2_indexed_parameter_get_value( - *ret); - return {static_cast(value)}; - } - break; - default: - return jsi::Value::null(); - } - } - - return jsi::Value::null(); - } - ); - } else if (methodName == "getInternalformatParameter") { - 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) args[0]->NumberValue(context).ToChecked(); - auto internalformat = (uint32_t) args[1]->NumberValue(context).ToChecked(); - auto pname = (uint32_t) args[2]->NumberValue(context).ToChecked(); - switch (internalformat) { - case GL_RGB: - case GL_RGBA: - case GL_R8UI: - case GL_R8I: - case GL_R16UI: - case GL_R16I: - case GL_R32UI: - case GL_R32I: - case GL_RG8UI: - case GL_RG8I: - case GL_RG16UI: - case GL_RG16I: - case GL_RG32UI: - case GL_RG32I: - case GL_RGBA8UI: - case GL_RGBA8I: - case GL_RGB10_A2UI: - case GL_RGBA16UI: - case GL_RGBA16I: - case GL_RGBA32UI: - case GL_RGBA32I: { - // empty - - auto value = rust::Vec(); - auto buffer = std::make_shared>( - std::move(value)); - auto array = jsi::ArrayBuffer( - runtime, buffer); - - auto Int32Array = runtime.global() - .getProperty(runtime, - "Int32Array") - .asObject(runtime) - .asFunction(runtime); - - - return Int32Array.callAsConstructor( - runtime, array); - } - case GL_R8: - case GL_RG8: - case GL_RGB565: - case GL_RGBA8: - case GL_SRGB8_ALPHA8: - case GL_RGB5_A1: - case GL_RGBA4: - case GL_RGB10_A2: - case GL_DEPTH_COMPONENT16: - case GL_DEPTH_COMPONENT24: - case GL_DEPTH_COMPONENT32F: - case GL_DEPTH24_STENCIL8: - case GL_DEPTH32F_STENCIL8: - case GL_STENCIL_INDEX8: - // noop - break; - case GL_R16F: - case GL_RG16F: - case GL_R32F: - case GL_RG32F: - case GL_RGBA32F: - case GL_R11F_G11F_B10F: - // noop - break; - default: - return jsi::Value::null(); - } - - - auto ret = canvas_native_webgl2_get_internalformat_parameter( - target, - internalformat, - pname, - ptr->GetState() - ); - - if (pname == GL_SAMPLES) { - auto value = canvas_native_webgl_result_get_i32_array( - *ret); - - auto buffer = std::make_shared>( - std::move(value)); - auto array = jsi::ArrayBuffer( - runtime, - buffer); - - auto Int32Array = runtime.global() - .getProperty(runtime, - "Int32Array") - .asObject(runtime) - .asFunction(runtime); - - - return Int32Array.callAsConstructor( - runtime, array); - } else { - return jsi::Value::null(); - } - } - - return jsi::Value::null(); - } - ); - } else if (methodName == "getParameter") { - 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 > 0) { - auto pname = (uint32_t) args[0]->NumberValue(context).ToChecked(); - auto result = canvas_native_webgl2_get_parameter( - pname, - ptr->GetState()); - switch (pname) { - case GL_COPY_READ_BUFFER_BINDING: - case GL_COPY_WRITE_BUFFER_BINDING: - case GL_DRAW_FRAMEBUFFER_BINDING: - return {canvas_native_webgl_result_get_i32( - *result)}; - default: - return this->GetParameterInternal( - runtime, pname, - std::move(result)); - } - } - - return jsi::Value::null(); - } - ); - } else if (methodName == "getQueryParameter") { - 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) { - auto query = getHostObject( - runtime, args[0]); - if (query != nullptr) { - auto pname = (uint32_t) args[1]->NumberValue(context).ToChecked(); - - - auto ret = canvas_native_webgl2_get_query_parameter( - query->GetQuery(), - pname, - ptr->GetState()); - if (pname == GL_QUERY_RESULT) { - return {canvas_native_webgl_result_get_bool( - *ret)}; - } else if (pname == - GL_QUERY_RESULT_AVAILABLE) { - return {(int32_t) canvas_native_webgl_result_get_u32( - *ret)}; - } - } - } - - return jsi::Value::null(); - } - ); - } else if (methodName == "getQuery") { - 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) { - auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); - auto pname = (uint32_t) args[1]->NumberValue(context).ToChecked(); - auto ret = canvas_native_webgl2_get_query( - target, - pname, - ptr->GetState()); - if (pname == GL_CURRENT_QUERY) { - return {canvas_native_webgl_result_get_i32( - *ret)}; - } - } - - return jsi::Value::null(); - } - ); - } else if (methodName == "getSamplerParameter") { - 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) { - auto sampler = getHostObject( - runtime, args[0]); - if (sampler != nullptr) { - auto pname = (uint32_t) args[1]->NumberValue(context).ToChecked(); - auto ret = canvas_native_webgl2_get_sampler_parameter( - sampler->GetSampler(), - pname, - ptr->GetState()); - - switch (pname) { - case GL_TEXTURE_MAX_LOD: - case GL_TEXTURE_MIN_LOD: - return {static_cast(canvas_native_webgl_result_get_f32( - *ret))}; - case GL_TEXTURE_COMPARE_FUNC: - case GL_TEXTURE_COMPARE_MODE: - case GL_TEXTURE_MAG_FILTER: - case GL_TEXTURE_MIN_FILTER: - case GL_TEXTURE_WRAP_R: - case GL_TEXTURE_WRAP_S: - case GL_TEXTURE_WRAP_T: - return {canvas_native_webgl_result_get_i32( - *ret)}; - default: - return jsi::Value::null(); - } - } - } - - return jsi::Value::null(); - } - ); - } else if (methodName == "getSyncParameter") { - 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) { - auto sync = getHostObject( - runtime, args[0]); - if (sync != nullptr) { - auto pname = (uint32_t) args[1]->NumberValue(context).ToChecked(); - auto ret = canvas_native_webgl2_get_sync_parameter( - sync->GetSync(), - pname, - ptr->GetState()); - - switch (pname) { - case GL_OBJECT_TYPE: - case GL_SYNC_STATUS: - case GL_SYNC_CONDITION: - case GL_SYNC_FLAGS: - return {canvas_native_webgl_result_get_i32( - *ret)}; - default: - return jsi::Value::null(); - } - } - } - return jsi::Value::null(); - } - ); - } else if (methodName == "getTransformFeedbackVarying") { - 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) { - auto program = getHostObject( - runtime, args[0]); - auto index = (uint32_t) args[1]->NumberValue(context).ToChecked(); - if (program != nullptr) { - auto ret = canvas_native_webgl2_get_transform_feedback_varying( - program->GetProgram(), - index, - ptr->GetState() - ); - - if (canvas_native_webgl_active_info_get_is_empty( - *ret)) { - return jsi::Value::null(); - } - - auto info = std::make_shared( - std::move(ret)); - - return jsi::Object::createFromHostObject( - runtime, info); - } - } - - return jsi::Value::null(); - } - ); - } else if (methodName == "getUniformBlockIndex") { - 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) { - auto program = getHostObject( - runtime, args[0]); - auto index = args[1].asString( - runtime).utf8(runtime); - if (program != nullptr) { - auto ret = canvas_native_webgl2_get_uniform_block_index( - program->GetProgram(), - rust::Str(index.c_str()), - ptr->GetState()); - - return {(int) ret}; - } - } - - return jsi::Value::null(); - } - ); - } else if (methodName == "getUniformIndices") { - 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 && args[1]->IsObject()) { - auto program = getHostObject( - runtime, args[0]); - auto uniformNamesObject = args[1].asObject( - runtime); - if (program != nullptr && - uniformNamesObject.isArray( - runtime)) { - auto uniformNames = uniformNamesObject.getArray( - runtime); - auto len = uniformNames.size( - runtime); - rust::Vec store; - store.reserve(len); - for (int j = 0; j < len; ++j) { - auto name = uniformNames.getValueAtIndex( - runtime, j).asString( - runtime).utf8(runtime); - rust::Str val(name.data(), - name.size()); - store.push_back(val); - } - rust::Slice slice( - store.data(), - store.size()); - auto ret = canvas_native_webgl2_get_uniform_indices( - program->GetProgram(), - slice, - ptr->GetState()); - - auto retSize = ret.size(); - auto result = jsi::Array(runtime, - retSize); - for (int j = 0; j < retSize; ++j) { - auto item = ret[j]; - result.setValueAtIndex(runtime, - j, - jsi::Value( - (int32_t) item)); - } - - return result; - } - } - - return jsi::Value::null(); - } - ); - } else if (methodName == "invalidateFramebuffer") { - 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 && args[1]->IsObject()) { - auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); - auto attachments = args[1].asObject( - runtime); - - if (attachments.isArray(runtime)) { - auto array = attachments.getArray( - runtime); - auto len = array.size(runtime); - rust::Vec buf; - buf.reserve(len); - for (int j = 0; j < len; ++j) { - auto item = (uint32_t) array.getValueAtIndex( - runtime, j)->NumberValue(context).ToChecked(); - buf.push_back(item); - } - - rust::Slice slice( - buf.data(), buf.size()); - canvas_native_webgl2_invalidate_framebuffer( - target, slice, - ptr->GetState()); - } - } - - return jsi::Value::undefined(); - } - ); - } else if (methodName == "invalidateSubFramebuffer") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 6, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { - - - if (count > 5 && args[1]->IsObject()) { - auto attachments = args[1].asObject( - runtime); - if (attachments.isArray(runtime)) { - auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); - auto x = (int32_t) args[2]->NumberValue(context).ToChecked(); - auto y = (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 array = attachments.getArray( - runtime); - auto len = array.size(runtime); - rust::Vec buf; - buf.reserve(len); - for (int j = 0; j < len; ++j) { - auto item = (uint) array.getValueAtIndex( - runtime, j)->NumberValue(context).ToChecked(); - buf.push_back(item); - } - rust::Slice slice( - buf.data(), buf.size()); - - canvas_native_webgl2_invalidate_sub_framebuffer( - target, - slice, - x, - y, - width, - height, - ptr->GetState()); - } - - - } - - return jsi::Value::undefined(); - } - ); - } else if (methodName == "isQuery") { - 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 > 0) { - auto query = getHostObject( - runtime, args[0]); - if (query != nullptr) { - auto ret = canvas_native_webgl2_is_query( - query->GetQuery(), - ptr->GetState()); - return {ret}; - } - } - // todo check return - return {false}; - } - ); - } else if (methodName == "isSampler") { - 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 > 0) { - auto sampler = getHostObject( - runtime, args[0]); - if (sampler != nullptr) { - auto ret = canvas_native_webgl2_is_sampler( - sampler->GetSampler(), - ptr->GetState()); - return {ret}; - } - } - // todo check return - return {false}; - } - ); - } else if (methodName == "isSync") { - 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 > 0) { - auto sync = getHostObject( - runtime, args[0]); - if (sync != nullptr) { - auto ret = canvas_native_webgl2_is_sync( - sync->GetSync(), - ptr->GetState()); - return {ret}; - } - } - // todo check return - return {false}; - } - ); - } else if (methodName == "isTransformFeedback") { - 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 > 0) { - auto transformFeedback = getHostObject( - runtime, args[0]); - if (transformFeedback != nullptr) { - auto ret = canvas_native_webgl2_is_transform_feedback( - transformFeedback->GetFeedback(), - ptr->GetState()); - return {ret}; - } - } - // todo check return - return {false}; - } - ); - } else if (methodName == "isVertexArray") { - 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 > 0) { - auto vertexArray = getHostObject( - runtime, args[0]); - if (vertexArray != nullptr) { - auto ret = canvas_native_webgl2_is_vertex_array( - vertexArray->GetVertexArrayObject(), - ptr->GetState()); - return {ret}; - } - } - // todo check return - return {false}; - - - } - ); - } else if (methodName == "pauseTransformFeedback") { - 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 { - - canvas_native_webgl2_pause_transform_feedback( - ptr->GetState()); - - return jsi::Value::undefined(); - } - ); - } else if (methodName == "readBuffer") { - 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 > 0) { - auto src = (uint32_t) args[0]->NumberValue(context).ToChecked(); - canvas_native_webgl2_read_buffer( - src, - ptr->GetState() - ); - } - - return jsi::Value::undefined(); - } - ); - } else if (methodName == "renderbufferStorageMultisample") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 5, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { - - if (count > 4) { - auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); - auto samples = (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(); - canvas_native_webgl2_renderbuffer_storage_multisample( - target, - samples, - internalFormat, - width, - height, - ptr->GetState() - ); - } - - return jsi::Value::undefined(); - } - ); - } else if (methodName == "resumeTransformFeedback") { - 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 { - canvas_native_webgl2_resume_transform_feedback( - ptr->GetState()); - return jsi::Value::undefined(); - } - ); - } else if (methodName == "samplerParameterf") { - 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 sampler = getHostObject( - runtime, args[0]); - auto pname = (uint32_t) args[1]->NumberValue(context).ToChecked(); - auto param = args[2]->NumberValue(context).ToChecked(); - if (sampler != nullptr) { - canvas_native_webgl2_sampler_parameterf( - sampler->GetSampler(), - pname, - static_cast(param), - ptr->GetState()); - } - } - - return jsi::Value::undefined(); - } - ); - } else if (methodName == "samplerParameteri") { - 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 sampler = getHostObject( - runtime, args[0]); - auto pname = (uint32_t) args[1]->NumberValue(context).ToChecked(); - auto param = (int32_t) args[2]->NumberValue(context).ToChecked(); - if (sampler != nullptr) { - canvas_native_webgl2_sampler_parameteri( - sampler->GetSampler(), - pname, - param, - ptr->GetState()); - } - } - - return jsi::Value::undefined(); - } - ); - } else if (methodName == "texImage3D") { - 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 == 10) { - auto target = (int32_t) args[0]->NumberValue(context).ToChecked(); - auto level = (int32_t) args[1]->NumberValue(context).ToChecked(); - auto internalformat = (int32_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 depth = (int32_t) args[5]->NumberValue(context).ToChecked(); - auto border = (int32_t) args[6]->NumberValue(context).ToChecked(); - auto format = (int32_t) args[7]->NumberValue(context).ToChecked(); - auto type = (uint32_t) args[8]->NumberValue(context).ToChecked(); - - - if (args[9]->IsNumber()) { - auto imageOrPixelsOrOffset = args[9]->NumberValue(context).ToChecked(); - canvas_native_webgl2_tex_image3d_none( - target, - level, - internalformat, - width, - height, - depth, - border, - format, - type, - static_cast(imageOrPixelsOrOffset), - ptr->GetState() - ); - return jsi::Value::undefined(); - } - - if (args[9]->IsObject()) { - auto imageOrPixelsOrOffsetObject = args[9].asObject( - runtime); - - if (imageOrPixelsOrOffsetObject.isTypedArray( - runtime)) { - auto buf = imageOrPixelsOrOffsetObject.getTypedArray( - runtime); - auto slice = GetTypedArrayData( - runtime, buf); - - - canvas_native_webgl2_tex_image3d( - target, - level, - internalformat, - width, - height, - depth, - border, - format, - type, - slice, - ptr->GetState() - ); - return jsi::Value::undefined(); - } - - /* - try { - auto image_asset = getHostObject( - runtime, args[9]); - if (image_asset != nullptr) { - canvas_native_webgl2_tex_image3d_asset( - target, - level, - internalformat, - width, - height, - depth, - border, - format, - type, - image_asset->GetImageAsset(), - ptr->GetState() - ); - - return jsi::Value::undefined(); - } - } catch (...) {} - - try { - auto image_bitmap = getHostObject( - runtime, args[9]); - if (image_bitmap != nullptr) { - canvas_native_webgl2_tex_image3d_asset( - target, - level, - internalformat, - width, - height, - depth, - border, - format, - type, - image_bitmap->GetImageAsset(), - ptr->GetState() - ); - - return jsi::Value::undefined(); - } - } catch (...) {} -*/ - - } - } else if (count > 10) { - - auto target = (int32_t) args[0]->NumberValue(context).ToChecked(); - auto level = (int32_t) args[1]->NumberValue(context).ToChecked(); - auto internalformat = (int32_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 depth = (int32_t) args[5]->NumberValue(context).ToChecked(); - auto border = (int32_t) args[6]->NumberValue(context).ToChecked(); - auto format = (int32_t) args[7]->NumberValue(context).ToChecked(); - auto type = (uint32_t) args[8]->NumberValue(context).ToChecked(); - if (args[9]->IsObject()) { - auto imageOrPixelsOrOffset = args[9].asObject( - runtime); - size_t srcOffsetValue = 0; - if (args[9]->IsNumber()) { - srcOffsetValue = static_cast(args[9]->NumberValue(context).ToChecked()); - } - - if (imageOrPixelsOrOffset.isTypedArray( - runtime)) { - auto buf = imageOrPixelsOrOffset.getTypedArray( - runtime); - auto size = buf.size(runtime); - auto array = GetTypedArrayData( - runtime, buf); - - srcOffsetValue = - srcOffsetValue * size; - if (srcOffsetValue > - size) { - return jsi::Value::undefined(); - } - - canvas_native_webgl2_tex_image3d_offset( - target, - level, - internalformat, - width, - height, - depth, - border, - format, - type, - array, - srcOffsetValue, - ptr->GetState() - ); - return jsi::Value::undefined(); - } - } - - } - - return jsi::Value::undefined(); - } - ); - } else if (methodName == "texStorage2D") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 5, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { - if (count > 4) { - auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); - auto levels = (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(); - canvas_native_webgl2_tex_storage2d( - target, - levels, - internalFormat, - width, - height, - ptr->GetState() - ); - } - - return jsi::Value::undefined(); - - } - ); - } else if (methodName == "texStorage3D") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 6, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { - - if (count > 5) { - auto target = (uint32_t) args[0]->NumberValue(context).ToChecked(); - auto levels = (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 depth = (int32_t) args[5]->NumberValue(context).ToChecked(); - canvas_native_webgl2_tex_storage3d( - target, - levels, - internalFormat, - width, - height, - depth, - ptr->GetState() - ); - } - - return jsi::Value::undefined(); - - } - ); - } else if (methodName == "texSubImage3D") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 12, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { - if (count == 11) { - 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 zoffset = (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 depth = (int32_t) args[7]->NumberValue(context).ToChecked(); - auto format = (uint32_t) args[8]->NumberValue(context).ToChecked(); - auto type = (int32_t) args[9]->NumberValue(context).ToChecked(); - - if (args[10]->IsNumber()) { - auto imageOrPixelsOrOffset = args[10]->NumberValue(context).ToChecked(); - canvas_native_webgl2_tex_sub_image3d_none( - target, - level, - xoffset, - yoffset, - zoffset, - width, - height, - depth, - format, - type, - static_cast(imageOrPixelsOrOffset), - ptr->GetState() - ); - return jsi::Value::undefined(); - } - - if (args[10]->IsObject()) { - auto imageOrPixelsOrOffsetObject = args[10].asObject( - runtime); - if (imageOrPixelsOrOffsetObject.isTypedArray( - runtime)) { - auto array = imageOrPixelsOrOffsetObject.getTypedArray( - runtime); - auto slice = GetTypedArrayData( - runtime, array); - - canvas_native_webgl2_tex_sub_image3d( - target, - level, - xoffset, - yoffset, - zoffset, - width, - height, - depth, - format, - type, - slice, - ptr->GetState() - ); - - return jsi::Value::undefined(); - } - - /* - auto asset = getHostObject( - runtime, args[10]); - if (asset != nullptr) { - - canvas_native_webgl2_tex_sub_image3d_asset( - target, - level, - xoffset, - yoffset, - zoffset, - width, - height, - depth, - format, - type, - asset->GetImageAsset(), - ptr->GetState() - ); - } - - */ - } - - } else if (count > 11) { - 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 zoffset = (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 depth = (int32_t) args[7]->NumberValue(context).ToChecked(); - auto format = (uint32_t) args[8]->NumberValue(context).ToChecked(); - auto type = (uint32_t) args[9]->NumberValue(context).ToChecked(); - - size_t srcOffsetValue = 0; - if (args[11]->IsNumber()) { - srcOffsetValue = static_cast(args[11]->NumberValue(context).ToChecked()); - } - - if (args[10]->IsObject()) { - auto imageOrPixelsOrOffsetObject = args[10].asObject( - runtime); - - if (imageOrPixelsOrOffsetObject.isTypedArray( - runtime)) { - auto array = imageOrPixelsOrOffsetObject.getTypedArray( - runtime); - auto buf = GetTypedArrayData( - runtime, array); - auto size = array.size( - runtime); - srcOffsetValue = - srcOffsetValue * size; - if (srcOffsetValue > size) { - return jsi::Value::undefined(); - } - - rust::Slice slice( - buf.data(), - buf.size()); - - canvas_native_webgl2_tex_sub_image3d_offset( - target, - level, - xoffset, - yoffset, - zoffset, - width, - height, - depth, - format, - type, - slice, - srcOffsetValue, - ptr->GetState() - ); - } - - } - } - - return jsi::Value::undefined(); - - } - ); - } else if (methodName == "transformFeedbackVaryings") { - 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 && args[1]->IsObject()) { - auto program = getHostObject( - runtime, args[0]); - auto varyingsObject = args[1].asObject( - runtime); - auto bufferMode = (uint32_t) args[2]->NumberValue(context).ToChecked(); - - if (program != nullptr && - varyingsObject.isArray(runtime)) { - auto varyings = varyingsObject.getArray( - runtime); - auto len = varyings.size(runtime); - rust::Vec buf; - buf.reserve(len); - for (int j = 0; j < len; ++j) { - auto name = varyings.getValueAtIndex( - runtime, j).asString( - runtime).utf8(runtime); - rust::Str val(name.data(), - name.size()); - buf.emplace_back(val); - } - - rust::Slice slice( - buf.data(), buf.size()); - - canvas_native_webgl2_transform_feedback_varyings( - program->GetProgram(), - slice, - bufferMode, - ptr->GetState() - ); - } - } - return jsi::Value::undefined(); - } - ); - } else if (methodName == "uniform1ui") { - 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 && args[1]->IsNumber()) { - - auto location = getHostObject( - runtime, args[0]); - auto v0 = (uint32_t) args[1]->NumberValue(context).ToChecked(); - - if (location != nullptr) { - canvas_native_webgl2_uniform1ui( - location->GetUniformLocation(), - v0, - ptr->GetState() - ); - } - } - return jsi::Value::undefined(); - } - ); - } else if (methodName == "uniform1uiv") { - 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 && args[1]->IsObject()) { - auto location = getHostObject( - runtime, args[0]); - auto data = args[1].asObject( - runtime); - if (location != nullptr && - data.isUint32Array(runtime)) { - auto array = data.getTypedArray( - runtime); - auto slice = GetTypedArrayData( - runtime, array); - canvas_native_webgl2_uniform1uiv( - location->GetUniformLocation(), - slice, - ptr->GetState() - ); - } else { - rust::Vec buf; - auto array = data.getArray( - runtime); - auto len = array.size(runtime); - buf.reserve(len); - for (int i = 0; i < len; i++) { - auto item = (uint32_t) array.getValueAtIndex( - runtime, i)->NumberValue(context).ToChecked(); - buf.push_back(item); - } - rust::Slice slice( - buf.data(), buf.size()); - canvas_native_webgl2_uniform1uiv( - location->GetUniformLocation(), - slice, - ptr->GetState() - ); - } - - - } - return jsi::Value::undefined(); - - } - ); - } else if (methodName == "uniform2ui") { - 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 location = getHostObject( - runtime, args[0]); - auto v0 = (uint32_t) args[1]->NumberValue(context).ToChecked(); - auto v1 = (uint32_t) args[2]->NumberValue(context).ToChecked(); - - if (location != nullptr) { - canvas_native_webgl2_uniform2ui( - location->GetUniformLocation(), - v0, - v1, - ptr->GetState() - ); - } - - - } - return jsi::Value::undefined(); - } - ); - } else if (methodName == "uniform2uiv") { - 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 > 1 && args[1]->IsObject()) { - - auto location = getHostObject( - runtime, args[0]); - auto data = args[1].asObject( - runtime); - - if (data.isUint32Array(runtime)) { - auto array = data.getTypedArray( - runtime); - auto slice = GetTypedArrayData( - runtime, array); - canvas_native_webgl2_uniform2uiv( - location->GetUniformLocation(), - slice, - ptr->GetState() - ); - } else { - rust::Vec buf; - auto array = data.getArray( - runtime); - auto len = array.size(runtime); - buf.reserve(len); - for (int i = 0; i < len; i++) { - auto item = (uint32_t) array.getValueAtIndex( - runtime, i)->NumberValue(context).ToChecked(); - buf.push_back(item); - } - - rust::Slice slice( - buf.data(), buf.size()); - canvas_native_webgl2_uniform2uiv( - location->GetUniformLocation(), - slice, - ptr->GetState() - ); - } - } - return jsi::Value::undefined(); - - } - ); - } else if (methodName == "uniform3ui") { - 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 { - if (count > 3) { - auto location = getHostObject( - runtime, args[0]); - auto v0 = (uint32_t) args[1]->NumberValue(context).ToChecked(); - auto v1 = (uint32_t) args[2]->NumberValue(context).ToChecked(); - auto v2 = (uint32_t) args[3]->NumberValue(context).ToChecked(); - if (location != nullptr) { - canvas_native_webgl2_uniform3ui( - location->GetUniformLocation(), - v0, - v1, - v2, - ptr->GetState() - ); - } - } - - return jsi::Value::undefined(); - } - ); - } else if (methodName == "uniform3uiv") { - 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 && args[1]->IsObject()) { - auto location = getHostObject( - runtime, args[0]); - auto data = args[1].asObject( - runtime); - - if (data.isUint32Array(runtime)) { - auto array = data.getTypedArray( - runtime); - auto slice = GetTypedArrayData( - runtime, array); - canvas_native_webgl2_uniform3uiv( - location->GetUniformLocation(), - slice, - ptr->GetState() - ); - } else { - rust::Vec buf; - auto array = data.getArray( - runtime); - auto len = array.size(runtime); - buf.reserve(len); - for (int i = 0; i < len; i++) { - auto item = array.getValueAtIndex( - runtime, i)->NumberValue(context).ToChecked(); - buf.push_back((uint32_t) item); - } - - rust::Slice slice( - buf.data(), buf.size()); - - canvas_native_webgl2_uniform3uiv( - location->GetUniformLocation(), - slice, - ptr->GetState() - ); - } - } - return jsi::Value::undefined(); - - } - ); - } else if (methodName == "uniform4ui") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 5, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { - - if (count > 4) { - - auto location = getHostObject( - runtime, args[0]); - auto v0 = (uint32_t) args[1]->NumberValue(context).ToChecked(); - auto v1 = (uint32_t) args[2]->NumberValue(context).ToChecked(); - auto v2 = (uint32_t) args[3]->NumberValue(context).ToChecked(); - auto v3 = (uint32_t) args[4]->NumberValue(context).ToChecked(); - if (location != nullptr) { - canvas_native_webgl2_uniform4ui( - location->GetUniformLocation(), - v0, - v1, - v2, - v3, - ptr->GetState() - ); - } - } - - return jsi::Value::undefined(); - } - ); - } else if (methodName == "uniform4uiv") { - 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 && args[1]->IsObject()) { - - auto location = getHostObject( - runtime, args[0]); - auto data = args[1].asObject( - runtime); - - if (data.isUint32Array(runtime)) { - auto array = data.getTypedArray( - runtime); - auto slice = GetTypedArrayData( - runtime, array); - canvas_native_webgl2_uniform4uiv( - location->GetUniformLocation(), - slice, - ptr->GetState() - ); - } else { - rust::Vec buf; - auto array = data.getArray( - runtime); - auto len = array.size(runtime); - buf.reserve(len); - for (int i = 0; i < len; i++) { - auto item = array.getValueAtIndex( - runtime, i)->NumberValue(context).ToChecked(); - buf.push_back((uint32_t) item); - } - - rust::Slice slice( - buf.data(), buf.size()); - - canvas_native_webgl2_uniform4uiv( - location->GetUniformLocation(), - slice, - ptr->GetState() - ); - } - } - - return jsi::Value::undefined(); - - } - ); - } else if (methodName == "uniformBlockBinding") { - 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 program = getHostObject( - runtime, args[0]); - auto uniformBlockIndex = args[1]->NumberValue(context).ToChecked(); - auto uniformBlockBinding = args[2]->NumberValue(context).ToChecked(); - - if (program != nullptr) { - canvas_native_webgl2_uniform_block_binding( - program->GetProgram(), - (uint32_t) uniformBlockIndex, - (uint32_t) uniformBlockBinding, - ptr->GetState() - ); - } - - } - return jsi::Value::undefined(); - } - ); - } else if (methodName == "uniformMatrix2x3fv") { - 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 && args[2]->IsObject()) { - - auto location = getHostObject( - runtime, args[0]); - auto transpose = args[1].asBool(); - auto data = args[2].asObject( - runtime); - - if (data.isFloat32Array(runtime)) { - auto array = data.getTypedArray( - runtime); - auto slice = GetTypedArrayData( - runtime, array); - canvas_native_webgl2_uniform_matrix2x3fv( - location->GetUniformLocation(), - transpose, - slice, - ptr->GetState() - ); - } else if (data.isArray(runtime)) { - rust::Vec buf; - auto array = data.getArray( - runtime); - auto len = array.size(runtime); - for (int i = 0; i < len; i++) { - auto item = array.getValueAtIndex( - runtime, i); - if (item->IsNumber()) { - buf.push_back( - static_cast(item->NumberValue(context).ToChecked())); - } else { - buf.push_back( - std::nanf("")); - } - } - - rust::Slice slice( - buf.data(), buf.size()); - - canvas_native_webgl2_uniform_matrix2x3fv( - location->GetUniformLocation(), - transpose, - slice, - ptr->GetState() - ); - } - } - return jsi::Value::undefined(); - - } - ); - } else if (methodName == "uniformMatrix2x4fv") { - 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 && args[2]->IsObject()) { - - auto location = getHostObject( - runtime, args[0]); - auto transpose = args[1].asBool(); - auto data = args[2].asObject( - runtime); - - if (data.isFloat32Array(runtime)) { - auto array = data.getTypedArray( - runtime); - auto slice = GetTypedArrayData( - runtime, array); - canvas_native_webgl2_uniform_matrix2x4fv( - location->GetUniformLocation(), - transpose, - slice, - ptr->GetState() - ); - } else if (data.isArray(runtime)) { - rust::Vec buf; - auto array = data.getArray( - runtime); - auto len = array.size(runtime); - for (int i = 0; i < len; i++) { - auto item = array.getValueAtIndex( - runtime, i); - if (item->IsNumber()) { - buf.push_back( - static_cast(item->NumberValue(context).ToChecked())); - } else { - buf.push_back( - std::nanf("")); - } - } - rust::Slice slice( - buf.data(), buf.size()); - - canvas_native_webgl2_uniform_matrix2x4fv( - location->GetUniformLocation(), - transpose, - slice, - ptr->GetState() - ); - } - } - - return jsi::Value::undefined(); - } - ); - } else if (methodName == "uniformMatrix3x2fv") { - 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 && args[2]->IsObject()) { - - auto location = getHostObject( - runtime, args[0]); - auto transpose = args[1].asBool(); - auto data = args[2].asObject( - runtime); - - if (data.isFloat32Array(runtime)) { - auto array = data.getTypedArray( - runtime); - auto slice = GetTypedArrayData( - runtime, array); - canvas_native_webgl2_uniform_matrix3x2fv( - location->GetUniformLocation(), - transpose, - slice, - ptr->GetState() - ); - } else if (data.isArray(runtime)) { - rust::Vec buf; - auto array = data.getArray( - runtime); - auto len = array.size(runtime); - for (int i = 0; i < len; i++) { - auto item = array.getValueAtIndex( - runtime, i); - if (item->IsNumber()) { - buf.push_back( - static_cast(item->NumberValue(context).ToChecked())); - } else { - buf.push_back( - std::nanf("")); - } - } - - rust::Slice slice( - buf.data(), buf.size()); - - canvas_native_webgl2_uniform_matrix3x2fv( - location->GetUniformLocation(), - transpose, - slice, - ptr->GetState() - ); - } - } - - return jsi::Value::undefined(); - } - ); - } else if (methodName == "uniformMatrix3x4fv") { - 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 && args[2]->IsObject()) { - - auto location = getHostObject( - runtime, args[0]); - auto transpose = args[1].asBool(); - auto data = args[2].asObject( - runtime); - - if (data.isFloat32Array(runtime)) { - auto array = data.getTypedArray( - runtime); - auto slice = GetTypedArrayData( - runtime, array); - canvas_native_webgl2_uniform_matrix3x4fv( - location->GetUniformLocation(), - transpose, - slice, - ptr->GetState() - ); - } else if (data.isArray(runtime)) { - rust::Vec buf; - auto array = data.getArray( - runtime); - auto len = array.size(runtime); - for (int i = 0; i < len; i++) { - auto item = array.getValueAtIndex( - runtime, i); - if (item->IsNumber()) { - buf.push_back( - static_cast(item->NumberValue(context).ToChecked())); - } else { - buf.push_back( - std::nanf("")); - } - } - - rust::Slice slice( - buf.data(), buf.size()); - - canvas_native_webgl2_uniform_matrix3x4fv( - location->GetUniformLocation(), - transpose, - slice, - ptr->GetState() - ); - } - } - - return jsi::Value::undefined(); - } - ); - } else if (methodName == "uniformMatrix4x2fv") { - 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 && args[2]->IsObject()) { - - auto location = getHostObject( - runtime, args[0]); - auto transpose = args[1].asBool(); - auto data = args[2].asObject( - runtime); - - if (data.isFloat32Array(runtime)) { - auto array = data.getTypedArray( - runtime); - auto slice = GetTypedArrayData( - runtime, array); - canvas_native_webgl2_uniform_matrix4x2fv( - location->GetUniformLocation(), - transpose, - slice, - ptr->GetState() - ); - } else if (data.isArray(runtime)) { - rust::Vec buf; - auto array = data.getArray( - runtime); - auto len = array.size(runtime); - for (int i = 0; i < len; i++) { - auto item = array.getValueAtIndex( - runtime, i); - if (item->IsNumber()) { - buf.push_back( - static_cast(item->NumberValue(context).ToChecked())); - } else { - buf.push_back( - std::nanf("")); - } - } - - rust::Slice slice( - buf.data(), buf.size()); - - canvas_native_webgl2_uniform_matrix4x2fv( - location->GetUniformLocation(), - transpose, - slice, - ptr->GetState() - ); - } - } - return jsi::Value::undefined(); - - } - ); - } else if (methodName == "uniformMatrix4x3fv") { - 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 && args[2]->IsObject()) { - - auto location = getHostObject( - runtime, args[0]); - auto transpose = args[1].asBool(); - auto data = args[2].asObject( - runtime); - - if (data.isFloat32Array(runtime)) { - auto array = data.getTypedArray( - runtime); - auto slice = GetTypedArrayData( - runtime, array); - canvas_native_webgl2_uniform_matrix4x3fv( - location->GetUniformLocation(), - transpose, - slice, - ptr->GetState() - ); - } else if (data.isArray(runtime)) { - rust::Vec buf; - auto array = data.getArray( - runtime); - auto len = array.size(runtime); - for (int i = 0; i < len; i++) { - auto item = array.getValueAtIndex( - runtime, i); - if (item->IsNumber()) { - buf.push_back( - static_cast(item->NumberValue(context).ToChecked())); - } else { - buf.push_back( - std::nanf("")); - } - } - - rust::Slice slice( - buf.data(), buf.size()); - - canvas_native_webgl2_uniform_matrix4x3fv( - location->GetUniformLocation(), - transpose, - slice, - ptr->GetState() - ); - } - } - - return jsi::Value::undefined(); - } - ); - } else if (methodName == "vertexAttribDivisor") { - 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) { - auto index = args[0]->NumberValue(context).ToChecked(); - auto divisor = args[1]->NumberValue(context).ToChecked(); - canvas_native_webgl2_vertex_attrib_divisor( - (uint32_t) index, - (uint32_t) divisor, - ptr->GetState() - ); - } - return jsi::Value::undefined(); - } - ); - } else if (methodName == "vertexAttribI4i") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 5, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { - - if (count > 4) { - auto index = args[0]->NumberValue(context).ToChecked(); - auto v0 = args[1]->NumberValue(context).ToChecked(); - auto v1 = args[2]->NumberValue(context).ToChecked(); - auto v2 = args[3]->NumberValue(context).ToChecked(); - auto v3 = args[4]->NumberValue(context).ToChecked(); - canvas_native_webgl2_vertex_attrib_i4i( - (uint32_t) index, - (int32_t) v0, - (int32_t) v1, - (int32_t) v2, - (int32_t) v3, - ptr->GetState() - ); - } - return jsi::Value::undefined(); - } - ); - } else if (methodName == "vertexAttribI4iv") { - 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 && args[1]->IsObject()) { - auto index = (uint32_t) args[0]->NumberValue(context).ToChecked(); - auto value = args[1].asObject( - runtime); - if (value.isInt32Array(runtime)) { - auto array = value.getTypedArray( - runtime); - auto slice = GetTypedArrayData( - runtime, array); - canvas_native_webgl2_vertex_attrib_i4iv( - index, - slice, - ptr->GetState() - ); - } else if (value.isArray(runtime)) { - auto array = value.getArray( - runtime); - auto len = array.size(runtime); - rust::Vec buf; - buf.reserve(len); - for (int i = 0; i < len; i++) { - auto item = (int32_t) array.getValueAtIndex( - runtime, i)->NumberValue(context).ToChecked(); - buf.push_back(item); - } - - rust::Slice slice( - buf.data(), buf.size()); - - canvas_native_webgl2_vertex_attrib_i4iv( - index, - slice, - ptr->GetState() - ); - } - } - - return jsi::Value::undefined(); - } - ); - } else if (methodName == "vertexAttribI4ui") { - return jsi::Function::createFromHostFunction(runtime, - jsi::PropNameID::forAscii(runtime, methodName), - 5, - [this](jsi::Runtime &runtime, - const jsi::Value &thisValue, - const jsi::Value *arguments, - size_t count) -> jsi::Value { - - if (count > 4) { - auto index = (uint32_t) args[0]->NumberValue(context).ToChecked(); - auto v0 = (uint32_t) args[1]->NumberValue(context).ToChecked(); - auto v1 = (uint32_t) args[2]->NumberValue(context).ToChecked(); - auto v2 = (uint32_t) args[3]->NumberValue(context).ToChecked(); - auto v3 = (uint32_t) args[4]->NumberValue(context).ToChecked(); - - canvas_native_webgl2_vertex_attrib_i4ui( - index, - v0, - v1, - v2, - v3, - ptr->GetState() - ); - } - return jsi::Value::undefined(); - } - ); - } else if (methodName == "vertexAttribI4uiv") { - 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 && args[1]->IsObject()) { - auto index = (uint32_t) args[0]->NumberValue(context).ToChecked(); - auto value = args[1].asObject( - runtime); - if (value.isUint32Array(runtime)) { - auto array = value.getTypedArray( - runtime); - auto slice = GetTypedArrayData( - runtime, array); - canvas_native_webgl2_vertex_attrib_i4uiv( - index, - slice, - ptr->GetState() - ); - } else if (value.isArray(runtime)) { - auto array = value.getArray( - runtime); - auto len = array.size(runtime); - rust::Vec buf; - buf.reserve(len); - for (int i = 0; i < len; i++) { - auto item = (uint32_t) array.getValueAtIndex( - runtime, i)->NumberValue(context).ToChecked(); - buf.push_back(item); - } - - rust::Slice slice( - buf.data(), buf.size()); - - canvas_native_webgl2_vertex_attrib_i4uiv( - index, - slice, - ptr->GetState() - ); - } - } - return jsi::Value::undefined(); - } + + if (args.Length() > 4) { + auto index = args[0]->NumberValue( + context).ToChecked(); + auto v0 = args[1]->NumberValue( + context).ToChecked(); + auto v1 = args[2]->NumberValue( + context).ToChecked(); + auto v2 = args[3]->NumberValue( + context).ToChecked(); + auto v3 = args[4]->NumberValue( + context).ToChecked(); + canvas_native_webgl2_vertex_attrib_i4i( + (uint32_t) index, + (int32_t) v0, + (int32_t) v1, + (int32_t) v2, + (int32_t) v3, + ptr->GetState() ); } - if (!prop.isUndefined()) { - return prop; +} + +void WebGL2RenderingContext::VertexAttribI4iv(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + + if (args.Length() > 1 && + args[1]->IsObject()) { + auto index = (uint32_t) args[0]->NumberValue( + context).ToChecked(); + auto value = args[1]; + if (value->IsInt32Array()) { + auto array = value.As(); + auto slice = GetTypedArrayData(array); + canvas_native_webgl2_vertex_attrib_i4iv( + index, + slice, + ptr->GetState() + ); + } else if (value->IsArray()) { + auto array = value.As(); + auto len = array->Length(); + rust::Vec buf; + buf.reserve(len); + for (int i = 0; i < len; i++) { + auto item = (int32_t) array->Get( + context, + i).ToLocalChecked()->NumberValue( + context).ToChecked(); + buf.push_back(item); + } + + rust::Slice slice( + buf.data(), buf.size()); + + canvas_native_webgl2_vertex_attrib_i4iv( + index, + slice, + ptr->GetState() + ); + } + } + +} + +void WebGL2RenderingContext::VertexAttribI4ui(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; } - auto gl_return = WebGLRenderingContext::get(runtime, name); - if (!gl_return.isUndefined()) { - return gl_return; + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + + if (args.Length() > 4) { + auto index = (uint32_t) args[0]->NumberValue( + context).ToChecked(); + auto v0 = (uint32_t) args[1]->NumberValue( + context).ToChecked(); + auto v1 = (uint32_t) args[2]->NumberValue( + context).ToChecked(); + auto v2 = (uint32_t) args[3]->NumberValue( + context).ToChecked(); + auto v3 = (uint32_t) args[4]->NumberValue( + context).ToChecked(); + + canvas_native_webgl2_vertex_attrib_i4ui( + index, + v0, + v1, + v2, + v3, + ptr->GetState() + ); } - return jsi::Value::undefined(); + } +void WebGL2RenderingContext::VertexAttribI4uiv(const v8::FunctionCallbackInfo &args) { + WebGL2RenderingContext *ptr = GetPointer(args.This()); + if (ptr == nullptr) { + return; + } + + auto isolate = args.GetIsolate(); + auto context = isolate->GetCurrentContext(); + + + if (args.Length() > 1 && + args[1]->IsObject()) { + auto index = (uint32_t) args[0]->NumberValue( + context).ToChecked(); + auto value = args[1]; + if (value->IsUint32Array()) { + auto array = value.As(); + auto slice = GetTypedArrayData(array); + canvas_native_webgl2_vertex_attrib_i4uiv( + index, + slice, + ptr->GetState() + ); + } else if (value->IsArray()) { + auto array = value.As(); + auto len = array->Length(); + rust::Vec buf; + buf.reserve(len); + for (int i = 0; i < len; i++) { + auto item = (uint32_t) array->Get( + context, + i).ToLocalChecked()->NumberValue( + context).ToChecked(); + buf.push_back(item); + } + + rust::Slice slice( + buf.data(), buf.size()); + + canvas_native_webgl2_vertex_attrib_i4uiv( + index, + slice, + ptr->GetState() + ); + } + } + +} void WebGL2RenderingContext::SetConstants(v8::Isolate *isolate, const v8::Local &tmpl) { @@ -4848,3 +3917,459 @@ void WebGL2RenderingContext::SetConstants(v8::Isolate *isolate, /* Transform feedback */ } + + +void WebGL2RenderingContext::SetMethods(v8::Isolate *isolate, + const v8::Local &tmpl) { + + tmpl->Set( + ConvertToV8String(isolate, "beginQuery"), + v8::FunctionTemplate::New(isolate, &BeginQuery) + ); + + tmpl->Set( + ConvertToV8String(isolate, "beginTransformFeedback"), + v8::FunctionTemplate::New(isolate, &BeginTransformFeedback) + ); + + tmpl->Set( + ConvertToV8String(isolate, "bindBufferBase"), + v8::FunctionTemplate::New(isolate, &BindBufferBase) + ); + + tmpl->Set( + ConvertToV8String(isolate, "bindBufferRange"), + v8::FunctionTemplate::New(isolate, &BindBufferRange) + ); + + tmpl->Set( + ConvertToV8String(isolate, "bindSampler"), + v8::FunctionTemplate::New(isolate, &BindSampler) + ); + + tmpl->Set( + ConvertToV8String(isolate, "bindTransformFeedback"), + v8::FunctionTemplate::New(isolate, &BindTransformFeedback) + ); + + tmpl->Set( + ConvertToV8String(isolate, "bindVertexArray"), + v8::FunctionTemplate::New(isolate, &BindVertexArray) + ); + + tmpl->Set( + ConvertToV8String(isolate, "blitFramebuffer"), + v8::FunctionTemplate::New(isolate, &BlitFramebuffer) + ); + + tmpl->Set( + ConvertToV8String(isolate, "clearBufferfi"), + v8::FunctionTemplate::New(isolate, &ClearBufferfi) + ); + + tmpl->Set( + ConvertToV8String(isolate, "clearBufferfv"), + v8::FunctionTemplate::New(isolate, &ClearBufferfv) + ); + + tmpl->Set( + ConvertToV8String(isolate, "clearBufferiv"), + v8::FunctionTemplate::New(isolate, &ClearBufferiv) + ); + + tmpl->Set( + ConvertToV8String(isolate, "clearBufferuiv"), + v8::FunctionTemplate::New(isolate, &ClearBufferuiv) + ); + + tmpl->Set( + ConvertToV8String(isolate, "clientWaitSync"), + v8::FunctionTemplate::New(isolate, &ClientWaitSync) + ); + + tmpl->Set( + ConvertToV8String(isolate, "compressedTexSubImage3D"), + v8::FunctionTemplate::New(isolate, &CompressedTexSubImage3D) + ); + + tmpl->Set( + ConvertToV8String(isolate, "copyBufferSubData"), + v8::FunctionTemplate::New(isolate, &CopyBufferSubData) + ); + + tmpl->Set( + ConvertToV8String(isolate, "copyTexSubImage3D"), + v8::FunctionTemplate::New(isolate, &CopyTexSubImage3D) + ); + + tmpl->Set( + ConvertToV8String(isolate, "createQuery"), + v8::FunctionTemplate::New(isolate, &CreateQuery) + ); + + tmpl->Set( + ConvertToV8String(isolate, "createSampler"), + v8::FunctionTemplate::New(isolate, &CreateSampler) + ); + + tmpl->Set( + ConvertToV8String(isolate, "createTransformFeedback"), + v8::FunctionTemplate::New(isolate, &CreateTransformFeedback) + ); + + tmpl->Set( + ConvertToV8String(isolate, "createVertexArray"), + v8::FunctionTemplate::New(isolate, &CreateVertexArray) + ); + + tmpl->Set( + ConvertToV8String(isolate, "deleteQuery"), + v8::FunctionTemplate::New(isolate, &DeleteQuery) + ); + + + tmpl->Set( + ConvertToV8String(isolate, "deleteSampler"), + v8::FunctionTemplate::New(isolate, &DeleteSampler) + ); + + tmpl->Set( + ConvertToV8String(isolate, "deleteSync"), + v8::FunctionTemplate::New(isolate, &DeleteSync) + ); + + tmpl->Set( + ConvertToV8String(isolate, "deleteTransformFeedback"), + v8::FunctionTemplate::New(isolate, &DeleteTransformFeedback) + ); + + tmpl->Set( + ConvertToV8String(isolate, "deleteVertexArray"), + v8::FunctionTemplate::New(isolate, &DeleteVertexArray) + ); + + tmpl->Set( + ConvertToV8String(isolate, "drawArraysInstanced"), + v8::FunctionTemplate::New(isolate, &DrawArraysInstanced) + ); + + tmpl->Set( + ConvertToV8String(isolate, "drawBuffers"), + v8::FunctionTemplate::New(isolate, &DrawBuffers) + ); + + tmpl->Set( + ConvertToV8String(isolate, "drawElementsInstanced"), + v8::FunctionTemplate::New(isolate, &DrawElementsInstanced) + ); + + tmpl->Set( + ConvertToV8String(isolate, "drawRangeElements"), + v8::FunctionTemplate::New(isolate, &DrawRangeElements) + ); + + tmpl->Set( + ConvertToV8String(isolate, "endQuery"), + v8::FunctionTemplate::New(isolate, &EndQuery) + ); + + tmpl->Set( + ConvertToV8String(isolate, "endTransformFeedback"), + v8::FunctionTemplate::New(isolate, &EndTransformFeedback) + ); + + tmpl->Set( + ConvertToV8String(isolate, "fenceSync"), + v8::FunctionTemplate::New(isolate, &FenceSync) + ); + + tmpl->Set( + ConvertToV8String(isolate, "framebufferTextureLayer"), + v8::FunctionTemplate::New(isolate, &FramebufferTextureLayer) + ); + + tmpl->Set( + ConvertToV8String(isolate, "uniform1ui"), + v8::FunctionTemplate::New(isolate, &Uniform1ui) + ); + + tmpl->Set( + ConvertToV8String(isolate, "uniform1uiv"), + v8::FunctionTemplate::New(isolate, &Uniform1uiv) + ); + + tmpl->Set( + ConvertToV8String(isolate, "uniform2ui"), + v8::FunctionTemplate::New(isolate, &Uniform2ui) + ); + + tmpl->Set( + ConvertToV8String(isolate, "uniform2uiv"), + v8::FunctionTemplate::New(isolate, &Uniform2uiv) + ); + + tmpl->Set( + ConvertToV8String(isolate, "uniform3ui"), + v8::FunctionTemplate::New(isolate, &Uniform3ui) + ); + + tmpl->Set( + ConvertToV8String(isolate, "uniform3uiv"), + v8::FunctionTemplate::New(isolate, &Uniform3uiv) + ); + + tmpl->Set( + ConvertToV8String(isolate, "uniform4ui"), + v8::FunctionTemplate::New(isolate, &Uniform4ui) + ); + + tmpl->Set( + ConvertToV8String(isolate, "uniform4uiv"), + v8::FunctionTemplate::New(isolate, &Uniform4uiv) + ); + + + tmpl->Set( + ConvertToV8String(isolate, "uniformBlockBinding"), + v8::FunctionTemplate::New(isolate, &UniformBlockBinding) + ); + + + tmpl->Set( + ConvertToV8String(isolate, "uniformMatrix2x3fv"), + v8::FunctionTemplate::New(isolate, &UniformMatrix2x3fv) + ); + + tmpl->Set( + ConvertToV8String(isolate, "uniformMatrix2x4fv"), + v8::FunctionTemplate::New(isolate, &UniformMatrix2x4fv) + ); + + tmpl->Set( + ConvertToV8String(isolate, "uniformMatrix3x2fv"), + v8::FunctionTemplate::New(isolate, &UniformMatrix3x2fv) + ); + + + tmpl->Set( + ConvertToV8String(isolate, "uniformMatrix3x4fv"), + v8::FunctionTemplate::New(isolate, &UniformMatrix3x4fv) + ); + + tmpl->Set( + ConvertToV8String(isolate, "uniformMatrix4x2fv"), + v8::FunctionTemplate::New(isolate, &UniformMatrix4x2fv) + ); + + tmpl->Set( + ConvertToV8String(isolate, "uniformMatrix4x3fv"), + v8::FunctionTemplate::New(isolate, &UniformMatrix4x3fv) + ); + + tmpl->Set( + ConvertToV8String(isolate, "uniformMatrix4x3fv"), + v8::FunctionTemplate::New(isolate, &UniformMatrix4x3fv) + ); + + tmpl->Set( + ConvertToV8String(isolate, "vertexAttribDivisor"), + v8::FunctionTemplate::New(isolate, &VertexAttribDivisor) + ); + + tmpl->Set( + ConvertToV8String(isolate, "vertexAttribI4i"), + v8::FunctionTemplate::New(isolate, &VertexAttribI4i) + ); + + tmpl->Set( + ConvertToV8String(isolate, "vertexAttribI4iv"), + v8::FunctionTemplate::New(isolate, &VertexAttribI4iv) + ); + + tmpl->Set( + ConvertToV8String(isolate, "vertexAttribI4ui"), + v8::FunctionTemplate::New(isolate, &VertexAttribI4ui) + ); + + tmpl->Set( + ConvertToV8String(isolate, "vertexAttribI4uiv"), + v8::FunctionTemplate::New(isolate, &VertexAttribI4uiv) + ); + + tmpl->Set( + ConvertToV8String(isolate, "getActiveUniformBlockName"), + v8::FunctionTemplate::New(isolate, &GetActiveUniformBlockName) + ); + + tmpl->Set( + ConvertToV8String(isolate, "getActiveUniformBlockParameter"), + v8::FunctionTemplate::New(isolate, &GetActiveUniformBlockParameter) + ); + + tmpl->Set( + ConvertToV8String(isolate, "getActiveUniforms"), + v8::FunctionTemplate::New(isolate, &GetActiveUniforms) + ); + + tmpl->Set( + ConvertToV8String(isolate, "getBufferSubData"), + v8::FunctionTemplate::New(isolate, &GetBufferSubData) + ); + + + tmpl->Set( + ConvertToV8String(isolate, "getFragDataLocation"), + v8::FunctionTemplate::New(isolate, &GetFragDataLocation) + ); + + + tmpl->Set( + ConvertToV8String(isolate, "getIndexedParameter"), + v8::FunctionTemplate::New(isolate, &GetIndexedParameter) + ); + + tmpl->Set( + ConvertToV8String(isolate, "getInternalformatParameter"), + v8::FunctionTemplate::New(isolate, &GetInternalformatParameter) + ); + + tmpl->Set( + ConvertToV8String(isolate, "getParameter"), + v8::FunctionTemplate::New(isolate, &GetParameter) + ); + + tmpl->Set( + ConvertToV8String(isolate, "getQueryParameter"), + v8::FunctionTemplate::New(isolate, &GetQueryParameter) + ); + + + tmpl->Set( + ConvertToV8String(isolate, "getQuery"), + v8::FunctionTemplate::New(isolate, &GetQuery) + ); + + tmpl->Set( + ConvertToV8String(isolate, "getSamplerParameter"), + v8::FunctionTemplate::New(isolate, &GetSamplerParameter) + ); + + tmpl->Set( + ConvertToV8String(isolate, "getSyncParameter"), + v8::FunctionTemplate::New(isolate, &GetSyncParameter) + ); + + tmpl->Set( + ConvertToV8String(isolate, "getTransformFeedbackVarying"), + v8::FunctionTemplate::New(isolate, &GetTransformFeedbackVarying) + ); + + tmpl->Set( + ConvertToV8String(isolate, "getUniformBlockIndex"), + v8::FunctionTemplate::New(isolate, &GetUniformBlockIndex) + ); + + tmpl->Set( + ConvertToV8String(isolate, "getUniformIndices"), + v8::FunctionTemplate::New(isolate, &GetUniformIndices) + ); + + tmpl->Set( + ConvertToV8String(isolate, "invalidateFramebuffer"), + v8::FunctionTemplate::New(isolate, &InvalidateFramebuffer) + ); + + tmpl->Set( + ConvertToV8String(isolate, "invalidateSubFramebuffer"), + v8::FunctionTemplate::New(isolate, &InvalidateSubFramebuffer) + ); + + + tmpl->Set( + ConvertToV8String(isolate, "isQuery"), + v8::FunctionTemplate::New(isolate, &IsQuery) + ); + + tmpl->Set( + ConvertToV8String(isolate, "isSampler"), + v8::FunctionTemplate::New(isolate, &IsSampler) + ); + + tmpl->Set( + ConvertToV8String(isolate, "isSync"), + v8::FunctionTemplate::New(isolate, &IsSync) + ); + + tmpl->Set( + ConvertToV8String(isolate, "isTransformFeedback"), + v8::FunctionTemplate::New(isolate, &IsTransformFeedback) + ); + + tmpl->Set( + ConvertToV8String(isolate, "isVertexArray"), + v8::FunctionTemplate::New(isolate, &IsVertexArray) + ); + + + tmpl->Set( + ConvertToV8String(isolate, "pauseTransformFeedback"), + v8::FunctionTemplate::New(isolate, &PauseTransformFeedback) + ); + + tmpl->Set( + ConvertToV8String(isolate, "readBuffer"), + v8::FunctionTemplate::New(isolate, &ReadBuffer) + ); + + tmpl->Set( + ConvertToV8String(isolate, "renderbufferStorageMultisample"), + v8::FunctionTemplate::New(isolate, &RenderbufferStorageMultisample) + ); + + + tmpl->Set( + ConvertToV8String(isolate, "resumeTransformFeedback"), + v8::FunctionTemplate::New(isolate, &ResumeTransformFeedback) + ); + + tmpl->Set( + ConvertToV8String(isolate, "samplerParameterf"), + v8::FunctionTemplate::New(isolate, &SamplerParameterf) + ); + + tmpl->Set( + ConvertToV8String(isolate, "samplerParameteri"), + v8::FunctionTemplate::New(isolate, &SamplerParameteri) + ); + + tmpl->Set( + ConvertToV8String(isolate, "texImage3D"), + v8::FunctionTemplate::New(isolate, &TexImage3D) + ); + + + tmpl->Set( + ConvertToV8String(isolate, "texStorage2D"), + v8::FunctionTemplate::New(isolate, &TexStorage2D) + ); + + tmpl->Set( + ConvertToV8String(isolate, "texStorage3D"), + v8::FunctionTemplate::New(isolate, &TexStorage3D) + ); + + tmpl->Set( + ConvertToV8String(isolate, "texSubImage3D"), + v8::FunctionTemplate::New(isolate, &TexSubImage3D) + ); + + tmpl->Set( + ConvertToV8String(isolate, "transformFeedbackVaryings"), + v8::FunctionTemplate::New(isolate, &TransformFeedbackVaryings) + ); +} + +void WebGL2RenderingContext::SetProps(v8::Isolate *isolate, + const v8::Local &webgl2RenderingContextTpl) { + +} diff --git a/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl2/WebGL2RenderingContext.h b/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl2/WebGL2RenderingContext.h index f4a0c49b6..446ecb019 100644 --- a/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl2/WebGL2RenderingContext.h +++ b/packages/canvas/src-native/canvas-android/canvas/src/main/cpp/webgl2/WebGL2RenderingContext.h @@ -44,7 +44,7 @@ class WebGL2RenderingContext : public WebGLRenderingContext { SetProps(v8::Isolate *isolate, const v8::Local &webgl2RenderingContextTpl); static void SetMethods(v8::Isolate *isolate, - const v8::Local &webgl2RenderingContextTpl); + const v8::Local &tmpl); static void BeginQuery(const v8::FunctionCallbackInfo &args);