Search in sources :

Example 1 with ParticleDataWithTextureCoordinates

use of io.xol.chunkstories.api.particles.ParticleDataWithTextureCoordinates in project chunkstories by Hugobros3.

the class ClientParticlesRenderer method renderParticles.

public void renderParticles(RenderingInterface renderingInterface) {
    // For all present particles types
    for (ParticleTypeHandler particleTypeHandler : particles.keySet()) {
        String renderPass = particleTypeHandler.getType().getRenderPass();
        if (!renderingInterface.getCurrentPass().name.equals(renderPass))
            continue;
        // Don't bother rendering empty sets
        if (particles.get(particleTypeHandler).size() > 0) {
            Iterator<ParticleData> iterator = particles.get(particleTypeHandler).iterator();
            boolean haveTextureCoordinates = false;
            ParticleTypeRenderer renderer = getRendererForType(particleTypeHandler);
            renderer.beginRenderingForType(renderingInterface);
            textureCoordinatesBuffer.clear();
            particlesPositionsBuffer.clear();
            // Some stuff don't wanna be rendered, so don't
            boolean actuallyRenderThatStuff = !renderPass.equals("lights");
            int elementsInDrawBuffer = 0;
            while (iterator.hasNext()) {
                // Iterate over dem particles
                ParticleData p = iterator.next();
                // Check we don't have a null particle
                if (p != null) {
                    renderer.forEach_Rendering(renderingInterface, p);
                    if (p.isDed())
                        iterator.remove();
                } else {
                    iterator.remove();
                    continue;
                }
                if (!actuallyRenderThatStuff)
                    continue;
                // If > 60k elements, buffer is full, draw it
                if (elementsInDrawBuffer >= 60000) {
                    drawBuffers(renderingInterface, elementsInDrawBuffer, haveTextureCoordinates);
                    elementsInDrawBuffer = 0;
                }
                particlesPositionsBuffer.put((float) p.x());
                particlesPositionsBuffer.put((float) p.y());
                particlesPositionsBuffer.put((float) p.z());
                particlesPositionsBuffer.put((float) p.x());
                particlesPositionsBuffer.put((float) p.y());
                particlesPositionsBuffer.put((float) p.z());
                particlesPositionsBuffer.put((float) p.x());
                particlesPositionsBuffer.put((float) p.y());
                particlesPositionsBuffer.put((float) p.z());
                // Second triangle
                particlesPositionsBuffer.put((float) p.x());
                particlesPositionsBuffer.put((float) p.y());
                particlesPositionsBuffer.put((float) p.z());
                particlesPositionsBuffer.put((float) p.x());
                particlesPositionsBuffer.put((float) p.y());
                particlesPositionsBuffer.put((float) p.z());
                particlesPositionsBuffer.put((float) p.x());
                particlesPositionsBuffer.put((float) p.y());
                particlesPositionsBuffer.put((float) p.z());
                // TODO No this sucks. Delet dis.
                if (p instanceof ParticleDataWithTextureCoordinates) {
                    haveTextureCoordinates = true;
                    ParticleDataWithTextureCoordinates texCoords = (ParticleDataWithTextureCoordinates) p;
                    textureCoordinatesBuffer.put(texCoords.getTextureCoordinateXTopRight());
                    textureCoordinatesBuffer.put(texCoords.getTextureCoordinateYTopRight());
                    textureCoordinatesBuffer.put(texCoords.getTextureCoordinateXTopLeft());
                    textureCoordinatesBuffer.put(texCoords.getTextureCoordinateYTopLeft());
                    textureCoordinatesBuffer.put(texCoords.getTextureCoordinateXBottomLeft());
                    textureCoordinatesBuffer.put(texCoords.getTextureCoordinateYBottomLeft());
                    textureCoordinatesBuffer.put(texCoords.getTextureCoordinateXBottomLeft());
                    textureCoordinatesBuffer.put(texCoords.getTextureCoordinateYBottomLeft());
                    textureCoordinatesBuffer.put(texCoords.getTextureCoordinateXTopRight());
                    textureCoordinatesBuffer.put(texCoords.getTextureCoordinateYTopRight());
                    textureCoordinatesBuffer.put(texCoords.getTextureCoordinateXTopLeft());
                    textureCoordinatesBuffer.put(texCoords.getTextureCoordinateYBottomLeft());
                }
                elementsInDrawBuffer += 6;
            }
            // Draw the stuff
            if (elementsInDrawBuffer > 0) {
                drawBuffers(renderingInterface, elementsInDrawBuffer, haveTextureCoordinates);
                elementsInDrawBuffer = 0;
            }
        }
    }
    // We done here
    renderingInterface.getRenderTargetManager().setDepthMask(true);
    renderingInterface.setBlendMode(BlendMode.DISABLED);
// return totalDrawn;
}
Also used : ParticleData(io.xol.chunkstories.api.particles.ParticleTypeHandler.ParticleData) ParticleTypeRenderer(io.xol.chunkstories.api.particles.ParticleTypeHandler.ParticleTypeRenderer) ParticleTypeHandler(io.xol.chunkstories.api.particles.ParticleTypeHandler) ParticleDataWithTextureCoordinates(io.xol.chunkstories.api.particles.ParticleDataWithTextureCoordinates)

Aggregations

ParticleDataWithTextureCoordinates (io.xol.chunkstories.api.particles.ParticleDataWithTextureCoordinates)1 ParticleTypeHandler (io.xol.chunkstories.api.particles.ParticleTypeHandler)1 ParticleData (io.xol.chunkstories.api.particles.ParticleTypeHandler.ParticleData)1 ParticleTypeRenderer (io.xol.chunkstories.api.particles.ParticleTypeHandler.ParticleTypeRenderer)1