mirror of
https://github.com/DrBeef/ioq3quest.git
synced 2024-11-22 12:01:41 +00:00
OpenXR - Make the initializations more universal
This commit is contained in:
parent
b43a9a67c7
commit
807a8d2820
2 changed files with 33 additions and 32 deletions
|
@ -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