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