diff --git a/dependencies.gradle b/dependencies.gradle index 736e53d83..6f8fdbaa0 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -49,19 +49,19 @@ configurations { } dependencies { - compileOnly("com.github.GTNewHorizons:Hodgepodge:2.6.9") + compileOnly("com.github.GTNewHorizons:Hodgepodge:2.6.22") - compileOnly("com.gtnewhorizons.retrofuturabootstrap:RetroFuturaBootstrap:0.4.0") { transitive = false } + compileOnly("com.gtnewhorizons.retrofuturabootstrap:RetroFuturaBootstrap:1.0.7") { transitive = false } - compileOnly("org.projectlombok:lombok:1.18.22") { transitive = false } - annotationProcessor("org.projectlombok:lombok:1.18.22") + compileOnly("org.projectlombok:lombok:1.18.34") { transitive = false } + annotationProcessor("org.projectlombok:lombok:1.18.34") // Use modern models+textures to inject QuadProviders devOnlyNonPublishable('com.github.GTNewHorizons:TX-Loader:1.8.0:dev') // Iris Shaders - compileOnly('org.jetbrains:annotations:24.0.1') - api("com.github.GTNewHorizons:GTNHLib:0.6.0:dev") + compileOnly('org.jetbrains:annotations:26.0.2') + api("com.github.GTNewHorizons:GTNHLib:0.6.6:dev") shadowImplementation("org.anarres:jcpp:1.4.14") // Apache 2.0 shadowImplementation("org.taumc:glsl-transformation-lib:0.2.0-4.g6b42bca") { exclude module: "antlr4" // we only want to shadow the runtime module @@ -70,20 +70,20 @@ dependencies { compileOnly "org.apache.ant:ant:1.8.2" // Because who doesn't want NEI - devOnlyNonPublishable('com.github.GTNewHorizons:NotEnoughItems:2.7.4-GTNH:dev') - devOnlyNonPublishable('com.github.GTNewHorizons:CodeChickenCore:1.4.0:dev') + devOnlyNonPublishable('com.github.GTNewHorizons:NotEnoughItems:2.7.27-GTNH:dev') + devOnlyNonPublishable('com.github.GTNewHorizons:CodeChickenCore:1.4.1:dev') // Notfine Deps compileOnly("thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev") devOnlyNonPublishable("com.github.GTNewHorizons:Baubles:1.0.4:dev") - compileOnly("com.github.GTNewHorizons:twilightforest:2.7.1:dev") { transitive = false } + compileOnly("com.github.GTNewHorizons:twilightforest:2.7.4:dev") { transitive = false } compileOnly(rfg.deobf('curse.maven:witchery-69673:2234410')) - compileOnly("com.github.GTNewHorizons:TinkersConstruct:1.13.1-GTNH:dev") { transitive = false } - compileOnly("com.github.GTNewHorizons:Natura:2.7.5:dev") + compileOnly("com.github.GTNewHorizons:TinkersConstruct:1.13.8-GTNH:dev") { transitive = false } + compileOnly("com.github.GTNewHorizons:Natura:2.8.2:dev") - compileOnly("com.github.GTNewHorizons:ThaumicHorizons:1.6.5:dev") + compileOnly("com.github.GTNewHorizons:ThaumicHorizons:1.7.1:dev") - compileOnly("com.github.GTNewHorizons:Battlegear2:1.4.1:dev") { transitive = false } + compileOnly("com.github.GTNewHorizons:Battlegear2:1.4.2:dev") { transitive = false } compileOnly(rfg.deobf('maven.modrinth:backhand:1.4.1')) { transitive = false } compileOnly("com.falsepattern:chunkapi-mc1.7.10:0.5.1:api") { transitive = false } @@ -100,7 +100,7 @@ dependencies { compileOnly(rfg.deobf("curse.maven:campfirebackport-387444:4611675")) compileOnly(rfg.deobf("curse.maven:xaeros-minimap-263420:5060684")) - compileOnly("com.github.GTNewHorizons:HoloInventory:2.4.13-GTNH:dev") + compileOnly("com.github.GTNewHorizons:HoloInventory:2.5.0-GTNH:dev") runtimeOnlyNonPublishable(rfg.deobf("CoreTweaks:CoreTweaks:0.3.3.2")) @@ -111,7 +111,7 @@ dependencies { compileOnly("com.github.GTNewHorizons:BetterCrashes:1.4.0-GTNH:dev") // Tests - testImplementation(platform('org.junit:junit-bom:5.9.2')) + testImplementation(platform('org.junit:junit-bom:5.11.4')) testImplementation('org.junit.jupiter:junit-jupiter') testImplementation("org.mockito:mockito-core:3.+") testImplementation("org.lwjgl.lwjgl:lwjgl:2.9.4-nightly-20150209") diff --git a/settings.gradle b/settings.gradle index 1f6da72c2..c51facf9f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,5 +16,5 @@ pluginManagement { } plugins { - id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.30' + id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.31' } diff --git a/src/main/java/com/gtnewhorizons/angelica/AngelicaMod.java b/src/main/java/com/gtnewhorizons/angelica/AngelicaMod.java index 6a0590012..00556f640 100644 --- a/src/main/java/com/gtnewhorizons/angelica/AngelicaMod.java +++ b/src/main/java/com/gtnewhorizons/angelica/AngelicaMod.java @@ -16,7 +16,7 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent; name = "Angelica", version = Tags.VERSION, dependencies = " before:lwjgl3ify@[1.5.3,);" + " after:hodgepodge@[2.4.4,);" + " after:CodeChickenCore@[1.2.0,);" - + " after:archaicfix@[0.7.0,);" + " required-after:gtnhlib@[0.4.2,);", + + " after:archaicfix@[0.7.0,);" + " required-after:gtnhlib@[0.6.6,);", acceptedMinecraftVersions = "[1.7.10]", acceptableRemoteVersions = "*", guiFactory = "com.gtnewhorizons.angelica.config.AngelicaGuiConfigFactory") diff --git a/src/main/java/com/gtnewhorizons/angelica/client/font/BatchingFontRenderer.java b/src/main/java/com/gtnewhorizons/angelica/client/font/BatchingFontRenderer.java index d64923fba..e6d638bd5 100644 --- a/src/main/java/com/gtnewhorizons/angelica/client/font/BatchingFontRenderer.java +++ b/src/main/java/com/gtnewhorizons/angelica/client/font/BatchingFontRenderer.java @@ -1,6 +1,7 @@ package com.gtnewhorizons.angelica.client.font; -import com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.*; + import com.gtnewhorizons.angelica.glsm.GLStateManager; import com.gtnewhorizons.angelica.mixins.interfaces.FontRendererAccessor; import it.unimi.dsi.fastutil.chars.Char2ShortOpenHashMap; @@ -10,7 +11,6 @@ import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; -import org.lwjgl.BufferUtils; import org.lwjgl.opengl.GL11; import java.nio.ByteBuffer; @@ -97,10 +97,10 @@ public class BatchingFontRenderer { private static final int INITIAL_BATCH_SIZE = 256; private static final ResourceLocation DUMMY_RESOURCE_LOCATION = new ResourceLocation("angelica$dummy", "this is invalid!"); - private FloatBuffer batchVtxPositions = BufferUtils.createFloatBuffer(INITIAL_BATCH_SIZE * 2); - private ByteBuffer batchVtxColors = BufferUtils.createByteBuffer(INITIAL_BATCH_SIZE * 4); - private FloatBuffer batchVtxTexCoords = BufferUtils.createFloatBuffer(INITIAL_BATCH_SIZE * 2); - private IntBuffer batchIndices = BufferUtils.createIntBuffer(INITIAL_BATCH_SIZE / 2 * 3); + private FloatBuffer batchVtxPositions = memAllocFloat(INITIAL_BATCH_SIZE * 2); + private ByteBuffer batchVtxColors = memAlloc(INITIAL_BATCH_SIZE * 4); + private FloatBuffer batchVtxTexCoords = memAllocFloat(INITIAL_BATCH_SIZE * 2); + private IntBuffer batchIndices = memAllocInt(INITIAL_BATCH_SIZE / 2 * 3); private final ObjectArrayList batchCommands = ObjectArrayList.wrap(new FontDrawCmd[64], 0); private final ObjectArrayList batchCommandPool = ObjectArrayList.wrap(new FontDrawCmd[64], 0); @@ -109,12 +109,12 @@ public class BatchingFontRenderer { final int oldCap = batchVtxPositions.capacity() / 2; if (vtxWriterIndex >= oldCap) { final int newCap = oldCap * 2; - batchVtxPositions = CompatMemoryUtil.memReallocDirect(batchVtxPositions, newCap * 2); - batchVtxColors = CompatMemoryUtil.memReallocDirect(batchVtxColors, newCap * 4); - batchVtxTexCoords = CompatMemoryUtil.memReallocDirect(batchVtxTexCoords, newCap * 2); + batchVtxPositions = memRealloc(batchVtxPositions, newCap * 2); + batchVtxColors = memRealloc(batchVtxColors, newCap * 4); + batchVtxTexCoords = memRealloc(batchVtxTexCoords, newCap * 2); final int oldIdxCap = batchIndices.capacity(); final int newIdxCap = oldIdxCap * 2; - batchIndices = CompatMemoryUtil.memReallocDirect(batchIndices, newIdxCap); + batchIndices = memRealloc(batchIndices, newIdxCap); } final int idx = vtxWriterIndex; final int idx2 = idx * 2; diff --git a/src/main/java/com/gtnewhorizons/angelica/compat/lwjgl/CompatMemoryUtil.java b/src/main/java/com/gtnewhorizons/angelica/compat/lwjgl/CompatMemoryUtil.java deleted file mode 100644 index 9d027f736..000000000 --- a/src/main/java/com/gtnewhorizons/angelica/compat/lwjgl/CompatMemoryUtil.java +++ /dev/null @@ -1,327 +0,0 @@ -package com.gtnewhorizons.angelica.compat.lwjgl; - -import static com.gtnewhorizons.angelica.compat.lwjgl.Pointer.BITS64; - -import it.unimi.dsi.fastutil.longs.LongPredicate; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.FloatBuffer; -import java.nio.IntBuffer; -import org.lwjgl.BufferUtils; - -/** - * Backported from LWJGL3 under the BSD 3-Clause "New" or "Revised" License license - * - *

This class provides functionality for managing native memory. - * - *

All methods in this class will make use of {@link sun.misc.Unsafe} if it's available, for performance. If Unsafe is not available, the fallback - * implementations make use of reflection and, in the worst-case, JNI.

- * - *

Method names in this class are prefixed with {@code mem} to avoid ambiguities when used with static imports.

- */ -public class CompatMemoryUtil { - public static final long NULL = 0; - - static final sun.misc.Unsafe UNSAFE; - - private static final Class BUFFER_BYTE; - private static final Class BUFFER_INT; - private static final Class BUFFER_FLOAT; - - private static final long MARK; - private static final long POSITION; - private static final long LIMIT; - private static final long CAPACITY; - - private static final long ADDRESS; - - static { - ByteBuffer bb = ByteBuffer.allocateDirect(0).order(ByteOrder.nativeOrder()); - BUFFER_BYTE = bb.getClass(); - BUFFER_INT = bb.asIntBuffer().getClass(); - BUFFER_FLOAT = bb.asFloatBuffer().getClass(); - - UNSAFE = getUnsafeInstance(); - - MARK = getMarkOffset(); - POSITION = getPositionOffset(); - LIMIT = getLimitOffset(); - CAPACITY = getCapacityOffset(); - - ADDRESS = getAddressOffset(); - } - - public static ByteBuffer memReallocDirect(ByteBuffer old, int capacity) { - ByteBuffer newBuf = BufferUtils.createByteBuffer(capacity); - int oldPos = old.position(); - old.rewind(); - newBuf.put(old); - newBuf.position(Math.min(capacity, oldPos)); - return newBuf; - } - - public static IntBuffer memReallocDirect(IntBuffer old, int capacity) { - IntBuffer newBuf = BufferUtils.createIntBuffer(capacity); - int oldPos = old.position(); - old.rewind(); - newBuf.put(old); - newBuf.position(Math.min(capacity, oldPos)); - return newBuf; - } - - public static FloatBuffer memReallocDirect(FloatBuffer old, int capacity) { - FloatBuffer newBuf = BufferUtils.createFloatBuffer(capacity); - int oldPos = old.position(); - old.rewind(); - newBuf.put(old); - newBuf.position(Math.min(capacity, oldPos)); - return newBuf; - } - - /* ------------------------------------- - ------------------------------------- - UNSAFE MEMORY ACCESS API - ------------------------------------- - ------------------------------------- */ - - private static final int FILL_PATTERN_32 = Integer.divideUnsigned(-1, 255); - private static final long FILL_PATTERN_64 = Long.divideUnsigned(-1L, 255L); - - /** - * Sets all bytes in a specified block of memory to a fixed value (usually zero). - * - * @param ptr the starting memory address - * @param value the value to set (memSet will convert it to unsigned byte) - * @param bytes the number of bytes to set - */ - public static void memSet(long ptr, int value, long bytes) { - if (/*DEBUG*/ false && (ptr == NULL || bytes < 0)) { - throw new IllegalArgumentException(); - } - - /* - - Unsafe.setMemory is very slow. - - A custom Java loop is fastest at small sizes, approximately up to 256 bytes. - - The native memset becomes fastest at bigger sizes, when the JNI overhead becomes negligible. - TODO: verify this - */ - - //UNSAFE.setMemory(ptr, bytes, (byte)(value & 0xFF)); - //if (bytes < 256L) { - int p = (int)ptr; - if (BITS64) { - if ((p & 7) == 0) { - memSet64(ptr, value, (int)bytes & 0xFF); - return; - } - } else { - if ((p & 3) == 0) { - memSet32(p, value, (int)bytes & 0xFF); - return; - } - } - //} - //nmemset(ptr, value, bytes); - } - private static void memSet64(long ptr, int value, int bytes) { - int aligned = bytes & ~7; - - // Aligned body - long valuel = (value & 0xFF) * FILL_PATTERN_64; - for (int i = 0; i < aligned; i += 8) { - UNSAFE.putLong(null, ptr + i, valuel); - } - - // Unaligned tail - byte valueb = (byte)(value & 0xFF); - for (int i = aligned; i < bytes; i++) { - UNSAFE.putByte(null, ptr + i, valueb); - } - } - private static void memSet32(int ptr, int value, int bytes) { - int aligned = bytes & ~3; - - // Aligned body - int vi = (value & 0xFF) * FILL_PATTERN_32; - for (int i = 0; i < aligned; i += 4) { - UNSAFE.putInt(null, (ptr + i) & 0xFFFF_FFFFL, vi); - } - - // Unaligned tail - byte vb = (byte)(value & 0xFF); - for (int i = aligned; i < bytes; i++) { - UNSAFE.putByte(null, (ptr + i) & 0xFFFF_FFFFL, vb); - } - } - - public static boolean memGetBoolean(long ptr) { return UNSAFE.getByte(null, ptr) != 0; } - public static byte memGetByte(long ptr) { return UNSAFE.getByte(null, ptr); } - public static short memGetShort(long ptr) { return UNSAFE.getShort(null, ptr); } - public static int memGetInt(long ptr) { return UNSAFE.getInt(null, ptr); } - public static long memGetLong(long ptr) { return UNSAFE.getLong(null, ptr); } - public static float memGetFloat(long ptr) { return UNSAFE.getFloat(null, ptr); } - public static double memGetDouble(long ptr) { return UNSAFE.getDouble(null, ptr); } - - public static void memPutByte(long ptr, byte value) { UNSAFE.putByte(null, ptr, value); } - public static void memPutShort(long ptr, short value) { UNSAFE.putShort(null, ptr, value); } - public static void memPutInt(long ptr, int value) { UNSAFE.putInt(null, ptr, value); } - public static void memPutLong(long ptr, long value) { UNSAFE.putLong(null, ptr, value); } - public static void memPutFloat(long ptr, float value) { UNSAFE.putFloat(null, ptr, value); } - public static void memPutDouble(long ptr, double value) { UNSAFE.putDouble(null, ptr, value); } - - // ------------------------------------------------- - // ------------------------------------------------- - // ------------------------------------------------- - - private static sun.misc.Unsafe getUnsafeInstance() { - java.lang.reflect.Field[] fields = sun.misc.Unsafe.class.getDeclaredFields(); - - /* - Different runtimes use different names for the Unsafe singleton, - so we cannot use .getDeclaredField and we scan instead. For example: - - Oracle: theUnsafe - PERC : m_unsafe_instance - Android: THE_ONE - */ - for (java.lang.reflect.Field field : fields) { - if (!field.getType().equals(sun.misc.Unsafe.class)) { - continue; - } - - int modifiers = field.getModifiers(); - if (!(java.lang.reflect.Modifier.isStatic(modifiers) && java.lang.reflect.Modifier.isFinal(modifiers))) { - continue; - } - - try { - field.setAccessible(true); - return (sun.misc.Unsafe)field.get(null); - } catch (Exception ignored) { - } - break; - } - - throw new UnsupportedOperationException("LWJGL requires sun.misc.Unsafe to be available."); - } - - /** - * Recursively searches an object and its superclasses for a field with the same name and type. If the field isn't - * public, it may not be stable across library/JVM versions, and these calls are likely not portable. You have been - * warned! - */ - private static long getFieldOffset(Class containerType, Class fieldType, String name) { - Class c = containerType; - while (c != Object.class) { - Field[] fields = c.getDeclaredFields(); - for (Field field : fields) { - if (!field.getType().isAssignableFrom(fieldType) || Modifier.isStatic(field.getModifiers()) || field.isSynthetic()) { - continue; - } - - long offset = UNSAFE.objectFieldOffset(field); - if (field.getName().equals(name)) { - return offset; - } - } - c = c.getSuperclass(); - } - throw new UnsupportedOperationException("Failed to find field offset in class."); - } - - private static long getFieldOffset(Class containerType, Class fieldType, LongPredicate predicate) { - Class c = containerType; - while (c != Object.class) { - Field[] fields = c.getDeclaredFields(); - for (Field field : fields) { - if (!field.getType().isAssignableFrom(fieldType) || Modifier.isStatic(field.getModifiers()) || field.isSynthetic()) { - continue; - } - - long offset = UNSAFE.objectFieldOffset(field); - if (predicate.test(offset)) { - return offset; - } - } - c = c.getSuperclass(); - } - throw new UnsupportedOperationException("Failed to find field offset in class."); - } - - private static long getFieldOffsetInt(Object container, int value) { - return getFieldOffset(container.getClass(), int.class, offset -> UNSAFE.getInt(container, offset) == value); - } - - private static long getAddressOffset() { - final ByteBuffer bb = ByteBuffer.allocateDirect(0); - return getFieldOffset(bb.getClass(), long.class, "address"); - - // TODO: do this portably - // long MAGIC_ADDRESS = 0xDEADBEEF8BADF00DL & (BITS32 ? 0xFFFF_FFFFL : 0xFFFF_FFFF_FFFF_FFFFL); - // ByteBuffer bb = Objects.requireNonNull(NewDirectByteBuffer(MAGIC_ADDRESS, 0)); - //return getFieldOffset(bb.getClass(), long.class, offset -> UNSAFE.getLong(bb, offset) == MAGIC_ADDRESS); - } - - private static final int MAGIC_CAPACITY = 0x0D15EA5E; - private static final int MAGIC_POSITION = 0x00FACADE; - - private static long getMarkOffset() { - // TODO: is this actually reliable without NewDirectByteBuffer? - ByteBuffer bb = ByteBuffer.allocateDirect(0); - return getFieldOffsetInt(bb, -1); - // ByteBuffer bb = Objects.requireNonNull(NewDirectByteBuffer(1L, 0)); - // return getFieldOffsetInt(bb, -1); - } - - private static long getPositionOffset() { - ByteBuffer bb = ByteBuffer.allocateDirect(MAGIC_CAPACITY); - bb.position(MAGIC_POSITION); - return getFieldOffsetInt(bb, MAGIC_POSITION); - } - - private static long getLimitOffset() { - ByteBuffer bb = ByteBuffer.allocateDirect(MAGIC_CAPACITY); - bb.limit(MAGIC_POSITION); - return getFieldOffsetInt(bb, MAGIC_POSITION); - } - - private static long getCapacityOffset() { - ByteBuffer bb = ByteBuffer.allocateDirect(MAGIC_CAPACITY); - bb.limit(0); - return getFieldOffsetInt(bb, MAGIC_CAPACITY); - } - - static IntBuffer wrapBufferInt(long address, int capacity) { - IntBuffer buffer; - try { - buffer = (IntBuffer)UNSAFE.allocateInstance(BUFFER_INT); - } catch (InstantiationException e) { - throw new UnsupportedOperationException(e); - } - - UNSAFE.putLong(buffer, ADDRESS, address); - UNSAFE.putInt(buffer, MARK, -1); - UNSAFE.putInt(buffer, LIMIT, capacity); - UNSAFE.putInt(buffer, CAPACITY, capacity); - - return buffer; - } - - static FloatBuffer wrapBufferFloat(long address, int capacity) { - FloatBuffer buffer; - try { - buffer = (FloatBuffer)UNSAFE.allocateInstance(BUFFER_FLOAT); - } catch (InstantiationException e) { - throw new UnsupportedOperationException(e); - } - - UNSAFE.putLong(buffer, ADDRESS, address); - UNSAFE.putInt(buffer, MARK, -1); - UNSAFE.putInt(buffer, LIMIT, capacity); - UNSAFE.putInt(buffer, CAPACITY, capacity); - - return buffer; - } -} diff --git a/src/main/java/com/gtnewhorizons/angelica/compat/lwjgl/MemoryStack.java b/src/main/java/com/gtnewhorizons/angelica/compat/lwjgl/MemoryStack.java deleted file mode 100644 index 28180d803..000000000 --- a/src/main/java/com/gtnewhorizons/angelica/compat/lwjgl/MemoryStack.java +++ /dev/null @@ -1,382 +0,0 @@ -/* - * This class is backported from LWJGL3 under the BSD 3-clause "New" or "Revised" License - */ - -package com.gtnewhorizons.angelica.compat.lwjgl; - - -import static com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil.memPutDouble; -import static com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil.memPutFloat; -import static com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil.memPutInt; -import static com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil.memPutLong; -import static com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil.memPutShort; -import static com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil.memSet; -import static com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil.wrapBufferFloat; -import static com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil.wrapBufferInt; - -import com.gtnewhorizons.angelica.loading.AngelicaTweaker; -import java.nio.ByteBuffer; -import java.nio.FloatBuffer; -import java.nio.IntBuffer; -import java.util.Arrays; -import org.jetbrains.annotations.Nullable; -import org.lwjgl.BufferUtils; -import org.lwjgl.MemoryUtil; - -/** - * An off-heap memory stack. - * - *

This class should be used in a thread-local manner for stack allocations.

- * - * @ see Configuration#STACK_SIZE - * @ see Configuration#DEBUG_STACK - */ -@SuppressWarnings("LombokGetterMayBeUsed") -public class MemoryStack extends Pointer.Default implements AutoCloseable { - - private static final int DEFAULT_STACK_SIZE = /*Configuration.STACK_SIZE.get(64)*/ 64 * 1024; - private static final int DEFAULT_STACK_FRAMES = 8; - - private static final ThreadLocal TLS = ThreadLocal.withInitial(MemoryStack::create); - - static { - if (DEFAULT_STACK_SIZE < 0) { - throw new IllegalStateException("Invalid stack size."); - } - } - - @SuppressWarnings({"FieldCanBeLocal", "unused"}) - private final @Nullable ByteBuffer container; - - private final int size; - - private int pointer; - - private int[] frames; - protected int frameIndex; - - /** - * Creates a new {@code MemoryStack} backed by the specified memory region. - * - *

In the initial state, there is no active stack frame. The {@link #push} method must be used before any allocations.

- * - * @param container the backing memory buffer, may be null - * @param address the backing memory address - * @param size the backing memory size - */ - protected MemoryStack(@Nullable ByteBuffer container, long address, int size) { - super(address); - this.container = container; - - this.size = size; - this.pointer = size; - - this.frames = new int[DEFAULT_STACK_FRAMES]; - } - - /** - * Creates a new {@code MemoryStack} with the default size. - * - *

In the initial state, there is no active stack frame. The {@link #push} method must be used before any allocations.

- */ - public static MemoryStack create() { - return create(DEFAULT_STACK_SIZE); - } - - /** - * Creates a new {@code MemoryStack} with the specified size. - * - *

In the initial state, there is no active stack frame. The {@link #push} method must be used before any allocations.

- * - * @param capacity the maximum number of bytes that may be allocated on the stack - */ - public static MemoryStack create(int capacity) { - return create(BufferUtils.createByteBuffer(capacity)); - } - - /** - * Creates a new {@code MemoryStack} backed by the specified memory buffer. - * - *

In the initial state, there is no active stack frame. The {@link #push} method must be used before any allocations.

- * - * @param buffer the backing memory buffer - */ - public static MemoryStack create(ByteBuffer buffer) { - long address = MemoryUtil.getAddress(buffer); - int size = buffer.remaining(); - return new MemoryStack(buffer, address, size); - } - - /** - * Creates a new {@code MemoryStack} backed by the specified memory region. - * - *

In the initial state, there is no active stack frame. The {@link #push} method must be used before any allocations.

- * - * @param address the backing memory address - * @param size the backing memory size - */ - public static MemoryStack ncreate(long address, int size) { - return new MemoryStack(null, address, size); - } - - /** - * Stores the current stack pointer and pushes a new frame to the stack. - * - *

This method should be called when entering a method, before doing any stack allocations. When exiting a method, call the {@link #pop} method to - * restore the previous stack frame.

- * - *

Pairs of push/pop calls may be nested. Care must be taken to:

- *
    - *
  • match every push with a pop
  • - *
  • not call pop before push has been called at least once
  • - *
  • not nest push calls to more than the maximum supported depth
  • - *
- * - * @return this stack - */ - public MemoryStack push() { - if (frameIndex == frames.length) { - frameOverflow(); - } - - frames[frameIndex++] = pointer; - return this; - } - - private void frameOverflow() { - if (/*DEBUG*/ false) { - AngelicaTweaker.LOGGER.warn("[WARNING] Out of frame stack space (" + frames.length + ") in thread: " + Thread.currentThread()); - } - frames = Arrays.copyOf(frames, frames.length * 3 / 2); - } - - /** - * Pops the current stack frame and moves the stack pointer to the end of the previous stack frame. - * - * @return this stack - */ - public MemoryStack pop() { - pointer = frames[--frameIndex]; - return this; - } - - /** - * Calls {@link #pop} on this {@code MemoryStack}. - * - *

This method should not be used directly. It is called automatically when the {@code MemoryStack} is used as a resource in a try-with-resources - * statement.

- */ - @Override - public void close() { - //noinspection resource - pop(); - } - - /** - * Returns the address of the backing off-heap memory. - * - *

The stack grows "downwards", so the bottom of the stack is at {@code address + size}, while the top is at {@code address}.

- */ - public long getAddress() { - return address; - } - - /** - * Returns the size of the backing off-heap memory. - * - *

This is the maximum number of bytes that may be allocated on the stack.

- */ - public int getSize() { - return size; - } - - /** - * Returns the current frame index. - * - *

This is the current number of nested {@link #push} calls.

- */ - public int getFrameIndex() { - return frameIndex; - } - - /** Returns the memory address at the current stack pointer. */ - public long getPointerAddress() { - return address + (pointer & 0xFFFF_FFFFL); - } - - /** - * Returns the current stack pointer. - * - *

The stack grows "downwards", so when the stack is empty {@code pointer} is equal to {@code size}. On every allocation {@code pointer} is reduced by - * the allocated size (after alignment) and {@code address + pointer} points to the first byte of the last allocation.

- * - *

Effectively, this methods returns how many more bytes may be allocated on the stack.

- */ - public int getPointer() { - return pointer; - } - - /** - * Sets the current stack pointer. - * - *

This method directly manipulates the stack pointer. Using it irresponsibly may break the internal state of the stack. It should only be used in rare - * cases or in auto-generated code.

- */ - public void setPointer(int pointer) { - if (/*CHECKS*/ false) { - checkPointer(pointer); - } - - this.pointer = pointer; - } - - private void checkPointer(int pointer) { - if (pointer < 0 || size < pointer) { - throw new IndexOutOfBoundsException("Invalid stack pointer"); - } - } - - private static void checkAlignment(int alignment) { - if (Integer.bitCount(alignment) != 1) { - throw new IllegalArgumentException("Alignment must be a power-of-two value."); - } - } - - /** - * Calls {@link #nmalloc(int, int)} with {@code alignment} equal to {@link Pointer#POINTER_SIZE POINTER_SIZE}. - * - * @param size the allocation size - * - * @return the memory address on the stack for the requested allocation - */ - public long nmalloc(int size) { - return nmalloc(POINTER_SIZE, size); - } - - /** - * Allocates a block of {@code size} bytes of memory on the stack. The content of the newly allocated block of memory is not initialized, remaining with - * indeterminate values. - * - * @param alignment the required alignment - * @param size the allocation size - * - * @return the memory address on the stack for the requested allocation - */ - public long nmalloc(int alignment, int size) { - // Align address to the specified alignment - long address = (this.address + pointer - size) & ~Integer.toUnsignedLong(alignment - 1); - - pointer = (int)(address - this.address); - if (/*CHECKS*/ false && pointer < 0) { - throw new OutOfMemoryError("Out of stack space."); - } - - return address; - } - - /** - * Allocates a block of memory on the stack for an array of {@code num} elements, each of them {@code size} bytes long, and initializes all its bits to - * zero. - * - * @param alignment the required element alignment - * @param num num the number of elements to allocate - * @param size the size of each element - * - * @return the memory address on the stack for the requested allocation - */ - public long ncalloc(int alignment, int num, int size) { - int bytes = num * size; - long address = nmalloc(alignment, bytes); - memSet(address, 0, bytes); - return address; - } - - // ------------------------------------------------- - - /** Unsafe version of {@link #shorts(short)}. */ - public long nshort(short value) { - long a = nmalloc(2, 2); - memPutShort(a, value); - return a; - } - - // ------------------------------------------------- - - /** Int version of {@link #malloc(int)}. */ - public IntBuffer mallocInt(int size) { return wrapBufferInt(nmalloc(4, size << 2), size); } - - /** Unsafe version of {@link #ints(int)}. */ - public long nint(int value) { - long a = nmalloc(4, 4); - memPutInt(a, value); - return a; - } - - // ------------------------------------------------- - - /** Unsafe version of {@link #longs(long)}. */ - public long nlong(long value) { - long a = nmalloc(8, 8); - memPutLong(a, value); - return a; - } - - // ------------------------------------------------- - - /** Float version of {@link #malloc(int)}. */ - public FloatBuffer mallocFloat(int size) { return wrapBufferFloat(nmalloc(4, size << 2), size); } - - /** Unsafe version of {@link #floats(float)}. */ - public long nfloat(float value) { - long a = nmalloc(4, 4); - memPutFloat(a, value); - return a; - } - - // ------------------------------------------------- - - /** Unsafe version of {@link #doubles(double)}. */ - public long ndouble(double value) { - long a = nmalloc(8, 8); - memPutDouble(a, value); - return a; - } - - // ------------------------------------------------- - // ------------------------------------------------- - // ------------------------------------------------- - - - /** Returns the stack of the current thread. */ - public static MemoryStack stackGet() { - return TLS.get(); - } - - /** - * Calls {@link #push} on the stack of the current thread. - * - * @return the stack of the current thread. - */ - public static MemoryStack stackPush() { - return stackGet().push(); - } - - /** - * Calls {@link #pop} on the stack of the current thread. - * - * @return the stack of the current thread. - */ - public static MemoryStack stackPop() { - return stackGet().pop(); - } - - /** Thread-local version of {@link #nmalloc(int)}. */ - public static long nstackMalloc(int size) { return stackGet().nmalloc(size); } - /** Thread-local version of {@link #nmalloc(int, int)}. */ - public static long nstackMalloc(int alignment, int size) { return stackGet().nmalloc(alignment, size); } - /** Thread-local version of {@link #ncalloc}. */ - public static long nstackCalloc(int alignment, int num, int size) { return stackGet().ncalloc(alignment, num, size); } - - // ------------------------------------------------- - -} diff --git a/src/main/java/com/gtnewhorizons/angelica/compat/lwjgl/Pointer.java b/src/main/java/com/gtnewhorizons/angelica/compat/lwjgl/Pointer.java deleted file mode 100644 index 254aabfa8..000000000 --- a/src/main/java/com/gtnewhorizons/angelica/compat/lwjgl/Pointer.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * This class is backported from LWJGL3 under the BSD 3-clause "New" or "Revised" License - */ -package com.gtnewhorizons.angelica.compat.lwjgl; - - -import static com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil.NULL; -import static com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil.UNSAFE; -import static org.lwjgl.LWJGLUtil.CHECKS; - -import net.minecraft.util.Util; -import org.jetbrains.annotations.Nullable; - -/** - * Pointer interface. - * - *

LWJGL can run on both 32bit and 64bit architectures. Since LWJGL applications deal with native memory directly, this interface provides necessary - * information about the underlying architecture of the running JVM process.

- * - *

When interacting with native functions, pointer values are mapped to Java {@code long}. LWJGL automatically converts long values to the correct pointer - * addresses when used in native code. Native functions sometimes require arrays of pointer values; the {@link PointerBuffer} class may be used for that - * purpose. It has an API similar to a {@link java.nio.LongBuffer} but handles pointer casts automatically.

- */ -public interface Pointer { - - /** The pointer size in bytes. Will be 4 on a 32bit JVM and 8 on a 64bit one. */ - int POINTER_SIZE = UNSAFE.addressSize(); - - /** The pointer size power-of-two. Will be 2 on a 32bit JVM and 3 on a 64bit one. */ - int POINTER_SHIFT = POINTER_SIZE == 8 ? 3 : 2; - - /** The value of {@code sizeof(long)} for the current platform. */ - int CLONG_SIZE = POINTER_SIZE == 8 && Util.getOSType() == Util.EnumOS.WINDOWS ? 4 : POINTER_SIZE; - - /** The value of {@code sizeof(long)} as a power-of-two. */ - int CLONG_SHIFT = CLONG_SIZE == 8 ? 3 : 2; - - /** Will be true on a 32bit JVM. */ - boolean BITS32 = POINTER_SIZE * 8 == 32; - - /** Will be true on a 64bit JVM. */ - boolean BITS64 = POINTER_SIZE * 8 == 64; - - /** - * Returns the raw pointer address as a {@code long} value. - * - * @return the pointer address - */ - long address(); - - /** Default {@link Pointer} implementation. */ - abstract class Default implements Pointer { - - // Removed final due to JDK-8139758. TODO: Restore if the fix is backported to JDK 8. - protected long address; - - protected Default(long address) { - if (CHECKS && address == NULL) { - throw new NullPointerException(); - } - this.address = address; - } - - @Override - public long address() { - return address; - } - - public boolean equals(@Nullable Object o) { - if (this == o) { - return true; - } - if (!(o instanceof Pointer)) { - return false; - } - - Pointer that = (Pointer)o; - - return address == that.address(); - } - - public int hashCode() { - return (int)(address ^ (address >>> 32)); - } - - @Override - public String toString() { - return String.format("%s pointer [0x%X]", getClass().getSimpleName(), address); - } - - } - -} diff --git a/src/main/java/com/gtnewhorizons/angelica/compat/mojang/NativeImage.java b/src/main/java/com/gtnewhorizons/angelica/compat/mojang/NativeImage.java index 64d021aa2..fd9b1c13a 100644 --- a/src/main/java/com/gtnewhorizons/angelica/compat/mojang/NativeImage.java +++ b/src/main/java/com/gtnewhorizons/angelica/compat/mojang/NativeImage.java @@ -1,6 +1,7 @@ package com.gtnewhorizons.angelica.compat.mojang; -import com.gtnewhorizons.angelica.compat.lwjgl.MemoryStack; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryStack.*; + import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; @@ -8,6 +9,8 @@ import java.io.InputStream; import java.nio.ByteBuffer; import java.nio.IntBuffer; import javax.imageio.ImageIO; + +import com.gtnewhorizon.gtnhlib.bytebuf.MemoryStack; import lombok.Getter; import net.coderbot.iris.Iris; import org.lwjgl.opengl.GL11; @@ -58,7 +61,7 @@ public class NativeImage extends BufferedImage { // final int width = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, level, GL11.GL_TEXTURE_WIDTH); // final int height = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, level, GL11.GL_TEXTURE_HEIGHT); - try (final MemoryStack stack = MemoryStack.stackPush()) { + try (final MemoryStack stack = stackPush()) { final IntBuffer buffer = stack.mallocInt(size); GL11.glGetTexImage(GL11.GL_TEXTURE_2D, level, format.glFormat, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, buffer); diff --git a/src/main/java/com/gtnewhorizons/angelica/debug/F3Graph.java b/src/main/java/com/gtnewhorizons/angelica/debug/F3Graph.java index bb26867ba..a84b19e92 100644 --- a/src/main/java/com/gtnewhorizons/angelica/debug/F3Graph.java +++ b/src/main/java/com/gtnewhorizons/angelica/debug/F3Graph.java @@ -28,9 +28,10 @@ import static org.lwjgl.opengl.GL20.glUniform1; import static org.lwjgl.opengl.GL20.glUniform1f; import static org.lwjgl.opengl.GL20.glUniform1i; import static org.lwjgl.opengl.GL20.glVertexAttribPointer; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryStack.*; +import com.gtnewhorizon.gtnhlib.bytebuf.MemoryStack; import com.gtnewhorizon.gtnhlib.client.renderer.shader.ShaderProgram; -import com.gtnewhorizons.angelica.compat.lwjgl.MemoryStack; import java.nio.FloatBuffer; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; @@ -131,7 +132,7 @@ public abstract class F3Graph { // Load vertex buffer vertBuf = glGenBuffers(); glBindBuffer(GL_ARRAY_BUFFER, vertBuf); - try (final MemoryStack stack = MemoryStack.stackPush()) { + try (final MemoryStack stack = stackPush()) { final FloatBuffer vertices = stack.mallocFloat(VERT_COUNT * VERT_FLOATS); // Since we use a triangle strip, we only need 4 vertices. The quad extends to the top of the screen so spikes // don't get truncated. The max height is replaced in the vert shader, no need to be precise. diff --git a/src/main/java/me/jellysquid/mods/sodium/client/gl/util/GlMultiDrawBatch.java b/src/main/java/me/jellysquid/mods/sodium/client/gl/util/GlMultiDrawBatch.java index d38ee8d2d..0199af4b6 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/gl/util/GlMultiDrawBatch.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/gl/util/GlMultiDrawBatch.java @@ -1,6 +1,7 @@ package me.jellysquid.mods.sodium.client.gl.util; -import org.lwjgl.BufferUtils; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.*; + import org.lwjgl.opengl.GL20; @@ -17,8 +18,8 @@ public class GlMultiDrawBatch { private boolean isBuilding; public GlMultiDrawBatch(int capacity) { - this.bufIndices = BufferUtils.createIntBuffer(capacity); - this.bufLen = BufferUtils.createIntBuffer(capacity); + this.bufIndices = memAllocInt(capacity); + this.bufLen = memAllocInt(capacity); } public IntBuffer getIndicesBuffer() { @@ -59,8 +60,8 @@ public class GlMultiDrawBatch { } public void delete() { - this.bufIndices.clear(); - this.bufLen.clear(); + memFree(this.bufIndices); + memFree(this.bufLen); this.bufIndices = null; this.bufLen = null; diff --git a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/buffer/VertexBufferBuilder.java b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/buffer/VertexBufferBuilder.java index 82372cb66..b5757c6fb 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/buffer/VertexBufferBuilder.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/buffer/VertexBufferBuilder.java @@ -1,6 +1,7 @@ package me.jellysquid.mods.sodium.client.model.vertex.buffer; -import com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.*; + import me.jellysquid.mods.sodium.client.gl.attribute.BufferVertexFormat; import org.lwjgl.BufferUtils; @@ -16,7 +17,7 @@ public class VertexBufferBuilder implements VertexBufferView { public VertexBufferBuilder(BufferVertexFormat vertexFormat, int initialCapacity) { this.vertexFormat = vertexFormat; - this.buffer = BufferUtils.createByteBuffer(initialCapacity); + this.buffer = memAlloc(initialCapacity); this.capacity = initialCapacity; this.writerOffset = 0; } @@ -25,7 +26,7 @@ public class VertexBufferBuilder implements VertexBufferView { // The new capacity will at least as large as the write it needs to service final int cap = Math.max(this.capacity * 2, this.capacity + len); - this.buffer = CompatMemoryUtil.memReallocDirect(this.buffer, cap); + this.buffer = memRealloc(this.buffer, cap); this.capacity = cap; } diff --git a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/glyph/writer/GlyphVertexBufferWriterUnsafe.java b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/glyph/writer/GlyphVertexBufferWriterUnsafe.java index 697a6a95e..896c751ff 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/glyph/writer/GlyphVertexBufferWriterUnsafe.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/glyph/writer/GlyphVertexBufferWriterUnsafe.java @@ -1,6 +1,7 @@ package me.jellysquid.mods.sodium.client.model.vertex.formats.glyph.writer; -import com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.*; + import me.jellysquid.mods.sodium.client.model.vertex.VanillaVertexTypes; import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferView; import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferWriterUnsafe; @@ -15,13 +16,13 @@ public class GlyphVertexBufferWriterUnsafe extends VertexBufferWriterUnsafe impl public void writeGlyph(float x, float y, float z, int color, float u, float v, int light) { long i = this.writePointer; - CompatMemoryUtil.memPutFloat(i, x); - CompatMemoryUtil.memPutFloat(i + 4, y); - CompatMemoryUtil.memPutFloat(i + 8, z); - CompatMemoryUtil.memPutInt(i + 12, color); - CompatMemoryUtil.memPutFloat(i + 16, u); - CompatMemoryUtil.memPutFloat(i + 20, v); - CompatMemoryUtil.memPutInt(i + 24, light); + memPutFloat(i, x); + memPutFloat(i + 4, y); + memPutFloat(i + 8, z); + memPutInt(i + 12, color); + memPutFloat(i + 16, u); + memPutFloat(i + 20, v); + memPutInt(i + 24, light); this.advance(); diff --git a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/line/writer/LineVertexBufferWriterUnsafe.java b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/line/writer/LineVertexBufferWriterUnsafe.java index 2744be84a..55295dc8b 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/line/writer/LineVertexBufferWriterUnsafe.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/line/writer/LineVertexBufferWriterUnsafe.java @@ -1,6 +1,7 @@ package me.jellysquid.mods.sodium.client.model.vertex.formats.line.writer; -import com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.*; + import me.jellysquid.mods.sodium.client.model.vertex.VanillaVertexTypes; import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferView; import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferWriterUnsafe; @@ -15,10 +16,10 @@ public class LineVertexBufferWriterUnsafe extends VertexBufferWriterUnsafe imple public void vertexLine(float x, float y, float z, int color) { long i = this.writePointer; - CompatMemoryUtil.memPutFloat(i, x); - CompatMemoryUtil.memPutFloat(i + 4, y); - CompatMemoryUtil.memPutFloat(i + 8, z); - CompatMemoryUtil.memPutInt(i + 12, color); + memPutFloat(i, x); + memPutFloat(i + 4, y); + memPutFloat(i + 8, z); + memPutInt(i + 12, color); this.advance(); } diff --git a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/particle/writer/ParticleVertexBufferWriterUnsafe.java b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/particle/writer/ParticleVertexBufferWriterUnsafe.java index 564f18bc2..2714d0aa4 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/particle/writer/ParticleVertexBufferWriterUnsafe.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/particle/writer/ParticleVertexBufferWriterUnsafe.java @@ -1,6 +1,7 @@ package me.jellysquid.mods.sodium.client.model.vertex.formats.particle.writer; -import com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.*; + import me.jellysquid.mods.sodium.client.model.vertex.VanillaVertexTypes; import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferView; import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferWriterUnsafe; @@ -15,13 +16,13 @@ public class ParticleVertexBufferWriterUnsafe extends VertexBufferWriterUnsafe i public void writeParticle(float x, float y, float z, float u, float v, int color, int light) { long i = this.writePointer; - CompatMemoryUtil.memPutFloat(i, x); - CompatMemoryUtil.memPutFloat(i + 4, y); - CompatMemoryUtil.memPutFloat(i + 8, z); - CompatMemoryUtil.memPutFloat(i + 12, u); - CompatMemoryUtil.memPutFloat(i + 16, v); - CompatMemoryUtil.memPutInt(i + 20, color); - CompatMemoryUtil.memPutInt(i + 24, light); + memPutFloat(i, x); + memPutFloat(i + 4, y); + memPutFloat(i + 8, z); + memPutFloat(i + 12, u); + memPutFloat(i + 16, v); + memPutInt(i + 20, color); + memPutInt(i + 24, light); this.advance(); } diff --git a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/quad/writer/QuadVertexBufferWriterUnsafe.java b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/quad/writer/QuadVertexBufferWriterUnsafe.java index f38c56d94..bab1953d7 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/quad/writer/QuadVertexBufferWriterUnsafe.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/quad/writer/QuadVertexBufferWriterUnsafe.java @@ -1,6 +1,7 @@ package me.jellysquid.mods.sodium.client.model.vertex.formats.quad.writer; -import com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.*; + import me.jellysquid.mods.sodium.client.model.vertex.VanillaVertexTypes; import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferView; import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferWriterUnsafe; @@ -15,15 +16,15 @@ public class QuadVertexBufferWriterUnsafe extends VertexBufferWriterUnsafe imple public void writeQuad(float x, float y, float z, int color, float u, float v, int light, int overlay, int normal) { final long i = this.writePointer; - CompatMemoryUtil.memPutFloat(i, x); - CompatMemoryUtil.memPutFloat(i + 4, y); - CompatMemoryUtil.memPutFloat(i + 8, z); - CompatMemoryUtil.memPutInt(i + 12, color); - CompatMemoryUtil.memPutFloat(i + 16, u); - CompatMemoryUtil.memPutFloat(i + 20, v); - CompatMemoryUtil.memPutInt(i + 24, overlay); - CompatMemoryUtil.memPutInt(i + 28, light); - CompatMemoryUtil.memPutInt(i + 32, normal); + memPutFloat(i, x); + memPutFloat(i + 4, y); + memPutFloat(i + 8, z); + memPutInt(i + 12, color); + memPutFloat(i + 16, u); + memPutFloat(i + 20, v); + memPutInt(i + 24, overlay); + memPutInt(i + 28, light); + memPutInt(i + 32, normal); this.advance(); } diff --git a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/screen_quad/writer/BasicScreenQuadVertexBufferWriterUnsafe.java b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/screen_quad/writer/BasicScreenQuadVertexBufferWriterUnsafe.java index 502dbb226..511d61a20 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/screen_quad/writer/BasicScreenQuadVertexBufferWriterUnsafe.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/screen_quad/writer/BasicScreenQuadVertexBufferWriterUnsafe.java @@ -1,6 +1,7 @@ package me.jellysquid.mods.sodium.client.model.vertex.formats.screen_quad.writer; -import com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.*; + import me.jellysquid.mods.sodium.client.model.vertex.VanillaVertexTypes; import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferView; import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferWriterUnsafe; @@ -15,10 +16,10 @@ public class BasicScreenQuadVertexBufferWriterUnsafe extends VertexBufferWriterU public void writeQuad(float x, float y, float z, int color) { long i = this.writePointer; - CompatMemoryUtil.memPutFloat(i, x); - CompatMemoryUtil.memPutFloat(i + 4, y); - CompatMemoryUtil.memPutFloat(i + 8, z); - CompatMemoryUtil.memPutInt(i + 12, color); + memPutFloat(i, x); + memPutFloat(i + 4, y); + memPutFloat(i + 8, z); + memPutInt(i + 12, color); this.advance(); } diff --git a/src/main/java/me/jellysquid/mods/sodium/client/render/GameRendererContext.java b/src/main/java/me/jellysquid/mods/sodium/client/render/GameRendererContext.java index 3d65f43cd..f280b2218 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/render/GameRendererContext.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/render/GameRendererContext.java @@ -1,6 +1,6 @@ package me.jellysquid.mods.sodium.client.render; -import com.gtnewhorizons.angelica.compat.lwjgl.MemoryStack; +import com.gtnewhorizon.gtnhlib.bytebuf.MemoryStack; import com.gtnewhorizons.angelica.compat.toremove.MatrixStack; import com.gtnewhorizons.angelica.config.AngelicaConfig; import com.gtnewhorizons.angelica.rendering.RenderingState; diff --git a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/backends/multidraw/ChunkDrawCallBatcher.java b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/backends/multidraw/ChunkDrawCallBatcher.java index aeb88fbcf..e9ace34cd 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/backends/multidraw/ChunkDrawCallBatcher.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/backends/multidraw/ChunkDrawCallBatcher.java @@ -1,6 +1,7 @@ package me.jellysquid.mods.sodium.client.render.chunk.backends.multidraw; -import com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.*; + import com.gtnewhorizons.angelica.compat.mojang.CompatMathHelper; import me.jellysquid.mods.sodium.client.SodiumClientMod; import org.lwjgl.MemoryUtil; @@ -83,10 +84,10 @@ public abstract class ChunkDrawCallBatcher extends StructBuffer { throw new BufferUnderflowException(); } - CompatMemoryUtil.memPutInt(this.writePointer , count); // Vertex Count - CompatMemoryUtil.memPutInt(this.writePointer + 4, instanceCount); // Instance Count - CompatMemoryUtil.memPutInt(this.writePointer + 8, first); // Vertex Start - CompatMemoryUtil.memPutInt(this.writePointer + 12, baseInstance); // Base Instance + memPutInt(this.writePointer , count); // Vertex Count + memPutInt(this.writePointer + 4, instanceCount); // Instance Count + memPutInt(this.writePointer + 8, first); // Vertex Start + memPutInt(this.writePointer + 12, baseInstance); // Base Instance this.writePointer += this.stride; } diff --git a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/backends/multidraw/ChunkDrawParamsVector.java b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/backends/multidraw/ChunkDrawParamsVector.java index 05b71837e..cb2b7d23b 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/backends/multidraw/ChunkDrawParamsVector.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/backends/multidraw/ChunkDrawParamsVector.java @@ -1,6 +1,7 @@ package me.jellysquid.mods.sodium.client.render.chunk.backends.multidraw; -import com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.*; + import me.jellysquid.mods.sodium.client.SodiumClientMod; import org.lwjgl.MemoryUtil; @@ -32,7 +33,7 @@ public abstract class ChunkDrawParamsVector extends StructBuffer { protected void growBuffer() { this.capacity = this.capacity * 2; - this.buffer = CompatMemoryUtil.memReallocDirect(this.buffer, this.capacity * this.stride); + this.buffer = memRealloc(this.buffer, this.capacity * this.stride); } public static class UnsafeChunkDrawCallVector extends ChunkDrawParamsVector { @@ -51,9 +52,9 @@ public abstract class ChunkDrawParamsVector extends StructBuffer { this.growBuffer(); } - CompatMemoryUtil.memPutFloat(this.writePointer , x); - CompatMemoryUtil.memPutFloat(this.writePointer + 4, y); - CompatMemoryUtil.memPutFloat(this.writePointer + 8, z); + memPutFloat(this.writePointer , x); + memPutFloat(this.writePointer + 4, y); + memPutFloat(this.writePointer + 8, z); this.writePointer += this.stride; } @@ -64,7 +65,7 @@ public abstract class ChunkDrawParamsVector extends StructBuffer { long offset = this.writePointer - this.basePointer; - this.basePointer = MemoryUtil.getAddress(this.buffer); + this.basePointer = memAddress(this.buffer); this.writePointer = this.basePointer + offset; } diff --git a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/backends/multidraw/IndirectCommandBufferVector.java b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/backends/multidraw/IndirectCommandBufferVector.java index 37cf45484..2b07f2553 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/backends/multidraw/IndirectCommandBufferVector.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/backends/multidraw/IndirectCommandBufferVector.java @@ -1,6 +1,6 @@ package me.jellysquid.mods.sodium.client.render.chunk.backends.multidraw; -import com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.*; public class IndirectCommandBufferVector extends StructBuffer { protected IndirectCommandBufferVector(int capacity) { @@ -32,6 +32,6 @@ public class IndirectCommandBufferVector extends StructBuffer { } protected void growBuffer(int n) { - this.buffer = CompatMemoryUtil.memReallocDirect(this.buffer, Math.max(this.buffer.capacity() * 2, this.buffer.capacity() + n)); + this.buffer = memRealloc(this.buffer, Math.max(this.buffer.capacity() * 2, this.buffer.capacity() + n)); } } diff --git a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/backends/multidraw/StructBuffer.java b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/backends/multidraw/StructBuffer.java index 89399cd56..254938222 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/backends/multidraw/StructBuffer.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/backends/multidraw/StructBuffer.java @@ -1,7 +1,6 @@ package me.jellysquid.mods.sodium.client.render.chunk.backends.multidraw; -import org.lwjgl.BufferUtils; -import org.lwjgl.MemoryUtil; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.*; import java.nio.ByteBuffer; @@ -11,7 +10,7 @@ public abstract class StructBuffer { protected final int stride; protected StructBuffer(int bytes, int stride) { - this.buffer = BufferUtils.createByteBuffer(bytes * stride); + this.buffer = memAlloc(bytes * stride); this.stride = stride; } @@ -20,7 +19,7 @@ public abstract class StructBuffer { } public long getBufferAddress() { - return MemoryUtil.getAddress(this.buffer); + return memAddress(this.buffer); } public void delete() { diff --git a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/format/hfp/HFPModelVertexBufferWriterUnsafe.java b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/format/hfp/HFPModelVertexBufferWriterUnsafe.java index e53fbbe2c..14565d9c9 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/format/hfp/HFPModelVertexBufferWriterUnsafe.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/format/hfp/HFPModelVertexBufferWriterUnsafe.java @@ -1,6 +1,7 @@ package me.jellysquid.mods.sodium.client.render.chunk.format.hfp; -import com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.*; + import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferView; import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferWriterUnsafe; import me.jellysquid.mods.sodium.client.render.chunk.format.DefaultModelVertexFormats; @@ -28,13 +29,13 @@ public class HFPModelVertexBufferWriterUnsafe extends VertexBufferWriterUnsafe i private void writeQuadInternal(short x, short y, short z, int color, short u, short v, int light) { long i = this.writePointer; - CompatMemoryUtil.memPutShort(i, x); - CompatMemoryUtil.memPutShort(i + 2, y); - CompatMemoryUtil.memPutShort(i + 4, z); - CompatMemoryUtil.memPutInt(i + 8, color); - CompatMemoryUtil.memPutShort(i + 12, u); - CompatMemoryUtil.memPutShort(i + 14, v); - CompatMemoryUtil.memPutInt(i + 16, light); + memPutShort(i, x); + memPutShort(i + 2, y); + memPutShort(i + 4, z); + memPutInt(i + 8, color); + memPutShort(i + 12, u); + memPutShort(i + 14, v); + memPutInt(i + 16, light); this.advance(); } diff --git a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/format/sfp/SFPModelVertexBufferWriterUnsafe.java b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/format/sfp/SFPModelVertexBufferWriterUnsafe.java index d4ca903cb..ff4abb4de 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/format/sfp/SFPModelVertexBufferWriterUnsafe.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/format/sfp/SFPModelVertexBufferWriterUnsafe.java @@ -1,6 +1,7 @@ package me.jellysquid.mods.sodium.client.render.chunk.format.sfp; -import com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.*; + import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferView; import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferWriterUnsafe; import me.jellysquid.mods.sodium.client.render.chunk.format.DefaultModelVertexFormats; @@ -15,13 +16,13 @@ public class SFPModelVertexBufferWriterUnsafe extends VertexBufferWriterUnsafe i public void writeQuad(float x, float y, float z, int color, float u, float v, int light) { long i = this.writePointer; - CompatMemoryUtil.memPutFloat(i, x); - CompatMemoryUtil.memPutFloat(i + 4, y); - CompatMemoryUtil.memPutFloat(i + 8, z); - CompatMemoryUtil.memPutInt(i + 12, color); - CompatMemoryUtil.memPutFloat(i + 16, u); - CompatMemoryUtil.memPutFloat(i + 20, v); - CompatMemoryUtil.memPutInt(i + 24, encodeLightMapTexCoord(light)); + memPutFloat(i, x); + memPutFloat(i + 4, y); + memPutFloat(i + 8, z); + memPutInt(i + 12, color); + memPutFloat(i + 16, u); + memPutFloat(i + 20, v); + memPutInt(i + 24, encodeLightMapTexCoord(light)); this.advance(); } diff --git a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/shader/ChunkProgram.java b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/shader/ChunkProgram.java index 6d26d4fa5..ffe195a39 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/shader/ChunkProgram.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/shader/ChunkProgram.java @@ -1,6 +1,8 @@ package me.jellysquid.mods.sodium.client.render.chunk.shader; -import com.gtnewhorizons.angelica.compat.lwjgl.MemoryStack; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryStack.*; + +import com.gtnewhorizon.gtnhlib.bytebuf.MemoryStack; import com.gtnewhorizons.angelica.compat.toremove.MatrixStack; import me.jellysquid.mods.sodium.client.gl.device.RenderDevice; import me.jellysquid.mods.sodium.client.gl.shader.GlProgram; @@ -49,7 +51,7 @@ public class ChunkProgram extends GlProgram { this.fogShader.setup(); if (this.uModelViewProjectionMatrix == -1) return; - try (MemoryStack stack = MemoryStack.stackPush()) { + try (MemoryStack stack = stackPush()) { GL20.glUniformMatrix4( this.uModelViewProjectionMatrix, false, diff --git a/src/main/java/net/coderbot/iris/gl/framebuffer/GlFramebuffer.java b/src/main/java/net/coderbot/iris/gl/framebuffer/GlFramebuffer.java index 24f314a2d..6c9a57be4 100644 --- a/src/main/java/net/coderbot/iris/gl/framebuffer/GlFramebuffer.java +++ b/src/main/java/net/coderbot/iris/gl/framebuffer/GlFramebuffer.java @@ -1,6 +1,8 @@ package net.coderbot.iris.gl.framebuffer; -import com.gtnewhorizons.angelica.compat.lwjgl.MemoryStack; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryStack.*; + +import com.gtnewhorizon.gtnhlib.bytebuf.MemoryStack; import com.gtnewhorizons.angelica.glsm.RenderSystem; import com.gtnewhorizons.angelica.glsm.texture.TextureInfoCache; import it.unimi.dsi.fastutil.ints.Int2IntArrayMap; @@ -51,7 +53,7 @@ public class GlFramebuffer extends GlResource { } public void noDrawBuffers() { - try (MemoryStack stack = MemoryStack.stackPush()) { + try (MemoryStack stack = stackPush()) { final IntBuffer buffer = stack.mallocInt(1); buffer.put(GL11.GL_NONE); RenderSystem.drawBuffers(getGlId(), buffer); @@ -59,7 +61,7 @@ public class GlFramebuffer extends GlResource { } public void drawBuffers(int[] buffers) { - try (MemoryStack stack = MemoryStack.stackPush()) { + try (MemoryStack stack = stackPush()) { final IntBuffer glBuffers = stack.mallocInt(buffers.length); int index = 0; diff --git a/src/main/java/net/coderbot/iris/rendertarget/RenderTarget.java b/src/main/java/net/coderbot/iris/rendertarget/RenderTarget.java index 9ca5cb17a..9d5344cf2 100644 --- a/src/main/java/net/coderbot/iris/rendertarget/RenderTarget.java +++ b/src/main/java/net/coderbot/iris/rendertarget/RenderTarget.java @@ -1,6 +1,8 @@ package net.coderbot.iris.rendertarget; -import com.gtnewhorizons.angelica.compat.lwjgl.MemoryStack; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryStack.*; + +import com.gtnewhorizon.gtnhlib.bytebuf.MemoryStack; import com.gtnewhorizons.angelica.glsm.GLStateManager; import com.gtnewhorizons.angelica.glsm.RenderSystem; import lombok.Getter; @@ -41,7 +43,7 @@ public class RenderTarget { this.width = builder.width; this.height = builder.height; - try (MemoryStack stack = MemoryStack.stackPush()) { + try (MemoryStack stack = stackPush()) { IntBuffer textures = stack.mallocInt(2); GL11.glGenTextures(textures); diff --git a/src/main/java/net/coderbot/iris/sodium/shader_overrides/IrisChunkProgram.java b/src/main/java/net/coderbot/iris/sodium/shader_overrides/IrisChunkProgram.java index 2917a6367..5538cfed8 100644 --- a/src/main/java/net/coderbot/iris/sodium/shader_overrides/IrisChunkProgram.java +++ b/src/main/java/net/coderbot/iris/sodium/shader_overrides/IrisChunkProgram.java @@ -1,6 +1,8 @@ package net.coderbot.iris.sodium.shader_overrides; -import com.gtnewhorizons.angelica.compat.lwjgl.MemoryStack; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryStack.*; + +import com.gtnewhorizon.gtnhlib.bytebuf.MemoryStack; import com.gtnewhorizons.angelica.compat.toremove.MatrixStack; import com.gtnewhorizons.angelica.glsm.RenderSystem; import java.nio.FloatBuffer; @@ -86,7 +88,7 @@ public class IrisChunkProgram extends ChunkProgram { return; } - try (MemoryStack stack = MemoryStack.stackPush()) { + try (MemoryStack stack = stackPush()) { FloatBuffer buffer = stack.mallocFloat(16); matrix.get(buffer); diff --git a/src/main/java/net/coderbot/iris/sodium/vertex_format/entity_xhfp/EntityVertexBufferWriterUnsafe.java b/src/main/java/net/coderbot/iris/sodium/vertex_format/entity_xhfp/EntityVertexBufferWriterUnsafe.java index c697bec3b..f0a503295 100644 --- a/src/main/java/net/coderbot/iris/sodium/vertex_format/entity_xhfp/EntityVertexBufferWriterUnsafe.java +++ b/src/main/java/net/coderbot/iris/sodium/vertex_format/entity_xhfp/EntityVertexBufferWriterUnsafe.java @@ -1,6 +1,7 @@ package net.coderbot.iris.sodium.vertex_format.entity_xhfp; -import com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.*; + import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferView; import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferWriterUnsafe; import me.jellysquid.mods.sodium.client.model.vertex.formats.glyph.GlyphVertexSink; @@ -32,14 +33,14 @@ public class EntityVertexBufferWriterUnsafe extends VertexBufferWriterUnsafe imp uSum += u; vSum += v; - CompatMemoryUtil.memPutFloat(i, x); - CompatMemoryUtil.memPutFloat(i + 4, y); - CompatMemoryUtil.memPutFloat(i + 8, z); - CompatMemoryUtil.memPutInt(i + 12, color); - CompatMemoryUtil.memPutFloat(i + 16, u); - CompatMemoryUtil.memPutFloat(i + 20, v); - CompatMemoryUtil.memPutInt(i + 24, overlay); - CompatMemoryUtil.memPutInt(i + 28, light); + memPutFloat(i, x); + memPutFloat(i + 4, y); + memPutFloat(i + 8, z); + memPutInt(i + 12, color); + memPutFloat(i + 16, u); + memPutFloat(i + 20, v); + memPutInt(i + 24, overlay); + memPutInt(i + 28, light); if (vertexCount == 4) { this.endQuad(normal); @@ -80,10 +81,10 @@ public class EntityVertexBufferWriterUnsafe extends VertexBufferWriterUnsafe imp int tangent = NormalHelper.computeTangent(normalX, normalY, normalZ, quad); for (long vertex = 0; vertex < 4; vertex++) { - CompatMemoryUtil.memPutFloat(i + 36 - STRIDE * vertex, uSum); - CompatMemoryUtil.memPutFloat(i + 40 - STRIDE * vertex, vSum); - CompatMemoryUtil.memPutInt(i + 32 - STRIDE * vertex, normal); - CompatMemoryUtil.memPutInt(i + 44 - STRIDE * vertex, tangent); + memPutFloat(i + 36 - STRIDE * vertex, uSum); + memPutFloat(i + 40 - STRIDE * vertex, vSum); + memPutInt(i + 32 - STRIDE * vertex, normal); + memPutInt(i + 44 - STRIDE * vertex, tangent); } uSum = 0; diff --git a/src/main/java/net/coderbot/iris/sodium/vertex_format/entity_xhfp/GlyphVertexBufferWriterUnsafe.java b/src/main/java/net/coderbot/iris/sodium/vertex_format/entity_xhfp/GlyphVertexBufferWriterUnsafe.java index 70d4d719b..2c8d3d617 100644 --- a/src/main/java/net/coderbot/iris/sodium/vertex_format/entity_xhfp/GlyphVertexBufferWriterUnsafe.java +++ b/src/main/java/net/coderbot/iris/sodium/vertex_format/entity_xhfp/GlyphVertexBufferWriterUnsafe.java @@ -1,6 +1,7 @@ package net.coderbot.iris.sodium.vertex_format.entity_xhfp; -import com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.*; + import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferView; import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferWriterUnsafe; import me.jellysquid.mods.sodium.client.model.vertex.formats.glyph.GlyphVertexSink; @@ -32,13 +33,13 @@ public class GlyphVertexBufferWriterUnsafe extends VertexBufferWriterUnsafe impl uSum += u; vSum += v; - CompatMemoryUtil.memPutFloat(i, x); - CompatMemoryUtil.memPutFloat(i + 4, y); - CompatMemoryUtil.memPutFloat(i + 8, z); - CompatMemoryUtil.memPutInt(i + 12, color); - CompatMemoryUtil.memPutFloat(i + 16, u); - CompatMemoryUtil.memPutFloat(i + 20, v); - CompatMemoryUtil.memPutInt(i + 24, light); + memPutFloat(i, x); + memPutFloat(i + 4, y); + memPutFloat(i + 8, z); + memPutInt(i + 12, color); + memPutFloat(i + 16, u); + memPutFloat(i + 20, v); + memPutInt(i + 24, light); if (vertexCount == 4) { this.endQuad(normal); @@ -79,10 +80,10 @@ public class GlyphVertexBufferWriterUnsafe extends VertexBufferWriterUnsafe impl int tangent = NormalHelper.computeTangent(normalX, normalY, normalZ, quad); for (long vertex = 0; vertex < 4; vertex++) { - CompatMemoryUtil.memPutFloat(i + 36 - STRIDE * vertex, uSum); - CompatMemoryUtil.memPutFloat(i + 40 - STRIDE * vertex, vSum); - CompatMemoryUtil.memPutInt(i + 28 - STRIDE * vertex, normal); - CompatMemoryUtil.memPutInt(i + 44 - STRIDE * vertex, tangent); + memPutFloat(i + 36 - STRIDE * vertex, uSum); + memPutFloat(i + 40 - STRIDE * vertex, vSum); + memPutInt(i + 28 - STRIDE * vertex, normal); + memPutInt(i + 44 - STRIDE * vertex, tangent); } uSum = 0; diff --git a/src/main/java/net/coderbot/iris/sodium/vertex_format/entity_xhfp/QuadViewEntity.java b/src/main/java/net/coderbot/iris/sodium/vertex_format/entity_xhfp/QuadViewEntity.java index bb56d1aaa..2ee3f6670 100644 --- a/src/main/java/net/coderbot/iris/sodium/vertex_format/entity_xhfp/QuadViewEntity.java +++ b/src/main/java/net/coderbot/iris/sodium/vertex_format/entity_xhfp/QuadViewEntity.java @@ -1,6 +1,7 @@ package net.coderbot.iris.sodium.vertex_format.entity_xhfp; -import com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.*; + import net.coderbot.iris.vertices.IrisQuadView; import java.nio.ByteBuffer; @@ -44,7 +45,7 @@ public abstract class QuadViewEntity implements IrisQuadView { @Override float getFloat(long writePointer) { - return CompatMemoryUtil.memGetFloat(writePointer); + return memGetFloat(writePointer); } } diff --git a/src/main/java/net/coderbot/iris/sodium/vertex_format/terrain_xhfp/QuadViewTerrain.java b/src/main/java/net/coderbot/iris/sodium/vertex_format/terrain_xhfp/QuadViewTerrain.java index b1e96fbf7..c6c485c18 100644 --- a/src/main/java/net/coderbot/iris/sodium/vertex_format/terrain_xhfp/QuadViewTerrain.java +++ b/src/main/java/net/coderbot/iris/sodium/vertex_format/terrain_xhfp/QuadViewTerrain.java @@ -1,6 +1,7 @@ package net.coderbot.iris.sodium.vertex_format.terrain_xhfp; -import com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.*; + import net.coderbot.iris.vertices.IrisQuadView; import java.nio.ByteBuffer; @@ -52,7 +53,7 @@ public abstract class QuadViewTerrain implements IrisQuadView { @Override short getShort(long writePointer) { - return CompatMemoryUtil.memGetShort(writePointer); + return memGetShort(writePointer); } } diff --git a/src/main/java/net/coderbot/iris/sodium/vertex_format/terrain_xhfp/XHFPModelVertexBufferWriterUnsafe.java b/src/main/java/net/coderbot/iris/sodium/vertex_format/terrain_xhfp/XHFPModelVertexBufferWriterUnsafe.java index f9047c6a6..5f5d8a9a4 100644 --- a/src/main/java/net/coderbot/iris/sodium/vertex_format/terrain_xhfp/XHFPModelVertexBufferWriterUnsafe.java +++ b/src/main/java/net/coderbot/iris/sodium/vertex_format/terrain_xhfp/XHFPModelVertexBufferWriterUnsafe.java @@ -1,6 +1,7 @@ package net.coderbot.iris.sodium.vertex_format.terrain_xhfp; -import com.gtnewhorizons.angelica.compat.lwjgl.CompatMemoryUtil; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.*; + import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferView; import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferWriterUnsafe; import me.jellysquid.mods.sodium.client.render.chunk.format.ModelVertexSink; @@ -54,21 +55,21 @@ public class XHFPModelVertexBufferWriterUnsafe extends VertexBufferWriterUnsafe vertexCount++; // NB: uSum and vSum must already be incremented outside of this function. - CompatMemoryUtil.memPutShort(i, x); - CompatMemoryUtil.memPutShort(i + 2, y); - CompatMemoryUtil.memPutShort(i + 4, z); - CompatMemoryUtil.memPutInt(i + 8, color); - CompatMemoryUtil.memPutShort(i + 12, u); - CompatMemoryUtil.memPutShort(i + 14, v); - CompatMemoryUtil.memPutShort(i + 16, (short) (light & 0xFFFF)); - CompatMemoryUtil.memPutShort(i + 18, (short) (light >> 16 & 0xFFFF)); + memPutShort(i, x); + memPutShort(i + 2, y); + memPutShort(i + 4, z); + memPutInt(i + 8, color); + memPutShort(i + 12, u); + memPutShort(i + 14, v); + memPutShort(i + 16, (short) (light & 0xFFFF)); + memPutShort(i + 18, (short) (light >> 16 & 0xFFFF)); // NB: We don't set midTexCoord, normal, and tangent here, they will be filled in later. // block ID: We only set the first 2 values, any legacy shaders using z or w will get filled in based on the GLSL spec // https://www.khronos.org/opengl/wiki/Vertex_Specification#Vertex_format // TODO: can we pack this into one short? - CompatMemoryUtil.memPutShort(i + 36, materialId); - CompatMemoryUtil.memPutShort(i + 38, renderType); - CompatMemoryUtil.memPutInt(i + 40, packedMidBlock); + memPutShort(i + 36, materialId); + memPutShort(i + 38, renderType); + memPutInt(i + 40, packedMidBlock); if (vertexCount == 4) { vertexCount = 0; @@ -103,15 +104,15 @@ public class XHFPModelVertexBufferWriterUnsafe extends VertexBufferWriterUnsafe uSum *= 0.25f; vSum *= 0.25f; - CompatMemoryUtil.memPutFloat(i + 20, uSum); - CompatMemoryUtil.memPutFloat(i + 20 - STRIDE, uSum); - CompatMemoryUtil.memPutFloat(i + 20 - STRIDE * 2, uSum); - CompatMemoryUtil.memPutFloat(i + 20 - STRIDE * 3, uSum); + memPutFloat(i + 20, uSum); + memPutFloat(i + 20 - STRIDE, uSum); + memPutFloat(i + 20 - STRIDE * 2, uSum); + memPutFloat(i + 20 - STRIDE * 3, uSum); - CompatMemoryUtil.memPutFloat(i + 24, vSum); - CompatMemoryUtil.memPutFloat(i + 24 - STRIDE, vSum); - CompatMemoryUtil.memPutFloat(i + 24 - STRIDE * 2, vSum); - CompatMemoryUtil.memPutFloat(i + 24 - STRIDE * 3, vSum); + memPutFloat(i + 24, vSum); + memPutFloat(i + 24 - STRIDE, vSum); + memPutFloat(i + 24 - STRIDE * 2, vSum); + memPutFloat(i + 24 - STRIDE * 3, vSum); uSum = 0; vSum = 0; @@ -124,17 +125,17 @@ public class XHFPModelVertexBufferWriterUnsafe extends VertexBufferWriterUnsafe NormalHelper.computeFaceNormal(normal, quad); int packedNormal = NormalHelper.packNormal(normal, 0.0f); - CompatMemoryUtil.memPutInt(i + 32, packedNormal); - CompatMemoryUtil.memPutInt(i + 32 - STRIDE, packedNormal); - CompatMemoryUtil.memPutInt(i + 32 - STRIDE * 2, packedNormal); - CompatMemoryUtil.memPutInt(i + 32 - STRIDE * 3, packedNormal); + memPutInt(i + 32, packedNormal); + memPutInt(i + 32 - STRIDE, packedNormal); + memPutInt(i + 32 - STRIDE * 2, packedNormal); + memPutInt(i + 32 - STRIDE * 3, packedNormal); int tangent = NormalHelper.computeTangent(normal.x, normal.y, normal.z, quad); - CompatMemoryUtil.memPutInt(i + 28, tangent); - CompatMemoryUtil.memPutInt(i + 28 - STRIDE, tangent); - CompatMemoryUtil.memPutInt(i + 28 - STRIDE * 2, tangent); - CompatMemoryUtil.memPutInt(i + 28 - STRIDE * 3, tangent); + memPutInt(i + 28, tangent); + memPutInt(i + 28 - STRIDE, tangent); + memPutInt(i + 28 - STRIDE * 2, tangent); + memPutInt(i + 28 - STRIDE * 3, tangent); } this.advance(); diff --git a/src/main/java/net/coderbot/iris/texture/util/TextureManipulationUtil.java b/src/main/java/net/coderbot/iris/texture/util/TextureManipulationUtil.java index e27d507ca..e05d3b5e1 100644 --- a/src/main/java/net/coderbot/iris/texture/util/TextureManipulationUtil.java +++ b/src/main/java/net/coderbot/iris/texture/util/TextureManipulationUtil.java @@ -1,5 +1,8 @@ package net.coderbot.iris.texture.util; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryStack.*; + +import com.gtnewhorizon.gtnhlib.bytebuf.MemoryStack; import com.gtnewhorizons.angelica.glsm.GLStateManager; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.OpenGlHelper; @@ -14,43 +17,60 @@ public class TextureManipulationUtil { private static int colorFillFBO = -1; public static void fillWithColor(int textureId, int maxLevel, int rgba) { - if (colorFillFBO == -1) { - colorFillFBO = OpenGlHelper.func_153165_e/*glGenFramebuffers*/(); - } - - final int previousFramebufferId = GL11.glGetInteger(GL30.GL_FRAMEBUFFER_BINDING); - // TODO: allocations - final FloatBuffer previousClearColorBuffer = BufferUtils.createFloatBuffer(4); - GL11.glGetFloat(GL11.GL_COLOR_CLEAR_VALUE, previousClearColorBuffer); - final int previousTextureId = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D); - final IntBuffer previousViewportBuffer = BufferUtils.createIntBuffer(4); - GL11.glGetInteger(GL11.GL_VIEWPORT, previousViewportBuffer); - - OpenGlHelper.func_153171_g/*glBindFramebuffer*/(GL30.GL_FRAMEBUFFER, colorFillFBO); - GL11.glClearColor( - (rgba >> 24 & 0xFF) / 255.0f, - (rgba >> 16 & 0xFF) / 255.0f, - (rgba >> 8 & 0xFF) / 255.0f, - (rgba & 0xFF) / 255.0f - ); - GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, textureId); - for (int level = 0; level <= maxLevel; ++level) { - final int width = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, level, GL11.GL_TEXTURE_WIDTH); - final int height = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, level, GL11.GL_TEXTURE_HEIGHT); - GL11.glViewport(0, 0, width, height); - GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, textureId, level); - GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); - if (Minecraft.isRunningOnMac) { - GL11.glGetError(); + try(final MemoryStack stack = stackPush()) { + if (colorFillFBO == -1) { + colorFillFBO = OpenGlHelper.func_153165_e/*glGenFramebuffers*/(); } + final int previousFramebufferId = GL11.glGetInteger(GL30.GL_FRAMEBUFFER_BINDING); + final FloatBuffer previousClearColorBuffer = stack.mallocFloat(4); + GL11.glGetFloat(GL11.GL_COLOR_CLEAR_VALUE, previousClearColorBuffer); + final int previousTextureId = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D); + final IntBuffer previousViewportBuffer = stack.mallocInt(4); + GL11.glGetInteger(GL11.GL_VIEWPORT, previousViewportBuffer); - GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, 0, level); - } + OpenGlHelper.func_153171_g/*glBindFramebuffer*/(GL30.GL_FRAMEBUFFER, colorFillFBO); + GL11.glClearColor( + (rgba >> 24 & 0xFF) / 255.0f, + (rgba >> 16 & 0xFF) / 255.0f, + (rgba >> 8 & 0xFF) / 255.0f, + (rgba & 0xFF) / 255.0f); + GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, textureId); + for (int level = 0; level <= maxLevel; ++level) { + final int width = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, level, GL11.GL_TEXTURE_WIDTH); + final int height = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, level, GL11.GL_TEXTURE_HEIGHT); + GL11.glViewport(0, 0, width, height); + GL30.glFramebufferTexture2D( + GL30.GL_FRAMEBUFFER, + GL30.GL_COLOR_ATTACHMENT0, + GL11.GL_TEXTURE_2D, + textureId, + level); + GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); + if (Minecraft.isRunningOnMac) { + GL11.glGetError(); + } - OpenGlHelper.func_153171_g/*glBindFramebuffer*/(GL30.GL_FRAMEBUFFER, previousFramebufferId); - GL11.glClearColor(previousClearColorBuffer.get(0), previousClearColorBuffer.get(1), previousClearColorBuffer.get(2), previousClearColorBuffer.get(3)); - GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, previousTextureId); - GL11.glViewport(previousViewportBuffer.get(0), previousViewportBuffer.get(1), previousViewportBuffer.get(2), previousViewportBuffer.get(3)); + GL30.glFramebufferTexture2D( + GL30.GL_FRAMEBUFFER, + GL30.GL_COLOR_ATTACHMENT0, + GL11.GL_TEXTURE_2D, + 0, + level); + } + + OpenGlHelper.func_153171_g/*glBindFramebuffer*/(GL30.GL_FRAMEBUFFER, previousFramebufferId); + GL11.glClearColor( + previousClearColorBuffer.get(0), + previousClearColorBuffer.get(1), + previousClearColorBuffer.get(2), + previousClearColorBuffer.get(3)); + GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, previousTextureId); + GL11.glViewport( + previousViewportBuffer.get(0), + previousViewportBuffer.get(1), + previousViewportBuffer.get(2), + previousViewportBuffer.get(3)); + } } }