Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down Expand Up @@ -2782,12 +2784,12 @@ 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

A WebGL application must be prepared to lose context at any time. This is an unfortunate part of life when working on the web. If this happens `regl` will make a best faith effort to recover functionality after the context is restored, however it is still up to the user to handle this situation.

### 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.
8 changes: 4 additions & 4 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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`.

Expand All @@ -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.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
[![API Stability](https://img.shields.io/badge/stability-experimental-orange.svg?style=flat-square)](https://nodejs.org/api/documentation.html#documentation_stability_index)
[![NPM Version](https://img.shields.io/npm/v/regl.svg?style=flat-square)](https://npmjs.org/package/regl)
[![Build Status](https://img.shields.io/travis/regl-project/regl.svg?style=flat-square)](https://travis-ci.org/regl-project/regl/)
[![File Size](https://badge-size.herokuapp.com/mikolalysenko/regl/gh-pages/dist/regl.min.js.svg?compression=gzip&style=flat-square)](https://npmcdn.com/regl/dist/regl.min.js)
[![File Size](https://badge-size.herokuapp.com/regl-project/regl/gh-pages/dist/regl.min.js.svg?compression=gzip&style=flat-square)](https://npmcdn.com/regl/dist/regl.min.js)
[![Downloads](https://img.shields.io/npm/dm/regl.svg?style=flat-square)](https://npmjs.org/package/regl)
[![Standard](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://standardjs.com)

Expand All @@ -28,7 +28,7 @@
Docs
</a>
<span> | </span>
<a href="https://gitter.im/mikolalysenko/regl">
<a href="https://gitter.im/regl-project/regl">
Chat
</a>
<span> | </span>
Expand Down
4 changes: 2 additions & 2 deletions bench/bench-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion bin/build-gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function generateGallery (files) {
// source code link
li += '<p>' +
'<a href="' +
'https://github.com/mikolalysenko/regl/blob/gh-pages/' + file +
'https://github.com/regl-project/regl/blob/gh-pages/' + file +
'">Source Code</a>' +
'</p>'

Expand Down
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
1 change: 0 additions & 1 deletion lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This enables ANGLE_instanced_arrays for every regl call, which makes Firefox display warnings on loseContext/restoreContext

var INSTANCING
if (extInstancing) {
INSTANCING = env.link(extInstancing)
Expand Down
65 changes: 64 additions & 1 deletion lib/limits.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var pool = require('./util/pool')

var GL_SUBPIXEL_BITS = 0x0D50
var GL_RED_BITS = 0x0D52
var GL_GREEN_BITS = 0x0D53
Expand Down Expand Up @@ -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) {
Expand All @@ -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: [
Expand Down Expand Up @@ -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
}
}
8 changes: 7 additions & 1 deletion lib/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = function wrapReadPixels (
reglPoll,
context,
glAttributes,
extensions) {
extensions,
limits) {
function readPixelsImpl (input) {
var type
if (framebufferState.next === null) {
Expand All @@ -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,
Expand Down Expand Up @@ -128,3 +133,4 @@ module.exports = function wrapReadPixels (

return readPixels
}

35 changes: 30 additions & 5 deletions lib/texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)

Expand All @@ -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)
}
}
}

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions lib/util/is-pow2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (v) {
return !(v & (v - 1)) && (!!v)
}
Loading