Skip to content

Commit

Permalink
fix(webgl): update GPGPU texture & shader handling
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jul 6, 2019
1 parent 7e559a1 commit ce286ad
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions packages/webgl/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ export interface GPGPUTextureConfig

export interface GPGPUJobConfig {
shader: ShaderSpec;
src: string;
src: string | ShaderFn;
uniforms: ShaderUniformSpecs;
inputs: number;
outputs?: number;
Expand All @@ -1116,7 +1116,7 @@ export const GL_RGBA32F = 0x8814;
export const DEFAULT_BLEND: Tuple<GLenum, 2> = [0x302, 0x303];

export const GL_EXT_INFO = {
EXT_draw_buffers: {
WEBGL_draw_buffers: {
gl: true,
alias: "GL_EXT_draw_buffers"
},
Expand All @@ -1128,6 +1128,7 @@ export const GL_EXT_INFO = {

export interface WebGLExtensionMap {
EXT_blend_minmax: EXT_blend_minmax;
EXT_color_buffer_float: WEBGL_color_buffer_float;
EXT_texture_filter_anisotropic: EXT_texture_filter_anisotropic;
EXT_frag_depth: EXT_frag_depth;
EXT_shader_texture_lod: EXT_shader_texture_lod;
Expand Down
9 changes: 6 additions & 3 deletions packages/webgl/src/gpgpu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class GPGPU implements IRelease {
...map(
() =>
<GPGPUIO>{
tex: floatTexture(gl, undefined, width, width),
tex: floatTexture(gl, null, width, width),
opts: { stride: 4 }
},
range(specs)
Expand All @@ -136,6 +136,7 @@ export class GPGPU implements IRelease {
(opts) =>
<GPGPUIO>{
tex: texture(gl, {
image: null,
width: width,
height: width,
filter: gl.NEAREST,
Expand Down Expand Up @@ -199,6 +200,8 @@ export class GPGPUJob implements IRelease {
type: input.opts.type || gl.FLOAT,
internalFormat: input.opts.internalFormat || internalFormat,
format: input.opts.format || GL_RGBA,
filter: gl.NEAREST,
wrap: gl.CLAMP_TO_EDGE,
height: width,
width
});
Expand All @@ -213,7 +216,7 @@ export class GPGPUJob implements IRelease {
return this;
}

result(out?: Float32Array, id = 0) {
result(out?: Float32Array | null, id = 0) {
const ctx = this.ctx;
const width = ctx.width;
const gl = ctx.gl;
Expand Down Expand Up @@ -269,7 +272,7 @@ export class GPGPUJob implements IRelease {
}
shaderSpec.uniforms!.inputs = ["sampler2D[]", opts.inputs];
if (ctx.opts.version === 1 && opts.outputs! > 1) {
shaderSpec.ext!.EXT_draw_buffers = "require";
shaderSpec.ext!.WEBGL_draw_buffers = "require";
}
spec.uniforms!.inputs = [...range(opts.inputs)];
spec.textures = ctx.inputs.slice(0, opts.inputs).map((t) => t.tex);
Expand Down
2 changes: 1 addition & 1 deletion packages/webgl/src/texture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export const cubeMap = (
*/
export const floatTexture = (
gl: WebGLRenderingContext,
data: Float32Array | undefined,
data: Float32Array | undefined | null,
width: number,
height: number,
internalFormat?: GLenum,
Expand Down

0 comments on commit ce286ad

Please sign in to comment.