import { SAMPLER_FILTER_MODE , SAMPLER_WRAP_MODE } from "../constants" ; import { Renderer } from "../Renderer" ; export interface ISamplerAdressModeOptions { U : SAMPLER_WRAP_MODE ; V : SAMPLER_WRAP_MODE ; W : SAMPLER_WRAP_MODE ; } export interface ISamplerOptions { name ? : string ; addressMode ? : ISamplerAdressModeOptions ; filterMode ? : SAMPLER_FILTER_MODE ; } export const SAMPLER_DEFAULT_OPTIONS = { name : null , addressMode : { U : SAMPLER_WRAP_MODE . REPEAT , V : SAMPLER_WRAP_MODE . REPEAT , W : SAMPLER_WRAP_MODE . REPEAT } , filterMode : SAMPLER_FILTER_MODE . LINEAR } ; export class Sampler { private _name : string = null ; private _addressMode : ISamplerAdressModeOptions = null ; private _filterMode : SAMPLER_FILTER_MODE = SAMPLER_FILTER_MODE . NONE ; private _resource : GPUSampler = null ; param options public constructor ( options ? ) { options = Object . assign ( { } , SAMPLER_DEFAULT_OPTIONS , options ) ; this . setName ( options . name ) ; this . _addressMode = Object . assign ( { } , options . addressMode ) ; this . _filterMode = options . filterMode ; } /**
     * The sampler name
     */ public getName ( ) { return this . _name ; } param value public setName ( value ) { this . _name = value ; } /**
     * The sampler address mode
     */ public getAddressMode ( ) { return Object . assign ( { } , this . _addressMode ) ; } /**
     * The sampler filter mode
     */ public getFilterMode ( ) { return this . _filterMode ; } /**
     * The GPU sampler resource
     */ public getResource ( ) { return this . _resource ; } param renderer param descriptor public create ( renderer , descriptor ) { if ( this . _resource === null ) { const device = renderer . getDevice ( ) ; const instance = device . createSampler ( descriptor ) ; this . _resource = instance ; } } /**
     * Update this sampler
     */ public update ( _renderer ) { } /**
     * Destroy this Object
     */ public destroy ( ) { this . _name = null ; this . _addressMode = null ; this . _resource = null ; } }