mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-10-29 12:57:46 +00:00
Unify Iris integrations
Iris now has built-in support for NeoForge, so we can use the same integration on both. We also re-enable Forge's client tests, and test Iris there too. Fixes #1967
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
// SPDX-FileCopyrightText: 2022 The CC: Tweaked Developers
|
||||
//
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
package dan200.computercraft.client.integration;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import dan200.computercraft.client.render.RenderTypes;
|
||||
import dan200.computercraft.client.render.text.DirectFixedWidthFontRenderer;
|
||||
import dan200.computercraft.shared.platform.PlatformHelper;
|
||||
import net.irisshaders.iris.api.v0.IrisApi;
|
||||
import net.irisshaders.iris.api.v0.IrisTextVertexSink;
|
||||
import net.minecraft.util.FastColor;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Optional;
|
||||
import java.util.function.IntFunction;
|
||||
|
||||
@AutoService(ShaderMod.Provider.class)
|
||||
public class IrisShaderMod implements ShaderMod.Provider {
|
||||
@Override
|
||||
public Optional<ShaderMod> get() {
|
||||
return PlatformHelper.get().isModLoaded("iris") ? Optional.of(new Impl()) : Optional.empty();
|
||||
}
|
||||
|
||||
private static final class Impl extends ShaderMod {
|
||||
@Override
|
||||
public boolean isRenderingShadowPass() {
|
||||
return IrisApi.getInstance().isRenderingShadowPass();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DirectFixedWidthFontRenderer.QuadEmitter getQuadEmitter(int vertexCount, IntFunction<ByteBuffer> makeBuffer) {
|
||||
return IrisApi.getInstance().getMinorApiRevision() >= 1
|
||||
? new IrisQuadEmitter(vertexCount, makeBuffer)
|
||||
: super.getQuadEmitter(vertexCount, makeBuffer);
|
||||
}
|
||||
|
||||
private static final class IrisQuadEmitter implements DirectFixedWidthFontRenderer.QuadEmitter {
|
||||
private final IrisTextVertexSink sink;
|
||||
|
||||
private IrisQuadEmitter(int vertexCount, IntFunction<ByteBuffer> makeBuffer) {
|
||||
sink = IrisApi.getInstance().createTextVertexSink(vertexCount, makeBuffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexFormat format() {
|
||||
return sink.getUnderlyingVertexFormat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuffer buffer() {
|
||||
return sink.getUnderlyingByteBuffer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void quad(float x1, float y1, float x2, float y2, float z, int colour, float u1, float v1, float u2, float v2) {
|
||||
sink.quad(x1, y1, x2, y2, z, FastColor.ABGR32.fromArgb32(colour), u1, v1, u2, v2, RenderTypes.FULL_BRIGHT_LIGHTMAP);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,14 @@ public interface PlatformHelper {
|
||||
return instance == null ? Services.raise(PlatformHelper.class, Instance.ERROR) : instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the specified mod is loaded.
|
||||
*
|
||||
* @param id The id of the mod to check.
|
||||
* @return Whether this mod is loaded.
|
||||
*/
|
||||
boolean isModLoaded(String id);
|
||||
|
||||
/**
|
||||
* Create a new config builder.
|
||||
*
|
||||
|
||||
@@ -49,6 +49,11 @@ import java.util.function.Predicate;
|
||||
|
||||
@AutoService({ PlatformHelper.class, ComputerCraftAPIService.class })
|
||||
public class TestPlatformHelper extends AbstractComputerCraftAPI implements PlatformHelper {
|
||||
@Override
|
||||
public boolean isModLoaded(String id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigFile.Builder createConfigBuilder() {
|
||||
throw new UnsupportedOperationException("Cannot create config file inside tests");
|
||||
|
||||
Reference in New Issue
Block a user