Add compatibility for GLSL Shaders
This commit is contained in:
@@ -0,0 +1,52 @@
|
|||||||
|
package com.replaymod.compat.shaders.mixin;
|
||||||
|
|
||||||
|
import com.replaymod.replay.ReplayHandler;
|
||||||
|
import com.replaymod.replay.ReplayModReplay;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.EntityRenderer;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
@Mixin(EntityRenderer.class)
|
||||||
|
public abstract class MixinShaderEntityRenderer {
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
public Minecraft mc;
|
||||||
|
|
||||||
|
private static Field replayModCompat_frameTimeCounterField = null;
|
||||||
|
|
||||||
|
static {
|
||||||
|
replayModCompat_initFrameTimeCounterField();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void replayModCompat_initFrameTimeCounterField() {
|
||||||
|
try {
|
||||||
|
replayModCompat_frameTimeCounterField = Class.forName("shadersmod.client.Shaders")
|
||||||
|
.getDeclaredField("frameTimeCounter");
|
||||||
|
replayModCompat_frameTimeCounterField.setAccessible(true);
|
||||||
|
} catch (ClassNotFoundException ignore) {
|
||||||
|
// no shaders mod installed
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
// the field wasn't found. Has it been renamed?
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "renderWorld", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;enableDepth()V"))
|
||||||
|
private void replayModCompat_updateShaderFrameTimeCounter(CallbackInfo ignore) {
|
||||||
|
if (replayModCompat_frameTimeCounterField != null) {
|
||||||
|
ReplayHandler replayHandler = ReplayModReplay.instance.getReplayHandler();
|
||||||
|
float timestamp = replayHandler.getReplaySender().currentTimeStamp() / 1000f % 3600f;
|
||||||
|
try {
|
||||||
|
replayModCompat_frameTimeCounterField.set(null, timestamp);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@ public class LoadingPlugin implements IFMLLoadingPlugin {
|
|||||||
MixinEnvironment.getDefaultEnvironment().addConfiguration("mixins.recording.replaymod.json");
|
MixinEnvironment.getDefaultEnvironment().addConfiguration("mixins.recording.replaymod.json");
|
||||||
MixinEnvironment.getDefaultEnvironment().addConfiguration("mixins.render.replaymod.json");
|
MixinEnvironment.getDefaultEnvironment().addConfiguration("mixins.render.replaymod.json");
|
||||||
MixinEnvironment.getDefaultEnvironment().addConfiguration("mixins.replay.replaymod.json");
|
MixinEnvironment.getDefaultEnvironment().addConfiguration("mixins.replay.replaymod.json");
|
||||||
|
MixinEnvironment.getDefaultEnvironment().addConfiguration("mixins.compat.shaders.replaymod.json");
|
||||||
|
|
||||||
CodeSource codeSource = getClass().getProtectionDomain().getCodeSource();
|
CodeSource codeSource = getClass().getProtectionDomain().getCodeSource();
|
||||||
if (codeSource != null) {
|
if (codeSource != null) {
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ import com.replaymod.render.frame.ODSOpenGlFrame;
|
|||||||
import com.replaymod.render.frame.OpenGlFrame;
|
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 net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
import net.minecraft.crash.CrashReport;
|
import net.minecraft.crash.CrashReport;
|
||||||
import net.minecraft.util.ReportedException;
|
import net.minecraft.util.ReportedException;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import org.lwjgl.util.Dimension;
|
|
||||||
import org.lwjgl.util.ReadableDimension;
|
import org.lwjgl.util.ReadableDimension;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -31,6 +31,8 @@ public class ODSFrameCapturer implements FrameCapturer<ODSOpenGlFrame> {
|
|||||||
private final BooleanState[] previousStates = new BooleanState[3];
|
private final BooleanState[] previousStates = new BooleanState[3];
|
||||||
private final BooleanState previousFogState;
|
private final BooleanState previousFogState;
|
||||||
|
|
||||||
|
private final Minecraft mc = Minecraft.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() {
|
||||||
private int call;
|
private int call;
|
||||||
@@ -143,6 +145,8 @@ public class ODSFrameCapturer implements FrameCapturer<ODSOpenGlFrame> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected OpenGlFrame renderFrame(int frameId, float partialTicks, CubicOpenGlFrameCapturer.Data captureData) {
|
protected OpenGlFrame renderFrame(int frameId, float partialTicks, CubicOpenGlFrameCapturer.Data captureData) {
|
||||||
|
resize(getFrameWidth(), getFrameHeight());
|
||||||
|
|
||||||
pushMatrix();
|
pushMatrix();
|
||||||
frameBuffer().bindFramebuffer(true);
|
frameBuffer().bindFramebuffer(true);
|
||||||
|
|
||||||
@@ -150,7 +154,7 @@ public class ODSFrameCapturer implements FrameCapturer<ODSOpenGlFrame> {
|
|||||||
enableTexture2D();
|
enableTexture2D();
|
||||||
|
|
||||||
directionVariable.set(captureData.ordinal());
|
directionVariable.set(captureData.ordinal());
|
||||||
worldRenderer.renderWorld(new Dimension(getFrameWidth(), getFrameHeight()), partialTicks, null);
|
worldRenderer.renderWorld(partialTicks, null);
|
||||||
|
|
||||||
frameBuffer().unbindFramebuffer();
|
frameBuffer().unbindFramebuffer();
|
||||||
popMatrix();
|
popMatrix();
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.replaymod.render.frame.OpenGlFrame;
|
|||||||
import com.replaymod.render.rendering.Frame;
|
import com.replaymod.render.rendering.Frame;
|
||||||
import com.replaymod.render.rendering.FrameCapturer;
|
import com.replaymod.render.rendering.FrameCapturer;
|
||||||
import com.replaymod.render.utils.ByteBufferPool;
|
import com.replaymod.render.utils.ByteBufferPool;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.OpenGlHelper;
|
import net.minecraft.client.renderer.OpenGlHelper;
|
||||||
import net.minecraft.client.shader.Framebuffer;
|
import net.minecraft.client.shader.Framebuffer;
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
@@ -24,6 +25,8 @@ public abstract class OpenGlFrameCapturer<F extends Frame, D extends CaptureData
|
|||||||
protected int framesDone;
|
protected int framesDone;
|
||||||
private Framebuffer frameBuffer;
|
private Framebuffer frameBuffer;
|
||||||
|
|
||||||
|
private final Minecraft mc = Minecraft.getMinecraft();
|
||||||
|
|
||||||
public OpenGlFrameCapturer(WorldRenderer worldRenderer, RenderInfo renderInfo) {
|
public OpenGlFrameCapturer(WorldRenderer worldRenderer, RenderInfo renderInfo) {
|
||||||
this.worldRenderer = worldRenderer;
|
this.worldRenderer = worldRenderer;
|
||||||
this.renderInfo = renderInfo;
|
this.renderInfo = renderInfo;
|
||||||
@@ -56,7 +59,7 @@ public abstract class OpenGlFrameCapturer<F extends Frame, D extends CaptureData
|
|||||||
|
|
||||||
protected Framebuffer frameBuffer() {
|
protected Framebuffer frameBuffer() {
|
||||||
if (frameBuffer == null) {
|
if (frameBuffer == null) {
|
||||||
frameBuffer = new Framebuffer(getFrameWidth(), getFrameHeight(), true);
|
frameBuffer = Minecraft.getMinecraft().getFramebuffer();
|
||||||
}
|
}
|
||||||
return frameBuffer;
|
return frameBuffer;
|
||||||
}
|
}
|
||||||
@@ -71,13 +74,15 @@ public abstract class OpenGlFrameCapturer<F extends Frame, D extends CaptureData
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected OpenGlFrame renderFrame(int frameId, float partialTicks, D captureData) {
|
protected OpenGlFrame renderFrame(int frameId, float partialTicks, D captureData) {
|
||||||
|
resize(getFrameWidth(), getFrameHeight());
|
||||||
|
|
||||||
pushMatrix();
|
pushMatrix();
|
||||||
frameBuffer().bindFramebuffer(true);
|
frameBuffer().bindFramebuffer(true);
|
||||||
|
|
||||||
clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
enableTexture2D();
|
enableTexture2D();
|
||||||
|
|
||||||
worldRenderer.renderWorld(frameSize, partialTicks, captureData);
|
worldRenderer.renderWorld(partialTicks, captureData);
|
||||||
|
|
||||||
frameBuffer().unbindFramebuffer();
|
frameBuffer().unbindFramebuffer();
|
||||||
popMatrix();
|
popMatrix();
|
||||||
@@ -102,11 +107,18 @@ public abstract class OpenGlFrameCapturer<F extends Frame, D extends CaptureData
|
|||||||
return new OpenGlFrame(frameId, new Dimension(getFrameWidth(), getFrameHeight()), buffer);
|
return new OpenGlFrame(frameId, new Dimension(getFrameWidth(), getFrameHeight()), buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void resize(int width, int height) {
|
||||||
|
if (width != mc.displayWidth || height != mc.displayHeight) {
|
||||||
|
setWindowSize(width, height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setWindowSize(int width, int height) {
|
||||||
|
mc.resize(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
worldRenderer.close();
|
worldRenderer.close();
|
||||||
if (frameBuffer != null) {
|
|
||||||
frameBuffer.deleteFramebuffer();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
package com.replaymod.render.capturer;
|
package com.replaymod.render.capturer;
|
||||||
|
|
||||||
import org.lwjgl.util.ReadableDimension;
|
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
|
|
||||||
public interface WorldRenderer extends Closeable {
|
public interface WorldRenderer extends Closeable {
|
||||||
void renderWorld(ReadableDimension displaySize, float partialTicks, CaptureData data);
|
void renderWorld(float partialTicks, CaptureData data);
|
||||||
void setOmnidirectional(boolean omnidirectional);
|
void setOmnidirectional(boolean omnidirectional);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,14 +5,12 @@ import com.replaymod.render.capturer.CaptureData;
|
|||||||
import com.replaymod.render.capturer.WorldRenderer;
|
import com.replaymod.render.capturer.WorldRenderer;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.culling.ClippingHelper;
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
|
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||||
import org.lwjgl.util.ReadableDimension;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static net.minecraft.client.renderer.GlStateManager.*;
|
|
||||||
|
|
||||||
public class EntityRendererHandler implements WorldRenderer {
|
public class EntityRendererHandler implements WorldRenderer {
|
||||||
public final Minecraft mc = Minecraft.getMinecraft();
|
public final Minecraft mc = Minecraft.getMinecraft();
|
||||||
|
|
||||||
@@ -29,39 +27,27 @@ public class EntityRendererHandler implements WorldRenderer {
|
|||||||
((IEntityRenderer) mc.entityRenderer).replayModRender_setHandler(this);
|
((IEntityRenderer) mc.entityRenderer).replayModRender_setHandler(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void withDisplaySize(int displayWidth, int displayHeight, Runnable runnable) {
|
|
||||||
final int prevWidth = mc.displayWidth;
|
|
||||||
final int prevHeight = mc.displayHeight;
|
|
||||||
mc.displayWidth = displayWidth;
|
|
||||||
mc.displayHeight = displayHeight;
|
|
||||||
|
|
||||||
runnable.run();
|
|
||||||
|
|
||||||
mc.displayWidth = prevWidth;
|
|
||||||
mc.displayHeight = prevHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderWorld(ReadableDimension displaySize, final float partialTicks, CaptureData data) {
|
public void renderWorld(final float partialTicks, CaptureData data) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
withDisplaySize(displaySize.getWidth(), displaySize.getHeight(), new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
renderWorld(partialTicks, 0);
|
renderWorld(partialTicks, 0);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void renderWorld(float partialTicks, long finishTimeNano) {
|
public void renderWorld(float partialTicks, long finishTimeNano) {
|
||||||
FMLCommonHandler.instance().onRenderTickStart(partialTicks);
|
FMLCommonHandler.instance().onRenderTickStart(partialTicks);
|
||||||
|
|
||||||
|
// the Shaders Mod does an initializing call in the EntityRenderer#renderWorld method
|
||||||
|
if (FMLClientHandler.instance().hasOptifine()) {
|
||||||
|
mc.entityRenderer.renderWorld(partialTicks, finishTimeNano);
|
||||||
|
} else {
|
||||||
mc.entityRenderer.updateLightmap(partialTicks);
|
mc.entityRenderer.updateLightmap(partialTicks);
|
||||||
|
|
||||||
enableDepth();
|
GlStateManager.enableDepth();
|
||||||
enableAlpha();
|
GlStateManager.enableAlpha();
|
||||||
alphaFunc(516, 0.5F);
|
GlStateManager.alphaFunc(516, 0.5F);
|
||||||
|
|
||||||
mc.entityRenderer.renderWorldPass(2, partialTicks, finishTimeNano);
|
mc.entityRenderer.renderWorldPass(2, partialTicks, finishTimeNano);
|
||||||
|
}
|
||||||
|
|
||||||
FMLCommonHandler.instance().onRenderTickEnd(partialTicks);
|
FMLCommonHandler.instance().onRenderTickEnd(partialTicks);
|
||||||
}
|
}
|
||||||
@@ -76,13 +62,6 @@ public class EntityRendererHandler implements WorldRenderer {
|
|||||||
this.omnidirectional = omnidirectional;
|
this.omnidirectional = omnidirectional;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class NoCullingClippingHelper extends ClippingHelper {
|
|
||||||
@Override
|
|
||||||
public boolean isBoxInFrustum(double p_78553_1_, double p_78553_3_, double p_78553_5_, double p_78553_7_, double p_78553_9_, double p_78553_11_) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface GluPerspective {
|
public interface GluPerspective {
|
||||||
void replayModRender_gluPerspective(float fovY, float aspect, float zNear, float zFar);
|
void replayModRender_gluPerspective(float fovY, float aspect, float zNear, float zFar);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import net.minecraft.client.Minecraft;
|
|||||||
import net.minecraft.client.renderer.EntityRenderer;
|
import net.minecraft.client.renderer.EntityRenderer;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
import net.minecraft.client.renderer.RenderGlobal;
|
import net.minecraft.client.renderer.RenderGlobal;
|
||||||
import net.minecraft.client.renderer.culling.Frustum;
|
|
||||||
import net.minecraft.client.settings.GameSettings;
|
import net.minecraft.client.settings.GameSettings;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
@@ -49,14 +48,6 @@ public abstract class MixinEntityRenderer implements EntityRendererHandler.IEnti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Redirect(method = "renderWorldPass", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/culling/Frustum;setPosition(DDD)V"))
|
|
||||||
public void replayModRender_createNoCullingFrustum(Frustum frustum, double x, double y, double z) {
|
|
||||||
if (replayModRender_handler != null) {
|
|
||||||
frustum.clippingHelper = new EntityRendererHandler.NoCullingClippingHelper();
|
|
||||||
}
|
|
||||||
frustum.setPosition(x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "orientCamera", at = @At("HEAD"))
|
@Inject(method = "orientCamera", at = @At("HEAD"))
|
||||||
private void replayModRender_resetRotationIfNeeded(float partialTicks, CallbackInfo ci) {
|
private void replayModRender_resetRotationIfNeeded(float partialTicks, CallbackInfo ci) {
|
||||||
if (replayModRender_handler != null) {
|
if (replayModRender_handler != null) {
|
||||||
|
|||||||
10
src/main/resources/mixins.compat.shaders.replaymod.json
Normal file
10
src/main/resources/mixins.compat.shaders.replaymod.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"required": true,
|
||||||
|
"package": "com.replaymod.compat.shaders.mixin",
|
||||||
|
"mixins": [],
|
||||||
|
"server": [],
|
||||||
|
"client": [
|
||||||
|
"MixinShaderEntityRenderer"
|
||||||
|
],
|
||||||
|
"refmap": "mixins.replaymod.refmap.json"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user