Atlas - SDL_vitagles.c
Home / ext / SDL / src / video / vita Lines: 1 | Size: 7008 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#if defined(SDL_VIDEO_DRIVER_VITA) && defined(SDL_VIDEO_VITA_PIB) 24#include <stdlib.h> 25#include <string.h> 26 27#include "SDL_vitavideo.h" 28 29/*****************************************************************************/ 30// SDL OpenGL/OpenGL ES functions 31/*****************************************************************************/ 32#define EGLCHK(stmt) \ 33 do { \ 34 EGLint err; \ 35 \ 36 stmt; \ 37 err = eglGetError(); \ 38 if (err != EGL_SUCCESS) { \ 39 SDL_SetError("EGL error %d", err); \ 40 return NULL; \ 41 } \ 42 } while (0) 43 44void VITA_GLES_KeyboardCallback(ScePigletPreSwapData *data) 45{ 46 SceCommonDialogUpdateParam commonDialogParam; 47 SDL_zero(commonDialogParam); 48 commonDialogParam.renderTarget.colorFormat = data->colorFormat; 49 commonDialogParam.renderTarget.surfaceType = data->surfaceType; 50 commonDialogParam.renderTarget.colorSurfaceData = data->colorSurfaceData; 51 commonDialogParam.renderTarget.depthSurfaceData = data->depthSurfaceData; 52 commonDialogParam.renderTarget.width = data->width; 53 commonDialogParam.renderTarget.height = data->height; 54 commonDialogParam.renderTarget.strideInPixels = data->strideInPixels; 55 commonDialogParam.displaySyncObject = data->displaySyncObject; 56 57 sceCommonDialogUpdate(&commonDialogParam); 58} 59 60bool VITA_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) 61{ 62 pibInit(PIB_SHACCCG | PIB_GET_PROC_ADDR_CORE); 63 return true; 64} 65 66SDL_FunctionPointer VITA_GLES_GetProcAddress(SDL_VideoDevice *_this, const char *proc) 67{ 68 return eglGetProcAddress(proc); 69} 70 71void VITA_GLES_UnloadLibrary(SDL_VideoDevice *_this) 72{ 73 eglTerminate(_this->gl_data->display); 74} 75 76static EGLint width = 960; 77static EGLint height = 544; 78 79SDL_GLContext VITA_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) 80{ 81 82 SDL_WindowData *wdata = window->internal; 83 84 EGLint attribs[32]; 85 EGLDisplay display; 86 EGLContext context; 87 EGLSurface surface; 88 EGLConfig config; 89 EGLint num_configs; 90 PFNEGLPIGLETVITASETPRESWAPCALLBACKSCEPROC preSwapCallback; 91 int i; 92 93 const EGLint contextAttribs[] = { 94 EGL_CONTEXT_CLIENT_VERSION, 2, 95 EGL_NONE 96 }; 97 98 EGLCHK(display = eglGetDisplay(0)); 99 100 EGLCHK(eglInitialize(display, NULL, NULL)); 101 wdata->uses_gles = true; 102 window->flags |= SDL_WINDOW_FULLSCREEN; 103 104 EGLCHK(eglBindAPI(EGL_OPENGL_ES_API)); 105 106 i = 0; 107 attribs[i++] = EGL_RED_SIZE; 108 attribs[i++] = 8; 109 attribs[i++] = EGL_GREEN_SIZE; 110 attribs[i++] = 8; 111 attribs[i++] = EGL_BLUE_SIZE; 112 attribs[i++] = 8; 113 attribs[i++] = EGL_DEPTH_SIZE; 114 attribs[i++] = 0; 115 attribs[i++] = EGL_ALPHA_SIZE; 116 attribs[i++] = 8; 117 attribs[i++] = EGL_STENCIL_SIZE; 118 attribs[i++] = 0; 119 120 attribs[i++] = EGL_SURFACE_TYPE; 121 attribs[i++] = 5; 122 123 attribs[i++] = EGL_RENDERABLE_TYPE; 124 attribs[i++] = EGL_OPENGL_ES2_BIT; 125 126 attribs[i++] = EGL_CONFORMANT; 127 attribs[i++] = EGL_OPENGL_ES2_BIT; 128 129 attribs[i++] = EGL_NONE; 130 131 EGLCHK(eglChooseConfig(display, attribs, &config, 1, &num_configs)); 132 133 if (num_configs == 0) { 134 SDL_SetError("No valid EGL configs for requested mode"); 135 return NULL; 136 } 137 138 EGLCHK(surface = eglCreateWindowSurface(display, config, VITA_WINDOW_960X544, NULL)); 139 140 EGLCHK(context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs)); 141 142 EGLCHK(eglMakeCurrent(display, surface, surface, context)); 143 144 EGLCHK(eglQuerySurface(display, surface, EGL_WIDTH, &width)); 145 EGLCHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height)); 146 147 _this->gl_data->display = display; 148 _this->gl_data->context = context; 149 _this->gl_data->surface = surface; 150 151 preSwapCallback = (PFNEGLPIGLETVITASETPRESWAPCALLBACKSCEPROC)eglGetProcAddress("eglPigletVitaSetPreSwapCallbackSCE"); 152 preSwapCallback(VITA_GLES_KeyboardCallback); 153 154 return context; 155} 156 157bool VITA_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) 158{ 159 if (!eglMakeCurrent(_this->gl_data->display, _this->gl_data->surface, 160 _this->gl_data->surface, _this->gl_data->context)) { 161 return SDL_SetError("Unable to make EGL context current"); 162 } 163 return true; 164} 165 166bool VITA_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval) 167{ 168 EGLBoolean status; 169 status = eglSwapInterval(_this->gl_data->display, interval); 170 if (status == EGL_TRUE) { 171 // Return success to upper level 172 _this->gl_data->swapinterval = interval; 173 return true; 174 } 175 // Failed to set swap interval 176 return SDL_SetError("Unable to set the EGL swap interval"); 177} 178 179bool VITA_GLES_GetSwapInterval(SDL_VideoDevice *_this, int *interval) 180{ 181 *interval = _this->gl_data->swapinterval; 182 return true; 183} 184 185bool VITA_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) 186{ 187 if (!eglSwapBuffers(_this->gl_data->display, _this->gl_data->surface)) { 188 return SDL_SetError("eglSwapBuffers() failed"); 189 } 190 return true; 191} 192 193bool VITA_GLES_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context) 194{ 195 SDL_VideoData *phdata = _this->internal; 196 EGLBoolean status; 197 198 if (phdata->egl_initialized != true) { 199 return SDL_SetError("VITA: GLES initialization failed, no OpenGL ES support"); 200 } 201 202 // Check if OpenGL ES connection has been initialized 203 if (_this->gl_data->display != EGL_NO_DISPLAY) { 204 if (context != EGL_NO_CONTEXT) { 205 status = eglDestroyContext(_this->gl_data->display, context); 206 if (status != EGL_TRUE) { 207 // Error during OpenGL ES context destroying 208 return SDL_SetError("VITA: OpenGL ES context destroy error"); 209 } 210 } 211 } 212 213 return true; 214} 215 216#endif // SDL_VIDEO_DRIVER_VITA 217[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.