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