Skip to content

Commit

Permalink
feat(webgl): add webgl resource factory fns, update buffer() arg order
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Apr 5, 2019
1 parent ab81ed4 commit 131e551
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
21 changes: 14 additions & 7 deletions packages/webgl/src/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export class WebGLArrayBuffer<T extends TypedArray> implements IWebGLBuffer<T> {

constructor(
gl: WebGLRenderingContext,
data?: T,
target = gl.ARRAY_BUFFER,
mode = gl.STATIC_DRAW,
data?: T
mode = gl.STATIC_DRAW
) {
this.gl = gl;
this.buffer = gl.createBuffer();
Expand Down Expand Up @@ -54,7 +54,14 @@ export class WebGLArrayBuffer<T extends TypedArray> implements IWebGLBuffer<T> {
}
}

export const compileBuffers = (
export const buffer = (
gl: WebGLRenderingContext,
data?: TypedArray,
target = gl.ARRAY_BUFFER,
mode = gl.STATIC_DRAW
) => new WebGLArrayBuffer(gl, data, target, mode);

export const compileModel = (
gl: WebGLRenderingContext,
spec: ModelSpec,
mode = gl.STATIC_DRAW
Expand All @@ -79,9 +86,9 @@ const compileAttribs = (
} else {
attr.buffer = new WebGLArrayBuffer(
gl,
attr.data,
gl.ARRAY_BUFFER,
mode,
attr.data
mode
);
}
}
Expand All @@ -99,9 +106,9 @@ const compileIndices = (
} else {
index.buffer = new WebGLArrayBuffer(
gl,
index.data,
gl.ELEMENT_ARRAY_BUFFER,
mode,
index.data
mode
);
}
};
3 changes: 3 additions & 0 deletions packages/webgl/src/fbo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,6 @@ export class FBO implements IFbo {
}
}
}

export const fbo = (gl: WebGLRenderingContext, opts?: Partial<FboOpts>) =>
new FBO(gl, opts);
5 changes: 5 additions & 0 deletions packages/webgl/src/renderbuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,8 @@ export class RenderBuffer implements IRenderBuffer {
return true;
}
}

export const renderBuffer = (
gl: WebGLRenderingContext,
opts?: Partial<RenderBufferOpts>
) => new RenderBuffer(gl, opts);
5 changes: 4 additions & 1 deletion packages/webgl/src/shader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class Shader implements IShader {
}
}

setState(id: number, val: GLenum | boolean) {
protected setState(id: number, val: GLenum | boolean) {
if (val) {
this.gl.enable(id);
} else {
Expand All @@ -191,6 +191,9 @@ export class Shader implements IShader {
}
}

export const shader = (gl: WebGLRenderingContext, spec: ShaderSpec) =>
Shader.fromSpec(gl, spec);

const compileVars = (
attribs: any,
syntax: Fn3<string, any, GLSLDeclPrefixes, string>,
Expand Down
5 changes: 5 additions & 0 deletions packages/webgl/src/texture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,8 @@ export class Texture implements ITexture {
return false;
}
}

export const texture = (
gl: WebGLRenderingContext,
opts?: Partial<TextureOpts>
) => new Texture(gl, opts);

0 comments on commit 131e551

Please sign in to comment.