| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 #include "jni/android_extension.h" | |
| 6 | |
| 7 #include <android/log.h> | |
| 8 #include <EGL/egl.h> | |
| 9 #include <GLES2/gl2.h> | |
| 10 #include <GLES2/gl2ext.h> | |
| 11 #include <jni.h> | |
| 12 #include <stdio.h> | |
| 13 #include <stdlib.h> | |
| 14 #include <string.h> | |
| 15 | |
| 16 #include "include/dart_api.h" | |
| 17 #include "jni/log.h" | |
| 18 | |
| 19 Dart_Handle HandleError(Dart_Handle handle) { | |
| 20 if (Dart_IsError(handle)) Dart_PropagateError(handle); | |
| 21 return handle; | |
| 22 } | |
| 23 | |
| 24 void CheckGLError(const char *function) { | |
| 25 int error = glGetError(); | |
| 26 if (error != GL_NO_ERROR) { | |
| 27 LOGE("ERROR!: %s returns %d", function, error); | |
| 28 } | |
| 29 } | |
| 30 | |
| 31 const char* GetStringArg(Dart_NativeArguments arguments, int idx) { | |
| 32 Dart_Handle whatHandle = HandleError(Dart_GetNativeArgument(arguments, idx)); | |
| 33 uint8_t* str; | |
| 34 intptr_t length; | |
| 35 HandleError(Dart_StringLength(whatHandle, &length)); | |
| 36 HandleError(Dart_StringToUTF8(whatHandle, &str, &length)); | |
| 37 str[length] = 0; | |
| 38 return const_cast<const char*>(reinterpret_cast<char*>(str)); | |
| 39 } | |
| 40 | |
| 41 void Log(Dart_NativeArguments arguments) { | |
| 42 Dart_EnterScope(); | |
| 43 LOGI(GetStringArg(arguments, 0)); | |
| 44 Dart_ExitScope(); | |
| 45 } | |
| 46 | |
| 47 void SystemRand(Dart_NativeArguments arguments) { | |
| 48 Dart_EnterScope(); | |
| 49 Dart_Handle result = HandleError(Dart_NewInteger(rand())); | |
| 50 Dart_SetReturnValue(arguments, result); | |
| 51 Dart_ExitScope(); | |
| 52 } | |
| 53 | |
| 54 void SystemSrand(Dart_NativeArguments arguments) { | |
| 55 Dart_EnterScope(); | |
| 56 bool success = false; | |
| 57 Dart_Handle seed_object = HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 58 if (Dart_IsInteger(seed_object)) { | |
| 59 bool fits; | |
| 60 HandleError(Dart_IntegerFitsIntoInt64(seed_object, &fits)); | |
| 61 if (fits) { | |
| 62 int64_t seed; | |
| 63 HandleError(Dart_IntegerToInt64(seed_object, &seed)); | |
| 64 srand(static_cast<unsigned>(seed)); | |
| 65 success = true; | |
| 66 } | |
| 67 } | |
| 68 Dart_SetReturnValue(arguments, HandleError(Dart_NewBoolean(success))); | |
| 69 Dart_ExitScope(); | |
| 70 } | |
| 71 | |
| 72 void EGLSwapBuffers(Dart_NativeArguments arguments) { | |
| 73 LOGI("GLSwapBuffers"); | |
| 74 Dart_EnterScope(); | |
| 75 | |
| 76 EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); | |
| 77 EGLSurface surface = eglGetCurrentSurface(EGL_DRAW); | |
| 78 eglSwapBuffers(display, surface); | |
| 79 | |
| 80 CheckGLError("eglSwapBuffers"); | |
| 81 Dart_ExitScope(); | |
| 82 } | |
| 83 | |
| 84 void GLAttachShader(Dart_NativeArguments arguments) { | |
| 85 LOGI("GLAttachShader"); | |
| 86 Dart_EnterScope(); | |
| 87 | |
| 88 Dart_Handle programHandle = HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 89 int64_t program; | |
| 90 HandleError(Dart_IntegerToInt64(programHandle, &program)); | |
| 91 | |
| 92 Dart_Handle shaderHandle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 93 int64_t shader; | |
| 94 HandleError(Dart_IntegerToInt64(shaderHandle, &shader)); | |
| 95 | |
| 96 glAttachShader(program, shader); | |
| 97 CheckGLError("glAttachShader"); | |
| 98 Dart_ExitScope(); | |
| 99 } | |
| 100 | |
| 101 void GLBindBuffer(Dart_NativeArguments arguments) { | |
| 102 LOGI("GLBindBuffer"); | |
| 103 Dart_EnterScope(); | |
| 104 | |
| 105 Dart_Handle targetHandle = HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 106 int64_t target; | |
| 107 HandleError(Dart_IntegerToInt64(targetHandle, &target)); | |
| 108 | |
| 109 Dart_Handle bufferHandle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 110 int64_t buffer; | |
| 111 HandleError(Dart_IntegerToInt64(bufferHandle, &buffer)); | |
| 112 | |
| 113 glBindBuffer(target, buffer); | |
| 114 CheckGLError("glBindBuffer"); | |
| 115 Dart_ExitScope(); | |
| 116 } | |
| 117 | |
| 118 void GLBufferData(Dart_NativeArguments arguments) { | |
| 119 LOGI("GLBufferData"); | |
| 120 Dart_EnterScope(); | |
| 121 | |
| 122 Dart_Handle targetHandle = HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 123 int64_t target; | |
| 124 HandleError(Dart_IntegerToInt64(targetHandle, &target)); | |
| 125 | |
| 126 Dart_Handle dataHandle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 127 intptr_t size; | |
| 128 HandleError(Dart_ListLength(dataHandle, &size)); | |
| 129 | |
| 130 LOGI("Size: %d", size); | |
| 131 | |
| 132 // TODO(vsm): No guarantee that this is a float! | |
| 133 float* data = reinterpret_cast<float*>(malloc(size * sizeof(float))); | |
| 134 for (int i = 0; i < size; i++) { | |
| 135 Dart_Handle elemHandle = HandleError(Dart_ListGetAt(dataHandle, i)); | |
| 136 double value; | |
| 137 Dart_DoubleValue(elemHandle, &value); | |
| 138 data[i] = static_cast<float>(value); | |
| 139 LOGI("Value[%d]: %f", i, data[i]); | |
| 140 } | |
| 141 | |
| 142 Dart_Handle usageHandle = HandleError(Dart_GetNativeArgument(arguments, 2)); | |
| 143 int64_t usage; | |
| 144 HandleError(Dart_IntegerToInt64(usageHandle, &usage)); | |
| 145 | |
| 146 glBufferData(target, size * sizeof(float), data, usage); | |
| 147 CheckGLError("glBufferData"); | |
| 148 free(data); | |
| 149 Dart_ExitScope(); | |
| 150 } | |
| 151 | |
| 152 void GLCompileShader(Dart_NativeArguments arguments) { | |
| 153 Dart_EnterScope(); | |
| 154 | |
| 155 Dart_Handle shaderHandle = HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 156 int64_t shader; | |
| 157 HandleError(Dart_IntegerToInt64(shaderHandle, &shader)); | |
| 158 | |
| 159 LOGI("GLCompileShader"); | |
| 160 glCompileShader(shader); | |
| 161 CheckGLError("glCompileShader"); | |
| 162 Dart_ExitScope(); | |
| 163 } | |
| 164 | |
| 165 void GLCreateBuffer(Dart_NativeArguments arguments) { | |
| 166 LOGI("GLCreateBuffer"); | |
| 167 Dart_EnterScope(); | |
| 168 GLuint buffer; | |
| 169 | |
| 170 glGenBuffers(1, &buffer); | |
| 171 CheckGLError("glGenBuffers"); | |
| 172 Dart_Handle result = HandleError(Dart_NewInteger(buffer)); | |
| 173 Dart_SetReturnValue(arguments, result); | |
| 174 Dart_ExitScope(); | |
| 175 } | |
| 176 | |
| 177 void GLCreateProgram(Dart_NativeArguments arguments) { | |
| 178 LOGI("GLCreateProgram"); | |
| 179 Dart_EnterScope(); | |
| 180 | |
| 181 int64_t program = glCreateProgram(); | |
| 182 CheckGLError("glCreateProgram"); | |
| 183 Dart_Handle result = HandleError(Dart_NewInteger(program)); | |
| 184 Dart_SetReturnValue(arguments, result); | |
| 185 Dart_ExitScope(); | |
| 186 } | |
| 187 | |
| 188 void GLCreateShader(Dart_NativeArguments arguments) { | |
| 189 Dart_EnterScope(); | |
| 190 | |
| 191 Dart_Handle typeHandle = HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 192 int64_t type; | |
| 193 HandleError(Dart_IntegerToInt64(typeHandle, &type)); | |
| 194 | |
| 195 int64_t shader = glCreateShader((GLenum)type); | |
| 196 LOGI("GLCreateShader"); | |
| 197 CheckGLError("glCreateShader"); | |
| 198 Dart_Handle result = HandleError(Dart_NewInteger(shader)); | |
| 199 Dart_SetReturnValue(arguments, result); | |
| 200 Dart_ExitScope(); | |
| 201 } | |
| 202 | |
| 203 void GLDrawArrays(Dart_NativeArguments arguments) { | |
| 204 LOGI("GLDrawArrays"); | |
| 205 Dart_EnterScope(); | |
| 206 | |
| 207 Dart_Handle modeHandle = HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 208 int64_t mode; | |
| 209 HandleError(Dart_IntegerToInt64(modeHandle, &mode)); | |
| 210 | |
| 211 Dart_Handle firstHandle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 212 int64_t first; | |
| 213 HandleError(Dart_IntegerToInt64(firstHandle, &first)); | |
| 214 | |
| 215 Dart_Handle countHandle = HandleError(Dart_GetNativeArgument(arguments, 2)); | |
| 216 int64_t count; | |
| 217 HandleError(Dart_IntegerToInt64(countHandle, &count)); | |
| 218 | |
| 219 glDrawArrays(mode, first, count); | |
| 220 CheckGLError("glDrawArrays"); | |
| 221 Dart_ExitScope(); | |
| 222 } | |
| 223 | |
| 224 void GLEnableVertexAttribArray(Dart_NativeArguments arguments) { | |
| 225 LOGI("GLEnableVertexAttribArray"); | |
| 226 Dart_EnterScope(); | |
| 227 | |
| 228 Dart_Handle locationHandle = | |
| 229 HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 230 int64_t location; | |
| 231 HandleError(Dart_IntegerToInt64(locationHandle, &location)); | |
| 232 | |
| 233 glEnableVertexAttribArray(location); | |
| 234 CheckGLError("glEnableVertexAttribArray"); | |
| 235 Dart_ExitScope(); | |
| 236 } | |
| 237 | |
| 238 void GLGetAttribLocation(Dart_NativeArguments arguments) { | |
| 239 LOGI("GLGetAttribLocation"); | |
| 240 Dart_EnterScope(); | |
| 241 | |
| 242 Dart_Handle programHandle = HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 243 int64_t program; | |
| 244 HandleError(Dart_IntegerToInt64(programHandle, &program)); | |
| 245 | |
| 246 Dart_Handle nameHandle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 247 intptr_t length; | |
| 248 HandleError(Dart_StringLength(nameHandle, &length)); | |
| 249 uint8_t* str; | |
| 250 HandleError(Dart_StringToUTF8(nameHandle, &str, &length)); | |
| 251 str[length] = 0; | |
| 252 | |
| 253 int64_t location = glGetAttribLocation(program, | |
| 254 const_cast<const GLchar*>(reinterpret_cast<GLchar*>(str))); | |
| 255 CheckGLError("glGetAttribLocation"); | |
| 256 Dart_Handle result = HandleError(Dart_NewInteger(location)); | |
| 257 Dart_SetReturnValue(arguments, result); | |
| 258 Dart_ExitScope(); | |
| 259 } | |
| 260 | |
| 261 void GLGetError(Dart_NativeArguments arguments) { | |
| 262 LOGI("GLGetError"); | |
| 263 Dart_EnterScope(); | |
| 264 | |
| 265 int64_t error = glGetError(); | |
| 266 Dart_Handle result = HandleError(Dart_NewInteger(error)); | |
| 267 Dart_SetReturnValue(arguments, result); | |
| 268 Dart_ExitScope(); | |
| 269 } | |
| 270 | |
| 271 void GLGetProgramParameter(Dart_NativeArguments arguments) { | |
| 272 LOGI("GLGetProgramParameter"); | |
| 273 Dart_EnterScope(); | |
| 274 | |
| 275 Dart_Handle programHandle = HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 276 int64_t program; | |
| 277 HandleError(Dart_IntegerToInt64(programHandle, &program)); | |
| 278 | |
| 279 Dart_Handle paramHandle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 280 int64_t param; | |
| 281 HandleError(Dart_IntegerToInt64(paramHandle, ¶m)); | |
| 282 | |
| 283 GLint value = -1; | |
| 284 glGetProgramiv(program, param, &value); | |
| 285 CheckGLError("glGetProgramiv"); | |
| 286 | |
| 287 Dart_Handle result = HandleError(Dart_NewInteger(value)); | |
| 288 Dart_SetReturnValue(arguments, result); | |
| 289 Dart_ExitScope(); | |
| 290 } | |
| 291 | |
| 292 void GLGetShaderParameter(Dart_NativeArguments arguments) { | |
| 293 LOGI("GLGetShaderParameter"); | |
| 294 Dart_EnterScope(); | |
| 295 | |
| 296 Dart_Handle shaderHandle = HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 297 int64_t shader; | |
| 298 HandleError(Dart_IntegerToInt64(shaderHandle, &shader)); | |
| 299 | |
| 300 Dart_Handle paramHandle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 301 int64_t param; | |
| 302 HandleError(Dart_IntegerToInt64(paramHandle, ¶m)); | |
| 303 | |
| 304 GLint value = -1; | |
| 305 glGetShaderiv((GLuint)shader, (GLenum)param, &value); | |
| 306 CheckGLError("glGetShaderiv"); | |
| 307 | |
| 308 Dart_Handle result = HandleError(Dart_NewInteger(value)); | |
| 309 Dart_SetReturnValue(arguments, result); | |
| 310 Dart_ExitScope(); | |
| 311 } | |
| 312 | |
| 313 void GLGetShaderInfoLog(Dart_NativeArguments arguments) { | |
| 314 LOGI("GLGetShaderInfoLog"); | |
| 315 Dart_EnterScope(); | |
| 316 | |
| 317 Dart_Handle shaderHandle = HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 318 int64_t shader; | |
| 319 HandleError(Dart_IntegerToInt64(shaderHandle, &shader)); | |
| 320 | |
| 321 GLint infoLogLength = 0; | |
| 322 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength); | |
| 323 | |
| 324 GLchar* strInfoLog = new GLchar[infoLogLength + 1]; | |
| 325 glGetShaderInfoLog(shader, infoLogLength, NULL, strInfoLog); | |
| 326 strInfoLog[infoLogLength] = 0; | |
| 327 | |
| 328 Dart_Handle result = HandleError(Dart_NewStringFromCString(strInfoLog)); | |
| 329 Dart_SetReturnValue(arguments, result); | |
| 330 Dart_ExitScope(); | |
| 331 delete[] strInfoLog; | |
| 332 } | |
| 333 | |
| 334 void GLGetProgramInfoLog(Dart_NativeArguments arguments) { | |
| 335 LOGI("GLGetProgramInfoLog"); | |
| 336 Dart_EnterScope(); | |
| 337 | |
| 338 Dart_Handle programHandle = HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 339 int64_t program; | |
| 340 HandleError(Dart_IntegerToInt64(programHandle, &program)); | |
| 341 | |
| 342 GLint infoLogLength; | |
| 343 glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength); | |
| 344 | |
| 345 GLchar* strInfoLog = new GLchar[infoLogLength + 1]; | |
| 346 glGetProgramInfoLog(program, infoLogLength, NULL, strInfoLog); | |
| 347 strInfoLog[infoLogLength] = 0; | |
| 348 | |
| 349 Dart_Handle result = HandleError(Dart_NewStringFromCString(strInfoLog)); | |
| 350 Dart_SetReturnValue(arguments, result); | |
| 351 Dart_ExitScope(); | |
| 352 delete[] strInfoLog; | |
| 353 } | |
| 354 | |
| 355 void GLGetUniformLocation(Dart_NativeArguments arguments) { | |
| 356 LOGI("GLGetUniformLocation"); | |
| 357 Dart_EnterScope(); | |
| 358 | |
| 359 Dart_Handle programHandle = HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 360 int64_t program; | |
| 361 HandleError(Dart_IntegerToInt64(programHandle, &program)); | |
| 362 | |
| 363 Dart_Handle nameHandle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 364 intptr_t length; | |
| 365 HandleError(Dart_StringLength(nameHandle, &length)); | |
| 366 uint8_t* str; | |
| 367 HandleError(Dart_StringToUTF8(nameHandle, &str, &length)); | |
| 368 str[length] = 0; | |
| 369 | |
| 370 int64_t location = glGetUniformLocation(program, | |
| 371 const_cast<const GLchar*>(reinterpret_cast<GLchar*>(str))); | |
| 372 CheckGLError("glGetUniformLocation"); | |
| 373 Dart_Handle result = HandleError(Dart_NewInteger(location)); | |
| 374 Dart_SetReturnValue(arguments, result); | |
| 375 Dart_ExitScope(); | |
| 376 } | |
| 377 | |
| 378 void GLLinkProgram(Dart_NativeArguments arguments) { | |
| 379 LOGI("GLLinkProgram"); | |
| 380 Dart_EnterScope(); | |
| 381 | |
| 382 Dart_Handle programHandle = HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 383 int64_t program; | |
| 384 HandleError(Dart_IntegerToInt64(programHandle, &program)); | |
| 385 | |
| 386 glLinkProgram(program); | |
| 387 CheckGLError("glLinkProgram"); | |
| 388 Dart_ExitScope(); | |
| 389 } | |
| 390 | |
| 391 void GLShaderSource(Dart_NativeArguments arguments) { | |
| 392 LOGI("GLShaderSource"); | |
| 393 Dart_EnterScope(); | |
| 394 | |
| 395 Dart_Handle shaderHandle = HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 396 int64_t shader; | |
| 397 HandleError(Dart_IntegerToInt64(shaderHandle, &shader)); | |
| 398 | |
| 399 Dart_Handle sourceHandle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 400 intptr_t length[1]; | |
| 401 HandleError(Dart_StringLength(sourceHandle, length)); | |
| 402 LOGI("Source length is %d", length[0]); | |
| 403 uint8_t* str[1]; | |
| 404 HandleError(Dart_StringToUTF8(sourceHandle, &str[0], length)); | |
| 405 LOGI("Converted length is %d", length[0]); | |
| 406 str[0][*length] = 0; | |
| 407 | |
| 408 const GLchar* source = | |
| 409 const_cast<const GLchar*>(reinterpret_cast<GLchar*>(str[0])); | |
| 410 LOGI("Source: %s", source); | |
| 411 glShaderSource(shader, 1, | |
| 412 const_cast<const GLchar**>(reinterpret_cast<GLchar**>(str)), NULL); | |
| 413 CheckGLError("glShaderSource"); | |
| 414 Dart_ExitScope(); | |
| 415 } | |
| 416 | |
| 417 void GLUseProgram(Dart_NativeArguments arguments) { | |
| 418 LOGI("GLUseProgram"); | |
| 419 Dart_EnterScope(); | |
| 420 | |
| 421 Dart_Handle programHandle = HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 422 int64_t program; | |
| 423 HandleError(Dart_IntegerToInt64(programHandle, &program)); | |
| 424 | |
| 425 glUseProgram(program); | |
| 426 CheckGLError("glUseProgram"); | |
| 427 Dart_ExitScope(); | |
| 428 } | |
| 429 | |
| 430 void GLUniform1i(Dart_NativeArguments arguments) { | |
| 431 LOGI("GLUniform1i"); | |
| 432 Dart_EnterScope(); | |
| 433 | |
| 434 Dart_Handle locationHandle = | |
| 435 HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 436 int64_t location; | |
| 437 HandleError(Dart_IntegerToInt64(locationHandle, &location)); | |
| 438 | |
| 439 Dart_Handle v0Handle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 440 int64_t v0; | |
| 441 HandleError(Dart_IntegerToInt64(v0Handle, &v0)); | |
| 442 | |
| 443 glUniform1i(location, v0); | |
| 444 CheckGLError("glUniform1i"); | |
| 445 Dart_ExitScope(); | |
| 446 } | |
| 447 | |
| 448 void GLUniform2i(Dart_NativeArguments arguments) { | |
| 449 LOGI("GLUniform2i"); | |
| 450 Dart_EnterScope(); | |
| 451 | |
| 452 Dart_Handle locationHandle = | |
| 453 HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 454 int64_t location; | |
| 455 HandleError(Dart_IntegerToInt64(locationHandle, &location)); | |
| 456 | |
| 457 Dart_Handle v0Handle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 458 int64_t v0; | |
| 459 HandleError(Dart_IntegerToInt64(v0Handle, &v0)); | |
| 460 | |
| 461 Dart_Handle v1Handle = HandleError(Dart_GetNativeArgument(arguments, 2)); | |
| 462 int64_t v1; | |
| 463 HandleError(Dart_IntegerToInt64(v1Handle, &v1)); | |
| 464 | |
| 465 glUniform2i(location, v0, v1); | |
| 466 CheckGLError("glUniform2i"); | |
| 467 Dart_ExitScope(); | |
| 468 } | |
| 469 | |
| 470 void GLUniform3i(Dart_NativeArguments arguments) { | |
| 471 LOGI("GLUniform3i"); | |
| 472 Dart_EnterScope(); | |
| 473 | |
| 474 Dart_Handle locationHandle = | |
| 475 HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 476 int64_t location; | |
| 477 HandleError(Dart_IntegerToInt64(locationHandle, &location)); | |
| 478 | |
| 479 Dart_Handle v0Handle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 480 int64_t v0; | |
| 481 HandleError(Dart_IntegerToInt64(v0Handle, &v0)); | |
| 482 | |
| 483 Dart_Handle v1Handle = HandleError(Dart_GetNativeArgument(arguments, 2)); | |
| 484 int64_t v1; | |
| 485 HandleError(Dart_IntegerToInt64(v1Handle, &v1)); | |
| 486 | |
| 487 Dart_Handle v2Handle = HandleError(Dart_GetNativeArgument(arguments, 3)); | |
| 488 int64_t v2; | |
| 489 HandleError(Dart_IntegerToInt64(v2Handle, &v2)); | |
| 490 | |
| 491 glUniform3i(location, v0, v1, v2); | |
| 492 CheckGLError("glUniform3i"); | |
| 493 Dart_ExitScope(); | |
| 494 } | |
| 495 | |
| 496 void GLUniform4i(Dart_NativeArguments arguments) { | |
| 497 LOGI("GLUniform4i"); | |
| 498 Dart_EnterScope(); | |
| 499 | |
| 500 Dart_Handle locationHandle = | |
| 501 HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 502 int64_t location; | |
| 503 HandleError(Dart_IntegerToInt64(locationHandle, &location)); | |
| 504 | |
| 505 Dart_Handle v0Handle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 506 int64_t v0; | |
| 507 HandleError(Dart_IntegerToInt64(v0Handle, &v0)); | |
| 508 | |
| 509 Dart_Handle v1Handle = HandleError(Dart_GetNativeArgument(arguments, 2)); | |
| 510 int64_t v1; | |
| 511 HandleError(Dart_IntegerToInt64(v1Handle, &v1)); | |
| 512 | |
| 513 Dart_Handle v2Handle = HandleError(Dart_GetNativeArgument(arguments, 3)); | |
| 514 int64_t v2; | |
| 515 HandleError(Dart_IntegerToInt64(v2Handle, &v2)); | |
| 516 | |
| 517 Dart_Handle v3Handle = HandleError(Dart_GetNativeArgument(arguments, 4)); | |
| 518 int64_t v3; | |
| 519 HandleError(Dart_IntegerToInt64(v3Handle, &v3)); | |
| 520 | |
| 521 glUniform4i(location, v0, v1, v2, v3); | |
| 522 CheckGLError("glUniform4i"); | |
| 523 Dart_ExitScope(); | |
| 524 } | |
| 525 | |
| 526 void GLUniform1f(Dart_NativeArguments arguments) { | |
| 527 LOGI("GLUniform1f"); | |
| 528 Dart_EnterScope(); | |
| 529 | |
| 530 Dart_Handle locationHandle = | |
| 531 HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 532 int64_t location; | |
| 533 HandleError(Dart_IntegerToInt64(locationHandle, &location)); | |
| 534 | |
| 535 Dart_Handle v0Handle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 536 double v0; | |
| 537 HandleError(Dart_DoubleValue(v0Handle, &v0)); | |
| 538 | |
| 539 glUniform1f(location, v0); | |
| 540 CheckGLError("glUniform1f"); | |
| 541 Dart_ExitScope(); | |
| 542 } | |
| 543 | |
| 544 void GLUniform2f(Dart_NativeArguments arguments) { | |
| 545 LOGI("GLUniform2f"); | |
| 546 Dart_EnterScope(); | |
| 547 | |
| 548 Dart_Handle locationHandle = | |
| 549 HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 550 int64_t location; | |
| 551 HandleError(Dart_IntegerToInt64(locationHandle, &location)); | |
| 552 | |
| 553 Dart_Handle v0Handle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 554 double v0; | |
| 555 HandleError(Dart_DoubleValue(v0Handle, &v0)); | |
| 556 | |
| 557 Dart_Handle v1Handle = HandleError(Dart_GetNativeArgument(arguments, 2)); | |
| 558 double v1; | |
| 559 HandleError(Dart_DoubleValue(v1Handle, &v1)); | |
| 560 | |
| 561 glUniform2f(location, v0, v1); | |
| 562 CheckGLError("glUniform2f"); | |
| 563 Dart_ExitScope(); | |
| 564 } | |
| 565 | |
| 566 void GLUniform3f(Dart_NativeArguments arguments) { | |
| 567 LOGI("GLUniform3f"); | |
| 568 Dart_EnterScope(); | |
| 569 | |
| 570 Dart_Handle locationHandle = | |
| 571 HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 572 int64_t location; | |
| 573 HandleError(Dart_IntegerToInt64(locationHandle, &location)); | |
| 574 | |
| 575 Dart_Handle v0Handle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 576 double v0; | |
| 577 HandleError(Dart_DoubleValue(v0Handle, &v0)); | |
| 578 | |
| 579 Dart_Handle v1Handle = HandleError(Dart_GetNativeArgument(arguments, 2)); | |
| 580 double v1; | |
| 581 HandleError(Dart_DoubleValue(v1Handle, &v1)); | |
| 582 | |
| 583 Dart_Handle v2Handle = HandleError(Dart_GetNativeArgument(arguments, 3)); | |
| 584 double v2; | |
| 585 HandleError(Dart_DoubleValue(v2Handle, &v2)); | |
| 586 | |
| 587 glUniform3f(location, v0, v1, v2); | |
| 588 CheckGLError("glUniform3f"); | |
| 589 Dart_ExitScope(); | |
| 590 } | |
| 591 | |
| 592 void GLUniform4f(Dart_NativeArguments arguments) { | |
| 593 LOGI("GLUniform4f"); | |
| 594 Dart_EnterScope(); | |
| 595 | |
| 596 Dart_Handle locationHandle = | |
| 597 HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 598 int64_t location; | |
| 599 HandleError(Dart_IntegerToInt64(locationHandle, &location)); | |
| 600 | |
| 601 Dart_Handle v0Handle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 602 double v0; | |
| 603 HandleError(Dart_DoubleValue(v0Handle, &v0)); | |
| 604 | |
| 605 Dart_Handle v1Handle = HandleError(Dart_GetNativeArgument(arguments, 2)); | |
| 606 double v1; | |
| 607 HandleError(Dart_DoubleValue(v1Handle, &v1)); | |
| 608 | |
| 609 Dart_Handle v2Handle = HandleError(Dart_GetNativeArgument(arguments, 3)); | |
| 610 double v2; | |
| 611 HandleError(Dart_DoubleValue(v2Handle, &v2)); | |
| 612 | |
| 613 Dart_Handle v3Handle = HandleError(Dart_GetNativeArgument(arguments, 4)); | |
| 614 double v3; | |
| 615 HandleError(Dart_DoubleValue(v3Handle, &v3)); | |
| 616 | |
| 617 glUniform4f(location, v0, v1, v2, v3); | |
| 618 CheckGLError("glUniform4f"); | |
| 619 Dart_ExitScope(); | |
| 620 } | |
| 621 | |
| 622 void GLUniform1iv(Dart_NativeArguments arguments) { | |
| 623 LOGI("GLUniform1iv"); | |
| 624 Dart_EnterScope(); | |
| 625 | |
| 626 Dart_Handle locationHandle = | |
| 627 HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 628 int64_t location; | |
| 629 HandleError(Dart_IntegerToInt64(locationHandle, &location)); | |
| 630 | |
| 631 Dart_Handle argHandle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 632 | |
| 633 if (Dart_IsList(argHandle)) { | |
| 634 int len; | |
| 635 HandleError(Dart_ListLength(argHandle, &len)); | |
| 636 GLint* list = new GLint[len]; | |
| 637 for (int i = 0; i < len; i++) { | |
| 638 Dart_Handle vHandle = Dart_ListGetAt(argHandle, i); | |
| 639 int64_t v; | |
| 640 HandleError(Dart_IntegerToInt64(vHandle, &v)); | |
| 641 list[i] = v; | |
| 642 } | |
| 643 glUniform1iv(location, len, list); | |
| 644 delete [] list; | |
| 645 CheckGLError("glUniform1iv"); | |
| 646 } | |
| 647 Dart_ExitScope(); | |
| 648 } | |
| 649 | |
| 650 void GLUniform2iv(Dart_NativeArguments arguments) { | |
| 651 LOGI("GLUniform2iv"); | |
| 652 Dart_EnterScope(); | |
| 653 | |
| 654 Dart_Handle locationHandle = | |
| 655 HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 656 int64_t location; | |
| 657 HandleError(Dart_IntegerToInt64(locationHandle, &location)); | |
| 658 | |
| 659 Dart_Handle argHandle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 660 | |
| 661 if (Dart_IsList(argHandle)) { | |
| 662 int len; | |
| 663 HandleError(Dart_ListLength(argHandle, &len)); | |
| 664 GLint* list = new GLint[len]; | |
| 665 for (int i = 0; i < len; i++) { | |
| 666 Dart_Handle vHandle = Dart_ListGetAt(argHandle, i); | |
| 667 int64_t v; | |
| 668 HandleError(Dart_IntegerToInt64(vHandle, &v)); | |
| 669 list[i] = v; | |
| 670 } | |
| 671 glUniform2iv(location, len / 2, list); | |
| 672 delete [] list; | |
| 673 CheckGLError("glUniform2iv"); | |
| 674 } | |
| 675 Dart_ExitScope(); | |
| 676 } | |
| 677 | |
| 678 void GLUniform3iv(Dart_NativeArguments arguments) { | |
| 679 LOGI("GLUniform3iv"); | |
| 680 Dart_EnterScope(); | |
| 681 | |
| 682 Dart_Handle locationHandle = | |
| 683 HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 684 int64_t location; | |
| 685 HandleError(Dart_IntegerToInt64(locationHandle, &location)); | |
| 686 | |
| 687 Dart_Handle argHandle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 688 | |
| 689 if (Dart_IsList(argHandle)) { | |
| 690 int len; | |
| 691 HandleError(Dart_ListLength(argHandle, &len)); | |
| 692 GLint* list = new GLint[len]; | |
| 693 for (int i = 0; i < len; i++) { | |
| 694 Dart_Handle vHandle = Dart_ListGetAt(argHandle, i); | |
| 695 int64_t v; | |
| 696 HandleError(Dart_IntegerToInt64(vHandle, &v)); | |
| 697 list[i] = v; | |
| 698 } | |
| 699 glUniform3iv(location, len / 3, list); | |
| 700 delete [] list; | |
| 701 CheckGLError("glUniform3iv"); | |
| 702 } | |
| 703 Dart_ExitScope(); | |
| 704 } | |
| 705 | |
| 706 void GLUniform4iv(Dart_NativeArguments arguments) { | |
| 707 LOGI("GLUniform4iv"); | |
| 708 Dart_EnterScope(); | |
| 709 | |
| 710 Dart_Handle locationHandle = | |
| 711 HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 712 int64_t location; | |
| 713 HandleError(Dart_IntegerToInt64(locationHandle, &location)); | |
| 714 | |
| 715 Dart_Handle argHandle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 716 | |
| 717 if (Dart_IsList(argHandle)) { | |
| 718 int len; | |
| 719 HandleError(Dart_ListLength(argHandle, &len)); | |
| 720 GLint* list = new GLint[len]; | |
| 721 for (int i = 0; i < len; i++) { | |
| 722 Dart_Handle vHandle = Dart_ListGetAt(argHandle, i); | |
| 723 int64_t v; | |
| 724 HandleError(Dart_IntegerToInt64(vHandle, &v)); | |
| 725 list[i] = v; | |
| 726 } | |
| 727 glUniform1iv(location, len / 4, list); | |
| 728 delete [] list; | |
| 729 CheckGLError("glUniform4iv"); | |
| 730 } | |
| 731 Dart_ExitScope(); | |
| 732 } | |
| 733 | |
| 734 void GLUniform1fv(Dart_NativeArguments arguments) { | |
| 735 LOGI("GLUniform1fv"); | |
| 736 Dart_EnterScope(); | |
| 737 | |
| 738 Dart_Handle locationHandle = | |
| 739 HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 740 int64_t location; | |
| 741 HandleError(Dart_IntegerToInt64(locationHandle, &location)); | |
| 742 | |
| 743 Dart_Handle argHandle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 744 | |
| 745 if (Dart_IsList(argHandle)) { | |
| 746 int len; | |
| 747 HandleError(Dart_ListLength(argHandle, &len)); | |
| 748 GLfloat* list = new GLfloat[len]; | |
| 749 for (int i = 0; i < len; i++) { | |
| 750 Dart_Handle vHandle = Dart_ListGetAt(argHandle, i); | |
| 751 double v; | |
| 752 HandleError(Dart_DoubleValue(vHandle, &v)); | |
| 753 list[i] = v; | |
| 754 } | |
| 755 glUniform1fv(location, len, list); | |
| 756 delete [] list; | |
| 757 CheckGLError("glUniform1fv"); | |
| 758 } | |
| 759 Dart_ExitScope(); | |
| 760 } | |
| 761 | |
| 762 void GLUniform2fv(Dart_NativeArguments arguments) { | |
| 763 LOGI("GLUniform2fv"); | |
| 764 Dart_EnterScope(); | |
| 765 | |
| 766 Dart_Handle locationHandle = | |
| 767 HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 768 int64_t location; | |
| 769 HandleError(Dart_IntegerToInt64(locationHandle, &location)); | |
| 770 | |
| 771 Dart_Handle argHandle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 772 | |
| 773 if (Dart_IsList(argHandle)) { | |
| 774 int len; | |
| 775 HandleError(Dart_ListLength(argHandle, &len)); | |
| 776 GLfloat* list = new GLfloat[len]; | |
| 777 for (int i = 0; i < len; i++) { | |
| 778 Dart_Handle vHandle = Dart_ListGetAt(argHandle, i); | |
| 779 double v; | |
| 780 HandleError(Dart_DoubleValue(vHandle, &v)); | |
| 781 list[i] = v; | |
| 782 } | |
| 783 glUniform2fv(location, len / 2, list); | |
| 784 delete [] list; | |
| 785 CheckGLError("glUniform2fv"); | |
| 786 } | |
| 787 Dart_ExitScope(); | |
| 788 } | |
| 789 | |
| 790 void GLUniform3fv(Dart_NativeArguments arguments) { | |
| 791 LOGI("GLUniform3fv"); | |
| 792 Dart_EnterScope(); | |
| 793 | |
| 794 Dart_Handle locationHandle = | |
| 795 HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 796 int64_t location; | |
| 797 HandleError(Dart_IntegerToInt64(locationHandle, &location)); | |
| 798 | |
| 799 Dart_Handle argHandle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 800 | |
| 801 if (Dart_IsList(argHandle)) { | |
| 802 int len; | |
| 803 HandleError(Dart_ListLength(argHandle, &len)); | |
| 804 GLfloat* list = new GLfloat[len]; | |
| 805 for (int i = 0; i < len; i++) { | |
| 806 Dart_Handle vHandle = Dart_ListGetAt(argHandle, i); | |
| 807 double v; | |
| 808 HandleError(Dart_DoubleValue(vHandle, &v)); | |
| 809 list[i] = v; | |
| 810 } | |
| 811 glUniform3fv(location, len / 3, list); | |
| 812 delete [] list; | |
| 813 CheckGLError("glUniform3fv"); | |
| 814 } | |
| 815 Dart_ExitScope(); | |
| 816 } | |
| 817 | |
| 818 void GLUniform4fv(Dart_NativeArguments arguments) { | |
| 819 LOGI("In GLUniform4fv"); | |
| 820 Dart_EnterScope(); | |
| 821 | |
| 822 Dart_Handle locationHandle = | |
| 823 HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 824 int64_t location; | |
| 825 HandleError(Dart_IntegerToInt64(locationHandle, &location)); | |
| 826 | |
| 827 Dart_Handle argHandle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 828 | |
| 829 if (Dart_IsList(argHandle)) { | |
| 830 int len; | |
| 831 HandleError(Dart_ListLength(argHandle, &len)); | |
| 832 GLfloat* list = new GLfloat[len]; | |
| 833 for (int i = 0; i < len; i++) { | |
| 834 Dart_Handle vHandle = Dart_ListGetAt(argHandle, i); | |
| 835 double v; | |
| 836 HandleError(Dart_DoubleValue(vHandle, &v)); | |
| 837 list[i] = v; | |
| 838 } | |
| 839 glUniform4fv(location, len / 4, list); | |
| 840 delete [] list; | |
| 841 CheckGLError("glUniform4fv"); | |
| 842 } | |
| 843 Dart_ExitScope(); | |
| 844 } | |
| 845 | |
| 846 void GLViewport(Dart_NativeArguments arguments) { | |
| 847 LOGI("GLViewport"); | |
| 848 Dart_EnterScope(); | |
| 849 | |
| 850 Dart_Handle xHandle = HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 851 int64_t x; | |
| 852 HandleError(Dart_IntegerToInt64(xHandle, &x)); | |
| 853 | |
| 854 Dart_Handle yHandle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 855 int64_t y; | |
| 856 HandleError(Dart_IntegerToInt64(yHandle, &y)); | |
| 857 | |
| 858 Dart_Handle widthHandle = HandleError(Dart_GetNativeArgument(arguments, 2)); | |
| 859 int64_t width; | |
| 860 HandleError(Dart_IntegerToInt64(widthHandle, &width)); | |
| 861 | |
| 862 Dart_Handle heightHandle = HandleError(Dart_GetNativeArgument(arguments, 3)); | |
| 863 int64_t height; | |
| 864 HandleError(Dart_IntegerToInt64(heightHandle, &height)); | |
| 865 | |
| 866 LOGI("Dimensions: [%ld, %ld, %ld, %ld]", x, y, width, height); | |
| 867 | |
| 868 glViewport(x, y, width, height); | |
| 869 CheckGLError("glViewPort"); | |
| 870 Dart_ExitScope(); | |
| 871 } | |
| 872 | |
| 873 void GLVertexAttribPointer(Dart_NativeArguments arguments) { | |
| 874 LOGI("GLVertexAttribPointer"); | |
| 875 Dart_EnterScope(); | |
| 876 | |
| 877 Dart_Handle indexHandle = HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 878 int64_t index; | |
| 879 HandleError(Dart_IntegerToInt64(indexHandle, &index)); | |
| 880 | |
| 881 Dart_Handle sizeHandle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 882 int64_t size; | |
| 883 HandleError(Dart_IntegerToInt64(sizeHandle, &size)); | |
| 884 | |
| 885 Dart_Handle typeHandle = HandleError(Dart_GetNativeArgument(arguments, 2)); | |
| 886 int64_t type; | |
| 887 HandleError(Dart_IntegerToInt64(typeHandle, &type)); | |
| 888 | |
| 889 Dart_Handle normalizedHandle = | |
| 890 HandleError(Dart_GetNativeArgument(arguments, 3)); | |
| 891 bool normalized; | |
| 892 HandleError(Dart_BooleanValue(normalizedHandle, &normalized)); | |
| 893 | |
| 894 Dart_Handle strideHandle = HandleError(Dart_GetNativeArgument(arguments, 4)); | |
| 895 int64_t stride; | |
| 896 HandleError(Dart_IntegerToInt64(strideHandle, &stride)); | |
| 897 | |
| 898 Dart_Handle pointerHandle = HandleError(Dart_GetNativeArgument(arguments, 5)); | |
| 899 int64_t pointerValue; | |
| 900 HandleError(Dart_IntegerToInt64(pointerHandle, &pointerValue)); | |
| 901 const void* pointer; | |
| 902 pointer = const_cast<const void*>(reinterpret_cast<void*>(pointerValue)); | |
| 903 | |
| 904 glVertexAttribPointer(index, size, type, normalized, stride, pointer); | |
| 905 CheckGLError("glVertexAttribPointer"); | |
| 906 Dart_ExitScope(); | |
| 907 } | |
| 908 | |
| 909 void GLClearColor(Dart_NativeArguments arguments) { | |
| 910 LOGI("GLClearColor"); | |
| 911 Dart_EnterScope(); | |
| 912 | |
| 913 Dart_Handle redHandle = HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 914 double red; | |
| 915 HandleError(Dart_DoubleValue(redHandle, &red)); | |
| 916 | |
| 917 Dart_Handle greenHandle = HandleError(Dart_GetNativeArgument(arguments, 1)); | |
| 918 double green; | |
| 919 HandleError(Dart_DoubleValue(greenHandle, &green)); | |
| 920 | |
| 921 Dart_Handle blueHandle = HandleError(Dart_GetNativeArgument(arguments, 2)); | |
| 922 double blue; | |
| 923 HandleError(Dart_DoubleValue(blueHandle, &blue)); | |
| 924 | |
| 925 Dart_Handle alphaHandle = HandleError(Dart_GetNativeArgument(arguments, 3)); | |
| 926 double alpha; | |
| 927 HandleError(Dart_DoubleValue(alphaHandle, &alpha)); | |
| 928 | |
| 929 glClearColor(red, green, blue, alpha); | |
| 930 CheckGLError("glClearColor"); | |
| 931 Dart_ExitScope(); | |
| 932 } | |
| 933 | |
| 934 void GLClearDepth(Dart_NativeArguments arguments) { | |
| 935 LOGI("GLClearDepth"); | |
| 936 Dart_EnterScope(); | |
| 937 | |
| 938 Dart_Handle depthHandle = HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 939 double depth; | |
| 940 HandleError(Dart_DoubleValue(depthHandle, &depth)); | |
| 941 | |
| 942 glClearDepthf(depth); | |
| 943 CheckGLError("glClearDepthf"); | |
| 944 Dart_ExitScope(); | |
| 945 } | |
| 946 | |
| 947 void GLClear(Dart_NativeArguments arguments) { | |
| 948 LOGI("GLClear"); | |
| 949 Dart_EnterScope(); | |
| 950 Dart_Handle maskHandle = HandleError(Dart_GetNativeArgument(arguments, 0)); | |
| 951 int64_t mask; | |
| 952 HandleError(Dart_IntegerToInt64(maskHandle, &mask)); | |
| 953 glClear(mask); | |
| 954 CheckGLError("glClear"); | |
| 955 Dart_ExitScope(); | |
| 956 } | |
| 957 | |
| 958 void GLArrayBuffer(Dart_NativeArguments arguments) { | |
| 959 LOGI("GLArrayBuffer"); | |
| 960 Dart_EnterScope(); | |
| 961 Dart_Handle result = HandleError(Dart_NewInteger(GL_ARRAY_BUFFER)); | |
| 962 Dart_SetReturnValue(arguments, result); | |
| 963 Dart_ExitScope(); | |
| 964 } | |
| 965 | |
| 966 void GLColorBufferBit(Dart_NativeArguments arguments) { | |
| 967 LOGI("GLColorBuffer"); | |
| 968 Dart_EnterScope(); | |
| 969 Dart_Handle result = HandleError(Dart_NewInteger(GL_COLOR_BUFFER_BIT)); | |
| 970 Dart_SetReturnValue(arguments, result); | |
| 971 Dart_ExitScope(); | |
| 972 } | |
| 973 | |
| 974 void GLCompileStatus(Dart_NativeArguments arguments) { | |
| 975 LOGI("GLCompileStatus"); | |
| 976 Dart_EnterScope(); | |
| 977 Dart_Handle result = HandleError(Dart_NewInteger(GL_COMPILE_STATUS)); | |
| 978 Dart_SetReturnValue(arguments, result); | |
| 979 Dart_ExitScope(); | |
| 980 } | |
| 981 | |
| 982 void GLDepthBufferBit(Dart_NativeArguments arguments) { | |
| 983 LOGI("GLDepthBufferBit"); | |
| 984 Dart_EnterScope(); | |
| 985 Dart_Handle result = HandleError(Dart_NewInteger(GL_DEPTH_BUFFER_BIT)); | |
| 986 Dart_SetReturnValue(arguments, result); | |
| 987 Dart_ExitScope(); | |
| 988 } | |
| 989 | |
| 990 void GLFloat(Dart_NativeArguments arguments) { | |
| 991 Dart_EnterScope(); | |
| 992 Dart_Handle result = HandleError(Dart_NewInteger(GL_FLOAT)); | |
| 993 Dart_SetReturnValue(arguments, result); | |
| 994 Dart_ExitScope(); | |
| 995 } | |
| 996 | |
| 997 void GLFragmentShader(Dart_NativeArguments arguments) { | |
| 998 Dart_EnterScope(); | |
| 999 Dart_Handle result = HandleError(Dart_NewInteger(GL_FRAGMENT_SHADER)); | |
| 1000 Dart_SetReturnValue(arguments, result); | |
| 1001 Dart_ExitScope(); | |
| 1002 } | |
| 1003 | |
| 1004 void GLLinkStatus(Dart_NativeArguments arguments) { | |
| 1005 Dart_EnterScope(); | |
| 1006 Dart_Handle result = HandleError(Dart_NewInteger(GL_LINK_STATUS)); | |
| 1007 Dart_SetReturnValue(arguments, result); | |
| 1008 Dart_ExitScope(); | |
| 1009 } | |
| 1010 | |
| 1011 void GLStaticDraw(Dart_NativeArguments arguments) { | |
| 1012 Dart_EnterScope(); | |
| 1013 Dart_Handle result = HandleError(Dart_NewInteger(GL_STATIC_DRAW)); | |
| 1014 Dart_SetReturnValue(arguments, result); | |
| 1015 Dart_ExitScope(); | |
| 1016 } | |
| 1017 | |
| 1018 void GLTriangleStrip(Dart_NativeArguments arguments) { | |
| 1019 Dart_EnterScope(); | |
| 1020 Dart_Handle result = HandleError(Dart_NewInteger(GL_TRIANGLE_STRIP)); | |
| 1021 Dart_SetReturnValue(arguments, result); | |
| 1022 Dart_ExitScope(); | |
| 1023 } | |
| 1024 | |
| 1025 void GLTriangles(Dart_NativeArguments arguments) { | |
| 1026 Dart_EnterScope(); | |
| 1027 Dart_Handle result = HandleError(Dart_NewInteger(GL_TRIANGLES)); | |
| 1028 Dart_SetReturnValue(arguments, result); | |
| 1029 Dart_ExitScope(); | |
| 1030 } | |
| 1031 | |
| 1032 void GLTrue(Dart_NativeArguments arguments) { | |
| 1033 Dart_EnterScope(); | |
| 1034 Dart_Handle result = HandleError(Dart_NewInteger(GL_TRUE)); | |
| 1035 Dart_SetReturnValue(arguments, result); | |
| 1036 Dart_ExitScope(); | |
| 1037 } | |
| 1038 | |
| 1039 void GLVertexShader(Dart_NativeArguments arguments) { | |
| 1040 Dart_EnterScope(); | |
| 1041 Dart_Handle result = HandleError(Dart_NewInteger(GL_VERTEX_SHADER)); | |
| 1042 Dart_SetReturnValue(arguments, result); | |
| 1043 Dart_ExitScope(); | |
| 1044 } | |
| 1045 | |
| 1046 uint8_t* RandomArray(int seed, int length) { | |
| 1047 if (length <= 0 || length > 10000000) return NULL; | |
| 1048 uint8_t* values = reinterpret_cast<uint8_t*>(malloc(length)); | |
| 1049 if (NULL == values) return NULL; | |
| 1050 srand(seed); | |
| 1051 for (int i = 0; i < length; ++i) { | |
| 1052 values[i] = rand() % 256; | |
| 1053 } | |
| 1054 return values; | |
| 1055 } | |
| 1056 | |
| 1057 void WrappedRandomArray(Dart_Port dest_port_id, | |
| 1058 Dart_Port reply_port_id, | |
| 1059 Dart_CObject* message) { | |
| 1060 if (message->type == Dart_CObject::kArray && | |
| 1061 2 == message->value.as_array.length) { | |
| 1062 // Use .as_array and .as_int32 to access the data in the Dart_CObject. | |
| 1063 Dart_CObject* param0 = message->value.as_array.values[0]; | |
| 1064 Dart_CObject* param1 = message->value.as_array.values[1]; | |
| 1065 if (param0->type == Dart_CObject::kInt32 && | |
| 1066 param1->type == Dart_CObject::kInt32) { | |
| 1067 int length = param0->value.as_int32; | |
| 1068 int seed = param1->value.as_int32; | |
| 1069 | |
| 1070 uint8_t* values = RandomArray(seed, length); | |
| 1071 | |
| 1072 if (values != NULL) { | |
| 1073 Dart_CObject result; | |
| 1074 result.type = Dart_CObject::kUint8Array; | |
| 1075 result.value.as_byte_array.values = values; | |
| 1076 result.value.as_byte_array.length = length; | |
| 1077 Dart_PostCObject(reply_port_id, &result); | |
| 1078 free(values); | |
| 1079 // It is OK that result is destroyed when function exits. | |
| 1080 // Dart_PostCObject has copied its data. | |
| 1081 return; | |
| 1082 } | |
| 1083 } | |
| 1084 } | |
| 1085 Dart_CObject result; | |
| 1086 result.type = Dart_CObject::kNull; | |
| 1087 Dart_PostCObject(reply_port_id, &result); | |
| 1088 } | |
| 1089 | |
| 1090 void RandomArrayServicePort(Dart_NativeArguments arguments) { | |
| 1091 Dart_EnterScope(); | |
| 1092 Dart_SetReturnValue(arguments, Dart_Null()); | |
| 1093 Dart_Port service_port = | |
| 1094 Dart_NewNativePort("RandomArrayService", WrappedRandomArray, true); | |
| 1095 if (service_port != ((Dart_Port)0)) { | |
| 1096 Dart_Handle send_port = HandleError(Dart_NewSendPort(service_port)); | |
| 1097 Dart_SetReturnValue(arguments, send_port); | |
| 1098 } | |
| 1099 Dart_ExitScope(); | |
| 1100 } | |
| 1101 | |
| 1102 void PlayBackground(Dart_NativeArguments arguments) { | |
| 1103 LOGI("PlayBackground"); | |
| 1104 Dart_EnterScope(); | |
| 1105 const char* what = GetStringArg(arguments, 0); | |
| 1106 PlayBackground(what); | |
| 1107 Dart_ExitScope(); | |
| 1108 } | |
| 1109 | |
| 1110 void StopBackground(Dart_NativeArguments arguments) { | |
| 1111 LOGI("StopBackground"); | |
| 1112 Dart_EnterScope(); | |
| 1113 StopBackground(); | |
| 1114 Dart_ExitScope(); | |
| 1115 } | |
| 1116 | |
| 1117 struct FunctionLookup { | |
| 1118 const char* name; | |
| 1119 Dart_NativeFunction function; | |
| 1120 }; | |
| 1121 | |
| 1122 FunctionLookup function_list[] = { | |
| 1123 {"Log", Log}, | |
| 1124 {"SystemRand", SystemRand}, | |
| 1125 {"SystemSrand", SystemSrand}, | |
| 1126 {"EGLSwapBuffers", EGLSwapBuffers}, | |
| 1127 {"GLAttachShader", GLAttachShader}, | |
| 1128 {"GLBindBuffer", GLBindBuffer}, | |
| 1129 {"GLBufferData", GLBufferData}, | |
| 1130 {"GLClear", GLClear}, | |
| 1131 {"GLClearColor", GLClearColor}, | |
| 1132 {"GLClearDepth", GLClearDepth}, | |
| 1133 {"GLCompileShader", GLCompileShader}, | |
| 1134 {"GLCreateBuffer", GLCreateBuffer}, | |
| 1135 {"GLCreateProgram", GLCreateProgram}, | |
| 1136 {"GLCreateShader", GLCreateShader}, | |
| 1137 {"GLDrawArrays", GLDrawArrays}, | |
| 1138 {"GLEnableVertexAttribArray", GLEnableVertexAttribArray}, | |
| 1139 {"GLGetAttribLocation", GLGetAttribLocation}, | |
| 1140 {"GLGetError", GLGetError}, | |
| 1141 {"GLGetProgramParameter", GLGetProgramParameter}, | |
| 1142 {"GLGetShaderParameter", GLGetShaderParameter}, | |
| 1143 {"GLGetUniformLocation", GLGetUniformLocation}, | |
| 1144 {"GLLinkProgram", GLLinkProgram}, | |
| 1145 {"GLShaderSource", GLShaderSource}, | |
| 1146 {"GLUniform1f", GLUniform1f}, | |
| 1147 {"GLUniform2f", GLUniform2f}, | |
| 1148 {"GLUniform3f", GLUniform3f}, | |
| 1149 {"GLUniform4f", GLUniform4f}, | |
| 1150 {"GLUniform1i", GLUniform1i}, | |
| 1151 {"GLUniform2i", GLUniform2i}, | |
| 1152 {"GLUniform3i", GLUniform3i}, | |
| 1153 {"GLUniform4i", GLUniform4i}, | |
| 1154 {"GLUniform1fv", GLUniform1fv}, | |
| 1155 {"GLUniform2fv", GLUniform2fv}, | |
| 1156 {"GLUniform3fv", GLUniform3fv}, | |
| 1157 {"GLUniform4fv", GLUniform4fv}, | |
| 1158 {"GLUniform1iv", GLUniform1iv}, | |
| 1159 {"GLUniform2iv", GLUniform2iv}, | |
| 1160 {"GLUniform3iv", GLUniform3iv}, | |
| 1161 {"GLUniform4iv", GLUniform4iv}, | |
| 1162 {"GLUseProgram", GLUseProgram}, | |
| 1163 {"GLVertexAttribPointer", GLVertexAttribPointer}, | |
| 1164 {"GLViewport", GLViewport}, | |
| 1165 {"GLArrayBuffer", GLArrayBuffer}, | |
| 1166 {"GLColorBufferBit", GLColorBufferBit}, | |
| 1167 {"GLCompileStatus", GLCompileStatus}, | |
| 1168 {"GLDepthBufferBit", GLDepthBufferBit}, | |
| 1169 {"GLFloat", GLFloat}, | |
| 1170 {"GLFragmentShader", GLFragmentShader}, | |
| 1171 {"GLLinkStatus", GLLinkStatus}, | |
| 1172 {"GLTriangleStrip", GLTriangleStrip}, | |
| 1173 {"GLTriangles", GLTriangles}, | |
| 1174 {"GLTrue", GLTrue}, | |
| 1175 {"GLStaticDraw", GLStaticDraw}, | |
| 1176 {"GLVertexShader", GLVertexShader}, | |
| 1177 {"GLGetShaderInfoLog", GLGetShaderInfoLog}, | |
| 1178 {"GLGetProgramInfoLog", GLGetProgramInfoLog}, | |
| 1179 {"RandomArray_ServicePort", RandomArrayServicePort}, | |
| 1180 | |
| 1181 // Audio support. | |
| 1182 {"PlayBackground", PlayBackground}, | |
| 1183 {"StopBackground", StopBackground}, | |
| 1184 | |
| 1185 {NULL, NULL}}; | |
| 1186 | |
| 1187 Dart_NativeFunction ResolveName(Dart_Handle name, int argc) { | |
| 1188 if (!Dart_IsString(name)) return NULL; | |
| 1189 Dart_NativeFunction result = NULL; | |
| 1190 Dart_EnterScope(); | |
| 1191 const char* cname; | |
| 1192 HandleError(Dart_StringToCString(name, &cname)); | |
| 1193 for (int i = 0; function_list[i].name != NULL; ++i) { | |
| 1194 if (strcmp(function_list[i].name, cname) == 0) { | |
| 1195 result = function_list[i].function; | |
| 1196 break; | |
| 1197 } | |
| 1198 } | |
| 1199 Dart_ExitScope(); | |
| 1200 return result; | |
| 1201 } | |
| OLD | NEW |