luma.gl/modules/webgl/test/classes/texture-2d.spec.js
2019-03-21 15:33:26 -07:00

64 lines
1.7 KiB
JavaScript

import test from 'tape-catch';
import {Texture2D} from '@luma.gl/webgl';
import {fixture} from 'test/setup';
test('WebGL#Texture2D construct/delete', t => {
const {gl} = fixture;
t.throws(
() => new Texture2D(),
/.*WebGLRenderingContext.*/,
'Texture2D throws on missing gl context'
);
const texture = new Texture2D(gl);
t.ok(texture instanceof Texture2D, 'Texture2D construction successful');
t.comment(JSON.stringify(texture.getParameters({keys: true})));
texture.delete();
t.ok(texture instanceof Texture2D, 'Texture2D delete successful');
texture.delete();
t.ok(texture instanceof Texture2D, 'Texture2D repeated delete successful');
t.end();
});
test('WebGL#Texture2D async constructor', t => {
const {gl} = fixture;
let texture = new Texture2D(gl);
t.ok(texture instanceof Texture2D, 'Synchronous Texture2D construction successful');
t.equal(texture.loaded, true, 'Sync Texture2D marked as loaded');
texture.delete();
let loadCompleted;
const loadPromise = new Promise(resolve => {
loadCompleted = resolve; // eslint-disable-line
});
texture = new Texture2D(gl, loadPromise);
t.ok(texture instanceof Texture2D, 'Asynchronous Texture2D construction successful');
t.equal(texture.loaded, false, 'Async Texture2D initially marked as not loaded');
loadPromise.then(() => {
t.equal(texture.loaded, true, 'Async Texture2D marked as loaded on promise completion');
t.end();
});
loadCompleted(null);
});
test('WebGL#Texture2D buffer update', t => {
const {gl} = fixture;
let texture = new Texture2D(gl);
t.ok(texture instanceof Texture2D, 'Texture2D construction successful');
texture = texture.delete();
t.ok(texture instanceof Texture2D, 'Texture2D delete successful');
t.end();
});