blob: 0502332cb4defb13721d842227a8c660f06543a6 [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.com42ab7ea2011-01-19 17:19:40 +000056 */
57
reed@google.comac10a2d2010-12-22 21:39:39 +000058
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +000059#if !defined(GR_GL_LOG_CALLS)
bsalomon@google.com3723a482011-02-17 21:47:25 +000060 #define GR_GL_LOG_CALLS 0
61#endif
62
63#if !defined(GR_GL_LOG_CALLS_START)
64 #define GR_GL_LOG_CALLS_START 0
65#endif
66
reed@google.com27a1e772011-03-08 15:34:06 +000067#if !defined(GR_GL_CHECK_ERROR)
bsalomon@google.com3723a482011-02-17 21:47:25 +000068 #define GR_GL_CHECK_ERROR GR_DEBUG
69#endif
70
71#if !defined(GR_GL_CHECK_ERROR_START)
72 #define GR_GL_CHECK_ERROR_START 1
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +000073#endif
74
bsalomon@google.com42ab7ea2011-01-19 17:19:40 +000075////////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +000076
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000077/**
78 * The following macros are used to staticlly configure the default
79 * GrGLInterface, but should not be used outside of the GrGLInterface
80 * scaffolding. Undefine here to prevent accidental use.
81 */
82#undef GR_SUPPORT_GLDESKTOP
83#undef GR_SUPPORT_GLES1
84#undef GR_SUPPORT_GLES2
85#undef GR_SUPPORT_GLES
86
87////////////////////////////////////////////////////////////////////////////////
88
reed@google.comac10a2d2010-12-22 21:39:39 +000089#if GR_SCALAR_IS_FIXED
90 #define GrGLType GL_FIXED
91#elif GR_SCALAR_IS_FLOAT
twiz@google.com0f31ca72011-03-18 17:38:11 +000092 #define GrGLType GR_GL_FLOAT
reed@google.comac10a2d2010-12-22 21:39:39 +000093#else
94 #error "unknown GR_SCALAR type"
95#endif
96
97#if GR_TEXT_SCALAR_IS_USHORT
twiz@google.com0f31ca72011-03-18 17:38:11 +000098 #define GrGLTextType GR_GL_UNSIGNED_SHORT
reed@google.comac10a2d2010-12-22 21:39:39 +000099 #define GR_GL_TEXT_TEXTURE_NORMALIZED 1
100#elif GR_TEXT_SCALAR_IS_FLOAT
twiz@google.com0f31ca72011-03-18 17:38:11 +0000101 #define GrGLTextType GR_GL_FLOAT
reed@google.comac10a2d2010-12-22 21:39:39 +0000102 #define GR_GL_TEXT_TEXTURE_NORMALIZED 0
103#elif GR_TEXT_SCALAR_IS_FIXED
twiz@google.com0f31ca72011-03-18 17:38:11 +0000104 #define GrGLTextType GR_GL_FIXED
reed@google.comac10a2d2010-12-22 21:39:39 +0000105 #define GR_GL_TEXT_TEXTURE_NORMALIZED 0
reed@google.com63100f92011-01-18 21:32:14 +0000106#else
reed@google.comac10a2d2010-12-22 21:39:39 +0000107 #error "unknown GR_TEXT_SCALAR type"
108#endif
109
twiz@google.com59a190b2011-03-14 21:23:01 +0000110// Pick a pixel config for 32bit bitmaps. Our default is GL_RGBA (except on
bsalomon@google.com2fbc7fa2011-01-05 16:34:41 +0000111// Windows where we match GDI's order).
112#ifndef GR_GL_32BPP_COLOR_FORMAT
113 #if GR_WIN32_BUILD
bsalomon@google.comc312bf92011-03-21 21:10:33 +0000114 #define GR_GL_32BPP_COLOR_FORMAT GR_GL_BGRA
115 #else
twiz@google.com0f31ca72011-03-18 17:38:11 +0000116 #define GR_GL_32BPP_COLOR_FORMAT GR_GL_RGBA
bsalomon@google.com2fbc7fa2011-01-05 16:34:41 +0000117 #endif
reed@google.comac10a2d2010-12-22 21:39:39 +0000118#endif
119
reed@google.comac10a2d2010-12-22 21:39:39 +0000120////////////////////////////////////////////////////////////////////////////////
reed@google.com63100f92011-01-18 21:32:14 +0000121
reed@google.comac10a2d2010-12-22 21:39:39 +0000122extern void GrGLCheckErr(const char* location, const char* call);
123
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000124extern void GrGLClearErr();
reed@google.comac10a2d2010-12-22 21:39:39 +0000125
bsalomon@google.com3723a482011-02-17 21:47:25 +0000126#if GR_GL_CHECK_ERROR
127 extern bool gCheckErrorGL;
128 #define GR_GL_CHECK_ERROR_IMPL(X) if (gCheckErrorGL) GrGLCheckErr(GR_FILE_AND_LINE_STR, #X)
reed@google.comac10a2d2010-12-22 21:39:39 +0000129#else
bsalomon@google.com3723a482011-02-17 21:47:25 +0000130 #define GR_GL_CHECK_ERROR_IMPL(X)
reed@google.comac10a2d2010-12-22 21:39:39 +0000131#endif
reed@google.comac10a2d2010-12-22 21:39:39 +0000132
133#if GR_GL_LOG_CALLS
bsalomon@google.com3723a482011-02-17 21:47:25 +0000134 extern bool gLogCallsGL;
135 #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 +0000136#else
bsalomon@google.com3723a482011-02-17 21:47:25 +0000137 #define GR_GL_LOG_CALLS_IMPL(X)
reed@google.comac10a2d2010-12-22 21:39:39 +0000138#endif
139
twiz@google.com59a190b2011-03-14 21:23:01 +0000140#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 +0000141#define GR_GL_NO_ERR(X) GrGLGetGLInterface()->f##X;; GR_GL_LOG_CALLS_IMPL(X);
bsalomon@google.com8895a7a2011-02-18 16:09:55 +0000142
twiz@google.comb65e0cb2011-03-18 20:41:44 +0000143#define GR_GL_SUPPORT_DESKTOP (kDesktop_GrGLBinding == GrGLGetGLInterface()->fBindingsExported)
144#define GR_GL_SUPPORT_ES1 (kES1_GrGLBinding == GrGLGetGLInterface()->fBindingsExported)
145#define GR_GL_SUPPORT_ES2 (kES2_GrGLBinding == GrGLGetGLInterface()->fBindingsExported)
146#define GR_GL_SUPPORT_ES (GR_GL_SUPPORT_ES1 || GR_GL_SUPPORT_ES2)
147
bsalomon@google.com8895a7a2011-02-18 16:09:55 +0000148////////////////////////////////////////////////////////////////////////////////
149
150/**
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000151 * GrGLRestoreResetRowLength() will reset GL_UNPACK_ROW_LENGTH to 0. We write
bsalomon@google.com8895a7a2011-02-18 16:09:55 +0000152 * this wrapper, since GL_UNPACK_ROW_LENGTH is not available on all GL versions
153 */
bsalomon@google.comf987d1b2011-04-04 17:13:52 +0000154extern void GrGLRestoreResetRowLength();
bsalomon@google.com8895a7a2011-02-18 16:09:55 +0000155
156////////////////////////////////////////////////////////////////////////////////
157
158/**
159 * Some drivers want the var-int arg to be zero-initialized on input.
160 */
161#define GR_GL_INIT_ZERO 0
162#define GR_GL_GetIntegerv(e, p) \
163 do { \
164 *(p) = GR_GL_INIT_ZERO; \
165 GR_GL(GetIntegerv(e, p)); \
166 } while (0)
167
168////////////////////////////////////////////////////////////////////////////////
169
reed@google.com27a1e772011-03-08 15:34:06 +0000170#endif