| OLD | NEW |
| (Empty) |
| 1 // Copyright 2011, Google Inc. | |
| 2 // All rights reserved. | |
| 3 // | |
| 4 // Redistribution and use in source and binary forms, with or without | |
| 5 // modification, are permitted provided that the following conditions are | |
| 6 // met: | |
| 7 // | |
| 8 // * Redistributions of source code must retain the above copyright | |
| 9 // notice, this list of conditions and the following disclaimer. | |
| 10 // * Redistributions in binary form must reproduce the above | |
| 11 // copyright notice, this list of conditions and the following disclaimer | |
| 12 // in the documentation and/or other materials provided with the | |
| 13 // distribution. | |
| 14 // * Neither the name of Google Inc. nor the names of its | |
| 15 // contributors may be used to endorse or promote products derived from | |
| 16 // this software without specific prior written permission. | |
| 17 // | |
| 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 | |
| 30 #include "config.h" | |
| 31 | |
| 32 #include "bindings/core/dart/DartWebGLRenderingContext.h" | |
| 33 | |
| 34 #include "bindings/core/dart/DartANGLEInstancedArrays.h" | |
| 35 #include "bindings/core/dart/DartDOMWrapper.h" | |
| 36 #include "bindings/core/dart/DartEXTFragDepth.h" | |
| 37 #include "bindings/core/dart/DartEXTTextureFilterAnisotropic.h" | |
| 38 #include "bindings/core/dart/DartHTMLCanvasElement.h" | |
| 39 #include "bindings/core/dart/DartHTMLImageElement.h" | |
| 40 #include "bindings/core/dart/DartHTMLVideoElement.h" | |
| 41 #include "bindings/core/dart/DartImageData.h" | |
| 42 #include "bindings/core/dart/DartOESElementIndexUint.h" | |
| 43 #include "bindings/core/dart/DartOESStandardDerivatives.h" | |
| 44 #include "bindings/core/dart/DartOESTextureFloat.h" | |
| 45 #include "bindings/core/dart/DartOESTextureFloatLinear.h" | |
| 46 #include "bindings/core/dart/DartOESTextureHalfFloat.h" | |
| 47 #include "bindings/core/dart/DartOESTextureHalfFloatLinear.h" | |
| 48 #include "bindings/core/dart/DartOESVertexArrayObject.h" | |
| 49 #include "bindings/core/dart/DartWebGLBuffer.h" | |
| 50 #include "bindings/core/dart/DartWebGLCompressedTextureATC.h" | |
| 51 #include "bindings/core/dart/DartWebGLCompressedTexturePVRTC.h" | |
| 52 #include "bindings/core/dart/DartWebGLCompressedTextureS3TC.h" | |
| 53 #include "bindings/core/dart/DartWebGLDebugRendererInfo.h" | |
| 54 #include "bindings/core/dart/DartWebGLDebugShaders.h" | |
| 55 #include "bindings/core/dart/DartWebGLDepthTexture.h" | |
| 56 #include "bindings/core/dart/DartWebGLDrawBuffers.h" | |
| 57 #include "bindings/core/dart/DartWebGLFramebuffer.h" | |
| 58 #include "bindings/core/dart/DartWebGLLoseContext.h" | |
| 59 #include "bindings/core/dart/DartWebGLProgram.h" | |
| 60 #include "bindings/core/dart/DartWebGLRenderbuffer.h" | |
| 61 #include "bindings/core/dart/DartWebGLShader.h" | |
| 62 #include "bindings/core/dart/DartWebGLTexture.h" | |
| 63 #include "bindings/core/dart/DartWebGLUniformLocation.h" | |
| 64 #include "bindings/core/dart/DartWebGLVertexArrayObjectOES.h" | |
| 65 #include "core/dom/ExceptionCode.h" | |
| 66 #include "core/html/canvas/WebGLExtensionName.h" | |
| 67 #include "core/html/canvas/WebGLRenderingContext.h" | |
| 68 #include "platform/NotImplemented.h" | |
| 69 | |
| 70 #include <limits> | |
| 71 #include <wtf/FastMalloc.h> | |
| 72 | |
| 73 namespace blink { | |
| 74 | |
| 75 namespace DartWebGLRenderingContextInternal { | |
| 76 | |
| 77 template <class Element> | |
| 78 inline Element toWebGLArrayElement(Dart_Handle, Dart_Handle& exception); | |
| 79 | |
| 80 template <> | |
| 81 inline double toWebGLArrayElement<double>(Dart_Handle object, Dart_Handle& excep
tion) | |
| 82 { | |
| 83 return DartUtilities::dartToDouble(object, exception); | |
| 84 } | |
| 85 | |
| 86 template <> | |
| 87 inline float toWebGLArrayElement<float>(Dart_Handle object, Dart_Handle& excepti
on) | |
| 88 { | |
| 89 return DartUtilities::dartToDouble(object, exception); | |
| 90 } | |
| 91 | |
| 92 template <> | |
| 93 inline int8_t toWebGLArrayElement<int8_t>(Dart_Handle object, Dart_Handle& excep
tion) | |
| 94 { | |
| 95 return DartUtilities::toInteger(object, exception); | |
| 96 } | |
| 97 | |
| 98 template <> | |
| 99 inline int16_t toWebGLArrayElement<int16_t>(Dart_Handle object, Dart_Handle& exc
eption) | |
| 100 { | |
| 101 return DartUtilities::toInteger(object, exception); | |
| 102 } | |
| 103 | |
| 104 template <> | |
| 105 inline int32_t toWebGLArrayElement<int32_t>(Dart_Handle object, Dart_Handle& exc
eption) | |
| 106 { | |
| 107 return DartUtilities::toInteger(object, exception); | |
| 108 } | |
| 109 | |
| 110 template <> | |
| 111 inline int64_t toWebGLArrayElement<int64_t>(Dart_Handle object, Dart_Handle& exc
eption) | |
| 112 { | |
| 113 return DartUtilities::toInteger(object, exception); | |
| 114 } | |
| 115 | |
| 116 template <> | |
| 117 inline uint8_t toWebGLArrayElement<uint8_t>(Dart_Handle object, Dart_Handle& exc
eption) | |
| 118 { | |
| 119 return DartUtilities::toInteger(object, exception); | |
| 120 } | |
| 121 | |
| 122 template <> | |
| 123 inline uint16_t toWebGLArrayElement<uint16_t>(Dart_Handle object, Dart_Handle& e
xception) | |
| 124 { | |
| 125 return DartUtilities::toInteger(object, exception); | |
| 126 } | |
| 127 | |
| 128 template <> | |
| 129 inline uint32_t toWebGLArrayElement<uint32_t>(Dart_Handle object, Dart_Handle& e
xception) | |
| 130 { | |
| 131 return DartUtilities::toInteger(object, exception); | |
| 132 } | |
| 133 | |
| 134 template <class Element> | |
| 135 inline void dartListToVector(Dart_Handle list, Vector<Element>& array, Dart_Hand
le& exception) | |
| 136 { | |
| 137 // FIXME: create vector from list for primitive types | |
| 138 // without element-by-element copying and conversion. | |
| 139 // Need VM support. | |
| 140 DartUtilities::toVector(&toWebGLArrayElement<Element>, list, array, exceptio
n); | |
| 141 } | |
| 142 | |
| 143 template <class Array> | |
| 144 struct TypedArrayTraits; | |
| 145 | |
| 146 template <> | |
| 147 struct TypedArrayTraits<Int8Array> { | |
| 148 typedef int8_t ElementType; | |
| 149 typedef int ReturnedElementType; | |
| 150 }; | |
| 151 | |
| 152 template <> | |
| 153 struct TypedArrayTraits<Int16Array> { | |
| 154 typedef int16_t ElementType; | |
| 155 typedef int ReturnedElementType; | |
| 156 }; | |
| 157 | |
| 158 template <> | |
| 159 struct TypedArrayTraits<Int32Array> { | |
| 160 typedef int32_t ElementType; | |
| 161 typedef int ReturnedElementType; | |
| 162 }; | |
| 163 | |
| 164 template <> | |
| 165 struct TypedArrayTraits<Uint8Array> { | |
| 166 typedef uint8_t ElementType; | |
| 167 typedef unsigned ReturnedElementType; | |
| 168 }; | |
| 169 | |
| 170 template <> | |
| 171 struct TypedArrayTraits<Uint8ClampedArray> { | |
| 172 typedef uint8_t ElementType; | |
| 173 typedef unsigned ReturnedElementType; | |
| 174 }; | |
| 175 | |
| 176 template <> | |
| 177 struct TypedArrayTraits<Uint16Array> { | |
| 178 typedef uint16_t ElementType; | |
| 179 typedef unsigned ReturnedElementType; | |
| 180 }; | |
| 181 | |
| 182 template <> | |
| 183 struct TypedArrayTraits<Uint32Array> { | |
| 184 typedef uint32_t ElementType; | |
| 185 typedef unsigned ReturnedElementType; | |
| 186 }; | |
| 187 | |
| 188 template <> | |
| 189 struct TypedArrayTraits<Float32Array> { | |
| 190 typedef float ElementType; | |
| 191 typedef float ReturnedElementType; | |
| 192 }; | |
| 193 | |
| 194 template <> | |
| 195 struct TypedArrayTraits<Float64Array> { | |
| 196 typedef double ElementType; | |
| 197 typedef double ReturnedElementType; | |
| 198 }; | |
| 199 | |
| 200 template<typename ElementType> | |
| 201 struct ToDartTraits { | |
| 202 }; | |
| 203 | |
| 204 template<> | |
| 205 struct ToDartTraits<String> { | |
| 206 static Dart_Handle toDart(const String& value) { return DartUtilities::strin
gToDart(value); } | |
| 207 }; | |
| 208 | |
| 209 template<> | |
| 210 struct ToDartTraits<bool> { | |
| 211 static Dart_Handle toDart(bool value) { return DartUtilities::boolToDart(val
ue); } | |
| 212 }; | |
| 213 | |
| 214 template<> | |
| 215 struct ToDartTraits<int> { | |
| 216 static Dart_Handle toDart(int value) { return DartUtilities::intToDart(value
); } | |
| 217 }; | |
| 218 | |
| 219 template<> | |
| 220 struct ToDartTraits<unsigned> { | |
| 221 static Dart_Handle toDart(unsigned value) { return DartUtilities::unsignedTo
Dart(value); } | |
| 222 }; | |
| 223 | |
| 224 template<> | |
| 225 struct ToDartTraits<float> { | |
| 226 static Dart_Handle toDart(float value) { return DartUtilities::doubleToDart(
value); } | |
| 227 }; | |
| 228 | |
| 229 template<> | |
| 230 struct ToDartTraits<double> { | |
| 231 static Dart_Handle toDart(double value) { return DartUtilities::doubleToDart
(value); } | |
| 232 }; | |
| 233 | |
| 234 template<typename T> | |
| 235 static Dart_Handle vectorToDart(const Vector<T>& vector) | |
| 236 { | |
| 237 Dart_Handle list = Dart_NewList(vector.size()); | |
| 238 if (Dart_IsError(list)) | |
| 239 return list; | |
| 240 for (size_t i = 0; i < vector.size(); i++) { | |
| 241 Dart_Handle element = ToDartTraits<T>::toDart(vector[i]); | |
| 242 Dart_Handle result = Dart_ListSetAt(list, i, element); | |
| 243 if (Dart_IsError(result)) | |
| 244 return result; | |
| 245 } | |
| 246 return list; | |
| 247 } | |
| 248 | |
| 249 static Dart_Handle webGLExtensionToDart(WebGLExtension* extension) | |
| 250 { | |
| 251 if (!extension) | |
| 252 return Dart_Null(); | |
| 253 switch (extension->name()) { | |
| 254 case WebGLLoseContextName: | |
| 255 return DartWebGLLoseContext::toDart(static_cast<WebGLLoseContext*>(exten
sion)); | |
| 256 case WebGLDrawBuffersName: | |
| 257 return DartWebGLDrawBuffers::toDart(static_cast<WebGLDrawBuffers*>(exten
sion)); | |
| 258 case ANGLEInstancedArraysName: | |
| 259 return DartANGLEInstancedArrays::toDart(static_cast<ANGLEInstancedArrays
*>(extension)); | |
| 260 case EXTFragDepthName: | |
| 261 return DartEXTFragDepth::toDart(static_cast<EXTFragDepth*>(extension)); | |
| 262 case EXTTextureFilterAnisotropicName: | |
| 263 return DartEXTTextureFilterAnisotropic::toDart(static_cast<EXTTextureFil
terAnisotropic*>(extension)); | |
| 264 case OESStandardDerivativesName: | |
| 265 return DartOESStandardDerivatives::toDart(static_cast<OESStandardDerivat
ives*>(extension)); | |
| 266 case OESTextureFloatName: | |
| 267 return DartOESTextureFloat::toDart(static_cast<OESTextureFloat*>(extensi
on)); | |
| 268 case OESTextureFloatLinearName: | |
| 269 return DartOESTextureFloatLinear::toDart(static_cast<OESTextureFloatLine
ar*>(extension)); | |
| 270 case OESTextureHalfFloatName: | |
| 271 return DartOESTextureHalfFloat::toDart(static_cast<OESTextureHalfFloat*>
(extension)); | |
| 272 case OESTextureHalfFloatLinearName: | |
| 273 return DartOESTextureHalfFloatLinear::toDart(static_cast<OESTextureHalfF
loatLinear*>(extension)); | |
| 274 case OESVertexArrayObjectName: | |
| 275 return DartOESVertexArrayObject::toDart(static_cast<OESVertexArrayObject
*>(extension)); | |
| 276 case OESElementIndexUintName: | |
| 277 return DartOESElementIndexUint::toDart(static_cast<OESElementIndexUint*>
(extension)); | |
| 278 case WebGLDebugRendererInfoName: | |
| 279 return DartWebGLDebugRendererInfo::toDart(static_cast<WebGLDebugRenderer
Info*>(extension)); | |
| 280 case WebGLDebugShadersName: | |
| 281 return DartWebGLDebugShaders::toDart(static_cast<WebGLDebugShaders*>(ext
ension)); | |
| 282 case WebGLCompressedTextureATCName: | |
| 283 return DartWebGLCompressedTextureATC::toDart(static_cast<WebGLCompressed
TextureATC*>(extension)); | |
| 284 case WebGLCompressedTexturePVRTCName: | |
| 285 return DartWebGLCompressedTexturePVRTC::toDart(static_cast<WebGLCompress
edTexturePVRTC*>(extension)); | |
| 286 case WebGLCompressedTextureS3TCName: | |
| 287 return DartWebGLCompressedTextureS3TC::toDart(static_cast<WebGLCompresse
dTextureS3TC*>(extension)); | |
| 288 case WebGLDepthTextureName: | |
| 289 return DartWebGLDepthTexture::toDart(static_cast<WebGLDepthTexture*>(ext
ension)); | |
| 290 default: | |
| 291 ASSERT_NOT_REACHED(); | |
| 292 } | |
| 293 | |
| 294 ASSERT_NOT_REACHED(); | |
| 295 return Dart_Null(); | |
| 296 } | |
| 297 | |
| 298 static Dart_Handle webGLGetInfoToDart(const WebGLGetInfo& info) | |
| 299 { | |
| 300 switch (info.getType()) { | |
| 301 case WebGLGetInfo::kTypeBool: | |
| 302 return DartUtilities::boolToDart(info.getBool()); | |
| 303 case WebGLGetInfo::kTypeBoolArray: | |
| 304 return vectorToDart(info.getBoolArray()); | |
| 305 case WebGLGetInfo::kTypeFloat: | |
| 306 return DartUtilities::doubleToDart(info.getFloat()); | |
| 307 case WebGLGetInfo::kTypeInt: | |
| 308 return DartUtilities::intToDart(info.getInt()); | |
| 309 case WebGLGetInfo::kTypeNull: | |
| 310 return Dart_Null(); | |
| 311 case WebGLGetInfo::kTypeString: | |
| 312 return DartUtilities::stringToDart(info.getString()); | |
| 313 case WebGLGetInfo::kTypeUnsignedInt: | |
| 314 return DartUtilities::unsignedToDart(info.getUnsignedInt()); | |
| 315 case WebGLGetInfo::kTypeWebGLBuffer: | |
| 316 return DartWebGLBuffer::toDart(info.getWebGLBuffer()); | |
| 317 case WebGLGetInfo::kTypeWebGLFloatArray: | |
| 318 return DartUtilities::arrayBufferViewToDart(info.getWebGLFloatArray()); | |
| 319 case WebGLGetInfo::kTypeWebGLFramebuffer: | |
| 320 return DartWebGLFramebuffer::toDart(info.getWebGLFramebuffer()); | |
| 321 case WebGLGetInfo::kTypeWebGLIntArray: | |
| 322 return DartUtilities::arrayBufferViewToDart(info.getWebGLIntArray()); | |
| 323 case WebGLGetInfo::kTypeWebGLObjectArray: | |
| 324 // FIXME: implement WebGLObjectArray. | |
| 325 return DART_UNIMPLEMENTED_EXCEPTION(); | |
| 326 case WebGLGetInfo::kTypeWebGLProgram: | |
| 327 return DartWebGLProgram::toDart(info.getWebGLProgram()); | |
| 328 case WebGLGetInfo::kTypeWebGLRenderbuffer: | |
| 329 return DartWebGLRenderbuffer::toDart(info.getWebGLRenderbuffer()); | |
| 330 case WebGLGetInfo::kTypeWebGLTexture: | |
| 331 return DartWebGLTexture::toDart(info.getWebGLTexture()); | |
| 332 case WebGLGetInfo::kTypeWebGLUnsignedByteArray: | |
| 333 return DartUtilities::arrayBufferViewToDart(info.getWebGLUnsignedByteArr
ay()); | |
| 334 case WebGLGetInfo::kTypeWebGLUnsignedIntArray: | |
| 335 return DartUtilities::arrayBufferViewToDart(info.getWebGLUnsignedIntArra
y()); | |
| 336 case WebGLGetInfo::kTypeWebGLVertexArrayObjectOES: | |
| 337 return DartWebGLVertexArrayObjectOES::toDart(info.getWebGLVertexArrayObj
ectOES()); | |
| 338 } | |
| 339 | |
| 340 ASSERT_NOT_REACHED(); | |
| 341 return Dart_Null(); | |
| 342 } | |
| 343 | |
| 344 enum ObjectType { | |
| 345 kBuffer, kRenderbuffer, kTexture, kVertexAttrib | |
| 346 }; | |
| 347 | |
| 348 static void getObjectParameter(Dart_NativeArguments args, ObjectType objectType) | |
| 349 { | |
| 350 Dart_Handle exception = 0; | |
| 351 { | |
| 352 WebGLRenderingContext* context = DartDOMWrapper::receiver<WebGLRendering
Context>(args); | |
| 353 int target = DartUtilities::dartToInt(Dart_GetNativeArgument(args, 1), e
xception); | |
| 354 if (exception) | |
| 355 goto fail; | |
| 356 int pname = DartUtilities::dartToInt(Dart_GetNativeArgument(args, 2), ex
ception); | |
| 357 if (exception) | |
| 358 goto fail; | |
| 359 | |
| 360 WebGLGetInfo info; | |
| 361 switch (objectType) { | |
| 362 case kBuffer: | |
| 363 info = context->getBufferParameter(target, pname); | |
| 364 break; | |
| 365 case kRenderbuffer: | |
| 366 info = context->getRenderbufferParameter(target, pname); | |
| 367 break; | |
| 368 case kTexture: | |
| 369 info = context->getTexParameter(target, pname); | |
| 370 break; | |
| 371 case kVertexAttrib: | |
| 372 // target => index | |
| 373 info = context->getVertexAttrib(target, pname); | |
| 374 break; | |
| 375 default: | |
| 376 notImplemented(); | |
| 377 break; | |
| 378 } | |
| 379 Dart_Handle result = webGLGetInfoToDart(info); | |
| 380 if (!DartUtilities::checkResult(result, exception)) | |
| 381 goto fail; | |
| 382 | |
| 383 Dart_SetReturnValue(args, result); | |
| 384 return; | |
| 385 } | |
| 386 | |
| 387 fail: | |
| 388 Dart_ThrowException(exception); | |
| 389 ASSERT_NOT_REACHED(); | |
| 390 } | |
| 391 | |
| 392 void getBufferParameterCallback(Dart_NativeArguments args) | |
| 393 { | |
| 394 getObjectParameter(args, kBuffer); | |
| 395 } | |
| 396 | |
| 397 void getExtensionCallback(Dart_NativeArguments args) | |
| 398 { | |
| 399 Dart_Handle exception = 0; | |
| 400 { | |
| 401 WebGLRenderingContext* context = DartDOMWrapper::receiver<WebGLRendering
Context>(args); | |
| 402 DartStringAdapter name = DartUtilities::dartToString(args, 1, exception)
; | |
| 403 if (exception) | |
| 404 goto fail; | |
| 405 | |
| 406 WebGLExtension* extension = context->getExtension(name).get(); | |
| 407 Dart_Handle result = webGLExtensionToDart(extension); | |
| 408 if (!DartUtilities::checkResult(result, exception)) | |
| 409 goto fail; | |
| 410 Dart_SetReturnValue(args, result); | |
| 411 return; | |
| 412 } | |
| 413 | |
| 414 fail: | |
| 415 Dart_ThrowException(exception); | |
| 416 ASSERT_NOT_REACHED(); | |
| 417 } | |
| 418 | |
| 419 void getFramebufferAttachmentParameterCallback(Dart_NativeArguments args) | |
| 420 { | |
| 421 Dart_Handle exception = 0; | |
| 422 { | |
| 423 WebGLRenderingContext* context = DartDOMWrapper::receiver<WebGLRendering
Context>(args); | |
| 424 int target = DartUtilities::dartToInt(Dart_GetNativeArgument(args, 1), e
xception); | |
| 425 if (exception) | |
| 426 goto fail; | |
| 427 int attachment = DartUtilities::dartToInt(Dart_GetNativeArgument(args, 2
), exception); | |
| 428 if (exception) | |
| 429 goto fail; | |
| 430 int pname = DartUtilities::dartToInt(Dart_GetNativeArgument(args, 3), ex
ception); | |
| 431 if (exception) | |
| 432 goto fail; | |
| 433 | |
| 434 WebGLGetInfo info = context->getFramebufferAttachmentParameter(target, a
ttachment, pname); | |
| 435 Dart_Handle result = webGLGetInfoToDart(info); | |
| 436 if (!DartUtilities::checkResult(result, exception)) | |
| 437 goto fail; | |
| 438 Dart_SetReturnValue(args, result); | |
| 439 return; | |
| 440 } | |
| 441 | |
| 442 fail: | |
| 443 Dart_ThrowException(exception); | |
| 444 ASSERT_NOT_REACHED(); | |
| 445 } | |
| 446 | |
| 447 void getParameterCallback(Dart_NativeArguments args) | |
| 448 { | |
| 449 Dart_Handle exception = 0; | |
| 450 { | |
| 451 WebGLRenderingContext* context = DartDOMWrapper::receiver<WebGLRendering
Context>(args); | |
| 452 int pname = DartUtilities::dartToInt(Dart_GetNativeArgument(args, 1), ex
ception); | |
| 453 if (exception) | |
| 454 goto fail; | |
| 455 | |
| 456 WebGLGetInfo info = context->getParameter(pname); | |
| 457 Dart_Handle result = webGLGetInfoToDart(info); | |
| 458 if (!DartUtilities::checkResult(result, exception)) | |
| 459 goto fail; | |
| 460 | |
| 461 Dart_SetReturnValue(args, result); | |
| 462 return; | |
| 463 } | |
| 464 | |
| 465 fail: | |
| 466 Dart_ThrowException(exception); | |
| 467 ASSERT_NOT_REACHED(); | |
| 468 } | |
| 469 | |
| 470 void getProgramParameterCallback(Dart_NativeArguments args) | |
| 471 { | |
| 472 Dart_Handle exception = 0; | |
| 473 { | |
| 474 WebGLRenderingContext* context = DartDOMWrapper::receiver<WebGLRendering
Context>(args); | |
| 475 WebGLProgram* program = DartWebGLProgram::toNativeWithNullCheck(Dart_Get
NativeArgument(args, 1), exception); | |
| 476 if (exception) | |
| 477 goto fail; | |
| 478 int pname = DartUtilities::dartToInt(Dart_GetNativeArgument(args, 2), ex
ception); | |
| 479 if (exception) | |
| 480 goto fail; | |
| 481 | |
| 482 WebGLGetInfo info = context->getProgramParameter(program, pname); | |
| 483 Dart_Handle result = webGLGetInfoToDart(info); | |
| 484 if (!DartUtilities::checkResult(result, exception)) | |
| 485 goto fail; | |
| 486 | |
| 487 Dart_SetReturnValue(args, result); | |
| 488 return; | |
| 489 } | |
| 490 | |
| 491 fail: | |
| 492 Dart_ThrowException(exception); | |
| 493 ASSERT_NOT_REACHED(); | |
| 494 } | |
| 495 | |
| 496 void getRenderbufferParameterCallback(Dart_NativeArguments args) | |
| 497 { | |
| 498 getObjectParameter(args, kRenderbuffer); | |
| 499 } | |
| 500 | |
| 501 void getShaderParameterCallback(Dart_NativeArguments args) | |
| 502 { | |
| 503 Dart_Handle exception = 0; | |
| 504 { | |
| 505 WebGLRenderingContext* context = DartDOMWrapper::receiver<WebGLRendering
Context>(args); | |
| 506 WebGLShader* shader = DartWebGLShader::toNativeWithNullCheck(Dart_GetNat
iveArgument(args, 1), exception); | |
| 507 if (exception) | |
| 508 goto fail; | |
| 509 int pname = DartUtilities::dartToInt(Dart_GetNativeArgument(args, 2), ex
ception); | |
| 510 if (exception) | |
| 511 goto fail; | |
| 512 | |
| 513 WebGLGetInfo info = context->getShaderParameter(shader, pname); | |
| 514 Dart_Handle result = webGLGetInfoToDart(info); | |
| 515 if (!DartUtilities::checkResult(result, exception)) | |
| 516 goto fail; | |
| 517 | |
| 518 Dart_SetReturnValue(args, result); | |
| 519 return; | |
| 520 } | |
| 521 | |
| 522 fail: | |
| 523 Dart_ThrowException(exception); | |
| 524 ASSERT_NOT_REACHED(); | |
| 525 } | |
| 526 | |
| 527 void getSupportedExtensionsCallback(Dart_NativeArguments args) | |
| 528 { | |
| 529 Dart_Handle exception = 0; | |
| 530 { | |
| 531 WebGLRenderingContext* context = DartDOMWrapper::receiver<WebGLRendering
Context>(args); | |
| 532 Nullable<Vector<String>> value = context->getSupportedExtensions(); | |
| 533 if (value.isNull()) { | |
| 534 // Return null. | |
| 535 return; | |
| 536 } | |
| 537 | |
| 538 Dart_Handle result = vectorToDart(value.get()); | |
| 539 if (!DartUtilities::checkResult(result, exception)) | |
| 540 goto fail; | |
| 541 | |
| 542 Dart_SetReturnValue(args, result); | |
| 543 return; | |
| 544 } | |
| 545 | |
| 546 fail: | |
| 547 Dart_ThrowException(exception); | |
| 548 ASSERT_NOT_REACHED(); | |
| 549 } | |
| 550 | |
| 551 void getTexParameterCallback(Dart_NativeArguments args) | |
| 552 { | |
| 553 getObjectParameter(args, kTexture); | |
| 554 } | |
| 555 | |
| 556 void getUniformCallback(Dart_NativeArguments args) | |
| 557 { | |
| 558 getObjectParameter(args, kVertexAttrib); | |
| 559 } | |
| 560 | |
| 561 void getVertexAttribCallback(Dart_NativeArguments args) | |
| 562 { | |
| 563 getObjectParameter(args, kVertexAttrib); | |
| 564 } | |
| 565 | |
| 566 enum FunctionToCall { | |
| 567 kUniform1v, kUniform2v, kUniform3v, kUniform4v, | |
| 568 kVertexAttrib1v, kVertexAttrib2v, kVertexAttrib3v, kVertexAttrib4v | |
| 569 }; | |
| 570 | |
| 571 static inline bool isFunctionToCallForAttribute(FunctionToCall functionToCall) | |
| 572 { | |
| 573 switch (functionToCall) { | |
| 574 case kVertexAttrib1v: | |
| 575 case kVertexAttrib2v: | |
| 576 case kVertexAttrib3v: | |
| 577 case kVertexAttrib4v: | |
| 578 return true; | |
| 579 default: | |
| 580 break; | |
| 581 } | |
| 582 return false; | |
| 583 } | |
| 584 | |
| 585 static void vertexAttribAndUniformHelperf(Dart_NativeArguments args, FunctionToC
all functionToCall) | |
| 586 { | |
| 587 Dart_Handle exception = 0; | |
| 588 { | |
| 589 // Forms: | |
| 590 // * glUniform1fv(WebGLUniformLocation location, Array data); | |
| 591 // * glUniform1fv(WebGLUniformLocation location, Float32Array data); | |
| 592 // * glUniform2fv(WebGLUniformLocation location, Array data); | |
| 593 // * glUniform2fv(WebGLUniformLocation location, Float32Array data); | |
| 594 // * glUniform3fv(WebGLUniformLocation location, Array data); | |
| 595 // * glUniform3fv(WebGLUniformLocation location, Float32Array data); | |
| 596 // * glUniform4fv(WebGLUniformLocation location, Array data); | |
| 597 // * glUniform4fv(WebGLUniformLocation location, Float32Array data); | |
| 598 // * glVertexAttrib1fv(GLint index, Array data); | |
| 599 // * glVertexAttrib1fv(GLint index, Float32Array data); | |
| 600 // * glVertexAttrib2fv(GLint index, Array data); | |
| 601 // * glVertexAttrib2fv(GLint index, Float32Array data); | |
| 602 // * glVertexAttrib3fv(GLint index, Array data); | |
| 603 // * glVertexAttrib3fv(GLint index, Float32Array data); | |
| 604 // * glVertexAttrib4fv(GLint index, Array data); | |
| 605 // * glVertexAttrib4fv(GLint index, Float32Array data); | |
| 606 WebGLRenderingContext* context = DartDOMWrapper::receiver<WebGLRendering
Context>(args); | |
| 607 int index = -1; | |
| 608 WebGLUniformLocation* location = 0; | |
| 609 | |
| 610 if (isFunctionToCallForAttribute(functionToCall)) { | |
| 611 int indexParam = DartUtilities::dartToInt(Dart_GetNativeArgument(arg
s, 1), exception); | |
| 612 if (exception) | |
| 613 goto fail; | |
| 614 index = indexParam; | |
| 615 } else { | |
| 616 WebGLUniformLocation* locationParam = DartWebGLUniformLocation::toNa
tiveWithNullCheck(Dart_GetNativeArgument(args, 1), exception); | |
| 617 if (exception) | |
| 618 goto fail; | |
| 619 location = locationParam; | |
| 620 } | |
| 621 | |
| 622 RefPtr<Float32Array> array = DartUtilities::dartToFloat32Array(Dart_GetN
ativeArgument(args, 2), exception); | |
| 623 if (exception) | |
| 624 goto fail; | |
| 625 | |
| 626 switch (functionToCall) { | |
| 627 case kUniform1v: | |
| 628 context->uniform1fv(location, array.get()); | |
| 629 break; | |
| 630 case kUniform2v: | |
| 631 context->uniform2fv(location, array.get()); | |
| 632 break; | |
| 633 case kUniform3v: | |
| 634 context->uniform3fv(location, array.get()); | |
| 635 break; | |
| 636 case kUniform4v: | |
| 637 context->uniform4fv(location, array.get()); | |
| 638 break; | |
| 639 case kVertexAttrib1v: | |
| 640 context->vertexAttrib1fv(index, array.get()); | |
| 641 break; | |
| 642 case kVertexAttrib2v: | |
| 643 context->vertexAttrib2fv(index, array.get()); | |
| 644 break; | |
| 645 case kVertexAttrib3v: | |
| 646 context->vertexAttrib3fv(index, array.get()); | |
| 647 break; | |
| 648 case kVertexAttrib4v: | |
| 649 context->vertexAttrib4fv(index, array.get()); | |
| 650 break; | |
| 651 } | |
| 652 return; | |
| 653 } | |
| 654 | |
| 655 fail: | |
| 656 Dart_ThrowException(exception); | |
| 657 ASSERT_NOT_REACHED(); | |
| 658 } | |
| 659 | |
| 660 static void uniformHelperi(Dart_NativeArguments args, FunctionToCall functionToC
all) | |
| 661 { | |
| 662 Dart_Handle exception = 0; | |
| 663 { | |
| 664 // Forms: | |
| 665 // * glUniform1iv(GLUniformLocation location, Array data); | |
| 666 // * glUniform1iv(GLUniformLocation location, Int32Array data); | |
| 667 // * glUniform2iv(GLUniformLocation location, Array data); | |
| 668 // * glUniform2iv(GLUniformLocation location, Int32Array data); | |
| 669 // * glUniform3iv(GLUniformLocation location, Array data); | |
| 670 // * glUniform3iv(GLUniformLocation location, Int32Array data); | |
| 671 // * glUniform4iv(GLUniformLocation location, Array data); | |
| 672 // * glUniform4iv(GLUniformLocation location, Int32Array data); | |
| 673 WebGLRenderingContext* context = DartDOMWrapper::receiver<WebGLRendering
Context>(args); | |
| 674 WebGLUniformLocation* location = DartWebGLUniformLocation::toNativeWithN
ullCheck(Dart_GetNativeArgument(args, 1), exception); | |
| 675 if (exception) | |
| 676 goto fail; | |
| 677 | |
| 678 RefPtr<Int32Array> array = DartUtilities::dartToInt32Array(Dart_GetNativ
eArgument(args, 2), exception); | |
| 679 if (exception) | |
| 680 goto fail; | |
| 681 | |
| 682 switch (functionToCall) { | |
| 683 case kUniform1v: | |
| 684 context->uniform1iv(location, array.get()); | |
| 685 break; | |
| 686 case kUniform2v: | |
| 687 context->uniform2iv(location, array.get()); | |
| 688 break; | |
| 689 case kUniform3v: | |
| 690 context->uniform3iv(location, array.get()); | |
| 691 break; | |
| 692 case kUniform4v: | |
| 693 context->uniform4iv(location, array.get()); | |
| 694 break; | |
| 695 default: | |
| 696 ASSERT_NOT_REACHED(); | |
| 697 break; | |
| 698 } | |
| 699 return; | |
| 700 } | |
| 701 | |
| 702 fail: | |
| 703 Dart_ThrowException(exception); | |
| 704 ASSERT_NOT_REACHED(); | |
| 705 } | |
| 706 | |
| 707 static void uniformMatrixHelper(Dart_NativeArguments args, int matrixSize) | |
| 708 { | |
| 709 Dart_Handle exception = 0; | |
| 710 { | |
| 711 // Forms: | |
| 712 // * glUniformMatrix2fv(GLint location, GLboolean transpose, Array data)
; | |
| 713 // * glUniformMatrix2fv(GLint location, GLboolean transpose, Float32Arra
y data); | |
| 714 // * glUniformMatrix3fv(GLint location, GLboolean transpose, Array data)
; | |
| 715 // * glUniformMatrix3fv(GLint location, GLboolean transpose, Float32Arra
y data); | |
| 716 // * glUniformMatrix4fv(GLint location, GLboolean transpose, Array data)
; | |
| 717 // * glUniformMatrix4fv(GLint location, GLboolean transpose, Float32Arra
y data); | |
| 718 // | |
| 719 WebGLRenderingContext* context = DartDOMWrapper::receiver<WebGLRendering
Context>(args); | |
| 720 WebGLUniformLocation* location = DartWebGLUniformLocation::toNativeWithN
ullCheck(Dart_GetNativeArgument(args, 1), exception); | |
| 721 if (exception) | |
| 722 goto fail; | |
| 723 bool transpose = DartUtilities::dartToBool(Dart_GetNativeArgument(args,
2), exception); | |
| 724 if (exception) | |
| 725 goto fail; | |
| 726 | |
| 727 RefPtr<Float32Array> array = DartUtilities::dartToFloat32Array(Dart_GetN
ativeArgument(args, 3), exception); | |
| 728 if (exception) | |
| 729 goto fail; | |
| 730 | |
| 731 switch (matrixSize) { | |
| 732 case 2: | |
| 733 context->uniformMatrix2fv(location, transpose, array.get()); | |
| 734 break; | |
| 735 case 3: | |
| 736 context->uniformMatrix3fv(location, transpose, array.get()); | |
| 737 break; | |
| 738 case 4: | |
| 739 context->uniformMatrix4fv(location, transpose, array.get()); | |
| 740 break; | |
| 741 default: | |
| 742 ASSERT_NOT_REACHED(); | |
| 743 break; | |
| 744 } | |
| 745 return; | |
| 746 } | |
| 747 | |
| 748 fail: | |
| 749 Dart_ThrowException(exception); | |
| 750 ASSERT_NOT_REACHED(); | |
| 751 } | |
| 752 | |
| 753 void uniform1fvCallback(Dart_NativeArguments args) | |
| 754 { | |
| 755 vertexAttribAndUniformHelperf(args, kUniform1v); | |
| 756 } | |
| 757 | |
| 758 void uniform1ivCallback(Dart_NativeArguments args) | |
| 759 { | |
| 760 uniformHelperi(args, kUniform1v); | |
| 761 } | |
| 762 | |
| 763 void uniform2fvCallback(Dart_NativeArguments args) | |
| 764 { | |
| 765 vertexAttribAndUniformHelperf(args, kUniform2v); | |
| 766 } | |
| 767 | |
| 768 void uniform2ivCallback(Dart_NativeArguments args) | |
| 769 { | |
| 770 uniformHelperi(args, kUniform2v); | |
| 771 } | |
| 772 | |
| 773 void uniform3fvCallback(Dart_NativeArguments args) | |
| 774 { | |
| 775 vertexAttribAndUniformHelperf(args, kUniform3v); | |
| 776 } | |
| 777 | |
| 778 void uniform3ivCallback(Dart_NativeArguments args) | |
| 779 { | |
| 780 uniformHelperi(args, kUniform3v); | |
| 781 } | |
| 782 | |
| 783 void uniform4fvCallback(Dart_NativeArguments args) | |
| 784 { | |
| 785 vertexAttribAndUniformHelperf(args, kUniform4v); | |
| 786 } | |
| 787 | |
| 788 void uniform4ivCallback(Dart_NativeArguments args) | |
| 789 { | |
| 790 uniformHelperi(args, kUniform4v); | |
| 791 } | |
| 792 | |
| 793 void uniformMatrix2fvCallback(Dart_NativeArguments args) | |
| 794 { | |
| 795 uniformMatrixHelper(args, 2); | |
| 796 } | |
| 797 | |
| 798 void uniformMatrix3fvCallback(Dart_NativeArguments args) | |
| 799 { | |
| 800 uniformMatrixHelper(args, 3); | |
| 801 } | |
| 802 | |
| 803 void uniformMatrix4fvCallback(Dart_NativeArguments args) | |
| 804 { | |
| 805 uniformMatrixHelper(args, 4); | |
| 806 } | |
| 807 | |
| 808 void vertexAttrib1fvCallback(Dart_NativeArguments args) | |
| 809 { | |
| 810 vertexAttribAndUniformHelperf(args, kVertexAttrib1v); | |
| 811 } | |
| 812 | |
| 813 void vertexAttrib2fvCallback(Dart_NativeArguments args) | |
| 814 { | |
| 815 vertexAttribAndUniformHelperf(args, kVertexAttrib2v); | |
| 816 } | |
| 817 | |
| 818 void vertexAttrib3fvCallback(Dart_NativeArguments args) | |
| 819 { | |
| 820 vertexAttribAndUniformHelperf(args, kVertexAttrib3v); | |
| 821 } | |
| 822 | |
| 823 void vertexAttrib4fvCallback(Dart_NativeArguments args) | |
| 824 { | |
| 825 vertexAttribAndUniformHelperf(args, kVertexAttrib4v); | |
| 826 } | |
| 827 | |
| 828 } | |
| 829 | |
| 830 } | |
| OLD | NEW |