Skip to content

Commit

Permalink
fix(webgl): ensure system defaults for all uniforms, update equiv checks
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Oct 29, 2019
1 parent f16bb45 commit 39dc83f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
4 changes: 2 additions & 2 deletions packages/webgl/src/api/shader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
IDeref,
IObjectOf,
IRelease,
TypedArray
NumericArray
} from "@thi.ng/api";
import { Func, Sym } from "@thi.ng/shader-ast";
import { GLSLTarget } from "@thi.ng/shader-ast-glsl";
Expand Down Expand Up @@ -64,7 +64,7 @@ export type AttribBufferData =
| Uint16Array
| Float32Array;

export type UniformValue = number | number[] | TypedArray;
export type UniformValue = number | NumericArray;

export type UniformValues = IObjectOf<
UniformValue | Fn2<ShaderUniforms, any, UniformValue> | IDeref<UniformValue>
Expand Down
52 changes: 27 additions & 25 deletions packages/webgl/src/uniforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ const uniformS = (fn: SetterS) => (
};
};

const uniformV = (fn: SetterV, sysDefault?: ReadonlyVec) => (
const uniformV = (fn: SetterV, sysDefault: ReadonlyVec) => (
gl: WebGLRenderingContext,
loc: WebGLUniformLocation,
defaultVal = sysDefault
) => {
let prev: GLVec = [];
return (x?: any) => {
return (x?: ReadonlyVec) => {
x = x === undefined ? defaultVal : x;
if (!equivArrayLike(prev, x)) {
(<any>gl)["uniform" + fn](loc, x);
prev = x;
prev = [...x];
}
};
};
Expand All @@ -68,11 +68,13 @@ const uniformM = (fn: SetterM, sysDefault?: ReadonlyVec) => (
x = x === undefined ? defaultVal : x;
if (!equivArrayLike(prev, x)) {
(<any>gl)["uniformMatrix" + fn](loc, false, x);
prev = x;
prev = [...x];
}
};
};

const Z1 = [0];

export const UNIFORM_SETTERS: IObjectOf<
Fn3<
WebGLRenderingContext,
Expand Down Expand Up @@ -102,25 +104,25 @@ export const UNIFORM_SETTERS: IObjectOf<
sampler3D: uniformS("i"),
samplerCube: uniformS("i"),
samplerCubeShadow: uniformS("i"),
"bool[]": uniformV("1iv"),
"float[]": uniformV("1fv"),
"int[]": uniformV("1iv"),
"uint[]": uniformV("1uiv"),
"bvec2[]": uniformV("2iv"),
"bvec3[]": uniformV("3iv"),
"bvec4[]": uniformV("4iv"),
"ivec2[]": uniformV("2iv"),
"ivec3[]": uniformV("3iv"),
"ivec4[]": uniformV("4iv"),
"vec2[]": uniformV("2fv"),
"vec3[]": uniformV("3fv"),
"vec4[]": uniformV("4fv"),
"mat2[]": uniformM("2fv"),
"mat3[]": uniformM("3fv"),
"mat4[]": uniformM("4fv"),
"sampler2D[]": uniformV("1iv"),
"sampler2DShadow[]": uniformV("1iv"),
"sampler3D[]": uniformV("1iv"),
"samplerCube[]": uniformV("1iv"),
"samplerCubeShadow[]": uniformV("1iv")
"bool[]": uniformV("1iv", Z1),
"float[]": uniformV("1fv", Z1),
"int[]": uniformV("1iv", Z1),
"uint[]": uniformV("1uiv", Z1),
"bvec2[]": uniformV("2iv", ZERO2),
"bvec3[]": uniformV("3iv", ZERO3),
"bvec4[]": uniformV("4iv", ZERO4),
"ivec2[]": uniformV("2iv", ZERO2),
"ivec3[]": uniformV("3iv", ZERO3),
"ivec4[]": uniformV("4iv", ZERO4),
"vec2[]": uniformV("2fv", ZERO2),
"vec3[]": uniformV("3fv", ZERO3),
"vec4[]": uniformV("4fv", ZERO4),
"mat2[]": uniformM("2fv", ZERO2),
"mat3[]": uniformM("3fv", ZERO3),
"mat4[]": uniformM("4fv", ZERO4),
"sampler2D[]": uniformV("1iv", Z1),
"sampler2DShadow[]": uniformV("1iv", Z1),
"sampler3D[]": uniformV("1iv", Z1),
"samplerCube[]": uniformV("1iv", Z1),
"samplerCubeShadow[]": uniformV("1iv", Z1)
};

0 comments on commit 39dc83f

Please sign in to comment.