Only update uniforms when ODS shader is bound (fixes GL errors)

This commit is contained in:
Jonas Herzig
2019-03-10 16:07:41 +01:00
parent cdcd6f6893
commit 5f0bd1cf5d
2 changed files with 38 additions and 31 deletions

View File

@@ -56,3 +56,5 @@ replayModVersions.each { version ->
buildFileName = '../common.gradle' buildFileName = '../common.gradle'
} }
} }
include ':mixin-hack'

View File

@@ -1,6 +1,5 @@
package com.replaymod.render.capturer; package com.replaymod.render.capturer;
import com.replaymod.core.versions.MCVer;
import com.replaymod.render.RenderSettings; import com.replaymod.render.RenderSettings;
import com.replaymod.render.frame.CubicOpenGlFrame; import com.replaymod.render.frame.CubicOpenGlFrame;
import com.replaymod.render.frame.ODSOpenGlFrame; import com.replaymod.render.frame.ODSOpenGlFrame;
@@ -8,12 +7,10 @@ import com.replaymod.render.frame.OpenGlFrame;
import com.replaymod.render.rendering.FrameCapturer; import com.replaymod.render.rendering.FrameCapturer;
import com.replaymod.render.shader.Program; import com.replaymod.render.shader.Program;
import de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension; import de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension;
import net.minecraft.client.Minecraft;
import net.minecraft.crash.CrashReport; import net.minecraft.crash.CrashReport;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
//#if MC>=10800 //#if MC>=10800
import net.minecraft.client.renderer.GlStateManager;
import static net.minecraft.client.renderer.GlStateManager.*; import static net.minecraft.client.renderer.GlStateManager.*;
//#else //#else
//$$ import com.replaymod.render.hooks.GLStateTracker.BooleanState; //$$ import com.replaymod.render.hooks.GLStateTracker.BooleanState;
@@ -36,9 +33,7 @@ public class ODSFrameCapturer implements FrameCapturer<ODSOpenGlFrame> {
private final Program.Uniform leftEyeVariable; private final Program.Uniform leftEyeVariable;
private final BooleanState[] previousStates = new BooleanState[3]; private final BooleanState[] previousStates = new BooleanState[3];
private final BooleanState previousFogState; private BooleanState previousFogState;
private final Minecraft mc = MCVer.getMinecraft();
public ODSFrameCapturer(WorldRenderer worldRenderer, final RenderInfo renderInfo, int frameSize) { public ODSFrameCapturer(WorldRenderer worldRenderer, final RenderInfo renderInfo, int frameSize) {
RenderInfo fakeInfo = new RenderInfo() { RenderInfo fakeInfo = new RenderInfo() {
@@ -62,9 +57,9 @@ public class ODSFrameCapturer implements FrameCapturer<ODSOpenGlFrame> {
@Override @Override
public float updateForNextFrame() { public float updateForNextFrame() {
if (call++ % 2 == 0) { if (call++ % 2 == 0) {
shaderProgram.stopUsing(); unbindProgram();
partialTicks = renderInfo.updateForNextFrame(); partialTicks = renderInfo.updateForNextFrame();
shaderProgram.use(); bindProgram();
} }
return partialTicks; return partialTicks;
} }
@@ -78,9 +73,15 @@ public class ODSFrameCapturer implements FrameCapturer<ODSOpenGlFrame> {
right = new CubicStereoFrameCapturer(worldRenderer, fakeInfo, frameSize); right = new CubicStereoFrameCapturer(worldRenderer, fakeInfo, frameSize);
try { try {
shaderProgram = new Program(vertexResource, fragmentResource); shaderProgram = new Program(vertexResource, fragmentResource);
shaderProgram.use();
leftEyeVariable = shaderProgram.getUniformVariable("leftEye"); leftEyeVariable = shaderProgram.getUniformVariable("leftEye");
directionVariable = shaderProgram.getUniformVariable("direction"); directionVariable = shaderProgram.getUniformVariable("direction");
} catch (Exception e) {
throw newReportedException(CrashReport.makeCrashReport(e, "Creating ODS shaders"));
}
}
private void bindProgram() {
shaderProgram.use();
setTexture("texture", 0); setTexture("texture", 0);
setTexture("lightMap", 1); setTexture("lightMap", 1);
linkState(0, "textureEnabled"); linkState(0, "textureEnabled");
@@ -90,16 +91,23 @@ public class ODSFrameCapturer implements FrameCapturer<ODSOpenGlFrame> {
previousFogState = fog(); previousFogState = fog();
uniform.set(previousFogState.currentState); uniform.set(previousFogState.currentState);
fog(new BooleanState(previousFogState.capability) { fog(new BooleanState(previousFogState.capability) {
{ currentState = previousFogState.currentState; }
@Override @Override
public void setState(boolean state) { public void setState(boolean state) {
super.setState(state); super.setState(state);
uniform.set(state); uniform.set(state);
} }
}); });
shaderProgram.stopUsing();
} catch (Exception e) {
throw newReportedException(CrashReport.makeCrashReport(e, "Creating ODS shaders"));
} }
private void unbindProgram() {
for (int i = 0; i < previousStates.length; i++) {
previousStates[i].currentState = texture2DState(i).currentState;
texture2DState(i, previousStates[i]);
}
previousFogState.currentState = fog().currentState;
fog(previousFogState);
shaderProgram.stopUsing();
} }
private void setTexture(String texture, int i) { private void setTexture(String texture, int i) {
@@ -111,6 +119,7 @@ public class ODSFrameCapturer implements FrameCapturer<ODSOpenGlFrame> {
previousStates[id] = texture2DState(id); previousStates[id] = texture2DState(id);
uniform.set(previousStates[id].currentState); uniform.set(previousStates[id].currentState);
texture2DState(id, new BooleanState(previousStates[id].capability) { texture2DState(id, new BooleanState(previousStates[id].capability) {
{ currentState = previousStates[id].currentState; }
@Override @Override
public void setState(boolean state) { public void setState(boolean state) {
super.setState(state); super.setState(state);
@@ -126,12 +135,12 @@ public class ODSFrameCapturer implements FrameCapturer<ODSOpenGlFrame> {
@Override @Override
public ODSOpenGlFrame process() { public ODSOpenGlFrame process() {
shaderProgram.use(); bindProgram();
leftEyeVariable.set(true); leftEyeVariable.set(true);
CubicOpenGlFrame leftFrame = left.process(); CubicOpenGlFrame leftFrame = left.process();
leftEyeVariable.set(false); leftEyeVariable.set(false);
CubicOpenGlFrame rightFrame = right.process(); CubicOpenGlFrame rightFrame = right.process();
shaderProgram.stopUsing(); unbindProgram();
if (leftFrame != null && rightFrame != null) { if (leftFrame != null && rightFrame != null) {
return new ODSOpenGlFrame(leftFrame, rightFrame); return new ODSOpenGlFrame(leftFrame, rightFrame);
@@ -144,10 +153,6 @@ public class ODSFrameCapturer implements FrameCapturer<ODSOpenGlFrame> {
left.close(); left.close();
right.close(); right.close();
shaderProgram.delete(); shaderProgram.delete();
for (int i = 0; i < previousStates.length; i++) {
texture2DState(i, previousStates[i]);
}
fog(previousFogState);
} }
private class CubicStereoFrameCapturer extends CubicPboOpenGlFrameCapturer { private class CubicStereoFrameCapturer extends CubicPboOpenGlFrameCapturer {