Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: Source/WebCore/bindings/dart/custom/DartWebGLRenderingContextCustom.cpp

Issue 9231022: WebGL support. (Closed) Base URL: svn://svn.chromium.org/multivm/trunk/webkit
Patch Set: Review Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2011, Google Inc. 1 // Copyright 2011, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 14 matching lines...) Expand all
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 29
30 #include "config.h" 30 #include "config.h"
31 #include "DartWebGLRenderingContext.h" 31 #include "DartWebGLRenderingContext.h"
32 32
33 #if ENABLE(WEBGL) 33 #if ENABLE(WEBGL)
34 34
35 #include "DartArrayBufferView.h"
36 #include "DartDOMWrapper.h"
37 #include "DartFloat32Array.h"
38 #include "DartHTMLCanvasElement.h"
39 #include "DartHTMLImageElement.h"
40 #include "DartHTMLVideoElement.h"
41 #include "DartImageData.h"
42 #include "DartInt16Array.h"
43 #include "DartInt32Array.h"
44 #include "DartInt8Array.h"
45 #include "DartOESStandardDerivatives.h"
46 #include "DartOESTextureFloat.h"
47 #include "DartOESVertexArrayObject.h"
48 #include "DartUint16Array.h"
49 #include "DartUint32Array.h"
50 #include "DartUint8Array.h"
51 #include "DartWebGLBuffer.h"
52 #include "DartWebGLDebugRendererInfo.h"
53 #include "DartWebGLDebugShaders.h"
54 #include "DartWebGLFramebuffer.h"
55 #include "DartWebGLLoseContext.h"
56 #include "DartWebGLProgram.h"
57 #include "DartWebGLRenderbuffer.h"
58 #include "DartWebGLShader.h"
59 #include "DartWebGLTexture.h"
60 #include "DartWebGLUniformLocation.h"
61 #include "DartWebGLVertexArrayObjectOES.h"
62 #include "ExceptionCode.h"
63 #include "NotImplemented.h"
64 #include "WebGLRenderingContext.h"
65
66 #include <limits>
67 #include <wtf/FastMalloc.h>
68
35 namespace WebCore { 69 namespace WebCore {
36 70
37 namespace DartWebGLRenderingContextInternal { 71 namespace DartWebGLRenderingContextInternal {
38 72
39 void getAttachedShadersCallback(Dart_NativeArguments) 73 static Dart_Handle webGLExtensionToDart(WebGLExtension* extension)
40 { 74 {
41 // FIXME: proper implementation. 75 if (!extension)
42 DART_UNIMPLEMENTED(); 76 return 0;
43 } 77 switch (extension->getName()) {
44 78 case WebGLExtension::WebKitWebGLLoseContextName:
45 void getBufferParameterCallback(Dart_NativeArguments) 79 return toDartValue(static_cast<WebGLLoseContext*>(extension));
46 { 80 case WebGLExtension::OESStandardDerivativesName:
47 // FIXME: proper implementation. 81 return toDartValue(static_cast<OESStandardDerivatives*>(extension));
48 DART_UNIMPLEMENTED(); 82 case WebGLExtension::OESTextureFloatName:
49 } 83 return toDartValue(static_cast<OESTextureFloat*>(extension));
50 84 case WebGLExtension::OESVertexArrayObjectName:
51 void getExtensionCallback(Dart_NativeArguments) 85 return toDartValue(static_cast<OESVertexArrayObject*>(extension));
52 { 86 case WebGLExtension::WebGLDebugRendererInfoName:
53 // FIXME: proper implementation. 87 return toDartValue(static_cast<WebGLDebugRendererInfo*>(extension));
54 DART_UNIMPLEMENTED(); 88 case WebGLExtension::WebGLDebugShadersName:
55 } 89 return toDartValue(static_cast<WebGLDebugShaders*>(extension));
56 90 default:
57 void getFramebufferAttachmentParameterCallback(Dart_NativeArguments) 91 ASSERT_NOT_REACHED();
58 { 92 return 0;
59 // FIXME: proper implementation. 93 }
60 DART_UNIMPLEMENTED(); 94 }
61 } 95
62 96 static Dart_Handle webGLGetInfoToDart(const WebGLGetInfo& info)
63 void getParameterCallback(Dart_NativeArguments) 97 {
64 { 98 switch (info.getType()) {
65 // FIXME: proper implementation. 99 case WebGLGetInfo::kTypeBool:
66 DART_UNIMPLEMENTED(); 100 return toDartValue(info.getBool());
67 } 101 case WebGLGetInfo::kTypeBoolArray:
68 102 return DartUtilities::vectorToDartList(info.getBoolArray());
69 void getProgramParameterCallback(Dart_NativeArguments) 103 case WebGLGetInfo::kTypeFloat:
70 { 104 return toDartValue(info.getFloat());
71 // FIXME: proper implementation. 105 case WebGLGetInfo::kTypeInt:
72 DART_UNIMPLEMENTED(); 106 return toDartValue(info.getInt());
73 } 107 case WebGLGetInfo::kTypeNull:
74 108 return 0;
75 void getRenderbufferParameterCallback(Dart_NativeArguments) 109 case WebGLGetInfo::kTypeString:
76 { 110 return toDartValue(info.getString());
77 // FIXME: proper implementation. 111 case WebGLGetInfo::kTypeUnsignedInt:
78 DART_UNIMPLEMENTED(); 112 return toDartValue(static_cast<intptr_t>(info.getUnsignedInt()));
79 } 113 case WebGLGetInfo::kTypeWebGLBuffer:
80 114 return toDartValue(info.getWebGLBuffer());
81 void getShaderParameterCallback(Dart_NativeArguments) 115 case WebGLGetInfo::kTypeWebGLFloatArray:
82 { 116 return toDartValue(info.getWebGLFloatArray());
83 // FIXME: proper implementation. 117 case WebGLGetInfo::kTypeWebGLFramebuffer:
84 DART_UNIMPLEMENTED(); 118 return toDartValue(info.getWebGLFramebuffer());
85 } 119 case WebGLGetInfo::kTypeWebGLIntArray:
86 120 return toDartValue(info.getWebGLIntArray());
87 void getSupportedExtensionsCallback(Dart_NativeArguments) 121 // FIXME: implement WebGLObjectArray.
88 { 122 // case WebGLGetInfo::kTypeWebGLObjectArray:
89 // FIXME: proper implementation. 123 case WebGLGetInfo::kTypeWebGLProgram:
90 DART_UNIMPLEMENTED(); 124 return toDartValue(info.getWebGLProgram());
91 } 125 case WebGLGetInfo::kTypeWebGLRenderbuffer:
92 126 return toDartValue(info.getWebGLRenderbuffer());
93 void getTexParameterCallback(Dart_NativeArguments) 127 case WebGLGetInfo::kTypeWebGLTexture:
94 { 128 return toDartValue(info.getWebGLTexture());
95 // FIXME: proper implementation. 129 case WebGLGetInfo::kTypeWebGLUnsignedByteArray:
96 DART_UNIMPLEMENTED(); 130 return toDartValue(info.getWebGLUnsignedByteArray());
97 } 131 case WebGLGetInfo::kTypeWebGLVertexArrayObjectOES:
98 132 return toDartValue(info.getWebGLVertexArrayObjectOES());
99 void getUniformCallback(Dart_NativeArguments) 133 default:
100 { 134 ASSERT_NOT_REACHED();
101 // FIXME: proper implementation. 135 return 0;
102 DART_UNIMPLEMENTED(); 136 }
103 } 137 }
104 138
105 void getVertexAttribCallback(Dart_NativeArguments) 139 enum ObjectType {
106 { 140 kBuffer, kRenderbuffer, kTexture, kVertexAttrib
107 // FIXME: proper implementation. 141 };
108 DART_UNIMPLEMENTED(); 142
109 } 143 static void getObjectParameter(Dart_NativeArguments args, ObjectType objectType)
110 144 {
111 void uniform1fvCallback(Dart_NativeArguments) 145 DartApiScope dartApiScope;
112 { 146 Dart_Handle exception;
113 // FIXME: proper implementation. 147 {
114 DART_UNIMPLEMENTED(); 148 ExceptionCode ec = 0;
115 } 149 WebGLRenderingContext* context = DartDOMWrapper::receiver<WebGLRendering Context>(args);
116 150 const ParameterAdapter<int> target(Dart_GetNativeArgument(args, 1));
117 void uniform1ivCallback(Dart_NativeArguments) 151 if (!target.conversionSuccessful()) {
118 { 152 exception = target.exception();
119 // FIXME: proper implementation. 153 goto fail;
120 DART_UNIMPLEMENTED(); 154 }
121 } 155 const ParameterAdapter<int> pname(Dart_GetNativeArgument(args, 2));
122 156 if (!pname.conversionSuccessful()) {
123 void uniform2fvCallback(Dart_NativeArguments) 157 exception = pname.exception();
124 { 158 goto fail;
125 // FIXME: proper implementation. 159 }
126 DART_UNIMPLEMENTED(); 160
127 } 161 WebGLGetInfo info;
128 162 switch (objectType) {
129 void uniform2ivCallback(Dart_NativeArguments) 163 case kBuffer:
130 { 164 info = context->getBufferParameter(target, pname, ec);
131 // FIXME: proper implementation. 165 break;
132 DART_UNIMPLEMENTED(); 166 case kRenderbuffer:
133 } 167 info = context->getRenderbufferParameter(target, pname, ec);
134 168 break;
135 void uniform3fvCallback(Dart_NativeArguments) 169 case kTexture:
136 { 170 info = context->getTexParameter(target, pname, ec);
137 // FIXME: proper implementation. 171 break;
138 DART_UNIMPLEMENTED(); 172 case kVertexAttrib:
139 } 173 // target => index
140 174 info = context->getVertexAttrib(target, pname, ec);
141 void uniform3ivCallback(Dart_NativeArguments) 175 break;
142 { 176 default:
143 // FIXME: proper implementation. 177 notImplemented();
144 DART_UNIMPLEMENTED(); 178 break;
145 } 179 }
146 180 if (UNLIKELY(ec)) {
147 void uniform4fvCallback(Dart_NativeArguments) 181 exception = DartDOMWrapper::exceptionCodeToDartException(ec);
148 { 182 goto fail;
149 // FIXME: proper implementation. 183 }
150 DART_UNIMPLEMENTED(); 184 Dart_Handle result = webGLGetInfoToDart(info);
151 } 185 if (!DartUtilities::checkResult(result, exception))
152 186 goto fail;
153 void uniform4ivCallback(Dart_NativeArguments) 187
154 { 188 Dart_SetReturnValue(args, result);
155 // FIXME: proper implementation. 189 return;
156 DART_UNIMPLEMENTED(); 190 }
157 } 191
158 192 fail:
159 void uniformMatrix2fvCallback(Dart_NativeArguments) 193 Dart_ThrowException(exception);
160 { 194 ASSERT_NOT_REACHED();
161 // FIXME: proper implementation. 195 }
162 DART_UNIMPLEMENTED(); 196
163 } 197 void getAttachedShadersCallback(Dart_NativeArguments args)
164 198 {
165 void uniformMatrix3fvCallback(Dart_NativeArguments) 199 DartApiScope dartApiScope;
166 { 200 Dart_Handle exception = 0;
167 // FIXME: proper implementation. 201 {
168 DART_UNIMPLEMENTED(); 202 WebGLRenderingContext* context = DartDOMWrapper::receiver<WebGLRendering Context>(args);
169 } 203 const ParameterAdapter<RefPtr<WebGLProgram>, DartWebGLProgram> program(D art_GetNativeArgument(args, 1));
170 204 if (!program.conversionSuccessful()) {
171 void uniformMatrix4fvCallback(Dart_NativeArguments) 205 exception = program.exception();
172 { 206 goto fail;
173 // FIXME: proper implementation. 207 }
174 DART_UNIMPLEMENTED(); 208
175 } 209 Vector<RefPtr<WebGLShader> > shaders;
176 210 ExceptionCode ec = 0;
177 void vertexAttrib1fvCallback(Dart_NativeArguments) 211 bool succeed = context->getAttachedShaders(program, shaders, ec);
178 { 212 if (UNLIKELY(ec)) {
179 // FIXME: proper implementation. 213 exception = DartDOMWrapper::exceptionCodeToDartException(ec);
180 DART_UNIMPLEMENTED(); 214 goto fail;
181 } 215 }
182 216 Dart_Handle result;
183 void vertexAttrib2fvCallback(Dart_NativeArguments) 217 if (succeed) {
184 { 218 result = DartUtilities::vectorToDartList(shaders);
185 // FIXME: proper implementation. 219 if (!DartUtilities::checkResult(result, exception))
186 DART_UNIMPLEMENTED(); 220 goto fail;
187 } 221 } else
188 222 result = 0;
189 void vertexAttrib3fvCallback(Dart_NativeArguments) 223 Dart_SetReturnValue(args, result);
190 { 224 return;
191 // FIXME: proper implementation. 225 }
192 DART_UNIMPLEMENTED(); 226
193 } 227 fail:
194 228 Dart_ThrowException(exception);
195 void vertexAttrib4fvCallback(Dart_NativeArguments) 229 ASSERT_NOT_REACHED();
196 { 230 }
197 // FIXME: proper implementation. 231
198 DART_UNIMPLEMENTED(); 232 void getBufferParameterCallback(Dart_NativeArguments args)
199 } 233 {
200 234 getObjectParameter(args, kBuffer);
201 } 235 }
236
237 void getExtensionCallback(Dart_NativeArguments args)
238 {
239 DartApiScope dartApiScope;
240 Dart_Handle exception;
241 {
242 WebGLRenderingContext* context = DartDOMWrapper::receiver<WebGLRendering Context>(args);
243 const ParameterAdapter<String> name(Dart_GetNativeArgument(args, 1));
244 if (!name.conversionSuccessful()) {
245 exception = name.exception();
246 goto fail;
247 }
248
249 WebGLExtension* extension = context->getExtension(name);
250 Dart_Handle result = webGLExtensionToDart(extension);
251 if (!DartUtilities::checkResult(result, exception))
252 goto fail;
253 Dart_SetReturnValue(args, result);
254 return;
255 }
256
257 fail:
258 Dart_ThrowException(exception);
259 ASSERT_NOT_REACHED();
260 }
261
262 void getFramebufferAttachmentParameterCallback(Dart_NativeArguments args)
263 {
264 DartApiScope dartApiScope;
265 Dart_Handle exception;
266 {
267 WebGLRenderingContext* context = DartDOMWrapper::receiver<WebGLRendering Context>(args);
268 const ParameterAdapter<int> target(Dart_GetNativeArgument(args, 1));
269 if (!target.conversionSuccessful()) {
270 exception = target.exception();
271 goto fail;
272 }
273 const ParameterAdapter<int> attachment(Dart_GetNativeArgument(args, 2));
274 if (!attachment.conversionSuccessful()) {
275 exception = attachment.exception();
276 goto fail;
277 }
278 const ParameterAdapter<int> pname(Dart_GetNativeArgument(args, 3));
279 if (!pname.conversionSuccessful()) {
280 exception = pname.exception();
281 goto fail;
282 }
283
284 ExceptionCode ec = 0;
285 WebGLGetInfo info = context->getFramebufferAttachmentParameter(target, a ttachment, pname, ec);
286 if (UNLIKELY(ec)) {
287 exception = DartDOMWrapper::exceptionCodeToDartException(ec);
288 goto fail;
289 }
290 Dart_Handle result = webGLGetInfoToDart(info);
291 if (!DartUtilities::checkResult(result, exception))
292 goto fail;
293 Dart_SetReturnValue(args, result);
294 return;
295 }
296
297 fail:
298 Dart_ThrowException(exception);
299 ASSERT_NOT_REACHED();
300 }
301
302 void getParameterCallback(Dart_NativeArguments args)
303 {
304 DartApiScope dartApiScope;
305 Dart_Handle exception = 0;
306 {
307 WebGLRenderingContext* context = DartDOMWrapper::receiver<WebGLRendering Context>(args);
308 const ParameterAdapter<int> pname(Dart_GetNativeArgument(args, 1));
309 if (!pname.conversionSuccessful()) {
310 exception = pname.exception();
311 goto fail;
312 }
313
314 ExceptionCode ec = 0;
315 WebGLGetInfo info = context->getParameter(pname, ec);
316 if (UNLIKELY(ec)) {
317 exception = DartDOMWrapper::exceptionCodeToDartException(ec);
318 goto fail;
319 }
320 Dart_Handle result = webGLGetInfoToDart(info);
321 if (!DartUtilities::checkResult(result, exception))
322 goto fail;
323
324 Dart_SetReturnValue(args, result);
325 return;
326 }
327
328 fail:
329 Dart_ThrowException(exception);
330 ASSERT_NOT_REACHED();
331 }
332
333 void getProgramParameterCallback(Dart_NativeArguments args)
334 {
335 DartApiScope dartApiScope;
336 Dart_Handle exception;
337 {
338 WebGLRenderingContext* context = DartDOMWrapper::receiver<WebGLRendering Context>(args);
339 const ParameterAdapter<WebGLProgram, DartWebGLProgram> program(Dart_GetN ativeArgument(args, 1));
340 if (!program.conversionSuccessful()) {
341 exception = program.exception();
342 goto fail;
343 }
344 const ParameterAdapter<int> pname(Dart_GetNativeArgument(args, 2));
345 if (!pname.conversionSuccessful()) {
346 exception = pname.exception();
347 goto fail;
348 }
349
350 ExceptionCode ec = 0;
351 WebGLGetInfo info = context->getProgramParameter(program, pname, ec);
352 if (UNLIKELY(ec)) {
353 exception = DartDOMWrapper::exceptionCodeToDartException(ec);
354 goto fail;
355 }
356 Dart_Handle result = webGLGetInfoToDart(info);
357 if (!DartUtilities::checkResult(result, exception))
358 goto fail;
359
360 Dart_SetReturnValue(args, result);
361 return;
362 }
363
364 fail:
365 Dart_ThrowException(exception);
366 ASSERT_NOT_REACHED();
367 }
368
369 void getRenderbufferParameterCallback(Dart_NativeArguments args)
370 {
371 getObjectParameter(args, kRenderbuffer);
372 }
373
374 void getShaderParameterCallback(Dart_NativeArguments args)
375 {
376 DartApiScope dartApiScope;
377 Dart_Handle exception;
378 {
379 WebGLRenderingContext* context = DartDOMWrapper::receiver<WebGLRendering Context>(args);
380 const ParameterAdapter<WebGLShader, DartWebGLShader> shader(Dart_GetNati veArgument(args, 1));
381 if (!shader.conversionSuccessful()) {
382 exception = shader.exception();
383 goto fail;
384 }
385 const ParameterAdapter<int> pname(Dart_GetNativeArgument(args, 2));
386 if (!pname.conversionSuccessful()) {
387 exception = pname.exception();
388 goto fail;
389 }
390
391 ExceptionCode ec = 0;
392 WebGLGetInfo info = context->getShaderParameter(shader, pname, ec);
393 if (UNLIKELY(ec)) {
394 exception = DartDOMWrapper::exceptionCodeToDartException(ec);
395 goto fail;
396 }
397 Dart_Handle result = webGLGetInfoToDart(info);
398 if (!DartUtilities::checkResult(result, exception))
399 goto fail;
400
401 Dart_SetReturnValue(args, result);
402 return;
403 }
404
405 fail:
406 Dart_ThrowException(exception);
407 ASSERT_NOT_REACHED();
408 }
409
410 void getSupportedExtensionsCallback(Dart_NativeArguments args)
411 {
412 DartApiScope dartApiScope;
413 Dart_Handle exception = 0;
414 {
415 WebGLRenderingContext* context = DartDOMWrapper::receiver<WebGLRendering Context>(args);
416 Vector<String> value = context->getSupportedExtensions();
417 Dart_Handle result = DartUtilities::vectorToDartList(value);
418 if (!DartUtilities::checkResult(result, exception))
419 goto fail;
420
421 Dart_SetReturnValue(args, result);
422 return;
423 }
424
425 fail:
426 Dart_ThrowException(exception);
427 ASSERT_NOT_REACHED();
428 }
429
430 void getTexParameterCallback(Dart_NativeArguments args)
431 {
432 getObjectParameter(args, kTexture);
433 }
434
435 void getUniformCallback(Dart_NativeArguments args)
436 {
437 getObjectParameter(args, kVertexAttrib);
438 }
439
440 void getVertexAttribCallback(Dart_NativeArguments args)
441 {
442 getObjectParameter(args, kVertexAttrib);
443 }
444
445 enum FunctionToCall {
446 kUniform1v, kUniform2v, kUniform3v, kUniform4v,
447 kVertexAttrib1v, kVertexAttrib2v, kVertexAttrib3v, kVertexAttrib4v
448 };
449
450 static inline bool isFunctionToCallForAttribute(FunctionToCall functionToCall)
451 {
452 switch (functionToCall) {
453 case kVertexAttrib1v:
454 case kVertexAttrib2v:
455 case kVertexAttrib3v:
456 case kVertexAttrib4v:
457 return true;
458 default:
459 break;
460 }
461 return false;
462 }
463
464 static void vertexAttribAndUniformHelperf(Dart_NativeArguments args, FunctionToC all functionToCall)
465 {
466 DartApiScope dartApiScope;
467 Dart_Handle exception;
468 {
469 // Forms:
470 // * glUniform1fv(WebGLUniformLocation location, Array data);
471 // * glUniform1fv(WebGLUniformLocation location, Float32Array data);
472 // * glUniform2fv(WebGLUniformLocation location, Array data);
473 // * glUniform2fv(WebGLUniformLocation location, Float32Array data);
474 // * glUniform3fv(WebGLUniformLocation location, Array data);
475 // * glUniform3fv(WebGLUniformLocation location, Float32Array data);
476 // * glUniform4fv(WebGLUniformLocation location, Array data);
477 // * glUniform4fv(WebGLUniformLocation location, Float32Array data);
478 // * glVertexAttrib1fv(GLint index, Array data);
479 // * glVertexAttrib1fv(GLint index, Float32Array data);
480 // * glVertexAttrib2fv(GLint index, Array data);
481 // * glVertexAttrib2fv(GLint index, Float32Array data);
482 // * glVertexAttrib3fv(GLint index, Array data);
483 // * glVertexAttrib3fv(GLint index, Float32Array data);
484 // * glVertexAttrib4fv(GLint index, Array data);
485 // * glVertexAttrib4fv(GLint index, Float32Array data);
486 WebGLRenderingContext* context = DartDOMWrapper::receiver<WebGLRendering Context>(args);
487 int index = -1;
488 WebGLUniformLocation* location = 0;
489
490 if (isFunctionToCallForAttribute(functionToCall)) {
491 const ParameterAdapter<int> indexParam(Dart_GetNativeArgument(args, 1));
492 if (!indexParam.conversionSuccessful()) {
493 exception = indexParam.exception();
494 goto fail;
495 }
496 index = indexParam;
497 } else {
498 const ParameterAdapter<WebGLUniformLocation, DartWebGLUniformLocatio n> locationParam(Dart_GetNativeArgument(args, 1));
499 if (!locationParam.conversionSuccessful()) {
500 exception = locationParam.exception();
501 goto fail;
502 }
503 location = locationParam;
504 }
505
506 // FIXME: process Dart lists as parameters.
507 const ParameterAdapter<Float32Array, DartFloat32Array> array(Dart_GetNat iveArgument(args, 2));
508 if (!array.conversionSuccessful()) {
509 exception = array.exception();
510 goto fail;
511 }
512
513 ExceptionCode ec = 0;
514 switch (functionToCall) {
515 case kUniform1v:
516 context->uniform1fv(location, array, ec);
517 break;
518 case kUniform2v:
519 context->uniform2fv(location, array, ec);
520 break;
521 case kUniform3v:
522 context->uniform3fv(location, array, ec);
523 break;
524 case kUniform4v:
525 context->uniform4fv(location, array, ec);
526 break;
527 case kVertexAttrib1v:
528 context->vertexAttrib1fv(index, array);
529 break;
530 case kVertexAttrib2v:
531 context->vertexAttrib2fv(index, array);
532 break;
533 case kVertexAttrib3v:
534 context->vertexAttrib3fv(index, array);
535 break;
536 case kVertexAttrib4v:
537 context->vertexAttrib4fv(index, array);
538 break;
539 default:
540 ASSERT_NOT_REACHED();
541 break;
542 }
543 if (UNLIKELY(ec)) {
544 exception = DartDOMWrapper::exceptionCodeToDartException(ec);
545 goto fail;
546 }
547 return;
548 }
549
550 fail:
551 Dart_ThrowException(exception);
552 ASSERT_NOT_REACHED();
553 }
554
555 static void uniformHelperi(Dart_NativeArguments args, FunctionToCall functionToC all)
556 {
557 DartApiScope dartApiScope;
558 Dart_Handle exception;
559 {
560 // Forms:
561 // * glUniform1iv(GLUniformLocation location, Array data);
562 // * glUniform1iv(GLUniformLocation location, Int32Array data);
563 // * glUniform2iv(GLUniformLocation location, Array data);
564 // * glUniform2iv(GLUniformLocation location, Int32Array data);
565 // * glUniform3iv(GLUniformLocation location, Array data);
566 // * glUniform3iv(GLUniformLocation location, Int32Array data);
567 // * glUniform4iv(GLUniformLocation location, Array data);
568 // * glUniform4iv(GLUniformLocation location, Int32Array data);
569 WebGLRenderingContext* context = DartDOMWrapper::receiver<WebGLRendering Context>(args);
570 const ParameterAdapter<WebGLUniformLocation, DartWebGLUniformLocation> l ocation(Dart_GetNativeArgument(args, 1));
571 if (!location.conversionSuccessful()) {
572 exception = location.exception();
573 goto fail;
574 }
575 const ParameterAdapter<Int32Array, DartInt32Array> array(Dart_GetNativeA rgument(args, 2));
576 // FIXME: maybe process Dart lists ars parameters too?
577 if (!array.conversionSuccessful()) {
578 exception = array.exception();
579 goto fail;
580 }
581
582 ExceptionCode ec = 0;
583 switch (functionToCall) {
584 case kUniform1v:
585 context->uniform1iv(location, array, ec);
586 break;
587 case kUniform2v:
588 context->uniform2iv(location, array, ec);
589 break;
590 case kUniform3v:
591 context->uniform3iv(location, array, ec);
592 break;
593 case kUniform4v:
594 context->uniform4iv(location, array, ec);
595 break;
596 default:
597 ASSERT_NOT_REACHED();
598 break;
599 }
600 if (UNLIKELY(ec)) {
601 exception = DartDOMWrapper::exceptionCodeToDartException(ec);
602 goto fail;
603 }
604 return;
605 }
606
607 fail:
608 Dart_ThrowException(exception);
609 ASSERT_NOT_REACHED();
610 }
611
612 static void uniformMatrixHelper(Dart_NativeArguments args, int matrixSize)
613 {
614 DartApiScope dartApiScope;
615 Dart_Handle exception;
616 {
617 // Forms:
618 // * glUniformMatrix2fv(GLint location, GLboolean transpose, Array data) ;
619 // * glUniformMatrix2fv(GLint location, GLboolean transpose, Float32Arra y data);
620 // * glUniformMatrix3fv(GLint location, GLboolean transpose, Array data) ;
621 // * glUniformMatrix3fv(GLint location, GLboolean transpose, Float32Arra y data);
622 // * glUniformMatrix4fv(GLint location, GLboolean transpose, Array data) ;
623 // * glUniformMatrix4fv(GLint location, GLboolean transpose, Float32Arra y data);
624 //
625 WebGLRenderingContext* context = DartDOMWrapper::receiver<WebGLRendering Context>(args);
626 const ParameterAdapter<WebGLUniformLocation, DartWebGLUniformLocation> l ocation(Dart_GetNativeArgument(args, 1));
627 if (!location.conversionSuccessful()) {
628 exception = location.exception();
629 goto fail;
630 }
631 const ParameterAdapter<bool> transpose(Dart_GetNativeArgument(args, 2));
632 if (!transpose.conversionSuccessful()) {
633 exception = transpose.exception();
634 goto fail;
635 }
636 // FIXME: maybe process Dart lists ars parameters too?
637 const ParameterAdapter<Float32Array, DartFloat32Array> array(Dart_GetNat iveArgument(args, 3));
638 if (!array.conversionSuccessful()) {
639 exception = array.exception();
640 goto fail;
641 }
642
643 ExceptionCode ec = 0;
644 switch (matrixSize) {
645 case 2:
646 context->uniformMatrix2fv(location, transpose, array, ec);
647 break;
648 case 3:
649 context->uniformMatrix3fv(location, transpose, array, ec);
650 break;
651 case 4:
652 context->uniformMatrix4fv(location, transpose, array, ec);
653 break;
654 default:
655 ASSERT_NOT_REACHED();
656 break;
657 }
658 if (UNLIKELY(ec)) {
659 exception = DartDOMWrapper::exceptionCodeToDartException(ec);
660 goto fail;
661 }
662 return;
663 }
664
665 fail:
666 Dart_ThrowException(exception);
667 ASSERT_NOT_REACHED();
668 }
669
670 void uniform1fvCallback(Dart_NativeArguments args)
671 {
672 vertexAttribAndUniformHelperf(args, kUniform1v);
673 }
674
675 void uniform1ivCallback(Dart_NativeArguments args)
676 {
677 uniformHelperi(args, kUniform1v);
678 }
679
680 void uniform2fvCallback(Dart_NativeArguments args)
681 {
682 vertexAttribAndUniformHelperf(args, kUniform2v);
683 }
684
685 void uniform2ivCallback(Dart_NativeArguments args)
686 {
687 uniformHelperi(args, kUniform2v);
688 }
689
690 void uniform3fvCallback(Dart_NativeArguments args)
691 {
692 vertexAttribAndUniformHelperf(args, kUniform3v);
693 }
694
695 void uniform3ivCallback(Dart_NativeArguments args)
696 {
697 uniformHelperi(args, kUniform3v);
698 }
699
700 void uniform4fvCallback(Dart_NativeArguments args)
701 {
702 vertexAttribAndUniformHelperf(args, kUniform4v);
703 }
704
705 void uniform4ivCallback(Dart_NativeArguments args)
706 {
707 uniformHelperi(args, kUniform4v);
708 }
709
710 void uniformMatrix2fvCallback(Dart_NativeArguments args)
711 {
712 uniformMatrixHelper(args, 2);
713 }
714
715 void uniformMatrix3fvCallback(Dart_NativeArguments args)
716 {
717 uniformMatrixHelper(args, 3);
718 }
719
720 void uniformMatrix4fvCallback(Dart_NativeArguments args)
721 {
722 uniformMatrixHelper(args, 4);
723 }
724
725 void vertexAttrib1fvCallback(Dart_NativeArguments args)
726 {
727 vertexAttribAndUniformHelperf(args, kVertexAttrib1v);
728 }
729
730 void vertexAttrib2fvCallback(Dart_NativeArguments args)
731 {
732 vertexAttribAndUniformHelperf(args, kVertexAttrib2v);
733 }
734
735 void vertexAttrib3fvCallback(Dart_NativeArguments args)
736 {
737 vertexAttribAndUniformHelperf(args, kVertexAttrib3v);
738 }
739
740 void vertexAttrib4fvCallback(Dart_NativeArguments args)
741 {
742 vertexAttribAndUniformHelperf(args, kVertexAttrib4v);
743 }
744
745 }
202 746
203 } 747 }
204 748
205 #endif // ENABLE(WEBGL) 749 #endif // ENABLE(WEBGL)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698