From 5e34ca7d56e2cf4997be015e12946914bfc1a024 Mon Sep 17 00:00:00 2001 From: StellaArtois Date: Mon, 16 Nov 2015 08:33:28 +0000 Subject: [PATCH] Start to implement use of createSwapTextureSet --- .gitignore | 1 + JRift | 2 +- normalisePatchLineEndings.bat | 3 + normalisePatchLineEndings.py | 18 ++++ .../net/minecraft/client/Minecraft.java.patch | 50 ++++++--- .../client/shader/Framebuffer.java.patch | 100 ++++++++++++++---- .../mtbs3d/minecrift/api/IStereoProvider.java | 2 + .../provider/NullStereoRenderer.java | 6 ++ 8 files changed, 148 insertions(+), 34 deletions(-) create mode 100644 normalisePatchLineEndings.bat create mode 100644 normalisePatchLineEndings.py diff --git a/.gitignore b/.gitignore index f89b874b..8c02e6b5 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ patchsrc/ src/JRift bin/intelij_prod optionsvrprofiles.txt +crash-reports/ diff --git a/JRift b/JRift index 190d35b9..28f519a8 160000 --- a/JRift +++ b/JRift @@ -1 +1 @@ -Subproject commit 190d35b929b31c1bdfed31ea700f6bcba68ca6a7 +Subproject commit 28f519a88a989ebaa8e12f01741daa20658bdae8 diff --git a/normalisePatchLineEndings.bat b/normalisePatchLineEndings.bat new file mode 100644 index 00000000..38ee6636 --- /dev/null +++ b/normalisePatchLineEndings.bat @@ -0,0 +1,3 @@ +@echo off +python normalisePatchLineEndings.py %* + diff --git a/normalisePatchLineEndings.py b/normalisePatchLineEndings.py new file mode 100644 index 00000000..d0cdf33c --- /dev/null +++ b/normalisePatchLineEndings.py @@ -0,0 +1,18 @@ +import sys, os + +def normalisePatchLineEndings(): + + base_dir = os.path.dirname(os.path.abspath(__file__)) + patchDir = os.path.join(base_dir, 'patches') + for root, dirs, files in os.walk(patchDir): + for file in files: + if file.endswith(".java.patch"): + fileContent = '' + patchFile = os.path.join(root, file) + with open( patchFile, 'rb') as input: + fileContent = input.read() + with open( patchFile, 'wb') as out: + out.write( fileContent.replace('\r\n','\n').replace('\r','\n') ) + +if __name__ == '__main__': + normalisePatchLineEndings() diff --git a/patches/net/minecraft/client/Minecraft.java.patch b/patches/net/minecraft/client/Minecraft.java.patch index 98d107a0..956bb327 100644 --- a/patches/net/minecraft/client/Minecraft.java.patch +++ b/patches/net/minecraft/client/Minecraft.java.patch @@ -212,7 +212,7 @@ + public int currentDisplayWidth = 0; + public int currentDisplayHeight = 0; + -+ public final String minecriftVerString = "Minecrift 1.7.10 R1b"; ++ public final String minecriftVerString = "Minecrift 1.7.10 R1c"; + /** END MINECRIFT */ + public Minecraft(Session sessionIn, int displayWidth, int displayHeight, boolean fullscreen, boolean isDemo, File dataDir, File assetsDir, File resourcePackDir, Proxy proxy, String version, Multimap twitchDetails, String assetsJsonVersion) @@ -320,6 +320,15 @@ } catch (LWJGLException var7) { +@@ -539,7 +684,7 @@ + logger.error("Couldn\'t initialize twitch stream"); + } + +- this.framebufferMc = new Framebuffer(this.displayWidth, this.displayHeight, true); ++ this.framebufferMc = new Framebuffer(this.displayWidth, this.displayHeight, true); // TODO: Need to set this to the guiFramebuffer instead? + this.framebufferMc.setFramebufferColor(0.0F, 0.0F, 0.0F, 0.0F); + this.guiAchievement = new GuiAchievement(this); + this.metadataSerializer_.registerMetadataSectionType(new TextureMetadataSectionSerializer(), TextureMetadataSection.class); @@ -552,11 +697,33 @@ this.mcResourceManager = new SimpleReloadableResourceManager(this.metadataSerializer_); this.mcLanguageManager = new LanguageManager(this.metadataSerializer_, this.gameSettings.language); @@ -1622,7 +1631,7 @@ /** * Returns whether snooping is enabled or not. -@@ -3134,4 +3710,961 @@ +@@ -3134,4 +3710,978 @@ } } } @@ -1749,16 +1758,22 @@ + if (this.framebuffers[0] != null) { + this.framebuffers[0].deleteFramebuffer(); + this.framebuffers[0] = null; ++ ++ // TODO: Delete swap texture set + } + + if (this.framebuffers[1] != null) { + this.framebuffers[1].deleteFramebuffer(); + this.framebuffers[1] = null; ++ ++ // TODO: Delete swap texture set + } + + if (this.guiFramebuffer != null) { + this.guiFramebuffer.deleteFramebuffer(); + this.guiFramebuffer = null; ++ ++ // TODO: Delete mirror texture + } + + if (this.fsaaFirstPassResultFBO[0] != null) { @@ -1782,25 +1797,36 @@ + _LanczosShader_texelHeightOffsetUniform = -1; + _LanczosShader_inputImageTextureUniform = -1; + -+ int multiSampleCount = 0; // TODO: The SDK (0.3.2 preview) doesn't like anything other than 0 currently AFAICT ++ int multiSampleCount = 0; + boolean multiSample = (multiSampleCount > 0 ? true : false); + boolean genMipMaps = true; + this.entityRenderer.generatedIconMipmaps[0] = false; + this.entityRenderer.generatedIconMipmaps[1] = false; + -+ this.framebuffers[0] = new Framebuffer(this.EyeTextureSize[0].w, this.EyeTextureSize[0].h, true, genMipMaps, multiSample, multiSampleCount); -+ glConfig.TexId = this.framebuffers[0].framebufferTexture; -+ this.checkGLError("Viewport 1 framebuffer setup"); -+ this.framebuffers[1] = new Framebuffer(this.EyeTextureSize[1].w, this.EyeTextureSize[1].h, true, genMipMaps, multiSample, multiSampleCount); -+ glConfig.TexId2 = this.framebuffers[1].framebufferTexture; -+ this.checkGLError("Viewport 2 framebuffer setup"); ++ SwapTextureSet renderTextures = this.stereoProvider.createSwapTextureSet(this.EyeTextureSize[0].w, this.EyeTextureSize[0].h); // TODO: Support differing buffer sizes for each eye? ++ if (renderTextures == null) ++ { ++ this.framebuffers[0] = new Framebuffer(this.EyeTextureSize[0].w, this.EyeTextureSize[0].h, true, genMipMaps, multiSample, multiSampleCount, Framebuffer.NO_TEXTURE_ID); ++ glConfig.TexId = this.framebuffers[0].framebufferTexture; ++ this.checkGLError("Viewport 1 framebuffer setup"); ++ this.framebuffers[1] = new Framebuffer(this.EyeTextureSize[1].w, this.EyeTextureSize[1].h, true, genMipMaps, multiSample, multiSampleCount, Framebuffer.NO_TEXTURE_ID); ++ glConfig.TexId2 = this.framebuffers[1].framebufferTexture; ++ this.checkGLError("Viewport 2 framebuffer setup"); ++ this.framebuffers[0].setFramebufferColor(RED_COLOUR_COMPONENT, GREEN_COLOUR_COMPONENT, BLUE_COLOUR_COMPONENT, 0.0F); ++ this.framebuffers[1].setFramebufferColor(RED_COLOUR_COMPONENT, GREEN_COLOUR_COMPONENT, BLUE_COLOUR_COMPONENT, 0.0F); ++ } ++ else ++ { ++ // TODO: Initialise framebuffer sets... ++ } ++ ++ // TODO: How to initialise mirror texture? ++ + this.guiFramebuffer = new Framebuffer(this.displayFBWidth, this.displayFBHeight, true, genMipMaps); + this.checkGLError("GUI framebuffer setup"); -+ -+ this.framebuffers[0].setFramebufferColor(RED_COLOUR_COMPONENT, GREEN_COLOUR_COMPONENT, BLUE_COLOUR_COMPONENT, 0.0F); -+ this.framebuffers[1].setFramebufferColor(RED_COLOUR_COMPONENT, GREEN_COLOUR_COMPONENT, BLUE_COLOUR_COMPONENT, 0.0F); + this.guiFramebuffer.setFramebufferColor(RED_COLOUR_COMPONENT, GREEN_COLOUR_COMPONENT, BLUE_COLOUR_COMPONENT, 0.0F); + ++ + try + { + if (this.vrSettings.useFsaa) diff --git a/patches/net/minecraft/client/shader/Framebuffer.java.patch b/patches/net/minecraft/client/shader/Framebuffer.java.patch index cb1abbe4..b3b40adc 100644 --- a/patches/net/minecraft/client/shader/Framebuffer.java.patch +++ b/patches/net/minecraft/client/shader/Framebuffer.java.patch @@ -19,7 +19,7 @@ public class Framebuffer { -@@ -20,8 +28,28 @@ +@@ -20,22 +28,62 @@ public int framebufferFilter; private static final String __OBFID = "CL_00000959"; @@ -29,60 +29,118 @@ + public boolean multiSample = false; + public int multiSampleCount = 0; + public int textureType = GL11.GL_TEXTURE_2D; ++ public static final int NO_TEXTURE_ID = -1; ++ public boolean generatedFramebufferTexture = true; + /** END MINECRIFT */ + public Framebuffer(int p_i45078_1_, int p_i45078_2_, boolean p_i45078_3_) { + /** MINECRIFT */ -+ this(p_i45078_1_, p_i45078_2_, p_i45078_3_, false, false, 0); ++ this(p_i45078_1_, p_i45078_2_, p_i45078_3_, false, false, 0, NO_TEXTURE_ID); + } + + public Framebuffer(int p_i45078_1_, int p_i45078_2_, boolean p_i45078_3_, boolean generateMipMaps) + { -+ this(p_i45078_1_, p_i45078_2_, p_i45078_3_, generateMipMaps, false, 0); ++ this(p_i45078_1_, p_i45078_2_, p_i45078_3_, generateMipMaps, false, 0, NO_TEXTURE_ID); + } + -+ public Framebuffer(int p_i45078_1_, int p_i45078_2_, boolean p_i45078_3_, boolean generateMipMaps, boolean multisample, int multisamplecount) ++ public Framebuffer(int p_i45078_1_, int p_i45078_2_, boolean p_i45078_3_, boolean generateMipMaps, boolean multisample, int multisamplecount, int textureId) + { + /** END MINECRIFT */ ++ /** MINECRIFT */ this.useDepth = p_i45078_3_; this.framebufferObject = -1; - this.framebufferTexture = -1; -@@ -31,6 +59,15 @@ +- this.framebufferTexture = -1; ++ this.framebufferTexture = NO_TEXTURE_ID; ++ this.generatedFramebufferTexture = true; + this.depthBuffer = -1; + this.framebufferColor = new float[4]; + this.framebufferColor[0] = 1.0F; this.framebufferColor[1] = 1.0F; this.framebufferColor[2] = 1.0F; this.framebufferColor[3] = 0.0F; +- this.createBindFramebuffer(p_i45078_1_, p_i45078_2_); + -+ /** MINECRIFT */ + this.genMipMaps = generateMipMaps; + this.multiSample = multisample; + if (this.multiSample) { + this.multiSampleCount = multisamplecount; + this.textureType = GL32.GL_TEXTURE_2D_MULTISAMPLE; + } ++ + /** END MINECRIFT */ - this.createBindFramebuffer(p_i45078_1_, p_i45078_2_); ++ this.createBindFramebuffer(p_i45078_1_, p_i45078_2_, textureId); } -@@ -51,7 +88,9 @@ + public void createBindFramebuffer(int p_147613_1_, int p_147613_2_) + { ++/** MINECRIFT */ ++ createBindFramebuffer(p_147613_1_, p_147613_2_, NO_TEXTURE_ID); ++ } ++ ++ public void createBindFramebuffer(int p_147613_1_, int p_147613_2_, int textureId) ++ { ++/** END MINECRIFT */ + if (!OpenGlHelper.isFramebufferEnabled()) + { + this.framebufferWidth = p_147613_1_; +@@ -50,8 +98,10 @@ + this.deleteFramebuffer(); } - this.createFramebuffer(p_147613_1_, p_147613_2_); +- this.createFramebuffer(p_147613_1_, p_147613_2_); - this.checkFramebufferComplete(); ++ this.createFramebuffer(p_147613_1_, p_147613_2_, textureId); + /** MINECRIFT * + this.checkFramebufferComplete(); + ** END MINECRIFT */ OpenGlHelper.func_153171_g(OpenGlHelper.field_153198_e, 0); } } -@@ -97,43 +136,81 @@ +@@ -68,8 +118,9 @@ + OpenGlHelper.func_153184_g(this.depthBuffer); + this.depthBuffer = -1; + } +- +- if (this.framebufferTexture > -1) ++ /* MINECRIFT */ ++ if (this.framebufferTexture > NO_TEXTURE_ID && this.generatedFramebufferTexture == true) ++ /* END MINECRIFT */ + { + TextureUtil.deleteTexture(this.framebufferTexture); + this.framebufferTexture = -1; +@@ -86,6 +137,13 @@ + + public void createFramebuffer(int p_147605_1_, int p_147605_2_) + { ++/** MINECRIFT */ ++ createFramebuffer(p_147605_1_, p_147605_2_, NO_TEXTURE_ID); ++ } ++ ++ public void createFramebuffer(int p_147605_1_, int p_147605_2_, int textureId) ++ { ++/** END MINECRIFT */ + this.framebufferWidth = p_147605_1_; + this.framebufferHeight = p_147605_2_; + this.framebufferTextureWidth = p_147605_1_; +@@ -97,43 +155,90 @@ } else { - this.framebufferObject = OpenGlHelper.func_153165_e(); +- this.framebufferTexture = TextureUtil.glGenTextures(); + /** MINECRIFT */ + this.framebufferObject = OpenGlHelper.func_153165_e(); // GL30.glGenFramebuffers() - this.framebufferTexture = TextureUtil.glGenTextures(); ++ if (textureId != NO_TEXTURE_ID) { ++ // generate texture ++ this.framebufferTexture = TextureUtil.glGenTextures(); ++ this.generatedFramebufferTexture = true; ++ } ++ else { ++ // Use supplied texture ID ++ this.framebufferTexture = textureId; ++ this.generatedFramebufferTexture = false; ++ } if (this.useDepth) { @@ -139,15 +197,15 @@ + /** END MINECRIFT */ } + -+ } -+ + } + + /** MINECRIFT */ + public void genMipMaps() + { + GL30.glGenerateMipmap(this.textureType); // TODO: Minecrift - Check GLContext capabilities - } ++ } + /** END MINECRIFT */ - ++ public void setFramebufferFilter(int p_147607_1_) { if (OpenGlHelper.isFramebufferEnabled()) @@ -172,7 +230,7 @@ } } -@@ -159,6 +236,12 @@ +@@ -159,6 +264,12 @@ { throw new RuntimeException("GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER"); } @@ -185,7 +243,7 @@ else { throw new RuntimeException("glCheckFramebufferStatus returned unknown status:" + var1); -@@ -168,18 +251,22 @@ +@@ -168,18 +279,22 @@ public void bindFramebufferTexture() { @@ -210,7 +268,7 @@ } public void bindFramebuffer(boolean p_147610_1_) -@@ -213,6 +300,13 @@ +@@ -213,6 +328,13 @@ public void framebufferRender(int p_147615_1_, int p_147615_2_) { @@ -224,7 +282,7 @@ if (OpenGlHelper.isFramebufferEnabled()) { GL11.glColorMask(true, true, true, false); -@@ -224,8 +318,10 @@ +@@ -224,8 +346,10 @@ GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); GL11.glTranslatef(0.0F, 0.0F, -2000.0F); @@ -237,7 +295,7 @@ GL11.glDisable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_ALPHA_TEST); GL11.glDisable(GL11.GL_BLEND); -@@ -265,4 +361,44 @@ +@@ -265,4 +389,44 @@ GL11.glClear(var1); this.unbindFramebuffer(); } diff --git a/src/com/mtbs3d/minecrift/api/IStereoProvider.java b/src/com/mtbs3d/minecrift/api/IStereoProvider.java index 26f5e325..81346bcc 100644 --- a/src/com/mtbs3d/minecrift/api/IStereoProvider.java +++ b/src/com/mtbs3d/minecrift/api/IStereoProvider.java @@ -36,6 +36,8 @@ public EyeRenderParams configureRenderingDualTexture(Sizei InTexture1Size, FovPort RightFov, float worldScale); + public SwapTextureSet createSwapTextureSet(int width, int height); + public void resetRenderConfig(); public EyeType eyeRenderOrder(int index); diff --git a/src/com/mtbs3d/minecrift/provider/NullStereoRenderer.java b/src/com/mtbs3d/minecrift/provider/NullStereoRenderer.java index 75e724ca..a71fee42 100644 --- a/src/com/mtbs3d/minecrift/provider/NullStereoRenderer.java +++ b/src/com/mtbs3d/minecrift/provider/NullStereoRenderer.java @@ -180,4 +180,10 @@ public double getCurrentTimeSecs() { return System.nanoTime() / 1000000000d; } + + @Override + public SwapTextureSet createSwapTextureSet(int width, int height) + { + return null; + } }