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