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