mirror of https://github.com/bjornbytes/lovr.git
OpenXR: MSAA;
This commit is contained in:
parent
17e250c415
commit
37522bd8a3
|
@ -1681,7 +1681,7 @@ Texture* lovrTextureCreate(TextureType type, TextureData** slices, uint32_t slic
|
|||
return texture;
|
||||
}
|
||||
|
||||
Texture* lovrTextureCreateFromHandle(uint32_t handle, TextureType type, uint32_t depth) {
|
||||
Texture* lovrTextureCreateFromHandle(uint32_t handle, TextureType type, uint32_t depth, uint32_t msaa) {
|
||||
Texture* texture = lovrAlloc(Texture);
|
||||
state.stats.textureCount++;
|
||||
texture->type = type;
|
||||
|
@ -1699,6 +1699,15 @@ Texture* lovrTextureCreateFromHandle(uint32_t handle, TextureType type, uint32_t
|
|||
texture->depth = depth; // There isn't an easy way to get depth/layer count, so it's passed in...
|
||||
texture->mipmapCount = 1;
|
||||
|
||||
if (msaa > 1) {
|
||||
texture->msaa = msaa;
|
||||
GLint internalFormat;
|
||||
glGetTexLevelParameteriv(texture->target, 0, GL_TEXTURE_INTERNAL_FORMAT, &internalFormat);
|
||||
glGenRenderbuffers(1, &texture->msaaId);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, texture->msaaId);
|
||||
glRenderbufferStorageMultisample(GL_RENDERBUFFER, texture->msaa, internalFormat, width, height);
|
||||
}
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ typedef enum {
|
|||
|
||||
typedef struct Texture Texture;
|
||||
Texture* lovrTextureCreate(TextureType type, struct TextureData** slices, uint32_t sliceCount, bool srgb, bool mipmaps, uint32_t msaa);
|
||||
Texture* lovrTextureCreateFromHandle(uint32_t handle, TextureType type, uint32_t depth);
|
||||
Texture* lovrTextureCreateFromHandle(uint32_t handle, TextureType type, uint32_t depth, uint32_t msaa);
|
||||
void lovrTextureDestroy(void* ref);
|
||||
void lovrTextureAllocate(Texture* texture, uint32_t width, uint32_t height, uint32_t depth, TextureFormat format);
|
||||
void lovrTextureReplacePixels(Texture* texture, struct TextureData* data, uint32_t x, uint32_t y, uint32_t slice, uint32_t mipmap);
|
||||
|
|
|
@ -41,7 +41,7 @@ static Texture* lookupTexture(uint32_t handle) {
|
|||
if (index == MAP_NIL) {
|
||||
index = state.textures.length;
|
||||
map_set(&state.textureLookup, hash, index);
|
||||
arr_push(&state.textures, lovrTextureCreateFromHandle(handle, TEXTURE_2D, 1));
|
||||
arr_push(&state.textures, lovrTextureCreateFromHandle(handle, TEXTURE_2D, 1, 1));
|
||||
}
|
||||
|
||||
return state.textures.data[index];
|
||||
|
|
|
@ -79,6 +79,7 @@ static XrResult handleResult(XrResult result, const char* file, int line) {
|
|||
static void openxr_destroy();
|
||||
|
||||
static bool openxr_init(float offset, uint32_t msaa) {
|
||||
state.msaa = msaa;
|
||||
|
||||
{ // Instance
|
||||
XrInstanceCreateInfo info = {
|
||||
|
@ -122,7 +123,6 @@ static bool openxr_init(float offset, uint32_t msaa) {
|
|||
return false;
|
||||
}
|
||||
|
||||
state.msaa = views[0].recommendedSwapchainSampleCount;
|
||||
state.width = views[0].recommendedImageRectWidth;
|
||||
state.height = views[0].recommendedImageRectHeight;
|
||||
}
|
||||
|
@ -261,9 +261,9 @@ static bool openxr_init(float offset, uint32_t msaa) {
|
|||
.type = XR_TYPE_SWAPCHAIN_CREATE_INFO,
|
||||
.usageFlags = XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT | XR_SWAPCHAIN_USAGE_SAMPLED_BIT,
|
||||
.format = GL_SRGB8_ALPHA8,
|
||||
.sampleCount = state.msaa,
|
||||
.width = state.width * 2,
|
||||
.height = state.height,
|
||||
.sampleCount = 1,
|
||||
.faceCount = 1,
|
||||
.arraySize = 1,
|
||||
.mipCount = 1
|
||||
|
@ -278,7 +278,7 @@ static bool openxr_init(float offset, uint32_t msaa) {
|
|||
XR_INIT(xrEnumerateSwapchainImages(state.swapchain, MAX_IMAGES, &state.imageCount, (XrSwapchainImageBaseHeader*) images));
|
||||
|
||||
for (uint32_t i = 0; i < state.imageCount; i++) {
|
||||
state.textures[i] = lovrTextureCreateFromHandle(images[i].image, TEXTURE_2D, 1);
|
||||
state.textures[i] = lovrTextureCreateFromHandle(images[i].image, TEXTURE_2D, 1, state.msaa);
|
||||
}
|
||||
|
||||
// Pre-init composition layer
|
||||
|
@ -579,7 +579,7 @@ static void openxr_renderTo(void (*callback)(void*), void* userdata) {
|
|||
|
||||
if (XR(xrWaitSwapchainImage(state.swapchain, &waitInfo)) != XR_TIMEOUT_EXPIRED) {
|
||||
if (!state.canvas) {
|
||||
CanvasFlags flags = { .depth = { true, false, FORMAT_D24S8 }, .stereo = true, .mipmaps = true, .msaa = state.msaa };
|
||||
CanvasFlags flags = { .depth = { true, false, FORMAT_D24S8 }, .stereo = true, .mipmaps = false, .msaa = state.msaa };
|
||||
state.canvas = lovrCanvasCreate(state.width, state.height, flags);
|
||||
lovrPlatformSetSwapInterval(0);
|
||||
}
|
||||
|
|
|
@ -628,7 +628,7 @@ static void vrapi_renderTo(void (*callback)(void*), void* userdata) {
|
|||
for (uint32_t i = 0; i < state.swapchainLength; i++) {
|
||||
state.canvases[i] = lovrCanvasCreate(width, height, flags);
|
||||
uint32_t handle = vrapi_GetTextureSwapChainHandle(state.swapchain, i);
|
||||
Texture* texture = lovrTextureCreateFromHandle(handle, TEXTURE_ARRAY, 2);
|
||||
Texture* texture = lovrTextureCreateFromHandle(handle, TEXTURE_ARRAY, 2, 1);
|
||||
lovrCanvasSetAttachments(state.canvases[i], &(Attachment) { .texture = texture }, 1);
|
||||
lovrRelease(Texture, texture);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue