blob: e59fe553cf716228d1ca486b95ad124a2ef6cb27 [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
twiz@google.com59a190b2011-03-14 21:23:01 +00002 Copyright 2011 Google Inc.
reed@google.comac10a2d2010-12-22 21:39:39 +00003
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.com0f31ca72011-03-18 17:38:11 +000022#include "GrGLDefines.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000023
bsalomon@google.com42ab7ea2011-01-19 17:19:40 +000024/**
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000025 * Optional GL config file.
twiz@google.comb65e0cb2011-03-18 20:41:44 +000026 */
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000027#ifdef GR_GL_CUSTOM_SETUP_HEADER
28 #include GR_GL_CUSTOM_SETUP_HEADER
29#endif
30
31#if !defined(GR_GL_FUNCTION_TYPE)
32 #define GR_GL_FUNCTION_TYPE
33#endif
twiz@google.comb65e0cb2011-03-18 20:41:44 +000034
35/**
bsalomon@google.com3723a482011-02-17 21:47:25 +000036 * 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.comf987d1b2011-04-04 17:13:52 +000038 * file (if one is in use). If a GR_GL_CUSTOM_SETUP_HEADER is used they can
39 * also be placed there.
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +000040 *
bsalomon@google.com3723a482011-02-17 21:47:25 +000041 * GR_GL_LOG_CALLS: if 1 Gr can print every GL call using GrPrintf. Defaults to
reed@google.com27a1e772011-03-08 15:34:06 +000042 * 0. Logging can be enabled and disabled at runtime using a debugger via to
bsalomon@google.com3723a482011-02-17 21:47:25 +000043 * 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.com27a1e772011-03-08 15:34:06 +000050 * 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 +000051 * 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.com4be283f2011-04-19 21:15:09 +000056 *
57 * GR_GL_NO_CONSTANT_ATTRIBUTES: if this evaluates to true then the GL backend
58 * will use uniforms instead of attributes in all cases when there is not
59 * per-vertex data. This is important when the underlying GL implementation
60 * doesn't actually support immediate style attribute values (e.g. when
61 * the GL stream is converted to DX as in ANGLE on Chrome). Defaults to 0.
62 *
63 * GR_GL_ATTRIBUTE_MATRICES: If changing uniforms is very expensive it may be
64 * faster to use vertex attributes for matrices (set via glVertexAttrib3fv).
65 * Setting this build flag enables this behavior. GR_GL_NO_CONSTANT_ATTRIBUTES
66 * must not be set since this uses constant attributes for the matrices.
67 * Defaults to 0.
bsalomon@google.com9ae44292011-07-01 15:21:59 +000068 *
69 * GR_GL_USE_BUFFER_DATA_NULL_HINT: When specifing new data for a vertex/index
70 * buffer that replaces old data Ganesh can give a hint to the driver that the
71 * previous data will not be used in future draws like this:
72 * glBufferData(GL_..._BUFFER, size, NULL, usage); //<--hint, NULL means
73 * glBufferSubData(GL_..._BUFFER, 0, lessThanSize, data) // old data can't be
74 * // used again.
75 * However, this can cause a performance decrease on Chrome cmd buffer because
76 * it will create a new allocation and memset the whole thing to zero (for
77 * security reasons). Defaults to 1 (enabled).
bsalomon@google.com42ab7ea2011-01-19 17:19:40 +000078 */
79
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +000080#if !defined(GR_GL_LOG_CALLS)
bsalomon@google.com4be283f2011-04-19 21:15:09 +000081 #define GR_GL_LOG_CALLS 0
bsalomon@google.com3723a482011-02-17 21:47:25 +000082#endif
83
84#if !defined(GR_GL_LOG_CALLS_START)
bsalomon@google.com4be283f2011-04-19 21:15:09 +000085 #define GR_GL_LOG_CALLS_START 0
bsalomon@google.com3723a482011-02-17 21:47:25 +000086#endif
87
reed@google.com27a1e772011-03-08 15:34:06 +000088#if !defined(GR_GL_CHECK_ERROR)
bsalomon@google.com4be283f2011-04-19 21:15:09 +000089 #define GR_GL_CHECK_ERROR GR_DEBUG
bsalomon@google.com3723a482011-02-17 21:47:25 +000090#endif
91
92#if !defined(GR_GL_CHECK_ERROR_START)
bsalomon@google.com4be283f2011-04-19 21:15:09 +000093 #define GR_GL_CHECK_ERROR_START 1
94#endif
95
96#if !defined(GR_GL_NO_CONSTANT_ATTRIBUTES)
97 #define GR_GL_NO_CONSTANT_ATTRIBUTES 0
98#endif
99
100#if !defined(GR_GL_ATTRIBUTE_MATRICES)
101 #define GR_GL_ATTRIBUTE_MATRICES 0
102#endif
103
bsalomon@google.com9ae44292011-07-01 15:21:59 +0000104#if !defined(GR_GL_USE_BUFFER_DATA_NULL_HINT)
105 #define GR_GL_USE_BUFFER_DATA_NULL_HINT 1
106#endif
107
bsalomon@google.com4be283f2011-04-19 21:15:09 +0000108#if(GR_GL_NO_CONSTANT_ATTRIBUTES) && (GR_GL_ATTRIBUTE_MATRICES)
109 #error "Cannot combine GR_GL_NO_CONSTANT_ATTRIBUTES and GR_GL_ATTRIBUTE_MATRICES"
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +0000110#endif
111
bsalomon@google.com42ab7ea2011-01-19 17:19:40 +0000112////////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000113
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000114/**
115 * The following macros are used to staticlly configure the default
116 * GrGLInterface, but should not be used outside of the GrGLInterface
117 * scaffolding. Undefine here to prevent accidental use.
118 */
119#undef GR_SUPPORT_GLDESKTOP
120#undef GR_SUPPORT_GLES1
121#undef GR_SUPPORT_GLES2
122#undef GR_SUPPORT_GLES
123
124////////////////////////////////////////////////////////////////////////////////
125
reed@google.comac10a2d2010-12-22 21:39:39 +0000126#if GR_SCALAR_IS_FIXED
127 #define GrGLType GL_FIXED
128#elif GR_SCALAR_IS_FLOAT
twiz@google.com0f31ca72011-03-18 17:38:11 +0000129 #define GrGLType GR_GL_FLOAT
reed@google.comac10a2d2010-12-22 21:39:39 +0000130#else
131 #error "unknown GR_SCALAR type"
132#endif
133
134#if GR_TEXT_SCALAR_IS_USHORT
twiz@google.com0f31ca72011-03-18 17:38:11 +0000135 #define GrGLTextType GR_GL_UNSIGNED_SHORT
reed@google.comac10a2d2010-12-22 21:39:39 +0000136 #define GR_GL_TEXT_TEXTURE_NORMALIZED 1
137#elif GR_TEXT_SCALAR_IS_FLOAT
twiz@google.com0f31ca72011-03-18 17:38:11 +0000138 #define GrGLTextType GR_GL_FLOAT
reed@google.comac10a2d2010-12-22 21:39:39 +0000139 #define GR_GL_TEXT_TEXTURE_NORMALIZED 0
140#elif GR_TEXT_SCALAR_IS_FIXED
twiz@google.com0f31ca72011-03-18 17:38:11 +0000141 #define GrGLTextType GR_GL_FIXED
reed@google.comac10a2d2010-12-22 21:39:39 +0000142 #define GR_GL_TEXT_TEXTURE_NORMALIZED 0
reed@google.com63100f92011-01-18 21:32:14 +0000143#else
reed@google.comac10a2d2010-12-22 21:39:39 +0000144 #error "unknown GR_TEXT_SCALAR type"
145#endif
146
twiz@google.com59a190b2011-03-14 21:23:01 +0000147// Pick a pixel config for 32bit bitmaps. Our default is GL_RGBA (except on
bsalomon@google.com2fbc7fa2011-01-05 16:34:41 +0000148// Windows where we match GDI's order).
149#ifndef GR_GL_32BPP_COLOR_FORMAT
senorblanco@chromium.org99c2a8b2011-05-04 20:12:01 +0000150 #if GR_WIN32_BUILD || GR_LINUX_BUILD
bsalomon@google.comc312bf92011-03-21 21:10:33 +0000151 #define GR_GL_32BPP_COLOR_FORMAT GR_GL_BGRA
152 #else
twiz@google.com0f31ca72011-03-18 17:38:11 +0000153 #define GR_GL_32BPP_COLOR_FORMAT GR_GL_RGBA
bsalomon@google.com2fbc7fa2011-01-05 16:34:41 +0000154 #endif
reed@google.comac10a2d2010-12-22 21:39:39 +0000155#endif
156
reed@google.comac10a2d2010-12-22 21:39:39 +0000157////////////////////////////////////////////////////////////////////////////////
reed@google.com63100f92011-01-18 21:32:14 +0000158
reed@google.comac10a2d2010-12-22 21:39:39 +0000159extern void GrGLCheckErr(const char* location, const char* call);
160
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000161extern void GrGLClearErr();
reed@google.comac10a2d2010-12-22 21:39:39 +0000162
bsalomon@google.com3723a482011-02-17 21:47:25 +0000163#if GR_GL_CHECK_ERROR
164 extern bool gCheckErrorGL;
165 #define GR_GL_CHECK_ERROR_IMPL(X) if (gCheckErrorGL) GrGLCheckErr(GR_FILE_AND_LINE_STR, #X)
reed@google.comac10a2d2010-12-22 21:39:39 +0000166#else
bsalomon@google.com3723a482011-02-17 21:47:25 +0000167 #define GR_GL_CHECK_ERROR_IMPL(X)
reed@google.comac10a2d2010-12-22 21:39:39 +0000168#endif
reed@google.comac10a2d2010-12-22 21:39:39 +0000169
170#if GR_GL_LOG_CALLS
bsalomon@google.com3723a482011-02-17 21:47:25 +0000171 extern bool gLogCallsGL;
172 #define GR_GL_LOG_CALLS_IMPL(X) if (gLogCallsGL) GrPrintf(GR_FILE_AND_LINE_STR "GL: " #X "\n")
reed@google.comac10a2d2010-12-22 21:39:39 +0000173#else
bsalomon@google.com3723a482011-02-17 21:47:25 +0000174 #define GR_GL_LOG_CALLS_IMPL(X)
reed@google.comac10a2d2010-12-22 21:39:39 +0000175#endif
176
twiz@google.com59a190b2011-03-14 21:23:01 +0000177#define GR_GL(X) GrGLGetGLInterface()->f##X;; GR_GL_LOG_CALLS_IMPL(X); GR_GL_CHECK_ERROR_IMPL(X);
bsalomon@google.com9ccdb952011-04-14 17:43:23 +0000178#define GR_GL_NO_ERR(X) GrGLGetGLInterface()->f##X;; GR_GL_LOG_CALLS_IMPL(X);
bsalomon@google.com8895a7a2011-02-18 16:09:55 +0000179
twiz@google.comb65e0cb2011-03-18 20:41:44 +0000180#define GR_GL_SUPPORT_DESKTOP (kDesktop_GrGLBinding == GrGLGetGLInterface()->fBindingsExported)
181#define GR_GL_SUPPORT_ES1 (kES1_GrGLBinding == GrGLGetGLInterface()->fBindingsExported)
182#define GR_GL_SUPPORT_ES2 (kES2_GrGLBinding == GrGLGetGLInterface()->fBindingsExported)
183#define GR_GL_SUPPORT_ES (GR_GL_SUPPORT_ES1 || GR_GL_SUPPORT_ES2)
184
bsalomon@google.com8895a7a2011-02-18 16:09:55 +0000185////////////////////////////////////////////////////////////////////////////////
186
187/**
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000188 * GrGLRestoreResetRowLength() will reset GL_UNPACK_ROW_LENGTH to 0. We write
bsalomon@google.com8895a7a2011-02-18 16:09:55 +0000189 * this wrapper, since GL_UNPACK_ROW_LENGTH is not available on all GL versions
190 */
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000191extern void GrGLRestoreResetRowLength();
bsalomon@google.com8895a7a2011-02-18 16:09:55 +0000192
193////////////////////////////////////////////////////////////////////////////////
194
195/**
196 * Some drivers want the var-int arg to be zero-initialized on input.
197 */
198#define GR_GL_INIT_ZERO 0
199#define GR_GL_GetIntegerv(e, p) \
200 do { \
201 *(p) = GR_GL_INIT_ZERO; \
202 GR_GL(GetIntegerv(e, p)); \
203 } while (0)
204
205////////////////////////////////////////////////////////////////////////////////
206
reed@google.com27a1e772011-03-08 15:34:06 +0000207#endif