forked from EXT/VR180-Web-Player
74 lines
2.0 KiB
JavaScript
74 lines
2.0 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { VideoTextureManager } from '../vr180player/rendering/texture-manager.js';
|
|
|
|
function createTexture(name) {
|
|
return {
|
|
disposed: false,
|
|
name,
|
|
needsUpdate: false,
|
|
dispose() {
|
|
this.disposed = true;
|
|
}
|
|
};
|
|
}
|
|
|
|
function createVideo({ paused = false, ended = false } = {}) {
|
|
return { ended, paused };
|
|
}
|
|
|
|
test('VideoTextureManager replaces the previous texture when creating a new one', () => {
|
|
const created = [];
|
|
const manager = new VideoTextureManager(createVideo(), () => {
|
|
const texture = createTexture(`texture-${created.length}`);
|
|
created.push(texture);
|
|
return texture;
|
|
});
|
|
|
|
const first = manager.create();
|
|
const second = manager.create();
|
|
|
|
assert.equal(first.disposed, true);
|
|
assert.equal(second.disposed, false);
|
|
assert.equal(manager.current, second);
|
|
assert.equal(created.length, 2);
|
|
});
|
|
|
|
test('VideoTextureManager assigns and clears material maps', () => {
|
|
const material = { map: null, needsUpdate: false };
|
|
const manager = new VideoTextureManager(createVideo(), () => createTexture('assigned'));
|
|
|
|
const texture = manager.assignToMaterial(material);
|
|
|
|
assert.equal(material.map, texture);
|
|
assert.equal(material.needsUpdate, true);
|
|
assert.equal(manager.current, texture);
|
|
|
|
material.needsUpdate = false;
|
|
manager.clearMaterial(material);
|
|
|
|
assert.equal(texture.disposed, true);
|
|
assert.equal(material.map, null);
|
|
assert.equal(material.needsUpdate, true);
|
|
assert.equal(manager.current, null);
|
|
});
|
|
|
|
test('VideoTextureManager only marks textures dirty while playback is active', () => {
|
|
const video = createVideo();
|
|
const manager = new VideoTextureManager(video, () => createTexture('playing'));
|
|
const texture = manager.create();
|
|
|
|
manager.updateIfPlaying();
|
|
assert.equal(texture.needsUpdate, true);
|
|
|
|
texture.needsUpdate = false;
|
|
video.paused = true;
|
|
manager.updateIfPlaying();
|
|
assert.equal(texture.needsUpdate, false);
|
|
|
|
video.paused = false;
|
|
video.ended = true;
|
|
manager.updateIfPlaying();
|
|
assert.equal(texture.needsUpdate, false);
|
|
});
|