1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "../include/context/webgl2_rendering_context_base.h"
16 #include "../../common/napi/n_func_arg.h"
17 #include "../../common/napi/n_class.h"
18 #include "../include/webgl/webgl_active_info.h"
19 #include "../include/webgl/webgl_shader.h"
20 #include "../include/webgl/webgl_buffer.h"
21 #include "../include/webgl/webgl_framebuffer.h"
22 #include "../include/webgl/webgl_program.h"
23 #include "../include/webgl/webgl_renderbuffer.h"
24 #include "../include/webgl/webgl_texture.h"
25 #include "../include/webgl/webgl_sync.h"
26 #include "../include/webgl/webgl_sampler.h"
27 #include "../include/webgl/webgl_query.h"
28 #include "../include/webgl/webgl_transform_feedback.h"
29 #include "../include/webgl/webgl_uniform_location.h"
30 #include "../include/webgl/webgl_vertex_array_object.h"
31 #include "../include/util/log.h"
32 #include "../include/util/util.h"
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 namespace OHOS {
39 namespace Rosen {
40 using namespace std;
41
DrawBuffers(napi_env env,napi_callback_info info)42 napi_value WebGL2RenderingContextBase::DrawBuffers(napi_env env, napi_callback_info info)
43 {
44 NFuncArg funcArg(env, info);
45
46 if (!funcArg.InitArgs(NARG_CNT::ONE)) {
47 return nullptr;
48 }
49 LOGI("WebGL2 drawBuffers start");
50 napi_value array = funcArg[NARG_POS::FIRST];
51 bool isArray = false;
52 bool succ = false;
53 tie(succ, isArray) = NVal(env, array).IsArray();
54 if (!isArray || !succ) {
55 return nullptr;
56 }
57 uint32_t length;
58 napi_status lengthStatus = napi_get_array_length(env, array, &length);
59 if (lengthStatus != napi_ok) {
60 return nullptr;
61 }
62 int64_t drawBuffers[length];
63 uint32_t i;
64 for (i = 0; i < length; i++) {
65 napi_value element;
66 napi_status eleStatus = napi_get_element(env, array, i, &element);
67 if (eleStatus != napi_ok) {
68 return nullptr;
69 }
70 int64_t ele;
71 napi_status intStatus = napi_get_value_int64(env, element, &ele);
72 if (intStatus != napi_ok) {
73 return nullptr;
74 }
75 drawBuffers[i] = ele;
76 }
77 glDrawBuffers(static_cast<GLsizei>(length), reinterpret_cast<GLenum *>(drawBuffers));
78 LOGI("WebGL2 drawBuffers end");
79 return nullptr;
80 }
81
ClearBufferfv(napi_env env,napi_callback_info info)82 napi_value WebGL2RenderingContextBase::ClearBufferfv(napi_env env, napi_callback_info info)
83 {
84 NFuncArg funcArg(env, info);
85
86 if (!funcArg.InitArgs(NARG_CNT::THREE, NARG_CNT::FOUR)) {
87 return nullptr;
88 }
89
90 LOGI("WebGL2 clearBufferfv start");
91 bool succ = false;
92 int64_t buffer;
93 tie(succ, buffer) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt64();
94 if (!succ) {
95 return nullptr;
96 }
97 LOGI("WebGL2 WebGL2RenderingContextBase::clearBufferfv buffer = %{public}u", buffer);
98 int64_t drawbuffer;
99 tie(succ, drawbuffer) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt64();
100 if (!succ) {
101 return nullptr;
102 }
103 LOGI("WebGL2 WebGL2RenderingContextBase::clearBufferfv drawbuffer = %{public}u", drawbuffer);
104
105 if (funcArg[NARG_POS::THIRD] == nullptr) {
106 return nullptr;
107 }
108 int64_t srcOffset = 0;
109 if (funcArg[NARG_POS::FOURTH] != nullptr) {
110 tie(succ, srcOffset) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt64();
111 if (!succ) {
112 return nullptr;
113 }
114 LOGI("WebGL2 WebGL2RenderingContextBase::clearBufferfv srcOffset = %{public}u", srcOffset);
115 }
116
117 napi_value array = funcArg[NARG_POS::THIRD];
118 bool isArray = false;
119 tie(succ, isArray) = NVal(env, array).IsArray();
120 if (isArray) {
121 uint32_t length;
122 napi_status lengthStatus = napi_get_array_length(env, array, &length);
123 if (lengthStatus != napi_ok) {
124 return nullptr;
125 }
126 float clearBufferfv[length];
127 uint32_t i;
128 for (i = 0; i < length; i++) {
129 napi_value element;
130 napi_status eleStatus = napi_get_element(env, array, i, &element);
131 if (eleStatus != napi_ok) {
132 return nullptr;
133 }
134 double ele;
135 napi_status doubleStatus = napi_get_value_double(env, element, &ele);
136 if (doubleStatus != napi_ok) {
137 return nullptr;
138 }
139 clearBufferfv[i] = (float)ele;
140 }
141 glClearBufferfv(static_cast<GLenum>(buffer), static_cast<GLint>(drawbuffer),
142 reinterpret_cast<GLfloat *>(clearBufferfv + srcOffset));
143 LOGI("WebGL2 clearBufferfv array end");
144 return nullptr;
145 }
146 bool isTypedarray = false;
147 tie(succ, isTypedarray) = NVal(env, array).IsTypeArray();
148 if (!isTypedarray || !succ) {
149 return nullptr;
150 }
151 void *data = nullptr;
152 size_t length;
153 napi_typedarray_type type;
154 tie(succ, type, data, length) = NVal(env, array).ToTypedArray();
155 if (!succ) {
156 return nullptr;
157 }
158 if (type == napi_float32_array) {
159 float* inputFloat = (float*)((uint8_t*)(data) + srcOffset);
160 glClearBufferfv(static_cast<GLenum>(buffer), static_cast<GLint>(drawbuffer),
161 reinterpret_cast<GLfloat *>(inputFloat));
162 }
163 LOGI("WebGL2 clearBufferfv typeArray end");
164 return nullptr;
165 }
166
ClearBufferiv(napi_env env,napi_callback_info info)167 napi_value WebGL2RenderingContextBase::ClearBufferiv(napi_env env, napi_callback_info info)
168 {
169 NFuncArg funcArg(env, info);
170
171 if (!funcArg.InitArgs(NARG_CNT::THREE, NARG_CNT::FOUR)) {
172 return nullptr;
173 }
174
175 LOGI("WebGL2 clearBufferiv start");
176
177 bool succ = false;
178 int64_t buffer;
179 tie(succ, buffer) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt64();
180 if (!succ) {
181 return nullptr;
182 }
183 LOGI("WebGL2 WebGL2RenderingContextBase::clearBufferiv buffer = %{public}u", buffer);
184 int64_t drawbuffer;
185 tie(succ, drawbuffer) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt64();
186 if (!succ) {
187 return nullptr;
188 }
189 LOGI("WebGL2 WebGL2RenderingContextBase::clearBufferiv drawbuffer = %{public}u", drawbuffer);
190
191 if (funcArg[NARG_POS::THIRD] == nullptr) {
192 return nullptr;
193 }
194 int64_t srcOffset = 0;
195 if (funcArg[NARG_POS::FOURTH] != nullptr) {
196 tie(succ, srcOffset) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt64();
197 if (!succ) {
198 return nullptr;
199 }
200 LOGI("WebGL2 WebGL2RenderingContextBase::clearBufferiv srcOffset = %{public}u", srcOffset);
201 }
202
203 napi_value array = funcArg[NARG_POS::THIRD];
204 bool isArray = false;
205 tie(succ, isArray) = NVal(env, array).IsArray();
206 if (isArray) {
207 uint32_t length;
208 napi_status lengthStatus = napi_get_array_length(env, array, &length);
209 if (lengthStatus != napi_ok) {
210 return nullptr;
211 }
212 int64_t clearBufferiv[length];
213 uint32_t i;
214 for (i = 0; i < length; i++) {
215 napi_value element;
216 napi_status eleStatus = napi_get_element(env, array, i, &element);
217 if (eleStatus != napi_ok) {
218 return nullptr;
219 }
220 int64_t ele;
221 napi_status intStatus = napi_get_value_int64(env, element, &ele);
222 if (intStatus != napi_ok) {
223 return nullptr;
224 }
225 clearBufferiv[i] = ele;
226 }
227 glClearBufferiv(static_cast<GLenum>(buffer), static_cast<GLint>(drawbuffer),
228 reinterpret_cast<GLint *>(clearBufferiv + srcOffset));
229 LOGI("WebGL2 clearBufferiv array end");
230 return nullptr;
231 }
232 bool isTypedarray = false;
233 tie(succ, isTypedarray) = NVal(env, array).IsTypeArray();
234 if (!isTypedarray || !succ) {
235 return nullptr;
236 }
237 void *data = nullptr;
238 size_t length;
239 napi_typedarray_type type;
240 tie(succ, type, data, length) = NVal(env, array).ToTypedArray();
241 if (!succ) {
242 return nullptr;
243 }
244 if (type == napi_int8_array) {
245 int8_t* inputInt8 = (int8_t*)((uint8_t*)(data) + srcOffset);
246 glClearBufferiv(static_cast<GLenum>(buffer), static_cast<GLint>(drawbuffer),
247 reinterpret_cast<GLint *>(inputInt8));
248 }
249 LOGI("WebGL2 clearBufferiv typeArray end");
250 return nullptr;
251 }
252
ClearBufferuiv(napi_env env,napi_callback_info info)253 napi_value WebGL2RenderingContextBase::ClearBufferuiv(napi_env env, napi_callback_info info)
254 {
255 NFuncArg funcArg(env, info);
256
257 if (!funcArg.InitArgs(NARG_CNT::THREE, NARG_CNT::FOUR)) {
258 return nullptr;
259 }
260
261 LOGI("WebGL2 clearBufferuiv start");
262
263 bool succ = false;
264 int64_t buffer;
265 tie(succ, buffer) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt64();
266 if (!succ) {
267 return nullptr;
268 }
269 LOGI("WebGL2 WebGL2RenderingContextBase::clearBufferuiv buffer = %{public}u", buffer);
270 int64_t drawbuffer;
271 tie(succ, drawbuffer) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt64();
272 if (!succ) {
273 return nullptr;
274 }
275 LOGI("WebGL2 WebGL2RenderingContextBase::clearBufferuiv drawbuffer = %{public}u", drawbuffer);
276
277 if (funcArg[NARG_POS::THIRD] == nullptr) {
278 return nullptr;
279 }
280 int64_t srcOffset = 0;
281 if (funcArg[NARG_POS::FOURTH] != nullptr) {
282 tie(succ, srcOffset) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt64();
283 if (!succ) {
284 return nullptr;
285 }
286 LOGI("WebGL2 WebGL2RenderingContextBase::clearBufferuiv srcOffset = %{public}u", srcOffset);
287 }
288
289 napi_value array = funcArg[NARG_POS::THIRD];
290 bool isArray = false;
291 tie(succ, isArray) = NVal(env, array).IsArray();
292 if (isArray) {
293 uint32_t length;
294 napi_status lengthStatus = napi_get_array_length(env, array, &length);
295 if (lengthStatus != napi_ok) {
296 return nullptr;
297 }
298 uint32_t clearBufferuiv[length];
299 uint32_t i;
300 for (i = 0; i < length; i++) {
301 napi_value element;
302 napi_status eleStatus = napi_get_element(env, array, i, &element);
303 if (eleStatus != napi_ok) {
304 return nullptr;
305 }
306 uint32_t ele;
307 napi_status uintStatus = napi_get_value_uint32(env, element, &ele);
308 if (uintStatus != napi_ok) {
309 return nullptr;
310 }
311 clearBufferuiv[i] = ele;
312 }
313 glClearBufferuiv(static_cast<GLenum>(buffer), static_cast<GLint>(drawbuffer),
314 reinterpret_cast<GLuint *>(clearBufferuiv + srcOffset));
315 LOGI("WebGL2 clearBufferuiv array end");
316 return nullptr;
317 }
318 bool isTypedarray = false;
319 tie(succ, isTypedarray) = NVal(env, array).IsTypeArray();
320 if (!isTypedarray || !succ) {
321 return nullptr;
322 }
323 void *data = nullptr;
324 size_t length;
325 napi_typedarray_type type;
326 tie(succ, type, data, length) = NVal(env, array).ToTypedArray();
327 if (!succ) {
328 return nullptr;
329 }
330 if (type == napi_int8_array) {
331 uint8_t* inputUint8 = (uint8_t*)((uint8_t*)(data) + srcOffset);
332 glClearBufferuiv(static_cast<GLenum>(buffer), static_cast<GLint>(drawbuffer),
333 reinterpret_cast<GLuint *>(inputUint8));
334 }
335
336 LOGI("WebGL2 clearBufferuiv typeArray end");
337 return nullptr;
338 }
339
ClearBufferfi(napi_env env,napi_callback_info info)340 napi_value WebGL2RenderingContextBase::ClearBufferfi(napi_env env, napi_callback_info info)
341 {
342 NFuncArg funcArg(env, info);
343
344 if (!funcArg.InitArgs(NARG_CNT::FOUR)) {
345 return nullptr;
346 }
347 bool succ = false;
348 LOGI("WebGL2 clearBufferfi start");
349 int64_t buffer;
350 tie(succ, buffer) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt64();
351 if (!succ) {
352 return nullptr;
353 }
354 LOGI("WebGL2 WebGL2RenderingContextBase::clearBufferfi buffer = %{public}u", buffer);
355 int64_t drawbuffer;
356 tie(succ, drawbuffer) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt64();
357 if (!succ) {
358 return nullptr;
359 }
360 LOGI("WebGL2 WebGL2RenderingContextBase::clearBufferfi drawbuffer = %{public}u", drawbuffer);
361 double depth;
362 tie(succ, depth) = NVal(env, funcArg[NARG_POS::THIRD]).ToDouble();
363 if (!succ) {
364 return nullptr;
365 }
366
367 int64_t stencil;
368 tie(succ, stencil) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt64();
369 if (!succ) {
370 return nullptr;
371 }
372 LOGI("WebGL2 WebGL2RenderingContextBase::clearBufferfi stencil = %{public}u", stencil);
373 glClearBufferfi(static_cast<GLenum>(buffer), static_cast<GLint>(drawbuffer),
374 static_cast<GLfloat>((float) depth), static_cast<GLint>(stencil));
375 LOGI("WebGL2 clearBufferfi end");
376 return nullptr;
377 }
378
CreateQuery(napi_env env,napi_callback_info info)379 napi_value WebGL2RenderingContextBase::CreateQuery(napi_env env, napi_callback_info info)
380 {
381 LOGI("WebGL2 createQuery start");
382 napi_value objQuery = NClass::InstantiateClass(env, WebGLQuery::className, {});
383 if (!objQuery) {
384 return nullptr;
385 }
386 auto webGlQuery = NClass::GetEntityOf<WebGLQuery>(env, objQuery);
387 if (!webGlQuery) {
388 return nullptr;
389 }
390 unsigned int queryId;
391 glGenQueries(1, &queryId);
392 webGlQuery->SetQuery(queryId);
393 LOGI("WebGL2 WebGL2RenderingContextBase::createQuery queryId = %{public}u", queryId);
394 LOGI("WebGL2 createQuery end");
395 return objQuery;
396 }
397
DeleteQuery(napi_env env,napi_callback_info info)398 napi_value WebGL2RenderingContextBase::DeleteQuery(napi_env env, napi_callback_info info)
399 {
400 NFuncArg funcArg(env, info);
401
402 if (!funcArg.InitArgs(NARG_CNT::ONE)) {
403 return nullptr;
404 }
405 LOGI("WebGL2 deleteQuery start");
406 if (funcArg[NARG_POS::FIRST] == nullptr) {
407 return nullptr;
408 }
409
410 WebGLQuery *webGlQuery = nullptr;
411 napi_status queryStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGlQuery);
412 if (queryStatus != napi_ok) {
413 return nullptr;
414 }
415 unsigned int query = webGlQuery->GetQuery();
416
417 glDeleteQueries(1, &query);
418 LOGI("WebGL2 deleteQuery end");
419 return nullptr;
420 }
421
IsQuery(napi_env env,napi_callback_info info)422 napi_value WebGL2RenderingContextBase::IsQuery(napi_env env, napi_callback_info info)
423 {
424 NFuncArg funcArg(env, info);
425
426 if (!funcArg.InitArgs(NARG_CNT::ONE)) {
427 return NVal::CreateBool(env, false).val_;
428 }
429 LOGI("WebGL2 isQuery start");
430 if (funcArg[NARG_POS::FIRST] == nullptr) {
431 return NVal::CreateBool(env, false).val_;
432 }
433
434 WebGLQuery *webGlQuery = nullptr;
435 napi_status queryStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGlQuery);
436 if (queryStatus != napi_ok) {
437 return NVal::CreateBool(env, false).val_;
438 }
439 unsigned int query = webGlQuery->GetQuery();
440
441 GLboolean returnValue = glIsQuery(static_cast<GLuint>(query));
442 bool res = static_cast<bool>(returnValue);
443 LOGI("WebGL2 isQuery end");
444 return NVal::CreateBool(env, res).val_;
445 }
446
BeginQuery(napi_env env,napi_callback_info info)447 napi_value WebGL2RenderingContextBase::BeginQuery(napi_env env, napi_callback_info info)
448 {
449 NFuncArg funcArg(env, info);
450
451 if (!funcArg.InitArgs(NARG_CNT::TWO)) {
452 return nullptr;
453 }
454 bool succ = false;
455 LOGI("WebGL2 beginQuery start");
456 int64_t target;
457 tie(succ, target) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt64();
458 if (!succ) {
459 return nullptr;
460 }
461 LOGI("WebGL2 WebGL2RenderingContextBase::BeginQuery target = %{public}u", target);
462
463 if (funcArg[NARG_POS::SECOND] == nullptr) {
464 return nullptr;
465 }
466
467 WebGLQuery *webGlQuery = nullptr;
468 napi_status queryStatus = napi_unwrap(env, funcArg[NARG_POS::SECOND], (void **) &webGlQuery);
469 if (queryStatus != napi_ok) {
470 return nullptr;
471 }
472 unsigned int query = webGlQuery->GetQuery();
473
474 WebGL2RenderingContextBase *obj = reinterpret_cast<WebGL2RenderingContextBase *>(Util::GetContextObject(env,
475 funcArg.GetThisVar(), "webgl2"));
476 if (obj == nullptr) {
477 return nullptr;
478 }
479
480 obj->queryMaps.insert({ static_cast<GLenum>(target), static_cast<GLuint>(query) });
481
482 glBeginQuery(static_cast<GLenum>(target), static_cast<GLuint>(query));
483 LOGI("WebGL2 beginQuery end");
484 return nullptr;
485 }
486
EndQuery(napi_env env,napi_callback_info info)487 napi_value WebGL2RenderingContextBase::EndQuery(napi_env env, napi_callback_info info)
488 {
489 NFuncArg funcArg(env, info);
490
491 if (!funcArg.InitArgs(NARG_CNT::ONE)) {
492 return nullptr;
493 }
494 bool succ = false;
495 LOGI("WebGL2 endQuery start");
496 int64_t target;
497 tie(succ, target) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt64();
498 if (!succ) {
499 return nullptr;
500 }
501 LOGI("WebGL2 WebGL2RenderingContextBase::endQuery target = %{public}u", target);
502
503 WebGL2RenderingContextBase *obj = reinterpret_cast<WebGL2RenderingContextBase *>(Util::GetContextObject(env,
504 funcArg.GetThisVar(), "webgl2"));
505 if (obj == nullptr) {
506 return nullptr;
507 }
508 obj->queryMaps.erase(static_cast<GLenum>(target));
509
510 glEndQuery(static_cast<GLenum>(target));
511 LOGI("WebGL2 endQuery end");
512 return nullptr;
513 }
514
GetQuery(napi_env env,napi_callback_info info)515 napi_value WebGL2RenderingContextBase::GetQuery(napi_env env, napi_callback_info info)
516 {
517 NFuncArg funcArg(env, info);
518
519 if (!funcArg.InitArgs(NARG_CNT::TWO)) {
520 return nullptr;
521 }
522 bool succ = false;
523 LOGI("WebGL2 getQuery start");
524 int64_t target;
525 tie(succ, target) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt64();
526 if (!succ) {
527 return nullptr;
528 }
529 LOGI("WebGL2 WebGL2RenderingContextBase::getQuery target = %{public}u", target);
530
531 int64_t pName;
532 tie(succ, pName) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt64();
533 if (!succ) {
534 return nullptr;
535 }
536 LOGI("WebGL2 WebGL2RenderingContextBase::getQuery pName = %{public}u", pName);
537
538 WebGL2RenderingContextBase *obj = reinterpret_cast<WebGL2RenderingContextBase *>(Util::GetContextObject(env,
539 funcArg.GetThisVar(), "webgl2"));
540 if (obj == nullptr) {
541 return nullptr;
542 }
543 auto objects = obj->queryMaps;
544 auto it = objects.find(static_cast<GLenum>(target));
545 if (it == objects.end()) {
546 return NVal::CreateNull(env).val_;
547 }
548 GLint params;
549 glGetQueryiv(static_cast<GLenum>(target), static_cast<GLenum>(pName), ¶ms);
550 napi_value objQuery = NClass::InstantiateClass(env, WebGLQuery::className, {});
551 if (!objQuery) {
552 return nullptr;
553 }
554 auto webGlQuery = NClass::GetEntityOf<WebGLQuery>(env, objQuery);
555 if (!webGlQuery) {
556 return nullptr;
557 }
558 webGlQuery->SetQuery(it->second);
559 LOGI("WebGL2 getQuery end");
560 return objQuery;
561 }
562
GetQueryParameter(napi_env env,napi_callback_info info)563 napi_value WebGL2RenderingContextBase::GetQueryParameter(napi_env env, napi_callback_info info)
564 {
565 NFuncArg funcArg(env, info);
566
567 if (!funcArg.InitArgs(NARG_CNT::TWO)) {
568 return nullptr;
569 }
570
571 if (funcArg[NARG_POS::FIRST] == nullptr) {
572 return nullptr;
573 }
574 LOGI("WebGL2 getQueryParameter start");
575 WebGLSampler *webGlSampler = nullptr;
576 napi_status samplerStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGlSampler);
577 if (samplerStatus != napi_ok) {
578 return nullptr;
579 }
580 unsigned int sampler = webGlSampler->GetSampler();
581
582 bool succ = false;
583 int64_t pName;
584 tie(succ, pName) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt64();
585 if (!succ) {
586 return nullptr;
587 }
588 LOGI("WebGL2 WebGL2RenderingContextBase::getQueryParameter pName = %{public}u", pName);
589 GLuint params;
590 glGetQueryObjectuiv(static_cast<GLuint>(sampler), static_cast<GLenum>(pName), ¶ms);
591 if (pName == GL_QUERY_RESULT) {
592 int64_t res = static_cast<int64_t>(params);
593 LOGI("WebGL2 getQueryParameter end");
594 return NVal::CreateInt64(env, res).val_;
595 } else if (pName == GL_QUERY_RESULT_AVAILABLE) {
596 bool res = (params == GL_FALSE) ? false : true;
597 LOGI("WebGL2 getQueryParameter end");
598 return NVal::CreateBool(env, res).val_;
599 } else {
600 return nullptr;
601 }
602 }
603
CreateSampler(napi_env env,napi_callback_info info)604 napi_value WebGL2RenderingContextBase::CreateSampler(napi_env env, napi_callback_info info)
605 {
606 LOGI("WebGL2 createSampler start");
607 napi_value objSampler = NClass::InstantiateClass(env, WebGLSampler::className, {});
608 if (!objSampler) {
609 return nullptr;
610 }
611 auto webGlSampler = NClass::GetEntityOf<WebGLSampler>(env, objSampler);
612 if (!webGlSampler) {
613 return nullptr;
614 }
615 unsigned int samplerId;
616 glGenSamplers(1, &samplerId);
617 webGlSampler->SetSampler(samplerId);
618 LOGI("WebGL2 WebGL2RenderingContextBase::createSampler samplerId = %{public}u", samplerId);
619 LOGI("WebGL2 createSampler end");
620 return objSampler;
621 }
622
DeleteSampler(napi_env env,napi_callback_info info)623 napi_value WebGL2RenderingContextBase::DeleteSampler(napi_env env, napi_callback_info info)
624 {
625 NFuncArg funcArg(env, info);
626
627 if (!funcArg.InitArgs(NARG_CNT::ONE)) {
628 return nullptr;
629 }
630 LOGI("WebGL2 deleteSampler start");
631 if (funcArg[NARG_POS::FIRST] == nullptr) {
632 return nullptr;
633 }
634
635 WebGLSampler *webGlSampler = nullptr;
636 napi_status samplerStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGlSampler);
637 if (samplerStatus != napi_ok) {
638 return nullptr;
639 }
640 unsigned int sampler = webGlSampler->GetSampler();
641
642 glDeleteSamplers(1, &sampler);
643 LOGI("WebGL2 deleteSampler end");
644 return nullptr;
645 }
646
IsSampler(napi_env env,napi_callback_info info)647 napi_value WebGL2RenderingContextBase::IsSampler(napi_env env, napi_callback_info info)
648 {
649 NFuncArg funcArg(env, info);
650
651 if (!funcArg.InitArgs(NARG_CNT::ONE)) {
652 return NVal::CreateBool(env, false).val_;
653 }
654 LOGI("WebGL2 isSampler start");
655 if (funcArg[NARG_POS::FIRST] == nullptr) {
656 return NVal::CreateBool(env, false).val_;
657 }
658
659 WebGLSampler *webGlSampler = nullptr;
660 napi_status samplerStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGlSampler);
661 if (samplerStatus != napi_ok) {
662 return NVal::CreateBool(env, false).val_;
663 }
664 unsigned int sampler = webGlSampler->GetSampler();
665
666 GLboolean returnValue = glIsSampler(static_cast<GLuint>(sampler));
667 bool res = static_cast<bool>(returnValue);
668 LOGI("WebGL2 isSampler end");
669 return NVal::CreateBool(env, res).val_;
670 }
671
BindSampler(napi_env env,napi_callback_info info)672 napi_value WebGL2RenderingContextBase::BindSampler(napi_env env, napi_callback_info info)
673 {
674 NFuncArg funcArg(env, info);
675
676 if (!funcArg.InitArgs(NARG_CNT::TWO)) {
677 return nullptr;
678 }
679 bool succ = false;
680 LOGI("WebGL2 bindSampler start");
681 int64_t unit;
682 tie(succ, unit) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt64();
683 if (!succ) {
684 return nullptr;
685 }
686 LOGI("WebGL2 WebGL2RenderingContextBase::bindSampler unit = %{public}u", unit);
687
688 if (funcArg[NARG_POS::SECOND] == nullptr) {
689 return nullptr;
690 }
691
692 WebGLSampler *webGlSampler = nullptr;
693 napi_status samplerStatus = napi_unwrap(env, funcArg[NARG_POS::SECOND], (void **) &webGlSampler);
694 if (samplerStatus != napi_ok) {
695 return nullptr;
696 }
697 unsigned int sampler = webGlSampler->GetSampler();
698 glBindSampler(static_cast<GLuint>(unit), static_cast<GLuint>(sampler));
699 LOGI("WebGL2 bindSampler end");
700 return nullptr;
701 }
702
SamplerParameteri(napi_env env,napi_callback_info info)703 napi_value WebGL2RenderingContextBase::SamplerParameteri(napi_env env, napi_callback_info info)
704 {
705 NFuncArg funcArg(env, info);
706
707 if (!funcArg.InitArgs(NARG_CNT::THREE)) {
708 return nullptr;
709 }
710
711 if (funcArg[NARG_POS::FIRST] == nullptr) {
712 return nullptr;
713 }
714 LOGI("WebGL2 samplerParameteri start");
715 WebGLSampler *webGlSampler = nullptr;
716 napi_status samplerStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGlSampler);
717 if (samplerStatus != napi_ok) {
718 return nullptr;
719 }
720 unsigned int sampler = webGlSampler->GetSampler();
721
722 bool succ = false;
723 int64_t pName;
724 tie(succ, pName) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt64();
725 if (!succ) {
726 return nullptr;
727 }
728 LOGI("WebGL2 WebGL2RenderingContextBase::samplerParameteri pName = %{public}u", pName);
729 int64_t param;
730 tie(succ, param) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt64();
731 if (!succ) {
732 return nullptr;
733 }
734 LOGI("WebGL2 WebGL2RenderingContextBase::samplerParameteri param = %{public}u", param);
735 glSamplerParameteri(static_cast<GLuint>(sampler), static_cast<GLenum>(pName), static_cast<GLint>(param));
736 LOGI("WebGL2 samplerParameteri end");
737 return nullptr;
738 }
739
SamplerParameterf(napi_env env,napi_callback_info info)740 napi_value WebGL2RenderingContextBase::SamplerParameterf(napi_env env, napi_callback_info info)
741 {
742 NFuncArg funcArg(env, info);
743
744 if (!funcArg.InitArgs(NARG_CNT::THREE)) {
745 return nullptr;
746 }
747
748 if (funcArg[NARG_POS::FIRST] == nullptr) {
749 return nullptr;
750 }
751 LOGI("WebGL2 samplerParameterf start");
752 WebGLSampler *webGlSampler = nullptr;
753 napi_status samplerStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGlSampler);
754 if (samplerStatus != napi_ok) {
755 return nullptr;
756 }
757 unsigned int sampler = webGlSampler->GetSampler();
758
759 bool succ = false;
760 int64_t pName;
761 tie(succ, pName) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt64();
762 if (!succ) {
763 return nullptr;
764 }
765 LOGI("WebGL2 WebGL2RenderingContextBase::samplerParameterf pName = %{public}u", pName);
766 double param;
767 tie(succ, param) = NVal(env, funcArg[NARG_POS::THIRD]).ToDouble();
768 if (!succ) {
769 return nullptr;
770 }
771 glSamplerParameterf(static_cast<GLuint>(sampler), static_cast<GLenum>(pName),
772 static_cast<GLfloat>((float) param));
773 LOGI("WebGL2 samplerParameterf end");
774 return nullptr;
775 }
776
GetSamplerParameter(napi_env env,napi_callback_info info)777 napi_value WebGL2RenderingContextBase::GetSamplerParameter(napi_env env, napi_callback_info info)
778 {
779 NFuncArg funcArg(env, info);
780
781 if (!funcArg.InitArgs(NARG_CNT::TWO)) {
782 return nullptr;
783 }
784
785 if (funcArg[NARG_POS::FIRST] == nullptr) {
786 return nullptr;
787 }
788 LOGI("WebGL2 getSamplerParameter start");
789 WebGLSampler *webGlSampler = nullptr;
790 napi_status samplerStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGlSampler);
791 if (samplerStatus != napi_ok) {
792 return nullptr;
793 }
794 unsigned int sampler = webGlSampler->GetSampler();
795
796 bool succ = false;
797 int64_t pName;
798 tie(succ, pName) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt64();
799 if (!succ) {
800 return nullptr;
801 }
802 LOGI("WebGL2 WebGL2RenderingContextBase::getSamplerParameter pName = %{public}u", pName);
803 if (pName == GL_TEXTURE_MAX_LOD || pName == GL_TEXTURE_MIN_LOD) {
804 GLfloat params;
805 glGetSamplerParameterfv(static_cast<GLuint>(sampler), static_cast<GLenum>(pName), ¶ms);
806 float res = static_cast<float>(params);
807 LOGI("WebGL2 getSamplerParameter end");
808 return NVal::CreateDouble(env, (double) res).val_;
809 } else {
810 GLint params;
811 glGetSamplerParameteriv(static_cast<GLuint>(sampler), static_cast<GLenum>(pName), ¶ms);
812 int64_t res = static_cast<int64_t>(params);
813 LOGI("WebGL2 getSamplerParameter end");
814 return NVal::CreateInt64(env, res).val_;
815 }
816 }
817
FenceSync(napi_env env,napi_callback_info info)818 napi_value WebGL2RenderingContextBase::FenceSync(napi_env env, napi_callback_info info)
819 {
820 NFuncArg funcArg(env, info);
821
822 if (!funcArg.InitArgs(NARG_CNT::TWO)) {
823 return nullptr;
824 }
825 bool succ = false;
826 LOGI("WebGL2 fenceSync start");
827 int64_t condition;
828 tie(succ, condition) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt64();
829 if (!succ) {
830 return nullptr;
831 }
832 LOGI("WebGL2 WebGL2RenderingContextBase::fenceSync condition = %{public}u", condition);
833
834 int64_t flags;
835 tie(succ, flags) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt64();
836 if (!succ) {
837 return nullptr;
838 }
839 LOGI("WebGL2 WebGL2RenderingContextBase::fenceSync flags = %{public}u", flags);
840
841 napi_value objSync = NClass::InstantiateClass(env, WebGLSync::className, {});
842 if (!objSync) {
843 return nullptr;
844 }
845 auto webGlSync = NClass::GetEntityOf<WebGLSync>(env, objSync);
846 if (!webGlSync) {
847 return nullptr;
848 }
849 GLsync returnValue = glFenceSync(static_cast<GLenum>(condition), static_cast<GLbitfield>(flags));
850 long value = reinterpret_cast<long>(returnValue);
851 webGlSync->SetSync(value);
852 LOGI("WebGL2 fenceSync end");
853 return objSync;
854 }
855
IsSync(napi_env env,napi_callback_info info)856 napi_value WebGL2RenderingContextBase::IsSync(napi_env env, napi_callback_info info)
857 {
858 NFuncArg funcArg(env, info);
859
860 if (!funcArg.InitArgs(NARG_CNT::ONE)) {
861 return NVal::CreateBool(env, false).val_;
862 }
863 LOGI("WebGL2 isSync start");
864 if (funcArg[NARG_POS::FIRST] == nullptr) {
865 return NVal::CreateBool(env, false).val_;
866 }
867
868 WebGLSync *webGlSync = nullptr;
869 napi_status syncStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGlSync);
870 if (syncStatus != napi_ok) {
871 return NVal::CreateBool(env, false).val_;
872 }
873 long sync = webGlSync->GetSync();
874
875 GLboolean returnValue = glIsSync(reinterpret_cast<GLsync>(sync));
876 bool res = static_cast<bool>(returnValue);
877 LOGI("WebGL2 isSync end");
878 return NVal::CreateBool(env, res).val_;
879 }
880
DeleteSync(napi_env env,napi_callback_info info)881 napi_value WebGL2RenderingContextBase::DeleteSync(napi_env env, napi_callback_info info)
882 {
883 NFuncArg funcArg(env, info);
884
885 if (!funcArg.InitArgs(NARG_CNT::ONE)) {
886 return nullptr;
887 }
888 LOGI("WebGL2 deleteSync start");
889 if (funcArg[NARG_POS::FIRST] == nullptr) {
890 return nullptr;
891 }
892
893 WebGLSync *webGlSync = nullptr;
894 napi_status syncStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGlSync);
895 if (syncStatus != napi_ok) {
896 return nullptr;
897 }
898 long sync = webGlSync->GetSync();
899
900 glDeleteSync(reinterpret_cast<GLsync>(sync));
901 LOGI("WebGL2 deleteSync end");
902 return nullptr;
903 }
904
ClientWaitSync(napi_env env,napi_callback_info info)905 napi_value WebGL2RenderingContextBase::ClientWaitSync(napi_env env, napi_callback_info info)
906 {
907 NFuncArg funcArg(env, info);
908 int res = 0;
909 if (!funcArg.InitArgs(NARG_CNT::THREE)) {
910 return NVal::CreateInt64(env, res).val_;
911 }
912
913 if (funcArg[NARG_POS::FIRST] == nullptr) {
914 return NVal::CreateInt64(env, res).val_;
915 }
916 LOGI("WebGL2 clientWaitSync start");
917 WebGLSync *webGlSync = nullptr;
918 napi_status syncStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGlSync);
919 if (syncStatus != napi_ok) {
920 return NVal::CreateInt64(env, res).val_;
921 }
922 long sync = webGlSync->GetSync();
923
924 bool succ = false;
925 int64_t flags;
926 tie(succ, flags) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt64();
927 if (!succ) {
928 return NVal::CreateInt64(env, res).val_;
929 }
930 LOGI("WebGL2 WebGL2RenderingContextBase::clientWaitSync flags = %{public}u", flags);
931 int64_t timeout;
932 tie(succ, timeout) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt64();
933 if (!succ) {
934 return NVal::CreateInt64(env, res).val_;
935 }
936 LOGI("WebGL2 WebGL2RenderingContextBase::clientWaitSync timeout = %{public}u", timeout);
937 GLenum returnValue = glClientWaitSync(reinterpret_cast<GLsync>(sync), static_cast<GLbitfield>(flags),
938 static_cast<GLuint64>(timeout));
939 res = static_cast<int>(returnValue);
940 LOGI("WebGL2 clientWaitSync end");
941 return NVal::CreateInt64(env, res).val_;
942 }
943
WaitSync(napi_env env,napi_callback_info info)944 napi_value WebGL2RenderingContextBase::WaitSync(napi_env env, napi_callback_info info)
945 {
946 NFuncArg funcArg(env, info);
947
948 if (!funcArg.InitArgs(NARG_CNT::THREE)) {
949 return nullptr;
950 }
951
952 if (funcArg[NARG_POS::FIRST] == nullptr) {
953 return nullptr;
954 }
955 LOGI("WebGL2 waitSync start");
956 WebGLSync *webGlSync = nullptr;
957 napi_status syncStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGlSync);
958 if (syncStatus != napi_ok) {
959 return nullptr;
960 }
961 long sync = webGlSync->GetSync();
962
963 bool succ = false;
964 int64_t flags;
965 tie(succ, flags) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt64();
966 if (!succ) {
967 return nullptr;
968 }
969 LOGI("WebGL2 WebGL2RenderingContextBase::waitSync flags = %{public}u", flags);
970 int64_t timeout;
971 tie(succ, timeout) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt64();
972 if (!succ) {
973 return nullptr;
974 }
975 LOGI("WebGL2 WebGL2RenderingContextBase::waitSync timeout = %{public}u", timeout);
976 glWaitSync(reinterpret_cast<GLsync>(sync), static_cast<GLbitfield>(flags),
977 static_cast<GLuint64>(timeout));
978 LOGI("WebGL2 waitSync end");
979 return nullptr;
980 }
981
GetSyncParameter(napi_env env,napi_callback_info info)982 napi_value WebGL2RenderingContextBase::GetSyncParameter(napi_env env, napi_callback_info info)
983 {
984 NFuncArg funcArg(env, info);
985
986 if (!funcArg.InitArgs(NARG_CNT::TWO)) {
987 return nullptr;
988 }
989
990 if (funcArg[NARG_POS::FIRST] == nullptr) {
991 return nullptr;
992 }
993 LOGI("WebGL2 getSyncParameter start");
994 WebGLSync *webGlSync = nullptr;
995 napi_status syncStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGlSync);
996 if (syncStatus != napi_ok) {
997 return nullptr;
998 }
999 long sync = webGlSync->GetSync();
1000
1001 bool succ = false;
1002 int64_t pname;
1003 tie(succ, pname) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt64();
1004 if (!succ) {
1005 return nullptr;
1006 }
1007 LOGI("WebGL2 WebGL2RenderingContextBase::getSyncParameter pname = %{public}u", pname);
1008 GLint status;
1009 glGetSynciv(reinterpret_cast<GLsync>(sync), static_cast<GLenum>(pname),
1010 sizeof(GLint), nullptr, &status);
1011 int res = static_cast<int>(status);
1012 LOGI("WebGL2 getSyncParameter end");
1013 return NVal::CreateInt64(env, res).val_;
1014 }
1015
CreateTransformFeedback(napi_env env,napi_callback_info info)1016 napi_value WebGL2RenderingContextBase::CreateTransformFeedback(napi_env env, napi_callback_info info)
1017 {
1018 LOGI("WebGL2 createTransformFeedback start");
1019 napi_value objTransformFeedback = NClass::InstantiateClass(env, WebGLTransformFeedback::className, {});
1020 if (!objTransformFeedback) {
1021 return nullptr;
1022 }
1023 auto webGlTransformFeedback = NClass::GetEntityOf<WebGLTransformFeedback>(env, objTransformFeedback);
1024 if (!webGlTransformFeedback) {
1025 return nullptr;
1026 }
1027 unsigned int transformFeedbackId;
1028 glGenTransformFeedbacks(1, &transformFeedbackId);
1029 webGlTransformFeedback->SetTransformFeedback(transformFeedbackId);
1030 LOGI("WebGL2 createTransformFeedback end");
1031 return objTransformFeedback;
1032 }
1033
DeleteTransformFeedback(napi_env env,napi_callback_info info)1034 napi_value WebGL2RenderingContextBase::DeleteTransformFeedback(napi_env env, napi_callback_info info)
1035 {
1036 NFuncArg funcArg(env, info);
1037
1038 if (!funcArg.InitArgs(NARG_CNT::ONE)) {
1039 return nullptr;
1040 }
1041 LOGI("WebGL2 deleteTransformFeedback start");
1042 if (funcArg[NARG_POS::FIRST] == nullptr) {
1043 return nullptr;
1044 }
1045
1046 WebGLTransformFeedback *webGlTransformFeedback = nullptr;
1047 napi_status transformFeedbackStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST],
1048 (void **)&webGlTransformFeedback);
1049 if (transformFeedbackStatus != napi_ok) {
1050 return nullptr;
1051 }
1052 unsigned int transformFeedback = static_cast<unsigned int>(webGlTransformFeedback->GetTransformFeedback());
1053
1054 glDeleteTransformFeedbacks(1, &transformFeedback);
1055 LOGI("WebGL2 deleteTransformFeedback end");
1056 return nullptr;
1057 }
1058
IsTransformFeedback(napi_env env,napi_callback_info info)1059 napi_value WebGL2RenderingContextBase::IsTransformFeedback(napi_env env, napi_callback_info info)
1060 {
1061 NFuncArg funcArg(env, info);
1062
1063 if (!funcArg.InitArgs(NARG_CNT::ONE)) {
1064 return NVal::CreateBool(env, false).val_;
1065 }
1066 LOGI("WebGL2 isTransformFeedback start");
1067 if (funcArg[NARG_POS::FIRST] == nullptr) {
1068 return NVal::CreateBool(env, false).val_;
1069 }
1070
1071 WebGLTransformFeedback *webGlTransformFeedback = nullptr;
1072 napi_status transformFeedbackStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST],
1073 (void **) &webGlTransformFeedback);
1074 if (transformFeedbackStatus != napi_ok) {
1075 return NVal::CreateBool(env, false).val_;
1076 }
1077 unsigned int transformFeedback = static_cast<unsigned int>(webGlTransformFeedback->GetTransformFeedback());
1078
1079 GLboolean returnValue = glIsTransformFeedback(static_cast<GLuint>(transformFeedback));
1080 bool res = static_cast<bool>(returnValue);
1081 LOGI("WebGL2 isTransformFeedback end");
1082 return NVal::CreateBool(env, res).val_;
1083 }
1084
BindTransformFeedback(napi_env env,napi_callback_info info)1085 napi_value WebGL2RenderingContextBase::BindTransformFeedback(napi_env env, napi_callback_info info)
1086 {
1087 NFuncArg funcArg(env, info);
1088
1089 if (!funcArg.InitArgs(NARG_CNT::TWO)) {
1090 return nullptr;
1091 }
1092 bool succ = false;
1093 LOGI("WebGL2 bindTransformFeedback start");
1094 int64_t target;
1095 tie(succ, target) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt64();
1096 if (!succ) {
1097 return nullptr;
1098 }
1099 WebGLTransformFeedback *webGlTransformFeedback = nullptr;
1100 napi_status transformFeedbackStatus = napi_unwrap(env, funcArg[NARG_POS::SECOND],
1101 (void **) &webGlTransformFeedback);
1102 if (transformFeedbackStatus != napi_ok) {
1103 return nullptr;
1104 }
1105 unsigned int transformFeedback = static_cast<unsigned int>(webGlTransformFeedback->GetTransformFeedback());
1106
1107 glBindTransformFeedback(static_cast<GLenum>(target), static_cast<GLuint>(transformFeedback));
1108 LOGI("WebGL2 bindTransformFeedback end");
1109 return nullptr;
1110 }
1111
BeginTransformFeedback(napi_env env,napi_callback_info info)1112 napi_value WebGL2RenderingContextBase::BeginTransformFeedback(napi_env env, napi_callback_info info)
1113 {
1114 NFuncArg funcArg(env, info);
1115
1116 if (!funcArg.InitArgs(NARG_CNT::ONE)) {
1117 return nullptr;
1118 }
1119 bool succ = false;
1120 LOGI("WebGL2 beginTransformFeedback start");
1121 int64_t primitiveMode;
1122 tie(succ, primitiveMode) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt64();
1123 if (!succ) {
1124 return nullptr;
1125 }
1126 LOGI("WebGL2 WebGL2RenderingContextBase::beginTransformFeedback primitiveMode = %{public}u", primitiveMode);
1127 glBeginTransformFeedback(static_cast<GLenum>(primitiveMode));
1128 LOGI("WebGL2 beginTransformFeedback end");
1129 return nullptr;
1130 }
1131
EndTransformFeedback(napi_env env,napi_callback_info info)1132 napi_value WebGL2RenderingContextBase::EndTransformFeedback(napi_env env, napi_callback_info info)
1133 {
1134 LOGI("WebGL2 endTransformFeedback start");
1135 glEndTransformFeedback();
1136 LOGI("WebGL2 cullendTransformFeedbackFace end");
1137 return nullptr;
1138 }
1139
TexStorage3D(napi_env env,napi_callback_info info)1140 napi_value WebGL2RenderingContextBase::TexStorage3D(napi_env env, napi_callback_info info)
1141 {
1142 NFuncArg funcArg(env, info);
1143
1144 if (!funcArg.InitArgs(NARG_CNT::SIX)) {
1145 return nullptr;
1146 }
1147 bool succ = false;
1148 LOGI("WebGL2 texStorage3D start");
1149 int32_t target;
1150 tie(succ, target) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt32();
1151 if (!succ) {
1152 return nullptr;
1153 }
1154 LOGI("WebGL WebGL2RenderingContextBase::texStorage3D target = %{public}u", target);
1155 int32_t levels;
1156 tie(succ, levels) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32();
1157 if (!succ) {
1158 return nullptr;
1159 }
1160 LOGI("WebGL WebGL2RenderingContextBase::texStorage3D levels = %{public}u", levels);
1161 int32_t internalFormat;
1162 tie(succ, internalFormat) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt32();
1163 if (!succ) {
1164 return nullptr;
1165 }
1166 LOGI("WebGL WebGL2RenderingContextBase::texStorage3D internalFormat = %{public}u", internalFormat);
1167 int32_t width;
1168 tie(succ, width) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt32();
1169 if (!succ) {
1170 return nullptr;
1171 }
1172 LOGI("WebGL WebGL2RenderingContextBase::texStorage3D width = %{public}u", width);
1173 int32_t height;
1174 tie(succ, height) = NVal(env, funcArg[NARG_POS::FIFTH]).ToInt32();
1175 if (!succ) {
1176 return nullptr;
1177 }
1178 LOGI("WebGL WebGL2RenderingContextBase::texStorage3D height = %{public}u", height);
1179 int32_t depth;
1180 tie(succ, depth) = NVal(env, funcArg[NARG_POS::SIXTH]).ToInt32();
1181 if (!succ) {
1182 return nullptr;
1183 }
1184 LOGI("WebGL WebGL2RenderingContextBase::texStorage3D depth = %{public}u", depth);
1185 glTexStorage3D(static_cast<GLenum>(target), static_cast<GLsizei>(levels),
1186 static_cast<GLenum>(internalFormat),
1187 static_cast<GLsizei>(width), static_cast<GLsizei>(height), static_cast<GLsizei>(depth));
1188 LOGI("WebGL2 texStorage3D end");
1189 return nullptr;
1190 }
1191
TexImage3D(napi_env env,napi_callback_info info)1192 napi_value WebGL2RenderingContextBase::TexImage3D(napi_env env, napi_callback_info info)
1193 {
1194 NFuncArg funcArg(env, info);
1195
1196 if (!funcArg.InitArgs(NARG_CNT::TEN, NARG_CNT::ELEVEN)) {
1197 return nullptr;
1198 }
1199
1200 bool succ = false;
1201 int32_t target;
1202 tie(succ, target) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt32();
1203 if (!succ) {
1204 return nullptr;
1205 }
1206 LOGI("WebGL WebGL2RenderingContextBase::texImage3D target = %{public}u", target);
1207 int32_t level;
1208 tie(succ, level) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32();
1209 if (!succ) {
1210 return nullptr;
1211 }
1212 LOGI("WebGL WebGL2RenderingContextBase::texImage3D level = %{public}u", level);
1213 int32_t internalFormat;
1214 tie(succ, internalFormat) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt32();
1215 if (!succ) {
1216 return nullptr;
1217 }
1218 LOGI("WebGL WebGL2RenderingContextBase::texImage3D internalFormat = %{public}u", internalFormat);
1219 int32_t width;
1220 tie(succ, width) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt32();
1221 if (!succ) {
1222 return nullptr;
1223 }
1224 LOGI("WebGL WebGL2RenderingContextBase::texImage3D width = %{public}u", width);
1225 int32_t height;
1226 tie(succ, height) = NVal(env, funcArg[NARG_POS::FIFTH]).ToInt32();
1227 if (!succ) {
1228 return nullptr;
1229 }
1230 LOGI("WebGL WebGL2RenderingContextBase::texImage3D height = %{public}u", height);
1231 int32_t depth;
1232 tie(succ, depth) = NVal(env, funcArg[NARG_POS::SIXTH]).ToInt32();
1233 if (!succ) {
1234 return nullptr;
1235 }
1236 LOGI("WebGL WebGL2RenderingContextBase::texImage3D depth = %{public}u", depth);
1237 int32_t border;
1238 tie(succ, border) = NVal(env, funcArg[NARG_POS::SEVENTH]).ToInt32();
1239 if (!succ) {
1240 return nullptr;
1241 }
1242 LOGI("WebGL WebGL2RenderingContextBase::texImage3D border = %{public}u", border);
1243 int32_t format;
1244 tie(succ, format) = NVal(env, funcArg[NARG_POS::EIGHTH]).ToInt32();
1245 if (!succ) {
1246 return nullptr;
1247 }
1248 LOGI("WebGL WebGL2RenderingContextBase::texImage3D format = %{public}u", format);
1249 int32_t type;
1250 tie(succ, type) = NVal(env, funcArg[NARG_POS::NINTH]).ToInt32();
1251 if (!succ) {
1252 return nullptr;
1253 }
1254 LOGI("WebGL WebGL2RenderingContextBase::texImage3D type = %{public}u", type);
1255 int32_t pboOffset;
1256 void *pixels = nullptr;
1257 bool usagesucc = NVal(env, funcArg[NARG_POS::TENTH]).TypeIs(napi_number);
1258 if (funcArg.InitArgs(NARG_CNT::TEN)) {
1259 LOGI("WebGL WebGL2RenderingContextBase::texImage3D into TEN");
1260 size_t size;
1261 char *pixelsBase = nullptr;
1262 if (usagesucc) {
1263 tie(succ, pboOffset) = NVal(env, funcArg[NARG_POS::TENTH]).ToInt32();
1264 if (!succ) {
1265 return nullptr;
1266 }
1267 LOGI("WebGL WebGL2RenderingContextBase::texImage3D pboOffset = %{public}u", pboOffset);
1268 pixels = reinterpret_cast<GLvoid *>((pixelsBase + pboOffset));
1269 LOGI("WebGL WebGLRenderContext::texImage3D1 pixels = %{public}u", pixels);
1270 } else if (funcArg[NARG_POS::TENTH] != nullptr) {
1271 LOGI("WebGL WebGLRenderContext::texImage3D1 into 11 ArrayBufferView");
1272 void *source = nullptr;
1273 tie(succ, source, size) = NVal(env, funcArg[NARG_POS::TENTH]).ToArraybuffer();
1274 if (!succ) {
1275 napi_value teximagesource = funcArg[NARG_POS::TENTH];
1276 napi_value resultobject = nullptr;
1277 napi_status statusobject = napi_coerce_to_object(env, teximagesource, &resultobject);
1278 if (statusobject != napi_ok) {
1279 return nullptr;
1280 }
1281 LOGI("WebGL WebGLRenderContext::texImage3D resultobject = %{public}u", resultobject);
1282 napi_value resultwidth = nullptr;
1283 napi_status widthstatus = napi_get_named_property(env, resultobject, "width", &resultwidth);
1284 if (widthstatus != napi_ok) {
1285 return nullptr;
1286 }
1287 int64_t dataWidth;
1288 tie(succ, dataWidth) = NVal(env, resultwidth).ToInt64();
1289 if (!succ) {
1290 return nullptr;
1291 }
1292 LOGI("WebGL WebGLRenderContext::texImage3D dataWidth= %{public}u", dataWidth);
1293 napi_value resultheight = nullptr;
1294 napi_status heightstatus = napi_get_named_property(env, resultobject, "height", &resultheight);
1295 if (heightstatus != napi_ok) {
1296 return nullptr;
1297 }
1298 int64_t dataHeight;
1299 tie(succ, dataHeight) = NVal(env, resultheight).ToInt64();
1300 if (!succ) {
1301 return nullptr;
1302 }
1303 LOGI("WebGL WebGLRenderContext::texImage3D dataHeight = %{public}u", dataHeight);
1304 napi_value resultdata = nullptr;
1305 napi_status datares = napi_get_named_property(env, resultobject, "data", &resultdata);
1306 if (datares != napi_ok) {
1307 return nullptr;
1308 }
1309 napi_value resultstr;
1310 napi_status rsuStatus = napi_coerce_to_string(env, resultdata, &resultstr);
1311 LOGI("WebGL WebGLRenderContext::texImage3D rsuStatus = %{public}u", rsuStatus);
1312 if (rsuStatus != napi_ok) {
1313 return nullptr;
1314 }
1315 unique_ptr<char[]> name;
1316 tie(succ, name, ignore) = NVal(env, resultstr).ToUTF8String();
1317 if (!succ) {
1318 return nullptr;
1319 }
1320 glTexImage3D(static_cast<GLenum>(target), static_cast<GLint>(level), static_cast<GLint>(internalFormat),
1321 static_cast<GLsizei>((width != 0) ? width : dataWidth),
1322 static_cast<GLsizei>((height != 0) ? height : dataHeight),
1323 static_cast<GLsizei>(depth), static_cast<GLint>(border), static_cast<GLenum>(format),
1324 static_cast<GLenum>(type), reinterpret_cast<GLvoid *>(name.get()));
1325 LOGI("WebGL texImage3D end");
1326 return nullptr;
1327 }
1328 char *sourceBase = static_cast<char *>(source);
1329 pixels = reinterpret_cast<GLvoid *>((sourceBase + 0));
1330 LOGI("WebGL WebGLRenderContext::texImage3D source = %{public}u", source);
1331 LOGI("WebGL WebGLRenderContext::texImage3D pixels = %{public}u", pixels);
1332 }
1333 } else if (funcArg.InitArgs(NARG_CNT::ELEVEN)) { // 参数是十一个情况
1334 int32_t srcOffset;
1335 size_t size;
1336 tie(succ, srcOffset) = NVal(env, funcArg[NARG_POS::ELEVENTH]).ToInt32();
1337 if (!succ) {
1338 return nullptr;
1339 }
1340 LOGI("WebGL WebGL2RenderingContextBase::texImage3D srcOffset = %{public}u", srcOffset);
1341 void *srcData = nullptr;
1342 tie(succ, srcData, size) = NVal(env, funcArg[NARG_POS::TENTH]).ToArraybuffer();
1343 char *srcDataBase = static_cast<char *>(srcData);
1344 pixels = reinterpret_cast<GLvoid *>((srcDataBase + srcOffset));
1345 LOGI("WebGL WebGL2RenderingContextBase::texImage3D srcData = %{public}u", srcData);
1346 LOGI("WebGL WebGL2RenderingContextBase::texImage3D pixels = %{public}u", pixels);
1347 } else {
1348 return nullptr;
1349 }
1350 glTexImage3D(static_cast<GLenum>(target), static_cast<GLint>(level), static_cast<GLint>(internalFormat),
1351 static_cast<GLsizei>(width), static_cast<GLsizei>(height),
1352 static_cast<GLsizei>(depth), static_cast<GLint>(border), static_cast<GLenum>(format),
1353 static_cast<GLenum>(type), reinterpret_cast<GLvoid *>(pixels));
1354 LOGI("WebGL texImage3D end");
1355 return nullptr;
1356 }
1357
TexSubImage3D(napi_env env,napi_callback_info info)1358 napi_value WebGL2RenderingContextBase::TexSubImage3D(napi_env env, napi_callback_info info)
1359 {
1360 NFuncArg funcArg(env, info);
1361
1362 if (!funcArg.InitArgs(NARG_CNT::ELEVEN, NARG_CNT::TWELVE)) {
1363 return nullptr;
1364 }
1365 bool succ = false;
1366 LOGI("WebGL2 texSubImage3D start");
1367 int32_t target;
1368 tie(succ, target) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt32();
1369 if (!succ) {
1370 return nullptr;
1371 }
1372 LOGI("WebGL WebGL2RenderingContextBase::texSubImage3D target = %{public}u", target);
1373 int32_t level;
1374 tie(succ, level) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32();
1375 if (!succ) {
1376 return nullptr;
1377 }
1378 LOGI("WebGL WebGL2RenderingContextBase::texSubImage3D level = %{public}u", level);
1379 int32_t xOffset;
1380 tie(succ, xOffset) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt32();
1381 if (!succ) {
1382 return nullptr;
1383 }
1384 LOGI("WebGL WebGL2RenderingContextBase::texSubImage3D xOffset = %{public}u", xOffset);
1385 int32_t yOffset;
1386 tie(succ, yOffset) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt32();
1387 if (!succ) {
1388 return nullptr;
1389 }
1390 LOGI("WebGL WebGL2RenderingContextBase::texSubImage3D yOffset = %{public}u", yOffset);
1391 int32_t zOffset;
1392 tie(succ, zOffset) = NVal(env, funcArg[NARG_POS::FIFTH]).ToInt32();
1393 if (!succ) {
1394 return nullptr;
1395 }
1396 LOGI("WebGL WebGL2RenderingContextBase::texSubImage3D zOffset = %{public}u", zOffset);
1397 int32_t width;
1398 tie(succ, width) = NVal(env, funcArg[NARG_POS::SIXTH]).ToInt32();
1399 if (!succ) {
1400 return nullptr;
1401 }
1402 LOGI("WebGL WebGL2RenderingContextBase::texSubImage3D width = %{public}u", width);
1403 int32_t height;
1404 tie(succ, height) = NVal(env, funcArg[NARG_POS::SEVENTH]).ToInt32();
1405 if (!succ) {
1406 return nullptr;
1407 }
1408 LOGI("WebGL WebGL2RenderingContextBase::texSubImage3D height = %{public}u", height);
1409 int32_t depth;
1410 tie(succ, depth) = NVal(env, funcArg[NARG_POS::EIGHTH]).ToInt32();
1411 if (!succ) {
1412 return nullptr;
1413 }
1414 LOGI("WebGL WebGL2RenderingContextBase::texSubImage3D depth = %{public}u", depth);
1415 int32_t format;
1416 tie(succ, format) = NVal(env, funcArg[NARG_POS::NINTH]).ToInt32();
1417 if (!succ) {
1418 return nullptr;
1419 }
1420 LOGI("WebGL WebGL2RenderingContextBase::texSubImage3D format = %{public}u", format);
1421 int32_t type;
1422 tie(succ, type) = NVal(env, funcArg[NARG_POS::TENTH]).ToInt32();
1423 if (!succ) {
1424 return nullptr;
1425 }
1426 LOGI("WebGL WebGL2RenderingContextBase::texSubImage3D type = %{public}u", type);
1427 void *offset = nullptr;
1428 bool offsetsucc = NVal(env, funcArg[NARG_POS::TENTH]).TypeIs(napi_number);
1429 if (funcArg.InitArgs(NARG_CNT::ELEVEN)) { // 十一个参数
1430 if (offsetsucc) {
1431 LOGI("WebGL WebGL2RenderingContextBase::texSubImage3D into eleven on GLint");
1432 char *offsetBase = nullptr;
1433 int32_t pboOffset;
1434 tie(succ, pboOffset) = NVal(env, funcArg[NARG_POS::ELEVENTH]).ToInt32();
1435 if (!succ) {
1436 napi_value teximagesource = funcArg[NARG_POS::ELEVENTH];
1437 napi_value resultobject = nullptr;
1438 napi_status statusobject = napi_coerce_to_object(env, teximagesource, &resultobject);
1439 if (statusobject != napi_ok) {
1440 return nullptr;
1441 }
1442 LOGI("WebGL WebGLRenderContext::texSubImage3D resultobject = %{public}u", resultobject);
1443 napi_value resultwidth = nullptr;
1444 napi_status widthstatus = napi_get_named_property(env, resultobject, "width", &resultwidth);
1445 if (widthstatus != napi_ok) {
1446 return nullptr;
1447 }
1448 int64_t dataWidth;
1449 tie(succ, dataWidth) = NVal(env, resultwidth).ToInt64();
1450 if (!succ) {
1451 return nullptr;
1452 }
1453 LOGI("WebGL WebGLRenderContext::texSubImage3D dataWidth = %{public}u", dataWidth);
1454 napi_value resultheight = nullptr;
1455 napi_status heightstatus = napi_get_named_property(env, resultobject, "height", &resultheight);
1456 if (heightstatus != napi_ok) {
1457 return nullptr;
1458 }
1459 int64_t dataHeight;
1460 tie(succ, dataHeight) = NVal(env, resultheight).ToInt64();
1461 if (!succ) {
1462 return nullptr;
1463 }
1464 LOGI("WebGL WebGLRenderContext::texSubImage3D dataHeight = %{public}u", dataHeight);
1465 napi_value resultdata = nullptr;
1466 napi_status datares = napi_get_named_property(env, resultobject, "data", &resultdata);
1467 if (datares != napi_ok) {
1468 return nullptr;
1469 }
1470 napi_value resultstr;
1471 napi_status rsuStatus = napi_coerce_to_string(env, resultdata, &resultstr);
1472 LOGI("WebGL WebGLRenderContext::texSubImage3D rsuStatus = %{public}u", rsuStatus);
1473 if (rsuStatus != napi_ok) {
1474 return nullptr;
1475 }
1476 unique_ptr<char[]> name;
1477 tie(succ, name, ignore) = NVal(env, resultstr).ToUTF8String();
1478 if (!succ) {
1479 return nullptr;
1480 }
1481 glTexSubImage3D(static_cast<GLenum>(target), static_cast<GLint>(level), static_cast<GLint>(xOffset),
1482 static_cast<GLint>(yOffset), static_cast<GLint>(zOffset),
1483 static_cast<GLsizei>((width != 0) ? width : dataWidth),
1484 static_cast<GLsizei>((height != 0) ? height : dataHeight), static_cast<GLsizei>(depth),
1485 static_cast<GLenum>(format),
1486 static_cast<GLenum>(type), reinterpret_cast<GLvoid *>(name.get()));
1487 LOGI("WebGL texSubImage3D end");
1488 return nullptr;
1489 }
1490 LOGI("WebGL WebGLRenderContext::texSubImage3D pboOffset = %{public}u", pboOffset);
1491 offset = reinterpret_cast<GLvoid *>((offsetBase + pboOffset));
1492 LOGI("WebGL WebGLRenderContext::texSubImage3D offset = %{public}u", offset);
1493 } else {
1494 return nullptr; // TexImageSource
1495 }
1496 } else if (funcArg.InitArgs(NARG_CNT::TWELVE)) { // 十二个参数
1497 int32_t srcOffset;
1498 tie(succ, srcOffset) = NVal(env, funcArg[NARG_POS::TWELVETH]).ToInt32();
1499 if (!succ) {
1500 return nullptr;
1501 }
1502 LOGI("WebGL WebGL2RenderingContextBase::texSubImage3D srcOffset = %{public}u", srcOffset);
1503 void *srcData = nullptr;
1504 size_t size;
1505 tie(succ, srcData, size) = NVal(env, funcArg[NARG_POS::ELEVENTH]).ToArraybuffer();
1506 char *srcDataBase = static_cast<char *>(srcData);
1507 offset = reinterpret_cast<GLvoid *>((srcDataBase + srcOffset));
1508 } else {
1509 return nullptr;
1510 }
1511 glTexSubImage3D(static_cast<GLenum>(target), static_cast<GLint>(level), static_cast<GLint>(xOffset),
1512 static_cast<GLint>(yOffset), static_cast<GLint>(zOffset), static_cast<GLsizei>(width),
1513 static_cast<GLsizei>(height), static_cast<GLsizei>(depth), static_cast<GLenum>(format),
1514 static_cast<GLenum>(type), reinterpret_cast<GLvoid *>(offset));
1515 LOGI("WebGL texSubImage3D end");
1516 return nullptr;
1517 }
1518
CopyTexSubImage3D(napi_env env,napi_callback_info info)1519 napi_value WebGL2RenderingContextBase::CopyTexSubImage3D(napi_env env, napi_callback_info info)
1520 {
1521 NFuncArg funcArg(env, info);
1522
1523 if (!funcArg.InitArgs(NARG_CNT::NINE)) {
1524 return nullptr;
1525 }
1526 bool succ = false;
1527 LOGI("WebGL2 copyTexSubImage3D start");
1528 int32_t target;
1529 tie(succ, target) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt32();
1530 if (!succ) {
1531 return nullptr;
1532 }
1533 LOGI("WebGL WebGL2RenderingContextBase::copyTexSubImage3D target = %{public}u", target);
1534 int32_t level;
1535 tie(succ, level) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32();
1536 if (!succ) {
1537 return nullptr;
1538 }
1539 LOGI("WebGL WebGL2RenderingContextBase::copyTexSubImage3D level = %{public}u", level);
1540 int32_t xOffset;
1541 tie(succ, xOffset) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt32();
1542 if (!succ) {
1543 return nullptr;
1544 }
1545 LOGI("WebGL WebGL2RenderingContextBase::copyTexSubImage3D xOffset = %{public}u", xOffset);
1546 int32_t yOffset;
1547 tie(succ, yOffset) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt32();
1548 if (!succ) {
1549 return nullptr;
1550 }
1551 LOGI("WebGL WebGL2RenderingContextBase::copyTexSubImage3D yOffset = %{public}u", yOffset);
1552 int32_t zOffset;
1553 tie(succ, zOffset) = NVal(env, funcArg[NARG_POS::FIFTH]).ToInt32();
1554 if (!succ) {
1555 return nullptr;
1556 }
1557 LOGI("WebGL WebGL2RenderingContextBase::copyTexSubImage3D zOffset = %{public}u", zOffset);
1558 int32_t x;
1559 tie(succ, x) = NVal(env, funcArg[NARG_POS::SIXTH]).ToInt32();
1560 if (!succ) {
1561 return nullptr;
1562 }
1563 LOGI("WebGL WebGL2RenderingContextBase::copyTexSubImage3D x = %{public}u", x);
1564 int32_t y;
1565 tie(succ, y) = NVal(env, funcArg[NARG_POS::SEVENTH]).ToInt32();
1566 if (!succ) {
1567 return nullptr;
1568 }
1569 LOGI("WebGL WebGL2RenderingContextBase::copyTexSubImage3D y = %{public}u", y);
1570 int32_t width;
1571 tie(succ, width) = NVal(env, funcArg[NARG_POS::EIGHTH]).ToInt32();
1572 if (!succ) {
1573 return nullptr;
1574 }
1575 LOGI("WebGL WebGL2RenderingContextBase::copyTexSubImage3D width = %{public}u", width);
1576 int32_t height;
1577 tie(succ, height) = NVal(env, funcArg[NARG_POS::NINTH]).ToInt32();
1578 if (!succ) {
1579 return nullptr;
1580 }
1581 LOGI("WebGL WebGL2RenderingContextBase::copyTexSubImage3D height = %{public}u", height);
1582 glCopyTexSubImage3D(static_cast<GLenum>(target), static_cast<GLint>(level), static_cast<GLint>(xOffset),
1583 static_cast<GLint>(yOffset), static_cast<GLint>(zOffset), static_cast<GLint>(x),
1584 static_cast<GLint>(y), static_cast<GLsizei>(width), static_cast<GLsizei>(height));
1585 LOGI("WebGL copyTexSubImage3D end");
1586 return nullptr;
1587 }
1588
CompressedTexImage3D(napi_env env,napi_callback_info info)1589 napi_value WebGL2RenderingContextBase::CompressedTexImage3D(napi_env env, napi_callback_info info)
1590 {
1591 NFuncArg funcArg(env, info);
1592
1593 if (!funcArg.InitArgs(NARG_CNT::NINE, NARG_CNT::TEN)) {
1594 return nullptr;
1595 }
1596
1597 bool succ = false;
1598 LOGI("WebGL compressedTexImage3D start");
1599 int32_t target;
1600 tie(succ, target) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt32();
1601 if (!succ) {
1602 return nullptr;
1603 }
1604 LOGI("WebGL WebGL2RenderingContextBase::compressedTexImage3D target = %{public}u", target);
1605 int32_t level;
1606 tie(succ, level) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32();
1607 if (!succ) {
1608 return nullptr;
1609 }
1610 LOGI("WebGL WebGL2RenderingContextBase::compressedTexImage3D level = %{public}u", level);
1611 int32_t internalFormat;
1612 tie(succ, internalFormat) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt32();
1613 if (!succ) {
1614 return nullptr;
1615 }
1616 LOGI("WebGL WebGL2RenderingContextBase::compressedTexImage3D internalFormat = %{public}u", internalFormat);
1617 int32_t width;
1618 tie(succ, width) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt32();
1619 if (!succ) {
1620 return nullptr;
1621 }
1622 LOGI("WebGL WebGL2RenderingContextBase::compressedTexImage3D width = %{public}u", width);
1623 int32_t height;
1624 tie(succ, height) = NVal(env, funcArg[NARG_POS::FIFTH]).ToInt32();
1625 if (!succ) {
1626 return nullptr;
1627 }
1628 LOGI("WebGL WebGL2RenderingContextBase::compressedTexImage3D height = %{public}u", height);
1629 int32_t depth;
1630 tie(succ, depth) = NVal(env, funcArg[NARG_POS::SIXTH]).ToInt32();
1631 if (!succ) {
1632 return nullptr;
1633 }
1634 LOGI("WebGL WebGL2RenderingContextBase::compressedTexImage3D depth = %{public}u", depth);
1635 int32_t border;
1636 tie(succ, border) = NVal(env, funcArg[NARG_POS::SEVENTH]).ToInt32();
1637 if (!succ) {
1638 return nullptr;
1639 }
1640 LOGI("WebGL WebGL2RenderingContextBase::compressedTexImage3D border = %{public}u", border);
1641 bool imagesucc = NVal(env, funcArg[NARG_POS::EIGHTH]).TypeIs(napi_number);
1642 void *offset = nullptr;
1643 int32_t imageSize;
1644 if (imagesucc) {
1645 LOGI("WebGL WebGL2RenderingContextBase::compressedTexImage3D into nine");
1646 tie(succ, imageSize) = NVal(env, funcArg[NARG_POS::EIGHTH]).ToInt32();
1647 if (!succ) {
1648 return nullptr;
1649 }
1650 LOGI("WebGL WebGL2RenderingContextBase::compressedTexImage3D imageSize = %{public}u", imageSize);
1651 int32_t srcOffset;
1652 tie(succ, srcOffset) = NVal(env, funcArg[NARG_POS::NINTH]).ToInt32();
1653 if (!succ) {
1654 return nullptr;
1655 }
1656 LOGI("WebGL WebGL2RenderingContextBase::compressedTexImage3D srcOffset = %{public}u", srcOffset);
1657 void *srcData = nullptr;
1658 char *srcDataBase = static_cast<char *>(srcData);
1659 offset = reinterpret_cast<GLvoid *>((srcDataBase + srcOffset));
1660 LOGI("WebGL WebGL2RenderingContextBase::compressedTexImage3D offset = %{public}u", offset);
1661 } else {
1662 int32_t srcOffset = 0;
1663 int32_t srcLengthOverride = 0;
1664 void *srcData = nullptr;
1665 tie(succ, srcOffset) = NVal(env, funcArg[NARG_POS::NINTH]).ToInt32();
1666 if (!succ) {
1667 return nullptr;
1668 }
1669 LOGI("WebGL WebGL2RenderingContextBase::compressedTexImage3D srcOffset = %{public}u", srcOffset);
1670 tie(succ, srcLengthOverride) = NVal(env, funcArg[NARG_POS::TENTH]).ToInt32();
1671 if (!succ) {
1672 return nullptr;
1673 }
1674 LOGI("WebGL WebGL2RenderingContextBase::compressedTexImage3D srcLengthOverride = %{public}u",
1675 srcLengthOverride);
1676 tie(succ, srcData, srcLengthOverride) = NVal(env, funcArg[NARG_POS::EIGHTH]).ToArraybuffer();
1677 char *srcDataBase = static_cast<char *>(srcData);
1678 offset = reinterpret_cast<GLvoid *>((srcDataBase + srcOffset));
1679 imageSize = static_cast<int>(srcLengthOverride);
1680 LOGI("WebGL WebGL2RenderingContextBase::compressedTexImage3D offset = %{public}u", offset);
1681 LOGI("WebGL WebGL2RenderingContextBase::compressedTexImage3D imageSize = %{public}u", imageSize);
1682 }
1683
1684 glCompressedTexImage3D(static_cast<GLenum>(target), static_cast<GLint>(level),
1685 static_cast<GLenum>(internalFormat),
1686 static_cast<GLsizei>(width), static_cast<GLsizei>(height),
1687 static_cast<GLsizei>(depth),
1688 static_cast<GLint>(border), static_cast<GLsizei>(imageSize),
1689 reinterpret_cast<GLvoid *>(offset));
1690 LOGI("WebGL compressedTexImage3D end");
1691 return nullptr;
1692 }
1693
CompressedTexSubImage3D(napi_env env,napi_callback_info info)1694 napi_value WebGL2RenderingContextBase::CompressedTexSubImage3D(napi_env env, napi_callback_info info)
1695 {
1696 NFuncArg funcArg(env, info);
1697
1698 if (!funcArg.InitArgs(NARG_CNT::ELEVEN, NARG_CNT::TWELVE)) {
1699 return nullptr;
1700 }
1701 bool succ = false;
1702 LOGI("WebGL compressedTexSubImage3D start");
1703 int32_t target;
1704 tie(succ, target) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt32();
1705 if (!succ) {
1706 return nullptr;
1707 }
1708 LOGI("WebGL WebGL2RenderingContextBase::compressedTexSubImage3D target = %{public}u", target);
1709 int32_t level;
1710 tie(succ, level) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32();
1711 if (!succ) {
1712 return nullptr;
1713 }
1714 LOGI("WebGL WebGL2RenderingContextBase::compressedTexSubImage3D level = %{public}u", level);
1715 int32_t xOffset;
1716 tie(succ, xOffset) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt32();
1717 if (!succ) {
1718 return nullptr;
1719 }
1720 LOGI("WebGL WebGL2RenderingContextBase::compressedTexSubImage3D xOffset = %{public}u", xOffset);
1721 int32_t yOffset;
1722 tie(succ, yOffset) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt32();
1723 if (!succ) {
1724 return nullptr;
1725 }
1726 LOGI("WebGL WebGL2RenderingContextBase::compressedTexSubImage3D yOffset = %{public}u", yOffset);
1727 int32_t zOffset;
1728 tie(succ, zOffset) = NVal(env, funcArg[NARG_POS::FIFTH]).ToInt32();
1729 if (!succ) {
1730 return nullptr;
1731 }
1732 LOGI("WebGL WebGL2RenderingContextBase::compressedTexSubImage3D zOffset = %{public}u", zOffset);
1733 int32_t width;
1734 tie(succ, width) = NVal(env, funcArg[NARG_POS::SIXTH]).ToInt32();
1735 if (!succ) {
1736 return nullptr;
1737 }
1738 LOGI("WebGL WebGL2RenderingContextBase::compressedTexSubImage3D width = %{public}u", width);
1739 int32_t height;
1740 tie(succ, height) = NVal(env, funcArg[NARG_POS::SEVENTH]).ToInt32();
1741 if (!succ) {
1742 return nullptr;
1743 }
1744 LOGI("WebGL WebGL2RenderingContextBase::compressedTexSubImage3D height = %{public}u", height);
1745 int32_t depth;
1746 tie(succ, depth) = NVal(env, funcArg[NARG_POS::EIGHTH]).ToInt32();
1747 if (!succ) {
1748 return nullptr;
1749 }
1750 LOGI("WebGL WebGL2RenderingContextBase::compressedTexSubImage3D depth = %{public}u", depth);
1751 int32_t format;
1752 tie(succ, format) = NVal(env, funcArg[NARG_POS::NINTH]).ToInt32();
1753 if (!succ) {
1754 return nullptr;
1755 }
1756 LOGI("WebGL WebGL2RenderingContextBase::compressedTexSubImage3D format = %{public}u", format);
1757 bool imagesucc = NVal(env, funcArg[NARG_POS::TENTH]).TypeIs(napi_number);
1758 void *offset = nullptr;
1759 int32_t imageSize;
1760 if (imagesucc) {
1761 // 是十一个参数
1762 tie(succ, imageSize) = NVal(env, funcArg[NARG_POS::TENTH]).ToInt32();
1763 if (!succ) {
1764 return nullptr;
1765 }
1766 LOGI("WebGL WebGL2RenderingContextBase::compressedTexSubImage3D imageSize = %{public}u", imageSize);
1767 int32_t srcOffset;
1768 tie(succ, srcOffset) = NVal(env, funcArg[NARG_POS::ELEVENTH]).ToInt32();
1769 if (!succ) {
1770 return nullptr;
1771 }
1772 LOGI("WebGL WebGL2RenderingContextBase::compressedTexSubImage3D srcOffset = %{public}u", srcOffset);
1773 void *srcData = nullptr;
1774 char *srcDataBase = static_cast<char *>(srcData);
1775 offset = reinterpret_cast<GLvoid *>((srcDataBase + srcOffset));
1776 } else {
1777 int32_t srcOffset = 0;
1778 int32_t srcLengthOverride = 0;
1779 void *srcData = nullptr;
1780 tie(succ, srcOffset) = NVal(env, funcArg[NARG_POS::ELEVENTH]).ToInt32();
1781 if (!succ) {
1782 return nullptr;
1783 }
1784 LOGI("WebGL WebGL2RenderingContextBase::compressedTexSubImage3D srcOffset = %{public}u", srcOffset);
1785 tie(succ, srcLengthOverride) = NVal(env, funcArg[NARG_POS::TWELVETH]).ToInt32();
1786 if (!succ) {
1787 return nullptr;
1788 }
1789 LOGI("WebGL WebGL2RenderingContextBase::compressedTexSubImage3D srcLengthOverride = %{public}u",
1790 srcLengthOverride);
1791 tie(succ, srcData, srcLengthOverride) = NVal(env, funcArg[NARG_POS::TENTH]).ToArraybuffer();
1792 char *srcDataBase = static_cast<char *>(srcData);
1793 offset = reinterpret_cast<GLvoid *>((srcDataBase + srcOffset));
1794 imageSize = static_cast<int>(srcLengthOverride);
1795 LOGI("WebGL WebGL2RenderingContextBase::compressedTexSubImage3D srcDataBase = %{public}u", srcDataBase);
1796 LOGI("WebGL WebGL2RenderingContextBase::compressedTexSubImage3D imageSize = %{public}u", imageSize);
1797 }
1798 glCompressedTexSubImage3D(static_cast<GLenum>(target), static_cast<GLint>(level),
1799 static_cast<GLint>(xOffset),
1800 static_cast<GLint>(yOffset), static_cast<GLint>(zOffset),
1801 static_cast<GLsizei>(width), static_cast<GLsizei>(height),
1802 static_cast<GLsizei>(depth),
1803 static_cast<GLenum>(format), static_cast<GLsizei>(imageSize),
1804 reinterpret_cast<GLvoid *>(offset));
1805 LOGI("WebGL compressedTexSubImage3D end");
1806 return nullptr;
1807 }
1808
GetFragDataLocation(napi_env env,napi_callback_info info)1809 napi_value WebGL2RenderingContextBase::GetFragDataLocation(napi_env env, napi_callback_info info)
1810 {
1811 NFuncArg funcArg(env, info);
1812
1813 if (!funcArg.InitArgs(NARG_CNT::TWO)) {
1814 return nullptr;
1815 }
1816 LOGI("WebGL2 getFragDataLocation start");
1817 WebGLProgram *webGlProgram = nullptr;
1818 napi_status programStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGlProgram);
1819 if (programStatus != napi_ok) {
1820 return nullptr;
1821 }
1822 bool succ = false;
1823 int program = webGlProgram->GetProgramId();
1824 unique_ptr<char[]> name;
1825 tie(succ, name, ignore) = NVal(env, funcArg[NARG_POS::SECOND]).ToUTF8String();
1826 if (!succ) {
1827 return nullptr;
1828 }
1829 LOGI("WebGL WebGLRenderingContextBase::getFragDataLocation name = %{public}s", name.get());
1830 int32_t res = static_cast<int32_t>(glGetFragDataLocation(static_cast<GLuint>(program),
1831 const_cast<char *>(name.get())));
1832 LOGI("WebGL getFragDataLocation end");
1833 return NVal::CreateInt64(env, res).val_;
1834 }
1835
Uniform1ui(napi_env env,napi_callback_info info)1836 napi_value WebGL2RenderingContextBase::Uniform1ui(napi_env env, napi_callback_info info)
1837 {
1838 NFuncArg funcArg(env, info);
1839
1840 if (!funcArg.InitArgs(NARG_CNT::TWO)) {
1841 return nullptr;
1842 }
1843 bool succ = false;
1844 LOGI("WebGL2 uniform1ui start");
1845 WebGLUniformLocation *webGLUniformLocation = nullptr;
1846 napi_status locationStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGLUniformLocation);
1847 if (locationStatus != napi_ok) {
1848 return nullptr;
1849 }
1850 int location = webGLUniformLocation->GetUniformLocationId();
1851 LOGI("WebGL WebGL2RenderingContextBase::uniform1ui location = %{public}u", location);
1852 int32_t v0;
1853 tie(succ, v0) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32();
1854 if (!succ) {
1855 return nullptr;
1856 }
1857 LOGI("WebGL WebGL2RenderingContextBase::uniform1ui v0 = %{public}u", v0);
1858 glUniform1ui(static_cast<GLint>(location), static_cast<GLuint>(v0));
1859 LOGI("WebGL uniform1ui end");
1860 return nullptr;
1861 }
1862
Uniform2ui(napi_env env,napi_callback_info info)1863 napi_value WebGL2RenderingContextBase::Uniform2ui(napi_env env, napi_callback_info info)
1864 {
1865 NFuncArg funcArg(env, info);
1866
1867 if (!funcArg.InitArgs(NARG_CNT::THREE)) {
1868 return nullptr;
1869 }
1870 bool succ = false;
1871 LOGI("WebGL2 uniform2ui start");
1872 WebGLUniformLocation *webGLUniformLocation = nullptr;
1873 napi_status locationStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGLUniformLocation);
1874 if (locationStatus != napi_ok) {
1875 return nullptr;
1876 }
1877 int location = webGLUniformLocation->GetUniformLocationId();
1878 LOGI("WebGL WebGL2RenderingContextBase::uniform2ui location = %{public}u", location);
1879 int32_t v0;
1880 tie(succ, v0) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32();
1881 if (!succ) {
1882 return nullptr;
1883 }
1884 LOGI("WebGL WebGL2RenderingContextBase::uniform2ui v0 = %{public}u", v0);
1885 int32_t v1;
1886 tie(succ, v1) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32();
1887 if (!succ) {
1888 return nullptr;
1889 }
1890 LOGI("WebGL WebGL2RenderingContextBase::uniform2ui v1 = %{public}u", v1);
1891 glUniform2ui(static_cast<GLint>(location), static_cast<GLuint>(v0), static_cast<GLuint>(v1));
1892 LOGI("WebGL uniform2ui end");
1893 return nullptr;
1894 }
1895
Uniform3ui(napi_env env,napi_callback_info info)1896 napi_value WebGL2RenderingContextBase::Uniform3ui(napi_env env, napi_callback_info info)
1897 {
1898 NFuncArg funcArg(env, info);
1899
1900 if (!funcArg.InitArgs(NARG_CNT::FOUR)) {
1901 return nullptr;
1902 }
1903 bool succ = false;
1904 LOGI("WebGL2 uniform3ui start");
1905 WebGLUniformLocation *webGLUniformLocation = nullptr;
1906 napi_status locationStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGLUniformLocation);
1907 if (locationStatus != napi_ok) {
1908 return nullptr;
1909 }
1910 int location = webGLUniformLocation->GetUniformLocationId();
1911 LOGI("WebGL WebGL2RenderingContextBase::uniform3ui location = %{public}u", location);
1912 int32_t v0;
1913 tie(succ, v0) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32();
1914 if (!succ) {
1915 return nullptr;
1916 }
1917 LOGI("WebGL WebGL2RenderingContextBase::uniform3ui v0 = %{public}u", v0);
1918 int32_t v1;
1919 tie(succ, v1) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt32();
1920 if (!succ) {
1921 return nullptr;
1922 }
1923 LOGI("WebGL WebGL2RenderingContextBase::uniform3ui v1 = %{public}u", v1);
1924 int32_t v2;
1925 tie(succ, v2) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt32();
1926 if (!succ) {
1927 return nullptr;
1928 }
1929 LOGI("WebGL WebGL2RenderingContextBase::uniform3ui v2 = %{public}u", v2);
1930 glUniform3ui(static_cast<GLint>(location), static_cast<GLuint>(v0), static_cast<GLuint>(v1),
1931 static_cast<GLuint>(v2));
1932 LOGI("WebGL uniform3ui end");
1933 return nullptr;
1934 }
1935
Uniform4ui(napi_env env,napi_callback_info info)1936 napi_value WebGL2RenderingContextBase::Uniform4ui(napi_env env, napi_callback_info info)
1937 {
1938 NFuncArg funcArg(env, info);
1939
1940 if (!funcArg.InitArgs(NARG_CNT::FIVE)) {
1941 return nullptr;
1942 }
1943 bool succ = false;
1944 LOGI("WebGL2 uniform4ui start");
1945 WebGLUniformLocation *webGLUniformLocation = nullptr;
1946 napi_status locationStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGLUniformLocation);
1947 if (locationStatus != napi_ok) {
1948 return nullptr;
1949 }
1950 int location = webGLUniformLocation->GetUniformLocationId();
1951 LOGI("WebGL WebGL2RenderingContextBase::uniform4ui location = %{public}u", location);
1952 int32_t v0;
1953 tie(succ, v0) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32();
1954 if (!succ) {
1955 return nullptr;
1956 }
1957 LOGI("WebGL WebGL2RenderingContextBase::uniform4ui v0 = %{public}u", v0);
1958 int32_t v1;
1959 tie(succ, v1) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt32();
1960 if (!succ) {
1961 return nullptr;
1962 }
1963 LOGI("WebGL WebGL2RenderingContextBase::uniform4ui v1 = %{public}u", v1);
1964 int32_t v2;
1965 tie(succ, v2) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt32();
1966 if (!succ) {
1967 return nullptr;
1968 }
1969 LOGI("WebGL WebGL2RenderingContextBase::uniform4ui v2 = %{public}u", v2);
1970 int32_t v3;
1971 tie(succ, v3) = NVal(env, funcArg[NARG_POS::FIFTH]).ToInt32();
1972 if (!succ) {
1973 return nullptr;
1974 }
1975 LOGI("WebGL WebGL2RenderingContextBase::uniform4ui v3 = %{public}u", v3);
1976 glUniform4ui(static_cast<GLint>(location), static_cast<GLuint>(v0), static_cast<GLuint>(v1),
1977 static_cast<GLuint>(v2), static_cast<GLuint>(v3));
1978 LOGI("WebGL uniform4ui end");
1979 return nullptr;
1980 }
1981
VertexAttribI4i(napi_env env,napi_callback_info info)1982 napi_value WebGL2RenderingContextBase::VertexAttribI4i(napi_env env, napi_callback_info info)
1983 {
1984 NFuncArg funcArg(env, info);
1985
1986 if (!funcArg.InitArgs(NARG_CNT::FIVE)) {
1987 return nullptr;
1988 }
1989 bool succ = false;
1990 LOGI("WebGL vertexAttribI4i start");
1991 int32_t index;
1992 tie(succ, index) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt32();
1993 if (!succ) {
1994 return nullptr;
1995 }
1996 LOGI("WebGL WebGL2RenderingContextBase::vertexAttribI4i index = %{public}u", index);
1997 int32_t x;
1998 tie(succ, x) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32();
1999 if (!succ) {
2000 return nullptr;
2001 }
2002 LOGI("WebGL WebGL2RenderingContextBase::vertexAttribI4i x = %{public}u", x);
2003 int32_t y;
2004 tie(succ, y) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt32();
2005 if (!succ) {
2006 return nullptr;
2007 }
2008 LOGI("WebGL WebGL2RenderingContextBase::vertexAttribI4i y = %{public}u", y);
2009 int32_t z;
2010 tie(succ, z) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt32();
2011 if (!succ) {
2012 return nullptr;
2013 }
2014 LOGI("WebGL WebGL2RenderingContextBase::vertexAttribI4i z = %{public}u", z);
2015 int32_t w;
2016 tie(succ, w) = NVal(env, funcArg[NARG_POS::FIFTH]).ToInt32();
2017 if (!succ) {
2018 return nullptr;
2019 }
2020 LOGI("WebGL WebGL2RenderingContextBase::vertexAttribI4i w = %{public}u", w);
2021 glVertexAttribI4i(static_cast<GLuint>(index), static_cast<GLint>(x), static_cast<GLint>(y),
2022 static_cast<GLint>(z), static_cast<GLint>(w));
2023 LOGI("WebGL vertexAttribI4i end");
2024 return nullptr;
2025 }
2026
VertexAttribI4ui(napi_env env,napi_callback_info info)2027 napi_value WebGL2RenderingContextBase::VertexAttribI4ui(napi_env env, napi_callback_info info)
2028 {
2029 NFuncArg funcArg(env, info);
2030
2031 if (!funcArg.InitArgs(NARG_CNT::FIVE)) {
2032 return nullptr;
2033 }
2034 bool succ = false;
2035 LOGI("WebGL vertexAttribI4ui start");
2036 int32_t index;
2037 tie(succ, index) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt32();
2038 if (!succ) {
2039 return nullptr;
2040 }
2041 LOGI("WebGL WebGL2RenderingContextBase::vertexAttribI4ui index = %{public}u", index);
2042 int32_t x;
2043 tie(succ, x) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32();
2044 if (!succ) {
2045 return nullptr;
2046 }
2047 LOGI("WebGL WebGL2RenderingContextBase::vertexAttribI4ui x = %{public}u", x);
2048 int32_t y;
2049 tie(succ, y) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt32();
2050 if (!succ) {
2051 return nullptr;
2052 }
2053 LOGI("WebGL WebGL2RenderingContextBase::vertexAttribI4ui y = %{public}u", y);
2054 int32_t z;
2055 tie(succ, z) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt32();
2056 if (!succ) {
2057 return nullptr;
2058 }
2059 LOGI("WebGL WebGL2RenderingContextBase::vertexAttribI4ui z = %{public}u", z);
2060 int32_t w;
2061 tie(succ, w) = NVal(env, funcArg[NARG_POS::FIFTH]).ToInt32();
2062 if (!succ) {
2063 return nullptr;
2064 }
2065 LOGI("WebGL WebGL2RenderingContextBase::vertexAttribI4ui w = %{public}u", w);
2066 glVertexAttribI4ui(static_cast<GLuint>(index), static_cast<GLuint>(x), static_cast<GLuint>(y),
2067 static_cast<GLuint>(z), static_cast<GLuint>(w));
2068 LOGI("WebGL vertexAttribI4ui end");
2069 return nullptr;
2070 }
2071
VertexAttribIPointer(napi_env env,napi_callback_info info)2072 napi_value WebGL2RenderingContextBase::VertexAttribIPointer(napi_env env, napi_callback_info info)
2073 {
2074 NFuncArg funcArg(env, info);
2075
2076 if (!funcArg.InitArgs(NARG_CNT::FIVE)) {
2077 return nullptr;
2078 }
2079 bool succ = false;
2080 LOGI("WebGL vertexAttribIPointer start");
2081 int32_t index;
2082 tie(succ, index) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt32();
2083 if (!succ) {
2084 return nullptr;
2085 }
2086 LOGI("WebGL WebGL2RenderingContextBase::vertexAttribIPointer index = %{public}u", index);
2087 int32_t size;
2088 tie(succ, size) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32();
2089 if (!succ) {
2090 return nullptr;
2091 }
2092 LOGI("WebGL WebGL2RenderingContextBase::vertexAttribIPointer size = %{public}u", size);
2093 int32_t type;
2094 tie(succ, type) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt32();
2095 if (!succ) {
2096 return nullptr;
2097 }
2098 LOGI("WebGL WebGL2RenderingContextBase::vertexAttribIPointer type = %{public}u", type);
2099 int32_t stride;
2100 tie(succ, stride) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt32();
2101 if (!succ) {
2102 return nullptr;
2103 }
2104 LOGI("WebGL WebGL2RenderingContextBase::vertexAttribIPointer stride = %{public}u", stride);
2105 int32_t offset;
2106 tie(succ, offset) = NVal(env, funcArg[NARG_POS::FIFTH]).ToInt32();
2107 if (!succ) {
2108 return nullptr;
2109 }
2110 LOGI("WebGL WebGL2RenderingContextBase::vertexAttribIPointer offset = %{public}u", offset);
2111 glVertexAttribIPointer(static_cast<GLuint>(index), static_cast<GLuint>(size), static_cast<GLenum>(type),
2112 static_cast<GLsizei>(stride), reinterpret_cast<GLvoid *>(static_cast<intptr_t>(offset)));
2113 LOGI("WebGL vertexAttribIPointer end");
2114 return nullptr;
2115 }
2116
VertexAttribDivisor(napi_env env,napi_callback_info info)2117 napi_value WebGL2RenderingContextBase::VertexAttribDivisor(napi_env env, napi_callback_info info)
2118 {
2119 NFuncArg funcArg(env, info);
2120
2121 if (!funcArg.InitArgs(NARG_CNT::TWO)) {
2122 return nullptr;
2123 }
2124 bool succ = false;
2125 LOGI("WebGL2 vertexAttribDivisor start");
2126 int32_t index;
2127 tie(succ, index) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt32();
2128 if (!succ) {
2129 return nullptr;
2130 }
2131 LOGI("WebGL WebGL2RenderingContextBase::vertexAttribDivisor index = %{public}u", index);
2132 int32_t divisor;
2133 tie(succ, divisor) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32();
2134 if (!succ) {
2135 return nullptr;
2136 }
2137 LOGI("WebGL WebGL2RenderingContextBase::vertexAttribDivisor divisor = %{public}u", divisor);
2138 glVertexAttribDivisor(static_cast<GLuint>(index), static_cast<GLuint>(divisor));
2139 LOGI("WebGL vertexAttribDivisor end");
2140 return nullptr;
2141 }
2142
DrawArraysInstanced(napi_env env,napi_callback_info info)2143 napi_value WebGL2RenderingContextBase::DrawArraysInstanced(napi_env env, napi_callback_info info)
2144 {
2145 NFuncArg funcArg(env, info);
2146
2147 if (!funcArg.InitArgs(NARG_CNT::FOUR)) {
2148 return nullptr;
2149 }
2150 bool succ = false;
2151 LOGI("WebGL2 drawArraysInstanced start");
2152 int32_t mode;
2153 tie(succ, mode) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt32();
2154 if (!succ) {
2155 return nullptr;
2156 }
2157 LOGI("WebGL WebGL2RenderingContextBase::drawArraysInstanced mode = %{public}u", mode);
2158 int32_t first;
2159 tie(succ, first) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32();
2160 if (!succ) {
2161 return nullptr;
2162 }
2163 LOGI("WebGL WebGL2RenderingContextBase::drawArraysInstanced first = %{public}u", first);
2164 int32_t count;
2165 tie(succ, count) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt32();
2166 if (!succ) {
2167 return nullptr;
2168 }
2169 LOGI("WebGL WebGL2RenderingContextBase::drawArraysInstanced count = %{public}u", count);
2170 int32_t instanceCount;
2171 tie(succ, instanceCount) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt32();
2172 if (!succ) {
2173 return nullptr;
2174 }
2175 LOGI("WebGL WebGL2RenderingContextBase::drawArraysInstanced instanceCount = %{public}u", instanceCount);
2176 glDrawArraysInstanced(static_cast<GLenum>(mode), static_cast<GLint>(first), static_cast<GLsizei>(count),
2177 static_cast<GLsizei>(instanceCount));
2178 LOGI("WebGL drawArraysInstanced end");
2179 return nullptr;
2180 }
2181
DrawElementsInstanced(napi_env env,napi_callback_info info)2182 napi_value WebGL2RenderingContextBase::DrawElementsInstanced(napi_env env, napi_callback_info info)
2183 {
2184 NFuncArg funcArg(env, info);
2185
2186 if (!funcArg.InitArgs(NARG_CNT::FIVE)) {
2187 return nullptr;
2188 }
2189 bool succ = false;
2190 LOGI("WebGL2 drawElementsInstanced start");
2191 int32_t mode;
2192 tie(succ, mode) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt32();
2193 if (!succ) {
2194 return nullptr;
2195 }
2196 LOGI("WebGL WebGL2RenderingContextBase::drawElementsInstanced mode = %{public}u", mode);
2197 int32_t count;
2198 tie(succ, count) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32();
2199 if (!succ) {
2200 return nullptr;
2201 }
2202 LOGI("WebGL WebGL2RenderingContextBase::drawElementsInstanced count = %{public}u", count);
2203 int32_t type;
2204 tie(succ, type) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt32();
2205 if (!succ) {
2206 return nullptr;
2207 }
2208 LOGI("WebGL WebGL2RenderingContextBase::drawElementsInstanced type = %{public}u", type);
2209 int32_t offset;
2210 tie(succ, offset) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt32();
2211 if (!succ) {
2212 return nullptr;
2213 }
2214 LOGI("WebGL WebGL2RenderingContextBase::drawElementsInstanced offset = %{public}u", offset);
2215 int32_t instanceCount;
2216 tie(succ, instanceCount) = NVal(env, funcArg[NARG_POS::FIFTH]).ToInt32();
2217 if (!succ) {
2218 return nullptr;
2219 }
2220 LOGI("WebGL WebGL2RenderingContextBase::drawElementsInstanced instanceCount = %{public}u", instanceCount);
2221 glDrawElementsInstanced(static_cast<GLenum>(mode), static_cast<GLsizei>(count), static_cast<GLenum>(type),
2222 reinterpret_cast<GLvoid *>(static_cast<intptr_t>(offset)),
2223 static_cast<GLsizei>(instanceCount));
2224 LOGI("WebGL drawElementsInstanced end");
2225 return nullptr;
2226 }
2227
DrawRangeElements(napi_env env,napi_callback_info info)2228 napi_value WebGL2RenderingContextBase::DrawRangeElements(napi_env env, napi_callback_info info)
2229 {
2230 NFuncArg funcArg(env, info);
2231
2232 if (!funcArg.InitArgs(NARG_CNT::SIX)) {
2233 return nullptr;
2234 }
2235 bool succ = false;
2236 LOGI("WebGL2 drawRangeElements start");
2237 int32_t mode;
2238 tie(succ, mode) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt32();
2239 if (!succ) {
2240 return nullptr;
2241 }
2242 LOGI("WebGL WebGL2RenderingContextBase::drawRangeElements mode = %{public}u", mode);
2243 int32_t start;
2244 tie(succ, start) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32();
2245 if (!succ) {
2246 return nullptr;
2247 }
2248 LOGI("WebGL WebGL2RenderingContextBase::drawRangeElements start = %{public}u", start);
2249 int32_t end;
2250 tie(succ, end) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt32();
2251 if (!succ) {
2252 return nullptr;
2253 }
2254 LOGI("WebGL WebGL2RenderingContextBase::drawRangeElements end = %{public}u", end);
2255 int32_t count;
2256 tie(succ, count) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt32();
2257 if (!succ) {
2258 return nullptr;
2259 }
2260 LOGI("WebGL WebGL2RenderingContextBase::drawRangeElements count = %{public}u", count);
2261 int32_t type;
2262 tie(succ, type) = NVal(env, funcArg[NARG_POS::FIFTH]).ToInt32();
2263 if (!succ) {
2264 return nullptr;
2265 }
2266 LOGI("WebGL WebGL2RenderingContextBase::drawRangeElements type = %{public}u", type);
2267 int32_t offset;
2268 tie(succ, offset) = NVal(env, funcArg[NARG_POS::SIXTH]).ToInt32();
2269 if (!succ) {
2270 return nullptr;
2271 }
2272 LOGI("WebGL WebGL2RenderingContextBase::drawRangeElements offset = %{public}u", offset);
2273 glDrawRangeElements(static_cast<GLenum>(mode), static_cast<GLuint>(start), static_cast<GLuint>(end),
2274 static_cast<GLsizei>(count), static_cast<GLenum>(type),
2275 reinterpret_cast<GLvoid *>(static_cast<intptr_t>(offset)));
2276 LOGI("WebGL drawRangeElements end");
2277 return nullptr;
2278 }
2279
CopyBufferSubData(napi_env env,napi_callback_info info)2280 napi_value WebGL2RenderingContextBase::CopyBufferSubData(napi_env env, napi_callback_info info)
2281 {
2282 NFuncArg funcArg(env, info);
2283
2284 if (!funcArg.InitArgs(NARG_CNT::FIVE)) {
2285 return nullptr;
2286 }
2287 bool succ = false;
2288 LOGI("WebGL copyBufferSubData start");
2289 int64_t readtarget;
2290 tie(succ, readtarget) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt64();
2291 if (!succ) {
2292 return nullptr;
2293 }
2294 LOGI("WebGL WebGL2RenderingContextBase::copyBufferSubData readtarget = %{public}u", readtarget);
2295 int64_t writetarget;
2296 tie(succ, writetarget) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt64();
2297 if (!succ) {
2298 return nullptr;
2299 }
2300 LOGI("WebGL WebGL2RenderingContextBase::copyBufferSubData writetarget = %{public}u", writetarget);
2301 int64_t readoffset;
2302 tie(succ, readoffset) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt64();
2303 if (!succ) {
2304 return nullptr;
2305 }
2306 LOGI("WebGL WebGL2RenderingContextBase::copyBufferSubData readoffset = %{public}u", readoffset);
2307
2308 int64_t writeoffset;
2309 tie(succ, writeoffset) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt64();
2310 if (!succ) {
2311 return nullptr;
2312 }
2313 LOGI("WebGL WebGL2RenderingContextBase::copyBufferSubData writeoffset = %{public}u", writeoffset);
2314
2315 int64_t size;
2316 tie(succ, size) = NVal(env, funcArg[NARG_POS::FIFTH]).ToInt64();
2317 if (!succ) {
2318 return nullptr;
2319 }
2320 LOGI("WebGL WebGL2RenderingContextBase::copyBufferSubData size = %{public}u", size);
2321 glCopyBufferSubData(static_cast<GLenum>(readtarget), static_cast<GLenum>(writetarget),
2322 static_cast<GLintptr>(readoffset), static_cast<GLintptr>(writeoffset), static_cast<GLsizeiptr>(size));
2323 LOGI("WebGL copyBufferSubData end");
2324 return nullptr;
2325 }
2326
GetBufferSubData(napi_env env,napi_callback_info info)2327 napi_value WebGL2RenderingContextBase::GetBufferSubData(napi_env env, napi_callback_info info)
2328 {
2329 NFuncArg funcArg(env, info);
2330 size_t argc = 5;
2331 napi_value args[5];
2332 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
2333 int64_t target;
2334 napi_get_value_int64(env, args[0], &target);
2335 LOGI("WebGL WebGL2RenderingContextBase::getBufferSubData target = %{public}u", target);
2336 int64_t srcByteOffset;
2337 napi_get_value_int64(env, args[1], &srcByteOffset);
2338 LOGI("WebGL WebGL2RenderingContextBase::getBufferSubData srcByteOffset = %{public}u", srcByteOffset);
2339 LOGI("WebGL WebGL2RenderingContextBase::getBufferSubData funcArg[NARG_POS::THIRD] = %{public}u",
2340 funcArg[NARG_POS::THIRD]);
2341 size_t bufLen = 0;
2342 void *buf = nullptr;
2343 napi_value arraybuffer = nullptr;
2344 size_t byteoff = 0;
2345 int a = 2;
2346 napi_get_dataview_info(env, args[a], &bufLen, &buf, &arraybuffer, &byteoff);
2347 LOGI("WebGL WebGL2RenderingContextBase::getBufferSubData buf = %{public}u", buf);
2348 LOGI("WebGL WebGL2RenderingContextBase::getBufferSubData bufLen = %{public}u", bufLen);
2349 LOGI("WebGL WebGL2RenderingContextBase::getBufferSubData arraybuffer = %{public}u", arraybuffer);
2350 LOGI("WebGL WebGL2RenderingContextBase::getBufferSubData byteoff = %{public}u", byteoff);
2351
2352 glBufferSubData(static_cast<GLenum>(target), static_cast<GLintptr>(srcByteOffset),
2353 static_cast<GLsizeiptr>(bufLen), static_cast<void*>(buf));
2354 LOGI("WebGL getBufferSubData end");
2355 return nullptr;
2356 }
2357
BlitFramebuffer(napi_env env,napi_callback_info info)2358 napi_value WebGL2RenderingContextBase::BlitFramebuffer(napi_env env, napi_callback_info info)
2359 {
2360 NFuncArg funcArg(env, info);
2361
2362 if (!funcArg.InitArgs(NARG_CNT::TEN)) {
2363 return nullptr;
2364 }
2365 bool succ = false;
2366 LOGI("WebGL blitFramebuffer start");
2367 int64_t srcX0;
2368 tie(succ, srcX0) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt64();
2369 if (!succ) {
2370 return nullptr;
2371 }
2372 LOGI("WebGL WebGL2RenderingContextBase::blitFramebuffer srcX0 = %{public}u", srcX0);
2373 int64_t srcY0;
2374 tie(succ, srcY0) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt64();
2375 if (!succ) {
2376 return nullptr;
2377 }
2378 LOGI("WebGL WebGL2RenderingContextBase::blitFramebuffer srcY0 = %{public}u", srcY0);
2379 int64_t srcX1;
2380 tie(succ, srcX1) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt64();
2381 if (!succ) {
2382 return nullptr;
2383 }
2384 LOGI("WebGL WebGL2RenderingContextBase::blitFramebuffer srcX1 = %{public}u", srcX1);
2385 int64_t srcY1;
2386 tie(succ, srcY1) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt64();
2387 if (!succ) {
2388 return nullptr;
2389 }
2390 LOGI("WebGL WebGL2RenderingContextBase::blitFramebuffer srcY1 = %{public}u", srcY1);
2391 int64_t dstX0;
2392 tie(succ, dstX0) = NVal(env, funcArg[NARG_POS::FIFTH]).ToInt64();
2393 if (!succ) {
2394 return nullptr;
2395 }
2396 LOGI("WebGL WebGL2RenderingContextBase::blitFramebuffer dstX0 = %{public}u", dstX0);
2397 int64_t dstY0;
2398 tie(succ, dstY0) = NVal(env, funcArg[NARG_POS::SIXTH]).ToInt64();
2399 if (!succ) {
2400 return nullptr;
2401 }
2402 LOGI("WebGL WebGL2RenderingContextBase::blitFramebuffer dstY0 = %{public}u", dstY0);
2403 int64_t dstX1;
2404 tie(succ, dstX1) = NVal(env, funcArg[NARG_POS::SEVENTH]).ToInt64();
2405 if (!succ) {
2406 return nullptr;
2407 }
2408 LOGI("WebGL WebGL2RenderingContextBase::blitFramebuffer dstX1 = %{public}u", dstX1);
2409 int64_t dstY1;
2410 tie(succ, dstY1) = NVal(env, funcArg[NARG_POS::EIGHTH]).ToInt64();
2411 if (!succ) {
2412 return nullptr;
2413 }
2414 LOGI("WebGL WebGL2RenderingContextBase::blitFramebuffer dstY1 = %{public}u", dstY1);
2415 int64_t mask;
2416 tie(succ, mask) = NVal(env, funcArg[NARG_POS::NINTH]).ToInt64();
2417 if (!succ) {
2418 return nullptr;
2419 }
2420 LOGI("WebGL WebGL2RenderingContextBase::blitFramebuffer mask = %{public}u", mask);
2421 int64_t filter;
2422 tie(succ, filter) = NVal(env, funcArg[NARG_POS::TENTH]).ToInt64();
2423 if (!succ) {
2424 return nullptr;
2425 }
2426 LOGI("WebGL WebGL2RenderingContextBase::blitFramebuffer filter = %{public}u", filter);
2427 glBlitFramebuffer(static_cast<GLint>(srcX0), static_cast<GLint>(srcY0), static_cast<GLint>(srcX1),
2428 static_cast<GLint>(srcY1), static_cast<GLint>(dstX0),
2429 static_cast<GLint>(dstY0), static_cast<GLint>(dstX1), static_cast<GLint>(dstY1),
2430 static_cast<GLbitfield>(mask), static_cast<GLenum>(filter));
2431 LOGI("WebGL blitFramebuffer end");
2432 return nullptr;
2433 }
2434
FramebufferTextureLayer(napi_env env,napi_callback_info info)2435 napi_value WebGL2RenderingContextBase::FramebufferTextureLayer(napi_env env, napi_callback_info info)
2436 {
2437 NFuncArg funcArg(env, info);
2438 if (!funcArg.InitArgs(NARG_CNT::FIVE)) {
2439 return nullptr;
2440 }
2441 bool succ = false;
2442 LOGI("WebGL framebufferTextureLayer start");
2443 int64_t target;
2444 tie(succ, target) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt64();
2445 if (!succ) {
2446 return nullptr;
2447 }
2448 LOGI("WebGL WebGL2RenderingContextBase::framebufferTextureLayer target = %{public}u", target);
2449 int64_t attachment;
2450 tie(succ, attachment) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt64();
2451 if (!succ) {
2452 return nullptr;
2453 }
2454 LOGI("WebGL WebGL2RenderingContextBase::framebufferTextureLayer attachment = %{public}u", attachment);
2455 if (funcArg[NARG_POS::THIRD] == nullptr) {
2456 return nullptr;
2457 }
2458 WebGLTexture *webGlTexture = nullptr;
2459 napi_status textureStatus = napi_unwrap(env, funcArg[NARG_POS::THIRD], (void **)&webGlTexture);
2460 if (textureStatus != napi_ok) {
2461 return nullptr;
2462 }
2463 unsigned int texture = webGlTexture->GetTexture();
2464 LOGI("WebGL WebGLRenderContext::WebGL2RenderingContextBase framebufferTextureLayer texture= %{public}u", texture);
2465 int64_t level;
2466 tie(succ, level) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt64();
2467 if (!succ) {
2468 return nullptr;
2469 }
2470 LOGI("WebGL WebGL2RenderingContextBase::framebufferTextureLayer level = %{public}u", level);
2471 int64_t layer;
2472 tie(succ, layer) = NVal(env, funcArg[NARG_POS::FIFTH]).ToInt64();
2473 if (!succ) {
2474 return nullptr;
2475 }
2476 LOGI("WebGL WebGL2RenderingContextBase::framebufferTextureLayer layer = %{public}u", layer);
2477 glFramebufferTextureLayer(static_cast<GLenum>(target), static_cast<GLenum>(attachment),
2478 static_cast<GLuint>(texture), static_cast<GLint>(level),
2479 static_cast<GLint>(layer));
2480 LOGI("WebGL framebufferTextureLayer end");
2481 return nullptr;
2482 }
2483
ReadBuffer(napi_env env,napi_callback_info info)2484 napi_value WebGL2RenderingContextBase::ReadBuffer(napi_env env, napi_callback_info info)
2485 {
2486 NFuncArg funcArg(env, info);
2487 if (!funcArg.InitArgs(NARG_CNT::ONE)) {
2488 return nullptr;
2489 }
2490 bool succ = false;
2491 LOGI("WebGL readBuffer start");
2492 int64_t src;
2493 tie(succ, src) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt64();
2494 if (!succ) {
2495 return nullptr;
2496 }
2497 LOGI("WebGL WebGL2RenderingContextBase::readBuffer src = %{public}u", src);
2498 glReadBuffer(static_cast<GLenum>(src));
2499 LOGI("WebGL readBuffer end");
2500 return nullptr;
2501 }
2502
RenderbufferStorageMultisample(napi_env env,napi_callback_info info)2503 napi_value WebGL2RenderingContextBase::RenderbufferStorageMultisample(napi_env env, napi_callback_info info)
2504 {
2505 NFuncArg funcArg(env, info);
2506 if (!funcArg.InitArgs(NARG_CNT::FIVE)) {
2507 return nullptr;
2508 }
2509 bool succ = false;
2510 LOGI("WebGL renderbufferStorageMultisample start");
2511 int64_t target;
2512 tie(succ, target) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt64();
2513 if (!succ) {
2514 return nullptr;
2515 }
2516 LOGI("WebGL WebGL2RenderingContextBase::renderbufferStorageMultisample target = %{public}u", target);
2517 int64_t samples;
2518 tie(succ, samples) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt64();
2519 if (!succ) {
2520 return nullptr;
2521 }
2522 LOGI("WebGL WebGL2RenderingContextBase::renderbufferStorageMultisample samples = %{public}u", samples);
2523 int64_t internalformat;
2524 tie(succ, internalformat) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt64();
2525 if (!succ) {
2526 return nullptr;
2527 }
2528 LOGI("WebGL WebGL2RenderingContextBase::renderbufferStorageMultisample internalformat end");
2529 int64_t width;
2530 tie(succ, width) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt64();
2531 if (!succ) {
2532 return nullptr;
2533 }
2534 LOGI("WebGL WebGL2RenderingContextBase::renderbufferStorageMultisample level = %{public}u", width);
2535 int64_t height;
2536 tie(succ, height) = NVal(env, funcArg[NARG_POS::FIFTH]).ToInt64();
2537 if (!succ) {
2538 return nullptr;
2539 }
2540 LOGI("WebGL WebGL2RenderingContextBase::renderbufferStorageMultisample height = %{public}u", height);
2541 glRenderbufferStorageMultisample(static_cast<GLenum>(target),
2542 static_cast<GLsizei>(samples), static_cast<GLenum>(internalformat),
2543 static_cast<GLsizei>(width), static_cast<GLsizei>(height));
2544 LOGI("WebGL renderbufferStorageMultisample end");
2545 return nullptr;
2546 }
2547
TexStorage2D(napi_env env,napi_callback_info info)2548 napi_value WebGL2RenderingContextBase::TexStorage2D(napi_env env, napi_callback_info info)
2549 {
2550 NFuncArg funcArg(env, info);
2551 if (!funcArg.InitArgs(NARG_CNT::FIVE)) {
2552 return nullptr;
2553 }
2554 bool succ = false;
2555 LOGI("WebGL texStorage2D start");
2556 int64_t target;
2557 tie(succ, target) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt64();
2558 if (!succ) {
2559 return nullptr;
2560 }
2561 LOGI("WebGL WebGL2RenderingContextBase::texStorage2D target = %{public}u", target);
2562 int64_t levels;
2563 tie(succ, levels) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt64();
2564 if (!succ) {
2565 return nullptr;
2566 }
2567 LOGI("WebGL WebGL2RenderingContextBase::texStorage2D levels = %{public}u", levels);
2568 int64_t internalformat;
2569 tie(succ, internalformat) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt64();
2570 if (!succ) {
2571 return nullptr;
2572 }
2573 LOGI("WebGL WebGLRenderContext::WebGL2RenderingContextBase texStorage2D internalformat= %{public}u",
2574 internalformat);
2575 int64_t width;
2576 tie(succ, width) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt64();
2577 if (!succ) {
2578 return nullptr;
2579 }
2580 LOGI("WebGL WebGL2RenderingContextBase::texStorage2D level = %{public}u", width);
2581 int64_t height;
2582 tie(succ, height) = NVal(env, funcArg[NARG_POS::FIFTH]).ToInt64();
2583 if (!succ) {
2584 return nullptr;
2585 }
2586 LOGI("WebGL WebGL2RenderingContextBase::texStorage2D height = %{public}u", height);
2587 glTexStorage2D(static_cast<GLenum>(target), static_cast<GLsizei>(levels), static_cast<GLenum>(internalformat),
2588 static_cast<GLsizei>(width), static_cast<GLsizei>(height));
2589 LOGI("WebGL texStorage2D end");
2590 return nullptr;
2591 }
2592
GetTransformFeedbackVarying(napi_env env,napi_callback_info info)2593 napi_value WebGL2RenderingContextBase::GetTransformFeedbackVarying(napi_env env, napi_callback_info info)
2594 {
2595 NFuncArg funcArg(env, info);
2596 napi_value res = nullptr;
2597 size_t argc = 2;
2598 napi_value args[2];
2599 napi_get_cb_info(env, info, &argc, args, &res, nullptr);
2600 if (!funcArg.InitArgs(NARG_CNT::TWO)) {
2601 return nullptr;
2602 }
2603 bool succ = false;
2604 LOGI("WebGL GetTransformFeedbackVarying start");
2605 WebGLProgram *webGlProgram = nullptr;
2606 napi_status programStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGlProgram);
2607 if (programStatus != napi_ok) {
2608 return nullptr;
2609 }
2610 int programId = webGlProgram->GetProgramId();
2611 LOGI("WebGL WebGL2RenderingContextBase::getTransformFeedbackVarying programId = %{public}u", programId);
2612 int64_t index;
2613 tie(succ, index) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt64();
2614 if (!succ) {
2615 return nullptr;
2616 }
2617 napi_value objActiveInfo = NClass::InstantiateClass(env, WebGLActiveInfo::className, {});
2618 if (!objActiveInfo) {
2619 return nullptr;
2620 }
2621 auto webGLActiveInfo = NClass::GetEntityOf<WebGLActiveInfo>(env, objActiveInfo);
2622 if (!webGLActiveInfo) {
2623 return nullptr;
2624 }
2625
2626 GLsizei bufSize = 0;
2627 int length;
2628 int size;
2629 unsigned int type;
2630 char name;
2631 LOGI("WebGL WebGL2RenderingContextBase::getTransformFeedbackVarying index = %{public}u", index);
2632 glGetTransformFeedbackVarying(static_cast<GLuint>(programId), static_cast<GLuint>(index),
2633 static_cast<GLsizei>(bufSize), static_cast<GLsizei*>(&length),
2634 static_cast<GLsizei*>(&size), static_cast<GLenum*>(&type), static_cast<GLchar*>(&name));
2635 webGLActiveInfo->SetActiveName(name);
2636 webGLActiveInfo->SetActiveSize(size);
2637 webGLActiveInfo->SetActiveType(type);
2638 LOGI("WebGL getTransformFeedbackVarying end");
2639 return res;
2640 }
2641
PauseTransformFeedback(napi_env env,napi_callback_info info)2642 napi_value WebGL2RenderingContextBase::PauseTransformFeedback(napi_env env, napi_callback_info info)
2643 {
2644 NFuncArg funcArg(env, info);
2645 LOGI("WebGL pauseTransformFeedback start");
2646 glPauseTransformFeedback();
2647 LOGI("WebGL pauseTransformFeedback end");
2648 return nullptr;
2649 }
2650
ResumeTransformFeedback(napi_env env,napi_callback_info info)2651 napi_value WebGL2RenderingContextBase::ResumeTransformFeedback(napi_env env, napi_callback_info info)
2652 {
2653 NFuncArg funcArg(env, info);
2654 LOGI("WebGL resumeTransformFeedback start");
2655 glResumeTransformFeedback();
2656 LOGI("WebGL resumeTransformFeedback end");
2657 return nullptr;
2658 }
2659
BindBufferBase(napi_env env,napi_callback_info info)2660 napi_value WebGL2RenderingContextBase::BindBufferBase(napi_env env, napi_callback_info info)
2661 {
2662 NFuncArg funcArg(env, info);
2663
2664 if (!funcArg.InitArgs(NARG_CNT::THREE)) {
2665 return nullptr;
2666 }
2667 bool succ = false;
2668 LOGI("WebGL bindBufferBase start");
2669 int64_t target;
2670 tie(succ, target) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt64();
2671 if (!succ) {
2672 return nullptr;
2673 }
2674 LOGI("WebGL WebGL2RenderingContextBase::bindBufferBase target = %{public}u", target);
2675 int64_t index;
2676 tie(succ, index) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt64();
2677 if (!succ) {
2678 return nullptr;
2679 }
2680 LOGI("WebGL WebGL2RenderingContextBase::bindBufferBase index = %{public}u", index);
2681 if (funcArg[NARG_POS::THIRD] == nullptr) {
2682 return nullptr;
2683 }
2684 WebGLBuffer *webGlBuffer = nullptr;
2685 napi_status bufferStatus = napi_unwrap(env, funcArg[NARG_POS::THIRD], (void **)&webGlBuffer);
2686 if (bufferStatus != napi_ok) {
2687 return nullptr;
2688 }
2689 unsigned int buffer = webGlBuffer->GetBuffer();
2690 LOGI("WebGL WebGLRenderContext::WebGL2RenderingContextBase bindBufferBase buffer= %{public}u", buffer);
2691 glBindBufferBase(static_cast<GLenum>(target), static_cast<GLuint>(index), static_cast<GLuint>(buffer));
2692 LOGI("WebGL bindBufferBase end");
2693 return nullptr;
2694 }
2695
BindBufferRange(napi_env env,napi_callback_info info)2696 napi_value WebGL2RenderingContextBase::BindBufferRange(napi_env env, napi_callback_info info)
2697 {
2698 NFuncArg funcArg(env, info);
2699 if (!funcArg.InitArgs(NARG_CNT::FIVE)) {
2700 return nullptr;
2701 }
2702 bool succ = false;
2703 LOGI("WebGL bindBufferRange start");
2704 int64_t target;
2705 tie(succ, target) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt64();
2706 if (!succ) {
2707 return nullptr;
2708 }
2709 LOGI("WebGL WebGL2RenderingContextBase::bindBufferRange target = %{public}u", target);
2710 int64_t index;
2711 tie(succ, index) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt64();
2712 if (!succ) {
2713 return nullptr;
2714 }
2715 LOGI("WebGL WebGL2RenderingContextBase::bindBufferRange index = %{public}u", index);
2716 if (funcArg[NARG_POS::THIRD] == nullptr) {
2717 return nullptr;
2718 }
2719 WebGLBuffer *webGlBuffer = nullptr;
2720 napi_status bufferStatus = napi_unwrap(env, funcArg[NARG_POS::THIRD], (void **)&webGlBuffer);
2721 if (bufferStatus != napi_ok) {
2722 return nullptr;
2723 }
2724 unsigned int buffer = webGlBuffer->GetBuffer();
2725 LOGI("WebGL WebGLRenderContext::WebGL2RenderingContextBase bindBufferRange buffer= %{public}u", buffer);
2726 int64_t offset;
2727 tie(succ, offset) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt64();
2728 if (!succ) {
2729 return nullptr;
2730 }
2731 LOGI("WebGL WebGL2RenderingContextBase::bindBufferRange offset = %{public}u", offset);
2732 int64_t size;
2733 tie(succ, size) = NVal(env, funcArg[NARG_POS::FIFTH]).ToInt64();
2734 if (!succ) {
2735 return nullptr;
2736 }
2737 LOGI("WebGL WebGL2RenderingContextBase::bindBufferRange size = %{public}u", size);
2738 glBindBufferRange(static_cast<GLenum>(target), static_cast<GLuint>(index), static_cast<GLuint>(buffer),
2739 static_cast<GLintptr>(offset), static_cast<GLsizeiptr>(size));
2740 LOGI("WebGL bindBufferRange end");
2741 return nullptr;
2742 }
2743
GetIndexedParameter(napi_env env,napi_callback_info info)2744 napi_value WebGL2RenderingContextBase::GetIndexedParameter(napi_env env, napi_callback_info info)
2745 {
2746 NFuncArg funcArg(env, info);
2747 if (!funcArg.InitArgs(NARG_CNT::TWO)) {
2748 return nullptr;
2749 }
2750 bool succ = false;
2751 LOGI("WebGL getIndexedParameter start");
2752 int64_t target;
2753 tie(succ, target) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt64();
2754 if (!succ) {
2755 return nullptr;
2756 }
2757 LOGI("WebGL WebGL2RenderingContextBase::getIndexedParameter target = %{public}u", target);
2758 int64_t index;
2759 tie(succ, index) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt64();
2760 if (!succ) {
2761 return nullptr;
2762 }
2763 LOGI("WebGL WebGL2RenderingContextBase::getIndexedParameter index = %{public}u", index);
2764 if (target == GL_TRANSFORM_FEEDBACK_BUFFER_BINDING || target == GL_UNIFORM_BUFFER_BINDING) {
2765 LOGI("WebGL getIndexedParameter return webGLBuffer start");
2766 napi_value objBuffer = NClass::InstantiateClass(env, WebGLBuffer::className, {});
2767 if (!objBuffer) {
2768 return nullptr;
2769 }
2770 auto webGlBuffer = NClass::GetEntityOf<WebGLBuffer>(env, objBuffer);
2771 if (!webGlBuffer) {
2772 return nullptr;
2773 }
2774 webGlBuffer->SetBuffer(index);
2775 LOGI("WebGL getIndexedParameter end");
2776 return objBuffer;
2777 } else if (target == GL_TRANSFORM_FEEDBACK_BUFFER_SIZE || target == GL_UNIFORM_BUFFER_SIZE) {
2778 int64_t data;
2779 glGetInteger64i_v(target, index, &data);
2780 LOGI("WebGL getIndexedParameter end");
2781 return NVal::CreateInt64(env, data).val_;
2782 } else if (target == GL_UNIFORM_BUFFER_SIZE || target == GL_UNIFORM_BUFFER_START) {
2783 int64_t data;
2784 glGetInteger64i_v(target, index, &data);
2785 LOGI("WebGL getIndexedParameter end");
2786 return NVal::CreateInt64(env, data).val_;
2787 } else {
2788 LOGI("WebGL getIndexedParameter end");
2789 return nullptr;
2790 }
2791 }
2792
GetUniformBlockIndex(napi_env env,napi_callback_info info)2793 napi_value WebGL2RenderingContextBase::GetUniformBlockIndex(napi_env env, napi_callback_info info)
2794 {
2795 NFuncArg funcArg(env, info);
2796
2797 if (!funcArg.InitArgs(NARG_CNT::TWO)) {
2798 return nullptr;
2799 }
2800 if (funcArg[NARG_POS::FIRST] == nullptr) {
2801 return nullptr;
2802 }
2803 bool succ = false;
2804 LOGI("WebGL2 getUniformBlockIndex start");
2805 WebGLProgram *webGlProgram = nullptr;
2806 napi_status programStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **)&webGlProgram);
2807 if (programStatus != napi_ok) {
2808 return nullptr;
2809 }
2810 int programId = webGlProgram->GetProgramId();
2811 LOGI("WebGL2 WebGL2RenderContext::getUniformBlockIndex programId = %{public}u", programId);
2812 unique_ptr<char[]> name;
2813 tie(succ, name, ignore) = NVal(env, funcArg[NARG_POS::SECOND]).ToUTF8String();
2814 if (!succ) {
2815 return nullptr;
2816 }
2817 const GLchar *uniformBlockName = name.get();
2818 LOGI("WebGL2 WebGL2RenderContext::getUniformBlockIndex uniformBlockName = %{public}s", name.get());
2819 GLuint returnValue = glGetUniformBlockIndex(static_cast<GLuint>(programId), uniformBlockName);
2820 int64_t res = static_cast<int64_t>(returnValue);
2821 LOGI("WebGL2 getUniformBlockIndex end");
2822 return NVal::CreateInt64(env, res).val_;
2823 }
2824
UniformBlockBinding(napi_env env,napi_callback_info info)2825 napi_value WebGL2RenderingContextBase::UniformBlockBinding(napi_env env, napi_callback_info info)
2826 {
2827 NFuncArg funcArg(env, info);
2828
2829 if (!funcArg.InitArgs(NARG_CNT::THREE)) {
2830 return nullptr;
2831 }
2832 if (funcArg[NARG_POS::FIRST] == nullptr) {
2833 return nullptr;
2834 }
2835 bool succ = false;
2836 LOGI("WebGL2 uniformBlockBinding start");
2837 WebGLProgram *webGlProgram = nullptr;
2838 napi_status programStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **)&webGlProgram);
2839 if (programStatus != napi_ok) {
2840 return nullptr;
2841 }
2842 int programId = webGlProgram->GetProgramId();
2843 LOGI("WebGL2 WebGL2RenderContext::uniformBlockBinding programId = %{public}u", programId);
2844 int64_t uniformBlockIndex;
2845 tie(succ, uniformBlockIndex) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt64();
2846 if (!succ) {
2847 return nullptr;
2848 }
2849 LOGI("WebGL2 WebGL2RenderContext::uniformBlockBinding uniformBlockIndex = %{public}u", uniformBlockIndex);
2850 int64_t uniformBlockBinding;
2851 tie(succ, uniformBlockBinding) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt64();
2852 if (!succ) {
2853 return nullptr;
2854 }
2855 LOGI("WebGL2 WebGL2RenderContext::uniformBlockBinding uniformBlockBinding = %{public}u", uniformBlockBinding);
2856 glUniformBlockBinding(static_cast<GLuint>(programId), static_cast<GLuint>(uniformBlockIndex),
2857 static_cast<GLuint>(uniformBlockBinding));
2858 LOGI("WebGL2 uniformBlockBinding end");
2859 return nullptr;
2860 }
2861
CreateVertexArray(napi_env env,napi_callback_info info)2862 napi_value WebGL2RenderingContextBase::CreateVertexArray(napi_env env, napi_callback_info info)
2863 {
2864 LOGI("WebGL2 createVertexArray start");
2865 napi_value objVertexArrayObject = NClass::InstantiateClass(env, WebGLVertexArrayObject::className, {});
2866 if (!objVertexArrayObject) {
2867 return nullptr;
2868 }
2869 auto webGLVertexArrayObject = NClass::GetEntityOf<WebGLVertexArrayObject>(env, objVertexArrayObject);
2870 if (!webGLVertexArrayObject) {
2871 return nullptr;
2872 }
2873 unsigned int vertexArraysId;
2874 glGenVertexArrays(1, &vertexArraysId);
2875 webGLVertexArrayObject->SetVertexArrays(vertexArraysId);
2876 LOGI("WebGL2 WebGL2RenderingContextBase::createVertexArray vertexArraysId = %{public}u", vertexArraysId);
2877 LOGI("WebGL2 createVertexArray end");
2878 return objVertexArrayObject;
2879 }
2880
DeleteVertexArray(napi_env env,napi_callback_info info)2881 napi_value WebGL2RenderingContextBase::DeleteVertexArray(napi_env env, napi_callback_info info)
2882 {
2883 NFuncArg funcArg(env, info);
2884
2885 if (!funcArg.InitArgs(NARG_CNT::ONE)) {
2886 return nullptr;
2887 }
2888 LOGI("WebGL deleteVertexArray start");
2889 if (funcArg[NARG_POS::FIRST] == nullptr) {
2890 return nullptr;
2891 }
2892 WebGLVertexArrayObject *webGLVertexArrayObject = nullptr;
2893 napi_status vertexArraysStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **)&webGLVertexArrayObject);
2894 if (vertexArraysStatus != napi_ok) {
2895 return nullptr;
2896 }
2897 unsigned int vertexArrays = webGLVertexArrayObject->GetVertexArrays();
2898
2899 glDeleteVertexArrays(1, &vertexArrays);
2900 LOGI("WebGL deleteVertexArray end");
2901 return nullptr;
2902 }
2903
IsVertexArray(napi_env env,napi_callback_info info)2904 napi_value WebGL2RenderingContextBase::IsVertexArray(napi_env env, napi_callback_info info)
2905 {
2906 NFuncArg funcArg(env, info);
2907 bool res = false;
2908 if (!funcArg.InitArgs(NARG_CNT::ONE)) {
2909 return NVal::CreateBool(env, res).val_;
2910 }
2911 LOGI("WebGL isVertexArray start");
2912 if (funcArg[NARG_POS::FIRST] == nullptr) {
2913 return NVal::CreateBool(env, res).val_;
2914 }
2915 WebGLVertexArrayObject *webGlVertexArrayObject = nullptr;
2916 napi_status vertexArraysStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **)&webGlVertexArrayObject);
2917 if (vertexArraysStatus != napi_ok) {
2918 return NVal::CreateBool(env, res).val_;
2919 }
2920 unsigned int vertexArrays = webGlVertexArrayObject->GetVertexArrays();
2921 GLboolean returnValue = glIsVertexArray(static_cast<GLuint>(vertexArrays));
2922 res = static_cast<bool>(returnValue);
2923 LOGI("WebGL isVertexArray end");
2924 return NVal::CreateBool(env, res).val_;
2925 }
2926
BindVertexArray(napi_env env,napi_callback_info info)2927 napi_value WebGL2RenderingContextBase::BindVertexArray(napi_env env, napi_callback_info info)
2928 {
2929 NFuncArg funcArg(env, info);
2930
2931 if (!funcArg.InitArgs(NARG_CNT::ONE)) {
2932 return nullptr;
2933 }
2934 if (funcArg[NARG_POS::FIRST] == nullptr) {
2935 return nullptr;
2936 }
2937 LOGI("WebGL bindVertexArray start");
2938 WebGLVertexArrayObject *webGlVertexArrayObject = nullptr;
2939 napi_status vertexArraysStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **)&webGlVertexArrayObject);
2940 if (vertexArraysStatus != napi_ok) {
2941 return nullptr;
2942 }
2943 unsigned int vertexArrays = webGlVertexArrayObject->GetVertexArrays();
2944 glBindVertexArray(static_cast<GLuint>(vertexArrays));
2945 LOGI("WebGL bindVertexArray end");
2946 return nullptr;
2947 }
2948
Uniform1uiv(napi_env env,napi_callback_info info)2949 napi_value WebGL2RenderingContextBase::Uniform1uiv(napi_env env, napi_callback_info info)
2950 {
2951 NFuncArg funcArg(env, info);
2952
2953 if (!funcArg.InitArgs(NARG_CNT::THREE, NARG_CNT::FOUR)) {
2954 return nullptr;
2955 }
2956
2957 LOGI("WebGL2 uniform1uiv start");
2958 bool succ = false;
2959 WebGLUniformLocation *webGLUniformLocation = nullptr;
2960 napi_status locationStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGLUniformLocation);
2961 if (locationStatus != napi_ok) {
2962 return nullptr;
2963 }
2964 int location = webGLUniformLocation->GetUniformLocationId();
2965 LOGI("WebGL2 WebGLRenderContext::uniform1uiv location = %{public}u", location);
2966 if (funcArg[NARG_POS::THIRD] == nullptr) {
2967 return nullptr;
2968 }
2969 int64_t srcOffset = 0;
2970 if (funcArg[NARG_POS::FOURTH] != nullptr) {
2971 tie(succ, srcOffset) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt64();
2972 if (!succ) {
2973 return nullptr;
2974 }
2975 LOGI("WebGL2 WebGL2RenderingContextBase::uniform1uiv srcOffset = %{public}u", srcOffset);
2976 }
2977 int64_t srcLength = 0;
2978 if (funcArg[NARG_POS::FOURTH] != nullptr) {
2979 tie(succ, srcLength) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt64();
2980 if (!succ) {
2981 return nullptr;
2982 }
2983 LOGI("WebGL2 WebGL2RenderingContextBase::uniform1uiv srcLength = %{public}u", srcLength);
2984 }
2985 napi_value array = funcArg[NARG_POS::SECOND];
2986 bool isArray = false;
2987 tie(succ, isArray) = NVal(env, array).IsArray();
2988 if (isArray) {
2989 LOGI("WebGL2 uniform1uiv is Array");
2990 uint32_t length;
2991 napi_status lengthStatus = napi_get_array_length(env, array, &length);
2992 if (lengthStatus != napi_ok) {
2993 return nullptr;
2994 }
2995 float uniform1uiv[length];
2996 uint32_t i;
2997 for (i = 0; i < length; i++) {
2998 napi_value element;
2999 napi_status eleStatus = napi_get_element(env, array, i, &element);
3000 if (eleStatus != napi_ok) {
3001 return nullptr;
3002 }
3003 double ele;
3004 napi_status doubleStatus = napi_get_value_double(env, element, &ele);
3005 if (doubleStatus != napi_ok) {
3006 return nullptr;
3007 }
3008 uniform1uiv[i] = (float) ele;
3009 }
3010 glUniform1uiv(static_cast<GLint>(location), static_cast<GLsizei>(srcLength),
3011 reinterpret_cast<GLuint *>(uniform1uiv + srcOffset));
3012 LOGI("WebGL2 uniform1uiv array end");
3013 return nullptr;
3014 }
3015 bool isTypedarray = false;
3016 tie(succ, isTypedarray) = NVal(env, array).IsTypeArray();
3017 if (!isTypedarray || !succ) {
3018 return nullptr;
3019 }
3020 void *data = nullptr;
3021 size_t length;
3022 napi_typedarray_type type;
3023 tie(succ, type, data, length) = NVal(env, array).ToTypedArray();
3024 if (!succ) {
3025 return nullptr;
3026 }
3027 if (type == napi_float32_array) {
3028 float *inputFloat = (float *) ((uint8_t*)(data) + srcOffset);
3029 glUniform1uiv(static_cast<GLint>(location), static_cast<GLsizei>(srcLength),
3030 reinterpret_cast<GLuint *>(inputFloat));
3031 }
3032 LOGI("WebGL2 uniform1uiv typeArray end");
3033 return nullptr;
3034 }
3035
Uniform2uiv(napi_env env,napi_callback_info info)3036 napi_value WebGL2RenderingContextBase::Uniform2uiv(napi_env env, napi_callback_info info)
3037 {
3038 NFuncArg funcArg(env, info);
3039
3040 if (!funcArg.InitArgs(NARG_CNT::THREE, NARG_CNT::FOUR)) {
3041 return nullptr;
3042 }
3043
3044 LOGI("WebGL2 uniform2uiv start");
3045 bool succ = false;
3046 WebGLUniformLocation *webGLUniformLocation = nullptr;
3047 napi_status locationStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGLUniformLocation);
3048 if (locationStatus != napi_ok) {
3049 return nullptr;
3050 }
3051 int location = webGLUniformLocation->GetUniformLocationId();
3052 LOGI("WebGL2 WebGLRenderContext::uniform2uiv location = %{public}u", location);
3053 if (funcArg[NARG_POS::THIRD] == nullptr) {
3054 return nullptr;
3055 }
3056 int64_t srcOffset = 0;
3057 if (funcArg[NARG_POS::FOURTH] != nullptr) {
3058 tie(succ, srcOffset) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt64();
3059 if (!succ) {
3060 return nullptr;
3061 }
3062 LOGI("WebGL2 WebGL2RenderingContextBase::uniform2uiv srcOffset = %{public}u", srcOffset);
3063 }
3064 int64_t srcLength = 0;
3065 if (funcArg[NARG_POS::FOURTH] != nullptr) {
3066 tie(succ, srcLength) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt64();
3067 if (!succ) {
3068 return nullptr;
3069 }
3070 LOGI("WebGL2 WebGL2RenderingContextBase::uniform2uiv srcLength = %{public}u", srcLength);
3071 }
3072 napi_value array = funcArg[NARG_POS::SECOND];
3073 bool isArray = false;
3074 tie(succ, isArray) = NVal(env, array).IsArray();
3075 if (isArray) {
3076 LOGI("WebGL2 uniform2uiv is Array");
3077 uint32_t length;
3078 napi_status lengthStatus = napi_get_array_length(env, array, &length);
3079 if (lengthStatus != napi_ok) {
3080 return nullptr;
3081 }
3082 float uniform2uiv[length];
3083 uint32_t i;
3084 for (i = 0; i < length; i++) {
3085 napi_value element;
3086 napi_status eleStatus = napi_get_element(env, array, i, &element);
3087 if (eleStatus != napi_ok) {
3088 return nullptr;
3089 }
3090 double ele;
3091 napi_status doubleStatus = napi_get_value_double(env, element, &ele);
3092 if (doubleStatus != napi_ok) {
3093 return nullptr;
3094 }
3095 uniform2uiv[i] = (float) ele;
3096 }
3097 glUniform2uiv(static_cast<GLint>(location), static_cast<GLsizei>(srcLength),
3098 reinterpret_cast<GLuint *>(uniform2uiv + srcOffset));
3099 LOGI("WebGL2 uniform2uiv array end");
3100 return nullptr;
3101 }
3102 bool isTypedarray = false;
3103 tie(succ, isTypedarray) = NVal(env, array).IsTypeArray();
3104 if (!isTypedarray || !succ) {
3105 return nullptr;
3106 }
3107 void *data = nullptr;
3108 size_t length;
3109 napi_typedarray_type type;
3110 tie(succ, type, data, length) = NVal(env, array).ToTypedArray();
3111 if (!succ) {
3112 return nullptr;
3113 }
3114 if (type == napi_float32_array) {
3115 float *inputFloat = (float *) ((uint8_t*)(data) + srcOffset);
3116 glUniform2uiv(static_cast<GLint>(location), static_cast<GLsizei>(srcLength),
3117 reinterpret_cast<GLuint *>(inputFloat));
3118 }
3119 LOGI("WebGL2 uniform2uiv typeArray end");
3120 return nullptr;
3121 }
3122
Uniform3uiv(napi_env env,napi_callback_info info)3123 napi_value WebGL2RenderingContextBase::Uniform3uiv(napi_env env, napi_callback_info info)
3124 {
3125 NFuncArg funcArg(env, info);
3126
3127 if (!funcArg.InitArgs(NARG_CNT::THREE, NARG_CNT::FOUR)) {
3128 return nullptr;
3129 }
3130
3131 LOGI("WebGL2 uniform3uiv start");
3132 bool succ = false;
3133 WebGLUniformLocation *webGLUniformLocation = nullptr;
3134 napi_status locationStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGLUniformLocation);
3135 if (locationStatus != napi_ok) {
3136 return nullptr;
3137 }
3138 int location = webGLUniformLocation->GetUniformLocationId();
3139 LOGI("WebGL2 WebGLRenderContext::uniform3uiv location = %{public}u", location);
3140 if (funcArg[NARG_POS::THIRD] == nullptr) {
3141 return nullptr;
3142 }
3143 int64_t srcOffset = 0;
3144 if (funcArg[NARG_POS::FOURTH] != nullptr) {
3145 tie(succ, srcOffset) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt64();
3146 if (!succ) {
3147 return nullptr;
3148 }
3149 LOGI("WebGL2 WebGL2RenderingContextBase::uniform3uiv srcOffset = %{public}u", srcOffset);
3150 }
3151 int64_t srcLength = 0;
3152 if (funcArg[NARG_POS::FOURTH] != nullptr) {
3153 tie(succ, srcLength) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt64();
3154 if (!succ) {
3155 return nullptr;
3156 }
3157 LOGI("WebGL2 WebGL2RenderingContextBase::uniform3uiv srcLength = %{public}u", srcLength);
3158 }
3159 napi_value array = funcArg[NARG_POS::SECOND];
3160 bool isArray = false;
3161 tie(succ, isArray) = NVal(env, array).IsArray();
3162 if (isArray) {
3163 LOGI("WebGL2 uniform3uiv is Array");
3164 uint32_t length;
3165 napi_status lengthStatus = napi_get_array_length(env, array, &length);
3166 if (lengthStatus != napi_ok) {
3167 return nullptr;
3168 }
3169 float uniform3uiv[length];
3170 uint32_t i;
3171 for (i = 0; i < length; i++) {
3172 napi_value element;
3173 napi_status eleStatus = napi_get_element(env, array, i, &element);
3174 if (eleStatus != napi_ok) {
3175 return nullptr;
3176 }
3177 double ele;
3178 napi_status doubleStatus = napi_get_value_double(env, element, &ele);
3179 if (doubleStatus != napi_ok) {
3180 return nullptr;
3181 }
3182 uniform3uiv[i] = (float) ele;
3183 }
3184 glUniform3uiv(static_cast<GLint>(location), static_cast<GLsizei>(srcLength),
3185 reinterpret_cast<GLuint *>(uniform3uiv + srcOffset));
3186 LOGI("WebGL2 uniform3uiv array end");
3187 return nullptr;
3188 }
3189 bool isTypedarray = false;
3190 tie(succ, isTypedarray) = NVal(env, array).IsTypeArray();
3191 if (!isTypedarray || !succ) {
3192 return nullptr;
3193 }
3194 void *data = nullptr;
3195 size_t length;
3196 napi_typedarray_type type;
3197 tie(succ, type, data, length) = NVal(env, array).ToTypedArray();
3198 if (!succ) {
3199 return nullptr;
3200 }
3201 if (type == napi_float32_array) {
3202 float *inputFloat = (float *) ((uint8_t*)(data) + srcOffset);
3203 glUniform3uiv(static_cast<GLint>(location), static_cast<GLsizei>(srcLength),
3204 reinterpret_cast<GLuint *>(inputFloat));
3205 }
3206 LOGI("WebGL2 uniform3uiv typeArray end");
3207 return nullptr;
3208 }
3209
Uniform4uiv(napi_env env,napi_callback_info info)3210 napi_value WebGL2RenderingContextBase::Uniform4uiv(napi_env env, napi_callback_info info)
3211 {
3212 NFuncArg funcArg(env, info);
3213
3214 if (!funcArg.InitArgs(NARG_CNT::THREE, NARG_CNT::FOUR)) {
3215 return nullptr;
3216 }
3217
3218 LOGI("WebGL2 uniform4uiv start");
3219 bool succ = false;
3220 WebGLUniformLocation *webGLUniformLocation = nullptr;
3221 napi_status locationStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGLUniformLocation);
3222 if (locationStatus != napi_ok) {
3223 return nullptr;
3224 }
3225 int location = webGLUniformLocation->GetUniformLocationId();
3226 LOGI("WebGL2 WebGLRenderContext::uniform4uiv location = %{public}u", location);
3227 if (funcArg[NARG_POS::THIRD] == nullptr) {
3228 return nullptr;
3229 }
3230 int64_t srcOffset = 0;
3231 if (funcArg[NARG_POS::FOURTH] != nullptr) {
3232 tie(succ, srcOffset) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt64();
3233 if (!succ) {
3234 return nullptr;
3235 }
3236 LOGI("WebGL2 WebGL2RenderingContextBase::uniform4uiv srcOffset = %{public}u", srcOffset);
3237 }
3238 int64_t srcLength = 0;
3239 if (funcArg[NARG_POS::FOURTH] != nullptr) {
3240 tie(succ, srcLength) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt64();
3241 if (!succ) {
3242 return nullptr;
3243 }
3244 LOGI("WebGL2 WebGL2RenderingContextBase::uniform4uiv srcLength = %{public}u", srcLength);
3245 }
3246 napi_value array = funcArg[NARG_POS::SECOND];
3247 bool isArray = false;
3248 tie(succ, isArray) = NVal(env, array).IsArray();
3249 if (isArray) {
3250 LOGI("WebGL2 uniform4uiv is Array");
3251 uint32_t length;
3252 napi_status lengthStatus = napi_get_array_length(env, array, &length);
3253 if (lengthStatus != napi_ok) {
3254 return nullptr;
3255 }
3256 float uniform4uiv[length];
3257 uint32_t i;
3258 for (i = 0; i < length; i++) {
3259 napi_value element;
3260 napi_status eleStatus = napi_get_element(env, array, i, &element);
3261 if (eleStatus != napi_ok) {
3262 return nullptr;
3263 }
3264 double ele;
3265 napi_status doubleStatus = napi_get_value_double(env, element, &ele);
3266 if (doubleStatus != napi_ok) {
3267 return nullptr;
3268 }
3269 uniform4uiv[i] = (float) ele;
3270 }
3271 glUniform4uiv(static_cast<GLint>(location), static_cast<GLsizei>(srcLength),
3272 reinterpret_cast<GLuint *>(uniform4uiv + srcOffset));
3273 LOGI("WebGL2 uniform4uiv array end");
3274 return nullptr;
3275 }
3276 bool isTypedarray = false;
3277 tie(succ, isTypedarray) = NVal(env, array).IsTypeArray();
3278 if (!isTypedarray || !succ) {
3279 return nullptr;
3280 }
3281 void *data = nullptr;
3282 size_t length;
3283 napi_typedarray_type type;
3284 tie(succ, type, data, length) = NVal(env, array).ToTypedArray();
3285 if (!succ) {
3286 return nullptr;
3287 }
3288 if (type == napi_float32_array) {
3289 float *inputFloat = (float *) ((uint8_t*)(data) + srcOffset);
3290 glUniform4uiv(static_cast<GLint>(location), static_cast<GLsizei>(srcLength),
3291 reinterpret_cast<GLuint *>(inputFloat));
3292 }
3293 LOGI("WebGL2 uniform4uiv typeArray end");
3294 return nullptr;
3295 }
3296
UniformMatrix3x2fv(napi_env env,napi_callback_info info)3297 napi_value WebGL2RenderingContextBase::UniformMatrix3x2fv(napi_env env, napi_callback_info info)
3298 {
3299 NFuncArg funcArg(env, info);
3300
3301 if (!funcArg.InitArgs(NARG_CNT::THREE, NARG_CNT::FIVE)) {
3302 return nullptr;
3303 }
3304
3305 LOGI("WebGL2 uniformMatrix3x2fv start");
3306 bool succ = false;
3307 WebGLUniformLocation *webGLUniformLocation = nullptr;
3308 napi_status locationStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGLUniformLocation);
3309 if (locationStatus != napi_ok) {
3310 return nullptr;
3311 }
3312 int location = webGLUniformLocation->GetUniformLocationId();
3313 LOGI("WebGL2 WebGLRenderContext::uniformMatrix3x2fv location = %{public}u", location);
3314 if (funcArg[NARG_POS::SECOND] == nullptr) {
3315 return nullptr;
3316 }
3317 bool transpose = false;
3318 tie(succ, transpose) = NVal(env, funcArg[NARG_POS::SECOND]).ToBool();
3319 if (!succ) {
3320 return nullptr;
3321 }
3322 LOGI("WebGL2 WebGL2RenderingContextBase::uniformMatrix3x2fv transpose = %{public}u", transpose);
3323
3324 int64_t srcOffset = 0;
3325 if (funcArg[NARG_POS::FOURTH] != nullptr) {
3326 tie(succ, srcOffset) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt64();
3327 if (!succ) {
3328 return nullptr;
3329 }
3330 LOGI("WebGL2 WebGL2RenderingContextBase::uniformMatrix3x2fv srcOffset = %{public}u", srcOffset);
3331 }
3332 int64_t srcLength = 0;
3333 if (funcArg[NARG_POS::FIFTH] != nullptr) {
3334 tie(succ, srcLength) = NVal(env, funcArg[NARG_POS::FIFTH]).ToInt64();
3335 if (!succ) {
3336 return nullptr;
3337 }
3338 LOGI("WebGL2 WebGL2RenderingContextBase::uniformMatrix3x2fv srcLength = %{public}u", srcLength);
3339 }
3340 napi_value array = funcArg[NARG_POS::THIRD];
3341 bool isArray = false;
3342 tie(succ, isArray) = NVal(env, array).IsArray();
3343 if (isArray) {
3344 LOGI("WebGL2 uniformMatrix3x2fv is Array");
3345 uint32_t length;
3346 napi_status lengthStatus = napi_get_array_length(env, array, &length);
3347 if (lengthStatus != napi_ok) {
3348 return nullptr;
3349 }
3350 float uniformMatrix3x2fv[length];
3351 uint32_t i;
3352 for (i = 0; i < length; i++) {
3353 napi_value element;
3354 napi_status eleStatus = napi_get_element(env, array, i, &element);
3355 if (eleStatus != napi_ok) {
3356 return nullptr;
3357 }
3358 double ele;
3359 napi_status doubleStatus = napi_get_value_double(env, element, &ele);
3360 if (doubleStatus != napi_ok) {
3361 return nullptr;
3362 }
3363 uniformMatrix3x2fv[i] = (float) ele;
3364 }
3365 glUniformMatrix3x2fv(static_cast<GLuint>(location), static_cast<GLsizei>(srcLength),
3366 static_cast<GLboolean>(transpose), reinterpret_cast<GLfloat*>(uniformMatrix3x2fv + srcOffset));
3367 LOGI("WebGL2 uniformMatrix3x2fv array end");
3368 return nullptr;
3369 }
3370 bool isTypedarray = false;
3371 tie(succ, isTypedarray) = NVal(env, array).IsTypeArray();
3372 if (!isTypedarray || !succ) {
3373 return nullptr;
3374 }
3375 void *data = nullptr;
3376 size_t length;
3377 napi_typedarray_type type;
3378 tie(succ, type, data, length) = NVal(env, array).ToTypedArray();
3379 if (!succ) {
3380 return nullptr;
3381 }
3382 if (type == napi_float32_array) {
3383 float *inputFloat = (float *) ((uint8_t*)(data) + srcOffset);
3384 glUniformMatrix3x2fv(static_cast<GLuint>(location), static_cast<GLsizei>(srcLength),
3385 static_cast<GLboolean>(transpose), reinterpret_cast<GLfloat*>(inputFloat));
3386 }
3387 LOGI("WebGL2 uniformMatrix3x2fv typeArray end");
3388 return nullptr;
3389 }
3390
UniformMatrix4x2fv(napi_env env,napi_callback_info info)3391 napi_value WebGL2RenderingContextBase::UniformMatrix4x2fv(napi_env env, napi_callback_info info)
3392 {
3393 NFuncArg funcArg(env, info);
3394
3395 if (!funcArg.InitArgs(NARG_CNT::THREE, NARG_CNT::FIVE)) {
3396 return nullptr;
3397 }
3398
3399 LOGI("WebGL2 uniformMatrix4x2fv start");
3400 bool succ = false;
3401 WebGLUniformLocation *webGLUniformLocation = nullptr;
3402 napi_status locationStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGLUniformLocation);
3403 if (locationStatus != napi_ok) {
3404 return nullptr;
3405 }
3406 int location = webGLUniformLocation->GetUniformLocationId();
3407 LOGI("WebGL2 WebGLRenderContext::uniformMatrix4x2fv location = %{public}u", location);
3408 if (funcArg[NARG_POS::SECOND] == nullptr) {
3409 return nullptr;
3410 }
3411 bool transpose = false;
3412 tie(succ, transpose) = NVal(env, funcArg[NARG_POS::SECOND]).ToBool();
3413 if (!succ) {
3414 return nullptr;
3415 }
3416 LOGI("WebGL2 WebGL2RenderingContextBase::uniformMatrix4x2fv transpose = %{public}u", transpose);
3417
3418 int64_t srcOffset = 0;
3419 if (funcArg[NARG_POS::FOURTH] != nullptr) {
3420 tie(succ, srcOffset) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt64();
3421 if (!succ) {
3422 return nullptr;
3423 }
3424 LOGI("WebGL2 WebGL2RenderingContextBase::uniformMatrix4x2fv srcOffset = %{public}u", srcOffset);
3425 }
3426 int64_t srcLength = 0;
3427 if (funcArg[NARG_POS::FIFTH] != nullptr) {
3428 tie(succ, srcLength) = NVal(env, funcArg[NARG_POS::FIFTH]).ToInt64();
3429 if (!succ) {
3430 return nullptr;
3431 }
3432 LOGI("WebGL2 WebGL2RenderingContextBase::uniformMatrix4x2fv srcLength = %{public}u", srcLength);
3433 }
3434 napi_value array = funcArg[NARG_POS::THIRD];
3435 bool isArray = false;
3436 tie(succ, isArray) = NVal(env, array).IsArray();
3437 if (isArray) {
3438 LOGI("WebGL2 uniformMatrix4x2fv is Array");
3439 uint32_t length;
3440 napi_status lengthStatus = napi_get_array_length(env, array, &length);
3441 if (lengthStatus != napi_ok) {
3442 return nullptr;
3443 }
3444 float uniformMatrix4x2fv[length];
3445 uint32_t i;
3446 for (i = 0; i < length; i++) {
3447 napi_value element;
3448 napi_status eleStatus = napi_get_element(env, array, i, &element);
3449 if (eleStatus != napi_ok) {
3450 return nullptr;
3451 }
3452 double ele;
3453 napi_status doubleStatus = napi_get_value_double(env, element, &ele);
3454 if (doubleStatus != napi_ok) {
3455 return nullptr;
3456 }
3457 uniformMatrix4x2fv[i] = (float) ele;
3458 }
3459 glUniformMatrix4x2fv(static_cast<GLuint>(location), static_cast<GLsizei>(srcLength),
3460 static_cast<GLboolean>(transpose), reinterpret_cast<GLfloat*>(uniformMatrix4x2fv + srcOffset));
3461 LOGI("WebGL2 uniformMatrix4x2fv array end");
3462 return nullptr;
3463 }
3464 bool isTypedarray = false;
3465 tie(succ, isTypedarray) = NVal(env, array).IsTypeArray();
3466 if (!isTypedarray || !succ) {
3467 return nullptr;
3468 }
3469 void *data = nullptr;
3470 size_t length;
3471 napi_typedarray_type type;
3472 tie(succ, type, data, length) = NVal(env, array).ToTypedArray();
3473 if (!succ) {
3474 return nullptr;
3475 }
3476 if (type == napi_float32_array) {
3477 float *inputFloat = (float *) ((uint8_t*)(data) + srcOffset);
3478 glUniformMatrix4x2fv(static_cast<GLuint>(location), static_cast<GLsizei>(srcLength),
3479 static_cast<GLboolean>(transpose), reinterpret_cast<GLfloat*>(inputFloat));
3480 }
3481 LOGI("WebGL2 uniformMatrix4x2fv typeArray end");
3482 return nullptr;
3483 }
3484
UniformMatrix2x3fv(napi_env env,napi_callback_info info)3485 napi_value WebGL2RenderingContextBase::UniformMatrix2x3fv(napi_env env, napi_callback_info info)
3486 {
3487 NFuncArg funcArg(env, info);
3488
3489 if (!funcArg.InitArgs(NARG_CNT::THREE, NARG_CNT::FIVE)) {
3490 return nullptr;
3491 }
3492
3493 LOGI("WebGL2 uniformMatrix2x3fv start");
3494 bool succ = false;
3495 WebGLUniformLocation *webGLUniformLocation = nullptr;
3496 napi_status locationStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGLUniformLocation);
3497 if (locationStatus != napi_ok) {
3498 return nullptr;
3499 }
3500 int location = webGLUniformLocation->GetUniformLocationId();
3501 LOGI("WebGL2 WebGLRenderContext::uniformMatrix2x3fv location = %{public}u", location);
3502 if (funcArg[NARG_POS::SECOND] == nullptr) {
3503 return nullptr;
3504 }
3505 bool transpose = false;
3506 tie(succ, transpose) = NVal(env, funcArg[NARG_POS::SECOND]).ToBool();
3507 if (!succ) {
3508 return nullptr;
3509 }
3510 LOGI("WebGL2 WebGL2RenderingContextBase::uniformMatrix2x3fv transpose = %{public}u", transpose);
3511
3512 int64_t srcOffset = 0;
3513 if (funcArg[NARG_POS::FOURTH] != nullptr) {
3514 tie(succ, srcOffset) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt64();
3515 if (!succ) {
3516 return nullptr;
3517 }
3518 LOGI("WebGL2 WebGL2RenderingContextBase::uniformMatrix2x3fv srcOffset = %{public}u", srcOffset);
3519 }
3520 int64_t srcLength = 0;
3521 if (funcArg[NARG_POS::FIFTH] != nullptr) {
3522 tie(succ, srcLength) = NVal(env, funcArg[NARG_POS::FIFTH]).ToInt64();
3523 if (!succ) {
3524 return nullptr;
3525 }
3526 LOGI("WebGL2 WebGL2RenderingContextBase::uniformMatrix2x3fv srcLength = %{public}u", srcLength);
3527 }
3528 napi_value array = funcArg[NARG_POS::THIRD];
3529 bool isArray = false;
3530 tie(succ, isArray) = NVal(env, array).IsArray();
3531 if (isArray) {
3532 LOGI("WebGL2 uniformMatrix2x3fv is Array");
3533 uint32_t length;
3534 napi_status lengthStatus = napi_get_array_length(env, array, &length);
3535 if (lengthStatus != napi_ok) {
3536 return nullptr;
3537 }
3538 float uniformMatrix2x3fv[length];
3539 uint32_t i;
3540 for (i = 0; i < length; i++) {
3541 napi_value element;
3542 napi_status eleStatus = napi_get_element(env, array, i, &element);
3543 if (eleStatus != napi_ok) {
3544 return nullptr;
3545 }
3546 double ele;
3547 napi_status doubleStatus = napi_get_value_double(env, element, &ele);
3548 if (doubleStatus != napi_ok) {
3549 return nullptr;
3550 }
3551 uniformMatrix2x3fv[i] = (float) ele;
3552 }
3553 glUniformMatrix2x3fv(static_cast<GLuint>(location), static_cast<GLsizei>(srcLength),
3554 static_cast<GLboolean>(transpose), reinterpret_cast<GLfloat*>(uniformMatrix2x3fv + srcOffset));
3555 LOGI("WebGL2 uniformMatrix2x3fv array end");
3556 return nullptr;
3557 }
3558 bool isTypedarray = false;
3559 tie(succ, isTypedarray) = NVal(env, array).IsTypeArray();
3560 if (!isTypedarray || !succ) {
3561 return nullptr;
3562 }
3563 void *data = nullptr;
3564 size_t length;
3565 napi_typedarray_type type;
3566 tie(succ, type, data, length) = NVal(env, array).ToTypedArray();
3567 if (!succ) {
3568 return nullptr;
3569 }
3570 if (type == napi_float32_array) {
3571 float *inputFloat = (float *) ((uint8_t*)(data) + srcOffset);
3572 glUniformMatrix2x3fv(static_cast<GLuint>(location), static_cast<GLsizei>(srcLength),
3573 static_cast<GLboolean>(transpose), reinterpret_cast<GLfloat*>(inputFloat));
3574 }
3575 LOGI("WebGL2 uniformMatrix2x3fv typeArray end");
3576 return nullptr;
3577 }
3578
UniformMatrix4x3fv(napi_env env,napi_callback_info info)3579 napi_value WebGL2RenderingContextBase::UniformMatrix4x3fv(napi_env env, napi_callback_info info)
3580 {
3581 NFuncArg funcArg(env, info);
3582
3583 if (!funcArg.InitArgs(NARG_CNT::FIVE)) {
3584 return nullptr;
3585 }
3586 LOGI("WebGL2 uniformMatrix4x3fv start");
3587 bool succ = false;
3588 WebGLUniformLocation *webGLUniformLocation = nullptr;
3589 napi_status locationStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGLUniformLocation);
3590 if (locationStatus != napi_ok) {
3591 return nullptr;
3592 }
3593 int location = webGLUniformLocation->GetUniformLocationId();
3594 LOGI("WebGL2 WebGLRenderContext::uniformMatrix4x3fv location = %{public}u", location);
3595 if (funcArg[NARG_POS::SECOND] == nullptr) {
3596 return nullptr;
3597 }
3598 bool transpose = false;
3599 tie(succ, transpose) = NVal(env, funcArg[NARG_POS::SECOND]).ToBool();
3600 if (!succ) {
3601 return nullptr;
3602 }
3603 LOGI("WebGL2 WebGL2RenderingContextBase::uniformMatrix4x3fv transpose = %{public}u", transpose);
3604
3605 int64_t srcOffset = 0;
3606 if (funcArg[NARG_POS::FOURTH] != nullptr) {
3607 tie(succ, srcOffset) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt64();
3608 if (!succ) {
3609 return nullptr;
3610 }
3611 LOGI("WebGL2 WebGL2RenderingContextBase::uniformMatrix4x3fv srcOffset = %{public}u", srcOffset);
3612 }
3613 int64_t srcLength = 0;
3614 if (funcArg[NARG_POS::FIFTH] != nullptr) {
3615 tie(succ, srcLength) = NVal(env, funcArg[NARG_POS::FIFTH]).ToInt64();
3616 if (!succ) {
3617 return nullptr;
3618 }
3619 LOGI("WebGL2 WebGL2RenderingContextBase::uniformMatrix4x3fv srcLength = %{public}u", srcLength);
3620 }
3621 napi_value array = funcArg[NARG_POS::THIRD];
3622 bool isArray = false;
3623 tie(succ, isArray) = NVal(env, array).IsArray();
3624 if (isArray) {
3625 LOGI("WebGL2 uniformMatrix4x3fv is Array");
3626 uint32_t length;
3627 napi_status lengthStatus = napi_get_array_length(env, array, &length);
3628 if (lengthStatus != napi_ok) {
3629 return nullptr;
3630 }
3631 float uniformMatrix4x3fv[length];
3632 uint32_t i;
3633 for (i = 0; i < length; i++) {
3634 napi_value element;
3635 napi_status eleStatus = napi_get_element(env, array, i, &element);
3636 if (eleStatus != napi_ok) {
3637 return nullptr;
3638 }
3639 double ele;
3640 napi_status doubleStatus = napi_get_value_double(env, element, &ele);
3641 if (doubleStatus != napi_ok) {
3642 return nullptr;
3643 }
3644 uniformMatrix4x3fv[i] = (float) ele;
3645 }
3646 glUniformMatrix4x3fv(static_cast<GLuint>(location), static_cast<GLsizei>(srcLength),
3647 static_cast<GLboolean>(transpose), reinterpret_cast<GLfloat*>(uniformMatrix4x3fv + srcOffset));
3648 LOGI("WebGL2 uniformMatrix4x3fv array end");
3649 return nullptr;
3650 }
3651 bool isTypedarray = false;
3652 tie(succ, isTypedarray) = NVal(env, array).IsTypeArray();
3653 if (!isTypedarray || !succ) {
3654 return nullptr;
3655 }
3656 void *data = nullptr;
3657 size_t length;
3658 napi_typedarray_type type;
3659 tie(succ, type, data, length) = NVal(env, array).ToTypedArray();
3660 if (!succ) {
3661 return nullptr;
3662 }
3663 if (type == napi_float32_array) {
3664 float *inputFloat = (float *) ((uint8_t*)(data) + srcOffset);
3665 glUniformMatrix4x3fv(static_cast<GLuint>(location), static_cast<GLsizei>(srcLength),
3666 static_cast<GLboolean>(transpose), reinterpret_cast<GLfloat*>(inputFloat));
3667 }
3668 LOGI("WebGL2 uniformMatrix4x3fv typeArray end");
3669 return nullptr;
3670 }
3671
UniformMatrix2x4fv(napi_env env,napi_callback_info info)3672 napi_value WebGL2RenderingContextBase::UniformMatrix2x4fv(napi_env env, napi_callback_info info)
3673 {
3674 NFuncArg funcArg(env, info);
3675
3676 if (!funcArg.InitArgs(NARG_CNT::FIVE)) {
3677 return nullptr;
3678 }
3679
3680 LOGI("WebGL2 uniformMatrix2x4fv start");
3681 bool succ = false;
3682 WebGLUniformLocation *webGLUniformLocation = nullptr;
3683 napi_status locationStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGLUniformLocation);
3684 if (locationStatus != napi_ok) {
3685 return nullptr;
3686 }
3687 int location = webGLUniformLocation->GetUniformLocationId();
3688 LOGI("WebGL2 WebGLRenderContext::uniformMatrix2x4fv location = %{public}u", location);
3689 if (funcArg[NARG_POS::SECOND] == nullptr) {
3690 return nullptr;
3691 }
3692 bool transpose = false;
3693 tie(succ, transpose) = NVal(env, funcArg[NARG_POS::SECOND]).ToBool();
3694 if (!succ) {
3695 return nullptr;
3696 }
3697 LOGI("WebGL2 WebGL2RenderingContextBase::uniformMatrix2x4fv transpose = %{public}u", transpose);
3698
3699 int64_t srcOffset = 0;
3700 if (funcArg[NARG_POS::FOURTH] != nullptr) {
3701 tie(succ, srcOffset) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt64();
3702 if (!succ) {
3703 return nullptr;
3704 }
3705 LOGI("WebGL2 WebGL2RenderingContextBase::uniformMatrix2x4fv srcOffset = %{public}u", srcOffset);
3706 }
3707 int64_t srcLength = 0;
3708 if (funcArg[NARG_POS::FIFTH] != nullptr) {
3709 tie(succ, srcLength) = NVal(env, funcArg[NARG_POS::FIFTH]).ToInt64();
3710 if (!succ) {
3711 return nullptr;
3712 }
3713 LOGI("WebGL2 WebGL2RenderingContextBase::uniformMatrix2x4fv srcLength = %{public}u", srcLength);
3714 }
3715 napi_value array = funcArg[NARG_POS::THIRD];
3716 bool isArray = false;
3717 tie(succ, isArray) = NVal(env, array).IsArray();
3718 if (isArray) {
3719 LOGI("WebGL2 uniformMatrix2x4fv is Array");
3720 uint32_t length;
3721 napi_status lengthStatus = napi_get_array_length(env, array, &length);
3722 if (lengthStatus != napi_ok) {
3723 return nullptr;
3724 }
3725 float uniformMatrix2x4fv[length];
3726 uint32_t i;
3727 for (i = 0; i < length; i++) {
3728 napi_value element;
3729 napi_status eleStatus = napi_get_element(env, array, i, &element);
3730 if (eleStatus != napi_ok) {
3731 return nullptr;
3732 }
3733 double ele;
3734 napi_status doubleStatus = napi_get_value_double(env, element, &ele);
3735 if (doubleStatus != napi_ok) {
3736 return nullptr;
3737 }
3738 uniformMatrix2x4fv[i] = (float) ele;
3739 }
3740 glUniformMatrix2x4fv(static_cast<GLuint>(location), static_cast<GLsizei>(srcLength),
3741 static_cast<GLboolean>(transpose), reinterpret_cast<GLfloat*>(uniformMatrix2x4fv + srcOffset));
3742 LOGI("WebGL2 uniformMatrix2x4fv array end");
3743 return nullptr;
3744 }
3745 bool isTypedarray = false;
3746 tie(succ, isTypedarray) = NVal(env, array).IsTypeArray();
3747 if (!isTypedarray || !succ) {
3748 return nullptr;
3749 }
3750 void *data = nullptr;
3751 size_t length;
3752 napi_typedarray_type type;
3753 tie(succ, type, data, length) = NVal(env, array).ToTypedArray();
3754 if (!succ) {
3755 return nullptr;
3756 }
3757 if (type == napi_float32_array) {
3758 float *inputFloat = (float *) ((uint8_t*)(data) + srcOffset);
3759 glUniformMatrix2x4fv(static_cast<GLuint>(location), static_cast<GLsizei>(srcLength),
3760 static_cast<GLboolean>(transpose), reinterpret_cast<GLfloat*>(inputFloat));
3761 }
3762 LOGI("WebGL2 uniformMatrix2x4fv typeArray end");
3763 return nullptr;
3764 }
3765
UniformMatrix3x4fv(napi_env env,napi_callback_info info)3766 napi_value WebGL2RenderingContextBase::UniformMatrix3x4fv(napi_env env, napi_callback_info info)
3767 {
3768 NFuncArg funcArg(env, info);
3769
3770 if (!funcArg.InitArgs(NARG_CNT::FIVE)) {
3771 return nullptr;
3772 }
3773 LOGI("WebGL2 uniformMatrix3x4fv start");
3774 bool succ = false;
3775 WebGLUniformLocation *webGLUniformLocation = nullptr;
3776 napi_status locationStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGLUniformLocation);
3777 if (locationStatus != napi_ok) {
3778 return nullptr;
3779 }
3780 int location = webGLUniformLocation->GetUniformLocationId();
3781 LOGI("WebGL2 WebGLRenderContext::uniformMatrix3x4fv location = %{public}u", location);
3782 if (funcArg[NARG_POS::SECOND] == nullptr) {
3783 return nullptr;
3784 }
3785 bool transpose = false;
3786 tie(succ, transpose) = NVal(env, funcArg[NARG_POS::SECOND]).ToBool();
3787 if (!succ) {
3788 return nullptr;
3789 }
3790 LOGI("WebGL2 WebGL2RenderingContextBase::uniformMatrix3x4fv transpose = %{public}u", transpose);
3791
3792 int64_t srcOffset = 0;
3793 if (funcArg[NARG_POS::FOURTH] != nullptr) {
3794 tie(succ, srcOffset) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt64();
3795 if (!succ) {
3796 return nullptr;
3797 }
3798 LOGI("WebGL2 WebGL2RenderingContextBase::uniformMatrix3x4fv srcOffset = %{public}u", srcOffset);
3799 }
3800 int64_t srcLength = 0;
3801 if (funcArg[NARG_POS::FIFTH] != nullptr) {
3802 tie(succ, srcLength) = NVal(env, funcArg[NARG_POS::FIFTH]).ToInt64();
3803 if (!succ) {
3804 return nullptr;
3805 }
3806 LOGI("WebGL2 WebGL2RenderingContextBase::uniformMatrix3x4fv srcLength = %{public}u", srcLength);
3807 }
3808 napi_value array = funcArg[NARG_POS::THIRD];
3809 bool isArray = false;
3810 tie(succ, isArray) = NVal(env, array).IsArray();
3811 if (isArray) {
3812 LOGI("WebGL2 uniformMatrix3x4fv is Array");
3813 uint32_t length;
3814 napi_status lengthStatus = napi_get_array_length(env, array, &length);
3815 if (lengthStatus != napi_ok) {
3816 return nullptr;
3817 }
3818 float uniformMatrix3x4fv[length];
3819 uint32_t i;
3820 for (i = 0; i < length; i++) {
3821 napi_value element;
3822 napi_status eleStatus = napi_get_element(env, array, i, &element);
3823 if (eleStatus != napi_ok) {
3824 return nullptr;
3825 }
3826 double ele;
3827 napi_status doubleStatus = napi_get_value_double(env, element, &ele);
3828 if (doubleStatus != napi_ok) {
3829 return nullptr;
3830 }
3831 uniformMatrix3x4fv[i] = (float) ele;
3832 }
3833 glUniformMatrix3x4fv(static_cast<GLuint>(location), static_cast<GLsizei>(srcLength),
3834 static_cast<GLboolean>(transpose), reinterpret_cast<GLfloat*>(uniformMatrix3x4fv + srcOffset));
3835 LOGI("WebGL2 uniformMatrix3x4fv array end");
3836 return nullptr;
3837 }
3838 bool isTypedarray = false;
3839 tie(succ, isTypedarray) = NVal(env, array).IsTypeArray();
3840 if (!isTypedarray || !succ) {
3841 return nullptr;
3842 }
3843 void *data = nullptr;
3844 size_t length;
3845 napi_typedarray_type type;
3846 tie(succ, type, data, length) = NVal(env, array).ToTypedArray();
3847 if (!succ) {
3848 return nullptr;
3849 }
3850 if (type == napi_float32_array) {
3851 float *inputFloat = (float *) ((uint8_t*)(data) + srcOffset);
3852 glUniformMatrix3x4fv(static_cast<GLuint>(location), static_cast<GLsizei>(srcLength),
3853 static_cast<GLboolean>(transpose), reinterpret_cast<GLfloat*>(inputFloat));
3854 }
3855 LOGI("WebGL2 uniformMatrix3x4fv typeArray end");
3856 return nullptr;
3857 }
3858
VertexAttribI4iv(napi_env env,napi_callback_info info)3859 napi_value WebGL2RenderingContextBase::VertexAttribI4iv(napi_env env, napi_callback_info info)
3860 {
3861 NFuncArg funcArg(env, info);
3862
3863 if (!funcArg.InitArgs(NARG_CNT::TWO)) {
3864 return nullptr;
3865 }
3866 LOGI("WebGL2 vertexAttribI4iv start");
3867 bool succ = false;
3868 int64_t index;
3869 tie(succ, index) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt64();
3870 if (!succ) {
3871 return nullptr;
3872 }
3873 LOGI("WebGL2 WebGL2RenderingContextBase::vertexAttribI4iv index = %{public}u", index);
3874 napi_value array = funcArg[NARG_POS::SECOND];
3875 bool isArray = false;
3876 tie(succ, isArray) = NVal(env, array).IsArray();
3877 if (isArray) {
3878 LOGI("WebGL2 vertexAttribI4iv is Array");
3879 uint32_t length;
3880 napi_status lengthStatus = napi_get_array_length(env, array, &length);
3881 if (lengthStatus != napi_ok) {
3882 return nullptr;
3883 }
3884 float vertexAttribI4iv[length];
3885 uint32_t i;
3886 for (i = 0; i < length; i++) {
3887 napi_value element;
3888 napi_status eleStatus = napi_get_element(env, array, i, &element);
3889 if (eleStatus != napi_ok) {
3890 return nullptr;
3891 }
3892 double ele;
3893 napi_status doubleStatus = napi_get_value_double(env, element, &ele);
3894 if (doubleStatus != napi_ok) {
3895 return nullptr;
3896 }
3897 vertexAttribI4iv[i] = (float) ele;
3898 }
3899 glVertexAttribI4iv(static_cast<GLuint>(index), reinterpret_cast<GLint *>(vertexAttribI4iv));
3900 LOGI("WebGL2 vertexAttribI4iv array end");
3901 return nullptr;
3902 }
3903 bool isTypedarray = false;
3904 tie(succ, isTypedarray) = NVal(env, array).IsTypeArray();
3905 if (!isTypedarray || !succ) {
3906 return nullptr;
3907 }
3908 void *data = nullptr;
3909 size_t length;
3910 napi_typedarray_type type;
3911 tie(succ, type, data, length) = NVal(env, array).ToTypedArray();
3912 if (!succ) {
3913 return nullptr;
3914 }
3915 if (type == napi_float32_array) {
3916 float *inputFloat = (float *) ((uint8_t*)(data));
3917 glVertexAttribI4iv(static_cast<GLuint>(index), reinterpret_cast<GLint *>(inputFloat));
3918 }
3919 LOGI("WebGL2 vertexAttribI4iv typeArray end");
3920 return nullptr;
3921 }
3922
VertexAttribI4uiv(napi_env env,napi_callback_info info)3923 napi_value WebGL2RenderingContextBase::VertexAttribI4uiv(napi_env env, napi_callback_info info)
3924 {
3925 NFuncArg funcArg(env, info);
3926
3927 if (!funcArg.InitArgs(NARG_CNT::TWO)) {
3928 return nullptr;
3929 }
3930
3931 LOGI("WebGL2 vertexAttribI4uiv start");
3932 bool succ = false;
3933 int64_t index;
3934 tie(succ, index) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt64();
3935 if (!succ) {
3936 return nullptr;
3937 }
3938 LOGI("WebGL2 WebGL2RenderingContextBase::vertexAttribI4uiv index = %{public}u", index);
3939 napi_value array = funcArg[NARG_POS::SECOND];
3940 bool isArray = false;
3941 tie(succ, isArray) = NVal(env, array).IsArray();
3942 if (isArray) {
3943 LOGI("WebGL2 vertexAttribI4uiv is Array");
3944 uint32_t length;
3945 napi_status lengthStatus = napi_get_array_length(env, array, &length);
3946 if (lengthStatus != napi_ok) {
3947 return nullptr;
3948 }
3949 float vertexAttribI4uiv[length];
3950 uint32_t i;
3951 for (i = 0; i < length; i++) {
3952 napi_value element;
3953 napi_status eleStatus = napi_get_element(env, array, i, &element);
3954 if (eleStatus != napi_ok) {
3955 return nullptr;
3956 }
3957 double ele;
3958 napi_status doubleStatus = napi_get_value_double(env, element, &ele);
3959 if (doubleStatus != napi_ok) {
3960 return nullptr;
3961 }
3962 vertexAttribI4uiv[i] = (float) ele;
3963 }
3964 glVertexAttribI4uiv(static_cast<GLuint>(index), reinterpret_cast<const GLuint *>(vertexAttribI4uiv));
3965 LOGI("WebGL2 vertexAttribI4uiv array end");
3966 return nullptr;
3967 }
3968 bool isTypedarray = false;
3969 tie(succ, isTypedarray) = NVal(env, array).IsTypeArray();
3970 if (!isTypedarray || !succ) {
3971 return nullptr;
3972 }
3973 void *data = nullptr;
3974 size_t length;
3975 napi_typedarray_type type;
3976 tie(succ, type, data, length) = NVal(env, array).ToTypedArray();
3977 if (!succ) {
3978 return nullptr;
3979 }
3980 if (type == napi_float32_array) {
3981 int *inputFloat = (int *) ((uint8_t*)(data));
3982 glVertexAttribI4uiv(static_cast<GLuint>(index), reinterpret_cast<const GLuint *>(inputFloat));
3983 }
3984 LOGI("WebGL2 vertexAttribI4uiv typeArray end");
3985 return nullptr;
3986 }
3987
InvalidateFramebuffer(napi_env env,napi_callback_info info)3988 napi_value WebGL2RenderingContextBase::InvalidateFramebuffer(napi_env env, napi_callback_info info)
3989 {
3990 NFuncArg funcArg(env, info);
3991
3992 if (!funcArg.InitArgs(NARG_CNT::TWO)) {
3993 return nullptr;
3994 }
3995 bool succ = false;
3996 LOGI("WebGL2 invalidateFramebuffer start");
3997 int64_t target;
3998 tie(succ, target) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt64();
3999 if (!succ) {
4000 return nullptr;
4001 }
4002 LOGI("WebGL2 WebGL2RenderingContextBase::invalidateFramebuffer target = %{public}u", target);
4003 napi_value uniformarray = funcArg[NARG_POS::SECOND];
4004 bool isUniformArray = false;
4005 tie(succ, isUniformArray) = NVal(env, uniformarray).IsArray();
4006 if (isUniformArray) {
4007 int64_t* a = nullptr;
4008 LOGI("WebGL2 invalidateFramebuffer is isUniformArray");
4009 uint32_t numAttachments;
4010 napi_status countStatus = napi_get_array_length(env, uniformarray, &numAttachments);
4011 if (countStatus != napi_ok) {
4012 return nullptr;
4013 }
4014 LOGI("WebGL2 WebGL2RenderingContextBase::invalidateFramebuffer numAttachments = %{public}u", numAttachments);
4015 int64_t attachments[numAttachments];
4016 uint32_t i;
4017 for (i = 0; i < numAttachments; i++) {
4018 napi_value element;
4019 napi_status eleStatus = napi_get_element(env, uniformarray, i, &element);
4020 if (eleStatus != napi_ok) {
4021 return nullptr;
4022 }
4023 int64_t ele;
4024 napi_status doubleStatus = napi_get_value_int64(env, element, &ele);
4025 if (doubleStatus != napi_ok) {
4026 return nullptr;
4027 }
4028 LOGI("WebGL2 WebGL2RenderingContextBase::invalidateFramebuffer ele = %{public}u", ele);
4029 attachments[i] = ele;
4030 }
4031 a = attachments;
4032 glInvalidateFramebuffer(static_cast<GLenum>(target),
4033 static_cast<GLsizei>(numAttachments), reinterpret_cast<GLenum*>(attachments));
4034 LOGI("WebGL2 invalidateFramebuffer invalidateFramebuffer end");
4035 return nullptr;
4036 }
4037 LOGI("WebGL2 invalidateFramebuffer end");
4038 return nullptr;
4039 }
4040
InvalidateSubFramebuffer(napi_env env,napi_callback_info info)4041 napi_value WebGL2RenderingContextBase::InvalidateSubFramebuffer(napi_env env, napi_callback_info info)
4042 {
4043 NFuncArg funcArg(env, info);
4044 if (!funcArg.InitArgs(NARG_CNT::SIX)) {
4045 return nullptr;
4046 }
4047 bool succ = false;
4048 LOGI("WebGL2 invalidateSubFramebuffer start");
4049 int64_t target;
4050 tie(succ, target) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt64();
4051 if (!succ) {
4052 return nullptr;
4053 }
4054 LOGI("WebGL2 WebGL2RenderingContextBase::invalidateSubFramebuffer target = %{public}u", target);
4055 napi_value uniformarray = funcArg[NARG_POS::SECOND];
4056 uint32_t numAttachments;
4057 void *attachments;
4058 bool isUniformArray = false;
4059 tie(succ, isUniformArray) = NVal(env, uniformarray).IsArray();
4060 if (isUniformArray) {
4061 LOGI("WebGL2 invalidateSubFramebuffer is isUniformArray");
4062 napi_status countStatus = napi_get_array_length(env, uniformarray, &numAttachments);
4063 if (countStatus != napi_ok) {
4064 return nullptr;
4065 }
4066 LOGI("WebGL2 WebGL2RenderingContextBase::invalidateSubFramebuffer numAttachments = %{public}u", numAttachments);
4067 uint64_t attachments1[numAttachments];
4068 uint32_t i;
4069 for (i = 0; i < numAttachments; i++) {
4070 napi_value element;
4071 napi_status eleStatus = napi_get_element(env, uniformarray, i, &element);
4072 if (eleStatus != napi_ok) {
4073 return nullptr;
4074 }
4075 int64_t ele;
4076 napi_status doubleStatus = napi_get_value_int64(env, element, &ele);
4077 if (doubleStatus != napi_ok) {
4078 return nullptr;
4079 }
4080 LOGI("WebGL2 WebGL2RenderingContextBase::invalidateSubFramebuffer ele = %{public}u", ele);
4081 attachments1[i] = static_cast<uint64_t>(ele);
4082 }
4083 attachments = attachments1;
4084 } else {
4085 return nullptr;
4086 }
4087
4088 int64_t x;
4089 tie(succ, x) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt64();
4090 if (!succ) {
4091 return nullptr;
4092 }
4093 LOGI("WebGL2 WebGL2RenderingContextBase::invalidateSubFramebuffer x = %{public}u", x);
4094 int64_t y;
4095 tie(succ, y) = NVal(env, funcArg[NARG_POS::FOURTH]).ToInt64();
4096 if (!succ) {
4097 return nullptr;
4098 }
4099 LOGI("WebGL2 WebGL2RenderingContextBase::invalidateSubFramebuffer y = %{public}u", y);
4100 int64_t width;
4101 tie(succ, width) = NVal(env, funcArg[NARG_POS::FIFTH]).ToInt64();
4102 if (!succ) {
4103 return nullptr;
4104 }
4105 LOGI("WebGL2 WebGL2RenderingContextBase::invalidateSubFramebuffer width = %{public}u", width);
4106 int64_t height;
4107 tie(succ, height) = NVal(env, funcArg[NARG_POS::SIXTH]).ToInt64();
4108 if (!succ) {
4109 return nullptr;
4110 }
4111 LOGI("WebGL2 WebGL2RenderingContextBase::invalidateSubFramebuffer height = %{public}u", height);
4112 glInvalidateSubFramebuffer(static_cast<GLenum>(target), static_cast<GLsizei>(numAttachments),
4113 reinterpret_cast<GLenum*>(attachments), static_cast<GLint>(x),
4114 static_cast<GLint>(y), static_cast<GLsizei>(width), static_cast<GLsizei>(height));
4115 LOGI("WebGL2 invalidateSubFramebuffer end");
4116 return nullptr;
4117 }
4118
GetInternalformatParameter(napi_env env,napi_callback_info info)4119 napi_value WebGL2RenderingContextBase::GetInternalformatParameter(napi_env env, napi_callback_info info)
4120 {
4121 NFuncArg funcArg(env, info);
4122 if (!funcArg.InitArgs(NARG_CNT::THREE)) {
4123 return nullptr;
4124 }
4125 bool succ = false;
4126 LOGI("WebGL2 getInternalformatParameter start");
4127 int64_t target;
4128 tie(succ, target) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt64();
4129 if (!succ) {
4130 return nullptr;
4131 }
4132 LOGI("WebGL2 WebGL2RenderingContextBase::getInternalformatParameter target = %{public}u", target);
4133 int64_t internalformat;
4134 tie(succ, internalformat) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt64();
4135 if (!succ) {
4136 return nullptr;
4137 }
4138 LOGI("WebGL2 WebGL2RenderingContextBase::getInternalformatParameter internalformat = %{public}u", internalformat);
4139 int64_t pname;
4140 tie(succ, pname) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt64();
4141 if (!succ) {
4142 return nullptr;
4143 }
4144 LOGI("WebGL2 WebGL2RenderingContextBase::getInternalformatParameter pname = %{public}u", pname);
4145
4146 napi_value retures = nullptr;
4147 static GLint* params = nullptr;
4148 if (pname == GL_SAMPLES) {
4149 LOGI("WebGL2 WebGL2RenderingContextBase::getInternalformatParameter GL_SAMPLES start");
4150 GLint length = -1;
4151 glGetInternalformativ(static_cast<GLenum>(target), static_cast<GLenum>(internalformat), GL_NUM_SAMPLE_COUNTS,
4152 1, &length);
4153 LOGI("WebGL2 WebGL2RenderingContextBase::getInternalformatParameter length = %{public}u", length);
4154 if (length <= 0) {
4155 return nullptr;
4156 }
4157 int a = static_cast<int>(length);
4158 params = new GLint[a];
4159 glGetInternalformativ(static_cast<GLenum>(target), static_cast<GLenum>(internalformat),
4160 static_cast<GLenum>(pname), static_cast<GLsizei>(length), static_cast<GLint *>(params));
4161 LOGI("WebGL2 WebGL2RenderingContextBase::getInternalformatParameter params = %{public}u", params);
4162 int res[length];
4163 for (int i = 0; i < length; i++) {
4164 res[i] = static_cast<int>(params[i]);
4165 }
4166 napi_value outputBuffer = nullptr;
4167 napi_create_external_arraybuffer(env, res, sizeof(res),
4168 [](napi_env env, void *finalize_data, void *finalize_hint) { },
4169 NULL, &outputBuffer);
4170 napi_create_typedarray(env, napi_int32_array, sizeof(res) / sizeof(int), outputBuffer, 0, &retures);
4171 delete []params;
4172 }
4173 LOGI("WebGL2 getInternalformatParameter end");
4174 return retures;
4175 }
4176
TransformFeedbackVaryings(napi_env env,napi_callback_info info)4177 napi_value WebGL2RenderingContextBase::TransformFeedbackVaryings(napi_env env, napi_callback_info info)
4178 {
4179 NFuncArg funcArg(env, info);
4180 if (!funcArg.InitArgs(NARG_CNT::THREE)) {
4181 return nullptr;
4182 }
4183 bool succ = false;
4184 LOGI("WebGL2 TransformFeedbackVaryings start");
4185 WebGLProgram *webGlProgram = nullptr;
4186 napi_status programStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGlProgram);
4187 if (programStatus != napi_ok) {
4188 return nullptr;
4189 }
4190 int programId = webGlProgram->GetProgramId();
4191 LOGI("WebGL2 WebGL2RenderingContextBase::transformFeedbackVaryings programId = %{public}u", programId);
4192
4193 napi_value transformFeedbackarray = funcArg[NARG_POS::SECOND];
4194 uint32_t count;
4195 bool istransformFeedbackArray = false;
4196 tie(succ, istransformFeedbackArray) = NVal(env, transformFeedbackarray).IsArray();
4197 if (istransformFeedbackArray) {
4198 LOGI("WebGL2 transformFeedbackVaryings is isUniformArray");
4199 napi_status countStatus = napi_get_array_length(env, transformFeedbackarray, &count);
4200 if (countStatus != napi_ok) {
4201 return nullptr;
4202 }
4203 LOGI("WebGL2 WebGL2RenderingContextBase::transformFeedbackVaryings count = %{public}u", count);
4204 char *varyings[count];
4205 uint32_t i;
4206 for (i = 0; i < count; i++) {
4207 napi_value element;
4208 napi_status eleStatus = napi_get_element(env, transformFeedbackarray, i, &element);
4209 LOGI("WebGL2 WebGL2RenderingContextBase::transformFeedbackVaryings element = %{public}u", element);
4210 if (eleStatus != napi_ok) {
4211 return nullptr;
4212 }
4213 napi_value result;
4214 napi_status rsuStatus = napi_coerce_to_string(env, element, &result);
4215 if (rsuStatus != napi_ok) {
4216 return nullptr;
4217 }
4218 unique_ptr<char[]> name;
4219 tie(succ, name, ignore) = NVal(env, result).ToUTF8String();
4220 if (!succ) {
4221 return nullptr;
4222 }
4223 LOGI("WebGL2 WebGL2RenderingContextBase::transformFeedbackVaryings name = %{public}s", name.get());
4224 varyings[i] = name.get();
4225 }
4226 int64_t bufferMode;
4227 tie(succ, bufferMode) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt64();
4228 if (!succ) {
4229 return nullptr;
4230 }
4231 LOGI("WebGL2 WebGL2RenderingContextBase::transformFeedbackVaryings bufferMode = %{public}u", bufferMode);
4232 glTransformFeedbackVaryings(static_cast<GLuint>(programId), static_cast<GLsizei>(count),
4233 varyings, static_cast<GLenum>(bufferMode));
4234 LOGI("WebGL2 transformFeedbackVaryings end");
4235 }
4236 return nullptr;
4237 }
4238
GetUniformIndices(napi_env env,napi_callback_info info)4239 napi_value WebGL2RenderingContextBase::GetUniformIndices(napi_env env, napi_callback_info info)
4240 {
4241 NFuncArg funcArg(env, info);
4242 if (!funcArg.InitArgs(NARG_CNT::TWO)) {
4243 return nullptr;
4244 }
4245 bool succ = false;
4246 LOGI("WebGL2 getUniformIndices start");
4247 WebGLProgram *webGlProgram = nullptr;
4248 napi_status programStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGlProgram);
4249 if (programStatus != napi_ok) {
4250 return nullptr;
4251 }
4252 int programId = webGlProgram->GetProgramId();
4253 LOGI("WebGL2 WebGL2RenderingContextBase::getUniformIndices programId = %{public}u", programId);
4254 napi_value transformFeedbackarray = funcArg[NARG_POS::SECOND];
4255 uint32_t uniformCount;
4256 string* uniformNames;
4257 string* transformFeedback = nullptr;
4258 bool istransformFeedbackArray = false;
4259 tie(succ, istransformFeedbackArray) = NVal(env, transformFeedbackarray).IsArray();
4260 if (istransformFeedbackArray) {
4261 LOGI("WebGL2 transformFeedbackVaryings is isUniformArray");
4262 napi_status countStatus = napi_get_array_length(env, transformFeedbackarray, &uniformCount);
4263 if (countStatus != napi_ok) {
4264 return nullptr;
4265 }
4266 LOGI("WebGL2 WebGLRenderingContextOverloads::getUniformIndices count = %{public}u", uniformCount);
4267 transformFeedback = new string[uniformCount];
4268 uint32_t i;
4269 for (i = 0; i < uniformCount; i++) {
4270 napi_value element;
4271 napi_status eleStatus = napi_get_element(env, transformFeedbackarray, i, &element);
4272 if (eleStatus != napi_ok) {
4273 delete []transformFeedback;
4274 return nullptr;
4275 }
4276 napi_value result;
4277 napi_status rsuStatus = napi_coerce_to_string(env, element, &result);
4278 if (rsuStatus != napi_ok) {
4279 delete []transformFeedback;
4280 return nullptr;
4281 }
4282 unique_ptr<char[]> name;
4283 tie(succ, name, ignore) = NVal(env, result).ToUTF8String();
4284 if (!succ) {
4285 delete []transformFeedback;
4286 return nullptr;
4287 }
4288 string str(name.get());
4289 LOGI("WebGL2 WebGLRenderingContextOverloads::getUniformIndices str = %{public}s", name.get());
4290 transformFeedback[i] = str;
4291 }
4292 uniformNames = transformFeedback;
4293 } else {
4294 return nullptr;
4295 }
4296 const char** uniformNames1 = (const char**)uniformNames;
4297 LOGI("WebGL2 WebGL2RenderingContextBase::getUniformIndices uniformNames = %{public}u", uniformNames);
4298 LOGI("WebGL2 WebGL2RenderingContextBase::getUniformIndices uniformCount = %{public}u", uniformCount);
4299 GLuint* uniformIndices = new GLuint[uniformCount];
4300 glGetUniformIndices(static_cast<GLuint>(programId), static_cast<GLsizei>(uniformCount),
4301 static_cast<const GLchar **>(uniformNames1), static_cast<GLuint *>(uniformIndices));
4302 LOGI("WebGL2 WebGL2RenderingContextBase::getUniformIndices uniformIndices = %{public}d", uniformIndices);
4303 napi_value ret;
4304 napi_create_array(env, &ret);
4305 for (uint32_t i = 0; i < uniformCount; i++) {
4306 uint32_t a = static_cast<GLuint>(uniformIndices[i]);
4307 LOGI("WebGL2 WebGL2RenderingContextBase::getUniformIndices a = %{public}d", a);
4308 napi_value result;
4309 napi_status status = napi_create_uint32(env, a, &result);
4310 if (status != napi_ok) {
4311 delete []transformFeedback;
4312 delete []uniformIndices;
4313 return nullptr;
4314 }
4315 napi_set_element(env, ret, i, result);
4316 }
4317 LOGI("WebGL2 getUniformIndices end");
4318 delete []transformFeedback;
4319 delete []uniformIndices;
4320 return ret;
4321 }
4322
GetActiveUniforms(napi_env env,napi_callback_info info)4323 napi_value WebGL2RenderingContextBase::GetActiveUniforms(napi_env env, napi_callback_info info)
4324 {
4325 NFuncArg funcArg(env, info);
4326 if (!funcArg.InitArgs(NARG_CNT::THREE)) {
4327 return nullptr;
4328 }
4329 bool succ = false;
4330 LOGI("WebGL2 getActiveUniforms start");
4331 WebGLProgram *webGlProgram = nullptr;
4332 napi_status programStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **) &webGlProgram);
4333 if (programStatus != napi_ok) {
4334 return nullptr;
4335 }
4336 int programId = webGlProgram->GetProgramId();
4337 LOGI("WebGL2 WebGL2RenderingContextBase::getActiveUniforms programId = %{public}u", programId);
4338 napi_value activeUniforms = funcArg[NARG_POS::SECOND];
4339 uint32_t uniformCount;
4340 void *uniformIndices;
4341 bool istransformFeedbackArray = false;
4342 int* transformFeedback = nullptr;
4343 tie(succ, istransformFeedbackArray) = NVal(env, activeUniforms).IsArray();
4344 if (istransformFeedbackArray) {
4345 LOGI("WebGL2 getActiveUniforms is isUniformArray");
4346 napi_status countStatus = napi_get_array_length(env, activeUniforms, &uniformCount);
4347 if (countStatus != napi_ok) {
4348 return nullptr;
4349 }
4350 LOGI("WebGL2 WebGL2RenderingContextBase::getActiveUniforms count = %{public}u", uniformCount);
4351 if (uniformCount == 0) {
4352 return nullptr;
4353 }
4354 transformFeedback = new int[uniformCount];
4355 uint32_t i;
4356 for (i = 0; i < uniformCount; i++) {
4357 napi_value element;
4358 napi_status eleStatus = napi_get_element(env, activeUniforms, i, &element);
4359 if (eleStatus != napi_ok) {
4360 delete []transformFeedback;
4361 return nullptr;
4362 }
4363 napi_value result;
4364 napi_status rsuStatus = napi_coerce_to_number(env, element, &result);
4365 if (rsuStatus != napi_ok) {
4366 delete []transformFeedback;
4367 return nullptr;
4368 }
4369 int64_t ele;
4370 napi_status doubleStatus = napi_get_value_int64(env, result, &ele);
4371 if (doubleStatus != napi_ok) {
4372 delete []transformFeedback;
4373 return nullptr;
4374 }
4375 transformFeedback[i] = ele;
4376 }
4377 uniformIndices = transformFeedback;
4378 } else {
4379 return nullptr;
4380 }
4381 LOGI("WebGL2 WebGL2RenderingContextBase::getActiveUniforms uniformCount = %{public}u", uniformCount);
4382 LOGI("WebGL2 WebGL2RenderingContextBase::getActiveUniforms uniformIndices = %{public}u", uniformIndices);
4383 int64_t pname;
4384 tie(succ, pname) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt64();
4385 if (!succ) {
4386 delete []transformFeedback;
4387 return nullptr;
4388 }
4389 LOGI("WebGL2 WebGL2RenderingContextBase::getActiveUniforms pname = %{public}u", pname);
4390 napi_value res = nullptr;
4391 napi_create_array(env, &res);
4392 if (pname == GL_UNIFORM_TYPE) {
4393 LOGI("WebGL2 getActiveUniforms GL_UNIFORM_TYPE start");
4394 auto params = new unsigned int[uniformCount];
4395 glGetActiveUniformsiv(static_cast<GLuint>(programId), static_cast<GLsizei>(uniformCount),
4396 static_cast<GLuint *>(uniformIndices), static_cast<GLenum>(pname),
4397 reinterpret_cast<GLint *>(params));
4398 LOGI("WebGL2 WebGL2RenderingContextBase::getActiveUniforms params = %{public}u", params);
4399 for (uint32_t i = 0; i < uniformCount; i++) {
4400 int64_t a = ((int64_t*)params)[i];
4401 napi_value result;
4402 napi_status status = napi_create_int64(env, a, &result);
4403 if (status != napi_ok) {
4404 delete []transformFeedback;
4405 delete []params;
4406 return nullptr;
4407 }
4408 napi_set_element(env, res, i, result);
4409 }
4410 delete []params;
4411 } else if (pname == GL_UNIFORM_SIZE) {
4412 LOGI("WebGL2 getActiveUniforms GL_UNIFORM_SIZE start");
4413 auto params = new unsigned int[uniformCount];
4414 glGetActiveUniformsiv(static_cast<GLuint>(programId), static_cast<GLsizei>(uniformCount),
4415 static_cast<GLuint *>(uniformIndices), static_cast<GLenum>(pname),
4416 reinterpret_cast<GLint *>(params));
4417 LOGI("WebGL2 WebGL2RenderingContextBase::getActiveUniforms params = %{public}u", params);
4418 for (uint32_t i = 0; i < uniformCount; i++) {
4419 uint32_t a = ((uint32_t*)params)[i];
4420 LOGI("WebGL2 WebGL2RenderingContextBase::getActiveUniforms a = %{public}u", a);
4421 napi_value result;
4422 napi_status status = napi_create_uint32(env, a, &result);
4423 if (status != napi_ok) {
4424 delete []transformFeedback;
4425 delete []params;
4426 return nullptr;
4427 }
4428 napi_set_element(env, res, i, result);
4429 }
4430 delete []params;
4431 } else if (pname == GL_UNIFORM_BLOCK_INDEX || pname == GL_UNIFORM_OFFSET || pname == GL_UNIFORM_ARRAY_STRIDE
4432 || pname == GL_UNIFORM_MATRIX_STRIDE) {
4433 LOGI("WebGL2 getActiveUniforms GL_UNIFORM_BLOCK_INDEX start");
4434 auto params = new int[uniformCount];
4435 glGetActiveUniformsiv(static_cast<GLuint>(programId), static_cast<GLsizei>(uniformCount),
4436 static_cast<GLuint *>(uniformIndices), static_cast<GLenum>(pname),
4437 reinterpret_cast<GLint *>(params));
4438 LOGI("WebGL2 WebGL2RenderingContextBase::getActiveUniforms params = %{public}u", params);
4439 for (uint32_t i = 0; i < uniformCount; i++) {
4440 int32_t a = ((int32_t*)params)[i];
4441 napi_value result;
4442 napi_status status = napi_create_int32(env, a, &result);
4443 if (status != napi_ok) {
4444 delete []transformFeedback;
4445 delete []params;
4446 return nullptr;
4447 }
4448 napi_set_element(env, res, i, result);
4449 }
4450 delete []params;
4451 } else if (pname == GL_UNIFORM_IS_ROW_MAJOR) {
4452 LOGI("WebGL2 getActiveUniforms GL_UNIFORM_IS_ROW_MAJOR start");
4453 auto params = new unsigned int[uniformCount];
4454 glGetActiveUniformsiv(static_cast<GLuint>(programId), static_cast<GLsizei>(uniformCount),
4455 static_cast<GLuint *>(uniformIndices), static_cast<GLenum>(pname),
4456 reinterpret_cast<GLint *>(params));
4457 LOGI("WebGL2 WebGL2RenderingContextBase::getActiveUniforms params = %{public}u", params);
4458 for (uint32_t i = 0; i < uniformCount; i++) {
4459 bool a = ((bool*)params)[i];
4460 napi_value result = nullptr;
4461 napi_status status = napi_get_boolean(env, a, &result);
4462 if (status != napi_ok) {
4463 delete []transformFeedback;
4464 delete []params;
4465 return nullptr;
4466 }
4467 napi_set_element(env, res, i, result);
4468 }
4469 delete []params;
4470 }
4471 LOGI("WebGL2 getActiveUniforms end");
4472 delete []transformFeedback;
4473 return res;
4474 }
4475
GetActiveUniformBlockParameter(napi_env env,napi_callback_info info)4476 napi_value WebGL2RenderingContextBase::GetActiveUniformBlockParameter(napi_env env, napi_callback_info info)
4477 {
4478 NFuncArg funcArg(env, info);
4479
4480 if (!funcArg.InitArgs(NARG_CNT::THREE)) {
4481 return nullptr;
4482 }
4483 if (funcArg[NARG_POS::FIRST] == nullptr) {
4484 return nullptr;
4485 }
4486 bool succ = false;
4487 LOGI("WebGL2 getActiveUniformBlockParameter start");
4488 WebGLProgram *webGlProgram = nullptr;
4489 napi_status programStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **)&webGlProgram);
4490 if (programStatus != napi_ok) {
4491 return nullptr;
4492 }
4493 int programId = webGlProgram->GetProgramId();
4494 LOGI("WebGL2 WebGL2RenderContext::getActiveUniformBlockParameter programId = %{public}u", programId);
4495 int64_t uniformBlockIndex;
4496 tie(succ, uniformBlockIndex) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt64();
4497 if (!succ) {
4498 return nullptr;
4499 }
4500 LOGI("WebGL2 WebGL2RenderContext::getActiveUniformBlockParameter uniformBlockIndex = %{public}u",
4501 uniformBlockIndex);
4502 int64_t pname;
4503 tie(succ, pname) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt64();
4504 if (!succ) {
4505 return nullptr;
4506 }
4507 LOGI("WebGL2 WebGL2RenderContext::getActiveUniformBlockParameter pname = %{public}u", pname);
4508 GLint params;
4509 glGetActiveUniformBlockiv(static_cast<GLuint>(programId), static_cast<GLuint>(uniformBlockIndex),
4510 static_cast<GLenum>(pname), ¶ms);
4511 if (pname == GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER ||
4512 pname == GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER) {
4513 bool res = (params == GL_FALSE) ? false : true;
4514 LOGI("WebGL2 getActiveUniformBlockParameter end");
4515 return NVal::CreateBool(env, res).val_;
4516 } else if (pname == GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) {
4517 GLint uniformCount = 1;
4518 LOGI("WebGL2 WebGL2RenderContext::getActiveUniformBlockParameter uniform_count = %{public}d",
4519 GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS);
4520 glGetActiveUniformBlockiv(static_cast<GLuint>(programId), static_cast<GLuint>(uniformBlockIndex),
4521 GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, &uniformCount);
4522 LOGI("WebGL2 WebGL2RenderContext::getActiveUniformBlockParameter uniform_count = %{public}d", uniformCount);
4523 GLint params[uniformCount];
4524 glGetActiveUniformBlockiv(static_cast<GLuint>(programId), static_cast<GLuint>(uniformBlockIndex),
4525 static_cast<GLenum>(pname), static_cast<GLint *>(params));
4526 static uint32_t *res = new uint32_t[uniformCount];
4527 int i;
4528 for (i = 0; i < uniformCount; i++) {
4529 res[i] = static_cast<uint32_t>(params[i]);
4530 }
4531 napi_value outputBuffer = nullptr;
4532 napi_create_external_arraybuffer(env, res, sizeof(params),
4533 [](napi_env env, void *finalize_data, void *finalize_hint) { },
4534 NULL, &outputBuffer);
4535 napi_value outputArray = nullptr;
4536 napi_create_typedarray(env, napi_uint32_array, sizeof(params) / sizeof(uint32_t),
4537 outputBuffer, 0, &outputArray);
4538 LOGI("WebGL2 getActiveUniformBlockParameter end");
4539 return outputArray;
4540 } else if (pname == GL_UNIFORM_BLOCK_BINDING ||
4541 pname == GL_UNIFORM_BLOCK_DATA_SIZE ||
4542 pname == GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS) {
4543 int64_t res = static_cast<int64_t>(params);
4544 LOGI("WebGL2 getActiveUniformBlockParameter end");
4545 return NVal::CreateInt64(env, res).val_;
4546 } else {
4547 LOGI("WebGL getActiveUniformBlockParameter : pname is wrong");
4548 return nullptr;
4549 }
4550 }
4551
GetActiveUniformBlockName(napi_env env,napi_callback_info info)4552 napi_value WebGL2RenderingContextBase::GetActiveUniformBlockName(napi_env env, napi_callback_info info)
4553 {
4554 NFuncArg funcArg(env, info);
4555
4556 if (!funcArg.InitArgs(NARG_CNT::TWO)) {
4557 return nullptr;
4558 }
4559 if (funcArg[NARG_POS::FIRST] == nullptr) {
4560 return nullptr;
4561 }
4562 bool succ = false;
4563 LOGI("WebGL2 getActiveUniformBlockName start");
4564 WebGLProgram *webGlProgram = nullptr;
4565 napi_status programStatus = napi_unwrap(env, funcArg[NARG_POS::FIRST], (void **)&webGlProgram);
4566 if (programStatus != napi_ok) {
4567 return nullptr;
4568 }
4569 int programId = webGlProgram->GetProgramId();
4570 LOGI("WebGL2 WebGL2RenderContext::getActiveUniformBlockName programId = %{public}u", programId);
4571 int64_t uniformBlockIndex;
4572 tie(succ, uniformBlockIndex) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt64();
4573 if (!succ) {
4574 return nullptr;
4575 }
4576 LOGI("WebGL2 WebGL2RenderContext::getActiveUniformBlockName uniformBlockIndex = %{public}u", uniformBlockIndex);
4577 GLint length = 0;
4578 GLsizei size = 0;
4579 glGetProgramiv(static_cast<GLuint>(programId), GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH, &length);
4580 std::unique_ptr<char[]> buf = std::make_unique<char[]>(length);
4581 if (buf == nullptr) {
4582 return nullptr;
4583 }
4584 glGetActiveUniformBlockName(programId, uniformBlockIndex, length, &size, buf.get());
4585 string str = buf.get();
4586 return NVal::CreateUTF8String(env, str).val_;
4587 }
4588 } // namespace Rosen
4589 } // namespace OHOS
4590
4591 #ifdef __cplusplus
4592 }
4593 #endif