blob: 0d18db1591c0c0a1f626b17d5f4f08e858a34b76 [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
2 Copyright 2010 Google Inc.
3
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"
22
reed@google.com63100f92011-01-18 21:32:14 +000023#if GR_CHROME_BUILD // temporary build-flag, orthogonal to mac/win/linux
24 #define GR_INCLUDE_GLES2 <GLES2/gl2.h>
25 #define GR_INCLUDE_GLES2ext <GLES2/gl2ext.h>
26 #define GR_GL_FUNC
27#elif GR_WIN32_BUILD
reed@google.comac10a2d2010-12-22 21:39:39 +000028 // glew has to be included before gl
29 #define GR_INCLUDE_GLDESKTOP <GL/glew.h>
30 #define GR_INCLUDE_GLDESKTOPext <GL/gl.h>
31 #define GR_GL_FUNC __stdcall
32 // undo stupid windows defines
33 #undef near
34 #undef far
35#elif GR_MAC_BUILD
36 #define GR_INCLUDE_GLDESKTOP <OpenGL/gl.h>
37 #define GR_INCLUDE_GLDESKTOPext <OpenGL/glext.h>
38 #define GR_GL_FUNC
39#elif GR_IOS_BUILD
40 #define GR_INCLUDE_GLES1 <OpenGLES/ES1/gl.h>
41 #define GR_INCLUDE_GLES1ext <OpenGLES/ES1/glext.h>
42 #define GR_INCLUDE_GLES2 <OpenGLES/ES2/gl.h>
43 #define GR_INCLUDE_GLES2ext <OpenGLES/ES2/glext.h>
44 #define GR_GL_FUNC
45#elif GR_ANDROID_BUILD
46 #ifndef GL_GLEXT_PROTOTYPES
47 #define GL_GLEXT_PROTOTYPES
48 #endif
49 #define GR_INCLUDE_GLES2 <GLES2/gl2.h>
50 #define GR_INCLUDE_GLES2ext <GLES2/gl2ext.h>
51 #define GR_GL_FUNC
52#elif GR_LINUX_BUILD
53 // need to distinguish between ES and Deskop versions for linux
54 #ifndef GL_GLEXT_PROTOTYPES
55 #define GL_GLEXT_PROTOTYPES
56 #endif
reed@google.com37df17d2010-12-23 20:20:51 +000057 #define GR_INCLUDE_GLDESKTOP <GL/gl.h>
58 #define GR_INCLUDE_GLDESKTOPext <GL/glext.h>
59// #define GR_INCLUDE_GLES1 <GLES/gl.h>
60// #define GR_INCLUDE_GLES1ext <GLES/glext.h>
61// #define GR_INCLUDE_GLES2 <GLES2/gl2.h>
62// #define GR_INCLUDE_GLES2ext <GLES2/gl2ext.h>
reed@google.comac10a2d2010-12-22 21:39:39 +000063 #define GR_GL_FUNC
64#elif GR_QNX_BUILD
65 #ifndef GL_GLEXT_PROTOTYPES
66 #define GL_GLEXT_PROTOTYPES
67 #endif
68 // This is needed by the QNX GLES2 headers
69 #define GL_API_EXT
70 #define GR_INCLUDE_GLES2 <GLES2/gl2.h>
71 #define GR_INCLUDE_GLES2ext <GLES2/gl2ext.h>
72 #define GR_INCLUDE_EGL <EGL/egl.h>
73 #define GR_GL_FUNC
74#else
75 #error "unsupported GR_???_BUILD"
76#endif
77
78// Ensure we're at least defined
79//
80
81#ifndef GR_SUPPORT_GLES1
82 #if defined(GR_INCLUDE_GLES1)
83 #define GR_SUPPORT_GLES1 1
84 #else
85 #define GR_SUPPORT_GLES1 0
86 #endif
87#endif
88
89#ifndef GR_SUPPORT_GLES2
90 #if defined(GR_INCLUDE_GLES2)
91 #define GR_SUPPORT_GLES2 1
92 #else
93 #define GR_SUPPORT_GLES2 0
94 #endif
95#endif
96
bsalomon@google.com8531c1c2011-01-13 19:52:45 +000097#define GR_SUPPORT_GLES (GR_SUPPORT_GLES1 || GR_SUPPORT_GLES2)
98
reed@google.comac10a2d2010-12-22 21:39:39 +000099#ifndef GR_SUPPORT_GLDESKTOP
100 #if defined(GR_INCLUDE_GLDESKTOP)
101 #define GR_SUPPORT_GLDESKTOP 1
102 #else
103 #define GR_SUPPORT_GLDESKTOP 0
104 #endif
105#endif
106
107#ifndef GR_SUPPORT_EGL
108 #if defined(GR_INCLUDE_EGL)
109 #define GR_SUPPORT_EGL 1
110 #else
111 #define GR_SUPPORT_EGL 0
112 #endif
113#endif
114// Filter the includes based on what we support
115//
116
117#if !GR_SUPPORT_GLES1
118 #undef GR_INCLUDE_GLES1
119 #undef GR_INCLUDE_GLES1ext
120#endif
121
122#if !GR_SUPPORT_GLES2
123 #undef GR_INCLUDE_GLES2
124 #undef GR_INCLUDE_GLES2ext
125#endif
126
127#if !GR_SUPPORT_GLDESKTOP
128 #undef GR_INCLUDE_GLDESKTOP
129 #undef GR_INCLUDE_GLDESKTOPext
130#endif
131
132#if !GR_SUPPORT_EGL
133 #undef GR_INCLUDE_EGL
134#endif
135
136// Begin including GL headers
137//
138
139#ifdef GR_INCLUDE_GLES1
140 #include GR_INCLUDE_GLES1
141#endif
142#ifdef GR_INCLUDE_GLES1ext
143 #include GR_INCLUDE_GLES1ext
144#endif
145#ifdef GR_INCLUDE_GLES2
146 #include GR_INCLUDE_GLES2
147#endif
148#ifdef GR_INCLUDE_GLES2ext
149 #include GR_INCLUDE_GLES2ext
150#endif
151#ifdef GR_INCLUDE_GLDESKTOP
152 #include GR_INCLUDE_GLDESKTOP
153#endif
154#ifdef GR_INCLUDE_GLDESKTOPext
155 #include GR_INCLUDE_GLDESKTOPext
156#endif
157#ifdef GR_INCLUDE_EGL
158 #include GR_INCLUDE_EGL
159#endif
160
161//
162// End including GL headers
163
reed@google.comac10a2d2010-12-22 21:39:39 +0000164#if GR_SCALAR_IS_FIXED
165 #define GrGLType GL_FIXED
166#elif GR_SCALAR_IS_FLOAT
167 #define GrGLType GL_FLOAT
168#else
169 #error "unknown GR_SCALAR type"
170#endif
171
172#if GR_TEXT_SCALAR_IS_USHORT
173 #define GrGLTextType GL_UNSIGNED_SHORT
174 #define GR_GL_TEXT_TEXTURE_NORMALIZED 1
175#elif GR_TEXT_SCALAR_IS_FLOAT
176 #define GrGLTextType GL_FLOAT
177 #define GR_GL_TEXT_TEXTURE_NORMALIZED 0
178#elif GR_TEXT_SCALAR_IS_FIXED
179 #define GrGLTextType GL_FIXED
180 #define GR_GL_TEXT_TEXTURE_NORMALIZED 0
reed@google.com63100f92011-01-18 21:32:14 +0000181#else
reed@google.comac10a2d2010-12-22 21:39:39 +0000182 #error "unknown GR_TEXT_SCALAR type"
183#endif
184
bsalomon@google.com2fbc7fa2011-01-05 16:34:41 +0000185// Pick a pixel config for 32bit bitmaps. Our default is GL_RGBA (expect on
186// Windows where we match GDI's order).
187#ifndef GR_GL_32BPP_COLOR_FORMAT
188 #if GR_WIN32_BUILD
bsalomon@google.comed3a0682011-01-18 16:54:04 +0000189 #define GR_GL_32BPP_COLOR_FORMAT GR_BGRA //use GR prefix because this
190 #else //may be an extension.
bsalomon@google.com2fbc7fa2011-01-05 16:34:41 +0000191 #define GR_GL_32BPP_COLOR_FORMAT GL_RGBA
192 #endif
reed@google.comac10a2d2010-12-22 21:39:39 +0000193#endif
194
195////////////////////////////////////////////////////////////////////////////////
196// setup for opengl ES/desktop extensions
197// we make a struct of function pointers so that each GL context
reed@google.com63100f92011-01-18 21:32:14 +0000198// can have it's own struct. (Some environments may have different proc
reed@google.comac10a2d2010-12-22 21:39:39 +0000199// addresses for different contexts).
200
201extern "C" {
202struct GrGLExts {
203// FBO
204 GLvoid (GR_GL_FUNC *GenFramebuffers)(GLsizei n, GLuint *framebuffers);
205 GLvoid (GR_GL_FUNC *BindFramebuffer)(GLenum target, GLuint framebuffer);
206 GLvoid (GR_GL_FUNC *FramebufferTexture2D)(GLenum target, GLenum attachment,
reed@google.com63100f92011-01-18 21:32:14 +0000207 GLenum textarget, GLuint texture,
reed@google.comac10a2d2010-12-22 21:39:39 +0000208 GLint level);
209 GLenum (GR_GL_FUNC *CheckFramebufferStatus)(GLenum target);
reed@google.com63100f92011-01-18 21:32:14 +0000210 GLvoid (GR_GL_FUNC *DeleteFramebuffers)(GLsizei n, const
reed@google.comac10a2d2010-12-22 21:39:39 +0000211 GLuint *framebuffers);
reed@google.com63100f92011-01-18 21:32:14 +0000212 GLvoid (GR_GL_FUNC *RenderbufferStorage)(GLenum target,
reed@google.comac10a2d2010-12-22 21:39:39 +0000213 GLenum internalformat,
214 GLsizei width, GLsizei height);
215 GLvoid (GR_GL_FUNC *GenRenderbuffers)(GLsizei n, GLuint *renderbuffers);
reed@google.com63100f92011-01-18 21:32:14 +0000216 GLvoid (GR_GL_FUNC *DeleteRenderbuffers)(GLsizei n,
reed@google.comac10a2d2010-12-22 21:39:39 +0000217 const GLuint *renderbuffers);
reed@google.com63100f92011-01-18 21:32:14 +0000218 GLvoid (GR_GL_FUNC *FramebufferRenderbuffer)(GLenum target,
reed@google.comac10a2d2010-12-22 21:39:39 +0000219 GLenum attachment,
reed@google.com63100f92011-01-18 21:32:14 +0000220 GLenum renderbuffertarget,
reed@google.comac10a2d2010-12-22 21:39:39 +0000221 GLuint renderbuffer);
222 GLvoid (GR_GL_FUNC *BindRenderbuffer)(GLenum target, GLuint renderbuffer);
223
224// Multisampling
225 // same prototype for ARB_FBO, EXT_FBO, GL 3.0, & Apple ES extension
reed@google.com63100f92011-01-18 21:32:14 +0000226 GLvoid (GR_GL_FUNC *RenderbufferStorageMultisample)(GLenum target,
reed@google.comac10a2d2010-12-22 21:39:39 +0000227 GLsizei samples,
228 GLenum internalformat,
reed@google.com63100f92011-01-18 21:32:14 +0000229 GLsizei width,
reed@google.comac10a2d2010-12-22 21:39:39 +0000230 GLsizei height);
231 // desktop: ext_fbo_blit, arb_fbo, gl 3.0
reed@google.com63100f92011-01-18 21:32:14 +0000232 GLvoid (GR_GL_FUNC *BlitFramebuffer)(GLint srcX0, GLint srcY0,
reed@google.comac10a2d2010-12-22 21:39:39 +0000233 GLint srcX1, GLint srcY1,
reed@google.com63100f92011-01-18 21:32:14 +0000234 GLint dstX0, GLint dstY0,
reed@google.comac10a2d2010-12-22 21:39:39 +0000235 GLint dstX1, GLint dstY1,
236 GLbitfield mask, GLenum filter);
237 // apple's es extension
238 GLvoid (GR_GL_FUNC *ResolveMultisampleFramebuffer)();
239
240 // IMG'e es extension
reed@google.com63100f92011-01-18 21:32:14 +0000241 GLvoid (GR_GL_FUNC *FramebufferTexture2DMultisample)(GLenum target,
reed@google.comac10a2d2010-12-22 21:39:39 +0000242 GLenum attachment,
reed@google.com63100f92011-01-18 21:32:14 +0000243 GLenum textarget,
244 GLuint texture,
245 GLint level,
reed@google.comac10a2d2010-12-22 21:39:39 +0000246 GLsizei samples);
247
248// Buffer mapping (extension in ES).
249 GLvoid* (GR_GL_FUNC *MapBuffer)(GLenum target, GLenum access);
250 GLboolean (GR_GL_FUNC *UnmapBuffer)(GLenum target);
251};
252}
253
bsalomon@google.comed3a0682011-01-18 16:54:04 +0000254// BGRA format
255
256#define GR_BGRA 0x80E1
257
bsalomon@google.com3f3ffd62011-01-18 17:14:52 +0000258// FBO / stencil formats
reed@google.comac10a2d2010-12-22 21:39:39 +0000259#define GR_FRAMEBUFFER 0x8D40
260#define GR_FRAMEBUFFER_COMPLETE 0x8CD5
261#define GR_COLOR_ATTACHMENT0 0x8CE0
reed@google.com63100f92011-01-18 21:32:14 +0000262#define GR_FRAMEBUFFER_BINDING 0x8CA6
reed@google.comac10a2d2010-12-22 21:39:39 +0000263#define GR_RENDERBUFFER 0x8D41
264#define GR_STENCIL_ATTACHMENT 0x8D20
bsalomon@google.com3f3ffd62011-01-18 17:14:52 +0000265#define GR_STENCIL_INDEX4 0x8D47
reed@google.comac10a2d2010-12-22 21:39:39 +0000266#define GR_STENCIL_INDEX8 0x8D48
267#define GR_STENCIL_INDEX16 0x8D49
bsalomon@google.com3f3ffd62011-01-18 17:14:52 +0000268#define GR_DEPTH24_STENCIL8 0x88F0
reed@google.comac10a2d2010-12-22 21:39:39 +0000269#define GR_MAX_RENDERBUFFER_SIZE 0x84E8
270#define GR_DEPTH_STENCIL_ATTACHMENT 0x821A
reed@google.comac10a2d2010-12-22 21:39:39 +0000271#define GR_DEPTH_STENCIL 0x84F9
272#define GR_RGBA8 0x8058
273#define GR_RGB565 0x8D62
274
275
276// Multisampling
277
278// IMG MAX_SAMPLES uses a different value than desktop, Apple ES extension.
279#define GR_MAX_SAMPLES 0x8D57
280#define GR_MAX_SAMPLES_IMG 0x9135
281#define GR_READ_FRAMEBUFFER 0x8CA8
282#define GR_DRAW_FRAMEBUFFER 0x8CA9
283
284// Buffer mapping
285#define GR_WRITE_ONLY 0x88B9
286#define GR_BUFFER_MAPPED 0x88BC
287
288// Palette texture
289#define GR_PALETTE8_RGBA8 0x8B91
290
291extern void GrGLInitExtensions(GrGLExts* exts);
292////////////////////////////////////////////////////////////////////////////////
reed@google.com63100f92011-01-18 21:32:14 +0000293
reed@google.comac10a2d2010-12-22 21:39:39 +0000294extern void GrGLCheckErr(const char* location, const char* call);
295
296static inline void GrGLClearErr() {
reed@google.com63100f92011-01-18 21:32:14 +0000297 while (GL_NO_ERROR != glGetError()) {}
reed@google.comac10a2d2010-12-22 21:39:39 +0000298}
299
300// GR_FORCE_GLCHECKERR can be defined by GrUserConfig.h
301#if defined(GR_FORCE_GLCHECKERR)
302 #define GR_LOCAL_CALL_CHECKERR GR_FORCE_GLCHECKERR
303#else
304 #define GR_LOCAL_CALL_CHECKERR GR_DEBUG
305#endif
306static inline void GrDebugGLCheckErr(const char* location, const char* call) {
307#if GR_LOCAL_CALL_CHECKERR
308 GrGLCheckErr(location, call);
309#endif
310}
311#undef GR_LOCAL_CALL_CHECKERR
312
313#if GR_GL_LOG_CALLS
314 extern bool gPrintGL;
315 #define GR_GL(X) gl ## X; GrDebugGLCheckErr(GR_FILE_AND_LINE_STR, #X); if (gPrintGL) GrPrintf(GR_FILE_AND_LINE_STR "GL: " #X "\n")
316 #define GR_GL_NO_ERR(X) GrGLClearErr(); gl ## X; if (gPrintGL) GrPrintf(GR_FILE_AND_LINE_STR "GL: " #X "\n")
317 #define GR_GLEXT(exts, X) exts. X; GrDebugGLCheckErr(GR_FILE_AND_LINE_STR, #X); if (gPrintGL) GrPrintf(GR_FILE_AND_LINE_STR "GL: " #X "\n")
318 #define GR_GLEXT_NO_ERR(exts, X) GrGLClearErr(); exts. X; if (gPrintGL) GrPrintf(GR_FILE_AND_LINE_STR "GL: " #X "\n")
319#else
320 #define GR_GL(X) gl ## X; GrDebugGLCheckErr(GR_FILE_AND_LINE_STR, #X)
321 #define GR_GL_NO_ERR(X) GrGLClearErr(); gl ## X
322 #define GR_GLEXT(exts, X) exts. X; GrDebugGLCheckErr(GR_FILE_AND_LINE_STR, #X)
323 #define GR_GLEXT_NO_ERR(exts, X) GrGLClearErr(); exts. X
324#endif
325
326#endif
327