import { FrameRunner } from "../FrameRunner.js";
import { WebGLRendererPool } from "../render/RendererPool.js";
import { buildCanvasViewFromTexture } from "../render/visibility/hiz/buildCanvasViewFromTexture.js";

/**
 * Useful tool for previewing textures
 * @param {THREE.Texture} texture
 * @param {number} resolution
 * @param {boolean} flipY
 */
export function debug_preview_texture({
                                          texture,
                                          resolution = 512,
                                          flipY = true
                                      }) {

    const preview = buildCanvasViewFromTexture({
        width: resolution,
        height: resolution,
        texture: texture,
        renderer: WebGLRendererPool.global.get(),
        flipY: flipY
    });

    const runner = new FrameRunner(() => {

        preview.render();
    });

    runner.startup();

    document.body.appendChild(
        preview.view.el
    );

    preview.view.link();

}