Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Browser fixes #479

Merged
merged 42 commits into from
May 18, 2018
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
beee719
Fix safari 0-data buffer setup
dy May 4, 2018
5339bf4
Fix extra logging
dy May 4, 2018
291fab9
Preinit texture with data
dy May 4, 2018
fc8c624
Remove extra comment
dy May 4, 2018
d8b91f5
Fix undefined Dtype
dy May 4, 2018
0b87f34
Add firefox interval timeout
dy May 4, 2018
9a7d9e5
Fix IE context creation
dy May 4, 2018
0703765
Merge branch 'master' into browser-fixes
dy May 14, 2018
16b7628
Use pool to preallocate texture
dy May 14, 2018
34d4b04
Fix test
dy May 14, 2018
50afc01
Add zero-pool for texture data
dy May 15, 2018
462f27c
Remove insignificant checks
dy May 15, 2018
be3326d
Move browser entry to tests
dy May 15, 2018
d18b56a
Move browser entry to test
dy May 15, 2018
1487bd6
Fix losing extension on context loss
dy May 15, 2018
127e0a0
Rename half_float to half_float_oes
dy May 15, 2018
85bef7d
Init zero-data texture on resize
dy May 15, 2018
23ba463
Ignore null allocation
dy May 15, 2018
b6f8d25
Revert test/index
dy May 15, 2018
9938a8e
Fix unsupported premultipliedAlpha in IE
dy May 15, 2018
54db288
Report a safari-specific test failure without halting all tests
May 14, 2018
202e395
Fix formatting
May 14, 2018
c6abb2e
1.3.2
dy May 16, 2018
0aa1b01
Fix links
dy May 16, 2018
d369dbf
Merge branch 'master' into browser-fixes
dy May 16, 2018
ac33e4f
Remove msg from code
dy May 16, 2018
449b5b5
Fix buffer test
dy May 16, 2018
1da66e1
Remove half float allocation - that breaks in safari
dy May 16, 2018
fc418cc
Unroll tests
dy May 16, 2018
0a82ba4
Fix safari framebuffer test
dy May 17, 2018
6afda7c
Display warning reading floats in contexts not supporting the feature
dy May 17, 2018
ad1c6ac
Rename mikolalysenko with regl-project
dy May 17, 2018
1a33343
Fix IE shader issues
dy May 17, 2018
3199462
Fix IE none colorspace test
dy May 17, 2018
617ff84
Add pow2 cube texture check
dy May 17, 2018
87e2ebf
Fix cube FBO test
dy May 17, 2018
b458147
Fix rest of IE tests
dy May 17, 2018
8addf24
Clean up
dy May 17, 2018
7745514
Move feature-detection to limits
dy May 18, 2018
0b31a64
Add API lines
dy May 18, 2018
71bba6c
Rename cubeNpot to npotCubeTexture
dy May 18, 2018
67d4cdd
Rename npotCubeTexture to npotTextureCube
dy May 18, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions lib/texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ module.exports = function createTextureSet (
var type = info.type
var width = info.width
var height = info.height
var channels = info.channels

setFlags(info)

Expand All @@ -839,8 +840,14 @@ 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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preallocate zero data for the texture to remove Firefox errors. Apparently browsers internally do the same.


gl.texImage2D(target, miplevel, format, width, height, 0, format, type, data)

if (nullData && data) {
pool.zero.freeType(data)
}
}
}

Expand Down Expand Up @@ -1325,12 +1332,15 @@ module.exports = function createTextureSet (

tempBind(texture)
for (var i = 0; texture.mipmask >> i; ++i) {
var _w = w >> i
var _h = h >> i
if (!_w || !_h) break
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Firefox warns when w/h is not POT, and it is not when _w === 0

gl.texImage2D(
GL_TEXTURE_2D,
i,
texture.format,
w >> i,
h >> i,
_w,
_h,
0,
texture.format,
texture.type,
Expand Down
113 changes: 61 additions & 52 deletions lib/util/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ var GL_UNSIGNED_SHORT = 5123
var GL_INT = 5124
var GL_UNSIGNED_INT = 5125
var GL_FLOAT = 5126

var bufferPool = loop(8, function () {
return []
})
var GL_HALF_FLOAT = 36193

function nextPow16 (v) {
for (var i = 16; i <= (1 << 28); i *= 16) {
Expand All @@ -34,59 +31,71 @@ 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:
case GL_HALF_FLOAT:
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()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reserved for zero-data inits.

4 changes: 2 additions & 2 deletions test/attributes-nested.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions test/elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,12 @@ tape('elements', function (t) {
t.ok('destroy successful')
}
]

var poll = setInterval(function () {
if (cases.length === 0) {
clearInterval(poll)
t.end()
} else {
(cases.shift())()
}
})
}, 0)
})
13 changes: 7 additions & 6 deletions test/texture2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ tape('texture 2d', function (t) {

var actual = regl.read()
for (i = 0; i < expected.length; ++i) {
if (!(Math.abs(actual[i] - expected[i]) <= tolerance)) {
// ignore null pixels as insignificant
if (expected[i] !== null && !(Math.abs(actual[i] - expected[i]) <= tolerance)) {
t.fail(name + ' @ index ' + i + ' ' + expected[i] + ' - ' + actual[i])
return
}
Expand Down Expand Up @@ -974,11 +975,11 @@ tape('texture 2d', function (t) {
width: 5,
height: 5,
pixels: [
255, 0, 0, 255, 255, 255, 255, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 0,
255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 0,
0, 0, 0, 255, 0, 0, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 0, 0, 0,
0, 0, 0, 255, 0, 0, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
255, 0, 0, 255, 255, 255, 255, 255, 0, 0, 0, 255, 0, 0, 0, 255, null, null, null, null,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null signifies insignificance

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted in the comment above, so sounds good 👍

255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 255, 0, 0, 0, 255, null, null, null, null,
0, 0, 0, 255, 0, 0, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, null, null, null, null,
0, 0, 0, 255, 0, 0, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null
],
format: 'rgba',
type: 'uint8'
Expand Down
5 changes: 3 additions & 2 deletions test/util/create-context.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down