blob: 7fab1b51895561e93dd72c57f7468a7e0cfded4f [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
193// Pick a pixel config for 32bit bitmaps. Our default is GL_RGBA
194#ifndef SK_GL_32BPP_COLOR_FORMAT
195 #define SK_GL_32BPP_COLOR_FORMAT GL_RGBA
196#endif
197
198////////////////////////////////////////////////////////////////////////////////
199// setup for opengl ES/desktop extensions
200// we make a struct of function pointers so that each GL context
201// can have it's own struct. (Some environments may have different proc
202// addresses for different contexts).
203
204extern "C" {
205struct GrGLExts {
206// FBO
207 GLvoid (GR_GL_FUNC *GenFramebuffers)(GLsizei n, GLuint *framebuffers);
208 GLvoid (GR_GL_FUNC *BindFramebuffer)(GLenum target, GLuint framebuffer);
209 GLvoid (GR_GL_FUNC *FramebufferTexture2D)(GLenum target, GLenum attachment,
210 GLenum textarget, GLuint texture,
211 GLint level);
212 GLenum (GR_GL_FUNC *CheckFramebufferStatus)(GLenum target);
213 GLvoid (GR_GL_FUNC *DeleteFramebuffers)(GLsizei n, const
214 GLuint *framebuffers);
215 GLvoid (GR_GL_FUNC *RenderbufferStorage)(GLenum target,
216 GLenum internalformat,
217 GLsizei width, GLsizei height);
218 GLvoid (GR_GL_FUNC *GenRenderbuffers)(GLsizei n, GLuint *renderbuffers);
219 GLvoid (GR_GL_FUNC *DeleteRenderbuffers)(GLsizei n,
220 const GLuint *renderbuffers);
221 GLvoid (GR_GL_FUNC *FramebufferRenderbuffer)(GLenum target,
222 GLenum attachment,
223 GLenum renderbuffertarget,
224 GLuint renderbuffer);
225 GLvoid (GR_GL_FUNC *BindRenderbuffer)(GLenum target, GLuint renderbuffer);
226
227// Multisampling
228 // same prototype for ARB_FBO, EXT_FBO, GL 3.0, & Apple ES extension
229 GLvoid (GR_GL_FUNC *RenderbufferStorageMultisample)(GLenum target,
230 GLsizei samples,
231 GLenum internalformat,
232 GLsizei width,
233 GLsizei height);
234 // desktop: ext_fbo_blit, arb_fbo, gl 3.0
235 GLvoid (GR_GL_FUNC *BlitFramebuffer)(GLint srcX0, GLint srcY0,
236 GLint srcX1, GLint srcY1,
237 GLint dstX0, GLint dstY0,
238 GLint dstX1, GLint dstY1,
239 GLbitfield mask, GLenum filter);
240 // apple's es extension
241 GLvoid (GR_GL_FUNC *ResolveMultisampleFramebuffer)();
242
243 // IMG'e es extension
244 GLvoid (GR_GL_FUNC *FramebufferTexture2DMultisample)(GLenum target,
245 GLenum attachment,
246 GLenum textarget,
247 GLuint texture,
248 GLint level,
249 GLsizei samples);
250
251// Buffer mapping (extension in ES).
252 GLvoid* (GR_GL_FUNC *MapBuffer)(GLenum target, GLenum access);
253 GLboolean (GR_GL_FUNC *UnmapBuffer)(GLenum target);
254};
255}
256
257// FBO
258#define GR_FRAMEBUFFER 0x8D40
259#define GR_FRAMEBUFFER_COMPLETE 0x8CD5
260#define GR_COLOR_ATTACHMENT0 0x8CE0
261#define GR_FRAMEBUFFER_BINDING 0x8CA6
262#define GR_RENDERBUFFER 0x8D41
263#define GR_STENCIL_ATTACHMENT 0x8D20
264#define GR_STENCIL_INDEX8 0x8D48
265#define GR_STENCIL_INDEX16 0x8D49
266#define GR_MAX_RENDERBUFFER_SIZE 0x84E8
267#define GR_DEPTH_STENCIL_ATTACHMENT 0x821A
268#define GR_UNSIGNED_INT_24_8 0x84FA
269#define GR_DEPTH_STENCIL 0x84F9
270#define GR_RGBA8 0x8058
271#define GR_RGB565 0x8D62
272
273
274// Multisampling
275
276// IMG MAX_SAMPLES uses a different value than desktop, Apple ES extension.
277#define GR_MAX_SAMPLES 0x8D57
278#define GR_MAX_SAMPLES_IMG 0x9135
279#define GR_READ_FRAMEBUFFER 0x8CA8
280#define GR_DRAW_FRAMEBUFFER 0x8CA9
281
282// Buffer mapping
283#define GR_WRITE_ONLY 0x88B9
284#define GR_BUFFER_MAPPED 0x88BC
285
286// Palette texture
287#define GR_PALETTE8_RGBA8 0x8B91
288
289extern void GrGLInitExtensions(GrGLExts* exts);
290////////////////////////////////////////////////////////////////////////////////
291
292extern void GrGLCheckErr(const char* location, const char* call);
293
294static inline void GrGLClearErr() {
295 while (GL_NO_ERROR != glGetError()) {}
296}
297
298// GR_FORCE_GLCHECKERR can be defined by GrUserConfig.h
299#if defined(GR_FORCE_GLCHECKERR)
300 #define GR_LOCAL_CALL_CHECKERR GR_FORCE_GLCHECKERR
301#else
302 #define GR_LOCAL_CALL_CHECKERR GR_DEBUG
303#endif
304static inline void GrDebugGLCheckErr(const char* location, const char* call) {
305#if GR_LOCAL_CALL_CHECKERR
306 GrGLCheckErr(location, call);
307#endif
308}
309#undef GR_LOCAL_CALL_CHECKERR
310
311#if GR_GL_LOG_CALLS
312 extern bool gPrintGL;
313 #define GR_GL(X) gl ## X; GrDebugGLCheckErr(GR_FILE_AND_LINE_STR, #X); if (gPrintGL) GrPrintf(GR_FILE_AND_LINE_STR "GL: " #X "\n")
314 #define GR_GL_NO_ERR(X) GrGLClearErr(); gl ## X; if (gPrintGL) GrPrintf(GR_FILE_AND_LINE_STR "GL: " #X "\n")
315 #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")
316 #define GR_GLEXT_NO_ERR(exts, X) GrGLClearErr(); exts. X; if (gPrintGL) GrPrintf(GR_FILE_AND_LINE_STR "GL: " #X "\n")
317#else
318 #define GR_GL(X) gl ## X; GrDebugGLCheckErr(GR_FILE_AND_LINE_STR, #X)
319 #define GR_GL_NO_ERR(X) GrGLClearErr(); gl ## X
320 #define GR_GLEXT(exts, X) exts. X; GrDebugGLCheckErr(GR_FILE_AND_LINE_STR, #X)
321 #define GR_GLEXT_NO_ERR(exts, X) GrGLClearErr(); exts. X
322#endif
323
324#endif
325