Atlas - SDL_pspgl.c

Home / ext / SDL / src / video / psp Lines: 1 | Size: 6177 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2025 Sam Lantinga <[email protected]> 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#ifdef SDL_VIDEO_DRIVER_PSP 24 25#include <stdlib.h> 26#include <string.h> 27 28#include "SDL_pspvideo.h" 29#include "SDL_pspgl_c.h" 30 31/*****************************************************************************/ 32// SDL OpenGL/OpenGL ES functions 33/*****************************************************************************/ 34#define EGLCHK(stmt) \ 35 do { \ 36 EGLint err; \ 37 \ 38 stmt; \ 39 err = eglGetError(); \ 40 if (err != EGL_SUCCESS) { \ 41 SDL_SetError("EGL error %d", err); \ 42 return NULL; \ 43 } \ 44 } while (0) 45 46bool PSP_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path) 47{ 48 return true; 49} 50 51/* pspgl doesn't provide this call, so stub it out since SDL requires it. 52#define GLSTUB(func,params) void func params {} 53 54GLSTUB(glOrtho,(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, 55 GLdouble zNear, GLdouble zFar)) 56*/ 57SDL_FunctionPointer PSP_GL_GetProcAddress(SDL_VideoDevice *_this, const char *proc) 58{ 59 return eglGetProcAddress(proc); 60} 61 62void PSP_GL_UnloadLibrary(SDL_VideoDevice *_this) 63{ 64 eglTerminate(_this->gl_data->display); 65} 66 67static EGLint width = 480; 68static EGLint height = 272; 69 70SDL_GLContext PSP_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) 71{ 72 73 SDL_WindowData *wdata = window->internal; 74 75 EGLint attribs[32]; 76 EGLDisplay display; 77 EGLContext context; 78 EGLSurface surface; 79 EGLConfig config; 80 EGLint num_configs; 81 int i; 82 83 // EGL init taken from glutCreateWindow() in PSPGL's glut.c. 84 EGLCHK(display = eglGetDisplay(0)); 85 EGLCHK(eglInitialize(display, NULL, NULL)); 86 wdata->uses_gles = true; 87 window->flags |= SDL_WINDOW_FULLSCREEN; 88 89 // Setup the config based on SDL's current values. 90 i = 0; 91 attribs[i++] = EGL_RED_SIZE; 92 attribs[i++] = _this->gl_config.red_size; 93 attribs[i++] = EGL_GREEN_SIZE; 94 attribs[i++] = _this->gl_config.green_size; 95 attribs[i++] = EGL_BLUE_SIZE; 96 attribs[i++] = _this->gl_config.blue_size; 97 attribs[i++] = EGL_DEPTH_SIZE; 98 attribs[i++] = _this->gl_config.depth_size; 99 100 if (_this->gl_config.alpha_size) { 101 attribs[i++] = EGL_ALPHA_SIZE; 102 attribs[i++] = _this->gl_config.alpha_size; 103 } 104 if (_this->gl_config.stencil_size) { 105 attribs[i++] = EGL_STENCIL_SIZE; 106 attribs[i++] = _this->gl_config.stencil_size; 107 } 108 109 attribs[i++] = EGL_NONE; 110 111 EGLCHK(eglChooseConfig(display, attribs, &config, 1, &num_configs)); 112 113 if (num_configs == 0) { 114 SDL_SetError("No valid EGL configs for requested mode"); 115 return NULL; 116 } 117 118 EGLCHK(eglGetConfigAttrib(display, config, EGL_WIDTH, &width)); 119 EGLCHK(eglGetConfigAttrib(display, config, EGL_HEIGHT, &height)); 120 121 EGLCHK(context = eglCreateContext(display, config, NULL, NULL)); 122 EGLCHK(surface = eglCreateWindowSurface(display, config, 0, NULL)); 123 EGLCHK(eglMakeCurrent(display, surface, surface, context)); 124 125 _this->gl_data->display = display; 126 _this->gl_data->context = context; 127 _this->gl_data->surface = surface; 128 129 return context; 130} 131 132bool PSP_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) 133{ 134 if (!eglMakeCurrent(_this->gl_data->display, _this->gl_data->surface, 135 _this->gl_data->surface, _this->gl_data->context)) { 136 return SDL_SetError("Unable to make EGL context current"); 137 } 138 return true; 139} 140 141bool PSP_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval) 142{ 143 EGLBoolean status; 144 status = eglSwapInterval(_this->gl_data->display, interval); 145 if (status == EGL_TRUE) { 146 // Return success to upper level 147 _this->gl_data->swapinterval = interval; 148 return true; 149 } 150 // Failed to set swap interval 151 return SDL_SetError("Unable to set the EGL swap interval"); 152} 153 154bool PSP_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval) 155{ 156 *interval = _this->gl_data->swapinterval; 157 return true; 158} 159 160bool PSP_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) 161{ 162 if (!eglSwapBuffers(_this->gl_data->display, _this->gl_data->surface)) { 163 return SDL_SetError("eglSwapBuffers() failed"); 164 } 165 return true; 166} 167 168bool PSP_GL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context) 169{ 170 SDL_VideoData *phdata = _this->internal; 171 EGLBoolean status; 172 173 if (phdata->egl_initialized != true) { 174 return SDL_SetError("PSP: GLES initialization failed, no OpenGL ES support"); 175 } 176 177 // Check if OpenGL ES connection has been initialized 178 if (_this->gl_data->display != EGL_NO_DISPLAY) { 179 if (context != EGL_NO_CONTEXT) { 180 status = eglDestroyContext(_this->gl_data->display, context); 181 if (status != EGL_TRUE) { 182 // Error during OpenGL ES context destroying 183 return SDL_SetError("PSP: OpenGL ES context destroy error"); 184 } 185 } 186 } 187 return true; 188} 189 190#endif // SDL_VIDEO_DRIVER_PSP 191
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.