mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-28 16:06:28 +01:00
Revert "Rename/refactor many interfaces"
This reverts commit 66aa987dbd
.
Can re-think the names later.
This commit is contained in:
parent
66aa987dbd
commit
762e526a27
53 changed files with 178 additions and 154 deletions
|
@ -42,7 +42,7 @@ public class Backend {
|
|||
private boolean enabled;
|
||||
public boolean chunkCachingEnabled;
|
||||
|
||||
private final List<ShaderContext<?>> contexts = new ArrayList<>();
|
||||
private final List<IShaderContext<?>> contexts = new ArrayList<>();
|
||||
private final Map<ResourceLocation, MaterialSpec<?>> materialRegistry = new HashMap<>();
|
||||
private final Map<ResourceLocation, ProgramSpec> programSpecRegistry = new HashMap<>();
|
||||
|
||||
|
@ -83,7 +83,7 @@ public class Backend {
|
|||
/**
|
||||
* Register a shader context.
|
||||
*/
|
||||
public <C extends ShaderContext<?>> C register(C spec) {
|
||||
public <C extends IShaderContext<?>> C register(C spec) {
|
||||
contexts.add(spec);
|
||||
return spec;
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ public class Backend {
|
|||
return programSpecRegistry.values();
|
||||
}
|
||||
|
||||
public Collection<ShaderContext<?>> allContexts() {
|
||||
public Collection<IShaderContext<?>> allContexts() {
|
||||
return contexts;
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,7 @@ public class Backend {
|
|||
public static boolean isFlywheelWorld(@Nullable LevelAccessor world) {
|
||||
if (world == null) return false;
|
||||
|
||||
if (world instanceof FlywheelWorld && ((FlywheelWorld) world).supportsFlywheel()) return true;
|
||||
if (world instanceof IFlywheelWorld && ((IFlywheelWorld) world).supportsFlywheel()) return true;
|
||||
|
||||
return world == Minecraft.getInstance().level;
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ public class Backend {
|
|||
public void _clearContexts() {
|
||||
SpecMetaRegistry.clear();
|
||||
programSpecRegistry.clear();
|
||||
contexts.forEach(ShaderContext::delete);
|
||||
contexts.forEach(IShaderContext::delete);
|
||||
contexts.clear();
|
||||
materialRegistry.clear();
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ package com.jozufozu.flywheel.backend;
|
|||
*
|
||||
* <code>Minecraft.getInstance().world</code> is special cased and will support Flywheel by default.
|
||||
*/
|
||||
public interface FlywheelWorld {
|
||||
public interface IFlywheelWorld {
|
||||
default boolean supportsFlywheel() {
|
||||
return true;
|
||||
}
|
|
@ -6,7 +6,7 @@ import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
|
|||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public interface ShaderContext<P extends GlProgram> {
|
||||
public interface IShaderContext<P extends GlProgram> {
|
||||
|
||||
default P getProgram(ResourceLocation loc) {
|
||||
return this.getProgramSupplier(loc)
|
|
@ -82,7 +82,7 @@ public class Loader implements ResourceManagerReloadListener {
|
|||
|
||||
Resolver.INSTANCE.resolve(sources);
|
||||
|
||||
for (ShaderContext<?> context : backend.allContexts()) {
|
||||
for (IShaderContext<?> context : backend.allContexts()) {
|
||||
context.load();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.jozufozu.flywheel.backend.gl.attrib;
|
||||
|
||||
public interface AttribSpec {
|
||||
public interface IAttribSpec {
|
||||
|
||||
void vertexAttribPointer(int stride, int index, int offset);
|
||||
|
|
@ -4,7 +4,7 @@ import org.lwjgl.opengl.GL20;
|
|||
|
||||
import com.jozufozu.flywheel.backend.gl.GlNumericType;
|
||||
|
||||
public enum MatrixAttributes implements AttribSpec {
|
||||
public enum MatrixAttributes implements IAttribSpec {
|
||||
MAT3(3, 3),
|
||||
MAT4(4, 4),
|
||||
;
|
||||
|
|
|
@ -4,7 +4,7 @@ import org.lwjgl.opengl.GL20;
|
|||
|
||||
import com.jozufozu.flywheel.backend.gl.GlNumericType;
|
||||
|
||||
public class VertexAttribSpec implements AttribSpec {
|
||||
public class VertexAttribSpec implements IAttribSpec {
|
||||
|
||||
private final GlNumericType type;
|
||||
private final int count;
|
||||
|
|
|
@ -5,16 +5,16 @@ import java.util.Collections;
|
|||
|
||||
public class VertexFormat {
|
||||
|
||||
private final ArrayList<AttribSpec> allAttributes;
|
||||
private final ArrayList<IAttribSpec> allAttributes;
|
||||
|
||||
private final int numAttributes;
|
||||
private final int stride;
|
||||
|
||||
public VertexFormat(ArrayList<AttribSpec> allAttributes) {
|
||||
public VertexFormat(ArrayList<IAttribSpec> allAttributes) {
|
||||
this.allAttributes = allAttributes;
|
||||
|
||||
int numAttributes = 0, stride = 0;
|
||||
for (AttribSpec spec : allAttributes) {
|
||||
for (IAttribSpec spec : allAttributes) {
|
||||
numAttributes += spec.getAttributeCount();
|
||||
stride += spec.getSize();
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public class VertexFormat {
|
|||
|
||||
public void vertexAttribPointers(int index) {
|
||||
int offset = 0;
|
||||
for (AttribSpec spec : this.allAttributes) {
|
||||
for (IAttribSpec spec : this.allAttributes) {
|
||||
spec.vertexAttribPointer(stride, index, offset);
|
||||
index += spec.getAttributeCount();
|
||||
offset += spec.getSize();
|
||||
|
@ -44,12 +44,12 @@ public class VertexFormat {
|
|||
}
|
||||
|
||||
public static class Builder {
|
||||
private final ArrayList<AttribSpec> allAttributes = new ArrayList<>();
|
||||
private final ArrayList<IAttribSpec> allAttributes = new ArrayList<>();
|
||||
|
||||
public Builder() {
|
||||
}
|
||||
|
||||
public Builder addAttributes(AttribSpec... attributes) {
|
||||
public Builder addAttributes(IAttribSpec... attributes) {
|
||||
Collections.addAll(allAttributes, attributes);
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import java.util.stream.Stream;
|
|||
|
||||
import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager;
|
||||
import com.jozufozu.flywheel.backend.material.MaterialManager;
|
||||
import com.jozufozu.flywheel.core.materials.FlatLight;
|
||||
import com.jozufozu.flywheel.core.materials.IFlatLight;
|
||||
import com.jozufozu.flywheel.light.ILightUpdateListener;
|
||||
import com.jozufozu.flywheel.light.ImmutableBox;
|
||||
import com.jozufozu.flywheel.light.LightProvider;
|
||||
|
@ -19,7 +19,7 @@ import net.minecraft.world.level.Level;
|
|||
* A general interface providing information about any type of thing that could use Flywheel's instanced rendering.
|
||||
* Right now, that's only {@link TileInstanceManager}, but there could be an entity equivalent in the future.
|
||||
*/
|
||||
public abstract class AbstractInstance implements Instance, ILightUpdateListener {
|
||||
public abstract class AbstractInstance implements IInstance, ILightUpdateListener {
|
||||
|
||||
protected final MaterialManager materialManager;
|
||||
public final Level world;
|
||||
|
@ -38,7 +38,7 @@ public abstract class AbstractInstance implements Instance, ILightUpdateListener
|
|||
* Update instance data here. Good for when data doesn't change very often and when animations are GPU based.
|
||||
* Don't query lighting data here, that's handled separately in {@link #updateLight()}.
|
||||
*
|
||||
* <br><br> If your animations are complex or more CPU driven, see {@link DynamicInstance} or {@link TickableInstance}.
|
||||
* <br><br> If your animations are complex or more CPU driven, see {@link IDynamicInstance} or {@link ITickableInstance}.
|
||||
*/
|
||||
public void update() {
|
||||
}
|
||||
|
@ -77,19 +77,19 @@ public abstract class AbstractInstance implements Instance, ILightUpdateListener
|
|||
updateLight();
|
||||
}
|
||||
|
||||
protected void relight(BlockPos pos, FlatLight... models) {
|
||||
protected void relight(BlockPos pos, IFlatLight<?>... models) {
|
||||
relight(world.getBrightness(LightLayer.BLOCK, pos), world.getBrightness(LightLayer.SKY, pos), models);
|
||||
}
|
||||
|
||||
protected <L extends FlatLight> void relight(BlockPos pos, Stream<L> models) {
|
||||
protected <L extends IFlatLight<?>> void relight(BlockPos pos, Stream<L> models) {
|
||||
relight(world.getBrightness(LightLayer.BLOCK, pos), world.getBrightness(LightLayer.SKY, pos), models);
|
||||
}
|
||||
|
||||
protected void relight(int block, int sky, FlatLight... models) {
|
||||
protected void relight(int block, int sky, IFlatLight<?>... models) {
|
||||
relight(block, sky, Arrays.stream(models));
|
||||
}
|
||||
|
||||
protected <L extends FlatLight> void relight(int block, int sky, Stream<L> models) {
|
||||
protected <L extends IFlatLight<?>> void relight(int block, int sky, Stream<L> models) {
|
||||
models.forEach(model -> model.setBlockLight(block)
|
||||
.setSkyLight(sky));
|
||||
}
|
||||
|
|
|
@ -13,13 +13,13 @@ import com.jozufozu.flywheel.backend.model.IBufferedModel;
|
|||
import com.jozufozu.flywheel.backend.model.ModelAllocator;
|
||||
import com.jozufozu.flywheel.backend.struct.StructType;
|
||||
import com.jozufozu.flywheel.backend.struct.StructWriter;
|
||||
import com.jozufozu.flywheel.core.model.Model;
|
||||
import com.jozufozu.flywheel.core.model.IModel;
|
||||
import com.jozufozu.flywheel.util.AttribUtil;
|
||||
|
||||
public class GPUInstancer<D extends InstanceData> implements Instancer<D> {
|
||||
|
||||
private final ModelAllocator modelAllocator;
|
||||
private final Model modelData;
|
||||
private final IModel modelData;
|
||||
private final VertexFormat instanceFormat;
|
||||
private final StructType<D> type;
|
||||
|
||||
|
@ -36,7 +36,7 @@ public class GPUInstancer<D extends InstanceData> implements Instancer<D> {
|
|||
boolean anyToRemove;
|
||||
boolean anyToUpdate;
|
||||
|
||||
public GPUInstancer(ModelAllocator modelAllocator, Model model, StructType<D> type) {
|
||||
public GPUInstancer(ModelAllocator modelAllocator, IModel model, StructType<D> type) {
|
||||
this.modelAllocator = modelAllocator;
|
||||
this.modelData = model;
|
||||
this.type = type;
|
||||
|
|
|
@ -4,14 +4,14 @@ import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
|
|||
|
||||
/**
|
||||
* An interface giving {@link TileEntityInstance}s a hook to have a function called at
|
||||
* the start of a frame. By implementing {@link DynamicInstance}, a {@link TileEntityInstance}
|
||||
* the start of a frame. By implementing {@link IDynamicInstance}, a {@link TileEntityInstance}
|
||||
* can animate its models in ways that could not be easily achieved by shader attribute
|
||||
* parameterization.
|
||||
*
|
||||
* <br><br> If your goal is offloading work to shaders, but you're unsure exactly how you need
|
||||
* to parameterize the instances, you're encouraged to implement this for prototyping.
|
||||
*/
|
||||
public interface DynamicInstance extends Instance {
|
||||
public interface IDynamicInstance extends IInstance {
|
||||
/**
|
||||
* Called every frame.
|
||||
* <br>
|
|
@ -2,6 +2,6 @@ package com.jozufozu.flywheel.backend.instancing;
|
|||
|
||||
import net.minecraft.core.BlockPos;
|
||||
|
||||
public interface Instance {
|
||||
public interface IInstance {
|
||||
BlockPos getWorldPosition();
|
||||
}
|
|
@ -1,9 +1,11 @@
|
|||
package com.jozufozu.flywheel.backend.instancing;
|
||||
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
/**
|
||||
* Something (a BlockEntity or Entity) that can be rendered using the instancing API.
|
||||
*/
|
||||
public interface InstanceRendered {
|
||||
public interface IInstanceRendered {
|
||||
|
||||
/**
|
||||
* @return true if there are parts of the renderer that cannot be implemented with Flywheel.
|
||||
|
@ -11,4 +13,6 @@ public interface InstanceRendered {
|
|||
default boolean shouldRenderNormally() {
|
||||
return false;
|
||||
}
|
||||
|
||||
Level getWorld();
|
||||
}
|
|
@ -4,9 +4,9 @@ import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
|
|||
|
||||
/**
|
||||
* An interface giving {@link TileEntityInstance}s a hook to have a function called at
|
||||
* the end of every tick. By implementing {@link TickableInstance}, a {@link TileEntityInstance}
|
||||
* the end of every tick. By implementing {@link ITickableInstance}, a {@link TileEntityInstance}
|
||||
* can update frequently, but not every frame.
|
||||
* <br> There are a few cases in which this should be considered over {@link DynamicInstance}:
|
||||
* <br> There are a few cases in which this should be considered over {@link IDynamicInstance}:
|
||||
* <ul>
|
||||
* <li>
|
||||
* You'd like to change something about the instance every now and then.
|
||||
|
@ -18,7 +18,7 @@ import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
|
|||
* </li>
|
||||
* </ul>
|
||||
*/
|
||||
public interface TickableInstance extends Instance {
|
||||
public interface ITickableInstance extends IInstance {
|
||||
|
||||
/**
|
||||
* Called every tick.
|
|
@ -27,8 +27,8 @@ public abstract class InstanceManager<T> implements MaterialManagerImpl.OriginSh
|
|||
private final Set<T> queuedUpdates;
|
||||
|
||||
protected final Map<T, AbstractInstance> instances;
|
||||
protected final Object2ObjectOpenHashMap<T, TickableInstance> tickableInstances;
|
||||
protected final Object2ObjectOpenHashMap<T, DynamicInstance> dynamicInstances;
|
||||
protected final Object2ObjectOpenHashMap<T, ITickableInstance> tickableInstances;
|
||||
protected final Object2ObjectOpenHashMap<T, IDynamicInstance> dynamicInstances;
|
||||
|
||||
protected int frame;
|
||||
protected int tick;
|
||||
|
@ -70,7 +70,7 @@ public abstract class InstanceManager<T> implements MaterialManagerImpl.OriginSh
|
|||
* Ticks the InstanceManager.
|
||||
*
|
||||
* <p>
|
||||
* {@link TickableInstance}s get ticked.
|
||||
* {@link ITickableInstance}s get ticked.
|
||||
* <br>
|
||||
* Queued updates are processed.
|
||||
* </p>
|
||||
|
@ -86,7 +86,7 @@ public abstract class InstanceManager<T> implements MaterialManagerImpl.OriginSh
|
|||
|
||||
if (tickableInstances.size() > 0) {
|
||||
tickableInstances.object2ObjectEntrySet().parallelStream().forEach(e -> {
|
||||
TickableInstance instance = e.getValue();
|
||||
ITickableInstance instance = e.getValue();
|
||||
if (!instance.decreaseTickRateWithDistance()) {
|
||||
instance.tick();
|
||||
return;
|
||||
|
@ -121,7 +121,7 @@ public abstract class InstanceManager<T> implements MaterialManagerImpl.OriginSh
|
|||
dynamicInstances.object2ObjectEntrySet()
|
||||
.parallelStream()
|
||||
.forEach(e -> {
|
||||
DynamicInstance dyn = e.getValue();
|
||||
IDynamicInstance dyn = e.getValue();
|
||||
if (!dyn.decreaseFramerateWithDistance() || shouldFrameUpdate(dyn.getWorldPosition(), lookX, lookY, lookZ, cX, cY, cZ))
|
||||
dyn.beginFrame();
|
||||
});
|
||||
|
@ -159,8 +159,8 @@ public abstract class InstanceManager<T> implements MaterialManagerImpl.OriginSh
|
|||
*
|
||||
* <p>
|
||||
* By default this is the only hook an IInstance has to change its internal state. This is the lowest frequency
|
||||
* update hook IInstance gets. For more frequent updates, see {@link TickableInstance} and
|
||||
* {@link DynamicInstance}.
|
||||
* update hook IInstance gets. For more frequent updates, see {@link ITickableInstance} and
|
||||
* {@link IDynamicInstance}.
|
||||
* </p>
|
||||
*
|
||||
* @param obj the object to update.
|
||||
|
@ -291,9 +291,9 @@ public abstract class InstanceManager<T> implements MaterialManagerImpl.OriginSh
|
|||
.addListener(renderer);
|
||||
instances.put(obj, renderer);
|
||||
|
||||
if (renderer instanceof DynamicInstance) dynamicInstances.put(obj, (DynamicInstance) renderer);
|
||||
if (renderer instanceof IDynamicInstance) dynamicInstances.put(obj, (IDynamicInstance) renderer);
|
||||
|
||||
if (renderer instanceof TickableInstance) tickableInstances.put(obj, ((TickableInstance) renderer));
|
||||
if (renderer instanceof ITickableInstance) tickableInstances.put(obj, ((ITickableInstance) renderer));
|
||||
}
|
||||
|
||||
return renderer;
|
||||
|
|
|
@ -71,7 +71,7 @@ public class InstanceWorld {
|
|||
* <p>
|
||||
* Check and shift the origin coordinate.
|
||||
* <br>
|
||||
* Call {@link DynamicInstance#beginFrame()} on all instances in this world.
|
||||
* Call {@link IDynamicInstance#beginFrame()} on all instances in this world.
|
||||
* </p>
|
||||
*/
|
||||
public void beginFrame(BeginFrameEvent event) {
|
||||
|
@ -84,7 +84,7 @@ public class InstanceWorld {
|
|||
/**
|
||||
* Tick the renderers after the game has ticked:
|
||||
* <p>
|
||||
* Call {@link TickableInstance#tick()} on all instances in this world.
|
||||
* Call {@link ITickableInstance#tick()} on all instances in this world.
|
||||
* </p>
|
||||
*/
|
||||
public void tick() {
|
||||
|
|
|
@ -6,8 +6,8 @@ import javax.annotation.Nullable;
|
|||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.jozufozu.flywheel.backend.instancing.entity.EntityInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.entity.EntityInstanceFactory;
|
||||
import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceFactory;
|
||||
import com.jozufozu.flywheel.backend.instancing.entity.IEntityInstanceFactory;
|
||||
import com.jozufozu.flywheel.backend.instancing.tile.ITileInstanceFactory;
|
||||
import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
|
||||
import com.jozufozu.flywheel.backend.material.MaterialManager;
|
||||
|
||||
|
@ -26,21 +26,19 @@ public class InstancedRenderRegistry {
|
|||
}
|
||||
|
||||
private final Object2BooleanMap<Object> skipRender = new Object2BooleanLinkedOpenHashMap<>();
|
||||
private final Map<BlockEntityType<?>, TileInstanceFactory<?>> tiles = Maps.newHashMap();
|
||||
private final Map<EntityType<?>, EntityInstanceFactory<?>> entities = Maps.newHashMap();
|
||||
private final Map<BlockEntityType<?>, ITileInstanceFactory<?>> tiles = Maps.newHashMap();
|
||||
private final Map<EntityType<?>, IEntityInstanceFactory<?>> entities = Maps.newHashMap();
|
||||
|
||||
protected InstancedRenderRegistry() {
|
||||
skipRender.defaultReturnValue(false);
|
||||
}
|
||||
|
||||
public <T extends BlockEntity> boolean shouldSkipRender(T type) {
|
||||
// _skipRender is faster than instanceof and cast, take advantage of short-circuiting
|
||||
return _skipRender(type.getType()) || ((type instanceof InstanceRendered) && !((InstanceRendered) type).shouldRenderNormally());
|
||||
return _skipRender(type.getType()) || ((type instanceof IInstanceRendered) && !((IInstanceRendered) type).shouldRenderNormally());
|
||||
}
|
||||
|
||||
public <T extends Entity> boolean shouldSkipRender(T type) {
|
||||
// _skipRender is faster than instanceof and cast, take advantage of short-circuiting
|
||||
return _skipRender(type.getType()) || ((type instanceof InstanceRendered) && !((InstanceRendered) type).shouldRenderNormally());
|
||||
return _skipRender(type.getType()) || ((type instanceof IInstanceRendered) && !((IInstanceRendered) type).shouldRenderNormally());
|
||||
}
|
||||
|
||||
public <T extends BlockEntity> boolean canInstance(BlockEntityType<? extends T> type) {
|
||||
|
@ -63,7 +61,7 @@ public class InstancedRenderRegistry {
|
|||
* @deprecated will be removed in 0.3.0, use {@link #tile}
|
||||
*/
|
||||
@Deprecated
|
||||
public <T extends BlockEntity> void register(BlockEntityType<? extends T> type, TileInstanceFactory<? super T> rendererFactory) {
|
||||
public <T extends BlockEntity> void register(BlockEntityType<? extends T> type, ITileInstanceFactory<? super T> rendererFactory) {
|
||||
this.tile(type)
|
||||
.factory(rendererFactory);
|
||||
}
|
||||
|
@ -72,7 +70,7 @@ public class InstancedRenderRegistry {
|
|||
* @deprecated will be removed in 0.3.0, use {@link #entity}
|
||||
*/
|
||||
@Deprecated
|
||||
public <T extends Entity> void register(EntityType<? extends T> type, EntityInstanceFactory<? super T> rendererFactory) {
|
||||
public <T extends Entity> void register(EntityType<? extends T> type, IEntityInstanceFactory<? super T> rendererFactory) {
|
||||
this.entity(type)
|
||||
.factory(rendererFactory);
|
||||
}
|
||||
|
@ -81,7 +79,7 @@ public class InstancedRenderRegistry {
|
|||
@Nullable
|
||||
public <T extends BlockEntity> TileEntityInstance<? super T> create(MaterialManager manager, T tile) {
|
||||
BlockEntityType<?> type = tile.getType();
|
||||
TileInstanceFactory<? super T> factory = (TileInstanceFactory<? super T>) this.tiles.get(type);
|
||||
ITileInstanceFactory<? super T> factory = (ITileInstanceFactory<? super T>) this.tiles.get(type);
|
||||
|
||||
if (factory == null) return null;
|
||||
else return factory.create(manager, tile);
|
||||
|
@ -92,7 +90,7 @@ public class InstancedRenderRegistry {
|
|||
@Nullable
|
||||
public <T extends Entity> EntityInstance<? super T> create(MaterialManager manager, T tile) {
|
||||
EntityType<?> type = tile.getType();
|
||||
EntityInstanceFactory<? super T> factory = (EntityInstanceFactory<? super T>) this.entities.get(type);
|
||||
IEntityInstanceFactory<? super T> factory = (IEntityInstanceFactory<? super T>) this.entities.get(type);
|
||||
|
||||
if (factory == null) return null;
|
||||
else return factory.create(manager, tile);
|
||||
|
@ -109,7 +107,7 @@ public class InstancedRenderRegistry {
|
|||
CONFIG setSkipRender(boolean skipRender);
|
||||
}
|
||||
|
||||
public class TileConfig<T extends BlockEntity> implements Config<TileConfig<T>, TileInstanceFactory<? super T>> {
|
||||
public class TileConfig<T extends BlockEntity> implements Config<TileConfig<T>, ITileInstanceFactory<? super T>> {
|
||||
|
||||
|
||||
private final BlockEntityType<T> type;
|
||||
|
@ -118,7 +116,7 @@ public class InstancedRenderRegistry {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public TileConfig<T> factory(TileInstanceFactory<? super T> rendererFactory) {
|
||||
public TileConfig<T> factory(ITileInstanceFactory<? super T> rendererFactory) {
|
||||
tiles.put(type, rendererFactory);
|
||||
return this;
|
||||
}
|
||||
|
@ -128,7 +126,7 @@ public class InstancedRenderRegistry {
|
|||
}
|
||||
|
||||
}
|
||||
public class EntityConfig<T extends Entity> implements Config<EntityConfig<T>, EntityInstanceFactory<? super T>> {
|
||||
public class EntityConfig<T extends Entity> implements Config<EntityConfig<T>, IEntityInstanceFactory<? super T>> {
|
||||
|
||||
|
||||
private final EntityType<T> type;
|
||||
|
@ -137,7 +135,7 @@ public class InstancedRenderRegistry {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public EntityConfig<T> factory(EntityInstanceFactory<? super T> rendererFactory) {
|
||||
public EntityConfig<T> factory(IEntityInstanceFactory<? super T> rendererFactory) {
|
||||
entities.put(type, rendererFactory);
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.jozufozu.flywheel.backend.instancing.entity;
|
||||
|
||||
import com.jozufozu.flywheel.backend.instancing.AbstractInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.DynamicInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.TickableInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.IDynamicInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.ITickableInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager;
|
||||
import com.jozufozu.flywheel.backend.material.MaterialManager;
|
||||
import com.jozufozu.flywheel.light.GridAlignedBB;
|
||||
|
@ -24,8 +24,8 @@ import net.minecraft.core.Vec3i;
|
|||
* *
|
||||
* <br><br> There are a few additional features that overriding classes can opt in to:
|
||||
* <ul>
|
||||
* <li>{@link DynamicInstance}</li>
|
||||
* <li>{@link TickableInstance}</li>
|
||||
* <li>{@link IDynamicInstance}</li>
|
||||
* <li>{@link ITickableInstance}</li>
|
||||
* </ul>
|
||||
* See the interfaces' documentation for more information about each one.
|
||||
*
|
||||
|
|
|
@ -5,6 +5,6 @@ import com.jozufozu.flywheel.backend.material.MaterialManager;
|
|||
import net.minecraft.world.entity.Entity;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface EntityInstanceFactory<E extends Entity> {
|
||||
public interface IEntityInstanceFactory<E extends Entity> {
|
||||
EntityInstance<? super E> create(MaterialManager manager, E te);
|
||||
}
|
|
@ -5,6 +5,6 @@ import com.jozufozu.flywheel.backend.material.MaterialManager;
|
|||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface TileInstanceFactory<T extends BlockEntity> {
|
||||
public interface ITileInstanceFactory<T extends BlockEntity> {
|
||||
TileEntityInstance<? super T> create(MaterialManager manager, T te);
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
package com.jozufozu.flywheel.backend.instancing.tile;
|
||||
|
||||
import com.jozufozu.flywheel.backend.instancing.AbstractInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.DynamicInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.TickableInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.IDynamicInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.ITickableInstance;
|
||||
import com.jozufozu.flywheel.backend.material.Material;
|
||||
import com.jozufozu.flywheel.backend.material.MaterialManager;
|
||||
import com.jozufozu.flywheel.core.Materials;
|
||||
|
@ -22,8 +22,8 @@ import net.minecraft.core.BlockPos;
|
|||
*
|
||||
* <br><br> There are a few additional features that overriding classes can opt in to:
|
||||
* <ul>
|
||||
* <li>{@link DynamicInstance}</li>
|
||||
* <li>{@link TickableInstance}</li>
|
||||
* <li>{@link IDynamicInstance}</li>
|
||||
* <li>{@link ITickableInstance}</li>
|
||||
* </ul>
|
||||
* See the interfaces' documentation for more information about each one.
|
||||
*
|
||||
|
|
|
@ -6,7 +6,7 @@ import com.jozufozu.flywheel.backend.instancing.InstanceData;
|
|||
import com.jozufozu.flywheel.backend.instancing.Instancer;
|
||||
import com.jozufozu.flywheel.core.PartialModel;
|
||||
import com.jozufozu.flywheel.core.model.BlockModel;
|
||||
import com.jozufozu.flywheel.core.model.Model;
|
||||
import com.jozufozu.flywheel.core.model.IModel;
|
||||
import com.jozufozu.flywheel.util.Pair;
|
||||
import com.jozufozu.flywheel.util.RenderUtil;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
|
@ -22,7 +22,7 @@ public interface Material<D extends InstanceData> {
|
|||
* @param modelSupplier A factory that creates the IModel that you want to render.
|
||||
* @return An instancer for the given model, capable of rendering many copies for little cost.
|
||||
*/
|
||||
Instancer<D> model(Object key, Supplier<Model> modelSupplier);
|
||||
Instancer<D> model(Object key, Supplier<IModel> modelSupplier);
|
||||
|
||||
default Instancer<D> getModel(PartialModel partial, BlockState referenceState) {
|
||||
return model(partial, () -> new BlockModel(partial.get(), referenceState));
|
||||
|
|
|
@ -10,7 +10,7 @@ import com.jozufozu.flywheel.backend.instancing.GPUInstancer;
|
|||
import com.jozufozu.flywheel.backend.instancing.InstanceData;
|
||||
import com.jozufozu.flywheel.backend.instancing.Instancer;
|
||||
import com.jozufozu.flywheel.backend.model.ModelPool;
|
||||
import com.jozufozu.flywheel.core.model.Model;
|
||||
import com.jozufozu.flywheel.core.model.IModel;
|
||||
|
||||
/**
|
||||
* A collection of Instancers that all have the same format.
|
||||
|
@ -42,7 +42,7 @@ public class MaterialImpl<D extends InstanceData> implements Material<D> {
|
|||
* @return An instancer for the given model, capable of rendering many copies for little cost.
|
||||
*/
|
||||
@Override
|
||||
public Instancer<D> model(Object key, Supplier<Model> modelSupplier) {
|
||||
public Instancer<D> model(Object key, Supplier<IModel> modelSupplier) {
|
||||
try {
|
||||
return models.get(key, () -> new GPUInstancer<>(modelPool, modelSupplier.get(), spec.getInstanceType()));
|
||||
} catch (ExecutionException e) {
|
||||
|
|
|
@ -4,7 +4,6 @@ import com.jozufozu.flywheel.backend.state.IRenderState;
|
|||
import com.jozufozu.flywheel.backend.state.RenderLayer;
|
||||
import com.jozufozu.flywheel.backend.state.TextureRenderState;
|
||||
|
||||
import net.minecraft.client.renderer.RenderStateShard;
|
||||
import net.minecraft.world.inventory.InventoryMenu;
|
||||
import net.minecraft.core.Vec3i;
|
||||
|
||||
|
|
|
@ -3,14 +3,14 @@ package com.jozufozu.flywheel.backend.model;
|
|||
import java.util.function.Supplier;
|
||||
|
||||
import com.jozufozu.flywheel.backend.gl.GlVertexArray;
|
||||
import com.jozufozu.flywheel.core.model.Model;
|
||||
import com.jozufozu.flywheel.core.model.IModel;
|
||||
import com.jozufozu.flywheel.util.AttribUtil;
|
||||
|
||||
public class ArrayModelRenderer extends ModelRenderer {
|
||||
|
||||
protected GlVertexArray vao;
|
||||
|
||||
public ArrayModelRenderer(Supplier<Model> model) {
|
||||
public ArrayModelRenderer(Supplier<IModel> model) {
|
||||
super(model);
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ public class ArrayModelRenderer extends ModelRenderer {
|
|||
@Override
|
||||
protected void init() {
|
||||
initialized = true;
|
||||
Model model = modelSupplier.get();
|
||||
IModel model = modelSupplier.get();
|
||||
|
||||
if (model.empty()) return;
|
||||
|
||||
|
|
|
@ -9,17 +9,17 @@ import com.jozufozu.flywheel.backend.gl.buffer.GlBuffer;
|
|||
import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType;
|
||||
import com.jozufozu.flywheel.backend.gl.buffer.MappedBuffer;
|
||||
import com.jozufozu.flywheel.backend.gl.buffer.MappedGlBuffer;
|
||||
import com.jozufozu.flywheel.core.model.Model;
|
||||
import com.jozufozu.flywheel.core.model.IModel;
|
||||
import com.jozufozu.flywheel.util.AttribUtil;
|
||||
|
||||
public class BufferedModel implements IBufferedModel {
|
||||
|
||||
protected final Model model;
|
||||
protected final IModel model;
|
||||
protected final GlPrimitive primitiveMode;
|
||||
protected GlBuffer vbo;
|
||||
protected boolean deleted;
|
||||
|
||||
public BufferedModel(GlPrimitive primitiveMode, Model model) {
|
||||
public BufferedModel(GlPrimitive primitiveMode, IModel model) {
|
||||
this.model = model;
|
||||
this.primitiveMode = primitiveMode;
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package com.jozufozu.flywheel.backend.model;
|
||||
|
||||
import com.jozufozu.flywheel.core.model.Model;
|
||||
import com.jozufozu.flywheel.core.model.IModel;
|
||||
|
||||
public class ImmediateAllocator implements ModelAllocator {
|
||||
|
||||
public static final ImmediateAllocator INSTANCE = new ImmediateAllocator();
|
||||
|
||||
@Override
|
||||
public IBufferedModel alloc(Model model, Callback allocationCallback) {
|
||||
public IBufferedModel alloc(IModel model, Callback allocationCallback) {
|
||||
IndexedModel out = new IndexedModel(model);
|
||||
allocationCallback.onAlloc(out);
|
||||
return out;
|
||||
|
|
|
@ -4,7 +4,7 @@ import org.lwjgl.opengl.GL20;
|
|||
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
import com.jozufozu.flywheel.backend.gl.GlPrimitive;
|
||||
import com.jozufozu.flywheel.core.model.Model;
|
||||
import com.jozufozu.flywheel.core.model.IModel;
|
||||
|
||||
/**
|
||||
* An indexed triangle model. Just what the driver ordered.
|
||||
|
@ -15,7 +15,7 @@ public class IndexedModel extends BufferedModel {
|
|||
|
||||
protected ElementBuffer ebo;
|
||||
|
||||
public IndexedModel(Model model) {
|
||||
public IndexedModel(IModel model) {
|
||||
super(GlPrimitive.TRIANGLES, model);
|
||||
|
||||
this.ebo = model.createEBO();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.jozufozu.flywheel.backend.model;
|
||||
|
||||
import com.jozufozu.flywheel.core.model.Model;
|
||||
import com.jozufozu.flywheel.core.model.IModel;
|
||||
|
||||
public interface ModelAllocator {
|
||||
/**
|
||||
|
@ -9,7 +9,7 @@ public interface ModelAllocator {
|
|||
* @param model The model to allocate.
|
||||
* @return A handle to the allocated model.
|
||||
*/
|
||||
IBufferedModel alloc(Model model, Callback allocationCallback);
|
||||
IBufferedModel alloc(IModel model, Callback allocationCallback);
|
||||
|
||||
@FunctionalInterface
|
||||
interface Callback {
|
||||
|
|
|
@ -10,7 +10,7 @@ import com.jozufozu.flywheel.backend.gl.buffer.GlBuffer;
|
|||
import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType;
|
||||
import com.jozufozu.flywheel.backend.gl.buffer.MappedBuffer;
|
||||
import com.jozufozu.flywheel.backend.gl.buffer.MappedGlBuffer;
|
||||
import com.jozufozu.flywheel.core.model.Model;
|
||||
import com.jozufozu.flywheel.core.model.IModel;
|
||||
import com.jozufozu.flywheel.util.AttribUtil;
|
||||
|
||||
public class ModelPool implements ModelAllocator {
|
||||
|
@ -47,7 +47,7 @@ public class ModelPool implements ModelAllocator {
|
|||
* @return A handle to the allocated model.
|
||||
*/
|
||||
@Override
|
||||
public PooledModel alloc(Model model, Callback callback) {
|
||||
public PooledModel alloc(IModel model, Callback callback) {
|
||||
PooledModel bufferedModel = new PooledModel(model, vertices);
|
||||
bufferedModel.callback = callback;
|
||||
vertices += model.vertexCount();
|
||||
|
@ -153,12 +153,12 @@ public class ModelPool implements ModelAllocator {
|
|||
private final ElementBuffer ebo;
|
||||
private Callback callback;
|
||||
|
||||
private final Model model;
|
||||
private final IModel model;
|
||||
private int first;
|
||||
|
||||
private boolean remove;
|
||||
|
||||
public PooledModel(Model model, int first) {
|
||||
public PooledModel(IModel model, int first) {
|
||||
this.model = model;
|
||||
this.first = first;
|
||||
ebo = model.createEBO();
|
||||
|
|
|
@ -2,16 +2,16 @@ package com.jozufozu.flywheel.backend.model;
|
|||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.jozufozu.flywheel.core.model.Model;
|
||||
import com.jozufozu.flywheel.core.model.IModel;
|
||||
|
||||
public class ModelRenderer {
|
||||
|
||||
protected Supplier<Model> modelSupplier;
|
||||
protected Supplier<IModel> modelSupplier;
|
||||
protected IBufferedModel model;
|
||||
|
||||
protected boolean initialized;
|
||||
|
||||
public ModelRenderer(Supplier<Model> modelSupplier) {
|
||||
public ModelRenderer(Supplier<IModel> modelSupplier) {
|
||||
this.modelSupplier = modelSupplier;
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ public class ModelRenderer {
|
|||
|
||||
protected void init() {
|
||||
initialized = true;
|
||||
Model model = modelSupplier.get();
|
||||
IModel model = modelSupplier.get();
|
||||
|
||||
if (model.empty()) return;
|
||||
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
package com.jozufozu.flywheel.backend.pipeline;
|
||||
|
||||
import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
|
||||
import com.jozufozu.flywheel.core.shader.GameStateProgram;
|
||||
import com.jozufozu.flywheel.core.shader.IMultiProgram;
|
||||
import com.jozufozu.flywheel.core.shader.WorldProgram;
|
||||
import com.jozufozu.flywheel.core.shader.spec.ProgramSpec;
|
||||
|
||||
/**
|
||||
* The main interface for compiling usable shaders from program specs.
|
||||
* @param <P> the type of the program that this pipeline compiles.
|
||||
*/
|
||||
public interface ShaderCompiler<P extends GlProgram> {
|
||||
public interface IShaderPipeline<P extends WorldProgram> {
|
||||
|
||||
GameStateProgram<P> compile(ProgramSpec spec);
|
||||
IMultiProgram<P> compile(ProgramSpec spec);
|
||||
|
||||
}
|
|
@ -9,33 +9,34 @@ import com.jozufozu.flywheel.backend.source.FileResolution;
|
|||
import com.jozufozu.flywheel.backend.source.SourceFile;
|
||||
import com.jozufozu.flywheel.core.shader.ExtensibleGlProgram;
|
||||
import com.jozufozu.flywheel.core.shader.GameStateProgram;
|
||||
import com.jozufozu.flywheel.core.shader.IMultiProgram;
|
||||
import com.jozufozu.flywheel.core.shader.WorldProgram;
|
||||
import com.jozufozu.flywheel.core.shader.spec.ProgramSpec;
|
||||
import com.jozufozu.flywheel.core.shader.spec.ProgramState;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public class WorldShaderCompiler<P extends WorldProgram> implements ShaderCompiler<P> {
|
||||
public class WorldShaderPipeline<P extends WorldProgram> implements IShaderPipeline<P> {
|
||||
|
||||
private final ExtensibleGlProgram.Factory<P> factory;
|
||||
|
||||
private final Template<?> template;
|
||||
private final FileResolution header;
|
||||
|
||||
public WorldShaderCompiler(ExtensibleGlProgram.Factory<P> factory, Template<?> template, FileResolution header) {
|
||||
public WorldShaderPipeline(ExtensibleGlProgram.Factory<P> factory, Template<?> template, FileResolution header) {
|
||||
this.factory = factory;
|
||||
this.template = template;
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
public GameStateProgram<P> compile(ProgramSpec spec) {
|
||||
public IMultiProgram<P> compile(ProgramSpec spec) {
|
||||
|
||||
SourceFile file = spec.getSource().getFile();
|
||||
|
||||
return compile(spec.name, file, spec.getStates());
|
||||
}
|
||||
|
||||
public GameStateProgram<P> compile(ResourceLocation name, SourceFile file, List<ProgramState> variants) {
|
||||
public IMultiProgram<P> compile(ResourceLocation name, SourceFile file, List<ProgramState> variants) {
|
||||
WorldShader shader = new WorldShader(name, template, header)
|
||||
.setMainSource(file);
|
||||
|
|
@ -62,7 +62,7 @@ public class FileResolution {
|
|||
* Called after all files are loaded. If we can't find the file here, it doesn't exist.
|
||||
* </p>
|
||||
*/
|
||||
void resolve(SourceHolder sources) {
|
||||
void resolve(ISourceHolder sources) {
|
||||
|
||||
try {
|
||||
file = sources.findSource(fileLoc);
|
||||
|
|
|
@ -6,7 +6,7 @@ import net.minecraft.resources.ResourceLocation;
|
|||
* A minimal source file lookup function.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface SourceHolder {
|
||||
public interface ISourceHolder {
|
||||
|
||||
SourceFile findSource(ResourceLocation name);
|
||||
}
|
|
@ -28,7 +28,7 @@ public class Resolver {
|
|||
/**
|
||||
* Try and resolve all referenced source files, printing errors if any aren't found.
|
||||
*/
|
||||
public void resolve(SourceHolder sources) {
|
||||
public void resolve(ISourceHolder sources) {
|
||||
for (FileResolution resolution : resolutions.values()) {
|
||||
resolution.resolve(sources);
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import net.minecraft.resources.ResourceLocation;
|
|||
/**
|
||||
* The main object for loading and parsing source files.
|
||||
*/
|
||||
public class ShaderSources implements SourceHolder {
|
||||
public class ShaderSources implements ISourceHolder {
|
||||
public static final String SHADER_DIR = "flywheel/shaders/";
|
||||
public static final ArrayList<String> EXTENSIONS = Lists.newArrayList(".vert", ".vsh", ".frag", ".fsh", ".glsl");
|
||||
|
||||
|
|
|
@ -6,10 +6,6 @@ import com.jozufozu.flywheel.backend.gl.GlTextureUnit;
|
|||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
/**
|
||||
* @deprecated TODO: Rework this to be more in-line/convertable with vanilla
|
||||
*/
|
||||
@Deprecated
|
||||
public interface IRenderState {
|
||||
|
||||
void bind();
|
||||
|
|
|
@ -3,9 +3,9 @@ package com.jozufozu.flywheel.core;
|
|||
import com.jozufozu.flywheel.Flywheel;
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
import com.jozufozu.flywheel.backend.SpecMetaRegistry;
|
||||
import com.jozufozu.flywheel.backend.pipeline.ShaderCompiler;
|
||||
import com.jozufozu.flywheel.backend.pipeline.IShaderPipeline;
|
||||
import com.jozufozu.flywheel.backend.pipeline.InstancingTemplate;
|
||||
import com.jozufozu.flywheel.backend.pipeline.WorldShaderCompiler;
|
||||
import com.jozufozu.flywheel.backend.pipeline.WorldShaderPipeline;
|
||||
import com.jozufozu.flywheel.backend.source.FileResolution;
|
||||
import com.jozufozu.flywheel.backend.source.Resolver;
|
||||
import com.jozufozu.flywheel.core.crumbling.CrumblingProgram;
|
||||
|
@ -32,8 +32,8 @@ public class Contexts {
|
|||
FileResolution crumblingBuiltins = Resolver.INSTANCE.findShader(ResourceUtil.subPath(Names.CRUMBLING, ".glsl"));
|
||||
FileResolution worldBuiltins = Resolver.INSTANCE.findShader(ResourceUtil.subPath(Names.WORLD, ".glsl"));
|
||||
|
||||
ShaderCompiler<CrumblingProgram> crumblingPipeline = new WorldShaderCompiler<>(CrumblingProgram::new, InstancingTemplate.INSTANCE, crumblingBuiltins);
|
||||
ShaderCompiler<WorldProgram> worldPipeline = new WorldShaderCompiler<>(WorldProgram::new, InstancingTemplate.INSTANCE, worldBuiltins);
|
||||
IShaderPipeline<CrumblingProgram> crumblingPipeline = new WorldShaderPipeline<>(CrumblingProgram::new, InstancingTemplate.INSTANCE, crumblingBuiltins);
|
||||
IShaderPipeline<WorldProgram> worldPipeline = new WorldShaderPipeline<>(WorldProgram::new, InstancingTemplate.INSTANCE, worldBuiltins);
|
||||
|
||||
CRUMBLING = backend.register(WorldContext.builder(backend, Names.CRUMBLING).build(crumblingPipeline));
|
||||
WORLD = backend.register(WorldContext.builder(backend, Names.WORLD).build(worldPipeline));
|
||||
|
|
|
@ -6,24 +6,24 @@ import java.util.function.Supplier;
|
|||
import java.util.stream.Stream;
|
||||
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
import com.jozufozu.flywheel.backend.ShaderContext;
|
||||
import com.jozufozu.flywheel.backend.IShaderContext;
|
||||
import com.jozufozu.flywheel.backend.material.MaterialSpec;
|
||||
import com.jozufozu.flywheel.backend.pipeline.ShaderCompiler;
|
||||
import com.jozufozu.flywheel.core.shader.GameStateProgram;
|
||||
import com.jozufozu.flywheel.backend.pipeline.IShaderPipeline;
|
||||
import com.jozufozu.flywheel.core.shader.IMultiProgram;
|
||||
import com.jozufozu.flywheel.core.shader.WorldProgram;
|
||||
import com.jozufozu.flywheel.core.shader.spec.ProgramSpec;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public class WorldContext<P extends WorldProgram> implements ShaderContext<P> {
|
||||
public class WorldContext<P extends WorldProgram> implements IShaderContext<P> {
|
||||
public final Backend backend;
|
||||
protected final Map<ResourceLocation, GameStateProgram<P>> programs = new HashMap<>();
|
||||
protected final Map<ResourceLocation, IMultiProgram<P>> programs = new HashMap<>();
|
||||
protected final ResourceLocation name;
|
||||
protected final Supplier<Stream<ResourceLocation>> specStream;
|
||||
|
||||
public final ShaderCompiler<P> pipeline;
|
||||
public final IShaderPipeline<P> pipeline;
|
||||
|
||||
public WorldContext(Backend backend, ResourceLocation name, Supplier<Stream<ResourceLocation>> specStream, ShaderCompiler<P> pipeline) {
|
||||
public WorldContext(Backend backend, ResourceLocation name, Supplier<Stream<ResourceLocation>> specStream, IShaderPipeline<P> pipeline) {
|
||||
this.backend = backend;
|
||||
this.name = name;
|
||||
this.specStream = specStream;
|
||||
|
@ -61,7 +61,7 @@ public class WorldContext<P extends WorldProgram> implements ShaderContext<P> {
|
|||
@Override
|
||||
public void delete() {
|
||||
programs.values()
|
||||
.forEach(GameStateProgram::delete);
|
||||
.forEach(IMultiProgram::delete);
|
||||
programs.clear();
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ public class WorldContext<P extends WorldProgram> implements ShaderContext<P> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public <P extends WorldProgram> WorldContext<P> build(ShaderCompiler<P> pipeline) {
|
||||
public <P extends WorldProgram> WorldContext<P> build(IShaderPipeline<P> pipeline) {
|
||||
if (specStream == null) {
|
||||
specStream = () -> backend.allMaterials()
|
||||
.stream()
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package com.jozufozu.flywheel.core.materials;
|
||||
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
|
||||
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
||||
import com.jozufozu.flywheel.backend.instancing.InstanceData;
|
||||
|
||||
public abstract class BasicData extends InstanceData implements FlatLight {
|
||||
public abstract class BasicData extends InstanceData implements IFlatLight<BasicData> {
|
||||
|
||||
public byte blockLight;
|
||||
public byte skyLight;
|
||||
|
|
|
@ -7,19 +7,21 @@ import com.jozufozu.flywheel.backend.instancing.InstanceData;
|
|||
* if they wish to make use of Flywheel's provided light update methods.
|
||||
* <p>
|
||||
* This only covers flat lighting, smooth lighting is still TODO.
|
||||
*
|
||||
* @param <D> The name of the class that implements this interface.
|
||||
*/
|
||||
public interface FlatLight {
|
||||
public interface IFlatLight<D extends InstanceData & IFlatLight<D>> {
|
||||
/**
|
||||
* @param blockLight An integer in the range [0, 15] representing the
|
||||
* amount of block light this instance should receive.
|
||||
* @return <code>this</code>
|
||||
*/
|
||||
FlatLight setBlockLight(int blockLight);
|
||||
D setBlockLight(int blockLight);
|
||||
|
||||
/**
|
||||
* @param skyLight An integer in the range [0, 15] representing the
|
||||
* amount of sky light this instance should receive.
|
||||
* @return <code>this</code>
|
||||
*/
|
||||
FlatLight setSkyLight(int skyLight);
|
||||
D setSkyLight(int skyLight);
|
||||
}
|
|
@ -25,7 +25,7 @@ import net.minecraft.core.Direction;
|
|||
import com.mojang.math.Vector3f;
|
||||
import net.minecraft.core.Vec3i;
|
||||
|
||||
public class BakedModelModel implements Model {
|
||||
public class BakedModelModel implements IModel {
|
||||
// DOWN, UP, NORTH, SOUTH, WEST, EAST, null
|
||||
private static final Direction[] dirs;
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@ package com.jozufozu.flywheel.core.model;
|
|||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
|
||||
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
||||
import com.jozufozu.flywheel.core.Formats;
|
||||
|
@ -23,7 +25,7 @@ import net.minecraft.core.BlockPos;
|
|||
/**
|
||||
* A model of a single block.
|
||||
*/
|
||||
public class BlockModel implements Model {
|
||||
public class BlockModel implements IModel {
|
||||
private static final PoseStack IDENTITY = new PoseStack();
|
||||
|
||||
private final BufferBuilderReader reader;
|
||||
|
|
|
@ -25,7 +25,7 @@ import com.jozufozu.flywheel.core.QuadConverter;
|
|||
* assert model.size() == final - initial;
|
||||
* }</pre>
|
||||
*/
|
||||
public interface Model {
|
||||
public interface IModel {
|
||||
|
||||
/**
|
||||
* Copy this model into the given buffer.
|
|
@ -6,7 +6,7 @@ import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
|
|||
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
||||
import com.jozufozu.flywheel.core.Formats;
|
||||
|
||||
public class ModelPart implements Model {
|
||||
public class ModelPart implements IModel {
|
||||
|
||||
private final List<PartBuilder.CuboidBuilder> cuboids;
|
||||
private int vertices;
|
||||
|
|
|
@ -12,7 +12,7 @@ import net.minecraft.client.renderer.RenderType;
|
|||
import net.minecraft.world.level.BlockAndTintGetter;
|
||||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
|
||||
|
||||
public class WorldModel implements Model {
|
||||
public class WorldModel implements IModel {
|
||||
|
||||
private final BufferBuilderReader reader;
|
||||
|
||||
|
|
|
@ -2,14 +2,13 @@ package com.jozufozu.flywheel.core.shader;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
|
||||
import com.jozufozu.flywheel.core.shader.spec.IGameStateCondition;
|
||||
import com.jozufozu.flywheel.util.Pair;
|
||||
|
||||
public class GameStateProgram<P extends GlProgram> implements Supplier<P> {
|
||||
public class GameStateProgram<P extends GlProgram> implements IMultiProgram<P> {
|
||||
|
||||
private final List<Pair<IGameStateCondition, P>> variants;
|
||||
private final P fallback;
|
||||
|
@ -19,9 +18,6 @@ public class GameStateProgram<P extends GlProgram> implements Supplier<P> {
|
|||
this.fallback = fallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the shader program most suited for the current game state.
|
||||
*/
|
||||
@Override
|
||||
public P get() {
|
||||
for (Pair<IGameStateCondition, P> variant : variants) {
|
||||
|
@ -32,9 +28,7 @@ public class GameStateProgram<P extends GlProgram> implements Supplier<P> {
|
|||
return fallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all associated programs.
|
||||
*/
|
||||
@Override
|
||||
public void delete() {
|
||||
for (Pair<IGameStateCondition, P> variant : variants) {
|
||||
variant.getSecond()
|
||||
|
@ -61,7 +55,7 @@ public class GameStateProgram<P extends GlProgram> implements Supplier<P> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public GameStateProgram<P> build() {
|
||||
public IMultiProgram<P> build() {
|
||||
return new GameStateProgram<>(ImmutableList.copyOf(variants), fallback);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package com.jozufozu.flywheel.core.shader;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
|
||||
|
||||
/**
|
||||
* Encapsulates any number of shader programs for use in similar contexts.
|
||||
* Allows the implementor to choose which shader program to use based on arbitrary state.
|
||||
*
|
||||
* @param <P>
|
||||
*/
|
||||
public interface IMultiProgram<P extends GlProgram> extends Supplier<P> {
|
||||
|
||||
/**
|
||||
* Get the shader program most suited for the current game state.
|
||||
*
|
||||
* @return The one true program.
|
||||
*/
|
||||
P get();
|
||||
|
||||
/**
|
||||
* Delete all shader programs encapsulated by your implementation.
|
||||
*/
|
||||
void delete();
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package com.jozufozu.flywheel.vanilla;
|
||||
|
||||
import com.jozufozu.flywheel.backend.instancing.DynamicInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.IDynamicInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
|
||||
import com.jozufozu.flywheel.backend.material.MaterialManager;
|
||||
import com.jozufozu.flywheel.core.Materials;
|
||||
|
@ -14,7 +14,7 @@ import net.minecraft.util.Mth;
|
|||
import com.mojang.math.Quaternion;
|
||||
import com.mojang.math.Vector3f;
|
||||
|
||||
public class BellInstance extends TileEntityInstance<BellBlockEntity> implements DynamicInstance {
|
||||
public class BellInstance extends TileEntityInstance<BellBlockEntity> implements IDynamicInstance {
|
||||
|
||||
private final OrientedData bell;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import java.util.Calendar;
|
|||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.jozufozu.flywheel.backend.instancing.DynamicInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.IDynamicInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
|
||||
import com.jozufozu.flywheel.backend.material.MaterialManager;
|
||||
import com.jozufozu.flywheel.backend.state.TextureRenderState;
|
||||
|
@ -29,7 +29,7 @@ import net.minecraft.world.level.block.DoubleBlockCombiner;
|
|||
import com.mojang.math.Quaternion;
|
||||
import com.mojang.math.Vector3f;
|
||||
|
||||
public class ChestInstance<T extends BlockEntity & LidBlockEntity> extends TileEntityInstance<T> implements DynamicInstance {
|
||||
public class ChestInstance<T extends BlockEntity & LidBlockEntity> extends TileEntityInstance<T> implements IDynamicInstance {
|
||||
|
||||
private final MatrixTransformStack stack = new MatrixTransformStack();
|
||||
private final OrientedData body;
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package com.jozufozu.flywheel.vanilla;
|
||||
|
||||
import com.jozufozu.flywheel.backend.instancing.DynamicInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.TickableInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.IDynamicInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.ITickableInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.entity.EntityInstance;
|
||||
import com.jozufozu.flywheel.backend.material.MaterialManager;
|
||||
import com.jozufozu.flywheel.backend.state.TextureRenderState;
|
||||
import com.jozufozu.flywheel.core.Materials;
|
||||
import com.jozufozu.flywheel.core.materials.model.ModelData;
|
||||
import com.jozufozu.flywheel.core.model.Model;
|
||||
import com.jozufozu.flywheel.core.model.IModel;
|
||||
import com.jozufozu.flywheel.core.model.ModelPart;
|
||||
import com.jozufozu.flywheel.util.AnimationTickHolder;
|
||||
import com.jozufozu.flywheel.util.transform.MatrixTransformStack;
|
||||
|
@ -21,7 +21,7 @@ import net.minecraft.util.Mth;
|
|||
import net.minecraft.world.phys.Vec3;
|
||||
import com.mojang.math.Vector3f;
|
||||
|
||||
public class MinecartInstance<T extends AbstractMinecart> extends EntityInstance<T> implements DynamicInstance, TickableInstance {
|
||||
public class MinecartInstance<T extends AbstractMinecart> extends EntityInstance<T> implements IDynamicInstance, ITickableInstance {
|
||||
|
||||
private static final ResourceLocation MINECART_LOCATION = new ResourceLocation("textures/entity/minecart.png");
|
||||
|
||||
|
@ -153,7 +153,7 @@ public class MinecartInstance<T extends AbstractMinecart> extends EntityInstance
|
|||
.createInstance();
|
||||
}
|
||||
|
||||
private Model getBodyModel() {
|
||||
private IModel getBodyModel() {
|
||||
int y = -3;
|
||||
return ModelPart.builder(64, 32)
|
||||
.cuboid().invertYZ().start(-10, -8, -y).size(20, 16, 2).textureOffset(0, 10).rotateX(((float)Math.PI / 2F)).endCuboid()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.jozufozu.flywheel.vanilla;
|
||||
|
||||
import com.jozufozu.flywheel.backend.instancing.DynamicInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.IDynamicInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
|
||||
import com.jozufozu.flywheel.backend.material.MaterialManager;
|
||||
import com.jozufozu.flywheel.core.Materials;
|
||||
|
@ -18,7 +18,7 @@ import net.minecraft.core.Direction;
|
|||
import com.mojang.math.Quaternion;
|
||||
import com.mojang.math.Vector3f;
|
||||
|
||||
public class ShulkerBoxInstance extends TileEntityInstance<ShulkerBoxBlockEntity> implements DynamicInstance {
|
||||
public class ShulkerBoxInstance extends TileEntityInstance<ShulkerBoxBlockEntity> implements IDynamicInstance {
|
||||
|
||||
private final TextureAtlasSprite texture;
|
||||
|
||||
|
|
Loading…
Reference in a new issue