blob: 81cba1badf0e5ac970594f9ffd21345540d95f4b [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.comac10a2d2010-12-22 21:39:39 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * 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.comac10a2d2010-12-22 21:39:39 +00007 */
8
9
epoger@google.comec3ed6a2011-07-28 14:26:00 +000010
reed@google.comac10a2d2010-12-22 21:39:39 +000011#ifndef GrGLConfig_DEFINED
12#define GrGLConfig_DEFINED
13
14#include "GrTypes.h"
15
bsalomon@google.com42ab7ea2011-01-19 17:19:40 +000016/**
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000017 * Optional GL config file.
twiz@google.comb65e0cb2011-03-18 20:41:44 +000018 */
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000019#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.comb65e0cb2011-03-18 20:41:44 +000026
27/**
bsalomon@google.com3723a482011-02-17 21:47:25 +000028 * 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.comf987d1b2011-04-04 17:13:52 +000030 * file (if one is in use). If a GR_GL_CUSTOM_SETUP_HEADER is used they can
31 * also be placed there.
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +000032 *
bsalomon@google.com3723a482011-02-17 21:47:25 +000033 * GR_GL_LOG_CALLS: if 1 Gr can print every GL call using GrPrintf. Defaults to
reed@google.com27a1e772011-03-08 15:34:06 +000034 * 0. Logging can be enabled and disabled at runtime using a debugger via to
bsalomon@google.com3723a482011-02-17 21:47:25 +000035 * 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.com27a1e772011-03-08 15:34:06 +000042 * Defaults to 1 if GR_DEBUG is set, otherwise 0. When GR_GL_CHECK_ERROR is 1
bsalomon@google.com3723a482011-02-17 21:47:25 +000043 * 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.com4be283f2011-04-19 21:15:09 +000048 *
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.comfbfcd562012-08-23 18:09:54 +000052 * doesn't actually support immediate style attribute values (e.g. when
bsalomon@google.com4be283f2011-04-19 21:15:09 +000053 * the GL stream is converted to DX as in ANGLE on Chrome). Defaults to 0.
54 *
bsalomon@google.com9ae44292011-07-01 15:21:59 +000055 * 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.com96e96df2011-10-10 14:49:29 +000061 * 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.com56bfc5a2011-09-01 13:28:16 +000064 *
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.com0a97be22011-11-08 19:20:57 +000073 *
bsalomon@google.coma85449d2011-11-19 02:36:05 +000074 * 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.com56d11e02011-11-30 19:59:08 +000077 *
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.com4f3c2532012-01-19 16:16:52 +000082 *
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.com4bcb0c62012-02-07 16:06:47 +000088 *
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.comded4f4b2012-06-28 18:48:06 +000095 *
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.com96966a52013-02-21 16:34:21 +000099 *
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.com26fb61a2013-02-28 19:26:04 +0000103 *
104 * GR_GL_USE_NEW_SHADER_SOURCE_SIGNATURE is for compatibility with the new version
105 * of the OpenGLES2.0 headers from Khronos. glShaderSource now takes a const char * const *,
106 * instead of a const char
bsalomon@google.com42ab7ea2011-01-19 17:19:40 +0000107 */
108
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +0000109#if !defined(GR_GL_LOG_CALLS)
bsalomon@google.com4bcb0c62012-02-07 16:06:47 +0000110 #define GR_GL_LOG_CALLS GR_DEBUG
bsalomon@google.com3723a482011-02-17 21:47:25 +0000111#endif
112
113#if !defined(GR_GL_LOG_CALLS_START)
bsalomon@google.com4bcb0c62012-02-07 16:06:47 +0000114 #define GR_GL_LOG_CALLS_START 0
bsalomon@google.com3723a482011-02-17 21:47:25 +0000115#endif
116
reed@google.com27a1e772011-03-08 15:34:06 +0000117#if !defined(GR_GL_CHECK_ERROR)
bsalomon@google.com4bcb0c62012-02-07 16:06:47 +0000118 #define GR_GL_CHECK_ERROR GR_DEBUG
bsalomon@google.com3723a482011-02-17 21:47:25 +0000119#endif
120
121#if !defined(GR_GL_CHECK_ERROR_START)
bsalomon@google.com4bcb0c62012-02-07 16:06:47 +0000122 #define GR_GL_CHECK_ERROR_START 1
bsalomon@google.com4be283f2011-04-19 21:15:09 +0000123#endif
124
125#if !defined(GR_GL_NO_CONSTANT_ATTRIBUTES)
bsalomon@google.com4bcb0c62012-02-07 16:06:47 +0000126 #define GR_GL_NO_CONSTANT_ATTRIBUTES 0
bsalomon@google.com4be283f2011-04-19 21:15:09 +0000127#endif
128
bsalomon@google.com9ae44292011-07-01 15:21:59 +0000129#if !defined(GR_GL_USE_BUFFER_DATA_NULL_HINT)
bsalomon@google.com4bcb0c62012-02-07 16:06:47 +0000130 #define GR_GL_USE_BUFFER_DATA_NULL_HINT 1
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +0000131#endif
132
133#if !defined(GR_GL_PER_GL_FUNC_CALLBACK)
bsalomon@google.com4bcb0c62012-02-07 16:06:47 +0000134 #define GR_GL_PER_GL_FUNC_CALLBACK 0
bsalomon@google.com9ae44292011-07-01 15:21:59 +0000135#endif
136
bsalomon@google.coma85449d2011-11-19 02:36:05 +0000137#if !defined(GR_GL_RGBA_8888_PIXEL_OPS_SLOW)
bsalomon@google.com4bcb0c62012-02-07 16:06:47 +0000138 #define GR_GL_RGBA_8888_PIXEL_OPS_SLOW 0
bsalomon@google.com0a97be22011-11-08 19:20:57 +0000139#endif
140
bsalomon@google.com56d11e02011-11-30 19:59:08 +0000141#if !defined(GR_GL_FULL_READPIXELS_FASTER_THAN_PARTIAL)
bsalomon@google.com4bcb0c62012-02-07 16:06:47 +0000142 #define GR_GL_FULL_READPIXELS_FASTER_THAN_PARTIAL 0
bsalomon@google.com56d11e02011-11-30 19:59:08 +0000143#endif
144
bsalomon@google.com4f3c2532012-01-19 16:16:52 +0000145#if !defined(GR_GL_CHECK_ALLOC_WITH_GET_ERROR)
bsalomon@google.com4bcb0c62012-02-07 16:06:47 +0000146 #define GR_GL_CHECK_ALLOC_WITH_GET_ERROR 1
147#endif
148
149#if !defined(GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT)
150 #define GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT 0
bsalomon@google.com4f3c2532012-01-19 16:16:52 +0000151#endif
152
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000153#if !defined(GR_GL_USE_NV_PATH_RENDERING)
154 #define GR_GL_USE_NV_PATH_RENDERING 0
155#endif
156
bsalomon@google.com96966a52013-02-21 16:34:21 +0000157#if !defined(GR_GL_MUST_USE_VBO)
158 #define GR_GL_MUST_USE_VBO 0
159#endif
160
bsalomon@google.com26fb61a2013-02-28 19:26:04 +0000161#if !defined(GR_GL_USE_NEW_SHADER_SOURCE_SIGNATURE)
162 #define GR_GL_USE_NEW_SHADER_SOURCE_SIGNATURE 0
163#endif
164
bsalomon@google.com5ffd5ba2012-03-01 15:29:07 +0000165/**
166 * There is a strange bug that occurs on Macs with NVIDIA GPUs. We don't
167 * fully understand it. When (element) array buffers are continually
bsalomon@google.comc1dd8882012-03-02 20:36:18 +0000168 * respecified using glBufferData performance can fall off of a cliff. The
169 * driver winds up performing many DMA mapping / unmappings and chews up ~50% of
170 * the core. However, it has been observed that occaisonally respecifiying the
171 * buffer using glBufferData and then writing data using glBufferSubData
172 * prevents the bad behavior.
bsalomon@google.com5ffd5ba2012-03-01 15:29:07 +0000173 *
174 * There is a lot of uncertainty around this issue. In Chrome backgrounding
175 * the tab somehow initiates this behavior and we don't know what the connection
176 * is. Another observation is that Chrome's cmd buffer server will actually
177 * create a buffer full of zeros when it sees a NULL data param (for security
178 * reasons). If this is disabled and NULL is actually passed all the way to the
179 * driver then the workaround doesn't help.
180 *
181 * The issue is tracked at:
182 * http://code.google.com/p/chromium/issues/detail?id=114865
183 *
bsalomon@google.comc1dd8882012-03-02 20:36:18 +0000184 * When the workaround is enabled we will use the glBufferData / glBufferSubData
185 * trick every 128 array buffer uploads.
bsalomon@google.com5ffd5ba2012-03-01 15:29:07 +0000186 *
187 * Hopefully we will understand this better and have a cleaner fix or get a
188 * OS/driver level fix.
189 */
190#define GR_GL_MAC_BUFFER_OBJECT_PERFOMANCE_WORKAROUND \
191 (GR_MAC_BUILD && \
192 !GR_GL_USE_BUFFER_DATA_NULL_HINT)
193
reed@google.com27a1e772011-03-08 15:34:06 +0000194#endif