FPLBase
An open source project by
FPL
.
Main Page
Programmer's Guide
API reference
Contributing
Modules
Class List
File List
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Groups
Pages
glplatform.h
1
// Copyright 2014 Google Inc. All rights reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
// clang-format off
16
17
// OpenGL platform definitions
18
19
#ifndef FPLBASE_GLPLATFORM_H
20
#define FPLBASE_GLPLATFORM_H
21
22
#include "fplbase/config.h"
// Must come first.
23
24
#ifdef __APPLE__
25
#include "TargetConditionals.h"
26
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
27
#define PLATFORM_MOBILE
28
#include <OpenGLES/ES3/gl.h>
29
#include <OpenGLES/ES3/glext.h>
30
#else // TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
31
#define PLATFORM_OSX
32
#include <OpenGL/gl.h>
33
#include <OpenGL/glext.h>
34
#define glGenVertexArrays glGenVertexArraysAPPLE
35
#define glBindVertexArray glBindVertexArrayAPPLE
36
#define glDeleteVertexArrays glDeleteVertexArraysAPPLE
37
#define glDrawElementsInstanced glDrawElementsInstancedARB
38
#endif // TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
39
40
#else // !defined(__APPLE__)
41
#ifdef __ANDROID__
42
#define PLATFORM_MOBILE
43
#include <EGL/egl.h>
44
#include <android/api-level.h>
45
#if __ANDROID_API__ >= 18
46
#include <GLES3/gl3.h>
47
#else // __ANDROID_API__ < 18
48
#include <GLES2/gl2.h>
49
#include "gl3stub.h"
50
#endif // __ANDROID_API__ < 18
51
#else // !defined(__ANDROID__), so WIN32 & Linux
52
#ifdef _WIN32
53
#define VC_EXTRALEAN
54
#ifndef WIN32_LEAN_AND_MEAN
55
#define WIN32_LEAN_AND_MEAN
56
#endif // !defined(WIN32_LEAN_AND_MEAN)
57
#ifndef NOMINMAX
58
#define NOMINMAX
59
#endif // !defined(NOMINMAX)
60
#include <windows.h>
61
#endif // !defined(_WIN32)
62
63
#include <GL/gl.h>
64
#include <GL/glext.h>
65
#if !defined(GL_GLEXT_PROTOTYPES)
66
#ifdef _WIN32
67
#define GLBASEEXTS \
68
GLEXT(PFNGLACTIVETEXTUREARBPROC, glActiveTexture, true) \
69
GLEXT(PFNGLCOMPRESSEDTEXIMAGE2DPROC, glCompressedTexImage2D, true) \
70
GLEXT(PFNGLBINDSAMPLERPROC, glBindSampler, true)
71
#else // !defined(_WIN32)
72
#define GLBASEEXTS
73
#endif // !defined(_WIN32)
74
#define GLEXTS \
75
GLEXT(PFNGLGENFRAMEBUFFERSPROC, glGenFramebuffers, true) \
76
GLEXT(PFNGLBINDFRAMEBUFFEREXTPROC, glBindFramebuffer, true) \
77
GLEXT(PFNGLGENRENDERBUFFERSEXTPROC, glGenRenderbuffers, true) \
78
GLEXT(PFNGLBINDRENDERBUFFEREXTPROC, glBindRenderbuffer, true) \
79
GLEXT(PFNGLRENDERBUFFERSTORAGEEXTPROC, glRenderbufferStorage, true) \
80
GLEXT(PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC, glFramebufferRenderbuffer, true) \
81
GLEXT(PFNGLFRAMEBUFFERTEXTURE2DPROC, glFramebufferTexture2D, true) \
82
GLEXT(PFNGLDRAWBUFFERSPROC, glDrawBuffers, true) \
83
GLEXT(PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC, glCheckFramebufferStatus, true) \
84
GLEXT(PFNGLDELETERENDERBUFFERSEXTPROC, glDeleteRenderbuffers, true) \
85
GLEXT(PFNGLDELETEFRAMEBUFFERSEXTPROC, glDeleteFramebuffers, true) \
86
GLEXT(PFNGLGENBUFFERSARBPROC, glGenBuffers, true) \
87
GLEXT(PFNGLBINDBUFFERARBPROC, glBindBuffer, true) \
88
GLEXT(PFNGLMAPBUFFERARBPROC, glMapBuffer, true) \
89
GLEXT(PFNGLUNMAPBUFFERARBPROC, glUnmapBuffer, true) \
90
GLEXT(PFNGLBUFFERDATAARBPROC, glBufferData, true) \
91
GLEXT(PFNGLBUFFERSUBDATAARBPROC, glBufferSubData, true) \
92
GLEXT(PFNGLDELETEBUFFERSARBPROC, glDeleteBuffers, true) \
93
GLEXT(PFNGLGETBUFFERSUBDATAARBPROC, glGetBufferSubData, true) \
94
GLEXT(PFNGLVERTEXATTRIBPOINTERARBPROC, glVertexAttribPointer, true) \
95
GLEXT(PFNGLENABLEVERTEXATTRIBARRAYARBPROC, glEnableVertexAttribArray, true) \
96
GLEXT(PFNGLDISABLEVERTEXATTRIBARRAYARBPROC, glDisableVertexAttribArray, true)\
97
GLEXT(PFNGLCREATEPROGRAMPROC, glCreateProgram, true) \
98
GLEXT(PFNGLDELETEPROGRAMPROC, glDeleteProgram, true) \
99
GLEXT(PFNGLDELETESHADERPROC, glDeleteShader, true) \
100
GLEXT(PFNGLUSEPROGRAMPROC, glUseProgram, true) \
101
GLEXT(PFNGLCREATESHADERPROC, glCreateShader, true) \
102
GLEXT(PFNGLSHADERSOURCEPROC, glShaderSource, true) \
103
GLEXT(PFNGLSTENCILFUNCSEPARATEPROC, glStencilFuncSeparate, true) \
104
GLEXT(PFNGLSTENCILOPSEPARATEPROC, glStencilOpSeparate, true) \
105
GLEXT(PFNGLCOMPILESHADERPROC, glCompileShader, true) \
106
GLEXT(PFNGLGETPROGRAMIVARBPROC, glGetProgramiv, true) \
107
GLEXT(PFNGLGETSHADERIVPROC, glGetShaderiv, true) \
108
GLEXT(PFNGLGETPROGRAMINFOLOGPROC, glGetProgramInfoLog, true) \
109
GLEXT(PFNGLGETSHADERINFOLOGPROC, glGetShaderInfoLog, true) \
110
GLEXT(PFNGLATTACHSHADERPROC, glAttachShader, true) \
111
GLEXT(PFNGLLINKPROGRAMARBPROC, glLinkProgram, true) \
112
GLEXT(PFNGLGETUNIFORMLOCATIONARBPROC, glGetUniformLocation, true) \
113
GLEXT(PFNGLUNIFORM1FARBPROC, glUniform1f, true) \
114
GLEXT(PFNGLUNIFORM2FARBPROC, glUniform2f, true) \
115
GLEXT(PFNGLUNIFORM3FARBPROC, glUniform3f, true) \
116
GLEXT(PFNGLUNIFORM4FARBPROC, glUniform4f, true) \
117
GLEXT(PFNGLUNIFORM1FVARBPROC, glUniform1fv, true) \
118
GLEXT(PFNGLUNIFORM2FVARBPROC, glUniform2fv, true) \
119
GLEXT(PFNGLUNIFORM3FVARBPROC, glUniform3fv, true) \
120
GLEXT(PFNGLUNIFORM4FVARBPROC, glUniform4fv, true) \
121
GLEXT(PFNGLUNIFORM1IARBPROC, glUniform1i, true) \
122
GLEXT(PFNGLUNIFORMMATRIX4FVARBPROC, glUniformMatrix4fv, true) \
123
GLEXT(PFNGLUNIFORMMATRIX4FVARBPROC
/*type*/
, glUniformMatrix3x4fv, true) \
124
GLEXT(PFNGLBINDATTRIBLOCATIONARBPROC, glBindAttribLocation, true) \
125
GLEXT(PFNGLGETACTIVEUNIFORMARBPROC, glGetActiveUniform, true) \
126
GLEXT(PFNGLGENERATEMIPMAPEXTPROC, glGenerateMipmap, true) \
127
GLEXT(PFNGLGETATTRIBLOCATIONPROC, glGetAttribLocation, true) \
128
GLEXT(PFNGLDRAWELEMENTSINSTANCEDPROC, glDrawElementsInstanced, true) \
129
GLEXT(PFNGLGENVERTEXARRAYSPROC, glGenVertexArrays, true) \
130
GLEXT(PFNGLDELETEVERTEXARRAYSPROC, glDeleteVertexArrays, true) \
131
GLEXT(PFNGLBINDVERTEXARRAYPROC, glBindVertexArray, true)
132
133
// TODO(jsanmiya): Get this compiling for all versions of OpenGL. Currently only
134
// valid when GL_VERSION_4_3 is defined.
135
// GLEXT(PFNGLPUSHDEBUGGROUPPROC, glPushDebugGroup, false)
136
// GLEXT(PFNGLPOPDEBUGGROUPPROC, glPopDebugGroup, false)
137
138
#define GLEXT(type, name, required) extern type name;
139
GLBASEEXTS
140
GLEXTS
141
#undef GLEXT
142
#endif // !defined(GL_GLEXT_PROTOTYPES)
143
#endif // !defined(__ANDROID__), so WIN32 & Linux
144
#endif // !defined(__APPLE__)
145
146
#ifdef PLATFORM_MOBILE
147
// TODO(jsanmiya): Get this compiling for all versions of iOS. Currently only
148
// valid with __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0)
149
// OpenGL ES extensions function pointers.
150
// typedef void (*PFNGLPUSHGROUPMARKEREXTPROC)(GLsizei length, const GLchar* message);
151
// typedef void (*PFNPOPGROUPMARKEREXTPROC)(void);
152
// #define glPushGroupMarker glPushGroupMarkerEXT
153
// #define glPopGroupMarker glPopGroupMarkerEXT
154
/*
155
#define GLESEXTS \
156
GLEXT(PFNGLPUSHGROUPMARKEREXTPROC, glPushGroupMarkerEXT, false) \
157
GLEXT(PFNPOPGROUPMARKEREXTPROC, glPopGroupMarkerEXT, false)
158
*/
159
//
160
// #define GLEXT(type, name, required) extern type name;
161
// GLESEXTS
162
// #undef GLEXT
163
#define GLESEXTS
164
#endif // PLATFORM_MOBILE
165
166
#ifdef PLATFORM_OSX
167
#define glPushGroupMarker glPushGroupMarkerEXT
168
#define glPopGroupMarker glPopGroupMarkerEXT
169
#endif // PLATFORM_OSX
170
171
// Define a GL_CALL macro to wrap each (void-returning) OpenGL call.
172
// This logs GL error when LOG_GL_ERRORS below is defined.
173
#if defined(_DEBUG) || DEBUG == 1 || !defined(NDEBUG)
174
#define LOG_GL_ERRORS
175
#endif
176
177
#ifdef LOG_GL_ERRORS
178
#define GL_CALL(call) \
179
{ \
180
call; \
181
LogGLError(__FILE__, __LINE__, #call); \
182
}
183
#else
184
#define GL_CALL(call) \
185
do { \
186
call; \
187
} while (0)
188
#endif
189
190
// The error checking function used by the GL_CALL macro above,
191
// uses glGetError() to check for errors.
192
extern
void
LogGLError(
const
char
*file,
int
line,
const
char
*call);
193
194
// These are missing in older NDKs.
195
#ifndef GL_ETC1_RGB8_OES
196
#define GL_ETC1_RGB8_OES 0x8D64
197
#endif
198
199
#ifndef GL_COMPRESSED_RGB8_ETC2
200
#define GL_COMPRESSED_RGB8_ETC2 0x9274
201
#endif
202
203
#ifndef GL_COMPRESSED_RGBA_ASTC_4x4_KHR
204
#define GL_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0
205
#endif
206
#ifndef GL_COMPRESSED_RGBA_ASTC_5x4_KHR
207
#define GL_COMPRESSED_RGBA_ASTC_5x4_KHR 0x93B1
208
#endif
209
#ifndef GL_COMPRESSED_RGBA_ASTC_5x5_KHR
210
#define GL_COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B2
211
#endif
212
#ifndef GL_COMPRESSED_RGBA_ASTC_6x5_KHR
213
#define GL_COMPRESSED_RGBA_ASTC_6x5_KHR 0x93B3
214
#endif
215
#ifndef GL_COMPRESSED_RGBA_ASTC_6x6_KHR
216
#define GL_COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B4
217
#endif
218
#ifndef GL_COMPRESSED_RGBA_ASTC_8x5_KHR
219
#define GL_COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B5
220
#endif
221
#ifndef GL_COMPRESSED_RGBA_ASTC_8x6_KHR
222
#define GL_COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B6
223
#endif
224
#ifndef GL_COMPRESSED_RGBA_ASTC_8x8_KHR
225
#define GL_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B7
226
#endif
227
#ifndef GL_COMPRESSED_RGBA_ASTC_10x5_KHR
228
#define GL_COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B8
229
#endif
230
#ifndef GL_COMPRESSED_RGBA_ASTC_10x6_KHR
231
#define GL_COMPRESSED_RGBA_ASTC_10x6_KHR 0x93B9
232
#endif
233
#ifndef GL_COMPRESSED_RGBA_ASTC_10x8_KHR
234
#define GL_COMPRESSED_RGBA_ASTC_10x8_KHR 0x93BA
235
#endif
236
#ifndef GL_COMPRESSED_RGBA_ASTC_10x10_KHR
237
#define GL_COMPRESSED_RGBA_ASTC_10x10_KHR 0x93BB
238
#endif
239
#ifndef GL_COMPRESSED_RGBA_ASTC_12x10_KHR
240
#define GL_COMPRESSED_RGBA_ASTC_12x10_KHR 0x93BC
241
#endif
242
#ifndef GL_COMPRESSED_RGBA_ASTC_12x12_KHR
243
#define GL_COMPRESSED_RGBA_ASTC_12x12_KHR 0x93BD
244
#endif
245
246
#endif // FPLBASE_GLPLATFORM_H