mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 08:17:35 +00:00
Optimise adding normal element to vertex formats (#4699)
This commit is contained in:
1 parent
4c1167c96d
commit
dda7bd5d42
1 file changed
+20
-10
@@ -31,7 +31,7 @@ import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import java.util.Objects;
|
||||
|
||||
public class VertexLighterFlat extends QuadGatheringTransformer
|
||||
{
|
||||
@@ -46,6 +46,8 @@ public class VertexLighterFlat extends QuadGatheringTransformer
|
||||
protected int colorIndex = -1;
|
||||
protected int lightmapIndex = -1;
|
||||
|
||||
protected VertexFormat baseFormat;
|
||||
|
||||
public VertexLighterFlat(BlockColors colors)
|
||||
{
|
||||
this.blockInfo = new BlockInfo(colors);
|
||||
@@ -55,9 +57,11 @@ public class VertexLighterFlat extends QuadGatheringTransformer
|
||||
public void setParent(IVertexConsumer parent)
|
||||
{
|
||||
super.setParent(parent);
|
||||
VertexFormat format = getVertexFormat(parent);
|
||||
if(Objects.equal(format, getVertexFormat())) return;
|
||||
setVertexFormat(format);
|
||||
setVertexFormat(parent.getVertexFormat());
|
||||
}
|
||||
|
||||
private void updateIndices()
|
||||
{
|
||||
for(int i = 0; i < getVertexFormat().getElementCount(); i++)
|
||||
{
|
||||
switch(getVertexFormat().getElement(i).getUsage())
|
||||
@@ -94,13 +98,19 @@ public class VertexLighterFlat extends QuadGatheringTransformer
|
||||
}
|
||||
}
|
||||
|
||||
private static VertexFormat getVertexFormat(IVertexConsumer parent)
|
||||
@Override
|
||||
public void setVertexFormat(VertexFormat format)
|
||||
{
|
||||
VertexFormat format = parent.getVertexFormat();
|
||||
if(format == null || format.hasNormal()) return format;
|
||||
format = new VertexFormat(format);
|
||||
format.addElement(NORMAL_4F);
|
||||
return format;
|
||||
if (Objects.equals(format, baseFormat)) return;
|
||||
baseFormat = format;
|
||||
super.setVertexFormat(withNormal(format));
|
||||
updateIndices();
|
||||
}
|
||||
|
||||
private static VertexFormat withNormal(VertexFormat format)
|
||||
{
|
||||
if (format == null || format.hasNormal()) return format;
|
||||
return new VertexFormat(format).addElement(NORMAL_4F);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user