aboutsummaryrefslogtreecommitdiffhomepage
path: root/gpu
diff options
context:
space:
mode:
authorGravatar twiz@google.com <twiz@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-03-14 21:23:01 +0000
committerGravatar twiz@google.com <twiz@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-03-14 21:23:01 +0000
commit59a190bcab5d4b2bf03f8f10cb6a581d19fed403 (patch)
tree86335475250c187f467aeff3bfb8d81084016c1f /gpu
parentcd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5 (diff)
Implementation of a GL-virtualization layer for Skia. This allows for
environments using skia to specify a GL implementation at run-time, instead of relying on the linker to pull in the appropriate GL impl. A new structure, GrGLInterface is exposed. This struct contains a set of function pointers that should point to an appropriate GL implementation. This change also removes the reliance on GLew on windows builds. Review: http://codereview.appspot.com/4254059/ git-svn-id: http://skia.googlecode.com/svn/trunk@937 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gpu')
-rw-r--r--gpu/include/GrGLConfig.h247
-rw-r--r--gpu/include/GrGLInterface.h270
-rw-r--r--gpu/include/GrGLPlatformIncludes.h518
-rw-r--r--gpu/src/GrGLIndexBuffer.cpp7
-rw-r--r--gpu/src/GrGLInterface.cpp350
-rw-r--r--gpu/src/GrGLTexture.cpp8
-rw-r--r--gpu/src/GrGLUtil.cpp222
-rw-r--r--gpu/src/GrGLVertexBuffer.cpp7
-rw-r--r--gpu/src/GrGpuFactory.cpp7
-rw-r--r--gpu/src/GrGpuGL.cpp170
-rw-r--r--gpu/src/GrGpuGL.h10
-rw-r--r--gpu/src/gr_files.mk1
12 files changed, 1245 insertions, 572 deletions
diff --git a/gpu/include/GrGLConfig.h b/gpu/include/GrGLConfig.h
index c467f99c67..0a86e72e8e 100644
--- a/gpu/include/GrGLConfig.h
+++ b/gpu/include/GrGLConfig.h
@@ -1,5 +1,5 @@
/*
- Copyright 2010 Google Inc.
+ Copyright 2011 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -19,58 +19,9 @@
#define GrGLConfig_DEFINED
#include "GrTypes.h"
+#include "GrGLInterface.h"
-#if !defined(GR_GL_CUSTOM_SETUP)
- #define GR_GL_CUSTOM_SETUP 0
-#endif
/**
- * We need to pull in the right GL headers and determine whether we are
- * compiling for ES1, ES2, or desktop GL. (We allow ES1 and ES2 to both be
- * supported in the same build but not ESx and desktop). We also need to know
- * the platform-specific way to get extension function pointers (e.g.
- * eglGetProcAddress). The port specifies this info explicitly or we will infer
- * it from the GR_*_BUILD flag.
- *
- * To specify GL setup directly define GR_GL_CUSTOM_SETUP to 1 and define:
- * GR_SUPPORT_GLDESKTOP or (GR_SUPPORT_GLES1 and/or GR_SUPPORT_GLES2) to 1
- *
- * if GR_SUPPORT_GLDESKTOP is 1 then provide:
- * 1. The name of your GL header in GR_INCLUDE_GLDESKTOP
- * 2. If necessary, the name of a file that includes extension
- * definitions in GR_INCLUDE_GLDESKTOPext.
- * if GR_SUPPORT_GLES1 is 1 then provide:
- * 1. The name of your GL header in GR_INCLUDE_GLES1
- * 2. If necessary, the name of a file that includes extension
- * definitions in GR_INCLUDE_GLES1ext.
- * if GR_SUPPORT_GLES2 is 1 then provide:
- * 1. The name of your GL header in GR_INCLUDE_GLES2
- * 2. If necessary, the name of a file that includes extension
- * definitions in GR_INCLUDE_GLES2ext.
- *
- * Optionally, define GR_GL_FUNC to any qualifier needed on GL function
- * pointer declarations (e.g. __stdcall).
- *
- * Define GR_GL_PROC_ADDRESS to take a gl function and produce a
- * function pointer. Two examples:
- * 1. Your platform doesn't require a proc address function, just take
- * the address of the function:
- * #define GR_GL_PROC_ADDRESS(X) &X
- * 2. Your platform uses eglGetProcAddress:
- * #define GR_GL_PROC_ADDRESS eglGetProcAddress(#X)
- *
- * Optionally define GR_GL_PROC_ADDRESS_HEADER to include any additional
- * header necessary to use GR_GL_PROC_ADDRESS (e.g. <EGL/egl.h>)
- *
- * Alternatively, define GR_GL_CUSTOM_SETUP_HEADER (and not GR_GL_CUSTOM_SETUP)
- * to a header that can be included. This file should:
- * 1. Define the approprate GR_SUPPORT_GL* macro(s) to 1
- * 2. Includes all necessary GL headers.
- * 3. Optionally define GR_GL_FUNC.
- * 4. Define GR_GL_PROC_ADDRESS.
- * 5. Optionally define GR_GL_PROC_ADDRESS_HEADER
- *
- *------------------------------------------------------------------------------
- *
* The following are optional defines that can be enabled at the compiler
* command line, in a IDE project, in a GrUserConfig.h file, or in a GL custom
* file (if one is in use). They don't require GR_GL_CUSTOM_SETUP or
@@ -93,122 +44,6 @@
* when GR_GL_CHECK_ERROR is 1. Defaults to 1.
*/
-#if GR_GL_CUSTOM_SETUP
-
- #ifdef GR_SUPPORT_GLES1
- #include GR_INCLUDE_GLES1
- #if defined(GR_INCLUDE_GLES1ext)
- #include GR_INCLUDE_GLES1ext
- #endif
- #endif
-
- #ifdef GR_SUPPORT_GLES2
- #include GR_INCLUDE_GLES2
- #if defined(GR_INCLUDE_GLES2ext)
- #include GR_INCLUDE_GLES2ext
- #endif
- #endif
-
- #ifdef GR_SUPPORT_GLDESKTOP
- #include GR_INCLUDE_GLDESKTOP
- #if defined(GR_INCLUDE_GLDESKTOPext)
- #include GR_INCLUDE_GLDESKTOPext
- #endif
- #endif
-
-#elif defined(GR_GL_CUSTOM_SETUP_HEADER)
-
- #include GR_GL_CUSTOM_SETUP_HEADER
-
-#else
- #undef GR_GL_FUNC
- #undef GR_GL_PROC_ADDRESS
- #undef GR_GL_PROC_ADDRESS_HEADER
-
- #if GR_WIN32_BUILD
- #define GR_SUPPORT_GLDESKTOP 1
- // glew has to be included before gl
- #include <GL/glew.h>
- #include <GL/gl.h>
- // remove stupid windows defines
- #undef near
- #undef far
- #define GR_GL_FUNC __stdcall
- #define GR_GL_PROC_ADDRESS(X) wglGetProcAddress(#X)
- #define GR_GL_PROC_ADDRESS_HEADER <windows.h>
- #elif GR_MAC_BUILD
- #define GR_SUPPORT_GLDESKTOP 1
- #include <OpenGL/gl.h>
- #include <OpenGL/glext.h>
- #define GR_GL_PROC_ADDRESS(X) &X
- #elif GR_IOS_BUILD
- #define GR_SUPPORT_GLES1 1
- #include <OpenGLES/ES1/gl.h>
- #include <OpenGLES/ES1/glext.h>
- #define GR_SUPPORT_GLES2 1
- #include <OpenGLES/ES2/gl.h>
- #include <OpenGLES/ES2/glext.h>
- #define GR_GL_PROC_ADDRESS(X) &X
- #elif GR_ANDROID_BUILD
- #ifndef GL_GLEXT_PROTOTYPES
- #define GL_GLEXT_PROTOTYPES
- #endif
- #define GR_SUPPORT_GLES2 1
- #include <GLES2/gl2.h>
- #include <GLES2/gl2ext.h>
- #define GR_GL_PROC_ADDRESS(X) eglGetProcAddress(#X)
- #define GR_GL_PROC_ADDRESS_HEADER <EGL/egl.h>
- #elif GR_QNX_BUILD
- #ifndef GL_GLEXT_PROTOTYPES
- #define GL_GLEXT_PROTOTYPES
- #endif
- #define GR_SUPPORT_GLES2 1
- // This is needed by the QNX GLES2 headers
- #define GL_API_EXT
- #include <GLES2/gl2.h>
- #include <GLES2/gl2ext.h>
- #define GR_GL_PROC_ADDRESS(X) eglGetProcAddress(#X)
- #define GR_GL_PROC_ADDRESS_HEADER <EGL/egl.h>
- #elif GR_LINUX_BUILD
- #ifndef GL_GLEXT_PROTOTYPES
- #define GL_GLEXT_PROTOTYPES
- #endif
- #define GL_EXT_framebuffer_blit 0
- #include <GL/gl.h>
- #include <GL/glext.h>
- #define GR_GL_PROC_ADDRESS(X) &X
- #define GR_SUPPORT_GLDESKTOP 1
- #else
- #error "unsupported GR_???_BUILD"
- #endif
-
-#endif
-
-#if !defined(GR_SUPPORT_GLDESKTOP)
- #define GR_SUPPORT_GLDESKTOP 0
-#endif
-#if !defined(GR_SUPPORT_GLES1)
- #define GR_SUPPORT_GLES1 0
-#endif
-#if !defined(GR_SUPPORT_GLES2)
- #define GR_SUPPORT_GLES2 0
-#endif
-
-#define GR_SUPPORT_GLES ((GR_SUPPORT_GLES1) || (GR_SUPPORT_GLES2))
-
-#if !GR_SUPPORT_GLES && !GR_SUPPORT_GLDESKTOP
- #error "Either desktop or ES GL must be supported"
-#elif GR_SUPPORT_GLES && GR_SUPPORT_GLDESKTOP
- #error "Cannot support both desktop and ES GL"
-#endif
-
-#if !defined(GR_GL_FUNC)
- #define GR_GL_FUNC
-#endif
-
-#if !defined(GR_GL_PROC_ADDRESS)
- #error "Must define GR_GL_PROC_ADDRESS"
-#endif
#if !defined(GR_GL_LOG_CALLS)
#define GR_GL_LOG_CALLS 0
@@ -249,7 +84,7 @@
#error "unknown GR_TEXT_SCALAR type"
#endif
-// Pick a pixel config for 32bit bitmaps. Our default is GL_RGBA (expect on
+// Pick a pixel config for 32bit bitmaps. Our default is GL_RGBA (except on
// Windows where we match GDI's order).
#ifndef GR_GL_32BPP_COLOR_FORMAT
#if GR_WIN32_BUILD
@@ -259,67 +94,9 @@
#endif
#endif
-////////////////////////////////////////////////////////////////////////////////
-// Setup for opengl ES/desktop extensions
-// We make a struct of function pointers so that each GL context
-// can have it's own struct. (Some environments may have different proc
-// addresses for different contexts).
-
-extern "C" {
-struct GrGLExts {
-// FBO
- GLvoid (GR_GL_FUNC *GenFramebuffers)(GLsizei n, GLuint *framebuffers);
- GLvoid (GR_GL_FUNC *BindFramebuffer)(GLenum target, GLuint framebuffer);
- GLvoid (GR_GL_FUNC *FramebufferTexture2D)(GLenum target, GLenum attachment,
- GLenum textarget, GLuint texture,
- GLint level);
- GLenum (GR_GL_FUNC *CheckFramebufferStatus)(GLenum target);
- GLvoid (GR_GL_FUNC *DeleteFramebuffers)(GLsizei n, const
- GLuint *framebuffers);
- GLvoid (GR_GL_FUNC *RenderbufferStorage)(GLenum target,
- GLenum internalformat,
- GLsizei width, GLsizei height);
- GLvoid (GR_GL_FUNC *GenRenderbuffers)(GLsizei n, GLuint *renderbuffers);
- GLvoid (GR_GL_FUNC *DeleteRenderbuffers)(GLsizei n,
- const GLuint *renderbuffers);
- GLvoid (GR_GL_FUNC *FramebufferRenderbuffer)(GLenum target,
- GLenum attachment,
- GLenum renderbuffertarget,
- GLuint renderbuffer);
- GLvoid (GR_GL_FUNC *BindRenderbuffer)(GLenum target, GLuint renderbuffer);
-// Multisampling
- // same prototype for ARB_FBO, EXT_FBO, GL 3.0, & Apple ES extension
- GLvoid (GR_GL_FUNC *RenderbufferStorageMultisample)(GLenum target,
- GLsizei samples,
- GLenum internalformat,
- GLsizei width,
- GLsizei height);
- // desktop: ext_fbo_blit, arb_fbo, gl 3.0
- GLvoid (GR_GL_FUNC *BlitFramebuffer)(GLint srcX0, GLint srcY0,
- GLint srcX1, GLint srcY1,
- GLint dstX0, GLint dstY0,
- GLint dstX1, GLint dstY1,
- GLbitfield mask, GLenum filter);
- // apple's es extension
- GLvoid (GR_GL_FUNC *ResolveMultisampleFramebuffer)();
-
- // IMG'e es extension
- GLvoid (GR_GL_FUNC *FramebufferTexture2DMultisample)(GLenum target,
- GLenum attachment,
- GLenum textarget,
- GLuint texture,
- GLint level,
- GLsizei samples);
-
-// Buffer mapping (extension in ES).
- GLvoid* (GR_GL_FUNC *MapBuffer)(GLenum target, GLenum access);
- GLboolean (GR_GL_FUNC *UnmapBuffer)(GLenum target);
-};
-}
// BGRA format
-
#define GR_BGRA 0x80E1
// FBO / stencil formats
@@ -355,14 +132,12 @@ struct GrGLExts {
// Palette texture
#define GR_PALETTE8_RGBA8 0x8B91
-extern void GrGLInitExtensions(GrGLExts* exts);
-
////////////////////////////////////////////////////////////////////////////////
extern void GrGLCheckErr(const char* location, const char* call);
static inline void GrGLClearErr() {
- while (GL_NO_ERROR != glGetError()) {}
+ while (GL_NO_ERROR != GrGLGetGLInterface()->fGetError()) {}
}
#if GR_GL_CHECK_ERROR
@@ -379,18 +154,8 @@ static inline void GrGLClearErr() {
#define GR_GL_LOG_CALLS_IMPL(X)
#endif
-#define GR_GL(X) gl ## X; GR_GL_LOG_CALLS_IMPL(X); GR_GL_CHECK_ERROR_IMPL(X);
-#define GR_GL_NO_ERR(X) GrGLClearErr(); gl ## X; GR_GL_LOG_CALLS_IMPL(X); GR_GL_CHECK_ERROR_IMPL(X);
-#define GR_GLEXT(exts, X) exts. X; GR_GL_LOG_CALLS_IMPL(X); GR_GL_CHECK_ERROR_IMPL(X);
-#define GR_GLEXT_NO_ERR(exts, X) GrGLClearErr(); exts. X; GR_GL_LOG_CALLS_IMPL(X); GR_GL_CHECK_ERROR_IMPL(X);
-
-////////////////////////////////////////////////////////////////////////////////
-
-/**
- * Helpers for glGetString()
- */
-bool has_gl_extension(const char* ext);
-void gl_version(int* major, int* minor);
+#define GR_GL(X) GrGLGetGLInterface()->f##X;; GR_GL_LOG_CALLS_IMPL(X); GR_GL_CHECK_ERROR_IMPL(X);
+#define GR_GL_NO_ERR(X) GrGLGetGLInterface()->f##X;; GR_GL_LOG_CALLS_IMPL(X); GR_GL_CHECK_ERROR_IMPL(X);
////////////////////////////////////////////////////////////////////////////////
diff --git a/gpu/include/GrGLInterface.h b/gpu/include/GrGLInterface.h
new file mode 100644
index 0000000000..0c2a2d9bad
--- /dev/null
+++ b/gpu/include/GrGLInterface.h
@@ -0,0 +1,270 @@
+/*
+ Copyright 2011 Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+
+#ifndef GrGLInterface_DEFINED
+#define GrGLInterface_DEFINED
+
+#include "GrGLPlatformIncludes.h"
+
+#if !defined(GR_GL_FUNCTION_TYPE)
+ #define GR_GL_FUNCTION_TYPE
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Helpers for glGetString()
+ */
+bool has_gl_extension(const char* ext);
+void gl_version(int* major, int* minor);
+
+////////////////////////////////////////////////////////////////////////////////
+
+/*
+ * Routines managing the global interface used to invoke OpenGL calls.
+ */
+struct GrGLInterface;
+extern GrGLInterface* GrGLGetGLInterface();
+extern void GrGLSetGLInterface(GrGLInterface* gl_interface);
+
+/*
+ * Populates the global GrGLInterface pointer with an instance pointing to the
+ * GL implementation linked with the executable.
+ */
+extern void GrGLSetDefaultGLInterface();
+
+extern "C" {
+/*
+ * The following interface exports the OpenGL entry points used by the system.
+ * Use of OpenGL calls is disallowed. All calls should be invoked through
+ * the global instance of this struct, defined above.
+ *
+ * IMPORTANT NOTE: The OpenGL entry points exposed here include both core GL
+ * functions, and extensions. The system assumes that the address of the
+ * extension pointer will be valid across contexts.
+ */
+struct GrGLInterface {
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLActiveTextureProc)(GLenum texture);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLAttachShaderProc)(GLuint program, GLuint shader);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLBindAttribLocationProc)(GLuint program, GLuint index, const char* name);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLBindBufferProc)(GLenum target, GLuint buffer);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLBindTextureProc)(GLenum target, GLuint texture);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLBlendFuncProc)(GLenum sfactor, GLenum dfactor);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLBufferDataProc)(GLenum target, GLsizei size, const void* data, GLenum usage);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLBufferSubDataProc)(GLenum target, GLint offset, GLsizei size, const void* data);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLClearProc)(GLbitfield mask);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLClearColorProc)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLClearStencilProc)(GLint s);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLClientActiveTextureProc)(GLenum texture);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLColor4ubProc)(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLColorMaskProc)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLColorPointerProc)(GLint size, GLenum type, GLsizei stride, const GLvoid* pointer);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLCompileShaderProc)(GLuint shader);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLCompressedTexImage2DProc)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void* data);
+ typedef GLuint (GR_GL_FUNCTION_TYPE *GrGLCreateProgramProc)(void);
+ typedef GLuint (GR_GL_FUNCTION_TYPE *GrGLCreateShaderProc)(GLenum type);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLCullFaceProc)(GLenum mode);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteBuffersProc)(GLsizei n, const GLuint* buffers);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteProgramProc)(GLuint program);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteShaderProc)(GLuint shader);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteTexturesProc)(GLsizei n, const GLuint* textures);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLDepthMaskProc)(GLboolean flag);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLDisableProc)(GLenum cap);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLDisableClientStateProc)(GLenum array);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLDisableVertexAttribArrayProc)(GLuint index);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawArraysProc)(GLenum mode, GLint first, GLsizei count);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawElementsProc)(GLenum mode, GLsizei count, GLenum type, const void* indices);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLEnableProc)(GLenum cap);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLEnableClientStateProc)(GLenum cap);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLEnableVertexAttribArrayProc)(GLuint index);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLFrontFaceProc)(GLenum mode);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLGenBuffersProc)(GLsizei n, GLuint* buffers);
+ typedef GLenum (GR_GL_FUNCTION_TYPE *GrGLGetErrorProc)(void);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLGenTexturesProc)(GLsizei n, GLuint* textures);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLGetBufferParameterivProc)(GLenum target, GLenum pname, GLint* params);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLGetIntegervProc)(GLenum pname, GLint* params);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLGetProgramInfoLogProc)(GLuint program, GLsizei bufsize, GLsizei* length, char* infolog);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLGetProgramivProc)(GLuint program, GLenum pname, GLint* params);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLGetShaderInfoLogProc)(GLuint shader, GLsizei bufsize, GLsizei* length, char* infolog);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLGetShaderivProc)(GLuint shader, GLenum pname, GLint* params);
+ typedef const GLubyte* (GR_GL_FUNCTION_TYPE *GrGLGetStringProc)(GLenum name);
+ typedef GLint (GR_GL_FUNCTION_TYPE *GrGLGetUniformLocationProc)(GLuint program, const char* name);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLLineWidthProc)(GLfloat width);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLLinkProgramProc)(GLuint program);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLLoadMatrixfProc)(const GLfloat* m);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLMatrixModeProc)(GLenum mode);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLPixelStoreiProc)(GLenum pname, GLint param);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLPointSizeProc)(GLfloat size);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLReadPixelsProc)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLScissorProc)(GLint x, GLint y, GLsizei width, GLsizei height);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLShadeModelProc)(GLenum mode);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLShaderSourceProc)(GLuint shader, GLsizei count, const char** str, const GLint* length);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilFuncProc)(GLenum func, GLint ref, GLuint mask);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilFuncSeparateProc)(GLenum face, GLenum func, GLint ref, GLuint mask);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilMaskProc)(GLuint mask);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilMaskSeparateProc)(GLenum face, GLuint mask);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilOpProc)(GLenum fail, GLenum zfail, GLenum zpass);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilOpSeparateProc)(GLenum face, GLenum fail, GLenum zfail, GLenum zpass);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLTexCoordPointerProc)(GLint size, GLenum type, GLsizei stride, const GLvoid* pointer);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLTexEnviProc)(GLenum target, GLenum pname, GLint param);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLTexImage2DProc)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void* pixels);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLTexParameteriProc)(GLenum target, GLenum pname, GLint param);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLTexSubImage2DProc)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void* pixels);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1fvProc)(GLint location, GLsizei count, const GLfloat* v);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1iProc)(GLint location, GLint x);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform4fvProc)(GLint location, GLsizei count, const GLfloat* v);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLUniformMatrix3fvProc)(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLUseProgramProc)(GLuint program);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLVertexAttrib4fvProc)(GLuint indx, const GLfloat* values);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLVertexAttribPointerProc)(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* ptr);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLVertexPointerProc)(GLint size, GLenum type, GLsizei stride, const GLvoid* pointer);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLViewportProc)(GLint x, GLint y, GLsizei width, GLsizei height);
+
+ // FBO Extension Functions
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLBindFramebufferProc)(GLenum target, GLuint framebuffer);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLBindRenderbufferProc)(GLenum target, GLuint renderbuffer);
+ typedef GLenum (GR_GL_FUNCTION_TYPE *GrGLCheckFramebufferStatusProc)(GLenum target);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteFramebuffersProc)(GLsizei n, const GLuint *framebuffers);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteRenderbuffersProc)(GLsizei n, const GLuint *renderbuffers);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLFramebufferRenderbufferProc)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLFramebufferTexture2DProc)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLGenFramebuffersProc)(GLsizei n, GLuint *framebuffers);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLGenRenderbuffersProc)(GLsizei n, GLuint *renderbuffers);
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLRenderbufferStorageProc)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
+
+ // Multisampling Extension Functions
+ // same prototype for ARB_FBO, EXT_FBO, GL 3.0, & Apple ES extension
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLRenderbufferStorageMultisampleProc)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+ // desktop: ext_fbo_blit, arb_fbo, gl 3.0
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLBlitFramebufferProc)(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
+ // apple's es extension
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLResolveMultisampleFramebufferProc)();
+
+ // IMG'e es extension
+ typedef GLvoid (GR_GL_FUNCTION_TYPE *GrGLFramebufferTexture2DMultisampleProc)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples);
+
+ // Buffer mapping (extension in ES).
+ typedef GLvoid* (GR_GL_FUNCTION_TYPE *GrGLMapBufferProc)(GLenum target, GLenum access);
+ typedef GLboolean (GR_GL_FUNCTION_TYPE *GrGLUnmapBufferProc)(GLenum target);
+
+ GrGLActiveTextureProc fActiveTexture;
+ GrGLAttachShaderProc fAttachShader;
+ GrGLBindAttribLocationProc fBindAttribLocation;
+ GrGLBindBufferProc fBindBuffer;
+ GrGLBindTextureProc fBindTexture;
+ GrGLBlendFuncProc fBlendFunc;
+ GrGLBufferDataProc fBufferData;
+ GrGLBufferSubDataProc fBufferSubData;
+ GrGLClearProc fClear;
+ GrGLClearColorProc fClearColor;
+ GrGLClearStencilProc fClearStencil;
+ GrGLClientActiveTextureProc fClientActiveTexture;
+ GrGLColor4ubProc fColor4ub;
+ GrGLColorMaskProc fColorMask;
+ GrGLColorPointerProc fColorPointer;
+ GrGLCompileShaderProc fCompileShader;
+ GrGLCompressedTexImage2DProc fCompressedTexImage2D;
+ GrGLCreateProgramProc fCreateProgram;
+ GrGLCreateShaderProc fCreateShader;
+ GrGLCullFaceProc fCullFace;
+ GrGLDeleteBuffersProc fDeleteBuffers;
+ GrGLDeleteProgramProc fDeleteProgram;
+ GrGLDeleteShaderProc fDeleteShader;
+ GrGLDeleteTexturesProc fDeleteTextures;
+ GrGLDepthMaskProc fDepthMask;
+ GrGLDisableProc fDisable;
+ GrGLDisableClientStateProc fDisableClientState;
+ GrGLDisableVertexAttribArrayProc fDisableVertexAttribArray;
+ GrGLDrawArraysProc fDrawArrays;
+ GrGLDrawElementsProc fDrawElements;
+ GrGLEnableProc fEnable;
+ GrGLEnableClientStateProc fEnableClientState;
+ GrGLEnableVertexAttribArrayProc fEnableVertexAttribArray;
+ GrGLFrontFaceProc fFrontFace;
+ GrGLGenBuffersProc fGenBuffers;
+ GrGLGenTexturesProc fGenTextures;
+ GrGLGetBufferParameterivProc fGetBufferParameteriv;
+ GrGLGetErrorProc fGetError;
+ GrGLGetIntegervProc fGetIntegerv;
+ GrGLGetProgramInfoLogProc fGetProgramInfoLog;
+ GrGLGetProgramivProc fGetProgramiv;
+ GrGLGetShaderInfoLogProc fGetShaderInfoLog;
+ GrGLGetShaderivProc fGetShaderiv;
+ GrGLGetStringProc fGetString;
+ GrGLGetUniformLocationProc fGetUniformLocation;
+ GrGLLineWidthProc fLineWidth;
+ GrGLLinkProgramProc fLinkProgram;
+ GrGLLoadMatrixfProc fLoadMatrixf;
+ GrGLMatrixModeProc fMatrixMode;
+ GrGLPixelStoreiProc fPixelStorei;
+ GrGLPointSizeProc fPointSize;
+ GrGLReadPixelsProc fReadPixels;
+ GrGLScissorProc fScissor;
+ GrGLShadeModelProc fShadeModel;
+ GrGLShaderSourceProc fShaderSource;
+ GrGLStencilFuncProc fStencilFunc;
+ GrGLStencilFuncSeparateProc fStencilFuncSeparate;
+ GrGLStencilMaskProc fStencilMask;
+ GrGLStencilMaskSeparateProc fStencilMaskSeparate;
+ GrGLStencilOpProc fStencilOp;
+ GrGLStencilOpSeparateProc fStencilOpSeparate;
+ GrGLTexCoordPointerProc fTexCoordPointer;
+ GrGLTexEnviProc fTexEnvi;
+ GrGLTexImage2DProc fTexImage2D;
+ GrGLTexParameteriProc fTexParameteri;
+ GrGLTexSubImage2DProc fTexSubImage2D;
+ GrGLUniform1fvProc fUniform1fv;
+ GrGLUniform1iProc fUniform1i;
+ GrGLUniform4fvProc fUniform4fv;
+ GrGLUniformMatrix3fvProc fUniformMatrix3fv;
+ GrGLUseProgramProc fUseProgram;
+ GrGLVertexAttrib4fvProc fVertexAttrib4fv;
+ GrGLVertexAttribPointerProc fVertexAttribPointer;
+ GrGLVertexPointerProc fVertexPointer;
+ GrGLViewportProc fViewport;
+
+ // FBO Extension Functions
+ GrGLBindFramebufferProc fBindFramebuffer;
+ GrGLBindRenderbufferProc fBindRenderbuffer;
+ GrGLCheckFramebufferStatusProc fCheckFramebufferStatus;
+ GrGLDeleteFramebuffersProc fDeleteFramebuffers;
+ GrGLDeleteRenderbuffersProc fDeleteRenderbuffers;
+ GrGLFramebufferRenderbufferProc fFramebufferRenderbuffer;
+ GrGLFramebufferTexture2DProc fFramebufferTexture2D;
+ GrGLGenFramebuffersProc fGenFramebuffers;
+ GrGLGenRenderbuffersProc fGenRenderbuffers;
+ GrGLRenderbufferStorageProc fRenderbufferStorage;
+
+ // Multisampling Extension Functions
+ // same prototype for ARB_FBO, EXT_FBO, GL 3.0, & Apple ES extension
+ GrGLRenderbufferStorageMultisampleProc fRenderbufferStorageMultisample;
+ // desktop: ext_fbo_blit, arb_fbo, gl 3.0
+ GrGLBlitFramebufferProc fBlitFramebuffer;
+ // apple's es extension
+ GrGLResolveMultisampleFramebufferProc fResolveMultisampleFramebuffer;
+
+ // IMG'e es extension
+ GrGLFramebufferTexture2DMultisampleProc fFramebufferTexture2DMultisample;
+
+ // Buffer mapping (extension in ES).
+ GrGLMapBufferProc fMapBuffer;
+ GrGLUnmapBufferProc fUnmapBuffer;
+};
+
+} // extern "C"
+
+#endif
diff --git a/gpu/include/GrGLPlatformIncludes.h b/gpu/include/GrGLPlatformIncludes.h
new file mode 100644
index 0000000000..1a4fa40003
--- /dev/null
+++ b/gpu/include/GrGLPlatformIncludes.h
@@ -0,0 +1,518 @@
+/*
+ Copyright 2011 Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+
+#ifndef GrGLPlatformIncludes_DEFINED
+#define GrGLPlatformIncludes_DEFINED
+
+#include "GrConfig.h"
+
+#if !defined(GR_GL_CUSTOM_SETUP)
+ #define GR_GL_CUSTOM_SETUP 0
+#endif
+
+/**
+ * We need to pull in the right GL headers and determine whether we are
+ * compiling for ES1, ES2, or desktop GL. (We allow ES1 and ES2 to both be
+ * supported in the same build but not ESx and desktop). We also need to know
+ * the platform-specific way to get extension function pointers (e.g.
+ * eglGetProcAddress). The port specifies this info explicitly or we will infer
+ * it from the GR_*_BUILD flag.
+ *
+ * To specify GL setup directly define GR_GL_CUSTOM_SETUP to 1 and define:
+ * GR_SUPPORT_GLDESKTOP or (GR_SUPPORT_GLES1 and/or GR_SUPPORT_GLES2) to 1
+ *
+ * if GR_SUPPORT_GLDESKTOP is 1 then provide:
+ * 1. The name of your GL header in GR_INCLUDE_GLDESKTOP
+ * 2. If necessary, the name of a file that includes extension
+ * definitions in GR_INCLUDE_GLDESKTOPext.
+ * if GR_SUPPORT_GLES1 is 1 then provide:
+ * 1. The name of your GL header in GR_INCLUDE_GLES1
+ * 2. If necessary, the name of a file that includes extension
+ * definitions in GR_INCLUDE_GLES1ext.
+ * if GR_SUPPORT_GLES2 is 1 then provide:
+ * 1. The name of your GL header in GR_INCLUDE_GLES2
+ * 2. If necessary, the name of a file that includes extension
+ * definitions in GR_INCLUDE_GLES2ext.
+ *
+ * Optionally, define GR_GL_FUNC to any qualifier needed on GL function
+ * pointer declarations (e.g. __stdcall).
+ *
+ * Define GR_GL_PROC_ADDRESS to take a gl function and produce a
+ * function pointer. Two examples:
+ * 1. Your platform doesn't require a proc address function, just take
+ * the address of the function:
+ * #define GR_GL_PROC_ADDRESS(X) &X
+ * 2. Your platform uses eglGetProcAddress:
+ * #define GR_GL_PROC_ADDRESS eglGetProcAddress(#X)
+ *
+ * Optionally define GR_GL_PROC_ADDRESS_HEADER to include any additional
+ * header necessary to use GR_GL_PROC_ADDRESS (e.g. <EGL/egl.h>)
+ *
+ * Alternatively, define GR_GL_CUSTOM_SETUP_HEADER (and not GR_GL_CUSTOM_SETUP)
+ * to a header that can be included. This file should:
+ * 1. Define the approprate GR_SUPPORT_GL* macro(s) to 1
+ * 2. Includes all necessary GL headers.
+ * 3. Optionally define GR_GL_FUNC.
+ * 4. Define GR_GL_PROC_ADDRESS.
+ * 5. Optionally define GR_GL_PROC_ADDRESS_HEADER
+ */
+
+#if GR_GL_CUSTOM_SETUP
+
+ #ifdef GR_SUPPORT_GLES1
+ #include GR_INCLUDE_GLES1
+ #if defined(GR_INCLUDE_GLES1ext)
+ #include GR_INCLUDE_GLES1ext
+ #endif
+ #endif
+
+ #ifdef GR_SUPPORT_GLES2
+ #include GR_INCLUDE_GLES2
+ #if defined(GR_INCLUDE_GLES2ext)
+ #include GR_INCLUDE_GLES2ext
+ #endif
+ #endif
+
+ #ifdef GR_SUPPORT_GLDESKTOP
+ #include GR_INCLUDE_GLDESKTOP
+ #if defined(GR_INCLUDE_GLDESKTOPext)
+ #include GR_INCLUDE_GLDESKTOPext
+ #endif
+ #endif
+
+#elif defined(GR_GL_CUSTOM_SETUP_HEADER)
+
+ #include GR_GL_CUSTOM_SETUP_HEADER
+
+#else
+ #undef GR_GL_FUNCTION_TYPE
+ #undef GR_GL_PROC_ADDRESS
+ #undef GR_GL_PROC_ADDRESS_HEADER
+
+ #if GR_WIN32_BUILD
+ #define GR_SUPPORT_GLDESKTOP 1
+ #include <Windows.h>
+ #include <GL/gl.h>
+ // remove stupid windows defines
+ #undef near
+ #undef far
+ #define GR_GL_EMIT_GL_CONSTANTS 1
+ #define GR_GL_FUNCTION_TYPE __stdcall
+ #define GR_GL_PROC_ADDRESS(X) wglGetProcAddress(#X)
+ #define GR_GL_PROC_ADDRESS_HEADER <windows.h>
+
+ // Force querying for the existence of these extensions on Windows
+ // builds.
+ #define GL_APPLE_framebuffer_multisample 1
+ #define GL_EXT_framebuffer_object 1
+ #define GL_IMG_multisampled_render_to_texture 1
+ #define GL_OES_mapbuffer 1
+ #define GL_OES_mapbuffer 1
+ #elif GR_MAC_BUILD
+ #define GR_SUPPORT_GLDESKTOP 1
+ #include <OpenGL/gl.h>
+ #include <OpenGL/glext.h>
+ #define GR_GL_PROC_ADDRESS(X) &X
+ #elif GR_IOS_BUILD
+ #define GR_SUPPORT_GLES1 1
+ #include <OpenGLES/ES1/gl.h>
+ #include <OpenGLES/ES1/glext.h>
+ #define GR_SUPPORT_GLES2 1
+ #include <OpenGLES/ES2/gl.h>
+ #include <OpenGLES/ES2/glext.h>
+ #define GR_GL_PROC_ADDRESS(X) &X
+ #elif GR_ANDROID_BUILD
+ #ifndef GL_GLEXT_PROTOTYPES
+ #define GL_GLEXT_PROTOTYPES
+ #endif
+ #define GR_SUPPORT_GLES2 1
+ #include <GLES2/gl2.h>
+ #include <GLES2/gl2ext.h>
+ #define GR_GL_PROC_ADDRESS(X) eglGetProcAddress(#X)
+ #define GR_GL_PROC_ADDRESS_HEADER <EGL/egl.h>
+ #elif GR_QNX_BUILD
+ #ifndef GL_GLEXT_PROTOTYPES
+ #define GL_GLEXT_PROTOTYPES
+ #endif
+ #define GR_SUPPORT_GLES2 1
+ // This is needed by the QNX GLES2 headers
+ #define GL_API_EXT
+ #include <GLES2/gl2.h>
+ #include <GLES2/gl2ext.h>
+ #define GR_GL_PROC_ADDRESS(X) eglGetProcAddress(#X)
+ #define GR_GL_PROC_ADDRESS_HEADER <EGL/egl.h>
+ #elif GR_LINUX_BUILD
+ #ifndef GL_GLEXT_PROTOTYPES
+ #define GL_GLEXT_PROTOTYPES
+ #endif
+ #include <GL/gl.h>
+ #include <GL/glext.h>
+ #define GR_GL_PROC_ADDRESS(X) glXGetProcAddress(reinterpret_cast<const GLubyte*>(#X))
+ #define GR_SUPPORT_GLDESKTOP 1
+ #define GR_GL_PROC_ADDRESS_HEADER <GL/glx.h>
+ #else
+ #error "unsupported GR_???_BUILD"
+ #endif
+
+#endif
+
+#if !defined(GR_SUPPORT_GLDESKTOP)
+ #define GR_SUPPORT_GLDESKTOP 0
+#endif
+#if !defined(GR_SUPPORT_GLES1)
+ #define GR_SUPPORT_GLES1 0
+#endif
+#if !defined(GR_SUPPORT_GLES2)
+ #define GR_SUPPORT_GLES2 0
+#endif
+
+#define GR_SUPPORT_GLES ((GR_SUPPORT_GLES1) || (GR_SUPPORT_GLES2))
+
+#if !GR_SUPPORT_GLES && !GR_SUPPORT_GLDESKTOP
+ #error "Either desktop or ES GL must be supported"
+#elif GR_SUPPORT_GLES && GR_SUPPORT_GLDESKTOP
+ #error "Cannot support both desktop and ES GL"
+#endif
+
+#if GR_WIN32_BUILD && GR_GL_EMIT_GL_CONSTANTS
+
+// The windows GL headers do not provide the constants used for extensions and
+// some versions of GL. Define them here.
+
+// OpenGL 1.2 Defines
+#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12
+#define GL_SMOOTH_POINT_SIZE_GRANULARITY 0x0B13
+#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22
+#define GL_SMOOTH_LINE_WIDTH_GRANULARITY 0x0B23
+#define GL_UNSIGNED_BYTE_3_3_2 0x8032
+#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033
+#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034
+#define GL_UNSIGNED_INT_8_8_8_8 0x8035
+#define GL_UNSIGNED_INT_10_10_10_2 0x8036
+#define GL_RESCALE_NORMAL 0x803A
+#define GL_TEXTURE_BINDING_3D 0x806A
+#define GL_PACK_SKIP_IMAGES 0x806B
+#define GL_PACK_IMAGE_HEIGHT 0x806C
+#define GL_UNPACK_SKIP_IMAGES 0x806D
+#define GL_UNPACK_IMAGE_HEIGHT 0x806E
+#define GL_TEXTURE_3D 0x806F
+#define GL_PROXY_TEXTURE_3D 0x8070
+#define GL_TEXTURE_DEPTH 0x8071
+#define GL_TEXTURE_WRAP_R 0x8072
+#define GL_MAX_3D_TEXTURE_SIZE 0x8073
+#define GL_BGR 0x80E0
+#define GL_BGRA 0x80E1
+#define GL_MAX_ELEMENTS_VERTICES 0x80E8
+#define GL_MAX_ELEMENTS_INDICES 0x80E9
+#define GL_CLAMP_TO_EDGE 0x812F
+#define GL_TEXTURE_MIN_LOD 0x813A
+#define GL_TEXTURE_MAX_LOD 0x813B
+#define GL_TEXTURE_BASE_LEVEL 0x813C
+#define GL_TEXTURE_MAX_LEVEL 0x813D
+#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8
+#define GL_SINGLE_COLOR 0x81F9
+#define GL_SEPARATE_SPECULAR_COLOR 0x81FA
+#define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362
+#define GL_UNSIGNED_SHORT_5_6_5 0x8363
+#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364
+#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365
+#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366
+#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367
+#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368
+#define GL_ALIASED_POINT_SIZE_RANGE 0x846D
+#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E
+
+// OpenGL 1.3 Multi-Sample Constant Values
+#define GL_MULTISAMPLE 0x809D
+#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E
+#define GL_SAMPLE_ALPHA_TO_ONE 0x809F
+#define GL_SAMPLE_COVERAGE 0x80A0
+#define GL_SAMPLE_BUFFERS 0x80A8
+#define GL_SAMPLES 0x80A9
+#define GL_SAMPLE_COVERAGE_VALUE 0x80AA
+#define GL_SAMPLE_COVERAGE_INVERT 0x80AB
+#define GL_CLAMP_TO_BORDER 0x812D
+#define GL_TEXTURE0 0x84C0
+#define GL_TEXTURE1 0x84C1
+#define GL_TEXTURE2 0x84C2
+#define GL_TEXTURE3 0x84C3
+#define GL_TEXTURE4 0x84C4
+#define GL_TEXTURE5 0x84C5
+#define GL_TEXTURE6 0x84C6
+#define GL_TEXTURE7 0x84C7
+#define GL_TEXTURE8 0x84C8
+#define GL_TEXTURE9 0x84C9
+#define GL_TEXTURE10 0x84CA
+#define GL_TEXTURE11 0x84CB
+#define GL_TEXTURE12 0x84CC
+#define GL_TEXTURE13 0x84CD
+#define GL_TEXTURE14 0x84CE
+#define GL_TEXTURE15 0x84CF
+#define GL_TEXTURE16 0x84D0
+#define GL_TEXTURE17 0x84D1
+#define GL_TEXTURE18 0x84D2
+#define GL_TEXTURE19 0x84D3
+#define GL_TEXTURE20 0x84D4
+#define GL_TEXTURE21 0x84D5
+#define GL_TEXTURE22 0x84D6
+#define GL_TEXTURE23 0x84D7
+#define GL_TEXTURE24 0x84D8
+#define GL_TEXTURE25 0x84D9
+#define GL_TEXTURE26 0x84DA
+#define GL_TEXTURE27 0x84DB
+#define GL_TEXTURE28 0x84DC
+#define GL_TEXTURE29 0x84DD
+#define GL_TEXTURE30 0x84DE
+#define GL_TEXTURE31 0x84DF
+#define GL_ACTIVE_TEXTURE 0x84E0
+#define GL_CLIENT_ACTIVE_TEXTURE 0x84E1
+#define GL_MAX_TEXTURE_UNITS 0x84E2
+#define GL_TRANSPOSE_MODELVIEW_MATRIX 0x84E3
+#define GL_TRANSPOSE_PROJECTION_MATRIX 0x84E4
+#define GL_TRANSPOSE_TEXTURE_MATRIX 0x84E5
+#define GL_TRANSPOSE_COLOR_MATRIX 0x84E6
+#define GL_SUBTRACT 0x84E7
+#define GL_COMPRESSED_ALPHA 0x84E9
+#define GL_COMPRESSED_LUMINANCE 0x84EA
+#define GL_COMPRESSED_LUMINANCE_ALPHA 0x84EB
+#define GL_COMPRESSED_INTENSITY 0x84EC
+#define GL_COMPRESSED_RGB 0x84ED
+#define GL_COMPRESSED_RGBA 0x84EE
+#define GL_TEXTURE_COMPRESSION_HINT 0x84EF
+#define GL_NORMAL_MAP 0x8511
+#define GL_REFLECTION_MAP 0x8512
+#define GL_TEXTURE_CUBE_MAP 0x8513
+#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A
+#define GL_PROXY_TEXTURE_CUBE_MAP 0x851B
+#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C
+#define GL_COMBINE 0x8570
+#define GL_COMBINE_RGB 0x8571
+#define GL_COMBINE_ALPHA 0x8572
+#define GL_RGB_SCALE 0x8573
+#define GL_ADD_SIGNED 0x8574
+#define GL_INTERPOLATE 0x8575
+#define GL_CONSTANT 0x8576
+#define GL_PRIMARY_COLOR 0x8577
+#define GL_PREVIOUS 0x8578
+#define GL_SOURCE0_RGB 0x8580
+#define GL_SOURCE1_RGB 0x8581
+#define GL_SOURCE2_RGB 0x8582
+#define GL_SOURCE0_ALPHA 0x8588
+#define GL_SOURCE1_ALPHA 0x8589
+#define GL_SOURCE2_ALPHA 0x858A
+#define GL_OPERAND0_RGB 0x8590
+#define GL_OPERAND1_RGB 0x8591
+#define GL_OPERAND2_RGB 0x8592
+#define GL_OPERAND0_ALPHA 0x8598
+#define GL_OPERAND1_ALPHA 0x8599
+#define GL_OPERAND2_ALPHA 0x859A
+#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE 0x86A0
+#define GL_TEXTURE_COMPRESSED 0x86A1
+#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2
+#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3
+#define GL_DOT3_RGB 0x86AE
+#define GL_DOT3_RGBA 0x86AF
+#define GL_MULTISAMPLE_BIT 0x20000000
+
+// OpenGL 1.4 Defines
+#define GL_BLEND_DST_RGB 0x80C8
+#define GL_BLEND_SRC_RGB 0x80C9
+#define GL_BLEND_DST_ALPHA 0x80CA
+#define GL_BLEND_SRC_ALPHA 0x80CB
+#define GL_POINT_SIZE_MIN 0x8126
+#define GL_POINT_SIZE_MAX 0x8127
+#define GL_POINT_FADE_THRESHOLD_SIZE 0x8128
+#define GL_POINT_DISTANCE_ATTENUATION 0x8129
+#define GL_GENERATE_MIPMAP 0x8191
+#define GL_GENERATE_MIPMAP_HINT 0x8192
+#define GL_DEPTH_COMPONENT16 0x81A5
+#define GL_DEPTH_COMPONENT24 0x81A6
+#define GL_DEPTH_COMPONENT32 0x81A7
+#define GL_MIRRORED_REPEAT 0x8370
+#define GL_FOG_COORDINATE_SOURCE 0x8450
+#define GL_FOG_COORDINATE 0x8451
+#define GL_FRAGMENT_DEPTH 0x8452
+#define GL_CURRENT_FOG_COORDINATE 0x8453
+#define GL_FOG_COORDINATE_ARRAY_TYPE 0x8454
+#define GL_FOG_COORDINATE_ARRAY_STRIDE 0x8455
+#define GL_FOG_COORDINATE_ARRAY_POINTER 0x8456
+#define GL_FOG_COORDINATE_ARRAY 0x8457
+#define GL_COLOR_SUM 0x8458
+#define GL_CURRENT_SECONDARY_COLOR 0x8459
+#define GL_SECONDARY_COLOR_ARRAY_SIZE 0x845A
+#define GL_SECONDARY_COLOR_ARRAY_TYPE 0x845B
+#define GL_SECONDARY_COLOR_ARRAY_STRIDE 0x845C
+#define GL_SECONDARY_COLOR_ARRAY_POINTER 0x845D
+#define GL_SECONDARY_COLOR_ARRAY 0x845E
+#define GL_MAX_TEXTURE_LOD_BIAS 0x84FD
+#define GL_TEXTURE_FILTER_CONTROL 0x8500
+#define GL_TEXTURE_LOD_BIAS 0x8501
+#define GL_INCR_WRAP 0x8507
+#define GL_DECR_WRAP 0x8508
+#define GL_TEXTURE_DEPTH_SIZE 0x884A
+#define GL_DEPTH_TEXTURE_MODE 0x884B
+#define GL_TEXTURE_COMPARE_MODE 0x884C
+#define GL_TEXTURE_COMPARE_FUNC 0x884D
+#define GL_COMPARE_R_TO_TEXTURE 0x884E
+
+// OpenGL 1.5 Defines
+#define GL_FOG_COORD_SRC GL_FOG_COORDINATE_SOURCE
+#define GL_FOG_COORD GL_FOG_COORDINATE
+#define GL_FOG_COORD_ARRAY GL_FOG_COORDINATE_ARRAY
+#define GL_SRC0_RGB GL_SOURCE0_RGB
+#define GL_FOG_COORD_ARRAY_POINTER GL_FOG_COORDINATE_ARRAY_POINTER
+#define GL_FOG_COORD_ARRAY_TYPE GL_FOG_COORDINATE_ARRAY_TYPE
+#define GL_SRC1_ALPHA GL_SOURCE1_ALPHA
+#define GL_CURRENT_FOG_COORD GL_CURRENT_FOG_COORDINATE
+#define GL_FOG_COORD_ARRAY_STRIDE GL_FOG_COORDINATE_ARRAY_STRIDE
+#define GL_SRC0_ALPHA GL_SOURCE0_ALPHA
+#define GL_SRC1_RGB GL_SOURCE1_RGB
+#define GL_FOG_COORD_ARRAY_BUFFER_BINDING GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING
+#define GL_SRC2_ALPHA GL_SOURCE2_ALPHA
+#define GL_SRC2_RGB GL_SOURCE2_RGB
+#define GL_BUFFER_SIZE 0x8764
+#define GL_BUFFER_USAGE 0x8765
+#define GL_QUERY_COUNTER_BITS 0x8864
+#define GL_CURRENT_QUERY 0x8865
+#define GL_QUERY_RESULT 0x8866
+#define GL_QUERY_RESULT_AVAILABLE 0x8867
+#define GL_ARRAY_BUFFER 0x8892
+#define GL_ELEMENT_ARRAY_BUFFER 0x8893
+#define GL_ARRAY_BUFFER_BINDING 0x8894
+#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895
+#define GL_VERTEX_ARRAY_BUFFER_BINDING 0x8896
+#define GL_NORMAL_ARRAY_BUFFER_BINDING 0x8897
+#define GL_COLOR_ARRAY_BUFFER_BINDING 0x8898
+#define GL_INDEX_ARRAY_BUFFER_BINDING 0x8899
+#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING 0x889A
+#define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING 0x889B
+#define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING 0x889C
+#define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING 0x889D
+#define GL_WEIGHT_ARRAY_BUFFER_BINDING 0x889E
+#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F
+#define GL_READ_ONLY 0x88B8
+#define GL_WRITE_ONLY 0x88B9
+#define GL_READ_WRITE 0x88BA
+#define GL_BUFFER_ACCESS 0x88BB
+#define GL_BUFFER_MAPPED 0x88BC
+#define GL_BUFFER_MAP_POINTER 0x88BD
+#define GL_STREAM_DRAW 0x88E0
+#define GL_STREAM_READ 0x88E1
+#define GL_STREAM_COPY 0x88E2
+#define GL_STATIC_DRAW 0x88E4
+#define GL_STATIC_READ 0x88E5
+#define GL_STATIC_COPY 0x88E6
+#define GL_DYNAMIC_DRAW 0x88E8
+#define GL_DYNAMIC_READ 0x88E9
+#define GL_DYNAMIC_COPY 0x88EA
+#define GL_SAMPLES_PASSED 0x8914
+
+// OpenGL 2.0 Defines
+#define GL_BLEND_EQUATION_RGB GL_BLEND_EQUATION
+#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622
+#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623
+#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624
+#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625
+#define GL_CURRENT_VERTEX_ATTRIB 0x8626
+#define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642
+#define GL_VERTEX_PROGRAM_TWO_SIDE 0x8643
+#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645
+#define GL_STENCIL_BACK_FUNC 0x8800
+#define GL_STENCIL_BACK_FAIL 0x8801
+#define GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802
+#define GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803
+#define GL_MAX_DRAW_BUFFERS 0x8824
+#define GL_DRAW_BUFFER0 0x8825
+#define GL_DRAW_BUFFER1 0x8826
+#define GL_DRAW_BUFFER2 0x8827
+#define GL_DRAW_BUFFER3 0x8828
+#define GL_DRAW_BUFFER4 0x8829
+#define GL_DRAW_BUFFER5 0x882A
+#define GL_DRAW_BUFFER6 0x882B
+#define GL_DRAW_BUFFER7 0x882C
+#define GL_DRAW_BUFFER8 0x882D
+#define GL_DRAW_BUFFER9 0x882E
+#define GL_DRAW_BUFFER10 0x882F
+#define GL_DRAW_BUFFER11 0x8830
+#define GL_DRAW_BUFFER12 0x8831
+#define GL_DRAW_BUFFER13 0x8832
+#define GL_DRAW_BUFFER14 0x8833
+#define GL_DRAW_BUFFER15 0x8834
+#define GL_BLEND_EQUATION_ALPHA 0x883D
+#define GL_POINT_SPRITE 0x8861
+#define GL_COORD_REPLACE 0x8862
+#define GL_MAX_VERTEX_ATTRIBS 0x8869
+#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A
+#define GL_MAX_TEXTURE_COORDS 0x8871
+#define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872
+#define GL_FRAGMENT_SHADER 0x8B30
+#define GL_VERTEX_SHADER 0x8B31
+#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS 0x8B49
+#define GL_MAX_VERTEX_UNIFORM_COMPONENTS 0x8B4A
+#define GL_MAX_VARYING_FLOATS 0x8B4B
+#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C
+#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D
+#define GL_SHADER_TYPE 0x8B4F
+#define GL_FLOAT_VEC2 0x8B50
+#define GL_FLOAT_VEC3 0x8B51
+#define GL_FLOAT_VEC4 0x8B52
+#define GL_INT_VEC2 0x8B53
+#define GL_INT_VEC3 0x8B54
+#define GL_INT_VEC4 0x8B55
+#define GL_BOOL 0x8B56
+#define GL_BOOL_VEC2 0x8B57
+#define GL_BOOL_VEC3 0x8B58
+#define GL_BOOL_VEC4 0x8B59
+#define GL_FLOAT_MAT2 0x8B5A
+#define GL_FLOAT_MAT3 0x8B5B
+#define GL_FLOAT_MAT4 0x8B5C
+#define GL_SAMPLER_1D 0x8B5D
+#define GL_SAMPLER_2D 0x8B5E
+#define GL_SAMPLER_3D 0x8B5F
+#define GL_SAMPLER_CUBE 0x8B60
+#define GL_SAMPLER_1D_SHADOW 0x8B61
+#define GL_SAMPLER_2D_SHADOW 0x8B62
+#define GL_DELETE_STATUS 0x8B80
+#define GL_COMPILE_STATUS 0x8B81
+#define GL_LINK_STATUS 0x8B82
+#define GL_VALIDATE_STATUS 0x8B83
+#define GL_INFO_LOG_LENGTH 0x8B84
+#define GL_ATTACHED_SHADERS 0x8B85
+#define GL_ACTIVE_UNIFORMS 0x8B86
+#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87
+#define GL_SHADER_SOURCE_LENGTH 0x8B88
+#define GL_ACTIVE_ATTRIBUTES 0x8B89
+#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A
+#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT 0x8B8B
+#define GL_SHADING_LANGUAGE_VERSION 0x8B8C
+#define GL_CURRENT_PROGRAM 0x8B8D
+#define GL_POINT_SPRITE_COORD_ORIGIN 0x8CA0
+#define GL_LOWER_LEFT 0x8CA1
+#define GL_UPPER_LEFT 0x8CA2
+#define GL_STENCIL_BACK_REF 0x8CA3
+#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4
+#define GL_STENCIL_BACK_WRITEMASK 0x8CA5
+
+#endif // GR_WIN32_BUILD
+
+#endif
diff --git a/gpu/src/GrGLIndexBuffer.cpp b/gpu/src/GrGLIndexBuffer.cpp
index 2dc4154209..9539c8a2a1 100644
--- a/gpu/src/GrGLIndexBuffer.cpp
+++ b/gpu/src/GrGLIndexBuffer.cpp
@@ -1,5 +1,5 @@
/*
- Copyright 2010 Google Inc.
+ Copyright 2011 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -57,8 +57,7 @@ void* GrGLIndexBuffer::lock() {
// Let driver know it can discard the old data
GR_GL(BufferData(GL_ELEMENT_ARRAY_BUFFER, size(), NULL,
dynamic() ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW));
- fLockPtr = GR_GLEXT(fGL->extensions(),
- MapBuffer(GL_ELEMENT_ARRAY_BUFFER, GR_WRITE_ONLY));
+ fLockPtr = GR_GL(MapBuffer(GL_ELEMENT_ARRAY_BUFFER, GR_WRITE_ONLY));
return fLockPtr;
}
@@ -75,7 +74,7 @@ void GrGLIndexBuffer::unlock() {
GrAssert(fGL->supportsBufferLocking());
bind();
- GR_GLEXT(fGL->extensions(), UnmapBuffer(GL_ELEMENT_ARRAY_BUFFER));
+ GR_GL(UnmapBuffer(GL_ELEMENT_ARRAY_BUFFER));
fLockPtr = NULL;
}
diff --git a/gpu/src/GrGLInterface.cpp b/gpu/src/GrGLInterface.cpp
new file mode 100644
index 0000000000..e74d29d497
--- /dev/null
+++ b/gpu/src/GrGLInterface.cpp
@@ -0,0 +1,350 @@
+/*
+ Copyright 2011 Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+
+#include "GrGLInterface.h"
+#include "GrTypes.h"
+
+#include <stdio.h>
+
+#if defined(GR_GL_PROC_ADDRESS_HEADER)
+ #include GR_GL_PROC_ADDRESS_HEADER
+#endif
+
+#if !defined(GR_GL_PROC_ADDRESS)
+ #error "Must define GR_GL_PROC_ADDRESS"
+#endif
+
+#define GR_GL_GET_PROC(PROC_NAME) \
+ glBindings->f##PROC_NAME = \
+ reinterpret_cast<GrGLInterface::GrGL##PROC_NAME##Proc>( \
+ GR_GL_PROC_ADDRESS(gl##PROC_NAME)); \
+ GrAssert(NULL != glBindings->f##PROC_NAME && \
+ "Missing GL binding: " #PROC_NAME);
+
+#define GR_GL_GET_PROC_SUFFIX(PROC_NAME, SUFFIX) \
+ glBindings->f##PROC_NAME = \
+ reinterpret_cast<GrGLInterface::GrGL##PROC_NAME##Proc>( \
+ GR_GL_PROC_ADDRESS(gl##PROC_NAME##SUFFIX)); \
+ GrAssert(NULL != glBindings->f##PROC_NAME && \
+ "Missing GL binding: " #PROC_NAME);
+
+#define GR_GL_GET_PROC_SYMBOL(PROC_NAME) \
+ glBindings->f##PROC_NAME = reinterpret_cast<GrGLInterface::GrGL##PROC_NAME##Proc>(gl##PROC_NAME);
+
+namespace {
+
+void gl_version_from_string(int* major, int* minor,
+ const char* versionString) {
+ if (NULL == versionString) {
+ GrAssert(0);
+ *major = 0;
+ *minor = 0;
+ return;
+ }
+#if GR_SUPPORT_GLDESKTOP
+ int n = sscanf(versionString, "%d.%d", major, minor);
+ if (n != 2) {
+ GrAssert(0);
+ *major = 0;
+ *minor = 0;
+ return;
+ }
+#else
+ char profile[2];
+ int n = sscanf(versionString, "OpenGL ES-%c%c %d.%d", profile, profile+1,
+ major, minor);
+ bool ok = 4 == n;
+ if (!ok) {
+ int n = sscanf(versionString, "OpenGL ES %d.%d", major, minor);
+ ok = 2 == n;
+ }
+ if (!ok) {
+ GrAssert(0);
+ *major = 0;
+ *minor = 0;
+ return;
+ }
+#endif
+}
+
+bool has_gl_extension_from_string(const char* ext,
+ const char* extensionString) {
+ int extLength = strlen(ext);
+
+ while (true) {
+ int n = strcspn(extensionString, " ");
+ if (n == extLength && 0 == strncmp(ext, extensionString, n)) {
+ return true;
+ }
+ if (0 == extensionString[n]) {
+ return false;
+ }
+ extensionString += n+1;
+ }
+
+ return false;
+}
+
+GrGLInterface* gGLInterface = NULL;
+
+void InitializeGLInterfaceExtensions(GrGLInterface* glBindings) {
+ int major, minor;
+ const char* versionString = reinterpret_cast<const char*>(
+ glBindings->fGetString(GL_VERSION));
+ const char* extensionString = reinterpret_cast<const char*>(
+ glBindings->fGetString(GL_EXTENSIONS));
+ gl_version_from_string(&major, &minor, versionString);
+
+ bool fboFound = false;
+#if GR_SUPPORT_GLDESKTOP
+ if (major >= 3 || has_gl_extension_from_string("GL_ARB_framebuffer_object",
+ extensionString)) {
+ // GL_ARB_framebuffer_object doesn't use ARB suffix.
+ GR_GL_GET_PROC(GenFramebuffers);
+ GR_GL_GET_PROC(BindFramebuffer);
+ GR_GL_GET_PROC(FramebufferTexture2D);
+ GR_GL_GET_PROC(CheckFramebufferStatus);
+ GR_GL_GET_PROC(DeleteFramebuffers);
+ GR_GL_GET_PROC(RenderbufferStorage);
+ GR_GL_GET_PROC(GenRenderbuffers);
+ GR_GL_GET_PROC(DeleteRenderbuffers);
+ GR_GL_GET_PROC(FramebufferRenderbuffer);
+ GR_GL_GET_PROC(BindRenderbuffer);
+ GR_GL_GET_PROC(RenderbufferStorageMultisample);
+ GR_GL_GET_PROC(BlitFramebuffer);
+ fboFound = true;
+ }
+
+ #if GL_EXT_framebuffer_object && !GR_MAC_BUILD
+ if (!fboFound &&
+ has_gl_extension_from_string("GL_EXT_framebuffer_object",
+ extensionString)) {
+ GR_GL_GET_PROC_SUFFIX(GenFramebuffers, EXT);
+ GR_GL_GET_PROC_SUFFIX(BindFramebuffer, EXT);
+ GR_GL_GET_PROC_SUFFIX(FramebufferTexture2D, EXT);
+ GR_GL_GET_PROC_SUFFIX(CheckFramebufferStatus, EXT);
+ GR_GL_GET_PROC_SUFFIX(DeleteFramebuffers, EXT);
+ GR_GL_GET_PROC_SUFFIX(RenderbufferStorage, EXT);
+ GR_GL_GET_PROC_SUFFIX(GenRenderbuffers, EXT);
+ GR_GL_GET_PROC_SUFFIX(DeleteRenderbuffers, EXT);
+ GR_GL_GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT);
+ GR_GL_GET_PROC_SUFFIX(BindRenderbuffer, EXT);
+ fboFound = true;
+
+ if (has_gl_extension_from_string("GL_EXT_framebuffer_multisample",
+ extensionString)) {
+ GR_GL_GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT);
+ }
+ if (has_gl_extension_from_string("GL_EXT_framebuffer_blit",
+ extensionString)) {
+ GR_GL_GET_PROC_SUFFIX(BlitFramebuffer, EXT);
+ }
+ }
+ #endif
+
+ // we assume we have at least GL 1.5 or higher (VBOs introduced in 1.5)
+ GrAssert((major == 1 && minor >= 5) || major >=2);
+ GR_GL_GET_PROC(MapBuffer);
+ GR_GL_GET_PROC(UnmapBuffer);
+#else // !GR_SUPPORT_GLDESKTOP
+ #if GR_SUPPORT_GLES2
+ if (!fboFound && major >= 2) {// ES 2.0 supports FBO
+ GR_GL_GET_PROC(GenFramebuffers);
+ GR_GL_GET_PROC(BindFramebuffer);
+ GR_GL_GET_PROC(FramebufferTexture2D);
+ GR_GL_GET_PROC(CheckFramebufferStatus);
+ GR_GL_GET_PROC(DeleteFramebuffers);
+ GR_GL_GET_PROC(RenderbufferStorage);
+ GR_GL_GET_PROC(GenRenderbuffers);
+ GR_GL_GET_PROC(DeleteRenderbuffers);
+ GR_GL_GET_PROC(FramebufferRenderbuffer);
+ GR_GL_GET_PROC(BindRenderbuffer);
+ fboFound = true;
+ }
+ #endif
+
+ #if GL_OES_mapbuffer
+ if (!fboFound &&
+ has_gl_extension_from_string("GL_OES_framebuffer_object",
+ extensionString)) {
+ GR_GL_GET_PROC_SUFFIX(GenFramebuffers, OES);
+ GR_GL_GET_PROC_SUFFIX(BindFramebuffer, OES);
+ GR_GL_GET_PROC_SUFFIX(FramebufferTexture2D, OES);
+ GR_GL_GET_PROC_SUFFIX(CheckFramebufferStatus, OES);
+ GR_GL_GET_PROC_SUFFIX(DeleteFramebuffers, OES);
+ GR_GL_GET_PROC_SUFFIX(RenderbufferStorage, OES);
+ GR_GL_GET_PROC_SUFFIX(GenRenderbuffers, OES);
+ GR_GL_GET_PROC_SUFFIX(DeleteRenderbuffers, OES);
+ GR_GL_GET_PROC_SUFFIX(FramebufferRenderbuffer, OES);
+ GR_GL_GET_PROC_SUFFIX(BindRenderbuffer, OES);
+ fboFound = true;
+ }
+ #endif
+
+ #if GL_APPLE_framebuffer_multisample
+ if (has_gl_extension_from_string("GL_APPLE_framebuffer_multisample",
+ extensionString)) {
+ GR_GL_GET_PROC_SUFFIX(ResolveMultisampleFramebuffer, APPLE);
+ }
+ #endif
+
+ #if GL_IMG_multisampled_render_to_texture
+ if (has_gl_extension_from_string(
+ "GL_IMG_multisampled_render_to_texture", extensionString)) {
+ GR_GL_GET_PROC_SUFFIX(FramebufferTexture2DMultisample, IMG);
+ }
+ #endif
+
+ #if GL_OES_mapbuffer
+ if (has_gl_extension_from_string("GL_OES_mapbuffer", extensionString)) {
+ GR_GL_GET_PROC_SUFFIX(MapBuffer, OES);
+ GR_GL_GET_PROC_SUFFIX(UnmapBuffer, OES);
+ }
+ #endif
+#endif // !GR_SUPPORT_GLDESKTOP
+
+ if (!fboFound) {
+ // we require some form of FBO
+ GrAssert(!"No FBOs supported?");
+ }
+}
+
+void GrGLInitializeGLInterface(GrGLInterface* glBindings) {
+ Gr_bzero(glBindings, sizeof(GrGLInterface));
+
+#if GR_SUPPORT_GLDESKTOP
+ // These entry points only exist on desktop GL implementations.
+ GR_GL_GET_PROC_SYMBOL(Color4ub);
+ GR_GL_GET_PROC_SYMBOL(ColorPointer);
+ GR_GL_GET_PROC_SYMBOL(DisableClientState);
+ GR_GL_GET_PROC_SYMBOL(EnableClientState);
+ GR_GL_GET_PROC_SYMBOL(LoadMatrixf);
+ GR_GL_GET_PROC_SYMBOL(MatrixMode);
+ GR_GL_GET_PROC_SYMBOL(PointSize);
+ GR_GL_GET_PROC_SYMBOL(ShadeModel);
+ GR_GL_GET_PROC_SYMBOL(TexCoordPointer);
+ GR_GL_GET_PROC_SYMBOL(TexEnvi);
+ GR_GL_GET_PROC_SYMBOL(VertexPointer);
+ GR_GL_GET_PROC(ClientActiveTexture);
+#endif
+
+ // The following gl entry points are part of GL 1.1, and will always be
+ // exported as symbols.
+ // Note that on windows, the wglGetProcAddress call will fail to retrieve
+ // these entry points.
+ GR_GL_GET_PROC_SYMBOL(BlendFunc);
+ GR_GL_GET_PROC_SYMBOL(Clear);
+ GR_GL_GET_PROC_SYMBOL(ClearColor);
+ GR_GL_GET_PROC_SYMBOL(ClearStencil);
+ GR_GL_GET_PROC_SYMBOL(ColorMask);
+ GR_GL_GET_PROC_SYMBOL(CullFace);
+ GR_GL_GET_PROC_SYMBOL(DeleteTextures);
+ GR_GL_GET_PROC_SYMBOL(DepthMask);
+ GR_GL_GET_PROC_SYMBOL(Disable);
+ GR_GL_GET_PROC_SYMBOL(DrawArrays);
+ GR_GL_GET_PROC_SYMBOL(DrawElements);
+ GR_GL_GET_PROC_SYMBOL(Enable);
+ GR_GL_GET_PROC_SYMBOL(FrontFace);
+ GR_GL_GET_PROC_SYMBOL(GenTextures);
+ GR_GL_GET_PROC_SYMBOL(GetError);
+ GR_GL_GET_PROC_SYMBOL(GetIntegerv);
+ GR_GL_GET_PROC_SYMBOL(GetString);
+ GR_GL_GET_PROC_SYMBOL(LineWidth);
+ GR_GL_GET_PROC_SYMBOL(PixelStorei);
+ GR_GL_GET_PROC_SYMBOL(ReadPixels);
+ GR_GL_GET_PROC_SYMBOL(Scissor);
+ GR_GL_GET_PROC_SYMBOL(StencilFunc);
+ GR_GL_GET_PROC_SYMBOL(StencilMask);
+ GR_GL_GET_PROC_SYMBOL(StencilOp);
+ GR_GL_GET_PROC_SYMBOL(TexImage2D);
+ GR_GL_GET_PROC_SYMBOL(TexParameteri);
+ GR_GL_GET_PROC_SYMBOL(TexSubImage2D);
+ GR_GL_GET_PROC_SYMBOL(Viewport);
+
+ // Capture the remaining entry points as gl extensions.
+ GR_GL_GET_PROC(ActiveTexture);
+ GR_GL_GET_PROC(AttachShader);
+ GR_GL_GET_PROC(BindAttribLocation);
+ GR_GL_GET_PROC(BindBuffer);
+ GR_GL_GET_PROC(BindTexture);
+ GR_GL_GET_PROC(BufferData);
+ GR_GL_GET_PROC(BufferSubData);
+ GR_GL_GET_PROC(CompileShader);
+ GR_GL_GET_PROC(CompressedTexImage2D);
+ GR_GL_GET_PROC(CreateProgram);
+ GR_GL_GET_PROC(CreateShader);
+ GR_GL_GET_PROC(DeleteBuffers);
+ GR_GL_GET_PROC(DeleteProgram);
+ GR_GL_GET_PROC(DeleteShader);
+ GR_GL_GET_PROC(DisableVertexAttribArray);
+ GR_GL_GET_PROC(EnableVertexAttribArray);
+ GR_GL_GET_PROC(GenBuffers);
+ GR_GL_GET_PROC(GetBufferParameteriv);
+ GR_GL_GET_PROC(GetProgramInfoLog);
+ GR_GL_GET_PROC(GetProgramiv);
+ GR_GL_GET_PROC(GetShaderInfoLog);
+ GR_GL_GET_PROC(GetShaderiv);
+ GR_GL_GET_PROC(GetUniformLocation);
+ GR_GL_GET_PROC(LinkProgram);
+ GR_GL_GET_PROC(ShaderSource);
+ GR_GL_GET_PROC(StencilFuncSeparate);
+ GR_GL_GET_PROC(StencilMaskSeparate);
+ GR_GL_GET_PROC(StencilOpSeparate);
+ GR_GL_GET_PROC(Uniform1fv);
+ GR_GL_GET_PROC(Uniform1i);
+ GR_GL_GET_PROC(Uniform4fv);
+ GR_GL_GET_PROC(UniformMatrix3fv);
+ GR_GL_GET_PROC(UseProgram);
+ GR_GL_GET_PROC(VertexAttrib4fv);
+ GR_GL_GET_PROC(VertexAttribPointer);
+
+ InitializeGLInterfaceExtensions(glBindings);
+}
+
+} // unnamed namespace
+
+void GrGLSetGLInterface(GrGLInterface* gl_interface) {
+ gGLInterface = gl_interface;
+}
+
+GrGLInterface* GrGLGetGLInterface() {
+ return gGLInterface;
+}
+
+void GrGLSetDefaultGLInterface() {
+ static GrGLInterface gDefaultInterface;
+ static bool gDefaultInitialized = false;
+ GrAssert(!gDefaultInitialized);
+
+ if (!gDefaultInitialized) {
+ GrGLInitializeGLInterface(&gDefaultInterface);
+ GrGLSetGLInterface(&gDefaultInterface);
+ }
+}
+
+bool has_gl_extension(const char* ext) {
+ const char* glstr = reinterpret_cast<const char*>(
+ GrGLGetGLInterface()->fGetString(GL_EXTENSIONS));
+
+ return has_gl_extension_from_string(ext, glstr);
+}
+
+void gl_version(int* major, int* minor) {
+ const char* v = reinterpret_cast<const char*>(
+ GrGLGetGLInterface()->fGetString(GL_VERSION));
+ gl_version_from_string(major, minor, v);
+}
diff --git a/gpu/src/GrGLTexture.cpp b/gpu/src/GrGLTexture.cpp
index 1acb871c79..7488d0f140 100644
--- a/gpu/src/GrGLTexture.cpp
+++ b/gpu/src/GrGLTexture.cpp
@@ -43,16 +43,16 @@ GrGLRenderTarget::~GrGLRenderTarget() {
fGL->notifyRenderTargetDelete(this);
if (fOwnIDs) {
if (fTexFBOID) {
- GR_GLEXT(fGL->extensions(), DeleteFramebuffers(1, &fTexFBOID));
+ GR_GL(DeleteFramebuffers(1, &fTexFBOID));
}
if (fRTFBOID && fRTFBOID != fTexFBOID) {
- GR_GLEXT(fGL->extensions(), DeleteFramebuffers(1, &fRTFBOID));
+ GR_GL(DeleteFramebuffers(1, &fRTFBOID));
}
if (fStencilRenderbufferID) {
- GR_GLEXT(fGL->extensions(), DeleteRenderbuffers(1, &fStencilRenderbufferID));
+ GR_GL(DeleteRenderbuffers(1, &fStencilRenderbufferID));
}
if (fMSColorRenderbufferID) {
- GR_GLEXT(fGL->extensions(), DeleteRenderbuffers(1, &fMSColorRenderbufferID));
+ GR_GL(DeleteRenderbuffers(1, &fMSColorRenderbufferID));
}
}
GrSafeUnref(fTexIDObj);
diff --git a/gpu/src/GrGLUtil.cpp b/gpu/src/GrGLUtil.cpp
index e128d353f0..2cb887a363 100644
--- a/gpu/src/GrGLUtil.cpp
+++ b/gpu/src/GrGLUtil.cpp
@@ -1,5 +1,5 @@
/*
- Copyright 2010 Google Inc.
+ Copyright 2011 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -15,227 +15,9 @@
*/
#include "GrGLConfig.h"
-#include "GrTypes.h"
-#include <stdio.h>
-
-bool has_gl_extension(const char* ext) {
- const char* glstr = (const char*) glGetString(GL_EXTENSIONS);
-
- int extLength = strlen(ext);
-
- while (true) {
- int n = strcspn(glstr, " ");
- if (n == extLength && 0 == strncmp(ext, glstr, n)) {
- return true;
- }
- if (0 == glstr[n]) {
- return false;
- }
- glstr += n+1;
- }
-}
-
-void gl_version(int* major, int* minor) {
- const char* v = (const char*) glGetString(GL_VERSION);
- if (NULL == v) {
- GrAssert(0);
- *major = 0;
- *minor = 0;
- return;
- }
-#if GR_SUPPORT_GLDESKTOP
- int n = sscanf(v, "%d.%d", major, minor);
- if (n != 2) {
- GrAssert(0);
- *major = 0;
- *minor = 0;
- return;
- }
-#else
- char profile[2];
- int n = sscanf(v, "OpenGL ES-%c%c %d.%d", profile, profile+1, major, minor);
- bool ok = 4 == n;
- if (!ok) {
- int n = sscanf(v, "OpenGL ES %d.%d", major, minor);
- ok = 2 == n;
- }
- if (!ok) {
- GrAssert(0);
- *major = 0;
- *minor = 0;
- return;
- }
-#endif
-}
-
-#if defined(GR_GL_PROC_ADDRESS_HEADER)
- #include GR_GL_PROC_ADDRESS_HEADER
-#endif
-
-typedef void (*glProc)(void);
-
-#define GET_PROC(EXT_STRUCT, PROC_NAME) \
- *(GrTCast<glProc*>(&(EXT_STRUCT-> PROC_NAME))) = (glProc)GR_GL_PROC_ADDRESS((gl ## PROC_NAME)); \
- GrAssert(NULL != EXT_STRUCT-> PROC_NAME)
-
-#define GET_SUFFIX_PROC(EXT_STRUCT, PROC_NAME, SUFFIX) \
- *(GrTCast<glProc*>(&(EXT_STRUCT-> PROC_NAME))) = (glProc)GR_GL_PROC_ADDRESS((gl ## PROC_NAME ## SUFFIX)); \
- GrAssert(NULL != EXT_STRUCT-> PROC_NAME)
-
-extern void GrGLInitExtensions(GrGLExts* exts) {
- exts->GenFramebuffers = NULL;
- exts->BindFramebuffer = NULL;
- exts->FramebufferTexture2D = NULL;
- exts->CheckFramebufferStatus = NULL;
- exts->DeleteFramebuffers = NULL;
- exts->RenderbufferStorage = NULL;
- exts->GenRenderbuffers = NULL;
- exts->DeleteRenderbuffers = NULL;
- exts->FramebufferRenderbuffer = NULL;
- exts->BindRenderbuffer = NULL;
- exts->RenderbufferStorageMultisample = NULL;
- exts->BlitFramebuffer = NULL;
- exts->ResolveMultisampleFramebuffer = NULL;
- exts->FramebufferTexture2DMultisample = NULL;
- exts->MapBuffer = NULL;
- exts->UnmapBuffer = NULL;
-
- GLint major, minor;
- gl_version(&major, &minor);
-
- bool fboFound = false;
-#if GR_SUPPORT_GLDESKTOP
- #if defined(GL_VERSION_3_0) && GL_VERSION_3_0
- if (!fboFound && major >= 3) { // all of ARB_fbo is in 3.x
- exts->GenFramebuffers = glGenFramebuffers;
- exts->BindFramebuffer = glBindFramebuffer;
- exts->FramebufferTexture2D = glFramebufferTexture2D;
- exts->CheckFramebufferStatus = glCheckFramebufferStatus;
- exts->DeleteFramebuffers = glDeleteFramebuffers;
- exts->RenderbufferStorage = glRenderbufferStorage;
- exts->GenRenderbuffers = glGenRenderbuffers;
- exts->DeleteRenderbuffers = glDeleteRenderbuffers;
- exts->FramebufferRenderbuffer = glFramebufferRenderbuffer;
- exts->BindRenderbuffer = glBindRenderbuffer;
- exts->RenderbufferStorageMultisample = glRenderbufferStorageMultisample;
- exts->BlitFramebuffer = glBlitFramebuffer;
- fboFound = true;
- }
- #endif
- #if GL_ARB_framebuffer_object
- if (!fboFound && has_gl_extension("GL_ARB_framebuffer_object")) {
- // GL_ARB_framebuffer_object doesn't use ARB suffix.
- GET_PROC(exts, GenFramebuffers);
- GET_PROC(exts, BindFramebuffer);
- GET_PROC(exts, FramebufferTexture2D);
- GET_PROC(exts, CheckFramebufferStatus);
- GET_PROC(exts, DeleteFramebuffers);
- GET_PROC(exts, RenderbufferStorage);
- GET_PROC(exts, GenRenderbuffers);
- GET_PROC(exts, DeleteRenderbuffers);
- GET_PROC(exts, FramebufferRenderbuffer);
- GET_PROC(exts, BindRenderbuffer);
- GET_PROC(exts, RenderbufferStorageMultisample);
- GET_PROC(exts, BlitFramebuffer);
- fboFound = true;
- }
- #endif
- // Mac doesn't declare prototypes for EXT FBO extensions
- #if GL_EXT_framebuffer_object && !GR_MAC_BUILD
- if (!fboFound && has_gl_extension("GL_EXT_framebuffer_object")) {
- GET_SUFFIX_PROC(exts, GenFramebuffers, EXT);
- GET_SUFFIX_PROC(exts, BindFramebuffer, EXT);
- GET_SUFFIX_PROC(exts, FramebufferTexture2D, EXT);
- GET_SUFFIX_PROC(exts, CheckFramebufferStatus, EXT);
- GET_SUFFIX_PROC(exts, DeleteFramebuffers, EXT);
- GET_SUFFIX_PROC(exts, RenderbufferStorage, EXT);
- GET_SUFFIX_PROC(exts, GenRenderbuffers, EXT);
- GET_SUFFIX_PROC(exts, DeleteRenderbuffers, EXT);
- GET_SUFFIX_PROC(exts, FramebufferRenderbuffer, EXT);
- GET_SUFFIX_PROC(exts, BindRenderbuffer, EXT);
- fboFound = true;
- // check for fbo ms and fbo blit
- #if GL_EXT_framebuffer_multisample
- if (has_gl_extension("GL_EXT_framebuffer_multisample")) {
- GET_SUFFIX_PROC(exts, RenderbufferStorageMultisample, EXT);
- }
- #endif
- #if GL_EXT_framebuffer_blit
- if (has_gl_extension("GL_EXT_framebuffer_blit")) {
- GET_SUFFIX_PROC(exts, BlitFramebuffer, EXT);
- }
- #endif
- }
- #endif
- if (!fboFound) {
- // we require some form of FBO
- GrAssert(!"No FBOs supported?");
- }
- // we assume we have at least GL 1.5 or higher (VBOs introduced in 1.5)
- exts->MapBuffer = glMapBuffer;
- exts->UnmapBuffer = glUnmapBuffer;
-#else // !GR_SUPPORT_GLDESKTOP
- #if GR_SUPPORT_GLES2
- if (!fboFound && major >= 2) {// ES 2.0 supports FBO
- exts->GenFramebuffers = glGenFramebuffers;
- exts->BindFramebuffer = glBindFramebuffer;
- exts->FramebufferTexture2D = glFramebufferTexture2D;
- exts->CheckFramebufferStatus = glCheckFramebufferStatus;
- exts->DeleteFramebuffers = glDeleteFramebuffers;
- exts->RenderbufferStorage = glRenderbufferStorage;
- exts->GenRenderbuffers = glGenRenderbuffers;
- exts->DeleteRenderbuffers = glDeleteRenderbuffers;
- exts->FramebufferRenderbuffer = glFramebufferRenderbuffer;
- exts->BindRenderbuffer = glBindRenderbuffer;
- fboFound = true;
- }
- #endif
- #if GL_OES_framebuffer_object
- if (!fboFound && has_gl_extension("GL_OES_framebuffer_object")) {
- GET_SUFFIX_PROC(exts, GenFramebuffers, OES);
- GET_SUFFIX_PROC(exts, BindFramebuffer, OES);
- GET_SUFFIX_PROC(exts, FramebufferTexture2D, OES);
- GET_SUFFIX_PROC(exts, CheckFramebufferStatus, OES);
- GET_SUFFIX_PROC(exts, DeleteFramebuffers, OES);
- GET_SUFFIX_PROC(exts, RenderbufferStorage, OES);
- GET_SUFFIX_PROC(exts, GenRenderbuffers, OES);
- GET_SUFFIX_PROC(exts, DeleteRenderbuffers, OES);
- GET_SUFFIX_PROC(exts, FramebufferRenderbuffer, OES);
- GET_SUFFIX_PROC(exts, BindRenderbuffer, OES);
- }
- #endif
-
- if (!fboFound) {
- // we require some form of FBO
- GrAssert(!"No FBOs supported?");
- }
-
- #if GL_APPLE_framebuffer_multisample
- if (has_gl_extension("GL_APPLE_framebuffer_multisample")) {
- GET_SUFFIX_PROC(exts, ResolveMultisampleFramebuffer, APPLE);
- }
- #endif
-
- #if GL_IMG_multisampled_render_to_texture
- if (has_gl_extension("GL_IMG_multisampled_render_to_texture")) {
- GET_SUFFIX_PROC(exts, FramebufferTexture2DMultisample, IMG);
- }
- #endif
-
- #if GL_OES_mapbuffer
- if (has_gl_extension("GL_OES_mapbuffer")) {
- GET_SUFFIX_PROC(exts, MapBuffer, OES);
- GET_SUFFIX_PROC(exts, UnmapBuffer, OES);
- }
- #endif
-#endif // !GR_SUPPORT_GLDESKTOP
-}
-
-
-///////////////////////////////////////////////////////////////////////////////
void GrGLCheckErr(const char* location, const char* call) {
- uint32_t err = glGetError();
+ uint32_t err = GrGLGetGLInterface()->fGetError();
if (GL_NO_ERROR != err) {
GrPrintf("---- glGetError %x", err);
if (NULL != location) {
diff --git a/gpu/src/GrGLVertexBuffer.cpp b/gpu/src/GrGLVertexBuffer.cpp
index ec489367ed..69913bf3eb 100644
--- a/gpu/src/GrGLVertexBuffer.cpp
+++ b/gpu/src/GrGLVertexBuffer.cpp
@@ -1,5 +1,5 @@
/*
- Copyright 2010 Google Inc.
+ Copyright 2011 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -57,8 +57,7 @@ void* GrGLVertexBuffer::lock() {
// Let driver know it can discard the old data
GR_GL(BufferData(GL_ARRAY_BUFFER, size(), NULL,
dynamic() ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW));
- fLockPtr = GR_GLEXT(fGL->extensions(),
- MapBuffer(GL_ARRAY_BUFFER, GR_WRITE_ONLY));
+ fLockPtr = GR_GL(MapBuffer(GL_ARRAY_BUFFER, GR_WRITE_ONLY));
return fLockPtr;
}
return NULL;
@@ -74,7 +73,7 @@ void GrGLVertexBuffer::unlock() {
GrAssert(fGL->supportsBufferLocking());
bind();
- GR_GLEXT(fGL->extensions(), UnmapBuffer(GL_ARRAY_BUFFER));
+ GR_GL(UnmapBuffer(GL_ARRAY_BUFFER));
fLockPtr = NULL;
}
diff --git a/gpu/src/GrGpuFactory.cpp b/gpu/src/GrGpuFactory.cpp
index 2298776f48..7c2db2b0b1 100644
--- a/gpu/src/GrGpuFactory.cpp
+++ b/gpu/src/GrGpuFactory.cpp
@@ -1,5 +1,5 @@
/*
- Copyright 2010 Google Inc.
+ Copyright 2011 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -36,6 +36,11 @@
#include "GrGpu.h"
GrGpu* GrGpu::Create(Engine engine, Platform3DContext context3D) {
+ // If no GL bindings have been installed, fall-back to calling the
+ // GL functions that have been linked with the executable.
+ if (!GrGLGetGLInterface())
+ GrGLSetDefaultGLInterface();
+
GrGpu* gpu = NULL;
switch (engine) {
diff --git a/gpu/src/GrGpuGL.cpp b/gpu/src/GrGpuGL.cpp
index dc9b92ddf1..94e9bfd591 100644
--- a/gpu/src/GrGpuGL.cpp
+++ b/gpu/src/GrGpuGL.cpp
@@ -103,8 +103,7 @@ bool GrGpuGL::TextureMatrixIsIdentity(const GrGLTexture* texture,
static bool gPrintStartupSpew;
-
-static bool fbo_test(GrGLExts exts, int w, int h) {
+static bool fbo_test(int w, int h) {
GLint savedFBO;
GLint savedTexUnit;
@@ -114,8 +113,8 @@ static bool fbo_test(GrGLExts exts, int w, int h) {
GR_GL(ActiveTexture(GL_TEXTURE0 + SPARE_TEX_UNIT));
GLuint testFBO;
- GR_GLEXT(exts, GenFramebuffers(1, &testFBO));
- GR_GLEXT(exts, BindFramebuffer(GR_FRAMEBUFFER, testFBO));
+ GR_GL(GenFramebuffers(1, &testFBO));
+ GR_GL(BindFramebuffer(GR_FRAMEBUFFER, testFBO));
GLuint testRTTex;
GR_GL(GenTextures(1, &testRTTex));
GR_GL(BindTexture(GL_TEXTURE_2D, testRTTex));
@@ -125,14 +124,14 @@ static bool fbo_test(GrGLExts exts, int w, int h) {
GR_GL(TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h,
0, GL_RGBA, GL_UNSIGNED_BYTE, NULL));
GR_GL(BindTexture(GL_TEXTURE_2D, 0));
- GR_GLEXT(exts, FramebufferTexture2D(GR_FRAMEBUFFER, GR_COLOR_ATTACHMENT0,
- GL_TEXTURE_2D, testRTTex, 0));
- GLenum status = GR_GLEXT(exts, CheckFramebufferStatus(GR_FRAMEBUFFER));
- GR_GLEXT(exts, DeleteFramebuffers(1, &testFBO));
+ GR_GL(FramebufferTexture2D(GR_FRAMEBUFFER, GR_COLOR_ATTACHMENT0,
+ GL_TEXTURE_2D, testRTTex, 0));
+ GLenum status = GR_GL(CheckFramebufferStatus(GR_FRAMEBUFFER));
+ GR_GL(DeleteFramebuffers(1, &testFBO));
GR_GL(DeleteTextures(1, &testRTTex));
GR_GL(ActiveTexture(savedTexUnit));
- GR_GLEXT(exts, BindFramebuffer(GR_FRAMEBUFFER, savedFBO));
+ GR_GL(BindFramebuffer(GR_FRAMEBUFFER, savedFBO));
return status == GR_FRAMEBUFFER_COMPLETE;
}
@@ -142,16 +141,18 @@ GrGpuGL::GrGpuGL() {
if (gPrintStartupSpew) {
GrPrintf("------------------------- create GrGpuGL %p --------------\n",
this);
- GrPrintf("------ VENDOR %s\n", glGetString(GL_VENDOR));
- GrPrintf("------ RENDERER %s\n", glGetString(GL_RENDERER));
- GrPrintf("------ VERSION %s\n", glGetString(GL_VERSION));
- GrPrintf("------ EXTENSIONS\n %s \n", glGetString(GL_EXTENSIONS));
+ GrPrintf("------ VENDOR %s\n",
+ GrGLGetGLInterface()->fGetString(GL_VENDOR));
+ GrPrintf("------ RENDERER %s\n",
+ GrGLGetGLInterface()->fGetString(GL_RENDERER));
+ GrPrintf("------ VERSION %s\n",
+ GrGLGetGLInterface()->fGetString(GL_VERSION));
+ GrPrintf("------ EXTENSIONS\n %s \n",
+ GrGLGetGLInterface()->fGetString(GL_EXTENSIONS));
}
GrGLClearErr();
- GrGLInitExtensions(&fExts);
-
resetDirtyFlags();
GLint maxTextureUnits;
@@ -329,7 +330,7 @@ GrGpuGL::GrGpuGL() {
// sanity check to make sure we can at least create an FBO from a POT texture
- bool simpleFBOSuccess = fbo_test(fExts, 128, 128);
+ bool simpleFBOSuccess = fbo_test(128, 128);
if (gPrintStartupSpew) {
if (!simpleFBOSuccess) {
GrPrintf("FBO Sanity Test: FAILED\n");
@@ -348,7 +349,7 @@ GrGpuGL::GrGpuGL() {
*/
bool fNPOTRenderTargetSupport = false;
if (fNPOTTextureSupport) {
- fNPOTRenderTargetSupport = fbo_test(fExts, 200, 200);
+ fNPOTRenderTargetSupport = fbo_test(200, 200);
}
if (gPrintStartupSpew) {
@@ -384,7 +385,7 @@ GrGpuGL::GrGpuGL() {
for (GLuint i = 1; i <= 256; fNPOTRenderTargetSupport ? ++i : i *= 2) {
GLuint w = maxRenderSize;
GLuint h = i;
- if (fbo_test(fExts, w, h)) {
+ if (fbo_test(w, h)) {
if (gPrintStartupSpew) {
GrPrintf("\t[%d, %d]: PASSED\n", w, h);
}
@@ -405,7 +406,7 @@ GrGpuGL::GrGpuGL() {
for (GLuint i = 1; i <= 256; fNPOTRenderTargetSupport ? i *= 2 : ++i) {
GLuint w = i;
GLuint h = maxRenderSize;
- if (fbo_test(fExts, w, h)) {
+ if (fbo_test(w, h)) {
if (gPrintStartupSpew) {
GrPrintf("\t[%d, %d]: PASSED\n", w, h);
}
@@ -777,7 +778,7 @@ GrTexture* GrGpuGL::createTextureHelper(const TextureDesc& desc,
GrAssert(NULL == srcData);
glDesc.fOrientation = GrGLTexture::kBottomUp_Orientation;
- GR_GLEXT(fExts, GenFramebuffers(1, &rtIDs.fTexFBOID));
+ GR_GL(GenFramebuffers(1, &rtIDs.fTexFBOID));
GrAssert(rtIDs.fTexFBOID);
// If we are using multisampling and any extension other than the IMG
@@ -785,16 +786,15 @@ GrTexture* GrGpuGL::createTextureHelper(const TextureDesc& desc,
// the texture bound to the other. The IMG extension does an implicit
// resolve.
if (samples > 1 && kIMG_MSFBO != fMSFBOType && kNone_MSFBO != fMSFBOType) {
- GR_GLEXT(fExts, GenFramebuffers(1, &rtIDs.fRTFBOID));
+ GR_GL(GenFramebuffers(1, &rtIDs.fRTFBOID));
GrAssert(0 != rtIDs.fRTFBOID);
- GR_GLEXT(fExts, GenRenderbuffers(1, &rtIDs.fMSColorRenderbufferID));
+ GR_GL(GenRenderbuffers(1, &rtIDs.fMSColorRenderbufferID));
GrAssert(0 != rtIDs.fMSColorRenderbufferID);
if (!fboInternalFormat(desc.fFormat, &msColorRenderbufferFormat)) {
- GR_GLEXT(fExts,
- DeleteRenderbuffers(1, &rtIDs.fMSColorRenderbufferID));
+ GR_GL(DeleteRenderbuffers(1, &rtIDs.fMSColorRenderbufferID));
GR_GL(DeleteTextures(1, &glDesc.fTextureID));
- GR_GLEXT(fExts, DeleteFramebuffers(1, &rtIDs.fTexFBOID));
- GR_GLEXT(fExts, DeleteFramebuffers(1, &rtIDs.fRTFBOID));
+ GR_GL(DeleteFramebuffers(1, &rtIDs.fTexFBOID));
+ GR_GL(DeleteFramebuffers(1, &rtIDs.fRTFBOID));
return return_null_texture();
}
} else {
@@ -802,7 +802,7 @@ GrTexture* GrGpuGL::createTextureHelper(const TextureDesc& desc,
}
int attempts = 1;
if (!(kNoPathRendering_TextureFlag & desc.fFlags)) {
- GR_GLEXT(fExts, GenRenderbuffers(1, &rtIDs.fStencilRenderbufferID));
+ GR_GL(GenRenderbuffers(1, &rtIDs.fStencilRenderbufferID));
GrAssert(0 != rtIDs.fStencilRenderbufferID);
attempts = GR_ARRAY_COUNT(gStencilFormats);
}
@@ -815,21 +815,20 @@ GrTexture* GrGpuGL::createTextureHelper(const TextureDesc& desc,
err = ~GL_NO_ERROR;
for (int i = 0; i < attempts; ++i) {
if (rtIDs.fStencilRenderbufferID) {
- GR_GLEXT(fExts, BindRenderbuffer(GR_RENDERBUFFER,
- rtIDs.fStencilRenderbufferID));
+ GR_GL(BindRenderbuffer(GR_RENDERBUFFER,
+ rtIDs.fStencilRenderbufferID));
if (samples > 1) {
- GR_GLEXT_NO_ERR(fExts, RenderbufferStorageMultisample(
+ GR_GL_NO_ERR(RenderbufferStorageMultisample(
GR_RENDERBUFFER,
samples,
gStencilFormats[i].fEnum,
glDesc.fAllocWidth,
glDesc.fAllocHeight));
} else {
- GR_GLEXT_NO_ERR(fExts, RenderbufferStorage(
- GR_RENDERBUFFER,
- gStencilFormats[i].fEnum,
- glDesc.fAllocWidth,
- glDesc.fAllocHeight));
+ GR_GL_NO_ERR(RenderbufferStorage(GR_RENDERBUFFER,
+ gStencilFormats[i].fEnum,
+ glDesc.fAllocWidth,
+ glDesc.fAllocHeight));
}
err = glGetError();
if (err != GL_NO_ERROR) {
@@ -838,9 +837,9 @@ GrTexture* GrGpuGL::createTextureHelper(const TextureDesc& desc,
}
if (rtIDs.fRTFBOID != rtIDs.fTexFBOID) {
GrAssert(samples > 1);
- GR_GLEXT(fExts, BindRenderbuffer(GR_RENDERBUFFER,
- rtIDs.fMSColorRenderbufferID));
- GR_GLEXT_NO_ERR(fExts, RenderbufferStorageMultisample(
+ GR_GL(BindRenderbuffer(GR_RENDERBUFFER,
+ rtIDs.fMSColorRenderbufferID));
+ GR_GL_NO_ERR(RenderbufferStorageMultisample(
GR_RENDERBUFFER,
samples,
msColorRenderbufferFormat,
@@ -851,52 +850,50 @@ GrTexture* GrGpuGL::createTextureHelper(const TextureDesc& desc,
continue;
}
}
- GR_GLEXT(fExts, BindFramebuffer(GR_FRAMEBUFFER, rtIDs.fTexFBOID));
+ GR_GL(BindFramebuffer(GR_FRAMEBUFFER, rtIDs.fTexFBOID));
#if GR_COLLECT_STATS
++fStats.fRenderTargetChngCnt;
#endif
if (kIMG_MSFBO == fMSFBOType && samples > 1) {
- GR_GLEXT(fExts, FramebufferTexture2DMultisample(
- GR_FRAMEBUFFER,
- GR_COLOR_ATTACHMENT0,
- GL_TEXTURE_2D,
- glDesc.fTextureID,
- 0,
- samples));
+ GR_GL(FramebufferTexture2DMultisample(GR_FRAMEBUFFER,
+ GR_COLOR_ATTACHMENT0,
+ GL_TEXTURE_2D,
+ glDesc.fTextureID,
+ 0,
+ samples));
} else {
- GR_GLEXT(fExts, FramebufferTexture2D(GR_FRAMEBUFFER,
- GR_COLOR_ATTACHMENT0,
- GL_TEXTURE_2D,
- glDesc.fTextureID, 0));
+ GR_GL(FramebufferTexture2D(GR_FRAMEBUFFER,
+ GR_COLOR_ATTACHMENT0,
+ GL_TEXTURE_2D,
+ glDesc.fTextureID, 0));
}
if (rtIDs.fRTFBOID != rtIDs.fTexFBOID) {
- GLenum status = GR_GLEXT(fExts,
- CheckFramebufferStatus(GR_FRAMEBUFFER));
+ GLenum status = GR_GL(CheckFramebufferStatus(GR_FRAMEBUFFER));
if (status != GR_FRAMEBUFFER_COMPLETE) {
GrPrintf("-- glCheckFramebufferStatus %x %d %d\n",
status, desc.fWidth, desc.fHeight);
continue;
}
- GR_GLEXT(fExts, BindFramebuffer(GR_FRAMEBUFFER, rtIDs.fRTFBOID));
+ GR_GL(BindFramebuffer(GR_FRAMEBUFFER, rtIDs.fRTFBOID));
#if GR_COLLECT_STATS
++fStats.fRenderTargetChngCnt;
#endif
- GR_GLEXT(fExts, FramebufferRenderbuffer(GR_FRAMEBUFFER,
- GR_COLOR_ATTACHMENT0,
- GR_RENDERBUFFER,
- rtIDs.fMSColorRenderbufferID));
+ GR_GL(FramebufferRenderbuffer(GR_FRAMEBUFFER,
+ GR_COLOR_ATTACHMENT0,
+ GR_RENDERBUFFER,
+ rtIDs.fMSColorRenderbufferID));
}
if (rtIDs.fStencilRenderbufferID) {
// bind the stencil to rt fbo if present, othewise the tex fbo
- GR_GLEXT(fExts, FramebufferRenderbuffer(GR_FRAMEBUFFER,
- GR_STENCIL_ATTACHMENT,
- GR_RENDERBUFFER,
- rtIDs.fStencilRenderbufferID));
+ GR_GL(FramebufferRenderbuffer(GR_FRAMEBUFFER,
+ GR_STENCIL_ATTACHMENT,
+ GR_RENDERBUFFER,
+ rtIDs.fStencilRenderbufferID));
}
- status = GR_GLEXT(fExts, CheckFramebufferStatus(GR_FRAMEBUFFER));
+ status = GR_GL(CheckFramebufferStatus(GR_FRAMEBUFFER));
#if GR_SUPPORT_GLDESKTOP
// On some implementations you have to be bound as DEPTH_STENCIL.
@@ -904,16 +901,15 @@ GrTexture* GrGpuGL::createTextureHelper(const TextureDesc& desc,
// buffer doesn't work.)
if (rtIDs.fStencilRenderbufferID &&
status != GR_FRAMEBUFFER_COMPLETE) {
- GR_GLEXT(fExts, FramebufferRenderbuffer(GR_FRAMEBUFFER,
- GR_STENCIL_ATTACHMENT,
- GR_RENDERBUFFER,
- 0));
- GR_GLEXT(fExts,
- FramebufferRenderbuffer(GR_FRAMEBUFFER,
- GR_DEPTH_STENCIL_ATTACHMENT,
- GR_RENDERBUFFER,
- rtIDs.fStencilRenderbufferID));
- status = GR_GLEXT(fExts, CheckFramebufferStatus(GR_FRAMEBUFFER));
+ GR_GL(FramebufferRenderbuffer(GR_FRAMEBUFFER,
+ GR_STENCIL_ATTACHMENT,
+ GR_RENDERBUFFER,
+ 0));
+ GR_GL(FramebufferRenderbuffer(GR_FRAMEBUFFER,
+ GR_DEPTH_STENCIL_ATTACHMENT,
+ GR_RENDERBUFFER,
+ rtIDs.fStencilRenderbufferID));
+ status = GR_GL(CheckFramebufferStatus(GR_FRAMEBUFFER));
}
#endif
if (status != GR_FRAMEBUFFER_COMPLETE) {
@@ -921,10 +917,10 @@ GrTexture* GrGpuGL::createTextureHelper(const TextureDesc& desc,
status, desc.fWidth, desc.fHeight);
#if GR_SUPPORT_GLDESKTOP
if (rtIDs.fStencilRenderbufferID) {
- GR_GLEXT(fExts, FramebufferRenderbuffer(GR_FRAMEBUFFER,
- GR_DEPTH_STENCIL_ATTACHMENT,
- GR_RENDERBUFFER,
- 0));
+ GR_GL(FramebufferRenderbuffer(GR_FRAMEBUFFER,
+ GR_DEPTH_STENCIL_ATTACHMENT,
+ GR_RENDERBUFFER,
+ 0));
}
#endif
continue;
@@ -942,18 +938,16 @@ GrTexture* GrGpuGL::createTextureHelper(const TextureDesc& desc,
}
if (failed) {
if (rtIDs.fStencilRenderbufferID) {
- GR_GLEXT(fExts,
- DeleteRenderbuffers(1, &rtIDs.fStencilRenderbufferID));
+ GR_GL(DeleteRenderbuffers(1, &rtIDs.fStencilRenderbufferID));
}
if (rtIDs.fMSColorRenderbufferID) {
- GR_GLEXT(fExts,
- DeleteRenderbuffers(1, &rtIDs.fMSColorRenderbufferID));
+ GR_GL(DeleteRenderbuffers(1, &rtIDs.fMSColorRenderbufferID));
}
if (rtIDs.fRTFBOID != rtIDs.fTexFBOID) {
- GR_GLEXT(fExts, DeleteFramebuffers(1, &rtIDs.fRTFBOID));
+ GR_GL(DeleteFramebuffers(1, &rtIDs.fRTFBOID));
}
if (rtIDs.fTexFBOID) {
- GR_GLEXT(fExts, DeleteFramebuffers(1, &rtIDs.fTexFBOID));
+ GR_GL(DeleteFramebuffers(1, &rtIDs.fTexFBOID));
}
GR_GL(DeleteTextures(1, &glDesc.fTextureID));
return return_null_texture();
@@ -1169,13 +1163,13 @@ void GrGpuGL::flushRenderTarget() {
if (fHWDrawState.fRenderTarget != fCurrDrawState.fRenderTarget) {
GrGLRenderTarget* rt = (GrGLRenderTarget*)fCurrDrawState.fRenderTarget;
- GR_GLEXT(fExts, BindFramebuffer(GR_FRAMEBUFFER, rt->renderFBOID()));
+ GR_GL(BindFramebuffer(GR_FRAMEBUFFER, rt->renderFBOID()));
#if GR_COLLECT_STATS
++fStats.fRenderTargetChngCnt;
#endif
rt->setDirty(true);
#if GR_DEBUG
- GLenum status = GR_GLEXT(fExts, CheckFramebufferStatus(GR_FRAMEBUFFER));
+ GLenum status = GR_GL(CheckFramebufferStatus(GR_FRAMEBUFFER));
if (status != GR_FRAMEBUFFER_COMPLETE) {
GrPrintf("-- glCheckFramebufferStatus %x\n", status);
}
@@ -1287,9 +1281,9 @@ void GrGpuGL::resolveTextureRenderTarget(GrGLTexture* texture) {
if (NULL != rt && rt->needsResolve()) {
GrAssert(kNone_MSFBO != fMSFBOType);
GrAssert(rt->textureFBOID() != rt->renderFBOID());
- GR_GLEXT(fExts, BindFramebuffer(GR_READ_FRAMEBUFFER,
+ GR_GL(BindFramebuffer(GR_READ_FRAMEBUFFER,
rt->renderFBOID()));
- GR_GLEXT(fExts, BindFramebuffer(GR_DRAW_FRAMEBUFFER,
+ GR_GL(BindFramebuffer(GR_DRAW_FRAMEBUFFER,
rt->textureFBOID()));
#if GR_COLLECT_STATS
++fStats.fRenderTargetChngCnt;
@@ -1305,11 +1299,11 @@ void GrGpuGL::resolveTextureRenderTarget(GrGLTexture* texture) {
if (kApple_MSFBO == fMSFBOType) {
GR_GL(Enable(GL_SCISSOR_TEST));
GR_GL(Scissor(left, bottom, right-left, top-bottom));
- GR_GLEXT(fExts, ResolveMultisampleFramebuffer());
+ GR_GL(ResolveMultisampleFramebuffer());
fHWBounds.fScissorRect.invalidate();
fHWBounds.fScissorEnabled = true;
} else {
- GR_GLEXT(fExts, BlitFramebuffer(left, bottom, right, top,
+ GR_GL(BlitFramebuffer(left, bottom, right, top,
left, bottom, right, top,
GL_COLOR_BUFFER_BIT, GL_NEAREST));
}
diff --git a/gpu/src/GrGpuGL.h b/gpu/src/GrGpuGL.h
index f9a6987772..a731226cc3 100644
--- a/gpu/src/GrGpuGL.h
+++ b/gpu/src/GrGpuGL.h
@@ -31,14 +31,6 @@ public:
GrGpuGL();
virtual ~GrGpuGL();
- /**
- * Gets the struct containing the GL extensions for the context
- * underlying the GrGpuGL
- *
- * @param struct containing extension function pointers
- */
- const GrGLExts& extensions() { return fExts; }
-
protected:
struct {
size_t fVertexOffset;
@@ -72,8 +64,6 @@ protected:
GrGLIRect fViewportRect;
} fHWBounds;
- GrGLExts fExts;
-
// GrGpu overrides
// overrides from GrGpu
virtual void resetContext();
diff --git a/gpu/src/gr_files.mk b/gpu/src/gr_files.mk
index d0f41e748f..8aeddc9d8d 100644
--- a/gpu/src/gr_files.mk
+++ b/gpu/src/gr_files.mk
@@ -5,6 +5,7 @@ SOURCE := \
GrContext.cpp \
GrDrawTarget.cpp \
GrGLIndexBuffer.cpp \
+ GrGLInterface.cpp \
GrGLTexture.cpp \
GrGLVertexBuffer.cpp \
GrGpu.cpp \