Skip to content

Commit

Permalink
Use correct pointer shifts on 32-bit platforms
Browse files Browse the repository at this point in the history
This fixes rendering glitches in translucent render passes
when using a 32-bit runtime/operating system.
  • Loading branch information
Luna0x01 committed Jan 12, 2025
1 parent 103b79d commit dfacd3e
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.caffeinemc.mods.sodium.client.render.viewport.CameraTransform;
import net.caffeinemc.mods.sodium.client.util.BitwiseMath;
import net.caffeinemc.mods.sodium.client.util.UInt32;
import org.lwjgl.system.Pointer;

import java.util.Iterator;

Expand Down Expand Up @@ -170,7 +171,7 @@ private static void addNonIndexedDrawCommands(MultiDrawBatch batch, long pMeshDa
// Uint32 -> Int32 cast is always safe and should be optimized away
MemoryUtil.memPutInt(pBaseVertex + (size << 2), (int) SectionRenderDataUnsafe.getVertexOffset(pMeshData, facing));
MemoryUtil.memPutInt(pElementCount + (size << 2), (int) SectionRenderDataUnsafe.getElementCount(pMeshData, facing));
MemoryUtil.memPutAddress(pElementPointer + (size << 3), 0 /* using a shared index buffer */);
MemoryUtil.memPutAddress(pElementPointer + (size << Pointer.POINTER_SHIFT), 0 /* using a shared index buffer */);

size += (mask >> facing) & 1;
}
Expand Down Expand Up @@ -202,7 +203,7 @@ private static void addIndexedDrawCommands(MultiDrawBatch batch, long pMeshData,

// * 4 to convert to bytes (the index buffer contains integers)
// the section render data storage for the indices stores the offset in indices (also called elements)
MemoryUtil.memPutAddress(pElementPointer + (size << 3), elementOffset << 2);
MemoryUtil.memPutAddress(pElementPointer + (size << Pointer.POINTER_SHIFT), elementOffset << 2);

// adding the number of elements works because the index data has one index per element (which are the indices)
elementOffset += elementCount;
Expand Down

0 comments on commit dfacd3e

Please sign in to comment.