Skip to content

Commit

Permalink
fix(webgl): apply ModelSpec mode in compileModel, fix/simplify draw fns
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed May 26, 2019
1 parent 10a337e commit 67334a6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/webgl/src/buffer.ts
Expand Up @@ -81,6 +81,7 @@ export const compileModel = (
}
spec.instances && compileAttribs(gl, spec.instances.attribs, mode);
compileIndices(gl, spec.indices, mode);
spec.mode == null && (spec.mode = gl.TRIANGLES);
// TODO auto-create VAO & inject into model spec?
return spec;
};
Expand Down
13 changes: 6 additions & 7 deletions packages/webgl/src/draw.ts
Expand Up @@ -19,7 +19,7 @@ export const draw = (specs: ModelSpec | ModelSpec[]) => {
drawInstanced(gl, spec);
} else {
gl.drawElements(
spec.mode || gl.TRIANGLES,
spec.mode,
spec.num,
indices.data instanceof Uint32Array
? gl.UNSIGNED_INT
Expand All @@ -31,7 +31,7 @@ export const draw = (specs: ModelSpec | ModelSpec[]) => {
if (spec.instances) {
drawInstanced(gl, spec);
} else {
gl.drawArrays(spec.mode || gl.TRIANGLES, 0, spec.num);
gl.drawArrays(spec.mode, 0, spec.num);
}
}
spec.shader.unbind(null);
Expand Down Expand Up @@ -60,22 +60,21 @@ const drawInstanced = (gl: WebGLRenderingContext, spec: ModelSpec) => {
: ext.vertexAttribDivisorANGLE(attr.loc, div);
}
}
const mode = spec.mode || gl.TRIANGLES;
if (spec.indices) {
const type =
spec.indices.data instanceof Uint32Array
? gl.UNSIGNED_INT
: gl.UNSIGNED_SHORT;
isGL2
? (<WebGL2RenderingContext>gl).drawElementsInstanced(
mode,
spec.mode,
spec.num,
type,
0,
spec.instances.num
)
: ext.drawElementsInstancedANGLE(
mode,
spec.mode,
spec.num,
type,
0,
Expand All @@ -84,13 +83,13 @@ const drawInstanced = (gl: WebGLRenderingContext, spec: ModelSpec) => {
} else {
isGL2
? (<WebGL2RenderingContext>gl).drawArraysInstanced(
mode,
spec.mode,
0,
spec.num,
spec.instances.num
)
: ext.drawArraysInstancedANGLE(
mode,
spec.mode,
0,
spec.num,
spec.instances.num
Expand Down

0 comments on commit 67334a6

Please sign in to comment.