ImageLayer.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { Scene } from "./Scene"
  2. import { TextureLayer } from "./TextureLayer";
  3. export class ImageLayer extends TextureLayer {
  4. constructor(
  5. scene: Scene,
  6. image: HTMLImageElement | HTMLCanvasElement,
  7. width : number,
  8. height : number,
  9. filterType: GLint = scene.gl.LINEAR,
  10. fragmentShader: string | null = null
  11. ) {
  12. const gl = scene.gl;
  13. // Create a texture.
  14. let texture = gl.createTexture()!;
  15. gl.bindTexture(gl.TEXTURE_2D, texture);
  16. // Set the parameters so we can render any size image.
  17. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  18. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  19. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filterType);
  20. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filterType);
  21. //Upload the image into the texture.
  22. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  23. super(scene, texture, image.width, image.height, width, height, fragmentShader)
  24. }
  25. }