/src/3rdparty/webkit/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGL.cpp

https://bitbucket.org/ultra_iter/qt-vtl · C++ · 196 lines · 123 code · 29 blank · 44 comment · 32 complexity · 9236684664e044ef4698e1cd7e206df9 MD5 · raw file

  1. /*
  2. * Copyright (C) 2010 Google 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. *
  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.
  13. *
  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.
  24. */
  25. #include "config.h"
  26. #if ENABLE(WEBGL)
  27. #include "Extensions3DOpenGL.h"
  28. #include "GraphicsContext3D.h"
  29. #include <wtf/Vector.h>
  30. #if PLATFORM(MAC)
  31. #include "ANGLE/ShaderLang.h"
  32. #include <OpenGL/gl.h>
  33. #elif PLATFORM(GTK)
  34. #include "OpenGLShims.h"
  35. #endif
  36. namespace WebCore {
  37. Extensions3DOpenGL::Extensions3DOpenGL(GraphicsContext3D* context)
  38. : m_initializedAvailableExtensions(false)
  39. , m_context(context)
  40. {
  41. }
  42. Extensions3DOpenGL::~Extensions3DOpenGL()
  43. {
  44. }
  45. bool Extensions3DOpenGL::supports(const String& name)
  46. {
  47. // Note on support for BGRA:
  48. //
  49. // For OpenGL ES2.0, requires checking for
  50. // GL_EXT_texture_format_BGRA8888 and GL_EXT_read_format_bgra.
  51. // For desktop GL, BGRA has been supported since OpenGL 1.2.
  52. //
  53. // However, note that the GL ES2 extension requires the
  54. // internalFormat to glTexImage2D() be GL_BGRA, while desktop GL
  55. // will not accept GL_BGRA (must be GL_RGBA), so this must be
  56. // checked on each platform. Desktop GL offers neither
  57. // GL_EXT_texture_format_BGRA8888 or GL_EXT_read_format_bgra, so
  58. // treat them as unsupported here.
  59. if (!m_initializedAvailableExtensions) {
  60. String extensionsString(reinterpret_cast<const char*>(::glGetString(GL_EXTENSIONS)));
  61. Vector<String> availableExtensions;
  62. extensionsString.split(" ", availableExtensions);
  63. for (size_t i = 0; i < availableExtensions.size(); ++i)
  64. m_availableExtensions.add(availableExtensions[i]);
  65. m_initializedAvailableExtensions = true;
  66. }
  67. // GL_ANGLE_framebuffer_blit and GL_ANGLE_framebuffer_multisample are "fake". They are implemented using other
  68. // extensions. In particular GL_EXT_framebuffer_blit and GL_EXT_framebuffer_multisample
  69. if (name == "GL_ANGLE_framebuffer_blit")
  70. return m_availableExtensions.contains("GL_EXT_framebuffer_blit");
  71. if (name == "GL_ANGLE_framebuffer_multisample")
  72. return m_availableExtensions.contains("GL_EXT_framebuffer_multisample");
  73. // Desktop GL always supports GL_OES_rgb8_rgba8.
  74. if (name == "GL_OES_rgb8_rgba8")
  75. return true;
  76. // If GL_ARB_texture_float is available then we report GL_OES_texture_float and
  77. // GL_OES_texture_half_float as available.
  78. if (name == "GL_OES_texture_float" || name == "GL_OES_texture_half_float")
  79. return m_availableExtensions.contains("GL_ARB_texture_float");
  80. // GL_OES_vertex_array_object
  81. if (name == "GL_OES_vertex_array_object")
  82. return m_availableExtensions.contains("GL_APPLE_vertex_array_object");
  83. // Desktop GL always supports the standard derivative functions
  84. if (name == "GL_OES_standard_derivatives")
  85. return true;
  86. return m_availableExtensions.contains(name);
  87. }
  88. void Extensions3DOpenGL::ensureEnabled(const String& name)
  89. {
  90. #if PLATFORM(MAC)
  91. if (name == "GL_OES_standard_derivatives") {
  92. // Enable support in ANGLE (if not enabled already)
  93. ANGLEWebKitBridge& compiler = m_context->m_compiler;
  94. ShBuiltInResources ANGLEResources = compiler.getResources();
  95. if (!ANGLEResources.OES_standard_derivatives) {
  96. ANGLEResources.OES_standard_derivatives = 1;
  97. compiler.setResources(ANGLEResources);
  98. }
  99. }
  100. #else
  101. ASSERT_UNUSED(name, supports(name));
  102. #endif
  103. }
  104. bool Extensions3DOpenGL::isEnabled(const String& name)
  105. {
  106. #if PLATFORM(MAC)
  107. if (name == "GL_OES_standard_derivatives") {
  108. ANGLEWebKitBridge& compiler = m_context->m_compiler;
  109. return compiler.getResources().OES_standard_derivatives;
  110. }
  111. #endif
  112. return supports(name);
  113. }
  114. int Extensions3DOpenGL::getGraphicsResetStatusARB()
  115. {
  116. return GraphicsContext3D::NO_ERROR;
  117. }
  118. 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)
  119. {
  120. ::glBlitFramebufferEXT(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
  121. }
  122. void Extensions3DOpenGL::renderbufferStorageMultisample(unsigned long target, unsigned long samples, unsigned long internalformat, unsigned long width, unsigned long height)
  123. {
  124. ::glRenderbufferStorageMultisampleEXT(target, samples, internalformat, width, height);
  125. }
  126. Platform3DObject Extensions3DOpenGL::createVertexArrayOES()
  127. {
  128. m_context->makeContextCurrent();
  129. #if !PLATFORM(GTK) && defined(GL_APPLE_vertex_array_object) && GL_APPLE_vertex_array_object
  130. GLuint array = 0;
  131. glGenVertexArraysAPPLE(1, &array);
  132. return array;
  133. #else
  134. return 0;
  135. #endif
  136. }
  137. void Extensions3DOpenGL::deleteVertexArrayOES(Platform3DObject array)
  138. {
  139. if (!array)
  140. return;
  141. m_context->makeContextCurrent();
  142. #if !PLATFORM(GTK) && defined(GL_APPLE_vertex_array_object) && GL_APPLE_vertex_array_object
  143. glDeleteVertexArraysAPPLE(1, &array);
  144. #endif
  145. }
  146. GC3Dboolean Extensions3DOpenGL::isVertexArrayOES(Platform3DObject array)
  147. {
  148. if (!array)
  149. return GL_FALSE;
  150. m_context->makeContextCurrent();
  151. #if !PLATFORM(GTK) && defined(GL_APPLE_vertex_array_object) && GL_APPLE_vertex_array_object
  152. return glIsVertexArrayAPPLE(array);
  153. #else
  154. return GL_FALSE;
  155. #endif
  156. }
  157. void Extensions3DOpenGL::bindVertexArrayOES(Platform3DObject array)
  158. {
  159. if (!array)
  160. return;
  161. m_context->makeContextCurrent();
  162. #if !PLATFORM(GTK) && defined(GL_APPLE_vertex_array_object) && GL_APPLE_vertex_array_object
  163. glBindVertexArrayAPPLE(array);
  164. #endif
  165. }
  166. } // namespace WebCore
  167. #endif // ENABLE(WEBGL)