diff --git a/src/main/java/com/jozufozu/flywheel/api/instance/DynamicInstance.java b/src/main/java/com/jozufozu/flywheel/api/instance/DynamicInstance.java index 14310c962..86e43e77b 100644 --- a/src/main/java/com/jozufozu/flywheel/api/instance/DynamicInstance.java +++ b/src/main/java/com/jozufozu/flywheel/api/instance/DynamicInstance.java @@ -30,7 +30,7 @@ public interface DynamicInstance extends Instance { *
You might want to opt out of this if you want your animations to remain smooth * even when far away from the camera. It is recommended to keep this as is, however. * - * @return true if your instance should be slow ticked. + * @return {@code true} if your instance should be slow ticked. */ default boolean decreaseFramerateWithDistance() { return true; diff --git a/src/main/java/com/jozufozu/flywheel/api/instance/TickableInstance.java b/src/main/java/com/jozufozu/flywheel/api/instance/TickableInstance.java index efb2fedb1..488ba8697 100644 --- a/src/main/java/com/jozufozu/flywheel/api/instance/TickableInstance.java +++ b/src/main/java/com/jozufozu/flywheel/api/instance/TickableInstance.java @@ -38,7 +38,7 @@ public interface TickableInstance extends Instance { *
You might want to opt out of this if you want your animations to remain smooth * even when far away from the camera. It is recommended to keep this as is, however. * - * @return true if your instance should be slow ticked. + * @return {@code true} if your instance should be slow ticked. */ default boolean decreaseTickRateWithDistance() { return true; diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/GlVertexArray.java b/src/main/java/com/jozufozu/flywheel/backend/gl/GlVertexArray.java index 1ec315fa9..4f194e5d9 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/GlVertexArray.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/GlVertexArray.java @@ -12,10 +12,17 @@ public class GlVertexArray extends GlObject { setHandle(GlStateManager._glGenVertexArrays()); } + public static void bind(int vao) { + GlStateManager._glBindVertexArray(vao); + BufferUploaderAccessor.flywheel$setLastVAO(vao); + } + public void bind() { - int handle = handle(); - GlStateManager._glBindVertexArray(handle); - BufferUploaderAccessor.flywheel$setLastVAO(handle); + bind(handle()); + } + + public static int getBoundVertexArray() { + return BufferUploaderAccessor.flywheel$getLastVAO(); } public static void unbind() { diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/GlBufferType.java b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/GlBufferType.java index 53a0ab9ac..16f0c450a 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/GlBufferType.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/GlBufferType.java @@ -50,4 +50,12 @@ public enum GlBufferType { case GL15C.GL_ARRAY_BUFFER -> BufferUploaderAccessor.flywheel$setLastVBO(0); } } + + public int getBoundBuffer() { + return switch (this.glEnum) { + case GL15C.GL_ELEMENT_ARRAY_BUFFER -> BufferUploaderAccessor.flywheel$getLastEBO(); + case GL15C.GL_ARRAY_BUFFER -> BufferUploaderAccessor.flywheel$getLastVBO(); + default -> -1; + }; + } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/versioned/GlVersioned.java b/src/main/java/com/jozufozu/flywheel/backend/gl/versioned/GlVersioned.java index d019832b7..8615e9086 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/versioned/GlVersioned.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/versioned/GlVersioned.java @@ -4,7 +4,7 @@ import org.lwjgl.opengl.GLCapabilities; /** * This interface should be implemented by enums such that the - * last defined variant always returns true. + * last defined variant always returns {@code true} */ public interface GlVersioned { /** diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstance.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstance.java index 1a2ebb781..6a3e67ba8 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstance.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstance.java @@ -65,13 +65,13 @@ public abstract class AbstractInstance implements Instance, LightListener { * When an instance is reset, the instance is deleted and re-created. * *

- * Just before {@link #update()} would be called, shouldReset() is checked. - * If this function returns true, then this instance will be {@link #remove removed}, + * Just before {@link #update()} would be called, {@code shouldReset()} is checked. + * If this function returns {@code true}, then this instance will be {@link #remove removed}, * and another instance will be constructed to replace it. This allows for more sane resource * acquisition compared to trying to update everything within the lifetime of an instance. *

* - * @return true if this instance should be discarded and refreshed. + * @return {@code true} if this instance should be discarded and refreshed. */ public boolean shouldReset() { return false; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityInstance.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityInstance.java index 11925664f..ed4313063 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityInstance.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityInstance.java @@ -48,12 +48,12 @@ public abstract class BlockEntityInstance extends Abstrac } /** - * Just before {@link #update()} would be called, shouldReset() is checked. - * If this function returns true, then this instance will be {@link #remove removed}, + * Just before {@link #update()} would be called, {@code shouldReset()} is checked. + * If this function returns {@code true}, then this instance will be {@link #remove removed}, * and another instance will be constructed to replace it. This allows for more sane resource * acquisition compared to trying to update everything within the lifetime of an instance. * - * @return true if this instance should be discarded and refreshed. + * @return {@code true} if this instance should be discarded and refreshed. */ public boolean shouldReset() { return blockEntity.getBlockState() != blockState; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java index b14cf78e7..8f044c733 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java @@ -79,6 +79,10 @@ public class InstancingEngine

implements Engine { */ @Override public void render(TaskEngine taskEngine, RenderLayerEvent event) { + int ebo = GlBufferType.ELEMENT_ARRAY_BUFFER.getBoundBuffer(); + int vbo = GlBufferType.ARRAY_BUFFER.getBoundBuffer(); + int vao = GlVertexArray.getBoundVertexArray(); + double camX; double camY; double camZ; @@ -99,9 +103,9 @@ public class InstancingEngine

implements Engine { getGroupsToRender(event.getLayer()).forEach(group -> group.render(viewProjection, camX, camY, camZ)); - GlBufferType.ELEMENT_ARRAY_BUFFER.unbind(); - GlBufferType.ARRAY_BUFFER.unbind(); - GlVertexArray.unbind(); + GlBufferType.ELEMENT_ARRAY_BUFFER.bind(ebo); + GlBufferType.ARRAY_BUFFER.bind(vbo); + GlVertexArray.bind(vao); } private Stream> getGroupsToRender(@Nullable RenderLayer layer) { diff --git a/src/main/java/com/jozufozu/flywheel/backend/source/SourceFile.java b/src/main/java/com/jozufozu/flywheel/backend/source/SourceFile.java index ab055553d..24a8d1836 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/source/SourceFile.java +++ b/src/main/java/com/jozufozu/flywheel/backend/source/SourceFile.java @@ -217,7 +217,7 @@ public class SourceFile { } /** - * Scan the source for #use "..." directives. + * Scan the source for {@code #use "..."} directives. * Records the contents of the directive into an {@link Import} object, and marks the directive for elision. * @param elisions */ diff --git a/src/main/java/com/jozufozu/flywheel/core/materials/FlatLit.java b/src/main/java/com/jozufozu/flywheel/core/materials/FlatLit.java index 038a7250a..3829a1a84 100644 --- a/src/main/java/com/jozufozu/flywheel/core/materials/FlatLit.java +++ b/src/main/java/com/jozufozu/flywheel/core/materials/FlatLit.java @@ -14,14 +14,14 @@ public interface FlatLit> { /** * @param blockLight An integer in the range [0, 15] representing the * amount of block light this instance should receive. - * @return this + * @return {@code this} */ D setBlockLight(int blockLight); /** * @param skyLight An integer in the range [0, 15] representing the * amount of sky light this instance should receive. - * @return this + * @return {@code this} */ D setSkyLight(int skyLight); diff --git a/src/main/java/com/jozufozu/flywheel/core/model/WorldModel.java b/src/main/java/com/jozufozu/flywheel/core/model/WorldModel.java index b3e96aa7d..c350361c9 100644 --- a/src/main/java/com/jozufozu/flywheel/core/model/WorldModel.java +++ b/src/main/java/com/jozufozu/flywheel/core/model/WorldModel.java @@ -16,7 +16,7 @@ public class WorldModel implements Model { private final String name; /** - * It is expected that renderWorld.getShade(...) returns a constant. + * It is expected that {@code renderWorld.getShade(...)} returns a constant. */ public WorldModel(BlockAndTintGetter renderWorld, RenderType layer, Collection blocks, String name) { reader = Formats.BLOCK.createReader(ModelUtil.getBufferBuilderFromTemplate(renderWorld, layer, blocks)); diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/spec/ProgramSpec.java b/src/main/java/com/jozufozu/flywheel/core/shader/spec/ProgramSpec.java index 3716caef2..e293a2732 100644 --- a/src/main/java/com/jozufozu/flywheel/core/shader/spec/ProgramSpec.java +++ b/src/main/java/com/jozufozu/flywheel/core/shader/spec/ProgramSpec.java @@ -15,11 +15,11 @@ import net.minecraft.resources.ResourceLocation; * An object describing a shader program that can be loaded by flywheel. * *

- * These are defined through json. All ProgramSpecs in assets/modid/flywheel/programs are parsed and + * These are defined through json. All ProgramSpecs in {@code assets/modid/flywheel/programs} are parsed and * processed. One ProgramSpec typically specifies one "material" that can be used in game to render things. *

*

- * All shader source files in assets/modid/flywheel/shaders are completely loaded and parsed into + * All shader source files in {@code assets/modid/flywheel/shaders} are completely loaded and parsed into * {@link SourceFile SourceFiles}, but not compiled until one of them is * referenced by a ProgramSpec. *

diff --git a/src/main/java/com/jozufozu/flywheel/mixin/BufferUploaderAccessor.java b/src/main/java/com/jozufozu/flywheel/mixin/BufferUploaderAccessor.java index 64b81bd2b..f7d609805 100644 --- a/src/main/java/com/jozufozu/flywheel/mixin/BufferUploaderAccessor.java +++ b/src/main/java/com/jozufozu/flywheel/mixin/BufferUploaderAccessor.java @@ -21,4 +21,19 @@ public interface BufferUploaderAccessor { static void flywheel$setLastEBO(int id) { throw new AssertionError(); } + + @Accessor("lastIndexBufferObject") + static int flywheel$getLastEBO() { + throw new AssertionError(); + } + + @Accessor("lastVertexBufferObject") + static int flywheel$getLastVBO() { + throw new AssertionError(); + } + + @Accessor("lastVertexArrayObject") + static int flywheel$getLastVAO() { + throw new AssertionError(); + } }