src/video/psp/SDL_pspgl.c
author Sam Lantinga
Fri, 27 Jan 2017 21:23:27 -0800
changeset 10861 71d8f9afb690
parent 10741 a32fd6b7412b
child 10960 5ebfa73d9f4b
permissions -rw-r--r--
Fixed bug 3569 - GL_UpdateViewport leaves PROJECTION matrix selected

Tom Seddon

GL_ActivateRenderer may call GL_UpdateViewport, which leaves the GL_PROJECTION matrix selected. But after GL_ResetState, the GL_MODELVIEW matrix is selected, suggesting that's the intended default state.

It seems at least like these should be consistent. Presumably GL_UpdateViewport should be doing a glMatrixMode(GL_MODELVIEW) before it finishes.
kimonline@7009
     1
/*
kimonline@7009
     2
  Simple DirectMedia Layer
slouken@10737
     3
  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
kimonline@7009
     4
kimonline@7009
     5
  This software is provided 'as-is', without any express or implied
kimonline@7009
     6
  warranty.  In no event will the authors be held liable for any damages
kimonline@7009
     7
  arising from the use of this software.
kimonline@7009
     8
kimonline@7009
     9
  Permission is granted to anyone to use this software for any purpose,
kimonline@7009
    10
  including commercial applications, and to alter it and redistribute it
kimonline@7009
    11
  freely, subject to the following restrictions:
kimonline@7009
    12
kimonline@7009
    13
  1. The origin of this software must not be misrepresented; you must not
kimonline@7009
    14
     claim that you wrote the original software. If you use this software
kimonline@7009
    15
     in a product, an acknowledgment in the product documentation would be
kimonline@7009
    16
     appreciated but is not required.
kimonline@7009
    17
  2. Altered source versions must be plainly marked as such, and must not be
kimonline@7009
    18
     misrepresented as being the original software.
kimonline@7009
    19
  3. This notice may not be removed or altered from any source distribution.
kimonline@7009
    20
*/
philipp@9328
    21
#include "../../SDL_internal.h"
kimonline@7009
    22
philipp@9329
    23
#if SDL_VIDEO_DRIVER_PSP
philipp@9329
    24
kimonline@7009
    25
#include <stdlib.h>
kimonline@7009
    26
#include <string.h>
kimonline@7009
    27
kimonline@7009
    28
#include "SDL_error.h"
kimonline@7009
    29
#include "SDL_pspvideo.h"
kimonline@7009
    30
#include "SDL_pspgl_c.h"
kimonline@7009
    31
kimonline@7009
    32
/*****************************************************************************/
kimonline@7009
    33
/* SDL OpenGL/OpenGL ES functions                                            */
kimonline@7009
    34
/*****************************************************************************/
slouken@7191
    35
#define EGLCHK(stmt)                            \
slouken@7191
    36
    do {                                        \
slouken@7191
    37
        EGLint err;                             \
slouken@7191
    38
                                                \
slouken@7191
    39
        stmt;                                   \
slouken@7191
    40
        err = eglGetError();                    \
slouken@7191
    41
        if (err != EGL_SUCCESS) {               \
slouken@7191
    42
            SDL_SetError("EGL error %d", err);  \
slouken@7191
    43
            return 0;                           \
slouken@7191
    44
        }                                       \
slouken@7191
    45
    } while (0)
kimonline@7009
    46
kimonline@7009
    47
int
kimonline@7009
    48
PSP_GL_LoadLibrary(_THIS, const char *path)
kimonline@7009
    49
{
kimonline@7009
    50
  return 0;
kimonline@7009
    51
}
kimonline@7009
    52
slouken@7191
    53
/* pspgl doesn't provide this call, so stub it out since SDL requires it.
kimonline@7009
    54
#define GLSTUB(func,params) void func params {}
slouken@7191
    55
kimonline@7009
    56
GLSTUB(glOrtho,(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top,
slouken@7191
    57
                    GLdouble zNear, GLdouble zFar))
kimonline@7009
    58
*/
kimonline@7009
    59
void *
kimonline@7009
    60
PSP_GL_GetProcAddress(_THIS, const char *proc)
kimonline@7009
    61
{
slouken@7191
    62
        return eglGetProcAddress(proc);
kimonline@7009
    63
}
kimonline@7009
    64
kimonline@7009
    65
void
kimonline@7009
    66
PSP_GL_UnloadLibrary(_THIS)
kimonline@7009
    67
{
slouken@7191
    68
        eglTerminate(_this->gl_data->display);
kimonline@7009
    69
}
kimonline@7009
    70
kimonline@7009
    71
static EGLint width = 480;
kimonline@7009
    72
static EGLint height = 272;
kimonline@7009
    73
kimonline@7009
    74
SDL_GLContext
kimonline@7009
    75
PSP_GL_CreateContext(_THIS, SDL_Window * window)
kimonline@7009
    76
{
kimonline@7009
    77
kimonline@7009
    78
    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
kimonline@7009
    79
slouken@7191
    80
        EGLint attribs[32];
slouken@7191
    81
        EGLDisplay display;
slouken@7191
    82
        EGLContext context;
slouken@7191
    83
        EGLSurface surface;
slouken@7191
    84
        EGLConfig config;
slouken@7191
    85
        EGLint num_configs;
slouken@7191
    86
        int i;
slouken@7191
    87
slouken@7191
    88
slouken@7191
    89
    /* EGL init taken from glutCreateWindow() in PSPGL's glut.c. */
slouken@7191
    90
        EGLCHK(display = eglGetDisplay(0));
slouken@7191
    91
        EGLCHK(eglInitialize(display, NULL, NULL));
slouken@7191
    92
    wdata->uses_gles = SDL_TRUE;
slouken@7191
    93
        window->flags |= SDL_WINDOW_FULLSCREEN;
slouken@7191
    94
slouken@7191
    95
        /* Setup the config based on SDL's current values. */
slouken@7191
    96
        i = 0;
slouken@7191
    97
        attribs[i++] = EGL_RED_SIZE;
slouken@7191
    98
        attribs[i++] = _this->gl_config.red_size;
slouken@7191
    99
        attribs[i++] = EGL_GREEN_SIZE;
slouken@7191
   100
        attribs[i++] = _this->gl_config.green_size;
slouken@7191
   101
        attribs[i++] = EGL_BLUE_SIZE;
slouken@7191
   102
        attribs[i++] = _this->gl_config.blue_size;
slouken@7191
   103
        attribs[i++] = EGL_DEPTH_SIZE;
slouken@7191
   104
        attribs[i++] = _this->gl_config.depth_size;
kimonline@7009
   105
slouken@7191
   106
        if (_this->gl_config.alpha_size)
slouken@7191
   107
        {
slouken@7191
   108
            attribs[i++] = EGL_ALPHA_SIZE;
slouken@7191
   109
            attribs[i++] = _this->gl_config.alpha_size;
slouken@7191
   110
        }
slouken@7191
   111
        if (_this->gl_config.stencil_size)
slouken@7191
   112
        {
slouken@7191
   113
            attribs[i++] = EGL_STENCIL_SIZE;
slouken@7191
   114
            attribs[i++] = _this->gl_config.stencil_size;
slouken@7191
   115
        }
slouken@7191
   116
slouken@7191
   117
        attribs[i++] = EGL_NONE;
slouken@7191
   118
slouken@7191
   119
        EGLCHK(eglChooseConfig(display, attribs, &config, 1, &num_configs));
kimonline@7009
   120
slouken@7191
   121
        if (num_configs == 0)
slouken@7191
   122
        {
slouken@7191
   123
            SDL_SetError("No valid EGL configs for requested mode");
slouken@7191
   124
            return 0;
slouken@7191
   125
        }
slouken@7191
   126
slouken@7191
   127
        EGLCHK(eglGetConfigAttrib(display, config, EGL_WIDTH, &width));
slouken@7191
   128
        EGLCHK(eglGetConfigAttrib(display, config, EGL_HEIGHT, &height));
slouken@7191
   129
slouken@7191
   130
        EGLCHK(context = eglCreateContext(display, config, NULL, NULL));
slouken@7191
   131
        EGLCHK(surface = eglCreateWindowSurface(display, config, 0, NULL));
slouken@7191
   132
        EGLCHK(eglMakeCurrent(display, surface, surface, context));
slouken@7191
   133
slouken@7191
   134
        _this->gl_data->display = display;
slouken@7191
   135
        _this->gl_data->context = context;
slouken@7191
   136
        _this->gl_data->surface = surface;
slouken@7191
   137
kimonline@7009
   138
kimonline@7009
   139
    return context;
kimonline@7009
   140
}
kimonline@7009
   141
kimonline@7009
   142
int
kimonline@7009
   143
PSP_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
kimonline@7009
   144
{
slouken@7191
   145
        if (!eglMakeCurrent(_this->gl_data->display, _this->gl_data->surface,
slouken@7191
   146
                          _this->gl_data->surface, _this->gl_data->context))
slouken@7191
   147
        {
slouken@7191
   148
            return SDL_SetError("Unable to make EGL context current");
slouken@7191
   149
        }
kimonline@7009
   150
    return 0;
kimonline@7009
   151
}
kimonline@7009
   152
kimonline@7009
   153
int
kimonline@7009
   154
PSP_GL_SetSwapInterval(_THIS, int interval)
kimonline@7009
   155
{
slouken@7191
   156
    EGLBoolean status;
kimonline@7009
   157
    status = eglSwapInterval(_this->gl_data->display, interval);
kimonline@7009
   158
    if (status == EGL_TRUE) {
kimonline@7009
   159
        /* Return success to upper level */
kimonline@7009
   160
        _this->gl_data->swapinterval = interval;
kimonline@7009
   161
        return 0;
kimonline@7009
   162
    }
kimonline@7009
   163
    /* Failed to set swap interval */
icculus@7037
   164
    return SDL_SetError("Unable to set the EGL swap interval");
kimonline@7009
   165
}
kimonline@7009
   166
kimonline@7009
   167
int
kimonline@7009
   168
PSP_GL_GetSwapInterval(_THIS)
kimonline@7009
   169
{
kimonline@7009
   170
    return _this->gl_data->swapinterval;
kimonline@7009
   171
}
kimonline@7009
   172
slouken@10690
   173
int
kimonline@7009
   174
PSP_GL_SwapWindow(_THIS, SDL_Window * window)
kimonline@7009
   175
{
slouken@10695
   176
    if (!eglSwapBuffers(_this->gl_data->display, _this->gl_data->surface)) {
slouken@10695
   177
        return SDL_SetError("!eglSwapBuffers() failed");
slouken@10695
   178
    }
slouken@10690
   179
    return 0;
kimonline@7009
   180
}
kimonline@7009
   181
kimonline@7009
   182
void
kimonline@7009
   183
PSP_GL_DeleteContext(_THIS, SDL_GLContext context)
kimonline@7009
   184
{
kimonline@7009
   185
    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
kimonline@7009
   186
    EGLBoolean status;
kimonline@7009
   187
kimonline@7009
   188
    if (phdata->egl_initialized != SDL_TRUE) {
kimonline@7009
   189
        SDL_SetError("PSP: GLES initialization failed, no OpenGL ES support");
kimonline@7009
   190
        return;
kimonline@7009
   191
    }
kimonline@7009
   192
kimonline@7009
   193
    /* Check if OpenGL ES connection has been initialized */
kimonline@7009
   194
    if (_this->gl_data->display != EGL_NO_DISPLAY) {
kimonline@7009
   195
        if (context != EGL_NO_CONTEXT) {
kimonline@7009
   196
            status = eglDestroyContext(_this->gl_data->display, context);
kimonline@7009
   197
            if (status != EGL_TRUE) {
kimonline@7009
   198
                /* Error during OpenGL ES context destroying */
kimonline@7009
   199
                SDL_SetError("PSP: OpenGL ES context destroy error");
kimonline@7009
   200
                return;
kimonline@7009
   201
            }
kimonline@7009
   202
        }
kimonline@7009
   203
    }
kimonline@7009
   204
kimonline@7009
   205
    return;
kimonline@7009
   206
}
kimonline@7009
   207
philipp@9329
   208
#endif /* SDL_VIDEO_DRIVER_PSP */
philipp@9329
   209
philipp@9329
   210
/* vi: set ts=4 sw=4 expandtab: */