root/trunk/BAL/Graphics/WebCore/Qt/BCGraphicsContext3DQt.cpp

Revision 1391, 55.7 kB (checked in by gbertal, 6 months ago)

merge with webkit revision 55361

Line 
1 /*
2     Copyright (C) 2010 Tieto Corporation.
3
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Lesser General Public
6     License as published by the Free Software Foundation; either
7     version 2.1 of the License, or (at your option) any later version.
8     
9     This library is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12     Lesser General Public License for more details.
13     
14     You should have received a copy of the GNU Lesser General Public
15     License along with this library; if not, write to the Free Software
16     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18
19 #include "config.h"
20
21 #if ENABLE(3D_CANVAS)
22
23 #include "GraphicsContext3D.h"
24
25 #include "CString.h"
26 #include "CanvasObject.h"
27 #include "GraphicsContext.h"
28 #include "HTMLCanvasElement.h"
29 #include "ImageBuffer.h"
30 #include "NotImplemented.h"
31 #include "WebGLActiveInfo.h"
32 #include "WebGLArray.h"
33 #include "WebGLBuffer.h"
34 #include "WebGLFloatArray.h"
35 #include "WebGLFramebuffer.h"
36 #include "WebGLIntArray.h"
37 #include "WebGLProgram.h"
38 #include "WebGLRenderbuffer.h"
39 #include "WebGLRenderingContext.h"
40 #include "WebGLShader.h"
41 #include "WebGLTexture.h"
42 #include "WebGLUnsignedByteArray.h"
43 #include <wtf/UnusedParam.h>
44
45 namespace WebCore {
46
47 #if !defined(GLchar)
48 typedef char GLchar;
49 #endif
50
51 #if !defined(APIENTRY)
52 #define APIENTRY
53 #endif
54
55 typedef void (APIENTRY* glActiveTextureType) (GLenum);
56 typedef void (APIENTRY* glAttachShaderType) (GLuint, GLuint);
57 typedef void (APIENTRY* glBindAttribLocationType) (GLuint, GLuint, const char*);
58 typedef void (APIENTRY* glBindBufferType) (GLenum, GLuint);
59 typedef void (APIENTRY* glBindFramebufferType) (GLenum, GLuint);
60 typedef void (APIENTRY* glBindRenderbufferType) (GLenum, GLuint);
61 typedef void (APIENTRY* glBlendColorType) (GLclampf, GLclampf, GLclampf, GLclampf);
62 typedef void (APIENTRY* glBlendEquationType) (GLenum);
63 typedef void (APIENTRY* glBlendEquationSeparateType)(GLenum, GLenum);
64 typedef void (APIENTRY* glBlendFuncSeparateType)(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
65 typedef void (APIENTRY* glBufferDataType) (GLenum, GLsizeiptr, const GLvoid*, GLenum);
66 typedef void (APIENTRY* glBufferSubDataType) (GLenum, GLintptr, GLsizeiptr, const GLvoid*);
67 typedef GLenum (APIENTRY* glCheckFramebufferStatusType) (GLenum);
68 typedef void (APIENTRY* glCompileShaderType) (GLuint);
69 typedef GLuint (APIENTRY* glCreateProgramType) ();
70 typedef GLuint (APIENTRY* glCreateShaderType) (GLenum);
71 typedef void (APIENTRY* glDeleteBuffersType) (GLsizei, const GLuint*);
72 typedef void (APIENTRY* glDeleteFramebuffersType) (GLsizei n, const GLuint*);
73 typedef void (APIENTRY* glDeleteProgramType) (GLuint);
74 typedef void (APIENTRY* glDeleteRenderbuffersType) (GLsizei n, const GLuint*);
75 typedef void (APIENTRY* glDeleteShaderType) (GLuint);
76 typedef void (APIENTRY* glDetachShaderType) (GLuint, GLuint);
77 typedef void (APIENTRY* glDisableVertexAttribArrayType) (GLuint);
78 typedef void (APIENTRY* glEnableVertexAttribArrayType) (GLuint);
79 typedef void (APIENTRY* glFramebufferRenderbufferType) (GLenum, GLenum, GLenum, GLuint);
80 typedef void (APIENTRY* glFramebufferTexture2DType) (GLenum, GLenum, GLenum, GLuint, GLint);
81 typedef void (APIENTRY* glGenBuffersType) (GLsizei, GLuint*);
82 typedef void (APIENTRY* glGenerateMipmapType) (GLenum target);
83 typedef void (APIENTRY* glGenFramebuffersType) (GLsizei, GLuint*);
84 typedef void (APIENTRY* glGenRenderbuffersType) (GLsizei, GLuint*);
85 typedef void (APIENTRY* glGetActiveAttribType) (GLuint, GLuint, GLsizei, GLsizei*, GLint*, GLenum*, GLchar*);
86 typedef void (APIENTRY* glGetActiveUniformType) (GLuint, GLuint, GLsizei, GLsizei*, GLint*, GLenum*, GLchar*);
87 typedef GLint (APIENTRY* glGetAttribLocationType) (GLuint, const char*);
88 typedef void (APIENTRY* glGetBufferParameterivType) (GLenum, GLenum, GLint*);
89 typedef void (APIENTRY* glGetFramebufferAttachmentParameterivType) (GLenum, GLenum, GLenum, GLint* params);
90 typedef void (APIENTRY* glGetProgramInfoLogType) (GLuint, GLsizei, GLsizei*, char*);
91 typedef void (APIENTRY* glGetProgramivType) (GLuint, GLenum, GLint*);
92 typedef void (APIENTRY* glGetRenderbufferParameterivType) (GLenum, GLenum, GLint*);
93 typedef void (APIENTRY* glGetShaderInfoLogType) (GLuint, GLsizei, GLsizei*, char*);
94 typedef void (APIENTRY* glGetShaderivType) (GLuint, GLenum, GLint*);
95 typedef void (APIENTRY* glGetShaderSourceType) (GLuint, GLsizei, GLsizei*, char*);
96 typedef GLint (APIENTRY* glGetUniformLocationType) (GLuint, const char*);
97 typedef void (APIENTRY* glGetUniformfvType) (GLuint, GLint, GLfloat*);
98 typedef void (APIENTRY* glGetUniformivType) (GLuint, GLint, GLint*);
99 typedef void (APIENTRY* glGetVertexAttribfvType) (GLuint, GLenum, GLfloat*);
100 typedef void (APIENTRY* glGetVertexAttribivType) (GLuint, GLenum, GLint*);
101 typedef void (APIENTRY* glGetVertexAttribPointervType) (GLuint, GLenum, GLvoid**);
102 typedef GLboolean (APIENTRY* glIsBufferType) (GLuint);
103 typedef GLboolean (APIENTRY* glIsFramebufferType) (GLuint);
104 typedef GLboolean (APIENTRY* glIsProgramType) (GLuint);
105 typedef GLboolean (APIENTRY* glIsRenderbufferType) (GLuint);
106 typedef GLboolean (APIENTRY* glIsShaderType) (GLuint);
107 typedef void (APIENTRY* glLinkProgramType) (GLuint);
108 typedef void (APIENTRY* glRenderbufferStorageType) (GLenum, GLenum, GLsizei, GLsizei);
109 typedef void (APIENTRY* glSampleCoverageType) (GLclampf, GLboolean);
110 typedef void (APIENTRY* glShaderSourceType) (GLuint, GLsizei, const char**, const GLint*);
111 typedef void (APIENTRY* glStencilFuncSeparateType) (GLenum, GLenum, GLint, GLuint);
112 typedef void (APIENTRY* glStencilMaskSeparateType) (GLenum, GLuint);
113 typedef void (APIENTRY* glStencilOpSeparateType) (GLenum, GLenum, GLenum, GLenum);
114 typedef void (APIENTRY* glUniform1fType) (GLint, GLfloat);
115 typedef void (APIENTRY* glUniform1fvType) (GLint, GLsizei, const GLfloat*);
116 typedef void (APIENTRY* glUniform1iType) (GLint, GLint);
117 typedef void (APIENTRY* glUniform1ivType) (GLint, GLsizei, const GLint*);
118 typedef void (APIENTRY* glUniform2fType) (GLint, GLfloat, GLfloat);
119 typedef void (APIENTRY* glUniform2fvType) (GLint, GLsizei, const GLfloat*);
120 typedef void (APIENTRY* glUniform2iType) (GLint, GLint, GLint);
121 typedef void (APIENTRY* glUniform2ivType) (GLint, GLsizei, const GLint*);
122 typedef void (APIENTRY* glUniform3fType) (GLint, GLfloat, GLfloat, GLfloat);
123 typedef void (APIENTRY* glUniform3fvType) (GLint, GLsizei, const GLfloat*);
124 typedef void (APIENTRY* glUniform3iType) (GLint, GLint, GLint, GLint);
125 typedef void (APIENTRY* glUniform3ivType) (GLint, GLsizei, const GLint*);
126 typedef void (APIENTRY* glUniform4fType) (GLint, GLfloat, GLfloat, GLfloat, GLfloat);
127 typedef void (APIENTRY* glUniform4fvType) (GLint, GLsizei, const GLfloat*);
128 typedef void (APIENTRY* glUniform4iType) (GLint, GLint, GLint, GLint, GLint);
129 typedef void (APIENTRY* glUniform4ivType) (GLint, GLsizei, const GLint*);
130 typedef void (APIENTRY* glUniformMatrix2fvType) (GLint, GLsizei, GLboolean, const GLfloat*);
131 typedef void (APIENTRY* glUniformMatrix3fvType) (GLint, GLsizei, GLboolean, const GLfloat*);
132 typedef void (APIENTRY* glUniformMatrix4fvType) (GLint, GLsizei, GLboolean, const GLfloat*);
133 typedef void (APIENTRY* glUseProgramType) (GLuint);
134 typedef void (APIENTRY* glValidateProgramType) (GLuint);
135 typedef void (APIENTRY* glVertexAttrib1fType) (GLuint, const GLfloat);
136 typedef void (APIENTRY* glVertexAttrib1fvType) (GLuint, const GLfloat*);
137 typedef void (APIENTRY* glVertexAttrib2fType) (GLuint, const GLfloat, const GLfloat);
138 typedef void (APIENTRY* glVertexAttrib2fvType) (GLuint, const GLfloat*);
139 typedef void (APIENTRY* glVertexAttrib3fType) (GLuint, const GLfloat, const GLfloat, const GLfloat);
140 typedef void (APIENTRY* glVertexAttrib3fvType) (GLuint, const GLfloat*);
141 typedef void (APIENTRY* glVertexAttrib4fType) (GLuint, const GLfloat, const GLfloat, const GLfloat, const GLfloat);
142 typedef void (APIENTRY* glVertexAttrib4fvType) (GLuint, const GLfloat*);
143 typedef void (APIENTRY* glVertexAttribPointerType) (GLuint, GLint, GLenum, GLboolean, GLsizei, const GLvoid*);
144
145 class GraphicsContext3DInternal {
146 public:
147     GraphicsContext3DInternal(GraphicsContext3D::Attributes attrs);
148     ~GraphicsContext3DInternal();
149
150     bool isContextValid() { return m_contextValid; }
151
152     glActiveTextureType activeTexture;
153     glAttachShaderType attachShader;
154     glBindAttribLocationType bindAttribLocation;
155     glBindBufferType bindBuffer;
156     glBindFramebufferType bindFramebuffer;
157     glBindRenderbufferType bindRenderbuffer;
158     glBlendColorType blendColor;
159     glBlendEquationType blendEquation;
160     glBlendEquationSeparateType blendEquationSeparate;
161     glBlendFuncSeparateType blendFuncSeparate;
162     glBufferDataType bufferData;
163     glBufferSubDataType bufferSubData;
164     glCheckFramebufferStatusType checkFramebufferStatus;
165     glCompileShaderType compileShader;
166     glCreateProgramType createProgram;
167     glCreateShaderType createShader;
168     glDeleteBuffersType deleteBuffers;
169     glDeleteFramebuffersType deleteFramebuffers;
170     glDeleteProgramType deleteProgram;
171     glDeleteRenderbuffersType deleteRenderbuffers;
172     glDeleteShaderType deleteShader;
173     glDetachShaderType detachShader;
174     glDisableVertexAttribArrayType disableVertexAttribArray;
175     glEnableVertexAttribArrayType enableVertexAttribArray;
176     glFramebufferRenderbufferType framebufferRenderbuffer;
177     glFramebufferTexture2DType framebufferTexture2D;
178     glGenBuffersType genBuffers;
179     glGenerateMipmapType generateMipmap;
180     glGenFramebuffersType genFramebuffers;
181     glGenRenderbuffersType genRenderbuffers;
182     glGetActiveAttribType getActiveAttrib;
183     glGetActiveUniformType getActiveUniform;
184     glGetAttribLocationType getAttribLocation;
185     glGetBufferParameterivType getBufferParameteriv;
186     glGetFramebufferAttachmentParameterivType getFramebufferAttachmentParameteriv;
187     glGetProgramInfoLogType getProgramInfoLog;
188     glGetProgramivType getProgramiv;
189     glGetRenderbufferParameterivType getRenderbufferParameteriv;
190     glGetShaderInfoLogType getShaderInfoLog;
191     glGetShaderivType getShaderiv;
192     glGetShaderSourceType getShaderSource;
193     glGetUniformfvType getUniformfv;
194     glGetUniformivType getUniformiv;
195     glGetUniformLocationType getUniformLocation;
196     glGetVertexAttribfvType getVertexAttribfv;
197     glGetVertexAttribivType getVertexAttribiv;
198     glGetVertexAttribPointervType getVertexAttribPointerv;
199     glIsBufferType isBuffer;
200     glIsFramebufferType isFramebuffer;
201     glIsProgramType isProgram;
202     glIsRenderbufferType isRenderbuffer;
203     glIsShaderType isShader;
204     glLinkProgramType linkProgram;
205     glRenderbufferStorageType renderbufferStorage;
206     glSampleCoverageType sampleCoverage;
207     glShaderSourceType shaderSource;
208     glStencilFuncSeparateType stencilFuncSeparate;
209     glStencilMaskSeparateType stencilMaskSeparate;
210     glStencilOpSeparateType stencilOpSeparate;
211     glUniform1fType uniform1f;
212     glUniform1fvType uniform1fv;
213     glUniform1iType uniform1i;
214     glUniform1ivType uniform1iv;
215     glUniform2fType uniform2f;
216     glUniform2fvType uniform2fv;
217     glUniform2iType uniform2i;
218     glUniform2ivType uniform2iv;
219     glUniform3fType uniform3f;
220     glUniform3fvType uniform3fv;
221     glUniform3iType uniform3i;
222     glUniform3ivType uniform3iv;
223     glUniform4fType uniform4f;
224     glUniform4fvType uniform4fv;
225     glUniform4iType uniform4i;
226     glUniform4ivType uniform4iv;
227     glUniformMatrix2fvType uniformMatrix2fv;
228     glUniformMatrix3fvType uniformMatrix3fv;
229     glUniformMatrix4fvType uniformMatrix4fv;
230     glUseProgramType useProgram;
231     glValidateProgramType validateProgram;
232     glVertexAttrib1fType vertexAttrib1f;
233     glVertexAttrib1fvType vertexAttrib1fv;
234     glVertexAttrib2fType vertexAttrib2f;
235     glVertexAttrib2fvType vertexAttrib2fv;
236     glVertexAttrib3fType vertexAttrib3f;
237     glVertexAttrib3fvType vertexAttrib3fv;
238     glVertexAttrib4fType vertexAttrib4f;
239     glVertexAttrib4fvType vertexAttrib4fv;
240     glVertexAttribPointerType vertexAttribPointer;
241
242     GraphicsContext3D::Attributes m_attrs;
243     QGLWidget* m_glWidget;
244     GLuint m_texture;
245     GLuint m_mainFbo;
246     GLuint m_currentFbo;
247     GLuint m_depthBuffer;
248     QImage m_pixels;
249     ListHashSet<unsigned long> m_syntheticErrors;
250
251 private:
252
253     void* getProcAddress(const String& proc);
254     bool m_contextValid;
255 };
256
257 #if defined (QT_OPENGL_ES_2)
258 #define GET_PROC_ADDRESS(Proc) Proc
259 #else
260 #define GET_PROC_ADDRESS(Proc) reinterpret_cast<Proc##Type>(getProcAddress(#Proc));
261 #endif
262  
263 GraphicsContext3DInternal::GraphicsContext3DInternal(GraphicsContext3D::Attributes attrs)
264     : m_attrs(attrs)
265     , m_glWidget(0)
266     , m_texture(0)
267     , m_mainFbo(0)
268     , m_currentFbo(0)
269     , m_depthBuffer(0)
270     , m_contextValid(true)
271 {
272     m_attrs.alpha = true;
273     m_attrs.depth = true;
274     m_attrs.stencil = false;
275     m_attrs.antialias = false;
276     m_attrs.premultipliedAlpha = true;
277
278     QGLFormat format;
279
280     format.setDepth(true);
281     format.setSampleBuffers(true);
282     format.setStencil(false);
283
284     m_glWidget = new QGLWidget(format);
285     if (!m_glWidget->isValid()) {
286         LOG_ERROR("GraphicsContext3D: QGLWidget does not have a valid context");
287         m_contextValid = false;
288         return;
289     }
290
291     m_glWidget->makeCurrent();
292
293     activeTexture = GET_PROC_ADDRESS(glActiveTexture);
294     attachShader = GET_PROC_ADDRESS(glAttachShader);
295     bindAttribLocation = GET_PROC_ADDRESS(glBindAttribLocation);
296     bindBuffer = GET_PROC_ADDRESS(glBindBuffer);
297     bindFramebuffer = GET_PROC_ADDRESS(glBindFramebuffer);
298     bindRenderbuffer = GET_PROC_ADDRESS(glBindRenderbuffer);
299     blendColor = GET_PROC_ADDRESS(glBlendColor);
300     blendEquation = GET_PROC_ADDRESS(glBlendEquation);
301     blendEquationSeparate = GET_PROC_ADDRESS(glBlendEquationSeparate);
302     blendFuncSeparate = GET_PROC_ADDRESS(glBlendFuncSeparate);
303     bufferData = GET_PROC_ADDRESS(glBufferData);
304     bufferSubData = GET_PROC_ADDRESS(glBufferSubData);
305     checkFramebufferStatus = GET_PROC_ADDRESS(glCheckFramebufferStatus);
306     compileShader = GET_PROC_ADDRESS(glCompileShader);
307     createProgram = GET_PROC_ADDRESS(glCreateProgram);
308     createShader = GET_PROC_ADDRESS(glCreateShader);
309     deleteBuffers = GET_PROC_ADDRESS(glDeleteBuffers);
310     deleteFramebuffers = GET_PROC_ADDRESS(glDeleteFramebuffers);
311     deleteProgram = GET_PROC_ADDRESS(glDeleteProgram);
312     deleteRenderbuffers = GET_PROC_ADDRESS(glDeleteRenderbuffers);
313     deleteShader = GET_PROC_ADDRESS(glDeleteShader);
314     detachShader = GET_PROC_ADDRESS(glDetachShader);
315     disableVertexAttribArray = GET_PROC_ADDRESS(glDisableVertexAttribArray);
316     enableVertexAttribArray = GET_PROC_ADDRESS(glEnableVertexAttribArray);
317     framebufferRenderbuffer = GET_PROC_ADDRESS(glFramebufferRenderbuffer);
318     framebufferTexture2D = GET_PROC_ADDRESS(glFramebufferTexture2D);
319     genBuffers = GET_PROC_ADDRESS(glGenBuffers);
320     generateMipmap = GET_PROC_ADDRESS(glGenerateMipmap);
321     genFramebuffers = GET_PROC_ADDRESS(glGenFramebuffers);
322     genRenderbuffers = GET_PROC_ADDRESS(glGenRenderbuffers);
323     getActiveAttrib = GET_PROC_ADDRESS(glGetActiveAttrib);
324     getActiveUniform = GET_PROC_ADDRESS(glGetActiveUniform);
325     getAttribLocation = GET_PROC_ADDRESS(glGetAttribLocation);
326     getBufferParameteriv = GET_PROC_ADDRESS(glGetBufferParameteriv);
327     getFramebufferAttachmentParameteriv = GET_PROC_ADDRESS(glGetFramebufferAttachmentParameteriv);
328     getProgramInfoLog = GET_PROC_ADDRESS(glGetProgramInfoLog);
329     getProgramiv = GET_PROC_ADDRESS(glGetProgramiv);
330     getRenderbufferParameteriv = GET_PROC_ADDRESS(glGetRenderbufferParameteriv);
331     getShaderInfoLog = GET_PROC_ADDRESS(glGetShaderInfoLog);
332     getShaderiv = GET_PROC_ADDRESS(glGetShaderiv);
333     getShaderSource = GET_PROC_ADDRESS(glGetShaderSource);
334     getUniformfv = GET_PROC_ADDRESS(glGetUniformfv);
335     getUniformiv = GET_PROC_ADDRESS(glGetUniformiv);
336     getUniformLocation = GET_PROC_ADDRESS(glGetUniformLocation);
337     getVertexAttribfv = GET_PROC_ADDRESS(glGetVertexAttribfv);
338     getVertexAttribiv = GET_PROC_ADDRESS(glGetVertexAttribiv);
339     getVertexAttribPointerv = GET_PROC_ADDRESS(glGetVertexAttribPointerv);
340     isBuffer = GET_PROC_ADDRESS(glIsBuffer);
341     isFramebuffer = GET_PROC_ADDRESS(glIsFramebuffer);
342     isProgram = GET_PROC_ADDRESS(glIsProgram);
343     isRenderbuffer = GET_PROC_ADDRESS(glIsRenderbuffer);
344     isShader = GET_PROC_ADDRESS(glIsShader);
345     linkProgram = GET_PROC_ADDRESS(glLinkProgram);
346     renderbufferStorage = GET_PROC_ADDRESS(glRenderbufferStorage);
347     sampleCoverage = GET_PROC_ADDRESS(glSampleCoverage);
348     shaderSource = GET_PROC_ADDRESS(glShaderSource);
349     stencilFuncSeparate = GET_PROC_ADDRESS(glStencilFuncSeparate);
350     stencilMaskSeparate = GET_PROC_ADDRESS(glStencilMaskSeparate);
351     stencilOpSeparate = GET_PROC_ADDRESS(glStencilOpSeparate);
352     uniform1f = GET_PROC_ADDRESS(glUniform1f);
353     uniform1fv = GET_PROC_ADDRESS(glUniform1fv);
354     uniform1i = GET_PROC_ADDRESS(glUniform1i);
355     uniform1iv = GET_PROC_ADDRESS(glUniform1iv);
356     uniform2f = GET_PROC_ADDRESS(glUniform2f);
357     uniform2fv = GET_PROC_ADDRESS(glUniform2fv);
358     uniform2i = GET_PROC_ADDRESS(glUniform2i);
359     uniform2iv = GET_PROC_ADDRESS(glUniform2iv);
360     uniform3f = GET_PROC_ADDRESS(glUniform3f);
361     uniform3fv = GET_PROC_ADDRESS(glUniform3fv);
362     uniform3i = GET_PROC_ADDRESS(glUniform3i);
363     uniform3iv = GET_PROC_ADDRESS(glUniform3iv);
364     uniform4f = GET_PROC_ADDRESS(glUniform4f);
365     uniform4fv = GET_PROC_ADDRESS(glUniform4fv);
366     uniform4i = GET_PROC_ADDRESS(glUniform4i);
367     uniform4iv = GET_PROC_ADDRESS(glUniform4iv);
368     uniformMatrix2fv = GET_PROC_ADDRESS(glUniformMatrix2fv);
369     uniformMatrix3fv = GET_PROC_ADDRESS(glUniformMatrix3fv);
370     uniformMatrix4fv = GET_PROC_ADDRESS(glUniformMatrix4fv);
371     useProgram = GET_PROC_ADDRESS(glUseProgram);
372     validateProgram = GET_PROC_ADDRESS(glValidateProgram);
373     vertexAttrib1f = GET_PROC_ADDRESS(glVertexAttrib1f);
374     vertexAttrib1fv = GET_PROC_ADDRESS(glVertexAttrib1fv);
375     vertexAttrib2f = GET_PROC_ADDRESS(glVertexAttrib2f);
376     vertexAttrib2fv = GET_PROC_ADDRESS(glVertexAttrib2fv);
377     vertexAttrib3f = GET_PROC_ADDRESS(glVertexAttrib3f);
378     vertexAttrib3fv = GET_PROC_ADDRESS(glVertexAttrib3fv);
379     vertexAttrib4f = GET_PROC_ADDRESS(glVertexAttrib4f);
380     vertexAttrib4fv = GET_PROC_ADDRESS(glVertexAttrib4fv);
381     vertexAttribPointer = GET_PROC_ADDRESS(glVertexAttribPointer);
382
383     if (!m_contextValid) {
384         LOG_ERROR("GraphicsContext3D: All needed OpenGL extensions are not available");
385         m_contextValid = false;
386         return;
387     }
388
389     glGenTextures(1, &m_texture);
390     glBindTexture(GraphicsContext3D::TEXTURE_2D, m_texture);
391     glTexParameterf(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR);
392     glTexParameterf(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR);
393     glTexParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE);
394     glTexParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE);
395     glTexImage2D(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D::RGBA, 1, 1, 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, 0);
396     glBindTexture(GraphicsContext3D::TEXTURE_2D, 0);
397
398     genFramebuffers(/* count */ 1, &m_mainFbo);
399     m_currentFbo = m_mainFbo;
400
401     bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_mainFbo);
402
403     genRenderbuffers(/* count */ 1, &m_depthBuffer);
404     bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, m_depthBuffer);
405 #if defined(QT_OPENGL_ES_2)
406     renderbufferStorage(GraphicsContext3D::RENDERBUFFER, GraphicsContext3D::DEPTH_COMPONENT16, /* width */ 1, /* height */ 1);
407 #else
408     renderbufferStorage(GraphicsContext3D::RENDERBUFFER, GraphicsContext3D::DEPTH_COMPONENT, /* width */ 1, /* height */ 1);
409 #endif
410
411     bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, 0);
412  
413     framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_texture, 0);
414     framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::DEPTH_ATTACHMENT, GraphicsContext3D::RENDERBUFFER, m_depthBuffer);
415     glClearColor(/* red */ 0, /* green */ 0, /* blue */ 0, /* alpha */ 0);
416
417     if (checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) != GraphicsContext3D::FRAMEBUFFER_COMPLETE) {
418         LOG_ERROR("GraphicsContext3D: Wasn't able to create the main framebuffer");
419         m_contextValid = false;
420     }
421 }
422
423 GraphicsContext3DInternal::~GraphicsContext3DInternal()
424 {
425     delete m_glWidget;
426     m_glWidget = 0;
427 }
428
429 void* GraphicsContext3DInternal::getProcAddress(const String& proc)
430 {
431     String ext[3] = { "", "ARB", "EXT" };
432
433     for (int i = 0; i < 3; i++) {
434         String nameWithExt = proc + ext[i];
435
436         void* addr = m_glWidget->context()->getProcAddress(nameWithExt.utf8().data());
437         if (addr)
438             return addr;
439     }
440
441     LOG_ERROR("GraphicsContext3D: Did not find GL function %s", proc.utf8().data());
442     m_contextValid = false;
443     return 0;
444 }
445
446 PassOwnPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3D::Attributes attrs)
447 {
448     OwnPtr<GraphicsContext3D> context(new GraphicsContext3D(attrs));
449     return context->m_internal ? context.release() : 0;
450 }
451
452 GraphicsContext3D::GraphicsContext3D(GraphicsContext3D::Attributes attrs)
453     : m_internal(new GraphicsContext3DInternal(attrs))
454 {
455     if (!m_internal->isContextValid())
456         m_internal = 0;
457 }
458
459 GraphicsContext3D::~GraphicsContext3D()
460 {
461 }
462
463 PlatformGraphicsContext3D GraphicsContext3D::platformGraphicsContext3D()
464 {
465     return m_internal->m_glWidget;
466 }
467
468 Platform3DObject GraphicsContext3D::platformTexture() const
469 {
470     return m_internal->m_texture;
471 }
472
473 void GraphicsContext3D::makeContextCurrent()
474 {
475     m_internal->m_glWidget->makeCurrent();
476 }
477
478 void GraphicsContext3D::beginPaint(WebGLRenderingContext* context)
479 {
480     m_internal->m_glWidget->makeCurrent();
481
482     HTMLCanvasElement* canvas = context->canvas();
483     ImageBuffer* imageBuffer = canvas->buffer();
484
485     m_internal->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_internal->m_mainFbo);
486
487     glReadPixels(/* x */ 0, /* y */ 0, m_currentWidth, m_currentHeight, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, m_internal->m_pixels.bits());
488
489     QPainter* p = imageBuffer->context()->platformContext();
490     p->drawImage(/* x */ 0, /* y */ 0, m_internal->m_pixels.transformed(QMatrix().rotate(180)));
491
492     m_internal->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_internal->m_currentFbo);
493 }
494
495 void GraphicsContext3D::endPaint()
496 {
497 }
498
499 void GraphicsContext3D::reshape(int width, int height)
500 {
501     if (((width == m_currentWidth) && (height == m_currentHeight)) || (!m_internal))
502         return;
503    
504     m_currentWidth = width;
505     m_currentHeight = height;
506
507     m_internal->m_pixels = QImage(m_currentWidth, m_currentHeight, QImage::Format_ARGB32);
508
509     m_internal->m_glWidget->makeCurrent();
510
511     glBindTexture(GraphicsContext3D::TEXTURE_2D, m_internal->m_texture);
512     glTexImage2D(GraphicsContext3D::TEXTURE_2D, /* level */ 0, GraphicsContext3D::RGBA, width, height, /* border */ 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, /* data */ 0);
513     glBindTexture(GraphicsContext3D::TEXTURE_2D, 0);
514    
515     m_internal->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_internal->m_mainFbo);
516     m_internal->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, m_internal->m_depthBuffer);
517 #if defined(QT_OPENGL_ES_2)
518     renderbufferStorage(GraphicsContext3D::RENDERBUFFER, GraphicsContext3D::DEPTH_COMPONENT16, width, height);
519 #else
520     renderbufferStorage(GraphicsContext3D::RENDERBUFFER, GraphicsContext3D::DEPTH_COMPONENT, width, height);
521 #endif
522     m_internal->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, 0);
523    
524     m_internal->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_internal->m_texture, 0);
525     m_internal->framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::DEPTH_ATTACHMENT, GraphicsContext3D::RENDERBUFFER, m_internal->m_depthBuffer);
526
527     GLenum status = m_internal->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER);
528     if (status != GraphicsContext3D::FRAMEBUFFER_COMPLETE) {
529         LOG_ERROR("GraphicsContext3D: Wasn't able to reshape the main framebuffer");
530         notImplemented();
531     }
532
533     glClear(GraphicsContext3D::COLOR_BUFFER_BIT);
534     glFlush();
535 }
536
537 void GraphicsContext3D::activeTexture(unsigned long texture)
538 {
539     m_internal->m_glWidget->makeCurrent();
540     m_internal->activeTexture(texture);
541 }
542
543 void GraphicsContext3D::attachShader(WebGLProgram* program, WebGLShader* shader)
544 {
545     ASSERT(program);
546     ASSERT(shader);
547     m_internal->m_glWidget->makeCurrent();
548     m_internal->attachShader((GLuint) program->object(), (GLuint) shader->object());
549 }
550
551 void GraphicsContext3D::bindAttribLocation(WebGLProgram* program, unsigned long index, const String& name)
552 {
553     ASSERT(program);
554     m_internal->m_glWidget->makeCurrent();
555     m_internal->bindAttribLocation((GLuint) program->object(), index, name.utf8().data());
556 }
557
558 void GraphicsContext3D::bindBuffer(unsigned long target, WebGLBuffer* buffer)
559 {
560     m_internal->m_glWidget->makeCurrent();
561     m_internal->bindBuffer(target, buffer ? (GLuint) buffer->object() : 0);
562 }
563
564 void GraphicsContext3D::bindFramebuffer(unsigned long target, WebGLFramebuffer* buffer)
565 {
566     m_internal->m_glWidget->makeCurrent();
567     m_internal->m_currentFbo = (buffer && buffer->object()) ? (GLuint) buffer->object() : m_internal->m_mainFbo;
568     m_internal->bindFramebuffer(target, m_internal->m_currentFbo);
569 }
570
571 void GraphicsContext3D::bindRenderbuffer(unsigned long target, WebGLRenderbuffer* renderbuffer)
572 {
573     m_internal->m_glWidget->makeCurrent();
574     m_internal->bindRenderbuffer(target, renderbuffer ? (GLuint) renderbuffer->object() : 0);
575 }
576
577 void GraphicsContext3D::bindTexture(unsigned long target, WebGLTexture* texture)
578 {
579     m_internal->m_glWidget->makeCurrent();
580     glBindTexture(target, texture ? (GLuint) texture->object() : 0);
581 }
582
583 void GraphicsContext3D::blendColor(double red, double green, double blue, double alpha)
584 {
585     m_internal->m_glWidget->makeCurrent();
586     m_internal->blendColor(static_cast<float>(red), static_cast<float>(green), static_cast<float>(blue), static_cast<float>(alpha));
587 }
588
589 void GraphicsContext3D::blendEquation(unsigned long mode)
590 {
591     m_internal->m_glWidget->makeCurrent();
592     m_internal->blendEquation(mode);
593 }
594
595 void GraphicsContext3D::blendEquationSeparate(unsigned long modeRGB, unsigned long modeAlpha)
596 {
597     m_internal->m_glWidget->makeCurrent();
598     m_internal->blendEquationSeparate(modeRGB, modeAlpha);
599 }
600
601 void GraphicsContext3D::blendFunc(unsigned long sfactor, unsigned long dfactor)
602 {
603     m_internal->m_glWidget->makeCurrent();
604     glBlendFunc(sfactor, dfactor);
605 }      
606
607 void GraphicsContext3D::blendFuncSeparate(unsigned long srcRGB, unsigned long dstRGB, unsigned long srcAlpha, unsigned long dstAlpha)
608 {
609     m_internal->m_glWidget->makeCurrent();
610     m_internal->blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
611 }
612
613 void GraphicsContext3D::bufferData(unsigned long target, int size, unsigned long usage)
614 {
615     m_internal->m_glWidget->makeCurrent();
616     m_internal->bufferData(target, size, /* data */ 0, usage);
617 }
618
619 void GraphicsContext3D::bufferData(unsigned long target, WebGLArray* array, unsigned long usage)
620 {
621     if (!array || !array->length())
622         return;
623    
624     m_internal->m_glWidget->makeCurrent();
625     m_internal->bufferData(target, array->byteLength(), array->baseAddress(), usage);
626 }
627
628 void GraphicsContext3D::bufferSubData(unsigned long target, long offset, WebGLArray* array)
629 {
630     if (!array || !array->length())
631         return;
632    
633     m_internal->m_glWidget->makeCurrent();
634     m_internal->bufferSubData(target, offset, array->byteLength(), array->baseAddress());
635 }
636
637 unsigned long GraphicsContext3D::checkFramebufferStatus(unsigned long target)
638 {
639     m_internal->m_glWidget->makeCurrent();
640     return m_internal->checkFramebufferStatus(target);
641 }
642
643 void GraphicsContext3D::clearColor(double r, double g, double b, double a)
644 {
645     m_internal->m_glWidget->makeCurrent();
646     glClearColor(static_cast<float>(r), static_cast<float>(g), static_cast<float>(b), static_cast<float>(a));
647 }
648
649 void GraphicsContext3D::clear(unsigned long mask)
650 {
651     m_internal->m_glWidget->makeCurrent();
652     glClear(mask);
653 }
654
655 void GraphicsContext3D::clearDepth(double depth)
656 {
657     m_internal->m_glWidget->makeCurrent();
658 #if defined(QT_OPENGL_ES_2)
659     glClearDepthf(depth);
660 #else
661     glClearDepth(depth);
662 #endif
663 }
664
665 void GraphicsContext3D::clearStencil(long s)
666 {
667     m_internal->m_glWidget->makeCurrent();
668     glClearStencil(s);
669 }
670
671 void GraphicsContext3D::colorMask(bool red, bool green, bool blue, bool alpha)
672 {
673     m_internal->m_glWidget->makeCurrent();
674     glColorMask(red, green, blue, alpha);
675 }
676
677 void GraphicsContext3D::compileShader(WebGLShader* shader)
678 {
679     ASSERT(shader);
680     m_internal->m_glWidget->makeCurrent();
681     m_internal->compileShader((GLuint) shader->object());
682 }
683
684 void GraphicsContext3D::copyTexImage2D(unsigned long target, long level, unsigned long internalformat, long x, long y, unsigned long width, unsigned long height, long border)
685 {
686     m_internal->m_glWidget->makeCurrent();
687     glCopyTexImage2D(target, level, internalformat, x, y, width, height, border);
688 }
689
690 void GraphicsContext3D::copyTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, long x, long y, unsigned long width, unsigned long height)
691 {
692     m_internal->m_glWidget->makeCurrent();
693     glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
694 }
695
696 void GraphicsContext3D::cullFace(unsigned long mode)
697 {
698     m_internal->m_glWidget->makeCurrent();
699     glCullFace(mode);
700 }
701
702 void GraphicsContext3D::depthFunc(unsigned long func)
703 {
704     m_internal->m_glWidget->makeCurrent();
705     glDepthFunc(func);
706 }
707
708 void GraphicsContext3D::depthMask(bool flag)
709 {
710     m_internal->m_glWidget->makeCurrent();
711     glDepthMask(flag);
712 }
713
714 void GraphicsContext3D::depthRange(double zNear, double zFar)
715 {
716     m_internal->m_glWidget->makeCurrent();
717 #if defined(QT_OPENGL_ES_2)
718     glDepthRangef(zNear, zFar);
719 #else
720     glDepthRange(zNear, zFar);
721 #endif
722 }
723
724 void GraphicsContext3D::detachShader(WebGLProgram* program, WebGLShader* shader)
725 {
726     ASSERT(program);
727     ASSERT(shader);
728     m_internal->m_glWidget->makeCurrent();
729     m_internal->detachShader((GLuint) program->object(), (GLuint) shader->object());
730 }
731
732 void GraphicsContext3D::disable(unsigned long cap)
733 {
734     m_internal->m_glWidget->makeCurrent();
735     glDisable(cap);
736 }
737
738 void GraphicsContext3D::disableVertexAttribArray(unsigned long index)
739 {
740     m_internal->m_glWidget->makeCurrent();
741     m_internal->disableVertexAttribArray(index);
742 }
743
744 void GraphicsContext3D::drawArrays(unsigned long mode, long first, long count)
745 {
746     m_internal->m_glWidget->makeCurrent();
747     glDrawArrays(mode, first, count);
748 }
749
750 void GraphicsContext3D::drawElements(unsigned long mode, unsigned long count, unsigned long type, long offset)
751 {
752     m_internal->m_glWidget->makeCurrent();
753     glDrawElements(mode, count, type, reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
754 }
755
756 void GraphicsContext3D::enable(unsigned long cap)
757 {
758     m_internal->m_glWidget->makeCurrent();
759     glEnable(cap);
760 }
761
762 void GraphicsContext3D::enableVertexAttribArray(unsigned long index)
763 {
764     m_internal->m_glWidget->makeCurrent();
765     m_internal->enableVertexAttribArray(index);
766 }
767
768 void GraphicsContext3D::finish()
769 {
770     m_internal->m_glWidget->makeCurrent();
771     glFinish();
772 }
773
774 void GraphicsContext3D::flush()
775 {
776     m_internal->m_glWidget->makeCurrent();
777     glFlush();
778 }
779
780 void GraphicsContext3D::framebufferRenderbuffer(unsigned long target, unsigned long attachment, unsigned long renderbuffertarget, WebGLRenderbuffer* buffer)
781 {
782     m_internal->m_glWidget->makeCurrent();
783     m_internal->framebufferRenderbuffer(target, attachment, renderbuffertarget, buffer ? (GLuint) buffer->object() : 0);
784 }
785
786 void GraphicsContext3D::framebufferTexture2D(unsigned long target, unsigned long attachment, unsigned long textarget, WebGLTexture* texture, long level)
787 {
788     m_internal->m_glWidget->makeCurrent();
789     m_internal->framebufferTexture2D(target, attachment, textarget, texture ? (GLuint) texture->object() : 0, level);
790 }
791
792 void GraphicsContext3D::frontFace(unsigned long mode)
793 {
794     m_internal->m_glWidget->makeCurrent();
795     glFrontFace(mode);
796 }
797
798 void GraphicsContext3D::generateMipmap(unsigned long target)
799 {
800     m_internal->m_glWidget->makeCurrent();
801     m_internal->generateMipmap(target);
802 }
803
804 bool GraphicsContext3D::getActiveAttrib(WebGLProgram* program, unsigned long index, ActiveInfo& info)
805 {
806     if (!program->object()) {
807         synthesizeGLError(INVALID_VALUE);
808         return false;
809     }
810
811     m_internal->m_glWidget->makeCurrent();
812
813     GLint maxLength;
814     m_internal->getProgramiv(static_cast<GLuint>(program->object()), GraphicsContext3D::ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxLength);
815
816     GLchar name[maxLength];
817     GLsizei nameLength;
818     GLint size;
819     GLenum type;
820
821     m_internal->getActiveAttrib(static_cast<GLuint>(program->object()), index, maxLength, &nameLength, &size, &type, name);
822
823     if (!nameLength)
824         return false;
825
826     info.name = String(name, nameLength);
827     info.type = type;
828     info.size = size;
829
830     return true;
831 }
832    
833 bool GraphicsContext3D::getActiveUniform(WebGLProgram* program, unsigned long index, ActiveInfo& info)
834 {
835     if (!program->object()) {
836         synthesizeGLError(INVALID_VALUE);
837         return false;
838     }
839
840     m_internal->m_glWidget->makeCurrent();
841
842     GLint maxLength;
843     m_internal->getProgramiv(static_cast<GLuint>(program->object()), GraphicsContext3D::ACTIVE_UNIFORM_MAX_LENGTH, &maxLength);
844
845     GLchar name[maxLength];
846     GLsizei nameLength;
847     GLint size;
848     GLenum type;
849
850     m_internal->getActiveUniform(static_cast<GLuint>(program->object()), index, maxLength, &nameLength, &size, &type, name);
851
852     if (!nameLength)
853         return false;
854
855     info.name = String(name, nameLength);
856     info.type = type;
857     info.size = size;
858
859     return true;
860 }
861
862 int GraphicsContext3D::getAttribLocation(WebGLProgram* program, const String& name)
863 {
864     if (!program)
865         return -1;
866    
867     m_internal->m_glWidget->makeCurrent();
868     return m_internal->getAttribLocation((GLuint) program->object(), name.utf8().data());
869 }
870
871 GraphicsContext3D::Attributes GraphicsContext3D::getContextAttributes()
872 {
873     return m_internal->m_attrs;
874 }
875
876 unsigned long GraphicsContext3D::getError()
877 {
878     if (m_internal->m_syntheticErrors.size() > 0) {
879         ListHashSet<unsigned long>::iterator iter = m_internal->m_syntheticErrors.begin();
880         unsigned long err = *iter;
881         m_internal->m_syntheticErrors.remove(iter);
882         return err;
883     }
884
885     m_internal->m_glWidget->makeCurrent();
886     return glGetError();
887 }
888
889 String GraphicsContext3D::getString(unsigned long name)
890 {
891     m_internal->m_glWidget->makeCurrent();
892     return String((const char*) glGetString(name));
893 }
894
895 void GraphicsContext3D::hint(unsigned long target, unsigned long mode)
896 {
897     m_internal->m_glWidget->makeCurrent();
898     glHint(target, mode);
899 }
900
901 bool GraphicsContext3D::isBuffer(WebGLBuffer* buffer)
902 {
903     if (!buffer)
904         return false;
905    
906     m_internal->m_glWidget->makeCurrent();
907     return m_internal->isBuffer((GLuint) buffer->object());
908 }
909
910 bool GraphicsContext3D::isEnabled(unsigned long cap)
911 {
912     m_internal->m_glWidget->makeCurrent();
913     return glIsEnabled(cap);
914 }
915
916 bool GraphicsContext3D::isFramebuffer(WebGLFramebuffer* framebuffer)
917 {
918     if (!framebuffer)
919         return false;
920    
921     m_internal->m_glWidget->makeCurrent();
922     return m_internal->isFramebuffer((GLuint) framebuffer->object());
923 }
924
925 bool GraphicsContext3D::isProgram(WebGLProgram* program)
926 {
927     if (!program)
928         return false;
929    
930     m_internal->m_glWidget->makeCurrent();
931     return m_internal->isProgram((GLuint) program->object());
932 }
933
934 bool GraphicsContext3D::isRenderbuffer(WebGLRenderbuffer* renderbuffer)
935 {
936     if (!renderbuffer)
937         return false;
938    
939     m_internal->m_glWidget->makeCurrent();
940     return m_internal->isRenderbuffer((GLuint) renderbuffer->object());
941 }
942
943 bool GraphicsContext3D::isShader(WebGLShader* shader)
944 {
945     if (!shader)
946         return false;
947    
948     m_internal->m_glWidget->makeCurrent();
949     return m_internal->isShader((GLuint) shader->object());
950 }
951
952 bool GraphicsContext3D::isTexture(WebGLTexture* texture)
953 {
954     if (!texture)
955         return false;
956    
957     m_internal->m_glWidget->makeCurrent();
958     return glIsTexture((GLuint) texture->object());
959 }
960
961 void GraphicsContext3D::lineWidth(double width)
962 {
963     m_internal->m_glWidget->makeCurrent();
964     glLineWidth(static_cast<float>(width));
965 }
966
967 void GraphicsContext3D::linkProgram(WebGLProgram* program)
968 {
969     ASSERT(program);
970     m_internal->m_glWidget->makeCurrent();
971     m_internal->linkProgram((GLuint) program->object());
972 }
973
974 void GraphicsContext3D::pixelStorei(unsigned long paramName, long param)
975 {
976     m_internal->m_glWidget->makeCurrent();
977     glPixelStorei(paramName, param);
978 }
979
980 void GraphicsContext3D::polygonOffset(double factor, double units)
981 {
982     m_internal->m_glWidget->makeCurrent();
983     glPolygonOffset(static_cast<float>(factor), static_cast<float>(units));
984 }
985
986 PassRefPtr<WebGLArray> GraphicsContext3D::readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type)
987 {
988     m_internal->m_glWidget->makeCurrent();
989    
990     if (type != GraphicsContext3D::UNSIGNED_BYTE || format != GraphicsContext3D::RGBA)
991         return 0;
992        
993     RefPtr<WebGLUnsignedByteArray> array = WebGLUnsignedByteArray::create(width * height * 4);
994     glReadPixels(x, y, width, height, format, type, (GLvoid*) array->data());
995     return array;   
996 }
997
998 void GraphicsContext3D::releaseShaderCompiler()
999 {
1000     m_internal->m_glWidget->makeCurrent();
1001     notImplemented();
1002 }
1003
1004 void GraphicsContext3D::renderbufferStorage(unsigned long target, unsigned long internalformat, unsigned long width, unsigned long height)
1005 {
1006     m_internal->m_glWidget->makeCurrent();
1007     m_internal->renderbufferStorage(target, internalformat, width, height);
1008 }
1009
1010 void GraphicsContext3D::sampleCoverage(double value, bool invert)
1011 {
1012     m_internal->m_glWidget->makeCurrent();
1013     m_internal->sampleCoverage(static_cast<float>(value), invert);
1014 }
1015
1016 void GraphicsContext3D::scissor(long x, long y, unsigned long width, unsigned long height)
1017 {
1018     m_internal->m_glWidget->makeCurrent();
1019     glScissor(x, y, width, height);
1020 }
1021
1022 void GraphicsContext3D::shaderSource(WebGLShader* shader, const String& string)
1023 {
1024     ASSERT(shader);
1025    
1026     m_internal->m_glWidget->makeCurrent();
1027
1028     // Force the use of GLSL 1.0:
1029     // https://cvs.khronos.org/svn/repos/registry/trunk/public/webgl/doc/spec/WebGL-spec.html#4.4
1030     // FIXME: Lines beginning with "#version" should be stripped out.
1031
1032     String prepared;
1033    
1034     prepared.append("#version 100\n");
1035 #if defined(QT_OPENGL_ES_2)
1036     prepared.append("precision mediump float;\n");
1037 #endif
1038     prepared.append(string);
1039
1040     CString preparedCS = prepared.utf8();
1041     const char* data = preparedCS.data();
1042     int length = prepared.length();
1043     m_internal->shaderSource((GLuint) shader->object(), /* count */ 1, &data, &length);
1044 }
1045
1046 void GraphicsContext3D::stencilFunc(unsigned long func, long ref, unsigned long mask)
1047 {
1048     m_internal->m_glWidget->makeCurrent();
1049     glStencilFunc(func, ref, mask);
1050 }
1051
1052 void GraphicsContext3D::stencilFuncSeparate(unsigned long face, unsigned long func, long ref, unsigned long mask)
1053 {
1054     m_internal->m_glWidget->makeCurrent();
1055     m_internal->stencilFuncSeparate(face, func, ref, mask);
1056 }
1057
1058 void GraphicsContext3D::stencilMask(unsigned long mask)
1059 {
1060     m_internal->m_glWidget->makeCurrent();
1061     glStencilMask(mask);
1062 }
1063
1064 void GraphicsContext3D::stencilMaskSeparate(unsigned long face, unsigned long mask)
1065 {
1066     m_internal->m_glWidget->makeCurrent();
1067     m_internal->stencilMaskSeparate(face, mask);
1068 }
1069
1070 void GraphicsContext3D::stencilOp(unsigned long fail, unsigned long zfail, unsigned long zpass)
1071 {
1072     m_internal->m_glWidget->makeCurrent();
1073     glStencilOp(fail, zfail, zpass);
1074 }
1075
1076 void GraphicsContext3D::stencilOpSeparate(unsigned long face, unsigned long fail, unsigned long zfail, unsigned long zpass)
1077 {
1078     m_internal->m_glWidget->makeCurrent();
1079     m_internal->stencilOpSeparate(face, fail, zfail, zpass);
1080 }
1081
1082 void GraphicsContext3D::texParameterf(unsigned target, unsigned paramName, float value)
1083 {
1084     m_internal->m_glWidget->makeCurrent();
1085     glTexParameterf(target, paramName, static_cast<float>(value));
1086 }
1087
1088 void GraphicsContext3D::texParameteri(unsigned target, unsigned paramName, int value)
1089 {
1090     m_internal->m_glWidget->makeCurrent();
1091     glTexParameteri(target, paramName, static_cast<float>(value));
1092 }
1093
1094 void GraphicsContext3D::uniform1f(long location, float v0)
1095 {
1096     m_internal->m_glWidget->makeCurrent();
1097     m_internal->uniform1f(location, v0);
1098 }
1099
1100 void GraphicsContext3D::uniform1fv(long location, float* array, int size)
1101 {
1102     m_internal->m_glWidget->makeCurrent();
1103     m_internal->uniform1fv(location, size, array);
1104 }
1105
1106 void GraphicsContext3D::uniform2f(long location, float v0, float v1)
1107 {
1108     m_internal->m_glWidget->makeCurrent();
1109     m_internal->uniform2f(location, v0, v1);
1110 }
1111
1112 void GraphicsContext3D::uniform2fv(long location, float* array, int size)
1113 {
1114     m_internal->m_glWidget->makeCurrent();
1115     m_internal->uniform2fv(location, size, array);
1116 }
1117
1118 void GraphicsContext3D::uniform3f(long location, float v0, float v1, float v2)
1119 {
1120     m_internal->m_glWidget->makeCurrent();
1121     m_internal->uniform3f(location, v0, v1, v2);
1122 }
1123
1124 void GraphicsContext3D::uniform3fv(long location, float* array, int size)
1125 {
1126     m_internal->m_glWidget->makeCurrent();
1127     m_internal->uniform3fv(location, size, array);
1128 }
1129
1130 void GraphicsContext3D::uniform4f(long location, float v0, float v1, float v2, float v3)
1131 {
1132     m_internal->m_glWidget->makeCurrent();
1133     m_internal->uniform4f(location, v0, v1, v2, v3);
1134 }
1135
1136 void GraphicsContext3D::uniform4fv(long location, float* array, int size)
1137 {
1138     m_internal->m_glWidget->makeCurrent();
1139     m_internal->uniform4fv(location, size, array);
1140 }
1141
1142 void GraphicsContext3D::uniform1i(long location, int v0)
1143 {
1144     m_internal->m_glWidget->makeCurrent();
1145     m_internal->uniform1i(location, v0);
1146 }
1147
1148 void GraphicsContext3D::uniform1iv(long location, int* array, int size)
1149 {
1150     m_internal->m_glWidget->makeCurrent();
1151     m_internal->uniform1iv(location, size, array);
1152 }
1153
1154 void GraphicsContext3D::uniform2i(long location, int v0, int v1)
1155 {
1156     m_internal->m_glWidget->makeCurrent();
1157     m_internal->uniform2i(location, v0, v1);
1158 }
1159
1160 void GraphicsContext3D::uniform2iv(long location, int* array, int size)
1161 {
1162     m_internal->m_glWidget->makeCurrent();
1163     m_internal->uniform2iv(location, size, array);
1164 }
1165
1166 void GraphicsContext3D::uniform3i(long location, int v0, int v1, int v2)
1167 {
1168     m_internal->m_glWidget->makeCurrent();
1169     m_internal->uniform3i(location, v0, v1, v2);
1170 }
1171
1172 void GraphicsContext3D::uniform3iv(long location, int* array, int size)
1173 {
1174     m_internal->m_glWidget->makeCurrent();
1175     m_internal->uniform3iv(location, size, array);
1176 }
1177
1178 void GraphicsContext3D::uniform4i(long location, int v0, int v1, int v2, int v3)
1179 {
1180     m_internal->m_glWidget->makeCurrent();
1181     m_internal->uniform4i(location, v0, v1, v2, v3);
1182 }
1183
1184 void GraphicsContext3D::uniform4iv(long location, int* array, int size)
1185 {
1186     m_internal->m_glWidget->makeCurrent();
1187     m_internal->uniform4iv(location, size, array);
1188 }
1189
1190 void GraphicsContext3D::uniformMatrix2fv(long location, bool transpose, float* array, int size)
1191 {
1192     m_internal->m_glWidget->makeCurrent();
1193     m_internal->uniformMatrix2fv(location, size, transpose, array);
1194 }
1195
1196 void GraphicsContext3D::uniformMatrix3fv(long location, bool transpose, float* array, int size)
1197 {
1198     m_internal->m_glWidget->makeCurrent();
1199     m_internal->uniformMatrix3fv(location, size, transpose, array);
1200 }
1201
1202 void GraphicsContext3D::uniformMatrix4fv(long location, bool transpose, float* array, int size)
1203 {
1204     m_internal->m_glWidget->makeCurrent();
1205     m_internal->uniformMatrix4fv(location, size, transpose, array);
1206 }
1207
1208 void GraphicsContext3D::useProgram(WebGLProgram* program)
1209 {
1210     ASSERT(program);
1211    
1212     m_internal->m_glWidget->makeCurrent();
1213     m_internal->useProgram((GLuint) program->object());
1214 }
1215
1216 void GraphicsContext3D::validateProgram(WebGLProgram* program)
1217 {
1218     ASSERT(program);
1219    
1220     m_internal->m_glWidget->makeCurrent();
1221     m_internal->validateProgram((GLuint) program->object());
1222 }
1223
1224 void GraphicsContext3D::vertexAttrib1f(unsigned long indx, float v0)
1225 {
1226     m_internal->m_glWidget->makeCurrent();
1227     m_internal->vertexAttrib1f(indx, v0);
1228 }
1229
1230 void GraphicsContext3D::vertexAttrib1fv(unsigned long indx, float* array)
1231 {
1232     m_internal->m_glWidget->makeCurrent();
1233     m_internal->vertexAttrib1fv(indx, array);
1234 }
1235
1236 void GraphicsContext3D::vertexAttrib2f(unsigned long indx, float v0, float v1)
1237 {
1238     m_internal->m_glWidget->makeCurrent();
1239     m_internal->vertexAttrib2f(indx, v0, v1);
1240 }
1241
1242 void GraphicsContext3D::vertexAttrib2fv(unsigned long indx, float* array)
1243 {
1244     m_internal->m_glWidget->makeCurrent();
1245     m_internal->vertexAttrib2fv(indx, array);
1246 }
1247
1248 void GraphicsContext3D::vertexAttrib3f(unsigned long indx, float v0, float v1, float v2)
1249 {
1250     m_internal->m_glWidget->makeCurrent();
1251     m_internal->vertexAttrib3f(indx, v0, v1, v2);
1252 }
1253
1254 void GraphicsContext3D::vertexAttrib3fv(unsigned long indx, float* array)
1255 {
1256     m_internal->m_glWidget->makeCurrent();
1257     m_internal->vertexAttrib3fv(indx, array);
1258 }
1259
1260 void GraphicsContext3D::vertexAttrib4f(unsigned long indx, float v0, float v1, float v2, float v3)
1261 {
1262     m_internal->m_glWidget->makeCurrent();
1263     m_internal->vertexAttrib4f(indx, v0, v1, v2, v3);
1264 }
1265
1266 void GraphicsContext3D::vertexAttrib4fv(unsigned long indx, float* array)
1267 {
1268     m_internal->m_glWidget->makeCurrent();
1269     m_internal->vertexAttrib4fv(indx, array);
1270 }
1271
1272 void GraphicsContext3D::vertexAttribPointer(unsigned long indx, int size, int type, bool normalized, unsigned long stride, unsigned long offset)
1273 {
1274     m_internal->m_glWidget->makeCurrent();
1275     m_internal->vertexAttribPointer(indx, size, type, normalized, stride, reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
1276 }
1277
1278 void GraphicsContext3D::viewport(long x, long y, unsigned long width, unsigned long height)
1279 {
1280     m_internal->m_glWidget->makeCurrent();
1281     glViewport(static_cast<GLint>(x), static_cast<GLint>(y), static_cast<GLsizei>(width), static_cast<GLsizei>(height));
1282 }
1283
1284 void GraphicsContext3D::getBooleanv(unsigned long paramName, unsigned char* value)
1285 {
1286     m_internal->m_glWidget->makeCurrent();
1287     glGetBooleanv(paramName, value);
1288 }
1289
1290 void GraphicsContext3D::getBufferParameteriv(unsigned long target, unsigned long paramName, int* value)
1291 {
1292     m_internal->m_glWidget->makeCurrent();
1293     m_internal->getBufferParameteriv(target, paramName, value);
1294 }
1295
1296 void GraphicsContext3D::getFloatv(unsigned long paramName, float* value)
1297 {
1298     m_internal->m_glWidget->makeCurrent();
1299     glGetFloatv(paramName, value);
1300 }
1301
1302 void GraphicsContext3D::getFramebufferAttachmentParameteriv(unsigned long target, unsigned long attachment, unsigned long paramName, int* value)
1303 {
1304     m_internal->m_glWidget->makeCurrent();
1305     m_internal->getFramebufferAttachmentParameteriv(target, attachment, paramName, value);
1306 }
1307
1308 void GraphicsContext3D::getIntegerv(unsigned long paramName, int* value)
1309 {
1310     m_internal->m_glWidget->makeCurrent();
1311     glGetIntegerv(paramName, value);
1312 }
1313
1314 void GraphicsContext3D::getProgramiv(WebGLProgram* program, unsigned long paramName, int* value)
1315 {
1316     m_internal->m_glWidget->makeCurrent();
1317     m_internal->getProgramiv((GLuint) program->object(), paramName, value);
1318 }
1319
1320 String GraphicsContext3D::getProgramInfoLog(WebGLProgram* program)
1321 {
1322     m_internal->m_glWidget->makeCurrent();
1323
1324     GLint length;
1325     m_internal->getProgramiv((GLuint) program->object(), GraphicsContext3D::INFO_LOG_LENGTH, &length);
1326
1327     GLsizei size;
1328
1329     GLchar* info = (GLchar*) fastMalloc(length);
1330     if (!info)
1331         return "";
1332
1333     m_internal->getProgramInfoLog((GLuint) program->object(), length, &size, info);
1334
1335     String result(info);
1336     fastFree(info);
1337
1338     return result;
1339 }
1340
1341 void GraphicsContext3D::getRenderbufferParameteriv(unsigned long target, unsigned long paramName, int* value)
1342 {
1343     m_internal->m_glWidget->makeCurrent();
1344     m_internal->getRenderbufferParameteriv(target, paramName, value);
1345 }
1346
1347 void GraphicsContext3D::getShaderiv(WebGLShader* shader, unsigned long paramName, int* value)
1348 {
1349     ASSERT(shader);
1350     m_internal->m_glWidget->makeCurrent();
1351     m_internal->getShaderiv((GLuint) shader->object(), paramName, value);
1352 }
1353
1354 String GraphicsContext3D::getShaderInfoLog(WebGLShader* shader)
1355 {
1356     m_internal->m_glWidget->makeCurrent();
1357
1358     GLint length;
1359     m_internal->getShaderiv((GLuint) shader->object(), GraphicsContext3D::INFO_LOG_LENGTH, &length);
1360
1361     GLsizei size;
1362     GLchar* info = (GLchar*) fastMalloc(length);
1363     if (!info)
1364         return "";
1365
1366     m_internal->getShaderInfoLog((GLuint) shader->object(), length, &size, info);
1367
1368     String result(info);
1369     fastFree(info);
1370
1371     return result;
1372 }
1373
1374 String GraphicsContext3D::getShaderSource(WebGLShader* shader)
1375 {
1376     m_internal->m_glWidget->makeCurrent();
1377
1378     GLint length;
1379     m_internal->getShaderiv((GLuint) shader->object(), GraphicsContext3D::SHADER_SOURCE_LENGTH, &length);
1380
1381     GLsizei size;
1382     GLchar* info = (GLchar*) fastMalloc(length);
1383     if (!info)
1384         return "";
1385
1386     m_internal->getShaderSource((GLuint) shader->object(), length, &size, info);
1387
1388     String result(info);
1389     fastFree(info);
1390
1391     return result;
1392 }
1393
1394 void GraphicsContext3D::getTexParameterfv(unsigned long target, unsigned long paramName, float* value)
1395 {
1396     m_internal->m_glWidget->makeCurrent();
1397     glGetTexParameterfv(target, paramName, value);
1398 }
1399
1400 void GraphicsContext3D::getTexParameteriv(unsigned long target, unsigned long paramName, int* value)
1401 {
1402     m_internal->m_glWidget->makeCurrent();
1403     glGetTexParameteriv(target, paramName, value);
1404 }
1405
1406 void GraphicsContext3D::getUniformfv(WebGLProgram* program, long location, float* value)
1407 {
1408     m_internal->m_glWidget->makeCurrent();
1409     m_internal->getUniformfv((GLuint) program->object(), location, value);
1410 }
1411
1412 void GraphicsContext3D::getUniformiv(WebGLProgram* program, long location, int* value)
1413 {
1414     m_internal->m_glWidget->makeCurrent();
1415     m_internal->getUniformiv((GLuint) program->object(), location, value);
1416 }
1417
1418 long GraphicsContext3D::getUniformLocation(WebGLProgram* program, const String& name)
1419 {
1420     ASSERT(program);
1421    
1422     m_internal->m_glWidget->makeCurrent();
1423     return m_internal->getUniformLocation((GLuint) program->object(), name.utf8().data());
1424 }
1425
1426 void GraphicsContext3D::getVertexAttribfv(unsigned long index, unsigned long paramName, float* value)
1427 {
1428     m_internal->m_glWidget->makeCurrent();
1429     m_internal->getVertexAttribfv(index, paramName, value);
1430 }
1431
1432 void GraphicsContext3D::getVertexAttribiv(unsigned long index, unsigned long paramName, int* value)
1433 {
1434     m_internal->m_glWidget->makeCurrent();
1435     m_internal->getVertexAttribiv(index, paramName, value);
1436 }
1437
1438 long GraphicsContext3D::getVertexAttribOffset(unsigned long index, unsigned long paramName)
1439 {
1440     m_internal->m_glWidget->makeCurrent();
1441    
1442     void* pointer;
1443     m_internal->getVertexAttribPointerv(index, paramName, &pointer);
1444     return reinterpret_cast<long>(pointer);
1445 }
1446
1447 int GraphicsContext3D::texImage2D(unsigned target, unsigned level, unsigned internalformat, unsigned width, unsigned height, unsigned border, unsigned format, unsigned type, void* pixels)
1448 {
1449     glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
1450     return 0;
1451 }
1452
1453 int GraphicsContext3D::texImage2D(unsigned target, unsigned level, Image* image, bool flipY, bool premultiplyAlpha)
1454 {
1455     ASSERT(image);
1456    
1457     m_internal->m_glWidget->makeCurrent();
1458
1459     Vector<uint8_t> imageData;
1460     GLuint format;
1461     GLuint internalFormat;
1462
1463     if (!extractImageData(image, flipY, premultiplyAlpha, imageData, &format, &internalFormat)) {
1464         LOG_ERROR("GraphicsContext3D::texImage2D: could not extract Image data");
1465         return -1;
1466     }
1467
1468     glTexImage2D(target, level, internalFormat, image->width(), image->height(),
1469                  /* border */ 0, format, GraphicsContext3D::UNSIGNED_BYTE, imageData.data());
1470
1471     return 0;
1472 }
1473    
1474 int GraphicsContext3D::texSubImage2D(unsigned target, unsigned level, unsigned xoff, unsigned yoff, unsigned width, unsigned height, unsigned format, unsigned type, void* pixels)
1475 {
1476     glTexSubImage2D(target, level, xoff, yoff, width, height, format, type, pixels);
1477     return 0;
1478 }
1479
1480 int GraphicsContext3D::texSubImage2D(unsigned target, unsigned level, unsigned xoff, unsigned yoff, Image* image, bool flipY, bool premultiplyAlpha)
1481 {
1482     ASSERT(image);
1483
1484     Vector<uint8_t> imageData;
1485     GLuint format;
1486     GLuint internalFormat;
1487
1488     if (!extractImageData(image, flipY, premultiplyAlpha, imageData, &format, &internalFormat)) {
1489         LOG_ERROR("GraphicsContext3D::texSubImage2D: could not extract Image data");
1490         return -1;
1491     }
1492
1493     glTexSubImage2D(target, level, xoff, yoff, image->width(), image->height(),
1494                     format, GraphicsContext3D::UNSIGNED_BYTE, imageData.data());
1495
1496     return 0;
1497 }
1498
1499 unsigned GraphicsContext3D::createBuffer()
1500 {
1501     m_internal->m_glWidget->makeCurrent();
1502     GLuint handle;
1503     m_internal->genBuffers(/* count */ 1, &handle);
1504     return handle;
1505 }
1506
1507 unsigned GraphicsContext3D::createFramebuffer()
1508 {
1509     m_internal->m_glWidget->makeCurrent();
1510     GLuint handle;
1511     m_internal->genFramebuffers(/* count */ 1, &handle);
1512     return handle;
1513 }
1514
1515 unsigned GraphicsContext3D::createProgram()
1516 {
1517     m_internal->m_glWidget->makeCurrent();
1518     return m_internal->createProgram();
1519 }
1520
1521 unsigned GraphicsContext3D::createRenderbuffer()
1522 {
1523     m_internal->m_glWidget->makeCurrent();
1524     GLuint handle;
1525     m_internal->genRenderbuffers(/* count */ 1, &handle);
1526     return handle;
1527 }
1528
1529 unsigned GraphicsContext3D::createShader(unsigned long type)
1530 {
1531     m_internal->m_glWidget->makeCurrent();
1532     return m_internal->createShader((type == FRAGMENT_SHADER) ? GraphicsContext3D::FRAGMENT_SHADER : GraphicsContext3D::VERTEX_SHADER);
1533 }
1534
1535 unsigned GraphicsContext3D::createTexture()
1536 {
1537     m_internal->m_glWidget->makeCurrent();
1538     GLuint handle;
1539     glGenTextures(1, &handle);
1540     return handle;
1541 }
1542
1543 void GraphicsContext3D::deleteBuffer(unsigned buffer)
1544 {
1545     m_internal->m_glWidget->makeCurrent();
1546     m_internal->deleteBuffers(1, &buffer);
1547 }
1548
1549 void GraphicsContext3D::deleteFramebuffer(unsigned framebuffer)
1550 {
1551     m_internal->m_glWidget->makeCurrent();
1552     m_internal->deleteFramebuffers(1, &framebuffer);
1553 }
1554
1555 void GraphicsContext3D::deleteProgram(unsigned program)
1556 {
1557     m_internal->m_glWidget->makeCurrent();
1558     m_internal->deleteProgram(program);
1559 }
1560
1561 void GraphicsContext3D::deleteRenderbuffer(unsigned renderbuffer)
1562 {
1563     m_internal->m_glWidget->makeCurrent();
1564     m_internal->deleteRenderbuffers(1, &renderbuffer);
1565 }
1566
1567 void GraphicsContext3D::deleteShader(unsigned shader)
1568 {
1569     m_internal->m_glWidget->makeCurrent();
1570     m_internal->deleteShader(shader);
1571 }
1572
1573 void GraphicsContext3D::deleteTexture(unsigned texture)
1574 {
1575     m_internal->m_glWidget->makeCurrent();
1576     glDeleteTextures(1, &texture);
1577 }
1578
1579 int GraphicsContext3D::sizeInBytes(int type)
1580 {
1581     switch (type) {
1582     case GraphicsContext3D::BYTE:
1583         return sizeof(GLbyte);
1584     case GraphicsContext3D::UNSIGNED_BYTE:
1585         return sizeof(GLubyte);
1586     case GraphicsContext3D::SHORT:
1587         return sizeof(GLshort);
1588     case GraphicsContext3D::UNSIGNED_SHORT:
1589         return sizeof(GLushort);
1590     case GraphicsContext3D::INT:
1591         return sizeof(GLint);
1592     case GraphicsContext3D::UNSIGNED_INT:
1593         return sizeof(GLuint);
1594     case GraphicsContext3D::FLOAT:
1595         return sizeof(GLfloat);
1596     default:
1597         return 0;
1598     }
1599 }
1600
1601 void GraphicsContext3D::synthesizeGLError(unsigned long error)
1602 {
1603     m_internal->m_syntheticErrors.add(error);
1604 }
1605
1606 bool GraphicsContext3D::getImageData(Image* image,
1607                                      Vector<uint8_t>& outputVector,
1608                                      bool premultiplyAlpha,
1609                                      bool* hasAlphaChannel,
1610                                      AlphaOp* neededAlphaOp,
1611                                      unsigned int* format)
1612 {
1613     QImage::Format imageFormat = (!premultiplyAlpha) ?
1614         QImage::Format_ARGB32 :
1615         QImage::Format_ARGB32_Premultiplied;
1616  
1617     QPixmap* nativePixmap = image->nativeImageForCurrentFrame();
1618
1619     *hasAlphaChannel = true;
1620     *neededAlphaOp = kAlphaDoNothing;
1621     *format = GraphicsContext3D::RGBA;
1622
1623     QImage nativeImage = nativePixmap->toImage().convertToFormat(imageFormat);
1624     outputVector.append(nativeImage.bits(), nativeImage.byteCount());
1625
1626     return true;
1627 }
1628
1629 }
1630
1631 #endif // ENABLE(3D_CANVAS)
1632
Note: See TracBrowser for help on using the browser.