src/video/SDL_sysvideo.h
author Sam Lantinga <slouken@libsdl.org>
Sun, 12 Aug 2012 11:16:24 -0700
changeset 6393 a773384edf20
parent 6392 fa7eb111f994
child 6422 fd0ac1b56115
permissions -rwxr-xr-x
Fixed bug 1565 - some small GL context creation enhancements

Matthias Bentrup 2012-08-09 12:53:17 PDT

With OpenGL 4.3 the ARB added a new context flag for context reset isolation
and renamed the existing ES2 profile bit to ES profile bit, as it can be used
to request GLES 3 compatible contexts, too.

This patch adds these changes to SDL on Linux and Windows.

Also SDL lacks the ability to create shared contexts. This patch also adds a
new GL attribute to enable context sharing. As casting a GL context to int is
not portable, I added only a boolean attribute
SDL_GL_SHARE_WITH_CURRENT_CONTEXT, which makes the new context share resources
with the context current on the creating thread.
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2012 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_sysvideo_h
    24 #define _SDL_sysvideo_h
    25 
    26 #include "SDL_shape.h"
    27 
    28 /* The SDL video driver */
    29 
    30 typedef struct SDL_WindowShaper SDL_WindowShaper;
    31 typedef struct SDL_ShapeDriver SDL_ShapeDriver;
    32 typedef struct SDL_VideoDisplay SDL_VideoDisplay;
    33 typedef struct SDL_VideoDevice SDL_VideoDevice;
    34 
    35 /* Define the SDL window-shaper structure */
    36 struct SDL_WindowShaper
    37 {   
    38     /* The window associated with the shaper */
    39     SDL_Window *window;
    40     
    41     /* The user's specified coordinates for the window, for once we give it a shape. */
    42     Uint32 userx,usery;
    43     
    44     /* The parameters for shape calculation. */
    45     SDL_WindowShapeMode mode;
    46     
    47     /* Has this window been assigned a shape? */
    48     SDL_bool hasshape;
    49     
    50     void *driverdata;
    51 };
    52 
    53 /* Define the SDL shape driver structure */
    54 struct SDL_ShapeDriver
    55 {
    56     SDL_WindowShaper *(*CreateShaper)(SDL_Window * window);
    57     int (*SetWindowShape)(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
    58     int (*ResizeWindowShape)(SDL_Window *window);
    59 };
    60 
    61 typedef struct SDL_WindowUserData
    62 {
    63     char *name;
    64     void *data;
    65     struct SDL_WindowUserData *next;
    66 } SDL_WindowUserData;
    67 
    68 /* Define the SDL window structure, corresponding to toplevel windows */
    69 struct SDL_Window
    70 {
    71     const void *magic;
    72     Uint32 id;
    73     char *title;
    74     int x, y;
    75     int w, h;
    76     Uint32 flags;
    77 
    78     /* Stored position and size for windowed mode */
    79     SDL_Rect windowed;
    80 
    81     SDL_DisplayMode fullscreen_mode;
    82     
    83     float brightness;
    84     Uint16 *gamma;
    85     Uint16 *saved_gamma;        /* (just offset into gamma) */
    86 
    87     SDL_Surface *surface;
    88     SDL_bool surface_valid;
    89 
    90     SDL_WindowShaper *shaper;
    91 
    92     SDL_WindowUserData *data;
    93 
    94     void *driverdata;
    95 
    96     SDL_Window *prev;
    97     SDL_Window *next;
    98 };
    99 #define FULLSCREEN_VISIBLE(W) \
   100     (((W)->flags & SDL_WINDOW_FULLSCREEN) && \
   101      ((W)->flags & SDL_WINDOW_SHOWN) && \
   102      !((W)->flags & SDL_WINDOW_MINIMIZED))
   103 
   104 /*
   105  * Define the SDL display structure This corresponds to physical monitors
   106  * attached to the system.
   107  */
   108 struct SDL_VideoDisplay
   109 {
   110     int max_display_modes;
   111     int num_display_modes;
   112     SDL_DisplayMode *display_modes;
   113     SDL_DisplayMode desktop_mode;
   114     SDL_DisplayMode current_mode;
   115 
   116     SDL_Window *fullscreen_window;
   117 
   118     SDL_VideoDevice *device;
   119 
   120     void *driverdata;
   121 };
   122 
   123 /* Forward declaration */
   124 struct SDL_SysWMinfo;
   125 
   126 /* Define the SDL video driver structure */
   127 #define _THIS	SDL_VideoDevice *_this
   128 
   129 struct SDL_VideoDevice
   130 {
   131     /* * * */
   132     /* The name of this video driver */
   133     const char *name;
   134 
   135     /* * * */
   136     /* Initialization/Query functions */
   137 
   138     /*
   139      * Initialize the native video subsystem, filling in the list of
   140      * displays for this driver, returning 0 or -1 if there's an error.
   141      */
   142     int (*VideoInit) (_THIS);
   143 
   144     /*
   145      * Reverse the effects VideoInit() -- called if VideoInit() fails or
   146      * if the application is shutting down the video subsystem.
   147      */
   148     void (*VideoQuit) (_THIS);
   149 
   150     /* * * */
   151     /*
   152      * Display functions
   153      */
   154 
   155     /*
   156      * Get the bounds of a display
   157      */
   158     int (*GetDisplayBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
   159 
   160     /*
   161      * Get a list of the available display modes for a display.
   162      */
   163     void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display);
   164 
   165     /*
   166      * Setting the display mode is independent of creating windows, so
   167      * when the display mode is changed, all existing windows should have
   168      * their data updated accordingly, including the display surfaces
   169      * associated with them.
   170      */
   171     int (*SetDisplayMode) (_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
   172 
   173     /* * * */
   174     /*
   175      * Window functions
   176      */
   177     int (*CreateWindow) (_THIS, SDL_Window * window);
   178     int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
   179     void (*SetWindowTitle) (_THIS, SDL_Window * window);
   180     void (*SetWindowIcon) (_THIS, SDL_Window * window, SDL_Surface * icon);
   181     void (*SetWindowPosition) (_THIS, SDL_Window * window);
   182     void (*SetWindowSize) (_THIS, SDL_Window * window);
   183     void (*ShowWindow) (_THIS, SDL_Window * window);
   184     void (*HideWindow) (_THIS, SDL_Window * window);
   185     void (*RaiseWindow) (_THIS, SDL_Window * window);
   186     void (*MaximizeWindow) (_THIS, SDL_Window * window);
   187     void (*MinimizeWindow) (_THIS, SDL_Window * window);
   188     void (*RestoreWindow) (_THIS, SDL_Window * window);
   189     void (*SetWindowFullscreen) (_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
   190     int (*SetWindowGammaRamp) (_THIS, SDL_Window * window, const Uint16 * ramp);
   191     int (*GetWindowGammaRamp) (_THIS, SDL_Window * window, Uint16 * ramp);
   192     void (*SetWindowGrab) (_THIS, SDL_Window * window);
   193     void (*DestroyWindow) (_THIS, SDL_Window * window);
   194     int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
   195     int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, SDL_Rect * rects, int numrects);
   196     void (*DestroyWindowFramebuffer) (_THIS, SDL_Window * window);
   197 
   198     /* * * */
   199     /*
   200      * Shaped-window functions
   201      */
   202     SDL_ShapeDriver shape_driver;
   203 
   204     /* Get some platform dependent window information */
   205       SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
   206                                   struct SDL_SysWMinfo * info);
   207 
   208     /* * * */
   209     /*
   210      * OpenGL support
   211      */
   212     int (*GL_LoadLibrary) (_THIS, const char *path);
   213     void *(*GL_GetProcAddress) (_THIS, const char *proc);
   214     void (*GL_UnloadLibrary) (_THIS);
   215       SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
   216     int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
   217     int (*GL_SetSwapInterval) (_THIS, int interval);
   218     int (*GL_GetSwapInterval) (_THIS);
   219     void (*GL_SwapWindow) (_THIS, SDL_Window * window);
   220     void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
   221 
   222     /* * * */
   223     /*
   224      * Event manager functions
   225      */
   226     void (*PumpEvents) (_THIS);
   227 
   228     /* Suspend the screensaver */
   229     void (*SuspendScreenSaver) (_THIS);
   230 
   231     /* Text input */
   232     void (*StartTextInput) (_THIS);
   233     void (*StopTextInput) (_THIS);
   234     void (*SetTextInputRect) (_THIS, SDL_Rect *rect);
   235 
   236     /* Screen keyboard */
   237     SDL_bool (*SDL_HasScreenKeyboardSupport) (_THIS, SDL_Window *window);
   238     int (*SDL_ShowScreenKeyboard) (_THIS, SDL_Window *window);
   239     int (*SDL_HideScreenKeyboard) (_THIS, SDL_Window *window);
   240     int (*SDL_ToggleScreenKeyboard) (_THIS, SDL_Window *window);
   241     SDL_bool (*SDL_IsScreenKeyboardShown) (_THIS, SDL_Window *window);
   242 
   243     /* Clipboard */
   244     int (*SetClipboardText) (_THIS, const char *text);
   245     char * (*GetClipboardText) (_THIS);
   246     SDL_bool (*HasClipboardText) (_THIS);
   247 
   248     /* * * */
   249     /* Data common to all drivers */
   250     SDL_bool suspend_screensaver;
   251     int num_displays;
   252     SDL_VideoDisplay *displays;
   253     SDL_Window *windows;
   254     Uint8 window_magic;
   255     Uint32 next_object_id;
   256     char * clipboard_text;
   257 
   258     /* * * */
   259     /* Data used by the GL drivers */
   260     struct
   261     {
   262         int red_size;
   263         int green_size;
   264         int blue_size;
   265         int alpha_size;
   266         int depth_size;
   267         int buffer_size;
   268         int stencil_size;
   269         int double_buffer;
   270         int accum_red_size;
   271         int accum_green_size;
   272         int accum_blue_size;
   273         int accum_alpha_size;
   274         int stereo;
   275         int multisamplebuffers;
   276         int multisamplesamples;
   277         int accelerated;
   278         int major_version;
   279         int minor_version;
   280         int flags;
   281         int profile_mask;
   282         int use_egl;
   283         int share_with_current_context;
   284         int retained_backing;
   285         int driver_loaded;
   286         char driver_path[256];
   287         void *dll_handle;
   288     } gl_config;
   289 
   290     /* * * */
   291     /* Cache current GL context; don't call the OS when it hasn't changed. */
   292     SDL_Window *current_glwin;
   293     SDL_GLContext current_glctx;
   294 
   295     /* * * */
   296     /* Data private to this driver */
   297     void *driverdata;
   298     struct SDL_GLDriverData *gl_data;
   299 
   300 #if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
   301     struct SDL_PrivateGLESData *gles_data;
   302 #endif
   303 
   304     /* * * */
   305     /* The function used to dispose of this structure */
   306     void (*free) (_THIS);
   307 };
   308 
   309 typedef struct VideoBootStrap
   310 {
   311     const char *name;
   312     const char *desc;
   313     int (*available) (void);
   314     SDL_VideoDevice *(*create) (int devindex);
   315 } VideoBootStrap;
   316 
   317 #if SDL_VIDEO_DRIVER_COCOA
   318 extern VideoBootStrap COCOA_bootstrap;
   319 #endif
   320 #if SDL_VIDEO_DRIVER_X11
   321 extern VideoBootStrap X11_bootstrap;
   322 #endif
   323 #if SDL_VIDEO_DRIVER_DIRECTFB
   324 extern VideoBootStrap DirectFB_bootstrap;
   325 #endif
   326 #if SDL_VIDEO_DRIVER_WINDOWS
   327 extern VideoBootStrap WINDOWS_bootstrap;
   328 #endif
   329 #if SDL_VIDEO_DRIVER_BWINDOW
   330 extern VideoBootStrap BWINDOW_bootstrap;
   331 #endif
   332 #if SDL_VIDEO_DRIVER_PANDORA
   333 extern VideoBootStrap PND_bootstrap;
   334 #endif
   335 #if SDL_VIDEO_DRIVER_NDS
   336 extern VideoBootStrap NDS_bootstrap;
   337 #endif
   338 #if SDL_VIDEO_DRIVER_UIKIT
   339 extern VideoBootStrap UIKIT_bootstrap;
   340 #endif
   341 #if SDL_VIDEO_DRIVER_ANDROID
   342 extern VideoBootStrap Android_bootstrap;
   343 #endif
   344 #if SDL_VIDEO_DRIVER_DUMMY
   345 extern VideoBootStrap DUMMY_bootstrap;
   346 #endif
   347 
   348 extern SDL_VideoDevice *SDL_GetVideoDevice(void);
   349 extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
   350 extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
   351 extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
   352 extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window);
   353 
   354 extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
   355 
   356 extern void SDL_OnWindowShown(SDL_Window * window);
   357 extern void SDL_OnWindowHidden(SDL_Window * window);
   358 extern void SDL_OnWindowResized(SDL_Window * window);
   359 extern void SDL_OnWindowMinimized(SDL_Window * window);
   360 extern void SDL_OnWindowRestored(SDL_Window * window);
   361 extern void SDL_OnWindowFocusGained(SDL_Window * window);
   362 extern void SDL_OnWindowFocusLost(SDL_Window * window);
   363 extern SDL_Window * SDL_GetFocusWindow(void);
   364 
   365 #endif /* _SDL_sysvideo_h */
   366 
   367 /* vi: set ts=4 sw=4 expandtab: */