src/video/SDL_sysvideo.h
author Sam Lantinga <slouken@libsdl.org>
Fri, 07 Jul 2006 10:39:33 +0000
branchSDL-1.3
changeset 1729 0ef52d56e8bb
parent 1725 98a3207ddde8
child 1733 0b1070f2f94d
permissions -rw-r--r--
Fixed compile problems with new OpenGL API.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2006 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 #include "SDL_config.h"
    23 
    24 #ifndef _SDL_sysvideo_h
    25 #define _SDL_sysvideo_h
    26 
    27 #include "SDL_mouse.h"
    28 
    29 /* The SDL video driver */
    30 
    31 typedef struct SDL_Window SDL_Window;
    32 typedef struct SDL_Texture SDL_Texture;
    33 typedef struct SDL_Renderer SDL_Renderer;
    34 typedef struct SDL_RenderDriver SDL_RenderDriver;
    35 typedef struct SDL_VideoDisplay SDL_VideoDisplay;
    36 typedef struct SDL_VideoDevice SDL_VideoDevice;
    37 
    38 /* Define the SDL texture structure */
    39 struct SDL_Texture
    40 {
    41     Uint32 id;
    42 
    43     Uint32 format;      /**< The pixel format of the texture */
    44     int access;         /**< SDL_TextureAccess */
    45     int w;              /**< The width of the texture */
    46     int h;              /**< The height of the texture */
    47 
    48     SDL_Renderer *renderer;
    49 
    50     void *driverdata;   /**< Driver specific texture representation */
    51 
    52     SDL_Texture *next;
    53 };
    54 
    55 /* Define the SDL renderer structure */
    56 struct SDL_Renderer
    57 {
    58     int (*CreateTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
    59     int (*QueryTexturePixels) (SDL_Renderer * renderer, SDL_Texture * texture,
    60                                void **pixels, int *pitch);
    61     int (*SetTexturePalette) (SDL_Renderer * renderer, SDL_Texture * texture,
    62                               const SDL_Color * colors, int firstcolor,
    63                               int ncolors);
    64     int (*GetTexturePalette) (SDL_Renderer * renderer, SDL_Texture * texture,
    65                               SDL_Color * colors, int firstcolor,
    66                               int ncolors);
    67     int (*UpdateTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
    68                           const SDL_Rect * rect, const void *pixels,
    69                           int pitch);
    70     int (*LockTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
    71                         const SDL_Rect * rect, int markDirty, void **pixels,
    72                         int *pitch);
    73     void (*UnlockTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
    74     void (*DirtyTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
    75                           int numrects, const SDL_Rect * rects);
    76     void (*SelectRenderTexture) (SDL_Renderer * renderer,
    77                                  SDL_Texture * texture);
    78     int (*RenderFill) (SDL_Renderer * renderer, const SDL_Rect * rect,
    79                        Uint32 color);
    80     int (*RenderCopy) (SDL_Renderer * renderer, SDL_Texture * texture,
    81                        const SDL_Rect * srcrect, const SDL_Rect * dstrect,
    82                        int blendMode, int scaleMode);
    83     int (*RenderReadPixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
    84                              void *pixels, int pitch);
    85     int (*RenderWritePixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
    86                               const void *pixels, int pitch);
    87     void (*RenderPresent) (SDL_Renderer * renderer);
    88     void (*DestroyTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
    89 
    90     void (*DestroyRenderer) (SDL_Renderer * renderer);
    91 
    92     /* The current renderer info */
    93     SDL_RendererInfo info;
    94 
    95     /* The window associated with the renderer */
    96     SDL_WindowID window;
    97 
    98     void *driverdata;
    99 };
   100 
   101 /* Define the SDL render driver structure */
   102 struct SDL_RenderDriver
   103 {
   104     SDL_Renderer *(*CreateRenderer) (SDL_Window * window, Uint32 flags);
   105 
   106     /* Info about the renderer capabilities */
   107     SDL_RendererInfo info;
   108 };
   109 
   110 /* Define the SDL window structure, corresponding to toplevel windows */
   111 struct SDL_Window
   112 {
   113     Uint32 id;
   114 
   115     char *title;
   116     int x, y;
   117     int w, h;
   118     Uint32 flags;
   119 
   120     Uint16 *gamma;
   121 
   122     int display;
   123     SDL_Renderer *renderer;
   124 
   125     void *userdata;
   126     void *driverdata;
   127 };
   128 
   129 /* Define the SDL display structure
   130    This corresponds to physical monitors attached to the system.
   131  */
   132 struct SDL_VideoDisplay
   133 {
   134     int max_display_modes;
   135     int num_display_modes;
   136     SDL_DisplayMode *display_modes;
   137     SDL_DisplayMode desktop_mode;
   138     SDL_DisplayMode current_mode;
   139     SDL_Palette *palette;
   140 
   141     int num_render_drivers;
   142     SDL_RenderDriver *render_drivers;
   143 
   144     int num_windows;
   145     SDL_Window *windows;
   146 
   147     SDL_Renderer *current_renderer;
   148 
   149     /* The hash list of textures */
   150     SDL_Texture *textures[64];
   151 
   152     SDL_VideoDevice *device;
   153 
   154     void *driverdata;
   155 };
   156 
   157 /* Define the SDL video driver structure */
   158 #define _THIS	SDL_VideoDevice *_this
   159 
   160 struct SDL_VideoDevice
   161 {
   162     /* * * */
   163     /* The name of this video driver */
   164     const char *name;
   165 
   166     /* * * */
   167     /* Initialization/Query functions */
   168 
   169     /* Initialize the native video subsystem, filling in the list
   170        of displays for this driver, returning 0 or -1 if there's an error.
   171      */
   172     int (*VideoInit) (_THIS);
   173 
   174     /* * * */
   175     /* Display functions
   176      */
   177     /* Setting the display mode is independent of creating windows,
   178      * so when the display mode is changed, all existing windows
   179      * should have their data updated accordingly, including the
   180      * display surfaces associated with them.
   181      */
   182     int (*SetDisplayMode) (_THIS, SDL_DisplayMode * mode);
   183 
   184     /* Sets the color entries of the display palette to those in 'colors'.
   185        The return value is 0 if all entries could be set properly or -1
   186        otherwise.
   187      */
   188     int (*SetDisplayPalette) (_THIS, SDL_Palette * palette);
   189 
   190     /* * * */
   191     /* Window functions
   192      */
   193     int (*CreateWindow) (_THIS, SDL_Window * window);
   194     int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
   195     void (*SetWindowTitle) (_THIS, SDL_Window * window);
   196     void (*SetWindowPosition) (_THIS, SDL_Window * window);
   197     void (*SetWindowSize) (_THIS, SDL_Window * window);
   198     void (*ShowWindow) (_THIS, SDL_Window * window);
   199     void (*HideWindow) (_THIS, SDL_Window * window);
   200     void (*RaiseWindow) (_THIS, SDL_Window * window);
   201     void (*MaximizeWindow) (_THIS, SDL_Window * window);
   202     void (*MinimizeWindow) (_THIS, SDL_Window * window);
   203     void (*RestoreWindow) (_THIS, SDL_Window * window);
   204     void (*SetWindowGrab) (_THIS, SDL_Window * window);
   205     void (*DestroyWindow) (_THIS, SDL_Window * window);
   206 
   207     /* Get some platform dependent window information */
   208       SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
   209                                   struct SDL_SysWMinfo * info);
   210 
   211     /* Reverse the effects VideoInit() -- called if VideoInit() fails
   212        or if the application is shutting down the video subsystem.
   213      */
   214     void (*VideoQuit) (_THIS);
   215 
   216     /* * * */
   217     /* Gamma support */
   218 
   219     /* Set the gamma correction directly (emulated with gamma ramps) */
   220     int (*SetGamma) (_THIS, float red, float green, float blue);
   221 
   222     /* Get the gamma correction directly (emulated with gamma ramps) */
   223     int (*GetGamma) (_THIS, float *red, float *green, float *blue);
   224 
   225     /* Set the gamma ramp */
   226     int (*SetGammaRamp) (_THIS, Uint16 * ramp);
   227 
   228     /* Get the gamma ramp */
   229     int (*GetGammaRamp) (_THIS, Uint16 * ramp);
   230 
   231     /* * * */
   232     /* OpenGL support */
   233 
   234     /* Sets the dll to use for OpenGL and loads it */
   235     int (*GL_LoadLibrary) (_THIS, const char *path);
   236 
   237     /* Retrieves the address of a function in the gl library */
   238     void *(*GL_GetProcAddress) (_THIS, const char *proc);
   239 
   240     /* Get attribute information from the windowing system. */
   241     int (*GL_GetAttribute) (_THIS, SDL_GLattr attrib, int *value);
   242 
   243     /* Make the context associated with this driver current */
   244     int (*GL_MakeCurrent) (_THIS);
   245 
   246     /* Swap the current buffers in double buffer mode. */
   247     void (*GL_SwapBuffers) (_THIS);
   248 
   249     /* Determine whether the mouse should be in relative mode or not.
   250        This function is called when the input grab state or cursor
   251        visibility state changes.
   252        If the cursor is not visible, and the input is grabbed, the
   253        driver can place the mouse in relative mode, which may result
   254        in higher accuracy sampling of the pointer motion.
   255      */
   256     void (*CheckMouseMode) (_THIS);
   257 
   258     /* * * */
   259     /* Event manager functions */
   260 
   261     /* Handle any queued OS events */
   262     void (*PumpEvents) (_THIS);
   263 
   264     /* * * */
   265     /* Data common to all drivers */
   266     int num_displays;
   267     SDL_VideoDisplay *displays;
   268     int current_display;
   269     Uint32 next_object_id;
   270 
   271     /* Driver information flags */
   272 
   273     /* * * */
   274     /* Data used by the GL drivers */
   275     struct
   276     {
   277         int red_size;
   278         int green_size;
   279         int blue_size;
   280         int alpha_size;
   281         int depth_size;
   282         int buffer_size;
   283         int stencil_size;
   284         int double_buffer;
   285         int accum_red_size;
   286         int accum_green_size;
   287         int accum_blue_size;
   288         int accum_alpha_size;
   289         int stereo;
   290         int multisamplebuffers;
   291         int multisamplesamples;
   292         int accelerated;
   293         int driver_loaded;
   294         char driver_path[256];
   295         void *dll_handle;
   296     } gl_config;
   297 
   298     /* * * */
   299     /* Data private to this driver */
   300     void *driverdata;
   301     struct SDL_PrivateGLData *gl_data;
   302 
   303     /* * * */
   304     /* The function used to dispose of this structure */
   305     void (*free) (_THIS);
   306 };
   307 
   308 typedef struct VideoBootStrap
   309 {
   310     const char *name;
   311     const char *desc;
   312     int (*available) (void);
   313     SDL_VideoDevice *(*create) (int devindex);
   314 } VideoBootStrap;
   315 
   316 #if SDL_VIDEO_DRIVER_QUARTZ
   317 extern VideoBootStrap QZ_bootstrap;
   318 #endif
   319 #if SDL_VIDEO_DRIVER_X11
   320 extern VideoBootStrap X11_bootstrap;
   321 #endif
   322 #if SDL_VIDEO_DRIVER_DGA
   323 extern VideoBootStrap DGA_bootstrap;
   324 #endif
   325 #if SDL_VIDEO_DRIVER_NANOX
   326 extern VideoBootStrap NX_bootstrap;
   327 #endif
   328 #if SDL_VIDEO_DRIVER_IPOD
   329 extern VideoBootStrap iPod_bootstrap;
   330 #endif
   331 #if SDL_VIDEO_DRIVER_QTOPIA
   332 extern VideoBootStrap Qtopia_bootstrap;
   333 #endif
   334 #if SDL_VIDEO_DRIVER_WSCONS
   335 extern VideoBootStrap WSCONS_bootstrap;
   336 #endif
   337 #if SDL_VIDEO_DRIVER_FBCON
   338 extern VideoBootStrap FBCON_bootstrap;
   339 #endif
   340 #if SDL_VIDEO_DRIVER_DIRECTFB
   341 extern VideoBootStrap DirectFB_bootstrap;
   342 #endif
   343 #if SDL_VIDEO_DRIVER_PS2GS
   344 extern VideoBootStrap PS2GS_bootstrap;
   345 #endif
   346 #if SDL_VIDEO_DRIVER_GGI
   347 extern VideoBootStrap GGI_bootstrap;
   348 #endif
   349 #if SDL_VIDEO_DRIVER_VGL
   350 extern VideoBootStrap VGL_bootstrap;
   351 #endif
   352 #if SDL_VIDEO_DRIVER_SVGALIB
   353 extern VideoBootStrap SVGALIB_bootstrap;
   354 #endif
   355 #if SDL_VIDEO_DRIVER_GAPI
   356 extern VideoBootStrap GAPI_bootstrap;
   357 #endif
   358 #if SDL_VIDEO_DRIVER_WIN32
   359 extern VideoBootStrap WIN32_bootstrap;
   360 #endif
   361 #if SDL_VIDEO_DRIVER_BWINDOW
   362 extern VideoBootStrap BWINDOW_bootstrap;
   363 #endif
   364 #if SDL_VIDEO_DRIVER_TOOLBOX
   365 extern VideoBootStrap TOOLBOX_bootstrap;
   366 #endif
   367 #if SDL_VIDEO_DRIVER_DRAWSPROCKET
   368 extern VideoBootStrap DSp_bootstrap;
   369 #endif
   370 #if SDL_VIDEO_DRIVER_CYBERGRAPHICS
   371 extern VideoBootStrap CGX_bootstrap;
   372 #endif
   373 #if SDL_VIDEO_DRIVER_PHOTON
   374 extern VideoBootStrap ph_bootstrap;
   375 #endif
   376 #if SDL_VIDEO_DRIVER_EPOC
   377 extern VideoBootStrap EPOC_bootstrap;
   378 #endif
   379 #if SDL_VIDEO_DRIVER_XBIOS
   380 extern VideoBootStrap XBIOS_bootstrap;
   381 #endif
   382 #if SDL_VIDEO_DRIVER_GEM
   383 extern VideoBootStrap GEM_bootstrap;
   384 #endif
   385 #if SDL_VIDEO_DRIVER_PICOGUI
   386 extern VideoBootStrap PG_bootstrap;
   387 #endif
   388 #if SDL_VIDEO_DRIVER_DC
   389 extern VideoBootStrap DC_bootstrap;
   390 #endif
   391 #if SDL_VIDEO_DRIVER_RISCOS
   392 extern VideoBootStrap RISCOS_bootstrap;
   393 #endif
   394 #if SDL_VIDEO_DRIVER_OS2FS
   395 extern VideoBootStrap OS2FSLib_bootstrap;
   396 #endif
   397 #if SDL_VIDEO_DRIVER_AALIB
   398 extern VideoBootStrap AALIB_bootstrap;
   399 #endif
   400 #if SDL_VIDEO_DRIVER_DUMMY
   401 extern VideoBootStrap DUMMY_bootstrap;
   402 #endif
   403 #if SDL_VIDEO_DRIVER_GLSDL
   404 extern VideoBootStrap glSDL_bootstrap;
   405 #endif
   406 
   407 #define SDL_CurrentDisplay	(_this->displays[_this->current_display])
   408 #define SDL_CurrentWindow	(SDL_CurrentDisplay.windows[0])
   409 
   410 extern SDL_VideoDevice *SDL_GetVideoDevice();
   411 extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
   412 extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
   413 extern SDL_bool SDL_AddDisplayMode(int displayIndex,
   414                                    const SDL_DisplayMode * mode);
   415 extern void SDL_AddRenderDriver(int displayIndex,
   416                                 const SDL_RenderDriver * driver);
   417 
   418 extern SDL_Window *SDL_GetWindowFromID(SDL_WindowID windowID);
   419 extern SDL_VideoDisplay *SDL_GetDisplayFromWindow(SDL_Window * window);
   420 
   421 #endif /* _SDL_sysvideo_h */
   422 
   423 /* vi: set ts=4 sw=4 expandtab: */