Skip to content

Commit

Permalink
chore: remove unused displaylist in SpriteParticleRenderer (#4692)
Browse files Browse the repository at this point in the history
  • Loading branch information
pollend authored May 18, 2021
1 parent fdae268 commit a1d2379
Showing 1 changed file with 2 additions and 105 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2016 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.engine.particles.rendering;

import org.joml.Matrix4f;
Expand All @@ -21,8 +8,6 @@
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL13;
import org.terasology.engine.core.subsystem.DisplayDevice;
import org.terasology.engine.core.subsystem.lwjgl.LwjglDisplayDevice;
import org.terasology.engine.entitySystem.systems.RegisterMode;
import org.terasology.engine.entitySystem.systems.RegisterSystem;
import org.terasology.engine.entitySystem.systems.RenderSystem;
Expand All @@ -36,15 +21,7 @@

import java.nio.FloatBuffer;

import static org.lwjgl.opengl.GL11.GL_TRIANGLE_FAN;
import static org.lwjgl.opengl.GL11.glBegin;
import static org.lwjgl.opengl.GL11.glBindTexture;
import static org.lwjgl.opengl.GL11.glCallList;
import static org.lwjgl.opengl.GL11.glDeleteLists;
import static org.lwjgl.opengl.GL11.glEnd;
import static org.lwjgl.opengl.GL11.glEndList;
import static org.lwjgl.opengl.GL11.glGenLists;
import static org.lwjgl.opengl.GL11.glNewList;

/**
* ParticleRenderer for basic sprite particle systems.
Expand All @@ -56,42 +33,12 @@ public class SpriteParticleRenderer implements RenderSystem {

private final FloatBuffer matrixBuffer = BufferUtils.createFloatBuffer(16);
private boolean opengl33 = false;
/**
* Vertices of a unit quad on the xy plane, centered on the origin.
* Vertices are in counter-clockwise order starting from the bottom right vertex.
*
* @return vertices coordinates
*/
protected static final float[] UNIT_QUAD_VERTICES = {
+0.5f, -0.5f, 0.0f,
+0.5f, +0.5f, 0.0f,
-0.5f, +0.5f, 0.0f,
-0.5f, -0.5f, 0.0f
};
@In
WorldRenderer worldRenderer;

@In
ParticleSystemManager particleSystemManager;

@In
DisplayDevice displayDevice;

private DisplayList drawUnitQuad;

public void finalize() throws Throwable {
super.finalize();
if (null != drawUnitQuad) {
drawUnitQuad.dispose();
}
}

public void dispose() {
if (null != drawUnitQuad) {
drawUnitQuad.dispose();
}
}

public void drawParticles(Material material, ParticleRenderingData<ParticleDataSpriteComponent> particleSystem) {
ParticleDataSpriteComponent particleData = particleSystem.particleData;

Expand Down Expand Up @@ -144,26 +91,6 @@ public void renderShadows() {
@Override
public void initialise() {
opengl33 = GL.createCapabilities().OpenGL33;
// Nasty hack to only run LWJGL code with a LwjglDisplayDevice. Should be unnecessary once "big todo" for drawParticles is resolved.
if (!(displayDevice instanceof LwjglDisplayDevice)) {
return;
}

drawUnitQuad = new DisplayList(() -> {
glBegin(GL_TRIANGLE_FAN);
GL11.glTexCoord2f(UNIT_QUAD_VERTICES[0] + 0.5f, -UNIT_QUAD_VERTICES[1] + 0.5f);
GL11.glVertex3f(UNIT_QUAD_VERTICES[0], UNIT_QUAD_VERTICES[1], UNIT_QUAD_VERTICES[2]);

GL11.glTexCoord2f(UNIT_QUAD_VERTICES[3] + 0.5f, -UNIT_QUAD_VERTICES[4] + 0.5f);
GL11.glVertex3f(UNIT_QUAD_VERTICES[3], UNIT_QUAD_VERTICES[4], UNIT_QUAD_VERTICES[5]);

GL11.glTexCoord2f(UNIT_QUAD_VERTICES[6] + 0.5f, -UNIT_QUAD_VERTICES[7] + 0.5f);
GL11.glVertex3f(UNIT_QUAD_VERTICES[6], UNIT_QUAD_VERTICES[7], UNIT_QUAD_VERTICES[8]);

GL11.glTexCoord2f(UNIT_QUAD_VERTICES[9] + 0.5f, -UNIT_QUAD_VERTICES[10] + 0.5f);
GL11.glVertex3f(UNIT_QUAD_VERTICES[9], UNIT_QUAD_VERTICES[10], UNIT_QUAD_VERTICES[11]);
glEnd();
});
}

@Override
Expand All @@ -188,35 +115,5 @@ public void postSave() {

@Override
public void shutdown() {
dispose();
}

private static class DisplayList {
private static final int DISPOSED = 0;
private int id;

DisplayList(Runnable commands) {
id = glGenLists(1);
glNewList(id, GL11.GL_COMPILE);
commands.run();
glEndList();
}

public void call() {
glCallList(id);
}

public void dispose() {
if (id != DISPOSED) {
glDeleteLists(id, 1);
id = DISPOSED;
}
}

@Override
public void finalize() throws Throwable {
super.finalize();
dispose();
}
}
}

0 comments on commit a1d2379

Please sign in to comment.