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