| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- import { Scene } from "./Scene"
- import { TextureLayer } from "./TextureLayer";
- export class ImageLayer extends TextureLayer {
- constructor(
- scene: Scene,
- image: HTMLImageElement | HTMLCanvasElement,
- width : number,
- height : number,
- filterType: GLint = scene.gl.LINEAR,
- fragmentShader: string | null = null
- ) {
- const gl = scene.gl;
- // Create a texture.
- let texture = gl.createTexture()!;
- gl.bindTexture(gl.TEXTURE_2D, texture);
- // Set the parameters so we can render any size image.
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filterType);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filterType);
- //Upload the image into the texture.
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
- super(scene, texture, image.width, image.height, width, height, fragmentShader)
- }
- }
|