-
-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(webgl): add/rename types, add/move checks, update deps
- Loading branch information
1 parent
8a6f450
commit d56b720
Showing
15 changed files
with
80 additions
and
68 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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { ITexture, TextureType } from "./api/texture"; | ||
|
||
export const isGL2Context = ( | ||
gl: WebGLRenderingContext | ||
): gl is WebGL2RenderingContext => | ||
typeof WebGL2RenderingContext !== "undefined" && | ||
gl instanceof WebGL2RenderingContext; | ||
|
||
export const isFloatTexture = (tex: ITexture) => | ||
tex.type === TextureType.FLOAT || | ||
tex.type === TextureType.HALF_FLOAT || | ||
tex.type === TextureType.HALF_FLOAT_OES || | ||
tex.type === TextureType.FLOAT_32_UNSIGNED_INT_24_8_REV; |
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
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
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
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
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,69 +1,50 @@ | ||
import { IObjectOf } from "@thi.ng/api"; | ||
import { | ||
$xy, | ||
assign, | ||
defMain, | ||
FLOAT0, | ||
FLOAT1, | ||
texture, | ||
vec4 | ||
} from "@thi.ng/shader-ast"; | ||
import { ShaderFn, ShaderSpec, ShaderUniformSpecs } from "./api/shader"; | ||
import { TextureOpts } from "./api/texture"; | ||
import { ShaderFn, ShaderSpec } from "./api/shader"; | ||
import { texture as _texture } from "./texture"; | ||
|
||
export const PASSTHROUGH_VS: ShaderFn = (gl, _, ins, outs) => [ | ||
export const PASSTHROUGH_VS: ShaderFn = (gl, _, ins) => [ | ||
defMain(() => [assign(gl.gl_Position, vec4(ins.position, FLOAT0, FLOAT1))]) | ||
]; | ||
|
||
export const PASSTHROUGH_VS_UV: ShaderFn = (gl, _, ins, outs) => [ | ||
defMain(() => [ | ||
assign(outs.v_uv, ins.uv), | ||
assign(gl.gl_Position, vec4(ins.position, FLOAT0, FLOAT1)) | ||
]) | ||
]; | ||
|
||
export const PASSTHROUGH_FS: ShaderFn = (_, unis, ins, outs) => [ | ||
export const PASSTHROUGH_FS: ShaderFn = (gl, _, __, outs) => [ | ||
defMain(() => [assign(outs.fragColor, $xy(gl.gl_FragCoord))]) | ||
]; | ||
|
||
export const PASSTHROUGH_FS_UV: ShaderFn = (_, unis, ins, outs) => [ | ||
defMain(() => [assign(outs.fragColor, texture(unis.tex, ins.v_uv))]) | ||
]; | ||
|
||
export const FX_SHADER_SPEC: ShaderSpec = { | ||
vs: PASSTHROUGH_VS, | ||
fs: PASSTHROUGH_FS, | ||
attribs: { position: "vec2" }, | ||
varying: {}, | ||
uniforms: {}, | ||
state: { depth: false }, | ||
ext: {} | ||
}; | ||
|
||
export const FX_SHADER_SPEC_UV: ShaderSpec = { | ||
vs: PASSTHROUGH_VS_UV, | ||
fs: PASSTHROUGH_FS_UV, | ||
attribs: { position: "vec2", uv: "vec2" }, | ||
varying: { v_uv: "vec2" }, | ||
uniforms: { tex: "sampler2D" }, | ||
state: { depth: false }, | ||
ext: {} | ||
}; | ||
|
||
export type GPGPUSize = number | [number, number]; | ||
export interface ShaderPipelineOpts { | ||
size: GPGPUSize; | ||
gl: WebGLRenderingContext | WebGL2RenderingContext; | ||
// canvas?: HTMLCanvasElement; | ||
version?: 1 | 2; | ||
textures: IObjectOf<TextureOpts>; | ||
passes: ShaderPass; | ||
} | ||
|
||
export interface ShaderPass { | ||
inputs: string[]; | ||
outputs: string[]; | ||
size?: [number, number]; | ||
uniforms?: ShaderUniformSpecs; | ||
fn: ShaderFn; | ||
} | ||
|
||
// export const shaderPipeline = (opts: ShaderPipelineOpts) => { | ||
// let width: number, height: number; | ||
// const gl = opts.gl; | ||
// if (isNumber(opts.size)) { | ||
// width = height = ceilPow2(Math.ceil(Math.sqrt(opts.size / 4))); | ||
// } else { | ||
// [width, height] = opts.size; | ||
// } | ||
// const textures = Object.keys(opts.textures).reduce((acc, id) => { | ||
// const tex = opts.textures[id]; | ||
// const format = TEX_FORMATS[tex.format]; | ||
// acc[id] = _texture(gl, { | ||
// width, | ||
// height | ||
// }); | ||
// }, {}); | ||
// }; |
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
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
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