RenderWebGL{Local,Worker} class methods return Promise instances from
all methods returning a value. This makes the API consistent from a
Web Worker vs. the local page, and also allows the possibility of
asynchronous render queries in the future.
The build generates a new output set called `render-webgl-worker`, meant
to be imported from a web worker. This exposes the `RenderWebGLRemote`
class to facilitate communication with the renderer using `postMessage`
and `onmessage`.
Only a few messages are implemented so far, but it's enough to run the
demo page.
Drawable now creates its own temporary texture upon construction. This
1x1 transparent texture is ready immediately and is replaced once a real
skin is loaded. This slightly simplifies some of the skin loading code
but more importantly prevents GL errors caused when trying to draw a
Drawable if it hasn't yet created its "real" texture, as in the SVG load
path.
The ability to bitwise-combine draw modes turns out to not be a benefit:
it's not safe to short-circuit drawing in the way that I had intended
because it could change the results of blending. Blending could create a
color that matches a "touching color?" check without that color existing
anywhere else.
- Always take color in unsigned-byte terms.
- Moved tolerance value into a class constant.
- Use the same tolerance in JS color comparison as in the shader.
Draw modes are now enabled/disabled by bitmask and can be combined.
Combining silhouette mode and color mask mode will be useful for
color-touching-color, for example.
Effect converters are now one field in a larger EFFECT_INFO map, which
also contains bitmask values for each effect. Drawable no longer makes
any assumptions regarding how ShaderManager will unpack the effect bits.
The shader cache is now an array of arrays, where the outer index is the
mask of active draw modes and the inner index is the mask of active
effects (as it was before). Effects which cannot impact the shape of a
Drawable are masked out in silhouette mode in order to avoid compiling
redundant shaders.
The renderer now calculates the native render target size based on the
edge coordinates provided to the constructor. This native size will be
used directly for queries such as "touching color?" and will be scaled
when rendering for display.
The `isTouchingColor` function now takes an optional mask parameter. If
provided, only the parts of the Drawable which match the mask color will
be used for the test. For example:
```
isTouchingColor(4, red, blue);
```
This means "are there any parts of Drawable #4 which are blue and are
touching a red pixel on some other Drawable?"
Also eliminate the ability to specify background alpha, since that can
affect page-level compositing in undesirable ways.
Also avoid some redundant GL state calls.
Fixed timing errors related to calling `setSkin()` a second time before
the first callback chain completes.
Fixed a typo causing problems when more than one Drawable is registered.
HSL's lightness is, in this case, basically the same as half of HSV's
value, so this change halves the threshold value used by the color
effect to make it similar in appearance to the HSV implementation.
- Increased canvas border in demo.html to make it more obvious if future
code forgets to compensate for the border.
- Fixed picking code to compensate for a border around the canvas.
- Completed support for picking with a touch larger than a single point.
This will allow rendering the primary view, picking view, and "touching
color" view with different projection matrices without needing to
recalculate the model matrix for every Drawable every time.
Pixelate still needs a bit more work: at certain scales the edges of the
"pixels" are ragged. This happens in Scratch 2.0 as well, but for me it
seems slightly worse in this implementation.
The renderer now uses premultiplied alpha in the frame buffer, though
textures are still stored without premultiplied alpha. This makes it
easier to get the desired results from the browser's canvas compositing
step, and might be nicer for mobile hardware depending on which parts of
the Internet you believe.
This implementation of the pixel effect is now very similar to the
PixelBender implementation in Scratch 2.0
I also added a slider to demo.html as a debugging aid: it manipulates a
value that is passed into the shader and used in whatever way helps.