Make IVertexConsumers such as the lighting pipeline, be aware of which format they are dealing with (#8665)

Also fix Lighting pipeline ignoring the overlay coords from the block renderer.
This commit is contained in:
gigaherz authored and GitHub committed 2022-06-09 21:41:00 +02:00
1 parent 67d4a0163b
commit be0facc2aa
13 files changed
+127 -53

No files matched your search

@@ -8,7 +8,7 @@
this.f_85648_.clear();
return Pair.of(bufferbuilder$drawstate, bytebuffer);
}
@@ -444,4 +_,15 @@
@@ -444,4 +_,16 @@
this.f_166822_ = p_166829_;
}
}
@@ -22,5 +22,6 @@
+ this.f_85652_ += buffer.limit();
+ }
+
+ @Override
+ public VertexFormat getVertexFormat() { return this.f_85658_; }
}
@@ -0,0 +1,9 @@
--- a/com/mojang/blaze3d/vertex/SheetedDecalTextureGenerator.java
+++ b/com/mojang/blaze3d/vertex/SheetedDecalTextureGenerator.java
@@ -91,4 +_,6 @@
this.f_85878_ = p_85902_;
return this;
}
+
+ public VertexFormat getVertexFormat() { return f_85867_.getVertexFormat(); }
}
@@ -0,0 +1,25 @@
--- a/com/mojang/blaze3d/vertex/VertexMultiConsumer.java
+++ b/com/mojang/blaze3d/vertex/VertexMultiConsumer.java
@@ -91,6 +_,8 @@
this.f_86171_.m_141991_();
this.f_86172_.m_141991_();
}
+
+ public VertexFormat getVertexFormat() { return f_86171_.getVertexFormat(); }
}
@OnlyIn(Dist.CLIENT)
@@ -176,6 +_,13 @@
public void m_141991_() {
this.m_167144_(VertexConsumer::m_141991_);
+ }
+
+ public VertexFormat getVertexFormat()
+ {
+ if (f_167071_.length > 0)
+ return f_167071_[0].getVertexFormat();
+ return DefaultVertexFormat.f_85811_;
}
}
}
@@ -0,0 +1,10 @@
--- a/net/minecraft/client/renderer/OutlineBufferSource.java
+++ b/net/minecraft/client/renderer/OutlineBufferSource.java
@@ -105,5 +_,7 @@
public void m_5752_() {
this.f_109936_.m_5483_(this.f_109937_, this.f_109938_, this.f_109939_).m_6122_(this.f_85825_, this.f_85826_, this.f_85827_, this.f_85828_).m_7421_(this.f_109940_, this.f_109941_).m_5752_();
}
+
+ public com.mojang.blaze3d.vertex.VertexFormat getVertexFormat() { return f_109936_.getVertexFormat(); }
}
}
@@ -0,0 +1,9 @@
--- a/net/minecraft/client/renderer/SpriteCoordinateExpander.java
+++ b/net/minecraft/client/renderer/SpriteCoordinateExpander.java
@@ -54,4 +_,6 @@
public void m_5954_(float p_110808_, float p_110809_, float p_110810_, float p_110811_, float p_110812_, float p_110813_, float p_110814_, float p_110815_, float p_110816_, int p_110817_, int p_110818_, float p_110819_, float p_110820_, float p_110821_) {
this.f_110795_.m_5954_(p_110808_, p_110809_, p_110810_, p_110811_, p_110812_, p_110813_, p_110814_, this.f_110796_.m_118367_((double)(p_110815_ * 16.0F)), this.f_110796_.m_118393_((double)(p_110816_ * 16.0F)), p_110817_, p_110818_, p_110819_, p_110820_, p_110821_);
}
+
+ public com.mojang.blaze3d.vertex.VertexFormat getVertexFormat() { return f_110795_.getVertexFormat(); }
}
@@ -5,13 +5,14 @@
package net.minecraftforge.client.extensions;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.blaze3d.vertex.VertexFormat;
import net.minecraft.client.renderer.block.model.BakedQuad;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import net.minecraftforge.client.model.pipeline.LightUtil;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.system.MemoryStack;
import java.nio.Buffer;
@@ -26,6 +27,13 @@ import net.minecraft.core.Vec3i;
public interface IForgeVertexConsumer
{
// TODO 1.19: Make not default and not nullable
@Nullable
default VertexFormat getVertexFormat()
{
return null;
}
// Copy of putBulkData, but enables tinting and per-vertex alpha
default void putBulkData(PoseStack.Pose poseStack, BakedQuad bakedQuad, float red, float green, float blue, int packedLight, int packedOverlay, boolean readExistingColor) {
putBulkData(poseStack, bakedQuad, red, green, blue, 1.0f, packedLight, packedOverlay, readExistingColor);
@@ -1,20 +1,6 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2022.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.client.gui;
@@ -43,6 +43,7 @@ public class ForgeBlockModelRenderer extends ModelBlockRenderer
{
VertexBufferConsumer consumer = consumerFlat.get();
consumer.setBuffer(buffer);
consumer.setPackedOverlay(packedOverlay);
VertexLighterFlat lighter = lighterFlat.get();
lighter.setParent(consumer);
@@ -63,6 +64,7 @@ public class ForgeBlockModelRenderer extends ModelBlockRenderer
{
VertexBufferConsumer consumer = consumerSmooth.get();
consumer.setBuffer(buffer);
consumer.setPackedOverlay(packedOverlay);
VertexLighterSmoothAo lighter = lighterSmooth.get();
lighter.setParent(consumer);
@@ -7,19 +7,31 @@ package net.minecraftforge.client.model.pipeline;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.blaze3d.vertex.VertexFormatElement;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.VertexFormat;
import net.minecraft.core.Direction;
import org.jetbrains.annotations.Nullable;
import java.util.List;
/**
* Assumes VertexFormatElement is present in the BufferBuilder's vertex format.
*/
public class VertexBufferConsumer implements IVertexConsumer
{
private VertexFormat format;
private List<VertexFormatElement> elements;
private VertexConsumer renderer;
private boolean overrideOverlayCoords;
private int overlayCoordU;
private int overlayCoordV;
public VertexBufferConsumer() {}
public VertexBufferConsumer()
{
setVertexFormat(DefaultVertexFormat.BLOCK);
}
public VertexBufferConsumer(VertexConsumer buffer)
{
@@ -29,7 +41,7 @@ public class VertexBufferConsumer implements IVertexConsumer
@Override
public final VertexFormat getVertexFormat()
{
return DefaultVertexFormat.BLOCK;
return format;
}
@Override
@@ -40,24 +52,36 @@ public class VertexBufferConsumer implements IVertexConsumer
final float d2 = data.length <= 2 ? 0 : data[2];
final float d3 = data.length <= 3 ? 0 : data[3];
switch (e)
var element = elements.get(e);
switch (element.getUsage())
{
case 0: // POSITION_3F
renderer.vertex(d0, d1, d2);
case POSITION: // POSITION_3F
if (element.getIndex() == 0)
renderer.vertex(d0, d1, d2);
break;
case 4: // NORMAL_3B
renderer.normal(d0, d1, d2);
case NORMAL: // NORMAL_3B
if (element.getIndex() == 0)
renderer.normal(d0, d1, d2);
break;
case 1: // COLOR_4UB
renderer.color(d0, d1, d2, d3);
case COLOR: // COLOR_4UB
if (element.getIndex() == 0)
renderer.color(d0, d1, d2, d3);
break;
case 2: // TEX_2F
renderer.uv(d0, d1);
case UV: // TEX_2F
switch(element.getIndex())
{
case 0 -> renderer.uv(d0, d1);
case 1 -> {
if (overrideOverlayCoords)
renderer.overlayCoords(overlayCoordU, overlayCoordV);
else
renderer.overlayCoords((int) (d0 * 32767f), (int) (d1 * 32767f));
}
case 2 -> renderer.uv2((int) (d0 * 0xF0), (int) (d1 * 0xF0));
}
break;
case 3: // TEX_2SB
renderer.uv2((int) (d0 * 0xF0), (int) (d1 * 0xF0));
break;
case 5: // PADDING_1B
case PADDING:
break;
default:
throw new IllegalArgumentException("Vertex element out of bounds: " + e);
@@ -71,6 +95,13 @@ public class VertexBufferConsumer implements IVertexConsumer
public void setBuffer(VertexConsumer buffer)
{
this.renderer = buffer;
setVertexFormat(buffer.getVertexFormat());
}
public void setVertexFormat(@Nullable VertexFormat format)
{
this.format = format != null ? format : DefaultVertexFormat.BLOCK;
this.elements = this.format.getElements();
}
@Override
@@ -81,4 +112,11 @@ public class VertexBufferConsumer implements IVertexConsumer
public void setApplyDiffuseLighting(boolean diffuse) {}
@Override
public void setTexture(TextureAtlasSprite texture ) {}
public void setPackedOverlay(int packedOverlay)
{
this.overrideOverlayCoords = true;
this.overlayCoordV = (packedOverlay >> 16) & 0xFFFF;
this.overlayCoordU = (packedOverlay) & 0xFFFF;
}
}
@@ -1,5 +1,5 @@
/*
* Minecraft Forge - Forge Development LLC
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
@@ -1,5 +1,5 @@
/*
* Minecraft Forge - Forge Development LLC
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
@@ -1,5 +1,5 @@
/*
* Minecraft Forge - Forge Development LLC
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
@@ -1,20 +1,6 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2022.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.debug.misc;