import { ParticleRenderer } from "../ParticleRenderer.js";
import { ShaderManager } from "../../shader/ShaderManager.js";

export class SoftBillboardParticleRenderer extends ParticleRenderer {
    /**
     *
     * @type {Map<Material, SoftBillboardParticlePool>}
     * @private
     */
    __pools = new Map();
    /**
     *
     * @private
     * @type {ShaderManager}
     */
    __shaders;

    /**
     *
     * @param {Engine} engine
     */
    constructor(engine) {
        super();


        this.__shaders = new ShaderManager(engine.assetManager, engine.graphics.getMaterialManager());
    }

    build_start() {

    }

    build_end() {


    }

    /**
     *
     * @param {ParticleLayer} layer
     * @returns {SoftBillboardParticlePool}
     * @private
     */
    __obtain_pool(layer) {

    }

    /**
     *
     * @param {ParticleLayer} layer
     */
    add(layer) {
        // TODO test frustum visibility

        const pool = this.__obtain_pool(layer);

        pool.add(layer);
    }

    __sort() {
        for (const [mat, pool] of this.__pools) {
            pool.sort();
        }

        // TODO sort pools themselves
    }

    /**
     * Release resources
     */
    dispose() {
        for (const [mat, pool] of this.__pools) {
            pool.dispose();
        }

        this.__pools.clear();

        this.__shaders.dispose();
    }
}
