未验证 提交 950bbfac 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #14045 from Mugen87/dev4

WebGLUniforms: Added full caching for PureArrayUniform
......@@ -496,19 +496,40 @@ function setValue1iv( gl, v ) {
function setValueV2a( gl, v ) {
gl.uniform2fv( this.addr, flatten( v, this.size, 2 ) );
var cache = this.cache;
var data = flatten( v, this.size, 2 );
if ( arraysEqual( cache, data ) ) return;
gl.uniform2fv( this.addr, data );
this.updateCache( data );
}
function setValueV3a( gl, v ) {
gl.uniform3fv( this.addr, flatten( v, this.size, 3 ) );
var cache = this.cache;
var data = flatten( v, this.size, 3 );
if ( arraysEqual( cache, data ) ) return;
gl.uniform3fv( this.addr, data );
this.updateCache( data );
}
function setValueV4a( gl, v ) {
gl.uniform4fv( this.addr, flatten( v, this.size, 4 ) );
var cache = this.cache;
var data = flatten( v, this.size, 4 );
if ( arraysEqual( cache, data ) ) return;
gl.uniform4fv( this.addr, data );
this.updateCache( data );
}
......@@ -516,19 +537,40 @@ function setValueV4a( gl, v ) {
function setValueM2a( gl, v ) {
gl.uniformMatrix2fv( this.addr, false, flatten( v, this.size, 4 ) );
var cache = this.cache;
var data = flatten( v, this.size, 4 );
if ( arraysEqual( cache, data ) ) return;
gl.uniformMatrix2fv( this.addr, false, data );
this.updateCache( data );
}
function setValueM3a( gl, v ) {
gl.uniformMatrix3fv( this.addr, false, flatten( v, this.size, 9 ) );
var cache = this.cache;
var data = flatten( v, this.size, 9 );
if ( arraysEqual( cache, data ) ) return;
gl.uniformMatrix3fv( this.addr, false, data );
this.updateCache( data );
}
function setValueM4a( gl, v ) {
gl.uniformMatrix4fv( this.addr, false, flatten( v, this.size, 16 ) );
var cache = this.cache;
var data = flatten( v, this.size, 16 );
if ( arraysEqual( cache, data ) ) return;
gl.uniformMatrix4fv( this.addr, false, data );
this.updateCache( data );
}
......@@ -630,6 +672,20 @@ function PureArrayUniform( id, activeInfo, addr ) {
}
PureArrayUniform.prototype.updateCache = function ( data ) {
var cache = this.cache;
if ( data instanceof Float32Array && cache.length !== data.length ) {
this.cache = new Float32Array( data.length );
}
copyArray( cache, data );
};
function StructuredUniform( id ) {
this.id = id;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册