mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-09 08:50:29 +00:00
Write colour channel as a single int
Should be a little more efficient than writing four bytes separately.
This commit is contained in:
parent
6b8ba8b80b
commit
782564e6ab
@ -13,10 +13,11 @@ import dan200.computercraft.core.terminal.Palette;
|
|||||||
import dan200.computercraft.core.terminal.Terminal;
|
import dan200.computercraft.core.terminal.Terminal;
|
||||||
import dan200.computercraft.core.terminal.TextBuffer;
|
import dan200.computercraft.core.terminal.TextBuffer;
|
||||||
import dan200.computercraft.core.util.Colour;
|
import dan200.computercraft.core.util.Colour;
|
||||||
import net.minecraft.util.FastColor;
|
import dan200.computercraft.shared.util.ARGB32;
|
||||||
import org.lwjgl.system.MemoryUtil;
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
import static dan200.computercraft.client.render.text.FixedWidthFontRenderer.*;
|
import static dan200.computercraft.client.render.text.FixedWidthFontRenderer.*;
|
||||||
import static org.lwjgl.system.MemoryUtil.*;
|
import static org.lwjgl.system.MemoryUtil.*;
|
||||||
@ -39,6 +40,8 @@ import static org.lwjgl.system.MemoryUtil.*;
|
|||||||
* {@link FixedWidthFontRenderer}.
|
* {@link FixedWidthFontRenderer}.
|
||||||
*/
|
*/
|
||||||
public final class DirectFixedWidthFontRenderer {
|
public final class DirectFixedWidthFontRenderer {
|
||||||
|
private static final boolean IS_LITTLE_ENDIAN = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN;
|
||||||
|
|
||||||
private DirectFixedWidthFontRenderer() {
|
private DirectFixedWidthFontRenderer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,18 +201,14 @@ public final class DirectFixedWidthFontRenderer {
|
|||||||
// Require the pointer to be aligned to a 32-bit boundary.
|
// Require the pointer to be aligned to a 32-bit boundary.
|
||||||
if ((addr & 3) != 0) throw new IllegalStateException("Memory is not aligned");
|
if ((addr & 3) != 0) throw new IllegalStateException("Memory is not aligned");
|
||||||
|
|
||||||
var red = (byte) FastColor.ARGB32.red(colour);
|
// Pack colour so it is equivalent to rgba:BBBB.
|
||||||
var green = (byte) FastColor.ARGB32.green(colour);
|
var colourAbgr = ARGB32.toABGR32(colour);
|
||||||
var blue = (byte) FastColor.ARGB32.blue(colour);
|
var nativeColour = IS_LITTLE_ENDIAN ? colourAbgr : Integer.reverseBytes(colourAbgr);
|
||||||
var alpha = (byte) FastColor.ARGB32.alpha(colour);
|
|
||||||
|
|
||||||
memPutFloat(addr + 0, x1);
|
memPutFloat(addr + 0, x1);
|
||||||
memPutFloat(addr + 4, y1);
|
memPutFloat(addr + 4, y1);
|
||||||
memPutFloat(addr + 8, z);
|
memPutFloat(addr + 8, z);
|
||||||
memPutByte(addr + 12, red);
|
memPutInt(addr + 12, nativeColour);
|
||||||
memPutByte(addr + 13, green);
|
|
||||||
memPutByte(addr + 14, blue);
|
|
||||||
memPutByte(addr + 15, alpha);
|
|
||||||
memPutFloat(addr + 16, u1);
|
memPutFloat(addr + 16, u1);
|
||||||
memPutFloat(addr + 20, v1);
|
memPutFloat(addr + 20, v1);
|
||||||
memPutShort(addr + 24, (short) 0xF0);
|
memPutShort(addr + 24, (short) 0xF0);
|
||||||
@ -218,10 +217,7 @@ public final class DirectFixedWidthFontRenderer {
|
|||||||
memPutFloat(addr + 28, x1);
|
memPutFloat(addr + 28, x1);
|
||||||
memPutFloat(addr + 32, y2);
|
memPutFloat(addr + 32, y2);
|
||||||
memPutFloat(addr + 36, z);
|
memPutFloat(addr + 36, z);
|
||||||
memPutByte(addr + 40, red);
|
memPutInt(addr + 40, nativeColour);
|
||||||
memPutByte(addr + 41, green);
|
|
||||||
memPutByte(addr + 42, blue);
|
|
||||||
memPutByte(addr + 43, alpha);
|
|
||||||
memPutFloat(addr + 44, u1);
|
memPutFloat(addr + 44, u1);
|
||||||
memPutFloat(addr + 48, v2);
|
memPutFloat(addr + 48, v2);
|
||||||
memPutShort(addr + 52, (short) 0xF0);
|
memPutShort(addr + 52, (short) 0xF0);
|
||||||
@ -230,10 +226,7 @@ public final class DirectFixedWidthFontRenderer {
|
|||||||
memPutFloat(addr + 56, x2);
|
memPutFloat(addr + 56, x2);
|
||||||
memPutFloat(addr + 60, y2);
|
memPutFloat(addr + 60, y2);
|
||||||
memPutFloat(addr + 64, z);
|
memPutFloat(addr + 64, z);
|
||||||
memPutByte(addr + 68, red);
|
memPutInt(addr + 68, nativeColour);
|
||||||
memPutByte(addr + 69, green);
|
|
||||||
memPutByte(addr + 70, blue);
|
|
||||||
memPutByte(addr + 71, alpha);
|
|
||||||
memPutFloat(addr + 72, u2);
|
memPutFloat(addr + 72, u2);
|
||||||
memPutFloat(addr + 76, v2);
|
memPutFloat(addr + 76, v2);
|
||||||
memPutShort(addr + 80, (short) 0xF0);
|
memPutShort(addr + 80, (short) 0xF0);
|
||||||
@ -242,10 +235,7 @@ public final class DirectFixedWidthFontRenderer {
|
|||||||
memPutFloat(addr + 84, x2);
|
memPutFloat(addr + 84, x2);
|
||||||
memPutFloat(addr + 88, y1);
|
memPutFloat(addr + 88, y1);
|
||||||
memPutFloat(addr + 92, z);
|
memPutFloat(addr + 92, z);
|
||||||
memPutByte(addr + 96, red);
|
memPutInt(addr + 96, nativeColour);
|
||||||
memPutByte(addr + 97, green);
|
|
||||||
memPutByte(addr + 98, blue);
|
|
||||||
memPutByte(addr + 99, alpha);
|
|
||||||
memPutFloat(addr + 100, u2);
|
memPutFloat(addr + 100, u2);
|
||||||
memPutFloat(addr + 104, v1);
|
memPutFloat(addr + 104, v1);
|
||||||
memPutShort(addr + 108, (short) 0xF0);
|
memPutShort(addr + 108, (short) 0xF0);
|
||||||
|
Loading…
Reference in New Issue
Block a user