gpu.js/src/texture.js
Robert Plummer 83641519dd fix: Rename Texture.texture.refs to more private Texture.texture._refs
fix: Create framebuffer for internal texture, and not per GPU Texture
fix: Set window.GPU by use of getter, and have no setter
2019-12-27 08:20:00 -05:00

74 lines
1.7 KiB
JavaScript

/**
* @desc WebGl Texture implementation in JS
* @param {IGPUTextureSettings} settings
*/
class Texture {
constructor(settings) {
const {
texture,
size,
dimensions,
output,
context,
type = 'NumberTexture',
kernel,
internalFormat,
textureFormat
} = settings;
if (!output) throw new Error('settings property "output" required.');
if (!context) throw new Error('settings property "context" required.');
if (!texture) throw new Error('settings property "texture" required.');
if (!kernel) throw new Error('settings property "kernel" required.');
this.texture = texture;
if (texture._refs) {
texture._refs++;
} else {
texture._refs = 1;
}
this.size = size;
this.dimensions = dimensions;
this.output = output;
this.context = context;
/**
* @type {Kernel}
*/
this.kernel = kernel;
this.type = type;
this._deleted = false;
this.internalFormat = internalFormat;
this.textureFormat = textureFormat;
}
/**
* @desc Converts the Texture into a JavaScript Array
* @returns {TextureArrayOutput}
*/
toArray() {
throw new Error(`Not implemented on ${this.constructor.name}`);
}
/**
* @desc Clones the Texture
* @returns {Texture}
*/
clone() {
throw new Error(`Not implemented on ${this.constructor.name}`);
}
/**
* @desc Deletes the Texture
*/
delete() {
if (this._deleted) return;
this._deleted = true;
if (this.texture._refs) {
this.texture._refs--;
if (this.texture._refs) return;
}
return this.context.deleteTexture(this.texture);
}
}
module.exports = {
Texture
};