@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
63 lines (45 loc) • 1.35 kB
JavaScript
import { IRenderContext } from "../IRenderContext.js";
import { RenderTarget } from "../resource/RenderTarget.js";
export class WebGLRenderContext extends IRenderContext {
/**
*
* @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;
}
}