( makeTexture: (gl: any) => WebGLTexture, size: [number, number] )
| 308 | ); |
| 309 | |
| 310 | export function createOneTextureLoader( |
| 311 | makeTexture: (gl: any) => WebGLTexture, |
| 312 | size: [number, number] |
| 313 | ) { |
| 314 | const textureId = Symbol("one-texture"); |
| 315 | const counters = { |
| 316 | constructor: 0, |
| 317 | dispose: 0, |
| 318 | canLoad: 0, |
| 319 | get: 0, |
| 320 | load: 0, |
| 321 | createTexture: 0 |
| 322 | }; |
| 323 | const d = defer(); |
| 324 | function resolve() { |
| 325 | d.resolve(); |
| 326 | return delay(50); // FIXME this is a hack. |
| 327 | } |
| 328 | function reject(e: Error) { |
| 329 | d.reject(e); |
| 330 | return delay(50); // FIXME this is a hack. |
| 331 | } |
| 332 | class Loader extends WebGLTextureLoader<typeof textureId> { |
| 333 | texture: ?Texture = null; |
| 334 | constructor(gl: WebGLRenderingContext) { |
| 335 | super(gl); |
| 336 | ++counters.constructor; |
| 337 | } |
| 338 | dispose() { |
| 339 | ++counters.dispose; |
| 340 | } |
| 341 | canLoad(input: any) { |
| 342 | ++counters.canLoad; |
| 343 | return input === textureId; |
| 344 | } |
| 345 | get() { |
| 346 | ++counters.get; |
| 347 | return ( |
| 348 | this.texture && { |
| 349 | texture: this.texture, |
| 350 | width: size[0], |
| 351 | height: size[1] |
| 352 | } |
| 353 | ); |
| 354 | } |
| 355 | load() { |
| 356 | ++counters.load; |
| 357 | const promise = d.promise.then(() => { |
| 358 | ++counters.createTexture; |
| 359 | this.texture = makeTexture(this.gl); |
| 360 | return { |
| 361 | texture: this.texture, |
| 362 | width: size[0], |
| 363 | height: size[1] |
| 364 | }; |
| 365 | }); |
| 366 | return promise; |
| 367 | } |
no outgoing calls
searching dependent graphs…