Last active
May 20, 2022 05:12
-
-
Save kaaass/b732443f4be7e67c40542e470b1dcb08 to your computer and use it in GitHub Desktop.
eglGetProcAddress test of PVR_PSP2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <SDL2/SDL.h> | |
#if defined(__VITA__) | |
#include <psp2/kernel/modulemgr.h> | |
extern "C" { | |
#include <gpu_es4/psp2_pvr_hint.h> | |
#include <EGL/eglplatform.h> | |
#include <EGL/egl.h> | |
#include <GLES2/gl2.h> | |
} | |
#endif | |
#define log(...) printf(__VA_ARGS__); fflush(stdout) | |
#define debug printf("%s:%d\n", __FUNCTION__, __LINE__); fflush(stdout); | |
//SCE | |
int _newlib_heap_size_user = 16 * 1024 * 1024; | |
unsigned int sceLibcHeapSize = 16 * 1024 * 1024; | |
void init_pvr_psp2() { | |
sceKernelLoadStartModule("vs0:sys/external/libfios2.suprx", 0, NULL, 0, NULL, NULL); | |
sceKernelLoadStartModule("vs0:sys/external/libc.suprx", 0, NULL, 0, NULL, NULL); | |
sceKernelLoadStartModule("app0:module/libgpu_es4_ext.suprx", 0, NULL, 0, NULL, NULL); | |
sceKernelLoadStartModule("app0:module/libIMGEGL.suprx", 0, NULL, 0, NULL, NULL); | |
// uncomment the following line fixs the problem magically | |
// sceKernelLoadStartModule("app0:module/libGLESv1_CM.suprx", 0, NULL, 0, NULL, NULL); | |
// hint PVR_PSP2 | |
PVRSRV_PSP2_APPHINT hint; | |
PVRSRVInitializeAppHint(&hint); | |
PVRSRVCreateVirtualAppHint(&hint); | |
} | |
int init_egl() { | |
static EGLDisplay egl_display; | |
static EGLSurface egl_surface; | |
static EGLContext egl_context; | |
EGLConfig config; | |
EGLBoolean eRetStatus; | |
EGLint major, minor; | |
EGLint config_count; | |
EGLint cfg_attribs[] = { | |
EGL_BUFFER_SIZE, EGL_DONT_CARE, | |
EGL_DEPTH_SIZE, 16, | |
EGL_RED_SIZE, 8, | |
EGL_GREEN_SIZE, 8, | |
EGL_BLUE_SIZE, 8, | |
EGL_ALPHA_SIZE, 8, | |
EGL_STENCIL_SIZE, 8, | |
EGL_SURFACE_TYPE, 5, | |
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, | |
EGL_NONE | |
}; | |
EGLint ctx_attribs[] = { | |
EGL_CONTEXT_CLIENT_VERSION, 2, | |
EGL_NONE | |
}; | |
egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); | |
if (egl_display == EGL_NO_DISPLAY) { | |
log("Error: eglGetDisplay\n"); | |
exit(0); | |
} | |
eRetStatus = eglInitialize(egl_display, &major, &minor); | |
if (eRetStatus != EGL_TRUE) { | |
log("Error: eglInitialize\n"); | |
exit(0); | |
} | |
eRetStatus = eglBindAPI(EGL_OPENGL_ES_API); | |
if (eRetStatus != EGL_TRUE) { | |
log("Error: eglBindAPI\n"); | |
exit(0); | |
} | |
eRetStatus = eglChooseConfig(egl_display, cfg_attribs, &config, 1, &config_count); | |
if (eRetStatus != EGL_TRUE) { | |
log("Error: eglChooseConfig\n"); | |
exit(0); | |
} | |
Psp2NativeWindow win; | |
win.type = PSP2_DRAWABLE_TYPE_WINDOW; | |
win.windowSize = PSP2_WINDOW_960X544; | |
win.numFlipBuffers = 2; | |
win.flipChainThrdAffinity = 0; | |
egl_surface = eglCreateWindowSurface(egl_display, config, &win, NULL); | |
if (egl_surface == EGL_NO_SURFACE) { | |
log("Error: eglCreateWindowSurface\n"); | |
exit(0); | |
} | |
egl_context = eglCreateContext(egl_display, config, EGL_NO_CONTEXT, ctx_attribs); | |
if (egl_context == EGL_NO_CONTEXT) { | |
log("Error: eglCreateContext\n"); | |
exit(0); | |
} | |
eRetStatus = eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context); | |
if (eRetStatus != EGL_TRUE) { | |
log("Error: eglMakeCurrent\n"); | |
exit(0); | |
} | |
const GLubyte *renderer = glGetString(GL_RENDERER); | |
const GLubyte *vendor = glGetString(GL_VENDOR); | |
const GLubyte *version = glGetString(GL_VERSION); | |
const GLubyte *glslVersion = glGetString(GL_SHADING_LANGUAGE_VERSION); | |
log("EGL Version : %d.%d\n", major, minor); | |
log("GL Vendor : %s\n", vendor); | |
log("GL Renderer : %s\n", renderer); | |
log("GL Version (string) : %s\n", version); | |
log("GLSL Version : %s\n", glslVersion); | |
return 0; | |
} | |
int main(int argc, char **argv) { | |
init_pvr_psp2(); | |
init_egl(); | |
auto addr = reinterpret_cast<uint32_t>(eglGetProcAddress("glGetError")); | |
log("glGetError addr = %x, error = %x\n", addr, eglGetError()); | |
log("glGetError = %d\n", glGetError()); | |
addr = reinterpret_cast<uint32_t>(eglGetProcAddress("glGetError")); | |
log("glGetError addr = %x, error = %x\n", addr, eglGetError()); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment