• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 GraphicsContext3D_h
27 #define GraphicsContext3D_h
28 
29 #include "PlatformString.h"
30 
31 #include <wtf/ListHashSet.h>
32 #include <wtf/Noncopyable.h>
33 #include <wtf/PassOwnPtr.h>
34 
35 // FIXME: Find a better way to avoid the name confliction for NO_ERROR.
36 #if ((PLATFORM(CHROMIUM) && OS(WINDOWS)) || PLATFORM(WIN))
37 #undef NO_ERROR
38 #endif
39 
40 #if PLATFORM(MAC)
41 #include <OpenGL/OpenGL.h>
42 
43 typedef void* PlatformGraphicsContext3D;
44 const  PlatformGraphicsContext3D NullPlatformGraphicsContext3D = 0;
45 typedef GLuint Platform3DObject;
46 const Platform3DObject NullPlatform3DObject = 0;
47 #else
48 typedef void* PlatformGraphicsContext3D;
49 const  PlatformGraphicsContext3D NullPlatformGraphicsContext3D = 0;
50 typedef int Platform3DObject;
51 const Platform3DObject NullPlatform3DObject = 0;
52 #endif
53 
54 namespace WebCore {
55     class WebGLActiveInfo;
56     class WebGLArray;
57     class WebGLBuffer;
58     class WebGLUnsignedByteArray;
59     class WebGLFloatArray;
60     class WebGLFramebuffer;
61     class WebGLIntArray;
62     class WebGLProgram;
63     class WebGLRenderbuffer;
64     class WebGLRenderingContext;
65     class WebGLShader;
66     class WebGLTexture;
67     class Image;
68 
69     struct ActiveInfo {
70         String name;
71         unsigned type;
72         int size;
73     };
74 
75     // FIXME: ideally this would be used on all platforms.
76 #if PLATFORM(CHROMIUM)
77     class GraphicsContext3DInternal;
78 #endif
79 
80     class GraphicsContext3D : public Noncopyable {
81     public:
82         enum WebGLEnumType {
83             DEPTH_BUFFER_BIT = 0x00000100,
84             STENCIL_BUFFER_BIT = 0x00000400,
85             COLOR_BUFFER_BIT = 0x00004000,
86             POINTS = 0x0000,
87             LINES = 0x0001,
88             LINE_LOOP = 0x0002,
89             LINE_STRIP = 0x0003,
90             TRIANGLES = 0x0004,
91             TRIANGLE_STRIP = 0x0005,
92             TRIANGLE_FAN = 0x0006,
93             ZERO = 0,
94             ONE = 1,
95             SRC_COLOR = 0x0300,
96             ONE_MINUS_SRC_COLOR = 0x0301,
97             SRC_ALPHA = 0x0302,
98             ONE_MINUS_SRC_ALPHA = 0x0303,
99             DST_ALPHA = 0x0304,
100             ONE_MINUS_DST_ALPHA = 0x0305,
101             DST_COLOR = 0x0306,
102             ONE_MINUS_DST_COLOR = 0x0307,
103             SRC_ALPHA_SATURATE = 0x0308,
104             FUNC_ADD = 0x8006,
105             BLEND_EQUATION = 0x8009,
106             BLEND_EQUATION_RGB = 0x8009,
107             BLEND_EQUATION_ALPHA = 0x883D,
108             FUNC_SUBTRACT = 0x800A,
109             FUNC_REVERSE_SUBTRACT = 0x800B,
110             BLEND_DST_RGB = 0x80C8,
111             BLEND_SRC_RGB = 0x80C9,
112             BLEND_DST_ALPHA = 0x80CA,
113             BLEND_SRC_ALPHA = 0x80CB,
114             CONSTANT_COLOR = 0x8001,
115             ONE_MINUS_CONSTANT_COLOR = 0x8002,
116             CONSTANT_ALPHA = 0x8003,
117             ONE_MINUS_CONSTANT_ALPHA = 0x8004,
118             BLEND_COLOR = 0x8005,
119             ARRAY_BUFFER = 0x8892,
120             ELEMENT_ARRAY_BUFFER = 0x8893,
121             ARRAY_BUFFER_BINDING = 0x8894,
122             ELEMENT_ARRAY_BUFFER_BINDING = 0x8895,
123             STREAM_DRAW = 0x88E0,
124             STATIC_DRAW = 0x88E4,
125             DYNAMIC_DRAW = 0x88E8,
126             BUFFER_SIZE = 0x8764,
127             BUFFER_USAGE = 0x8765,
128             CURRENT_VERTEX_ATTRIB = 0x8626,
129             FRONT = 0x0404,
130             BACK = 0x0405,
131             FRONT_AND_BACK = 0x0408,
132             TEXTURE_2D = 0x0DE1,
133             CULL_FACE = 0x0B44,
134             BLEND = 0x0BE2,
135             DITHER = 0x0BD0,
136             STENCIL_TEST = 0x0B90,
137             DEPTH_TEST = 0x0B71,
138             SCISSOR_TEST = 0x0C11,
139             POLYGON_OFFSET_FILL = 0x8037,
140             SAMPLE_ALPHA_TO_COVERAGE = 0x809E,
141             SAMPLE_COVERAGE = 0x80A0,
142             NO_ERROR = 0,
143             INVALID_ENUM = 0x0500,
144             INVALID_VALUE = 0x0501,
145             INVALID_OPERATION = 0x0502,
146             OUT_OF_MEMORY = 0x0505,
147             CW = 0x0900,
148             CCW = 0x0901,
149             LINE_WIDTH = 0x0B21,
150             ALIASED_POINT_SIZE_RANGE = 0x846D,
151             ALIASED_LINE_WIDTH_RANGE = 0x846E,
152             CULL_FACE_MODE = 0x0B45,
153             FRONT_FACE = 0x0B46,
154             DEPTH_RANGE = 0x0B70,
155             DEPTH_WRITEMASK = 0x0B72,
156             DEPTH_CLEAR_VALUE = 0x0B73,
157             DEPTH_FUNC = 0x0B74,
158             STENCIL_CLEAR_VALUE = 0x0B91,
159             STENCIL_FUNC = 0x0B92,
160             STENCIL_FAIL = 0x0B94,
161             STENCIL_PASS_DEPTH_FAIL = 0x0B95,
162             STENCIL_PASS_DEPTH_PASS = 0x0B96,
163             STENCIL_REF = 0x0B97,
164             STENCIL_VALUE_MASK = 0x0B93,
165             STENCIL_WRITEMASK = 0x0B98,
166             STENCIL_BACK_FUNC = 0x8800,
167             STENCIL_BACK_FAIL = 0x8801,
168             STENCIL_BACK_PASS_DEPTH_FAIL = 0x8802,
169             STENCIL_BACK_PASS_DEPTH_PASS = 0x8803,
170             STENCIL_BACK_REF = 0x8CA3,
171             STENCIL_BACK_VALUE_MASK = 0x8CA4,
172             STENCIL_BACK_WRITEMASK = 0x8CA5,
173             VIEWPORT = 0x0BA2,
174             SCISSOR_BOX = 0x0C10,
175             COLOR_CLEAR_VALUE = 0x0C22,
176             COLOR_WRITEMASK = 0x0C23,
177             UNPACK_ALIGNMENT = 0x0CF5,
178             PACK_ALIGNMENT = 0x0D05,
179             MAX_TEXTURE_SIZE = 0x0D33,
180             MAX_VIEWPORT_DIMS = 0x0D3A,
181             SUBPIXEL_BITS = 0x0D50,
182             RED_BITS = 0x0D52,
183             GREEN_BITS = 0x0D53,
184             BLUE_BITS = 0x0D54,
185             ALPHA_BITS = 0x0D55,
186             DEPTH_BITS = 0x0D56,
187             STENCIL_BITS = 0x0D57,
188             POLYGON_OFFSET_UNITS = 0x2A00,
189             POLYGON_OFFSET_FACTOR = 0x8038,
190             TEXTURE_BINDING_2D = 0x8069,
191             SAMPLE_BUFFERS = 0x80A8,
192             SAMPLES = 0x80A9,
193             SAMPLE_COVERAGE_VALUE = 0x80AA,
194             SAMPLE_COVERAGE_INVERT = 0x80AB,
195             NUM_COMPRESSED_TEXTURE_FORMATS = 0x86A2,
196             COMPRESSED_TEXTURE_FORMATS = 0x86A3,
197             DONT_CARE = 0x1100,
198             FASTEST = 0x1101,
199             NICEST = 0x1102,
200             GENERATE_MIPMAP_HINT = 0x8192,
201             BYTE = 0x1400,
202             UNSIGNED_BYTE = 0x1401,
203             SHORT = 0x1402,
204             UNSIGNED_SHORT = 0x1403,
205             INT = 0x1404,
206             UNSIGNED_INT = 0x1405,
207             FLOAT = 0x1406,
208             FIXED = 0x140C,
209             DEPTH_COMPONENT = 0x1902,
210             ALPHA = 0x1906,
211             RGB = 0x1907,
212             RGBA = 0x1908,
213             LUMINANCE = 0x1909,
214             LUMINANCE_ALPHA = 0x190A,
215             UNSIGNED_SHORT_4_4_4_4 = 0x8033,
216             UNSIGNED_SHORT_5_5_5_1 = 0x8034,
217             UNSIGNED_SHORT_5_6_5 = 0x8363,
218             FRAGMENT_SHADER = 0x8B30,
219             VERTEX_SHADER = 0x8B31,
220             MAX_VERTEX_ATTRIBS = 0x8869,
221             MAX_VERTEX_UNIFORM_VECTORS = 0x8DFB,
222             MAX_VARYING_VECTORS = 0x8DFC,
223             MAX_COMBINED_TEXTURE_IMAGE_UNITS = 0x8B4D,
224             MAX_VERTEX_TEXTURE_IMAGE_UNITS = 0x8B4C,
225             MAX_TEXTURE_IMAGE_UNITS = 0x8872,
226             MAX_FRAGMENT_UNIFORM_VECTORS = 0x8DFD,
227             SHADER_TYPE = 0x8B4F,
228             DELETE_STATUS = 0x8B80,
229             LINK_STATUS = 0x8B82,
230             VALIDATE_STATUS = 0x8B83,
231             ATTACHED_SHADERS = 0x8B85,
232             ACTIVE_UNIFORMS = 0x8B86,
233             ACTIVE_UNIFORM_MAX_LENGTH = 0x8B87,
234             ACTIVE_ATTRIBUTES = 0x8B89,
235             ACTIVE_ATTRIBUTE_MAX_LENGTH = 0x8B8A,
236             SHADING_LANGUAGE_VERSION = 0x8B8C,
237             CURRENT_PROGRAM = 0x8B8D,
238             NEVER = 0x0200,
239             LESS = 0x0201,
240             EQUAL = 0x0202,
241             LEQUAL = 0x0203,
242             GREATER = 0x0204,
243             NOTEQUAL = 0x0205,
244             GEQUAL = 0x0206,
245             ALWAYS = 0x0207,
246             KEEP = 0x1E00,
247             REPLACE = 0x1E01,
248             INCR = 0x1E02,
249             DECR = 0x1E03,
250             INVERT = 0x150A,
251             INCR_WRAP = 0x8507,
252             DECR_WRAP = 0x8508,
253             VENDOR = 0x1F00,
254             RENDERER = 0x1F01,
255             VERSION = 0x1F02,
256             EXTENSIONS = 0x1F03,
257             NEAREST = 0x2600,
258             LINEAR = 0x2601,
259             NEAREST_MIPMAP_NEAREST = 0x2700,
260             LINEAR_MIPMAP_NEAREST = 0x2701,
261             NEAREST_MIPMAP_LINEAR = 0x2702,
262             LINEAR_MIPMAP_LINEAR = 0x2703,
263             TEXTURE_MAG_FILTER = 0x2800,
264             TEXTURE_MIN_FILTER = 0x2801,
265             TEXTURE_WRAP_S = 0x2802,
266             TEXTURE_WRAP_T = 0x2803,
267             TEXTURE = 0x1702,
268             TEXTURE_CUBE_MAP = 0x8513,
269             TEXTURE_BINDING_CUBE_MAP = 0x8514,
270             TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515,
271             TEXTURE_CUBE_MAP_NEGATIVE_X = 0x8516,
272             TEXTURE_CUBE_MAP_POSITIVE_Y = 0x8517,
273             TEXTURE_CUBE_MAP_NEGATIVE_Y = 0x8518,
274             TEXTURE_CUBE_MAP_POSITIVE_Z = 0x8519,
275             TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x851A,
276             MAX_CUBE_MAP_TEXTURE_SIZE = 0x851C,
277             TEXTURE0 = 0x84C0,
278             TEXTURE1 = 0x84C1,
279             TEXTURE2 = 0x84C2,
280             TEXTURE3 = 0x84C3,
281             TEXTURE4 = 0x84C4,
282             TEXTURE5 = 0x84C5,
283             TEXTURE6 = 0x84C6,
284             TEXTURE7 = 0x84C7,
285             TEXTURE8 = 0x84C8,
286             TEXTURE9 = 0x84C9,
287             TEXTURE10 = 0x84CA,
288             TEXTURE11 = 0x84CB,
289             TEXTURE12 = 0x84CC,
290             TEXTURE13 = 0x84CD,
291             TEXTURE14 = 0x84CE,
292             TEXTURE15 = 0x84CF,
293             TEXTURE16 = 0x84D0,
294             TEXTURE17 = 0x84D1,
295             TEXTURE18 = 0x84D2,
296             TEXTURE19 = 0x84D3,
297             TEXTURE20 = 0x84D4,
298             TEXTURE21 = 0x84D5,
299             TEXTURE22 = 0x84D6,
300             TEXTURE23 = 0x84D7,
301             TEXTURE24 = 0x84D8,
302             TEXTURE25 = 0x84D9,
303             TEXTURE26 = 0x84DA,
304             TEXTURE27 = 0x84DB,
305             TEXTURE28 = 0x84DC,
306             TEXTURE29 = 0x84DD,
307             TEXTURE30 = 0x84DE,
308             TEXTURE31 = 0x84DF,
309             ACTIVE_TEXTURE = 0x84E0,
310             REPEAT = 0x2901,
311             CLAMP_TO_EDGE = 0x812F,
312             MIRRORED_REPEAT = 0x8370,
313             FLOAT_VEC2 = 0x8B50,
314             FLOAT_VEC3 = 0x8B51,
315             FLOAT_VEC4 = 0x8B52,
316             INT_VEC2 = 0x8B53,
317             INT_VEC3 = 0x8B54,
318             INT_VEC4 = 0x8B55,
319             BOOL = 0x8B56,
320             BOOL_VEC2 = 0x8B57,
321             BOOL_VEC3 = 0x8B58,
322             BOOL_VEC4 = 0x8B59,
323             FLOAT_MAT2 = 0x8B5A,
324             FLOAT_MAT3 = 0x8B5B,
325             FLOAT_MAT4 = 0x8B5C,
326             SAMPLER_2D = 0x8B5E,
327             SAMPLER_CUBE = 0x8B60,
328             VERTEX_ATTRIB_ARRAY_ENABLED = 0x8622,
329             VERTEX_ATTRIB_ARRAY_SIZE = 0x8623,
330             VERTEX_ATTRIB_ARRAY_STRIDE = 0x8624,
331             VERTEX_ATTRIB_ARRAY_TYPE = 0x8625,
332             VERTEX_ATTRIB_ARRAY_NORMALIZED = 0x886A,
333             VERTEX_ATTRIB_ARRAY_POINTER = 0x8645,
334             VERTEX_ATTRIB_ARRAY_BUFFER_BINDING = 0x889F,
335             IMPLEMENTATION_COLOR_READ_TYPE = 0x8B9A,
336             IMPLEMENTATION_COLOR_READ_FORMAT = 0x8B9B,
337             COMPILE_STATUS = 0x8B81,
338             INFO_LOG_LENGTH = 0x8B84,
339             SHADER_SOURCE_LENGTH = 0x8B88,
340             SHADER_COMPILER = 0x8DFA,
341             SHADER_BINARY_FORMATS = 0x8DF8,
342             NUM_SHADER_BINARY_FORMATS = 0x8DF9,
343             LOW_FLOAT = 0x8DF0,
344             MEDIUM_FLOAT = 0x8DF1,
345             HIGH_FLOAT = 0x8DF2,
346             LOW_INT = 0x8DF3,
347             MEDIUM_INT = 0x8DF4,
348             HIGH_INT = 0x8DF5,
349             FRAMEBUFFER = 0x8D40,
350             RENDERBUFFER = 0x8D41,
351             RGBA4 = 0x8056,
352             RGB5_A1 = 0x8057,
353             RGB565 = 0x8D62,
354             DEPTH_COMPONENT16 = 0x81A5,
355             STENCIL_INDEX = 0x1901,
356             STENCIL_INDEX8 = 0x8D48,
357             RENDERBUFFER_WIDTH = 0x8D42,
358             RENDERBUFFER_HEIGHT = 0x8D43,
359             RENDERBUFFER_INTERNAL_FORMAT = 0x8D44,
360             RENDERBUFFER_RED_SIZE = 0x8D50,
361             RENDERBUFFER_GREEN_SIZE = 0x8D51,
362             RENDERBUFFER_BLUE_SIZE = 0x8D52,
363             RENDERBUFFER_ALPHA_SIZE = 0x8D53,
364             RENDERBUFFER_DEPTH_SIZE = 0x8D54,
365             RENDERBUFFER_STENCIL_SIZE = 0x8D55,
366             FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE = 0x8CD0,
367             FRAMEBUFFER_ATTACHMENT_OBJECT_NAME = 0x8CD1,
368             FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL = 0x8CD2,
369             FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE = 0x8CD3,
370             COLOR_ATTACHMENT0 = 0x8CE0,
371             DEPTH_ATTACHMENT = 0x8D00,
372             STENCIL_ATTACHMENT = 0x8D20,
373             NONE = 0,
374             FRAMEBUFFER_COMPLETE = 0x8CD5,
375             FRAMEBUFFER_INCOMPLETE_ATTACHMENT = 0x8CD6,
376             FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = 0x8CD7,
377             FRAMEBUFFER_INCOMPLETE_DIMENSIONS = 0x8CD9,
378             FRAMEBUFFER_UNSUPPORTED = 0x8CDD,
379             FRAMEBUFFER_BINDING = 0x8CA6,
380             RENDERBUFFER_BINDING = 0x8CA7,
381             MAX_RENDERBUFFER_SIZE = 0x84E8,
382             INVALID_FRAMEBUFFER_OPERATION = 0x0506
383         };
384 
385         // Context creation attributes.
386         struct Attributes {
AttributesAttributes387             Attributes()
388                 : alpha(true)
389                 , depth(true)
390                 , stencil(true)
391                 , antialias(true)
392                 , premultipliedAlpha(true)
393             {
394             }
395 
396             bool alpha;
397             bool depth;
398             bool stencil;
399             bool antialias;
400             bool premultipliedAlpha;
401         };
402 
403         static PassOwnPtr<GraphicsContext3D> create(Attributes attrs);
404         virtual ~GraphicsContext3D();
405 
406 #if PLATFORM(MAC)
platformGraphicsContext3D()407         PlatformGraphicsContext3D platformGraphicsContext3D() const { return m_contextObj; }
platformTexture()408         Platform3DObject platformTexture() const { return m_texture; }
409 #elif PLATFORM(CHROMIUM)
410         PlatformGraphicsContext3D platformGraphicsContext3D() const;
411         Platform3DObject platformTexture() const;
412 #else
platformGraphicsContext3D()413         PlatformGraphicsContext3D platformGraphicsContext3D() const { return NullPlatformGraphicsContext3D; }
platformTexture()414         Platform3DObject platformTexture() const { return NullPlatform3DObject; }
415 #endif
416         void makeContextCurrent();
417 
418         // Helper to return the size in bytes of OpenGL data types
419         // like GL_FLOAT, GL_INT, etc.
420         int sizeInBytes(int type);
421 
422         void activeTexture(unsigned long texture);
423         void attachShader(WebGLProgram* program, WebGLShader* shader);
424         void bindAttribLocation(WebGLProgram*, unsigned long index, const String& name);
425         void bindBuffer(unsigned long target, WebGLBuffer*);
426         void bindFramebuffer(unsigned long target, WebGLFramebuffer*);
427         void bindRenderbuffer(unsigned long target, WebGLRenderbuffer*);
428         void bindTexture(unsigned long target, WebGLTexture* texture);
429         void blendColor(double red, double green, double blue, double alpha);
430         void blendEquation(unsigned long mode);
431         void blendEquationSeparate(unsigned long modeRGB, unsigned long modeAlpha);
432         void blendFunc(unsigned long sfactor, unsigned long dfactor);
433         void blendFuncSeparate(unsigned long srcRGB, unsigned long dstRGB, unsigned long srcAlpha, unsigned long dstAlpha);
434 
435         void bufferData(unsigned long target, int size, unsigned long usage);
436         void bufferData(unsigned long target, WebGLArray* data, unsigned long usage);
437         void bufferSubData(unsigned long target, long offset, WebGLArray* data);
438 
439         unsigned long checkFramebufferStatus(unsigned long target);
440         void clear(unsigned long mask);
441         void clearColor(double red, double green, double blue, double alpha);
442         void clearDepth(double depth);
443         void clearStencil(long s);
444         void colorMask(bool red, bool green, bool blue, bool alpha);
445         void compileShader(WebGLShader*);
446 
447         //void compressedTexImage2D(unsigned long target, long level, unsigned long internalformat, unsigned long width, unsigned long height, long border, unsigned long imageSize, const void* data);
448         //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);
449 
450         void copyTexImage2D(unsigned long target, long level, unsigned long internalformat, long x, long y, unsigned long width, unsigned long height, long border);
451         void copyTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, long x, long y, unsigned long width, unsigned long height);
452         void cullFace(unsigned long mode);
453         void depthFunc(unsigned long func);
454         void depthMask(bool flag);
455         void depthRange(double zNear, double zFar);
456         void detachShader(WebGLProgram*, WebGLShader*);
457         void disable(unsigned long cap);
458         void disableVertexAttribArray(unsigned long index);
459         void drawArrays(unsigned long mode, long first, long count);
460         void drawElements(unsigned long mode, unsigned long count, unsigned long type, long offset);
461 
462         void enable(unsigned long cap);
463         void enableVertexAttribArray(unsigned long index);
464         void finish();
465         void flush();
466         void framebufferRenderbuffer(unsigned long target, unsigned long attachment, unsigned long renderbuffertarget, WebGLRenderbuffer*);
467         void framebufferTexture2D(unsigned long target, unsigned long attachment, unsigned long textarget, WebGLTexture*, long level);
468         void frontFace(unsigned long mode);
469         void generateMipmap(unsigned long target);
470 
471         bool getActiveAttrib(WebGLProgram* program, unsigned long index, ActiveInfo&);
472         bool getActiveUniform(WebGLProgram* program, unsigned long index, ActiveInfo&);
473 
474         int  getAttribLocation(WebGLProgram*, const String& name);
475 
476         void getBooleanv(unsigned long pname, unsigned char* value);
477 
478         void getBufferParameteriv(unsigned long target, unsigned long pname, int* value);
479 
480         Attributes getContextAttributes();
481 
482         unsigned long getError();
483 
484         void getFloatv(unsigned long pname, float* value);
485 
486         void getFramebufferAttachmentParameteriv(unsigned long target, unsigned long attachment, unsigned long pname, int* value);
487 
488         void getIntegerv(unsigned long pname, int* value);
489 
490         void getProgramiv(WebGLProgram* program, unsigned long pname, int* value);
491 
492         String getProgramInfoLog(WebGLProgram*);
493 
494         void getRenderbufferParameteriv(unsigned long target, unsigned long pname, int* value);
495 
496         void getShaderiv(WebGLShader*, unsigned long pname, int* value);
497 
498         String getShaderInfoLog(WebGLShader*);
499 
500         // TBD
501         // void glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision);
502 
503         String getShaderSource(WebGLShader*);
504         String getString(unsigned long name);
505 
506         void getTexParameterfv(unsigned long target, unsigned long pname, float* value);
507         void getTexParameteriv(unsigned long target, unsigned long pname, int* value);
508 
509         void getUniformfv(WebGLProgram* program, long location, float* value);
510         void getUniformiv(WebGLProgram* program, long location, int* value);
511 
512         long getUniformLocation(WebGLProgram*, const String& name);
513 
514         void getVertexAttribfv(unsigned long index, unsigned long pname, float* value);
515         void getVertexAttribiv(unsigned long index, unsigned long pname, int* value);
516 
517         long getVertexAttribOffset(unsigned long index, unsigned long pname);
518 
519         void hint(unsigned long target, unsigned long mode);
520         bool isBuffer(WebGLBuffer*);
521         bool isEnabled(unsigned long cap);
522         bool isFramebuffer(WebGLFramebuffer*);
523         bool isProgram(WebGLProgram*);
524         bool isRenderbuffer(WebGLRenderbuffer*);
525         bool isShader(WebGLShader*);
526         bool isTexture(WebGLTexture*);
527         void lineWidth(double);
528         void linkProgram(WebGLProgram*);
529         void pixelStorei(unsigned long pname, long param);
530         void polygonOffset(double factor, double units);
531 
532         PassRefPtr<WebGLArray> readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type);
533 
534         void releaseShaderCompiler();
535         void renderbufferStorage(unsigned long target, unsigned long internalformat, unsigned long width, unsigned long height);
536         void sampleCoverage(double value, bool invert);
537         void scissor(long x, long y, unsigned long width, unsigned long height);
538         void shaderSource(WebGLShader*, const String& string);
539         void stencilFunc(unsigned long func, long ref, unsigned long mask);
540         void stencilFuncSeparate(unsigned long face, unsigned long func, long ref, unsigned long mask);
541         void stencilMask(unsigned long mask);
542         void stencilMaskSeparate(unsigned long face, unsigned long mask);
543         void stencilOp(unsigned long fail, unsigned long zfail, unsigned long zpass);
544         void stencilOpSeparate(unsigned long face, unsigned long fail, unsigned long zfail, unsigned long zpass);
545 
546         // These next several functions return an error code (0 if no errors) rather than using an ExceptionCode.
547         // Currently they return -1 on any error.
548         int texImage2D(unsigned target, unsigned level, unsigned internalformat, unsigned width, unsigned height, unsigned border, unsigned format, unsigned type, void* pixels);
549         int texImage2D(unsigned target, unsigned level, Image* image, bool flipY, bool premultiplyAlpha);
550 
551         void texParameterf(unsigned target, unsigned pname, float param);
552         void texParameteri(unsigned target, unsigned pname, int param);
553 
554         int texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, unsigned width, unsigned height, unsigned format, unsigned type, void* pixels);
555         int texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, Image* image, bool flipY, bool premultiplyAlpha);
556 
557         void uniform1f(long location, float x);
558         void uniform1fv(long location, float* v, int size);
559         void uniform1i(long location, int x);
560         void uniform1iv(long location, int* v, int size);
561         void uniform2f(long location, float x, float y);
562         void uniform2fv(long location, float* v, int size);
563         void uniform2i(long location, int x, int y);
564         void uniform2iv(long location, int* v, int size);
565         void uniform3f(long location, float x, float y, float z);
566         void uniform3fv(long location, float* v, int size);
567         void uniform3i(long location, int x, int y, int z);
568         void uniform3iv(long location, int* v, int size);
569         void uniform4f(long location, float x, float y, float z, float w);
570         void uniform4fv(long location, float* v, int size);
571         void uniform4i(long location, int x, int y, int z, int w);
572         void uniform4iv(long location, int* v, int size);
573         void uniformMatrix2fv(long location, bool transpose, float* value, int size);
574         void uniformMatrix3fv(long location, bool transpose, float* value, int size);
575         void uniformMatrix4fv(long location, bool transpose, float* value, int size);
576 
577         void useProgram(WebGLProgram*);
578         void validateProgram(WebGLProgram*);
579 
580         void vertexAttrib1f(unsigned long indx, float x);
581         void vertexAttrib1fv(unsigned long indx, float* values);
582         void vertexAttrib2f(unsigned long indx, float x, float y);
583         void vertexAttrib2fv(unsigned long indx, float* values);
584         void vertexAttrib3f(unsigned long indx, float x, float y, float z);
585         void vertexAttrib3fv(unsigned long indx, float* values);
586         void vertexAttrib4f(unsigned long indx, float x, float y, float z, float w);
587         void vertexAttrib4fv(unsigned long indx, float* values);
588         void vertexAttribPointer(unsigned long indx, int size, int type, bool normalized,
589                                  unsigned long stride, unsigned long offset);
590 
591         void viewport(long x, long y, unsigned long width, unsigned long height);
592 
593         void reshape(int width, int height);
594 
595         // Helpers for notification about paint events
596         void beginPaint(WebGLRenderingContext* context);
597         void endPaint();
598 
599         // Support for buffer creation and deletion
600         unsigned createBuffer();
601         unsigned createFramebuffer();
602         unsigned createProgram();
603         unsigned createRenderbuffer();
604         unsigned createShader(unsigned long);
605         unsigned createTexture();
606 
607         void deleteBuffer(unsigned);
608         void deleteFramebuffer(unsigned);
609         void deleteProgram(unsigned);
610         void deleteRenderbuffer(unsigned);
611         void deleteShader(unsigned);
612         void deleteTexture(unsigned);
613 
614         // Synthesizes an OpenGL error which will be returned from a
615         // later call to getError. This is used to emulate OpenGL ES
616         // 2.0 behavior on the desktop and to enforce additional error
617         // checking mandated by WebGL.
618         //
619         // Per the behavior of glGetError, this stores at most one
620         // instance of any given error, and returns them from calls to
621         // getError in the order they were added.
622         void synthesizeGLError(unsigned long error);
623 
624     private:
625         GraphicsContext3D(Attributes attrs);
626 
627         int m_currentWidth, m_currentHeight;
628 
629 #if PLATFORM(MAC)
630         Attributes m_attrs;
631         Vector<Vector<float> > m_vertexArray;
632 
633         CGLContextObj m_contextObj;
634         GLuint m_texture;
635         GLuint m_fbo;
636         GLuint m_depthBuffer;
637         // Errors raised by synthesizeGLError().
638         ListHashSet<unsigned long> m_syntheticErrors;
639 #endif
640 
641         // FIXME: ideally this would be used on all platforms.
642 #if PLATFORM(CHROMIUM)
643         friend class GraphicsContext3DInternal;
644         OwnPtr<GraphicsContext3DInternal> m_internal;
645 #endif
646     };
647 
648 } // namespace WebCore
649 
650 #endif // GraphicsContext3D_h
651