Skip to content

Commit

Permalink
feat(webgl): add varying int support (webgl2)
Browse files Browse the repository at this point in the history
- update varying handling in shaderSourceFromAST()
- extract varyingOpts()
  • Loading branch information
postspectacular committed Jul 26, 2020
1 parent bb1c566 commit c812800
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions packages/webgl/src/shader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ import {
isFunction,
} from "@thi.ng/checks";
import { unsupported } from "@thi.ng/errors";
import { input, output, program, Sym, sym, uniform } from "@thi.ng/shader-ast";
import {
input,
output,
program,
Sym,
sym,
SymOpts,
uniform,
} from "@thi.ng/shader-ast";
import { GLSLVersion, targetGLSL } from "@thi.ng/shader-ast-glsl";
import { vals } from "@thi.ng/transducers";
import {
Expand All @@ -31,6 +39,7 @@ import {
ShaderUniform,
ShaderUniforms,
ShaderUniformSpecs,
ShaderVaryingSpec,
UniformValue,
UniformValues,
} from "./api/shader";
Expand Down Expand Up @@ -300,19 +309,15 @@ export const shaderSourceFromAST = (
}
if (spec.varying) {
for (let id in spec.varying) {
const v = spec.varying[id];
outputs[id] = isArray(v)
? output(v[0], id, { num: v[1] })
: output(v, id);
const [vtype, opts] = varyingOpts(spec.varying[id]);
outputs[id] = output(vtype, id, opts);
}
}
} else {
if (spec.varying) {
for (let id in spec.varying) {
const v = spec.varying[id];
inputs[id] = isArray(v)
? input(v[0], id, { num: v[1] })
: input(v, id);
const [vtype, opts] = varyingOpts(spec.varying[id]);
inputs[id] = input(vtype, id, opts);
}
}
const outs = spec.outputs || DEFAULT_OUTPUT;
Expand Down Expand Up @@ -355,6 +360,14 @@ export const shaderSourceFromAST = (
);
};

const varyingOpts = (v: ShaderVaryingSpec): [GLSL, SymOpts] => {
const [vtype, opts]: [GLSL, SymOpts] = isArray(v)
? [v[0], { num: v[1] }]
: [v, {}];
/(u?int|[ui]vec[234])/.test(vtype) && (opts.smooth = "flat");
return [vtype, opts];
};

export const prepareShaderSource = (
spec: ShaderSpec,
type: ShaderType,
Expand Down

0 comments on commit c812800

Please sign in to comment.