diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/instance/GlyphInstance.java b/common/src/lib/java/dev/engine_room/flywheel/lib/instance/GlyphInstance.java index 510afd8bf..6d2c925e8 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/instance/GlyphInstance.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/instance/GlyphInstance.java @@ -5,6 +5,7 @@ import org.joml.Matrix4f; import dev.engine_room.flywheel.api.instance.InstanceHandle; import dev.engine_room.flywheel.api.instance.InstanceType; 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.util.FastColor; @@ -15,10 +16,8 @@ public class GlyphInstance extends AbstractInstance { public final Matrix4f pose = new Matrix4f(); - public float u0; - public float u1; - public float v0; - public float v1; + public int us; + public int vs; public byte red = (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) { var glyphReader = FlwLibLink.INSTANCE.getGlyphExtension(glyph); - u0 = glyphReader.flywheel$u0(); - u1 = glyphReader.flywheel$u1(); - v0 = glyphReader.flywheel$v0(); - v1 = glyphReader.flywheel$v1(); + setUvs(glyphReader); float left = glyphReader.flywheel$left(); float right = glyphReader.flywheel$right(); 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) { var glyphReader = FlwLibLink.INSTANCE.getGlyphExtension(glyph); - u0 = glyphReader.flywheel$u0(); - u1 = glyphReader.flywheel$u1(); - v0 = glyphReader.flywheel$v0(); - v1 = glyphReader.flywheel$v1(); + setUvs(glyphReader); pose.translate(x0, y0, depth); pose.scale(x1 - x0, y1 - y0, 1.0f); @@ -101,4 +94,14 @@ public class GlyphInstance extends AbstractInstance { this.blue = blue; 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); + } } diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/instance/InstanceTypes.java b/common/src/lib/java/dev/engine_room/flywheel/lib/instance/InstanceTypes.java index 4212e358f..ec220ce63 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/instance/InstanceTypes.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/instance/InstanceTypes.java @@ -106,21 +106,19 @@ public final class InstanceTypes { public static final InstanceType GLYPH = SimpleInstanceType.builder(GlyphInstance::new) .layout(LayoutBuilder.create() .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("light", FloatRepr.UNSIGNED_SHORT, 2) .build()) .writer((ptr, instance) -> { ExtraMemoryOps.putMatrix4f(ptr, instance.pose); - MemoryUtil.memPutFloat(ptr + 64, instance.u0); - MemoryUtil.memPutFloat(ptr + 68, instance.u1); - MemoryUtil.memPutFloat(ptr + 72, instance.v0); - MemoryUtil.memPutFloat(ptr + 76, instance.v1); - MemoryUtil.memPutByte(ptr + 80, instance.red); - MemoryUtil.memPutByte(ptr + 81, instance.green); - MemoryUtil.memPutByte(ptr + 82, instance.blue); - MemoryUtil.memPutByte(ptr + 83, instance.alpha); - ExtraMemoryOps.put2x16(ptr + 84, instance.light); + ExtraMemoryOps.put2x16(ptr + 64, instance.us); + ExtraMemoryOps.put2x16(ptr + 68, instance.vs); + MemoryUtil.memPutByte(ptr + 72, instance.red); + MemoryUtil.memPutByte(ptr + 73, instance.green); + MemoryUtil.memPutByte(ptr + 74, instance.blue); + MemoryUtil.memPutByte(ptr + 75, instance.alpha); + ExtraMemoryOps.put2x16(ptr + 76, instance.light); }) .vertexShader(Flywheel.rl("instance/glyph.vert")) .cullShader(Flywheel.rl("instance/cull/glyph.glsl"))