separate out some rendering logic
This commit is contained in:
+4
-4
@@ -224,8 +224,8 @@ public class BlazeDebugWireframeRenderer extends AbstractDebugWireframeRenderer
|
||||
{
|
||||
this.init();
|
||||
|
||||
if (BlazeDhTerrainRenderer.INSTANCE.dhColorTextureWrapper.isEmpty()
|
||||
|| BlazeDhTerrainRenderer.INSTANCE.dhDepthTextureWrapper.isEmpty())
|
||||
if (BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.isEmpty()
|
||||
|| BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -295,9 +295,9 @@ public class BlazeDebugWireframeRenderer extends AbstractDebugWireframeRenderer
|
||||
|
||||
try (RenderPass renderPass = commandEncoder.createRenderPass(
|
||||
this::getRenderPassName,
|
||||
BlazeDhTerrainRenderer.INSTANCE.dhColorTextureWrapper.textureView,
|
||||
BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.textureView,
|
||||
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
||||
BlazeDhTerrainRenderer.INSTANCE.dhDepthTextureWrapper.textureView,
|
||||
BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureView,
|
||||
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
||||
{
|
||||
// Bind instance data //
|
||||
|
||||
+4
-4
@@ -346,8 +346,8 @@ public class BlazeDhGenericObjectRenderer implements IDhGenericRenderer
|
||||
|
||||
//#endregion
|
||||
|
||||
if (BlazeDhTerrainRenderer.INSTANCE.dhColorTextureWrapper.isEmpty()
|
||||
|| BlazeDhTerrainRenderer.INSTANCE.dhDepthTextureWrapper.isEmpty())
|
||||
if (BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.isEmpty()
|
||||
|| BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -497,9 +497,9 @@ public class BlazeDhGenericObjectRenderer implements IDhGenericRenderer
|
||||
|
||||
try (RenderPass renderPass = COMMAND_ENCODER.createRenderPass(
|
||||
this::getRenderPassName,
|
||||
BlazeDhTerrainRenderer.INSTANCE.dhColorTextureWrapper.textureView,
|
||||
BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.textureView,
|
||||
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
||||
BlazeDhTerrainRenderer.INSTANCE.dhDepthTextureWrapper.textureView,
|
||||
BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureView,
|
||||
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
||||
{
|
||||
this.renderBoxGroupInstanced(renderPass, renderEventParam, boxGroup, camPos, profiler);
|
||||
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
package com.seibel.distanthorizons.common.render.blaze;
|
||||
|
||||
import com.mojang.blaze3d.textures.GpuTexture;
|
||||
import com.seibel.distanthorizons.common.render.blaze.apply.BlazeDhApplyRenderer;
|
||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureWrapper;
|
||||
import com.seibel.distanthorizons.core.render.RenderParams;
|
||||
import com.seibel.distanthorizons.core.util.ColorUtil;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhMetaRenderer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
public class BlazeDhMetaRenderer implements IDhMetaRenderer
|
||||
{
|
||||
public static final BlazeDhMetaRenderer INSTANCE = new BlazeDhMetaRenderer();
|
||||
|
||||
|
||||
private BlazeDhApplyRenderer applyRenderer;
|
||||
|
||||
public final BlazeTextureWrapper dhDepthTextureWrapper = BlazeTextureWrapper.createDepth("DhDepthTexture");
|
||||
public final BlazeTextureWrapper dhColorTextureWrapper = BlazeTextureWrapper.createColor("DhColorTexture");
|
||||
|
||||
|
||||
|
||||
//=============//
|
||||
// constructor //
|
||||
//=============//
|
||||
//region
|
||||
|
||||
private BlazeDhMetaRenderer()
|
||||
{
|
||||
this.applyRenderer = new BlazeDhApplyRenderer(
|
||||
"dh_apply_to_mc",
|
||||
null,
|
||||
"apply/blaze/vert", "apply/blaze/frag"
|
||||
);
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
|
||||
|
||||
//=================//
|
||||
// pre/post render //
|
||||
//=================//
|
||||
//region
|
||||
|
||||
@Override
|
||||
public void runRenderPassSetup(RenderParams renderParams)
|
||||
{
|
||||
// textures
|
||||
this.dhDepthTextureWrapper.tryCreateOrResize();
|
||||
this.dhColorTextureWrapper.tryCreateOrResize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runRenderPassCleanup(RenderParams renderParams) {}
|
||||
|
||||
@Override
|
||||
public void applyToMcTexture()
|
||||
{
|
||||
GpuTexture mcColorTexture = Minecraft.getInstance().getMainRenderTarget().getColorTexture();
|
||||
this.applyRenderer.render(this.dhColorTextureWrapper.texture, this.dhDepthTextureWrapper.texture, mcColorTexture);
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
|
||||
|
||||
//================//
|
||||
// clear textures //
|
||||
//================//
|
||||
//region
|
||||
|
||||
@Override
|
||||
public void clearDhDepthAndColorTextures(RenderParams renderParams)
|
||||
{
|
||||
// TODO use for clear color
|
||||
//IMinecraftRenderWrapper r;
|
||||
//r.getSkyColor()
|
||||
|
||||
this.dhDepthTextureWrapper.clearDepth(1.0f);
|
||||
this.dhColorTextureWrapper.clearColor(ColorUtil.argbToInt(1, 1, 1, 1));
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
|
||||
}
|
||||
+2
@@ -8,6 +8,7 @@ import com.seibel.distanthorizons.common.render.blaze.postProcessing.BlazeVanill
|
||||
import com.seibel.distanthorizons.common.render.blaze.test.BlazeDhTestTriangleRenderer;
|
||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.buffer.BlazeVertexBufferWrapper;
|
||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.uniform.BlazeLodUniformBufferWrapper;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.OpenGlDhMetaRenderer;
|
||||
import com.seibel.distanthorizons.core.render.renderer.AbstractDebugWireframeRenderer;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.AbstractDhRenderApiDefinition;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.IDhGenericObjectVertexBufferContainer;
|
||||
@@ -19,6 +20,7 @@ public class BlazeDhRenderApiDefinition extends AbstractDhRenderApiDefinition
|
||||
{
|
||||
public String getApiName() { return "Blaze3D"; }
|
||||
|
||||
@Override public IDhMetaRenderer getMetaRenderer() { return BlazeDhMetaRenderer.INSTANCE; }
|
||||
@Override public IDhTerrainRenderer getTerrainRenderer() { return BlazeDhTerrainRenderer.INSTANCE; }
|
||||
@Override public IDhSsaoRenderer getSsaoRenderer() { return BlazeDhSsaoRenderer.INSTANCE; }
|
||||
@Override public IDhFogRenderer getFogRenderer() { return BlazeDhFogRenderer.INSTANCE; }
|
||||
|
||||
+2
-35
@@ -63,8 +63,6 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
||||
public static final BlazeDhTerrainRenderer INSTANCE = new BlazeDhTerrainRenderer();
|
||||
|
||||
|
||||
private BlazeDhApplyRenderer applyRenderer;
|
||||
|
||||
private RenderPipeline opaquePipeline;
|
||||
private RenderPipeline transparentPipeline;
|
||||
private boolean init = false;
|
||||
@@ -74,9 +72,6 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
||||
private GpuBuffer fragUniformBuffer;
|
||||
private GpuBuffer vertSharedUniformBuffer;
|
||||
|
||||
public final BlazeTextureWrapper dhDepthTextureWrapper = BlazeTextureWrapper.createDepth("DhDepthTexture");
|
||||
public final BlazeTextureWrapper dhColorTextureWrapper = BlazeTextureWrapper.createColor("DhColorTexture");
|
||||
|
||||
|
||||
|
||||
//=============//
|
||||
@@ -95,12 +90,6 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
||||
this.init = true; // todo only set when succeeded (in case of exception)
|
||||
|
||||
|
||||
this.applyRenderer = new BlazeDhApplyRenderer(
|
||||
"dh_apply_to_mc",
|
||||
null,
|
||||
"apply/blaze/vert", "apply/blaze/frag"
|
||||
);
|
||||
|
||||
VertexFormat vertexFormat = VertexFormat.builder()
|
||||
.add("vPosition", DhBlazeVertexFormatUtil.SHORT_XYZ_POS)
|
||||
.add("meta", DhBlazeVertexFormatUtil.META)
|
||||
@@ -293,10 +282,6 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
||||
}
|
||||
}
|
||||
|
||||
// textures
|
||||
this.dhDepthTextureWrapper.tryCreateOrResize();
|
||||
this.dhColorTextureWrapper.tryCreateOrResize();
|
||||
|
||||
|
||||
|
||||
// render pass setup
|
||||
@@ -309,9 +294,9 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
||||
|
||||
try(RenderPass renderPass = COMMAND_ENCODER.createRenderPass(
|
||||
this::getRenderPassName,
|
||||
this.dhColorTextureWrapper.textureView,
|
||||
BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.textureView,
|
||||
optionalClearColorAsInt,
|
||||
this.dhDepthTextureWrapper.textureView, optionalDepthValueAsDouble)
|
||||
BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureView, optionalDepthValueAsDouble)
|
||||
)
|
||||
{
|
||||
// bind MC Lightmap
|
||||
@@ -392,24 +377,6 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
||||
private String getIndexBufferName() { return "distantHorizons:LodIndexBuffer"; }
|
||||
private String getRenderPassName() { return "distantHorizons:McLodRenderer"; }
|
||||
|
||||
|
||||
@Override
|
||||
public void runRenderPassSetup(RenderParams renderParams) {}
|
||||
@Override
|
||||
public void runRenderPassCleanup(RenderParams renderParams) {}
|
||||
|
||||
@Override
|
||||
public void applyToMcTexture()
|
||||
{
|
||||
GpuTexture mcColorTexture = Minecraft.getInstance().getMainRenderTarget().getColorTexture();
|
||||
this.applyRenderer.render(this.dhColorTextureWrapper.texture, this.dhDepthTextureWrapper.texture, mcColorTexture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearDepth() { this.dhDepthTextureWrapper.clearDepth(1.0f); }
|
||||
@Override
|
||||
public void clearColor() { this.dhColorTextureWrapper.clearColor(ColorUtil.argbToInt(1, 1, 1, 1)); }
|
||||
|
||||
//endregion
|
||||
|
||||
|
||||
|
||||
+6
-5
@@ -32,6 +32,7 @@ import com.mojang.blaze3d.systems.GpuDevice;
|
||||
import com.mojang.blaze3d.systems.RenderPass;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import com.seibel.distanthorizons.common.render.blaze.BlazeDhMetaRenderer;
|
||||
import com.seibel.distanthorizons.common.render.blaze.BlazeDhTerrainRenderer;
|
||||
import com.seibel.distanthorizons.common.render.blaze.apply.BlazeDhCopyRenderer;
|
||||
import com.seibel.distanthorizons.common.render.blaze.helpers.*;
|
||||
@@ -136,8 +137,8 @@ public class BlazeDhFarFadeRenderer implements IDhFarFadeRenderer
|
||||
this.tryInit();
|
||||
|
||||
|
||||
if (BlazeDhTerrainRenderer.INSTANCE.dhDepthTextureWrapper.isEmpty()
|
||||
|| BlazeDhTerrainRenderer.INSTANCE.dhColorTextureWrapper.isEmpty())
|
||||
if (BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.isEmpty()
|
||||
|| BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -191,7 +192,7 @@ public class BlazeDhFarFadeRenderer implements IDhFarFadeRenderer
|
||||
|
||||
|
||||
this.renderFadeToTexture();
|
||||
BlazeDhCopyRenderer.INSTANCE.render(this.dhFadeColorTextureWrapper, BlazeDhTerrainRenderer.INSTANCE.dhColorTextureWrapper);
|
||||
BlazeDhCopyRenderer.INSTANCE.render(this.dhFadeColorTextureWrapper, BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper);
|
||||
|
||||
}
|
||||
|
||||
@@ -208,8 +209,8 @@ public class BlazeDhFarFadeRenderer implements IDhFarFadeRenderer
|
||||
renderPass.bindTexture("uMcColorTexture", this.mcColorTextureViewWrapper.textureView, this.mcColorTextureViewWrapper.textureSampler);
|
||||
|
||||
// DH textures
|
||||
renderPass.bindTexture("uDhDepthTexture", BlazeDhTerrainRenderer.INSTANCE.dhDepthTextureWrapper.textureView, BlazeDhTerrainRenderer.INSTANCE.dhDepthTextureWrapper.textureSampler);
|
||||
renderPass.bindTexture("uDhColorTexture", BlazeDhTerrainRenderer.INSTANCE.dhColorTextureWrapper.textureView, BlazeDhTerrainRenderer.INSTANCE.dhColorTextureWrapper.textureSampler);
|
||||
renderPass.bindTexture("uDhDepthTexture", BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureView, BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureSampler);
|
||||
renderPass.bindTexture("uDhColorTexture", BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.textureView, BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.textureSampler);
|
||||
|
||||
renderPass.setUniform("fragUniformBlock", this.fragUniformBuffer);
|
||||
|
||||
|
||||
+4
-3
@@ -39,6 +39,7 @@ import com.seibel.distanthorizons.api.enums.rendering.EDhApiFogColorMode;
|
||||
import com.seibel.distanthorizons.api.enums.rendering.EDhApiHeightFogDirection;
|
||||
import com.seibel.distanthorizons.api.enums.rendering.EDhApiHeightFogMixMode;
|
||||
import com.seibel.distanthorizons.api.objects.math.DhApiMat4f;
|
||||
import com.seibel.distanthorizons.common.render.blaze.BlazeDhMetaRenderer;
|
||||
import com.seibel.distanthorizons.common.render.blaze.BlazeDhTerrainRenderer;
|
||||
import com.seibel.distanthorizons.common.render.blaze.apply.BlazeDhApplyRenderer;
|
||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureWrapper;
|
||||
@@ -154,8 +155,8 @@ public class BlazeDhFogRenderer implements IDhFogRenderer
|
||||
this.tryInit();
|
||||
|
||||
|
||||
if (BlazeDhTerrainRenderer.INSTANCE.dhDepthTextureWrapper.isEmpty()
|
||||
|| BlazeDhTerrainRenderer.INSTANCE.dhColorTextureWrapper.isEmpty())
|
||||
if (BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.isEmpty()
|
||||
|| BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -308,7 +309,7 @@ public class BlazeDhFogRenderer implements IDhFogRenderer
|
||||
|
||||
|
||||
this.renderFogToTexture();
|
||||
this.applyRenderer.render(this.fogColorTextureWrapper.texture, BlazeDhTerrainRenderer.INSTANCE.dhDepthTextureWrapper.texture, BlazeDhTerrainRenderer.INSTANCE.dhColorTextureWrapper.texture);
|
||||
this.applyRenderer.render(this.fogColorTextureWrapper.texture, BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.texture, BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.texture);
|
||||
|
||||
}
|
||||
|
||||
|
||||
+5
-4
@@ -36,6 +36,7 @@ import com.mojang.blaze3d.systems.RenderPass;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import com.seibel.distanthorizons.api.objects.math.DhApiMat4f;
|
||||
import com.seibel.distanthorizons.common.render.blaze.BlazeDhMetaRenderer;
|
||||
import com.seibel.distanthorizons.common.render.blaze.BlazeDhTerrainRenderer;
|
||||
import com.seibel.distanthorizons.common.render.blaze.apply.BlazeDhApplyRenderer;
|
||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureWrapper;
|
||||
@@ -145,8 +146,8 @@ public class BlazeDhSsaoRenderer implements IDhSsaoRenderer
|
||||
this.tryInit();
|
||||
|
||||
|
||||
if (BlazeDhTerrainRenderer.INSTANCE.dhDepthTextureWrapper.isEmpty()
|
||||
|| BlazeDhTerrainRenderer.INSTANCE.dhColorTextureWrapper.isEmpty())
|
||||
if (BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.isEmpty()
|
||||
|| BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -244,7 +245,7 @@ public class BlazeDhSsaoRenderer implements IDhSsaoRenderer
|
||||
this.renderSsaoToTexture();
|
||||
|
||||
this.applyRenderer.setUniform("applyFragUniformBlock", this.applyFragUniformBuffer);
|
||||
this.applyRenderer.render(this.ssaoColorTextureWrapper.texture, BlazeDhTerrainRenderer.INSTANCE.dhDepthTextureWrapper.texture, BlazeDhTerrainRenderer.INSTANCE.dhColorTextureWrapper.texture);
|
||||
this.applyRenderer.render(this.ssaoColorTextureWrapper.texture, BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.texture, BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.texture);
|
||||
|
||||
}
|
||||
|
||||
@@ -257,7 +258,7 @@ public class BlazeDhSsaoRenderer implements IDhSsaoRenderer
|
||||
/*depthTexture*/ null,
|
||||
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
||||
{
|
||||
renderPass.bindTexture("uDhDepthTexture", BlazeDhTerrainRenderer.INSTANCE.dhDepthTextureWrapper.textureView, BlazeDhTerrainRenderer.INSTANCE.dhDepthTextureWrapper.textureSampler);
|
||||
renderPass.bindTexture("uDhDepthTexture", BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureView, BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureSampler);
|
||||
|
||||
renderPass.setUniform("fragUniformBlock", this.fragUniformBuffer);
|
||||
|
||||
|
||||
+5
-4
@@ -32,6 +32,7 @@ import com.mojang.blaze3d.systems.GpuDevice;
|
||||
import com.mojang.blaze3d.systems.RenderPass;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import com.seibel.distanthorizons.common.render.blaze.BlazeDhMetaRenderer;
|
||||
import com.seibel.distanthorizons.common.render.blaze.BlazeDhTerrainRenderer;
|
||||
import com.seibel.distanthorizons.common.render.blaze.apply.BlazeDhCopyRenderer;
|
||||
import com.seibel.distanthorizons.common.render.blaze.helpers.*;
|
||||
@@ -144,8 +145,8 @@ public class BlazeVanillaFadeRenderer implements IDhVanillaFadeRenderer
|
||||
{
|
||||
this.tryInit();
|
||||
|
||||
if (BlazeDhTerrainRenderer.INSTANCE.dhDepthTextureWrapper.isEmpty()
|
||||
|| BlazeDhTerrainRenderer.INSTANCE.dhColorTextureWrapper.isEmpty())
|
||||
if (BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.isEmpty()
|
||||
|| BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -236,8 +237,8 @@ public class BlazeVanillaFadeRenderer implements IDhVanillaFadeRenderer
|
||||
renderPass.bindTexture("uMcDepthTexture", this.mcDepthTextureWrapper.textureView, this.mcDepthTextureWrapper.textureSampler);
|
||||
renderPass.bindTexture("uCombinedMcDhColorTexture", this.mcColorTextureWrapper.textureView, this.mcColorTextureWrapper.textureSampler);
|
||||
|
||||
renderPass.bindTexture("uDhDepthTexture", BlazeDhTerrainRenderer.INSTANCE.dhDepthTextureWrapper.textureView, BlazeDhTerrainRenderer.INSTANCE.dhDepthTextureWrapper.textureSampler);
|
||||
renderPass.bindTexture("uDhColorTexture", BlazeDhTerrainRenderer.INSTANCE.dhColorTextureWrapper.textureView, BlazeDhTerrainRenderer.INSTANCE.dhColorTextureWrapper.textureSampler);
|
||||
renderPass.bindTexture("uDhDepthTexture", BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureView, BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureSampler);
|
||||
renderPass.bindTexture("uDhColorTexture", BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.textureView, BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.textureSampler);
|
||||
|
||||
renderPass.setUniform("fragUniformBlock", this.fragUniformBuffer);
|
||||
|
||||
|
||||
+114
-509
@@ -35,7 +35,6 @@ import com.seibel.distanthorizons.common.render.nativeGl.glObject.vertexAttribut
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.glObject.vertexAttribute.VertexAttributePostGL43;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.glObject.vertexAttribute.VertexAttributePreGL43;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.glObject.vertexAttribute.VertexPointer;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.postProcessing.apply.DhApplyShader;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.util.vertexFormat.LodVertexFormat;
|
||||
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftGLWrapper;
|
||||
import com.seibel.distanthorizons.common.wrappers.misc.LightMapWrapper;
|
||||
@@ -47,23 +46,19 @@ import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.render.RenderBufferHandler;
|
||||
import com.seibel.distanthorizons.core.render.RenderParams;
|
||||
import com.seibel.distanthorizons.core.util.RenderUtil;
|
||||
import com.seibel.distanthorizons.core.util.math.Mat4f;
|
||||
import com.seibel.distanthorizons.core.util.math.Vec3d;
|
||||
import com.seibel.distanthorizons.core.util.math.Vec3f;
|
||||
import com.seibel.distanthorizons.core.util.objects.SortedArraySet;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.AbstractOptifineAccessor;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IIrisAccessor;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.IVertexBufferWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhTerrainRenderer;
|
||||
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
|
||||
import com.seibel.distanthorizons.coreapi.DependencyInjection.OverrideInjector;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.lwjgl.opengl.GL32;
|
||||
|
||||
/**
|
||||
@@ -72,9 +67,23 @@ import org.lwjgl.opengl.GL32;
|
||||
*/
|
||||
public class DhTerrainShaderProgram extends ShaderProgram implements IDhApiShaderProgram, IDhTerrainRenderer
|
||||
{
|
||||
public static final DhLogger LOGGER = new DhLoggerBuilder()
|
||||
.fileLevelConfig(Config.Common.Logging.logRendererEventToFile)
|
||||
.build();
|
||||
|
||||
public static final DhTerrainShaderProgram INSTANCE = new DhTerrainShaderProgram();
|
||||
|
||||
private static final MinecraftGLWrapper GLMC = MinecraftGLWrapper.INSTANCE;
|
||||
private static final IIrisAccessor IRIS_ACCESSOR = ModAccessorInjector.INSTANCE.get(IIrisAccessor.class);
|
||||
|
||||
|
||||
|
||||
public QuadElementBuffer quadIBO = null;
|
||||
public final AbstractVertexAttribute vao;
|
||||
|
||||
// Uniforms
|
||||
// uniforms //
|
||||
//region
|
||||
|
||||
public int uCombinedMatrix = -1;
|
||||
public int uModelOffset = -1;
|
||||
public int uWorldYOffset = -1;
|
||||
@@ -96,6 +105,8 @@ public class DhTerrainShaderProgram extends ShaderProgram implements IDhApiShade
|
||||
// Debug Uniform
|
||||
public int uIsWhiteWorld = -1;
|
||||
|
||||
//endregion
|
||||
|
||||
|
||||
|
||||
//=============//
|
||||
@@ -103,8 +114,7 @@ public class DhTerrainShaderProgram extends ShaderProgram implements IDhApiShade
|
||||
//=============//
|
||||
//region
|
||||
|
||||
// This will bind AbstractVertexAttribute
|
||||
public DhTerrainShaderProgram()
|
||||
private DhTerrainShaderProgram()
|
||||
{
|
||||
super(
|
||||
"shaders/standard.vert",
|
||||
@@ -169,9 +179,9 @@ public class DhTerrainShaderProgram extends ShaderProgram implements IDhApiShade
|
||||
|
||||
|
||||
|
||||
//=========//
|
||||
// methods //
|
||||
//=========//
|
||||
//=============//
|
||||
// API methods //
|
||||
//=============//
|
||||
//region
|
||||
|
||||
@Override
|
||||
@@ -260,533 +270,128 @@ public class DhTerrainShaderProgram extends ShaderProgram implements IDhApiShade
|
||||
|
||||
|
||||
|
||||
//===========//
|
||||
// rendering //
|
||||
//===========//
|
||||
//region
|
||||
|
||||
@Override
|
||||
public void runRenderPassSetup(RenderParams renderParams) { OpenGlRenderState.INSTANCE.runRenderPassSetup(renderParams); }
|
||||
|
||||
@Override
|
||||
public void runRenderPassCleanup(RenderParams renderParams) { OpenGlRenderState.INSTANCE.runRenderPassCleanup(renderParams); }
|
||||
|
||||
|
||||
@Override
|
||||
public void render(RenderParams renderEventParam, boolean opaquePass, SortedArraySet<LodBufferContainer> bufferContainers, IProfilerWrapper profiler)
|
||||
{
|
||||
OpenGlRenderState.INSTANCE.renderLodTerrain(bufferContainers, renderEventParam, opaquePass);
|
||||
}
|
||||
@Override
|
||||
public void applyToMcTexture()
|
||||
{
|
||||
}
|
||||
@Override
|
||||
public void clearDepth()
|
||||
{
|
||||
}
|
||||
@Override
|
||||
public void clearColor()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public static class OpenGlRenderState
|
||||
{
|
||||
public static final DhLogger LOGGER = new DhLoggerBuilder()
|
||||
.fileLevelConfig(Config.Common.Logging.logRendererEventToFile)
|
||||
.build();
|
||||
//=======================//
|
||||
// debug wireframe setup //
|
||||
//=======================//
|
||||
|
||||
public static final DhLogger RATE_LIMITED_LOGGER = new DhLoggerBuilder()
|
||||
.fileLevelConfig(Config.Common.Logging.logRendererEventToFile)
|
||||
.maxCountPerSecond(4)
|
||||
.build();
|
||||
|
||||
public static final OpenGlRenderState INSTANCE = new OpenGlRenderState();
|
||||
|
||||
|
||||
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
||||
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
||||
private static final MinecraftGLWrapper GLMC = MinecraftGLWrapper.INSTANCE;
|
||||
private static final IIrisAccessor IRIS_ACCESSOR = ModAccessorInjector.INSTANCE.get(IIrisAccessor.class);
|
||||
|
||||
|
||||
// these ID's either what any render is currently using (since only one renderer can be active at a time), or just used previously
|
||||
private int activeFramebufferId = -1;
|
||||
private int activeColorTextureId = -1;
|
||||
private int activeDepthTextureId = -1;
|
||||
private int textureWidth;
|
||||
private int textureHeight;
|
||||
|
||||
|
||||
private IDhApiShaderProgram lodRenderProgram = null;
|
||||
public QuadElementBuffer quadIBO = null;
|
||||
private boolean renderObjectsCreated = false;
|
||||
|
||||
// framebuffer and texture ID's for this renderer
|
||||
private IDhApiFramebuffer framebuffer;
|
||||
/** will be null if MC's framebuffer is being used since MC already has a color texture */
|
||||
@Nullable
|
||||
private DhColorTexture nullableColorTexture;
|
||||
private DHDepthTexture depthTexture;
|
||||
/**
|
||||
* If true the {@link OpenGlRenderState#framebuffer} is the same as MC's.
|
||||
* This should only be true in the case of Optifine so LODs won't be overwritten when shaders are enabled.
|
||||
*/
|
||||
private boolean usingMcFramebuffer = false;
|
||||
|
||||
|
||||
private IDhApiShaderProgram lodShaderProgramThisFrame;
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
public void runRenderPassSetup(RenderParams renderParams)
|
||||
boolean renderWireframe = Config.Client.Advanced.Debugging.renderWireframe.get();
|
||||
if (renderWireframe)
|
||||
{
|
||||
boolean firstPass =
|
||||
(renderParams.renderPass == EDhApiRenderPass.OPAQUE
|
||||
|| renderParams.renderPass == EDhApiRenderPass.OPAQUE_AND_TRANSPARENT);
|
||||
|
||||
if (!this.renderObjectsCreated)
|
||||
{
|
||||
boolean setupSuccess = this.createRenderObjects();
|
||||
if (!setupSuccess)
|
||||
{
|
||||
// shouldn't normally happen, but just in case
|
||||
return;
|
||||
}
|
||||
|
||||
this.renderObjectsCreated = true;
|
||||
}
|
||||
|
||||
|
||||
this.setGLState(renderParams, firstPass);
|
||||
|
||||
this.quadIBO.bind();
|
||||
renderParams.lightmap.bind();
|
||||
|
||||
this.lodShaderProgramThisFrame = this.lodRenderProgram;
|
||||
IDhApiShaderProgram lodShaderProgramOverride = OverrideInjector.INSTANCE.get(IDhApiShaderProgram.class);
|
||||
if (lodShaderProgramOverride != null && this.lodShaderProgramThisFrame.overrideThisFrame())
|
||||
{
|
||||
this.lodShaderProgramThisFrame = lodShaderProgramOverride;
|
||||
}
|
||||
|
||||
GL32.glPolygonMode(GL32.GL_FRONT_AND_BACK, GL32.GL_LINE);
|
||||
GLMC.disableFaceCulling();
|
||||
}
|
||||
|
||||
public void runRenderPassCleanup(RenderParams renderParams)
|
||||
else
|
||||
{
|
||||
boolean runningDeferredPass = (renderParams.renderPass == EDhApiRenderPass.TRANSPARENT);
|
||||
|
||||
|
||||
if (!runningDeferredPass)
|
||||
{
|
||||
//===================//
|
||||
// optifine clean up //
|
||||
//===================//
|
||||
|
||||
if (this.usingMcFramebuffer)
|
||||
{
|
||||
// If MC's framebuffer is being used the depth needs to be cleared to prevent rendering on top of MC.
|
||||
// This should only happen when Optifine shaders are being used.
|
||||
GL32.glClear(GL32.GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=============================//
|
||||
// Apply to the MC Framebuffer //
|
||||
//=============================//
|
||||
|
||||
boolean cancelApplyShader = ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeApplyShaderRenderEvent.class, renderParams);
|
||||
if (!cancelApplyShader)
|
||||
{
|
||||
//profiler.popPush("LOD Apply");
|
||||
|
||||
// Copy the LOD framebuffer to Minecraft's framebuffer
|
||||
DhApplyShader.INSTANCE.render(renderParams.partialTicks);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
renderParams.lightmap.unbind();
|
||||
this.quadIBO.unbind();
|
||||
this.lodShaderProgramThisFrame.unbind();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=================//
|
||||
// Setup Functions //
|
||||
//=================//
|
||||
//region
|
||||
|
||||
private void setGLState(
|
||||
DhApiRenderParam renderEventParam,
|
||||
boolean firstPass)
|
||||
{
|
||||
//===================//
|
||||
// framebuffer setup //
|
||||
//===================//
|
||||
|
||||
// get the active framebuffer
|
||||
IDhApiFramebuffer framebuffer = this.framebuffer;
|
||||
IDhApiFramebuffer framebufferOverride = OverrideInjector.INSTANCE.get(IDhApiFramebuffer.class);
|
||||
if (framebufferOverride != null && framebufferOverride.overrideThisFrame())
|
||||
{
|
||||
framebuffer = framebufferOverride;
|
||||
}
|
||||
this.activeFramebufferId = framebuffer.getId();
|
||||
framebuffer.bind();
|
||||
|
||||
|
||||
|
||||
//==========//
|
||||
// bindings //
|
||||
//==========//
|
||||
|
||||
// by default draw everything as triangles
|
||||
GL32.glPolygonMode(GL32.GL_FRONT_AND_BACK, GL32.GL_FILL);
|
||||
GLMC.enableFaceCulling();
|
||||
|
||||
GLMC.glBlendFunc(GL32.GL_SRC_ALPHA, GL32.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GLMC.glBlendFuncSeparate(GL32.GL_SRC_ALPHA, GL32.GL_ONE_MINUS_SRC_ALPHA, GL32.GL_ONE, GL32.GL_ZERO);
|
||||
|
||||
GL32.glDisable(GL32.GL_SCISSOR_TEST);
|
||||
|
||||
// Enable depth test and depth mask
|
||||
}
|
||||
|
||||
if (!opaquePass)
|
||||
{
|
||||
GLMC.enableBlend();
|
||||
GLMC.enableDepthTest();
|
||||
GLMC.glDepthFunc(GL32.GL_LESS);
|
||||
GLMC.enableDepthMask();
|
||||
|
||||
// This is required for MC versions 1.21.5+
|
||||
// due to MC updating the lightmap by changing the viewport size
|
||||
GL32.glViewport(0, 0, this.textureWidth, this.textureHeight);
|
||||
|
||||
this.lodRenderProgram.bind();
|
||||
|
||||
|
||||
|
||||
//==========//
|
||||
// uniforms //
|
||||
//==========//
|
||||
|
||||
IDhApiShaderProgram shaderProgramOverride = OverrideInjector.INSTANCE.get(IDhApiShaderProgram.class);
|
||||
if (shaderProgramOverride != null)
|
||||
{
|
||||
shaderProgramOverride.fillUniformData(renderEventParam);
|
||||
}
|
||||
|
||||
this.lodRenderProgram.fillUniformData(renderEventParam);
|
||||
|
||||
|
||||
|
||||
//===============//
|
||||
// texture setup //
|
||||
//===============//
|
||||
|
||||
// resize the textures if needed
|
||||
if (MC_RENDER.getTargetFramebufferViewportWidth() != this.textureWidth
|
||||
|| MC_RENDER.getTargetFramebufferViewportHeight() != this.textureHeight)
|
||||
{
|
||||
// just resizing the textures doesn't work when Optifine is present,
|
||||
// so recreate the textures with the new size instead
|
||||
this.createAndBindTextures();
|
||||
}
|
||||
|
||||
|
||||
// set the active textures
|
||||
this.activeDepthTextureId = this.depthTexture.getTextureId();
|
||||
|
||||
if (this.nullableColorTexture != null)
|
||||
{
|
||||
this.activeColorTextureId = this.nullableColorTexture.getTextureId();
|
||||
}
|
||||
else
|
||||
{
|
||||
// get MC's color texture
|
||||
this.activeColorTextureId = GL32.glGetFramebufferAttachmentParameteri(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0, GL32.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME);
|
||||
}
|
||||
|
||||
|
||||
// needs to be fired after all the textures have been created/bound
|
||||
boolean clearTextures = !ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeTextureClearEvent.class, renderEventParam);
|
||||
if (clearTextures)
|
||||
{
|
||||
GL32.glClearDepth(1.0);
|
||||
|
||||
float[] clearColorValues = new float[4];
|
||||
GL32.glGetFloatv(GL32.GL_COLOR_CLEAR_VALUE, clearColorValues);
|
||||
GL32.glClearColor(clearColorValues[0], clearColorValues[1], clearColorValues[2], 1.0f);
|
||||
|
||||
if (this.usingMcFramebuffer && framebufferOverride == null)
|
||||
{
|
||||
// Due to using MC/Optifine's framebuffer we need to re-bind the depth texture,
|
||||
// otherwise we'll be writing to MC/Optifine's depth texture which causes rendering issues
|
||||
framebuffer.addDepthAttachment(this.depthTexture.getTextureId(), EDhDepthBufferFormat.DEPTH32F.isCombinedStencil());
|
||||
|
||||
|
||||
// don't clear the color texture, that removes the sky
|
||||
GL32.glClear(GL32.GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
else if (firstPass)
|
||||
{
|
||||
GL32.glClear(GL32.GL_COLOR_BUFFER_BIT | GL32.GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
}
|
||||
GL32.glBlendEquation(GL32.GL_FUNC_ADD);
|
||||
GLMC.glBlendFuncSeparate(GL32.GL_SRC_ALPHA, GL32.GL_ONE_MINUS_SRC_ALPHA, GL32.GL_ONE, GL32.GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
else
|
||||
{
|
||||
GLMC.disableBlend();
|
||||
}
|
||||
|
||||
private boolean createRenderObjects()
|
||||
|
||||
|
||||
|
||||
//===========//
|
||||
// rendering //
|
||||
//===========//
|
||||
|
||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeRenderPassEvent.class, renderEventParam);
|
||||
|
||||
if (IRIS_ACCESSOR != null)
|
||||
{
|
||||
if (this.renderObjectsCreated)
|
||||
{
|
||||
LOGGER.warn("Renderer setup called but it has already completed setup!");
|
||||
return false;
|
||||
}
|
||||
|
||||
// GLProxy should have already been created by this point, but just in case create it now
|
||||
GLProxy.getInstance();
|
||||
|
||||
|
||||
|
||||
LOGGER.info("Setting up renderer");
|
||||
this.lodRenderProgram = new DhTerrainShaderProgram();
|
||||
|
||||
this.quadIBO = new QuadElementBuffer();
|
||||
this.quadIBO.reserve(LodQuadBuilder.getMaxBufferByteSize());
|
||||
|
||||
|
||||
// create or get the frame buffer
|
||||
if (AbstractOptifineAccessor.optifinePresent())
|
||||
{
|
||||
// use MC/Optifine's default Framebuffer so shaders won't remove the LODs
|
||||
int currentFramebufferId = MC_RENDER.getTargetFramebuffer();
|
||||
this.framebuffer = new DhFramebuffer(currentFramebufferId);
|
||||
this.usingMcFramebuffer = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// normal use case
|
||||
this.framebuffer = new DhFramebuffer();
|
||||
this.usingMcFramebuffer = false;
|
||||
}
|
||||
|
||||
// create and bind the necessary textures
|
||||
this.createAndBindTextures();
|
||||
|
||||
if(this.framebuffer.getStatus() != GL32.GL_FRAMEBUFFER_COMPLETE)
|
||||
{
|
||||
// This generally means something wasn't bound, IE missing either the color or depth texture
|
||||
LOGGER.warn("Framebuffer ["+this.framebuffer.getId()+"] isn't complete.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
LOGGER.info("Renderer setup complete");
|
||||
return true;
|
||||
// done to fix a bug with Iris where face culling isn't properly set or reverted in the MC state manager
|
||||
// which causes Sodium to render some water chunks with their normals inverted
|
||||
// https://github.com/IrisShaders/Iris/issues/2582
|
||||
// https://github.com/IrisShaders/Iris/blob/1.21.9/common/src/main/java/net/irisshaders/iris/compat/dh/LodRendererEvents.java#L346
|
||||
GLMC.enableFaceCulling();
|
||||
}
|
||||
|
||||
@SuppressWarnings( "deprecation" ) // done to ignore DhApiColorDepthTextureCreatedEvent
|
||||
private void createAndBindTextures()
|
||||
|
||||
if (bufferContainers != null)
|
||||
{
|
||||
int oldWidth = this.textureWidth;
|
||||
int oldHeight = this.textureHeight;
|
||||
this.textureWidth = MC_RENDER.getTargetFramebufferViewportWidth();
|
||||
this.textureHeight = MC_RENDER.getTargetFramebufferViewportHeight();
|
||||
|
||||
DhApiTextureCreatedParam textureCreatedParam = new DhApiTextureCreatedParam(
|
||||
oldWidth, oldHeight,
|
||||
this.textureWidth, this.textureHeight
|
||||
);
|
||||
|
||||
|
||||
// DhApiColorDepthTextureCreatedEvent needs to be kept around since old versions of Iris need it
|
||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiColorDepthTextureCreatedEvent.class, new DhApiColorDepthTextureCreatedEvent.EventParam(textureCreatedParam));
|
||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeColorDepthTextureCreatedEvent.class, textureCreatedParam);
|
||||
|
||||
|
||||
// also update the framebuffer override if present
|
||||
IDhApiFramebuffer framebufferOverride = OverrideInjector.INSTANCE.get(IDhApiFramebuffer.class);
|
||||
|
||||
|
||||
this.depthTexture = new DHDepthTexture(this.textureWidth, this.textureHeight, EDhDepthBufferFormat.DEPTH32F);
|
||||
this.framebuffer.addDepthAttachment(this.depthTexture.getTextureId(), EDhDepthBufferFormat.DEPTH32F.isCombinedStencil());
|
||||
if (framebufferOverride != null)
|
||||
for (int lodIndex = 0; lodIndex < bufferContainers.size(); lodIndex++)
|
||||
{
|
||||
framebufferOverride.addDepthAttachment(this.depthTexture.getTextureId(), EDhDepthBufferFormat.DEPTH32F.isCombinedStencil());
|
||||
}
|
||||
|
||||
|
||||
// if we are using MC's frame buffer, a color texture is already present and shouldn't need to be bound
|
||||
if (!this.usingMcFramebuffer)
|
||||
{
|
||||
this.nullableColorTexture = DhColorTexture.builder()
|
||||
.setDimensions(this.textureWidth, this.textureHeight)
|
||||
.setInternalFormat(EDhInternalTextureFormat.RGBA8)
|
||||
.setPixelType(EDhPixelType.UNSIGNED_BYTE)
|
||||
.setPixelFormat(EDhPixelFormat.RGBA)
|
||||
.build();
|
||||
LodBufferContainer bufferContainer = bufferContainers.get(lodIndex);
|
||||
this.setShaderProgramMvmOffset(bufferContainer.minCornerBlockPos, OpenGlDhMetaRenderer.INSTANCE.shaderProgramForThisFrame, renderEventParam);
|
||||
|
||||
this.framebuffer.addColorAttachment(0, this.nullableColorTexture.getTextureId());
|
||||
if (framebufferOverride != null)
|
||||
IVertexBufferWrapper[] vertexBuffers = (opaquePass ? bufferContainer.vbos : bufferContainer.vbosTransparent);
|
||||
for (int vboIndex = 0; vboIndex < vertexBuffers.length; vboIndex++)
|
||||
{
|
||||
framebufferOverride.addColorAttachment(0, this.nullableColorTexture.getTextureId());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.nullableColorTexture = null;
|
||||
}
|
||||
|
||||
|
||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiAfterColorDepthTextureCreatedEvent.class, textureCreatedParam);
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
|
||||
|
||||
//===============//
|
||||
// LOD rendering //
|
||||
//===============//
|
||||
//region
|
||||
|
||||
public void renderLodTerrain(SortedArraySet<LodBufferContainer> bufferContainers, RenderParams renderEventParam, boolean opaquePass)
|
||||
{
|
||||
IDhApiShaderProgram shaderProgram = this.lodShaderProgramThisFrame;
|
||||
|
||||
//=======================//
|
||||
// debug wireframe setup //
|
||||
//=======================//
|
||||
|
||||
boolean renderWireframe = Config.Client.Advanced.Debugging.renderWireframe.get();
|
||||
if (renderWireframe)
|
||||
{
|
||||
GL32.glPolygonMode(GL32.GL_FRONT_AND_BACK, GL32.GL_LINE);
|
||||
GLMC.disableFaceCulling();
|
||||
}
|
||||
else
|
||||
{
|
||||
GL32.glPolygonMode(GL32.GL_FRONT_AND_BACK, GL32.GL_FILL);
|
||||
GLMC.enableFaceCulling();
|
||||
}
|
||||
|
||||
if (!opaquePass)
|
||||
{
|
||||
GLMC.enableBlend();
|
||||
GLMC.enableDepthTest();
|
||||
GL32.glBlendEquation(GL32.GL_FUNC_ADD);
|
||||
GLMC.glBlendFuncSeparate(GL32.GL_SRC_ALPHA, GL32.GL_ONE_MINUS_SRC_ALPHA, GL32.GL_ONE, GL32.GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
else
|
||||
{
|
||||
GLMC.disableBlend();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//===========//
|
||||
// rendering //
|
||||
//===========//
|
||||
|
||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeRenderPassEvent.class, renderEventParam);
|
||||
|
||||
if (IRIS_ACCESSOR != null)
|
||||
{
|
||||
// done to fix a bug with Iris where face culling isn't properly set or reverted in the MC state manager
|
||||
// which causes Sodium to render some water chunks with their normal inverted
|
||||
// https://github.com/IrisShaders/Iris/issues/2582
|
||||
// https://github.com/IrisShaders/Iris/blob/1.21.9/common/src/main/java/net/irisshaders/iris/compat/dh/LodRendererEvents.java#L346
|
||||
GLMC.enableFaceCulling();
|
||||
}
|
||||
|
||||
|
||||
if (bufferContainers != null)
|
||||
{
|
||||
for (int lodIndex = 0; lodIndex < bufferContainers.size(); lodIndex++)
|
||||
{
|
||||
LodBufferContainer bufferContainer = bufferContainers.get(lodIndex);
|
||||
this.setShaderProgramMvmOffset(bufferContainer.minCornerBlockPos, shaderProgram, renderEventParam);
|
||||
|
||||
IVertexBufferWrapper[] vertexBuffers = (opaquePass ? bufferContainer.vbos : bufferContainer.vbosTransparent);
|
||||
for (int vboIndex = 0; vboIndex < vertexBuffers.length; vboIndex++)
|
||||
GLVertexBuffer vbo = (GLVertexBuffer) vertexBuffers[vboIndex];
|
||||
if (vbo == null)
|
||||
{
|
||||
GLVertexBuffer vbo = (GLVertexBuffer) vertexBuffers[vboIndex];
|
||||
if (vbo == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (vbo.getVertexCount() == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
vbo.bind();
|
||||
shaderProgram.bindVertexBuffer(vbo.getId());
|
||||
GL32.glDrawElements(
|
||||
GL32.GL_TRIANGLES,
|
||||
(int)(vbo.getVertexCount() * 1.5),
|
||||
this.quadIBO.getType(), 0);
|
||||
vbo.unbind();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (vbo.getVertexCount() == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
vbo.bind();
|
||||
OpenGlDhMetaRenderer.INSTANCE.shaderProgramForThisFrame.bindVertexBuffer(vbo.getId());
|
||||
GL32.glDrawElements(
|
||||
GL32.GL_TRIANGLES,
|
||||
(int)(vbo.getVertexCount() * 1.5),
|
||||
this.quadIBO.getType(), 0);
|
||||
vbo.unbind();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=========================//
|
||||
// debug wireframe cleanup //
|
||||
//=========================//
|
||||
|
||||
if (renderWireframe)
|
||||
{
|
||||
// default back to GL_FILL since all other rendering uses it
|
||||
GL32.glPolygonMode(GL32.GL_FRONT_AND_BACK, GL32.GL_FILL);
|
||||
GLMC.enableFaceCulling();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* the MVM offset is needed so LODs can be rendered anywhere in the MC world
|
||||
* without running into floating point percision loss.
|
||||
*/
|
||||
private void setShaderProgramMvmOffset(DhBlockPos pos, IDhApiShaderProgram shaderProgram, RenderParams renderEventParam) throws IllegalStateException
|
||||
|
||||
|
||||
//=========================//
|
||||
// debug wireframe cleanup //
|
||||
//=========================//
|
||||
|
||||
if (renderWireframe)
|
||||
{
|
||||
Vec3d camPos = renderEventParam.exactCameraPosition;
|
||||
Vec3f modelPos = new Vec3f(
|
||||
(float) (pos.getX() - camPos.x),
|
||||
(float) (pos.getY() - camPos.y),
|
||||
(float) (pos.getZ() - camPos.z));
|
||||
|
||||
shaderProgram.bind();
|
||||
shaderProgram.setModelOffsetPos(modelPos);
|
||||
|
||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeBufferRenderEvent.class, new DhApiBeforeBufferRenderEvent.EventParam(renderEventParam, modelPos));
|
||||
// default back to GL_FILL since all other rendering uses it
|
||||
GL32.glPolygonMode(GL32.GL_FRONT_AND_BACK, GL32.GL_FILL);
|
||||
GLMC.enableFaceCulling();
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
|
||||
|
||||
//===============//
|
||||
// API functions //
|
||||
//===============//
|
||||
//region
|
||||
|
||||
/** @return -1 if no frame buffer has been bound yet */
|
||||
public int getActiveFramebufferId() { return this.activeFramebufferId; }
|
||||
|
||||
/** @return -1 if no texture has been bound yet */
|
||||
public int getActiveColorTextureId() { return this.activeColorTextureId; }
|
||||
|
||||
/** @return -1 if no texture has been bound yet */
|
||||
public int getActiveDepthTextureId() { return this.activeDepthTextureId; }
|
||||
|
||||
//endregion
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* the MVM offset is needed so LODs can be rendered anywhere in the MC world
|
||||
* without running into floating point percision loss.
|
||||
*/
|
||||
private void setShaderProgramMvmOffset(DhBlockPos pos, IDhApiShaderProgram shaderProgram, RenderParams renderEventParam) throws IllegalStateException
|
||||
{
|
||||
Vec3d camPos = renderEventParam.exactCameraPosition;
|
||||
Vec3f modelPos = new Vec3f(
|
||||
(float) (pos.getX() - camPos.x),
|
||||
(float) (pos.getY() - camPos.y),
|
||||
(float) (pos.getZ() - camPos.z));
|
||||
|
||||
shaderProgram.bind();
|
||||
shaderProgram.setModelOffsetPos(modelPos);
|
||||
|
||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeBufferRenderEvent.class, new DhApiBeforeBufferRenderEvent.EventParam(renderEventParam, modelPos));
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
+448
@@ -0,0 +1,448 @@
|
||||
package com.seibel.distanthorizons.common.render.nativeGl;
|
||||
|
||||
import com.seibel.distanthorizons.api.enums.rendering.EDhApiRenderPass;
|
||||
import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiFramebuffer;
|
||||
import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiShaderProgram;
|
||||
import com.seibel.distanthorizons.api.methods.events.abstractEvents.*;
|
||||
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
|
||||
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiTextureCreatedParam;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.glObject.GLProxy;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.glObject.buffer.GLVertexBuffer;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.glObject.buffer.QuadElementBuffer;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.glObject.texture.*;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.postProcessing.apply.DhApplyShader;
|
||||
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftGLWrapper;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.LodBufferContainer;
|
||||
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.LodQuadBuilder;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.render.RenderParams;
|
||||
import com.seibel.distanthorizons.core.util.ColorUtil;
|
||||
import com.seibel.distanthorizons.core.util.math.Vec3d;
|
||||
import com.seibel.distanthorizons.core.util.math.Vec3f;
|
||||
import com.seibel.distanthorizons.core.util.objects.SortedArraySet;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.AbstractOptifineAccessor;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IIrisAccessor;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.IVertexBufferWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhMetaRenderer;
|
||||
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
|
||||
import com.seibel.distanthorizons.coreapi.DependencyInjection.OverrideInjector;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.lwjgl.opengl.GL32;
|
||||
|
||||
public class OpenGlDhMetaRenderer implements IDhMetaRenderer
|
||||
{
|
||||
public static final DhLogger LOGGER = new DhLoggerBuilder()
|
||||
.fileLevelConfig(Config.Common.Logging.logRendererEventToFile)
|
||||
.build();
|
||||
|
||||
public static final DhLogger RATE_LIMITED_LOGGER = new DhLoggerBuilder()
|
||||
.fileLevelConfig(Config.Common.Logging.logRendererEventToFile)
|
||||
.maxCountPerSecond(4)
|
||||
.build();
|
||||
|
||||
public static final OpenGlDhMetaRenderer INSTANCE = new OpenGlDhMetaRenderer();
|
||||
|
||||
|
||||
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
||||
private static final MinecraftGLWrapper GLMC = MinecraftGLWrapper.INSTANCE;
|
||||
|
||||
|
||||
private int activeFramebufferId = -1;
|
||||
private int activeColorTextureId = -1;
|
||||
private int activeDepthTextureId = -1;
|
||||
private int textureWidth;
|
||||
private int textureHeight;
|
||||
|
||||
|
||||
// framebuffer and texture ID's for this renderer
|
||||
private IDhApiFramebuffer framebuffer;
|
||||
/** will be null if MC's framebuffer is being used since MC already has a color texture */
|
||||
@Nullable
|
||||
private DhColorTexture nullableColorTexture;
|
||||
private DHDepthTexture depthTexture;
|
||||
/**
|
||||
* If true the {@link OpenGlDhMetaRenderer#framebuffer} is the same as MC's.
|
||||
* This should only be true in the case of Optifine so LODs won't be overwritten when shaders are enabled.
|
||||
*/
|
||||
private boolean usingMcFramebuffer = false;
|
||||
|
||||
private boolean renderObjectsCreated = false;
|
||||
/** used in case there's an API override */
|
||||
public IDhApiShaderProgram shaderProgramForThisFrame;
|
||||
|
||||
|
||||
|
||||
//============//
|
||||
// pre render //
|
||||
//============//
|
||||
//region
|
||||
|
||||
@Override
|
||||
public void runRenderPassSetup(RenderParams renderParams)
|
||||
{
|
||||
boolean firstPass =
|
||||
(renderParams.renderPass == EDhApiRenderPass.OPAQUE
|
||||
|| renderParams.renderPass == EDhApiRenderPass.OPAQUE_AND_TRANSPARENT);
|
||||
|
||||
if (!this.renderObjectsCreated)
|
||||
{
|
||||
boolean setupSuccess = this.createRenderObjects();
|
||||
if (!setupSuccess)
|
||||
{
|
||||
// shouldn't normally happen, but just in case
|
||||
return;
|
||||
}
|
||||
|
||||
this.renderObjectsCreated = true;
|
||||
}
|
||||
|
||||
this.shaderProgramForThisFrame = DhTerrainShaderProgram.INSTANCE;
|
||||
IDhApiShaderProgram lodShaderProgramOverride = OverrideInjector.INSTANCE.get(IDhApiShaderProgram.class);
|
||||
if (lodShaderProgramOverride != null && this.shaderProgramForThisFrame.overrideThisFrame())
|
||||
{
|
||||
this.shaderProgramForThisFrame = lodShaderProgramOverride;
|
||||
}
|
||||
|
||||
|
||||
this.setGLState(renderParams, firstPass);
|
||||
|
||||
DhTerrainShaderProgram.INSTANCE.quadIBO.bind();
|
||||
renderParams.lightmap.bind();
|
||||
}
|
||||
private void setGLState(
|
||||
DhApiRenderParam renderEventParam,
|
||||
boolean firstPass)
|
||||
{
|
||||
//===================//
|
||||
// framebuffer setup //
|
||||
//===================//
|
||||
|
||||
// get the active framebuffer
|
||||
IDhApiFramebuffer framebuffer = this.framebuffer;
|
||||
IDhApiFramebuffer framebufferOverride = OverrideInjector.INSTANCE.get(IDhApiFramebuffer.class);
|
||||
if (framebufferOverride != null && framebufferOverride.overrideThisFrame())
|
||||
{
|
||||
framebuffer = framebufferOverride;
|
||||
}
|
||||
this.activeFramebufferId = framebuffer.getId();
|
||||
framebuffer.bind();
|
||||
|
||||
|
||||
|
||||
//==========//
|
||||
// bindings //
|
||||
//==========//
|
||||
|
||||
// by default draw everything as triangles
|
||||
GL32.glPolygonMode(GL32.GL_FRONT_AND_BACK, GL32.GL_FILL);
|
||||
GLMC.enableFaceCulling();
|
||||
|
||||
GLMC.glBlendFunc(GL32.GL_SRC_ALPHA, GL32.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GLMC.glBlendFuncSeparate(GL32.GL_SRC_ALPHA, GL32.GL_ONE_MINUS_SRC_ALPHA, GL32.GL_ONE, GL32.GL_ZERO);
|
||||
|
||||
GL32.glDisable(GL32.GL_SCISSOR_TEST);
|
||||
|
||||
// Enable depth test and depth mask
|
||||
GLMC.enableDepthTest();
|
||||
GLMC.glDepthFunc(GL32.GL_LESS);
|
||||
GLMC.enableDepthMask();
|
||||
|
||||
// This is required for MC versions 1.21.5+
|
||||
// due to MC updating the lightmap by changing the viewport size
|
||||
GL32.glViewport(0, 0, this.textureWidth, this.textureHeight);
|
||||
|
||||
this.shaderProgramForThisFrame.bind();
|
||||
|
||||
|
||||
|
||||
//==========//
|
||||
// uniforms //
|
||||
//==========//
|
||||
|
||||
IDhApiShaderProgram shaderProgramOverride = OverrideInjector.INSTANCE.get(IDhApiShaderProgram.class);
|
||||
if (shaderProgramOverride != null)
|
||||
{
|
||||
shaderProgramOverride.fillUniformData(renderEventParam);
|
||||
}
|
||||
|
||||
this.shaderProgramForThisFrame.fillUniformData(renderEventParam);
|
||||
|
||||
|
||||
|
||||
//===============//
|
||||
// texture setup //
|
||||
//===============//
|
||||
|
||||
// resize the textures if needed
|
||||
if (MC_RENDER.getTargetFramebufferViewportWidth() != this.textureWidth
|
||||
|| MC_RENDER.getTargetFramebufferViewportHeight() != this.textureHeight)
|
||||
{
|
||||
// just resizing the textures doesn't work when Optifine is present,
|
||||
// so recreate the textures with the new size instead
|
||||
this.createAndBindTextures();
|
||||
}
|
||||
|
||||
|
||||
// set the active textures
|
||||
this.activeDepthTextureId = this.depthTexture.getTextureId();
|
||||
|
||||
if (this.nullableColorTexture != null)
|
||||
{
|
||||
this.activeColorTextureId = this.nullableColorTexture.getTextureId();
|
||||
}
|
||||
else
|
||||
{
|
||||
// get MC's color texture
|
||||
this.activeColorTextureId = GL32.glGetFramebufferAttachmentParameteri(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0, GL32.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME);
|
||||
}
|
||||
|
||||
|
||||
// needs to be fired after all the textures have been created/bound
|
||||
boolean clearTextures = !ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeTextureClearEvent.class, renderEventParam);
|
||||
if (clearTextures)
|
||||
{
|
||||
GL32.glClearDepth(1.0);
|
||||
|
||||
float[] clearColorValues = new float[4];
|
||||
GL32.glGetFloatv(GL32.GL_COLOR_CLEAR_VALUE, clearColorValues);
|
||||
GL32.glClearColor(clearColorValues[0], clearColorValues[1], clearColorValues[2], 1.0f);
|
||||
|
||||
if (this.usingMcFramebuffer && framebufferOverride == null)
|
||||
{
|
||||
// Due to using MC/Optifine's framebuffer we need to re-bind the depth texture,
|
||||
// otherwise we'll be writing to MC/Optifine's depth texture which causes rendering issues
|
||||
framebuffer.addDepthAttachment(this.depthTexture.getTextureId(), EDhDepthBufferFormat.DEPTH32F.isCombinedStencil());
|
||||
|
||||
|
||||
// don't clear the color texture, that removes the sky
|
||||
GL32.glClear(GL32.GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
else if (firstPass)
|
||||
{
|
||||
GL32.glClear(GL32.GL_COLOR_BUFFER_BIT | GL32.GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean createRenderObjects()
|
||||
{
|
||||
if (this.renderObjectsCreated)
|
||||
{
|
||||
LOGGER.warn("Renderer setup called but it has already completed setup!");
|
||||
return false;
|
||||
}
|
||||
|
||||
// GLProxy should have already been created by this point, but just in case create it now
|
||||
GLProxy.getInstance();
|
||||
|
||||
|
||||
|
||||
LOGGER.info("Setting up renderer");
|
||||
|
||||
DhTerrainShaderProgram.INSTANCE.quadIBO = new QuadElementBuffer();
|
||||
DhTerrainShaderProgram.INSTANCE.quadIBO.reserve(LodQuadBuilder.getMaxBufferByteSize());
|
||||
|
||||
|
||||
// create or get the frame buffer
|
||||
if (AbstractOptifineAccessor.optifinePresent())
|
||||
{
|
||||
// use MC/Optifine's default Framebuffer so shaders won't remove the LODs
|
||||
int currentFramebufferId = MC_RENDER.getTargetFramebuffer();
|
||||
this.framebuffer = new DhFramebuffer(currentFramebufferId);
|
||||
this.usingMcFramebuffer = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// normal use case
|
||||
this.framebuffer = new DhFramebuffer();
|
||||
this.usingMcFramebuffer = false;
|
||||
}
|
||||
|
||||
// create and bind the necessary textures
|
||||
this.createAndBindTextures();
|
||||
|
||||
if(this.framebuffer.getStatus() != GL32.GL_FRAMEBUFFER_COMPLETE)
|
||||
{
|
||||
// This generally means something wasn't bound, IE missing either the color or depth texture
|
||||
LOGGER.warn("Framebuffer ["+this.framebuffer.getId()+"] isn't complete.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
LOGGER.info("Renderer setup complete");
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings( "deprecation" ) // done to ignore DhApiColorDepthTextureCreatedEvent
|
||||
private void createAndBindTextures()
|
||||
{
|
||||
int oldWidth = this.textureWidth;
|
||||
int oldHeight = this.textureHeight;
|
||||
this.textureWidth = MC_RENDER.getTargetFramebufferViewportWidth();
|
||||
this.textureHeight = MC_RENDER.getTargetFramebufferViewportHeight();
|
||||
|
||||
DhApiTextureCreatedParam textureCreatedParam = new DhApiTextureCreatedParam(
|
||||
oldWidth, oldHeight,
|
||||
this.textureWidth, this.textureHeight
|
||||
);
|
||||
|
||||
|
||||
// DhApiColorDepthTextureCreatedEvent needs to be kept around since old versions of Iris need it
|
||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiColorDepthTextureCreatedEvent.class, new DhApiColorDepthTextureCreatedEvent.EventParam(textureCreatedParam));
|
||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeColorDepthTextureCreatedEvent.class, textureCreatedParam);
|
||||
|
||||
|
||||
// also update the framebuffer override if present
|
||||
IDhApiFramebuffer framebufferOverride = OverrideInjector.INSTANCE.get(IDhApiFramebuffer.class);
|
||||
|
||||
|
||||
this.depthTexture = new DHDepthTexture(this.textureWidth, this.textureHeight, EDhDepthBufferFormat.DEPTH32F);
|
||||
this.framebuffer.addDepthAttachment(this.depthTexture.getTextureId(), EDhDepthBufferFormat.DEPTH32F.isCombinedStencil());
|
||||
if (framebufferOverride != null)
|
||||
{
|
||||
framebufferOverride.addDepthAttachment(this.depthTexture.getTextureId(), EDhDepthBufferFormat.DEPTH32F.isCombinedStencil());
|
||||
}
|
||||
|
||||
|
||||
// if we are using MC's frame buffer, a color texture is already present and shouldn't need to be bound
|
||||
if (!this.usingMcFramebuffer)
|
||||
{
|
||||
this.nullableColorTexture = DhColorTexture.builder()
|
||||
.setDimensions(this.textureWidth, this.textureHeight)
|
||||
.setInternalFormat(EDhInternalTextureFormat.RGBA8)
|
||||
.setPixelType(EDhPixelType.UNSIGNED_BYTE)
|
||||
.setPixelFormat(EDhPixelFormat.RGBA)
|
||||
.build();
|
||||
|
||||
this.framebuffer.addColorAttachment(0, this.nullableColorTexture.getTextureId());
|
||||
if (framebufferOverride != null)
|
||||
{
|
||||
framebufferOverride.addColorAttachment(0, this.nullableColorTexture.getTextureId());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.nullableColorTexture = null;
|
||||
}
|
||||
|
||||
|
||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiAfterColorDepthTextureCreatedEvent.class, textureCreatedParam);
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
|
||||
|
||||
//=============//
|
||||
// post render //
|
||||
//=============//
|
||||
//region
|
||||
|
||||
@Override
|
||||
public void runRenderPassCleanup(RenderParams renderParams)
|
||||
{
|
||||
boolean runningDeferredPass = (renderParams.renderPass == EDhApiRenderPass.TRANSPARENT);
|
||||
if (!runningDeferredPass)
|
||||
{
|
||||
//===================//
|
||||
// optifine clean up //
|
||||
//===================//
|
||||
|
||||
if (this.usingMcFramebuffer)
|
||||
{
|
||||
// If MC's framebuffer is being used the depth needs to be cleared to prevent rendering on top of MC.
|
||||
// This should only happen when Optifine shaders are being used.
|
||||
GL32.glClear(GL32.GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
renderParams.lightmap.unbind();
|
||||
DhTerrainShaderProgram.INSTANCE.quadIBO.unbind();
|
||||
this.shaderProgramForThisFrame.unbind();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToMcTexture() { DhApplyShader.INSTANCE.render(0.0f); }
|
||||
|
||||
//endregion
|
||||
|
||||
|
||||
|
||||
//================//
|
||||
// clear textures //
|
||||
//================//
|
||||
//region
|
||||
|
||||
@Override
|
||||
public void clearDhDepthAndColorTextures(RenderParams renderParams)
|
||||
{
|
||||
IDhApiFramebuffer framebufferOverride = OverrideInjector.INSTANCE.get(IDhApiFramebuffer.class);
|
||||
|
||||
boolean firstPass =
|
||||
(renderParams.renderPass == EDhApiRenderPass.OPAQUE
|
||||
|| renderParams.renderPass == EDhApiRenderPass.OPAQUE_AND_TRANSPARENT);
|
||||
|
||||
|
||||
|
||||
// needs to be fired after all the textures have been created/bound
|
||||
boolean clearTextures = !ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeTextureClearEvent.class, renderParams);
|
||||
if (clearTextures)
|
||||
{
|
||||
GL32.glClearDepth(1.0);
|
||||
|
||||
float[] clearColorValues = new float[4];
|
||||
GL32.glGetFloatv(GL32.GL_COLOR_CLEAR_VALUE, clearColorValues);
|
||||
GL32.glClearColor(clearColorValues[0], clearColorValues[1], clearColorValues[2], 1.0f);
|
||||
|
||||
if (this.usingMcFramebuffer
|
||||
&& framebufferOverride == null)
|
||||
{
|
||||
//// Due to using MC/Optifine's framebuffer we need to re-bind the depth texture,
|
||||
//// otherwise we'll be writing to MC/Optifine's depth texture which causes rendering issues
|
||||
//this.framebuffer.addDepthAttachment(this.depthTexture.getTextureId(), EDhDepthBufferFormat.DEPTH32F.isCombinedStencil());
|
||||
|
||||
|
||||
// don't clear the color texture, that removes the sky
|
||||
GL32.glClear(GL32.GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
else if (firstPass)
|
||||
{
|
||||
GL32.glClear(GL32.GL_COLOR_BUFFER_BIT | GL32.GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
|
||||
|
||||
//===============//
|
||||
// API functions //
|
||||
//===============//
|
||||
//region
|
||||
|
||||
/** @return -1 if no frame buffer has been bound yet */
|
||||
public int getActiveFramebufferId() { return this.activeFramebufferId; }
|
||||
|
||||
/** @return -1 if no texture has been bound yet */
|
||||
public int getActiveColorTextureId() { return this.activeColorTextureId; }
|
||||
|
||||
/** @return -1 if no texture has been bound yet */
|
||||
public int getActiveDepthTextureId() { return this.activeDepthTextureId; }
|
||||
|
||||
//endregion
|
||||
|
||||
|
||||
|
||||
}
|
||||
+2
-1
@@ -21,7 +21,8 @@ public class OpenGlDhRenderApiDefinition extends AbstractDhRenderApiDefinition
|
||||
|
||||
public String getApiName() { return "OpenGL"; }
|
||||
|
||||
@Override public IDhTerrainRenderer getTerrainRenderer() { return new DhTerrainShaderProgram(); } // TODO not implemented // TODO how to support Iris?
|
||||
@Override public IDhMetaRenderer getMetaRenderer() { return OpenGlDhMetaRenderer.INSTANCE; }
|
||||
@Override public IDhTerrainRenderer getTerrainRenderer() { return DhTerrainShaderProgram.INSTANCE; } // TODO how to support Iris?
|
||||
@Override public IDhSsaoRenderer getSsaoRenderer() { return DhSSAORenderer.INSTANCE; }
|
||||
@Override public IDhFogRenderer getFogRenderer() { return DhFogRenderer.INSTANCE; }
|
||||
@Override public IDhFarFadeRenderer getFarFadeRenderer() { return DhFarFadeRenderer.INSTANCE; }
|
||||
|
||||
+6
-5
@@ -20,6 +20,7 @@
|
||||
package com.seibel.distanthorizons.common.render.nativeGl.postProcessing.apply;
|
||||
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.DhTerrainShaderProgram;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.OpenGlDhMetaRenderer;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.glObject.GLState;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.glObject.shader.ShaderProgram;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.postProcessing.ScreenQuad;
|
||||
@@ -117,11 +118,11 @@ public class DhApplyShader extends AbstractShaderRenderer
|
||||
//GLMC.glBlendFunc(GL32.GL_ONE, GL32.GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
GLMC.glActiveTexture(GL32.GL_TEXTURE0);
|
||||
GLMC.glBindTexture(DhTerrainShaderProgram.OpenGlRenderState.INSTANCE.getActiveColorTextureId());
|
||||
GLMC.glBindTexture(OpenGlDhMetaRenderer.INSTANCE.getActiveColorTextureId());
|
||||
GL32.glUniform1i(this.gDhColorTextureUniform, 0);
|
||||
|
||||
GLMC.glActiveTexture(GL32.GL_TEXTURE1);
|
||||
GLMC.glBindTexture(DhTerrainShaderProgram.OpenGlRenderState.INSTANCE.getActiveDepthTextureId());
|
||||
GLMC.glBindTexture(OpenGlDhMetaRenderer.INSTANCE.getActiveDepthTextureId());
|
||||
GL32.glUniform1i(this.gDepthMapUniform, 1);
|
||||
|
||||
// Copy to MC's framebuffer
|
||||
@@ -141,7 +142,7 @@ public class DhApplyShader extends AbstractShaderRenderer
|
||||
return;
|
||||
}
|
||||
|
||||
int dhFrameBufferId = DhTerrainShaderProgram.OpenGlRenderState.INSTANCE.getActiveFramebufferId();
|
||||
int dhFrameBufferId = OpenGlDhMetaRenderer.INSTANCE.getActiveFramebufferId();
|
||||
if (dhFrameBufferId == -1)
|
||||
{
|
||||
return;
|
||||
@@ -165,11 +166,11 @@ public class DhApplyShader extends AbstractShaderRenderer
|
||||
GLMC.disableBlend();
|
||||
|
||||
GLMC.glActiveTexture(GL32.GL_TEXTURE0);
|
||||
GLMC.glBindTexture(DhTerrainShaderProgram.OpenGlRenderState.INSTANCE.getActiveColorTextureId());
|
||||
GLMC.glBindTexture(OpenGlDhMetaRenderer.INSTANCE.getActiveColorTextureId());
|
||||
GL32.glUniform1i(this.gDhColorTextureUniform, 0);
|
||||
|
||||
GLMC.glActiveTexture(GL32.GL_TEXTURE1);
|
||||
GLMC.glBindTexture(DhTerrainShaderProgram.OpenGlRenderState.INSTANCE.getActiveDepthTextureId());
|
||||
GLMC.glBindTexture(OpenGlDhMetaRenderer.INSTANCE.getActiveDepthTextureId());
|
||||
GL32.glUniform1i(this.gDepthMapUniform, 1);
|
||||
|
||||
|
||||
|
||||
+2
-1
@@ -20,6 +20,7 @@
|
||||
package com.seibel.distanthorizons.common.render.nativeGl.postProcessing.fade;
|
||||
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.DhTerrainShaderProgram;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.OpenGlDhMetaRenderer;
|
||||
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftGLWrapper;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||
@@ -145,7 +146,7 @@ public class DhFarFadeRenderer implements IDhFarFadeRenderer
|
||||
|
||||
DhFarFadeApplyShader.INSTANCE.fadeTexture = this.fadeTexture;
|
||||
DhFarFadeApplyShader.INSTANCE.readFramebuffer = DhFarFadeShader.INSTANCE.frameBuffer;
|
||||
DhFarFadeApplyShader.INSTANCE.drawFramebuffer = DhTerrainShaderProgram.OpenGlRenderState.INSTANCE.getActiveFramebufferId();
|
||||
DhFarFadeApplyShader.INSTANCE.drawFramebuffer = OpenGlDhMetaRenderer.INSTANCE.getActiveFramebufferId();
|
||||
DhFarFadeApplyShader.INSTANCE.render(0.0f);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
+3
-2
@@ -21,6 +21,7 @@ package com.seibel.distanthorizons.common.render.nativeGl.postProcessing.fade;
|
||||
|
||||
import com.seibel.distanthorizons.api.objects.math.DhApiMat4f;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.DhTerrainShaderProgram;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.OpenGlDhMetaRenderer;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.glObject.shader.ShaderProgram;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.postProcessing.ScreenQuad;
|
||||
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftGLWrapper;
|
||||
@@ -128,8 +129,8 @@ public class DhFarFadeShader extends AbstractShaderRenderer
|
||||
@Override
|
||||
protected void onRender()
|
||||
{
|
||||
int depthTextureId = DhTerrainShaderProgram.OpenGlRenderState.INSTANCE.getActiveDepthTextureId();
|
||||
int colorTextureId = DhTerrainShaderProgram.OpenGlRenderState.INSTANCE.getActiveColorTextureId();
|
||||
int depthTextureId = OpenGlDhMetaRenderer.INSTANCE.getActiveDepthTextureId();
|
||||
int colorTextureId = OpenGlDhMetaRenderer.INSTANCE.getActiveColorTextureId();
|
||||
|
||||
if (depthTextureId == -1
|
||||
|| colorTextureId == -1)
|
||||
|
||||
+2
-1
@@ -20,6 +20,7 @@
|
||||
package com.seibel.distanthorizons.common.render.nativeGl.postProcessing.fade;
|
||||
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.DhTerrainShaderProgram;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.OpenGlDhMetaRenderer;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.glObject.GLState;
|
||||
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftGLWrapper;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
@@ -125,7 +126,7 @@ public class VanillaFadeRenderer implements IDhVanillaFadeRenderer
|
||||
@Override
|
||||
public void render(Mat4f mcModelViewMatrix, Mat4f mcProjectionMatrix, IClientLevelWrapper level)
|
||||
{
|
||||
int depthTextureId = DhTerrainShaderProgram.OpenGlRenderState.INSTANCE.getActiveDepthTextureId();
|
||||
int depthTextureId = OpenGlDhMetaRenderer.INSTANCE.getActiveDepthTextureId();
|
||||
if (depthTextureId == -1)
|
||||
{
|
||||
// the renderer hasn't been set up yet
|
||||
|
||||
+3
-2
@@ -20,6 +20,7 @@
|
||||
package com.seibel.distanthorizons.common.render.nativeGl.postProcessing.fade;
|
||||
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.DhTerrainShaderProgram;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.OpenGlDhMetaRenderer;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.glObject.shader.ShaderProgram;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.postProcessing.ScreenQuad;
|
||||
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftGLWrapper;
|
||||
@@ -164,8 +165,8 @@ public class VanillaFadeShader extends AbstractShaderRenderer
|
||||
@Override
|
||||
protected void onRender()
|
||||
{
|
||||
int depthTextureId = DhTerrainShaderProgram.OpenGlRenderState.INSTANCE.getActiveDepthTextureId();
|
||||
int colorTextureId = DhTerrainShaderProgram.OpenGlRenderState.INSTANCE.getActiveColorTextureId();
|
||||
int depthTextureId = OpenGlDhMetaRenderer.INSTANCE.getActiveDepthTextureId();
|
||||
int colorTextureId = OpenGlDhMetaRenderer.INSTANCE.getActiveColorTextureId();
|
||||
|
||||
if (depthTextureId == -1
|
||||
|| colorTextureId == -1)
|
||||
|
||||
+3
-2
@@ -20,6 +20,7 @@
|
||||
package com.seibel.distanthorizons.common.render.nativeGl.postProcessing.fog;
|
||||
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.DhTerrainShaderProgram;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.OpenGlDhMetaRenderer;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.glObject.shader.ShaderProgram;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.postProcessing.ScreenQuad;
|
||||
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftGLWrapper;
|
||||
@@ -81,7 +82,7 @@ public class FogApplyShader extends AbstractShaderRenderer
|
||||
GL32.glUniform1i(this.colorTextureUniform, 0);
|
||||
|
||||
GLMC.glActiveTexture(GL32.GL_TEXTURE1);
|
||||
GLMC.glBindTexture(DhTerrainShaderProgram.OpenGlRenderState.INSTANCE.getActiveDepthTextureId());
|
||||
GLMC.glBindTexture(OpenGlDhMetaRenderer.INSTANCE.getActiveDepthTextureId());
|
||||
GL32.glUniform1i(this.depthTextureUniform, 1);
|
||||
|
||||
}
|
||||
@@ -107,7 +108,7 @@ public class FogApplyShader extends AbstractShaderRenderer
|
||||
|
||||
// apply the rendered Fog to DH's framebuffer
|
||||
GLMC.glBindFramebuffer(GL32.GL_READ_FRAMEBUFFER, FogShader.INSTANCE.frameBuffer);
|
||||
GLMC.glBindFramebuffer(GL32.GL_DRAW_FRAMEBUFFER, DhTerrainShaderProgram.OpenGlRenderState.INSTANCE.getActiveFramebufferId());
|
||||
GLMC.glBindFramebuffer(GL32.GL_DRAW_FRAMEBUFFER, OpenGlDhMetaRenderer.INSTANCE.getActiveFramebufferId());
|
||||
|
||||
ScreenQuad.INSTANCE.render();
|
||||
|
||||
|
||||
+2
-1
@@ -24,6 +24,7 @@ import com.seibel.distanthorizons.api.enums.rendering.EDhApiHeightFogDirection;
|
||||
import com.seibel.distanthorizons.api.enums.rendering.EDhApiHeightFogMixMode;
|
||||
import com.seibel.distanthorizons.api.objects.math.DhApiMat4f;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.DhTerrainShaderProgram;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.OpenGlDhMetaRenderer;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.glObject.shader.ShaderProgram;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.postProcessing.ScreenQuad;
|
||||
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftGLWrapper;
|
||||
@@ -266,7 +267,7 @@ public class FogShader extends AbstractShaderRenderer
|
||||
GLMC.disableBlend();
|
||||
|
||||
GLMC.glActiveTexture(GL32.GL_TEXTURE0);
|
||||
GLMC.glBindTexture(DhTerrainShaderProgram.OpenGlRenderState.INSTANCE.getActiveDepthTextureId());
|
||||
GLMC.glBindTexture(OpenGlDhMetaRenderer.INSTANCE.getActiveDepthTextureId());
|
||||
GL32.glUniform1i(this.uDepthMap, 0);
|
||||
|
||||
// this is necessary for MC 1.16 (IE Legacy OpenGL)
|
||||
|
||||
+3
-2
@@ -20,6 +20,7 @@
|
||||
package com.seibel.distanthorizons.common.render.nativeGl.postProcessing.ssao;
|
||||
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.DhTerrainShaderProgram;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.OpenGlDhMetaRenderer;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.glObject.shader.ShaderProgram;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.postProcessing.ScreenQuad;
|
||||
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftGLWrapper;
|
||||
@@ -85,7 +86,7 @@ public class SSAOApplyShader extends AbstractShaderRenderer
|
||||
protected void onApplyUniforms(float partialTicks)
|
||||
{
|
||||
GLMC.glActiveTexture(GL32.GL_TEXTURE0);
|
||||
GLMC.glBindTexture(DhTerrainShaderProgram.OpenGlRenderState.INSTANCE.getActiveDepthTextureId());
|
||||
GLMC.glBindTexture(OpenGlDhMetaRenderer.INSTANCE.getActiveDepthTextureId());
|
||||
GL32.glUniform1i(this.gDepthMapUniform, 0);
|
||||
|
||||
GLMC.glActiveTexture(GL32.GL_TEXTURE1);
|
||||
@@ -134,7 +135,7 @@ public class SSAOApplyShader extends AbstractShaderRenderer
|
||||
|
||||
// apply the rendered SSAO to the LODs
|
||||
GLMC.glBindFramebuffer(GL32.GL_READ_FRAMEBUFFER, SSAOShader.INSTANCE.frameBuffer);
|
||||
GLMC.glBindFramebuffer(GL32.GL_DRAW_FRAMEBUFFER, DhTerrainShaderProgram.OpenGlRenderState.INSTANCE.getActiveFramebufferId());
|
||||
GLMC.glBindFramebuffer(GL32.GL_DRAW_FRAMEBUFFER, OpenGlDhMetaRenderer.INSTANCE.getActiveFramebufferId());
|
||||
|
||||
|
||||
ScreenQuad.INSTANCE.render();
|
||||
|
||||
+2
-1
@@ -21,6 +21,7 @@ package com.seibel.distanthorizons.common.render.nativeGl.postProcessing.ssao;
|
||||
|
||||
import com.seibel.distanthorizons.api.objects.math.DhApiMat4f;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.DhTerrainShaderProgram;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.OpenGlDhMetaRenderer;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.glObject.shader.ShaderProgram;
|
||||
import com.seibel.distanthorizons.common.render.nativeGl.postProcessing.ScreenQuad;
|
||||
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftGLWrapper;
|
||||
@@ -133,7 +134,7 @@ public class SSAOShader extends AbstractShaderRenderer
|
||||
GLMC.disableBlend();
|
||||
|
||||
GLMC.glActiveTexture(GL32.GL_TEXTURE0);
|
||||
GLMC.glBindTexture(DhTerrainShaderProgram.OpenGlRenderState.INSTANCE.getActiveDepthTextureId());
|
||||
GLMC.glBindTexture(OpenGlDhMetaRenderer.INSTANCE.getActiveDepthTextureId());
|
||||
|
||||
ScreenQuad.INSTANCE.render();
|
||||
}
|
||||
|
||||
+2
@@ -133,6 +133,8 @@ public class GlTestTriangleRenderer implements IDhTestTriangleRenderer
|
||||
this.va.bindBufferToAllBindingPoints(this.vbo.getId());
|
||||
|
||||
GL32.glDrawArrays(GL32.GL_TRIANGLES, 0, 3);
|
||||
|
||||
DhApplyShader.INSTANCE.render(0.0f);
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
+1
-1
Submodule coreSubProjects updated: 1b0f93db07...0362d89173
Reference in New Issue
Block a user