blob: 0a86e72e8ef1a32b09a760ae1c7c693c020a225c [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.com59a190b2011-03-14 21:23:01 +000022#include "GrGLInterface.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000023
bsalomon@google.com42ab7ea2011-01-19 17:19:40 +000024/**
bsalomon@google.com3723a482011-02-17 21:47:25 +000025 * The following are optional defines that can be enabled at the compiler
26 * command line, in a IDE project, in a GrUserConfig.h file, or in a GL custom
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +000027 * file (if one is in use). They don't require GR_GL_CUSTOM_SETUP or
bsalomon@google.com3723a482011-02-17 21:47:25 +000028 * setup GR_GL_CUSTOM_SETUP_HEADER to be enabled:
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +000029 *
bsalomon@google.com3723a482011-02-17 21:47:25 +000030 * GR_GL_LOG_CALLS: if 1 Gr can print every GL call using GrPrintf. Defaults to
reed@google.com27a1e772011-03-08 15:34:06 +000031 * 0. Logging can be enabled and disabled at runtime using a debugger via to
bsalomon@google.com3723a482011-02-17 21:47:25 +000032 * global gLogCallsGL. The initial value of gLogCallsGL is controlled by
33 * GR_GL_LOG_CALLS_START.
34 *
35 * GR_GL_LOG_CALLS_START: controls the initial value of gLogCallsGL when
36 * GR_GL_LOG_CALLS is 1. Defaults to 0.
37 *
38 * GR_GL_CHECK_ERROR: if enabled Gr can do a glGetError() after every GL call.
reed@google.com27a1e772011-03-08 15:34:06 +000039 * 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 +000040 * this can be toggled in a debugger using the gCheckErrorGL global. The initial
41 * value of gCheckErrorGL is controlled by by GR_GL_CHECK_ERROR_START.
42 *
43 * GR_GL_CHECK_ERROR_START: controls the initial value of gCheckErrorGL
44 * when GR_GL_CHECK_ERROR is 1. Defaults to 1.
bsalomon@google.com42ab7ea2011-01-19 17:19:40 +000045 */
46
reed@google.comac10a2d2010-12-22 21:39:39 +000047
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +000048#if !defined(GR_GL_LOG_CALLS)
bsalomon@google.com3723a482011-02-17 21:47:25 +000049 #define GR_GL_LOG_CALLS 0
50#endif
51
52#if !defined(GR_GL_LOG_CALLS_START)
53 #define GR_GL_LOG_CALLS_START 0
54#endif
55
reed@google.com27a1e772011-03-08 15:34:06 +000056#if !defined(GR_GL_CHECK_ERROR)
bsalomon@google.com3723a482011-02-17 21:47:25 +000057 #define GR_GL_CHECK_ERROR GR_DEBUG
58#endif
59
60#if !defined(GR_GL_CHECK_ERROR_START)
61 #define GR_GL_CHECK_ERROR_START 1
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +000062#endif
63
bsalomon@google.com42ab7ea2011-01-19 17:19:40 +000064////////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +000065
reed@google.comac10a2d2010-12-22 21:39:39 +000066#if GR_SCALAR_IS_FIXED
67 #define GrGLType GL_FIXED
68#elif GR_SCALAR_IS_FLOAT
69 #define GrGLType GL_FLOAT
70#else
71 #error "unknown GR_SCALAR type"
72#endif
73
74#if GR_TEXT_SCALAR_IS_USHORT
75 #define GrGLTextType GL_UNSIGNED_SHORT
76 #define GR_GL_TEXT_TEXTURE_NORMALIZED 1
77#elif GR_TEXT_SCALAR_IS_FLOAT
78 #define GrGLTextType GL_FLOAT
79 #define GR_GL_TEXT_TEXTURE_NORMALIZED 0
80#elif GR_TEXT_SCALAR_IS_FIXED
81 #define GrGLTextType GL_FIXED
82 #define GR_GL_TEXT_TEXTURE_NORMALIZED 0
reed@google.com63100f92011-01-18 21:32:14 +000083#else
reed@google.comac10a2d2010-12-22 21:39:39 +000084 #error "unknown GR_TEXT_SCALAR type"
85#endif
86
twiz@google.com59a190b2011-03-14 21:23:01 +000087// Pick a pixel config for 32bit bitmaps. Our default is GL_RGBA (except on
bsalomon@google.com2fbc7fa2011-01-05 16:34:41 +000088// Windows where we match GDI's order).
89#ifndef GR_GL_32BPP_COLOR_FORMAT
90 #if GR_WIN32_BUILD
bsalomon@google.comed3a0682011-01-18 16:54:04 +000091 #define GR_GL_32BPP_COLOR_FORMAT GR_BGRA //use GR prefix because this
92 #else //may be an extension.
bsalomon@google.com2fbc7fa2011-01-05 16:34:41 +000093 #define GR_GL_32BPP_COLOR_FORMAT GL_RGBA
94 #endif
reed@google.comac10a2d2010-12-22 21:39:39 +000095#endif
96
reed@google.comac10a2d2010-12-22 21:39:39 +000097
reed@google.comac10a2d2010-12-22 21:39:39 +000098
bsalomon@google.comed3a0682011-01-18 16:54:04 +000099// BGRA format
bsalomon@google.comed3a0682011-01-18 16:54:04 +0000100#define GR_BGRA 0x80E1
101
bsalomon@google.com3f3ffd62011-01-18 17:14:52 +0000102// FBO / stencil formats
reed@google.comac10a2d2010-12-22 21:39:39 +0000103#define GR_FRAMEBUFFER 0x8D40
104#define GR_FRAMEBUFFER_COMPLETE 0x8CD5
105#define GR_COLOR_ATTACHMENT0 0x8CE0
reed@google.com63100f92011-01-18 21:32:14 +0000106#define GR_FRAMEBUFFER_BINDING 0x8CA6
reed@google.comac10a2d2010-12-22 21:39:39 +0000107#define GR_RENDERBUFFER 0x8D41
108#define GR_STENCIL_ATTACHMENT 0x8D20
bsalomon@google.com3f3ffd62011-01-18 17:14:52 +0000109#define GR_STENCIL_INDEX4 0x8D47
reed@google.comac10a2d2010-12-22 21:39:39 +0000110#define GR_STENCIL_INDEX8 0x8D48
111#define GR_STENCIL_INDEX16 0x8D49
bsalomon@google.com3f3ffd62011-01-18 17:14:52 +0000112#define GR_DEPTH24_STENCIL8 0x88F0
reed@google.comac10a2d2010-12-22 21:39:39 +0000113#define GR_MAX_RENDERBUFFER_SIZE 0x84E8
114#define GR_DEPTH_STENCIL_ATTACHMENT 0x821A
reed@google.comac10a2d2010-12-22 21:39:39 +0000115#define GR_DEPTH_STENCIL 0x84F9
116#define GR_RGBA8 0x8058
117#define GR_RGB565 0x8D62
118
119
120// Multisampling
121
122// IMG MAX_SAMPLES uses a different value than desktop, Apple ES extension.
123#define GR_MAX_SAMPLES 0x8D57
124#define GR_MAX_SAMPLES_IMG 0x9135
125#define GR_READ_FRAMEBUFFER 0x8CA8
126#define GR_DRAW_FRAMEBUFFER 0x8CA9
127
128// Buffer mapping
129#define GR_WRITE_ONLY 0x88B9
130#define GR_BUFFER_MAPPED 0x88BC
131
132// Palette texture
133#define GR_PALETTE8_RGBA8 0x8B91
134
reed@google.comac10a2d2010-12-22 21:39:39 +0000135////////////////////////////////////////////////////////////////////////////////
reed@google.com63100f92011-01-18 21:32:14 +0000136
reed@google.comac10a2d2010-12-22 21:39:39 +0000137extern void GrGLCheckErr(const char* location, const char* call);
138
139static inline void GrGLClearErr() {
twiz@google.com59a190b2011-03-14 21:23:01 +0000140 while (GL_NO_ERROR != GrGLGetGLInterface()->fGetError()) {}
reed@google.comac10a2d2010-12-22 21:39:39 +0000141}
142
bsalomon@google.com3723a482011-02-17 21:47:25 +0000143#if GR_GL_CHECK_ERROR
144 extern bool gCheckErrorGL;
145 #define GR_GL_CHECK_ERROR_IMPL(X) if (gCheckErrorGL) GrGLCheckErr(GR_FILE_AND_LINE_STR, #X)
reed@google.comac10a2d2010-12-22 21:39:39 +0000146#else
bsalomon@google.com3723a482011-02-17 21:47:25 +0000147 #define GR_GL_CHECK_ERROR_IMPL(X)
reed@google.comac10a2d2010-12-22 21:39:39 +0000148#endif
reed@google.comac10a2d2010-12-22 21:39:39 +0000149
150#if GR_GL_LOG_CALLS
bsalomon@google.com3723a482011-02-17 21:47:25 +0000151 extern bool gLogCallsGL;
152 #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 +0000153#else
bsalomon@google.com3723a482011-02-17 21:47:25 +0000154 #define GR_GL_LOG_CALLS_IMPL(X)
reed@google.comac10a2d2010-12-22 21:39:39 +0000155#endif
156
twiz@google.com59a190b2011-03-14 21:23:01 +0000157#define GR_GL(X) GrGLGetGLInterface()->f##X;; GR_GL_LOG_CALLS_IMPL(X); GR_GL_CHECK_ERROR_IMPL(X);
158#define GR_GL_NO_ERR(X) GrGLGetGLInterface()->f##X;; GR_GL_LOG_CALLS_IMPL(X); GR_GL_CHECK_ERROR_IMPL(X);
bsalomon@google.com8895a7a2011-02-18 16:09:55 +0000159
160////////////////////////////////////////////////////////////////////////////////
161
162/**
163 * GrGL_RestoreResetRowLength() will reset GL_UNPACK_ROW_LENGTH to 0. We write
164 * this wrapper, since GL_UNPACK_ROW_LENGTH is not available on all GL versions
165 */
166#if GR_SUPPORT_GLDESKTOP
167 static inline void GrGL_RestoreResetRowLength() {
168 GR_GL(PixelStorei(GL_UNPACK_ROW_LENGTH, 0));
169 }
170#else
171 #define GrGL_RestoreResetRowLength()
172#endif
173
174////////////////////////////////////////////////////////////////////////////////
175
176/**
177 * Some drivers want the var-int arg to be zero-initialized on input.
178 */
179#define GR_GL_INIT_ZERO 0
180#define GR_GL_GetIntegerv(e, p) \
181 do { \
182 *(p) = GR_GL_INIT_ZERO; \
183 GR_GL(GetIntegerv(e, p)); \
184 } while (0)
185
186////////////////////////////////////////////////////////////////////////////////
187
reed@google.com27a1e772011-03-08 15:34:06 +0000188#endif