123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- import WebGPUBinding from './WebGPUBinding.js';
- class WebGPUUniformsGroup extends WebGPUBinding {
- constructor() {
- super();
- this.name = '';
- this.uniforms = new Map();
- this.update = function () {};
- this.type = 'uniform-buffer';
- this.visibility = GPUShaderStage.VERTEX;
- this.usage = GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST;
- this.array = null; // set by the renderer
- this.bufferGPU = null; // set by the renderer
- Object.defineProperty( this, 'isUniformsGroup', { value: true } );
- }
- setName( name ) {
- this.name = name;
- }
- setUniform( name, uniform ) {
- this.uniforms.set( name, uniform );
- return this;
- }
- removeUniform( name ) {
- this.uniforms.delete( name );
- return this;
- }
- setUpdateCallback( callback ) {
- this.update = callback;
- return this;
- }
- copy( source ) {
- this.name = source.name;
- const uniformsSource = source.uniforms;
- this.uniforms.clear();
- for ( const entry of uniformsSource ) {
- this.uniforms.set( ...entry );
- }
- return this;
- }
- clone() {
- return new this.constructor().copy( this );
- }
- getByteLength() {
- let size = 0;
- for ( const uniform of this.uniforms.values() ) {
- size += this.getUniformByteLength( uniform );
- }
- return size;
- }
- getUniformByteLength( uniform ) {
- let size;
- if ( typeof uniform === 'number' ) {
- size = 4;
- } else if ( uniform.isVector2 ) {
- size = 8;
- } else if ( uniform.isVector3 || uniform.isColor ) {
- size = 12;
- } else if ( uniform.isVector4 ) {
- size = 16;
- } else if ( uniform.isMatrix3 ) {
- size = 48; // (3 * 4) * 4 bytes
- } else if ( uniform.isMatrix4 ) {
- size = 64;
- } else if ( uniform.isTexture ) {
- console.error( 'THREE.UniformsGroup: Texture samplers can not be part of an uniforms group.' );
- } else {
- console.error( 'THREE.UniformsGroup: Unsupported uniform value type.', uniform );
- }
- return size;
- }
- }
- export default WebGPUUniformsGroup;
|