diff --git a/API.md b/API.md index b2f3c8b3..9465cfd4 100644 --- a/API.md +++ b/API.md @@ -2627,6 +2627,8 @@ regl exposes info about the WebGL context limits and capabilities via the `regl. | `vendor` | `gl.VENDOR` | | `version` | `gl.VERSION` | | `textureFormats` | A list of all supported texture formats | +| `readFloat` | If reading float numbers is supported | +| `npotTextureCube` | If non power of two cube texture dimensions are supported | **Relevant WebGL APIs** @@ -2782,7 +2784,7 @@ By default, `regl` is compiled with a number of assertions, checks and validatio ### Profiling tips -If your application is running too slow and you want to understand what is going on, regl provides many hooks which you can use to monitor and [debug your performance](https://github.com/mikolalysenko/regl/blob/gh-pages/API.md#profiling). +If your application is running too slow and you want to understand what is going on, regl provides many hooks which you can use to monitor and [debug your performance](https://github.com/regl-project/regl/blob/gh-pages/API.md#profiling). ### Context loss mitigation @@ -2790,4 +2792,4 @@ A WebGL application must be prepared to lose context at any time. This is an un ### Use batch mode -If you want to draw a bunch of copies of the same object, only with different properties, be sure to use [batch mode](https://github.com/mikolalysenko/regl/blob/gh-pages/API.md#batch-rendering). Commands rendered in batch mode can be optimized by avoiding certain state checks which are required for serial commands. +If you want to draw a bunch of copies of the same object, only with different properties, be sure to use [batch mode](https://github.com/regl-project/regl/blob/gh-pages/API.md#batch-rendering). Commands rendered in batch mode can be optimized by avoiding certain state checks which are required for serial commands. diff --git a/DEVELOPING.md b/DEVELOPING.md index 8a0080ee..e458ad50 100644 --- a/DEVELOPING.md +++ b/DEVELOPING.md @@ -138,7 +138,7 @@ The easiest way to add a new benchmark is to copy an existing benchmark (see for ### Size measurements -You can also get a report of the current bundle size of regl using [disc](https://github.com/hughsk/disc). [An up to date set of stats can be found in `www/size.html`.](https://mikolalysenko.github.io/regl/www/size.html) +You can also get a report of the current bundle size of regl using [disc](https://github.com/hughsk/disc). [An up to date set of stats can be found in `www/size.html`.](https://regl-project.github.io/regl/www/size.html) To regenerate these results, run the command @@ -148,7 +148,7 @@ npm run build-size ## Comparisons -The [comparisons pages](https://mikolalysenko.github.io/regl/www/compare.html) is autogenerated from the contents of the `compare/` directory. Each sub directory in the compare directory contains a task, and each task directory contains several implementations of this task. +The [comparisons pages](https://regl-project.github.io/regl/www/compare.html) is autogenerated from the contents of the `compare/` directory. Each sub directory in the compare directory contains a task, and each task directory contains several implementations of this task. An implementation may be either a raw JavaScript file (which is compiled with browserify) or an HTML web page. Each task must contain an image of the expected results (called `expected.png`) and a description called `description.txt`. @@ -164,8 +164,8 @@ npm run build Check out the [change log](CHANGES.md) for planned features and tasks. -There is also a list of [open issues on GitHub that need work](https://github.com/mikolalysenko/regl/issues). Anything with the "help wanted" tag may be good for a beginner starting out. +There is also a list of [open issues on GitHub that need work](https://github.com/regl-project/regl/issues). Anything with the "help wanted" tag may be good for a beginner starting out. Alternatively, if you want to propose a new feature or report a bug, you should open an issue on GitHub. -There is also active discussion in the [gitter chat](https://gitter.im/mikolalysenko/regl). If you join there, you can usually find someone to talk to. +There is also active discussion in the [gitter chat](https://gitter.im/regl-project/regl). If you join there, you can usually find someone to talk to. diff --git a/README.md b/README.md index a9db7e97..157dbe5e 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ [](https://nodejs.org/api/documentation.html#documentation_stability_index) [](https://npmjs.org/package/regl) [](https://travis-ci.org/regl-project/regl/) - [](https://npmcdn.com/regl/dist/regl.min.js) + [](https://npmcdn.com/regl/dist/regl.min.js) [](https://npmjs.org/package/regl) [](https://standardjs.com) @@ -28,7 +28,7 @@ Docs | - + Chat | diff --git a/bench/bench-graph.js b/bench/bench-graph.js index 68eb0cfe..474a2d3b 100644 --- a/bench/bench-graph.js +++ b/bench/bench-graph.js @@ -201,7 +201,7 @@ function createGraph (json) { .append('a') .attr('xlink:href', function (d) { - return 'https://github.com/mikolalysenko/regl/commit/' + d.hash + return 'https://github.com/regl-project/regl/commit/' + d.hash }) .attr('target', '"_blank"') .append('circle') @@ -219,7 +219,7 @@ function createGraph (json) { var desc = d.title + d.description var shortenedDesc = desc.length > 70 ? desc.substring(0, 69) + '...' : desc - var commitUrl = 'https://github.com/mikolalysenko/regl/commit/' + d.hash + var commitUrl = 'https://github.com/regl-project/regl/commit/' + d.hash var timeDiff = moment(d.date).fromNow() diff --git a/bin/build-gallery.js b/bin/build-gallery.js index ca113d5c..738db2ac 100644 --- a/bin/build-gallery.js +++ b/bin/build-gallery.js @@ -241,7 +241,7 @@ function generateGallery (files) { // source code link li += '
' + 'Source Code' + '
' diff --git a/lib/buffer.js b/lib/buffer.js index ae792125..3dcb55a7 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -268,7 +268,8 @@ module.exports = function wrapBufferState (gl, stats, config, attributeState) { buffer.bind() if (!data) { - gl.bufferData(buffer.type, byteLength, usage) + // #475 + if (byteLength) gl.bufferData(buffer.type, byteLength, usage) buffer.dtype = dtype || GL_UNSIGNED_BYTE buffer.usage = usage buffer.dimension = dimension diff --git a/lib/core.js b/lib/core.js index 025ac24e..2d788d0f 100644 --- a/lib/core.js +++ b/lib/core.js @@ -3278,7 +3278,6 @@ module.exports = function reglCore ( emitPollFramebuffer(env, refresh, null, true) // Refresh updates all attribute state changes - var extInstancing = gl.getExtension('angle_instanced_arrays') var INSTANCING if (extInstancing) { INSTANCING = env.link(extInstancing) diff --git a/lib/limits.js b/lib/limits.js index 6bd35e03..d5f2f283 100644 --- a/lib/limits.js +++ b/lib/limits.js @@ -1,3 +1,5 @@ +var pool = require('./util/pool') + var GL_SUBPIXEL_BITS = 0x0D50 var GL_RED_BITS = 0x0D52 var GL_GREEN_BITS = 0x0D53 @@ -31,6 +33,18 @@ var GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT = 0x84FF var GL_MAX_COLOR_ATTACHMENTS_WEBGL = 0x8CDF var GL_MAX_DRAW_BUFFERS_WEBGL = 0x8824 +var GL_TEXTURE_2D = 0x0DE1 +var GL_TEXTURE_CUBE_MAP = 0x8513 +var GL_TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515 +var GL_TEXTURE0 = 0x84C0 +var GL_RGBA = 0x1908 +var GL_FLOAT = 0x1406 +var GL_UNSIGNED_BYTE = 0x1401 +var GL_FRAMEBUFFER = 0x8D40 +var GL_FRAMEBUFFER_COMPLETE = 0x8CD5 +var GL_COLOR_ATTACHMENT0 = 0x8CE0 +var GL_COLOR_BUFFER_BIT = 0x4000 + module.exports = function (gl, extensions) { var maxAnisotropic = 1 if (extensions.ext_texture_filter_anisotropic) { @@ -44,6 +58,51 @@ module.exports = function (gl, extensions) { maxColorAttachments = gl.getParameter(GL_MAX_COLOR_ATTACHMENTS_WEBGL) } + // detect if reading float textures is available (Safari doesn't support) + var readFloat = !!extensions.oes_texture_float + if (readFloat) { + var readFloatTexture = gl.createTexture() + gl.bindTexture(GL_TEXTURE_2D, readFloatTexture) + gl.texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_FLOAT, null) + + var fbo = gl.createFramebuffer() + gl.bindFramebuffer(GL_FRAMEBUFFER, fbo) + gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, readFloatTexture, 0) + gl.bindTexture(GL_TEXTURE_2D, null) + + if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) !== GL_FRAMEBUFFER_COMPLETE) readFloat = false + + else { + gl.viewport(0, 0, 1, 1) + gl.clearColor(1.0, 0.0, 0.0, 1.0) + gl.clear(GL_COLOR_BUFFER_BIT) + var pixels = pool.allocType(GL_FLOAT, 4) + gl.readPixels(0, 0, 1, 1, GL_RGBA, GL_FLOAT, pixels) + + if (gl.getError()) readFloat = false + else { + gl.deleteFramebuffer(fbo) + gl.deleteTexture(readFloatTexture) + + readFloat = pixels[0] === 1.0 + } + + pool.freeType(pixels) + } + } + + // detect non power of two cube textures support (IE doesn't support) + var npotTextureCube = true + var cubeTexture = gl.createTexture() + var data = pool.allocType(GL_UNSIGNED_BYTE, 36) + gl.activeTexture(GL_TEXTURE0) + gl.bindTexture(GL_TEXTURE_CUBE_MAP, cubeTexture) + gl.texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 3, 3, 0, GL_RGBA, GL_UNSIGNED_BYTE, data) + pool.freeType(data) + gl.bindTexture(GL_TEXTURE_CUBE_MAP, null) + gl.deleteTexture(cubeTexture) + npotTextureCube = !gl.getError() + return { // drawing buffer bit depth colorBits: [ @@ -87,6 +146,10 @@ module.exports = function (gl, extensions) { glsl: gl.getParameter(GL_SHADING_LANGUAGE_VERSION), renderer: gl.getParameter(GL_RENDERER), vendor: gl.getParameter(GL_VENDOR), - version: gl.getParameter(GL_VERSION) + version: gl.getParameter(GL_VERSION), + + // quirks + readFloat: readFloat, + npotTextureCube: npotTextureCube } } diff --git a/lib/read.js b/lib/read.js index 00b10ae8..67ec5f40 100644 --- a/lib/read.js +++ b/lib/read.js @@ -12,7 +12,8 @@ module.exports = function wrapReadPixels ( reglPoll, context, glAttributes, - extensions) { + extensions, + limits) { function readPixelsImpl (input) { var type if (framebufferState.next === null) { @@ -30,6 +31,10 @@ module.exports = function wrapReadPixels ( check( type === GL_UNSIGNED_BYTE || type === GL_FLOAT, 'Reading from a framebuffer is only allowed for the types \'uint8\' and \'float\'') + + if (type === GL_FLOAT) { + check(limits.readFloat, 'Reading \'float\' values is not permitted in your browser. For a fallback, please see: https://www.npmjs.com/package/glsl-read-float') + } } else { check( type === GL_UNSIGNED_BYTE, @@ -128,3 +133,4 @@ module.exports = function wrapReadPixels ( return readPixels } + diff --git a/lib/texture.js b/lib/texture.js index 7b3e0858..a6b53957 100644 --- a/lib/texture.js +++ b/lib/texture.js @@ -7,6 +7,7 @@ var pool = require('./util/pool') var convertToHalfFloat = require('./util/to-half-float') var isArrayLike = require('./util/is-array-like') var flattenUtils = require('./util/flatten') +var isPow2 = require('./util/is-pow2') var dtypes = require('./constants/arraytypes.json') var arrayTypes = require('./constants/arraytypes.json') @@ -827,6 +828,7 @@ module.exports = function createTextureSet ( var type = info.type var width = info.width var height = info.height + var channels = info.channels setFlags(info) @@ -839,8 +841,16 @@ module.exports = function createTextureSet ( gl.copyTexImage2D( target, miplevel, format, info.xOffset, info.yOffset, width, height, 0) } else { - gl.texImage2D( - target, miplevel, format, width, height, 0, format, type, data) + var nullData = !data + if (nullData) { + data = pool.zero.allocType(type, width * height * channels) + } + + gl.texImage2D(target, miplevel, format, width, height, 0, format, type, data) + + if (nullData && data) { + pool.zero.freeType(data) + } } } @@ -1324,17 +1334,27 @@ module.exports = function createTextureSet ( reglTexture2D.height = texture.height = h tempBind(texture) + + var data + var channels = texture.channels + var type = texture.type + for (var i = 0; texture.mipmask >> i; ++i) { + var _w = w >> i + var _h = h >> i + if (!_w || !_h) break + data = pool.zero.allocType(type, _w * _h * channels) gl.texImage2D( GL_TEXTURE_2D, i, texture.format, - w >> i, - h >> i, + _w, + _h, 0, texture.format, texture.type, - null) + data) + if (data) pool.zero.freeType(data) } tempRestore() @@ -1420,6 +1440,11 @@ module.exports = function createTextureSet ( } copyFlags(texture, faces[0]) + + if (!limits.npotTextureCube) { + check(isPow2(texture.width) && isPow2(texture.height), 'your browser does not support non power or two texture dimensions') + } + if (texInfo.genMipmaps) { texture.mipmask = (faces[0].width << 1) - 1 } else { diff --git a/lib/util/is-pow2.js b/lib/util/is-pow2.js new file mode 100644 index 00000000..1043d18d --- /dev/null +++ b/lib/util/is-pow2.js @@ -0,0 +1,3 @@ +module.exports = function (v) { + return !(v & (v - 1)) && (!!v) +} diff --git a/lib/util/pool.js b/lib/util/pool.js index 9e8f24e7..f6c1c0a4 100644 --- a/lib/util/pool.js +++ b/lib/util/pool.js @@ -8,10 +8,6 @@ var GL_INT = 5124 var GL_UNSIGNED_INT = 5125 var GL_FLOAT = 5126 -var bufferPool = loop(8, function () { - return [] -}) - function nextPow16 (v) { for (var i = 16; i <= (1 << 28); i *= 16) { if (v <= i) { @@ -34,59 +30,70 @@ function log2 (v) { return r | (v >> 1) } -function alloc (n) { - var sz = nextPow16(n) - var bin = bufferPool[log2(sz) >> 2] - if (bin.length > 0) { - return bin.pop() +function createPool () { + var bufferPool = loop(8, function () { + return [] + }) + + function alloc (n) { + var sz = nextPow16(n) + var bin = bufferPool[log2(sz) >> 2] + if (bin.length > 0) { + return bin.pop() + } + return new ArrayBuffer(sz) } - return new ArrayBuffer(sz) -} -function free (buf) { - bufferPool[log2(buf.byteLength) >> 2].push(buf) -} + function free (buf) { + bufferPool[log2(buf.byteLength) >> 2].push(buf) + } -function allocType (type, n) { - var result = null - switch (type) { - case GL_BYTE: - result = new Int8Array(alloc(n), 0, n) - break - case GL_UNSIGNED_BYTE: - result = new Uint8Array(alloc(n), 0, n) - break - case GL_SHORT: - result = new Int16Array(alloc(2 * n), 0, n) - break - case GL_UNSIGNED_SHORT: - result = new Uint16Array(alloc(2 * n), 0, n) - break - case GL_INT: - result = new Int32Array(alloc(4 * n), 0, n) - break - case GL_UNSIGNED_INT: - result = new Uint32Array(alloc(4 * n), 0, n) - break - case GL_FLOAT: - result = new Float32Array(alloc(4 * n), 0, n) - break - default: - return null + function allocType (type, n) { + var result = null + switch (type) { + case GL_BYTE: + result = new Int8Array(alloc(n), 0, n) + break + case GL_UNSIGNED_BYTE: + result = new Uint8Array(alloc(n), 0, n) + break + case GL_SHORT: + result = new Int16Array(alloc(2 * n), 0, n) + break + case GL_UNSIGNED_SHORT: + result = new Uint16Array(alloc(2 * n), 0, n) + break + case GL_INT: + result = new Int32Array(alloc(4 * n), 0, n) + break + case GL_UNSIGNED_INT: + result = new Uint32Array(alloc(4 * n), 0, n) + break + case GL_FLOAT: + result = new Float32Array(alloc(4 * n), 0, n) + break + default: + return null + } + if (result.length !== n) { + return result.subarray(0, n) + } + return result } - if (result.length !== n) { - return result.subarray(0, n) + + function freeType (array) { + free(array.buffer) } - return result -} -function freeType (array) { - free(array.buffer) + return { + alloc: alloc, + free: free, + allocType: allocType, + freeType: freeType + } } -module.exports = { - alloc: alloc, - free: free, - allocType: allocType, - freeType: freeType -} +module.exports = createPool() + +// zero pool for initial zero data +module.exports.zero = createPool() diff --git a/lib/webgl.js b/lib/webgl.js index 5449a44f..25874288 100644 --- a/lib/webgl.js +++ b/lib/webgl.js @@ -52,10 +52,10 @@ function createCanvas (element, onDone, pixelRatio) { } } -function createContext (canvas, contexAttributes) { +function createContext (canvas, contextAttributes) { function get (name) { try { - return canvas.getContext(name, contexAttributes) + return canvas.getContext(name, contextAttributes) } catch (e) { return null } diff --git a/package.json b/package.json index 6e1d1d43..9090a866 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,8 @@ "google-closure-compiler": "^20160315.2.0", "hsv2rgb": "^1.1.0", "install": "^0.8.1", + "is-iexplorer": "^1.0.0", + "is-safari": "^1.0.0", "is-travis": "^2.0.0", "istanbul": "^0.4.3", "mkdirp": "^0.5.1", @@ -92,7 +94,7 @@ }, "scripts": { "test": "standard | snazzy && tape test/index.js | tap-min", - "test-browser": "budo test/util/browser.js --open", + "test-browser": "budo test/browser.js --open", "test-typescript": "tsc", "cover": "istanbul cover test/index.js", "bench-browser": "budo bench/bench.js --open", diff --git a/regl.js b/regl.js index 82f52755..ac8b4088 100644 --- a/regl.js +++ b/regl.js @@ -135,7 +135,7 @@ module.exports = function wrapREGL (args) { framebufferState, core.procs.poll, contextState, - glAttributes, extensions) + glAttributes, extensions, limits) var nextState = core.next var canvas = gl.canvas diff --git a/test/attributes-nested.js b/test/attributes-nested.js index 29d798ca..c282f9a7 100644 --- a/test/attributes-nested.js +++ b/test/attributes-nested.js @@ -46,8 +46,8 @@ tape('attributes nested', function (t) { function checkPixels (expected) { var actual = regl.read() - console.log('actual: ', actual) - console.log('expected: ', expected) + // console.log('actual: ', actual) + // console.log('expected: ', expected) for (var i = 0; i < 5 * 5; ++i) { if (!!actual[4 * i] !== !!expected[i]) { console.log('fail at: ', i) diff --git a/test/blend.js b/test/blend.js index 9aed11b9..a85398f7 100644 --- a/test/blend.js +++ b/test/blend.js @@ -117,7 +117,6 @@ tape('blend', function (t) { var staticOptions = { frag: [ 'precision mediump float;', - 'uniform vec4 color;', 'void main() {', ' gl_FragColor = vec4(1, 0, 0, 1);', '}' diff --git a/test/util/browser.js b/test/browser.js similarity index 98% rename from test/util/browser.js rename to test/browser.js index f6d1a772..372315b5 100644 --- a/test/util/browser.js +++ b/test/browser.js @@ -46,4 +46,4 @@ function updateDOM () { pendingRaf = null } -require('../index') +require('./index') diff --git a/test/buffer.js b/test/buffer.js index 9efd00cc..76cfc3f1 100644 --- a/test/buffer.js +++ b/test/buffer.js @@ -15,14 +15,12 @@ tape('buffer arg parsing', function (t) { t.same(bufferProps[prop], props[prop], prefix + '.' + prop) }) gl.bindBuffer(gl.ARRAY_BUFFER, bufferProps.buffer) - gl.getBufferParameter( + t.same(gl.getBufferParameter( gl.ARRAY_BUFFER, - gl.BUFFER_SIZE, - bufferProps.byteLength) - gl.getBufferParameter( + gl.BUFFER_SIZE), bufferProps.byteLength, prefix + ' gl.buffer size') + t.same(gl.getBufferParameter( gl.ARRAY_BUFFER, - gl.BUFFER_USAGE, - bufferProps.usage) + gl.BUFFER_USAGE), bufferProps.usage, prefix + ' gl.buffer usage') } checkProperties( diff --git a/test/constructor.js b/test/constructor.js index f6673fd7..2b129dff 100644 --- a/test/constructor.js +++ b/test/constructor.js @@ -1,6 +1,7 @@ var tape = require('tape') var createContext = require('./util/create-context') var createREGL = require('../regl') +var ie = require('is-iexplorer') tape('regl constructor', function (t) { // loading from a bad selector string breaks @@ -140,7 +141,7 @@ tape('regl constructor', function (t) { } }) t.equals(regl._gl.canvas, canvas, 'create from canvas ok') - t.equals(regl.attributes.premultipliedAlpha, false, 'create from attributes ok') + !ie && t.equals(regl.attributes.premultipliedAlpha, false, 'create from attributes ok') regl.destroy() var container = document.createElement('div') diff --git a/test/context-loss.js b/test/context-loss.js index 96e73674..9fb40603 100644 --- a/test/context-loss.js +++ b/test/context-loss.js @@ -240,6 +240,7 @@ function testContextLoss (t, gl, extLoseContext, onDone) { function pollTests () { if (tests.length === 0) { + t.equals(gl.getError(), 0, 'error ok') regl.destroy() onDone() return diff --git a/test/cube-fbo-resize.js b/test/cube-fbo-resize.js index e4e5157b..a5e81fa7 100644 --- a/test/cube-fbo-resize.js +++ b/test/cube-fbo-resize.js @@ -1,6 +1,7 @@ var createContext = require('./util/create-context') var createREGL = require('../regl') var tape = require('tape') +var ie = require('is-iexplorer') tape('cube fbo resize test', function (t) { var gl = createContext(2, 2) @@ -8,10 +9,19 @@ tape('cube fbo resize test', function (t) { t.equals(gl.getError(), 0, 'error code ok') - var cubeFbo = regl.framebufferCube(10) + var cubeFbo = regl.framebufferCube(8) t.equals(gl.getError(), 0, 'error code ok') - cubeFbo.resize(8) + cubeFbo.resize(4) + t.equals(gl.getError(), 0, 'error code ok') + + if (ie) { + t.throws(function () { + cubeFbo.resize(5) + }) + } else { + cubeFbo.resize(5) + } t.equals(gl.getError(), 0, 'error code ok') regl.destroy() diff --git a/test/culling.js b/test/culling.js index 5b170bae..85210110 100644 --- a/test/culling.js +++ b/test/culling.js @@ -30,7 +30,6 @@ tape('culling', function (t) { var staticOptions = { frag: [ 'precision mediump float;', - 'uniform vec4 color;', 'void main() {', ' gl_FragColor = vec4(1, 0, 0, 1);', '}' diff --git a/test/elements.js b/test/elements.js index e8ebb950..6bc598da 100644 --- a/test/elements.js +++ b/test/elements.js @@ -173,7 +173,6 @@ tape('elements', function (t) { t.ok('destroy successful') } ] - var poll = setInterval(function () { if (cases.length === 0) { clearInterval(poll) @@ -181,5 +180,5 @@ tape('elements', function (t) { } else { (cases.shift())() } - }) + }, 0) }) diff --git a/test/framebuffer-depth-stencil.js b/test/framebuffer-depth-stencil.js index 9ded9022..dd8c0a84 100644 --- a/test/framebuffer-depth-stencil.js +++ b/test/framebuffer-depth-stencil.js @@ -1,6 +1,7 @@ var createContext = require('./util/create-context') var createREGL = require('../regl') var tape = require('tape') +var ie = require('is-iexplorer') tape('framebuffer - depth stencil attachment', function (t) { var N = 5 @@ -44,6 +45,12 @@ tape('framebuffer - depth stencil attachment', function (t) { z: regl.prop('z') }, + depth: { + enable: function (context, props) { + return !!props.depth + } + }, + stencil: { enable: function (context, props) { return 'stencil' in props @@ -75,35 +82,41 @@ tape('framebuffer - depth stencil attachment', function (t) { color: [1, 0, 0, 1], x: [[-1, 2], [5, 2]], z: 0.5, - stencil: 1 + stencil: 1, + depth: depth }) drawLine({ color: [0, 1, 0, 1], x: [[1, -1], [1, 5]], z: 0.75, - stencil: 2 + stencil: 2, + depth: depth }) drawLine({ color: [0, 0, 1, 1], x: [[3, 0], [3, 5]], z: 0.25, - stencil: 1 + stencil: 1, + depth: depth }) } else { drawLine({ color: [1, 0, 0, 1], x: [[-1, 2], [5, 2]], - z: 0.5 + z: 0.5, + depth: depth }) drawLine({ color: [0, 1, 0, 1], x: [[1, -1], [1, 5]], - z: 0.75 + z: 0.75, + depth: depth }) drawLine({ color: [0, 0, 1, 1], x: [[3, -1], [3, 5]], - z: 0.25 + z: 0.25, + depth: depth }) } @@ -165,7 +178,7 @@ tape('framebuffer - depth stencil attachment', function (t) { // TODO: rendering to depth-stencil does not seem to work in headless // we should look into this. if (typeof document !== 'undefined') { - testFBOCube('color buffer only, cube fbo, ', + !ie && testFBOCube('color buffer only, cube fbo, ', regl.framebufferCube({ radius: N, depthStencil: false @@ -206,7 +219,7 @@ tape('framebuffer - depth stencil attachment', function (t) { }), true, true) - testFBOCube('depth-stencil renderbuffer - implicit, cube fbo, ', + !ie && testFBOCube('depth-stencil renderbuffer - implicit, cube fbo, ', regl.framebufferCube({ radius: N, depthStencil: true @@ -223,7 +236,7 @@ tape('framebuffer - depth stencil attachment', function (t) { }), true, true) - testFBOCube('depth-stencil renderbuffer, cube fbo, ', + !ie && testFBOCube('depth-stencil renderbuffer, cube fbo, ', regl.framebufferCube({ radius: N, depthStencil: regl.renderbuffer({ diff --git a/test/framebuffer-parse.js b/test/framebuffer-parse.js index 3779c679..663d2915 100644 --- a/test/framebuffer-parse.js +++ b/test/framebuffer-parse.js @@ -1,6 +1,7 @@ var createContext = require('./util/create-context') var createREGL = require('../regl') var tape = require('tape') +var ie = require('is-iexplorer') var GL_TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515 @@ -304,7 +305,7 @@ tape('framebuffer parsing', function (t) { }, 'explicit color cube') - checkPropertiesCube( + !ie && checkPropertiesCube( regl.framebufferCube({ radius: 5, stencil: true, @@ -325,7 +326,7 @@ tape('framebuffer parsing', function (t) { }, 'radius cube') - checkPropertiesCube( + !ie && checkPropertiesCube( regl.framebufferCube(5), { width: 5, @@ -362,7 +363,7 @@ tape('framebuffer parsing', function (t) { }, 'shape and no depth') - checkPropertiesCube( + !ie && checkPropertiesCube( regl.framebufferCube({ shape: [5, 5], depth: false, @@ -539,7 +540,7 @@ tape('framebuffer parsing', function (t) { // if not renderbuffer, also do the test for cubic fbo. if (testCase.tex) { try { - checkPropertiesCube( + !ie && checkPropertiesCube( regl.framebufferCube(fboArgs), { width: 10, diff --git a/test/framebuffer-resize.js b/test/framebuffer-resize.js index 986a04f5..bdfb9bcd 100644 --- a/test/framebuffer-resize.js +++ b/test/framebuffer-resize.js @@ -1,6 +1,7 @@ var createContext = require('./util/create-context') var createREGL = require('../regl') var tape = require('tape') +var ie = require('is-iexplorer') tape('framebuffer resizing', function (t) { var gl = createContext(16, 16) @@ -69,19 +70,21 @@ tape('framebuffer resizing', function (t) { checkFBO(fbo, {width: 2, height: 3}) t.equals(fbo.color[0], color) - // Now test .resize for cubic framebuffers. - var cubeFbo = regl.framebufferCube(10) + if (!ie) { + // Now test .resize for cubic framebuffers. + var cubeFbo = regl.framebufferCube(10) - t.equals(cubeFbo.resize(10), cubeFbo, 'cube, resizing to same size does nothing') - checkCubeFBO(cubeFbo, {width: 10, height: 10}) + t.equals(cubeFbo.resize(10), cubeFbo, 'cube, resizing to same size does nothing') + checkCubeFBO(cubeFbo, {width: 10, height: 10}) - // this testcase should pass, but right now it does not. - // We'll uncomment once issue #152 is resolved. - t.equals(cubeFbo.resize(3), cubeFbo, 'cube, resizing returns the right thing') - checkCubeFBO(cubeFbo, {width: 3, height: 3}) + // this testcase should pass, but right now it does not. + // We'll uncomment once issue #152 is resolved. + t.equals(cubeFbo.resize(3), cubeFbo, 'cube, resizing returns the right thing') + checkCubeFBO(cubeFbo, {width: 3, height: 3}) - cubeFbo({radius: 8}) - checkCubeFBO(cubeFbo, {width: 8, height: 8}) + cubeFbo({radius: 8}) + checkCubeFBO(cubeFbo, {width: 8, height: 8}) + } // now test .resize for MRT. if (regl.hasExtension('webgl_draw_buffers')) { diff --git a/test/framebuffer-simple.js b/test/framebuffer-simple.js index 57b7555e..ffeacb5f 100644 --- a/test/framebuffer-simple.js +++ b/test/framebuffer-simple.js @@ -1,6 +1,7 @@ var createContext = require('./util/create-context') var createREGL = require('../regl') var tape = require('tape') +var ie = require('is-iexplorer') tape('framebuffer', function (t) { var gl = createContext(16, 16) @@ -95,7 +96,7 @@ tape('framebuffer', function (t) { radius: 8 }) - var testCubeFBO1 = regl.framebufferCube({ + var testCubeFBO1 = !ie && regl.framebufferCube({ radius: 5 }) @@ -121,7 +122,7 @@ tape('framebuffer', function (t) { }, 'fbo 1 - static') }) - if (typeof document !== 'undefined') { + if (!ie && typeof document !== 'undefined') { for (i = 0; i < 6; i++) { setFramebufferStatic({ framebuffer: testCubeFBO1.faces[i] @@ -190,7 +191,7 @@ tape('framebuffer', function (t) { }, 'fbo 1 - restore') }) - if (typeof document !== 'undefined') { + if (!ie && typeof document !== 'undefined') { for (i = 0; i < 6; i++) { setFramebufferStatic({ framebuffer: testCubeFBO1.faces[i] @@ -287,7 +288,7 @@ tape('framebuffer', function (t) { color: [0, 0, 0, 255] }, 'draw buffer nested') - setFramebufferDynamic({ + !ie && setFramebufferDynamic({ framebuffer: testCubeFBO1.faces[(i + 1) % 6], color: [0, 0, 0, 0] }, function () { @@ -348,14 +349,14 @@ tape('framebuffer', function (t) { }) gl.finish() - /* if (typeof document !== 'undefined') { + if (!ie && typeof document !== 'undefined') { for (i = 0; i < 6; i++) { setFramebufferDynamic({ framebuffer: testCubeFBO1.faces[i], color: [0, 1, 1, 1] }) } - }*/ + } gl.finish() setFramebufferDynamic({ diff --git a/test/index.js b/test/index.js index 602a84c4..5152f0a7 100644 --- a/test/index.js +++ b/test/index.js @@ -1,5 +1,6 @@ // set minimal stacktrace to reduce obsessive logs -if (require('is-travis')) Error.stackTraceLimit = 0 +// if (require('is-travis')) + Error.stackTraceLimit = 0 require('./destroy-bound-buffer') require('./flatten') diff --git a/test/misc.js b/test/misc.js index 123d9c33..1a29f119 100644 --- a/test/misc.js +++ b/test/misc.js @@ -41,7 +41,6 @@ tape('misc. state', function (t) { var staticOptions = { frag: [ 'precision mediump float;', - 'uniform vec4 color;', 'void main() {', ' gl_FragColor = vec4(1, 0, 0, 1);', '}' diff --git a/test/polygon-offset.js b/test/polygon-offset.js index 14e7ff94..352cd3fa 100644 --- a/test/polygon-offset.js +++ b/test/polygon-offset.js @@ -39,7 +39,6 @@ tape('polygon offset', function (t) { var staticOptions = { frag: [ 'precision mediump float;', - 'uniform vec4 color;', 'void main() {', ' gl_FragColor = vec4(1, 0, 0, 1);', '}' diff --git a/test/read.js b/test/read.js index 82a97c3c..2687e15e 100644 --- a/test/read.js +++ b/test/read.js @@ -1,6 +1,7 @@ var createContext = require('./util/create-context') var createREGL = require('../regl') var tape = require('tape') +var safari = require('is-safari') tape('read pixels', function (t) { var W = 5 @@ -92,7 +93,7 @@ tape('read pixels', function (t) { }) // now do it for an float fbo - if (regl.hasExtension('oes_texture_float')) { + if (regl.hasExtension('oes_texture_float') && !safari) { fbo = regl.framebuffer({ width: W, height: H, diff --git a/test/sample.js b/test/sample.js index 6c18ae7e..32cb40fe 100644 --- a/test/sample.js +++ b/test/sample.js @@ -41,7 +41,6 @@ tape('sample', function (t) { var staticOptions = { frag: [ 'precision mediump float;', - 'uniform vec4 color;', 'void main() {', ' gl_FragColor = vec4(1, 0, 0, 1);', '}' diff --git a/test/scissor.js b/test/scissor.js index 6b784fbd..b2209ae9 100644 --- a/test/scissor.js +++ b/test/scissor.js @@ -59,7 +59,6 @@ tape('scissor', function (t) { var staticOptions = { frag: [ 'precision mediump float;', - 'uniform vec4 color;', 'void main() {', ' gl_FragColor = vec4(1, 0, 0, 1);', '}' diff --git a/test/stencil.js b/test/stencil.js index 66c0d1ac..db425386 100644 --- a/test/stencil.js +++ b/test/stencil.js @@ -167,7 +167,6 @@ tape('stencil', function (t) { var staticOptions = { frag: [ 'precision mediump float;', - 'uniform vec4 color;', 'void main() {', ' gl_FragColor = vec4(1, 0, 0, 1);', '}' diff --git a/test/texture2d.js b/test/texture2d.js index 5783caf4..cba7218d 100644 --- a/test/texture2d.js +++ b/test/texture2d.js @@ -1,6 +1,7 @@ var createContext = require('./util/create-context') var createREGL = require('../regl') var tape = require('tape') +var ie = require('is-iexplorer') tape('texture 2d', function (t) { var gl = createContext(16, 16) @@ -516,7 +517,7 @@ tape('texture 2d', function (t) { shape: [2, 2, 1], flipY: true, alignment: 4, - colorSpace: 'none', + colorSpace: ie ? 'browser' : 'none', data: new Uint8Array([1, 2, 0, 0, 3, 4, 0, 0]) }), { @@ -548,7 +549,7 @@ tape('texture 2d', function (t) { }, { flipY: false, - colorSpace: 'none', + colorSpace: ie ? 'browser' : 'none', data: new Uint8Array([1, 2, 0, 0, 3, 4, 0, 0]) }, { diff --git a/test/textureCube.js b/test/textureCube.js index 824d62f3..3a4b7fa9 100644 --- a/test/textureCube.js +++ b/test/textureCube.js @@ -1,6 +1,7 @@ var createContext = require('./util/create-context') var createREGL = require('../regl') var tape = require('tape') +var ie = require('is-iexplorer') tape('texture cube', function (t) { var gl = createContext(16, 16) @@ -185,7 +186,7 @@ tape('texture cube', function (t) { ] }) - checkProperties('cube shape only', regl.cube(5), { + !ie && checkProperties('cube shape only', regl.cube(5), { width: 5, height: 5 }) diff --git a/test/util/create-context.js b/test/util/create-context.js index 3e93cd13..31bc3485 100644 --- a/test/util/create-context.js +++ b/test/util/create-context.js @@ -1,10 +1,11 @@ if (typeof document !== 'undefined') { var canvas = document.createElement('canvas') - var context = canvas.getContext('webgl', { + var opts = { antialias: false, stencil: true, preserveDrawingBuffer: true - }) + } + var context = canvas.getContext('webgl', opts) || canvas.getContext('experimental-webgl', opts) canvas.style.position = 'fixed' canvas.style.top = '0' canvas.style.right = '0' diff --git a/test/viewport.js b/test/viewport.js index f0bc86b5..d0adf4f7 100644 --- a/test/viewport.js +++ b/test/viewport.js @@ -61,7 +61,6 @@ tape('viewport', function (t) { var staticOptions = { frag: [ 'precision mediump float;', - 'uniform vec4 color;', 'void main() {', ' gl_FragColor = vec4(1, 0, 0, 1);', '}'