Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepare for vertex array usage #21

Merged
merged 3 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/main/java/com/enderio/core/client/render/RenderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,24 @@ public static void addVerticesToTessellator(List<Vertex> vertices, Tessellator t
}
}

public static void addVerticesToTessellator(Vertex[] vertices, Tessellator tes) {
for (int i = 0; i < vertices.length; i++) {
if (vertices[i].brightness != -1) {
tes.setBrightness(vertices[i].brightness);
}
if (vertices[i].color != null) {
tes.setColorRGBA_F(vertices[i].r(), vertices[i].g(), vertices[i].b(), vertices[i].a());
}
if (vertices[i].uv != null) {
tes.setTextureUV(vertices[i].u(), vertices[i].v());
}
if (vertices[i].normal != null) {
tes.setNormal(vertices[i].nx(), vertices[i].ny(), vertices[i].nz());
}
tes.addVertex(vertices[i].x(), vertices[i].y(), vertices[i].z());
}
}

public static void renderConnectedTextureFace(IBlockAccess blockAccess, Block block, int x, int y, int z,
ForgeDirection face, IIcon texture, boolean forceAllEdges) {
renderConnectedTextureFace(blockAccess, block, x, y, z, face, texture, forceAllEdges, true, true);
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/com/enderio/core/common/vecmath/Vertex.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
public class Vertex {

public Vector3d xyz = new Vector3d();

/*
* some parts of EIO are relying on nulls as special values, can't just pre allocate new objects and set them when
* required, unless everything relying on nulls is rewritten
*/
public Vector2f uv = null;
public Vector3f normal = null;
public Vector4f color = null;
Expand Down Expand Up @@ -76,6 +81,42 @@ public void setBrightness(int brightness) {
this.brightness = brightness;
}

public void set(Vertex other) {
xyz.set(other.xyz);

if (other.uv != null) {
if (uv == null) {
uv = new Vector2f(other.uv);
} else {
uv.set(other.uv);
}
} else {
uv = null;
}

if (other.normal != null) {
if (normal == null) {
normal = new Vector3f(other.normal);
} else {
normal.set(other.normal);
}
} else {
normal = null;
}

if (other.color != null) {
if (color == null) {
color = new Vector4f(other.color);
} else {
color.set(other.color);
}
} else {
color = null;
}

brightness = other.brightness;
}

public Vector4f getColor() {
return color;
}
Expand Down