src/video/SDL_sysvideo.h
author Sam Lantinga <slouken@libsdl.org>
Sun, 08 Jan 2012 02:23:37 -0500
changeset 6188 e82023802002
parent 6138 4c64952a58fb
child 6296 b42657486c0d
permissions -rwxr-xr-x
Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11

Scott Percival 2011-07-03 06:41:51 PDT

This submission is aimed at making life easier for OpenGL ES capable devices
running a X11 stack (e.g. Maemo, Meego, TrimSlice, other ARM SoC boards not
running Android). SDL's Pandora support already has the neccesary GLES-to-X11
glue code, however it's all ghetto'd off in Makefile.pandora and not very
flexible.

The patch:
- adds an awesome --enable-video-opengles option to configure
- re-modifies the opengles and opengles2 SDL_renderers to use function pointers
- no idea why this was removed?
- for SDL_Renderers, links in libGLESv1_CM, libGLES_CM (for PowerVR fans) or
libGLESv2 at runtime
- links in libEGL.so at runtime - the old code made an assumption that
eglFunctions could be pulled from the active GLES library, PowerVR for one
doesn't let you do that with their libGLESv2
- allows you to pick which of GLES v1 or v2 to load via
SDL_GL_CONTEXT_MAJOR_VERSION

So far I've tested this on a Nokia N900 (OMAP 3430/SGX 530 running Maemo 5) and
a Toshiba AC100 (Tegra 2 running Ubuntu 10.10). I haven't tested it on... well,
everything that isn't those two, such as a Pandora, iOS or Android device. The
Pandora specific code should be kept intact (fingers crossed), and nothing
painfully drastic has been added to the SDL_renderers. The library loading
sequence in SDL_x11opengles has been updated to accomodate both NVIDIA's
propensity to let developers get away with murder and PowerVR's alternative of
punishing every missed step.

The test apps work okay with GLES or GLES2 as the renderer. For some reason
alpha blending doesn't seem to work on the Tegra 2; last week NVIDIA pushed out
a new set of X11 GLES drivers, so I'll try and investigate once I upgrade
those. Also, this patch adds things to configure.in, include/SDL_config.h.in
and test/configure.in. I didn't know what the policy was re. committing
generated spaghetti from autotools, so ./autogen.sh has to be run again. Sorry.

I think that's about everything, let me know if there's anything I've
overlooked.
slouken@0
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@6138
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
slouken@0
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@0
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@0
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@0
    20
*/
slouken@1402
    21
#include "SDL_config.h"
slouken@0
    22
slouken@0
    23
#ifndef _SDL_sysvideo_h
slouken@0
    24
#define _SDL_sysvideo_h
slouken@0
    25
eligottlieb@4782
    26
#include "SDL_shape.h"
slouken@0
    27
slouken@0
    28
/* The SDL video driver */
slouken@1895
    29
eligottlieb@4782
    30
typedef struct SDL_WindowShaper SDL_WindowShaper;
eligottlieb@4782
    31
typedef struct SDL_ShapeDriver SDL_ShapeDriver;
slouken@1895
    32
typedef struct SDL_VideoDisplay SDL_VideoDisplay;
slouken@0
    33
typedef struct SDL_VideoDevice SDL_VideoDevice;
slouken@0
    34
eligottlieb@4782
    35
/* Define the SDL window-shaper structure */
eligottlieb@4782
    36
struct SDL_WindowShaper
eligottlieb@4782
    37
{   
eligottlieb@4782
    38
    /* The window associated with the shaper */
eligottlieb@4782
    39
    SDL_Window *window;
eligottlieb@4782
    40
    
eligottlieb@4851
    41
    /* The user's specified coordinates for the window, for once we give it a shape. */
eligottlieb@4851
    42
    Uint32 userx,usery;
eligottlieb@4782
    43
    
eligottlieb@4807
    44
    /* The parameters for shape calculation. */
eligottlieb@4807
    45
    SDL_WindowShapeMode mode;
eligottlieb@4782
    46
    
eligottlieb@4782
    47
    /* Has this window been assigned a shape? */
eligottlieb@4782
    48
    SDL_bool hasshape;
eligottlieb@4782
    49
    
eligottlieb@4782
    50
    void *driverdata;
eligottlieb@4782
    51
};
eligottlieb@4782
    52
eligottlieb@4782
    53
/* Define the SDL shape driver structure */
eligottlieb@4782
    54
struct SDL_ShapeDriver
eligottlieb@4782
    55
{
eligottlieb@4782
    56
    SDL_WindowShaper *(*CreateShaper)(SDL_Window * window);
egottlieb@4849
    57
    int (*SetWindowShape)(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
eligottlieb@4782
    58
    int (*ResizeWindowShape)(SDL_Window *window);
eligottlieb@4782
    59
};
eligottlieb@4782
    60
slouken@5165
    61
typedef struct SDL_WindowUserData
slouken@5165
    62
{
slouken@5165
    63
    char *name;
slouken@5165
    64
    void *data;
slouken@5165
    65
    struct SDL_WindowUserData *next;
slouken@5165
    66
} SDL_WindowUserData;
slouken@5165
    67
slouken@1895
    68
/* Define the SDL window structure, corresponding to toplevel windows */
slouken@2753
    69
struct SDL_Window
slouken@2753
    70
{
slouken@3695
    71
    const void *magic;
slouken@2753
    72
    Uint32 id;
slouken@2753
    73
    char *title;
slouken@2753
    74
    int x, y;
slouken@2753
    75
    int w, h;
slouken@2753
    76
    Uint32 flags;
slouken@1895
    77
slouken@5398
    78
    /* Stored position and size for windowed mode */
slouken@5398
    79
    SDL_Rect windowed;
slouken@5398
    80
slouken@3500
    81
    SDL_DisplayMode fullscreen_mode;
eligottlieb@4782
    82
    
slouken@5466
    83
    float brightness;
slouken@5466
    84
    Uint16 *gamma;
slouken@5466
    85
    Uint16 *saved_gamma;        /* (just offset into gamma) */
slouken@5466
    86
slouken@5166
    87
    SDL_Surface *surface;
slouken@5174
    88
    SDL_bool surface_valid;
slouken@5166
    89
eligottlieb@4782
    90
    SDL_WindowShaper *shaper;
slouken@3500
    91
slouken@5165
    92
    SDL_WindowUserData *data;
slouken@5165
    93
slouken@2753
    94
    void *driverdata;
slouken@3685
    95
slouken@3685
    96
    SDL_Window *prev;
slouken@3685
    97
    SDL_Window *next;
slouken@1895
    98
};
slouken@1895
    99
#define FULLSCREEN_VISIBLE(W) \
slouken@1895
   100
    (((W)->flags & SDL_WINDOW_FULLSCREEN) && \
slouken@1895
   101
     ((W)->flags & SDL_WINDOW_SHOWN) && \
slouken@1895
   102
     !((W)->flags & SDL_WINDOW_MINIMIZED))
slouken@1895
   103
hfutrell@2742
   104
/*
hfutrell@2742
   105
 * Define the SDL display structure This corresponds to physical monitors
hfutrell@2742
   106
 * attached to the system.
slouken@1895
   107
 */
slouken@2753
   108
struct SDL_VideoDisplay
slouken@2753
   109
{
slouken@2753
   110
    int max_display_modes;
slouken@2753
   111
    int num_display_modes;
slouken@2753
   112
    SDL_DisplayMode *display_modes;
slouken@2753
   113
    SDL_DisplayMode desktop_mode;
slouken@2753
   114
    SDL_DisplayMode current_mode;
slouken@1895
   115
slouken@3517
   116
    SDL_Window *fullscreen_window;
slouken@1895
   117
slouken@2753
   118
    SDL_VideoDevice *device;
slouken@1895
   119
slouken@2753
   120
    void *driverdata;
slouken@1895
   121
};
slouken@1895
   122
slouken@5272
   123
/* Forward declaration */
slouken@5272
   124
struct SDL_SysWMinfo;
slouken@5272
   125
slouken@0
   126
/* Define the SDL video driver structure */
slouken@0
   127
#define _THIS	SDL_VideoDevice *_this
slouken@0
   128
slouken@2753
   129
struct SDL_VideoDevice
slouken@2753
   130
{
slouken@2753
   131
    /* * * */
slouken@2753
   132
    /* The name of this video driver */
slouken@2753
   133
    const char *name;
slouken@0
   134
slouken@2753
   135
    /* * * */
slouken@2753
   136
    /* Initialization/Query functions */
slouken@0
   137
slouken@2753
   138
    /*
slouken@2753
   139
     * Initialize the native video subsystem, filling in the list of
slouken@2753
   140
     * displays for this driver, returning 0 or -1 if there's an error.
slouken@2753
   141
     */
slouken@2753
   142
    int (*VideoInit) (_THIS);
slouken@0
   143
slouken@2753
   144
    /*
slouken@2753
   145
     * Reverse the effects VideoInit() -- called if VideoInit() fails or
slouken@2753
   146
     * if the application is shutting down the video subsystem.
slouken@2753
   147
     */
slouken@2753
   148
    void (*VideoQuit) (_THIS);
slouken@1913
   149
slouken@2753
   150
    /* * * */
slouken@2753
   151
    /*
slouken@2753
   152
     * Display functions
slouken@2753
   153
     */
slouken@0
   154
slouken@2753
   155
    /*
slouken@3528
   156
     * Get the bounds of a display
slouken@3528
   157
     */
slouken@3528
   158
    int (*GetDisplayBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
slouken@3528
   159
slouken@3528
   160
    /*
slouken@5246
   161
     * Get a list of the available display modes for a display.
slouken@2753
   162
     */
slouken@3500
   163
    void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display);
slouken@0
   164
slouken@2753
   165
    /*
slouken@2753
   166
     * Setting the display mode is independent of creating windows, so
slouken@2753
   167
     * when the display mode is changed, all existing windows should have
slouken@2753
   168
     * their data updated accordingly, including the display surfaces
slouken@2753
   169
     * associated with them.
slouken@2753
   170
     */
slouken@3500
   171
    int (*SetDisplayMode) (_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
slouken@0
   172
slouken@2753
   173
    /* * * */
slouken@2753
   174
    /*
slouken@2753
   175
     * Window functions
slouken@2753
   176
     */
slouken@2753
   177
    int (*CreateWindow) (_THIS, SDL_Window * window);
slouken@2753
   178
    int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
slouken@2753
   179
    void (*SetWindowTitle) (_THIS, SDL_Window * window);
slouken@2967
   180
    void (*SetWindowIcon) (_THIS, SDL_Window * window, SDL_Surface * icon);
slouken@2753
   181
    void (*SetWindowPosition) (_THIS, SDL_Window * window);
slouken@2753
   182
    void (*SetWindowSize) (_THIS, SDL_Window * window);
slouken@2753
   183
    void (*ShowWindow) (_THIS, SDL_Window * window);
slouken@2753
   184
    void (*HideWindow) (_THIS, SDL_Window * window);
slouken@2753
   185
    void (*RaiseWindow) (_THIS, SDL_Window * window);
slouken@2753
   186
    void (*MaximizeWindow) (_THIS, SDL_Window * window);
slouken@2753
   187
    void (*MinimizeWindow) (_THIS, SDL_Window * window);
slouken@2753
   188
    void (*RestoreWindow) (_THIS, SDL_Window * window);
slouken@5305
   189
    void (*SetWindowFullscreen) (_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
slouken@5466
   190
    int (*SetWindowGammaRamp) (_THIS, SDL_Window * window, const Uint16 * ramp);
slouken@5466
   191
    int (*GetWindowGammaRamp) (_THIS, SDL_Window * window, Uint16 * ramp);
slouken@2753
   192
    void (*SetWindowGrab) (_THIS, SDL_Window * window);
slouken@2753
   193
    void (*DestroyWindow) (_THIS, SDL_Window * window);
slouken@5166
   194
    int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
slouken@5297
   195
    int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, SDL_Rect * rects, int numrects);
slouken@5166
   196
    void (*DestroyWindowFramebuffer) (_THIS, SDL_Window * window);
slouken@5166
   197
eligottlieb@4782
   198
    /* * * */
eligottlieb@4782
   199
    /*
eligottlieb@4782
   200
     * Shaped-window functions
eligottlieb@4782
   201
     */
eligottlieb@4782
   202
    SDL_ShapeDriver shape_driver;
slouken@0
   203
slouken@2753
   204
    /* Get some platform dependent window information */
slouken@2753
   205
      SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
slouken@2753
   206
                                  struct SDL_SysWMinfo * info);
slouken@0
   207
slouken@2753
   208
    /* * * */
slouken@2753
   209
    /*
slouken@2753
   210
     * OpenGL support
slouken@2753
   211
     */
slouken@2753
   212
    int (*GL_LoadLibrary) (_THIS, const char *path);
slouken@2753
   213
    void *(*GL_GetProcAddress) (_THIS, const char *proc);
slouken@3057
   214
    void (*GL_UnloadLibrary) (_THIS);
slouken@2753
   215
      SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
slouken@2753
   216
    int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
slouken@2753
   217
    int (*GL_SetSwapInterval) (_THIS, int interval);
slouken@2753
   218
    int (*GL_GetSwapInterval) (_THIS);
slouken@2753
   219
    void (*GL_SwapWindow) (_THIS, SDL_Window * window);
slouken@2753
   220
    void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
slouken@0
   221
slouken@2753
   222
    /* * * */
slouken@2753
   223
    /*
slouken@2753
   224
     * Event manager functions
slouken@2753
   225
     */
slouken@2753
   226
    void (*PumpEvents) (_THIS);
slouken@0
   227
slouken@3025
   228
    /* Suspend the screensaver */
slouken@3025
   229
    void (*SuspendScreenSaver) (_THIS);
slouken@3025
   230
slouken@3280
   231
    /* Text input */
slouken@3280
   232
    void (*StartTextInput) (_THIS);
slouken@3280
   233
    void (*StopTextInput) (_THIS);
slouken@3280
   234
    void (*SetTextInputRect) (_THIS, SDL_Rect *rect);
slouken@3280
   235
slouken@4495
   236
    /* Clipboard */
slouken@4495
   237
    int (*SetClipboardText) (_THIS, const char *text);
slouken@4495
   238
    char * (*GetClipboardText) (_THIS);
slouken@4495
   239
    SDL_bool (*HasClipboardText) (_THIS);
slouken@4495
   240
slouken@2753
   241
    /* * * */
slouken@2753
   242
    /* Data common to all drivers */
slouken@3025
   243
    SDL_bool suspend_screensaver;
slouken@2753
   244
    int num_displays;
slouken@2753
   245
    SDL_VideoDisplay *displays;
slouken@5246
   246
    SDL_Window *windows;
slouken@3695
   247
    Uint8 window_magic;
slouken@2753
   248
    Uint32 next_object_id;
slouken@4495
   249
    char * clipboard_text;
slouken@0
   250
slouken@2753
   251
    /* * * */
slouken@2753
   252
    /* Data used by the GL drivers */
slouken@2753
   253
    struct
slouken@2753
   254
    {
slouken@2753
   255
        int red_size;
slouken@2753
   256
        int green_size;
slouken@2753
   257
        int blue_size;
slouken@2753
   258
        int alpha_size;
slouken@2753
   259
        int depth_size;
slouken@2753
   260
        int buffer_size;
slouken@2753
   261
        int stencil_size;
slouken@2753
   262
        int double_buffer;
slouken@2753
   263
        int accum_red_size;
slouken@2753
   264
        int accum_green_size;
slouken@2753
   265
        int accum_blue_size;
slouken@2753
   266
        int accum_alpha_size;
slouken@2753
   267
        int stereo;
slouken@2753
   268
        int multisamplebuffers;
slouken@2753
   269
        int multisamplesamples;
slouken@2753
   270
        int accelerated;
slouken@3100
   271
        int major_version;
slouken@3100
   272
        int minor_version;
slouken@2753
   273
        int retained_backing;
slouken@2753
   274
        int driver_loaded;
slouken@2753
   275
        char driver_path[256];
slouken@2753
   276
        void *dll_handle;
slouken@2753
   277
    } gl_config;
slouken@0
   278
slouken@2753
   279
    /* * * */
icculus@5563
   280
    /* Cache current GL context; don't call the OS when it hasn't changed. */
icculus@5563
   281
    SDL_Window *current_glwin;
icculus@5563
   282
    SDL_GLContext current_glctx;
icculus@5563
   283
icculus@5563
   284
    /* * * */
slouken@2753
   285
    /* Data private to this driver */
slouken@2753
   286
    void *driverdata;
slouken@2753
   287
    struct SDL_GLDriverData *gl_data;
slouken@0
   288
slouken@6188
   289
#if SDL_VIDEO_OPENGL_ES
slouken@3161
   290
    struct SDL_PrivateGLESData *gles_data;
slouken@3161
   291
#endif
slouken@3161
   292
slouken@2753
   293
    /* * * */
slouken@2753
   294
    /* The function used to dispose of this structure */
slouken@2753
   295
    void (*free) (_THIS);
slouken@1895
   296
};
slouken@0
   297
slouken@2753
   298
typedef struct VideoBootStrap
slouken@2753
   299
{
slouken@2753
   300
    const char *name;
slouken@2753
   301
    const char *desc;
slouken@2753
   302
    int (*available) (void);
slouken@2753
   303
    SDL_VideoDevice *(*create) (int devindex);
slouken@2753
   304
} VideoBootStrap;
slouken@0
   305
slouken@1931
   306
#if SDL_VIDEO_DRIVER_COCOA
slouken@1931
   307
extern VideoBootStrap COCOA_bootstrap;
slouken@1361
   308
#endif
slouken@1361
   309
#if SDL_VIDEO_DRIVER_X11
slouken@0
   310
extern VideoBootStrap X11_bootstrap;
slouken@0
   311
#endif
slouken@1361
   312
#if SDL_VIDEO_DRIVER_DIRECTFB
slouken@167
   313
extern VideoBootStrap DirectFB_bootstrap;
slouken@167
   314
#endif
slouken@5062
   315
#if SDL_VIDEO_DRIVER_WINDOWS
slouken@5062
   316
extern VideoBootStrap WINDOWS_bootstrap;
slouken@1361
   317
#endif
slouken@1361
   318
#if SDL_VIDEO_DRIVER_BWINDOW
slouken@1361
   319
extern VideoBootStrap BWINDOW_bootstrap;
slouken@1361
   320
#endif
slouken@5150
   321
#if SDL_VIDEO_DRIVER_PANDORA
slouken@5150
   322
extern VideoBootStrap PND_bootstrap;
slouken@3083
   323
#endif
slouken@5150
   324
#if SDL_VIDEO_DRIVER_NDS
slouken@5150
   325
extern VideoBootStrap NDS_bootstrap;
slouken@1361
   326
#endif
hfutrell@2742
   327
#if SDL_VIDEO_DRIVER_UIKIT
hfutrell@2742
   328
extern VideoBootStrap UIKIT_bootstrap;
hfutrell@2742
   329
#endif
slouken@5150
   330
#if SDL_VIDEO_DRIVER_ANDROID
slouken@5150
   331
extern VideoBootStrap Android_bootstrap;
slouken@5150
   332
#endif
slouken@1361
   333
#if SDL_VIDEO_DRIVER_DUMMY
slouken@173
   334
extern VideoBootStrap DUMMY_bootstrap;
slouken@173
   335
#endif
slouken@1361
   336
slouken@4472
   337
extern SDL_VideoDevice *SDL_GetVideoDevice(void);
slouken@2753
   338
extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
slouken@2753
   339
extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
slouken@3500
   340
extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
slouken@5246
   341
extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window);
slouken@1895
   342
slouken@2753
   343
extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
slouken@1895
   344
slouken@2753
   345
extern void SDL_OnWindowShown(SDL_Window * window);
slouken@2753
   346
extern void SDL_OnWindowHidden(SDL_Window * window);
slouken@5166
   347
extern void SDL_OnWindowResized(SDL_Window * window);
slouken@3502
   348
extern void SDL_OnWindowMinimized(SDL_Window * window);
slouken@3502
   349
extern void SDL_OnWindowRestored(SDL_Window * window);
slouken@2753
   350
extern void SDL_OnWindowFocusGained(SDL_Window * window);
slouken@2753
   351
extern void SDL_OnWindowFocusLost(SDL_Window * window);
slouken@3685
   352
extern SDL_Window * SDL_GetFocusWindow(void);
slouken@0
   353
slouken@2753
   354
#endif /* _SDL_sysvideo_h */
slouken@1895
   355
slouken@1895
   356
/* vi: set ts=4 sw=4 expandtab: */