SDL  2.0
SDL_pspgl.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2016 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 {
52  }
53 
54  return 0;
55 }
56 
57 /* pspgl doesn't provide this call, so stub it out since SDL requires it.
58 #define GLSTUB(func,params) void func params {}
59 
60 GLSTUB(glOrtho,(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top,
61  GLdouble zNear, GLdouble zFar))
62 */
63 void *
64 PSP_GL_GetProcAddress(_THIS, const char *proc)
65 {
66  return eglGetProcAddress(proc);
67 }
68 
69 void
71 {
72  eglTerminate(_this->gl_data->display);
73 }
74 
75 static EGLint width = 480;
76 static EGLint height = 272;
77 
80 {
81 
82  SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
83 
84  EGLint attribs[32];
85  EGLDisplay display;
86  EGLContext context;
87  EGLSurface surface;
88  EGLConfig config;
89  EGLint num_configs;
90  int i;
91 
92 
93  /* EGL init taken from glutCreateWindow() in PSPGL's glut.c. */
94  EGLCHK(display = eglGetDisplay(0));
95  EGLCHK(eglInitialize(display, NULL, NULL));
96  wdata->uses_gles = SDL_TRUE;
97  window->flags |= SDL_WINDOW_FULLSCREEN;
98 
99  /* Setup the config based on SDL's current values. */
100  i = 0;
101  attribs[i++] = EGL_RED_SIZE;
103  attribs[i++] = EGL_GREEN_SIZE;
105  attribs[i++] = EGL_BLUE_SIZE;
107  attribs[i++] = EGL_DEPTH_SIZE;
109 
111  {
112  attribs[i++] = EGL_ALPHA_SIZE;
114  }
116  {
117  attribs[i++] = EGL_STENCIL_SIZE;
119  }
120 
121  attribs[i++] = EGL_NONE;
122 
123  EGLCHK(eglChooseConfig(display, attribs, &config, 1, &num_configs));
124 
125  if (num_configs == 0)
126  {
127  SDL_SetError("No valid EGL configs for requested mode");
128  return 0;
129  }
130 
131  EGLCHK(eglGetConfigAttrib(display, config, EGL_WIDTH, &width));
132  EGLCHK(eglGetConfigAttrib(display, config, EGL_HEIGHT, &height));
133 
134  EGLCHK(context = eglCreateContext(display, config, NULL, NULL));
135  EGLCHK(surface = eglCreateWindowSurface(display, config, 0, NULL));
136  EGLCHK(eglMakeCurrent(display, surface, surface, context));
137 
138  _this->gl_data->display = display;
139  _this->gl_data->context = context;
140  _this->gl_data->surface = surface;
141 
142 
143  return context;
144 }
145 
146 int
148 {
149  if (!eglMakeCurrent(_this->gl_data->display, _this->gl_data->surface,
151  {
152  return SDL_SetError("Unable to make EGL context current");
153  }
154  return 0;
155 }
156 
157 int
158 PSP_GL_SetSwapInterval(_THIS, int interval)
159 {
160  EGLBoolean status;
161  status = eglSwapInterval(_this->gl_data->display, interval);
162  if (status == EGL_TRUE) {
163  /* Return success to upper level */
164  _this->gl_data->swapinterval = interval;
165  return 0;
166  }
167  /* Failed to set swap interval */
168  return SDL_SetError("Unable to set the EGL swap interval");
169 }
170 
171 int
173 {
174  return _this->gl_data->swapinterval;
175 }
176 
177 void
179 {
180  eglSwapBuffers(_this->gl_data->display, _this->gl_data->surface);
181 }
182 
183 void
185 {
187  EGLBoolean status;
188 
189  if (phdata->egl_initialized != SDL_TRUE) {
190  SDL_SetError("PSP: GLES initialization failed, no OpenGL ES support");
191  return;
192  }
193 
194  /* Check if OpenGL ES connection has been initialized */
195  if (_this->gl_data->display != EGL_NO_DISPLAY) {
196  if (context != EGL_NO_CONTEXT) {
197  status = eglDestroyContext(_this->gl_data->display, context);
198  if (status != EGL_TRUE) {
199  /* Error during OpenGL ES context destroying */
200  SDL_SetError("PSP: OpenGL ES context destroy error");
201  return;
202  }
203  }
204  }
205 
206  return;
207 }
208 
209 #endif /* SDL_VIDEO_DRIVER_PSP */
210 
211 /* vi: set ts=4 sw=4 expandtab: */
const GLint * attribs
uint32_t swapinterval
Definition: SDL_pspgl_c.h:36
GLint GLint GLsizei width
Definition: SDL_opengl.h:1565
void PSP_GL_UnloadLibrary(_THIS)
SDL_GLContext PSP_GL_CreateContext(_THIS, SDL_Window *window)
static SDL_Window * window
EGLSurface surface
Definition: SDL_pspgl_c.h:35
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1565
void PSP_GL_SwapWindow(_THIS, SDL_Window *window)
EGLDisplay display
Definition: SDL_pspgl_c.h:33
int PSP_GL_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
int PSP_GL_GetSwapInterval(_THIS)
struct SDL_GLDriverData * gl_data
Definition: SDL_sysvideo.h:346
static SDL_VideoDevice * _this
Definition: SDL_video.c:118
struct SDL_VideoDevice::@29 gl_config
void * SDL_GLContext
An opaque handle to an OpenGL context.
Definition: SDL_video.h:172
void PSP_GL_DeleteContext(_THIS, SDL_GLContext context)
#define _THIS
SDL_bool uses_gles
Definition: SDL_pandora.h:48
int PSP_GL_LoadLibrary(_THIS, const char *path)
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:143
#define SDL_SetError
The type used to identify a window.
Definition: SDL_sysvideo.h:71
void * PSP_GL_GetProcAddress(_THIS, const char *proc)
SDL_bool egl_initialized
Definition: SDL_pandora.h:32
GLsizei const GLchar *const * path
void * driverdata
Definition: SDL_sysvideo.h:109
EGLContext context
Definition: SDL_pspgl_c.h:34
Uint32 flags
Definition: SDL_sysvideo.h:81