mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-02-12 05:05:03 +01:00
Packing up
- Save 8 bytes per glyph instance by switching uvs to FloatRepr.NORMALIZED_UNSIGNED_SHORT - With vanilla's 256x glyph atlases we could technically save another 4 bytes, but that would make compat with caxton, which uses 4096x atlases, much more difficult later
This commit is contained in:
parent
bd3aab04bc
commit
183e2d78b7
2 changed files with 23 additions and 22 deletions
|
@ -5,6 +5,7 @@ import org.joml.Matrix4f;
|
||||||
import dev.engine_room.flywheel.api.instance.InstanceHandle;
|
import dev.engine_room.flywheel.api.instance.InstanceHandle;
|
||||||
import dev.engine_room.flywheel.api.instance.InstanceType;
|
import dev.engine_room.flywheel.api.instance.InstanceType;
|
||||||
import dev.engine_room.flywheel.lib.internal.FlwLibLink;
|
import dev.engine_room.flywheel.lib.internal.FlwLibLink;
|
||||||
|
import dev.engine_room.flywheel.lib.internal.GlyphExtension;
|
||||||
import net.minecraft.client.gui.font.glyphs.BakedGlyph;
|
import net.minecraft.client.gui.font.glyphs.BakedGlyph;
|
||||||
import net.minecraft.util.FastColor;
|
import net.minecraft.util.FastColor;
|
||||||
|
|
||||||
|
@ -15,10 +16,8 @@ public class GlyphInstance extends AbstractInstance {
|
||||||
|
|
||||||
public final Matrix4f pose = new Matrix4f();
|
public final Matrix4f pose = new Matrix4f();
|
||||||
|
|
||||||
public float u0;
|
public int us;
|
||||||
public float u1;
|
public int vs;
|
||||||
public float v0;
|
|
||||||
public float v1;
|
|
||||||
|
|
||||||
public byte red = (byte) 0xFF;
|
public byte red = (byte) 0xFF;
|
||||||
public byte green = (byte) 0xFF;
|
public byte green = (byte) 0xFF;
|
||||||
|
@ -34,10 +33,7 @@ public class GlyphInstance extends AbstractInstance {
|
||||||
public GlyphInstance setGlyph(BakedGlyph glyph, float x, float y, boolean italic) {
|
public GlyphInstance setGlyph(BakedGlyph glyph, float x, float y, boolean italic) {
|
||||||
var glyphReader = FlwLibLink.INSTANCE.getGlyphExtension(glyph);
|
var glyphReader = FlwLibLink.INSTANCE.getGlyphExtension(glyph);
|
||||||
|
|
||||||
u0 = glyphReader.flywheel$u0();
|
setUvs(glyphReader);
|
||||||
u1 = glyphReader.flywheel$u1();
|
|
||||||
v0 = glyphReader.flywheel$v0();
|
|
||||||
v1 = glyphReader.flywheel$v1();
|
|
||||||
float left = glyphReader.flywheel$left();
|
float left = glyphReader.flywheel$left();
|
||||||
float right = glyphReader.flywheel$right();
|
float right = glyphReader.flywheel$right();
|
||||||
float up = glyphReader.flywheel$up();
|
float up = glyphReader.flywheel$up();
|
||||||
|
@ -56,10 +52,7 @@ public class GlyphInstance extends AbstractInstance {
|
||||||
public GlyphInstance setEffect(BakedGlyph glyph, float x0, float y0, float x1, float y1, float depth) {
|
public GlyphInstance setEffect(BakedGlyph glyph, float x0, float y0, float x1, float y1, float depth) {
|
||||||
var glyphReader = FlwLibLink.INSTANCE.getGlyphExtension(glyph);
|
var glyphReader = FlwLibLink.INSTANCE.getGlyphExtension(glyph);
|
||||||
|
|
||||||
u0 = glyphReader.flywheel$u0();
|
setUvs(glyphReader);
|
||||||
u1 = glyphReader.flywheel$u1();
|
|
||||||
v0 = glyphReader.flywheel$v0();
|
|
||||||
v1 = glyphReader.flywheel$v1();
|
|
||||||
|
|
||||||
pose.translate(x0, y0, depth);
|
pose.translate(x0, y0, depth);
|
||||||
pose.scale(x1 - x0, y1 - y0, 1.0f);
|
pose.scale(x1 - x0, y1 - y0, 1.0f);
|
||||||
|
@ -101,4 +94,14 @@ public class GlyphInstance extends AbstractInstance {
|
||||||
this.blue = blue;
|
this.blue = blue;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setUvs(GlyphExtension glyphReader) {
|
||||||
|
float u0 = glyphReader.flywheel$u0();
|
||||||
|
float u1 = glyphReader.flywheel$u1();
|
||||||
|
float v0 = glyphReader.flywheel$v0();
|
||||||
|
float v1 = glyphReader.flywheel$v1();
|
||||||
|
|
||||||
|
us = (int) (u0 * 65536) | ((int) (u1 * 65536) << 16);
|
||||||
|
vs = (int) (v0 * 65536) | ((int) (v1 * 65536) << 16);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,21 +106,19 @@ public final class InstanceTypes {
|
||||||
public static final InstanceType<GlyphInstance> GLYPH = SimpleInstanceType.builder(GlyphInstance::new)
|
public static final InstanceType<GlyphInstance> GLYPH = SimpleInstanceType.builder(GlyphInstance::new)
|
||||||
.layout(LayoutBuilder.create()
|
.layout(LayoutBuilder.create()
|
||||||
.matrix("pose", FloatRepr.FLOAT, 4)
|
.matrix("pose", FloatRepr.FLOAT, 4)
|
||||||
.vector("u0u1v0v1", FloatRepr.FLOAT, 4)
|
.vector("u0u1v0v1", FloatRepr.NORMALIZED_UNSIGNED_SHORT, 4)
|
||||||
.vector("color", FloatRepr.NORMALIZED_UNSIGNED_BYTE, 4)
|
.vector("color", FloatRepr.NORMALIZED_UNSIGNED_BYTE, 4)
|
||||||
.vector("light", FloatRepr.UNSIGNED_SHORT, 2)
|
.vector("light", FloatRepr.UNSIGNED_SHORT, 2)
|
||||||
.build())
|
.build())
|
||||||
.writer((ptr, instance) -> {
|
.writer((ptr, instance) -> {
|
||||||
ExtraMemoryOps.putMatrix4f(ptr, instance.pose);
|
ExtraMemoryOps.putMatrix4f(ptr, instance.pose);
|
||||||
MemoryUtil.memPutFloat(ptr + 64, instance.u0);
|
ExtraMemoryOps.put2x16(ptr + 64, instance.us);
|
||||||
MemoryUtil.memPutFloat(ptr + 68, instance.u1);
|
ExtraMemoryOps.put2x16(ptr + 68, instance.vs);
|
||||||
MemoryUtil.memPutFloat(ptr + 72, instance.v0);
|
MemoryUtil.memPutByte(ptr + 72, instance.red);
|
||||||
MemoryUtil.memPutFloat(ptr + 76, instance.v1);
|
MemoryUtil.memPutByte(ptr + 73, instance.green);
|
||||||
MemoryUtil.memPutByte(ptr + 80, instance.red);
|
MemoryUtil.memPutByte(ptr + 74, instance.blue);
|
||||||
MemoryUtil.memPutByte(ptr + 81, instance.green);
|
MemoryUtil.memPutByte(ptr + 75, instance.alpha);
|
||||||
MemoryUtil.memPutByte(ptr + 82, instance.blue);
|
ExtraMemoryOps.put2x16(ptr + 76, instance.light);
|
||||||
MemoryUtil.memPutByte(ptr + 83, instance.alpha);
|
|
||||||
ExtraMemoryOps.put2x16(ptr + 84, instance.light);
|
|
||||||
})
|
})
|
||||||
.vertexShader(Flywheel.rl("instance/glyph.vert"))
|
.vertexShader(Flywheel.rl("instance/glyph.vert"))
|
||||||
.cullShader(Flywheel.rl("instance/cull/glyph.glsl"))
|
.cullShader(Flywheel.rl("instance/cull/glyph.glsl"))
|
||||||
|
|
Loading…
Reference in a new issue