1 /*
2 
3 Boost Software License - Version 1.0 - August 17th, 2003
4 
5 Permission is hereby granted, free of charge, to any person or organization
6 obtaining a copy of the software and accompanying documentation covered by
7 this license (the "Software") to use, reproduce, display, distribute,
8 execute, and transmit the Software, and to prepare derivative works of the
9 Software, and to permit third-parties to whom the Software is furnished to
10 do so, all subject to the following:
11 
12 The copyright notices in the Software and this entire statement, including
13 the above license grant, this restriction and the following disclaimer,
14 must be included in all copies of the Software, in whole or in part, and
15 all derivative works of the Software, unless such copies or derivative
16 works are solely in the form of machine-executable object code generated by
17 a source language processor.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
22 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
23 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 DEALINGS IN THE SOFTWARE.
26 
27 */
28 module derelict.gles.egl;
29 
30 public import derelict.gles.eglext,
31               derelict.gles.egltypes;
32 
33 import std.conv;
34 import derelict.util.loader,
35        derelict.util.exception,
36        derelict.util.system;
37 
38 private {
39     static if( Derelict_OS_Windows )
40         enum libNames = "libegl.dll";
41     else static if( Derelict_OS_Posix && !Derelict_OS_Mac )
42         enum libNames = "libEGL.so.1,libEGL.so";
43     else
44         static assert( 0, "Need to implement EGL libNames for this operating system." );
45 }
46 
47 enum : ubyte {
48     EGL_FALSE        = 0,
49     EGL_TRUE         = 1,
50 }
51 
52 /* Out-of-band handle values */
53 enum EGLNativeDisplayType EGL_DEFAULT_DISPLAY = cast(EGLNativeDisplayType)0;
54 enum EGLContext EGL_NO_CONTEXT = null;
55 enum EGLDisplay EGL_NO_DISPLAY = null;
56 enum EGLSurface EGL_NO_SURFACE = null;
57 enum EGLSync EGL_NO_SYNC       = null;
58 
59 /* Out-of-band attribute value */
60 enum EGLint EGL_DONT_CARE = -1;
61 
62 enum : EGLint {
63     /* Errors / GetError return values */
64     EGL_SUCCESS                     = 0x3000,
65     EGL_NOT_INITIALIZED             = 0x3001,
66     EGL_BAD_ACCESS                  = 0x3002,
67     EGL_BAD_ALLOC                   = 0x3003,
68     EGL_BAD_ATTRIBUTE               = 0x3004,
69     EGL_BAD_CONFIG                  = 0x3005,
70     EGL_BAD_CONTEXT                 = 0x3006,
71     EGL_BAD_CURRENT_SURFACE         = 0x3007,
72     EGL_BAD_DISPLAY                 = 0x3008,
73     EGL_BAD_MATCH                   = 0x3009,
74     EGL_BAD_NATIVE_PIXMAP           = 0x300A,
75     EGL_BAD_NATIVE_WINDOW           = 0x300B,
76     EGL_BAD_PARAMETER               = 0x300C,
77     EGL_BAD_SURFACE                 = 0x300D,
78     EGL_CONTEXT_LOST                = 0x300E,  /* EGL 1.1 - IMG_power_management */
79     /* Reserved 0x300F-0x301F for additional errors */
80 
81     /* Config attributes */
82     EGL_BUFFER_SIZE                 = 0x3020,
83     EGL_ALPHA_SIZE                  = 0x3021,
84     EGL_BLUE_SIZE                   = 0x3022,
85     EGL_GREEN_SIZE                  = 0x3023,
86     EGL_RED_SIZE                    = 0x3024,
87     EGL_DEPTH_SIZE                  = 0x3025,
88     EGL_STENCIL_SIZE                = 0x3026,
89     EGL_CONFIG_CAVEAT               = 0x3027,
90     EGL_CONFIG_ID                   = 0x3028,
91     EGL_LEVEL                       = 0x3029,
92     EGL_MAX_PBUFFER_HEIGHT          = 0x302A,
93     EGL_MAX_PBUFFER_PIXELS          = 0x302B,
94     EGL_MAX_PBUFFER_WIDTH           = 0x302C,
95     EGL_NATIVE_RENDERABLE           = 0x302D,
96     EGL_NATIVE_VISUAL_ID            = 0x302E,
97     EGL_NATIVE_VISUAL_TYPE          = 0x302F,
98     EGL_SAMPLES                     = 0x3031,
99     EGL_SAMPLE_BUFFERS              = 0x3032,
100     EGL_SURFACE_TYPE                = 0x3033,
101     EGL_TRANSPARENT_TYPE            = 0x3034,
102     EGL_TRANSPARENT_BLUE_VALUE      = 0x3035,
103     EGL_TRANSPARENT_GREEN_VALUE     = 0x3036,
104     EGL_TRANSPARENT_RED_VALUE       = 0x3037,
105     EGL_NONE                        = 0x3038,  /* Attrib list terminator */
106     EGL_BIND_TO_TEXTURE_RGB         = 0x3039,
107     EGL_BIND_TO_TEXTURE_RGBA        = 0x303A,
108     EGL_MIN_SWAP_INTERVAL           = 0x303B,
109     EGL_MAX_SWAP_INTERVAL           = 0x303C,
110     EGL_LUMINANCE_SIZE              = 0x303D,
111     EGL_ALPHA_MASK_SIZE             = 0x303E,
112     EGL_COLOR_BUFFER_TYPE           = 0x303F,
113     EGL_RENDERABLE_TYPE             = 0x3040,
114     EGL_MATCH_NATIVE_PIXMAP         = 0x3041,  /* Pseudo-attribute (not queryable) */
115     EGL_CONFORMANT                  = 0x3042,
116 
117     /* Reserved 0x3041-0x304F for additional config attributes */
118 
119     /* Config attribute values */
120     EGL_SLOW_CONFIG                 = 0x3050,  /* EGL_CONFIG_CAVEAT value */
121     EGL_NON_CONFORMANT_CONFIG       = 0x3051,  /* EGL_CONFIG_CAVEAT value */
122     EGL_TRANSPARENT_RGB             = 0x3052,  /* EGL_TRANSPARENT_TYPE value */
123     EGL_RGB_BUFFER                  = 0x308E,  /* EGL_COLOR_BUFFER_TYPE value */
124     EGL_LUMINANCE_BUFFER            = 0x308F,  /* EGL_COLOR_BUFFER_TYPE value */
125 
126     /* More config attribute values, for EGL_TEXTURE_FORMAT */
127     EGL_NO_TEXTURE                  = 0x305C,
128     EGL_TEXTURE_RGB                 = 0x305D,
129     EGL_TEXTURE_RGBA                = 0x305E,
130     EGL_TEXTURE_2D                  = 0x305F,
131 
132     /* Config attribute mask bits */
133     EGL_PBUFFER_BIT                 = 0x0001,  /* EGL_SURFACE_TYPE mask bits */
134     EGL_PIXMAP_BIT                  = 0x0002,  /* EGL_SURFACE_TYPE mask bits */
135     EGL_WINDOW_BIT                  = 0x0004,  /* EGL_SURFACE_TYPE mask bits */
136     EGL_VG_COLORSPACE_LINEAR_BIT    = 0x0020,  /* EGL_SURFACE_TYPE mask bits */
137     EGL_VG_ALPHA_FORMAT_PRE_BIT     = 0x0040,  /* EGL_SURFACE_TYPE mask bits */
138     EGL_MULTISAMPLE_RESOLVE_BOX_BIT = 0x0200,  /* EGL_SURFACE_TYPE mask bits */
139     EGL_SWAP_BEHAVIOR_PRESERVED_BIT = 0x0400,  /* EGL_SURFACE_TYPE mask bits */
140 
141     EGL_OPENGL_ES_BIT               = 0x0001,  /* EGL_RENDERABLE_TYPE mask bits */
142     EGL_OPENVG_BIT                  = 0x0002,  /* EGL_RENDERABLE_TYPE mask bits */
143     EGL_OPENGL_ES2_BIT              = 0x0004,  /* EGL_RENDERABLE_TYPE mask bits */
144     EGL_OPENGL_BIT                  = 0x0008,  /* EGL_RENDERABLE_TYPE mask bits */
145 
146     /* QueryString targets */
147     EGL_VENDOR                      = 0x3053,
148     EGL_VERSION                     = 0x3054,
149     EGL_EXTENSIONS                  = 0x3055,
150     EGL_CLIENT_APIS                 = 0x308D,
151 
152     /* QuerySurface / SurfaceAttrib / CreatePbufferSurface targets */
153     EGL_HEIGHT                      = 0x3056,
154     EGL_WIDTH                       = 0x3057,
155     EGL_LARGEST_PBUFFER             = 0x3058,
156     EGL_TEXTURE_FORMAT              = 0x3080,
157     EGL_TEXTURE_TARGET              = 0x3081,
158     EGL_MIPMAP_TEXTURE              = 0x3082,
159     EGL_MIPMAP_LEVEL                = 0x3083,
160     EGL_RENDER_BUFFER               = 0x3086,
161     EGL_VG_COLORSPACE               = 0x3087,
162     EGL_VG_ALPHA_FORMAT             = 0x3088,
163     EGL_HORIZONTAL_RESOLUTION       = 0x3090,
164     EGL_VERTICAL_RESOLUTION         = 0x3091,
165     EGL_PIXEL_ASPECT_RATIO          = 0x3092,
166     EGL_SWAP_BEHAVIOR               = 0x3093,
167     EGL_MULTISAMPLE_RESOLVE         = 0x3099,
168 
169     /* EGL_RENDER_BUFFER values / BindTexImage / ReleaseTexImage buffer targets */
170     EGL_BACK_BUFFER                 = 0x3084,
171     EGL_SINGLE_BUFFER               = 0x3085,
172 
173     /* OpenVG color spaces */
174     EGL_VG_COLORSPACE_sRGB          = 0x3089,  /* EGL_VG_COLORSPACE value */
175     EGL_VG_COLORSPACE_LINEAR        = 0x308A,  /* EGL_VG_COLORSPACE value */
176 
177     /* OpenVG alpha formats */
178     EGL_VG_ALPHA_FORMAT_NONPRE      = 0x308B,  /* EGL_ALPHA_FORMAT value */
179     EGL_VG_ALPHA_FORMAT_PRE         = 0x308C,  /* EGL_ALPHA_FORMAT value */
180 
181     /* Constant scale factor by which fractional display resolutions &
182      * aspect ratio are scaled when queried as integer values.
183      */
184     EGL_DISPLAY_SCALING             = 10000,
185 
186     /* Unknown display resolution/aspect ratio */
187     EGL_UNKNOWN                     = -1,
188 
189     /* Back buffer swap behaviors */
190     EGL_BUFFER_PRESERVED            = 0x3094,  /* EGL_SWAP_BEHAVIOR value */
191     EGL_BUFFER_DESTROYED            = 0x3095,  /* EGL_SWAP_BEHAVIOR value */
192 
193     /* CreatePbufferFromClientBuffer buffer types */
194     EGL_OPENVG_IMAGE                = 0x3096,
195 
196     /* QueryContext targets */
197     EGL_CONTEXT_CLIENT_TYPE         = 0x3097,
198 
199     /* CreateContext attributes */
200     EGL_CONTEXT_CLIENT_VERSION      = 0x3098,
201 
202     /* Multisample resolution behaviors */
203     EGL_MULTISAMPLE_RESOLVE_DEFAULT = 0x309A,  /* EGL_MULTISAMPLE_RESOLVE value */
204     EGL_MULTISAMPLE_RESOLVE_BOX     = 0x309B,  /* EGL_MULTISAMPLE_RESOLVE value */
205 
206     /* BindAPI/QueryAPI targets */
207     EGL_OPENGL_ES_API               = 0x30A0,
208     EGL_OPENVG_API                  = 0x30A1,
209     EGL_OPENGL_API                  = 0x30A2,
210 
211     /* GetCurrentSurface targets */
212     EGL_DRAW                        = 0x3059,
213     EGL_READ                        = 0x305A,
214 
215     /* WaitNative engines */
216     EGL_CORE_NATIVE_ENGINE          = 0x305B,
217 
218     /* EGL 1.2 tokens renamed for consistency in EGL 1.3 */
219     EGL_COLORSPACE                  = EGL_VG_COLORSPACE,
220     EGL_ALPHA_FORMAT                = EGL_VG_ALPHA_FORMAT,
221     EGL_COLORSPACE_sRGB             = EGL_VG_COLORSPACE_sRGB,
222     EGL_COLORSPACE_LINEAR           = EGL_VG_COLORSPACE_LINEAR,
223     EGL_ALPHA_FORMAT_NONPRE         = EGL_VG_ALPHA_FORMAT_NONPRE,
224     EGL_ALPHA_FORMAT_PRE            = EGL_VG_ALPHA_FORMAT_PRE,
225 
226     /* EGL 1.5 */
227     EGL_CONTEXT_MAJOR_VERSION       = 0x3098,
228     EGL_CONTEXT_MINOR_VERSION       = 0x30FB,
229     EGL_CONTEXT_OPENGL_PROFILE_MASK = 0x30FD,
230     EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY = 0x31BD,
231     EGL_NO_RESET_NOTIFICATION       = 0x31BE,
232     EGL_LOSE_CONTEXT_ON_RESET       = 0x31BF,
233     EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT = 0x00000001,
234     EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT = 0x00000002,
235     EGL_CONTEXT_OPENGL_DEBUG        = 0x31B0,
236     EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE = 0x31B1,
237     EGL_CONTEXT_OPENGL_ROBUST_ACCESS = 0x31B2,
238     EGL_OPENGL_ES3_BIT              = 0x00000040,
239     EGL_CL_EVENT_HANDLE             = 0x309C,
240     EGL_SYNC_CL_EVENT               = 0x30FE,
241     EGL_SYNC_CL_EVENT_COMPLETE      = 0x30FF,
242     EGL_SYNC_PRIOR_COMMANDS_COMPLETE = 0x30F0,
243     EGL_SYNC_TYPE                   = 0x30F7,
244     EGL_SYNC_STATUS                 = 0x30F1,
245     EGL_SYNC_CONDITION              = 0x30F8,
246     EGL_SIGNALED                    = 0x30F2,
247     EGL_UNSIGNALED                  = 0x30F3,
248     EGL_SYNC_FLUSH_COMMANDS_BIT     = 0x0001,
249     EGL_TIMEOUT_EXPIRED             = 0x30F5,
250     EGL_CONDITION_SATISFIED         = 0x30F6,
251     EGL_SYNC_FENCE                  = 0x30F9,
252     EGL_GL_COLORSPACE               = 0x309D,
253     EGL_GL_COLORSPACE_SRGB          = 0x3089,
254     EGL_GL_COLORSPACE_LINEAR        = 0x308A,
255     EGL_GL_RENDERBUFFER             = 0x30B9,
256     EGL_GL_TEXTURE_2D               = 0x30B1,
257     EGL_GL_TEXTURE_LEVEL            = 0x30BC,
258     EGL_GL_TEXTURE_3D               = 0x30B2,
259     EGL_GL_TEXTURE_ZOFFSET          = 0x30BD,
260     EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X = 0x30B3,
261     EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X = 0x30B4,
262     EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y = 0x30B5,
263     EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y = 0x30B6,
264     EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z = 0x30B7,
265     EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x30B8,
266 }
267 
268 static const EGLTime EGL_FOREVER = 0xFFFFFFFFFFFFFFFFUL;
269 
270 // This is a Derelict type, not from OpenGLES
271 enum EGLVersion {
272     None,
273     EGL10,
274     EGL11,
275     EGL12,
276     EGL13,
277     EGL14,
278     EGL15,
279     HighestSupported = EGL15,
280 }
281 
282 /* EGL Functions */
283 extern( System ) nothrow {
284     alias da_eglGetError = EGLint function(  );
285     alias da_eglGetDisplay = EGLDisplay function( EGLNativeDisplayType );
286     alias da_eglInitialize = EGLBoolean function( EGLDisplay, EGLint*, EGLint* );
287     alias da_eglTerminate = EGLBoolean function( EGLDisplay );
288     alias da_eglQueryString = const( char )* function( EGLDisplay, EGLint );
289     alias da_eglGetConfigs = EGLBoolean function( EGLDisplay, EGLConfig*, EGLint, EGLint* );
290     alias da_eglChooseConfig = EGLBoolean function( EGLDisplay, const( EGLint )*, EGLConfig*, EGLint, EGLint* );
291     alias da_eglGetConfigAttrib = EGLBoolean function( EGLDisplay, EGLConfig, EGLint, EGLint* );
292     alias da_eglCreateWindowSurface = EGLSurface function( EGLDisplay, EGLConfig, EGLNativeWindowType, const( EGLint )* );
293     alias da_eglCreatePbufferSurface = EGLSurface function( EGLDisplay, EGLConfig, const( EGLint )* );
294     alias da_eglCreatePixmapSurface = EGLSurface function( EGLDisplay, EGLConfig, EGLNativePixmapType, const( EGLint )* );
295     alias da_eglDestroySurface = EGLBoolean function( EGLDisplay, EGLSurface );
296     alias da_eglQuerySurface = EGLBoolean function( EGLDisplay, EGLSurface, EGLint, EGLint* );
297     alias da_eglBindAPI = EGLBoolean function( EGLenum );
298     alias da_eglQueryAPI = EGLenum function(  );
299     alias da_eglWaitClient = EGLBoolean function(  );
300     alias da_eglReleaseThread = EGLBoolean function(  );
301     alias da_eglCreatePbufferFromClientBuffer = EGLSurface function( EGLDisplay, EGLenum, EGLClientBuffer, EGLConfig, const( EGLint )* );
302     alias da_eglSurfaceAttrib = EGLBoolean function( EGLDisplay, EGLSurface, EGLint, EGLint );
303     alias da_eglBindTexImage = EGLBoolean function( EGLDisplay, EGLSurface, EGLint );
304     alias da_eglReleaseTexImage = EGLBoolean function( EGLDisplay, EGLSurface, EGLint );
305     alias da_eglSwapInterval = EGLBoolean function( EGLDisplay, EGLint );
306     alias da_eglCreateContext = EGLContext function( EGLDisplay, EGLConfig, EGLContext, const( EGLint )* );
307     alias da_eglDestroyContext = EGLBoolean function( EGLDisplay, EGLContext );
308     alias da_eglMakeCurrent = EGLBoolean function( EGLDisplay, EGLSurface, EGLSurface, EGLContext );
309     alias da_eglGetCurrentContext = EGLContext function(  );
310     alias da_eglGetCurrentSurface = EGLSurface function( EGLint );
311     alias da_eglGetCurrentDisplay = EGLDisplay function(  );
312     alias da_eglQueryContext = EGLBoolean function( EGLDisplay, EGLContext, EGLint, EGLint* );
313     alias da_eglWaitGL = EGLBoolean function(  );
314     alias da_eglWaitNative = EGLBoolean function( EGLint );
315     alias da_eglSwapBuffers = EGLBoolean function( EGLDisplay, EGLSurface );
316     alias da_eglCopyBuffers = EGLBoolean function( EGLDisplay, EGLSurface, EGLNativePixmapType );
317 
318     /* This is a generic function pointer type, whose name indicates it must
319      * be cast to the proper type *and calling convention* before use.
320      */
321     alias __eglMustCastToProperFunctionPointerType = void function(  );
322 
323     /* Now, define eglGetProcAddress using the generic function ptr. type */
324     alias da_eglGetProcAddress = __eglMustCastToProperFunctionPointerType function( const( char )* );
325 
326     /* EGL 1.5 */
327     alias da_eglCreateSync = EGLSync function ( EGLDisplay, EGLenum, const( EGLAttrib )* );
328     alias da_eglDestroySync = EGLBoolean function ( EGLDisplay, EGLSync );
329     alias da_eglClientWaitSync = EGLint function ( EGLDisplay, EGLSync, EGLint, EGLTime );
330     alias da_eglGetSyncAttrib = EGLBoolean function ( EGLDisplay, EGLSync, EGLint, EGLAttrib* );
331     alias da_eglGetPlatformDisplay = EGLDisplay function ( EGLenum, void*, const( EGLAttrib )* );
332     alias da_eglCreatePlatformWindowSurface = EGLSurface function ( EGLDisplay, EGLConfig, void*, const( EGLAttrib )* );
333     alias da_eglCreatePlatformPixmapSurface = EGLSurface function ( EGLDisplay, EGLConfig, void*, const( EGLAttrib )* );
334     alias da_eglWaitSync = EGLBoolean function ( EGLDisplay, EGLSync, EGLint );
335 }
336 
337 __gshared {
338     da_eglGetError eglGetError;
339     da_eglGetDisplay eglGetDisplay;
340     da_eglInitialize eglInitialize;
341     da_eglTerminate eglTerminate;
342     da_eglQueryString eglQueryString;
343     da_eglGetConfigs eglGetConfigs;
344     da_eglChooseConfig eglChooseConfig;
345     da_eglGetConfigAttrib eglGetConfigAttrib;
346     da_eglCreateWindowSurface eglCreateWindowSurface;
347     da_eglCreatePbufferSurface eglCreatePbufferSurface;
348     da_eglCreatePixmapSurface eglCreatePixmapSurface;
349     da_eglDestroySurface eglDestroySurface;
350     da_eglQuerySurface eglQuerySurface;
351     da_eglBindAPI eglBindAPI;
352     da_eglQueryAPI eglQueryAPI;
353     da_eglWaitClient eglWaitClient;
354     da_eglReleaseThread eglReleaseThread;
355     da_eglCreatePbufferFromClientBuffer eglCreatePbufferFromClientBuffer;
356     da_eglSurfaceAttrib eglSurfaceAttrib;
357     da_eglBindTexImage eglBindTexImage;
358     da_eglReleaseTexImage eglReleaseTexImage;
359     da_eglSwapInterval eglSwapInterval;
360     da_eglCreateContext eglCreateContext;
361     da_eglDestroyContext eglDestroyContext;
362     da_eglMakeCurrent eglMakeCurrent;
363     da_eglGetCurrentContext eglGetCurrentContext;
364     da_eglGetCurrentSurface eglGetCurrentSurface;
365     da_eglGetCurrentDisplay eglGetCurrentDisplay;
366     da_eglQueryContext eglQueryContext;
367     da_eglWaitGL eglWaitGL;
368     da_eglWaitNative eglWaitNative;
369     da_eglSwapBuffers eglSwapBuffers;
370     da_eglCopyBuffers eglCopyBuffers;
371     da_eglGetProcAddress eglGetProcAddress;
372     da_eglCreateSync eglCreateSync;
373     da_eglDestroySync eglDestroySync;
374     da_eglClientWaitSync eglClientWaitSync;
375     da_eglGetSyncAttrib eglGetSyncAttrib;
376     da_eglGetPlatformDisplay eglGetPlatformDisplay;
377     da_eglCreatePlatformWindowSurface eglCreatePlatformWindowSurface;
378     da_eglCreatePlatformPixmapSurface eglCreatePlatformPixmapSurface;
379     da_eglWaitSync eglWaitSync;
380 }
381 
382 class DerelictEGLLoader : SharedLibLoader
383 {
384     private EGLVersion _loadedVersion;
385 
386     public
387     {
388         this() {
389             super( libNames );
390         }
391 
392         EGLVersion loadedVersion() @property {
393             return _loadedVersion;
394         }
395 
396         protected override void loadSymbols() {
397             // EGL 1.0
398             bindFunc( cast( void** )&eglGetError, "eglGetError" );
399             bindFunc( cast( void** )&eglGetDisplay, "eglGetDisplay" );
400             bindFunc( cast( void** )&eglInitialize, "eglInitialize" );
401             bindFunc( cast( void** )&eglTerminate, "eglTerminate" );
402 
403             EGLDisplay disp = eglGetDisplay( EGL_DEFAULT_DISPLAY );
404             if( disp == EGL_NO_DISPLAY ) {
405                 throw new DerelictException( "Unable to get a display for EGL" );
406             }
407             EGLint major;
408             EGLint minor;
409             if( eglInitialize( disp, &major, &minor ) == EGL_FALSE ) {
410                 throw new DerelictException( "Failed to initialize the EGL display: " ~ to!string( eglGetError(  ) ) );
411             }
412 
413             if( major != 1 ) {
414                 eglTerminate( disp );
415                 throw new DerelictException( "The EGL version is not recognized: " ~ to!string( eglGetError(  ) ) );
416             }
417 
418             if( minor >= 0 ) {
419                 bindFunc( cast( void** )&eglQueryString, "eglQueryString" );
420                 bindFunc( cast( void** )&eglGetConfigs, "eglGetConfigs" );
421                 bindFunc( cast( void** )&eglChooseConfig, "eglChooseConfig" );
422                 bindFunc( cast( void** )&eglGetConfigAttrib, "eglGetConfigAttrib" );
423                 bindFunc( cast( void** )&eglCreateWindowSurface, "eglCreateWindowSurface" );
424                 bindFunc( cast( void** )&eglCreatePbufferSurface, "eglCreatePbufferSurface" );
425                 bindFunc( cast( void** )&eglCreatePixmapSurface, "eglCreatePixmapSurface" );
426                 bindFunc( cast( void** )&eglDestroySurface, "eglDestroySurface" );
427                 bindFunc( cast( void** )&eglQuerySurface, "eglQuerySurface" );
428                 bindFunc( cast( void** )&eglCreateContext, "eglCreateContext" );
429                 bindFunc( cast( void** )&eglDestroyContext, "eglDestroyContext" );
430                 bindFunc( cast( void** )&eglMakeCurrent, "eglMakeCurrent" );
431                 bindFunc( cast( void** )&eglGetCurrentSurface, "eglGetCurrentSurface" );
432                 bindFunc( cast( void** )&eglGetCurrentDisplay, "eglGetCurrentDisplay" );
433                 bindFunc( cast( void** )&eglQueryContext, "eglQueryContext" );
434                 bindFunc( cast( void** )&eglWaitGL, "eglWaitGL" );
435                 bindFunc( cast( void** )&eglWaitNative, "eglWaitNative" );
436                 bindFunc( cast( void** )&eglSwapBuffers, "eglSwapBuffers" );
437                 bindFunc( cast( void** )&eglCopyBuffers, "eglCopyBuffers" );
438                 bindFunc( cast( void** )&eglGetProcAddress, "eglGetProcAddress" );
439 
440                 _loadedVersion = EGLVersion.EGL10;
441             }
442             if( minor >= 1 ) {
443                 bindFunc( cast( void** )&eglSurfaceAttrib, "eglSurfaceAttrib" );
444                 bindFunc( cast( void** )&eglBindTexImage, "eglBindTexImage" );
445                 bindFunc( cast( void** )&eglReleaseTexImage, "eglReleaseTexImage" );
446                 bindFunc( cast( void** )&eglSwapInterval, "eglSwapInterval" );
447 
448                 _loadedVersion = EGLVersion.EGL11;
449             }
450             if( minor >= 2 ) {
451                 bindFunc( cast( void** )&eglBindAPI, "eglBindAPI" );
452                 bindFunc( cast( void** )&eglQueryAPI, "eglQueryAPI" );
453                 bindFunc( cast( void** )&eglWaitClient, "eglWaitClient" );
454                 bindFunc( cast( void** )&eglReleaseThread, "eglReleaseThread" );
455                 bindFunc( cast( void** )&eglCreatePbufferFromClientBuffer, "eglCreatePbufferFromClientBuffer" );
456 
457                 _loadedVersion = EGLVersion.EGL12;
458             }
459             if( minor >= 3 ) {
460                 _loadedVersion = EGLVersion.EGL13;
461             }
462             if( minor >= 4 ) {
463                 bindFunc( cast( void** )&eglGetCurrentContext, "eglGetCurrentContext" );
464 
465                 _loadedVersion = EGLVersion.EGL14;
466             }
467             if( minor >= 5 ) {
468                 bindFunc( cast( void** )&eglCreateSync, "eglCreateSync" );
469                 bindFunc( cast( void** )&eglDestroySync, "eglDestroySync" );
470                 bindFunc( cast( void** )&eglClientWaitSync, "eglClientWaitSync" );
471                 bindFunc( cast( void** )&eglGetSyncAttrib, "eglGetSyncAttrib" );
472                 bindFunc( cast( void** )&eglGetPlatformDisplay, "eglGetPlatformDisplay" );
473                 bindFunc( cast( void** )&eglCreatePlatformWindowSurface, "eglCreatePlatformWindowSurface" );
474                 bindFunc( cast( void** )&eglCreatePlatformPixmapSurface, "eglCreatePlatformPixmapSurface" );
475                 bindFunc( cast( void** )&eglWaitSync, "eglWaitSync" );
476 
477                 _loadedVersion = EGLVersion.EGL15;
478             }
479 
480             loadEXT( disp );
481             if( eglTerminate( disp ) == EGL_FALSE ) {
482                 throw new DerelictException( "Failed to terminate the EGL display: " ~ to!string( eglGetError(  ) ) );
483             }
484         }
485     }
486 }
487 
488 __gshared DerelictEGLLoader DerelictEGL;
489 
490 shared static this() {
491     DerelictEGL = new DerelictEGLLoader;
492 }