Search in sources :

Example 1 with ParticleTypeRenderer

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

the class ClientParticlesRenderer method getRendererForType.

private ParticleTypeRenderer getRendererForType(ParticleTypeHandler particleTypeHandler) {
    ParticleTypeRenderer r = this.renderers.get(particleTypeHandler);
    if (r == null) {
        r = particleTypeHandler.getRenderer(this);
        this.renderers.put(particleTypeHandler, r);
    }
    return r;
}
Also used : ParticleTypeRenderer(io.xol.chunkstories.api.particles.ParticleTypeHandler.ParticleTypeRenderer)

Example 2 with ParticleTypeRenderer

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

the class ClientParticlesRenderer method destroy.

public void destroy() {
    // Cleans up
    this.particlesPositions.destroy();
    this.texCoords.destroy();
    for (ParticleTypeRenderer type : renderers.values()) {
        type.destroy();
    }
}
Also used : ParticleTypeRenderer(io.xol.chunkstories.api.particles.ParticleTypeHandler.ParticleTypeRenderer)

Example 3 with ParticleTypeRenderer

use of io.xol.chunkstories.api.particles.ParticleTypeHandler.ParticleTypeRenderer 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

ParticleTypeRenderer (io.xol.chunkstories.api.particles.ParticleTypeHandler.ParticleTypeRenderer)3 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