import { IFrameGraphContext } from "../IFrameGraphContext.js";
import { RenderTarget } from "../resource/RenderTarget.js";

export class WebGLRenderContext extends IFrameGraphContext {
    /**
     *
     * @type {WebGL2RenderingContext|null}
     */
    #gl = null;

    /**
     *
     * @param {WebGL2RenderingContext} ctx
     */
    constructor(ctx) {
        super();

        this.#gl = ctx;
    }

    createResource(descriptor) {
        const resource_type = descriptor.type;

        if(resource_type === "texture"){
            return this.createRenderTarget(descriptor);
        }

        throw new Error(`Unsupported resource type ${resource_type}`);
    }

    destroyResource(resource, descriptor) {


        const resource_type = descriptor.type;

        if(resource_type === "texture"){
            return this.destroyRenderTarget(resource);
        }

        throw new Error(`Unsupported resource type ${resource_type}`);

    }

    /**
     *
     * @param {TextureDescriptor} descriptor
     */
    createRenderTarget(descriptor) {
        console.log("createRenderTarget", descriptor)

        const rt = new RenderTarget();

        rt.descriptor = descriptor;
        rt.handle = 0;

        return rt;
    }

    destroyRenderTarget(target) {
        return true;
    }
}
