mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
OpenXR - Dummy rendering working
This commit is contained in:
parent
d109e7c1d7
commit
08e01c9a2a
5 changed files with 12 additions and 184 deletions
|
@ -9,7 +9,6 @@ static engine_t vr_engine;
|
|||
int vr_initialized = 0;
|
||||
|
||||
const char* const requiredExtensionNames[] = {
|
||||
XR_KHR_ANDROID_CREATE_INSTANCE_EXTENSION_NAME,
|
||||
XR_KHR_OPENGL_ES_ENABLE_EXTENSION_NAME,
|
||||
XR_KHR_COMPOSITION_LAYER_CYLINDER_EXTENSION_NAME};
|
||||
const uint32_t numRequiredExtensions =
|
||||
|
@ -22,13 +21,6 @@ void VR_Init( ovrJava java )
|
|||
|
||||
ovrApp_Clear(&vr_engine.appState);
|
||||
|
||||
// Create the EGL Context
|
||||
ovrEgl_CreateContext(&vr_engine.appState.Egl, NULL);
|
||||
|
||||
XrInstanceCreateInfoAndroidKHR instanceCreateInfoAndroid = {XR_TYPE_INSTANCE_CREATE_INFO_ANDROID_KHR};
|
||||
instanceCreateInfoAndroid.applicationVM = java.Vm;
|
||||
instanceCreateInfoAndroid.applicationActivity = java.ActivityObject;
|
||||
|
||||
PFN_xrInitializeLoaderKHR xrInitializeLoaderKHR;
|
||||
xrGetInstanceProcAddr(
|
||||
XR_NULL_HANDLE, "xrInitializeLoaderKHR", (PFN_xrVoidFunction*)&xrInitializeLoaderKHR);
|
||||
|
@ -54,7 +46,7 @@ void VR_Init( ovrJava java )
|
|||
XrInstanceCreateInfo instanceCreateInfo;
|
||||
memset(&instanceCreateInfo, 0, sizeof(instanceCreateInfo));
|
||||
instanceCreateInfo.type = XR_TYPE_INSTANCE_CREATE_INFO;
|
||||
instanceCreateInfo.next = (XrBaseInStructure*)&instanceCreateInfoAndroid;
|
||||
instanceCreateInfo.next = NULL;
|
||||
instanceCreateInfo.createFlags = 0;
|
||||
instanceCreateInfo.applicationInfo = appInfo;
|
||||
instanceCreateInfo.enabledApiLayerCount = 0;
|
||||
|
@ -115,7 +107,6 @@ void VR_Destroy( engine_t* engine )
|
|||
{
|
||||
if (engine == &vr_engine) {
|
||||
xrDestroyInstance(engine->appState.Instance);
|
||||
ovrEgl_DestroyContext(&engine->appState.Egl);
|
||||
ovrApp_Destroy(&engine->appState);
|
||||
}
|
||||
}
|
||||
|
@ -131,9 +122,9 @@ void VR_EnterVR( engine_t* engine ) {
|
|||
XrGraphicsBindingOpenGLESAndroidKHR graphicsBindingAndroidGLES = {};
|
||||
graphicsBindingAndroidGLES.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_ES_ANDROID_KHR;
|
||||
graphicsBindingAndroidGLES.next = NULL;
|
||||
graphicsBindingAndroidGLES.display = engine->appState.Egl.Display;
|
||||
graphicsBindingAndroidGLES.config = engine->appState.Egl.Config;
|
||||
graphicsBindingAndroidGLES.context = engine->appState.Egl.Context;
|
||||
graphicsBindingAndroidGLES.display = eglGetCurrentDisplay();
|
||||
graphicsBindingAndroidGLES.config = eglGetCurrentSurface(EGL_DRAW);
|
||||
graphicsBindingAndroidGLES.context = eglGetCurrentContext();
|
||||
|
||||
XrSessionCreateInfo sessionCreateInfo = {};
|
||||
memset(&sessionCreateInfo, 0, sizeof(sessionCreateInfo));
|
||||
|
|
|
@ -23,152 +23,6 @@ Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rig
|
|||
/*
|
||||
================================================================================
|
||||
|
||||
ovrEgl
|
||||
|
||||
================================================================================
|
||||
*/
|
||||
|
||||
void ovrEgl_Clear(ovrEgl* egl) {
|
||||
egl->MajorVersion = 0;
|
||||
egl->MinorVersion = 0;
|
||||
egl->Display = 0;
|
||||
egl->Config = 0;
|
||||
egl->TinySurface = EGL_NO_SURFACE;
|
||||
egl->MainSurface = EGL_NO_SURFACE;
|
||||
egl->Context = EGL_NO_CONTEXT;
|
||||
}
|
||||
|
||||
void ovrEgl_CreateContext(ovrEgl* egl, const ovrEgl* shareEgl) {
|
||||
if (egl->Display != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
egl->Display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||
ALOGV(" eglInitialize( Display, &MajorVersion, &MinorVersion )");
|
||||
eglInitialize(egl->Display, &egl->MajorVersion, &egl->MinorVersion);
|
||||
// Do NOT use eglChooseConfig, because the Android EGL code pushes in multisample
|
||||
// flags in eglChooseConfig if the user has selected the "force 4x MSAA" option in
|
||||
// settings, and that is completely wasted for our warp target.
|
||||
const int MAX_CONFIGS = 1024;
|
||||
EGLConfig configs[MAX_CONFIGS];
|
||||
EGLint numConfigs = 0;
|
||||
if (eglGetConfigs(egl->Display, configs, MAX_CONFIGS, &numConfigs) == EGL_FALSE) {
|
||||
ALOGE(" eglGetConfigs() failed: %d", eglGetError());
|
||||
return;
|
||||
}
|
||||
const EGLint configAttribs[] = {
|
||||
EGL_RED_SIZE,
|
||||
8,
|
||||
EGL_GREEN_SIZE,
|
||||
8,
|
||||
EGL_BLUE_SIZE,
|
||||
8,
|
||||
EGL_ALPHA_SIZE,
|
||||
8, // need alpha for the multi-pass timewarp compositor
|
||||
EGL_DEPTH_SIZE,
|
||||
0,
|
||||
EGL_STENCIL_SIZE,
|
||||
0,
|
||||
EGL_SAMPLES,
|
||||
0,
|
||||
EGL_NONE};
|
||||
egl->Config = 0;
|
||||
for (int i = 0; i < numConfigs; i++) {
|
||||
EGLint value = 0;
|
||||
|
||||
eglGetConfigAttrib(egl->Display, configs[i], EGL_RENDERABLE_TYPE, &value);
|
||||
if ((value & EGL_OPENGL_ES3_BIT_KHR) != EGL_OPENGL_ES3_BIT_KHR) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// The pbuffer config also needs to be compatible with normal window rendering
|
||||
// so it can share textures with the window context.
|
||||
eglGetConfigAttrib(egl->Display, configs[i], EGL_SURFACE_TYPE, &value);
|
||||
if ((value & (EGL_WINDOW_BIT | EGL_PBUFFER_BIT)) != (EGL_WINDOW_BIT | EGL_PBUFFER_BIT)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int j = 0;
|
||||
for (; configAttribs[j] != EGL_NONE; j += 2) {
|
||||
eglGetConfigAttrib(egl->Display, configs[i], configAttribs[j], &value);
|
||||
if (value != configAttribs[j + 1]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (configAttribs[j] == EGL_NONE) {
|
||||
egl->Config = configs[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (egl->Config == 0) {
|
||||
ALOGE(" eglChooseConfig() failed: %d", eglGetError());
|
||||
return;
|
||||
}
|
||||
EGLint contextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE};
|
||||
ALOGV(" Context = eglCreateContext( Display, Config, EGL_NO_CONTEXT, contextAttribs )");
|
||||
egl->Context = eglCreateContext(
|
||||
egl->Display,
|
||||
egl->Config,
|
||||
(shareEgl != NULL) ? shareEgl->Context : EGL_NO_CONTEXT,
|
||||
contextAttribs);
|
||||
if (egl->Context == EGL_NO_CONTEXT) {
|
||||
ALOGE(" eglCreateContext() failed: %d", eglGetError());
|
||||
return;
|
||||
}
|
||||
const EGLint surfaceAttribs[] = {EGL_WIDTH, 16, EGL_HEIGHT, 16, EGL_NONE};
|
||||
ALOGV(" TinySurface = eglCreatePbufferSurface( Display, Config, surfaceAttribs )");
|
||||
egl->TinySurface = eglCreatePbufferSurface(egl->Display, egl->Config, surfaceAttribs);
|
||||
if (egl->TinySurface == EGL_NO_SURFACE) {
|
||||
ALOGE(" eglCreatePbufferSurface() failed: %d", eglGetError());
|
||||
eglDestroyContext(egl->Display, egl->Context);
|
||||
egl->Context = EGL_NO_CONTEXT;
|
||||
return;
|
||||
}
|
||||
ALOGV(" eglMakeCurrent( Display, TinySurface, TinySurface, Context )");
|
||||
if (eglMakeCurrent(egl->Display, egl->TinySurface, egl->TinySurface, egl->Context) ==
|
||||
EGL_FALSE) {
|
||||
ALOGE(" eglMakeCurrent() failed: %d", eglGetError());
|
||||
eglDestroySurface(egl->Display, egl->TinySurface);
|
||||
eglDestroyContext(egl->Display, egl->Context);
|
||||
egl->Context = EGL_NO_CONTEXT;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void ovrEgl_DestroyContext(ovrEgl* egl) {
|
||||
if (egl->Display != 0) {
|
||||
ALOGE(" eglMakeCurrent( Display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT )");
|
||||
if (eglMakeCurrent(egl->Display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) ==
|
||||
EGL_FALSE) {
|
||||
ALOGE(" eglMakeCurrent() failed: %d", eglGetError());
|
||||
}
|
||||
}
|
||||
if (egl->Context != EGL_NO_CONTEXT) {
|
||||
ALOGE(" eglDestroyContext( Display, Context )");
|
||||
if (eglDestroyContext(egl->Display, egl->Context) == EGL_FALSE) {
|
||||
ALOGE(" eglDestroyContext() failed: %d", eglGetError());
|
||||
}
|
||||
egl->Context = EGL_NO_CONTEXT;
|
||||
}
|
||||
if (egl->TinySurface != EGL_NO_SURFACE) {
|
||||
ALOGE(" eglDestroySurface( Display, TinySurface )");
|
||||
if (eglDestroySurface(egl->Display, egl->TinySurface) == EGL_FALSE) {
|
||||
ALOGE(" eglDestroySurface() failed: %d", eglGetError());
|
||||
}
|
||||
egl->TinySurface = EGL_NO_SURFACE;
|
||||
}
|
||||
if (egl->Display != 0) {
|
||||
ALOGE(" eglTerminate( Display )");
|
||||
if (eglTerminate(egl->Display) == EGL_FALSE) {
|
||||
ALOGE(" eglTerminate() failed: %d", eglGetError());
|
||||
}
|
||||
egl->Display = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================================================================================
|
||||
|
||||
ovrFramebuffer
|
||||
|
||||
================================================================================
|
||||
|
@ -392,7 +246,6 @@ void ovrApp_Clear(ovrApp* app) {
|
|||
app->RenderThreadTid = 0;
|
||||
app->TouchPadDownLastFrame = false;
|
||||
|
||||
ovrEgl_Clear(&app->Egl);
|
||||
ovrRenderer_Clear(&app->Renderer);
|
||||
}
|
||||
|
||||
|
|
|
@ -39,16 +39,6 @@ typedef struct {
|
|||
uint32_t Height;
|
||||
} ovrSwapChain;
|
||||
|
||||
typedef struct {
|
||||
EGLint MajorVersion;
|
||||
EGLint MinorVersion;
|
||||
EGLDisplay Display;
|
||||
EGLConfig Config;
|
||||
EGLSurface TinySurface;
|
||||
EGLSurface MainSurface;
|
||||
EGLContext Context;
|
||||
} ovrEgl;
|
||||
|
||||
typedef struct {
|
||||
int Width;
|
||||
int Height;
|
||||
|
@ -70,7 +60,6 @@ typedef struct {
|
|||
} ovrTrackedController;
|
||||
|
||||
typedef struct {
|
||||
ovrEgl Egl;
|
||||
int Focused;
|
||||
|
||||
XrInstance Instance;
|
||||
|
@ -138,9 +127,6 @@ void ovrApp_Clear(ovrApp* app);
|
|||
void ovrApp_Destroy(ovrApp* app);
|
||||
int ovrApp_HandleXrEvents(ovrApp* app);
|
||||
|
||||
void ovrEgl_CreateContext(ovrEgl* egl, const ovrEgl* shareEgl);
|
||||
void ovrEgl_DestroyContext(ovrEgl* egl);
|
||||
|
||||
void ovrFramebuffer_Acquire(ovrFramebuffer* frameBuffer);
|
||||
void ovrFramebuffer_Resolve(ovrFramebuffer* frameBuffer);
|
||||
void ovrFramebuffer_Release(ovrFramebuffer* frameBuffer);
|
||||
|
|
|
@ -168,11 +168,6 @@ void VR_Recenter(engine_t* engine) {
|
|||
}
|
||||
|
||||
void VR_InitRenderer( engine_t* engine ) {
|
||||
#if ENABLE_GL_DEBUG
|
||||
glEnable(GL_DEBUG_OUTPUT);
|
||||
glDebugMessageCallback(VR_GLDebugLog, 0);
|
||||
#endif
|
||||
|
||||
int eyeW, eyeH;
|
||||
VR_GetResolution(engine, &eyeW, &eyeH);
|
||||
|
||||
|
@ -349,7 +344,7 @@ void VR_DrawFrame( engine_t* engine ) {
|
|||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
|
||||
ovrFramebuffer* frameBuffer = &engine->appState.Renderer.FrameBuffer[eye];
|
||||
ovrFramebuffer_Resolve(frameBuffer);
|
||||
//TODO:ovrFramebuffer_Resolve(frameBuffer);
|
||||
ovrFramebuffer_Release(frameBuffer);
|
||||
}
|
||||
ovrFramebuffer_SetNone();
|
||||
|
|
|
@ -938,14 +938,14 @@ extern "C" bool Java_org_ppsspp_ppsspp_NativeRenderer_displayInit(JNIEnv * env,
|
|||
}, nullptr);
|
||||
|
||||
graphicsContext->ThreadStart();
|
||||
#ifdef OPENXR
|
||||
VR_EnterVR(VR_GetEngine());
|
||||
VR_InitRenderer(VR_GetEngine());
|
||||
#endif
|
||||
renderer_inited = true;
|
||||
}
|
||||
NativeMessageReceived("recreateviews", "");
|
||||
|
||||
#ifdef OPENXR
|
||||
VR_EnterVR(VR_GetEngine());
|
||||
VR_InitRenderer(VR_GetEngine());
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1063,6 +1063,9 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeRenderer_displayRender(JNIEnv *env,
|
|||
} else {
|
||||
UpdateRunLoopAndroid(env);
|
||||
}
|
||||
#ifdef OPENXR
|
||||
VR_DrawFrame(VR_GetEngine());
|
||||
#endif
|
||||
}
|
||||
|
||||
void System_AskForPermission(SystemPermission permission) {
|
||||
|
|
Loading…
Add table
Reference in a new issue