epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 10 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 11 | #ifndef GrGLConfig_DEFINED |
| 12 | #define GrGLConfig_DEFINED |
| 13 | |
| 14 | #include "GrTypes.h" |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 15 | #include "GrGLDefines.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 16 | |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 17 | /** |
bsalomon@google.com | f987d1b | 2011-04-04 17:13:52 +0000 | [diff] [blame] | 18 | * Optional GL config file. |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 19 | */ |
bsalomon@google.com | f987d1b | 2011-04-04 17:13:52 +0000 | [diff] [blame] | 20 | #ifdef GR_GL_CUSTOM_SETUP_HEADER |
| 21 | #include GR_GL_CUSTOM_SETUP_HEADER |
| 22 | #endif |
| 23 | |
| 24 | #if !defined(GR_GL_FUNCTION_TYPE) |
| 25 | #define GR_GL_FUNCTION_TYPE |
| 26 | #endif |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 27 | |
| 28 | /** |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 29 | * The following are optional defines that can be enabled at the compiler |
| 30 | * command line, in a IDE project, in a GrUserConfig.h file, or in a GL custom |
bsalomon@google.com | f987d1b | 2011-04-04 17:13:52 +0000 | [diff] [blame] | 31 | * file (if one is in use). If a GR_GL_CUSTOM_SETUP_HEADER is used they can |
| 32 | * also be placed there. |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 33 | * |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 34 | * 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] | 35 | * 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] | 36 | * global gLogCallsGL. The initial value of gLogCallsGL is controlled by |
| 37 | * GR_GL_LOG_CALLS_START. |
| 38 | * |
| 39 | * GR_GL_LOG_CALLS_START: controls the initial value of gLogCallsGL when |
| 40 | * GR_GL_LOG_CALLS is 1. Defaults to 0. |
| 41 | * |
| 42 | * 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] | 43 | * 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] | 44 | * this can be toggled in a debugger using the gCheckErrorGL global. The initial |
| 45 | * value of gCheckErrorGL is controlled by by GR_GL_CHECK_ERROR_START. |
| 46 | * |
| 47 | * GR_GL_CHECK_ERROR_START: controls the initial value of gCheckErrorGL |
| 48 | * when GR_GL_CHECK_ERROR is 1. Defaults to 1. |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 49 | * |
| 50 | * GR_GL_NO_CONSTANT_ATTRIBUTES: if this evaluates to true then the GL backend |
| 51 | * will use uniforms instead of attributes in all cases when there is not |
| 52 | * per-vertex data. This is important when the underlying GL implementation |
| 53 | * doesn't actually support immediate style attribute values (e.g. when |
| 54 | * the GL stream is converted to DX as in ANGLE on Chrome). Defaults to 0. |
| 55 | * |
| 56 | * GR_GL_ATTRIBUTE_MATRICES: If changing uniforms is very expensive it may be |
| 57 | * faster to use vertex attributes for matrices (set via glVertexAttrib3fv). |
| 58 | * Setting this build flag enables this behavior. GR_GL_NO_CONSTANT_ATTRIBUTES |
| 59 | * must not be set since this uses constant attributes for the matrices. |
| 60 | * Defaults to 0. |
bsalomon@google.com | 9ae4429 | 2011-07-01 15:21:59 +0000 | [diff] [blame] | 61 | * |
| 62 | * GR_GL_USE_BUFFER_DATA_NULL_HINT: When specifing new data for a vertex/index |
| 63 | * buffer that replaces old data Ganesh can give a hint to the driver that the |
| 64 | * previous data will not be used in future draws like this: |
| 65 | * glBufferData(GL_..._BUFFER, size, NULL, usage); //<--hint, NULL means |
| 66 | * glBufferSubData(GL_..._BUFFER, 0, lessThanSize, data) // old data can't be |
| 67 | * // used again. |
| 68 | * However, this can cause a performance decrease on Chrome cmd buffer because |
| 69 | * it will create a new allocation and memset the whole thing to zero (for |
| 70 | * security reasons). Defaults to 1 (enabled). |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 71 | */ |
| 72 | |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 73 | #if !defined(GR_GL_LOG_CALLS) |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 74 | #define GR_GL_LOG_CALLS 0 |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 75 | #endif |
| 76 | |
| 77 | #if !defined(GR_GL_LOG_CALLS_START) |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 78 | #define GR_GL_LOG_CALLS_START 0 |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 79 | #endif |
| 80 | |
reed@google.com | 27a1e77 | 2011-03-08 15:34:06 +0000 | [diff] [blame] | 81 | #if !defined(GR_GL_CHECK_ERROR) |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 82 | #define GR_GL_CHECK_ERROR GR_DEBUG |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 83 | #endif |
| 84 | |
| 85 | #if !defined(GR_GL_CHECK_ERROR_START) |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 86 | #define GR_GL_CHECK_ERROR_START 1 |
| 87 | #endif |
| 88 | |
| 89 | #if !defined(GR_GL_NO_CONSTANT_ATTRIBUTES) |
| 90 | #define GR_GL_NO_CONSTANT_ATTRIBUTES 0 |
| 91 | #endif |
| 92 | |
| 93 | #if !defined(GR_GL_ATTRIBUTE_MATRICES) |
| 94 | #define GR_GL_ATTRIBUTE_MATRICES 0 |
| 95 | #endif |
| 96 | |
bsalomon@google.com | 9ae4429 | 2011-07-01 15:21:59 +0000 | [diff] [blame] | 97 | #if !defined(GR_GL_USE_BUFFER_DATA_NULL_HINT) |
| 98 | #define GR_GL_USE_BUFFER_DATA_NULL_HINT 1 |
| 99 | #endif |
| 100 | |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 101 | #if(GR_GL_NO_CONSTANT_ATTRIBUTES) && (GR_GL_ATTRIBUTE_MATRICES) |
| 102 | #error "Cannot combine GR_GL_NO_CONSTANT_ATTRIBUTES and GR_GL_ATTRIBUTE_MATRICES" |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 103 | #endif |
| 104 | |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 105 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 106 | |
bsalomon@google.com | f987d1b | 2011-04-04 17:13:52 +0000 | [diff] [blame] | 107 | /** |
| 108 | * The following macros are used to staticlly configure the default |
| 109 | * GrGLInterface, but should not be used outside of the GrGLInterface |
| 110 | * scaffolding. Undefine here to prevent accidental use. |
| 111 | */ |
| 112 | #undef GR_SUPPORT_GLDESKTOP |
| 113 | #undef GR_SUPPORT_GLES1 |
| 114 | #undef GR_SUPPORT_GLES2 |
| 115 | #undef GR_SUPPORT_GLES |
| 116 | |
| 117 | //////////////////////////////////////////////////////////////////////////////// |
| 118 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 119 | #if GR_SCALAR_IS_FIXED |
| 120 | #define GrGLType GL_FIXED |
| 121 | #elif GR_SCALAR_IS_FLOAT |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 122 | #define GrGLType GR_GL_FLOAT |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 123 | #else |
| 124 | #error "unknown GR_SCALAR type" |
| 125 | #endif |
| 126 | |
| 127 | #if GR_TEXT_SCALAR_IS_USHORT |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 128 | #define GrGLTextType GR_GL_UNSIGNED_SHORT |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 129 | #define GR_GL_TEXT_TEXTURE_NORMALIZED 1 |
| 130 | #elif GR_TEXT_SCALAR_IS_FLOAT |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 131 | #define GrGLTextType GR_GL_FLOAT |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 132 | #define GR_GL_TEXT_TEXTURE_NORMALIZED 0 |
| 133 | #elif GR_TEXT_SCALAR_IS_FIXED |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 134 | #define GrGLTextType GR_GL_FIXED |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 135 | #define GR_GL_TEXT_TEXTURE_NORMALIZED 0 |
reed@google.com | 63100f9 | 2011-01-18 21:32:14 +0000 | [diff] [blame] | 136 | #else |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 137 | #error "unknown GR_TEXT_SCALAR type" |
| 138 | #endif |
| 139 | |
twiz@google.com | 59a190b | 2011-03-14 21:23:01 +0000 | [diff] [blame] | 140 | // 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] | 141 | // Windows where we match GDI's order). |
| 142 | #ifndef GR_GL_32BPP_COLOR_FORMAT |
senorblanco@chromium.org | 99c2a8b | 2011-05-04 20:12:01 +0000 | [diff] [blame] | 143 | #if GR_WIN32_BUILD || GR_LINUX_BUILD |
bsalomon@google.com | c312bf9 | 2011-03-21 21:10:33 +0000 | [diff] [blame] | 144 | #define GR_GL_32BPP_COLOR_FORMAT GR_GL_BGRA |
| 145 | #else |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 146 | #define GR_GL_32BPP_COLOR_FORMAT GR_GL_RGBA |
bsalomon@google.com | 2fbc7fa | 2011-01-05 16:34:41 +0000 | [diff] [blame] | 147 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 148 | #endif |
| 149 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 150 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | 63100f9 | 2011-01-18 21:32:14 +0000 | [diff] [blame] | 151 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 152 | struct GrGLInterface; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 153 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 154 | extern void GrGLCheckErr(const GrGLInterface* gl, |
| 155 | const char* location, |
| 156 | const char* call); |
| 157 | |
| 158 | extern void GrGLClearErr(const GrGLInterface* gl); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 159 | |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 160 | #if GR_GL_CHECK_ERROR |
| 161 | extern bool gCheckErrorGL; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 162 | #define GR_GL_CHECK_ERROR_IMPL(IFACE, X) \ |
| 163 | if (gCheckErrorGL) \ |
| 164 | GrGLCheckErr(IFACE, GR_FILE_AND_LINE_STR, #X) |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 165 | #else |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 166 | #define GR_GL_CHECK_ERROR_IMPL(IFACE, X) |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 167 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 168 | |
| 169 | #if GR_GL_LOG_CALLS |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 170 | extern bool gLogCallsGL; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 171 | #define GR_GL_LOG_CALLS_IMPL(X) |
| 172 | if (gLogCallsGL) \ |
| 173 | GrPrintf(GR_FILE_AND_LINE_STR "GL: " #X "\n") |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 174 | #else |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 175 | #define GR_GL_LOG_CALLS_IMPL(X) |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 176 | #endif |
| 177 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 178 | #define GR_GL_CALL(IFACE, X) \ |
| 179 | GR_GL_CALL_NOERRCHECK(IFACE, X) \ |
| 180 | GR_GL_CHECK_ERROR_IMPL(IFACE, X) |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 181 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 182 | #define GR_GL_CALL_NOERRCHECK(IFACE, X) \ |
| 183 | IFACE->f##X; \ |
| 184 | GR_GL_LOG_CALLS_IMPL(X); |
| 185 | |
| 186 | #define GR_GL_GET_ERROR(IFACE) (IFACE)->fGetError() |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 187 | |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 188 | //////////////////////////////////////////////////////////////////////////////// |
| 189 | |
| 190 | /** |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 191 | * GrGLResetRowLength() will reset GL_UNPACK_ROW_LENGTH to 0. We write |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 192 | * this wrapper, since GL_UNPACK_ROW_LENGTH is not available on all GL versions |
| 193 | */ |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 194 | extern void GrGLResetRowLength(const GrGLInterface*); |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 195 | |
| 196 | //////////////////////////////////////////////////////////////////////////////// |
| 197 | |
| 198 | /** |
| 199 | * Some drivers want the var-int arg to be zero-initialized on input. |
| 200 | */ |
| 201 | #define GR_GL_INIT_ZERO 0 |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 202 | #define GR_GL_GetIntegerv(gl, e, p) \ |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 203 | do { \ |
| 204 | *(p) = GR_GL_INIT_ZERO; \ |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 205 | GR_GL_CALL(gl, GetIntegerv(e, p)); \ |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 206 | } while (0) |
| 207 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 208 | #define GR_GL_GetFramebufferAttachmentParameteriv(gl, t, a, pname, p) \ |
| 209 | do { \ |
| 210 | *(p) = GR_GL_INIT_ZERO; \ |
| 211 | GR_GL_CALL(gl, GetFramebufferAttachmentParameteriv(t, a, pname, p)); \ |
bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 212 | } while (0) |
| 213 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 214 | #define GR_GL_GetRenderbufferParameteriv(gl, t, pname, p) \ |
| 215 | do { \ |
| 216 | *(p) = GR_GL_INIT_ZERO; \ |
| 217 | GR_GL_CALL(gl, GetRenderbufferParameteriv(t, pname, p)); \ |
bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 218 | } while (0) |
| 219 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 220 | #define GR_GL_GetTexLevelParameteriv(gl, t, l, pname, p) \ |
| 221 | do { \ |
| 222 | *(p) = GR_GL_INIT_ZERO; \ |
| 223 | GR_GL_CALL(gl, GetTexLevelParameteriv(t, l, pname, p)); \ |
bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 224 | } while (0) |
| 225 | |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 226 | //////////////////////////////////////////////////////////////////////////////// |
| 227 | |
reed@google.com | 27a1e77 | 2011-03-08 15:34:06 +0000 | [diff] [blame] | 228 | #endif |