This only works for passing arrays. It assumes you pass
however much data is needed for mips up to the level you
want uploaded. In other words. Say your texture is 10x7 RGBA.
Then src would be a TypedArray with 10x7 + 5x3 + 2x1 + 1x1
4 byte texels or exactly 352 bytes.
If you pass (10x7 + 5x3) * 4, which is 340 bytes, then it would
only fill out the first 2 mip levels. That texture would be
unrenderable unless you (1) set filtering to not use mips or
(2) set `maxLevel` to 1 (TEXTURE_MAX_LEVEL).
* fix colorRenderable, textureFilterable data
All compressed texture formats are textureFilterable but not
colorRenderable.
* Support cubemaps
This code got simpilied. We require the src to by the exact size.
so we can get the size of a face just by dividing by 6. No need
for the extra math. This works for both compressed and normal
textures.
Added a test
* Get rid of the compression option
We know if a texture is compressed based on its internalFormat
* Remove level stuff
I think there was a mis-understanding how how twgl works. If you
want to set anything other than level 0 you need to directly
call `setTextureFormArray` directly (or `setTextureFromElement`)
* Fix tests
The tests needed to check that the extension exists
Note: we need to decide if and how to handle cubemaps.
The code in their currently will fail. Will fix in next PR
I'm not really sure I should add these. I think I thought
about it before.
The issue is, createTexture and createTextures both return
usable textures immediately. No waiting. If the data for the
texture needs to be loaded asynchronously, they'll return a 1x1
pixel texture. createTextureAsync and createTexturesAsync on the
other hand, only return the texture after their async sources
have loaded.
These are more here for completeness as sometimes you actually
do want to wait until the texture's data is loaded and it's now
common to use promises for this purpose.
the pack state.
Before
const t = twgl.createTexture({src: 'https://some/img.jpg'});
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
// t is flipped
After
const t = twgl.createTexture({src: 'https://some/img.jpg'});
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
// t is not flipped
Internal change. `gl.pixelStorei` state for `UNPACK_COLORSPACE_CONVERSION_WEBGL`
`UNPACK_PREMULTIPLY_ALPHA_WEBGL` and `UNPACK_FLIP_Y_WEBGL`
is now saved and restored as the previous behavior had a race condition.
Before
```js
t1 = twgl.createTexture(gl, {src: 'https://p.com/slow.jpg'}); // may or may not be flipped!!!!
t2 = twgl.createTexture(gl, {src: 'https://p.com/fast.jpg', flipY: true }); // flipped
```
In the example above, whether or not `t1` is flipped was unknown
since if `t2` loads first, it would be flipped. If `t1` loads first
it would not be flipped.
The fix is to save and restore the `pixelStorei` state for each texture.
Unfortunately, this is a breaking change.
Before
```js
twgl.createTexture(gl, {src: someImageElem1, flipY: true }); // flipped
twgl.createTexture(gl, {src: someImageElem2 }); // also flipped
```
after
```js
twgl.createTexture(gl, {src: someImage, flipY: true }); // flipped
twgl.createTexture(gl, {src: someImage }); // NOT flipped
```
Note: in all versions the behavior was and still is, that if you set
the `pixelStorei` parameters outside they applied.
```js
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true)
twgl.createTexture(gl, {src: someImage }); // flipped
twgl.createTexture(gl, {src: someImage }); // flipped
```
This works but I wrote a sample and it ran really slow. Like
I couldn't even draw 6 cubes
Not sure why but don't want to merge a solution until it's fast