Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public interface VertexBufferWriter {
* @return An implementation of {@link VertexBufferWriter} which will write vertices into {@param consumer}
* @throws IllegalArgumentException If the vertex consumer does not implement the necessary interface
*/
static VertexBufferWriter of(VertexConsumer consumer) {
if (consumer instanceof VertexBufferWriter writer && writer.canUseIntrinsics()) {
static VertexBufferWriter sodium$of(VertexConsumer consumer) {
if (consumer instanceof VertexBufferWriter writer && writer.sodium$canUseIntrinsics()) {
return writer;
}

throw createUnsupportedVertexConsumerThrowable(consumer);
throw sodium$createUnsupportedVertexConsumerThrowable(consumer);
}

/**
Expand All @@ -30,15 +30,15 @@ static VertexBufferWriter of(VertexConsumer consumer) {
* if the vertex consumer does not implement the necessary interface
*/
@Nullable
static VertexBufferWriter tryOf(VertexConsumer consumer) {
if (consumer instanceof VertexBufferWriter writer && writer.canUseIntrinsics()) {
static VertexBufferWriter sodium$tryOf(VertexConsumer consumer) {
if (consumer instanceof VertexBufferWriter writer && writer.sodium$canUseIntrinsics()) {
return writer;
}

return null;
}

private static RuntimeException createUnsupportedVertexConsumerThrowable(VertexConsumer consumer) {
private static RuntimeException sodium$createUnsupportedVertexConsumerThrowable(VertexConsumer consumer) {
var clazz = consumer.getClass();
var name = clazz.getName();

Expand All @@ -61,15 +61,15 @@ private static RuntimeException createUnsupportedVertexConsumerThrowable(VertexC
* @param count The number of vertices to copy
* @param format The format of the vertices
*/
void push(MemoryStack stack, long ptr, int count, VertexFormat format);
void sodium$push(MemoryStack stack, long ptr, int count, VertexFormat format);

/**
* If this {@link VertexBufferWriter} passes through data to nested {@link VertexConsumer} implementations,
* this method should be implemented to check that the nested implementations also support use of VertexBufferWriter
* methods.
* @return true if the inner consumer is also a valid {@link VertexBufferWriter} that can use intrinsics
*/
default boolean canUseIntrinsics() {
default boolean sodium$canUseIntrinsics() {
return true;
}

Expand All @@ -84,15 +84,14 @@ default boolean canUseIntrinsics() {
* @param count The number of vertices to push
* @param format The format of the vertices
*/
static void copyInto(VertexBufferWriter writer,
MemoryStack stack, long ptr, int count,
VertexFormat format)
{
static void sodium$copyInto(VertexBufferWriter writer,
MemoryStack stack, long ptr, int count,
VertexFormat format) {
var length = count * format.getVertexSize();
var copy = stack.nmalloc(length);

MemoryIntrinsics.copyMemory(ptr, copy, length);

writer.push(stack, copy, count, format);
writer.sodium$push(stack, copy, count, format);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ public VanillaAdapter(BlockTintSource[] colors) {

@Override
public void getColors(LevelSlice slice, BlockPos pos, BlockPos.MutableBlockPos scratchPos, BlockState state, ModelQuadView quad, int[] output, boolean smooth) {
if (quad.getTintIndex() >= this.color.length) {
if (quad.sodium$getTintIndex() >= this.color.length) {
Arrays.fill(output, -1);
return;
}

Arrays.fill(output, 0xFF000000 | this.color[quad.getTintIndex()].colorInWorld(state, slice, pos));
Arrays.fill(output, 0xFF000000 | this.color[quad.sodium$getTintIndex()].colorInWorld(state, slice, pos));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void calculate(ModelQuadView quad, BlockPos pos, QuadLightData out, Direc
if (cullFace != null) {
Arrays.fill(out.br, this.getShade(this.lightCache.getLevel(), lightFace, shadeDirectionOverride));
} else {
int flags = quad.getFlags();
int flags = quad.sodium$getFlags();
if ((flags & ModelQuadFlags.IS_ALIGNED) != 0 || ((flags & ModelQuadFlags.IS_PARALLEL) != 0 && unpackFC(this.lightCache.get(pos)))) {
Arrays.fill(out.br, this.getShade(this.lightCache.getLevel(), lightFace, shadeDirectionOverride));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void calculate(ModelQuadView quad, BlockPos pos, QuadLightData out, Direc
lightmap = this.getOffsetLightmap(pos, cullFace);
Arrays.fill(out.br, this.getShade(this.lightCache.getLevel(), lightFace, shadeDirectionOverride));
} else {
int flags = quad.getFlags();
int flags = quad.sodium$getFlags();
// If the face is aligned, use the light data above it
// To match vanilla behavior, also treat the face as aligned if it is parallel and the block state is a full cube
if ((flags & ModelQuadFlags.IS_ALIGNED) != 0 || ((flags & ModelQuadFlags.IS_PARALLEL) != 0 && unpackFC(this.lightCache.get(pos)))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public SmoothLightPipeline(LightDataAccess cache) {
public void calculate(ModelQuadView quad, BlockPos pos, QuadLightData out, Direction cullFace, Direction lightFace, @Nullable Direction shadeDirectionOverride, boolean enhanced) {
this.updateCachedData(pos.asLong());

int flags = quad.getFlags();
int flags = quad.sodium$getFlags();

final AoNeighborInfo neighborInfo = AoNeighborInfo.get(lightFace);

Expand Down Expand Up @@ -113,9 +113,9 @@ private void applyAlignedFullFace(AoNeighborInfo neighborInfo, BlockPos pos, Dir
private void applyAlignedPartialFace(AoNeighborInfo neighborInfo, ModelQuadView quad, BlockPos pos, Direction dir, QuadLightData out, @Nullable Direction shadeDirectionOverride) {
for (int i = 0; i < 4; i++) {
// Clamp the vertex positions to the block's boundaries to prevent weird errors in lighting
float cx = clamp(quad.getX(i));
float cy = clamp(quad.getY(i));
float cz = clamp(quad.getZ(i));
float cx = clamp(quad.sodium$getX(i));
float cy = clamp(quad.sodium$getY(i));
float cz = clamp(quad.sodium$getZ(i));

float[] weights = this.weights;
neighborInfo.calculateCornerWeights(cx, cy, cz, weights);
Expand All @@ -135,9 +135,9 @@ private void applyAlignedPartialFace(AoNeighborInfo neighborInfo, ModelQuadView
private void applyParallelFace(AoNeighborInfo neighborInfo, ModelQuadView quad, BlockPos pos, Direction dir, QuadLightData out, @Nullable Direction shadeDirectionOverride) {
for (int i = 0; i < 4; i++) {
// Clamp the vertex positions to the block's boundaries to prevent weird errors in lighting
float cx = clamp(quad.getX(i));
float cy = clamp(quad.getY(i));
float cz = clamp(quad.getZ(i));
float cx = clamp(quad.sodium$getX(i));
float cy = clamp(quad.sodium$getY(i));
float cz = clamp(quad.sodium$getZ(i));

float[] weights = this.weights;
neighborInfo.calculateCornerWeights(cx, cy, cz, weights);
Expand All @@ -164,9 +164,9 @@ private void applyParallelFace(AoNeighborInfo neighborInfo, ModelQuadView quad,
private void applyNonParallelFace(AoNeighborInfo neighborInfo, ModelQuadView quad, BlockPos pos, Direction dir, QuadLightData out, @Nullable Direction shadeDirectionOverride) {
for (int i = 0; i < 4; i++) {
// Clamp the vertex positions to the block's boundaries to prevent weird errors in lighting
float cx = clamp(quad.getX(i));
float cy = clamp(quad.getY(i));
float cz = clamp(quad.getZ(i));
float cx = clamp(quad.sodium$getX(i));
float cy = clamp(quad.sodium$getY(i));
float cz = clamp(quad.sodium$getZ(i));

float[] weights = this.weights;
neighborInfo.calculateCornerWeights(cx, cy, cz, weights);
Expand Down Expand Up @@ -230,7 +230,7 @@ private void applyInsetPartialFaceVertex(BlockPos pos, Direction dir, float n1d,
private final AoFaceData tmpFace = new AoFaceData();

private AoFaceData gatherInsetFace(ModelQuadView quad, BlockPos blockPos, int vertexIndex, Direction lightFace, @Nullable Direction shadeDirectionOverride) {
final float w1 = AoNeighborInfo.get(lightFace).getDepth(quad.getX(vertexIndex), quad.getY(vertexIndex), quad.getZ(vertexIndex));
final float w1 = AoNeighborInfo.get(lightFace).getDepth(quad.sodium$getX(vertexIndex), quad.sodium$getY(vertexIndex), quad.sodium$getZ(vertexIndex));

if (Mth.equal(w1, 0)) {
return this.getCachedFaceData(blockPos, lightFace, true, shadeDirectionOverride);
Expand All @@ -254,7 +254,7 @@ private void applyIrregularFace(BlockPos blockPos, ModelQuadView quad, QuadLight

for (int i = 0; i < 4; i++) {
// TODO: Avoid this if the accurate normal is the face normal
Vector3f normal = NormI8.unpack(quad.getAccurateNormal(i), this.vertexNormal);
Vector3f normal = NormI8.unpack(quad.sodium$getAccurateNormal(i), this.vertexNormal);
float ao = 0, sky = 0, block = 0, maxAo = 0;
float maxSky = 0, maxBlock = 0;

Expand All @@ -263,7 +263,7 @@ private void applyIrregularFace(BlockPos blockPos, ModelQuadView quad, QuadLight
if (!Mth.equal(0f, x)) {
final Direction face = x > 0 ? Direction.EAST : Direction.WEST;
final AoFaceData fd = this.gatherInsetFace(quad, blockPos, i, face, shadeDirectionOverride);
AoNeighborInfo.get(face).calculateCornerWeights(quad.getX(i), quad.getY(i), quad.getZ(i), w);
AoNeighborInfo.get(face).calculateCornerWeights(quad.sodium$getX(i), quad.sodium$getY(i), quad.sodium$getZ(i), w);
final float n = x * x;
final float a = fd.getBlendedShade(w) * this.getAmbientBrightness(face, shadeDirectionOverride);
final float s = fd.getBlendedSkyLight(w);
Expand All @@ -281,7 +281,7 @@ private void applyIrregularFace(BlockPos blockPos, ModelQuadView quad, QuadLight
if (!Mth.equal(0f, y)) {
final Direction face = y > 0 ? Direction.UP : Direction.DOWN;
final AoFaceData fd = this.gatherInsetFace(quad, blockPos, i, face, shadeDirectionOverride);
AoNeighborInfo.get(face).calculateCornerWeights(quad.getX(i), quad.getY(i), quad.getZ(i), w);
AoNeighborInfo.get(face).calculateCornerWeights(quad.sodium$getX(i), quad.sodium$getY(i), quad.sodium$getZ(i), w);
final float n = y * y;
final float a = fd.getBlendedShade(w) * this.getAmbientBrightness(face, shadeDirectionOverride);
final float s = fd.getBlendedSkyLight(w);
Expand All @@ -299,7 +299,7 @@ private void applyIrregularFace(BlockPos blockPos, ModelQuadView quad, QuadLight
if (!Mth.equal(0f, z)) {
final Direction face = z > 0 ? Direction.SOUTH : Direction.NORTH;
final AoFaceData fd = this.gatherInsetFace(quad, blockPos, i, face, shadeDirectionOverride);
AoNeighborInfo.get(face).calculateCornerWeights(quad.getX(i), quad.getY(i), quad.getZ(i), w);
AoNeighborInfo.get(face).calculateCornerWeights(quad.sodium$getX(i), quad.sodium$getY(i), quad.sodium$getZ(i), w);
final float n = z * z;
final float a = fd.getBlendedShade(w) * this.getAmbientBrightness(face, shadeDirectionOverride);
final float s = fd.getBlendedSkyLight(w);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import net.caffeinemc.mods.sodium.client.model.quad.properties.ModelQuadFacing;

public interface BakedQuadView extends ModelQuadView {
ModelQuadFacing getNormalFace();
ModelQuadFacing sodium$getNormalFace();

int getFaceNormal();
int sodium$getFaceNormal();

boolean hasShade();
boolean sodium$hasShade();

boolean hasAO();
boolean sodium$hasAO();

int getLightEmission();
int sodium$getLightEmission();
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,72 +84,72 @@ public void setLightFace(Direction direction) {
}

@Override
public int getTintIndex() {
public int sodium$getTintIndex() {
return this.tintIdx;
}

@Override
public float getX(int idx) {
public float sodium$getX(int idx) {
return Float.intBitsToFloat(this.data[ModelQuadUtil.vertexOffset(idx) + ModelQuadUtil.POSITION_INDEX]);
}

@Override
public float getY(int idx) {
public float sodium$getY(int idx) {
return Float.intBitsToFloat(this.data[ModelQuadUtil.vertexOffset(idx) + ModelQuadUtil.POSITION_INDEX + 1]);
}

@Override
public float getZ(int idx) {
public float sodium$getZ(int idx) {
return Float.intBitsToFloat(this.data[ModelQuadUtil.vertexOffset(idx) + ModelQuadUtil.POSITION_INDEX + 2]);
}

@Override
public int getColor(int idx) {
public int sodium$getColor(int idx) {
return this.data[ModelQuadUtil.vertexOffset(idx) + ModelQuadUtil.COLOR_INDEX];
}

@Override
public float getTexU(int idx) {
public float sodium$getTexU(int idx) {
return Float.intBitsToFloat(this.data[ModelQuadUtil.vertexOffset(idx) + ModelQuadUtil.TEXTURE_INDEX]);
}

@Override
public float getTexV(int idx) {
public float sodium$getTexV(int idx) {
return Float.intBitsToFloat(this.data[ModelQuadUtil.vertexOffset(idx) + ModelQuadUtil.TEXTURE_INDEX + 1]);
}

@Override
public int getVertexNormal(int idx) {
public int sodium$getVertexNormal(int idx) {
return this.data[ModelQuadUtil.vertexOffset(idx) + ModelQuadUtil.NORMAL_INDEX];
}

@Override
public int getFaceNormal() {
public int sodium$getFaceNormal() {
return this.faceNormal;
}

@Override
public int getLight(int idx) {
public int sodium$getLight(int idx) {
return this.data[ModelQuadUtil.vertexOffset(idx) + ModelQuadUtil.LIGHT_INDEX];
}

@Override
public int getFlags() {
public int sodium$getFlags() {
return this.flags;
}

@Override
public TextureAtlasSprite getSprite() {
public TextureAtlasSprite sodium$getSprite() {
return this.sprite;
}

@Override
public Direction getLightFace() {
public Direction sodium$getLightFace() {
return this.direction;
}

@Override
public int getMaxLightQuad(int idx) {
return this.getLight(idx);
public int sodium$getMaxLightQuad(int idx) {
return this.sodium$getLight(idx);
}
}
Loading
Loading