2 * Copyright (C) 2015-2016 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "JSWebGLRenderingContextBase.h"
31 #include "ANGLEInstancedArrays.h"
32 #include "EXTBlendMinMax.h"
33 #include "EXTFragDepth.h"
34 #include "EXTShaderTextureLOD.h"
35 #include "EXTTextureFilterAnisotropic.h"
37 #include "ExceptionCode.h"
38 #include "HTMLCanvasElement.h"
39 #include "HTMLImageElement.h"
40 #include "JSANGLEInstancedArrays.h"
41 #include "JSEXTBlendMinMax.h"
42 #include "JSEXTFragDepth.h"
43 #include "JSEXTShaderTextureLOD.h"
44 #include "JSEXTTextureFilterAnisotropic.h"
45 #include "JSEXTsRGB.h"
46 #include "JSHTMLCanvasElement.h"
47 #include "JSHTMLImageElement.h"
48 #include "JSImageData.h"
49 #include "JSOESElementIndexUint.h"
50 #include "JSOESStandardDerivatives.h"
51 #include "JSOESTextureFloat.h"
52 #include "JSOESTextureFloatLinear.h"
53 #include "JSOESTextureHalfFloat.h"
54 #include "JSOESTextureHalfFloatLinear.h"
55 #include "JSOESVertexArrayObject.h"
56 #include "JSWebGLBuffer.h"
57 #include "JSWebGLCompressedTextureATC.h"
58 #include "JSWebGLCompressedTexturePVRTC.h"
59 #include "JSWebGLCompressedTextureS3TC.h"
60 #include "JSWebGLDebugRendererInfo.h"
61 #include "JSWebGLDebugShaders.h"
62 #include "JSWebGLDepthTexture.h"
63 #include "JSWebGLDrawBuffers.h"
64 #include "JSWebGLFramebuffer.h"
65 #include "JSWebGLLoseContext.h"
66 #include "JSWebGLProgram.h"
67 #include "JSWebGLRenderbuffer.h"
68 #include "JSWebGLRenderingContext.h"
69 #include "JSWebGLShader.h"
70 #include "JSWebGLTexture.h"
71 #include "JSWebGLUniformLocation.h"
72 #include "JSWebGLVertexArrayObject.h"
73 #include "JSWebGLVertexArrayObjectOES.h"
74 #include "JSWebKitCSSMatrix.h"
75 #include "NotImplemented.h"
76 #include "OESElementIndexUint.h"
77 #include "OESStandardDerivatives.h"
78 #include "OESTextureFloat.h"
79 #include "OESTextureFloatLinear.h"
80 #include "OESTextureHalfFloat.h"
81 #include "OESTextureHalfFloatLinear.h"
82 #include "OESVertexArrayObject.h"
83 #include "WebGLBuffer.h"
84 #include "WebGLCompressedTextureATC.h"
85 #include "WebGLCompressedTexturePVRTC.h"
86 #include "WebGLCompressedTextureS3TC.h"
87 #include "WebGLDebugRendererInfo.h"
88 #include "WebGLDebugShaders.h"
89 #include "WebGLDepthTexture.h"
90 #include "WebGLDrawBuffers.h"
91 #include "WebGLExtension.h"
92 #include "WebGLFramebuffer.h"
93 #include "WebGLGetInfo.h"
94 #include "WebGLLoseContext.h"
95 #include "WebGLProgram.h"
96 #include "WebGLRenderingContextBase.h"
97 #include "WebGLVertexArrayObject.h"
98 #include "WebGLVertexArrayObjectOES.h"
99 #include <runtime/Error.h>
100 #include <runtime/JSObjectInlines.h>
101 #include <runtime/JSTypedArrays.h>
102 #include <runtime/TypedArrayInlines.h>
103 #include <runtime/TypedArrays.h>
104 #include <wtf/FastMalloc.h>
107 #include "HTMLVideoElement.h"
108 #include "JSHTMLVideoElement.h"
112 #include "JSWebGL2RenderingContext.h"
119 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<WebGLRenderingContextBase>&& object)
122 if (is<WebGL2RenderingContext>(object))
123 return createWrapper<WebGL2RenderingContext>(globalObject, WTFMove(object));
125 return createWrapper<WebGLRenderingContext>(globalObject, WTFMove(object));
128 JSValue toJS(ExecState* state, JSDOMGlobalObject* globalObject, WebGLRenderingContextBase& object)
130 return wrap(state, globalObject, object);
133 static JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, const WebGLGetInfo& info)
135 switch (info.getType()) {
136 case WebGLGetInfo::kTypeBool:
137 return jsBoolean(info.getBool());
138 case WebGLGetInfo::kTypeBoolArray: {
139 MarkedArgumentBuffer list;
140 const Vector<bool>& value = info.getBoolArray();
141 for (size_t ii = 0; ii < value.size(); ++ii)
142 list.append(jsBoolean(value[ii]));
143 return constructArray(exec, 0, globalObject, list);
145 case WebGLGetInfo::kTypeFloat:
146 return jsNumber(info.getFloat());
147 case WebGLGetInfo::kTypeInt:
148 return jsNumber(info.getInt());
149 case WebGLGetInfo::kTypeNull:
151 case WebGLGetInfo::kTypeString:
152 return jsStringWithCache(exec, info.getString());
153 case WebGLGetInfo::kTypeUnsignedInt:
154 return jsNumber(info.getUnsignedInt());
155 case WebGLGetInfo::kTypeWebGLBuffer:
156 return toJS(exec, globalObject, info.getWebGLBuffer());
157 case WebGLGetInfo::kTypeWebGLFloatArray:
158 return toJS(exec, globalObject, info.getWebGLFloatArray());
159 case WebGLGetInfo::kTypeWebGLFramebuffer:
160 return toJS(exec, globalObject, info.getWebGLFramebuffer());
161 case WebGLGetInfo::kTypeWebGLIntArray:
162 return toJS(exec, globalObject, info.getWebGLIntArray());
163 // FIXME: implement WebGLObjectArray
164 // case WebGLGetInfo::kTypeWebGLObjectArray:
165 case WebGLGetInfo::kTypeWebGLProgram:
166 return toJS(exec, globalObject, info.getWebGLProgram());
167 case WebGLGetInfo::kTypeWebGLRenderbuffer:
168 return toJS(exec, globalObject, info.getWebGLRenderbuffer());
169 case WebGLGetInfo::kTypeWebGLTexture:
170 return toJS(exec, globalObject, info.getWebGLTexture());
171 case WebGLGetInfo::kTypeWebGLUnsignedByteArray:
172 return toJS(exec, globalObject, info.getWebGLUnsignedByteArray());
173 case WebGLGetInfo::kTypeWebGLUnsignedIntArray:
174 return toJS(exec, globalObject, info.getWebGLUnsignedIntArray());
176 case WebGLGetInfo::kTypeWebGLVertexArrayObject:
177 return toJS(exec, globalObject, info.getWebGLVertexArrayObject());
179 case WebGLGetInfo::kTypeWebGLVertexArrayObjectOES:
180 return toJS(exec, globalObject, info.getWebGLVertexArrayObjectOES());
183 return jsUndefined();
188 kBuffer, kRenderbuffer, kTexture, kVertexAttrib
191 static JSValue getObjectParameter(JSWebGLRenderingContextBase* obj, ExecState& state, ObjectType objectType)
194 auto scope = DECLARE_THROW_SCOPE(vm);
196 if (state.argumentCount() != 2)
197 return throwException(&state, scope, createNotEnoughArgumentsError(&state));
199 ExceptionCode ec = 0;
200 WebGLRenderingContextBase& context = obj->wrapped();
201 unsigned target = state.uncheckedArgument(0).toInt32(&state);
202 RETURN_IF_EXCEPTION(scope, JSValue());
203 unsigned pname = state.uncheckedArgument(1).toInt32(&state);
204 RETURN_IF_EXCEPTION(scope, JSValue());
206 switch (objectType) {
208 info = context.getBufferParameter(target, pname);
211 info = context.getRenderbufferParameter(target, pname);
214 info = context.getTexParameter(target, pname);
218 info = context.getVertexAttrib(target, pname);
225 setDOMException(&state, ec);
226 return jsUndefined();
228 return toJS(&state, obj->globalObject(), info);
231 enum WhichProgramCall {
232 kProgramParameter, kUniform
235 static JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, WebGLExtension* extension)
239 switch (extension->getName()) {
240 case WebGLExtension::WebGLLoseContextName:
241 return toJS(exec, globalObject, static_cast<WebGLLoseContext*>(extension));
242 case WebGLExtension::EXTShaderTextureLODName:
243 return toJS(exec, globalObject, static_cast<EXTShaderTextureLOD*>(extension));
244 case WebGLExtension::EXTTextureFilterAnisotropicName:
245 return toJS(exec, globalObject, static_cast<EXTTextureFilterAnisotropic*>(extension));
246 case WebGLExtension::EXTsRGBName:
247 return toJS(exec, globalObject, static_cast<EXTsRGB*>(extension));
248 case WebGLExtension::EXTFragDepthName:
249 return toJS(exec, globalObject, static_cast<EXTFragDepth*>(extension));
250 case WebGLExtension::EXTBlendMinMaxName:
251 return toJS(exec, globalObject, static_cast<EXTBlendMinMax*>(extension));
252 case WebGLExtension::OESStandardDerivativesName:
253 return toJS(exec, globalObject, static_cast<OESStandardDerivatives*>(extension));
254 case WebGLExtension::OESTextureFloatName:
255 return toJS(exec, globalObject, static_cast<OESTextureFloat*>(extension));
256 case WebGLExtension::OESTextureFloatLinearName:
257 return toJS(exec, globalObject, static_cast<OESTextureFloatLinear*>(extension));
258 case WebGLExtension::OESTextureHalfFloatName:
259 return toJS(exec, globalObject, static_cast<OESTextureHalfFloat*>(extension));
260 case WebGLExtension::OESTextureHalfFloatLinearName:
261 return toJS(exec, globalObject, static_cast<OESTextureHalfFloatLinear*>(extension));
262 case WebGLExtension::OESVertexArrayObjectName:
263 return toJS(exec, globalObject, static_cast<OESVertexArrayObject*>(extension));
264 case WebGLExtension::OESElementIndexUintName:
265 return toJS(exec, globalObject, static_cast<OESElementIndexUint*>(extension));
266 case WebGLExtension::WebGLDebugRendererInfoName:
267 return toJS(exec, globalObject, static_cast<WebGLDebugRendererInfo*>(extension));
268 case WebGLExtension::WebGLDebugShadersName:
269 return toJS(exec, globalObject, static_cast<WebGLDebugShaders*>(extension));
270 case WebGLExtension::WebGLCompressedTextureATCName:
271 return toJS(exec, globalObject, static_cast<WebGLCompressedTextureATC*>(extension));
272 case WebGLExtension::WebGLCompressedTexturePVRTCName:
273 return toJS(exec, globalObject, static_cast<WebGLCompressedTexturePVRTC*>(extension));
274 case WebGLExtension::WebGLCompressedTextureS3TCName:
275 return toJS(exec, globalObject, static_cast<WebGLCompressedTextureS3TC*>(extension));
276 case WebGLExtension::WebGLDepthTextureName:
277 return toJS(exec, globalObject, static_cast<WebGLDepthTexture*>(extension));
278 case WebGLExtension::WebGLDrawBuffersName:
279 return toJS(exec, globalObject, static_cast<WebGLDrawBuffers*>(extension));
280 case WebGLExtension::ANGLEInstancedArraysName:
281 return toJS(exec, globalObject, static_cast<ANGLEInstancedArrays*>(extension));
283 ASSERT_NOT_REACHED();
287 bool JSWebGLRenderingContextBaseOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
289 JSWebGLRenderingContextBase* jsWebGLRenderingContext = jsCast<JSWebGLRenderingContextBase*>(handle.slot()->asCell());
290 void* root = WebCore::root(jsWebGLRenderingContext->wrapped().canvas());
291 return visitor.containsOpaqueRoot(root);
294 void JSWebGLRenderingContextBase::visitAdditionalChildren(SlotVisitor& visitor)
296 visitor.addOpaqueRoot(&wrapped());
297 visitor.addOpaqueRoot(root(wrapped().canvas()));
300 JSValue JSWebGLRenderingContextBase::getAttachedShaders(ExecState& state)
303 auto scope = DECLARE_THROW_SCOPE(vm);
305 if (state.argumentCount() < 1)
306 return throwException(&state, scope, createNotEnoughArgumentsError(&state));
307 ExceptionCode ec = 0;
308 WebGLRenderingContextBase& context = wrapped();
309 WebGLProgram* program = JSWebGLProgram::toWrapped(state.uncheckedArgument(0));
310 if (!program && !state.uncheckedArgument(0).isUndefinedOrNull())
311 return throwTypeError(&state, scope);
312 Vector<RefPtr<WebGLShader>> shaders;
313 bool succeed = context.getAttachedShaders(program, shaders);
315 setDOMException(&state, ec);
320 JSC::MarkedArgumentBuffer list;
321 for (size_t ii = 0; ii < shaders.size(); ++ii)
322 list.append(toJS(&state, globalObject(), shaders[ii].get()));
323 return constructArray(&state, 0, globalObject(), list);
326 JSValue JSWebGLRenderingContextBase::getExtension(ExecState& state)
329 auto scope = DECLARE_THROW_SCOPE(vm);
331 if (state.argumentCount() < 1)
332 return throwException(&state, scope, createNotEnoughArgumentsError(&state));
334 WebGLRenderingContextBase& context = wrapped();
335 const String name = state.uncheckedArgument(0).toString(&state)->value(&state);
336 RETURN_IF_EXCEPTION(scope, JSValue());
337 WebGLExtension* extension = context.getExtension(name);
338 return toJS(&state, globalObject(), extension);
341 JSValue JSWebGLRenderingContextBase::getBufferParameter(ExecState& state)
343 return getObjectParameter(this, state, kBuffer);
346 JSValue JSWebGLRenderingContextBase::getFramebufferAttachmentParameter(ExecState& state)
349 auto scope = DECLARE_THROW_SCOPE(vm);
351 if (state.argumentCount() != 3)
352 return throwException(&state, scope, createNotEnoughArgumentsError(&state));
354 ExceptionCode ec = 0;
355 WebGLRenderingContextBase& context = wrapped();
356 unsigned target = state.uncheckedArgument(0).toInt32(&state);
357 RETURN_IF_EXCEPTION(scope, JSValue());
358 unsigned attachment = state.uncheckedArgument(1).toInt32(&state);
359 RETURN_IF_EXCEPTION(scope, JSValue());
360 unsigned pname = state.uncheckedArgument(2).toInt32(&state);
361 RETURN_IF_EXCEPTION(scope, JSValue());
362 WebGLGetInfo info = context.getFramebufferAttachmentParameter(target, attachment, pname, ec);
364 setDOMException(&state, ec);
365 return jsUndefined();
367 return toJS(&state, globalObject(), info);
370 JSValue JSWebGLRenderingContextBase::getParameter(ExecState& state)
373 auto scope = DECLARE_THROW_SCOPE(vm);
375 if (state.argumentCount() != 1)
376 return throwException(&state, scope, createNotEnoughArgumentsError(&state));
378 ExceptionCode ec = 0;
379 WebGLRenderingContextBase& context = wrapped();
380 unsigned pname = state.uncheckedArgument(0).toInt32(&state);
381 RETURN_IF_EXCEPTION(scope, JSValue());
382 WebGLGetInfo info = context.getParameter(pname, ec);
384 setDOMException(&state, ec);
385 return jsUndefined();
387 return toJS(&state, globalObject(), info);
390 JSValue JSWebGLRenderingContextBase::getProgramParameter(ExecState& state)
393 auto scope = DECLARE_THROW_SCOPE(vm);
395 if (state.argumentCount() != 2)
396 return throwException(&state, scope, createNotEnoughArgumentsError(&state));
398 ExceptionCode ec = 0;
399 WebGLRenderingContextBase& context = wrapped();
400 WebGLProgram* program = JSWebGLProgram::toWrapped(state.uncheckedArgument(0));
401 if (!program && !state.uncheckedArgument(0).isUndefinedOrNull())
402 return throwTypeError(&state, scope);
403 unsigned pname = state.uncheckedArgument(1).toInt32(&state);
404 RETURN_IF_EXCEPTION(scope, JSValue());
405 WebGLGetInfo info = context.getProgramParameter(program, pname);
407 setDOMException(&state, ec);
408 return jsUndefined();
410 return toJS(&state, globalObject(), info);
413 JSValue JSWebGLRenderingContextBase::getRenderbufferParameter(ExecState& state)
415 return getObjectParameter(this, state, kRenderbuffer);
418 JSValue JSWebGLRenderingContextBase::getShaderParameter(ExecState& state)
421 auto scope = DECLARE_THROW_SCOPE(vm);
423 if (state.argumentCount() != 2)
424 return throwException(&state, scope, createNotEnoughArgumentsError(&state));
426 ExceptionCode ec = 0;
427 WebGLRenderingContextBase& context = wrapped();
428 if (!state.uncheckedArgument(0).isUndefinedOrNull() && !state.uncheckedArgument(0).inherits(JSWebGLShader::info()))
429 return throwTypeError(&state, scope);
430 WebGLShader* shader = JSWebGLShader::toWrapped(state.uncheckedArgument(0));
431 unsigned pname = state.uncheckedArgument(1).toInt32(&state);
432 RETURN_IF_EXCEPTION(scope, JSValue());
433 WebGLGetInfo info = context.getShaderParameter(shader, pname);
435 setDOMException(&state, ec);
436 return jsUndefined();
438 return toJS(&state, globalObject(), info);
441 JSValue JSWebGLRenderingContextBase::getSupportedExtensions(ExecState& state)
443 WebGLRenderingContextBase& context = wrapped();
444 if (context.isContextLost())
446 Vector<String> value = context.getSupportedExtensions();
447 MarkedArgumentBuffer list;
448 for (size_t ii = 0; ii < value.size(); ++ii)
449 list.append(jsStringWithCache(&state, value[ii]));
450 return constructArray(&state, 0, globalObject(), list);
453 JSValue JSWebGLRenderingContextBase::getTexParameter(ExecState& state)
455 return getObjectParameter(this, state, kTexture);
458 JSValue JSWebGLRenderingContextBase::getUniform(ExecState& state)
461 auto scope = DECLARE_THROW_SCOPE(vm);
463 if (state.argumentCount() != 2)
464 return throwException(&state, scope, createNotEnoughArgumentsError(&state));
466 ExceptionCode ec = 0;
467 WebGLRenderingContextBase& context = wrapped();
468 WebGLProgram* program = JSWebGLProgram::toWrapped(state.uncheckedArgument(0));
469 if (!program && !state.uncheckedArgument(0).isUndefinedOrNull())
470 return throwTypeError(&state, scope);
471 WebGLUniformLocation* location = JSWebGLUniformLocation::toWrapped(state.uncheckedArgument(1));
472 if (!location && !state.uncheckedArgument(1).isUndefinedOrNull())
473 return throwTypeError(&state, scope);
474 WebGLGetInfo info = context.getUniform(program, location);
476 setDOMException(&state, ec);
477 return jsUndefined();
479 return toJS(&state, globalObject(), info);
482 JSValue JSWebGLRenderingContextBase::getVertexAttrib(ExecState& state)
484 return getObjectParameter(this, state, kVertexAttrib);
487 template<typename T, size_t inlineCapacity>
488 bool toVector(JSC::ExecState& state, JSC::JSValue value, Vector<T, inlineCapacity>& vector)
491 auto scope = DECLARE_THROW_SCOPE(vm);
493 if (!value.isObject())
496 JSC::JSObject* object = asObject(value);
497 int32_t length = object->get(&state, state.vm().propertyNames->length).toInt32(&state);
499 if (!vector.tryReserveCapacity(length))
501 vector.resize(length);
503 for (int32_t i = 0; i < length; ++i) {
504 JSC::JSValue v = object->get(&state, i);
505 RETURN_IF_EXCEPTION(scope, false);
506 vector[i] = static_cast<T>(v.toNumber(&state));
512 enum DataFunctionToCall {
513 f_uniform1v, f_uniform2v, f_uniform3v, f_uniform4v,
514 f_vertexAttrib1v, f_vertexAttrib2v, f_vertexAttrib3v, f_vertexAttrib4v
517 enum DataFunctionMatrixToCall {
518 f_uniformMatrix2fv, f_uniformMatrix3fv, f_uniformMatrix4fv
521 static bool functionForUniform(DataFunctionToCall f)
534 static JSC::JSValue dataFunctionf(DataFunctionToCall f, JSC::ExecState& state, WebGLRenderingContextBase& context)
537 auto scope = DECLARE_THROW_SCOPE(vm);
539 if (state.argumentCount() != 2)
540 return throwException(&state, scope, createNotEnoughArgumentsError(&state));
542 WebGLUniformLocation* location = 0;
545 if (functionForUniform(f)) {
546 location = JSWebGLUniformLocation::toWrapped(state.uncheckedArgument(0));
547 if (!location && !state.uncheckedArgument(0).isUndefinedOrNull())
548 return throwTypeError(&state, scope);
550 index = state.uncheckedArgument(0).toInt32(&state);
552 RETURN_IF_EXCEPTION(scope, JSValue());
554 RefPtr<Float32Array> webGLArray = toFloat32Array(state.uncheckedArgument(1));
555 RETURN_IF_EXCEPTION(scope, JSValue());
557 ExceptionCode ec = 0;
561 context.uniform1fv(location, *webGLArray);
564 context.uniform2fv(location, *webGLArray);
567 context.uniform3fv(location, *webGLArray);
570 context.uniform4fv(location, *webGLArray);
572 case f_vertexAttrib1v:
573 context.vertexAttrib1fv(index, *webGLArray);
575 case f_vertexAttrib2v:
576 context.vertexAttrib2fv(index, *webGLArray);
578 case f_vertexAttrib3v:
579 context.vertexAttrib3fv(index, *webGLArray);
581 case f_vertexAttrib4v:
582 context.vertexAttrib4fv(index, *webGLArray);
586 setDOMException(&state, ec);
587 return jsUndefined();
590 Vector<float, 64> array;
591 if (!toVector(state, state.uncheckedArgument(1), array))
592 return throwTypeError(&state, scope);
596 context.uniform1fv(location, array.data(), array.size());
599 context.uniform2fv(location, array.data(), array.size());
602 context.uniform3fv(location, array.data(), array.size());
605 context.uniform4fv(location, array.data(), array.size());
607 case f_vertexAttrib1v:
608 context.vertexAttrib1fv(index, array.data(), array.size());
610 case f_vertexAttrib2v:
611 context.vertexAttrib2fv(index, array.data(), array.size());
613 case f_vertexAttrib3v:
614 context.vertexAttrib3fv(index, array.data(), array.size());
616 case f_vertexAttrib4v:
617 context.vertexAttrib4fv(index, array.data(), array.size());
621 setDOMException(&state, ec);
622 return jsUndefined();
625 static JSC::JSValue dataFunctioni(DataFunctionToCall f, JSC::ExecState& state, WebGLRenderingContextBase& context)
628 auto scope = DECLARE_THROW_SCOPE(vm);
630 if (state.argumentCount() != 2)
631 return throwException(&state, scope, createNotEnoughArgumentsError(&state));
633 WebGLUniformLocation* location = JSWebGLUniformLocation::toWrapped(state.uncheckedArgument(0));
634 if (!location && !state.uncheckedArgument(0).isUndefinedOrNull())
635 return throwTypeError(&state, scope);
637 RefPtr<Int32Array> webGLArray = toInt32Array(state.uncheckedArgument(1));
639 ExceptionCode ec = 0;
643 context.uniform1iv(location, *webGLArray);
646 context.uniform2iv(location, *webGLArray);
649 context.uniform3iv(location, *webGLArray);
652 context.uniform4iv(location, *webGLArray);
658 setDOMException(&state, ec);
659 return jsUndefined();
663 Vector<int, 64> array;
664 if (!toVector(state, state.uncheckedArgument(1), array))
665 return throwTypeError(&state, scope);
669 context.uniform1iv(location, array.data(), array.size());
672 context.uniform2iv(location, array.data(), array.size());
675 context.uniform3iv(location, array.data(), array.size());
678 context.uniform4iv(location, array.data(), array.size());
684 setDOMException(&state, ec);
685 return jsUndefined();
688 static JSC::JSValue dataFunctionMatrix(DataFunctionMatrixToCall f, JSC::ExecState& state, WebGLRenderingContextBase& context)
691 auto scope = DECLARE_THROW_SCOPE(vm);
693 if (state.argumentCount() != 3)
694 return throwException(&state, scope, createNotEnoughArgumentsError(&state));
696 WebGLUniformLocation* location = JSWebGLUniformLocation::toWrapped(state.uncheckedArgument(0));
697 if (!location && !state.uncheckedArgument(0).isUndefinedOrNull())
698 return throwTypeError(&state, scope);
700 bool transpose = state.uncheckedArgument(1).toBoolean(&state);
701 RETURN_IF_EXCEPTION(scope, JSValue());
703 RefPtr<Float32Array> webGLArray = toFloat32Array(state.uncheckedArgument(2));
707 case f_uniformMatrix2fv:
708 context.uniformMatrix2fv(location, transpose, *webGLArray);
710 case f_uniformMatrix3fv:
711 context.uniformMatrix3fv(location, transpose, *webGLArray);
713 case f_uniformMatrix4fv:
714 context.uniformMatrix4fv(location, transpose, *webGLArray);
718 ExceptionCode ec = 0;
719 setDOMException(&state, ec);
720 return jsUndefined();
723 Vector<float, 64> array;
724 if (!toVector(state, state.uncheckedArgument(2), array))
725 return throwTypeError(&state, scope);
728 case f_uniformMatrix2fv:
729 context.uniformMatrix2fv(location, transpose, array.data(), array.size());
731 case f_uniformMatrix3fv:
732 context.uniformMatrix3fv(location, transpose, array.data(), array.size());
734 case f_uniformMatrix4fv:
735 context.uniformMatrix4fv(location, transpose, array.data(), array.size());
739 ExceptionCode ec = 0;
740 setDOMException(&state, ec);
741 return jsUndefined();
744 JSC::JSValue JSWebGLRenderingContextBase::uniform1fv(JSC::ExecState& state)
746 return dataFunctionf(f_uniform1v, state, wrapped());
749 JSC::JSValue JSWebGLRenderingContextBase::uniform1iv(JSC::ExecState& state)
751 return dataFunctioni(f_uniform1v, state, wrapped());
754 JSC::JSValue JSWebGLRenderingContextBase::uniform2fv(JSC::ExecState& state)
756 return dataFunctionf(f_uniform2v, state, wrapped());
759 JSC::JSValue JSWebGLRenderingContextBase::uniform2iv(JSC::ExecState& state)
761 return dataFunctioni(f_uniform2v, state, wrapped());
764 JSC::JSValue JSWebGLRenderingContextBase::uniform3fv(JSC::ExecState& state)
766 return dataFunctionf(f_uniform3v, state, wrapped());
769 JSC::JSValue JSWebGLRenderingContextBase::uniform3iv(JSC::ExecState& state)
771 return dataFunctioni(f_uniform3v, state, wrapped());
774 JSC::JSValue JSWebGLRenderingContextBase::uniform4fv(JSC::ExecState& state)
776 return dataFunctionf(f_uniform4v, state, wrapped());
779 JSC::JSValue JSWebGLRenderingContextBase::uniform4iv(JSC::ExecState& state)
781 return dataFunctioni(f_uniform4v, state, wrapped());
784 JSC::JSValue JSWebGLRenderingContextBase::uniformMatrix2fv(JSC::ExecState& state)
786 return dataFunctionMatrix(f_uniformMatrix2fv, state, wrapped());
789 JSC::JSValue JSWebGLRenderingContextBase::uniformMatrix3fv(JSC::ExecState& state)
791 return dataFunctionMatrix(f_uniformMatrix3fv, state, wrapped());
794 JSC::JSValue JSWebGLRenderingContextBase::uniformMatrix4fv(JSC::ExecState& state)
796 return dataFunctionMatrix(f_uniformMatrix4fv, state, wrapped());
799 JSC::JSValue JSWebGLRenderingContextBase::vertexAttrib1fv(JSC::ExecState& state)
801 return dataFunctionf(f_vertexAttrib1v, state, wrapped());
804 JSC::JSValue JSWebGLRenderingContextBase::vertexAttrib2fv(JSC::ExecState& state)
806 return dataFunctionf(f_vertexAttrib2v, state, wrapped());
809 JSC::JSValue JSWebGLRenderingContextBase::vertexAttrib3fv(JSC::ExecState& state)
811 return dataFunctionf(f_vertexAttrib3v, state, wrapped());
814 JSC::JSValue JSWebGLRenderingContextBase::vertexAttrib4fv(JSC::ExecState& state)
816 return dataFunctionf(f_vertexAttrib4v, state, wrapped());
819 } // namespace WebCore
821 #endif // ENABLE(WEBGL)