1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
|
/*
* Copyright (C) 2011 Google Inc. All rights reserved.
* Copyright (C) 2012 Research In Motion Limited. All rights reserved.
* Copyright (C) 2014 Collabora Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#if USE(OPENGL_ES)
#include "ExtensionsGLOpenGLES.h"
#if ENABLE(WEBGL)
#include "GraphicsContextGLOpenGL.h"
#include "NotImplemented.h"
#if USE(LIBEPOXY)
#include "EpoxyEGL.h"
#else
#include <EGL/egl.h>
#endif
namespace WebCore {
ExtensionsGLOpenGLES::ExtensionsGLOpenGLES(GraphicsContextGLOpenGL* context, bool useIndexedGetString)
: ExtensionsGLOpenGLCommon(context, useIndexedGetString)
, m_contextResetStatus(GL_NO_ERROR)
, m_supportsOESvertexArrayObject(false)
, m_supportsIMGMultisampledRenderToTexture(false)
, m_supportsANGLEinstancedArrays(false)
, m_glFramebufferTexture2DMultisampleIMG(0)
, m_glRenderbufferStorageMultisampleIMG(0)
, m_glBindVertexArrayOES(0)
, m_glDeleteVertexArraysOES(0)
, m_glGenVertexArraysOES(0)
, m_glIsVertexArrayOES(0)
, m_glGetGraphicsResetStatusEXT(0)
, m_glReadnPixelsEXT(0)
, m_glGetnUniformfvEXT(0)
, m_glGetnUniformivEXT(0)
, m_glVertexAttribDivisorANGLE(nullptr)
, m_glDrawArraysInstancedANGLE(nullptr)
, m_glDrawElementsInstancedANGLE(nullptr)
{
}
ExtensionsGLOpenGLES::~ExtensionsGLOpenGLES() = default;
bool ExtensionsGLOpenGLES::isEnabled(const String& name)
{
// Return false immediately if the extension is not supported by the drivers.
bool enabled = ExtensionsGLOpenGLCommon::isEnabled(name);
if (!enabled)
return false;
// For GL_EXT_robustness, check that the context supports robust access.
if (name == "GL_EXT_robustness"_s)
return m_context->getInteger(GraphicsContextGL::CONTEXT_ROBUST_ACCESS) == GL_TRUE;
return true;
}
void ExtensionsGLOpenGLES::framebufferTexture2DMultisampleIMG(unsigned long target, unsigned long attachment, unsigned long textarget, unsigned texture, int level, unsigned long samples)
{
if (!m_context->makeContextCurrent())
return;
if (m_glFramebufferTexture2DMultisampleIMG)
m_glFramebufferTexture2DMultisampleIMG(target, attachment, textarget, texture, level, samples);
else
m_context->synthesizeGLError(GL_INVALID_OPERATION);
}
void ExtensionsGLOpenGLES::renderbufferStorageMultisampleIMG(unsigned long target, unsigned long samples, unsigned long internalformat, unsigned long width, unsigned long height)
{
if (!m_context->makeContextCurrent())
return;
if (m_glRenderbufferStorageMultisampleIMG)
m_glRenderbufferStorageMultisampleIMG(target, samples, internalformat, width, height);
else
m_context->synthesizeGLError(GL_INVALID_OPERATION);
}
void ExtensionsGLOpenGLES::renderbufferStorageMultisampleANGLE(GCGLenum target, GCGLsizei samples, GCGLenum internalformat, GCGLsizei width, GCGLsizei height)
{
if (!m_context->makeContextCurrent())
return;
if (m_glRenderbufferStorageMultisampleIMG)
renderbufferStorageMultisampleIMG(target, samples, internalformat, width, height);
else
notImplemented();
}
PlatformGLObject ExtensionsGLOpenGLES::createVertexArrayOES()
{
if (m_glGenVertexArraysOES) {
if (!m_context->makeContextCurrent())
return 0;
GLuint array = 0;
m_glGenVertexArraysOES(1, &array);
return array;
}
m_context->synthesizeGLError(GL_INVALID_OPERATION);
return 0;
}
void ExtensionsGLOpenGLES::deleteVertexArrayOES(PlatformGLObject array)
{
if (!array)
return;
if (m_glDeleteVertexArraysOES) {
if (!m_context->makeContextCurrent())
return;
m_glDeleteVertexArraysOES(1, &array);
return;
}
m_context->synthesizeGLError(GL_INVALID_OPERATION);
}
GCGLboolean ExtensionsGLOpenGLES::isVertexArrayOES(PlatformGLObject array)
{
if (!array)
return GL_FALSE;
if (m_glIsVertexArrayOES) {
if (!m_context->makeContextCurrent())
return GL_FALSE;
return m_glIsVertexArrayOES(array);
}
m_context->synthesizeGLError(GL_INVALID_OPERATION);
return false;
}
void ExtensionsGLOpenGLES::bindVertexArrayOES(PlatformGLObject array)
{
if (m_glBindVertexArrayOES) {
if (!m_context->makeContextCurrent())
return;
m_glBindVertexArrayOES(array);
} else
m_context->synthesizeGLError(GL_INVALID_OPERATION);
}
void ExtensionsGLOpenGLES::drawBuffersEXT(GCGLSpan<const GCGLenum> /* bufs */)
{
// FIXME: implement the support.
notImplemented();
}
void ExtensionsGLOpenGLES::readnPixelsEXT(int x, int y, GCGLsizei width, GCGLsizei height, GCGLenum format, GCGLenum type, GCGLsizei bufSize, void *data)
{
if (m_glReadnPixelsEXT) {
if (!m_context->makeContextCurrent())
return;
// FIXME: remove the two glFlush calls when the driver bug is fixed, i.e.,
// all previous rendering calls should be done before reading pixels.
::glFlush();
// FIXME: If non-BlackBerry platforms use this, they will need to implement
// their anti-aliasing code here.
m_glReadnPixelsEXT(x, y, width, height, format, type, bufSize, data);
return;
}
m_context->synthesizeGLError(GL_INVALID_OPERATION);
}
void ExtensionsGLOpenGLES::getnUniformfvEXT(GCGLuint program, int location, GCGLsizei bufSize, float *params)
{
if (m_glGetnUniformfvEXT) {
if (!m_context->makeContextCurrent())
return;
m_glGetnUniformfvEXT(program, location, bufSize, params);
return;
}
m_context->synthesizeGLError(GL_INVALID_OPERATION);
}
void ExtensionsGLOpenGLES::getnUniformivEXT(GCGLuint program, int location, GCGLsizei bufSize, int *params)
{
if (m_glGetnUniformivEXT) {
if (!m_context->makeContextCurrent())
return;
m_glGetnUniformivEXT(program, location, bufSize, params);
return;
}
m_context->synthesizeGLError(GL_INVALID_OPERATION);
}
void ExtensionsGLOpenGLES::drawArraysInstancedANGLE(GCGLenum mode, GCGLint first, GCGLsizei count, GCGLsizei primcount)
{
if (!m_glDrawArraysInstancedANGLE) {
m_context->synthesizeGLError(GL_INVALID_OPERATION);
return;
}
if (!m_context->makeContextCurrent())
return;
m_glDrawArraysInstancedANGLE(mode, first, count, primcount);
}
void ExtensionsGLOpenGLES::drawElementsInstancedANGLE(GCGLenum mode, GCGLsizei count, GCGLenum type, GCGLvoidptr offset, GCGLsizei primcount)
{
if (!m_glDrawElementsInstancedANGLE) {
m_context->synthesizeGLError(GL_INVALID_OPERATION);
return;
}
if (!m_context->makeContextCurrent())
return;
m_glDrawElementsInstancedANGLE(mode, count, type, reinterpret_cast<GLvoid*>(static_cast<intptr_t>(offset)), primcount);
}
void ExtensionsGLOpenGLES::vertexAttribDivisorANGLE(GCGLuint index, GCGLuint divisor)
{
if (!m_glVertexAttribDivisorANGLE) {
m_context->synthesizeGLError(GL_INVALID_OPERATION);
return;
}
if (!m_context->makeContextCurrent())
return;
m_glVertexAttribDivisorANGLE(index, divisor);
}
bool ExtensionsGLOpenGLES::platformSupportsExtension(const String& name)
{
if (name == "GL_ANGLE_instanced_arrays"_s) {
auto majorVersion = []() {
GLint version = 0;
::glGetIntegerv(GL_MAJOR_VERSION, &version);
return version;
};
if (m_availableExtensions.contains(name)) {
m_glVertexAttribDivisorANGLE = reinterpret_cast<PFNGLVERTEXATTRIBDIVISORANGLEPROC>(eglGetProcAddress("glVertexAttribDivisorANGLE"));
m_glDrawArraysInstancedANGLE = reinterpret_cast<PFNGLDRAWARRAYSINSTANCEDANGLEPROC >(eglGetProcAddress("glDrawArraysInstancedANGLE"));
m_glDrawElementsInstancedANGLE = reinterpret_cast<PFNGLDRAWELEMENTSINSTANCEDANGLEPROC >(eglGetProcAddress("glDrawElementsInstancedANGLE"));
m_supportsANGLEinstancedArrays = true;
} else if (majorVersion() >= 3 || (m_availableExtensions.contains("GL_EXT_instanced_arrays"_s) && m_availableExtensions.contains("GL_EXT_draw_instanced"_s))) {
m_glVertexAttribDivisorANGLE = ::glVertexAttribDivisor;
m_glDrawArraysInstancedANGLE = ::glDrawArraysInstanced;
m_glDrawElementsInstancedANGLE = ::glDrawElementsInstanced;
m_supportsANGLEinstancedArrays = true;
}
return m_supportsANGLEinstancedArrays;
}
if (m_availableExtensions.contains(name)) {
if (!m_supportsOESvertexArrayObject && name == "GL_OES_vertex_array_object"_s) {
m_glBindVertexArrayOES = reinterpret_cast<PFNGLBINDVERTEXARRAYOESPROC>(eglGetProcAddress("glBindVertexArrayOES"));
m_glGenVertexArraysOES = reinterpret_cast<PFNGLGENVERTEXARRAYSOESPROC>(eglGetProcAddress("glGenVertexArraysOES"));
m_glDeleteVertexArraysOES = reinterpret_cast<PFNGLDELETEVERTEXARRAYSOESPROC>(eglGetProcAddress("glDeleteVertexArraysOES"));
m_glIsVertexArrayOES = reinterpret_cast<PFNGLISVERTEXARRAYOESPROC>(eglGetProcAddress("glIsVertexArrayOES"));
m_supportsOESvertexArrayObject = true;
} else if (!m_supportsIMGMultisampledRenderToTexture && name == "GL_IMG_multisampled_render_to_texture"_s) {
m_glFramebufferTexture2DMultisampleIMG = reinterpret_cast<PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEIMGPROC>(eglGetProcAddress("glFramebufferTexture2DMultisampleIMG"));
m_glRenderbufferStorageMultisampleIMG = reinterpret_cast<PFNGLRENDERBUFFERSTORAGEMULTISAMPLEIMGPROC>(eglGetProcAddress("glRenderbufferStorageMultisampleIMG"));
m_supportsIMGMultisampledRenderToTexture = true;
} else if (!m_glGetGraphicsResetStatusEXT && name == "GL_EXT_robustness"_s) {
m_glGetGraphicsResetStatusEXT = reinterpret_cast<PFNGLGETGRAPHICSRESETSTATUSEXTPROC>(eglGetProcAddress("glGetGraphicsResetStatusEXT"));
m_glReadnPixelsEXT = reinterpret_cast<PFNGLREADNPIXELSEXTPROC>(eglGetProcAddress("glReadnPixelsEXT"));
m_glGetnUniformfvEXT = reinterpret_cast<PFNGLGETNUNIFORMFVEXTPROC>(eglGetProcAddress("glGetnUniformfvEXT"));
m_glGetnUniformivEXT = reinterpret_cast<PFNGLGETNUNIFORMIVEXTPROC>(eglGetProcAddress("glGetnUniformivEXT"));
} else if (name == "GL_EXT_draw_buffers"_s) {
// FIXME: implement the support.
return false;
}
return true;
}
return false;
}
String ExtensionsGLOpenGLES::getExtensions()
{
return String::fromLatin1(reinterpret_cast<const char*>(::glGetString(GL_EXTENSIONS)));
}
} // namespace WebCore
#endif // ENABLE(WEBGL)
#endif // USE(OPENGL_ES)
|