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