-
Notifications
You must be signed in to change notification settings - Fork 326
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
Browser fixes #479
Changes from 11 commits
beee719
5339bf4
291fab9
fc8c624
d8b91f5
0b87f34
9a7d9e5
0703765
16b7628
34d4b04
50afc01
462f27c
be3326d
d18b56a
1487bd6
127e0a0
85bef7d
23ba463
b6f8d25
9938a8e
54db288
202e395
c6abb2e
0aa1b01
d369dbf
ac33e4f
449b5b5
1da66e1
fc418cc
0a82ba4
6afda7c
ad1c6ac
1a33343
3199462
617ff84
87e2ebf
b458147
8addf24
7745514
0b31a64
71bba6c
67d4cdd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
||
|
@@ -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) | ||
|
||
gl.texImage2D(target, miplevel, format, width, height, 0, format, type, data) | ||
|
||
if (nullData && data) { | ||
pool.zero.freeType(data) | ||
} | ||
} | ||
} | ||
|
||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Firefox warns when |
||
gl.texImage2D( | ||
GL_TEXTURE_2D, | ||
i, | ||
texture.format, | ||
w >> i, | ||
h >> i, | ||
_w, | ||
_h, | ||
0, | ||
texture.format, | ||
texture.type, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reserved for zero-data inits. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
} | ||
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' | ||
|
There was a problem hiding this comment.
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.