Skip to content

Commit

Permalink
Merge pull request #58 from lvonasek/hotfix-openxr-v69
Browse files Browse the repository at this point in the history
OpenXR - Fix for QuestOS V69
  • Loading branch information
longjunyu2 authored Aug 27, 2024
2 parents 5fa0dcb + 805d8b8 commit 315c139
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 36 deletions.
22 changes: 11 additions & 11 deletions app/src/main/cpp/xr/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@
#define ANDROID 1
#endif

#if defined(_DEBUG)
void GLCheckErrors(const char* file, int line);
void OXRCheckErrors(XrResult result, const char* file, int line);

#define GL(func) func; GLCheckErrors(__FILE__ , __LINE__);
#define OXR(func) OXRCheckErrors(func, __FILE__ , __LINE__);
#else
#define GL(func) func;
#define OXR(func) func;
#endif

#ifdef ANDROID
#include <android/log.h>
#define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, "OpenXR", __VA_ARGS__);
Expand All @@ -38,6 +27,17 @@ void OXRCheckErrors(XrResult result, const char* file, int line);
#include <openxr/openxr.h>
#include <openxr/openxr_platform.h>

#if defined(_DEBUG)
void GLCheckErrors(const char* file, int line);
void OXRCheckErrors(XrResult result, const char* file, int line);

#define GL(func) func; GLCheckErrors(__FILE__ , __LINE__);
#define OXR(func) OXRCheckErrors(func, __FILE__ , __LINE__);
#else
#define GL(func) func;
#define OXR(func) func;
#endif

enum
{
XrMaxLayerCount = 2
Expand Down
22 changes: 6 additions & 16 deletions app/src/main/cpp/xr/framebuffer.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "framebuffer.h"

#if XR_USE_GRAPHICS_API_OPENGL_ES
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <GLES3/gl3.h>
#include <GLES3/gl3ext.h>
#endif

#include <stdlib.h>
Expand All @@ -21,9 +21,7 @@ bool XrFramebufferCreate(struct XrFramebuffer *framebuffer, XrSession session, i
void XrFramebufferDestroy(struct XrFramebuffer *framebuffer)
{
#if XR_USE_GRAPHICS_API_OPENGL_ES
GL(glDeleteRenderbuffers(framebuffer->SwapchainLength, framebuffer->GLDepthBuffers));
GL(glDeleteFramebuffers(framebuffer->SwapchainLength, framebuffer->GLFrameBuffers));
free(framebuffer->GLDepthBuffers);
free(framebuffer->GLFrameBuffers);
#endif
OXR(xrDestroySwapchain(framebuffer->Handle));
Expand Down Expand Up @@ -57,7 +55,7 @@ void XrFramebufferAcquire(struct XrFramebuffer *framebuffer)
GL(glViewport(0, 0, framebuffer->Width, framebuffer->Height));
GL(glClearColor(0.0f, 0.0f, 0.0f, 0.0f));
GL(glScissor(0, 0, framebuffer->Width, framebuffer->Height));
GL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
GL(glClear(GL_COLOR_BUFFER_BIT));
GL(glScissor(0, 0, 0, 0));
GL(glDisable(GL_SCISSOR_TEST));
#endif
Expand All @@ -67,6 +65,8 @@ void XrFramebufferRelease(struct XrFramebuffer *framebuffer)
{
if (framebuffer->Acquired)
{
const GLenum depthAttachment[1] = {GL_DEPTH_ATTACHMENT};
glInvalidateFramebuffer(GL_FRAMEBUFFER, 1, depthAttachment);
XrSwapchainImageReleaseInfo release_info = {XR_TYPE_SWAPCHAIN_IMAGE_RELEASE_INFO, NULL};
OXR(xrReleaseSwapchainImage(framebuffer->Handle, &release_info));
framebuffer->Acquired = false;
Expand Down Expand Up @@ -97,7 +97,7 @@ bool XrFramebufferCreateGL(struct XrFramebuffer *framebuffer, XrSession session,
framebuffer->Height = swapchain_info.height;

// Create the color swapchain.
swapchain_info.format = GL_SRGB8_ALPHA8_EXT;
swapchain_info.format = GL_RGBA8;
swapchain_info.usageFlags = XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT;
OXR(xrCreateSwapchain(session, &swapchain_info, &framebuffer->Handle));
OXR(xrEnumerateSwapchainImages(framebuffer->Handle, 0, &framebuffer->SwapchainLength, NULL));
Expand All @@ -114,24 +114,14 @@ bool XrFramebufferCreateGL(struct XrFramebuffer *framebuffer, XrSession session,
&framebuffer->SwapchainLength,
(XrSwapchainImageBaseHeader*)framebuffer->SwapchainImage));

framebuffer->GLDepthBuffers = (GLuint*)malloc(framebuffer->SwapchainLength * sizeof(GLuint));
framebuffer->GLFrameBuffers = (GLuint*)malloc(framebuffer->SwapchainLength * sizeof(GLuint));
for (uint32_t i = 0; i < framebuffer->SwapchainLength; i++)
{
// Create color and depth buffers.
GLuint color_texture = ((XrSwapchainImageOpenGLESKHR*)framebuffer->SwapchainImage)[i].image;
GL(glGenRenderbuffers(1, &framebuffer->GLDepthBuffers[i]));
GL(glBindRenderbuffer(GL_RENDERBUFFER, framebuffer->GLDepthBuffers[i]));
GL(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, width, height));
GL(glBindRenderbuffer(GL_RENDERBUFFER, 0));

// Create the frame buffer.
GL(glGenFramebuffers(1, &framebuffer->GLFrameBuffers[i]));
GL(glBindFramebuffer(GL_FRAMEBUFFER, framebuffer->GLFrameBuffers[i]));
GL(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
framebuffer->GLDepthBuffers[i]));
GL(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,
framebuffer->GLDepthBuffers[i]));
GL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
color_texture, 0));
GL(GLenum renderFramebufferStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER));
Expand Down
1 change: 0 additions & 1 deletion app/src/main/cpp/xr/framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ struct XrFramebuffer {
uint32_t SwapchainLength;
void* SwapchainImage;

unsigned int* GLDepthBuffers;
unsigned int* GLFrameBuffers;
};

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/cpp/xr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void GLCheckErrors(const char* file, int line) {
void OXRCheckErrors(XrResult result, const char* file, int line) {
if (XR_FAILED(result)) {
char errorBuffer[XR_MAX_RESULT_STRING_SIZE];
xrResultToString(xr_module_engine->Instance, result, errorBuffer);
xrResultToString(xr_module_engine.Instance, result, errorBuffer);
ALOGE("OpenXR error on line %s:%d %s", file, line, errorBuffer);
}
}
Expand Down Expand Up @@ -85,12 +85,12 @@ JNIEXPORT jboolean JNICALL Java_com_winlator_XrActivity_beginFrame(JNIEnv *env,
// Set render canvas
int mode = immersive ? RENDER_MODE_MONO_6DOF : RENDER_MODE_MONO_SCREEN;
xr_module_renderer.ConfigFloat[CONFIG_CANVAS_DISTANCE] = 5.0f;
xr_module_renderer.ConfigInt[CONFIG_PASSTHROUGH] = true;
xr_module_renderer.ConfigInt[CONFIG_PASSTHROUGH] = !immersive;
xr_module_renderer.ConfigInt[CONFIG_MODE] = mode;
xr_module_renderer.ConfigInt[CONFIG_SBS] = sbs;

// Recenter if mode switched
static bool last_immersive = false;
static int last_immersive = -1;
if (last_immersive != immersive) {
XrRendererRecenter(&xr_module_engine, &xr_module_renderer);
last_immersive = immersive;
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/cpp/xr/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ void XrRendererRecenter(struct XrEngine* engine, struct XrRenderer* renderer)
// Create a default stage space to use if SPACE_TYPE_STAGE is not
// supported, or calls to xrGetReferenceSpaceBoundsRect fail.
space_info.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_LOCAL;
memset(&space_info.poseInReferenceSpace, 0, sizeof(XrPosef));
space_info.poseInReferenceSpace.orientation.w = 1.0;
if (engine->PlatformFlag[PLATFORM_TRACKING_FLOOR])
{
space_info.poseInReferenceSpace.position.y = -1.6750f;
Expand All @@ -482,7 +484,8 @@ void XrRendererRecenter(struct XrEngine* engine, struct XrRenderer* renderer)
if (renderer->StageSupported)
{
space_info.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_STAGE;
space_info.poseInReferenceSpace.position.y = 0.0;
memset(&space_info.poseInReferenceSpace, 0, sizeof(XrPosef));
space_info.poseInReferenceSpace.orientation.w = 1.0;
OXR(xrCreateReferenceSpace(engine->Session, &space_info, &engine->StageSpace));
ALOGV("Created stage space");
if (engine->PlatformFlag[PLATFORM_TRACKING_FLOOR])
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/winlator/XrActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ public static void updateControllers() {
float meter2px = instance.getXServer().screenInfo.width * 10.0f;
float dx = (axes[mouseAxisX.ordinal()] - lastAxes[mouseAxisX.ordinal()]) * meter2px;
float dy = (axes[mouseAxisY.ordinal()] - lastAxes[mouseAxisY.ordinal()]) * meter2px;
if ((Math.abs(dx) > 300) || (Math.abs(dy) > 300)) {
dx = 0;
dy = 0;
}

// Mouse control with head
Pointer mouse = instance.getXServer().pointer;
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/com/winlator/container/Container.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.os.Environment;

import com.winlator.XrActivity;
import com.winlator.box86_64.Box86_64Preset;
import com.winlator.core.EnvVars;
import com.winlator.core.FileUtils;
Expand All @@ -25,9 +26,9 @@ public enum XrControllerMapping {

public static final String DEFAULT_ENV_VARS = "ZINK_DESCRIPTORS=lazy ZINK_DEBUG=compact MESA_SHADER_CACHE_DISABLE=false MESA_SHADER_CACHE_MAX_SIZE=512MB mesa_glthread=true WINEESYNC=1 MESA_VK_WSI_PRESENT_MODE=mailbox TU_DEBUG=noconform";
public static final String DEFAULT_SCREEN_SIZE = "1280x720";
public static final String DEFAULT_GRAPHICS_DRIVER = "turnip";
public static final String DEFAULT_AUDIO_DRIVER = "alsa";
public static final String DEFAULT_DXWRAPPER = "dxvk";
public static final String DEFAULT_GRAPHICS_DRIVER = XrActivity.isSupported() ? "virgl-23.1.9" : "turnip";
public static final String DEFAULT_AUDIO_DRIVER = XrActivity.isSupported() ? "pulseaudio" : "alsa";
public static final String DEFAULT_DXWRAPPER = XrActivity.isSupported() ? "wined3d" : "dxvk";
public static final String DEFAULT_WINCOMPONENTS = "direct3d=1,directsound=1,directmusic=0,directshow=0,directplay=0,vcrun2010=1,wmdecoder=1";
public static final String FALLBACK_WINCOMPONENTS = "direct3d=0,directsound=0,directmusic=0,directshow=0,directplay=0,vcrun2010=0,wmdecoder=0";
public static final String DEFAULT_DRIVES = "D:"+Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+"E:/data/data/com.winlator/storage";
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/winlator/renderer/Texture.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public void allocateTexture(short width, short height, ByteBuffer data) {
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, minFilter);

GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
if (XrActivity.isSupported()) XrActivity.getInstance().bindFramebuffer();
}

public int getWrapS() {
Expand Down Expand Up @@ -118,6 +117,7 @@ public void copyFromFramebuffer(int framebuffer, short width, short height) {
GLES20.glCopyTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 0, 0, width, height, 0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
if (XrActivity.isSupported()) XrActivity.getInstance().bindFramebuffer();
}

public void destroy() {
Expand Down

0 comments on commit 315c139

Please sign in to comment.