Skip to content

Commit

Permalink
Fix VertexConsumers
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Jun 6, 2024
1 parent fbdf995 commit eb3f7e0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,67 +26,46 @@ public void clear() {
}

@Override
public VertexConsumer vertex(double x, double y, double z) {
public VertexConsumer addVertex(float x, float y, float z) {
Matrix4f matrix = poseStack.last().pose();
float fx = (float) x;
float fy = (float) y;
float fz = (float) z;
delegate.vertex(
MatrixMath.transformPositionX(matrix, fx, fy, fz),
MatrixMath.transformPositionY(matrix, fx, fy, fz),
MatrixMath.transformPositionZ(matrix, fx, fy, fz));
delegate.addVertex(
MatrixMath.transformPositionX(matrix, x, y, z),
MatrixMath.transformPositionY(matrix, x, y, z),
MatrixMath.transformPositionZ(matrix, x, y, z));
return this;
}

@Override
public VertexConsumer color(int red, int green, int blue, int alpha) {
delegate.color(red, green, blue, alpha);
public VertexConsumer setColor(int red, int green, int blue, int alpha) {
delegate.setColor(red, green, blue, alpha);
return this;
}

@Override
public VertexConsumer uv(float u, float v) {
delegate.uv(u, v);
public VertexConsumer setUv(float u, float v) {
delegate.setUv(u, v);
return this;
}

@Override
public VertexConsumer overlayCoords(int u, int v) {
delegate.overlayCoords(u, v);
public VertexConsumer setUv1(int u, int v) {
delegate.setUv1(u, v);
return this;
}

@Override
public VertexConsumer uv2(int u, int v) {
delegate.uv2(u, v);
public VertexConsumer setUv2(int u, int v) {
delegate.setUv2(u, v);
return this;
}

@Override
public VertexConsumer normal(float x, float y, float z) {
public VertexConsumer setNormal(float x, float y, float z) {
Matrix3f matrix = poseStack.last().normal();
float fx = (float) x;
float fy = (float) y;
float fz = (float) z;
delegate.normal(
MatrixMath.transformNormalX(matrix, fx, fy, fz),
MatrixMath.transformNormalY(matrix, fx, fy, fz),
MatrixMath.transformNormalZ(matrix, fx, fy, fz));
delegate.setNormal(
MatrixMath.transformNormalX(matrix, x, y, z),
MatrixMath.transformNormalY(matrix, x, y, z),
MatrixMath.transformNormalZ(matrix, x, y, z));
return this;
}

@Override
public void endVertex() {
delegate.endVertex();
}

@Override
public void defaultColor(int red, int green, int blue, int alpha) {
delegate.defaultColor(red, green, blue, alpha);
}

@Override
public void unsetDefaultColor() {
delegate.unsetDefaultColor();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,25 @@ public void setTextureMapper(@Nullable TextureMapper mapper) {
}

@Override
public VertexConsumer vertex(double x, double y, double z) {
public VertexConsumer addVertex(float x, float y, float z) {
if (!filledPosition) {
long ptr = vertexPtr();
MemoryUtil.memPutFloat(ptr, (float) x);
MemoryUtil.memPutFloat(ptr + 4, (float) y);
MemoryUtil.memPutFloat(ptr + 8, (float) z);
MemoryUtil.memPutFloat(ptr, x);
MemoryUtil.memPutFloat(ptr + 4, y);
MemoryUtil.memPutFloat(ptr + 8, z);
filledPosition = true;
}
return this;
return this.endVertex();
}

@Override
public VertexConsumer color(int red, int green, int blue, int alpha) {
public VertexConsumer setColor(int red, int green, int blue, int alpha) {
// ignore color
return this;
return this.endVertex();
}

@Override
public VertexConsumer uv(float u, float v) {
public VertexConsumer setUv(float u, float v) {
if (!filledTexture) {
if (textureMapper != null) {
uvVec.set(u, v);
Expand All @@ -66,35 +66,34 @@ public VertexConsumer uv(float u, float v) {
MemoryUtil.memPutFloat(ptr + 16, v);
filledTexture = true;
}
return this;
return this.endVertex();
}

@Override
public VertexConsumer overlayCoords(int u, int v) {
public VertexConsumer setUv1(int u, int v) {
// ignore overlay
return this;
return this.endVertex();
}

@Override
public VertexConsumer uv2(int u, int v) {
public VertexConsumer setUv2(int u, int v) {
// ignore light
return this;
return this.endVertex();
}

@Override
public VertexConsumer normal(float x, float y, float z) {
public VertexConsumer setNormal(float x, float y, float z) {
if (!filledNormal) {
long ptr = vertexPtr();
MemoryUtil.memPutByte(ptr + 20, RenderMath.nb(x));
MemoryUtil.memPutByte(ptr + 21, RenderMath.nb(y));
MemoryUtil.memPutByte(ptr + 22, RenderMath.nb(z));
filledNormal = true;
}
return this;
return this.endVertex();
}

@Override
public void endVertex() {
public VertexConsumer endVertex() {
if (!filledPosition || !filledTexture || !filledNormal) {
throw new IllegalStateException("Not filled all elements of the vertex");
}
Expand All @@ -109,14 +108,8 @@ public void endVertex() {
if (byteSize > capacity) {
data = data.realloc(capacity * 2);
}
}

@Override
public void defaultColor(int red, int green, int blue, int alpha) {
}

@Override
public void unsetDefaultColor() {
return this;
}

private long vertexPtr() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,59 +56,45 @@ private void prepareForGeometry(RenderMaterial material) {
}

@Override
public VertexConsumer vertex(double x, double y, double z) {
currentDelegate.vertex(x, y, z);
public VertexConsumer addVertex(float x, float y, float z) {
currentDelegate.addVertex(x, y, z);
return this;
}

@Override
public VertexConsumer color(int red, int green, int blue, int alpha) {
currentDelegate.color(red, green, blue, alpha);
public VertexConsumer setColor(int red, int green, int blue, int alpha) {
currentDelegate.setColor(red, green, blue, alpha);
return this;
}

@Override
public VertexConsumer uv(float u, float v) {
currentDelegate.uv(u, v);
public VertexConsumer setUv(float u, float v) {
currentDelegate.setUv(u, v);
return this;
}

@Override
public VertexConsumer overlayCoords(int u, int v) {
currentDelegate.overlayCoords(u, v);
public VertexConsumer setUv1(int u, int v) {
currentDelegate.setUv1(u, v);
return this;
}

@Override
public VertexConsumer uv2(int u, int v) {
currentDelegate.uv2(u, v);
public VertexConsumer setUv2(int u, int v) {
currentDelegate.setUv2(u, v);
return this;
}

@Override
public VertexConsumer normal(float x, float y, float z) {
currentDelegate.normal(x, y, z);
public VertexConsumer setNormal(float x, float y, float z) {
currentDelegate.setNormal(x, y, z);
return this;
}

// todo - parameter mappings
@Override
public void endVertex() {
currentDelegate.endVertex();
}

@Override
public void defaultColor(int red, int green, int blue, int alpha) {
currentDelegate.defaultColor(red, green, blue, alpha);
}

@Override
public void unsetDefaultColor() {
currentDelegate.unsetDefaultColor();
}

@Override
public void vertex(float x, float y, float z, float red, float green, float blue, float alpha, float u, float v, int overlay, int light, float normalX, float normalY, float normalZ) {
currentDelegate.vertex(x, y, z, red, green, blue, alpha, u, v, overlay, light, normalX, normalY, normalZ);
public void addVertex(float f, float g, float h, int i, float j, float k, int l, int m, float n, float o, float p) {
currentDelegate.addVertex(f, g, h, i, j, k, l, m, n, o, p);
}

@Override
Expand Down

0 comments on commit eb3f7e0

Please sign in to comment.