forked from doodlewind/beam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
148 lines (128 loc) · 4.11 KB
/
index.d.ts
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
export = Beam
declare namespace Beam {
export enum SchemaTypes {
vec4 = 'vec4',
vec3 = 'vec3',
vec2 = 'vec2',
int = 'int',
float = 'float',
mat4 = 'mat4',
mat3 = 'mat3',
mat2 = 'mat2',
tex2D = 'tex2D',
texCube = 'texCube'
}
export enum ResourceTypes {
VertexBuffers = 'VertexBuffers',
IndexBuffer = 'IndexBuffer',
Uniforms = 'Uniforms',
Textures = 'Textures',
OffscreenTarget = 'OffscreenTarget'
}
export enum GLTypes {
Triangles = 'Triangles',
Lines = 'Lines',
Repeat = 'Repeat',
MirroredRepeat = 'MirroredRepeat',
ClampToEdge = 'ClampToEdge',
Nearest = 'Nearest',
Linear = 'Linear',
NearestMipmapNearest = 'NearestMipmapNearest',
LinearMipmapNearest = 'LinearMipmapNearest',
NearestMipmapLinear = 'NearestMipmapLinear',
LinearMipmapLinear = 'LinearMipmapLinear',
RGB = 'RGB',
RGBA = 'RGBA',
SRGB = 'SRGB'
}
type Buffers = {
[key: string]: {
type: SchemaTypes;
default?: any;
n?: number;
}
}
type Uniforms = {
[key: string]: {
type: SchemaTypes;
default?: any;
}
}
type Textures = {
[key: string]: {
type: SchemaTypes;
default?: any;
}
}
export class Beam {
constructor(canvas: HTMLCanvasElement, config?: {
contextAttributes: object;
extensions: string[];
})
clear(color?: [Number, Number, Number, Number]): this
shader<B extends Buffers, U extends Uniforms, T extends Textures>(shaderTemplate: {
vs: string,
fs: string,
buffers?: B,
uniforms?: U,
textures?: T,
mode?: GLTypes
}): Shader<B, U, T>
draw(shader: Shader, ...resources: Resource[]): this
resource<T extends ResourceTypes, S extends object = {}>(type: T, state?: S): (
T extends ResourceTypes.VertexBuffers ? VertexBuffersResource<S> :
T extends ResourceTypes.IndexBuffer ? IndexBufferResource<S> :
T extends ResourceTypes.OffscreenTarget ? OffscreenTargetResource<S> :
T extends ResourceTypes.Textures ? TexturesResource<S> :
T extends ResourceTypes.Uniforms ? UniformsResource<S> :
never
)
define(command: {
name: string,
onBefore: (gl?: WebGLRenderingContext, args?: any) => void,
onAfter: (gl?: WebGLRenderingContext, args?: any) => void,
}): void
offscreen2D(offscreenTarget: OffscreenTargetResource, handler: Function): void
}
interface Shader<B extends Buffers = {}, U extends Uniforms = {}, T extends Textures = {}> {
beam: Beam
schema: {
buffers: B,
uniforms: U,
textures: T,
mode: GLTypes
}
shaderRefs: {
program: WebGLProgram,
attributes: {
[key: string]: {
type: SchemaTypes,
location: number
}
},
uniforms: {
[key: string]: {
type: SchemaTypes,
location: number
}
}
}
}
interface Resource<T = '', S = {}> {
type: T
state: S
set<K extends keyof S>(key: K | string, val: any): this
set(state: Partial<S> | any): this
}
interface VertexBuffersResource<S = {}> extends Resource<ResourceTypes.VertexBuffers, S> {}
interface IndexBufferResource<S = {}> extends Resource<ResourceTypes.IndexBuffer, S> {
destroy(): void
}
interface UniformsResource<S = {}> extends Resource<ResourceTypes.Uniforms, S> {}
interface TexturesResource<S = {}> extends Resource<ResourceTypes.Textures, S> {
destroy(): void
}
interface OffscreenTargetResource<S = {}> extends Resource<ResourceTypes.OffscreenTarget, S> {
destroy(): void
}
}