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" |
| 15 | |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 16 | /** |
bsalomon@google.com | f987d1b | 2011-04-04 17:13:52 +0000 | [diff] [blame] | 17 | * Optional GL config file. |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 18 | */ |
bsalomon@google.com | f987d1b | 2011-04-04 17:13:52 +0000 | [diff] [blame] | 19 | #ifdef GR_GL_CUSTOM_SETUP_HEADER |
| 20 | #include GR_GL_CUSTOM_SETUP_HEADER |
| 21 | #endif |
| 22 | |
| 23 | #if !defined(GR_GL_FUNCTION_TYPE) |
| 24 | #define GR_GL_FUNCTION_TYPE |
| 25 | #endif |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 26 | |
| 27 | /** |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 28 | * The following are optional defines that can be enabled at the compiler |
| 29 | * 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] | 30 | * file (if one is in use). If a GR_GL_CUSTOM_SETUP_HEADER is used they can |
| 31 | * also be placed there. |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 32 | * |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 33 | * 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] | 34 | * 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] | 35 | * global gLogCallsGL. The initial value of gLogCallsGL is controlled by |
| 36 | * GR_GL_LOG_CALLS_START. |
| 37 | * |
| 38 | * GR_GL_LOG_CALLS_START: controls the initial value of gLogCallsGL when |
| 39 | * GR_GL_LOG_CALLS is 1. Defaults to 0. |
| 40 | * |
| 41 | * 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] | 42 | * 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] | 43 | * this can be toggled in a debugger using the gCheckErrorGL global. The initial |
| 44 | * value of gCheckErrorGL is controlled by by GR_GL_CHECK_ERROR_START. |
| 45 | * |
| 46 | * GR_GL_CHECK_ERROR_START: controls the initial value of gCheckErrorGL |
| 47 | * when GR_GL_CHECK_ERROR is 1. Defaults to 1. |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 48 | * |
| 49 | * GR_GL_NO_CONSTANT_ATTRIBUTES: if this evaluates to true then the GL backend |
| 50 | * will use uniforms instead of attributes in all cases when there is not |
| 51 | * per-vertex data. This is important when the underlying GL implementation |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 52 | * doesn't actually support immediate style attribute values (e.g. when |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 53 | * the GL stream is converted to DX as in ANGLE on Chrome). Defaults to 0. |
| 54 | * |
bsalomon@google.com | 9ae4429 | 2011-07-01 15:21:59 +0000 | [diff] [blame] | 55 | * GR_GL_USE_BUFFER_DATA_NULL_HINT: When specifing new data for a vertex/index |
| 56 | * buffer that replaces old data Ganesh can give a hint to the driver that the |
| 57 | * previous data will not be used in future draws like this: |
| 58 | * glBufferData(GL_..._BUFFER, size, NULL, usage); //<--hint, NULL means |
| 59 | * glBufferSubData(GL_..._BUFFER, 0, lessThanSize, data) // old data can't be |
| 60 | * // used again. |
bsalomon@google.com | 96e96df | 2011-10-10 14:49:29 +0000 | [diff] [blame] | 61 | * However, this can be an unoptimization on some platforms, esp. Chrome. |
| 62 | * Chrome's cmd buffer will create a new allocation and memset the whole thing |
| 63 | * to zero (for security reasons). Defaults to 1 (enabled). |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 64 | * |
| 65 | * GR_GL_PER_GL_FUNC_CALLBACK: When set to 1 the GrGLInterface object provides |
| 66 | * a function pointer that is called just before every gl function. The ptr must |
| 67 | * be valid (i.e. there is no NULL check). However, by default the callback will |
| 68 | * be set to a function that does nothing. The signature of the function is: |
| 69 | * void function(const GrGLInterface*) |
| 70 | * It is not extern "C". |
| 71 | * The GrGLInterface field fCallback specifies the function ptr and there is an |
| 72 | * additional field fCallbackData of type intptr_t for client data. |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 73 | * |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 74 | * GR_GL_RGBA_8888_PIXEL_OPS_SLOW: Set this to 1 if it is known that performing |
| 75 | * glReadPixels / glTex(Sub)Image with format=GL_RGBA, type=GL_UNISIGNED_BYTE is |
| 76 | * significantly slower than format=GL_BGRA, type=GL_UNISIGNED_BYTE. |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 77 | * |
| 78 | * GR_GL_FULL_READPIXELS_FASTER_THAN_PARTIAL: Set this to 1 if calling |
| 79 | * glReadPixels to read the entire framebuffer is faster than calling it with |
| 80 | * the same sized rectangle but with a framebuffer bound that is larger than |
| 81 | * the rectangle read. |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 82 | * |
| 83 | * GR_GL_CHECK_ALLOC_WITH_GET_ERROR: If set to 1 this will then glTexImage, |
| 84 | * glBufferData, glRenderbufferStorage, etc will be checked for errors. This |
| 85 | * amounts to ensuring the error is GL_NO_ERROR, calling the allocating |
| 86 | * function, and then checking that the error is still GL_NO_ERROR. When the |
| 87 | * value is 0 we will assume no error was generated without checking. |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 88 | * |
| 89 | * GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT: We will normally check the FBO status |
| 90 | * every time we bind a texture or renderbuffer to an FBO. However, in some |
| 91 | * environments CheckFrameBufferStatus is very expensive. If this is set we will |
| 92 | * check the first time we use a color format or a combination of color / |
| 93 | * stencil formats as attachments. If the FBO is complete we will assume |
| 94 | * subsequent attachments with the same formats are complete as well. |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 95 | * |
| 96 | * GR_GL_USE_NV_PATH_RENDERING: Enable experimental support for |
| 97 | * GL_NV_path_rendering. There are known issues with clipping, non-AA paths, and |
| 98 | * perspective. |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame^] | 99 | * |
| 100 | * GR_GL_MUST_USE_VBO: Indicates that all vertices and indices must be rendered |
| 101 | * from VBOs. Chromium's command buffer doesn't allow glVertexAttribArray with |
| 102 | * ARARY_BUFFER 0 bound or glDrawElements with ELEMENT_ARRAY_BUFFER 0 bound. |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 103 | */ |
| 104 | |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 105 | #if !defined(GR_GL_LOG_CALLS) |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 106 | #define GR_GL_LOG_CALLS GR_DEBUG |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 107 | #endif |
| 108 | |
| 109 | #if !defined(GR_GL_LOG_CALLS_START) |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 110 | #define GR_GL_LOG_CALLS_START 0 |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 111 | #endif |
| 112 | |
reed@google.com | 27a1e77 | 2011-03-08 15:34:06 +0000 | [diff] [blame] | 113 | #if !defined(GR_GL_CHECK_ERROR) |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 114 | #define GR_GL_CHECK_ERROR GR_DEBUG |
bsalomon@google.com | 3723a48 | 2011-02-17 21:47:25 +0000 | [diff] [blame] | 115 | #endif |
| 116 | |
| 117 | #if !defined(GR_GL_CHECK_ERROR_START) |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 118 | #define GR_GL_CHECK_ERROR_START 1 |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 119 | #endif |
| 120 | |
| 121 | #if !defined(GR_GL_NO_CONSTANT_ATTRIBUTES) |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 122 | #define GR_GL_NO_CONSTANT_ATTRIBUTES 0 |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 123 | #endif |
| 124 | |
bsalomon@google.com | 9ae4429 | 2011-07-01 15:21:59 +0000 | [diff] [blame] | 125 | #if !defined(GR_GL_USE_BUFFER_DATA_NULL_HINT) |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 126 | #define GR_GL_USE_BUFFER_DATA_NULL_HINT 1 |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 127 | #endif |
| 128 | |
| 129 | #if !defined(GR_GL_PER_GL_FUNC_CALLBACK) |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 130 | #define GR_GL_PER_GL_FUNC_CALLBACK 0 |
bsalomon@google.com | 9ae4429 | 2011-07-01 15:21:59 +0000 | [diff] [blame] | 131 | #endif |
| 132 | |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 133 | #if !defined(GR_GL_RGBA_8888_PIXEL_OPS_SLOW) |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 134 | #define GR_GL_RGBA_8888_PIXEL_OPS_SLOW 0 |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 135 | #endif |
| 136 | |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 137 | #if !defined(GR_GL_FULL_READPIXELS_FASTER_THAN_PARTIAL) |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 138 | #define GR_GL_FULL_READPIXELS_FASTER_THAN_PARTIAL 0 |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 139 | #endif |
| 140 | |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 141 | #if !defined(GR_GL_CHECK_ALLOC_WITH_GET_ERROR) |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 142 | #define GR_GL_CHECK_ALLOC_WITH_GET_ERROR 1 |
| 143 | #endif |
| 144 | |
| 145 | #if !defined(GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT) |
| 146 | #define GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT 0 |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 147 | #endif |
| 148 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 149 | #if !defined(GR_GL_USE_NV_PATH_RENDERING) |
| 150 | #define GR_GL_USE_NV_PATH_RENDERING 0 |
| 151 | #endif |
| 152 | |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame^] | 153 | #if !defined(GR_GL_MUST_USE_VBO) |
| 154 | #define GR_GL_MUST_USE_VBO 0 |
| 155 | #endif |
| 156 | |
bsalomon@google.com | 5ffd5ba | 2012-03-01 15:29:07 +0000 | [diff] [blame] | 157 | /** |
| 158 | * There is a strange bug that occurs on Macs with NVIDIA GPUs. We don't |
| 159 | * fully understand it. When (element) array buffers are continually |
bsalomon@google.com | c1dd888 | 2012-03-02 20:36:18 +0000 | [diff] [blame] | 160 | * respecified using glBufferData performance can fall off of a cliff. The |
| 161 | * driver winds up performing many DMA mapping / unmappings and chews up ~50% of |
| 162 | * the core. However, it has been observed that occaisonally respecifiying the |
| 163 | * buffer using glBufferData and then writing data using glBufferSubData |
| 164 | * prevents the bad behavior. |
bsalomon@google.com | 5ffd5ba | 2012-03-01 15:29:07 +0000 | [diff] [blame] | 165 | * |
| 166 | * There is a lot of uncertainty around this issue. In Chrome backgrounding |
| 167 | * the tab somehow initiates this behavior and we don't know what the connection |
| 168 | * is. Another observation is that Chrome's cmd buffer server will actually |
| 169 | * create a buffer full of zeros when it sees a NULL data param (for security |
| 170 | * reasons). If this is disabled and NULL is actually passed all the way to the |
| 171 | * driver then the workaround doesn't help. |
| 172 | * |
| 173 | * The issue is tracked at: |
| 174 | * http://code.google.com/p/chromium/issues/detail?id=114865 |
| 175 | * |
bsalomon@google.com | c1dd888 | 2012-03-02 20:36:18 +0000 | [diff] [blame] | 176 | * When the workaround is enabled we will use the glBufferData / glBufferSubData |
| 177 | * trick every 128 array buffer uploads. |
bsalomon@google.com | 5ffd5ba | 2012-03-01 15:29:07 +0000 | [diff] [blame] | 178 | * |
| 179 | * Hopefully we will understand this better and have a cleaner fix or get a |
| 180 | * OS/driver level fix. |
| 181 | */ |
| 182 | #define GR_GL_MAC_BUFFER_OBJECT_PERFOMANCE_WORKAROUND \ |
| 183 | (GR_MAC_BUILD && \ |
| 184 | !GR_GL_USE_BUFFER_DATA_NULL_HINT) |
| 185 | |
reed@google.com | 27a1e77 | 2011-03-08 15:34:06 +0000 | [diff] [blame] | 186 | #endif |