From 2300ef2088051a33dfb8c68c432b07f6e41cb56a Mon Sep 17 00:00:00 2001 From: JozsefA Date: Sun, 30 May 2021 17:05:41 -0700 Subject: [PATCH] Organization, renaming, and fixing a dumb crash --- .../jozufozu/flywheel/backend/Backend.java | 16 +++-- .../{instancing => }/IFlywheelWorld.java | 4 +- .../flywheel/backend/ShaderContext.java | 4 +- .../flywheel/backend/ShaderLoader.java | 4 +- .../core/FirstNonnullMultiProgram.java | 6 -- .../flywheel/backend/core/IndexedModel.java | 56 --------------- .../backend/core/shader/ShaderCallback.java | 19 ----- ...lPrimitiveType.java => GlNumericType.java} | 23 ++++--- .../flywheel/backend/gl/GlPrimitive.java | 23 +++++++ .../backend/gl/attrib/CommonAttributes.java | 24 +++---- .../backend/gl/attrib/MatrixAttributes.java | 8 +-- .../backend/gl/attrib/VertexAttribSpec.java | 10 +-- .../versioned/instancing/DrawInstanced.java | 43 ++++++++---- .../backend/instancing/IInstance.java | 5 +- .../backend/instancing/IInstanceFactory.java | 5 ++ .../backend/instancing/IInstanceRendered.java | 9 ++- .../backend/instancing/ITickableInstance.java | 2 +- .../backend/instancing/InstanceData.java | 4 +- .../backend/instancing/InstanceFactory.java | 5 -- .../InstancedTileRenderRegistry.java | 6 +- .../instancing/InstancedTileRenderer.java | 19 +++-- .../{InstancedModel.java => Instancer.java} | 12 ++-- .../backend/instancing/MaterialSpec.java | 6 +- .../backend/instancing/RenderMaterial.java | 41 +++++------ .../instancing/TileEntityInstance.java | 6 +- .../backend/light/CoordinateConsumer.java | 6 -- ...essingStage.java => IProcessingStage.java} | 2 +- .../flywheel/backend/loading/LayoutTag.java | 6 +- .../backend/loading/ProgramTemplate.java | 2 +- .../backend/loading/ShaderTransformer.java | 8 +-- .../core/BufferedArrayModel.java | 11 +-- .../{backend => }/core/BufferedModel.java | 35 +++++----- .../{backend => }/core/CrumblingProgram.java | 6 +- .../{backend => }/core/CrumblingRenderer.java | 4 +- .../{backend => }/core/FullscreenQuad.java | 6 +- .../jozufozu/flywheel/core/IndexedModel.java | 69 +++++++++++++++++++ .../{backend => }/core/PartialModel.java | 2 +- .../core/context => core}/WorldContext.java | 13 ++-- .../{backend => }/core/WorldTileRenderer.java | 9 ++- .../instancing}/ConditionalInstance.java | 8 +-- .../instancing/GroupInstance.java} | 12 ++-- .../instancing}/SelectInstance.java | 8 +-- .../core/materials/BasicData.java | 6 +- .../core/materials/IFlatLight.java | 2 +- .../core/materials/ModelData.java | 6 +- .../core/materials/OrientedData.java | 6 +- .../core/shader/ExtensibleGlProgram.java | 6 +- .../{backend => }/core/shader/FogMode.java | 4 +- .../{backend => }/core/shader/GlFog.java | 2 +- .../core/shader/IMultiProgram.java | 2 +- .../core/shader/IProgramCallback.java | 19 +++++ .../shader/StateSensitiveMultiProgram.java | 8 +-- .../{backend => }/core/shader/WorldFog.java | 8 +-- .../core/shader/WorldProgram.java | 4 +- .../shader/extension/IExtensionInstance.java | 2 +- .../shader/extension/IProgramExtension.java | 4 +- .../extension/UnitExtensionInstance.java | 2 +- .../shader/gamestate/FogStateProvider.java | 4 +- .../shader/gamestate/IGameStateProvider.java | 4 +- .../gamestate/NormalDebugStateProvider.java | 4 +- .../gamestate/RainbowDebugStateProvider.java | 4 +- .../shader/spec/BooleanContextCondition.java | 4 +- .../shader/spec/IBooleanStateProvider.java | 4 +- .../core/shader/spec/IContextCondition.java | 4 +- .../core/shader/spec/ProgramSpec.java | 2 +- .../core/shader/spec/ProgramState.java | 4 +- .../core/shader/spec/SpecMetaRegistry.java | 14 ++-- .../shader/spec/SpecificValueCondition.java | 4 +- .../{backend => }/light/GridAlignedBB.java | 4 +- .../flywheel/light/ICoordinateConsumer.java | 6 ++ .../ILightUpdateListener.java} | 4 +- .../{backend => }/light/LightUpdater.java | 42 +++++------ .../{backend => }/light/LightVolume.java | 2 +- .../jozufozu/flywheel/util/AttribUtil.java | 8 +-- .../com/simibubi/create/AllBlockPartials.java | 4 +- .../com/simibubi/create/CreateClient.java | 2 +- .../animations/AnimatedBlazeBurner.java | 2 +- .../category/animations/AnimatedKinetics.java | 2 +- .../contraptions/base/HalfShaftInstance.java | 4 +- .../contraptions/base/KineticData.java | 6 +- .../contraptions/base/RotatingData.java | 4 +- .../base/ShaftlessCogInstance.java | 4 +- .../base/SingleRotatingInstance.java | 4 +- .../components/actors/ActorData.java | 4 +- .../components/actors/DrillInstance.java | 4 +- .../actors/HarvesterActorInstance.java | 2 +- .../PortableStorageInterfaceRenderer.java | 2 +- .../components/clock/CuckooClockRenderer.java | 2 +- .../clock/CuckooClockTileEntity.java | 10 +-- .../crafter/MechanicalCrafterInstance.java | 4 +- .../crafter/MechanicalCrafterRenderer.java | 2 +- .../crafter/MechanicalCrafterTileEntity.java | 8 +-- .../components/crank/HandCrankBlock.java | 2 +- .../components/crank/HandCrankInstance.java | 8 +-- .../components/crank/HandCrankRenderer.java | 2 +- .../components/crank/HandCrankTileEntity.java | 2 +- .../components/crank/ValveHandleBlock.java | 2 +- .../deployer/DeployerActorInstance.java | 4 +- .../components/deployer/DeployerInstance.java | 4 +- .../components/deployer/DeployerRenderer.java | 2 +- .../deployer/DeployerTileEntity.java | 4 +- .../components/flywheel/FlyWheelInstance.java | 6 +- .../flywheel/engine/EngineBlock.java | 2 +- .../flywheel/engine/EngineInstance.java | 4 +- .../flywheel/engine/EngineRenderer.java | 2 +- .../flywheel/engine/FurnaceEngineBlock.java | 2 +- .../millstone/MillStoneCogInstance.java | 4 +- .../components/mixer/MixerInstance.java | 2 +- .../components/press/PressInstance.java | 2 +- .../components/saw/SawInstance.java | 4 +- .../components/saw/SawRenderer.java | 2 +- .../components/saw/SawTileEntity.java | 4 +- .../structureMovement/Contraption.java | 4 +- .../structureMovement/ContraptionLighter.java | 10 +-- .../NonStationaryLighter.java | 2 +- .../bearing/AnchoredLighter.java | 2 +- .../bearing/BearingInstance.java | 4 +- .../bearing/BearingRenderer.java | 2 +- .../bearing/ClockworkBearingTileEntity.java | 6 +- .../bearing/MechanicalBearingTileEntity.java | 8 +-- .../bearing/StabilizedBearingInstance.java | 2 +- .../StabilizedBearingMovementBehaviour.java | 2 +- .../chassis/StickerInstance.java | 2 +- .../gantry/GantryCarriageInstance.java | 2 +- .../gantry/GantryCarriageTileEntity.java | 4 +- .../piston/PistonLighter.java | 2 +- .../pulley/AbstractPulleyInstance.java | 46 ++++++------- .../pulley/AbstractPulleyRenderer.java | 2 +- .../pulley/HosePulleyInstance.java | 14 ++-- .../pulley/PulleyLighter.java | 2 +- .../pulley/PulleyRenderer.java | 2 +- .../pulley/PulleyTileEntity.java | 8 +-- .../pulley/RopePulleyInstance.java | 14 ++-- .../render/ContraptionProgram.java | 4 +- .../render/ContraptionRenderDispatcher.java | 2 +- .../render/EmptyLighter.java | 2 +- .../render/LightVolumeDebugger.java | 2 +- .../render/RenderedContraption.java | 13 ++-- .../contraptions/fluids/PumpCogInstance.java | 4 +- .../contraptions/fluids/PumpTileEntity.java | 4 +- .../fluids/actors/HosePulleyRenderer.java | 2 +- .../fluids/actors/HosePulleyTileEntity.java | 2 +- .../fluids/actors/SpoutRenderer.java | 2 +- .../fluids/pipes/FluidValveInstance.java | 2 +- .../fluids/pipes/FluidValveTileEntity.java | 4 +- .../processing/BasinOperatingTileEntity.java | 12 ++-- .../burner/BlazeBurnerRenderer.java | 2 +- .../advanced/SpeedControllerTileEntity.java | 4 +- .../contraptions/relays/belt/BeltData.java | 4 +- .../relays/belt/BeltInstance.java | 10 +-- .../relays/belt/BeltRenderer.java | 2 +- .../relays/belt/BeltTileEntity.java | 10 +-- .../relays/encased/SplitShaftInstance.java | 4 +- .../relays/gauge/GaugeInstance.java | 16 ++--- .../relays/gauge/GaugeRenderer.java | 2 +- .../relays/gauge/GaugeTileEntity.java | 2 +- .../relays/gearbox/GearboxInstance.java | 4 +- .../armor/CopperBacktankInstance.java | 4 +- .../armor/CopperBacktankTileEntity.java | 4 +- .../symmetry/mirror/CrossPlaneMirror.java | 2 +- .../symmetry/mirror/EmptyMirror.java | 2 +- .../symmetry/mirror/PlaneMirror.java | 2 +- .../symmetry/mirror/SymmetryMirror.java | 2 +- .../symmetry/mirror/TriplePlaneMirror.java | 2 +- .../tools/ExtendoGripRenderHandler.java | 2 +- .../content/logistics/block/FlapData.java | 6 +- .../belts/tunnel/BeltTunnelInstance.java | 4 +- .../belts/tunnel/BeltTunnelTileEntity.java | 2 +- .../block/depot/EjectorInstance.java | 2 +- .../block/depot/EjectorTileEntity.java | 2 +- .../diodes/AdjustableRepeaterInstance.java | 2 +- .../block/funnel/FunnelInstance.java | 6 +- .../block/funnel/FunnelRenderer.java | 2 +- .../block/funnel/FunnelTileEntity.java | 2 +- .../block/mechanicalArm/ArmInstance.java | 8 +-- .../mechanicalArm/ArmInteractionPoint.java | 2 +- .../block/mechanicalArm/ArmTileEntity.java | 2 +- .../block/redstone/AnalogLeverInstance.java | 2 +- .../block/SchematicannonInstance.java | 2 +- .../block/SchematicannonTileEntity.java | 2 +- .../simibubi/create/events/ClientEvents.java | 4 +- .../data/CreateTileEntityBuilder.java | 2 +- .../create/foundation/gui/GuiGameElement.java | 2 +- .../flywheel/CancelTileEntityRenderMixin.java | 2 +- .../mixin/flywheel/FogColorTrackerMixin.java | 2 +- .../mixin/flywheel/TileWorldHookMixin.java | 4 +- .../flywheel/light/LightUpdateMixin.java | 2 +- .../light/NetworkLightUpdateMixin.java | 2 +- .../foundation/render/AllMaterialSpecs.java | 4 +- .../create/foundation/render/Compartment.java | 2 +- .../foundation/render/PartialBufferer.java | 2 +- .../render/SuperByteBufferCache.java | 2 +- .../render/effects/EffectsContext.java | 4 +- .../render/effects/EffectsHandler.java | 2 +- .../render/effects/SphereFilterProgram.java | 2 +- .../PlacementSimulationWorld.java | 2 +- 196 files changed, 659 insertions(+), 602 deletions(-) rename src/main/java/com/jozufozu/flywheel/backend/{instancing => }/IFlywheelWorld.java (61%) delete mode 100644 src/main/java/com/jozufozu/flywheel/backend/core/FirstNonnullMultiProgram.java delete mode 100644 src/main/java/com/jozufozu/flywheel/backend/core/IndexedModel.java delete mode 100644 src/main/java/com/jozufozu/flywheel/backend/core/shader/ShaderCallback.java rename src/main/java/com/jozufozu/flywheel/backend/gl/{GlPrimitiveType.java => GlNumericType.java} (63%) create mode 100644 src/main/java/com/jozufozu/flywheel/backend/gl/GlPrimitive.java create mode 100644 src/main/java/com/jozufozu/flywheel/backend/instancing/IInstanceFactory.java delete mode 100644 src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceFactory.java rename src/main/java/com/jozufozu/flywheel/backend/instancing/{InstancedModel.java => Instancer.java} (92%) delete mode 100644 src/main/java/com/jozufozu/flywheel/backend/light/CoordinateConsumer.java rename src/main/java/com/jozufozu/flywheel/backend/loading/{ProcessingStage.java => IProcessingStage.java} (73%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/BufferedArrayModel.java (76%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/BufferedModel.java (64%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/CrumblingProgram.java (77%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/CrumblingRenderer.java (75%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/FullscreenQuad.java (86%) create mode 100644 src/main/java/com/jozufozu/flywheel/core/IndexedModel.java rename src/main/java/com/jozufozu/flywheel/{backend => }/core/PartialModel.java (97%) rename src/main/java/com/jozufozu/flywheel/{backend/core/context => core}/WorldContext.java (90%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/WorldTileRenderer.java (87%) rename src/main/java/com/jozufozu/flywheel/{backend/instancing/util => core/instancing}/ConditionalInstance.java (80%) rename src/main/java/com/jozufozu/flywheel/{backend/instancing/util/InstanceGroup.java => core/instancing/GroupInstance.java} (80%) rename src/main/java/com/jozufozu/flywheel/{backend/instancing/util => core/instancing}/SelectInstance.java (82%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/materials/BasicData.java (90%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/materials/IFlatLight.java (94%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/materials/ModelData.java (77%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/materials/OrientedData.java (92%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/shader/ExtensibleGlProgram.java (91%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/shader/FogMode.java (91%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/shader/GlFog.java (95%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/shader/IMultiProgram.java (91%) create mode 100644 src/main/java/com/jozufozu/flywheel/core/shader/IProgramCallback.java rename src/main/java/com/jozufozu/flywheel/{backend => }/core/shader/StateSensitiveMultiProgram.java (83%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/shader/WorldFog.java (76%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/shader/WorldProgram.java (91%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/shader/extension/IExtensionInstance.java (83%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/shader/extension/IProgramExtension.java (85%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/shader/extension/UnitExtensionInstance.java (88%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/shader/gamestate/FogStateProvider.java (79%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/shader/gamestate/IGameStateProvider.java (69%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/shader/gamestate/NormalDebugStateProvider.java (78%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/shader/gamestate/RainbowDebugStateProvider.java (81%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/shader/spec/BooleanContextCondition.java (86%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/shader/spec/IBooleanStateProvider.java (53%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/shader/spec/IContextCondition.java (55%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/shader/spec/ProgramSpec.java (96%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/shader/spec/ProgramState.java (93%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/shader/spec/SpecMetaRegistry.java (78%) rename src/main/java/com/jozufozu/flywheel/{backend => }/core/shader/spec/SpecificValueCondition.java (88%) rename src/main/java/com/jozufozu/flywheel/{backend => }/light/GridAlignedBB.java (98%) create mode 100644 src/main/java/com/jozufozu/flywheel/light/ICoordinateConsumer.java rename src/main/java/com/jozufozu/flywheel/{backend/light/LightUpdateListener.java => light/ILightUpdateListener.java} (92%) rename src/main/java/com/jozufozu/flywheel/{backend => }/light/LightUpdater.java (75%) rename src/main/java/com/jozufozu/flywheel/{backend => }/light/LightVolume.java (99%) diff --git a/src/main/java/com/jozufozu/flywheel/backend/Backend.java b/src/main/java/com/jozufozu/flywheel/backend/Backend.java index 73fb81cad..5e577a590 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/Backend.java +++ b/src/main/java/com/jozufozu/flywheel/backend/Backend.java @@ -20,16 +20,15 @@ import org.apache.logging.log4j.Logger; import org.lwjgl.opengl.GL; import org.lwjgl.opengl.GLCapabilities; -import com.jozufozu.flywheel.backend.core.CrumblingRenderer; -import com.jozufozu.flywheel.backend.core.WorldTileRenderer; -import com.jozufozu.flywheel.backend.core.context.WorldContext; -import com.jozufozu.flywheel.backend.core.shader.WorldProgram; -import com.jozufozu.flywheel.backend.core.shader.spec.ProgramSpec; import com.jozufozu.flywheel.backend.gl.shader.GlProgram; import com.jozufozu.flywheel.backend.gl.versioned.GlCompat; -import com.jozufozu.flywheel.backend.instancing.IFlywheelWorld; import com.jozufozu.flywheel.backend.instancing.InstanceData; import com.jozufozu.flywheel.backend.instancing.MaterialSpec; +import com.jozufozu.flywheel.core.CrumblingRenderer; +import com.jozufozu.flywheel.core.WorldContext; +import com.jozufozu.flywheel.core.WorldTileRenderer; +import com.jozufozu.flywheel.core.shader.WorldProgram; +import com.jozufozu.flywheel.core.shader.spec.ProgramSpec; import com.jozufozu.flywheel.util.WorldAttached; import com.simibubi.create.foundation.config.AllConfigs; @@ -141,8 +140,11 @@ public class Backend { return programSpecRegistry.get(name); } + /** + * Used to avoid calling Flywheel functions on (fake) worlds that don't specifically support it. + */ public static boolean isFlywheelWorld(World world) { - return world == Minecraft.getInstance().world || (world instanceof IFlywheelWorld && ((IFlywheelWorld) world).supportsFlywheel()); + return (world instanceof IFlywheelWorld && ((IFlywheelWorld) world).supportsFlywheel()) || world == Minecraft.getInstance().world; } public static boolean available() { diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/IFlywheelWorld.java b/src/main/java/com/jozufozu/flywheel/backend/IFlywheelWorld.java similarity index 61% rename from src/main/java/com/jozufozu/flywheel/backend/instancing/IFlywheelWorld.java rename to src/main/java/com/jozufozu/flywheel/backend/IFlywheelWorld.java index 5a138fefc..52f1712ed 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/IFlywheelWorld.java +++ b/src/main/java/com/jozufozu/flywheel/backend/IFlywheelWorld.java @@ -1,10 +1,10 @@ -package com.jozufozu.flywheel.backend.instancing; +package com.jozufozu.flywheel.backend; /** * A marker interface custom worlds can override to indicate * that tiles inside the world should render with Flywheel. * - * Minecraft.getInstance().world will always support Flywheel. + * Minecraft.getInstance().world is special cased and will support Flywheel by default. */ public interface IFlywheelWorld { default boolean supportsFlywheel() { diff --git a/src/main/java/com/jozufozu/flywheel/backend/ShaderContext.java b/src/main/java/com/jozufozu/flywheel/backend/ShaderContext.java index 0a86e017a..e93aeae41 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/ShaderContext.java +++ b/src/main/java/com/jozufozu/flywheel/backend/ShaderContext.java @@ -4,13 +4,13 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; -import com.jozufozu.flywheel.backend.core.shader.IMultiProgram; -import com.jozufozu.flywheel.backend.core.shader.spec.ProgramSpec; import com.jozufozu.flywheel.backend.gl.shader.GlProgram; import com.jozufozu.flywheel.backend.gl.shader.ShaderType; import com.jozufozu.flywheel.backend.loading.Program; import com.jozufozu.flywheel.backend.loading.Shader; import com.jozufozu.flywheel.backend.loading.ShaderTransformer; +import com.jozufozu.flywheel.core.shader.IMultiProgram; +import com.jozufozu.flywheel.core.shader.spec.ProgramSpec; import net.minecraft.util.ResourceLocation; diff --git a/src/main/java/com/jozufozu/flywheel/backend/ShaderLoader.java b/src/main/java/com/jozufozu/flywheel/backend/ShaderLoader.java index 848b5943c..068c8ecb1 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/ShaderLoader.java +++ b/src/main/java/com/jozufozu/flywheel/backend/ShaderLoader.java @@ -30,14 +30,14 @@ import com.google.common.collect.Lists; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; -import com.jozufozu.flywheel.backend.core.shader.spec.ProgramSpec; -import com.jozufozu.flywheel.backend.core.shader.spec.SpecMetaRegistry; import com.jozufozu.flywheel.backend.gl.GlObject; import com.jozufozu.flywheel.backend.gl.shader.GlShader; import com.jozufozu.flywheel.backend.gl.shader.ShaderType; import com.jozufozu.flywheel.backend.loading.Program; import com.jozufozu.flywheel.backend.loading.Shader; import com.jozufozu.flywheel.backend.loading.ShaderLoadingException; +import com.jozufozu.flywheel.core.shader.spec.ProgramSpec; +import com.jozufozu.flywheel.core.shader.spec.SpecMetaRegistry; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.datafixers.util.Pair; import com.mojang.serialization.DataResult; diff --git a/src/main/java/com/jozufozu/flywheel/backend/core/FirstNonnullMultiProgram.java b/src/main/java/com/jozufozu/flywheel/backend/core/FirstNonnullMultiProgram.java deleted file mode 100644 index 1e7b441dd..000000000 --- a/src/main/java/com/jozufozu/flywheel/backend/core/FirstNonnullMultiProgram.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.jozufozu.flywheel.backend.core; - -import com.jozufozu.flywheel.backend.gl.shader.GlProgram; - -public class FirstNonnullMultiProgram

{ -} diff --git a/src/main/java/com/jozufozu/flywheel/backend/core/IndexedModel.java b/src/main/java/com/jozufozu/flywheel/backend/core/IndexedModel.java deleted file mode 100644 index cb76197d7..000000000 --- a/src/main/java/com/jozufozu/flywheel/backend/core/IndexedModel.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.jozufozu.flywheel.backend.core; - -import java.nio.ByteBuffer; - -import org.lwjgl.opengl.GL20; - -import com.jozufozu.flywheel.backend.gl.GlPrimitiveType; -import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; -import com.jozufozu.flywheel.backend.gl.buffer.GlBuffer; -import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType; -import com.jozufozu.flywheel.util.AttribUtil; - -public class IndexedModel extends BufferedModel { - - protected GlPrimitiveType eboIndexType; - protected GlBuffer ebo; - - public IndexedModel(VertexFormat modelFormat, ByteBuffer buf, int vertices, ByteBuffer indices, GlPrimitiveType indexType) { - super(modelFormat, buf, vertices); - - ebo = new GlBuffer(GlBufferType.ELEMENT_ARRAY_BUFFER); - this.eboIndexType = indexType; - - int indicesSize = vertexCount * indexType.getSize(); - - ebo.bind(); - - ebo.alloc(indicesSize); - ebo.getBuffer(0, indicesSize) - .put(indices) - .flush(); - - ebo.unbind(); - } - - public void render() { - vbo.bind(); - ebo.bind(); - - AttribUtil.enableArrays(getAttributeCount()); - format.vertexAttribPointers(0); - - GL20.glDrawElements(GL20.GL_QUADS, vertexCount, eboIndexType.getGlConstant(), 0); - - AttribUtil.disableArrays(getAttributeCount()); - - ebo.unbind(); - vbo.unbind(); - } - - @Override - public void delete() { - super.delete(); - ebo.delete(); - } -} diff --git a/src/main/java/com/jozufozu/flywheel/backend/core/shader/ShaderCallback.java b/src/main/java/com/jozufozu/flywheel/backend/core/shader/ShaderCallback.java deleted file mode 100644 index 2bf2f5440..000000000 --- a/src/main/java/com/jozufozu/flywheel/backend/core/shader/ShaderCallback.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.jozufozu.flywheel.backend.core.shader; - -import com.jozufozu.flywheel.backend.gl.shader.GlProgram; - -/** - * A Callback for when a shader is called. Used to define shader uniforms. - */ -@FunctionalInterface -public interface ShaderCallback

{ - - void call(P program); - - default ShaderCallback

andThen(ShaderCallback

other) { - return program -> { - call(program); - other.call(program); - }; - } -} diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/GlPrimitiveType.java b/src/main/java/com/jozufozu/flywheel/backend/gl/GlNumericType.java similarity index 63% rename from src/main/java/com/jozufozu/flywheel/backend/gl/GlPrimitiveType.java rename to src/main/java/com/jozufozu/flywheel/backend/gl/GlNumericType.java index 1737c6bd4..7a39b34b6 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/GlPrimitiveType.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/GlNumericType.java @@ -13,27 +13,28 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @OnlyIn(Dist.CLIENT) -public enum GlPrimitiveType { +public enum GlNumericType { FLOAT(4, "float", GL11.GL_FLOAT), UBYTE(1, "ubyte", GL11.GL_UNSIGNED_BYTE), BYTE(1, "byte", GL11.GL_BYTE), USHORT(2, "ushort", GL11.GL_UNSIGNED_SHORT), SHORT(2, "short", GL11.GL_SHORT), UINT(4, "uint", GL11.GL_UNSIGNED_INT), - INT(4, "int", GL11.GL_INT); + INT(4, "int", GL11.GL_INT), + ; - private static final GlPrimitiveType[] VALUES = values(); - private static final Map NAME_LOOKUP = Arrays.stream(VALUES) - .collect(Collectors.toMap(GlPrimitiveType::getDisplayName, type -> type)); + private static final GlNumericType[] VALUES = values(); + private static final Map NAME_LOOKUP = Arrays.stream(VALUES) + .collect(Collectors.toMap(GlNumericType::getDisplayName, type -> type)); private final int size; private final String displayName; - private final int glConstant; + private final int glEnum; - GlPrimitiveType(int bytes, String name, int glEnum) { + GlNumericType(int bytes, String name, int glEnum) { this.size = bytes; this.displayName = name; - this.glConstant = glEnum; + this.glEnum = glEnum; } public int getSize() { @@ -44,12 +45,12 @@ public enum GlPrimitiveType { return this.displayName; } - public int getGlConstant() { - return this.glConstant; + public int getGlEnum() { + return this.glEnum; } @Nullable - public static GlPrimitiveType byName(String name) { + public static GlNumericType byName(String name) { return name == null ? null : NAME_LOOKUP.get(name.toLowerCase(Locale.ROOT)); } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/GlPrimitive.java b/src/main/java/com/jozufozu/flywheel/backend/gl/GlPrimitive.java new file mode 100644 index 000000000..71a8d5353 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/GlPrimitive.java @@ -0,0 +1,23 @@ +package com.jozufozu.flywheel.backend.gl; + +import org.lwjgl.opengl.GL11; + +public enum GlPrimitive { + POINTS(GL11.GL_POINTS), + LINES(GL11.GL_LINES), + LINE_LOOP(GL11.GL_LINE_LOOP), + LINE_STRIP(GL11.GL_LINE_STRIP), + TRIANGLES(GL11.GL_TRIANGLES), + TRIANGLE_STRIP(GL11.GL_TRIANGLE_STRIP), + TRIANGLE_FAN(GL11.GL_TRIANGLE_FAN), + QUADS(GL11.GL_QUADS), + QUAD_STRIP(GL11.GL_QUAD_STRIP), + POLYGON(GL11.GL_POLYGON), + ; + + public final int glEnum; + + GlPrimitive(int glEnum) { + this.glEnum = glEnum; + } +} diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/attrib/CommonAttributes.java b/src/main/java/com/jozufozu/flywheel/backend/gl/attrib/CommonAttributes.java index 99f754efe..a1726fae0 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/attrib/CommonAttributes.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/attrib/CommonAttributes.java @@ -1,21 +1,21 @@ package com.jozufozu.flywheel.backend.gl.attrib; -import com.jozufozu.flywheel.backend.gl.GlPrimitiveType; +import com.jozufozu.flywheel.backend.gl.GlNumericType; public class CommonAttributes { - public static final VertexAttribSpec VEC4 = new VertexAttribSpec(GlPrimitiveType.FLOAT, 4); - public static final VertexAttribSpec VEC3 = new VertexAttribSpec(GlPrimitiveType.FLOAT, 3); - public static final VertexAttribSpec VEC2 = new VertexAttribSpec(GlPrimitiveType.FLOAT, 2); - public static final VertexAttribSpec FLOAT = new VertexAttribSpec(GlPrimitiveType.FLOAT, 1); + public static final VertexAttribSpec VEC4 = new VertexAttribSpec(GlNumericType.FLOAT, 4); + public static final VertexAttribSpec VEC3 = new VertexAttribSpec(GlNumericType.FLOAT, 3); + public static final VertexAttribSpec VEC2 = new VertexAttribSpec(GlNumericType.FLOAT, 2); + public static final VertexAttribSpec FLOAT = new VertexAttribSpec(GlNumericType.FLOAT, 1); - public static final VertexAttribSpec QUATERNION = new VertexAttribSpec(GlPrimitiveType.FLOAT, 4); - public static final VertexAttribSpec NORMAL = new VertexAttribSpec(GlPrimitiveType.BYTE, 3, true); - public static final VertexAttribSpec UV = new VertexAttribSpec(GlPrimitiveType.FLOAT, 2); + public static final VertexAttribSpec QUATERNION = new VertexAttribSpec(GlNumericType.FLOAT, 4); + public static final VertexAttribSpec NORMAL = new VertexAttribSpec(GlNumericType.BYTE, 3, true); + public static final VertexAttribSpec UV = new VertexAttribSpec(GlNumericType.FLOAT, 2); - public static final VertexAttribSpec RGBA = new VertexAttribSpec(GlPrimitiveType.UBYTE, 4, true); - public static final VertexAttribSpec RGB = new VertexAttribSpec(GlPrimitiveType.UBYTE, 3, true); - public static final VertexAttribSpec LIGHT = new VertexAttribSpec(GlPrimitiveType.UBYTE, 2, true); + public static final VertexAttribSpec RGBA = new VertexAttribSpec(GlNumericType.UBYTE, 4, true); + public static final VertexAttribSpec RGB = new VertexAttribSpec(GlNumericType.UBYTE, 3, true); + public static final VertexAttribSpec LIGHT = new VertexAttribSpec(GlNumericType.UBYTE, 2, true); - public static final VertexAttribSpec NORMALIZED_BYTE = new VertexAttribSpec(GlPrimitiveType.BYTE, 1, true); + public static final VertexAttribSpec NORMALIZED_BYTE = new VertexAttribSpec(GlNumericType.BYTE, 1, true); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/attrib/MatrixAttributes.java b/src/main/java/com/jozufozu/flywheel/backend/gl/attrib/MatrixAttributes.java index 86cf089aa..49b6731fe 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/attrib/MatrixAttributes.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/attrib/MatrixAttributes.java @@ -2,7 +2,7 @@ package com.jozufozu.flywheel.backend.gl.attrib; import org.lwjgl.opengl.GL20; -import com.jozufozu.flywheel.backend.gl.GlPrimitiveType; +import com.jozufozu.flywheel.backend.gl.GlNumericType; public enum MatrixAttributes implements IAttribSpec { MAT3(3, 3), @@ -20,14 +20,14 @@ public enum MatrixAttributes implements IAttribSpec { @Override public void vertexAttribPointer(int stride, int index, int pointer) { for (int i = 0; i < rows; i++) { - long attribPointer = pointer + (long) i * cols * GlPrimitiveType.FLOAT.getSize(); - GL20.glVertexAttribPointer(index + i, cols, GlPrimitiveType.FLOAT.getGlConstant(), false, stride, attribPointer); + long attribPointer = pointer + (long) i * cols * GlNumericType.FLOAT.getSize(); + GL20.glVertexAttribPointer(index + i, cols, GlNumericType.FLOAT.getGlEnum(), false, stride, attribPointer); } } @Override public int getSize() { - return GlPrimitiveType.FLOAT.getSize() * rows * cols; + return GlNumericType.FLOAT.getSize() * rows * cols; } @Override diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/attrib/VertexAttribSpec.java b/src/main/java/com/jozufozu/flywheel/backend/gl/attrib/VertexAttribSpec.java index 7717114ab..663ad8342 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/attrib/VertexAttribSpec.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/attrib/VertexAttribSpec.java @@ -2,21 +2,21 @@ package com.jozufozu.flywheel.backend.gl.attrib; import org.lwjgl.opengl.GL20; -import com.jozufozu.flywheel.backend.gl.GlPrimitiveType; +import com.jozufozu.flywheel.backend.gl.GlNumericType; public class VertexAttribSpec implements IAttribSpec { - private final GlPrimitiveType type; + private final GlNumericType type; private final int count; private final int size; private final int attributeCount; private final boolean normalized; - public VertexAttribSpec(GlPrimitiveType type, int count) { + public VertexAttribSpec(GlNumericType type, int count) { this(type, count, false); } - public VertexAttribSpec(GlPrimitiveType type, int count, boolean normalized) { + public VertexAttribSpec(GlNumericType type, int count, boolean normalized) { this.type = type; this.count = count; this.size = type.getSize() * count; @@ -26,7 +26,7 @@ public class VertexAttribSpec implements IAttribSpec { @Override public void vertexAttribPointer(int stride, int index, int pointer) { - GL20.glVertexAttribPointer(index, count, type.getGlConstant(), normalized, stride, pointer); + GL20.glVertexAttribPointer(index, count, type.getGlEnum(), normalized, stride, pointer); } @Override diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/versioned/instancing/DrawInstanced.java b/src/main/java/com/jozufozu/flywheel/backend/gl/versioned/instancing/DrawInstanced.java index e30ba9bfc..c2d73e0c4 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/versioned/instancing/DrawInstanced.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/versioned/instancing/DrawInstanced.java @@ -5,6 +5,8 @@ import org.lwjgl.opengl.EXTDrawInstanced; import org.lwjgl.opengl.GL31; import org.lwjgl.opengl.GLCapabilities; +import com.jozufozu.flywheel.backend.gl.GlNumericType; +import com.jozufozu.flywheel.backend.gl.GlPrimitive; import com.jozufozu.flywheel.backend.gl.versioned.GlVersioned; public enum DrawInstanced implements GlVersioned { @@ -15,8 +17,13 @@ public enum DrawInstanced implements GlVersioned { } @Override - public void drawArraysInstanced(int mode, int first, int count, int primcount) { - GL31.glDrawArraysInstanced(mode, first, count, primcount); + public void drawArraysInstanced(GlPrimitive mode, int first, int count, int primcount) { + GL31.glDrawArraysInstanced(mode.glEnum, first, count, primcount); + } + + @Override + public void drawElementsInstanced(GlPrimitive mode, int elementCount, GlNumericType type, long indices, int primcount) { + GL31.glDrawElementsInstanced(mode.glEnum, elementCount, type.getGlEnum(), indices, primcount); } }, ARB_DRAW_INSTANCED { @@ -26,8 +33,13 @@ public enum DrawInstanced implements GlVersioned { } @Override - public void drawArraysInstanced(int mode, int first, int count, int primcount) { - ARBDrawInstanced.glDrawArraysInstancedARB(mode, first, count, primcount); + public void drawArraysInstanced(GlPrimitive mode, int first, int count, int primcount) { + ARBDrawInstanced.glDrawArraysInstancedARB(mode.glEnum, first, count, primcount); + } + + @Override + public void drawElementsInstanced(GlPrimitive mode, int elementCount, GlNumericType type, long indices, int primcount) { + ARBDrawInstanced.glDrawElementsInstancedARB(mode.glEnum, elementCount, type.getGlEnum(), indices, primcount); } }, EXT_DRAW_INSTANCED { @@ -37,8 +49,13 @@ public enum DrawInstanced implements GlVersioned { } @Override - public void drawArraysInstanced(int mode, int first, int count, int primcount) { - EXTDrawInstanced.glDrawArraysInstancedEXT(mode, first, count, primcount); + public void drawArraysInstanced(GlPrimitive mode, int first, int count, int primcount) { + EXTDrawInstanced.glDrawArraysInstancedEXT(mode.glEnum, first, count, primcount); + } + + @Override + public void drawElementsInstanced(GlPrimitive mode, int elementCount, GlNumericType type, long indices, int primcount) { + EXTDrawInstanced.glDrawElementsInstancedEXT(mode.glEnum, elementCount, type.getGlEnum(), indices, primcount); } }, UNSUPPORTED { @@ -46,12 +63,14 @@ public enum DrawInstanced implements GlVersioned { public boolean supported(GLCapabilities caps) { return true; } - - @Override - public void drawArraysInstanced(int mode, int first, int count, int primcount) { - throw new UnsupportedOperationException(); - } }; - public abstract void drawArraysInstanced(int mode, int first, int count, int primcount); + + public void drawArraysInstanced(GlPrimitive mode, int first, int count, int primcount) { + throw new UnsupportedOperationException(); + } + + public void drawElementsInstanced(GlPrimitive mode, int elementCount, GlNumericType type, long indices, int primcount) { + throw new UnsupportedOperationException(); + } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstance.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstance.java index 32bab42ab..8030ef77d 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstance.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstance.java @@ -3,9 +3,8 @@ package com.jozufozu.flywheel.backend.instancing; import net.minecraft.util.math.BlockPos; /** - * A general interface providing information about any type of thing that could use - * Flywheel's instanced rendering. Right now, that's only {@link InstancedTileRenderer}, - * but there could be an entity equivalent in the future. + * A general interface providing information about any type of thing that could use Flywheel's instanced rendering. + * Right now, that's only {@link InstancedTileRenderer}, but there could be an entity equivalent in the future. */ public interface IInstance { diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstanceFactory.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstanceFactory.java new file mode 100644 index 000000000..f2364392c --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstanceFactory.java @@ -0,0 +1,5 @@ +package com.jozufozu.flywheel.backend.instancing; + +public interface IInstanceFactory { + D create(Instancer owner); +} diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstanceRendered.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstanceRendered.java index b9494058c..bf5382e34 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstanceRendered.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstanceRendered.java @@ -1,7 +1,14 @@ package com.jozufozu.flywheel.backend.instancing; +/** + * Something (a TileEntity or Entity) that can be rendered using the instancing API. + */ public interface IInstanceRendered { - default boolean shouldRenderAsTE() { + + /** + * @return true if there are parts of the renderer that cannot be implemented with Flywheel. + */ + default boolean shouldRenderNormally() { return false; } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/ITickableInstance.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/ITickableInstance.java index e660195c1..846ad7d8e 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/ITickableInstance.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/ITickableInstance.java @@ -8,7 +8,7 @@ package com.jozufozu.flywheel.backend.instancing; *