|
1 | 1 | (function(GPU) { |
2 | | - function dimToTexSize(gpu, dimensions, output) { |
| 2 | + function dimToTexSize(opt, dimensions, output) { |
3 | 3 | var numTexels = dimensions[0]; |
4 | 4 | for (var i=1; i<dimensions.length; i++) { |
5 | 5 | numTexels *= dimensions[i]; |
6 | 6 | } |
7 | 7 |
|
8 | | - if (gpu.OES_texture_float && !output) { |
| 8 | + if (opt.floatTextures && !output) { |
9 | 9 | numTexels = Math.ceil(numTexels / 4); |
10 | 10 | } |
11 | 11 |
|
12 | | - // TODO: find out why this is broken in Safari |
13 | | - /* |
14 | | - var gl = gpu.getGl(); |
15 | | - var maxSize = gl.getParameter(gl.MAX_TEXTURE_SIZE); |
16 | | - if (numTexels < maxSize) { |
17 | | - return [numTexels, 1]; |
18 | | - } else { |
19 | | - var height = Math.ceil(numTexels / maxSize); |
20 | | - return [maxSize, height]; |
21 | | - } |
22 | | - */ |
23 | | - |
24 | 12 | var w = Math.ceil(Math.sqrt(numTexels)); |
25 | 13 | return [w, w]; |
26 | 14 | } |
|
158 | 146 | var programCache = []; |
159 | 147 |
|
160 | 148 | function ret() { |
| 149 | + if (opt.floatTextures && !gpu.OES_texture_float) { |
| 150 | + throw "Float textures are not supported on this browser"; |
| 151 | + } |
| 152 | + |
161 | 153 | if (!opt.dimensions || opt.dimensions.length === 0) { |
162 | 154 | if (arguments.length != 1) { |
163 | 155 | throw "Auto dimensions only supported for kernels with only one input"; |
|
340 | 332 | ' highp vec3 xyz = vec3(floor(x + 0.5), floor(y + 0.5), floor(z + 0.5));', |
341 | 333 | (opt.wraparound ? ' xyz = mod(xyz, texDim);' : ''), |
342 | 334 | ' highp float index = floor((xyz.z * texDim.x * texDim.y) + (xyz.y * texDim.x) + xyz.x + 0.5);', |
343 | | - (gpu.OES_texture_float ? ' int channel = int(integerMod(index, 4.0));' : ''), |
344 | | - (gpu.OES_texture_float ? ' index = float(int(index)/4);' : ''), |
| 335 | + (opt.floatTextures ? ' int channel = int(integerMod(index, 4.0));' : ''), |
| 336 | + (opt.floatTextures ? ' index = float(int(index)/4);' : ''), |
345 | 337 | ' highp float w = floor(texSize.x + 0.5);', |
346 | 338 | ' highp float s = integerMod(index, w);', |
347 | 339 | ' highp float t = float(int(index) / int(w));', |
348 | 340 | ' s += 0.5;', |
349 | 341 | ' t += 0.5;', |
350 | | - (gpu.OES_texture_float ? ' index = float(int(index)/4);' : ''), |
| 342 | + (opt.floatTextures ? ' index = float(int(index)/4);' : ''), |
351 | 343 | ' highp vec4 texel = texture2D(tex, vec2(s / texSize.x, t / texSize.y));', |
352 | | - (gpu.OES_texture_float ? ' if (channel == 0) return texel.r;' : ''), |
353 | | - (gpu.OES_texture_float ? ' if (channel == 1) return texel.g;' : ''), |
354 | | - (gpu.OES_texture_float ? ' if (channel == 2) return texel.b;' : ''), |
355 | | - (gpu.OES_texture_float ? ' if (channel == 3) return texel.a;' : ''), |
| 344 | + (opt.floatTextures ? ' if (channel == 0) return texel.r;' : ''), |
| 345 | + (opt.floatTextures ? ' if (channel == 1) return texel.g;' : ''), |
| 346 | + (opt.floatTextures ? ' if (channel == 2) return texel.b;' : ''), |
| 347 | + (opt.floatTextures ? ' if (channel == 3) return texel.a;' : ''), |
356 | 348 | ' return decode32(texel);', |
357 | 349 | '}', |
358 | 350 | '', |
|
474 | 466 |
|
475 | 467 | var paramArray = flatten(arguments[textureCount]); |
476 | 468 | var paramLength = paramSize[0] * paramSize[1]; |
477 | | - if (gpu.OES_texture_float) { |
| 469 | + if (opt.floatTextures) { |
478 | 470 | paramLength *= 4; |
479 | 471 | } |
480 | 472 | while (paramArray.length < paramLength) { |
481 | 473 | paramArray.push(0); |
482 | 474 | } |
483 | 475 |
|
484 | 476 | var argBuffer; |
485 | | - if (gpu.OES_texture_float) { |
| 477 | + if (opt.floatTextures) { |
486 | 478 | argBuffer = new Float32Array(paramArray); |
487 | 479 | gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, paramSize[0], paramSize[1], 0, gl.RGBA, gl.FLOAT, argBuffer); |
488 | 480 | } else { |
|
595 | 587 | }; |
596 | 588 |
|
597 | 589 | ret.wraparound = function(flag) { |
| 590 | + console.warn("Wraparound mode is not supported and undocumented."); |
598 | 591 | opt.wraparound = flag; |
599 | 592 | return ret; |
600 | 593 | }; |
|
604 | 597 | return ret; |
605 | 598 | }; |
606 | 599 |
|
607 | | - ret.outputToTexture = function(outputToTexture) { |
608 | | - opt.outputToTexture = outputToTexture; |
| 600 | + ret.outputToTexture = function(flag) { |
| 601 | + opt.outputToTexture = flag; |
| 602 | + return ret; |
| 603 | + }; |
| 604 | + |
| 605 | + ret.floatTextures = function(flag) { |
| 606 | + opt.floatTextures = flag; |
609 | 607 | return ret; |
610 | 608 | }; |
611 | 609 |
|
|
0 commit comments