feat: 简单优化uniform和attribute set性能

This commit is contained in:
unanmed 2024-10-09 23:04:42 +08:00
parent ca18cc9dbb
commit d98bae7144

View File

@ -69,26 +69,6 @@ interface ShaderBuffer {
indices: WebGLBuffer; indices: WebGLBuffer;
} }
// interface ShaderUniform {
// u_sampler: WebGLUniformLocation;
// [x: string]: WebGLUniformLocation | null;
// }
// interface ShaderAttribute {
// a_texCoord: number;
// a_position: number;
// [x: string]: number;
// }
// interface ShaderProgram {
// program: WebGLProgram | null;
// shader: CompiledShader | null;
// uniform: ShaderUniform | null;
// attribute: ShaderAttribute | null;
// }
const enum ShaderVersion { const enum ShaderVersion {
ES_100, ES_100,
ES_300 ES_300
@ -868,8 +848,9 @@ class ShaderProgram {
const obj: ShaderUniform<T> = { const obj: ShaderUniform<T> = {
location, location,
type, type,
set: (...params: Parameters<UniformSetFn[T]>) => { set: (p0, p1, p2, p3) => {
fn(gl, location, ...params); // @ts-ignore
fn(gl, location, p0, p1, p2, p3);
} }
}; };
this.uniform.set(uniform, obj); this.uniform.set(uniform, obj);
@ -923,8 +904,9 @@ class ShaderProgram {
const obj: ShaderAttrib<T> = { const obj: ShaderAttrib<T> = {
location, location,
type, type,
set: (...params: Parameters<AttribSetFn[T]>) => { set: (p0, p1, p2, p3) => {
fn(gl, location, ...params); // @ts-ignore
fn(gl, location, p0, p1, p2, p3);
}, },
pointer: (p0, p1, p2, p3, p4) => { pointer: (p0, p1, p2, p3, p4) => {
gl.vertexAttribPointer(location, p0, p1, p2, p3, p4); gl.vertexAttribPointer(location, p0, p1, p2, p3, p4);