24 #include <GLES3/gl3.h>
32 0, 1, 2, 3, 3, 4, 4, 5, 6, 7, 7, 8, 8, 9, 10, 11, 11, 12, 12, 13, 14, 15, 15, 16, 16, 17, 18, 19, 19, 20, 20, 21, 22, 23,
124 0.0f, 0.0f, 0.0f, 1.0f,
125 1.0f, 0.0f, 0.0f, 1.0f,
126 0.0f, 1.0f, 0.0f, 1.0f,
127 1.0f, 1.0f, 0.0f, 1.0f,
130 1.0f, 0.0f, 0.0f, 1.0f,
131 0.0f, 0.0f, 1.0f, 1.0f,
132 1.0f, 1.0f, 0.0f, 1.0f,
133 0.0f, 1.0f, 1.0f, 1.0f,
136 0.0f, 0.0f, 1.0f, 1.0f,
137 1.0f, 0.0f, 1.0f, 1.0f,
138 0.0f, 1.0f, 1.0f, 1.0f,
139 1.0f, 1.0f, 1.0f, 1.0f,
142 1.0f, 0.0f, 1.0f, 1.0f,
143 0.0f, 0.0f, 0.0f, 1.0f,
144 1.0f, 1.0f, 1.0f, 1.0f,
145 0.0f, 1.0f, 0.0f, 1.0f,
148 0.0f, 1.0f, 0.0f, 1.0f,
149 1.0f, 1.0f, 0.0f, 1.0f,
150 1.0f, 1.0f, 1.0f, 1.0f,
151 0.0f, 1.0f, 1.0f, 1.0f,
154 1.0f, 0.0f, 1.0f, 1.0f,
155 0.0f, 0.0f, 1.0f, 1.0f,
156 0.0f, 0.0f, 0.0f, 1.0f,
157 1.0f, 0.0f, 0.0f, 1.0f,
174 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
176 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT ,
188 EGL_CONTEXT_CLIENT_VERSION, 3,
197 EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA,
198 EGL_TEXTURE_TARGET, EGL_TEXTURE_2D,
203 EGLConfig
findConfig(EGLDisplay display,
bool strictMatch,
bool offscreen)
205 EGLConfig *configsArray = NULL;
206 EGLint numberOfConfigs = 0;
207 EGLBoolean success = EGL_FALSE;
210 success = eglChooseConfig(display,
configAttributes, NULL, 0, &numberOfConfigs);
211 if(success != EGL_TRUE)
213 EGLint error = eglGetError();
214 LOGE(
"eglGetError(): %i (0x%.4x)\n", (
int)error, (
int)error);
215 LOGE(
"Failed to enumerate EGL configs at %s:%i\n", __FILE__, __LINE__);
219 LOGD(
"Number of configs found is %d\n", numberOfConfigs);
221 if (numberOfConfigs == 0)
223 LOGD(
"Disabling AntiAliasing to try and find a config.\n");
225 success = eglChooseConfig(display,
configAttributes, NULL, 0, &numberOfConfigs);
226 if(success != EGL_TRUE)
228 EGLint error = eglGetError();
229 LOGE(
"eglGetError(): %i (0x%.4x)\n", (
int)error, (
int)error);
230 LOGE(
"Failed to enumerate EGL configs at %s:%i\n", __FILE__, __LINE__);
234 if (numberOfConfigs == 0)
236 LOGE(
"No configs found with the requested attributes.\n");
241 LOGD(
"Configs found when antialiasing disabled.\n ");
246 configsArray = (EGLConfig *)calloc(numberOfConfigs,
sizeof(EGLConfig));
247 if(configsArray == NULL)
249 LOGE(
"Out of memory at %s:%i\n", __FILE__, __LINE__);
252 success = eglChooseConfig(display,
configAttributes, configsArray, numberOfConfigs, &numberOfConfigs);
253 if(success != EGL_TRUE)
255 EGLint error = eglGetError();
256 LOGE(
"eglGetError(): %i (0x%.4x)\n", (
int)error, (
int)error);
257 LOGE(
"Failed to enumerate EGL configs at %s:%i\n", __FILE__, __LINE__);
261 bool matchFound =
false;
262 int matchingConfig = -1;
275 for(
int configsIndex = 0; (configsIndex < numberOfConfigs) && !matchFound; configsIndex++)
277 EGLint attributeValue = 0;
279 success = eglGetConfigAttrib(display, configsArray[configsIndex], EGL_RED_SIZE, &attributeValue);
280 if(success != EGL_TRUE)
282 EGLint error = eglGetError();
283 LOGE(
"eglGetError(): %i (0x%.4x)\n", (
int)error, (
int)error);
284 LOGE(
"Failed to get EGL attribute at %s:%i\n", __FILE__, __LINE__);
288 if(attributeValue == redSize)
290 success = eglGetConfigAttrib(display, configsArray[configsIndex], EGL_GREEN_SIZE, &attributeValue);
291 if(success != EGL_TRUE)
293 EGLint error = eglGetError();
294 LOGE(
"eglGetError(): %i (0x%.4x)\n", (
int)error, (
int)error);
295 LOGE(
"Failed to get EGL attribute at %s:%i\n", __FILE__, __LINE__);
299 if(attributeValue == greenSize)
301 success = eglGetConfigAttrib(display, configsArray[configsIndex], EGL_BLUE_SIZE, &attributeValue);
302 if(success != EGL_TRUE)
304 EGLint error = eglGetError();
305 LOGE(
"eglGetError(): %i (0x%.4x)\n", (
int)error, (
int)error);
306 LOGE(
"Failed to get EGL attribute at %s:%i\n", __FILE__, __LINE__);
310 if(attributeValue == blueSize)
314 success = eglGetConfigAttrib(display, configsArray[configsIndex], EGL_SURFACE_TYPE, &attributeValue);
315 if(success != EGL_TRUE)
317 EGLint error = eglGetError();
318 LOGE(
"eglGetError(): %i (0x%.4x)\n", (
int)error, (
int)error);
319 LOGE(
"Failed to get EGL attribute at %s:%i\n", __FILE__, __LINE__);
322 if(attributeValue & EGL_PBUFFER_BIT)
325 matchingConfig = configsIndex;
332 matchingConfig = configsIndex;
348 LOGE(
"Failed to find matching EGL config at %s:%i\n", __FILE__, __LINE__);
353 EGLConfig configToReturn = configsArray[matchingConfig];
358 return configToReturn;
static const float cubeColors[]
EGLint configAttributes[]
static const float cubeVertices[]
EGLint contextAttributes[]
static const float cubeTextureCoordinates[]
EGLConfig findConfig(EGLDisplay display, bool strictMatch, bool offscreen)
static const GLubyte cubeIndices[]
EGLint pBufferAttributes[]