mirror of
https://github.com/DrBeef/ioq3quest.git
synced 2024-11-10 06:41:58 +00:00
Merge pull request #86 from lvonasek/feature_openxr_tweaks
Make OpenXR build behave the same like VrAPI build
This commit is contained in:
commit
9634ff74cd
3 changed files with 46 additions and 38 deletions
|
@ -23,7 +23,8 @@ extern vr_clientinfo_t vr;
|
||||||
extern cvar_t *vr_heightAdjust;
|
extern cvar_t *vr_heightAdjust;
|
||||||
|
|
||||||
XrView* projections;
|
XrView* projections;
|
||||||
GLboolean stageSupported = GL_FALSE;
|
qboolean needRecenter = qtrue;
|
||||||
|
qboolean stageSupported = qfalse;
|
||||||
|
|
||||||
void VR_UpdateStageBounds(ovrApp* pappState) {
|
void VR_UpdateStageBounds(ovrApp* pappState) {
|
||||||
XrExtent2Df stageBounds = {};
|
XrExtent2Df stageBounds = {};
|
||||||
|
@ -278,7 +279,7 @@ void VR_InitRenderer( engine_t* engine ) {
|
||||||
|
|
||||||
for (uint32_t i = 0; i < numOutputSpaces; i++) {
|
for (uint32_t i = 0; i < numOutputSpaces; i++) {
|
||||||
if (referenceSpaces[i] == XR_REFERENCE_SPACE_TYPE_STAGE) {
|
if (referenceSpaces[i] == XR_REFERENCE_SPACE_TYPE_STAGE) {
|
||||||
stageSupported = GL_TRUE;
|
stageSupported = qtrue;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -505,13 +506,13 @@ void VR_DrawFrame( engine_t* engine ) {
|
||||||
cylinder_layer.subImage.imageArrayIndex = 0;
|
cylinder_layer.subImage.imageArrayIndex = 0;
|
||||||
const XrVector3f axis = {0.0f, 1.0f, 0.0f};
|
const XrVector3f axis = {0.0f, 1.0f, 0.0f};
|
||||||
XrVector3f pos = {
|
XrVector3f pos = {
|
||||||
invViewTransform[0].position.x - sin(radians(vr.menuYaw)) * 4.0f,
|
invViewTransform[0].position.x - sin(radians(vr.menuYaw)) * 6.0f,
|
||||||
-0.25f,
|
invViewTransform[0].position.y,
|
||||||
invViewTransform[0].position.z - cos(radians(vr.menuYaw)) * 4.0f
|
invViewTransform[0].position.z - cos(radians(vr.menuYaw)) * 6.0f
|
||||||
};
|
};
|
||||||
cylinder_layer.pose.orientation = XrQuaternionf_CreateFromVectorAngle(axis, radians(vr.menuYaw));
|
cylinder_layer.pose.orientation = XrQuaternionf_CreateFromVectorAngle(axis, radians(vr.menuYaw));
|
||||||
cylinder_layer.pose.position = pos;
|
cylinder_layer.pose.position = pos;
|
||||||
cylinder_layer.radius = 12.0f;
|
cylinder_layer.radius = 8.0f;
|
||||||
cylinder_layer.centralAngle = MATH_PI * 0.5f;
|
cylinder_layer.centralAngle = MATH_PI * 0.5f;
|
||||||
cylinder_layer.aspectRatio = width / (float)height / 0.75f;
|
cylinder_layer.aspectRatio = width / (float)height / 0.75f;
|
||||||
|
|
||||||
|
@ -534,4 +535,10 @@ void VR_DrawFrame( engine_t* engine ) {
|
||||||
OXR(xrEndFrame(engine->appState.Session, &endFrameInfo));
|
OXR(xrEndFrame(engine->appState.Session, &endFrameInfo));
|
||||||
frameBuffer->TextureSwapChainIndex++;
|
frameBuffer->TextureSwapChainIndex++;
|
||||||
frameBuffer->TextureSwapChainIndex %= frameBuffer->TextureSwapChainLength;
|
frameBuffer->TextureSwapChainIndex %= frameBuffer->TextureSwapChainLength;
|
||||||
|
|
||||||
|
if (needRecenter)
|
||||||
|
{
|
||||||
|
VR_Recenter(engine);
|
||||||
|
needRecenter = qfalse;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,10 @@ void ovrFramebuffer_Clear(ovrFramebuffer* frameBuffer) {
|
||||||
frameBuffer->ColorSwapChain.Width = 0;
|
frameBuffer->ColorSwapChain.Width = 0;
|
||||||
frameBuffer->ColorSwapChain.Height = 0;
|
frameBuffer->ColorSwapChain.Height = 0;
|
||||||
frameBuffer->ColorSwapChainImage = NULL;
|
frameBuffer->ColorSwapChainImage = NULL;
|
||||||
frameBuffer->DepthBuffers = NULL;
|
frameBuffer->DepthSwapChain.Handle = XR_NULL_HANDLE;
|
||||||
|
frameBuffer->DepthSwapChain.Width = 0;
|
||||||
|
frameBuffer->DepthSwapChain.Height = 0;
|
||||||
|
frameBuffer->DepthSwapChainImage = NULL;
|
||||||
frameBuffer->FrameBuffers = NULL;
|
frameBuffer->FrameBuffers = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,8 +67,6 @@ bool ovrFramebuffer_Create(
|
||||||
XrSwapchainCreateInfo swapChainCreateInfo;
|
XrSwapchainCreateInfo swapChainCreateInfo;
|
||||||
memset(&swapChainCreateInfo, 0, sizeof(swapChainCreateInfo));
|
memset(&swapChainCreateInfo, 0, sizeof(swapChainCreateInfo));
|
||||||
swapChainCreateInfo.type = XR_TYPE_SWAPCHAIN_CREATE_INFO;
|
swapChainCreateInfo.type = XR_TYPE_SWAPCHAIN_CREATE_INFO;
|
||||||
swapChainCreateInfo.usageFlags = XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT;
|
|
||||||
swapChainCreateInfo.format = GL_RGBA8;
|
|
||||||
swapChainCreateInfo.sampleCount = 1;
|
swapChainCreateInfo.sampleCount = 1;
|
||||||
swapChainCreateInfo.width = width;
|
swapChainCreateInfo.width = width;
|
||||||
swapChainCreateInfo.height = height;
|
swapChainCreateInfo.height = height;
|
||||||
|
@ -75,56 +76,58 @@ bool ovrFramebuffer_Create(
|
||||||
|
|
||||||
frameBuffer->ColorSwapChain.Width = swapChainCreateInfo.width;
|
frameBuffer->ColorSwapChain.Width = swapChainCreateInfo.width;
|
||||||
frameBuffer->ColorSwapChain.Height = swapChainCreateInfo.height;
|
frameBuffer->ColorSwapChain.Height = swapChainCreateInfo.height;
|
||||||
|
frameBuffer->DepthSwapChain.Width = swapChainCreateInfo.width;
|
||||||
|
frameBuffer->DepthSwapChain.Height = swapChainCreateInfo.height;
|
||||||
|
|
||||||
// Create the swapchain.
|
// Create the color swapchain.
|
||||||
|
swapChainCreateInfo.format = GL_RGBA8;
|
||||||
|
swapChainCreateInfo.usageFlags = XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT;
|
||||||
OXR(xrCreateSwapchain(session, &swapChainCreateInfo, &frameBuffer->ColorSwapChain.Handle));
|
OXR(xrCreateSwapchain(session, &swapChainCreateInfo, &frameBuffer->ColorSwapChain.Handle));
|
||||||
|
|
||||||
|
// Create the depth swapchain.
|
||||||
|
swapChainCreateInfo.format = GL_DEPTH24_STENCIL8;
|
||||||
|
swapChainCreateInfo.usageFlags = XR_SWAPCHAIN_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
||||||
|
OXR(xrCreateSwapchain(session, &swapChainCreateInfo, &frameBuffer->DepthSwapChain.Handle));
|
||||||
|
|
||||||
// Get the number of swapchain images.
|
// Get the number of swapchain images.
|
||||||
OXR(xrEnumerateSwapchainImages(
|
OXR(xrEnumerateSwapchainImages(
|
||||||
frameBuffer->ColorSwapChain.Handle, 0, &frameBuffer->TextureSwapChainLength, NULL));
|
frameBuffer->ColorSwapChain.Handle, 0, &frameBuffer->TextureSwapChainLength, NULL));
|
||||||
|
|
||||||
// Allocate the swapchain images array.
|
// Allocate the swapchain images array.
|
||||||
frameBuffer->ColorSwapChainImage = (XrSwapchainImageOpenGLESKHR*)malloc(
|
frameBuffer->ColorSwapChainImage = (XrSwapchainImageOpenGLESKHR*)malloc(
|
||||||
frameBuffer->TextureSwapChainLength * sizeof(XrSwapchainImageOpenGLESKHR));
|
frameBuffer->TextureSwapChainLength * sizeof(XrSwapchainImageOpenGLESKHR));
|
||||||
|
frameBuffer->DepthSwapChainImage = (XrSwapchainImageOpenGLESKHR*)malloc(
|
||||||
|
frameBuffer->TextureSwapChainLength * sizeof(XrSwapchainImageOpenGLESKHR));
|
||||||
|
|
||||||
// Populate the swapchain image array.
|
// Populate the swapchain image array.
|
||||||
for (uint32_t i = 0; i < frameBuffer->TextureSwapChainLength; i++) {
|
for (uint32_t i = 0; i < frameBuffer->TextureSwapChainLength; i++) {
|
||||||
frameBuffer->ColorSwapChainImage[i].type = XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_ES_KHR;
|
frameBuffer->ColorSwapChainImage[i].type = XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_ES_KHR;
|
||||||
frameBuffer->ColorSwapChainImage[i].next = NULL;
|
frameBuffer->ColorSwapChainImage[i].next = NULL;
|
||||||
|
frameBuffer->DepthSwapChainImage[i].type = XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_ES_KHR;
|
||||||
|
frameBuffer->DepthSwapChainImage[i].next = NULL;
|
||||||
}
|
}
|
||||||
OXR(xrEnumerateSwapchainImages(
|
OXR(xrEnumerateSwapchainImages(
|
||||||
frameBuffer->ColorSwapChain.Handle,
|
frameBuffer->ColorSwapChain.Handle,
|
||||||
frameBuffer->TextureSwapChainLength,
|
frameBuffer->TextureSwapChainLength,
|
||||||
&frameBuffer->TextureSwapChainLength,
|
&frameBuffer->TextureSwapChainLength,
|
||||||
(XrSwapchainImageBaseHeader*)frameBuffer->ColorSwapChainImage));
|
(XrSwapchainImageBaseHeader*)frameBuffer->ColorSwapChainImage));
|
||||||
|
OXR(xrEnumerateSwapchainImages(
|
||||||
|
frameBuffer->DepthSwapChain.Handle,
|
||||||
|
frameBuffer->TextureSwapChainLength,
|
||||||
|
&frameBuffer->TextureSwapChainLength,
|
||||||
|
(XrSwapchainImageBaseHeader*)frameBuffer->DepthSwapChainImage));
|
||||||
|
|
||||||
frameBuffer->DepthBuffers =
|
frameBuffer->FrameBuffers = (GLuint*)malloc(frameBuffer->TextureSwapChainLength * sizeof(GLuint));
|
||||||
(GLuint*)malloc(frameBuffer->TextureSwapChainLength * sizeof(GLuint));
|
|
||||||
frameBuffer->FrameBuffers =
|
|
||||||
(GLuint*)malloc(frameBuffer->TextureSwapChainLength * sizeof(GLuint));
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < frameBuffer->TextureSwapChainLength; i++) {
|
for (uint32_t i = 0; i < frameBuffer->TextureSwapChainLength; i++) {
|
||||||
// Create the color buffer texture.
|
// Create the color buffer texture.
|
||||||
const GLuint colorTexture = frameBuffer->ColorSwapChainImage[i].image;
|
const GLuint colorTexture = frameBuffer->ColorSwapChainImage[i].image;
|
||||||
|
const GLuint depthTexture = frameBuffer->DepthSwapChainImage[i].image;
|
||||||
GLfloat borderColor[] = {0.0f, 0.0f, 0.0f, 0.0f};
|
|
||||||
GLenum textureTarget = GL_TEXTURE_2D_ARRAY;
|
|
||||||
GL(glBindTexture(textureTarget, colorTexture));
|
|
||||||
GL(glTexParameterfv(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BORDER_COLOR, borderColor));
|
|
||||||
GL(glTexParameteri(textureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
|
|
||||||
GL(glTexParameteri(textureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
|
|
||||||
GL(glTexParameteri(textureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
|
|
||||||
GL(glTexParameteri(textureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
|
|
||||||
GL(glBindTexture(textureTarget, 0));
|
|
||||||
|
|
||||||
// Create depth buffer.
|
|
||||||
GL(glGenTextures(1, &frameBuffer->DepthBuffers[i]));
|
|
||||||
GL(glBindTexture(textureTarget, frameBuffer->DepthBuffers[i]));
|
|
||||||
GL(glTexStorage3D(textureTarget, 1, GL_DEPTH_COMPONENT24, width, height, 2));
|
|
||||||
GL(glBindTexture(textureTarget, 0));
|
|
||||||
|
|
||||||
// Create the frame buffer.
|
// Create the frame buffer.
|
||||||
GL(glGenFramebuffers(1, &frameBuffer->FrameBuffers[i]));
|
GL(glGenFramebuffers(1, &frameBuffer->FrameBuffers[i]));
|
||||||
GL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBuffer->FrameBuffers[i]));
|
GL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBuffer->FrameBuffers[i]));
|
||||||
GL(glFramebufferTextureMultiviewOVR(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, frameBuffer->DepthBuffers[i], 0, 0, 2));
|
GL(glFramebufferTextureMultiviewOVR(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, depthTexture, 0, 0, 2));
|
||||||
|
GL(glFramebufferTextureMultiviewOVR(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthTexture, 0, 0, 2));
|
||||||
GL(glFramebufferTextureMultiviewOVR(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, colorTexture, 0, 0, 2));
|
GL(glFramebufferTextureMultiviewOVR(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, colorTexture, 0, 0, 2));
|
||||||
GL(GLenum renderFramebufferStatus = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER));
|
GL(GLenum renderFramebufferStatus = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER));
|
||||||
GL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0));
|
GL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0));
|
||||||
|
@ -139,11 +142,10 @@ bool ovrFramebuffer_Create(
|
||||||
|
|
||||||
void ovrFramebuffer_Destroy(ovrFramebuffer* frameBuffer) {
|
void ovrFramebuffer_Destroy(ovrFramebuffer* frameBuffer) {
|
||||||
GL(glDeleteFramebuffers(frameBuffer->TextureSwapChainLength, frameBuffer->FrameBuffers));
|
GL(glDeleteFramebuffers(frameBuffer->TextureSwapChainLength, frameBuffer->FrameBuffers));
|
||||||
GL(glDeleteRenderbuffers(frameBuffer->TextureSwapChainLength, frameBuffer->DepthBuffers));
|
|
||||||
OXR(xrDestroySwapchain(frameBuffer->ColorSwapChain.Handle));
|
OXR(xrDestroySwapchain(frameBuffer->ColorSwapChain.Handle));
|
||||||
|
OXR(xrDestroySwapchain(frameBuffer->DepthSwapChain.Handle));
|
||||||
free(frameBuffer->ColorSwapChainImage);
|
free(frameBuffer->ColorSwapChainImage);
|
||||||
|
free(frameBuffer->DepthSwapChainImage);
|
||||||
free(frameBuffer->DepthBuffers);
|
|
||||||
free(frameBuffer->FrameBuffers);
|
free(frameBuffer->FrameBuffers);
|
||||||
|
|
||||||
ovrFramebuffer_Clear(frameBuffer);
|
ovrFramebuffer_Clear(frameBuffer);
|
||||||
|
@ -250,7 +252,6 @@ void ovrApp_Clear(ovrApp* app) {
|
||||||
app->LayerCount = 0;
|
app->LayerCount = 0;
|
||||||
app->MainThreadTid = 0;
|
app->MainThreadTid = 0;
|
||||||
app->RenderThreadTid = 0;
|
app->RenderThreadTid = 0;
|
||||||
app->TouchPadDownLastFrame = false;
|
|
||||||
|
|
||||||
ovrRenderer_Clear(&app->Renderer);
|
ovrRenderer_Clear(&app->Renderer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,8 +56,9 @@ typedef struct {
|
||||||
uint32_t TextureSwapChainLength;
|
uint32_t TextureSwapChainLength;
|
||||||
uint32_t TextureSwapChainIndex;
|
uint32_t TextureSwapChainIndex;
|
||||||
ovrSwapChain ColorSwapChain;
|
ovrSwapChain ColorSwapChain;
|
||||||
|
ovrSwapChain DepthSwapChain;
|
||||||
XrSwapchainImageOpenGLESKHR* ColorSwapChainImage;
|
XrSwapchainImageOpenGLESKHR* ColorSwapChainImage;
|
||||||
GLuint* DepthBuffers;
|
XrSwapchainImageOpenGLESKHR* DepthSwapChainImage;
|
||||||
GLuint* FrameBuffers;
|
GLuint* FrameBuffers;
|
||||||
} ovrFramebuffer;
|
} ovrFramebuffer;
|
||||||
|
|
||||||
|
@ -97,7 +98,6 @@ typedef struct {
|
||||||
ovrCompositorLayer_Union Layers[ovrMaxLayerCount];
|
ovrCompositorLayer_Union Layers[ovrMaxLayerCount];
|
||||||
int LayerCount;
|
int LayerCount;
|
||||||
|
|
||||||
GLboolean TouchPadDownLastFrame;
|
|
||||||
ovrRenderer Renderer;
|
ovrRenderer Renderer;
|
||||||
ovrTrackedController TrackedController[2];
|
ovrTrackedController TrackedController[2];
|
||||||
} ovrApp;
|
} ovrApp;
|
||||||
|
|
Loading…
Reference in a new issue