-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webgl): add/update opts for defQuadModel()
BREAKING CHANGE: add/update opts for defQuadModel() - update callsite in defMultiPass()
- Loading branch information
1 parent
c812800
commit 13b7d9e
Showing
2 changed files
with
54 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters