src/video/SDL_egl.h
author Sam Lantinga <slouken@libsdl.org>
Sun, 14 Jul 2013 11:28:44 -0700
changeset 7776 d4a39491577f
parent 7659 ac4ce59c40e7
child 8541 0041edb891f3
permissions -rw-r--r--
Added the platform specific messagebox function to the video function list
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 #include "SDL_config.h"
    22 
    23 #ifndef _SDL_egl_h
    24 #define _SDL_egl_h
    25 
    26 #if SDL_VIDEO_OPENGL_EGL
    27 
    28 #include <EGL/egl.h>
    29 
    30 #include <dlfcn.h>
    31 #if defined(__OpenBSD__) && !defined(__ELF__)
    32 #define dlsym(x,y) dlsym(x, "_" y)
    33 #endif
    34 
    35 #include "SDL_sysvideo.h"
    36 
    37 typedef struct SDL_EGL_VideoData
    38 {
    39     void *egl_dll_handle;
    40     EGLDisplay egl_display;
    41     EGLConfig egl_config;
    42     int egl_swapinterval;
    43     
    44     EGLDisplay(*eglGetDisplay) (NativeDisplayType display);
    45     EGLBoolean(*eglInitialize) (EGLDisplay dpy, EGLint * major,
    46                                 EGLint * minor);
    47     EGLBoolean(*eglTerminate) (EGLDisplay dpy);
    48     
    49     void *(*eglGetProcAddress) (const char * procName);
    50     
    51     EGLBoolean(*eglChooseConfig) (EGLDisplay dpy,
    52                                   const EGLint * attrib_list,
    53                                   EGLConfig * configs,
    54                                   EGLint config_size, EGLint * num_config);
    55     
    56     EGLContext(*eglCreateContext) (EGLDisplay dpy,
    57                                    EGLConfig config,
    58                                    EGLContext share_list,
    59                                    const EGLint * attrib_list);
    60     
    61     EGLBoolean(*eglDestroyContext) (EGLDisplay dpy, EGLContext ctx);
    62     
    63     EGLSurface(*eglCreateWindowSurface) (EGLDisplay dpy,
    64                                          EGLConfig config,
    65                                          NativeWindowType window,
    66                                          const EGLint * attrib_list);
    67     EGLBoolean(*eglDestroySurface) (EGLDisplay dpy, EGLSurface surface);
    68     
    69     EGLBoolean(*eglMakeCurrent) (EGLDisplay dpy, EGLSurface draw,
    70                                  EGLSurface read, EGLContext ctx);
    71     
    72     EGLBoolean(*eglSwapBuffers) (EGLDisplay dpy, EGLSurface draw);
    73     
    74     EGLBoolean(*eglSwapInterval) (EGLDisplay dpy, EGLint interval);
    75     
    76     const char *(*eglQueryString) (EGLDisplay dpy, EGLint name);
    77     
    78     EGLBoolean(*eglGetConfigAttrib) (EGLDisplay dpy, EGLConfig config,
    79                                      EGLint attribute, EGLint * value);
    80     
    81     EGLBoolean(*eglWaitNative) (EGLint  engine);
    82 
    83     EGLBoolean(*eglWaitGL)(void);   
    84 } SDL_EGL_VideoData;
    85 
    86 /* OpenGLES functions */
    87 extern int SDL_EGL_GetAttribute(_THIS, SDL_GLattr attrib, int *value);
    88 extern int SDL_EGL_LoadLibrary(_THIS, const char *path, NativeDisplayType native_display);
    89 extern void *SDL_EGL_GetProcAddress(_THIS, const char *proc);
    90 extern void SDL_EGL_UnloadLibrary(_THIS);
    91 extern int SDL_EGL_ChooseConfig(_THIS);
    92 extern int SDL_EGL_SetSwapInterval(_THIS, int interval);
    93 extern int SDL_EGL_GetSwapInterval(_THIS);
    94 extern void SDL_EGL_DeleteContext(_THIS, SDL_GLContext context);
    95 extern EGLSurface *SDL_EGL_CreateSurface(_THIS, NativeWindowType nw);
    96 extern void SDL_EGL_DestroySurface(_THIS, EGLSurface egl_surface);
    97 
    98 /* These need to be wrapped to get the surface for the window by the platform GLES implementation */
    99 extern SDL_GLContext SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface);
   100 extern int SDL_EGL_MakeCurrent(_THIS, EGLSurface egl_surface, SDL_GLContext context);
   101 extern void SDL_EGL_SwapBuffers(_THIS, EGLSurface egl_surface);
   102 
   103 /* A few of useful macros */
   104 
   105 #define SDL_EGL_SwapWindow_impl(BACKEND) void \
   106 BACKEND ## _GLES_SwapWindow(_THIS, SDL_Window * window) \
   107 {\
   108     SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);\
   109 }
   110 
   111 #define SDL_EGL_MakeCurrent_impl(BACKEND) int \
   112 BACKEND ## _GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) \
   113 {\
   114     if (window && context) { \
   115         return SDL_EGL_MakeCurrent(_this, ((SDL_WindowData *) window->driverdata)->egl_surface, context); \
   116     }\
   117     else {\
   118         return SDL_EGL_MakeCurrent(_this, NULL, NULL);\
   119     }\
   120 }
   121 
   122 #define SDL_EGL_CreateContext_impl(BACKEND) SDL_GLContext \
   123 BACKEND ## _GLES_CreateContext(_THIS, SDL_Window * window) \
   124 {\
   125     return SDL_EGL_CreateContext(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);\
   126 }
   127 
   128 #endif /* SDL_VIDEO_OPENGL_EGL */
   129 
   130 #endif /* _SDL_egl_h */
   131 
   132 /* vi: set ts=4 sw=4 expandtab: */