Fix some vertex format changes not being handled correctly (#5368)
This commit is contained in:
parent
441a9c9024
commit
1fcfd54584
4 changed files with 73 additions and 46 deletions
|
@ -544,9 +544,10 @@ public class ForgeHooksClient
|
||||||
VertexFormat format = quad.getFormat();
|
VertexFormat format = quad.getFormat();
|
||||||
int size = format.getIntegerSize();
|
int size = format.getIntegerSize();
|
||||||
int offset = format.getColorOffset() / 4; // assumes that color is aligned
|
int offset = format.getColorOffset() / 4; // assumes that color is aligned
|
||||||
|
boolean hasColor = format.hasColor();
|
||||||
for(int i = 0; i < 4; i++)
|
for(int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
int vc = quad.getVertexData()[offset + size * i];
|
int vc = hasColor ? quad.getVertexData()[offset + size * i] : 0xFFFFFFFF;
|
||||||
float vcr = vc & 0xFF;
|
float vcr = vc & 0xFF;
|
||||||
float vcg = (vc >>> 8) & 0xFF;
|
float vcg = (vc >>> 8) & 0xFF;
|
||||||
float vcb = (vc >>> 16) & 0xFF;
|
float vcb = (vc >>> 16) & 0xFF;
|
||||||
|
|
|
@ -39,10 +39,8 @@ public class ForgeBlockModelRenderer extends BlockModelRenderer
|
||||||
{
|
{
|
||||||
private final ThreadLocal<VertexLighterFlat> lighterFlat;
|
private final ThreadLocal<VertexLighterFlat> lighterFlat;
|
||||||
private final ThreadLocal<VertexLighterSmoothAo> lighterSmooth;
|
private final ThreadLocal<VertexLighterSmoothAo> lighterSmooth;
|
||||||
private final ThreadLocal<VertexBufferConsumer> wrFlat = new ThreadLocal<>();
|
private final ThreadLocal<VertexBufferConsumer> consumerFlat = ThreadLocal.withInitial(VertexBufferConsumer::new);
|
||||||
private final ThreadLocal<VertexBufferConsumer> wrSmooth = new ThreadLocal<>();
|
private final ThreadLocal<VertexBufferConsumer> consumerSmooth = ThreadLocal.withInitial(VertexBufferConsumer::new);
|
||||||
private final ThreadLocal<BufferBuilder> lastRendererFlat = new ThreadLocal<>();
|
|
||||||
private final ThreadLocal<BufferBuilder> lastRendererSmooth = new ThreadLocal<>();
|
|
||||||
|
|
||||||
public ForgeBlockModelRenderer(BlockColors colors)
|
public ForgeBlockModelRenderer(BlockColors colors)
|
||||||
{
|
{
|
||||||
|
@ -56,15 +54,14 @@ public class ForgeBlockModelRenderer extends BlockModelRenderer
|
||||||
{
|
{
|
||||||
if(ForgeMod.forgeLightPipelineEnabled)
|
if(ForgeMod.forgeLightPipelineEnabled)
|
||||||
{
|
{
|
||||||
if(buffer != lastRendererFlat.get())
|
VertexBufferConsumer consumer = consumerFlat.get();
|
||||||
{
|
consumer.setBuffer(buffer);
|
||||||
lastRendererFlat.set(buffer);
|
consumer.setOffset(pos);
|
||||||
VertexBufferConsumer newCons = new VertexBufferConsumer(buffer);
|
|
||||||
wrFlat.set(newCons);
|
VertexLighterFlat lighter = lighterFlat.get();
|
||||||
lighterFlat.get().setParent(newCons);
|
lighter.setParent(consumer);
|
||||||
}
|
|
||||||
wrFlat.get().setOffset(pos);
|
return render(lighter, world, model, state, pos, buffer, checkSides, rand, seed);
|
||||||
return render(lighterFlat.get(), world, model, state, pos, buffer, checkSides, rand, seed);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -77,15 +74,14 @@ public class ForgeBlockModelRenderer extends BlockModelRenderer
|
||||||
{
|
{
|
||||||
if(ForgeMod.forgeLightPipelineEnabled)
|
if(ForgeMod.forgeLightPipelineEnabled)
|
||||||
{
|
{
|
||||||
if(buffer != lastRendererSmooth.get())
|
VertexBufferConsumer consumer = consumerSmooth.get();
|
||||||
{
|
consumer.setBuffer(buffer);
|
||||||
lastRendererSmooth.set(buffer);
|
consumer.setOffset(pos);
|
||||||
VertexBufferConsumer newCons = new VertexBufferConsumer(buffer);
|
|
||||||
wrSmooth.set(newCons);
|
VertexLighterSmoothAo lighter = lighterSmooth.get();
|
||||||
lighterSmooth.get().setParent(newCons);
|
lighter.setParent(consumer);
|
||||||
}
|
|
||||||
wrSmooth.get().setOffset(pos);
|
return render(lighter, world, model, state, pos, buffer, checkSides, rand, seed);
|
||||||
return render(lighterSmooth.get(), world, model, state, pos, buffer, checkSides, rand, seed);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -250,6 +250,7 @@ public class LightUtil
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IVertexConsumer tessellator = null;
|
private static IVertexConsumer tessellator = null;
|
||||||
|
@Deprecated // TODO: remove
|
||||||
public static IVertexConsumer getTessellator()
|
public static IVertexConsumer getTessellator()
|
||||||
{
|
{
|
||||||
if(tessellator == null)
|
if(tessellator == null)
|
||||||
|
@ -262,6 +263,7 @@ public class LightUtil
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ItemConsumer itemConsumer = null;
|
private static ItemConsumer itemConsumer = null;
|
||||||
|
@Deprecated // TODO: remove
|
||||||
public static ItemConsumer getItemConsumer()
|
public static ItemConsumer getItemConsumer()
|
||||||
{
|
{
|
||||||
if(itemConsumer == null)
|
if(itemConsumer == null)
|
||||||
|
@ -271,20 +273,29 @@ public class LightUtil
|
||||||
return itemConsumer;
|
return itemConsumer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// renders quad in any Vertex Format, but is slower
|
private static final class ItemPipeline
|
||||||
public static void renderQuadColorSlow(BufferBuilder wr, BakedQuad quad, int auxColor)
|
|
||||||
{
|
{
|
||||||
ItemConsumer cons;
|
final VertexBufferConsumer bufferConsumer;
|
||||||
if(wr == Tessellator.getInstance().getBuffer())
|
final ItemConsumer itemConsumer;
|
||||||
|
|
||||||
|
ItemPipeline()
|
||||||
{
|
{
|
||||||
cons = getItemConsumer();
|
this.bufferConsumer = new VertexBufferConsumer();
|
||||||
|
this.itemConsumer = new ItemConsumer(bufferConsumer);
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
|
||||||
cons = new ItemConsumer(new VertexBufferConsumer(wr));
|
private static final ThreadLocal<ItemPipeline> itemPipeline = ThreadLocal.withInitial(ItemPipeline::new);
|
||||||
}
|
|
||||||
float b = (float)(auxColor & 0xFF) / 0xFF;
|
// renders quad in any Vertex Format, but is slower
|
||||||
float g = (float)((auxColor >>> 8) & 0xFF) / 0xFF;
|
public static void renderQuadColorSlow(BufferBuilder buffer, BakedQuad quad, int auxColor)
|
||||||
|
{
|
||||||
|
ItemPipeline pipeline = itemPipeline.get();
|
||||||
|
pipeline.bufferConsumer.setBuffer(buffer);
|
||||||
|
ItemConsumer cons = pipeline.itemConsumer;
|
||||||
|
|
||||||
|
float b = (float)( auxColor & 0xFF) / 0xFF;
|
||||||
|
float g = (float)((auxColor >>> 8) & 0xFF) / 0xFF;
|
||||||
float r = (float)((auxColor >>> 16) & 0xFF) / 0xFF;
|
float r = (float)((auxColor >>> 16) & 0xFF) / 0xFF;
|
||||||
float a = (float)((auxColor >>> 24) & 0xFF) / 0xFF;
|
float a = (float)((auxColor >>> 24) & 0xFF) / 0xFF;
|
||||||
|
|
||||||
|
@ -292,16 +303,19 @@ public class LightUtil
|
||||||
quad.pipe(cons);
|
quad.pipe(cons);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void renderQuadColor(BufferBuilder wr, BakedQuad quad, int auxColor)
|
public static void renderQuadColor(BufferBuilder buffer, BakedQuad quad, int auxColor)
|
||||||
{
|
{
|
||||||
if (quad.getFormat().equals(wr.getVertexFormat()))
|
if (quad.getFormat().equals(buffer.getVertexFormat()))
|
||||||
{
|
{
|
||||||
wr.addVertexData(quad.getVertexData());
|
buffer.addVertexData(quad.getVertexData());
|
||||||
ForgeHooksClient.putQuadColor(wr, quad, auxColor);
|
if (buffer.getVertexFormat().hasColor())
|
||||||
|
{
|
||||||
|
ForgeHooksClient.putQuadColor(buffer, quad, auxColor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
renderQuadColorSlow(wr, quad, auxColor);
|
renderQuadColorSlow(buffer, quad, auxColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,7 +342,8 @@ public class LightUtil
|
||||||
if(getVertexFormat().getElement(element).getUsage() == EnumUsage.COLOR)
|
if(getVertexFormat().getElement(element).getUsage() == EnumUsage.COLOR)
|
||||||
{
|
{
|
||||||
System.arraycopy(auxColor, 0, buf, 0, buf.length);
|
System.arraycopy(auxColor, 0, buf, 0, buf.length);
|
||||||
for(int i = 0; i < 4; i++)
|
int n = Math.min(4, data.length);
|
||||||
|
for(int i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
buf[i] *= data[i];
|
buf[i] *= data[i];
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,16 +32,17 @@ import net.minecraft.util.EnumFacing;
|
||||||
public class VertexBufferConsumer implements IVertexConsumer
|
public class VertexBufferConsumer implements IVertexConsumer
|
||||||
{
|
{
|
||||||
private static final float[] dummyColor = new float[]{ 1, 1, 1, 1 };
|
private static final float[] dummyColor = new float[]{ 1, 1, 1, 1 };
|
||||||
private final BufferBuilder renderer;
|
|
||||||
private final int[] quadData;
|
private BufferBuilder renderer;
|
||||||
|
private int[] quadData;
|
||||||
private int v = 0;
|
private int v = 0;
|
||||||
private BlockPos offset = BlockPos.ORIGIN;
|
private BlockPos offset = BlockPos.ORIGIN;
|
||||||
|
|
||||||
public VertexBufferConsumer(BufferBuilder renderer)
|
public VertexBufferConsumer() {}
|
||||||
|
|
||||||
|
public VertexBufferConsumer(BufferBuilder buffer)
|
||||||
{
|
{
|
||||||
super();
|
setBuffer(buffer);
|
||||||
this.renderer = renderer;
|
|
||||||
quadData = new int[renderer.getVertexFormat().getSize()/* / 4 * 4 */];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -72,6 +73,20 @@ public class VertexBufferConsumer implements IVertexConsumer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkVertexFormat()
|
||||||
|
{
|
||||||
|
if (quadData == null || renderer.getVertexFormat().getSize() != quadData.length)
|
||||||
|
{
|
||||||
|
quadData = new int[renderer.getVertexFormat().getSize()];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBuffer(BufferBuilder buffer)
|
||||||
|
{
|
||||||
|
this.renderer = buffer;
|
||||||
|
checkVertexFormat();
|
||||||
|
}
|
||||||
|
|
||||||
public void setOffset(BlockPos offset)
|
public void setOffset(BlockPos offset)
|
||||||
{
|
{
|
||||||
this.offset = new BlockPos(offset);
|
this.offset = new BlockPos(offset);
|
||||||
|
|
Loading…
Reference in a new issue