WebCore/html/canvas/WebGLRenderingContext.h
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2  * Copyright (C) 2009 Apple Inc. 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
       
     6  * are met:
       
     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.
       
    12  *
       
    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. 
       
    24  */
       
    25 
       
    26 #ifndef WebGLRenderingContext_h
       
    27 #define WebGLRenderingContext_h
       
    28 
       
    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"
       
    37 
       
    38 namespace WebCore {
       
    39 
       
    40 class WebGLActiveInfo;
       
    41 class WebGLBuffer;
       
    42 class WebGLContextAttributes;
       
    43 class WebGLFramebuffer;
       
    44 class CanvasObject;
       
    45 class WebGLProgram;
       
    46 class WebGLRenderbuffer;
       
    47 class WebGLShader;
       
    48 class WebGLTexture;
       
    49 class WebGLUniformLocation;
       
    50 class HTMLImageElement;
       
    51 class HTMLVideoElement;
       
    52 class ImageData;
       
    53 class WebKitCSSMatrix;
       
    54 
       
    55     class WebGLRenderingContext : public CanvasRenderingContext {
       
    56     public:
       
    57         static PassOwnPtr<WebGLRenderingContext> create(HTMLCanvasElement*, WebGLContextAttributes*);
       
    58         virtual ~WebGLRenderingContext();
       
    59 
       
    60         virtual bool is3d() const { return true; }
       
    61 
       
    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);
       
    65 
       
    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);
       
    78 
       
    79         void bufferData(unsigned long target, int size, unsigned long usage, ExceptionCode&);
       
    80         void bufferData(unsigned long target, ArrayBuffer* data, unsigned long usage, ExceptionCode&);
       
    81         void bufferData(unsigned long target, ArrayBufferView* data, unsigned long usage, ExceptionCode&);
       
    82         void bufferSubData(unsigned long target, long offset, ArrayBuffer* data, ExceptionCode&);
       
    83         void bufferSubData(unsigned long target, long offset, ArrayBufferView* data, ExceptionCode&);
       
    84 
       
    85         unsigned long checkFramebufferStatus(unsigned long target);
       
    86         void clear(unsigned long mask);
       
    87         void clearColor(double red, double green, double blue, double alpha);
       
    88         void clearDepth(double);
       
    89         void clearStencil(long);
       
    90         void colorMask(bool red, bool green, bool blue, bool alpha);
       
    91         void compileShader(WebGLShader*, ExceptionCode& ec);
       
    92         
       
    93         //void compressedTexImage2D(unsigned long target, long level, unsigned long internalformat, unsigned long width, unsigned long height, long border, unsigned long imageSize, const void* data);
       
    94         //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);
       
    95         
       
    96         void copyTexImage2D(unsigned long target, long level, unsigned long internalformat, long x, long y, unsigned long width, unsigned long height, long border);
       
    97         void copyTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, long x, long y, unsigned long width, unsigned long height);
       
    98 
       
    99         PassRefPtr<WebGLBuffer> createBuffer();
       
   100         PassRefPtr<WebGLFramebuffer> createFramebuffer();
       
   101         PassRefPtr<WebGLProgram> createProgram();
       
   102         PassRefPtr<WebGLRenderbuffer> createRenderbuffer();
       
   103         PassRefPtr<WebGLShader> createShader(unsigned long type, ExceptionCode&);
       
   104         PassRefPtr<WebGLTexture> createTexture();
       
   105 
       
   106         void cullFace(unsigned long mode);
       
   107 
       
   108         void deleteBuffer(WebGLBuffer*);
       
   109         void deleteFramebuffer(WebGLFramebuffer*);
       
   110         void deleteProgram(WebGLProgram*);
       
   111         void deleteRenderbuffer(WebGLRenderbuffer*);
       
   112         void deleteShader(WebGLShader*);
       
   113         void deleteTexture(WebGLTexture*);
       
   114         
       
   115         void depthFunc(unsigned long);
       
   116         void depthMask(bool);
       
   117         void depthRange(double zNear, double zFar);
       
   118         void detachShader(WebGLProgram*, WebGLShader*, ExceptionCode&);
       
   119         void disable(unsigned long cap);
       
   120         void disableVertexAttribArray(unsigned long index, ExceptionCode&);
       
   121         void drawArrays(unsigned long mode, long first, long count, ExceptionCode&);
       
   122         void drawElements(unsigned long mode, long count, unsigned long type, long offset, ExceptionCode&);
       
   123 
       
   124         void enable(unsigned long cap);
       
   125         void enableVertexAttribArray(unsigned long index, ExceptionCode&);
       
   126         void finish();
       
   127         void flush();
       
   128         void framebufferRenderbuffer(unsigned long target, unsigned long attachment, unsigned long renderbuffertarget, WebGLRenderbuffer*, ExceptionCode& ec);
       
   129         void framebufferTexture2D(unsigned long target, unsigned long attachment, unsigned long textarget, WebGLTexture*, long level, ExceptionCode& ec);
       
   130         void frontFace(unsigned long mode);
       
   131         void generateMipmap(unsigned long target);
       
   132 
       
   133         PassRefPtr<WebGLActiveInfo> getActiveAttrib(WebGLProgram*, unsigned long index, ExceptionCode&);
       
   134         PassRefPtr<WebGLActiveInfo> getActiveUniform(WebGLProgram*, unsigned long index, ExceptionCode&);
       
   135 
       
   136         bool getAttachedShaders(WebGLProgram*, Vector<WebGLShader*>&, ExceptionCode&);
       
   137 
       
   138         int  getAttribLocation(WebGLProgram*, const String& name);
       
   139 
       
   140         WebGLGetInfo getBufferParameter(unsigned long target, unsigned long pname, ExceptionCode&);
       
   141 
       
   142         PassRefPtr<WebGLContextAttributes> getContextAttributes();
       
   143 
       
   144         unsigned long getError();
       
   145 
       
   146         WebGLGetInfo getFramebufferAttachmentParameter(unsigned long target, unsigned long attachment, unsigned long pname, ExceptionCode&);
       
   147 
       
   148         WebGLGetInfo getParameter(unsigned long pname, ExceptionCode&);
       
   149 
       
   150         WebGLGetInfo getProgramParameter(WebGLProgram*, unsigned long pname, ExceptionCode&);
       
   151 
       
   152         String getProgramInfoLog(WebGLProgram*, ExceptionCode& ec);
       
   153 
       
   154         WebGLGetInfo getRenderbufferParameter(unsigned long target, unsigned long pname, ExceptionCode&);
       
   155 
       
   156         WebGLGetInfo getShaderParameter(WebGLShader*, unsigned long pname, ExceptionCode& ec);
       
   157 
       
   158         String getShaderInfoLog(WebGLShader*, ExceptionCode& ec);
       
   159 
       
   160         // TBD
       
   161         // void glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision);
       
   162 
       
   163         String getShaderSource(WebGLShader*, ExceptionCode&);
       
   164         String getString(unsigned long name);
       
   165 
       
   166         WebGLGetInfo getTexParameter(unsigned long target, unsigned long pname, ExceptionCode&);
       
   167 
       
   168         WebGLGetInfo getUniform(WebGLProgram*, const WebGLUniformLocation*, ExceptionCode&);
       
   169 
       
   170         PassRefPtr<WebGLUniformLocation> getUniformLocation(WebGLProgram*, const String&, ExceptionCode&);
       
   171 
       
   172         WebGLGetInfo getVertexAttrib(unsigned long index, unsigned long pname, ExceptionCode&);
       
   173 
       
   174         long getVertexAttribOffset(unsigned long index, unsigned long pname);
       
   175 
       
   176         void hint(unsigned long target, unsigned long mode);
       
   177         bool isBuffer(WebGLBuffer*);
       
   178         bool isEnabled(unsigned long cap);
       
   179         bool isFramebuffer(WebGLFramebuffer*);
       
   180         bool isProgram(WebGLProgram*);
       
   181         bool isRenderbuffer(WebGLRenderbuffer*);
       
   182         bool isShader(WebGLShader*);
       
   183         bool isTexture(WebGLTexture*);
       
   184         void lineWidth(double);
       
   185         void linkProgram(WebGLProgram*, ExceptionCode&);
       
   186         void pixelStorei(unsigned long pname, long param);
       
   187         void polygonOffset(double factor, double units);
       
   188         void readPixels(long x, long y, long width, long height, unsigned long format, unsigned long type, ArrayBufferView* pixels);
       
   189         void releaseShaderCompiler();
       
   190         void renderbufferStorage(unsigned long target, unsigned long internalformat, unsigned long width, unsigned long height);
       
   191         void sampleCoverage(double value, bool invert);
       
   192         void scissor(long x, long y, unsigned long width, unsigned long height);
       
   193         void shaderSource(WebGLShader*, const String&, ExceptionCode&);
       
   194         void stencilFunc(unsigned long func, long ref, unsigned long mask);
       
   195         void stencilFuncSeparate(unsigned long face, unsigned long func, long ref, unsigned long mask);
       
   196         void stencilMask(unsigned long);
       
   197         void stencilMaskSeparate(unsigned long face, unsigned long mask);
       
   198         void stencilOp(unsigned long fail, unsigned long zfail, unsigned long zpass);
       
   199         void stencilOpSeparate(unsigned long face, unsigned long fail, unsigned long zfail, unsigned long zpass);
       
   200 
       
   201         void texImage2D(unsigned target, unsigned level, unsigned internalformat,
       
   202                         unsigned width, unsigned height, unsigned border,
       
   203                         unsigned format, unsigned type, ArrayBufferView* pixels, ExceptionCode&);
       
   204         void texImage2D(unsigned target, unsigned level, unsigned internalformat,
       
   205                         unsigned format, unsigned type, ImageData* pixels, ExceptionCode&);
       
   206         void texImage2D(unsigned target, unsigned level, unsigned internalformat,
       
   207                         unsigned format, unsigned type, HTMLImageElement* image, ExceptionCode&);
       
   208         void texImage2D(unsigned target, unsigned level, unsigned internalformat,
       
   209                         unsigned format, unsigned type, HTMLCanvasElement* canvas, ExceptionCode&);
       
   210         void texImage2D(unsigned target, unsigned level, unsigned internalformat,
       
   211                         unsigned format, unsigned type, HTMLVideoElement* video, ExceptionCode&);
       
   212         // Obsolete entry points -- to be removed shortly. (FIXME)
       
   213         void texImage2D(unsigned target, unsigned level, ImageData* pixels, ExceptionCode&);
       
   214         void texImage2D(unsigned target, unsigned level, ImageData* pixels, bool flipY, ExceptionCode&);
       
   215         void texImage2D(unsigned target, unsigned level, ImageData* pixels, bool flipY, bool premultiplyAlpha, ExceptionCode&);
       
   216         void texImage2D(unsigned target, unsigned level, HTMLImageElement* image, ExceptionCode&);
       
   217         void texImage2D(unsigned target, unsigned level, HTMLImageElement* image, bool flipY, ExceptionCode&);
       
   218         void texImage2D(unsigned target, unsigned level, HTMLImageElement* image, bool flipY, bool premultiplyAlpha, ExceptionCode&);
       
   219         void texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, ExceptionCode&);
       
   220         void texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, bool flipY, ExceptionCode&);
       
   221         void texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, bool flipY, bool premultiplyAlpha, ExceptionCode&);
       
   222         void texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, ExceptionCode&);
       
   223         void texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, bool flipY, ExceptionCode&);
       
   224         void texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, bool flipY, bool premultiplyAlpha, ExceptionCode&);
       
   225 
       
   226         void texParameterf(unsigned target, unsigned pname, float param);
       
   227         void texParameteri(unsigned target, unsigned pname, int param);
       
   228 
       
   229         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
       
   230                            unsigned width, unsigned height,
       
   231                            unsigned format, unsigned type, ArrayBufferView* pixels, ExceptionCode&);
       
   232         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
       
   233                            unsigned format, unsigned type, ImageData* pixels, ExceptionCode&);
       
   234         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
       
   235                            unsigned format, unsigned type, HTMLImageElement* image, ExceptionCode&);
       
   236         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
       
   237                            unsigned format, unsigned type, HTMLCanvasElement* canvas, ExceptionCode&);
       
   238         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
       
   239                            unsigned format, unsigned type, HTMLVideoElement* video, ExceptionCode&);
       
   240         // Obsolete entry points -- to be removed shortly. (FIXME)
       
   241         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, ImageData* pixels, ExceptionCode&);
       
   242         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, ImageData* pixels, bool flipY, ExceptionCode&);
       
   243         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, ImageData* pixels, bool flipY, bool premultiplyAlpha, ExceptionCode&);
       
   244         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLImageElement* image, ExceptionCode&);
       
   245         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLImageElement* image, bool flipY, ExceptionCode&);
       
   246         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLImageElement* image, bool flipY, bool premultiplyAlpha, ExceptionCode&);
       
   247         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLCanvasElement* canvas, ExceptionCode&);
       
   248         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLCanvasElement* canvas, bool flipY, ExceptionCode&);
       
   249         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLCanvasElement* canvas, bool flipY, bool premultiplyAlpha, ExceptionCode&);
       
   250         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLVideoElement* video, ExceptionCode&);
       
   251         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLVideoElement* video, bool flipY, ExceptionCode&);
       
   252         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLVideoElement* video, bool flipY, bool premultiplyAlpha, ExceptionCode&);
       
   253 
       
   254         void uniform1f(const WebGLUniformLocation* location, float x, ExceptionCode&);
       
   255         void uniform1fv(const WebGLUniformLocation* location, Float32Array* v, ExceptionCode&);
       
   256         void uniform1fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&);
       
   257         void uniform1i(const WebGLUniformLocation* location, int x, ExceptionCode&);
       
   258         void uniform1iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode&);
       
   259         void uniform1iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&);
       
   260         void uniform2f(const WebGLUniformLocation* location, float x, float y, ExceptionCode&);
       
   261         void uniform2fv(const WebGLUniformLocation* location, Float32Array* v, ExceptionCode&);
       
   262         void uniform2fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&);
       
   263         void uniform2i(const WebGLUniformLocation* location, int x, int y, ExceptionCode&);
       
   264         void uniform2iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode&);
       
   265         void uniform2iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&);
       
   266         void uniform3f(const WebGLUniformLocation* location, float x, float y, float z, ExceptionCode&);
       
   267         void uniform3fv(const WebGLUniformLocation* location, Float32Array* v, ExceptionCode&);
       
   268         void uniform3fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&);
       
   269         void uniform3i(const WebGLUniformLocation* location, int x, int y, int z, ExceptionCode&);
       
   270         void uniform3iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode&);
       
   271         void uniform3iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&);
       
   272         void uniform4f(const WebGLUniformLocation* location, float x, float y, float z, float w, ExceptionCode&);
       
   273         void uniform4fv(const WebGLUniformLocation* location, Float32Array* v, ExceptionCode&);
       
   274         void uniform4fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&);
       
   275         void uniform4i(const WebGLUniformLocation* location, int x, int y, int z, int w, ExceptionCode&);
       
   276         void uniform4iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode&);
       
   277         void uniform4iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&);
       
   278         void uniformMatrix2fv(const WebGLUniformLocation* location, bool transpose, Float32Array* value, ExceptionCode&);
       
   279         void uniformMatrix2fv(const WebGLUniformLocation* location, bool transpose, float* value, int size, ExceptionCode&);
       
   280         void uniformMatrix3fv(const WebGLUniformLocation* location, bool transpose, Float32Array* value, ExceptionCode&);
       
   281         void uniformMatrix3fv(const WebGLUniformLocation* location, bool transpose, float* value, int size, ExceptionCode&);
       
   282         void uniformMatrix4fv(const WebGLUniformLocation* location, bool transpose, Float32Array* value, ExceptionCode&);
       
   283         void uniformMatrix4fv(const WebGLUniformLocation* location, bool transpose, float* value, int size, ExceptionCode&);
       
   284 
       
   285         void useProgram(WebGLProgram*, ExceptionCode&);
       
   286         void validateProgram(WebGLProgram*, ExceptionCode&);
       
   287 
       
   288         void vertexAttrib1f(unsigned long index, float x);
       
   289         void vertexAttrib1fv(unsigned long index, Float32Array* values);
       
   290         void vertexAttrib1fv(unsigned long index, float* values, int size);
       
   291         void vertexAttrib2f(unsigned long index, float x, float y);
       
   292         void vertexAttrib2fv(unsigned long index, Float32Array* values);
       
   293         void vertexAttrib2fv(unsigned long index, float* values, int size);
       
   294         void vertexAttrib3f(unsigned long index, float x, float y, float z);
       
   295         void vertexAttrib3fv(unsigned long index, Float32Array* values);
       
   296         void vertexAttrib3fv(unsigned long index, float* values, int size);
       
   297         void vertexAttrib4f(unsigned long index, float x, float y, float z, float w);
       
   298         void vertexAttrib4fv(unsigned long index, Float32Array* values);
       
   299         void vertexAttrib4fv(unsigned long index, float* values, int size);
       
   300         void vertexAttribPointer(unsigned long index, long size, unsigned long type, bool normalized,
       
   301                                  long stride, long offset, ExceptionCode&);
       
   302 
       
   303         void viewport(long x, long y, unsigned long width, unsigned long height);
       
   304 
       
   305         GraphicsContext3D* graphicsContext3D() const { return m_context.get(); }
       
   306     
       
   307         void reshape(int width, int height);
       
   308 
       
   309         // Return value true indicates canvas is updated during the call,
       
   310         // false indicates no updates.
       
   311         bool paintRenderingResultsToCanvas();
       
   312 
       
   313         // Helpers for notification about paint events.
       
   314         void beginPaint();
       
   315         void endPaint();
       
   316         
       
   317         void removeObject(CanvasObject*);
       
   318         
       
   319     private:
       
   320         friend class CanvasObject;
       
   321 
       
   322         WebGLRenderingContext(HTMLCanvasElement*, PassOwnPtr<GraphicsContext3D>);
       
   323 
       
   324         void addObject(CanvasObject*);
       
   325         void detachAndRemoveAllObjects();
       
   326         WebGLTexture* findTexture(Platform3DObject);
       
   327         WebGLRenderbuffer* findRenderbuffer(Platform3DObject);
       
   328         WebGLBuffer* findBuffer(Platform3DObject);
       
   329         WebGLShader* findShader(Platform3DObject);
       
   330 
       
   331         void markContextChanged();
       
   332         void cleanupAfterGraphicsCall(bool changed)
       
   333         {
       
   334             if (changed)
       
   335                 markContextChanged();
       
   336         }
       
   337 
       
   338         bool isGLES2Compliant();
       
   339         
       
   340         // Basic validation of count and offset against number of elements in element array buffer
       
   341         bool validateElementArraySize(unsigned long count, unsigned long type, long offset);
       
   342 
       
   343         // Conservative but quick index validation
       
   344         bool validateIndexArrayConservative(unsigned long type, long& numElementsRequired);
       
   345 
       
   346         // Precise but slow index validation -- only done if conservative checks fail
       
   347         bool validateIndexArrayPrecise(unsigned long count, unsigned long type, long offset, long& numElementsRequired);
       
   348         bool validateRenderingState(long numElements);
       
   349 
       
   350         bool validateWebGLObject(CanvasObject* object);
       
   351 
       
   352         OwnPtr<GraphicsContext3D> m_context;
       
   353         bool m_needsUpdate;
       
   354         bool m_markedCanvasDirty;
       
   355         // FIXME: I think this is broken -- it does not increment any
       
   356         // reference counts, so may refer to destroyed objects.
       
   357         HashSet<RefPtr<CanvasObject> > m_canvasObjects;
       
   358         
       
   359         // List of bound VBO's. Used to maintain info about sizes for ARRAY_BUFFER and stored values for ELEMENT_ARRAY_BUFFER
       
   360         RefPtr<WebGLBuffer> m_boundArrayBuffer;
       
   361         RefPtr<WebGLBuffer> m_boundElementArrayBuffer;
       
   362     
       
   363         // Cached values for vertex attrib range checks
       
   364         class VertexAttribState {
       
   365         public:
       
   366             VertexAttribState()
       
   367                 : enabled(false)
       
   368                 , bytesPerElement(0)
       
   369                 , size(4)
       
   370                 , type(GraphicsContext3D::FLOAT)
       
   371                 , normalized(false)
       
   372                 , stride(16)
       
   373                 , originalStride(0)
       
   374                 , offset(0)
       
   375             {
       
   376                 initValue();
       
   377             }
       
   378 
       
   379             void initValue()
       
   380             {
       
   381                 value[0] = 0.0f;
       
   382                 value[1] = 0.0f;
       
   383                 value[2] = 0.0f;
       
   384                 value[3] = 1.0f;
       
   385             }
       
   386 
       
   387             bool enabled;
       
   388             RefPtr<WebGLBuffer> bufferBinding;
       
   389             long bytesPerElement;
       
   390             long size;
       
   391             unsigned long type;
       
   392             bool normalized;
       
   393             long stride;
       
   394             long originalStride;
       
   395             long offset;
       
   396             float value[4];
       
   397         };
       
   398         
       
   399         Vector<VertexAttribState> m_vertexAttribState;
       
   400         unsigned m_maxVertexAttribs;
       
   401         RefPtr<WebGLBuffer> m_vertexAttrib0Buffer;
       
   402         long m_vertexAttrib0BufferSize;
       
   403         float m_vertexAttrib0BufferValue[4];
       
   404 
       
   405         RefPtr<WebGLProgram> m_currentProgram;
       
   406         RefPtr<WebGLFramebuffer> m_framebufferBinding;
       
   407         RefPtr<WebGLRenderbuffer> m_renderbufferBinding;
       
   408         class TextureUnitState {
       
   409         public:
       
   410             RefPtr<WebGLTexture> m_texture2DBinding;
       
   411             RefPtr<WebGLTexture> m_textureCubeMapBinding;
       
   412         };
       
   413         Vector<TextureUnitState> m_textureUnits;
       
   414         unsigned long m_activeTextureUnit;
       
   415 
       
   416         RefPtr<WebGLTexture> m_blackTexture2D;
       
   417         RefPtr<WebGLTexture> m_blackTextureCubeMap;
       
   418 
       
   419         int m_maxTextureSize;
       
   420         int m_maxCubeMapTextureSize;
       
   421         int m_maxTextureLevel;
       
   422         int m_maxCubeMapTextureLevel;
       
   423 
       
   424         int m_packAlignment;
       
   425         int m_unpackAlignment;
       
   426         unsigned long m_implementationColorReadFormat;
       
   427         unsigned long m_implementationColorReadType;
       
   428         bool m_unpackFlipY;
       
   429         bool m_unpackPremultiplyAlpha;
       
   430 
       
   431         // Helpers for getParameter and others
       
   432         WebGLGetInfo getBooleanParameter(unsigned long pname);
       
   433         WebGLGetInfo getBooleanArrayParameter(unsigned long pname);
       
   434         WebGLGetInfo getFloatParameter(unsigned long pname);
       
   435         WebGLGetInfo getIntParameter(unsigned long pname);
       
   436         WebGLGetInfo getLongParameter(unsigned long pname);
       
   437         WebGLGetInfo getUnsignedLongParameter(unsigned long pname);
       
   438         WebGLGetInfo getWebGLFloatArrayParameter(unsigned long pname);
       
   439         WebGLGetInfo getWebGLIntArrayParameter(unsigned long pname);
       
   440 
       
   441         void texImage2DBase(unsigned target, unsigned level, unsigned internalformat,
       
   442                             unsigned width, unsigned height, unsigned border,
       
   443                             unsigned format, unsigned type, void* pixels, ExceptionCode&);
       
   444         void texImage2DImpl(unsigned target, unsigned level, unsigned internalformat,
       
   445                             unsigned format, unsigned type, Image* image,
       
   446                             bool flipY, bool premultiplyAlpha, ExceptionCode&);
       
   447         void texSubImage2DBase(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
       
   448                                unsigned width, unsigned height,
       
   449                                unsigned format, unsigned type, void* pixels, ExceptionCode&);
       
   450         void texSubImage2DImpl(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
       
   451                                unsigned format, unsigned type,
       
   452                                Image* image, bool flipY, bool premultiplyAlpha, ExceptionCode&);
       
   453 
       
   454         void handleNPOTTextures(bool prepareToDraw);
       
   455 
       
   456         void createFallbackBlackTextures1x1();
       
   457 
       
   458         // Helper function for copyTex{Sub}Image, check whether the internalformat
       
   459         // and the color buffer format of the current bound framebuffer combination
       
   460         // is valid.
       
   461         bool isTexInternalFormatColorBufferCombinationValid(unsigned long texInternalFormat,
       
   462                                                             unsigned long colorBufferFormat);
       
   463 
       
   464         // Helper function to get the current bound texture.
       
   465         WebGLTexture* getTextureBinding(unsigned long target);
       
   466 
       
   467         // Helper function to check input format/type for functions {copy}Tex{Sub}Image.
       
   468         // Generates GL error and returns false if parameters are invalid.
       
   469         bool validateTexFuncFormatAndType(unsigned long format, unsigned long type);
       
   470 
       
   471         // Helper function to check input parameters for functions {copy}Tex{Sub}Image.
       
   472         // Generates GL error and returns false if parameters are invalid.
       
   473         bool validateTexFuncParameters(unsigned long target, long level,
       
   474                                        unsigned long internalformat,
       
   475                                        long width, long height, long border,
       
   476                                        unsigned long format, unsigned long type);
       
   477 
       
   478         // Helper function to validate that the given ArrayBufferView
       
   479         // is of the correct type and contains enough data for the texImage call.
       
   480         // Generates GL error and returns false if parameters are invalid.
       
   481         bool validateTexFuncData(long width, long height,
       
   482                                  unsigned long format, unsigned long type,
       
   483                                  ArrayBufferView* pixels);
       
   484 
       
   485         // Helper function to validate mode for draw{Arrays/Elements}.
       
   486         bool validateDrawMode(unsigned long);
       
   487 
       
   488         // Helper function for texParameterf and texParameteri.
       
   489         void texParameter(unsigned long target, unsigned long pname, float parami, int paramf, bool isFloat);
       
   490 
       
   491         // Helper function to print warnings to console. Currently
       
   492         // used only to warn about use of obsolete functions.
       
   493         void printWarningToConsole(const String& message);
       
   494 
       
   495         // Helper function to validate input parameters for framebuffer functions.
       
   496         // Generate GL error if parameters are illegal.
       
   497         bool validateFramebufferFuncParameters(unsigned long target, unsigned long attachment);
       
   498 
       
   499         // Helper function to validate blend equation mode.
       
   500         bool validateBlendEquation(unsigned long);
       
   501 
       
   502         // Helper function to validate a GL capability.
       
   503         bool validateCapability(unsigned long);
       
   504 
       
   505         // Helper function to validate input parameters for uniform functions.
       
   506         bool validateUniformParameters(const WebGLUniformLocation* location, Float32Array* v, int mod);
       
   507         bool validateUniformParameters(const WebGLUniformLocation* location, Int32Array* v, int mod);
       
   508         bool validateUniformParameters(const WebGLUniformLocation* location, void* v, int size, int mod);
       
   509         bool validateUniformMatrixParameters(const WebGLUniformLocation* location, bool transpose, Float32Array* v, int mod);
       
   510         bool validateUniformMatrixParameters(const WebGLUniformLocation* location, bool transpose, void* v, int size, int mod);
       
   511 
       
   512         // Helper function to validate parameters for bufferData.
       
   513         // Return the current bound buffer to target, or 0 if parameters are invalid.
       
   514         WebGLBuffer* validateBufferDataParameters(unsigned long target, unsigned long usage);
       
   515 
       
   516         // Helper functions for vertexAttribNf{v}.
       
   517         void vertexAttribfImpl(unsigned long index, int expectedSize, float v0, float v1, float v2, float v3);
       
   518         void vertexAttribfvImpl(unsigned long index, Float32Array* v, int expectedSize);
       
   519         void vertexAttribfvImpl(unsigned long index, float* v, int size, int expectedSize);
       
   520 
       
   521         // Helpers for simulating vertexAttrib0
       
   522         void initVertexAttrib0();
       
   523         bool simulateVertexAttrib0(long numVertex);
       
   524         void restoreStatesAfterVertexAttrib0Simulation();
       
   525 
       
   526         friend class WebGLStateRestorer;
       
   527     };
       
   528 
       
   529 } // namespace WebCore
       
   530 
       
   531 #endif