|
1 | 1 | package org.vivecraft.client_vr.provider.openxr; |
2 | 2 |
|
3 | | -import com.mojang.blaze3d.opengl.GlStateManager; |
4 | 3 | import com.mojang.blaze3d.pipeline.RenderTarget; |
5 | 4 | import net.minecraft.util.Tuple; |
6 | 5 | import org.joml.Matrix4f; |
7 | 6 | import org.lwjgl.PointerBuffer; |
8 | | -import org.lwjgl.opengl.GL11C; |
9 | 7 | import org.lwjgl.openxr.*; |
10 | 8 | import org.lwjgl.system.MemoryStack; |
11 | 9 | import org.vivecraft.client_vr.VRTextureTarget; |
|
18 | 16 |
|
19 | 17 | public class OpenXRStereoRenderer extends VRRenderer { |
20 | 18 | private final MCOpenXR openxr; |
21 | | - private int[] swapIndex = new int[2]; |
| 19 | + private final int[] swapIndex = new int[] {0, 0}; // Needs to be initialized otherwise stuff splodes |
22 | 20 | private VRTextureTarget[] leftFramebuffers; |
23 | 21 | private VRTextureTarget[] rightFramebuffers; |
24 | 22 | private boolean render; |
@@ -49,8 +47,11 @@ public void createRenderTexture(int width, int height) { |
49 | 47 | XrSwapchainImageBaseHeader.create(swapchainImageBuffer.address(), swapchainImageBuffer.capacity())); |
50 | 48 | this.openxr.logError(error, "xrEnumerateSwapchainImages", "get images"); |
51 | 49 |
|
52 | | - this.leftFramebuffers = new VRTextureTarget[imageCount]; |
53 | | - this.rightFramebuffers = new VRTextureTarget[imageCount]; |
| 50 | + if(i == 0) { |
| 51 | + this.leftFramebuffers = new VRTextureTarget[imageCount]; |
| 52 | + } else { |
| 53 | + this.rightFramebuffers = new VRTextureTarget[imageCount]; |
| 54 | + } |
54 | 55 |
|
55 | 56 | String leftError = ""; |
56 | 57 | String rightError = ""; |
@@ -103,7 +104,7 @@ public void setupRenderConfiguration(boolean render) throws IOException, RenderC |
103 | 104 | .fov(this.openxr.viewBuffer.get(i).fov()) |
104 | 105 | .subImage(); |
105 | 106 | subImage.swapchain(this.openxr.swapchain[i]); |
106 | | - subImage.imageRect().offset().set(i * this.openxr.width, 0); |
| 107 | + subImage.imageRect().offset().set(0, 0); |
107 | 108 | subImage.imageRect().extent().set(this.openxr.width, this.openxr.height); |
108 | 109 | } |
109 | 110 | this.recalculateProjectionMatrix = true; |
@@ -197,13 +198,19 @@ public void destroy() { |
197 | 198 |
|
198 | 199 | if (this.leftFramebuffers != null) { |
199 | 200 | for (VRTextureTarget leftFramebuffer : this.leftFramebuffers) { |
| 201 | + if(leftFramebuffer == null) { |
| 202 | + continue; |
| 203 | + } |
200 | 204 | leftFramebuffer.destroyBuffers(); |
201 | 205 | } |
202 | 206 | this.leftFramebuffers = null; |
203 | 207 | } |
204 | 208 |
|
205 | 209 | if (this.rightFramebuffers != null) { |
206 | 210 | for (VRTextureTarget rightFramebuffer : this.rightFramebuffers) { |
| 211 | + if(rightFramebuffer == null) { |
| 212 | + continue; |
| 213 | + } |
207 | 214 | rightFramebuffer.destroyBuffers(); |
208 | 215 | } |
209 | 216 | this.rightFramebuffers = null; |
|
0 commit comments