some attrib stuff

This commit is contained in:
JozsefA 2021-02-11 14:31:50 -08:00
parent 3820e11954
commit 576165e3d6
4 changed files with 89 additions and 16 deletions

View file

@ -7,4 +7,6 @@ public interface IVertexAttrib {
VertexAttribSpec attribSpec();
int getDivisor();
int getBufferIndex();
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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<Class<? extends Enum<? extends IVertexAttrib>>> allAttributes;
public VertexFormat2(ArrayList<Class<? extends Enum<? extends IVertexAttrib>>> allAttributes) {
this.allAttributes = allAttributes;
}
public static Builder builder() {
return new Builder();
}
public Stream<IVertexAttrib> getAttributeStream() {
return (Stream<IVertexAttrib>) allAttributes.stream().flatMap(it -> Arrays.stream(it.getEnumConstants()));
}
public static class Builder {
private final ArrayList<Class<? extends Enum<? extends IVertexAttrib>>> allAttributes;
public Builder() {
allAttributes = new ArrayList<>();
}
public <A extends Enum<A> & IVertexAttrib> Builder addAttributes(Class<A> attribEnum) {
allAttributes.add(attribEnum);
return this;
}
public VertexFormat2 build() {
return new VertexFormat2(allAttributes);
}
}
}