#include "SDL_internal.h"
#ifdef SDL_VIDEO_DRIVER_PSP
#include <stdlib.h>
#include <string.h>
#include "SDL_pspvideo.h"
#include "SDL_pspgl_c.h"
#define EGLCHK(stmt) \
do { \
EGLint err; \
\
stmt; \
err = eglGetError(); \
if (err != EGL_SUCCESS) { \
SDL_SetError("EGL error %d", err); \
return NULL; \
} \
} while (0)
bool PSP_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path)
{
return true;
}
SDL_FunctionPointer PSP_GL_GetProcAddress(SDL_VideoDevice *_this, const char *proc)
{
return eglGetProcAddress(proc);
}
void PSP_GL_UnloadLibrary(SDL_VideoDevice *_this)
{
eglTerminate(_this->gl_data->display);
}
static EGLint width = 480;
static EGLint height = 272;
SDL_GLContext PSP_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window)
{
SDL_WindowData *wdata = window->internal;
EGLint attribs[32];
EGLDisplay display;
EGLContext context;
EGLSurface surface;
EGLConfig config;
EGLint num_configs;
int i;
EGLCHK(display = eglGetDisplay(0));
EGLCHK(eglInitialize(display, NULL, NULL));
wdata->uses_gles = true;
window->flags |= SDL_WINDOW_FULLSCREEN;
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 NULL;
}
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;
}
bool PSP_GL_MakeCurrent(SDL_VideoDevice *_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 true;
}
bool PSP_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval)
{
EGLBoolean status;
status = eglSwapInterval(_this->gl_data->display, interval);
if (status == EGL_TRUE) {
_this->gl_data->swapinterval = interval;
return true;
}
return SDL_SetError("Unable to set the EGL swap interval");
}
bool PSP_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval)
{
*interval = _this->gl_data->swapinterval;
return true;
}
bool PSP_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
{
if (!eglSwapBuffers(_this->gl_data->display, _this->gl_data->surface)) {
return SDL_SetError("eglSwapBuffers() failed");
}
return true;
}
bool PSP_GL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context)
{
SDL_VideoData *phdata = _this->internal;
EGLBoolean status;
if (phdata->egl_initialized != true) {
return SDL_SetError("PSP: GLES initialization failed, no OpenGL ES support");
}
if (_this->gl_data->display != EGL_NO_DISPLAY) {
if (context != EGL_NO_CONTEXT) {
status = eglDestroyContext(_this->gl_data->display, context);
if (status != EGL_TRUE) {
return SDL_SetError("PSP: OpenGL ES context destroy error");
}
}
}
return true;
}
#endif