Skip to content

Commit

Permalink
Fix color handling of ARGB... somehow
Browse files Browse the repository at this point in the history
A cautionary tale
  • Loading branch information
IMS212 committed Nov 29, 2023
1 parent fae888e commit 0cea9d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static int toABGR(int color, int alpha) {
}

public static int toABGR(int color) {
return Integer.reverseBytes(color << 8);
return Integer.reverseBytes(Integer.rotateLeft(color, 8));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.caffeinemc.mods.sodium.api.memory.MemoryIntrinsics;
import net.caffeinemc.mods.sodium.api.util.ColorABGR;
import net.caffeinemc.mods.sodium.api.util.ColorARGB;
import net.caffeinemc.mods.sodium.api.util.NormI8;
import net.caffeinemc.mods.sodium.api.vertex.attributes.CommonVertexAttribute;
import net.caffeinemc.mods.sodium.api.vertex.attributes.common.*;
Expand Down Expand Up @@ -295,12 +296,17 @@ public VertexConsumer color(int red, int green, int blue, int alpha) {
}

@Override
public VertexConsumer color(int rgba) {
public VertexConsumer color(int argb) { // No, this isn't a typo. One method takes RGBA, but this one takes ARGB.
if (this.colorFixed) {
throw new IllegalStateException();
}

this.putColorAttribute(rgba);
// This should be RGBA.
// There is no reason it should be anything other than RGBA.
// It should certainly never be ABGR.
// But it is.
// Why?
this.putColorAttribute(ColorARGB.toABGR(argb));

return this;
}
Expand Down

0 comments on commit 0cea9d0

Please sign in to comment.