|
|
@@ -6,18 +6,54 @@ import { DepthStencilFormat, DepthFormat, UnsignedIntType, UnsignedInt248Type, E
|
|
|
|
|
|
const _size = /*@__PURE__*/ new Vector3();
|
|
|
|
|
|
+/**
|
|
|
+ * This module manages the textures of the renderer.
|
|
|
+ *
|
|
|
+ * @private
|
|
|
+ */
|
|
|
class Textures extends DataMap {
|
|
|
|
|
|
+ /**
|
|
|
+ * Constructs a new texture management component.
|
|
|
+ *
|
|
|
+ * @param {Renderer} renderer - The renderer.
|
|
|
+ * @param {Backend} backend - The renderer's backend.
|
|
|
+ * @param {Info} info - Renderer component for managing metrics and monitoring data.
|
|
|
+ */
|
|
|
constructor( renderer, backend, info ) {
|
|
|
|
|
|
super();
|
|
|
|
|
|
+ /**
|
|
|
+ * The renderer.
|
|
|
+ *
|
|
|
+ * @type {Renderer}
|
|
|
+ */
|
|
|
this.renderer = renderer;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The backend.
|
|
|
+ *
|
|
|
+ * @type {Backend}
|
|
|
+ */
|
|
|
this.backend = backend;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Renderer component for managing metrics and monitoring data.
|
|
|
+ *
|
|
|
+ * @type {Info}
|
|
|
+ */
|
|
|
this.info = info;
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Updates the given render target. Based on the given render target configuration,
|
|
|
+ * it updates the texture states representing the attachments of the framebuffer.
|
|
|
+ *
|
|
|
+ * @param {RenderTarget} renderTarget - The render target to update.
|
|
|
+ * @param {Number} [activeMipmapLevel=0] - The active mipmap level.
|
|
|
+ */
|
|
|
updateRenderTarget( renderTarget, activeMipmapLevel = 0 ) {
|
|
|
|
|
|
const renderTargetData = this.get( renderTarget );
|
|
|
@@ -139,6 +175,14 @@ class Textures extends DataMap {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Updates the given texture. Depending on the texture state, this method
|
|
|
+ * triggers the upload of texture data to the GPU memory. If the texture data are
|
|
|
+ * not yet ready for the upload, it uses default texture data for as a placeholder.
|
|
|
+ *
|
|
|
+ * @param {Texture} texture - The texture to update.
|
|
|
+ * @param {Object} [options={}] - The options.
|
|
|
+ */
|
|
|
updateTexture( texture, options = {} ) {
|
|
|
|
|
|
const textureData = this.get( texture );
|
|
|
@@ -292,6 +336,18 @@ class Textures extends DataMap {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Computes the size of the given texture and writes the result
|
|
|
+ * into the target vector. This vector is also returned by the
|
|
|
+ * method.
|
|
|
+ *
|
|
|
+ * If no texture data are available for the compute yet, the method
|
|
|
+ * returns default size values.
|
|
|
+ *
|
|
|
+ * @param {Texture} texture - The texture to compute the size for.
|
|
|
+ * @param {Vector3} target - The target vector.
|
|
|
+ * @return {Vector3} The target vector.
|
|
|
+ */
|
|
|
getSize( texture, target = _size ) {
|
|
|
|
|
|
let image = texture.images ? texture.images[ 0 ] : texture.image;
|
|
|
@@ -314,6 +370,14 @@ class Textures extends DataMap {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Computes the number of mipmap levels for the given texture.
|
|
|
+ *
|
|
|
+ * @param {Texture} texture - The texture.
|
|
|
+ * @param {Number} width - The texture's width.
|
|
|
+ * @param {Number} height - The texture's height.
|
|
|
+ * @return {Number} The number of mipmap levels.
|
|
|
+ */
|
|
|
getMipLevels( texture, width, height ) {
|
|
|
|
|
|
let mipLevelCount;
|
|
|
@@ -340,12 +404,24 @@ class Textures extends DataMap {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns `true` if the given texture requires mipmaps.
|
|
|
+ *
|
|
|
+ * @param {Texture} texture - The texture.
|
|
|
+ * @return {Boolean} Whether mipmaps are required or not.
|
|
|
+ */
|
|
|
needsMipmaps( texture ) {
|
|
|
|
|
|
return this.isEnvironmentTexture( texture ) || texture.isCompressedTexture === true || texture.generateMipmaps;
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns `true` if the given texture is an environment map.
|
|
|
+ *
|
|
|
+ * @param {Texture} texture - The texture.
|
|
|
+ * @return {Boolean} Whether the given texture is an environment map or not.
|
|
|
+ */
|
|
|
isEnvironmentTexture( texture ) {
|
|
|
|
|
|
const mapping = texture.mapping;
|
|
|
@@ -354,6 +430,12 @@ class Textures extends DataMap {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Frees internal resource when the given texture isn't
|
|
|
+ * required anymore.
|
|
|
+ *
|
|
|
+ * @param {Texture} texture - The texture to destroy.
|
|
|
+ */
|
|
|
_destroyTexture( texture ) {
|
|
|
|
|
|
this.backend.destroySampler( texture );
|