blob: 3c1c5971fab447038a54ff1031c8cd5028a82258 [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"
twiz@google.com0f31ca72011-03-18 17:38:11 +000023#include "GrGLDefines.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000024
bsalomon@google.com42ab7ea2011-01-19 17:19:40 +000025/**
bsalomon@google.com3723a482011-02-17 21:47:25 +000026 * The following are optional defines that can be enabled at the compiler
27 * command line, in a IDE project, in a GrUserConfig.h file, or in a GL custom
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +000028 * file (if one is in use). They don't require GR_GL_CUSTOM_SETUP or
bsalomon@google.com3723a482011-02-17 21:47:25 +000029 * setup GR_GL_CUSTOM_SETUP_HEADER to be enabled:
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +000030 *
bsalomon@google.com3723a482011-02-17 21:47:25 +000031 * GR_GL_LOG_CALLS: if 1 Gr can print every GL call using GrPrintf. Defaults to
reed@google.com27a1e772011-03-08 15:34:06 +000032 * 0. Logging can be enabled and disabled at runtime using a debugger via to
bsalomon@google.com3723a482011-02-17 21:47:25 +000033 * global gLogCallsGL. The initial value of gLogCallsGL is controlled by
34 * GR_GL_LOG_CALLS_START.
35 *
36 * GR_GL_LOG_CALLS_START: controls the initial value of gLogCallsGL when
37 * GR_GL_LOG_CALLS is 1. Defaults to 0.
38 *
39 * GR_GL_CHECK_ERROR: if enabled Gr can do a glGetError() after every GL call.
reed@google.com27a1e772011-03-08 15:34:06 +000040 * 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 +000041 * this can be toggled in a debugger using the gCheckErrorGL global. The initial
42 * value of gCheckErrorGL is controlled by by GR_GL_CHECK_ERROR_START.
43 *
44 * GR_GL_CHECK_ERROR_START: controls the initial value of gCheckErrorGL
45 * when GR_GL_CHECK_ERROR is 1. Defaults to 1.
bsalomon@google.com42ab7ea2011-01-19 17:19:40 +000046 */
47
reed@google.comac10a2d2010-12-22 21:39:39 +000048
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +000049#if !defined(GR_GL_LOG_CALLS)
bsalomon@google.com3723a482011-02-17 21:47:25 +000050 #define GR_GL_LOG_CALLS 0
51#endif
52
53#if !defined(GR_GL_LOG_CALLS_START)
54 #define GR_GL_LOG_CALLS_START 0
55#endif
56
reed@google.com27a1e772011-03-08 15:34:06 +000057#if !defined(GR_GL_CHECK_ERROR)
bsalomon@google.com3723a482011-02-17 21:47:25 +000058 #define GR_GL_CHECK_ERROR GR_DEBUG
59#endif
60
61#if !defined(GR_GL_CHECK_ERROR_START)
62 #define GR_GL_CHECK_ERROR_START 1
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +000063#endif
64
bsalomon@google.com42ab7ea2011-01-19 17:19:40 +000065////////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +000066
reed@google.comac10a2d2010-12-22 21:39:39 +000067#if GR_SCALAR_IS_FIXED
68 #define GrGLType GL_FIXED
69#elif GR_SCALAR_IS_FLOAT
twiz@google.com0f31ca72011-03-18 17:38:11 +000070 #define GrGLType GR_GL_FLOAT
reed@google.comac10a2d2010-12-22 21:39:39 +000071#else
72 #error "unknown GR_SCALAR type"
73#endif
74
75#if GR_TEXT_SCALAR_IS_USHORT
twiz@google.com0f31ca72011-03-18 17:38:11 +000076 #define GrGLTextType GR_GL_UNSIGNED_SHORT
reed@google.comac10a2d2010-12-22 21:39:39 +000077 #define GR_GL_TEXT_TEXTURE_NORMALIZED 1
78#elif GR_TEXT_SCALAR_IS_FLOAT
twiz@google.com0f31ca72011-03-18 17:38:11 +000079 #define GrGLTextType GR_GL_FLOAT
reed@google.comac10a2d2010-12-22 21:39:39 +000080 #define GR_GL_TEXT_TEXTURE_NORMALIZED 0
81#elif GR_TEXT_SCALAR_IS_FIXED
twiz@google.com0f31ca72011-03-18 17:38:11 +000082 #define GrGLTextType GR_GL_FIXED
reed@google.comac10a2d2010-12-22 21:39:39 +000083 #define GR_GL_TEXT_TEXTURE_NORMALIZED 0
reed@google.com63100f92011-01-18 21:32:14 +000084#else
reed@google.comac10a2d2010-12-22 21:39:39 +000085 #error "unknown GR_TEXT_SCALAR type"
86#endif
87
twiz@google.com59a190b2011-03-14 21:23:01 +000088// Pick a pixel config for 32bit bitmaps. Our default is GL_RGBA (except on
bsalomon@google.com2fbc7fa2011-01-05 16:34:41 +000089// Windows where we match GDI's order).
90#ifndef GR_GL_32BPP_COLOR_FORMAT
91 #if GR_WIN32_BUILD
bsalomon@google.comed3a0682011-01-18 16:54:04 +000092 #define GR_GL_32BPP_COLOR_FORMAT GR_BGRA //use GR prefix because this
93 #else //may be an extension.
twiz@google.com0f31ca72011-03-18 17:38:11 +000094 #define GR_GL_32BPP_COLOR_FORMAT GR_GL_RGBA
bsalomon@google.com2fbc7fa2011-01-05 16:34:41 +000095 #endif
reed@google.comac10a2d2010-12-22 21:39:39 +000096#endif
97
reed@google.comac10a2d2010-12-22 21:39:39 +000098
reed@google.comac10a2d2010-12-22 21:39:39 +000099
bsalomon@google.comed3a0682011-01-18 16:54:04 +0000100// BGRA format
bsalomon@google.comed3a0682011-01-18 16:54:04 +0000101#define GR_BGRA 0x80E1
102
bsalomon@google.com3f3ffd62011-01-18 17:14:52 +0000103// FBO / stencil formats
reed@google.comac10a2d2010-12-22 21:39:39 +0000104#define GR_FRAMEBUFFER 0x8D40
105#define GR_FRAMEBUFFER_COMPLETE 0x8CD5
106#define GR_COLOR_ATTACHMENT0 0x8CE0
reed@google.com63100f92011-01-18 21:32:14 +0000107#define GR_FRAMEBUFFER_BINDING 0x8CA6
reed@google.comac10a2d2010-12-22 21:39:39 +0000108#define GR_RENDERBUFFER 0x8D41
109#define GR_STENCIL_ATTACHMENT 0x8D20
bsalomon@google.com3f3ffd62011-01-18 17:14:52 +0000110#define GR_STENCIL_INDEX4 0x8D47
reed@google.comac10a2d2010-12-22 21:39:39 +0000111#define GR_STENCIL_INDEX8 0x8D48
112#define GR_STENCIL_INDEX16 0x8D49
bsalomon@google.com3f3ffd62011-01-18 17:14:52 +0000113#define GR_DEPTH24_STENCIL8 0x88F0
reed@google.comac10a2d2010-12-22 21:39:39 +0000114#define GR_MAX_RENDERBUFFER_SIZE 0x84E8
115#define GR_DEPTH_STENCIL_ATTACHMENT 0x821A
reed@google.comac10a2d2010-12-22 21:39:39 +0000116#define GR_DEPTH_STENCIL 0x84F9
117#define GR_RGBA8 0x8058
118#define GR_RGB565 0x8D62
119
120
121// Multisampling
122
123// IMG MAX_SAMPLES uses a different value than desktop, Apple ES extension.
124#define GR_MAX_SAMPLES 0x8D57
125#define GR_MAX_SAMPLES_IMG 0x9135
126#define GR_READ_FRAMEBUFFER 0x8CA8
127#define GR_DRAW_FRAMEBUFFER 0x8CA9
128
129// Buffer mapping
130#define GR_WRITE_ONLY 0x88B9
131#define GR_BUFFER_MAPPED 0x88BC
132
133// Palette texture
134#define GR_PALETTE8_RGBA8 0x8B91
135
reed@google.comac10a2d2010-12-22 21:39:39 +0000136////////////////////////////////////////////////////////////////////////////////
reed@google.com63100f92011-01-18 21:32:14 +0000137
reed@google.comac10a2d2010-12-22 21:39:39 +0000138extern void GrGLCheckErr(const char* location, const char* call);
139
140static inline void GrGLClearErr() {
twiz@google.com0f31ca72011-03-18 17:38:11 +0000141 while (GR_GL_NO_ERROR != GrGLGetGLInterface()->fGetError()) {}
reed@google.comac10a2d2010-12-22 21:39:39 +0000142}
143
bsalomon@google.com3723a482011-02-17 21:47:25 +0000144#if GR_GL_CHECK_ERROR
145 extern bool gCheckErrorGL;
146 #define GR_GL_CHECK_ERROR_IMPL(X) if (gCheckErrorGL) GrGLCheckErr(GR_FILE_AND_LINE_STR, #X)
reed@google.comac10a2d2010-12-22 21:39:39 +0000147#else
bsalomon@google.com3723a482011-02-17 21:47:25 +0000148 #define GR_GL_CHECK_ERROR_IMPL(X)
reed@google.comac10a2d2010-12-22 21:39:39 +0000149#endif
reed@google.comac10a2d2010-12-22 21:39:39 +0000150
151#if GR_GL_LOG_CALLS
bsalomon@google.com3723a482011-02-17 21:47:25 +0000152 extern bool gLogCallsGL;
153 #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 +0000154#else
bsalomon@google.com3723a482011-02-17 21:47:25 +0000155 #define GR_GL_LOG_CALLS_IMPL(X)
reed@google.comac10a2d2010-12-22 21:39:39 +0000156#endif
157
twiz@google.com59a190b2011-03-14 21:23:01 +0000158#define GR_GL(X) GrGLGetGLInterface()->f##X;; GR_GL_LOG_CALLS_IMPL(X); GR_GL_CHECK_ERROR_IMPL(X);
159#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 +0000160
161////////////////////////////////////////////////////////////////////////////////
162
163/**
164 * GrGL_RestoreResetRowLength() will reset GL_UNPACK_ROW_LENGTH to 0. We write
165 * this wrapper, since GL_UNPACK_ROW_LENGTH is not available on all GL versions
166 */
167#if GR_SUPPORT_GLDESKTOP
168 static inline void GrGL_RestoreResetRowLength() {
twiz@google.com0f31ca72011-03-18 17:38:11 +0000169 GR_GL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0));
bsalomon@google.com8895a7a2011-02-18 16:09:55 +0000170 }
171#else
172 #define GrGL_RestoreResetRowLength()
173#endif
174
175////////////////////////////////////////////////////////////////////////////////
176
177/**
178 * Some drivers want the var-int arg to be zero-initialized on input.
179 */
180#define GR_GL_INIT_ZERO 0
181#define GR_GL_GetIntegerv(e, p) \
182 do { \
183 *(p) = GR_GL_INIT_ZERO; \
184 GR_GL(GetIntegerv(e, p)); \
185 } while (0)
186
187////////////////////////////////////////////////////////////////////////////////
188
reed@google.com27a1e772011-03-08 15:34:06 +0000189#endif