Skip to content

Commit

Permalink
feat(webgl): add/update opts for defQuadModel()
Browse files Browse the repository at this point in the history
BREAKING CHANGE: add/update opts for defQuadModel()

- update callsite in defMultiPass()
  • Loading branch information
postspectacular committed Jul 26, 2020
1 parent c812800 commit 13b7d9e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 20 deletions.
72 changes: 53 additions & 19 deletions packages/webgl/src/geo/quad.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,56 @@
import { DrawMode, ModelSpec } from "../api/model";

export const defQuadModel = (uv = true): ModelSpec => ({
attribs: {
position: {
data: new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]),
size: 2,
export interface QuadOpts {
/**
* Side length of the quad in each direction (always square).
*
* @defaultValue 2.0
*/
size: number;
/**
* @defaultValue true
*/
uv: boolean;
/**
* If true, the quad's position will be centered around (0,0). If false, the
* quad's bottom-left corner will be at (0,0).
*
* @defaultValue true
*/
center: boolean;
}

export const defQuadModel = (opts?: Partial<QuadOpts>): ModelSpec => {
let { size, uv, center } = { size: 2, uv: true, center: true, ...opts };
size *= 0.5;
const o = center ? 0 : size;
return {
attribs: {
position: {
data: new Float32Array([
o - size,
o - size,
o + size,
o - size,
o - size,
o + size,
o + size,
o + size,
]),
size: 2,
},
...(uv
? {
uv: {
data: new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]),
size: 2,
},
}
: null),
},
...(uv
? {
uv: {
data: new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]),
size: 2,
},
}
: null),
},
uniforms: {},
shader: <any>null,
mode: DrawMode.TRIANGLE_STRIP,
num: 4,
});
uniforms: {},
shader: <any>null,
mode: DrawMode.TRIANGLE_STRIP,
num: 4,
};
};
2 changes: 1 addition & 1 deletion packages/webgl/src/multipass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const defMultiPass = (opts: MultipassOpts) => {
return acc;
}, <IObjectOf<ITexture>>{});

const model = compileModel(gl, defQuadModel(false));
const model = compileModel(gl, defQuadModel({ uv: false }));
const models = opts.passes.map((pass) => {
const m = pass.model ? compileModel(gl, <any>pass.model) : { ...model };
m.shader = initShader(pass);
Expand Down

0 comments on commit 13b7d9e

Please sign in to comment.