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