reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2010 Google Inc. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | |
| 18 | #ifndef GrGLConfig_DEFINED |
| 19 | #define GrGLConfig_DEFINED |
| 20 | |
| 21 | #include "GrTypes.h" |
| 22 | |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 23 | #if !defined(GR_GL_CUSTOM_SETUP) |
| 24 | #define GR_GL_CUSTOM_SETUP 0 |
| 25 | #endif |
| 26 | /** |
| 27 | * We need to pull in the right GL headers and determine whether we are |
| 28 | * compiling for ES1, ES2, or desktop GL. (We allow ES1 and ES2 to both be |
| 29 | * supported in the same build but not ESx and desktop). We also need to know |
| 30 | * the platform-specific way to get extension function pointers (e.g. |
| 31 | * eglGetProcAddress). The port specifies this info explicitly or we will infer |
| 32 | * it from the GR_*_BUILD flag. |
| 33 | * |
| 34 | * To specify GL setup directly define GR_GL_CUSTOM_SETUP to 1 and define: |
| 35 | * GR_SUPPORT_GLDESKTOP or (GR_SUPPORT_GLES1 and/or GR_SUPPORT_GLES2) to 1 |
| 36 | * |
| 37 | * if GR_SUPPORT_GLDESKTOP is 1 then provide: |
| 38 | * 1. The name of your GL header in GR_INCLUDE_GLDESKTOP |
| 39 | * 2. If necessary, the name of a file that includes extension |
| 40 | * definitions in GR_INCLUDE_GLDESKTOPext. |
| 41 | * if GR_SUPPORT_GLES1 is 1 then provide: |
| 42 | * 1. The name of your GL header in GR_INCLUDE_GLES1 |
| 43 | * 2. If necessary, the name of a file that includes extension |
| 44 | * definitions in GR_INCLUDE_GLES1ext. |
| 45 | * if GR_SUPPORT_GLES2 is 1 then provide: |
| 46 | * 1. The name of your GL header in GR_INCLUDE_GLES2 |
| 47 | * 2. If necessary, the name of a file that includes extension |
| 48 | * definitions in GR_INCLUDE_GLES2ext. |
| 49 | * |
| 50 | * Optionally, define GR_GL_FUNC to any qualifier needed on GL function |
| 51 | * pointer declarations (e.g. __stdcall). |
| 52 | * |
| 53 | * Define GR_GL_PROC_ADDRESS to take a gl function and produce a |
| 54 | * function pointer. Two examples: |
| 55 | * 1. Your platform doesn't require a proc address function, just take |
| 56 | * the address of the function: |
| 57 | * #define GR_GL_PROC_ADDRESS(X) &X |
| 58 | * 2. Your platform uses eglGetProcAddress: |
| 59 | * #define GR_GL_PROC_ADDRESS eglGetProcAddress(#X) |
| 60 | * |
| 61 | * Optionally define GR_GL_PROC_ADDRESS_HEADER to include any additional |
| 62 | * header necessary to use GR_GL_PROC_ADDRESS (e.g. <EGL/egl.h>) |
| 63 | * |
| 64 | * Alternatively, define GR_GL_CUSTOM_SETUP_HEADER (and not GR_GL_CUSTOM_SETUP) |
| 65 | * to a header that can be included. This file should: |
| 66 | * 1. Define the approprate GR_SUPPORT_GL* macro(s) to 1 |
| 67 | * 2. Includes all necessary GL headers. |
| 68 | * 3. Optionally define GR_GL_FUNC. |
| 69 | * 4. Define GR_GL_PROC_ADDRESS. |
| 70 | * 5. Optionally define GR_GL_PROC_ADDRESS_HEADER |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 71 | * |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 72 | *------------------------------------------------------------------------------ |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 73 | * |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 74 | * The following are optional defines that can be enabled at the compiler |
| 75 | * command line, in a IDE project, in a GrUserConfig.h file, or in a GL custom |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 76 | * file (if one is in use). They don't require GR_GL_CUSTOM_SETUP or |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 77 | * setup GR_GL_CUSTOM_SETUP_HEADER to be enabled: |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 78 | * |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 79 | * GR_GL_LOG_CALLS: if 1 Gr can print every GL call using GrPrintf. Defaults to |
reed@google.com | 27a1e77 | 2011-03-08 15:34:06 +0000 | [diff] [blame^] | 80 | * 0. Logging can be enabled and disabled at runtime using a debugger via to |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 81 | * global gLogCallsGL. The initial value of gLogCallsGL is controlled by |
| 82 | * GR_GL_LOG_CALLS_START. |
| 83 | * |
| 84 | * GR_GL_LOG_CALLS_START: controls the initial value of gLogCallsGL when |
| 85 | * GR_GL_LOG_CALLS is 1. Defaults to 0. |
| 86 | * |
| 87 | * GR_GL_CHECK_ERROR: if enabled Gr can do a glGetError() after every GL call. |
reed@google.com | 27a1e77 | 2011-03-08 15:34:06 +0000 | [diff] [blame^] | 88 | * Defaults to 1 if GR_DEBUG is set, otherwise 0. When GR_GL_CHECK_ERROR is 1 |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 89 | * this can be toggled in a debugger using the gCheckErrorGL global. The initial |
| 90 | * value of gCheckErrorGL is controlled by by GR_GL_CHECK_ERROR_START. |
| 91 | * |
| 92 | * GR_GL_CHECK_ERROR_START: controls the initial value of gCheckErrorGL |
| 93 | * when GR_GL_CHECK_ERROR is 1. Defaults to 1. |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 94 | */ |
| 95 | |
| 96 | #if GR_GL_CUSTOM_SETUP |
| 97 | |
| 98 | #ifdef GR_SUPPORT_GLES1 |
| 99 | #include GR_INCLUDE_GLES1 |
| 100 | #if defined(GR_INCLUDE_GLES1ext) |
| 101 | #include GR_INCLUDE_GLES1ext |
| 102 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 103 | #endif |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 104 | |
| 105 | #ifdef GR_SUPPORT_GLES2 |
| 106 | #include GR_INCLUDE_GLES2 |
| 107 | #if defined(GR_INCLUDE_GLES2ext) |
| 108 | #include GR_INCLUDE_GLES2ext |
| 109 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 110 | #endif |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 111 | |
| 112 | #ifdef GR_SUPPORT_GLDESKTOP |
| 113 | #include GR_INCLUDE_GLDESKTOP |
| 114 | #if defined(GR_INCLUDE_GLDESKTOPext) |
| 115 | #include GR_INCLUDE_GLDESKTOPext |
| 116 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 117 | #endif |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 118 | |
| 119 | #elif defined(GR_GL_CUSTOM_SETUP_HEADER) |
| 120 | |
| 121 | #include GR_GL_CUSTOM_SETUP_HEADER |
| 122 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 123 | #else |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 124 | #undef GR_GL_FUNC |
| 125 | #undef GR_GL_PROC_ADDRESS |
| 126 | #undef GR_GL_PROC_ADDRESS_HEADER |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 127 | |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 128 | #if GR_WIN32_BUILD |
| 129 | #define GR_SUPPORT_GLDESKTOP 1 |
| 130 | // glew has to be included before gl |
| 131 | #include <GL/glew.h> |
| 132 | #include <GL/gl.h> |
| 133 | // remove stupid windows defines |
| 134 | #undef near |
| 135 | #undef far |
| 136 | #define GR_GL_FUNC __stdcall |
| 137 | #define GR_GL_PROC_ADDRESS(X) wglGetProcAddress(#X) |
| 138 | #define GR_GL_PROC_ADDRESS_HEADER <windows.h> |
| 139 | #elif GR_MAC_BUILD |
| 140 | #define GR_SUPPORT_GLDESKTOP 1 |
| 141 | #include <OpenGL/gl.h> |
| 142 | #include <OpenGL/glext.h> |
| 143 | #define GR_GL_PROC_ADDRESS(X) &X |
| 144 | #elif GR_IOS_BUILD |
| 145 | #define GR_SUPPORT_GLES1 1 |
| 146 | #include <OpenGLES/ES1/gl.h> |
| 147 | #include <OpenGLES/ES1/glext.h> |
| 148 | #define GR_SUPPORT_GLES2 1 |
| 149 | #include <OpenGLES/ES2/gl.h> |
| 150 | #include <OpenGLES/ES2/glext.h> |
| 151 | #define GR_GL_PROC_ADDRESS(X) &X |
| 152 | #elif GR_ANDROID_BUILD |
| 153 | #ifndef GL_GLEXT_PROTOTYPES |
| 154 | #define GL_GLEXT_PROTOTYPES |
| 155 | #endif |
| 156 | #define GR_SUPPORT_GLES2 1 |
| 157 | #include <GLES2/gl2.h> |
| 158 | #include <GLES2/gl2ext.h> |
| 159 | #define GR_GL_PROC_ADDRESS(X) eglGetProcAddress(#X) |
| 160 | #define GR_GL_PROC_ADDRESS_HEADER <EGL/egl.h> |
| 161 | #elif GR_QNX_BUILD |
| 162 | #ifndef GL_GLEXT_PROTOTYPES |
| 163 | #define GL_GLEXT_PROTOTYPES |
| 164 | #endif |
| 165 | #define GR_SUPPORT_GLES2 1 |
| 166 | // This is needed by the QNX GLES2 headers |
| 167 | #define GL_API_EXT |
| 168 | #include <GLES2/gl2.h> |
| 169 | #include <GLES2/gl2ext.h> |
| 170 | #define GR_GL_PROC_ADDRESS(X) eglGetProcAddress(#X) |
| 171 | #define GR_GL_PROC_ADDRESS_HEADER <EGL/egl.h> |
| 172 | #elif GR_LINUX_BUILD |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 173 | #ifndef GL_GLEXT_PROTOTYPES |
| 174 | #define GL_GLEXT_PROTOTYPES |
reed@google.com | 9341bb6 | 2011-01-26 17:11:51 +0000 | [diff] [blame] | 175 | #endif |
reed@google.com | e42e845 | 2011-01-26 17:20:51 +0000 | [diff] [blame] | 176 | #define GL_EXT_framebuffer_blit 0 |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 177 | #include <GL/gl.h> |
| 178 | #include <GL/glext.h> |
reed@google.com | 9341bb6 | 2011-01-26 17:11:51 +0000 | [diff] [blame] | 179 | #define GR_GL_PROC_ADDRESS(X) &X |
reed@google.com | e42e845 | 2011-01-26 17:20:51 +0000 | [diff] [blame] | 180 | #define GR_SUPPORT_GLDESKTOP 1 |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 181 | #else |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 182 | #error "unsupported GR_???_BUILD" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 183 | #endif |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 184 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 185 | #endif |
| 186 | |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 187 | #if !defined(GR_SUPPORT_GLDESKTOP) |
| 188 | #define GR_SUPPORT_GLDESKTOP 0 |
| 189 | #endif |
| 190 | #if !defined(GR_SUPPORT_GLES1) |
| 191 | #define GR_SUPPORT_GLES1 0 |
| 192 | #endif |
| 193 | #if !defined(GR_SUPPORT_GLES2) |
| 194 | #define GR_SUPPORT_GLES2 0 |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 195 | #endif |
| 196 | |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 197 | #define GR_SUPPORT_GLES ((GR_SUPPORT_GLES1) || (GR_SUPPORT_GLES2)) |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 198 | |
reed@google.com | bf858b7 | 2011-01-19 19:04:04 +0000 | [diff] [blame] | 199 | #if !GR_SUPPORT_GLES && !GR_SUPPORT_GLDESKTOP |
| 200 | #error "Either desktop or ES GL must be supported" |
| 201 | #elif GR_SUPPORT_GLES && GR_SUPPORT_GLDESKTOP |
| 202 | #error "Cannot support both desktop and ES GL" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 203 | #endif |
| 204 | |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 205 | #if !defined(GR_GL_FUNC) |
| 206 | #define GR_GL_FUNC |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 207 | #endif |
| 208 | |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 209 | #if !defined(GR_GL_PROC_ADDRESS) |
| 210 | #error "Must define GR_GL_PROC_ADDRESS" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 211 | #endif |
| 212 | |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 213 | #if !defined(GR_GL_LOG_CALLS) |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 214 | #define GR_GL_LOG_CALLS 0 |
| 215 | #endif |
| 216 | |
| 217 | #if !defined(GR_GL_LOG_CALLS_START) |
| 218 | #define GR_GL_LOG_CALLS_START 0 |
| 219 | #endif |
| 220 | |
reed@google.com | 27a1e77 | 2011-03-08 15:34:06 +0000 | [diff] [blame^] | 221 | #if !defined(GR_GL_CHECK_ERROR) |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 222 | #define GR_GL_CHECK_ERROR GR_DEBUG |
| 223 | #endif |
| 224 | |
| 225 | #if !defined(GR_GL_CHECK_ERROR_START) |
| 226 | #define GR_GL_CHECK_ERROR_START 1 |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 227 | #endif |
| 228 | |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 229 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 230 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 231 | #if GR_SCALAR_IS_FIXED |
| 232 | #define GrGLType GL_FIXED |
| 233 | #elif GR_SCALAR_IS_FLOAT |
| 234 | #define GrGLType GL_FLOAT |
| 235 | #else |
| 236 | #error "unknown GR_SCALAR type" |
| 237 | #endif |
| 238 | |
| 239 | #if GR_TEXT_SCALAR_IS_USHORT |
| 240 | #define GrGLTextType GL_UNSIGNED_SHORT |
| 241 | #define GR_GL_TEXT_TEXTURE_NORMALIZED 1 |
| 242 | #elif GR_TEXT_SCALAR_IS_FLOAT |
| 243 | #define GrGLTextType GL_FLOAT |
| 244 | #define GR_GL_TEXT_TEXTURE_NORMALIZED 0 |
| 245 | #elif GR_TEXT_SCALAR_IS_FIXED |
| 246 | #define GrGLTextType GL_FIXED |
| 247 | #define GR_GL_TEXT_TEXTURE_NORMALIZED 0 |
reed@google.com | 63100f9 | 2011-01-18 21:32:14 +0000 | [diff] [blame] | 248 | #else |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 249 | #error "unknown GR_TEXT_SCALAR type" |
| 250 | #endif |
| 251 | |
bsalomon@google.com | 2fbc7fa | 2011-01-05 16:34:41 +0000 | [diff] [blame] | 252 | // Pick a pixel config for 32bit bitmaps. Our default is GL_RGBA (expect on |
| 253 | // Windows where we match GDI's order). |
| 254 | #ifndef GR_GL_32BPP_COLOR_FORMAT |
| 255 | #if GR_WIN32_BUILD |
bsalomon@google.com | ed3a068 | 2011-01-18 16:54:04 +0000 | [diff] [blame] | 256 | #define GR_GL_32BPP_COLOR_FORMAT GR_BGRA //use GR prefix because this |
| 257 | #else //may be an extension. |
bsalomon@google.com | 2fbc7fa | 2011-01-05 16:34:41 +0000 | [diff] [blame] | 258 | #define GR_GL_32BPP_COLOR_FORMAT GL_RGBA |
| 259 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 260 | #endif |
| 261 | |
| 262 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 263 | // Setup for opengl ES/desktop extensions |
| 264 | // We make a struct of function pointers so that each GL context |
reed@google.com | 63100f9 | 2011-01-18 21:32:14 +0000 | [diff] [blame] | 265 | // can have it's own struct. (Some environments may have different proc |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 266 | // addresses for different contexts). |
| 267 | |
| 268 | extern "C" { |
| 269 | struct GrGLExts { |
| 270 | // FBO |
| 271 | GLvoid (GR_GL_FUNC *GenFramebuffers)(GLsizei n, GLuint *framebuffers); |
| 272 | GLvoid (GR_GL_FUNC *BindFramebuffer)(GLenum target, GLuint framebuffer); |
| 273 | GLvoid (GR_GL_FUNC *FramebufferTexture2D)(GLenum target, GLenum attachment, |
reed@google.com | 63100f9 | 2011-01-18 21:32:14 +0000 | [diff] [blame] | 274 | GLenum textarget, GLuint texture, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 275 | GLint level); |
| 276 | GLenum (GR_GL_FUNC *CheckFramebufferStatus)(GLenum target); |
reed@google.com | 63100f9 | 2011-01-18 21:32:14 +0000 | [diff] [blame] | 277 | GLvoid (GR_GL_FUNC *DeleteFramebuffers)(GLsizei n, const |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 278 | GLuint *framebuffers); |
reed@google.com | 63100f9 | 2011-01-18 21:32:14 +0000 | [diff] [blame] | 279 | GLvoid (GR_GL_FUNC *RenderbufferStorage)(GLenum target, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 280 | GLenum internalformat, |
| 281 | GLsizei width, GLsizei height); |
| 282 | GLvoid (GR_GL_FUNC *GenRenderbuffers)(GLsizei n, GLuint *renderbuffers); |
reed@google.com | 63100f9 | 2011-01-18 21:32:14 +0000 | [diff] [blame] | 283 | GLvoid (GR_GL_FUNC *DeleteRenderbuffers)(GLsizei n, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 284 | const GLuint *renderbuffers); |
reed@google.com | 63100f9 | 2011-01-18 21:32:14 +0000 | [diff] [blame] | 285 | GLvoid (GR_GL_FUNC *FramebufferRenderbuffer)(GLenum target, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 286 | GLenum attachment, |
reed@google.com | 63100f9 | 2011-01-18 21:32:14 +0000 | [diff] [blame] | 287 | GLenum renderbuffertarget, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 288 | GLuint renderbuffer); |
| 289 | GLvoid (GR_GL_FUNC *BindRenderbuffer)(GLenum target, GLuint renderbuffer); |
| 290 | |
| 291 | // Multisampling |
| 292 | // same prototype for ARB_FBO, EXT_FBO, GL 3.0, & Apple ES extension |
reed@google.com | 63100f9 | 2011-01-18 21:32:14 +0000 | [diff] [blame] | 293 | GLvoid (GR_GL_FUNC *RenderbufferStorageMultisample)(GLenum target, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 294 | GLsizei samples, |
| 295 | GLenum internalformat, |
reed@google.com | 63100f9 | 2011-01-18 21:32:14 +0000 | [diff] [blame] | 296 | GLsizei width, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 297 | GLsizei height); |
| 298 | // desktop: ext_fbo_blit, arb_fbo, gl 3.0 |
reed@google.com | 63100f9 | 2011-01-18 21:32:14 +0000 | [diff] [blame] | 299 | GLvoid (GR_GL_FUNC *BlitFramebuffer)(GLint srcX0, GLint srcY0, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 300 | GLint srcX1, GLint srcY1, |
reed@google.com | 63100f9 | 2011-01-18 21:32:14 +0000 | [diff] [blame] | 301 | GLint dstX0, GLint dstY0, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 302 | GLint dstX1, GLint dstY1, |
| 303 | GLbitfield mask, GLenum filter); |
| 304 | // apple's es extension |
| 305 | GLvoid (GR_GL_FUNC *ResolveMultisampleFramebuffer)(); |
| 306 | |
| 307 | // IMG'e es extension |
reed@google.com | 63100f9 | 2011-01-18 21:32:14 +0000 | [diff] [blame] | 308 | GLvoid (GR_GL_FUNC *FramebufferTexture2DMultisample)(GLenum target, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 309 | GLenum attachment, |
reed@google.com | 63100f9 | 2011-01-18 21:32:14 +0000 | [diff] [blame] | 310 | GLenum textarget, |
| 311 | GLuint texture, |
| 312 | GLint level, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 313 | GLsizei samples); |
| 314 | |
| 315 | // Buffer mapping (extension in ES). |
| 316 | GLvoid* (GR_GL_FUNC *MapBuffer)(GLenum target, GLenum access); |
| 317 | GLboolean (GR_GL_FUNC *UnmapBuffer)(GLenum target); |
| 318 | }; |
| 319 | } |
| 320 | |
bsalomon@google.com | ed3a068 | 2011-01-18 16:54:04 +0000 | [diff] [blame] | 321 | // BGRA format |
| 322 | |
| 323 | #define GR_BGRA 0x80E1 |
| 324 | |
bsalomon@google.com | 3f3ffd6 | 2011-01-18 17:14:52 +0000 | [diff] [blame] | 325 | // FBO / stencil formats |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 326 | #define GR_FRAMEBUFFER 0x8D40 |
| 327 | #define GR_FRAMEBUFFER_COMPLETE 0x8CD5 |
| 328 | #define GR_COLOR_ATTACHMENT0 0x8CE0 |
reed@google.com | 63100f9 | 2011-01-18 21:32:14 +0000 | [diff] [blame] | 329 | #define GR_FRAMEBUFFER_BINDING 0x8CA6 |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 330 | #define GR_RENDERBUFFER 0x8D41 |
| 331 | #define GR_STENCIL_ATTACHMENT 0x8D20 |
bsalomon@google.com | 3f3ffd6 | 2011-01-18 17:14:52 +0000 | [diff] [blame] | 332 | #define GR_STENCIL_INDEX4 0x8D47 |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 333 | #define GR_STENCIL_INDEX8 0x8D48 |
| 334 | #define GR_STENCIL_INDEX16 0x8D49 |
bsalomon@google.com | 3f3ffd6 | 2011-01-18 17:14:52 +0000 | [diff] [blame] | 335 | #define GR_DEPTH24_STENCIL8 0x88F0 |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 336 | #define GR_MAX_RENDERBUFFER_SIZE 0x84E8 |
| 337 | #define GR_DEPTH_STENCIL_ATTACHMENT 0x821A |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 338 | #define GR_DEPTH_STENCIL 0x84F9 |
| 339 | #define GR_RGBA8 0x8058 |
| 340 | #define GR_RGB565 0x8D62 |
| 341 | |
| 342 | |
| 343 | // Multisampling |
| 344 | |
| 345 | // IMG MAX_SAMPLES uses a different value than desktop, Apple ES extension. |
| 346 | #define GR_MAX_SAMPLES 0x8D57 |
| 347 | #define GR_MAX_SAMPLES_IMG 0x9135 |
| 348 | #define GR_READ_FRAMEBUFFER 0x8CA8 |
| 349 | #define GR_DRAW_FRAMEBUFFER 0x8CA9 |
| 350 | |
| 351 | // Buffer mapping |
| 352 | #define GR_WRITE_ONLY 0x88B9 |
| 353 | #define GR_BUFFER_MAPPED 0x88BC |
| 354 | |
| 355 | // Palette texture |
| 356 | #define GR_PALETTE8_RGBA8 0x8B91 |
| 357 | |
| 358 | extern void GrGLInitExtensions(GrGLExts* exts); |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 359 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 360 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | 63100f9 | 2011-01-18 21:32:14 +0000 | [diff] [blame] | 361 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 362 | extern void GrGLCheckErr(const char* location, const char* call); |
| 363 | |
| 364 | static inline void GrGLClearErr() { |
reed@google.com | 63100f9 | 2011-01-18 21:32:14 +0000 | [diff] [blame] | 365 | while (GL_NO_ERROR != glGetError()) {} |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 366 | } |
| 367 | |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 368 | #if GR_GL_CHECK_ERROR |
| 369 | extern bool gCheckErrorGL; |
| 370 | #define GR_GL_CHECK_ERROR_IMPL(X) if (gCheckErrorGL) GrGLCheckErr(GR_FILE_AND_LINE_STR, #X) |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 371 | #else |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 372 | #define GR_GL_CHECK_ERROR_IMPL(X) |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 373 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 374 | |
| 375 | #if GR_GL_LOG_CALLS |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 376 | extern bool gLogCallsGL; |
| 377 | #define GR_GL_LOG_CALLS_IMPL(X) if (gLogCallsGL) GrPrintf(GR_FILE_AND_LINE_STR "GL: " #X "\n") |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 378 | #else |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 379 | #define GR_GL_LOG_CALLS_IMPL(X) |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 380 | #endif |
| 381 | |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 382 | #define GR_GL(X) gl ## X; GR_GL_LOG_CALLS_IMPL(X); GR_GL_CHECK_ERROR_IMPL(X); |
| 383 | #define GR_GL_NO_ERR(X) GrGLClearErr(); gl ## X; GR_GL_LOG_CALLS_IMPL(X); GR_GL_CHECK_ERROR_IMPL(X); |
| 384 | #define GR_GLEXT(exts, X) exts. X; GR_GL_LOG_CALLS_IMPL(X); GR_GL_CHECK_ERROR_IMPL(X); |
| 385 | #define GR_GLEXT_NO_ERR(exts, X) GrGLClearErr(); exts. X; GR_GL_LOG_CALLS_IMPL(X); GR_GL_CHECK_ERROR_IMPL(X); |
| 386 | |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 387 | //////////////////////////////////////////////////////////////////////////////// |
| 388 | |
| 389 | /** |
| 390 | * Helpers for glGetString() |
| 391 | */ |
| 392 | bool has_gl_extension(const char* ext); |
| 393 | void gl_version(int* major, int* minor); |
| 394 | |
| 395 | //////////////////////////////////////////////////////////////////////////////// |
| 396 | |
| 397 | /** |
| 398 | * GrGL_RestoreResetRowLength() will reset GL_UNPACK_ROW_LENGTH to 0. We write |
| 399 | * this wrapper, since GL_UNPACK_ROW_LENGTH is not available on all GL versions |
| 400 | */ |
| 401 | #if GR_SUPPORT_GLDESKTOP |
| 402 | static inline void GrGL_RestoreResetRowLength() { |
| 403 | GR_GL(PixelStorei(GL_UNPACK_ROW_LENGTH, 0)); |
| 404 | } |
| 405 | #else |
| 406 | #define GrGL_RestoreResetRowLength() |
| 407 | #endif |
| 408 | |
| 409 | //////////////////////////////////////////////////////////////////////////////// |
| 410 | |
| 411 | /** |
| 412 | * Some drivers want the var-int arg to be zero-initialized on input. |
| 413 | */ |
| 414 | #define GR_GL_INIT_ZERO 0 |
| 415 | #define GR_GL_GetIntegerv(e, p) \ |
| 416 | do { \ |
| 417 | *(p) = GR_GL_INIT_ZERO; \ |
| 418 | GR_GL(GetIntegerv(e, p)); \ |
| 419 | } while (0) |
| 420 | |
| 421 | //////////////////////////////////////////////////////////////////////////////// |
| 422 | |
reed@google.com | 27a1e77 | 2011-03-08 15:34:06 +0000 | [diff] [blame^] | 423 | #endif |