2 * Copyright (C) 2009 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 COMPUTER, 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 COMPUTER, 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.
26 #ifndef WebGLRenderingContext_h
27 #define WebGLRenderingContext_h
29 #include "CanvasRenderingContext.h"
30 #include "ExceptionCode.h"
31 #include "Float32Array.h"
32 #include "WebGLGetInfo.h"
33 #include "Int32Array.h"
34 #include "Uint8Array.h"
35 #include "GraphicsContext3D.h"
36 #include "PlatformString.h"
40 class WebGLActiveInfo;
42 class WebGLContextAttributes;
43 class WebGLFramebuffer;
46 class WebGLRenderbuffer;
49 class WebGLUniformLocation;
50 class HTMLImageElement;
51 class HTMLVideoElement;
53 class WebKitCSSMatrix;
55 class WebGLRenderingContext : public CanvasRenderingContext {
57 static PassOwnPtr<WebGLRenderingContext> create(HTMLCanvasElement*, WebGLContextAttributes*);
58 virtual ~WebGLRenderingContext();
60 virtual bool is3d() const { return true; }
62 // Helper to return the size in bytes of OpenGL data types
63 // like GL_FLOAT, GL_INT, etc.
64 int sizeInBytes(int type, ExceptionCode& ec);
66 void activeTexture(unsigned long texture, ExceptionCode& ec);
67 void attachShader(WebGLProgram*, WebGLShader*, ExceptionCode& ec);
68 void bindAttribLocation(WebGLProgram*, unsigned long index, const String& name, ExceptionCode& ec);
69 void bindBuffer(unsigned long target, WebGLBuffer*, ExceptionCode& ec);
70 void bindFramebuffer(unsigned long target, WebGLFramebuffer*, ExceptionCode& ec);
71 void bindRenderbuffer(unsigned long target, WebGLRenderbuffer*, ExceptionCode& ec);
72 void bindTexture(unsigned long target, WebGLTexture*, ExceptionCode& ec);
73 void blendColor(double red, double green, double blue, double alpha);
74 void blendEquation(unsigned long mode);
75 void blendEquationSeparate(unsigned long modeRGB, unsigned long modeAlpha);
76 void blendFunc(unsigned long sfactor, unsigned long dfactor);
77 void blendFuncSeparate(unsigned long srcRGB, unsigned long dstRGB, unsigned long srcAlpha, unsigned long dstAlpha);
79 void bufferData(unsigned long target, int size, unsigned long usage, ExceptionCode&);
80 void bufferData(unsigned long target, ArrayBufferView* data, unsigned long usage, ExceptionCode&);
81 void bufferSubData(unsigned long target, long offset, ArrayBufferView* data, ExceptionCode&);
83 unsigned long checkFramebufferStatus(unsigned long target);
84 void clear(unsigned long mask);
85 void clearColor(double red, double green, double blue, double alpha);
86 void clearDepth(double);
87 void clearStencil(long);
88 void colorMask(bool red, bool green, bool blue, bool alpha);
89 void compileShader(WebGLShader*, ExceptionCode& ec);
91 //void compressedTexImage2D(unsigned long target, long level, unsigned long internalformat, unsigned long width, unsigned long height, long border, unsigned long imageSize, const void* data);
92 //void compressedTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, unsigned long width, unsigned long height, unsigned long format, unsigned long imageSize, const void* data);
94 void copyTexImage2D(unsigned long target, long level, unsigned long internalformat, long x, long y, unsigned long width, unsigned long height, long border);
95 void copyTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, long x, long y, unsigned long width, unsigned long height);
97 PassRefPtr<WebGLBuffer> createBuffer();
98 PassRefPtr<WebGLFramebuffer> createFramebuffer();
99 PassRefPtr<WebGLProgram> createProgram();
100 PassRefPtr<WebGLRenderbuffer> createRenderbuffer();
101 PassRefPtr<WebGLShader> createShader(unsigned long type, ExceptionCode&);
102 PassRefPtr<WebGLTexture> createTexture();
104 void cullFace(unsigned long mode);
106 void deleteBuffer(WebGLBuffer*);
107 void deleteFramebuffer(WebGLFramebuffer*);
108 void deleteProgram(WebGLProgram*);
109 void deleteRenderbuffer(WebGLRenderbuffer*);
110 void deleteShader(WebGLShader*);
111 void deleteTexture(WebGLTexture*);
113 void depthFunc(unsigned long);
114 void depthMask(bool);
115 void depthRange(double zNear, double zFar);
116 void detachShader(WebGLProgram*, WebGLShader*, ExceptionCode&);
117 void disable(unsigned long cap);
118 void disableVertexAttribArray(unsigned long index, ExceptionCode&);
119 void drawArrays(unsigned long mode, long first, long count, ExceptionCode&);
120 void drawElements(unsigned long mode, long count, unsigned long type, long offset, ExceptionCode&);
122 void enable(unsigned long cap);
123 void enableVertexAttribArray(unsigned long index, ExceptionCode&);
126 void framebufferRenderbuffer(unsigned long target, unsigned long attachment, unsigned long renderbuffertarget, WebGLRenderbuffer*, ExceptionCode& ec);
127 void framebufferTexture2D(unsigned long target, unsigned long attachment, unsigned long textarget, WebGLTexture*, long level, ExceptionCode& ec);
128 void frontFace(unsigned long mode);
129 void generateMipmap(unsigned long target);
131 PassRefPtr<WebGLActiveInfo> getActiveAttrib(WebGLProgram*, unsigned long index, ExceptionCode&);
132 PassRefPtr<WebGLActiveInfo> getActiveUniform(WebGLProgram*, unsigned long index, ExceptionCode&);
134 bool getAttachedShaders(WebGLProgram*, Vector<WebGLShader*>&, ExceptionCode&);
136 int getAttribLocation(WebGLProgram*, const String& name);
138 WebGLGetInfo getBufferParameter(unsigned long target, unsigned long pname, ExceptionCode&);
140 PassRefPtr<WebGLContextAttributes> getContextAttributes();
142 unsigned long getError();
144 WebGLGetInfo getFramebufferAttachmentParameter(unsigned long target, unsigned long attachment, unsigned long pname, ExceptionCode&);
146 WebGLGetInfo getParameter(unsigned long pname, ExceptionCode&);
148 WebGLGetInfo getProgramParameter(WebGLProgram*, unsigned long pname, ExceptionCode&);
150 String getProgramInfoLog(WebGLProgram*, ExceptionCode& ec);
152 WebGLGetInfo getRenderbufferParameter(unsigned long target, unsigned long pname, ExceptionCode&);
154 WebGLGetInfo getShaderParameter(WebGLShader*, unsigned long pname, ExceptionCode& ec);
156 String getShaderInfoLog(WebGLShader*, ExceptionCode& ec);
159 // void glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision);
161 String getShaderSource(WebGLShader*, ExceptionCode&);
162 String getString(unsigned long name);
164 WebGLGetInfo getTexParameter(unsigned long target, unsigned long pname, ExceptionCode&);
166 WebGLGetInfo getUniform(WebGLProgram*, const WebGLUniformLocation*, ExceptionCode&);
168 PassRefPtr<WebGLUniformLocation> getUniformLocation(WebGLProgram*, const String&, ExceptionCode&);
170 WebGLGetInfo getVertexAttrib(unsigned long index, unsigned long pname, ExceptionCode&);
172 long getVertexAttribOffset(unsigned long index, unsigned long pname);
174 void hint(unsigned long target, unsigned long mode);
175 bool isBuffer(WebGLBuffer*);
176 bool isEnabled(unsigned long cap);
177 bool isFramebuffer(WebGLFramebuffer*);
178 bool isProgram(WebGLProgram*);
179 bool isRenderbuffer(WebGLRenderbuffer*);
180 bool isShader(WebGLShader*);
181 bool isTexture(WebGLTexture*);
182 void lineWidth(double);
183 void linkProgram(WebGLProgram*, ExceptionCode&);
184 void pixelStorei(unsigned long pname, long param);
185 void polygonOffset(double factor, double units);
186 void readPixels(long x, long y, long width, long height, unsigned long format, unsigned long type, ArrayBufferView* pixels);
187 void releaseShaderCompiler();
188 void renderbufferStorage(unsigned long target, unsigned long internalformat, unsigned long width, unsigned long height);
189 void sampleCoverage(double value, bool invert);
190 void scissor(long x, long y, unsigned long width, unsigned long height);
191 void shaderSource(WebGLShader*, const String&, ExceptionCode&);
192 void stencilFunc(unsigned long func, long ref, unsigned long mask);
193 void stencilFuncSeparate(unsigned long face, unsigned long func, long ref, unsigned long mask);
194 void stencilMask(unsigned long);
195 void stencilMaskSeparate(unsigned long face, unsigned long mask);
196 void stencilOp(unsigned long fail, unsigned long zfail, unsigned long zpass);
197 void stencilOpSeparate(unsigned long face, unsigned long fail, unsigned long zfail, unsigned long zpass);
199 void texImage2D(unsigned target, unsigned level, unsigned internalformat,
200 unsigned width, unsigned height, unsigned border,
201 unsigned format, unsigned type, ArrayBufferView* pixels, ExceptionCode&);
202 void texImage2D(unsigned target, unsigned level, unsigned internalformat,
203 unsigned format, unsigned type, ImageData* pixels, ExceptionCode&);
204 void texImage2D(unsigned target, unsigned level, unsigned internalformat,
205 unsigned format, unsigned type, HTMLImageElement* image, ExceptionCode&);
206 void texImage2D(unsigned target, unsigned level, unsigned internalformat,
207 unsigned format, unsigned type, HTMLCanvasElement* canvas, ExceptionCode&);
208 void texImage2D(unsigned target, unsigned level, unsigned internalformat,
209 unsigned format, unsigned type, HTMLVideoElement* video, ExceptionCode&);
210 // Obsolete entry points -- to be removed shortly. (FIXME)
211 void texImage2D(unsigned target, unsigned level, ImageData* pixels, ExceptionCode&);
212 void texImage2D(unsigned target, unsigned level, ImageData* pixels, bool flipY, ExceptionCode&);
213 void texImage2D(unsigned target, unsigned level, ImageData* pixels, bool flipY, bool premultiplyAlpha, ExceptionCode&);
214 void texImage2D(unsigned target, unsigned level, HTMLImageElement* image, ExceptionCode&);
215 void texImage2D(unsigned target, unsigned level, HTMLImageElement* image, bool flipY, ExceptionCode&);
216 void texImage2D(unsigned target, unsigned level, HTMLImageElement* image, bool flipY, bool premultiplyAlpha, ExceptionCode&);
217 void texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, ExceptionCode&);
218 void texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, bool flipY, ExceptionCode&);
219 void texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, bool flipY, bool premultiplyAlpha, ExceptionCode&);
220 void texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, ExceptionCode&);
221 void texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, bool flipY, ExceptionCode&);
222 void texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, bool flipY, bool premultiplyAlpha, ExceptionCode&);
224 void texParameterf(unsigned target, unsigned pname, float param);
225 void texParameteri(unsigned target, unsigned pname, int param);
227 void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
228 unsigned width, unsigned height,
229 unsigned format, unsigned type, ArrayBufferView* pixels, ExceptionCode&);
230 void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
231 unsigned format, unsigned type, ImageData* pixels, ExceptionCode&);
232 void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
233 unsigned format, unsigned type, HTMLImageElement* image, ExceptionCode&);
234 void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
235 unsigned format, unsigned type, HTMLCanvasElement* canvas, ExceptionCode&);
236 void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
237 unsigned format, unsigned type, HTMLVideoElement* video, ExceptionCode&);
238 // Obsolete entry points -- to be removed shortly. (FIXME)
239 void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, ImageData* pixels, ExceptionCode&);
240 void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, ImageData* pixels, bool flipY, ExceptionCode&);
241 void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, ImageData* pixels, bool flipY, bool premultiplyAlpha, ExceptionCode&);
242 void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLImageElement* image, ExceptionCode&);
243 void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLImageElement* image, bool flipY, ExceptionCode&);
244 void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLImageElement* image, bool flipY, bool premultiplyAlpha, ExceptionCode&);
245 void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLCanvasElement* canvas, ExceptionCode&);
246 void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLCanvasElement* canvas, bool flipY, ExceptionCode&);
247 void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLCanvasElement* canvas, bool flipY, bool premultiplyAlpha, ExceptionCode&);
248 void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLVideoElement* video, ExceptionCode&);
249 void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLVideoElement* video, bool flipY, ExceptionCode&);
250 void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLVideoElement* video, bool flipY, bool premultiplyAlpha, ExceptionCode&);
252 void uniform1f(const WebGLUniformLocation* location, float x, ExceptionCode&);
253 void uniform1fv(const WebGLUniformLocation* location, Float32Array* v, ExceptionCode&);
254 void uniform1fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&);
255 void uniform1i(const WebGLUniformLocation* location, int x, ExceptionCode&);
256 void uniform1iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode&);
257 void uniform1iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&);
258 void uniform2f(const WebGLUniformLocation* location, float x, float y, ExceptionCode&);
259 void uniform2fv(const WebGLUniformLocation* location, Float32Array* v, ExceptionCode&);
260 void uniform2fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&);
261 void uniform2i(const WebGLUniformLocation* location, int x, int y, ExceptionCode&);
262 void uniform2iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode&);
263 void uniform2iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&);
264 void uniform3f(const WebGLUniformLocation* location, float x, float y, float z, ExceptionCode&);
265 void uniform3fv(const WebGLUniformLocation* location, Float32Array* v, ExceptionCode&);
266 void uniform3fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&);
267 void uniform3i(const WebGLUniformLocation* location, int x, int y, int z, ExceptionCode&);
268 void uniform3iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode&);
269 void uniform3iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&);
270 void uniform4f(const WebGLUniformLocation* location, float x, float y, float z, float w, ExceptionCode&);
271 void uniform4fv(const WebGLUniformLocation* location, Float32Array* v, ExceptionCode&);
272 void uniform4fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&);
273 void uniform4i(const WebGLUniformLocation* location, int x, int y, int z, int w, ExceptionCode&);
274 void uniform4iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode&);
275 void uniform4iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&);
276 void uniformMatrix2fv(const WebGLUniformLocation* location, bool transpose, Float32Array* value, ExceptionCode&);
277 void uniformMatrix2fv(const WebGLUniformLocation* location, bool transpose, float* value, int size, ExceptionCode&);
278 void uniformMatrix3fv(const WebGLUniformLocation* location, bool transpose, Float32Array* value, ExceptionCode&);
279 void uniformMatrix3fv(const WebGLUniformLocation* location, bool transpose, float* value, int size, ExceptionCode&);
280 void uniformMatrix4fv(const WebGLUniformLocation* location, bool transpose, Float32Array* value, ExceptionCode&);
281 void uniformMatrix4fv(const WebGLUniformLocation* location, bool transpose, float* value, int size, ExceptionCode&);
283 void useProgram(WebGLProgram*, ExceptionCode&);
284 void validateProgram(WebGLProgram*, ExceptionCode&);
286 void vertexAttrib1f(unsigned long indx, float x);
287 void vertexAttrib1fv(unsigned long indx, Float32Array* values);
288 void vertexAttrib1fv(unsigned long indx, float* values, int size);
289 void vertexAttrib2f(unsigned long indx, float x, float y);
290 void vertexAttrib2fv(unsigned long indx, Float32Array* values);
291 void vertexAttrib2fv(unsigned long indx, float* values, int size);
292 void vertexAttrib3f(unsigned long indx, float x, float y, float z);
293 void vertexAttrib3fv(unsigned long indx, Float32Array* values);
294 void vertexAttrib3fv(unsigned long indx, float* values, int size);
295 void vertexAttrib4f(unsigned long indx, float x, float y, float z, float w);
296 void vertexAttrib4fv(unsigned long indx, Float32Array* values);
297 void vertexAttrib4fv(unsigned long indx, float* values, int size);
298 void vertexAttribPointer(unsigned long indx, long size, unsigned long type, bool normalized,
299 unsigned long stride, unsigned long offset, ExceptionCode&);
301 void viewport(long x, long y, unsigned long width, unsigned long height);
303 GraphicsContext3D* graphicsContext3D() const { return m_context.get(); }
305 void reshape(int width, int height);
307 // Helpers for notification about paint events.
311 void removeObject(CanvasObject*);
314 friend class CanvasObject;
316 WebGLRenderingContext(HTMLCanvasElement*, PassOwnPtr<GraphicsContext3D>);
318 void addObject(CanvasObject*);
319 void detachAndRemoveAllObjects();
320 WebGLTexture* findTexture(Platform3DObject);
321 WebGLRenderbuffer* findRenderbuffer(Platform3DObject);
322 WebGLBuffer* findBuffer(Platform3DObject);
323 WebGLShader* findShader(Platform3DObject);
325 void markContextChanged();
326 void cleanupAfterGraphicsCall(bool changed)
329 markContextChanged();
332 bool isGLES2Compliant();
334 // Basic validation of count and offset against number of elements in element array buffer
335 bool validateElementArraySize(unsigned long count, unsigned long type, long offset);
337 // Conservative but quick index validation
338 bool validateIndexArrayConservative(unsigned long type, long& numElementsRequired);
340 // Precise but slow index validation -- only done if conservative checks fail
341 bool validateIndexArrayPrecise(unsigned long count, unsigned long type, long offset, long& numElementsRequired);
342 bool validateRenderingState(long numElements);
344 bool validateWebGLObject(CanvasObject* object);
346 OwnPtr<GraphicsContext3D> m_context;
348 bool m_markedCanvasDirty;
349 // FIXME: I think this is broken -- it does not increment any
350 // reference counts, so may refer to destroyed objects.
351 HashSet<RefPtr<CanvasObject> > m_canvasObjects;
353 // List of bound VBO's. Used to maintain info about sizes for ARRAY_BUFFER and stored values for ELEMENT_ARRAY_BUFFER
354 RefPtr<WebGLBuffer> m_boundArrayBuffer;
355 RefPtr<WebGLBuffer> m_boundElementArrayBuffer;
357 // Cached values for vertex attrib range checks
358 class VertexAttribState {
360 VertexAttribState() : enabled(false), bytesPerElement(0), stride(0), offset(0) { }
362 RefPtr<WebGLBuffer> bufferBinding;
363 long bytesPerElement;
364 unsigned long stride;
365 unsigned long offset;
368 Vector<VertexAttribState> m_vertexAttribState;
369 unsigned m_maxVertexAttribs;
371 RefPtr<WebGLProgram> m_currentProgram;
372 RefPtr<WebGLFramebuffer> m_framebufferBinding;
373 RefPtr<WebGLRenderbuffer> m_renderbufferBinding;
374 class TextureUnitState {
376 RefPtr<WebGLTexture> m_texture2DBinding;
377 RefPtr<WebGLTexture> m_textureCubeMapBinding;
379 Vector<TextureUnitState> m_textureUnits;
380 unsigned long m_activeTextureUnit;
382 RefPtr<WebGLTexture> m_blackTexture2D;
383 RefPtr<WebGLTexture> m_blackTextureCubeMap;
385 long m_maxTextureSize;
386 long m_maxCubeMapTextureSize;
389 int m_unpackAlignment;
390 unsigned long m_implementationColorReadFormat;
391 unsigned long m_implementationColorReadType;
393 bool m_unpackPremultiplyAlpha;
395 // Helpers for getParameter and others
396 WebGLGetInfo getBooleanParameter(unsigned long pname);
397 WebGLGetInfo getBooleanArrayParameter(unsigned long pname);
398 WebGLGetInfo getFloatParameter(unsigned long pname);
399 WebGLGetInfo getIntParameter(unsigned long pname);
400 WebGLGetInfo getLongParameter(unsigned long pname);
401 WebGLGetInfo getUnsignedLongParameter(unsigned long pname);
402 WebGLGetInfo getWebGLFloatArrayParameter(unsigned long pname);
403 WebGLGetInfo getWebGLIntArrayParameter(unsigned long pname);
405 void texImage2DBase(unsigned target, unsigned level, unsigned internalformat,
406 unsigned width, unsigned height, unsigned border,
407 unsigned format, unsigned type, void* pixels, ExceptionCode&);
408 void texImage2DImpl(unsigned target, unsigned level, unsigned internalformat,
409 unsigned format, unsigned type, Image* image,
410 bool flipY, bool premultiplyAlpha, ExceptionCode&);
411 void texSubImage2DBase(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
412 unsigned width, unsigned height,
413 unsigned format, unsigned type, void* pixels, ExceptionCode&);
414 void texSubImage2DImpl(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
415 unsigned format, unsigned type,
416 Image* image, bool flipY, bool premultiplyAlpha, ExceptionCode&);
418 void handleNPOTTextures(bool prepareToDraw);
420 void createFallbackBlackTextures1x1();
422 // Helper function for copyTex{Sub}Image, check whether the internalformat
423 // and the color buffer format of the current bound framebuffer combination
425 bool isTexInternalFormatColorBufferCombinationValid(unsigned long texInternalFormat,
426 unsigned long colorBufferFormat);
428 // Helper function to get the current bound texture.
429 WebGLTexture* getTextureBinding(unsigned long target);
431 // Helper function to check input format/type for functions {copy}Tex{Sub}Image.
432 // Generates GL error and returns false if parameters are invalid.
433 bool validateTexFuncFormatAndType(unsigned long format, unsigned long type);
435 // Helper function to check input parameters for functions {copy}Tex{Sub}Image.
436 // Generates GL error and returns false if parameters are invalid.
437 bool validateTexFuncParameters(unsigned long target, long level,
438 unsigned long internalformat,
439 long width, long height, long border,
440 unsigned long format, unsigned long type);
442 // Helper function to validate that the given ArrayBufferView
443 // is of the correct type and contains enough data for the texImage call.
444 // Generates GL error and returns false if parameters are invalid.
445 bool validateTexFuncData(long width, long height,
446 unsigned long format, unsigned long type,
447 ArrayBufferView* pixels);
449 // Helper function to validate mode for draw{Arrays/Elements}.
450 bool validateDrawMode(unsigned long);
452 // Helper function for texParameterf and texParameteri.
453 void texParameter(unsigned long target, unsigned long pname, float parami, int paramf, bool isFloat);
455 // Helper function to print warnings to console. Currently
456 // used only to warn about use of obsolete functions.
457 void printWarningToConsole(const String& message);
459 // Helper function to validate input parameters for framebuffer functions.
460 // Generate GL error if parameters are illegal.
461 bool validateFramebufferFuncParameters(unsigned long target, unsigned long attachment);
463 // Helper function to validate blend equation mode.
464 bool validateBlendEquation(unsigned long);
466 // Helper function to validate a GL capability.
467 bool validateCapability(unsigned long);
469 // Helper function to validate input parameters for uniform functions.
470 bool validateUniformParameters(const WebGLUniformLocation* location, Float32Array* v, int mod);
471 bool validateUniformParameters(const WebGLUniformLocation* location, Int32Array* v, int mod);
472 bool validateUniformParameters(const WebGLUniformLocation* location, void* v, int size, int mod);
473 bool validateUniformMatrixParameters(const WebGLUniformLocation* location, bool transpose, Float32Array* v, int mod);
474 bool validateUniformMatrixParameters(const WebGLUniformLocation* location, bool transpose, void* v, int size, int mod);
476 friend class WebGLStateRestorer;
479 } // namespace WebCore