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();
|
||||
int size = format.getIntegerSize();
|
||||
int offset = format.getColorOffset() / 4; // assumes that color is aligned
|
||||
boolean hasColor = format.hasColor();
|
||||
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 vcg = (vc >>> 8) & 0xFF;
|
||||
float vcb = (vc >>> 16) & 0xFF;
|
||||
|
|
|
@ -39,10 +39,8 @@ public class ForgeBlockModelRenderer extends BlockModelRenderer
|
|||
{
|
||||
private final ThreadLocal<VertexLighterFlat> lighterFlat;
|
||||
private final ThreadLocal<VertexLighterSmoothAo> lighterSmooth;
|
||||
private final ThreadLocal<VertexBufferConsumer> wrFlat = new ThreadLocal<>();
|
||||
private final ThreadLocal<VertexBufferConsumer> wrSmooth = new ThreadLocal<>();
|
||||
private final ThreadLocal<BufferBuilder> lastRendererFlat = new ThreadLocal<>();
|
||||
private final ThreadLocal<BufferBuilder> lastRendererSmooth = new ThreadLocal<>();
|
||||
private final ThreadLocal<VertexBufferConsumer> consumerFlat = ThreadLocal.withInitial(VertexBufferConsumer::new);
|
||||
private final ThreadLocal<VertexBufferConsumer> consumerSmooth = ThreadLocal.withInitial(VertexBufferConsumer::new);
|
||||
|
||||
public ForgeBlockModelRenderer(BlockColors colors)
|
||||
{
|
||||
|
@ -56,15 +54,14 @@ public class ForgeBlockModelRenderer extends BlockModelRenderer
|
|||
{
|
||||
if(ForgeMod.forgeLightPipelineEnabled)
|
||||
{
|
||||
if(buffer != lastRendererFlat.get())
|
||||
{
|
||||
lastRendererFlat.set(buffer);
|
||||
VertexBufferConsumer newCons = new VertexBufferConsumer(buffer);
|
||||
wrFlat.set(newCons);
|
||||
lighterFlat.get().setParent(newCons);
|
||||
}
|
||||
wrFlat.get().setOffset(pos);
|
||||
return render(lighterFlat.get(), world, model, state, pos, buffer, checkSides, rand, seed);
|
||||
VertexBufferConsumer consumer = consumerFlat.get();
|
||||
consumer.setBuffer(buffer);
|
||||
consumer.setOffset(pos);
|
||||
|
||||
VertexLighterFlat lighter = lighterFlat.get();
|
||||
lighter.setParent(consumer);
|
||||
|
||||
return render(lighter, world, model, state, pos, buffer, checkSides, rand, seed);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -77,15 +74,14 @@ public class ForgeBlockModelRenderer extends BlockModelRenderer
|
|||
{
|
||||
if(ForgeMod.forgeLightPipelineEnabled)
|
||||
{
|
||||
if(buffer != lastRendererSmooth.get())
|
||||
{
|
||||
lastRendererSmooth.set(buffer);
|
||||
VertexBufferConsumer newCons = new VertexBufferConsumer(buffer);
|
||||
wrSmooth.set(newCons);
|
||||
lighterSmooth.get().setParent(newCons);
|
||||
}
|
||||
wrSmooth.get().setOffset(pos);
|
||||
return render(lighterSmooth.get(), world, model, state, pos, buffer, checkSides, rand, seed);
|
||||
VertexBufferConsumer consumer = consumerSmooth.get();
|
||||
consumer.setBuffer(buffer);
|
||||
consumer.setOffset(pos);
|
||||
|
||||
VertexLighterSmoothAo lighter = lighterSmooth.get();
|
||||
lighter.setParent(consumer);
|
||||
|
||||
return render(lighter, world, model, state, pos, buffer, checkSides, rand, seed);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -250,6 +250,7 @@ public class LightUtil
|
|||
}
|
||||
|
||||
private static IVertexConsumer tessellator = null;
|
||||
@Deprecated // TODO: remove
|
||||
public static IVertexConsumer getTessellator()
|
||||
{
|
||||
if(tessellator == null)
|
||||
|
@ -262,6 +263,7 @@ public class LightUtil
|
|||
}
|
||||
|
||||
private static ItemConsumer itemConsumer = null;
|
||||
@Deprecated // TODO: remove
|
||||
public static ItemConsumer getItemConsumer()
|
||||
{
|
||||
if(itemConsumer == null)
|
||||
|
@ -271,20 +273,29 @@ public class LightUtil
|
|||
return itemConsumer;
|
||||
}
|
||||
|
||||
// renders quad in any Vertex Format, but is slower
|
||||
public static void renderQuadColorSlow(BufferBuilder wr, BakedQuad quad, int auxColor)
|
||||
private static final class ItemPipeline
|
||||
{
|
||||
ItemConsumer cons;
|
||||
if(wr == Tessellator.getInstance().getBuffer())
|
||||
final VertexBufferConsumer bufferConsumer;
|
||||
final ItemConsumer itemConsumer;
|
||||
|
||||
ItemPipeline()
|
||||
{
|
||||
cons = getItemConsumer();
|
||||
this.bufferConsumer = new VertexBufferConsumer();
|
||||
this.itemConsumer = new ItemConsumer(bufferConsumer);
|
||||
}
|
||||
else
|
||||
{
|
||||
cons = new ItemConsumer(new VertexBufferConsumer(wr));
|
||||
}
|
||||
float b = (float)(auxColor & 0xFF) / 0xFF;
|
||||
float g = (float)((auxColor >>> 8) & 0xFF) / 0xFF;
|
||||
}
|
||||
|
||||
private static final ThreadLocal<ItemPipeline> itemPipeline = ThreadLocal.withInitial(ItemPipeline::new);
|
||||
|
||||
// renders quad in any Vertex Format, but is slower
|
||||
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 a = (float)((auxColor >>> 24) & 0xFF) / 0xFF;
|
||||
|
||||
|
@ -292,16 +303,19 @@ public class LightUtil
|
|||
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());
|
||||
ForgeHooksClient.putQuadColor(wr, quad, auxColor);
|
||||
buffer.addVertexData(quad.getVertexData());
|
||||
if (buffer.getVertexFormat().hasColor())
|
||||
{
|
||||
ForgeHooksClient.putQuadColor(buffer, quad, auxColor);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
renderQuadColorSlow(wr, quad, auxColor);
|
||||
renderQuadColorSlow(buffer, quad, auxColor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -328,7 +342,8 @@ public class LightUtil
|
|||
if(getVertexFormat().getElement(element).getUsage() == EnumUsage.COLOR)
|
||||
{
|
||||
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];
|
||||
}
|
||||
|
|
|
@ -32,16 +32,17 @@ import net.minecraft.util.EnumFacing;
|
|||
public class VertexBufferConsumer implements IVertexConsumer
|
||||
{
|
||||
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 BlockPos offset = BlockPos.ORIGIN;
|
||||
|
||||
public VertexBufferConsumer(BufferBuilder renderer)
|
||||
public VertexBufferConsumer() {}
|
||||
|
||||
public VertexBufferConsumer(BufferBuilder buffer)
|
||||
{
|
||||
super();
|
||||
this.renderer = renderer;
|
||||
quadData = new int[renderer.getVertexFormat().getSize()/* / 4 * 4 */];
|
||||
setBuffer(buffer);
|
||||
}
|
||||
|
||||
@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)
|
||||
{
|
||||
this.offset = new BlockPos(offset);
|
||||
|
|
Loading…
Reference in a new issue