1
1
import type { IObjectOf } from "@thi.ng/api" ;
2
2
import { assert } from "@thi.ng/errors/assert" ;
3
- import { S2D , V2 , V4 } from "@thi.ng/shader-ast/api/types" ;
3
+ import { S2D , S3D , V2 , V4 } from "@thi.ng/shader-ast/api/types" ;
4
4
import { assign } from "@thi.ng/shader-ast/ast/assign" ;
5
5
import { defMain } from "@thi.ng/shader-ast/ast/function" ;
6
6
import { INT0 , ivec2 } from "@thi.ng/shader-ast/ast/lit" ;
7
7
import { $xy } from "@thi.ng/shader-ast/ast/swizzle" ;
8
8
import { texelFetch } from "@thi.ng/shader-ast/builtin/texture" ;
9
+ import { mapIndexed } from "@thi.ng/transducers" ;
9
10
import { assocObj } from "@thi.ng/transducers/assoc-obj" ;
10
11
import { map } from "@thi.ng/transducers/map" ;
11
12
import { range } from "@thi.ng/transducers/range" ;
@@ -19,7 +20,12 @@ import type {
19
20
ShaderUniformSpecs ,
20
21
UniformDecl ,
21
22
} from "./api/shader.js" ;
22
- import type { ITexture } from "./api/texture.js" ;
23
+ import {
24
+ TextureFilter ,
25
+ TextureRepeat ,
26
+ TextureTarget ,
27
+ type ITexture ,
28
+ } from "./api/texture.js" ;
23
29
import { compileModel } from "./buffer.js" ;
24
30
import { isFloatTexture , isGL2Context } from "./checks.js" ;
25
31
import { draw } from "./draw.js" ;
@@ -110,28 +116,38 @@ const initPasses = (opts: MultipassOpts, textures: IObjectOf<ITexture>) => {
110
116
} ) ;
111
117
} ;
112
118
119
+ const TEX_TYPE_MAP : Record < number , string > = {
120
+ [ TextureTarget . TEXTURE_2D ] : S2D ,
121
+ [ TextureTarget . TEXTURE_3D ] : S3D ,
122
+ [ TextureTarget . TEXTURE_CUBE_MAP ] : "samplerCube" ,
123
+ } ;
124
+
113
125
const initShader = (
114
126
gl : WebGLRenderingContext ,
115
127
pass : PassOpts ,
116
128
textures : IObjectOf < ITexture >
117
129
) => {
118
130
const isGL2 = isGL2Context ( gl ) ;
119
- const numIns = pass . inputs . length ;
131
+ // const numIns = pass.inputs.length;
120
132
const numOuts = pass . outputs . length ;
121
- const ext : ExtensionBehaviors = { } ;
133
+ const ext : ExtensionBehaviors = { ... pass . ext } ;
122
134
const spec : ShaderSpec = {
123
135
vs : pass . vs || PASSTHROUGH_VS ,
124
136
fs : pass . fs ,
125
- attribs : pass . attribs || {
126
- position : V2 ,
127
- } ,
137
+ attribs : pass . attribs || { position : V2 } ,
128
138
varying : pass . varying ,
129
139
uniforms : < ShaderUniformSpecs > {
130
140
...pass . uniforms ,
131
141
...transduce (
132
- map ( ( i ) => < [ string , UniformDecl ] > [ `input${ i } ` , [ S2D , i ] ] ) ,
142
+ mapIndexed (
143
+ ( i , id ) =>
144
+ < [ string , UniformDecl ] > [
145
+ `input${ i } ` ,
146
+ [ TEX_TYPE_MAP [ textures [ id ] . target ] , i ] ,
147
+ ]
148
+ ) ,
133
149
assocObj ( ) ,
134
- range ( numIns )
150
+ pass . inputs
135
151
) ,
136
152
} ,
137
153
outputs : numOuts
@@ -170,8 +186,9 @@ const initTextures = (opts: MultipassOpts) =>
170
186
acc [ id ] = defTexture ( opts . gl , {
171
187
width : opts . width ,
172
188
height : opts . height ,
173
- filter : opts . gl . NEAREST ,
174
- wrap : opts . gl . CLAMP_TO_EDGE ,
189
+ depth : opts . depth ,
190
+ filter : TextureFilter . NEAREST ,
191
+ wrap : TextureRepeat . CLAMP ,
175
192
image : null ,
176
193
...opts . textures [ id ] ,
177
194
} ) ;
0 commit comments