src/video/pandora/SDL_pandora.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Wed, 20 Jul 2016 21:00:36 +0200
changeset 10207 e66f6ab2b059
parent 10205 baabe483bb99
child 10208 49c460371a4a
permissions -rw-r--r--
Pandora: Fixed compile warnings in video implementation (thanks, Bombo!). Fixes Bugzilla #2734.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     2
  Simple DirectMedia Layer
9998
f67cf37e9cd4 Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents: 9619
diff changeset
     3
  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     7
  arising from the use of this software.
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    11
  freely, subject to the following restrictions:
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 7468
diff changeset
    21
#include "../../SDL_internal.h"
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    22
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    23
#if SDL_VIDEO_DRIVER_PANDORA
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
/* SDL internals */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
#include "../SDL_sysvideo.h"
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
#include "SDL_version.h"
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
#include "SDL_syswm.h"
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
#include "SDL_loadso.h"
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
#include "SDL_events.h"
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
#include "../../events/SDL_mouse_c.h"
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
#include "../../events/SDL_keyboard_c.h"
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
/* PND declarations */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
#include "SDL_pandora.h"
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
#include "SDL_pandora_events.h"
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
3438
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
    38
/* WIZ declarations */
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
    39
#include "GLES/gl.h"
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
    40
#ifdef WIZ_GLES_LITE
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
    41
static NativeWindowType hNativeWnd = 0; /* A handle to the window we will create. */
3438
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
    42
#endif
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
    43
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
static int
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
PND_available(void)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
    return 1;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    48
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
static void
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
PND_destroy(SDL_VideoDevice * device)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
    if (device->driverdata != NULL) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
        device->driverdata = NULL;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
static SDL_VideoDevice *
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
PND_create()
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    61
    SDL_VideoDevice *device;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
    SDL_VideoData *phdata;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
    int status;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
    /* Check if pandora could be initialized */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
    status = PND_available();
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
    if (status == 0) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
        /* PND could not be used */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    69
        return NULL;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    70
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    71
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    72
    /* Initialize SDL_VideoDevice structure */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    73
    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    74
    if (device == NULL) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
        SDL_OutOfMemory();
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
        return NULL;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
    /* Initialize internal Pandora specific data */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    80
    phdata = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    81
    if (phdata == NULL) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    82
        SDL_OutOfMemory();
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    83
        SDL_free(device);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
        return NULL;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    86
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    87
    device->driverdata = phdata;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    88
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
    phdata->egl_initialized = SDL_TRUE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
10202
16c283d1dcca Updated comments in video implementations.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 10201
diff changeset
    92
    /* Setup amount of available displays */
3238
96492d29034a David Carre to Sam
Sam Lantinga <slouken@libsdl.org>
parents: 3235
diff changeset
    93
    device->num_displays = 0;
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    94
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    95
    /* Set device free function */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    96
    device->free = PND_destroy;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    97
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    98
    /* Setup all functions which we can handle */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
    device->VideoInit = PND_videoinit;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
    device->VideoQuit = PND_videoquit;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   101
    device->GetDisplayModes = PND_getdisplaymodes;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   102
    device->SetDisplayMode = PND_setdisplaymode;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   103
    device->CreateWindow = PND_createwindow;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   104
    device->CreateWindowFrom = PND_createwindowfrom;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
    device->SetWindowTitle = PND_setwindowtitle;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
    device->SetWindowIcon = PND_setwindowicon;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   107
    device->SetWindowPosition = PND_setwindowposition;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   108
    device->SetWindowSize = PND_setwindowsize;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   109
    device->ShowWindow = PND_showwindow;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   110
    device->HideWindow = PND_hidewindow;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   111
    device->RaiseWindow = PND_raisewindow;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   112
    device->MaximizeWindow = PND_maximizewindow;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   113
    device->MinimizeWindow = PND_minimizewindow;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   114
    device->RestoreWindow = PND_restorewindow;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
    device->SetWindowGrab = PND_setwindowgrab;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   116
    device->DestroyWindow = PND_destroywindow;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   117
    device->GetWindowWMInfo = PND_getwindowwminfo;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   118
    device->GL_LoadLibrary = PND_gl_loadlibrary;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
    device->GL_GetProcAddress = PND_gl_getprocaddres;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   120
    device->GL_UnloadLibrary = PND_gl_unloadlibrary;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   121
    device->GL_CreateContext = PND_gl_createcontext;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
    device->GL_MakeCurrent = PND_gl_makecurrent;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   123
    device->GL_SetSwapInterval = PND_gl_setswapinterval;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   124
    device->GL_GetSwapInterval = PND_gl_getswapinterval;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   125
    device->GL_SwapWindow = PND_gl_swapwindow;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
    device->GL_DeleteContext = PND_gl_deletecontext;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   127
    device->PumpEvents = PND_PumpEvents;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
   129
    /* !!! FIXME: implement SetWindowBordered */
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
   130
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   131
    return device;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   132
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   133
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   134
VideoBootStrap PND_bootstrap = {
3438
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   135
#ifdef WIZ_GLES_LITE
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   136
    "wiz",
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   137
    "SDL Wiz Video Driver",
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   138
#else
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
    "pandora",
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   140
    "SDL Pandora Video Driver",
3438
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   141
#endif
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
    PND_available,
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
    PND_create
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
};
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   145
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   146
/*****************************************************************************/
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   147
/* SDL Video and Display initialization/handling functions                   */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   148
/*****************************************************************************/
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
int
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
PND_videoinit(_THIS)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
    SDL_VideoDisplay display;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   153
    SDL_DisplayMode current_mode;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   155
    SDL_zero(current_mode);
3438
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   156
#ifdef WIZ_GLES_LITE
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   157
    current_mode.w = 320;
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   158
    current_mode.h = 240;
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   159
#else
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   160
    current_mode.w = 800;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   161
    current_mode.h = 480;
3438
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   162
#endif
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   163
    current_mode.refresh_rate = 60;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   164
    current_mode.format = SDL_PIXELFORMAT_RGB565;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   165
    current_mode.driverdata = NULL;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   166
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
    SDL_zero(display);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   168
    display.desktop_mode = current_mode;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   169
    display.current_mode = current_mode;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   170
    display.driverdata = NULL;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   171
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   172
    SDL_AddVideoDisplay(&display);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   173
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   174
    return 1;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   175
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   176
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   177
void
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   178
PND_videoquit(_THIS)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   179
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   180
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   181
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   182
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   183
void
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3438
diff changeset
   184
PND_getdisplaymodes(_THIS, SDL_VideoDisplay * display)
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   185
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   186
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   187
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   188
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   189
int
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3438
diff changeset
   190
PND_setdisplaymode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   191
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   192
    return 0;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   193
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   194
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   195
int
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   196
PND_createwindow(_THIS, SDL_Window * window)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   197
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   198
    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   199
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   200
    SDL_WindowData *wdata;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   201
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   202
    /* Allocate window internal data */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   203
    wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   204
    if (wdata == NULL) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   205
        return SDL_OutOfMemory();
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   206
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   207
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   208
    /* Setup driver data for this window */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   209
    window->driverdata = wdata;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   210
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   211
    /* Check if window must support OpenGL ES rendering */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   212
    if ((window->flags & SDL_WINDOW_OPENGL) == SDL_WINDOW_OPENGL) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   213
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   214
        EGLBoolean initstatus;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   215
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   216
        /* Mark this window as OpenGL ES compatible */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   217
        wdata->uses_gles = SDL_TRUE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   218
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   219
        /* Create connection to OpenGL ES */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   220
        if (phdata->egl_display == EGL_NO_DISPLAY) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   221
            phdata->egl_display = eglGetDisplay((NativeDisplayType) 0);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   222
            if (phdata->egl_display == EGL_NO_DISPLAY) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   223
                return SDL_SetError("PND: Can't get connection to OpenGL ES");
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   224
            }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   225
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   226
            initstatus = eglInitialize(phdata->egl_display, NULL, NULL);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   227
            if (initstatus != EGL_TRUE) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   228
                return SDL_SetError("PND: Can't init OpenGL ES library");
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   229
            }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   230
        }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   231
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   232
        phdata->egl_refcount++;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   233
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   234
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   235
    /* Window has been successfully created */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   236
    return 0;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   237
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   238
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   239
int
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   240
PND_createwindowfrom(_THIS, SDL_Window * window, const void *data)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   241
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   242
    return -1;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   243
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   244
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   245
void
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   246
PND_setwindowtitle(_THIS, SDL_Window * window)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   247
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   248
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   249
void
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   250
PND_setwindowicon(_THIS, SDL_Window * window, SDL_Surface * icon)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   251
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   252
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   253
void
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   254
PND_setwindowposition(_THIS, SDL_Window * window)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   255
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   256
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   257
void
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   258
PND_setwindowsize(_THIS, SDL_Window * window)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   259
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   260
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   261
void
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   262
PND_showwindow(_THIS, SDL_Window * window)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   263
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   264
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   265
void
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   266
PND_hidewindow(_THIS, SDL_Window * window)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   267
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   268
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   269
void
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   270
PND_raisewindow(_THIS, SDL_Window * window)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   271
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   272
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   273
void
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   274
PND_maximizewindow(_THIS, SDL_Window * window)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   275
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   276
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   277
void
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   278
PND_minimizewindow(_THIS, SDL_Window * window)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   279
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   280
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   281
void
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   282
PND_restorewindow(_THIS, SDL_Window * window)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   283
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   284
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   285
void
10207
e66f6ab2b059 Pandora: Fixed compile warnings in video implementation (thanks, Bombo!).
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 10205
diff changeset
   286
PND_setwindowgrab(_THIS, SDL_Window * window, SDL_bool grabbed)
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   287
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   288
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   289
void
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   290
PND_destroywindow(_THIS, SDL_Window * window)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   291
{
3235
d35b649858e0 David Carre to Sam
Sam Lantinga <slouken@libsdl.org>
parents: 3161
diff changeset
   292
    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
d35b649858e0 David Carre to Sam
Sam Lantinga <slouken@libsdl.org>
parents: 3161
diff changeset
   293
    eglTerminate(phdata->egl_display);
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   294
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   295
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   296
/*****************************************************************************/
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   297
/* SDL Window Manager function                                               */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   298
/*****************************************************************************/
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   299
SDL_bool
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   300
PND_getwindowwminfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   301
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   302
    if (info->version.major <= SDL_MAJOR_VERSION) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   303
        return SDL_TRUE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   304
    } else {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   305
        SDL_SetError("application not compiled with SDL %d.%d\n",
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   306
                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   307
        return SDL_FALSE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   308
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   309
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   310
    /* Failed to get window manager information */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   311
    return SDL_FALSE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   312
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   313
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   314
/*****************************************************************************/
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   315
/* SDL OpenGL/OpenGL ES functions                                            */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   316
/*****************************************************************************/
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   317
int
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   318
PND_gl_loadlibrary(_THIS, const char *path)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   319
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   320
    /* Check if OpenGL ES library is specified for GF driver */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   321
    if (path == NULL) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   322
        path = SDL_getenv("SDL_OPENGL_LIBRARY");
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   323
        if (path == NULL) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   324
            path = SDL_getenv("SDL_OPENGLES_LIBRARY");
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   325
        }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   326
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   327
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   328
    /* Check if default library loading requested */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   329
    if (path == NULL) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   330
        /* Already linked with GF library which provides egl* subset of  */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   331
        /* functions, use Common profile of OpenGL ES library by default */
3438
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   332
#ifdef WIZ_GLES_LITE
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   333
    path = "/lib/libopengles_lite.so";
3438
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   334
#else
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   335
        path = "/usr/lib/libGLES_CM.so";
3438
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   336
#endif
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   337
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   338
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   339
    /* Load dynamic library */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   340
    _this->gl_config.dll_handle = SDL_LoadObject(path);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   341
    if (!_this->gl_config.dll_handle) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   342
        /* Failed to load new GL ES library */
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   343
        return SDL_SetError("PND: Failed to locate OpenGL ES library");
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   344
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   345
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   346
    /* Store OpenGL ES library path and name */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   347
    SDL_strlcpy(_this->gl_config.driver_path, path,
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   348
                SDL_arraysize(_this->gl_config.driver_path));
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   349
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   350
    /* New OpenGL ES library is loaded */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   351
    return 0;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   352
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   353
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   354
void *
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   355
PND_gl_getprocaddres(_THIS, const char *proc)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   356
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   357
    void *function_address;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   358
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   359
    /* Try to get function address through the egl interface */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   360
    function_address = eglGetProcAddress(proc);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   361
    if (function_address != NULL) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   362
        return function_address;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   363
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   364
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   365
    /* Then try to get function in the OpenGL ES library */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   366
    if (_this->gl_config.dll_handle) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   367
        function_address =
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   368
            SDL_LoadFunction(_this->gl_config.dll_handle, proc);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   369
        if (function_address != NULL) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   370
            return function_address;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   371
        }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   372
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   373
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   374
    /* Failed to get GL ES function address pointer */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   375
    SDL_SetError("PND: Cannot locate OpenGL ES function name");
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   376
    return NULL;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   377
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   378
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   379
void
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   380
PND_gl_unloadlibrary(_THIS)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   381
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   382
    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   383
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   384
    if (phdata->egl_initialized == SDL_TRUE) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   385
        /* Unload OpenGL ES library */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   386
        if (_this->gl_config.dll_handle) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   387
            SDL_UnloadObject(_this->gl_config.dll_handle);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   388
            _this->gl_config.dll_handle = NULL;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   389
        }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   390
    } else {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   391
        SDL_SetError("PND: GF initialization failed, no OpenGL ES support");
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   392
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   393
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   394
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   395
SDL_GLContext
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   396
PND_gl_createcontext(_THIS, SDL_Window * window)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   397
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   398
    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   399
    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   400
    EGLBoolean status;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   401
    EGLint configs;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   402
    uint32_t attr_pos;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   403
    EGLint attr_value;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   404
    EGLint cit;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   405
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   406
    /* Check if EGL was initialized */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   407
    if (phdata->egl_initialized != SDL_TRUE) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   408
        SDL_SetError("PND: EGL initialization failed, no OpenGL ES support");
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   409
        return NULL;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   410
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   411
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   412
    /* Prepare attributes list to pass them to OpenGL ES */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   413
    attr_pos = 0;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   414
    wdata->gles_attributes[attr_pos++] = EGL_SURFACE_TYPE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   415
    wdata->gles_attributes[attr_pos++] = EGL_WINDOW_BIT;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   416
    wdata->gles_attributes[attr_pos++] = EGL_RED_SIZE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   417
    wdata->gles_attributes[attr_pos++] = _this->gl_config.red_size;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   418
    wdata->gles_attributes[attr_pos++] = EGL_GREEN_SIZE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   419
    wdata->gles_attributes[attr_pos++] = _this->gl_config.green_size;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   420
    wdata->gles_attributes[attr_pos++] = EGL_BLUE_SIZE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   421
    wdata->gles_attributes[attr_pos++] = _this->gl_config.blue_size;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   422
    wdata->gles_attributes[attr_pos++] = EGL_ALPHA_SIZE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   423
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   424
    /* Setup alpha size in bits */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   425
    if (_this->gl_config.alpha_size) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   426
        wdata->gles_attributes[attr_pos++] = _this->gl_config.alpha_size;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   427
    } else {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   428
        wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   429
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   430
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   431
    /* Setup color buffer size */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   432
    if (_this->gl_config.buffer_size) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   433
        wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   434
        wdata->gles_attributes[attr_pos++] = _this->gl_config.buffer_size;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   435
    } else {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   436
        wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   437
        wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   438
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   439
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   440
    /* Setup depth buffer bits */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   441
    wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   442
    wdata->gles_attributes[attr_pos++] = _this->gl_config.depth_size;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   443
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   444
    /* Setup stencil bits */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   445
    if (_this->gl_config.stencil_size) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   446
        wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   447
        wdata->gles_attributes[attr_pos++] = _this->gl_config.buffer_size;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   448
    } else {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   449
        wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   450
        wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   451
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   452
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   453
    /* Set number of samples in multisampling */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   454
    if (_this->gl_config.multisamplesamples) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   455
        wdata->gles_attributes[attr_pos++] = EGL_SAMPLES;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   456
        wdata->gles_attributes[attr_pos++] =
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   457
            _this->gl_config.multisamplesamples;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   458
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   459
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   460
    /* Multisample buffers, OpenGL ES 1.0 spec defines 0 or 1 buffer */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   461
    if (_this->gl_config.multisamplebuffers) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   462
        wdata->gles_attributes[attr_pos++] = EGL_SAMPLE_BUFFERS;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   463
        wdata->gles_attributes[attr_pos++] =
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   464
            _this->gl_config.multisamplebuffers;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   465
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   466
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   467
    /* Finish attributes list */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   468
    wdata->gles_attributes[attr_pos] = EGL_NONE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   469
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   470
    /* Request first suitable framebuffer configuration */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   471
    status = eglChooseConfig(phdata->egl_display, wdata->gles_attributes,
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   472
                             wdata->gles_configs, 1, &configs);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   473
    if (status != EGL_TRUE) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   474
        SDL_SetError("PND: Can't find closest configuration for OpenGL ES");
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   475
        return NULL;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   476
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   477
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   478
    /* Check if nothing has been found, try "don't care" settings */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   479
    if (configs == 0) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   480
        int32_t it;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   481
        int32_t jt;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   482
        GLint depthbits[4] = { 32, 24, 16, EGL_DONT_CARE };
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   483
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   484
        for (it = 0; it < 4; it++) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   485
            for (jt = 16; jt >= 0; jt--) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   486
                /* Don't care about color buffer bits, use what exist */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   487
                /* Replace previous set data with EGL_DONT_CARE       */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   488
                attr_pos = 0;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   489
                wdata->gles_attributes[attr_pos++] = EGL_SURFACE_TYPE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   490
                wdata->gles_attributes[attr_pos++] = EGL_WINDOW_BIT;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   491
                wdata->gles_attributes[attr_pos++] = EGL_RED_SIZE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   492
                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   493
                wdata->gles_attributes[attr_pos++] = EGL_GREEN_SIZE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   494
                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   495
                wdata->gles_attributes[attr_pos++] = EGL_BLUE_SIZE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   496
                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   497
                wdata->gles_attributes[attr_pos++] = EGL_ALPHA_SIZE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   498
                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   499
                wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   500
                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   501
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   502
                /* Try to find requested or smallest depth */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   503
                if (_this->gl_config.depth_size) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   504
                    wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   505
                    wdata->gles_attributes[attr_pos++] = depthbits[it];
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   506
                } else {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   507
                    wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   508
                    wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   509
                }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   510
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   511
                if (_this->gl_config.stencil_size) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   512
                    wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   513
                    wdata->gles_attributes[attr_pos++] = jt;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   514
                } else {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   515
                    wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   516
                    wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   517
                }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   518
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   519
                wdata->gles_attributes[attr_pos++] = EGL_SAMPLES;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   520
                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   521
                wdata->gles_attributes[attr_pos++] = EGL_SAMPLE_BUFFERS;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   522
                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   523
                wdata->gles_attributes[attr_pos] = EGL_NONE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   524
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   525
                /* Request first suitable framebuffer configuration */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   526
                status =
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   527
                    eglChooseConfig(phdata->egl_display,
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   528
                                    wdata->gles_attributes,
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   529
                                    wdata->gles_configs, 1, &configs);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   530
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   531
                if (status != EGL_TRUE) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   532
                    SDL_SetError
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   533
                        ("PND: Can't find closest configuration for OpenGL ES");
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   534
                    return NULL;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   535
                }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   536
                if (configs != 0) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   537
                    break;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   538
                }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   539
            }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   540
            if (configs != 0) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   541
                break;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   542
            }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   543
        }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   544
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   545
        /* No available configs */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   546
        if (configs == 0) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   547
            SDL_SetError("PND: Can't find any configuration for OpenGL ES");
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   548
            return NULL;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   549
        }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   550
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   551
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   552
    /* Initialize config index */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   553
    wdata->gles_config = 0;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   554
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   555
    /* Now check each configuration to find out the best */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   556
    for (cit = 0; cit < configs; cit++) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   557
        uint32_t stencil_found;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   558
        uint32_t depth_found;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   559
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   560
        stencil_found = 0;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   561
        depth_found = 0;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   562
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   563
        if (_this->gl_config.stencil_size) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   564
            status =
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   565
                eglGetConfigAttrib(phdata->egl_display,
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   566
                                   wdata->gles_configs[cit], EGL_STENCIL_SIZE,
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   567
                                   &attr_value);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   568
            if (status == EGL_TRUE) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   569
                if (attr_value != 0) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   570
                    stencil_found = 1;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   571
                }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   572
            }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   573
        } else {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   574
            stencil_found = 1;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   575
        }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   576
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   577
        if (_this->gl_config.depth_size) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   578
            status =
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   579
                eglGetConfigAttrib(phdata->egl_display,
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   580
                                   wdata->gles_configs[cit], EGL_DEPTH_SIZE,
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   581
                                   &attr_value);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   582
            if (status == EGL_TRUE) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   583
                if (attr_value != 0) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   584
                    depth_found = 1;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   585
                }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   586
            }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   587
        } else {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   588
            depth_found = 1;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   589
        }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   590
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   591
        /* Exit from loop if found appropriate configuration */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   592
        if ((depth_found != 0) && (stencil_found != 0)) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   593
            break;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   594
        }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   595
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   596
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   597
    /* If best could not be found, use first */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   598
    if (cit == configs) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   599
        cit = 0;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   600
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   601
    wdata->gles_config = cit;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   602
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   603
    /* Create OpenGL ES context */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   604
    wdata->gles_context =
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   605
        eglCreateContext(phdata->egl_display,
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   606
                         wdata->gles_configs[wdata->gles_config], NULL, NULL);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   607
    if (wdata->gles_context == EGL_NO_CONTEXT) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   608
        SDL_SetError("PND: OpenGL ES context creation has been failed");
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   609
        return NULL;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   610
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   611
3438
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   612
#ifdef WIZ_GLES_LITE
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   613
    if( !hNativeWnd ) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   614
    hNativeWnd = (NativeWindowType)malloc(16*1024);
3438
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   615
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   616
    if(!hNativeWnd)
10205
baabe483bb99 Pandora: Fixed SDL version in debug output.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 10202
diff changeset
   617
        printf( "Error: Wiz framebuffer allocatation failed\n" );
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   618
    else
10205
baabe483bb99 Pandora: Fixed SDL version in debug output.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 10202
diff changeset
   619
        printf( "SDL: Wiz framebuffer allocated: %X\n", hNativeWnd );
3438
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   620
    }
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   621
    else {
10205
baabe483bb99 Pandora: Fixed SDL version in debug output.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 10202
diff changeset
   622
        printf( "SDL: Wiz framebuffer already allocated: %X\n", hNativeWnd );
3438
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   623
    }
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   624
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   625
    wdata->gles_surface =
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   626
    eglCreateWindowSurface(phdata->egl_display,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   627
                   wdata->gles_configs[wdata->gles_config],
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   628
                   hNativeWnd, NULL );
3438
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   629
#else
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   630
    wdata->gles_surface =
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   631
        eglCreateWindowSurface(phdata->egl_display,
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   632
                               wdata->gles_configs[wdata->gles_config],
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   633
                               (NativeWindowType) 0, NULL);
3438
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   634
#endif
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   635
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   636
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   637
    if (wdata->gles_surface == 0) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   638
        SDL_SetError("Error : eglCreateWindowSurface failed;\n");
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   639
        return NULL;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   640
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   641
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   642
    /* Make just created context current */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   643
    status =
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   644
        eglMakeCurrent(phdata->egl_display, wdata->gles_surface,
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   645
                       wdata->gles_surface, wdata->gles_context);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   646
    if (status != EGL_TRUE) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   647
        /* Destroy OpenGL ES surface */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   648
        eglDestroySurface(phdata->egl_display, wdata->gles_surface);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   649
        eglDestroyContext(phdata->egl_display, wdata->gles_context);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   650
        wdata->gles_context = EGL_NO_CONTEXT;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   651
        SDL_SetError("PND: Can't set OpenGL ES context on creation");
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   652
        return NULL;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   653
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   654
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   655
    _this->gl_config.accelerated = 1;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   656
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   657
    /* Always clear stereo enable, since OpenGL ES do not supports stereo */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   658
    _this->gl_config.stereo = 0;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   659
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   660
    /* Get back samples and samplebuffers configurations. Rest framebuffer */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   661
    /* parameters could be obtained through the OpenGL ES API              */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   662
    status =
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   663
        eglGetConfigAttrib(phdata->egl_display,
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   664
                           wdata->gles_configs[wdata->gles_config],
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   665
                           EGL_SAMPLES, &attr_value);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   666
    if (status == EGL_TRUE) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   667
        _this->gl_config.multisamplesamples = attr_value;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   668
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   669
    status =
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   670
        eglGetConfigAttrib(phdata->egl_display,
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   671
                           wdata->gles_configs[wdata->gles_config],
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   672
                           EGL_SAMPLE_BUFFERS, &attr_value);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   673
    if (status == EGL_TRUE) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   674
        _this->gl_config.multisamplebuffers = attr_value;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   675
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   676
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   677
    /* Get back stencil and depth buffer sizes */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   678
    status =
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   679
        eglGetConfigAttrib(phdata->egl_display,
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   680
                           wdata->gles_configs[wdata->gles_config],
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   681
                           EGL_DEPTH_SIZE, &attr_value);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   682
    if (status == EGL_TRUE) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   683
        _this->gl_config.depth_size = attr_value;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   684
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   685
    status =
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   686
        eglGetConfigAttrib(phdata->egl_display,
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   687
                           wdata->gles_configs[wdata->gles_config],
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   688
                           EGL_STENCIL_SIZE, &attr_value);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   689
    if (status == EGL_TRUE) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   690
        _this->gl_config.stencil_size = attr_value;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   691
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   692
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   693
    /* Under PND OpenGL ES output can't be double buffered */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   694
    _this->gl_config.double_buffer = 0;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   695
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   696
    /* GL ES context was successfully created */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   697
    return wdata->gles_context;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   698
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   699
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   700
int
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   701
PND_gl_makecurrent(_THIS, SDL_Window * window, SDL_GLContext context)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   702
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   703
    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   704
    SDL_WindowData *wdata;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   705
    EGLBoolean status;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   706
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   707
    if (phdata->egl_initialized != SDL_TRUE) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   708
        return SDL_SetError("PND: GF initialization failed, no OpenGL ES support");
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   709
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   710
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   711
    if ((window == NULL) && (context == NULL)) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   712
        status =
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   713
            eglMakeCurrent(phdata->egl_display, EGL_NO_SURFACE,
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   714
                           EGL_NO_SURFACE, EGL_NO_CONTEXT);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   715
        if (status != EGL_TRUE) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   716
            /* Failed to set current GL ES context */
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   717
            return SDL_SetError("PND: Can't set OpenGL ES context");
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   718
        }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   719
    } else {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   720
        wdata = (SDL_WindowData *) window->driverdata;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   721
        if (wdata->gles_surface == EGL_NO_SURFACE) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   722
            return SDL_SetError
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   723
                ("PND: OpenGL ES surface is not initialized for this window");
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   724
        }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   725
        if (wdata->gles_context == EGL_NO_CONTEXT) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   726
            return SDL_SetError
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   727
                ("PND: OpenGL ES context is not initialized for this window");
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   728
        }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   729
        if (wdata->gles_context != context) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   730
            return SDL_SetError
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   731
                ("PND: OpenGL ES context is not belong to this window");
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   732
        }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   733
        status =
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   734
            eglMakeCurrent(phdata->egl_display, wdata->gles_surface,
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   735
                           wdata->gles_surface, wdata->gles_context);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   736
        if (status != EGL_TRUE) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   737
            /* Failed to set current GL ES context */
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   738
            return SDL_SetError("PND: Can't set OpenGL ES context");
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   739
        }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   740
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   741
    return 0;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   742
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   743
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   744
int
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   745
PND_gl_setswapinterval(_THIS, int interval)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   746
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   747
    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   748
    EGLBoolean status;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   749
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   750
    if (phdata->egl_initialized != SDL_TRUE) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   751
        return SDL_SetError("PND: EGL initialization failed, no OpenGL ES support");
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   752
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   753
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   754
    /* Check if OpenGL ES connection has been initialized */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   755
    if (phdata->egl_display != EGL_NO_DISPLAY) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   756
        /* Set swap OpenGL ES interval */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   757
        status = eglSwapInterval(phdata->egl_display, interval);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   758
        if (status == EGL_TRUE) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   759
            /* Return success to upper level */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   760
            phdata->swapinterval = interval;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   761
            return 0;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   762
        }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   763
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   764
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   765
    /* Failed to set swap interval */
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   766
    return SDL_SetError("PND: Cannot set swap interval");
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   767
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   768
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   769
int
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   770
PND_gl_getswapinterval(_THIS)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   771
{
6382
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6138
diff changeset
   772
    return ((SDL_VideoData *) _this->driverdata)->swapinterval;
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   773
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   774
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   775
void
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   776
PND_gl_swapwindow(_THIS, SDL_Window * window)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   777
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   778
    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   779
    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   780
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   781
    if (phdata->egl_initialized != SDL_TRUE) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   782
        SDL_SetError("PND: GLES initialization failed, no OpenGL ES support");
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   783
        return;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   784
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   785
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   786
    /* Many applications do not uses glFinish(), so we call it for them */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   787
    glFinish();
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   788
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   789
    /* Wait until OpenGL ES rendering is completed */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   790
    eglWaitGL();
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   791
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   792
    eglSwapBuffers(phdata->egl_display, wdata->gles_surface);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   793
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   794
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   795
void
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   796
PND_gl_deletecontext(_THIS, SDL_GLContext context)
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   797
{
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   798
    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   799
    EGLBoolean status;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   800
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   801
    if (phdata->egl_initialized != SDL_TRUE) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   802
        SDL_SetError("PND: GLES initialization failed, no OpenGL ES support");
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   803
        return;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   804
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   805
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   806
    /* Check if OpenGL ES connection has been initialized */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   807
    if (phdata->egl_display != EGL_NO_DISPLAY) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   808
        if (context != EGL_NO_CONTEXT) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   809
            status = eglDestroyContext(phdata->egl_display, context);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   810
            if (status != EGL_TRUE) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   811
                /* Error during OpenGL ES context destroying */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   812
                SDL_SetError("PND: OpenGL ES context destroy error");
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   813
                return;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   814
            }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   815
        }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   816
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   817
3438
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   818
#ifdef WIZ_GLES_LITE
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   819
    if( hNativeWnd != 0 )
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   820
    {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   821
      free(hNativeWnd);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   822
      hNativeWnd = 0;
10205
baabe483bb99 Pandora: Fixed SDL version in debug output.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 10202
diff changeset
   823
      printf( "SDL: Wiz framebuffer released\n" );
3438
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   824
    }
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   825
#endif
ca5663493497 Scott to slouken
Sam Lantinga <slouken@libsdl.org>
parents: 3238
diff changeset
   826
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   827
    return;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   828
}
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   829
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   830
#endif /* SDL_VIDEO_DRIVER_PANDORA */
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   831
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   832
/* vi: set ts=4 sw=4 expandtab: */