blob: b1838924723444140a82190859c7e4eacc1b56db [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
23#if GR_WIN32_BUILD
24 // glew has to be included before gl
25 #define GR_INCLUDE_GLDESKTOP <GL/glew.h>
26 #define GR_INCLUDE_GLDESKTOPext <GL/gl.h>
27 #define GR_GL_FUNC __stdcall
28 // undo stupid windows defines
29 #undef near
30 #undef far
31#elif GR_MAC_BUILD
32 #define GR_INCLUDE_GLDESKTOP <OpenGL/gl.h>
33 #define GR_INCLUDE_GLDESKTOPext <OpenGL/glext.h>
34 #define GR_GL_FUNC
35#elif GR_IOS_BUILD
36 #define GR_INCLUDE_GLES1 <OpenGLES/ES1/gl.h>
37 #define GR_INCLUDE_GLES1ext <OpenGLES/ES1/glext.h>
38 #define GR_INCLUDE_GLES2 <OpenGLES/ES2/gl.h>
39 #define GR_INCLUDE_GLES2ext <OpenGLES/ES2/glext.h>
40 #define GR_GL_FUNC
41#elif GR_ANDROID_BUILD
42 #ifndef GL_GLEXT_PROTOTYPES
43 #define GL_GLEXT_PROTOTYPES
44 #endif
45 #define GR_INCLUDE_GLES2 <GLES2/gl2.h>
46 #define GR_INCLUDE_GLES2ext <GLES2/gl2ext.h>
47 #define GR_GL_FUNC
48#elif GR_LINUX_BUILD
49 // need to distinguish between ES and Deskop versions for linux
50 #ifndef GL_GLEXT_PROTOTYPES
51 #define GL_GLEXT_PROTOTYPES
52 #endif
reed@google.com37df17d2010-12-23 20:20:51 +000053 #define GR_INCLUDE_GLDESKTOP <GL/gl.h>
54 #define GR_INCLUDE_GLDESKTOPext <GL/glext.h>
55// #define GR_INCLUDE_GLES1 <GLES/gl.h>
56// #define GR_INCLUDE_GLES1ext <GLES/glext.h>
57// #define GR_INCLUDE_GLES2 <GLES2/gl2.h>
58// #define GR_INCLUDE_GLES2ext <GLES2/gl2ext.h>
reed@google.comac10a2d2010-12-22 21:39:39 +000059 #define GR_GL_FUNC
60#elif GR_QNX_BUILD
61 #ifndef GL_GLEXT_PROTOTYPES
62 #define GL_GLEXT_PROTOTYPES
63 #endif
64 // This is needed by the QNX GLES2 headers
65 #define GL_API_EXT
66 #define GR_INCLUDE_GLES2 <GLES2/gl2.h>
67 #define GR_INCLUDE_GLES2ext <GLES2/gl2ext.h>
68 #define GR_INCLUDE_EGL <EGL/egl.h>
69 #define GR_GL_FUNC
70#else
71 #error "unsupported GR_???_BUILD"
72#endif
73
74// Ensure we're at least defined
75//
76
77#ifndef GR_SUPPORT_GLES1
78 #if defined(GR_INCLUDE_GLES1)
79 #define GR_SUPPORT_GLES1 1
80 #else
81 #define GR_SUPPORT_GLES1 0
82 #endif
83#endif
84
85#ifndef GR_SUPPORT_GLES2
86 #if defined(GR_INCLUDE_GLES2)
87 #define GR_SUPPORT_GLES2 1
88 #else
89 #define GR_SUPPORT_GLES2 0
90 #endif
91#endif
92
93#ifndef GR_SUPPORT_GLDESKTOP
94 #if defined(GR_INCLUDE_GLDESKTOP)
95 #define GR_SUPPORT_GLDESKTOP 1
96 #else
97 #define GR_SUPPORT_GLDESKTOP 0
98 #endif
99#endif
100
101#ifndef GR_SUPPORT_EGL
102 #if defined(GR_INCLUDE_EGL)
103 #define GR_SUPPORT_EGL 1
104 #else
105 #define GR_SUPPORT_EGL 0
106 #endif
107#endif
108// Filter the includes based on what we support
109//
110
111#if !GR_SUPPORT_GLES1
112 #undef GR_INCLUDE_GLES1
113 #undef GR_INCLUDE_GLES1ext
114#endif
115
116#if !GR_SUPPORT_GLES2
117 #undef GR_INCLUDE_GLES2
118 #undef GR_INCLUDE_GLES2ext
119#endif
120
121#if !GR_SUPPORT_GLDESKTOP
122 #undef GR_INCLUDE_GLDESKTOP
123 #undef GR_INCLUDE_GLDESKTOPext
124#endif
125
126#if !GR_SUPPORT_EGL
127 #undef GR_INCLUDE_EGL
128#endif
129
130// Begin including GL headers
131//
132
133#ifdef GR_INCLUDE_GLES1
134 #include GR_INCLUDE_GLES1
135#endif
136#ifdef GR_INCLUDE_GLES1ext
137 #include GR_INCLUDE_GLES1ext
138#endif
139#ifdef GR_INCLUDE_GLES2
140 #include GR_INCLUDE_GLES2
141#endif
142#ifdef GR_INCLUDE_GLES2ext
143 #include GR_INCLUDE_GLES2ext
144#endif
145#ifdef GR_INCLUDE_GLDESKTOP
146 #include GR_INCLUDE_GLDESKTOP
147#endif
148#ifdef GR_INCLUDE_GLDESKTOPext
149 #include GR_INCLUDE_GLDESKTOPext
150#endif
151#ifdef GR_INCLUDE_EGL
152 #include GR_INCLUDE_EGL
153#endif
154
155//
156// End including GL headers
157
158#if GL_VERSION_1_1
159 #define GR_GL_DESKTOP 1
160 #define GR_GL_ES 0
161#else
162 #ifndef GL_ES_VERSION_2_0
163 GR_STATIC_ASSERT(GL_VERSION_ES_CM_1_0 ||
164 GL_VERSION_ES_CL_1_0 ||
165 GL_VERSION_ES_CM_1_1 ||
166 GL_VERSION_ES_CL_1_1);
167 #endif
168 #define GR_GL_DESKTOP 0
169 #define GR_GL_ES 1
170#endif
171
172#if GR_SCALAR_IS_FIXED
173 #define GrGLType GL_FIXED
174#elif GR_SCALAR_IS_FLOAT
175 #define GrGLType GL_FLOAT
176#else
177 #error "unknown GR_SCALAR type"
178#endif
179
180#if GR_TEXT_SCALAR_IS_USHORT
181 #define GrGLTextType GL_UNSIGNED_SHORT
182 #define GR_GL_TEXT_TEXTURE_NORMALIZED 1
183#elif GR_TEXT_SCALAR_IS_FLOAT
184 #define GrGLTextType GL_FLOAT
185 #define GR_GL_TEXT_TEXTURE_NORMALIZED 0
186#elif GR_TEXT_SCALAR_IS_FIXED
187 #define GrGLTextType GL_FIXED
188 #define GR_GL_TEXT_TEXTURE_NORMALIZED 0
189#else
190 #error "unknown GR_TEXT_SCALAR type"
191#endif
192
bsalomon@google.com2fbc7fa2011-01-05 16:34:41 +0000193// Pick a pixel config for 32bit bitmaps. Our default is GL_RGBA (expect on
194// Windows where we match GDI's order).
195#ifndef GR_GL_32BPP_COLOR_FORMAT
196 #if GR_WIN32_BUILD
197 #define GR_GL_32BPP_COLOR_FORMAT GL_BGRA
198 #else
199 #define GR_GL_32BPP_COLOR_FORMAT GL_RGBA
200 #endif
reed@google.comac10a2d2010-12-22 21:39:39 +0000201#endif
202
203////////////////////////////////////////////////////////////////////////////////
204// setup for opengl ES/desktop extensions
205// we make a struct of function pointers so that each GL context
206// can have it's own struct. (Some environments may have different proc
207// addresses for different contexts).
208
209extern "C" {
210struct GrGLExts {
211// FBO
212 GLvoid (GR_GL_FUNC *GenFramebuffers)(GLsizei n, GLuint *framebuffers);
213 GLvoid (GR_GL_FUNC *BindFramebuffer)(GLenum target, GLuint framebuffer);
214 GLvoid (GR_GL_FUNC *FramebufferTexture2D)(GLenum target, GLenum attachment,
215 GLenum textarget, GLuint texture,
216 GLint level);
217 GLenum (GR_GL_FUNC *CheckFramebufferStatus)(GLenum target);
218 GLvoid (GR_GL_FUNC *DeleteFramebuffers)(GLsizei n, const
219 GLuint *framebuffers);
220 GLvoid (GR_GL_FUNC *RenderbufferStorage)(GLenum target,
221 GLenum internalformat,
222 GLsizei width, GLsizei height);
223 GLvoid (GR_GL_FUNC *GenRenderbuffers)(GLsizei n, GLuint *renderbuffers);
224 GLvoid (GR_GL_FUNC *DeleteRenderbuffers)(GLsizei n,
225 const GLuint *renderbuffers);
226 GLvoid (GR_GL_FUNC *FramebufferRenderbuffer)(GLenum target,
227 GLenum attachment,
228 GLenum renderbuffertarget,
229 GLuint renderbuffer);
230 GLvoid (GR_GL_FUNC *BindRenderbuffer)(GLenum target, GLuint renderbuffer);
231
232// Multisampling
233 // same prototype for ARB_FBO, EXT_FBO, GL 3.0, & Apple ES extension
234 GLvoid (GR_GL_FUNC *RenderbufferStorageMultisample)(GLenum target,
235 GLsizei samples,
236 GLenum internalformat,
237 GLsizei width,
238 GLsizei height);
239 // desktop: ext_fbo_blit, arb_fbo, gl 3.0
240 GLvoid (GR_GL_FUNC *BlitFramebuffer)(GLint srcX0, GLint srcY0,
241 GLint srcX1, GLint srcY1,
242 GLint dstX0, GLint dstY0,
243 GLint dstX1, GLint dstY1,
244 GLbitfield mask, GLenum filter);
245 // apple's es extension
246 GLvoid (GR_GL_FUNC *ResolveMultisampleFramebuffer)();
247
248 // IMG'e es extension
249 GLvoid (GR_GL_FUNC *FramebufferTexture2DMultisample)(GLenum target,
250 GLenum attachment,
251 GLenum textarget,
252 GLuint texture,
253 GLint level,
254 GLsizei samples);
255
256// Buffer mapping (extension in ES).
257 GLvoid* (GR_GL_FUNC *MapBuffer)(GLenum target, GLenum access);
258 GLboolean (GR_GL_FUNC *UnmapBuffer)(GLenum target);
259};
260}
261
262// FBO
263#define GR_FRAMEBUFFER 0x8D40
264#define GR_FRAMEBUFFER_COMPLETE 0x8CD5
265#define GR_COLOR_ATTACHMENT0 0x8CE0
266#define GR_FRAMEBUFFER_BINDING 0x8CA6
267#define GR_RENDERBUFFER 0x8D41
268#define GR_STENCIL_ATTACHMENT 0x8D20
269#define GR_STENCIL_INDEX8 0x8D48
270#define GR_STENCIL_INDEX16 0x8D49
271#define GR_MAX_RENDERBUFFER_SIZE 0x84E8
272#define GR_DEPTH_STENCIL_ATTACHMENT 0x821A
273#define GR_UNSIGNED_INT_24_8 0x84FA
274#define GR_DEPTH_STENCIL 0x84F9
275#define GR_RGBA8 0x8058
276#define GR_RGB565 0x8D62
277
278
279// Multisampling
280
281// IMG MAX_SAMPLES uses a different value than desktop, Apple ES extension.
282#define GR_MAX_SAMPLES 0x8D57
283#define GR_MAX_SAMPLES_IMG 0x9135
284#define GR_READ_FRAMEBUFFER 0x8CA8
285#define GR_DRAW_FRAMEBUFFER 0x8CA9
286
287// Buffer mapping
288#define GR_WRITE_ONLY 0x88B9
289#define GR_BUFFER_MAPPED 0x88BC
290
291// Palette texture
292#define GR_PALETTE8_RGBA8 0x8B91
293
294extern void GrGLInitExtensions(GrGLExts* exts);
295////////////////////////////////////////////////////////////////////////////////
296
297extern void GrGLCheckErr(const char* location, const char* call);
298
299static inline void GrGLClearErr() {
300 while (GL_NO_ERROR != glGetError()) {}
301}
302
303// GR_FORCE_GLCHECKERR can be defined by GrUserConfig.h
304#if defined(GR_FORCE_GLCHECKERR)
305 #define GR_LOCAL_CALL_CHECKERR GR_FORCE_GLCHECKERR
306#else
307 #define GR_LOCAL_CALL_CHECKERR GR_DEBUG
308#endif
309static inline void GrDebugGLCheckErr(const char* location, const char* call) {
310#if GR_LOCAL_CALL_CHECKERR
311 GrGLCheckErr(location, call);
312#endif
313}
314#undef GR_LOCAL_CALL_CHECKERR
315
316#if GR_GL_LOG_CALLS
317 extern bool gPrintGL;
318 #define GR_GL(X) gl ## X; GrDebugGLCheckErr(GR_FILE_AND_LINE_STR, #X); if (gPrintGL) GrPrintf(GR_FILE_AND_LINE_STR "GL: " #X "\n")
319 #define GR_GL_NO_ERR(X) GrGLClearErr(); gl ## X; if (gPrintGL) GrPrintf(GR_FILE_AND_LINE_STR "GL: " #X "\n")
320 #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")
321 #define GR_GLEXT_NO_ERR(exts, X) GrGLClearErr(); exts. X; if (gPrintGL) GrPrintf(GR_FILE_AND_LINE_STR "GL: " #X "\n")
322#else
323 #define GR_GL(X) gl ## X; GrDebugGLCheckErr(GR_FILE_AND_LINE_STR, #X)
324 #define GR_GL_NO_ERR(X) GrGLClearErr(); gl ## X
325 #define GR_GLEXT(exts, X) exts. X; GrDebugGLCheckErr(GR_FILE_AND_LINE_STR, #X)
326 #define GR_GLEXT_NO_ERR(exts, X) GrGLClearErr(); exts. X
327#endif
328
329#endif
330