mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-27 07:26:48 +01:00
Internal overlay
- Add overlay to internal vertex format. - Move interval vertex format related constants to helper class. - Switch strides to long so java stops complaining about implicit casts in multiplication. - Remove VertexTypes#init as it's not needed anymore.
This commit is contained in:
parent
eace28cdd8
commit
1808d615d0
14 changed files with 257 additions and 50 deletions
|
@ -32,7 +32,6 @@ import com.jozufozu.flywheel.lib.model.baked.PartialModel;
|
|||
import com.jozufozu.flywheel.lib.util.LevelAttached;
|
||||
import com.jozufozu.flywheel.lib.util.ShadersModHandler;
|
||||
import com.jozufozu.flywheel.lib.util.StringUtil;
|
||||
import com.jozufozu.flywheel.lib.vertex.VertexTypes;
|
||||
import com.jozufozu.flywheel.vanilla.VanillaVisuals;
|
||||
import com.mojang.logging.LogUtils;
|
||||
|
||||
|
@ -129,7 +128,6 @@ public class Flywheel {
|
|||
}
|
||||
|
||||
private static void onClientSetup(FMLClientSetupEvent event) {
|
||||
VertexTypes.init();
|
||||
InstanceTypes.init();
|
||||
CutoutShaders.init();
|
||||
FogShaders.init();
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package com.jozufozu.flywheel.backend;
|
||||
|
||||
import com.jozufozu.flywheel.api.layout.BufferLayout;
|
||||
import com.jozufozu.flywheel.api.vertex.ReusableVertexList;
|
||||
import com.jozufozu.flywheel.lib.vertex.FullVertex;
|
||||
import com.jozufozu.flywheel.lib.vertex.FullVertexList;
|
||||
|
||||
public class InternalLayout {
|
||||
public static final BufferLayout LAYOUT = FullVertex.FORMAT;
|
||||
|
||||
public static ReusableVertexList createVertexList() {
|
||||
return new FullVertexList();
|
||||
}
|
||||
}
|
|
@ -3,11 +3,11 @@ package com.jozufozu.flywheel.backend.compile;
|
|||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.jozufozu.flywheel.backend.InternalLayout;
|
||||
import com.jozufozu.flywheel.backend.compile.component.UniformComponent;
|
||||
import com.jozufozu.flywheel.gl.shader.ShaderType;
|
||||
import com.jozufozu.flywheel.glsl.ShaderSources;
|
||||
import com.jozufozu.flywheel.glsl.SourceComponent;
|
||||
import com.jozufozu.flywheel.lib.vertex.BlockVertex;
|
||||
|
||||
public class PipelineCompiler {
|
||||
private static final Compile<PipelineProgramKey> PIPELINE = new Compile<>();
|
||||
|
@ -19,7 +19,7 @@ public class PipelineCompiler {
|
|||
.link(PIPELINE.shader(pipeline.glslVersion(), ShaderType.VERTEX)
|
||||
.withComponent(uniformComponent)
|
||||
.withComponent(key -> pipeline.assembler()
|
||||
.assemble(new Pipeline.InstanceAssemblerContext(BlockVertex.FORMAT.getAttributeCount(), key.instanceType())))
|
||||
.assemble(new Pipeline.InstanceAssemblerContext(InternalLayout.LAYOUT.getAttributeCount(), key.instanceType())))
|
||||
.withResource(pipeline.vertexAPI())
|
||||
.withComponents(vertexComponents)
|
||||
.withResource(key -> key.instanceType()
|
||||
|
|
|
@ -8,19 +8,15 @@ import java.util.Map;
|
|||
import org.jetbrains.annotations.Nullable;
|
||||
import org.joml.Vector4fc;
|
||||
|
||||
import com.jozufozu.flywheel.api.layout.BufferLayout;
|
||||
import com.jozufozu.flywheel.api.model.Mesh;
|
||||
import com.jozufozu.flywheel.backend.InternalLayout;
|
||||
import com.jozufozu.flywheel.gl.GlNumericType;
|
||||
import com.jozufozu.flywheel.gl.array.GlVertexArray;
|
||||
import com.jozufozu.flywheel.gl.buffer.GlBuffer;
|
||||
import com.jozufozu.flywheel.lib.memory.MemoryBlock;
|
||||
import com.jozufozu.flywheel.lib.model.QuadIndexSequence;
|
||||
import com.jozufozu.flywheel.lib.vertex.BlockVertex;
|
||||
import com.jozufozu.flywheel.lib.vertex.BlockVertexList;
|
||||
|
||||
public class IndirectMeshPool {
|
||||
private static final BufferLayout LAYOUT = BlockVertex.FORMAT;
|
||||
|
||||
private final Map<Mesh, BufferedMesh> meshes = new HashMap<>();
|
||||
private final List<BufferedMesh> meshList = new ArrayList<>();
|
||||
|
||||
|
@ -39,8 +35,8 @@ public class IndirectMeshPool {
|
|||
vertexArray = GlVertexArray.create();
|
||||
|
||||
vertexArray.setElementBuffer(ebo.handle());
|
||||
vertexArray.bindVertexBuffer(0, vbo.handle(), 0, LAYOUT.getStride());
|
||||
vertexArray.bindAttributes(0, 0, LAYOUT.attributes());
|
||||
vertexArray.bindVertexBuffer(0, vbo.handle(), 0, InternalLayout.LAYOUT.getStride());
|
||||
vertexArray.bindAttributes(0, 0, InternalLayout.LAYOUT.attributes());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,7 +89,7 @@ public class IndirectMeshPool {
|
|||
final long vertexPtr = vertexBlock.ptr();
|
||||
final long indexPtr = indexBlock.ptr();
|
||||
|
||||
var target = new BlockVertexList();
|
||||
var target = InternalLayout.createVertexList();
|
||||
|
||||
int byteIndex = 0;
|
||||
int baseVertex = 0;
|
||||
|
@ -154,7 +150,7 @@ public class IndirectMeshPool {
|
|||
}
|
||||
|
||||
public int size() {
|
||||
return mesh.vertexCount() * LAYOUT.getStride();
|
||||
return mesh.vertexCount() * InternalLayout.LAYOUT.getStride();
|
||||
}
|
||||
|
||||
public int indexCount() {
|
||||
|
|
|
@ -11,18 +11,14 @@ import org.jetbrains.annotations.Nullable;
|
|||
import org.lwjgl.opengl.GL32;
|
||||
|
||||
import com.jozufozu.flywheel.Flywheel;
|
||||
import com.jozufozu.flywheel.api.layout.BufferLayout;
|
||||
import com.jozufozu.flywheel.api.model.Mesh;
|
||||
import com.jozufozu.flywheel.backend.InternalLayout;
|
||||
import com.jozufozu.flywheel.gl.GlPrimitive;
|
||||
import com.jozufozu.flywheel.gl.array.GlVertexArray;
|
||||
import com.jozufozu.flywheel.gl.buffer.GlBuffer;
|
||||
import com.jozufozu.flywheel.gl.buffer.MappedBuffer;
|
||||
import com.jozufozu.flywheel.lib.vertex.BlockVertex;
|
||||
import com.jozufozu.flywheel.lib.vertex.BlockVertexList;
|
||||
|
||||
public class InstancedMeshPool {
|
||||
private static final BufferLayout LAYOUT = BlockVertex.FORMAT;
|
||||
|
||||
private final Map<Mesh, BufferedMesh> meshes = new HashMap<>();
|
||||
private final List<BufferedMesh> allBuffered = new ArrayList<>();
|
||||
private final List<BufferedMesh> pendingUpload = new ArrayList<>();
|
||||
|
@ -37,7 +33,7 @@ public class InstancedMeshPool {
|
|||
* Create a new mesh pool.
|
||||
*/
|
||||
public InstancedMeshPool() {
|
||||
int stride = LAYOUT.getStride();
|
||||
int stride = InternalLayout.LAYOUT.getStride();
|
||||
vbo = new GlBuffer();
|
||||
vbo.growthFunction(l -> Math.max(l + stride * 128L, (long) (l * 1.6)));
|
||||
}
|
||||
|
@ -113,7 +109,7 @@ public class InstancedMeshPool {
|
|||
try (MappedBuffer mapped = vbo.map()) {
|
||||
long ptr = mapped.ptr();
|
||||
|
||||
var vertexList = new BlockVertexList();
|
||||
var vertexList = InternalLayout.createVertexList();
|
||||
|
||||
for (BufferedMesh mesh : pendingUpload) {
|
||||
vertexList.ptr(ptr + mesh.byteIndex);
|
||||
|
@ -154,11 +150,11 @@ public class InstancedMeshPool {
|
|||
}
|
||||
|
||||
public int size() {
|
||||
return mesh.vertexCount() * LAYOUT.getStride();
|
||||
return mesh.vertexCount() * InternalLayout.LAYOUT.getStride();
|
||||
}
|
||||
|
||||
public int getAttributeCount() {
|
||||
return LAYOUT.getAttributeCount();
|
||||
return InternalLayout.LAYOUT.getAttributeCount();
|
||||
}
|
||||
|
||||
public boolean isDeleted() {
|
||||
|
@ -171,8 +167,8 @@ public class InstancedMeshPool {
|
|||
|
||||
public void setup(GlVertexArray vao) {
|
||||
if (boundTo.add(vao)) {
|
||||
vao.bindVertexBuffer(0, InstancedMeshPool.this.vbo.handle(), byteIndex, LAYOUT.getStride());
|
||||
vao.bindAttributes(0, 0, LAYOUT.attributes());
|
||||
vao.bindVertexBuffer(0, InstancedMeshPool.this.vbo.handle(), byteIndex, InternalLayout.LAYOUT.getStride());
|
||||
vao.bindAttributes(0, 0, InternalLayout.LAYOUT.attributes());
|
||||
vao.setElementBuffer(ebo);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import com.jozufozu.flywheel.lib.math.RenderMath;
|
|||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
|
||||
public class BlockVertexList extends AbstractVertexList {
|
||||
private static final int STRIDE = 32;
|
||||
private static final long STRIDE = 32;
|
||||
|
||||
@Override
|
||||
public float x(int index) {
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package com.jozufozu.flywheel.lib.vertex;
|
||||
|
||||
import com.jozufozu.flywheel.api.layout.BufferLayout;
|
||||
import com.jozufozu.flywheel.api.vertex.VertexType;
|
||||
import com.jozufozu.flywheel.lib.layout.CommonItems;
|
||||
|
||||
public class FullVertex implements VertexType {
|
||||
public static final BufferLayout FORMAT = BufferLayout.builder()
|
||||
.addItem(CommonItems.VEC3, "position")
|
||||
.addItem(CommonItems.UNORM_4x8, "color")
|
||||
.addItem(CommonItems.VEC2, "tex")
|
||||
.addItem(CommonItems.LIGHT_COORD, "overlay")
|
||||
.addItem(CommonItems.LIGHT_COORD, "light")
|
||||
.addItem(CommonItems.NORM_3x8, "normal")
|
||||
.withPadding(1)
|
||||
.build();
|
||||
|
||||
@Override
|
||||
public int getStride() {
|
||||
return FORMAT.getStride();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FullVertexList createVertexList() {
|
||||
return new FullVertexList();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,180 @@
|
|||
package com.jozufozu.flywheel.lib.vertex;
|
||||
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
|
||||
import com.jozufozu.flywheel.api.vertex.MutableVertexList;
|
||||
import com.jozufozu.flywheel.lib.math.RenderMath;
|
||||
|
||||
public class FullVertexList extends AbstractVertexList {
|
||||
private static final long STRIDE = 36;
|
||||
|
||||
@Override
|
||||
public float x(int index) {
|
||||
return MemoryUtil.memGetFloat(ptr + index * STRIDE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float y(int index) {
|
||||
return MemoryUtil.memGetFloat(ptr + index * STRIDE + 4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float z(int index) {
|
||||
return MemoryUtil.memGetFloat(ptr + index * STRIDE + 8);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float r(int index) {
|
||||
return RenderMath.uf(MemoryUtil.memGetByte(ptr + index * STRIDE + 12));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float g(int index) {
|
||||
return RenderMath.uf(MemoryUtil.memGetByte(ptr + index * STRIDE + 13));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float b(int index) {
|
||||
return RenderMath.uf(MemoryUtil.memGetByte(ptr + index * STRIDE + 14));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float a(int index) {
|
||||
return RenderMath.uf(MemoryUtil.memGetByte(ptr + index * STRIDE + 15));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float u(int index) {
|
||||
return MemoryUtil.memGetFloat(ptr + index * STRIDE + 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float v(int index) {
|
||||
return MemoryUtil.memGetFloat(ptr + index * STRIDE + 20);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int overlay(int index) {
|
||||
return MemoryUtil.memGetInt(ptr + index * STRIDE + 24);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int light(int index) {
|
||||
return MemoryUtil.memGetInt(ptr + index * STRIDE + 28) << 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float normalX(int index) {
|
||||
return RenderMath.f(MemoryUtil.memGetByte(ptr + index * STRIDE + 32));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float normalY(int index) {
|
||||
return RenderMath.f(MemoryUtil.memGetByte(ptr + index * STRIDE + 33));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float normalZ(int index) {
|
||||
return RenderMath.f(MemoryUtil.memGetByte(ptr + index * STRIDE + 34));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void x(int index, float x) {
|
||||
MemoryUtil.memPutFloat(ptr + index * STRIDE, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void y(int index, float y) {
|
||||
MemoryUtil.memPutFloat(ptr + index * STRIDE + 4, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void z(int index, float z) {
|
||||
MemoryUtil.memPutFloat(ptr + index * STRIDE + 8, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void r(int index, float r) {
|
||||
MemoryUtil.memPutByte(ptr + index * STRIDE + 12, RenderMath.unb(r));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void g(int index, float g) {
|
||||
MemoryUtil.memPutByte(ptr + index * STRIDE + 13, RenderMath.unb(g));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void b(int index, float b) {
|
||||
MemoryUtil.memPutByte(ptr + index * STRIDE + 14, RenderMath.unb(b));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void a(int index, float a) {
|
||||
MemoryUtil.memPutByte(ptr + index * STRIDE + 15, RenderMath.unb(a));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void u(int index, float u) {
|
||||
MemoryUtil.memPutFloat(ptr + index * STRIDE + 16, u);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void v(int index, float v) {
|
||||
MemoryUtil.memPutFloat(ptr + index * STRIDE + 20, v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void overlay(int index, int overlay) {
|
||||
MemoryUtil.memPutInt(ptr + index * STRIDE + 24, overlay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void light(int index, int light) {
|
||||
MemoryUtil.memPutInt(ptr + index * STRIDE + 28, light >> 4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void normalX(int index, float normalX) {
|
||||
MemoryUtil.memPutByte(ptr + index * STRIDE + 32, RenderMath.nb(normalX));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void normalY(int index, float normalY) {
|
||||
MemoryUtil.memPutByte(ptr + index * STRIDE + 33, RenderMath.nb(normalY));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void normalZ(int index, float normalZ) {
|
||||
MemoryUtil.memPutByte(ptr + index * STRIDE + 34, RenderMath.nb(normalZ));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(MutableVertexList dst, int srcIndex, int dstIndex) {
|
||||
if (getClass() == dst.getClass()) {
|
||||
long dstPtr = ((FullVertexList) dst).ptr;
|
||||
MemoryUtil.memCopy(ptr + srcIndex * STRIDE, dstPtr + dstIndex * STRIDE, STRIDE);
|
||||
} else {
|
||||
super.write(dst, srcIndex, dstIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(MutableVertexList dst, int srcStartIndex, int dstStartIndex, int vertexCount) {
|
||||
if (getClass() == dst.getClass()) {
|
||||
long dstPtr = ((FullVertexList) dst).ptr;
|
||||
MemoryUtil.memCopy(ptr + srcStartIndex * STRIDE, dstPtr + dstStartIndex * STRIDE, vertexCount * STRIDE);
|
||||
} else {
|
||||
super.write(dst, srcStartIndex, dstStartIndex, vertexCount);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeAll(MutableVertexList dst) {
|
||||
if (getClass() == dst.getClass()) {
|
||||
long dstPtr = ((FullVertexList) dst).ptr;
|
||||
MemoryUtil.memCopy(ptr, dstPtr, vertexCount * STRIDE);
|
||||
} else {
|
||||
super.writeAll(dst);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@ import net.minecraft.client.renderer.LightTexture;
|
|||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
|
||||
public class PosTexNormalVertexList extends AbstractVertexList {
|
||||
private static final int STRIDE = 23;
|
||||
private static final long STRIDE = 23;
|
||||
|
||||
@Override
|
||||
public float x(int index) {
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
package com.jozufozu.flywheel.lib.vertex;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
public final class VertexTypes {
|
||||
public static final BlockVertex BLOCK = new BlockVertex();
|
||||
public static final PosTexNormalVertex POS_TEX_NORMAL = new PosTexNormalVertex();
|
||||
public static final FullVertex FULL = new FullVertex();
|
||||
|
||||
private VertexTypes() {
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static void init() {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
#include "flywheel:api/vertex.glsl"
|
||||
|
||||
layout(location = 0) in vec3 v_pos;
|
||||
layout(location = 1) in vec4 v_color;
|
||||
layout(location = 2) in vec2 v_texCoord;
|
||||
layout(location = 3) in ivec2 v_light;
|
||||
layout(location = 4) in vec3 v_normal;
|
||||
|
||||
void _flw_layoutVertex() {
|
||||
flw_vertexPos = vec4(v_pos, 1.0);
|
||||
flw_vertexColor = v_color;
|
||||
flw_vertexTexCoord = v_texCoord;
|
||||
flw_vertexOverlay = ivec2(0, 10);
|
||||
flw_vertexLight = v_light / 15.0;
|
||||
flw_vertexNormal = v_normal;
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
#include "flywheel:internal/indirect/draw_command.glsl"
|
||||
#include "flywheel:internal/indirect/object.glsl"
|
||||
#include "flywheel:internal/material.glsl"
|
||||
#include "flywheel:internal/block.vert"
|
||||
#include "flywheel:internal/vertex_input.glsl"
|
||||
#include "flywheel:util/diffuse.glsl"
|
||||
|
||||
flat out uvec3 _flw_material;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "flywheel:internal/instancing/api/vertex.glsl"
|
||||
#include "flywheel:internal/material.glsl"
|
||||
#include "flywheel:internal/block.vert"
|
||||
#include "flywheel:internal/vertex_input.glsl"
|
||||
#include "flywheel:util/diffuse.glsl"
|
||||
|
||||
uniform uvec4 _flw_packedMaterial;
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
#include "flywheel:api/vertex.glsl"
|
||||
|
||||
layout(location = 0) in vec3 _flw_pos;
|
||||
layout(location = 1) in vec4 _flw_color;
|
||||
layout(location = 2) in vec2 _flw_texCoord;
|
||||
layout(location = 3) in ivec2 _flw_overlay;
|
||||
layout(location = 4) in ivec2 _flw_light;
|
||||
layout(location = 5) in vec3 _flw_normal;
|
||||
|
||||
void _flw_layoutVertex() {
|
||||
flw_vertexPos = vec4(_flw_pos, 1.0);
|
||||
flw_vertexColor = _flw_color;
|
||||
flw_vertexTexCoord = _flw_texCoord;
|
||||
flw_vertexOverlay = _flw_overlay;
|
||||
flw_vertexLight = _flw_light / 15.0;
|
||||
flw_vertexNormal = _flw_normal;
|
||||
}
|
Loading…
Reference in a new issue