57 lines
1.2 KiB
TypeScript
57 lines
1.2 KiB
TypeScript
import type { WebGLCanvas } from "./WebGLCanvas";
|
|
|
|
/**
|
|
* Used for management, caching, encapsulation, WebGL context.
|
|
*/
|
|
abstract class WebGLStateAbstract {
|
|
|
|
private _canvas: WebGLCanvas | undefined;
|
|
|
|
/**
|
|
* binded canvas.
|
|
*/
|
|
public get canvas(): WebGLCanvas {
|
|
if (this._canvas) {
|
|
return this._canvas;
|
|
}
|
|
else {
|
|
throw new Error(
|
|
"[ray-lab WebGLStateBasic] Please get canvas instance after context binding."
|
|
);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Bind new WebGLCanvas.
|
|
*/
|
|
public bindCanvas(canvas: WebGLCanvas) {
|
|
this.contextWillBind(canvas);
|
|
this._canvas = canvas;
|
|
};
|
|
|
|
/**
|
|
* Life cycle hook function.
|
|
* Triggered when the context is rebound.
|
|
* @param newcanvas - New canvas object to be bound.
|
|
*/
|
|
public abstract contextWillBind(newcanvas: WebGLCanvas): any;
|
|
|
|
/**
|
|
* Life cycle hook function.
|
|
* Triggered when the context is lost.
|
|
*/
|
|
public abstract contextLost(): any;
|
|
|
|
/**
|
|
* Reset all states.
|
|
*/
|
|
public abstract resetState(): any;
|
|
|
|
/**
|
|
* Triggered when destroyed.
|
|
*/
|
|
public abstract destroy(): any;
|
|
}
|
|
|
|
export { WebGLStateAbstract };
|