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

Minor optimization to renderGuiTank() #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
21 changes: 10 additions & 11 deletions src/main/java/com/enderio/core/client/render/RenderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,11 @@ public static void renderGuiTank(FluidStack fluid, int capacity, int amount, dou
}
}

double minU = icon.getMinU();
double maxU = icon.getMaxU();
double minV = icon.getMinV();
double maxV = icon.getMaxV();

int renderAmount = (int) Math.max(Math.min(height, amount * height / capacity), 1);
int posY = (int) (y + height - renderAmount);

Expand All @@ -583,28 +588,22 @@ public static void renderGuiTank(FluidStack fluid, int capacity, int amount, dou
GL11.glColor3ub((byte) (color >> 16 & 0xFF), (byte) (color >> 8 & 0xFF), (byte) (color & 0xFF));

GL11.glEnable(GL11.GL_BLEND);
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
for (int i = 0; i < width; i += 16) {
int drawWidth = (int) Math.min(width - i, 16);
int drawX = (int) (x + i);
for (int j = 0; j < renderAmount; j += 16) {
int drawWidth = (int) Math.min(width - i, 16);
int drawHeight = Math.min(renderAmount - j, 16);

int drawX = (int) (x + i);
int drawY = posY + j;

double minU = icon.getMinU();
double maxU = icon.getMaxU();
double minV = icon.getMinV();
double maxV = icon.getMaxV();

Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.addVertexWithUV(drawX, drawY + drawHeight, 0, minU, minV + (maxV - minV) * drawHeight / 16F);
tessellator.addVertexWithUV(drawX + drawWidth, drawY + drawHeight, 0, minU + (maxU - minU) * drawWidth / 16F, minV + (maxV - minV) * drawHeight / 16F);
tessellator.addVertexWithUV(drawX + drawWidth, drawY, 0, minU + (maxU - minU) * drawWidth / 16F, minV);
tessellator.addVertexWithUV(drawX, drawY, 0, minU, minV);
tessellator.draw();
}
}
tessellator.draw();
GL11.glDisable(GL11.GL_BLEND);
}

Expand Down