54 EGL_RENDERABLE_TYPE, 0,
56 EGL_SURFACE_TYPE, EGL_WINDOW_BIT ,
68 EGL_CONTEXT_CLIENT_VERSION, 0,
87 EGLConfig *configsArray = NULL;
88 EGLint numberOfConfigs = 0;
89 EGLBoolean success = EGL_FALSE;
93 if(success != EGL_TRUE)
95 EGLint error = eglGetError();
96 LOGE(
"eglGetError(): %i (0x%.4x)\n", (
int)error, (
int)error);
97 LOGE(
"Failed to enumerate EGL configs at %s:%i\n", __FILE__, __LINE__);
101 LOGD(
"Number of configs found is %d\n", numberOfConfigs);
103 if (numberOfConfigs == 0)
105 LOGD(
"Disabling AntiAliasing to try and find a config.\n");
108 if(success != EGL_TRUE)
110 EGLint error = eglGetError();
111 LOGE(
"eglGetError(): %i (0x%.4x)\n", (
int)error, (
int)error);
112 LOGE(
"Failed to enumerate EGL configs at %s:%i\n", __FILE__, __LINE__);
116 if (numberOfConfigs == 0)
118 LOGE(
"No configs found with the requested attributes.\n");
123 LOGD(
"Configs found when antialiasing disabled.\n ");
128 configsArray = (EGLConfig *)calloc(numberOfConfigs,
sizeof(EGLConfig));
129 if(configsArray == NULL)
131 LOGE(
"Out of memory at %s:%i\n", __FILE__, __LINE__);
135 if(success != EGL_TRUE)
137 EGLint error = eglGetError();
138 LOGE(
"eglGetError(): %i (0x%.4x)\n", (
int)error, (
int)error);
139 LOGE(
"Failed to enumerate EGL configs at %s:%i\n", __FILE__, __LINE__);
143 bool matchFound =
false;
144 int matchingConfig = -1;
157 for(
int configsIndex = 0; (configsIndex < numberOfConfigs) && !matchFound; configsIndex++)
159 EGLint attributeValue = 0;
161 success = eglGetConfigAttrib(
display, configsArray[configsIndex], EGL_RED_SIZE, &attributeValue);
162 if(success != EGL_TRUE)
164 EGLint error = eglGetError();
165 LOGE(
"eglGetError(): %i (0x%.4x)\n", (
int)error, (
int)error);
166 LOGE(
"Failed to get EGL attribute at %s:%i\n", __FILE__, __LINE__);
170 if(attributeValue == redSize)
172 success = eglGetConfigAttrib(
display, configsArray[configsIndex], EGL_GREEN_SIZE, &attributeValue);
173 if(success != EGL_TRUE)
175 EGLint error = eglGetError();
176 LOGE(
"eglGetError(): %i (0x%.4x)\n", (
int)error, (
int)error);
177 LOGE(
"Failed to get EGL attribute at %s:%i\n", __FILE__, __LINE__);
181 if(attributeValue == greenSize)
183 success = eglGetConfigAttrib(
display, configsArray[configsIndex], EGL_BLUE_SIZE, &attributeValue);
184 if(success != EGL_TRUE)
186 EGLint error = eglGetError();
187 LOGE(
"eglGetError(): %i (0x%.4x)\n", (
int)error, (
int)error);
188 LOGE(
"Failed to get EGL attribute at %s:%i\n", __FILE__, __LINE__);
192 if(attributeValue == blueSize)
195 matchingConfig = configsIndex;
210 LOGE(
"Failed to find matching EGL config at %s:%i\n", __FILE__, __LINE__);
215 EGLConfig configToReturn = configsArray[matchingConfig];
220 return configToReturn;
225 EGLBoolean success = EGL_FALSE;
230 #elif defined(__arm__)
232 display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
235 platform->display = XOpenDisplay(NULL);
241 EGLint error = eglGetError();
242 LOGE(
"eglGetError(): %i (0x%.4x)\n", (
int)error, (
int)error);
243 LOGE(
"No EGL Display available at %s:%i\n", __FILE__, __LINE__);
248 success = eglInitialize(
display, NULL, NULL);
249 if(success != EGL_TRUE)
251 EGLint error = eglGetError();
252 LOGE(
"eglGetError(): %i (0x%.4x)\n", (
int)error, (
int)error);
253 LOGE(
"Failed to initialize EGL at %s:%i\n", __FILE__, __LINE__);
263 else if(requestedAPIVersion ==
OPENGLES2)
275 else if (requestedAPIVersion ==
OPENGLES3)
292 #if defined(__linux__) && !defined(__arm__)
293 ((DesktopLinuxPlatform*)(
platform))->createX11Window();
300 EGLint error = eglGetError();
301 LOGE(
"eglGetError(): %i (0x%.4x)\n", (
int)error, (
int)error);
302 LOGE(
"Failed to create EGL surface at %s:%i\n", __FILE__, __LINE__);
307 eglBindAPI(EGL_OPENGL_ES_API);
312 EGLint error = eglGetError();
313 LOGE(
"eglGetError(): %i (0x%.4x)\n", (
int)error, (
int)error);
314 LOGE(
"Failed to create EGL context at %s:%i\n", __FILE__, __LINE__);
327 eglBindAPI(EGL_OPENGL_ES_API);
329 eglMakeCurrent(
display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
static EGLint contextAttributes[]
Used to specify the EGL attributes we require from a context.
static EGLSurface surface
The EGL surface in use.
static EGLint configAttributes[]
Used to specify the EGL attributes we require from a configuration.
static void setEGLSamples(EGLint requiredEGLSamples)
Set the value of EGL_SAMPLES (AntiAliasing level) to be requested.
static EGLConfig findConfig(bool strictMatch)
Search for an EGL config with the attributes set in configAttributes.
static EGLDisplay display
The EGL display in use (a platform native window handle).
static EGLContext context
The EGL context in use.
static void terminateEGL(void)
Shuts down EGL.
static void initializeEGL(OpenGLESVersion requestedAPIVersion)
Setup EGL environment.
static EGLint windowAttributes[]
Used to specify the EGL attributes we require from a window surface.
static EGLConfig config
The selected EGL config which matches the required attributes.
OpenGLESVersion
An enum to define OpenGL ES versions.