SDL_pspgl.c
Go to the documentation of this file.
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_PSP
#include <stdlib.h>
#include <string.h>
#include "SDL_error.h"
#include "SDL_pspvideo.h"
#include "SDL_pspgl_c.h"
/*****************************************************************************/
/* SDL OpenGL/OpenGL ES functions */
/*****************************************************************************/
#define EGLCHK(stmt) \
do { \
EGLint err; \
\
stmt; \
err = eglGetError(); \
if (err != EGL_SUCCESS) { \
SDL_SetError("EGL error %d", err); \
return 0; \
} \
} while (0)
int
PSP_GL_LoadLibrary(_THIS, const char *path)
{
return 0;
}
/* pspgl doesn't provide this call, so stub it out since SDL requires it.
#define GLSTUB(func,params) void func params {}
GLSTUB(glOrtho,(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top,
GLdouble zNear, GLdouble zFar))
*/
void *
PSP_GL_GetProcAddress(_THIS, const char *proc)
{
return eglGetProcAddress(proc);
}
void
PSP_GL_UnloadLibrary(_THIS)
{
eglTerminate(_this->gl_data->display);
}
static EGLint width = 480;
static EGLint height = 272;
SDL_GLContext
PSP_GL_CreateContext(_THIS, SDL_Window * window)
{
SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
EGLint attribs[32];
EGLDisplay display;
EGLContext context;
EGLSurface surface;
EGLConfig config;
EGLint num_configs;
int i;
/* EGL init taken from glutCreateWindow() in PSPGL's glut.c. */
EGLCHK(display = eglGetDisplay(0));
EGLCHK(eglInitialize(display, NULL, NULL));
wdata->uses_gles = SDL_TRUE;
window->flags |= SDL_WINDOW_FULLSCREEN;
/* Setup the config based on SDL's current values. */
i = 0;
attribs[i++] = EGL_RED_SIZE;
attribs[i++] = _this->gl_config.red_size;
attribs[i++] = EGL_GREEN_SIZE;
attribs[i++] = _this->gl_config.green_size;
attribs[i++] = EGL_BLUE_SIZE;
attribs[i++] = _this->gl_config.blue_size;
attribs[i++] = EGL_DEPTH_SIZE;
attribs[i++] = _this->gl_config.depth_size;
if (_this->gl_config.alpha_size)
{
attribs[i++] = EGL_ALPHA_SIZE;
attribs[i++] = _this->gl_config.alpha_size;
}
if (_this->gl_config.stencil_size)
{
attribs[i++] = EGL_STENCIL_SIZE;
attribs[i++] = _this->gl_config.stencil_size;
}
attribs[i++] = EGL_NONE;
EGLCHK(eglChooseConfig(display, attribs, &config, 1, &num_configs));
if (num_configs == 0)
{
SDL_SetError("No valid EGL configs for requested mode");
return 0;
}
EGLCHK(eglGetConfigAttrib(display, config, EGL_WIDTH, &width));
EGLCHK(eglGetConfigAttrib(display, config, EGL_HEIGHT, &height));
EGLCHK(context = eglCreateContext(display, config, NULL, NULL));
EGLCHK(surface = eglCreateWindowSurface(display, config, 0, NULL));
EGLCHK(eglMakeCurrent(display, surface, surface, context));
_this->gl_data->display = display;
_this->gl_data->context = context;
_this->gl_data->surface = surface;
return context;
}
int
PSP_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
{
if (!eglMakeCurrent(_this->gl_data->display, _this->gl_data->surface,
_this->gl_data->surface, _this->gl_data->context))
{
return SDL_SetError("Unable to make EGL context current");
}
return 0;
}
int
PSP_GL_SetSwapInterval(_THIS, int interval)
{
EGLBoolean status;
status = eglSwapInterval(_this->gl_data->display, interval);
if (status == EGL_TRUE) {
/* Return success to upper level */
_this->gl_data->swapinterval = interval;
return 0;
}
/* Failed to set swap interval */
return SDL_SetError("Unable to set the EGL swap interval");
}
int
PSP_GL_GetSwapInterval(_THIS)
{
return _this->gl_data->swapinterval;
}
int
PSP_GL_SwapWindow(_THIS, SDL_Window * window)
{
if (!eglSwapBuffers(_this->gl_data->display, _this->gl_data->surface)) {
return SDL_SetError("eglSwapBuffers() failed");
}
return 0;
}
void
PSP_GL_DeleteContext(_THIS, SDL_GLContext context)
{
SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
EGLBoolean status;
if (phdata->egl_initialized != SDL_TRUE) {
SDL_SetError("PSP: GLES initialization failed, no OpenGL ES support");
return;
}
/* Check if OpenGL ES connection has been initialized */
if (_this->gl_data->display != EGL_NO_DISPLAY) {
if (context != EGL_NO_CONTEXT) {
status = eglDestroyContext(_this->gl_data->display, context);
if (status != EGL_TRUE) {
/* Error during OpenGL ES context destroying */
SDL_SetError("PSP: OpenGL ES context destroy error");
return;
}
}
}
return;
}
#endif /* SDL_VIDEO_DRIVER_PSP */
/* vi: set ts=4 sw=4 expandtab: */
attribs
const GLint * attribs
Definition: SDL_opengl_glext.h:9688
eglTerminate
EGLAPI EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy)
SDL_GLDriverData::swapinterval
uint32_t swapinterval
Definition: SDL_pspgl_c.h:36
SDL_TRUE
Definition: SDL_stdinc.h:142
EGL_RED_SIZE
#define EGL_RED_SIZE
Definition: egl.h:104
EGLSurface
void * EGLSurface
Definition: egl.h:59
eglCreateWindowSurface
EGLAPI EGLSurface EGLAPIENTRY eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list)
EGLConfig
void * EGLConfig
Definition: egl.h:58
PSP_GL_UnloadLibrary
void PSP_GL_UnloadLibrary(_THIS)
eglMakeCurrent
EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
PSP_GL_CreateContext
SDL_GLContext PSP_GL_CreateContext(_THIS, SDL_Window *window)
SDL_VideoDevice::blue_size
int blue_size
Definition: SDL_sysvideo.h:325
surface
EGLSurface surface
Definition: eglext.h:248
SDL_VideoDevice::driverdata
void * driverdata
Definition: SDL_sysvideo.h:377
EGL_ALPHA_SIZE
#define EGL_ALPHA_SIZE
Definition: egl.h:62
context
static screen_context_t context
Definition: video.c:25
EGL_NONE
#define EGL_NONE
Definition: egl.h:95
SDL_GLDriverData::surface
EGLSurface surface
Definition: SDL_pspgl_c.h:35
eglGetProcAddress
EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY eglGetProcAddress(const char *procname)
EGLDisplay
void * EGLDisplay
Definition: egl.h:55
EGL_HEIGHT
#define EGL_HEIGHT
Definition: egl.h:86
eglGetConfigAttrib
EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
SDL_GLDriverData::display
EGLDisplay display
Definition: SDL_pspgl_c.h:33
EGL_TRUE
#define EGL_TRUE
Definition: egl.h:116
EGL_NO_DISPLAY
#define EGL_NO_DISPLAY
Definition: egl.h:99
PSP_GL_MakeCurrent
int PSP_GL_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
width
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
PSP_GL_GetSwapInterval
int PSP_GL_GetSwapInterval(_THIS)
EGL_BLUE_SIZE
#define EGL_BLUE_SIZE
Definition: egl.h:75
SDL_VideoDevice::gl_data
struct SDL_GLDriverData * gl_data
Definition: SDL_sysvideo.h:378
EGLBoolean
unsigned int EGLBoolean
Definition: egl.h:54
SDL_WindowData
Definition: SDL_androidwindow.h:35
eglChooseConfig
EGLAPI EGLBoolean EGLAPIENTRY eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config)
_this
static SDL_VideoDevice * _this
Definition: SDL_video.c:121
eglDestroyContext
EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
EGLContext
void * EGLContext
Definition: egl.h:60
SDL_GLContext
void * SDL_GLContext
An opaque handle to an OpenGL context.
Definition: SDL_video.h:175
EGL_NO_CONTEXT
#define EGL_NO_CONTEXT
Definition: egl.h:98
SDL_pspgl_c.h
SDL_VideoDevice::depth_size
int depth_size
Definition: SDL_sysvideo.h:327
SDL_VideoDevice::red_size
int red_size
Definition: SDL_sysvideo.h:323
PSP_GL_DeleteContext
void PSP_GL_DeleteContext(_THIS, SDL_GLContext context)
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
SDL_pspvideo.h
EGLint
khronos_int32_t EGLint
Definition: eglplatform.h:122
SDL_WindowData::uses_gles
SDL_bool uses_gles
Definition: SDL_pandora.h:48
PSP_GL_LoadLibrary
int PSP_GL_LoadLibrary(_THIS, const char *path)
SDL_VideoDevice::green_size
int green_size
Definition: SDL_sysvideo.h:324
SDL_VideoDevice::alpha_size
int alpha_size
Definition: SDL_sysvideo.h:326
EGL_DEPTH_SIZE
#define EGL_DEPTH_SIZE
Definition: egl.h:80
PSP_GL_SetSwapInterval
int PSP_GL_SetSwapInterval(_THIS, int interval)
SDL_VideoDevice::stencil_size
int stencil_size
Definition: SDL_sysvideo.h:329
i
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
NULL
#define NULL
Definition: begin_code.h:164
eglGetDisplay
EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay(EGLNativeDisplayType display_id)
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
eglSwapBuffers
EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
height
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1572
window
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
PSP_GL_SwapWindow
int PSP_GL_SwapWindow(_THIS, SDL_Window *window)
SDL_Window
The type used to identify a window.
Definition: SDL_sysvideo.h:73
PSP_GL_GetProcAddress
void * PSP_GL_GetProcAddress(_THIS, const char *proc)
config
EGLConfig config
Definition: eglext.h:433
SDL_WINDOW_FULLSCREEN
Definition: SDL_video.h:100
EGL_GREEN_SIZE
#define EGL_GREEN_SIZE
Definition: egl.h:85
SDL_VideoData::egl_initialized
SDL_bool egl_initialized
Definition: SDL_pandora.h:32
eglSwapInterval
EGLAPI EGLBoolean EGLAPIENTRY eglSwapInterval(EGLDisplay dpy, EGLint interval)
SDL_VideoData
Definition: SDL_androidvideo.h:35
EGL_STENCIL_SIZE
#define EGL_STENCIL_SIZE
Definition: egl.h:108
path
GLsizei const GLchar *const * path
Definition: SDL_opengl_glext.h:3730
SDL_VideoDevice::gl_config
struct SDL_VideoDevice::@34 gl_config
SDL_Window::driverdata
void * driverdata
Definition: SDL_sysvideo.h:111
SDL_GLDriverData::context
EGLContext context
Definition: SDL_pspgl_c.h:34
SDL_Window::flags
Uint32 flags
Definition: SDL_sysvideo.h:83
eglCreateContext
EGLAPI EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list)
SDL_error.h
EGL_WIDTH
#define EGL_WIDTH
Definition: egl.h:119
eglInitialize
EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)