Skip to content

Commit

Permalink
use CCRenderState instance to allow for multithreaded rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexdoru committed Oct 3, 2024
1 parent c56614a commit b45c75f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
final CCRenderState state = CCRenderState.instance();
switch (item.getItemDamage() >> 12) {
case 0:
EnderChestRenderer.renderChest(rotation, freq, !owner.equals("global"), x, y, z, 0, 0);
EnderChestRenderer.renderChest(state, rotation, freq, !owner.equals("global"), x, y, z, 0, 0);
break;
case 1:
CCRenderState.reset();
CCRenderState.pullLightmap();
state.reset();
state.pullLightmap();
state.useNormals = true;
EnderTankRenderer.renderTank(rotation, 0, freq, !owner.equals("global"), x, y, z, 0, false);
EnderTankRenderer.renderTank(state, rotation, 0, freq, !owner.equals("global"), x, y, z, 0, false);
EnderTankRenderer.renderLiquid(TankSynchroniser.getClientLiquid(freq, owner), x, y, z);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ public class EnderChestRenderer extends TileEntitySpecialRenderer {

public EnderChestRenderer() {}

public static void renderChest(int rotation, int freq, boolean owned, double x, double y, double z, int offset,
float lidAngle) {
public static void renderChest(CCRenderState state, int rotation, int freq, boolean owned, double x, double y,
double z, int offset, float lidAngle) {
final boolean isChestOpen = lidAngle < 0f;
if (isChestOpen && !EnderStorage.disableFXChest) {
renderEndPortal.renderAt(x, y, z);
}
GL11.glColor4f(1, 1, 1, 1);

CCRenderState.changeTexture("enderstorage:textures/enderchest.png");
state.changeTexture("enderstorage:textures/enderchest.png");
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
GL11.glPushMatrix();
GL11.glColor4f(1, 1, 1, 1);
Expand All @@ -48,7 +48,7 @@ public static void renderChest(int rotation, int freq, boolean owned, double x,

GL11.glPushMatrix();
GL11.glTranslated(x, y, z);
CCRenderState.changeTexture("enderstorage:textures/buttons.png");
state.changeTexture("enderstorage:textures/buttons.png");
drawButton(0, EnderStorageManager.getColourFromFreq(freq, 0), rotation, lidAngle);
drawButton(1, EnderStorageManager.getColourFromFreq(freq, 1), rotation, lidAngle);
drawButton(2, EnderStorageManager.getColourFromFreq(freq, 2), rotation, lidAngle);
Expand All @@ -66,10 +66,10 @@ public static void renderChest(int rotation, int freq, boolean owned, double x,
0.04);

GL11.glDisable(GL11.GL_LIGHTING);
CCRenderState.changeTexture("enderstorage:textures/hedronmap.png");
CCRenderState.startDrawing(4);
state.changeTexture("enderstorage:textures/hedronmap.png");
state.startDrawing(4);
CCModelLibrary.icosahedron4.render(pearlMat);
CCRenderState.draw();
state.draw();
GL11.glEnable(GL11.GL_LIGHTING);
}
}
Expand Down Expand Up @@ -122,12 +122,13 @@ private static void addVecWithUV(Vector3 vec, double u, double v) {

public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float partialTicks) {
final CCRenderState state = CCRenderState.instance();
CCRenderState.reset();
CCRenderState.setBrightness(tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord);
state.reset();
state.setBrightness(tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord);
state.useNormals = true;

TileEnderChest chest = (TileEnderChest) tile;
renderChest(
state,
chest.rotation,
chest.freq,
!chest.owner.equals("global"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@ public void renderTileEntityAt(TileEntity tile, double x, double y, double z, fl
TileEnderTank tank = (TileEnderTank) tile;

final CCRenderState state = CCRenderState.instance();
CCRenderState.reset();
CCRenderState.pullLightmap();
state.reset();
state.pullLightmap();
state.useNormals = true;

renderTank(
state,
tank.rotation,
(float) MathHelper.interpolate(tank.pressure_state.b_rotate, tank.pressure_state.a_rotate, f)
* 0.01745F,
Expand All @@ -117,8 +118,8 @@ private static boolean shouldRenderFx(TileEntity tile) {
/**
* @param renderFx set to true to render the portal texture and the floating hedron
*/
public static void renderTank(int rotation, float valve, int freq, boolean owned, double x, double y, double z,
int offset, boolean renderFx) {
public static void renderTank(CCRenderState state, int rotation, float valve, int freq, boolean owned, double x,
double y, double z, int offset, boolean renderFx) {
if (renderFx && !EnderStorage.disableFXTank) {
renderEndPortal.renderAt(x, y, z);
}
Expand All @@ -129,25 +130,25 @@ public static void renderTank(int rotation, float valve, int freq, boolean owned
GL11.glTranslated(x + 0.5, y, z + 0.5);
GL11.glRotatef(-90 * (rotation + 2), 0, 1, 0);

CCRenderState.changeTexture("enderstorage:textures/endertank.png");
CCRenderState.startDrawing(4);
state.changeTexture("enderstorage:textures/endertank.png");
state.startDrawing(4);
tankModel.render();
CCRenderState.draw();
state.draw();

CCRenderState.changeTexture("enderstorage:textures/buttons.png");
CCRenderState.startDrawing(7);
state.changeTexture("enderstorage:textures/buttons.png");
state.startDrawing(7);
for (int i = 0; i < 3; i++) {
int colour = EnderStorageManager.getColourFromFreq(freq, i);
buttons[i].render(UVTranslationButtons[colour]);
}
CCRenderState.draw();
state.draw();

new Rotation(valve, Z).at(point).glApply();

CCRenderState.changeTexture("enderstorage:textures/endertank.png");
CCRenderState.startDrawing(4);
state.changeTexture("enderstorage:textures/endertank.png");
state.startDrawing(4);
valveModel.render(owned ? UVTvalveOwned : UVTvalveNotOwned);
CCRenderState.draw();
state.draw();
GL11.glPopMatrix();
GL11.glDisable(GL12.GL_RESCALE_NORMAL);

Expand All @@ -158,10 +159,10 @@ public static void renderTank(int rotation, float valve, int freq, boolean owned
new Rotation(time / 3, Y),
0.04);
GL11.glDisable(GL11.GL_LIGHTING);
CCRenderState.changeTexture("enderstorage:textures/hedronmap.png");
CCRenderState.startDrawing(4);
state.changeTexture("enderstorage:textures/hedronmap.png");
state.startDrawing(4);
CCModelLibrary.icosahedron4.render(pearlMat);
CCRenderState.draw();
state.draw();
GL11.glEnable(GL11.GL_LIGHTING);
}
}
Expand Down

0 comments on commit b45c75f

Please sign in to comment.