-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshader.ts
More file actions
27 lines (24 loc) · 784 Bytes
/
shader.ts
File metadata and controls
27 lines (24 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { Program, VertexArray } from 'luma.gl'
import { Cell, Seed } from './loop'
import { GLContext } from './contexts'
type Props = { vs: string, fs: string }
export type Shader = {
program: Program
vertexArray: VertexArray
}
export default function Shader(props: Props, cell?: Cell): Shader {
if (!cell) return Seed<Shader>(Shader, props)
const { vs, fs } = props
const gl = cell.read(GLContext)
return cell.effect<Shader>('program', _ => {
const program = new Program(gl, { vs, fs })
const vertexArray = new VertexArray(gl, { program })
_({program, vertexArray})
return (binding: any) => {
if (!binding) return
const { program, vertexArray } = binding
program.delete()
vertexArray.delete()
}
}, [gl, vs, fs])
}