mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-28 16:06:28 +01:00
No more material spec, everything is StructType
This commit is contained in:
parent
eee9b3fb51
commit
5374baf241
28 changed files with 101 additions and 90 deletions
|
@ -1,7 +1,5 @@
|
||||||
package com.jozufozu.flywheel.api;
|
package com.jozufozu.flywheel.api;
|
||||||
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Something (a BlockEntity or Entity) that can be rendered using the instancing API.
|
* Something (a BlockEntity or Entity) that can be rendered using the instancing API.
|
||||||
*/
|
*/
|
||||||
|
@ -13,6 +11,4 @@ public interface FlywheelRendered {
|
||||||
default boolean shouldRenderNormally() {
|
default boolean shouldRenderNormally() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Level getWorld();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.jozufozu.flywheel.api;
|
package com.jozufozu.flywheel.api;
|
||||||
|
|
||||||
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
|
|
||||||
public interface MaterialGroup {
|
public interface MaterialGroup {
|
||||||
/**
|
/**
|
||||||
* Get the material as defined by the given {@link MaterialSpec spec}.
|
* Get the material as defined by the given {@link MaterialSpec spec}.
|
||||||
|
@ -8,5 +10,5 @@ public interface MaterialGroup {
|
||||||
* @param <D> The type representing the per instance data.
|
* @param <D> The type representing the per instance data.
|
||||||
* @return A material you can use to render models.
|
* @return A material you can use to render models.
|
||||||
*/
|
*/
|
||||||
<D extends InstanceData> Material<D> material(MaterialSpec<D> spec);
|
<D extends InstanceData> Material<D> material(StructType<D> spec);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
package com.jozufozu.flywheel.api;
|
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.struct.StructType;
|
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
|
|
||||||
public class MaterialSpec<D extends InstanceData> {
|
|
||||||
|
|
||||||
public final ResourceLocation name;
|
|
||||||
|
|
||||||
private final ResourceLocation programSpec;
|
|
||||||
private final StructType<D> instanceType;
|
|
||||||
|
|
||||||
public MaterialSpec(ResourceLocation name, ResourceLocation programSpec, StructType<D> type) {
|
|
||||||
this.name = name;
|
|
||||||
this.programSpec = programSpec;
|
|
||||||
this.instanceType = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResourceLocation getProgramName() {
|
|
||||||
return programSpec;
|
|
||||||
}
|
|
||||||
|
|
||||||
public StructType<D> getInstanceType() {
|
|
||||||
return instanceType;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.jozufozu.flywheel.backend.struct;
|
package com.jozufozu.flywheel.api.struct;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.core.model.Model;
|
import com.jozufozu.flywheel.core.model.Model;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.jozufozu.flywheel.backend.struct;
|
package com.jozufozu.flywheel.api.struct;
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
|
@ -1,8 +1,10 @@
|
||||||
package com.jozufozu.flywheel.backend.struct;
|
package com.jozufozu.flywheel.api.struct;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
||||||
|
|
||||||
public interface Writeable<S> extends StructType<S> {
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
|
public interface Instanced<S> extends StructType<S> {
|
||||||
/**
|
/**
|
||||||
* Create a {@link StructWriter} that will consume instances of S and write them to the given buffer.
|
* Create a {@link StructWriter} that will consume instances of S and write them to the given buffer.
|
||||||
*
|
*
|
||||||
|
@ -10,8 +12,10 @@ public interface Writeable<S> extends StructType<S> {
|
||||||
*/
|
*/
|
||||||
StructWriter<S> getWriter(VecBuffer backing);
|
StructWriter<S> getWriter(VecBuffer backing);
|
||||||
|
|
||||||
|
ResourceLocation getProgramSpec();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default Writeable<S> asWriteable() {
|
default Instanced<S> asInstanced() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package com.jozufozu.flywheel.backend.struct;
|
package com.jozufozu.flywheel.api.struct;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
|
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ public interface StructType<S> {
|
||||||
*/
|
*/
|
||||||
VertexFormat format();
|
VertexFormat format();
|
||||||
|
|
||||||
Writeable<S> asWriteable();
|
Instanced<S> asInstanced();
|
||||||
|
|
||||||
Batched<S> asBatched();
|
Batched<S> asBatched();
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package com.jozufozu.flywheel.backend.struct;
|
package com.jozufozu.flywheel.api.struct;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StructWriters can quickly consume many instances of S and write them to some backing buffer.
|
* StructWriters can quickly consume many instances of S and write them to some backing buffer.
|
|
@ -0,0 +1,6 @@
|
||||||
|
@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault
|
||||||
|
package com.jozufozu.flywheel.api.struct;
|
||||||
|
|
||||||
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
|
|
||||||
|
import net.minecraft.MethodsReturnNonnullByDefault;
|
|
@ -17,6 +17,7 @@ import com.jozufozu.flywheel.api.FlywheelWorld;
|
||||||
import com.jozufozu.flywheel.backend.gl.versioned.GlCompat;
|
import com.jozufozu.flywheel.backend.gl.versioned.GlCompat;
|
||||||
import com.jozufozu.flywheel.api.InstanceData;
|
import com.jozufozu.flywheel.api.InstanceData;
|
||||||
import com.jozufozu.flywheel.api.MaterialSpec;
|
import com.jozufozu.flywheel.api.MaterialSpec;
|
||||||
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
import com.jozufozu.flywheel.config.FlwConfig;
|
import com.jozufozu.flywheel.config.FlwConfig;
|
||||||
import com.jozufozu.flywheel.core.shader.spec.ProgramSpec;
|
import com.jozufozu.flywheel.core.shader.spec.ProgramSpec;
|
||||||
|
|
||||||
|
@ -43,7 +44,7 @@ public class Backend {
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
|
|
||||||
private final List<ShaderContext<?>> contexts = new ArrayList<>();
|
private final List<ShaderContext<?>> contexts = new ArrayList<>();
|
||||||
private final Map<ResourceLocation, MaterialSpec<?>> materialRegistry = new HashMap<>();
|
private final Map<ResourceLocation, StructType<?>> materialRegistry = new HashMap<>();
|
||||||
private final Map<ResourceLocation, ProgramSpec> programSpecRegistry = new HashMap<>();
|
private final Map<ResourceLocation, ProgramSpec> programSpecRegistry = new HashMap<>();
|
||||||
|
|
||||||
protected Backend() {
|
protected Backend() {
|
||||||
|
@ -91,14 +92,13 @@ public class Backend {
|
||||||
/**
|
/**
|
||||||
* Register an instancing material.
|
* Register an instancing material.
|
||||||
*/
|
*/
|
||||||
public <D extends InstanceData> MaterialSpec<D> register(MaterialSpec<D> spec) {
|
public <D extends InstanceData> StructType<D> register(ResourceLocation name, StructType<D> spec) {
|
||||||
ResourceLocation name = spec.name;
|
|
||||||
if (materialRegistry.containsKey(name)) {
|
if (materialRegistry.containsKey(name)) {
|
||||||
throw new IllegalStateException("Material spec '" + name + "' already registered.");
|
throw new IllegalStateException("Material spec '" + name + "' already registered.");
|
||||||
}
|
}
|
||||||
materialRegistry.put(name, spec);
|
materialRegistry.put(name, spec);
|
||||||
|
|
||||||
log.debug("registered material '" + name + "' with instance size " + spec.getInstanceType().format().getStride());
|
log.debug("registered material '" + name + "' with instance size " + spec.format().getStride());
|
||||||
|
|
||||||
return spec;
|
return spec;
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ public class Backend {
|
||||||
return canUseInstancing() && isFlywheelWorld(world);
|
return canUseInstancing() && isFlywheelWorld(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<MaterialSpec<?>> allMaterials() {
|
public Collection<StructType<?>> allMaterials() {
|
||||||
return materialRegistry.values();
|
return materialRegistry.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import java.util.BitSet;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstanceData;
|
import com.jozufozu.flywheel.api.InstanceData;
|
||||||
import com.jozufozu.flywheel.api.Instancer;
|
import com.jozufozu.flywheel.api.Instancer;
|
||||||
import com.jozufozu.flywheel.backend.struct.StructType;
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
import com.jozufozu.flywheel.core.model.Model;
|
import com.jozufozu.flywheel.core.model.Model;
|
||||||
|
|
||||||
public abstract class AbstractInstancer<D extends InstanceData> implements Instancer<D> {
|
public abstract class AbstractInstancer<D extends InstanceData> implements Instancer<D> {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import com.jozufozu.flywheel.api.InstanceData;
|
||||||
import com.jozufozu.flywheel.api.Instancer;
|
import com.jozufozu.flywheel.api.Instancer;
|
||||||
import com.jozufozu.flywheel.api.Material;
|
import com.jozufozu.flywheel.api.Material;
|
||||||
import com.jozufozu.flywheel.api.MaterialSpec;
|
import com.jozufozu.flywheel.api.MaterialSpec;
|
||||||
import com.jozufozu.flywheel.backend.struct.StructType;
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
import com.jozufozu.flywheel.core.model.Model;
|
import com.jozufozu.flywheel.core.model.Model;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||||
|
@ -18,8 +18,8 @@ public class BatchedMaterial<D extends InstanceData> implements Material<D> {
|
||||||
protected final Map<Object, CPUInstancer<D>> models;
|
protected final Map<Object, CPUInstancer<D>> models;
|
||||||
private final StructType<D> type;
|
private final StructType<D> type;
|
||||||
|
|
||||||
public BatchedMaterial(MaterialSpec<D> spec) {
|
public BatchedMaterial(StructType<D> type) {
|
||||||
type = spec.getInstanceType();
|
this.type = type;
|
||||||
|
|
||||||
this.models = new HashMap<>();
|
this.models = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import java.util.Map;
|
||||||
import com.jozufozu.flywheel.api.InstanceData;
|
import com.jozufozu.flywheel.api.InstanceData;
|
||||||
import com.jozufozu.flywheel.api.MaterialGroup;
|
import com.jozufozu.flywheel.api.MaterialGroup;
|
||||||
import com.jozufozu.flywheel.api.MaterialSpec;
|
import com.jozufozu.flywheel.api.MaterialSpec;
|
||||||
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||||
|
|
||||||
|
@ -16,7 +17,7 @@ public class BatchedMaterialGroup implements MaterialGroup {
|
||||||
|
|
||||||
protected final RenderType state;
|
protected final RenderType state;
|
||||||
|
|
||||||
private final Map<MaterialSpec<?>, BatchedMaterial<?>> materials = new HashMap<>();
|
private final Map<StructType<? extends InstanceData>, BatchedMaterial<?>> materials = new HashMap<>();
|
||||||
|
|
||||||
public BatchedMaterialGroup(RenderType state) {
|
public BatchedMaterialGroup(RenderType state) {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
|
@ -30,7 +31,7 @@ public class BatchedMaterialGroup implements MaterialGroup {
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public <D extends InstanceData> BatchedMaterial<D> material(MaterialSpec<D> spec) {
|
public <D extends InstanceData> BatchedMaterial<D> material(StructType<D> spec) {
|
||||||
return (BatchedMaterial<D>) materials.computeIfAbsent(spec, BatchedMaterial::new);
|
return (BatchedMaterial<D>) materials.computeIfAbsent(spec, BatchedMaterial::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@ package com.jozufozu.flywheel.backend.instancing.batching;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.instancing.AbstractInstancer;
|
import com.jozufozu.flywheel.backend.instancing.AbstractInstancer;
|
||||||
import com.jozufozu.flywheel.api.InstanceData;
|
import com.jozufozu.flywheel.api.InstanceData;
|
||||||
import com.jozufozu.flywheel.backend.struct.BatchingTransformer;
|
import com.jozufozu.flywheel.api.struct.BatchingTransformer;
|
||||||
import com.jozufozu.flywheel.backend.struct.StructType;
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
import com.jozufozu.flywheel.core.model.Model;
|
import com.jozufozu.flywheel.core.model.Model;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||||
|
|
|
@ -13,8 +13,8 @@ import com.jozufozu.flywheel.backend.instancing.AbstractInstancer;
|
||||||
import com.jozufozu.flywheel.api.InstanceData;
|
import com.jozufozu.flywheel.api.InstanceData;
|
||||||
import com.jozufozu.flywheel.backend.model.IBufferedModel;
|
import com.jozufozu.flywheel.backend.model.IBufferedModel;
|
||||||
import com.jozufozu.flywheel.backend.model.ModelAllocator;
|
import com.jozufozu.flywheel.backend.model.ModelAllocator;
|
||||||
import com.jozufozu.flywheel.backend.struct.StructType;
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
import com.jozufozu.flywheel.backend.struct.StructWriter;
|
import com.jozufozu.flywheel.api.struct.StructWriter;
|
||||||
import com.jozufozu.flywheel.core.model.Model;
|
import com.jozufozu.flywheel.core.model.Model;
|
||||||
import com.jozufozu.flywheel.util.AttribUtil;
|
import com.jozufozu.flywheel.util.AttribUtil;
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ public class GPUInstancer<D extends InstanceData> extends AbstractInstancer<D> {
|
||||||
if (length > 0) {
|
if (length > 0) {
|
||||||
MappedBuffer mapped = instanceVBO.getBuffer(offset, length);
|
MappedBuffer mapped = instanceVBO.getBuffer(offset, length);
|
||||||
|
|
||||||
StructWriter<D> writer = type.asWriteable().getWriter(mapped);
|
StructWriter<D> writer = type.asInstanced().getWriter(mapped);
|
||||||
|
|
||||||
dirtySet.stream()
|
dirtySet.stream()
|
||||||
.forEach(i -> {
|
.forEach(i -> {
|
||||||
|
@ -181,7 +181,7 @@ public class GPUInstancer<D extends InstanceData> extends AbstractInstancer<D> {
|
||||||
instanceVBO.alloc(glBufferSize);
|
instanceVBO.alloc(glBufferSize);
|
||||||
|
|
||||||
MappedBuffer buffer = instanceVBO.getBuffer(0, glBufferSize);
|
MappedBuffer buffer = instanceVBO.getBuffer(0, glBufferSize);
|
||||||
StructWriter<D> writer = type.asWriteable().getWriter(buffer);
|
StructWriter<D> writer = type.asInstanced().getWriter(buffer);
|
||||||
for (D datum : data) {
|
for (D datum : data) {
|
||||||
writer.write(datum);
|
writer.write(datum);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import com.jozufozu.flywheel.api.Instancer;
|
||||||
import com.jozufozu.flywheel.api.Material;
|
import com.jozufozu.flywheel.api.Material;
|
||||||
import com.jozufozu.flywheel.api.MaterialSpec;
|
import com.jozufozu.flywheel.api.MaterialSpec;
|
||||||
import com.jozufozu.flywheel.backend.model.ModelPool;
|
import com.jozufozu.flywheel.backend.model.ModelPool;
|
||||||
import com.jozufozu.flywheel.backend.struct.StructType;
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
import com.jozufozu.flywheel.core.Formats;
|
import com.jozufozu.flywheel.core.Formats;
|
||||||
import com.jozufozu.flywheel.core.model.Model;
|
import com.jozufozu.flywheel.core.model.Model;
|
||||||
|
|
||||||
|
@ -25,8 +25,8 @@ public class InstancedMaterial<D extends InstanceData> implements Material<D> {
|
||||||
protected final Cache<Object, GPUInstancer<D>> models;
|
protected final Cache<Object, GPUInstancer<D>> models;
|
||||||
protected final StructType<D> type;
|
protected final StructType<D> type;
|
||||||
|
|
||||||
public InstancedMaterial(MaterialSpec<D> spec) {
|
public InstancedMaterial(StructType<D> spec) {
|
||||||
this.type = spec.getInstanceType();
|
this.type = spec;
|
||||||
|
|
||||||
modelPool = new ModelPool(Formats.UNLIT_MODEL, 64);
|
modelPool = new ModelPool(Formats.UNLIT_MODEL, 64);
|
||||||
this.models = CacheBuilder.newBuilder()
|
this.models = CacheBuilder.newBuilder()
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.util.Map;
|
||||||
import com.jozufozu.flywheel.api.InstanceData;
|
import com.jozufozu.flywheel.api.InstanceData;
|
||||||
import com.jozufozu.flywheel.api.MaterialGroup;
|
import com.jozufozu.flywheel.api.MaterialGroup;
|
||||||
import com.jozufozu.flywheel.api.MaterialSpec;
|
import com.jozufozu.flywheel.api.MaterialSpec;
|
||||||
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
import com.jozufozu.flywheel.core.shader.WorldProgram;
|
import com.jozufozu.flywheel.core.shader.WorldProgram;
|
||||||
import com.jozufozu.flywheel.util.TextureBinder;
|
import com.jozufozu.flywheel.util.TextureBinder;
|
||||||
import com.mojang.math.Matrix4f;
|
import com.mojang.math.Matrix4f;
|
||||||
|
@ -26,7 +27,7 @@ public class InstancedMaterialGroup<P extends WorldProgram> implements MaterialG
|
||||||
|
|
||||||
protected final ArrayList<InstancedMaterialRenderer<P>> renderers = new ArrayList<>();
|
protected final ArrayList<InstancedMaterialRenderer<P>> renderers = new ArrayList<>();
|
||||||
|
|
||||||
private final Map<MaterialSpec<?>, InstancedMaterial<?>> materials = new HashMap<>();
|
private final Map<StructType<? extends InstanceData>, InstancedMaterial<?>> materials = new HashMap<>();
|
||||||
|
|
||||||
public InstancedMaterialGroup(InstancingEngine<P> owner, RenderType type) {
|
public InstancedMaterialGroup(InstancingEngine<P> owner, RenderType type) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
|
@ -41,7 +42,7 @@ public class InstancedMaterialGroup<P extends WorldProgram> implements MaterialG
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public <D extends InstanceData> InstancedMaterial<D> material(MaterialSpec<D> spec) {
|
public <D extends InstanceData> InstancedMaterial<D> material(StructType<D> spec) {
|
||||||
return (InstancedMaterial<D>) materials.computeIfAbsent(spec, this::createInstanceMaterial);
|
return (InstancedMaterial<D>) materials.computeIfAbsent(spec, this::createInstanceMaterial);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,10 +71,11 @@ public class InstancedMaterialGroup<P extends WorldProgram> implements MaterialG
|
||||||
renderers.clear();
|
renderers.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private InstancedMaterial<?> createInstanceMaterial(MaterialSpec<?> type) {
|
private InstancedMaterial<?> createInstanceMaterial(StructType<? extends InstanceData> type) {
|
||||||
InstancedMaterial<?> material = new InstancedMaterial<>(type);
|
InstancedMaterial<?> material = new InstancedMaterial<>(type);
|
||||||
|
|
||||||
this.renderers.add(new InstancedMaterialRenderer<>(owner.getProgram(type.getProgramName()), material, this::setup));
|
this.renderers.add(new InstancedMaterialRenderer<>(owner.getProgram(type.asInstanced()
|
||||||
|
.getProgramSpec()), material, this::setup));
|
||||||
|
|
||||||
return material;
|
return material;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.jozufozu.flywheel.backend.struct;
|
package com.jozufozu.flywheel.backend.struct;
|
||||||
|
|
||||||
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
|
import com.jozufozu.flywheel.api.struct.StructWriter;
|
||||||
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
|
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
|
||||||
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.jozufozu.flywheel.backend.struct;
|
||||||
|
|
||||||
import org.lwjgl.system.MemoryUtil;
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.jozufozu.flywheel.core;
|
package com.jozufozu.flywheel.core;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.MaterialSpec;
|
import com.jozufozu.flywheel.backend.Backend;
|
||||||
import com.jozufozu.flywheel.backend.struct.StructType;
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
import com.jozufozu.flywheel.core.materials.model.ModelData;
|
import com.jozufozu.flywheel.core.materials.model.ModelData;
|
||||||
import com.jozufozu.flywheel.core.materials.model.ModelType;
|
import com.jozufozu.flywheel.core.materials.model.ModelType;
|
||||||
import com.jozufozu.flywheel.core.materials.oriented.OrientedData;
|
import com.jozufozu.flywheel.core.materials.oriented.OrientedData;
|
||||||
|
@ -14,17 +14,14 @@ import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public class Materials {
|
public class Materials {
|
||||||
public static final StructType<OrientedData> ORIENTED_TYPE = new OrientedType();
|
|
||||||
public static final StructType<ModelData> TRANSFORMED_TYPE = new ModelType();
|
|
||||||
|
|
||||||
public static final MaterialSpec<OrientedData> ORIENTED = new MaterialSpec<>(Names.ORIENTED, Programs.ORIENTED, ORIENTED_TYPE);
|
public static final StructType<OrientedData> ORIENTED = new OrientedType();
|
||||||
public static final MaterialSpec<ModelData> TRANSFORMED = new MaterialSpec<>(Names.MODEL, Programs.TRANSFORMED, TRANSFORMED_TYPE);
|
public static final StructType<ModelData> TRANSFORMED = new ModelType();
|
||||||
|
|
||||||
public static void flwInit(GatherContextEvent event) {
|
public static void flwInit(GatherContextEvent event) {
|
||||||
event.getBackend()
|
Backend backend = event.getBackend();
|
||||||
.register(ORIENTED);
|
backend.register(Names.ORIENTED, ORIENTED);
|
||||||
event.getBackend()
|
backend.register(Names.MODEL, TRANSFORMED);
|
||||||
.register(TRANSFORMED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Names {
|
public static class Names {
|
||||||
|
|
|
@ -7,7 +7,6 @@ import java.util.stream.Stream;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.Backend;
|
import com.jozufozu.flywheel.backend.Backend;
|
||||||
import com.jozufozu.flywheel.backend.ShaderContext;
|
import com.jozufozu.flywheel.backend.ShaderContext;
|
||||||
import com.jozufozu.flywheel.api.MaterialSpec;
|
|
||||||
import com.jozufozu.flywheel.backend.pipeline.ShaderPipeline;
|
import com.jozufozu.flywheel.backend.pipeline.ShaderPipeline;
|
||||||
import com.jozufozu.flywheel.core.shader.ContextAwareProgram;
|
import com.jozufozu.flywheel.core.shader.ContextAwareProgram;
|
||||||
import com.jozufozu.flywheel.core.shader.WorldProgram;
|
import com.jozufozu.flywheel.core.shader.WorldProgram;
|
||||||
|
@ -88,7 +87,8 @@ public class WorldContext<P extends WorldProgram> implements ShaderContext<P> {
|
||||||
if (specStream == null) {
|
if (specStream == null) {
|
||||||
specStream = () -> backend.allMaterials()
|
specStream = () -> backend.allMaterials()
|
||||||
.stream()
|
.stream()
|
||||||
.map(MaterialSpec::getProgramName);
|
.map(type -> type.asInstanced()
|
||||||
|
.getProgramSpec());
|
||||||
}
|
}
|
||||||
return new WorldContext<>(backend, name, specStream, pipeline);
|
return new WorldContext<>(backend, name, specStream, pipeline);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.jozufozu.flywheel.core.materials.model;
|
package com.jozufozu.flywheel.core.materials.model;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.struct.BatchingTransformer;
|
import com.jozufozu.flywheel.api.struct.BatchingTransformer;
|
||||||
import com.jozufozu.flywheel.core.model.Model;
|
import com.jozufozu.flywheel.core.model.Model;
|
||||||
|
|
||||||
public class ModelTransformer extends BatchingTransformer<ModelData> {
|
public class ModelTransformer extends BatchingTransformer<ModelData> {
|
||||||
|
|
|
@ -2,15 +2,18 @@ package com.jozufozu.flywheel.core.materials.model;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
|
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
|
||||||
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
||||||
import com.jozufozu.flywheel.backend.struct.Batched;
|
import com.jozufozu.flywheel.api.struct.Batched;
|
||||||
import com.jozufozu.flywheel.backend.struct.BatchingTransformer;
|
import com.jozufozu.flywheel.api.struct.BatchingTransformer;
|
||||||
import com.jozufozu.flywheel.backend.struct.StructWriter;
|
import com.jozufozu.flywheel.api.struct.StructWriter;
|
||||||
import com.jozufozu.flywheel.backend.struct.Writeable;
|
import com.jozufozu.flywheel.api.struct.Instanced;
|
||||||
import com.jozufozu.flywheel.core.Formats;
|
import com.jozufozu.flywheel.core.Formats;
|
||||||
|
import com.jozufozu.flywheel.core.Programs;
|
||||||
import com.jozufozu.flywheel.core.materials.model.writer.UnsafeModelWriter;
|
import com.jozufozu.flywheel.core.materials.model.writer.UnsafeModelWriter;
|
||||||
import com.jozufozu.flywheel.core.model.Model;
|
import com.jozufozu.flywheel.core.model.Model;
|
||||||
|
|
||||||
public class ModelType implements Writeable<ModelData>, Batched<ModelData> {
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
|
public class ModelType implements Instanced<ModelData>, Batched<ModelData> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ModelData create() {
|
public ModelData create() {
|
||||||
|
@ -27,6 +30,11 @@ public class ModelType implements Writeable<ModelData>, Batched<ModelData> {
|
||||||
return new UnsafeModelWriter(backing, this);
|
return new UnsafeModelWriter(backing, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceLocation getProgramSpec() {
|
||||||
|
return Programs.TRANSFORMED;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BatchingTransformer<ModelData> getTransformer(Model model) {
|
public BatchingTransformer<ModelData> getTransformer(Model model) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault
|
||||||
|
package com.jozufozu.flywheel.core.materials.model;
|
||||||
|
|
||||||
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
|
|
||||||
|
import net.minecraft.MethodsReturnNonnullByDefault;
|
|
@ -3,7 +3,7 @@ package com.jozufozu.flywheel.core.materials.model.writer;
|
||||||
import org.lwjgl.system.MemoryUtil;
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
||||||
import com.jozufozu.flywheel.backend.struct.StructType;
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
import com.jozufozu.flywheel.backend.struct.UnsafeBufferWriter;
|
import com.jozufozu.flywheel.backend.struct.UnsafeBufferWriter;
|
||||||
import com.jozufozu.flywheel.core.materials.model.ModelData;
|
import com.jozufozu.flywheel.core.materials.model.ModelData;
|
||||||
import com.jozufozu.flywheel.util.WriteUnsafe;
|
import com.jozufozu.flywheel.util.WriteUnsafe;
|
||||||
|
|
|
@ -2,15 +2,18 @@ package com.jozufozu.flywheel.core.materials.oriented;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
|
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
|
||||||
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
||||||
import com.jozufozu.flywheel.backend.struct.Batched;
|
import com.jozufozu.flywheel.api.struct.Batched;
|
||||||
import com.jozufozu.flywheel.backend.struct.BatchingTransformer;
|
import com.jozufozu.flywheel.api.struct.BatchingTransformer;
|
||||||
import com.jozufozu.flywheel.backend.struct.StructWriter;
|
import com.jozufozu.flywheel.api.struct.StructWriter;
|
||||||
import com.jozufozu.flywheel.backend.struct.Writeable;
|
import com.jozufozu.flywheel.api.struct.Instanced;
|
||||||
import com.jozufozu.flywheel.core.Formats;
|
import com.jozufozu.flywheel.core.Formats;
|
||||||
|
import com.jozufozu.flywheel.core.Programs;
|
||||||
import com.jozufozu.flywheel.core.materials.oriented.writer.UnsafeOrientedWriter;
|
import com.jozufozu.flywheel.core.materials.oriented.writer.UnsafeOrientedWriter;
|
||||||
import com.jozufozu.flywheel.core.model.Model;
|
import com.jozufozu.flywheel.core.model.Model;
|
||||||
|
|
||||||
public class OrientedType implements Writeable<OrientedData>, Batched<OrientedData> {
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
|
public class OrientedType implements Instanced<OrientedData>, Batched<OrientedData> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OrientedData create() {
|
public OrientedData create() {
|
||||||
|
@ -27,6 +30,11 @@ public class OrientedType implements Writeable<OrientedData>, Batched<OrientedDa
|
||||||
return new UnsafeOrientedWriter(backing, this);
|
return new UnsafeOrientedWriter(backing, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceLocation getProgramSpec() {
|
||||||
|
return Programs.ORIENTED;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BatchingTransformer<OrientedData> getTransformer(Model model) {
|
public BatchingTransformer<OrientedData> getTransformer(Model model) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault
|
||||||
|
package com.jozufozu.flywheel.core.materials.oriented;
|
||||||
|
|
||||||
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
|
|
||||||
|
import net.minecraft.MethodsReturnNonnullByDefault;
|
|
@ -3,7 +3,7 @@ package com.jozufozu.flywheel.core.materials.oriented.writer;
|
||||||
import org.lwjgl.system.MemoryUtil;
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
||||||
import com.jozufozu.flywheel.backend.struct.StructType;
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
import com.jozufozu.flywheel.backend.struct.UnsafeBufferWriter;
|
import com.jozufozu.flywheel.backend.struct.UnsafeBufferWriter;
|
||||||
import com.jozufozu.flywheel.core.materials.oriented.OrientedData;
|
import com.jozufozu.flywheel.core.materials.oriented.OrientedData;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue