2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "Extensions3DOpenGL.h"
32 #include "GraphicsContext3D.h"
33 #include <wtf/Vector.h>
36 #include "ANGLE/ShaderLang.h"
37 #include <OpenGL/gl.h>
38 #elif PLATFORM(GTK) || PLATFORM(EFL) || PLATFORM(QT)
39 #include "OpenGLShims.h"
44 Extensions3DOpenGL::Extensions3DOpenGL(GraphicsContext3D* context)
45 : Extensions3DOpenGLCommon(context)
49 Extensions3DOpenGL::~Extensions3DOpenGL()
54 void Extensions3DOpenGL::blitFramebuffer(long srcX0, long srcY0, long srcX1, long srcY1, long dstX0, long dstY0, long dstX1, long dstY1, unsigned long mask, unsigned long filter)
56 ::glBlitFramebufferEXT(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
59 void Extensions3DOpenGL::renderbufferStorageMultisample(unsigned long target, unsigned long samples, unsigned long internalformat, unsigned long width, unsigned long height)
61 ::glRenderbufferStorageMultisampleEXT(target, samples, internalformat, width, height);
64 Platform3DObject Extensions3DOpenGL::createVertexArrayOES()
66 m_context->makeContextCurrent();
68 #if (PLATFORM(GTK) || PLATFORM(QT) || PLATFORM(EFL))
69 if (isVertexArrayObjectSupported())
70 glGenVertexArrays(1, &array);
71 #elif defined(GL_APPLE_vertex_array_object) && GL_APPLE_vertex_array_object
72 glGenVertexArraysAPPLE(1, &array);
77 void Extensions3DOpenGL::deleteVertexArrayOES(Platform3DObject array)
82 m_context->makeContextCurrent();
83 #if (PLATFORM(GTK) || PLATFORM(QT) || PLATFORM(EFL))
84 if (isVertexArrayObjectSupported())
85 glDeleteVertexArrays(1, &array);
86 #elif defined(GL_APPLE_vertex_array_object) && GL_APPLE_vertex_array_object
87 glDeleteVertexArraysAPPLE(1, &array);
91 GC3Dboolean Extensions3DOpenGL::isVertexArrayOES(Platform3DObject array)
96 m_context->makeContextCurrent();
97 #if (PLATFORM(GTK) || PLATFORM(QT) || PLATFORM(EFL))
98 if (isVertexArrayObjectSupported())
99 return glIsVertexArray(array);
100 #elif defined(GL_APPLE_vertex_array_object) && GL_APPLE_vertex_array_object
101 return glIsVertexArrayAPPLE(array);
106 void Extensions3DOpenGL::bindVertexArrayOES(Platform3DObject array)
108 m_context->makeContextCurrent();
109 #if (PLATFORM(GTK) || PLATFORM(QT) || PLATFORM(EFL))
110 if (isVertexArrayObjectSupported())
111 glBindVertexArray(array);
112 #elif defined(GL_APPLE_vertex_array_object) && GL_APPLE_vertex_array_object
113 glBindVertexArrayAPPLE(array);
119 void Extensions3DOpenGL::copyTextureCHROMIUM(GC3Denum, Platform3DObject, Platform3DObject, GC3Dint, GC3Denum)
121 // FIXME: implement this function and add GL_CHROMIUM_copy_texture in supports().
125 void Extensions3DOpenGL::insertEventMarkerEXT(const String&)
127 // FIXME: implement this function and add GL_EXT_debug_marker in supports().
131 void Extensions3DOpenGL::pushGroupMarkerEXT(const String&)
133 // FIXME: implement this function and add GL_EXT_debug_marker in supports().
137 void Extensions3DOpenGL::popGroupMarkerEXT(void)
139 // FIXME: implement this function and add GL_EXT_debug_marker in supports().
143 bool Extensions3DOpenGL::supportsExtension(const String& name)
145 // GL_ANGLE_framebuffer_blit and GL_ANGLE_framebuffer_multisample are "fake". They are implemented using other
146 // extensions. In particular GL_EXT_framebuffer_blit and GL_EXT_framebuffer_multisample
147 if (name == "GL_ANGLE_framebuffer_blit")
148 return m_availableExtensions.contains("GL_EXT_framebuffer_blit");
149 if (name == "GL_ANGLE_framebuffer_multisample")
150 return m_availableExtensions.contains("GL_EXT_framebuffer_multisample");
152 // Desktop GL always supports GL_OES_rgb8_rgba8.
153 if (name == "GL_OES_rgb8_rgba8")
156 // If GL_ARB_texture_float is available then we report GL_OES_texture_float and
157 // GL_OES_texture_half_float as available.
158 if (name == "GL_OES_texture_float" || name == "GL_OES_texture_half_float")
159 return m_availableExtensions.contains("GL_ARB_texture_float");
161 // GL_OES_vertex_array_object
162 if (name == "GL_OES_vertex_array_object") {
163 #if (PLATFORM(GTK) || PLATFORM(QT) || PLATFORM(EFL))
164 return m_availableExtensions.contains("GL_ARB_vertex_array_object");
166 return m_availableExtensions.contains("GL_APPLE_vertex_array_object");
170 // Desktop GL always supports the standard derivative functions
171 if (name == "GL_OES_standard_derivatives")
174 // Desktop GL always supports UNSIGNED_INT indices
175 if (name == "GL_OES_element_index_uint")
178 if (name == "GL_EXT_texture_filter_anisotropic")
179 return m_availableExtensions.contains("GL_EXT_texture_filter_anisotropic");
181 if (name == "GL_EXT_draw_buffers") {
183 return m_availableExtensions.contains("GL_ARB_draw_buffers");
185 // FIXME: implement support for other platforms.
189 return m_availableExtensions.contains(name);
192 void Extensions3DOpenGL::drawBuffersEXT(GC3Dsizei n, const GC3Denum* bufs)
194 // FIXME: implement support for other platforms.
196 ::glDrawBuffersARB(n, bufs);
203 String Extensions3DOpenGL::getExtensions()
205 return String(reinterpret_cast<const char*>(::glGetString(GL_EXTENSIONS)));
208 #if (PLATFORM(GTK) || PLATFORM(QT) || PLATFORM(EFL))
209 bool Extensions3DOpenGL::isVertexArrayObjectSupported()
211 static const bool supportsVertexArrayObject = supports("GL_OES_vertex_array_object");
212 return supportsVertexArrayObject;
216 } // namespace WebCore
218 #endif // USE(3D_GRAPHICS)