reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
twiz@google.com | 59a190b | 2011-03-14 21:23:01 +0000 | [diff] [blame] | 2 | Copyright 2011 Google Inc. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 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" |
twiz@google.com | 59a190b | 2011-03-14 21:23:01 +0000 | [diff] [blame] | 22 | #include "GrGLInterface.h" |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 23 | #include "GrGLDefines.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 24 | |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 25 | /** |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 26 | * The following macros are used to staticlly configure the default |
| 27 | * GrGLInterface, but should not be used outside of the GrGLInterface |
| 28 | * scaffolding. Undefine here to prevent accidental use. |
| 29 | */ |
| 30 | #undef GR_SUPPORT_GLDESKTOP |
| 31 | #undef GR_SUPPORT_GLES1 |
| 32 | #undef GR_SUPPORT_GLES2 |
| 33 | #undef GR_SUPPORT_GLES |
| 34 | |
| 35 | /** |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 36 | * The following are optional defines that can be enabled at the compiler |
| 37 | * 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] | 38 | * 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] | 39 | * setup GR_GL_CUSTOM_SETUP_HEADER to be enabled: |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 40 | * |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 41 | * 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] | 42 | * 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] | 43 | * global gLogCallsGL. The initial value of gLogCallsGL is controlled by |
| 44 | * GR_GL_LOG_CALLS_START. |
| 45 | * |
| 46 | * GR_GL_LOG_CALLS_START: controls the initial value of gLogCallsGL when |
| 47 | * GR_GL_LOG_CALLS is 1. Defaults to 0. |
| 48 | * |
| 49 | * 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] | 50 | * 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] | 51 | * this can be toggled in a debugger using the gCheckErrorGL global. The initial |
| 52 | * value of gCheckErrorGL is controlled by by GR_GL_CHECK_ERROR_START. |
| 53 | * |
| 54 | * GR_GL_CHECK_ERROR_START: controls the initial value of gCheckErrorGL |
| 55 | * when GR_GL_CHECK_ERROR is 1. Defaults to 1. |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 56 | */ |
| 57 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 58 | |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 59 | #if !defined(GR_GL_LOG_CALLS) |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 60 | #define GR_GL_LOG_CALLS 0 |
| 61 | #endif |
| 62 | |
| 63 | #if !defined(GR_GL_LOG_CALLS_START) |
| 64 | #define GR_GL_LOG_CALLS_START 0 |
| 65 | #endif |
| 66 | |
reed@google.com | 27a1e77 | 2011-03-08 15:34:06 +0000 | [diff] [blame] | 67 | #if !defined(GR_GL_CHECK_ERROR) |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 68 | #define GR_GL_CHECK_ERROR GR_DEBUG |
| 69 | #endif |
| 70 | |
| 71 | #if !defined(GR_GL_CHECK_ERROR_START) |
| 72 | #define GR_GL_CHECK_ERROR_START 1 |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 73 | #endif |
| 74 | |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 75 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 76 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 77 | #if GR_SCALAR_IS_FIXED |
| 78 | #define GrGLType GL_FIXED |
| 79 | #elif GR_SCALAR_IS_FLOAT |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 80 | #define GrGLType GR_GL_FLOAT |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 81 | #else |
| 82 | #error "unknown GR_SCALAR type" |
| 83 | #endif |
| 84 | |
| 85 | #if GR_TEXT_SCALAR_IS_USHORT |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 86 | #define GrGLTextType GR_GL_UNSIGNED_SHORT |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 87 | #define GR_GL_TEXT_TEXTURE_NORMALIZED 1 |
| 88 | #elif GR_TEXT_SCALAR_IS_FLOAT |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 89 | #define GrGLTextType GR_GL_FLOAT |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 90 | #define GR_GL_TEXT_TEXTURE_NORMALIZED 0 |
| 91 | #elif GR_TEXT_SCALAR_IS_FIXED |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 92 | #define GrGLTextType GR_GL_FIXED |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 93 | #define GR_GL_TEXT_TEXTURE_NORMALIZED 0 |
reed@google.com | 63100f9 | 2011-01-18 21:32:14 +0000 | [diff] [blame] | 94 | #else |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 95 | #error "unknown GR_TEXT_SCALAR type" |
| 96 | #endif |
| 97 | |
twiz@google.com | 59a190b | 2011-03-14 21:23:01 +0000 | [diff] [blame] | 98 | // Pick a pixel config for 32bit bitmaps. Our default is GL_RGBA (except on |
bsalomon@google.com | 2fbc7fa | 2011-01-05 16:34:41 +0000 | [diff] [blame] | 99 | // Windows where we match GDI's order). |
| 100 | #ifndef GR_GL_32BPP_COLOR_FORMAT |
| 101 | #if GR_WIN32_BUILD |
bsalomon@google.com | ed3a068 | 2011-01-18 16:54:04 +0000 | [diff] [blame] | 102 | #define GR_GL_32BPP_COLOR_FORMAT GR_BGRA //use GR prefix because this |
| 103 | #else //may be an extension. |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 104 | #define GR_GL_32BPP_COLOR_FORMAT GR_GL_RGBA |
bsalomon@google.com | 2fbc7fa | 2011-01-05 16:34:41 +0000 | [diff] [blame] | 105 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 106 | #endif |
| 107 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 108 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 109 | |
bsalomon@google.com | ed3a068 | 2011-01-18 16:54:04 +0000 | [diff] [blame] | 110 | // BGRA format |
bsalomon@google.com | ed3a068 | 2011-01-18 16:54:04 +0000 | [diff] [blame] | 111 | #define GR_BGRA 0x80E1 |
| 112 | |
bsalomon@google.com | 3f3ffd6 | 2011-01-18 17:14:52 +0000 | [diff] [blame] | 113 | // FBO / stencil formats |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 114 | #define GR_FRAMEBUFFER 0x8D40 |
| 115 | #define GR_FRAMEBUFFER_COMPLETE 0x8CD5 |
| 116 | #define GR_COLOR_ATTACHMENT0 0x8CE0 |
reed@google.com | 63100f9 | 2011-01-18 21:32:14 +0000 | [diff] [blame] | 117 | #define GR_FRAMEBUFFER_BINDING 0x8CA6 |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 118 | #define GR_RENDERBUFFER 0x8D41 |
| 119 | #define GR_STENCIL_ATTACHMENT 0x8D20 |
bsalomon@google.com | 3f3ffd6 | 2011-01-18 17:14:52 +0000 | [diff] [blame] | 120 | #define GR_STENCIL_INDEX4 0x8D47 |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 121 | #define GR_STENCIL_INDEX8 0x8D48 |
| 122 | #define GR_STENCIL_INDEX16 0x8D49 |
bsalomon@google.com | 3f3ffd6 | 2011-01-18 17:14:52 +0000 | [diff] [blame] | 123 | #define GR_DEPTH24_STENCIL8 0x88F0 |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 124 | #define GR_MAX_RENDERBUFFER_SIZE 0x84E8 |
| 125 | #define GR_DEPTH_STENCIL_ATTACHMENT 0x821A |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 126 | #define GR_DEPTH_STENCIL 0x84F9 |
| 127 | #define GR_RGBA8 0x8058 |
| 128 | #define GR_RGB565 0x8D62 |
| 129 | |
| 130 | |
| 131 | // Multisampling |
| 132 | |
| 133 | // IMG MAX_SAMPLES uses a different value than desktop, Apple ES extension. |
| 134 | #define GR_MAX_SAMPLES 0x8D57 |
| 135 | #define GR_MAX_SAMPLES_IMG 0x9135 |
| 136 | #define GR_READ_FRAMEBUFFER 0x8CA8 |
| 137 | #define GR_DRAW_FRAMEBUFFER 0x8CA9 |
| 138 | |
| 139 | // Buffer mapping |
| 140 | #define GR_WRITE_ONLY 0x88B9 |
| 141 | #define GR_BUFFER_MAPPED 0x88BC |
| 142 | |
| 143 | // Palette texture |
| 144 | #define GR_PALETTE8_RGBA8 0x8B91 |
| 145 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 146 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | 63100f9 | 2011-01-18 21:32:14 +0000 | [diff] [blame] | 147 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 148 | extern void GrGLCheckErr(const char* location, const char* call); |
| 149 | |
| 150 | static inline void GrGLClearErr() { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 151 | while (GR_GL_NO_ERROR != GrGLGetGLInterface()->fGetError()) {} |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 152 | } |
| 153 | |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 154 | #if GR_GL_CHECK_ERROR |
| 155 | extern bool gCheckErrorGL; |
| 156 | #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] | 157 | #else |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 158 | #define GR_GL_CHECK_ERROR_IMPL(X) |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 159 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 160 | |
| 161 | #if GR_GL_LOG_CALLS |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 162 | extern bool gLogCallsGL; |
| 163 | #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] | 164 | #else |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 165 | #define GR_GL_LOG_CALLS_IMPL(X) |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 166 | #endif |
| 167 | |
twiz@google.com | 59a190b | 2011-03-14 21:23:01 +0000 | [diff] [blame] | 168 | #define GR_GL(X) GrGLGetGLInterface()->f##X;; GR_GL_LOG_CALLS_IMPL(X); GR_GL_CHECK_ERROR_IMPL(X); |
| 169 | #define GR_GL_NO_ERR(X) GrGLGetGLInterface()->f##X;; GR_GL_LOG_CALLS_IMPL(X); GR_GL_CHECK_ERROR_IMPL(X); |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 170 | |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 171 | #define GR_GL_SUPPORT_DESKTOP (kDesktop_GrGLBinding == GrGLGetGLInterface()->fBindingsExported) |
| 172 | #define GR_GL_SUPPORT_ES1 (kES1_GrGLBinding == GrGLGetGLInterface()->fBindingsExported) |
| 173 | #define GR_GL_SUPPORT_ES2 (kES2_GrGLBinding == GrGLGetGLInterface()->fBindingsExported) |
| 174 | #define GR_GL_SUPPORT_ES (GR_GL_SUPPORT_ES1 || GR_GL_SUPPORT_ES2) |
| 175 | |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 176 | //////////////////////////////////////////////////////////////////////////////// |
| 177 | |
| 178 | /** |
| 179 | * GrGL_RestoreResetRowLength() will reset GL_UNPACK_ROW_LENGTH to 0. We write |
| 180 | * this wrapper, since GL_UNPACK_ROW_LENGTH is not available on all GL versions |
| 181 | */ |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 182 | static inline void GrGL_RestoreResetRowLength() { |
| 183 | if (GR_GL_SUPPORT_DESKTOP) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 184 | GR_GL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 185 | } |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 186 | } |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 187 | |
| 188 | //////////////////////////////////////////////////////////////////////////////// |
| 189 | |
| 190 | /** |
| 191 | * Some drivers want the var-int arg to be zero-initialized on input. |
| 192 | */ |
| 193 | #define GR_GL_INIT_ZERO 0 |
| 194 | #define GR_GL_GetIntegerv(e, p) \ |
| 195 | do { \ |
| 196 | *(p) = GR_GL_INIT_ZERO; \ |
| 197 | GR_GL(GetIntegerv(e, p)); \ |
| 198 | } while (0) |
| 199 | |
| 200 | //////////////////////////////////////////////////////////////////////////////// |
| 201 | |
reed@google.com | 27a1e77 | 2011-03-08 15:34:06 +0000 | [diff] [blame] | 202 | #endif |