src/video/SDL_sysvideo.h
author Sam Lantinga <slouken@libsdl.org>
Mon, 20 Feb 2012 23:37:57 -0500
changeset 6296 b42657486c0d
parent 6188 e82023802002
child 6370 93187f7f7d5d
permissions -rwxr-xr-x
Add OpenGL 3.X context creation support

Matthias Bentrup 2011-10-30 03:58:24 PDT

I've updated the context creation patch to include the bugfixes by Martin
Schreiber and also included a profile bit to request a ES2 compatible profile.

The wgl context creation may use 2 call to wglChoosePixelFormat if no
acceleration attribute is selected, this should work around a bug with buggy
AMD drivers (see #1254).
     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     /* Clipboard */
   237     int (*SetClipboardText) (_THIS, const char *text);
   238     char * (*GetClipboardText) (_THIS);
   239     SDL_bool (*HasClipboardText) (_THIS);
   240 
   241     /* * * */
   242     /* Data common to all drivers */
   243     SDL_bool suspend_screensaver;
   244     int num_displays;
   245     SDL_VideoDisplay *displays;
   246     SDL_Window *windows;
   247     Uint8 window_magic;
   248     Uint32 next_object_id;
   249     char * clipboard_text;
   250 
   251     /* * * */
   252     /* Data used by the GL drivers */
   253     struct
   254     {
   255         int red_size;
   256         int green_size;
   257         int blue_size;
   258         int alpha_size;
   259         int depth_size;
   260         int buffer_size;
   261         int stencil_size;
   262         int double_buffer;
   263         int accum_red_size;
   264         int accum_green_size;
   265         int accum_blue_size;
   266         int accum_alpha_size;
   267         int stereo;
   268         int multisamplebuffers;
   269         int multisamplesamples;
   270         int accelerated;
   271         int major_version;
   272         int minor_version;
   273         int flags;
   274         int profile_mask;
   275         int retained_backing;
   276         int driver_loaded;
   277         char driver_path[256];
   278         void *dll_handle;
   279     } gl_config;
   280 
   281     /* * * */
   282     /* Cache current GL context; don't call the OS when it hasn't changed. */
   283     SDL_Window *current_glwin;
   284     SDL_GLContext current_glctx;
   285 
   286     /* * * */
   287     /* Data private to this driver */
   288     void *driverdata;
   289     struct SDL_GLDriverData *gl_data;
   290 
   291 #if SDL_VIDEO_OPENGL_ES
   292     struct SDL_PrivateGLESData *gles_data;
   293 #endif
   294 
   295     /* * * */
   296     /* The function used to dispose of this structure */
   297     void (*free) (_THIS);
   298 };
   299 
   300 typedef struct VideoBootStrap
   301 {
   302     const char *name;
   303     const char *desc;
   304     int (*available) (void);
   305     SDL_VideoDevice *(*create) (int devindex);
   306 } VideoBootStrap;
   307 
   308 #if SDL_VIDEO_DRIVER_COCOA
   309 extern VideoBootStrap COCOA_bootstrap;
   310 #endif
   311 #if SDL_VIDEO_DRIVER_X11
   312 extern VideoBootStrap X11_bootstrap;
   313 #endif
   314 #if SDL_VIDEO_DRIVER_DIRECTFB
   315 extern VideoBootStrap DirectFB_bootstrap;
   316 #endif
   317 #if SDL_VIDEO_DRIVER_WINDOWS
   318 extern VideoBootStrap WINDOWS_bootstrap;
   319 #endif
   320 #if SDL_VIDEO_DRIVER_BWINDOW
   321 extern VideoBootStrap BWINDOW_bootstrap;
   322 #endif
   323 #if SDL_VIDEO_DRIVER_PANDORA
   324 extern VideoBootStrap PND_bootstrap;
   325 #endif
   326 #if SDL_VIDEO_DRIVER_NDS
   327 extern VideoBootStrap NDS_bootstrap;
   328 #endif
   329 #if SDL_VIDEO_DRIVER_UIKIT
   330 extern VideoBootStrap UIKIT_bootstrap;
   331 #endif
   332 #if SDL_VIDEO_DRIVER_ANDROID
   333 extern VideoBootStrap Android_bootstrap;
   334 #endif
   335 #if SDL_VIDEO_DRIVER_DUMMY
   336 extern VideoBootStrap DUMMY_bootstrap;
   337 #endif
   338 
   339 extern SDL_VideoDevice *SDL_GetVideoDevice(void);
   340 extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
   341 extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
   342 extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
   343 extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window);
   344 
   345 extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
   346 
   347 extern void SDL_OnWindowShown(SDL_Window * window);
   348 extern void SDL_OnWindowHidden(SDL_Window * window);
   349 extern void SDL_OnWindowResized(SDL_Window * window);
   350 extern void SDL_OnWindowMinimized(SDL_Window * window);
   351 extern void SDL_OnWindowRestored(SDL_Window * window);
   352 extern void SDL_OnWindowFocusGained(SDL_Window * window);
   353 extern void SDL_OnWindowFocusLost(SDL_Window * window);
   354 extern SDL_Window * SDL_GetFocusWindow(void);
   355 
   356 #endif /* _SDL_sysvideo_h */
   357 
   358 /* vi: set ts=4 sw=4 expandtab: */