Skip to content

Commit

Permalink
Desktop OpenGL 1.X/2.X PSVita Support
Browse files Browse the repository at this point in the history
  • Loading branch information
SonicMastr authored and icculus committed Mar 31, 2022
1 parent 2c04df8 commit 8c542a3
Show file tree
Hide file tree
Showing 12 changed files with 290 additions and 71 deletions.
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2321,6 +2321,7 @@ elseif(VITA)
check_include_file(gpu_es4/psp2_pvr_hint.h HAVE_PVR_H)
if(HAVE_PVR_H)
target_compile_definitions(sdl-build-options INTERFACE "-D__psp2__")
check_include_file(gl4esinit.h HAVE_GL4ES_H)
set(SDL_VIDEO_OPENGL_EGL 1)
set(HAVE_OPENGLES TRUE)
set(SDL_VIDEO_OPENGL_ES 1)
Expand All @@ -2332,8 +2333,18 @@ elseif(VITA)
libgpu_es4_ext_stub_weak
libIMGEGL_stub_weak
)

set(HAVE_VITA_PVR ON)
set(SDL_VIDEO_VITA_PVR 1)

if(HAVE_GL4ES_H)
set(HAVE_OPENGL TRUE)
set(SDL_VIDEO_OPENGL 1)
set(SDL_VIDEO_RENDER_OGL 1)
list(APPEND EXTRA_LIBS libGL_stub)
set(SDL_VIDEO_VITA_PVR_OGL 1)
endif()

else()
set(HAVE_VITA_PVR OFF)
endif()
Expand Down
1 change: 1 addition & 0 deletions include/SDL_config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@

#cmakedefine SDL_VIDEO_VITA_PIB @SDL_VIDEO_VITA_PIB@
#cmakedefine SDL_VIDEO_VITA_PVR @SDL_VIDEO_VITA_PVR@
#cmakedefine SDL_VIDEO_VITA_PVR_OGL @SDL_VIDEO_VITA_PVR_OGL@

#if !defined(__WIN32__) && !defined(__WINRT__)
# if !defined(_STDINT_H_) && !defined(_STDINT_H) && !defined(HAVE_STDINT_H) && !defined(_HAVE_STDINT_H)
Expand Down
7 changes: 7 additions & 0 deletions src/render/opengl/SDL_render_gl.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
#include <OpenGL/OpenGL.h>
#endif

#ifdef __psp2__
#include <GL/gl.h>
#include <GL/glext.h>
#endif

/* To prevent unnecessary window recreation,
* these should match the defaults selected in SDL_GL_ResetAttributes
*/
Expand Down Expand Up @@ -1733,6 +1738,7 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major);
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor);

#ifndef __psp2__
window_flags = SDL_GetWindowFlags(window);
if (!(window_flags & SDL_WINDOW_OPENGL) ||
profile_mask == SDL_GL_CONTEXT_PROFILE_ES || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) {
Expand All @@ -1746,6 +1752,7 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
goto error;
}
}
#endif

renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
if (!renderer) {
Expand Down
4 changes: 2 additions & 2 deletions src/video/SDL_egl.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
#define DEFAULT_OGL_ES "libGLESv1_CM.so.1"
#endif /* SDL_VIDEO_DRIVER_RPI */

#if SDL_VIDEO_OPENGL
#if SDL_VIDEO_OPENGL && !SDL_VIDEO_VITA_PVR_OGL
#include "SDL_opengl.h"
#endif

Expand Down Expand Up @@ -1062,7 +1062,7 @@ SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface)
if (SDL_GL_ExtensionSupported("GL_OES_surfaceless_context")) {
_this->gl_allow_no_surface = SDL_TRUE;
}
#if SDL_VIDEO_OPENGL
#if SDL_VIDEO_OPENGL && !defined(SDL_VIDEO_DRIVER_VITA)
} else {
/* Desktop OpenGL supports it by default from version 3.0 on. */
void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params);
Expand Down
65 changes: 47 additions & 18 deletions src/video/vita/SDL_vitagl_pvr.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
*/
#include "../../SDL_internal.h"

#if SDL_VIDEO_DRIVER_VITA && SDL_VIDEO_VITA_PVR
#if SDL_VIDEO_DRIVER_VITA && SDL_VIDEO_VITA_PVR && SDL_VIDEO_VITA_PVR_OGL
#include <stdlib.h>
#include <string.h>
#include <psp2/kernel/modulemgr.h>
#include <gpu_es4/psp2_pvr_hint.h>
#include <gl4esinit.h>

#include "SDL_error.h"
#include "SDL_log.h"
Expand All @@ -34,6 +35,16 @@

#define MAX_PATH 256 // vita limits are somehow wrong

/* Defaults */
int FB_WIDTH = 960;
int FB_HEIGHT = 544;

void getFBSize(int *width, int *height)
{
*width = FB_WIDTH;
*height = FB_HEIGHT;
}

int
VITA_GL_LoadLibrary(_THIS, const char *path)
{
Expand All @@ -53,6 +64,9 @@ VITA_GL_LoadLibrary(_THIS, const char *path)
sceKernelLoadStartModule("vs0:sys/external/libfios2.suprx", 0, NULL, 0, NULL, NULL);
sceKernelLoadStartModule("vs0:sys/external/libc.suprx", 0, NULL, 0, NULL, NULL);

SDL_snprintf(target_path, MAX_PATH, "%s/%s", default_path, "libGL.suprx");
sceKernelLoadStartModule(target_path, 0, NULL, 0, NULL, NULL);

SDL_snprintf(target_path, MAX_PATH, "%s/%s", default_path, "libgpu_es4_ext.suprx");
sceKernelLoadStartModule(target_path, 0, NULL, 0, NULL, NULL);

Expand All @@ -74,30 +88,45 @@ VITA_GL_LoadLibrary(_THIS, const char *path)
SDL_GLContext
VITA_GL_CreateContext(_THIS, SDL_Window * window)
{
return SDL_EGL_CreateContext(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
}
char gl_version[3];
SDL_GLContext context = NULL;
int temp_major = _this->gl_config.major_version;
int temp_minor = _this->gl_config.minor_version;
int temp_profile = _this->gl_config.profile_mask;

int
VITA_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
{
if (window && context) {
return SDL_EGL_MakeCurrent(_this, ((SDL_WindowData *) window->driverdata)->egl_surface, context);
} else {
return SDL_EGL_MakeCurrent(_this, NULL, NULL);
/* Set version to 2.1 and PROFILE to ES */
_this->gl_config.major_version = 2;
_this->gl_config.minor_version = 1;
_this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES;

context = SDL_EGL_CreateContext(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);

if (context != NULL)
{
FB_WIDTH = window->w;
FB_HEIGHT = window->h;
set_getprocaddress((void *(*)(const char *))eglGetProcAddress);
set_getmainfbsize(getFBSize);
SDL_snprintf(gl_version, 3, "%d%d", temp_major, temp_minor);
gl4es_setenv("LIBGL_NOTEXRECT", "1", 1); /* Currently broken in driver */
gl4es_setenv("LIBGL_GL", gl_version, 1);
initialize_gl4es();
}

/* Restore gl_config */
_this->gl_config.major_version = temp_major;
_this->gl_config.minor_version = temp_minor;
_this->gl_config.profile_mask = temp_profile;

return context;
}

int
VITA_GL_SwapWindow(_THIS, SDL_Window * window)
void *
VITA_GL_GetProcAddress(_THIS, const char *proc)
{
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
if (videodata->ime_active) {
sceImeUpdate();
}
return SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
return gl4es_GetProcAddress(proc);
}


#endif /* SDL_VIDEO_DRIVER_VITA && SDL_VIDEO_VITA_PVR */

/* vi: set ts=4 sw=4 expandtab: */
9 changes: 4 additions & 5 deletions src/video/vita/SDL_vitagl_pvr_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@
3. This notice may not be removed or altered from any source distribution.
*/

#ifndef SDL_vitagl_c_h_
#define SDL_vitagl_c_h_
#ifndef SDL_vitagl_pvr_c_h_
#define SDL_vitagl_pvr_c_h_

#include "SDL_vitavideo.h"

extern int VITA_GL_MakeCurrent(_THIS,SDL_Window * window, SDL_GLContext context);
extern int VITA_GL_SwapWindow(_THIS, SDL_Window * window);
extern SDL_GLContext VITA_GL_CreateContext(_THIS, SDL_Window * window);
extern int VITA_GL_LoadLibrary(_THIS, const char *path);
extern void *VITA_GL_GetProcAddress(_THIS, const char *proc);


#endif /* SDL_vitagl_c_h_ */
#endif /* SDL_vitagl_pvr_c_h_ */

/* vi: set ts=4 sw=4 expandtab: */
24 changes: 12 additions & 12 deletions src/video/vita/SDL_vitagl.c → src/video/vita/SDL_vitagles.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "SDL_error.h"
#include "SDL_log.h"
#include "SDL_vitavideo.h"
#include "SDL_vitagl_c.h"
#include "SDL_vitagles_c.h"

/*****************************************************************************/
/* SDL OpenGL/OpenGL ES functions */
Expand All @@ -45,7 +45,7 @@
} while (0)

void
VITA_GL_KeyboardCallback(ScePigletPreSwapData *data)
VITA_GLES_KeyboardCallback(ScePigletPreSwapData *data)
{
SceCommonDialogUpdateParam commonDialogParam;
SDL_zero(commonDialogParam);
Expand All @@ -62,20 +62,20 @@ VITA_GL_KeyboardCallback(ScePigletPreSwapData *data)
}

int
VITA_GL_LoadLibrary(_THIS, const char *path)
VITA_GLES_LoadLibrary(_THIS, const char *path)
{
pibInit(PIB_SHACCCG | PIB_GET_PROC_ADDR_CORE);
return 0;
}

void *
VITA_GL_GetProcAddress(_THIS, const char *proc)
VITA_GLES_GetProcAddress(_THIS, const char *proc)
{
return eglGetProcAddress(proc);
}

void
VITA_GL_UnloadLibrary(_THIS)
VITA_GLES_UnloadLibrary(_THIS)
{
eglTerminate(_this->gl_data->display);
}
Expand All @@ -84,7 +84,7 @@ static EGLint width = 960;
static EGLint height = 544;

SDL_GLContext
VITA_GL_CreateContext(_THIS, SDL_Window * window)
VITA_GLES_CreateContext(_THIS, SDL_Window * window)
{

SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
Expand Down Expand Up @@ -159,13 +159,13 @@ VITA_GL_CreateContext(_THIS, SDL_Window * window)
_this->gl_data->surface = surface;

preSwapCallback = (PFNEGLPIGLETVITASETPRESWAPCALLBACKSCEPROC) eglGetProcAddress("eglPigletVitaSetPreSwapCallbackSCE");
preSwapCallback(VITA_GL_KeyboardCallback);
preSwapCallback(VITA_GLES_KeyboardCallback);

return context;
}

int
VITA_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
VITA_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
{
if (!eglMakeCurrent(_this->gl_data->display, _this->gl_data->surface,
_this->gl_data->surface, _this->gl_data->context))
Expand All @@ -176,7 +176,7 @@ VITA_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
}

int
VITA_GL_SetSwapInterval(_THIS, int interval)
VITA_GLES_SetSwapInterval(_THIS, int interval)
{
EGLBoolean status;
status = eglSwapInterval(_this->gl_data->display, interval);
Expand All @@ -190,13 +190,13 @@ VITA_GL_SetSwapInterval(_THIS, int interval)
}

int
VITA_GL_GetSwapInterval(_THIS)
VITA_GLES_GetSwapInterval(_THIS)
{
return _this->gl_data->swapinterval;
}

int
VITA_GL_SwapWindow(_THIS, SDL_Window * window)
VITA_GLES_SwapWindow(_THIS, SDL_Window * window)
{
if (!eglSwapBuffers(_this->gl_data->display, _this->gl_data->surface)) {
return SDL_SetError("eglSwapBuffers() failed");
Expand All @@ -205,7 +205,7 @@ VITA_GL_SwapWindow(_THIS, SDL_Window * window)
}

void
VITA_GL_DeleteContext(_THIS, SDL_GLContext context)
VITA_GLES_DeleteContext(_THIS, SDL_GLContext context)
{
SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
EGLBoolean status;
Expand Down
24 changes: 12 additions & 12 deletions src/video/vita/SDL_vitagl_c.h → src/video/vita/SDL_vitagles_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
3. This notice may not be removed or altered from any source distribution.
*/

#ifndef SDL_vitagl_c_h_
#define SDL_vitagl_c_h_
#ifndef SDL_vitagles_c_h_
#define SDL_vitagles_c_h_


#include <pib.h>
Expand All @@ -39,19 +39,19 @@ typedef struct SDL_GLDriverData {
uint32_t swapinterval;
}SDL_GLDriverData;

extern void * VITA_GL_GetProcAddress(_THIS, const char *proc);
extern int VITA_GL_MakeCurrent(_THIS,SDL_Window * window, SDL_GLContext context);
extern void VITA_GL_SwapBuffers(_THIS);
extern void * VITA_GLES_GetProcAddress(_THIS, const char *proc);
extern int VITA_GLES_MakeCurrent(_THIS,SDL_Window * window, SDL_GLContext context);
extern void VITA_GLES_SwapBuffers(_THIS);

extern int VITA_GL_SwapWindow(_THIS, SDL_Window * window);
extern SDL_GLContext VITA_GL_CreateContext(_THIS, SDL_Window * window);
extern int VITA_GLES_SwapWindow(_THIS, SDL_Window * window);
extern SDL_GLContext VITA_GLES_CreateContext(_THIS, SDL_Window * window);

extern int VITA_GL_LoadLibrary(_THIS, const char *path);
extern void VITA_GL_UnloadLibrary(_THIS);
extern int VITA_GL_SetSwapInterval(_THIS, int interval);
extern int VITA_GL_GetSwapInterval(_THIS);
extern int VITA_GLES_LoadLibrary(_THIS, const char *path);
extern void VITA_GLES_UnloadLibrary(_THIS);
extern int VITA_GLES_SetSwapInterval(_THIS, int interval);
extern int VITA_GLES_GetSwapInterval(_THIS);


#endif /* SDL_vitagl_c_h_ */
#endif /* SDL_vitagles_c_h_ */

/* vi: set ts=4 sw=4 expandtab: */
Loading

0 comments on commit 8c542a3

Please sign in to comment.