SDL  2.0
SDL_pspgl.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2020 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) {
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: */
PSP_GL_DeleteContext
void PSP_GL_DeleteContext(_THIS, SDL_GLContext context)
eglGetDisplay
EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay(EGLNativeDisplayType display_id)
SDL_GLDriverData::context
EGLContext context
Definition: SDL_pspgl_c.h:34
EGLContext
void * EGLContext
Definition: egl.h:60
SDL_VideoDevice::driverdata
void * driverdata
Definition: SDL_sysvideo.h:389
PSP_GL_CreateContext
SDL_GLContext PSP_GL_CreateContext(_THIS, SDL_Window *window)
eglMakeCurrent
EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
if
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
Definition: pixman-arm-neon-asm.h:469
eglSwapBuffers
EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
eglInitialize
EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
NULL
#define NULL
Definition: begin_code.h:167
surface
EGLSurface surface
Definition: eglext.h:248
attribs
const GLint * attribs
Definition: SDL_opengl_glext.h:9691
width
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
PSP_GL_GetProcAddress
void * PSP_GL_GetProcAddress(_THIS, const char *proc)
SDL_VideoDevice::blue_size
int blue_size
Definition: SDL_sysvideo.h:337
SDL_error.h
SDL_WindowData
Definition: SDL_androidwindow.h:38
SDL_WINDOW_FULLSCREEN
@ SDL_WINDOW_FULLSCREEN
Definition: SDL_video.h:99
PSP_GL_SetSwapInterval
int PSP_GL_SetSwapInterval(_THIS, int interval)
SDL_VideoDevice::gl_data
struct SDL_GLDriverData * gl_data
Definition: SDL_sysvideo.h:390
PSP_GL_MakeCurrent
int PSP_GL_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
path
GLsizei const GLchar *const * path
Definition: SDL_opengl_glext.h:3733
SDL_VideoData::egl_initialized
SDL_bool egl_initialized
Definition: SDL_pandora.h:32
SDL_VideoDevice::depth_size
int depth_size
Definition: SDL_sysvideo.h:339
EGL_TRUE
#define EGL_TRUE
Definition: egl.h:116
eglGetProcAddress
EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY eglGetProcAddress(const char *procname)
SDL_VideoDevice::red_size
int red_size
Definition: SDL_sysvideo.h:335
EGL_NO_CONTEXT
#define EGL_NO_CONTEXT
Definition: egl.h:98
SDL_Window
The type used to identify a window.
Definition: SDL_sysvideo.h:74
EGL_GREEN_SIZE
#define EGL_GREEN_SIZE
Definition: egl.h:85
PSP_GL_LoadLibrary
int PSP_GL_LoadLibrary(_THIS, const char *path)
SDL_VideoDevice::gl_config
struct SDL_VideoDevice::@255 gl_config
EGL_NO_DISPLAY
#define EGL_NO_DISPLAY
Definition: egl.h:99
context
static screen_context_t context
Definition: video.c:25
EGLDisplay
void * EGLDisplay
Definition: egl.h:55
EGL_BLUE_SIZE
#define EGL_BLUE_SIZE
Definition: egl.h:75
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
EGLConfig
void * EGLConfig
Definition: egl.h:58
window
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
EGL_RED_SIZE
#define EGL_RED_SIZE
Definition: egl.h:104
EGL_WIDTH
#define EGL_WIDTH
Definition: egl.h:119
PSP_GL_SwapWindow
int PSP_GL_SwapWindow(_THIS, SDL_Window *window)
config
EGLConfig config
Definition: eglext.h:433
height
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1572
EGL_DEPTH_SIZE
#define EGL_DEPTH_SIZE
Definition: egl.h:80
eglDestroyContext
EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
EGL_STENCIL_SIZE
#define EGL_STENCIL_SIZE
Definition: egl.h:108
SDL_VideoDevice::green_size
int green_size
Definition: SDL_sysvideo.h:336
SDL_GLDriverData::swapinterval
uint32_t swapinterval
Definition: SDL_pspgl_c.h:36
eglCreateContext
EGLAPI EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list)
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
EGL_ALPHA_SIZE
#define EGL_ALPHA_SIZE
Definition: egl.h:62
eglCreateWindowSurface
EGLAPI EGLSurface EGLAPIENTRY eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list)
EGLBoolean
unsigned int EGLBoolean
Definition: egl.h:54
EGL_NONE
#define EGL_NONE
Definition: egl.h:95
eglSwapInterval
EGLAPI EGLBoolean EGLAPIENTRY eglSwapInterval(EGLDisplay dpy, EGLint interval)
EGL_HEIGHT
#define EGL_HEIGHT
Definition: egl.h:86
SDL_GLContext
void * SDL_GLContext
An opaque handle to an OpenGL context.
Definition: SDL_video.h:192
SDL_TRUE
@ SDL_TRUE
Definition: SDL_stdinc.h:164
EGLint
khronos_int32_t EGLint
Definition: eglplatform.h:122
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
SDL_WindowData::uses_gles
SDL_bool uses_gles
Definition: SDL_pandora.h:48
SDL_pspvideo.h
PSP_GL_GetSwapInterval
int PSP_GL_GetSwapInterval(_THIS)
eglTerminate
EGLAPI EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy)
SDL_GLDriverData::surface
EGLSurface surface
Definition: SDL_pspgl_c.h:35
PSP_GL_UnloadLibrary
void PSP_GL_UnloadLibrary(_THIS)
SDL_VideoDevice::alpha_size
int alpha_size
Definition: SDL_sysvideo.h:338
SDL_pspgl_c.h
EGLSurface
void * EGLSurface
Definition: egl.h:59
SDL_VideoDevice::stencil_size
int stencil_size
Definition: SDL_sysvideo.h:341
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
SDL_VideoData
Definition: SDL_androidvideo.h:36
eglGetConfigAttrib
EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
SDL_GLDriverData::display
EGLDisplay display
Definition: SDL_pspgl_c.h:33