Skip to content

Commit

Permalink
fix vertex writer endVertex
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Jun 8, 2024
1 parent 0d61c8d commit 99edb31
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public VertexConsumer addVertex(float x, float y, float z) {
MemoryUtil.memPutFloat(ptr + 8, z);
filledPosition = true;
}
return this;

return this.endVertex();
}

@Override
Expand Down Expand Up @@ -93,6 +94,25 @@ public VertexConsumer setNormal(float x, float y, float z) {
return this;
}

public VertexConsumer endVertex() {
if ((!filledPosition || !filledTexture || !filledNormal) && vertexCount != 0) {
throw new IllegalStateException("Not filled all elements of the vertex");
}

filledPosition = false;
filledTexture = false;
filledNormal = false;
vertexCount++;

long byteSize = (vertexCount + 1) * STRIDE;
long capacity = data.size();
if (byteSize > capacity) {
data = data.realloc(capacity * 2);
}

return this;
}

private long vertexPtr() {
return data.ptr() + vertexCount * STRIDE;
}
Expand Down

0 comments on commit 99edb31

Please sign in to comment.