Skip to content

Commit 055f54e

Browse files
committed
Make OES_texture_float an option instead of default
1 parent 8808d81 commit 055f54e

2 files changed

Lines changed: 35 additions & 31 deletions

File tree

src/backend/mode_cpu.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,24 @@
161161
return ret;
162162
};
163163

164-
ret.wraparound = function() {
165-
opt.wraparound = false;
164+
ret.wraparound = function(flag) {
165+
console.warn("Wraparound mode is not supported and undocumented.");
166+
opt.wraparound = flag;
166167
return ret;
167168
};
168169

169-
ret.hardcodeConstants = function() {
170-
opt.hardcodeConstants = false;
170+
ret.hardcodeConstants = function(flag) {
171+
opt.hardcodeConstants = flag;
171172
return ret;
172173
};
173174

174-
ret.outputToTexture = function() {
175-
opt.outputToTexture = false;
175+
ret.outputToTexture = function(flag) {
176+
opt.outputToTexture = flag;
177+
return ret;
178+
};
179+
180+
ret.floatTextures = function(flag) {
181+
opt.floatTextures = flag;
176182
return ret;
177183
};
178184

src/backend/mode_gpu.js

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,14 @@
11
(function(GPU) {
2-
function dimToTexSize(gpu, dimensions, output) {
2+
function dimToTexSize(opt, dimensions, output) {
33
var numTexels = dimensions[0];
44
for (var i=1; i<dimensions.length; i++) {
55
numTexels *= dimensions[i];
66
}
77

8-
if (gpu.OES_texture_float && !output) {
8+
if (opt.floatTextures && !output) {
99
numTexels = Math.ceil(numTexels / 4);
1010
}
1111

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-
2412
var w = Math.ceil(Math.sqrt(numTexels));
2513
return [w, w];
2614
}
@@ -158,6 +146,10 @@
158146
var programCache = [];
159147

160148
function ret() {
149+
if (opt.floatTextures && !gpu.OES_texture_float) {
150+
throw "Float textures are not supported on this browser";
151+
}
152+
161153
if (!opt.dimensions || opt.dimensions.length === 0) {
162154
if (arguments.length != 1) {
163155
throw "Auto dimensions only supported for kernels with only one input";
@@ -340,19 +332,19 @@
340332
' highp vec3 xyz = vec3(floor(x + 0.5), floor(y + 0.5), floor(z + 0.5));',
341333
(opt.wraparound ? ' xyz = mod(xyz, texDim);' : ''),
342334
' 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);' : ''),
345337
' highp float w = floor(texSize.x + 0.5);',
346338
' highp float s = integerMod(index, w);',
347339
' highp float t = float(int(index) / int(w));',
348340
' s += 0.5;',
349341
' t += 0.5;',
350-
(gpu.OES_texture_float ? ' index = float(int(index)/4);' : ''),
342+
(opt.floatTextures ? ' index = float(int(index)/4);' : ''),
351343
' 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;' : ''),
356348
' return decode32(texel);',
357349
'}',
358350
'',
@@ -474,15 +466,15 @@
474466

475467
var paramArray = flatten(arguments[textureCount]);
476468
var paramLength = paramSize[0] * paramSize[1];
477-
if (gpu.OES_texture_float) {
469+
if (opt.floatTextures) {
478470
paramLength *= 4;
479471
}
480472
while (paramArray.length < paramLength) {
481473
paramArray.push(0);
482474
}
483475

484476
var argBuffer;
485-
if (gpu.OES_texture_float) {
477+
if (opt.floatTextures) {
486478
argBuffer = new Float32Array(paramArray);
487479
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, paramSize[0], paramSize[1], 0, gl.RGBA, gl.FLOAT, argBuffer);
488480
} else {
@@ -595,6 +587,7 @@
595587
};
596588

597589
ret.wraparound = function(flag) {
590+
console.warn("Wraparound mode is not supported and undocumented.");
598591
opt.wraparound = flag;
599592
return ret;
600593
};
@@ -604,8 +597,13 @@
604597
return ret;
605598
};
606599

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;
609607
return ret;
610608
};
611609

0 commit comments

Comments
 (0)