Skip to content

Commit

Permalink
Merge branch '1.20.1' of https://github.com/IrisShaders/Iris into 1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
dima-dencep committed Feb 1, 2024
2 parents b613f2e + c6c2608 commit 1051549
Show file tree
Hide file tree
Showing 77 changed files with 989 additions and 725 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package net.coderbot.batchedentityrendering.mixin;

import com.mojang.blaze3d.vertex.BufferBuilder;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

import java.util.Map;

@Mixin(MultiBufferSource.BufferSource.class)
public interface BufferSourceAccessor {
@Accessor
Map<RenderType, BufferBuilder> getFixedBuffers();
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ public class MixinRenderBuffers implements RenderBuffersExt, MemoryTrackingRende
@Final
private ChunkBufferBuilderPack fixedBufferPack;

@Shadow
@Final
private SortedMap<RenderType, BufferBuilder> fixedBuffers;

@Inject(method = "bufferSource", at = @At("HEAD"), cancellable = true)
private void batchedentityrendering$replaceBufferSource(CallbackInfoReturnable<MultiBufferSource.BufferSource> cir) {
if (begins == 0) {
Expand Down Expand Up @@ -125,8 +121,9 @@ public int getMaxBegins() {
@Override
public void freeAndDeleteBuffers() {
buffered.freeAndDeleteBuffer();
((ChunkBufferBuilderPackAccessor) this.fixedBufferPack).getBuilders().values().forEach(bufferBuilder -> ((MemoryTrackingBuffer) bufferBuilder).freeAndDeleteBuffer());
fixedBuffers.values().forEach(bufferBuilder -> ((MemoryTrackingBuffer) bufferBuilder).freeAndDeleteBuffer());
((SectionBufferBuilderPackAccessor) this.fixedBufferPack).getBuilders().values().forEach(bufferBuilder -> ((MemoryTrackingBuffer) bufferBuilder).freeAndDeleteBuffer());
((BufferSourceAccessor) bufferSource).getFixedBuffers().forEach((renderType, bufferBuilder) -> ((MemoryTrackingBuffer) bufferBuilder).freeAndDeleteBuffer());
((BufferSourceAccessor) bufferSource).getFixedBuffers().clear();
((MemoryTrackingBuffer) ((OutlineBufferSourceAccessor) outlineBufferSource).getOutlineBufferSource()).freeAndDeleteBuffer();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.Map;

@Mixin(ChunkBufferBuilderPack.class)
public interface ChunkBufferBuilderPackAccessor {
public interface SectionBufferBuilderPackAccessor {
@Accessor
Map<RenderType, BufferBuilder> getBuilders();
}
26 changes: 17 additions & 9 deletions src/main/java/net/coderbot/iris/Iris.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.base.Throwables;
import com.mojang.blaze3d.platform.GlDebug;
import com.mojang.blaze3d.platform.InputConstants;
import com.sun.jna.platform.unix.LibC;
import net.coderbot.iris.config.IrisConfig;
import net.coderbot.iris.gl.GLDebug;
import net.coderbot.iris.gl.shader.ShaderCompileException;
Expand All @@ -27,6 +28,7 @@
import net.coderbot.iris.texture.pbr.PBRTextureManager;
import net.minecraft.ChatFormatting;
import net.minecraft.SharedConstants;
import net.minecraft.Util;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
Expand All @@ -46,6 +48,7 @@
import net.minecraftforge.network.NetworkConstants;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.system.Configuration;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -89,9 +92,10 @@ public class Iris {
private static PipelineManager pipelineManager;
private static IrisConfig irisConfig;
private static FileSystem zipFileSystem;
private static KeyMapping reloadKeybind;
private static KeyMapping toggleShadersKeybind;
private static KeyMapping shaderpackScreenKeybind;
private static final KeyMapping reloadKeybind = new KeyMapping("iris.keybind.reload", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_R, "iris.keybinds");
private static final KeyMapping toggleShadersKeybind = new KeyMapping("iris.keybind.toggleShaders", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_K, "iris.keybinds");
private static final KeyMapping shaderpackScreenKeybind = new KeyMapping("iris.keybind.shaderPackSelection", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_O, "iris.keybinds");
private static final KeyMapping wireframeKeybind = new KeyMapping("iris.keybind.wireframe", InputConstants.Type.KEYSYM, InputConstants.UNKNOWN.getValue(), "iris.keybinds");

private static final Map<String, String> shaderPackOptionQueue = new HashMap<>();
// Flag variable used when reloading
Expand All @@ -103,7 +107,7 @@ public class Iris {
private static boolean fallback;

// Change this for snapshots!
private static String backupVersionNumber = "1.19.4";
private static String backupVersionNumber = "1.20.3";

public Iris() {
try {
Expand All @@ -127,11 +131,7 @@ public Iris() {
*
* <p>This is called right before options are loaded, so we can add key bindings here.</p>
*/
public void onEarlyInitialize() {
reloadKeybind = new KeyMapping("iris.keybind.reload", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_R, "iris.keybinds");
toggleShadersKeybind = new KeyMapping("iris.keybind.toggleShaders", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_K, "iris.keybinds");
shaderpackScreenKeybind = new KeyMapping("iris.keybind.shaderPackSelection", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_O, "iris.keybinds");

public static void onEarlyInitialize() {
try {
if (!Files.exists(getShaderpacksDirectory())) {
Files.createDirectories(getShaderpacksDirectory());
Expand Down Expand Up @@ -230,9 +230,17 @@ public static void handleKeybinds(Minecraft minecraft) {
}
} else if (shaderpackScreenKeybind.consumeClick()) {
minecraft.setScreen(new ShaderPackScreen(null));
} else if (wireframeKeybind.consumeClick()) {
if (irisConfig.areDebugOptionsEnabled() && minecraft.player != null && !Minecraft.getInstance().isLocalServer()) {
minecraft.player.displayClientMessage(Component.literal("No cheating; wireframe only in singleplayer!"), false);
}
}
}

public static boolean shouldActivateWireframe() {
return irisConfig.areDebugOptionsEnabled() && wireframeKeybind.isDown();
}

public static void toggleShaders(Minecraft minecraft, boolean enabled) throws IOException {
irisConfig.setShadersEnabled(enabled);
irisConfig.save();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/coderbot/iris/features/FeatureFlags.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum FeatureFlags {
CUSTOM_IMAGES(() -> true, IrisRenderSystem::supportsImageLoadStore),
PER_BUFFER_BLENDING(() -> true, IrisRenderSystem::supportsBufferBlending),
COMPUTE_SHADERS(() -> true, IrisRenderSystem::supportsCompute),
TESSELATION_SHADERS(() -> true, IrisRenderSystem::supportsTesselation),
ENTITY_TRANSLUCENT(() -> true, () -> true),
REVERSED_CULLING(() -> true, () -> true),
SSBO(() -> true, IrisRenderSystem::supportsSSBO),
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/net/coderbot/iris/gl/IrisRenderSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class IrisRenderSystem {
private static DSAAccess dsaState;
private static boolean hasMultibind;
private static boolean supportsCompute;
private static boolean supportsTesselation;
private static int polygonMode = GL43C.GL_FILL;
private static int backupPolygonMode = GL43C.GL_FILL;
private static int[] samplers;

public static void initRenderer() {
Expand All @@ -59,6 +62,7 @@ public static void initRenderer() {
hasMultibind = GL.getCapabilities().OpenGL45 || GL.getCapabilities().GL_ARB_multi_bind;

supportsCompute = GL.getCapabilities().glDispatchCompute != MemoryUtil.NULL;
supportsTesselation = GL.getCapabilities().GL_ARB_tessellation_shader || GL.getCapabilities().OpenGL40;

samplers = new int[SamplerLimits.get().getMaxTextureUnits()];
}
Expand Down Expand Up @@ -365,6 +369,10 @@ public static boolean supportsCompute() {
return supportsCompute;
}

public static boolean supportsTesselation() {
return supportsTesselation;
}

public static int genSampler() {
return GL33C.glGenSamplers();
}
Expand Down Expand Up @@ -425,6 +433,23 @@ public static void deleteBuffers(int glId) {
GL43C.glDeleteBuffers(glId);
}

public static void setPolygonMode(int mode) {
if (mode != polygonMode) {
polygonMode = mode;
GL43C.glPolygonMode(GL43C.GL_FRONT_AND_BACK, mode);
}
}

public static void overridePolygonMode() {
backupPolygonMode = polygonMode;
setPolygonMode(GL43C.GL_FILL);
}

public static void restorePolygonMode() {
setPolygonMode(backupPolygonMode);
backupPolygonMode = GL43C.GL_FILL;
}

public interface DSAAccess {
void generateMipmaps(int texture, int target);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.coderbot.iris.gl.framebuffer;

public record ViewportData(float scale, float viewportX, float viewportY) {
private static ViewportData DEFAULT = new ViewportData(1.0f, 0.0f, 0.0f);

public static ViewportData defaultValue() {
return DEFAULT;
}
}
4 changes: 3 additions & 1 deletion src/main/java/net/coderbot/iris/gl/shader/ShaderType.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public enum ShaderType {
VERTEX(GL20.GL_VERTEX_SHADER),
GEOMETRY(GL32C.GL_GEOMETRY_SHADER),
FRAGMENT(GL20.GL_FRAGMENT_SHADER),
COMPUTE(GL43C.GL_COMPUTE_SHADER);
COMPUTE(GL43C.GL_COMPUTE_SHADER),
TESSELATION_CONTROL(GL43C.GL_TESS_CONTROL_SHADER),
TESSELATION_EVAL(GL43C.GL_TESS_EVALUATION_SHADER);

public final int id;

Expand Down
95 changes: 95 additions & 0 deletions src/main/java/net/coderbot/iris/gui/OldImageButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package net.coderbot.iris.gui;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;

@Environment(EnvType.CLIENT)
public class OldImageButton extends Button {
protected final ResourceLocation resourceLocation;
protected final int xTexStart;
protected final int yTexStart;
protected final int yDiffTex;
protected final int textureWidth;
protected final int textureHeight;

public OldImageButton(
int pImageButton0, int pInt1, int pInt2, int pInt3, int pInt4, int pInt5, ResourceLocation pResourceLocation6, Button.OnPress pButton$OnPress7
) {
this(pImageButton0, pInt1, pInt2, pInt3, pInt4, pInt5, pInt3, pResourceLocation6, 256, 256, pButton$OnPress7);
}

public OldImageButton(
int pImageButton0,
int pInt1,
int pInt2,
int pInt3,
int pInt4,
int pInt5,
int pInt6,
ResourceLocation pResourceLocation7,
Button.OnPress pButton$OnPress8
) {
this(pImageButton0, pInt1, pInt2, pInt3, pInt4, pInt5, pInt6, pResourceLocation7, 256, 256, pButton$OnPress8);
}

public OldImageButton(
int pImageButton0,
int pInt1,
int pInt2,
int pInt3,
int pInt4,
int pInt5,
int pInt6,
ResourceLocation pResourceLocation7,
int pInt8,
int pInt9,
Button.OnPress pButton$OnPress10
) {
this(pImageButton0, pInt1, pInt2, pInt3, pInt4, pInt5, pInt6, pResourceLocation7, pInt8, pInt9, pButton$OnPress10, CommonComponents.EMPTY);
}

public OldImageButton(
int pImageButton0,
int pInt1,
int pInt2,
int pInt3,
int pInt4,
int pInt5,
int pInt6,
ResourceLocation pResourceLocation7,
int pInt8,
int pInt9,
Button.OnPress pButton$OnPress10,
Component pComponent11
) {
super(pImageButton0, pInt1, pInt2, pInt3, pComponent11, pButton$OnPress10, DEFAULT_NARRATION);
this.textureWidth = pInt8;
this.textureHeight = pInt9;
this.xTexStart = pInt4;
this.yTexStart = pInt5;
this.yDiffTex = pInt6;
this.resourceLocation = pResourceLocation7;
}

@Override
public void renderWidget(GuiGraphics pImageButton0, int pInt1, int pInt2, float pFloat3) {
this.renderTexture(
pImageButton0,
this.resourceLocation,
this.getX(),
this.getY(),
this.xTexStart,
this.yTexStart,
this.yDiffTex,
this.width,
this.height,
this.textureWidth,
this.textureHeight
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,4 @@ protected void init() {

widget.visitWidgets(this::addRenderableWidget);
}

@Override
public void render(GuiGraphics guiGraphics, int i, int j, float f) {
if (this.minecraft.level == null) {
this.renderBackground(guiGraphics);
} else {
guiGraphics.fillGradient(0, 0, width, height, 0x4F232323, 0x4F232323);
}
super.render(guiGraphics, i, j, f);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.coderbot.iris.Iris;
import net.coderbot.iris.gui.GuiUtil;
import net.coderbot.iris.gui.NavigationController;
import net.coderbot.iris.gui.OldImageButton;
import net.coderbot.iris.gui.element.ShaderPackOptionList;
import net.coderbot.iris.gui.element.ShaderPackSelectionList;
import net.coderbot.iris.gui.element.widget.AbstractElementWidget;
Expand Down Expand Up @@ -263,7 +264,7 @@ protected void init() {
x = (int) (endOfLastButton + (freeSpace / 2.0f)) - 10;
}

ImageButton showHideButton = new ImageButton(
OldImageButton showHideButton = new OldImageButton(
x, this.height - 39,
20, 20,
this.guiHidden ? 20 : 0, 146, 20,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.phys.Vec3;
import org.joml.Quaternionf;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public class MixinGameRenderer {
private ArrayList<Program> iris$reloadGeometryShaders() {
ArrayList<Program> programs = Lists.newArrayList();
programs.addAll(IrisProgramTypes.GEOMETRY.getPrograms().values());
programs.addAll(IrisProgramTypes.TESS_CONTROL.getPrograms().values());
programs.addAll(IrisProgramTypes.TESS_EVAL.getPrograms().values());
return programs;
}

Expand Down Expand Up @@ -205,6 +207,7 @@ public class MixinGameRenderer {
"getRendertypeEntityTranslucentShader",
"getRendertypeEntityTranslucentCullShader",
"getRendertypeItemEntityTranslucentCullShader",
"getRendertypeBreezeWindShader",
"getRendertypeEntityNoOutlineShader"
}, at = @At("HEAD"), cancellable = true)
private static void iris$overrideEntityTranslucentShader(CallbackInfoReturnable<ShaderInstance> cir) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import com.mojang.blaze3d.platform.GlStateManager;
import net.coderbot.iris.gl.blending.DepthColorStorage;
import net.coderbot.iris.vertices.ImmediateState;
import org.lwjgl.opengl.GL43C;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(value = GlStateManager.class, remap = false)
Expand All @@ -24,4 +27,18 @@ public class MixinGlStateManager_DepthColorOverride {
ci.cancel();
}
}

@Redirect(method = "_drawElements", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glDrawElements(IIIJ)V"), remap = false)
private static void iris$modify(int mode, int count, int type, long indices) {
if (mode == GL43C.GL_TRIANGLES && ImmediateState.usingTessellation) {
mode = GL43C.GL_PATCHES;
}

GL43C.glDrawElements(mode, count, type, indices);
}

@Inject(method = "_glUseProgram", at = @At("TAIL"), remap = false)
private static void iris$resetTessellation(int pInt0, CallbackInfo ci) {
ImmediateState.usingTessellation = false;
}
}
Loading

0 comments on commit 1051549

Please sign in to comment.