From 576165e3d697b7d7845caf0237f36e0f6f1cc014 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Thu, 11 Feb 2021 14:31:50 -0800 Subject: [PATCH] some attrib stuff --- .../render/gl/attrib/IVertexAttrib.java | 2 + .../gl/attrib/ModelVertexAttributes.java | 36 +++++++++++++++++ .../gl/attrib/RotatingVertexAttributes.java | 28 ++++++------- .../render/gl/attrib/VertexFormat2.java | 39 +++++++++++++++++++ 4 files changed, 89 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/attrib/ModelVertexAttributes.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexFormat2.java diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/IVertexAttrib.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/IVertexAttrib.java index 30ef9ad45..8996f14ac 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/IVertexAttrib.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/IVertexAttrib.java @@ -7,4 +7,6 @@ public interface IVertexAttrib { VertexAttribSpec attribSpec(); int getDivisor(); + + int getBufferIndex(); } diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/ModelVertexAttributes.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/ModelVertexAttributes.java new file mode 100644 index 000000000..5b81e5a1f --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/ModelVertexAttributes.java @@ -0,0 +1,36 @@ +package com.simibubi.create.foundation.render.gl.attrib; + +public enum ModelVertexAttributes implements IVertexAttrib { + VERTEX_POSITION("aPos", CommonAttributes.VEC3), + NORMAL("aNormal", CommonAttributes.NORMAL), + TEXTURE("aTexCoords", CommonAttributes.UV), + ; + + private final String name; + private final VertexAttribSpec spec; + + ModelVertexAttributes(String name, VertexAttribSpec spec) { + this.name = name; + this.spec = spec; + } + + @Override + public String attribName() { + return name; + } + + @Override + public VertexAttribSpec attribSpec() { + return spec; + } + + @Override + public int getDivisor() { + return 0; + } + + @Override + public int getBufferIndex() { + return 0; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/RotatingVertexAttributes.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/RotatingVertexAttributes.java index efd958688..424700255 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/RotatingVertexAttributes.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/RotatingVertexAttributes.java @@ -1,29 +1,20 @@ package com.simibubi.create.foundation.render.gl.attrib; public enum RotatingVertexAttributes implements IVertexAttrib { - VERTEX_POSITION("aPos", CommonAttributes.VEC3), - NORMAL("aNormal", CommonAttributes.VEC3), - TEXTURE("aInstancePos", CommonAttributes.VEC3), - INSTANCE_POSITION("aInstancePos", CommonAttributes.VEC3, 1), - LIGHT("aLight", CommonAttributes.LIGHT, 1), - NETWORK_COLOR("aNetworkTint", CommonAttributes.RGB, 1), - SPEED("aSpeed", CommonAttributes.FLOAT, 1), - OFFSET("aOffset", CommonAttributes.FLOAT, 1), - AXIS("aAxis", CommonAttributes.NORMAL, 1), + INSTANCE_POSITION("aInstancePos", CommonAttributes.VEC3), + LIGHT("aLight", CommonAttributes.LIGHT), + NETWORK_COLOR("aNetworkTint", CommonAttributes.RGB), + SPEED("aSpeed", CommonAttributes.FLOAT), + OFFSET("aOffset", CommonAttributes.FLOAT), + AXIS("aAxis", CommonAttributes.NORMAL), ; private final String name; private final VertexAttribSpec spec; - private final int divisor; RotatingVertexAttributes(String name, VertexAttribSpec spec) { - this(name, spec, 0); - } - - RotatingVertexAttributes(String name, VertexAttribSpec spec, int divisor) { this.name = name; this.spec = spec; - this.divisor = divisor; } @Override @@ -38,6 +29,11 @@ public enum RotatingVertexAttributes implements IVertexAttrib { @Override public int getDivisor() { - return divisor; + return 1; + } + + @Override + public int getBufferIndex() { + return 1; } } diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexFormat2.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexFormat2.java new file mode 100644 index 000000000..497b7e136 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexFormat2.java @@ -0,0 +1,39 @@ +package com.simibubi.create.foundation.render.gl.attrib; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.stream.Stream; + +public class VertexFormat2 { + + private final ArrayList>> allAttributes; + + public VertexFormat2(ArrayList>> allAttributes) { + this.allAttributes = allAttributes; + } + + public static Builder builder() { + return new Builder(); + } + + public Stream getAttributeStream() { + return (Stream) allAttributes.stream().flatMap(it -> Arrays.stream(it.getEnumConstants())); + } + + public static class Builder { + private final ArrayList>> allAttributes; + + public Builder() { + allAttributes = new ArrayList<>(); + } + + public & IVertexAttrib> Builder addAttributes(Class attribEnum) { + allAttributes.add(attribEnum); + return this; + } + + public VertexFormat2 build() { + return new VertexFormat2(allAttributes); + } + } +}