mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-14 04:00:30 +00:00
Use the VBO monitor renderer by default
Historically, the VBO was an order of magnitude slower than the TBO
renderer. However, as of fccca22d3f
, the
difference is much smaller now. While TBOs /are/ still faster, this only
has a measurable impact in extreme stress tests, and so isn't worth the
occasional issues which occur.
I'm still keeping the code around for now: I'm incredibly fond of it,
even three years later. I may end up re-evaluating this the next time
Minecraft's rendering code changes :D.
This also adds a line to the debug screen showing the current monitor
renderer, though maybe less useful now that almost everyone will be
using VBOs!
This commit is contained in:
parent
53619a64b5
commit
a5bda7454a
@ -12,6 +12,7 @@ import dan200.computercraft.client.pocket.ClientPocketComputers;
|
||||
import dan200.computercraft.client.render.CableHighlightRenderer;
|
||||
import dan200.computercraft.client.render.PocketItemRenderer;
|
||||
import dan200.computercraft.client.render.PrintoutItemRenderer;
|
||||
import dan200.computercraft.client.render.monitor.MonitorBlockEntityRenderer;
|
||||
import dan200.computercraft.client.render.monitor.MonitorHighlightRenderer;
|
||||
import dan200.computercraft.client.render.monitor.MonitorRenderState;
|
||||
import dan200.computercraft.client.sound.SpeakerManager;
|
||||
@ -142,7 +143,7 @@ public final class ClientHooks {
|
||||
*
|
||||
* @param addText A callback which adds a single line of text.
|
||||
*/
|
||||
public static void addDebugInfo(Consumer<String> addText) {
|
||||
public static void addBlockDebugInfo(Consumer<String> addText) {
|
||||
var minecraft = Minecraft.getInstance();
|
||||
if (!minecraft.options.renderDebug || minecraft.level == null) return;
|
||||
if (minecraft.hitResult == null || minecraft.hitResult.getType() != HitResult.Type.BLOCK) return;
|
||||
@ -168,6 +169,17 @@ public final class ClientHooks {
|
||||
if (upgrade != null) out.accept(String.format("Upgrade[%s]: %s", side, upgrade.getUpgradeID()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add additional information about the game to the debug screen.
|
||||
*
|
||||
* @param addText A callback which adds a single line of text.
|
||||
*/
|
||||
public static void addGameDebugInfo(Consumer<String> addText) {
|
||||
if (MonitorBlockEntityRenderer.hasRenderedThisFrame()) {
|
||||
addText.accept("[CC:T] Monitor renderer: " + MonitorBlockEntityRenderer.currentRenderer());
|
||||
}
|
||||
}
|
||||
|
||||
public static @Nullable BlockState getBlockBreakingState(BlockState state, BlockPos pos) {
|
||||
// Only apply to cables which have both a cable and modem
|
||||
if (state.getBlock() != ModRegistry.Blocks.CABLE.get()
|
||||
|
@ -1,32 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.client.integration;
|
||||
|
||||
/**
|
||||
* Detect whether Optifine is installed.
|
||||
*/
|
||||
public final class Optifine {
|
||||
private static final boolean LOADED;
|
||||
|
||||
static {
|
||||
boolean loaded;
|
||||
try {
|
||||
Class.forName("optifine.Installer", false, Optifine.class.getClassLoader());
|
||||
loaded = true;
|
||||
} catch (ReflectiveOperationException | LinkageError ignore) {
|
||||
loaded = false;
|
||||
}
|
||||
|
||||
LOADED = loaded;
|
||||
}
|
||||
|
||||
private Optifine() {
|
||||
}
|
||||
|
||||
public static boolean isLoaded() {
|
||||
return LOADED;
|
||||
}
|
||||
}
|
@ -22,15 +22,6 @@ public class ShaderMod {
|
||||
return Storage.INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if shaders may be used in the current session.
|
||||
*
|
||||
* @return Whether a shader mod is loaded.
|
||||
*/
|
||||
public boolean isShaderMod() {
|
||||
return Optifine.isLoaded();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether we're currently rendering shadows. Rendering may fall back to a faster but less detailed pass.
|
||||
*
|
||||
|
@ -31,12 +31,9 @@ import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import org.joml.Matrix3f;
|
||||
import org.joml.Matrix4f;
|
||||
import org.lwjgl.opengl.GL;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
import org.lwjgl.opengl.GL31;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.nio.ByteBuffer;
|
||||
@ -47,8 +44,6 @@ import static dan200.computercraft.client.render.text.FixedWidthFontRenderer.FON
|
||||
import static dan200.computercraft.core.util.Nullability.assertNonNull;
|
||||
|
||||
public class MonitorBlockEntityRenderer implements BlockEntityRenderer<MonitorBlockEntity> {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MonitorBlockEntityRenderer.class);
|
||||
|
||||
/**
|
||||
* {@link MonitorBlockEntity#RENDER_MARGIN}, but a tiny bit of additional padding to ensure that there is no space between
|
||||
* the monitor frame and contents.
|
||||
@ -59,6 +54,8 @@ public class MonitorBlockEntityRenderer implements BlockEntityRenderer<MonitorBl
|
||||
|
||||
private static @Nullable ByteBuffer backingBuffer;
|
||||
|
||||
private static long lastFrame = -1;
|
||||
|
||||
public MonitorBlockEntityRenderer(BlockEntityRendererProvider.Context context) {
|
||||
}
|
||||
|
||||
@ -80,6 +77,7 @@ public class MonitorBlockEntityRenderer implements BlockEntityRenderer<MonitorBl
|
||||
return;
|
||||
}
|
||||
|
||||
lastFrame = renderFrame;
|
||||
renderState.lastRenderFrame = renderFrame;
|
||||
renderState.lastRenderPos = monitorPos;
|
||||
|
||||
@ -261,6 +259,14 @@ public class MonitorBlockEntityRenderer implements BlockEntityRenderer<MonitorBl
|
||||
return Config.monitorDistance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if any monitors were rendered this frame.
|
||||
*
|
||||
* @return Whether any monitors were rendered.
|
||||
*/
|
||||
public static boolean hasRenderedThisFrame() {
|
||||
return FrameInfo.getRenderFrame() == lastFrame;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current renderer to use.
|
||||
@ -274,16 +280,6 @@ public class MonitorBlockEntityRenderer implements BlockEntityRenderer<MonitorBl
|
||||
}
|
||||
|
||||
private static MonitorRenderer bestRenderer() {
|
||||
if (!GL.getCapabilities().OpenGL31) {
|
||||
LOG.warn("Texture buffers are not supported on your graphics card. Falling back to VBO monitor renderer.");
|
||||
return MonitorRenderer.VBO;
|
||||
}
|
||||
|
||||
if (ShaderMod.get().isShaderMod()) {
|
||||
LOG.warn("A shader mod is loaded, assuming shaders are being used. Falling back to VBO monitor renderer.");
|
||||
return MonitorRenderer.VBO;
|
||||
}
|
||||
|
||||
return MonitorRenderer.TBO;
|
||||
return MonitorRenderer.VBO;
|
||||
}
|
||||
}
|
||||
|
@ -30,11 +30,6 @@ public class IrisShaderMod implements ShaderMod.Provider {
|
||||
return IrisApi.getInstance().isRenderingShadowPass();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShaderMod() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DirectFixedWidthFontRenderer.QuadEmitter getQuadEmitter(int vertexCount, IntFunction<ByteBuffer> makeBuffer) {
|
||||
return IrisApi.getInstance().getMinorApiRevision() >= 1
|
||||
|
@ -18,7 +18,13 @@ import java.util.List;
|
||||
class DebugScreenOverlayMixin {
|
||||
@Inject(method = "getSystemInformation", at = @At("RETURN"))
|
||||
@SuppressWarnings("UnusedMethod")
|
||||
private void appendDebugInfo(CallbackInfoReturnable<List<String>> cir) {
|
||||
ClientHooks.addDebugInfo(cir.getReturnValue()::add);
|
||||
private void appendBlockDebugInfo(CallbackInfoReturnable<List<String>> cir) {
|
||||
ClientHooks.addBlockDebugInfo(cir.getReturnValue()::add);
|
||||
}
|
||||
|
||||
@Inject(method = "getGameInformation", at = @At("RETURN"))
|
||||
@SuppressWarnings("UnusedMethod")
|
||||
private void appendGameDebugInfo(CallbackInfoReturnable<List<String>> cir) {
|
||||
ClientHooks.addGameDebugInfo(cir.getReturnValue()::add);
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,8 @@ public final class ForgeClientHooks {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onRenderText(CustomizeGuiOverlayEvent.DebugText event) {
|
||||
ClientHooks.addDebugInfo(event.getRight()::add);
|
||||
ClientHooks.addGameDebugInfo(event.getLeft()::add);
|
||||
ClientHooks.addBlockDebugInfo(event.getRight()::add);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
@ -33,11 +33,6 @@ public class IrisShaderMod implements ShaderMod.Provider {
|
||||
return IrisApi.getInstance().isRenderingShadowPass();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShaderMod() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DirectFixedWidthFontRenderer.QuadEmitter getQuadEmitter(int vertexCount, IntFunction<ByteBuffer> makeBuffer) {
|
||||
return IrisApi.getInstance().getMinorApiRevision() >= 1
|
||||
|
Loading…
Reference in New Issue
Block a user