import { TEXTURE_FORMAT } from "../constants" ; import { Renderer } from "../Renderer" ; export interface ITextureOptions { name ? : string ; data ? : ArrayBufferView ; width : number ; height : number ; depth ? : number ; bytesPerRow ? : number ; isRenderable ? : boolean ; format : TEXTURE_FORMAT ; } export const TEXTURE_DEFAULT_OPTIONS = { name : null , data : null , width : 0 , height : 0 , depth : 1 , bytesPerRow : 0 , isRenderable : false , format : TEXTURE_FORMAT . NONE } ; export class Texture { private _name : string = null ; private _data : ArrayBufferView = null ; private _width : number = 0 ; private _height : number = 0 ; private _depth : number = 0 ; private _bytesPerRow : number = 0 ; private _format : TEXTURE_FORMAT = TEXTURE_FORMAT . NONE ; private _isRenderable : boolean = false ; private _resource : GPUTexture = null ; private _resourceView : GPUTextureView = null ; param options public constructor ( options ? ) { options = Object . assign ( { } , TEXTURE_DEFAULT_OPTIONS , options ) ; this . setName ( options . name ) ; this . _data = options . data ; this . _width = options . width ; this . _height = options . height ; this . _depth = options . depth ; this . _bytesPerRow = options . bytesPerRow ; this . _format = options . format ; this . _isRenderable = options . isRenderable ; } /**
     * The texture name
     */ public getName ( ) { return this . _name ; } param value public setName ( value ) { this . _name = value ; } /**
     * The texture data
     */ public getData ( ) { return this . _data ; } /**
     * The texture width
     */ public getWidth ( ) { return this . _width ; } /**
     * The texture height
     */ public getHeight ( ) { return this . _height ; } /**
     * The texture depth
     */ public getDepth ( ) { return this . _depth ; } /**
     * The texture bytes per row
     */ public getBytesPerRow ( ) { return this . _bytesPerRow ; } /**
     * The texture format
     */ public getFormat ( ) { return this . _format ; } /**
     * Indicates if this texture is renderable
     */ public isRenderable ( ) { return this . _isRenderable ; } /**
     * The GPU texture resource
     */ public getResource ( ) { return this . _resource ; } /**
     * The GPU texture view resource
     */ public getResourceView ( ) { return this . _resourceView ; } param renderer param descriptor public create ( renderer , descriptor ) { const device = renderer . getDevice ( ) ; if ( this . _resource === null ) { const texture = device . createTexture ( descriptor ) ; this . _resource = texture ; this . _resourceView = texture . createView ( ) ; if ( this . getData ( ) !== null ) { const imageData = this . getData ( ) ; const width = this . getWidth ( ) ; const height = this . getHeight ( ) ; const depth = this . getDepth ( ) ; const bytesPerRow = this . getBytesPerRow ( ) ; const resource = this . getResource ( ) ; renderer . getQueueCommander ( ) . transferDataToTexture ( resource , imageData , width , height , depth , bytesPerRow , null ) ; } } } /**
     * Update this texture
     */ public update ( _renderer ) { } /**
     * Destroy this Object
     */ public destroy ( ) { this . _name = null ; this . _data = null ; this . _resource = null ; this . _resourceView = null ; } }