All files / src/WebGL/core Texture.ts

2.27% Statements 1/44
0% Branches 0/3
0% Functions 0/3
2.27% Lines 1/44

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117                                                                                                                                                                                                                                      18x  
//Texture
//We really only create textures from 2d rendering contexts (to display text labels)
//edit: we can now create 3dtextures using volumetric data
 
import {
  ClampToEdgeWrapping,
  RFormat,
  FloatType,
  NearestFilter,
  RGBAFormat,
  UnsignedByteType,
  LinearFilter,
  LinearMipMapLinearFilter,
} from "../constants/TextureConstants";
import { Vector2 } from "../math";
import { EventDispatcher } from "./EventDispatcher";
import { UVMapping } from "./UVMapping";
 
/** @constructor */
export class Texture extends EventDispatcher {
  id: number;
  name: string;
  image: any;
  mapping: any;
  wrapS: number;
  wrapT: number;
  anisotropy: number;
  format: number;
  type: number;
  premultiplyAlpha: boolean;
  flipY: boolean;
  unpackAlignment: number;
  magFilter: number;
  minFilter: number;
  offset: any;
  repeat: any;
  needsUpdate: boolean;
  onUpdate: null;
  constructor(image?: any, is3D?: boolean) {
    super();
 
    this.id = TextureIdCount++;
 
    this.name = "";
 
    this.image = image;
 
    this.mapping = new UVMapping();
 
    this.wrapS = ClampToEdgeWrapping;
    this.wrapT = ClampToEdgeWrapping;
 
    this.anisotropy = 1;
 
    if (is3D) {
      this.format = RFormat;
      this.type = FloatType;
 
      this.premultiplyAlpha = false;
      this.flipY = false;
 
      this.unpackAlignment = 1;
 
      this.magFilter = NearestFilter;
      this.minFilter = NearestFilter;
    } else {
      this.format = RGBAFormat;
      this.type = UnsignedByteType;
 
      this.offset = new Vector2(0, 0);
      this.repeat = new Vector2(1, 1);
 
      this.premultiplyAlpha = false;
      this.flipY = true;
      this.unpackAlignment = 4;
 
      this.magFilter = LinearFilter;
      this.minFilter = LinearMipMapLinearFilter;
    }
 
    this.needsUpdate = false;
    this.onUpdate = null;
  }
 
  clone(texture = new Texture()): Texture {
 
    texture.image = this.image;
 
    texture.mapping = this.mapping;
 
    texture.wrapS = this.wrapS;
    texture.wrapT = this.wrapT;
 
    texture.magFilter = this.magFilter;
    texture.minFilter = this.minFilter;
 
    texture.anisotropy = this.anisotropy;
 
    texture.format = this.format;
    texture.type = this.type;
 
    texture.offset.copy(this.offset);
    texture.repeat.copy(this.repeat);
 
    texture.premultiplyAlpha = this.premultiplyAlpha;
    texture.flipY = this.flipY;
    texture.unpackAlignment = this.unpackAlignment;
 
    return texture;
  }
 
  dispose() {
    this.dispatchEvent({ type: "dispose" });
  }
}
export let TextureIdCount = 0;