mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-01 11:36:43 +01:00
Use a call list to speed up sphere rendering
This commit is contained in:
parent
12a64c77ce
commit
c2b4a07ecd
2 changed files with 103 additions and 30 deletions
|
@ -0,0 +1,94 @@
|
|||
package com.minelittlepony.unicopia.model;
|
||||
|
||||
import org.lwjgl.util.glu.GLU;
|
||||
import org.lwjgl.util.glu.Sphere;
|
||||
|
||||
import net.minecraft.client.renderer.GLAllocation;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
|
||||
public class ModelSphere {
|
||||
|
||||
private int displayList;
|
||||
private boolean baked;
|
||||
|
||||
protected double posX;
|
||||
protected double posY;
|
||||
protected double posZ;
|
||||
|
||||
protected float rotX;
|
||||
protected float rotY;
|
||||
protected float rotZ;
|
||||
|
||||
public void setPosition(double x, double y, double z) {
|
||||
posX = x - TileEntityRendererDispatcher.staticPlayerX;
|
||||
posY = y - TileEntityRendererDispatcher.staticPlayerY;
|
||||
posZ = z - TileEntityRendererDispatcher.staticPlayerZ;
|
||||
}
|
||||
|
||||
public void setRotation(float x, float y, float z) {
|
||||
rotX = x;
|
||||
rotY = y;
|
||||
rotZ = z;
|
||||
}
|
||||
|
||||
public void render(float scale) {
|
||||
if (scale == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!baked) {
|
||||
baked = true;
|
||||
bake();
|
||||
}
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
|
||||
if (posX != 0 && posY != 9 && posZ != 0) {
|
||||
GlStateManager.translate(posX, posY, posZ);
|
||||
}
|
||||
|
||||
glRotate(rotX, 1, 0, 0);
|
||||
glRotate(rotY, 0, 1, 0);
|
||||
glRotate(rotZ, 0, 0, 1);
|
||||
|
||||
GlStateManager.scale(scale, scale, scale);
|
||||
|
||||
GlStateManager.callList(displayList);
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
private void bake() {
|
||||
displayList = GLAllocation.generateDisplayLists(1);
|
||||
GlStateManager.glNewList(displayList, 4864);
|
||||
|
||||
GlStateManager.disableTexture2D();
|
||||
GlStateManager.enableAlpha();
|
||||
GlStateManager.enableColorMaterial();
|
||||
GlStateManager.colorMaterial(1032, 5634);
|
||||
|
||||
drawShape();
|
||||
|
||||
GlStateManager.disableColorMaterial();
|
||||
GlStateManager.disableAlpha();
|
||||
GlStateManager.enableTexture2D();
|
||||
|
||||
GlStateManager.glEndList();
|
||||
}
|
||||
|
||||
protected void drawShape() {
|
||||
Sphere sphere = new Sphere();
|
||||
|
||||
sphere.setDrawStyle(GLU.GLU_FILL);
|
||||
sphere.setNormals(GLU.GLU_SMOOTH);
|
||||
sphere.draw(1, 32, 32);
|
||||
}
|
||||
|
||||
static void glRotate(float angle, float x, float y, float z) {
|
||||
if (angle != 0) {
|
||||
GlStateManager.rotate(angle, x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -3,12 +3,9 @@ package com.minelittlepony.unicopia.particle.client;
|
|||
import net.minecraft.client.particle.Particle;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.world.World;
|
||||
import org.lwjgl.util.glu.GLU;
|
||||
import org.lwjgl.util.glu.Sphere;
|
||||
|
||||
import com.minelittlepony.unicopia.model.ModelSphere;
|
||||
import com.minelittlepony.unicopia.particle.IAttachableParticle;
|
||||
import com.minelittlepony.unicopia.spell.ICaster;
|
||||
import com.minelittlepony.util.render.Color;
|
||||
|
@ -17,13 +14,15 @@ public class ParticleSphere extends Particle implements IAttachableParticle {
|
|||
|
||||
private final float baseAlpha;
|
||||
|
||||
private int tint;
|
||||
private float alpha;
|
||||
protected int tint;
|
||||
protected float alpha;
|
||||
|
||||
private int radius;
|
||||
protected int radius;
|
||||
|
||||
private ICaster<?> caster;
|
||||
|
||||
private static final ModelSphere model = new ModelSphere();
|
||||
|
||||
public ParticleSphere(int id, World w, double x, double y, double z, double vX, double vY, double vZ, int... args) {
|
||||
this(w, x, y, z, args[0], args[1], args[2]/255F);
|
||||
}
|
||||
|
@ -67,37 +66,17 @@ public class ParticleSphere extends Particle implements IAttachableParticle {
|
|||
}
|
||||
}
|
||||
|
||||
public void renderParticle(BufferBuilder buffer, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) {
|
||||
public void renderParticle(BufferBuilder buffer, Entity viewer, float partialTicks, float x, float z, float yz, float xy, float xz) {
|
||||
if (alpha <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.disableTexture2D();
|
||||
GlStateManager.enableAlpha();
|
||||
GlStateManager.enableColorMaterial();
|
||||
GlStateManager.colorMaterial(1032, 5634);
|
||||
|
||||
GlStateManager.translate(
|
||||
posX - TileEntityRendererDispatcher.staticPlayerX,
|
||||
posY - TileEntityRendererDispatcher.staticPlayerY,
|
||||
posZ - TileEntityRendererDispatcher.staticPlayerZ
|
||||
);
|
||||
|
||||
Color.glColor(tint, alpha);
|
||||
|
||||
final Sphere s = new Sphere();
|
||||
|
||||
s.setDrawStyle(GLU.GLU_FILL);
|
||||
s.setNormals(GLU.GLU_SMOOTH);
|
||||
s.draw(radius, 32, 32);
|
||||
model.setPosition(posX, posY, posZ);
|
||||
model.render(radius);
|
||||
|
||||
GlStateManager.color(1, 1, 1, 1);
|
||||
|
||||
GlStateManager.disableColorMaterial();
|
||||
GlStateManager.disableAlpha();
|
||||
GlStateManager.enableTexture2D();
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue