Class TextureBase
Base class for Texture, SpriteAtlas, IESProfile and other assets that can contain texture data.
Inherited Members
Assembly: FlaxEngine.dll
File: Engine/Graphics/Textures/TextureBase.h
Syntax
public class TextureBase : public BinaryAsset, public ITextureOwner
Fields
_customData
Declaration
protected InitData* _customData
Field Value
InitData
|
_parent
_texture
Methods
CalculateChunkIndex(int32 mipIndex)
Declaration
protected virtual int32 CalculateChunkIndex(int32 mipIndex) const
Parameters
int32
mipIndex
|
Returns
int32
|
CancelStreaming()
Cancels any asynchronous content streaming by this asset (eg. mesh data streaming into GPU memory). Will release any locks for asset storage container.
Declaration
public virtual void CancelStreaming() override
Overrides
Format()
GetArraySize()
Gets the total array size of the texture.
Declaration
public int32 GetArraySize() const
Returns
int32
|
GetCurrentMemoryUsage()
Gets the amount of the memory used by this resource. Exact value may differ due to memory alignment and resource allocation policy.
Declaration
public uint64 GetCurrentMemoryUsage() const
Returns
uint64
|
GetMemoryUsage()
Gets amount of CPU memory used by this resource (in bytes). It's a rough estimation. Memory may be fragmented, compressed or sub-allocated so the actual memory pressure from this resource may vary.
Declaration
public virtual uint64 GetMemoryUsage() const override
Returns
uint64
|
Overrides
GetMipData(int32 mipIndex, BytesContainer& data)
Gets texture mip map data. May fail if not data requested. See RequestMipDataAsync.
Declaration
public virtual void GetMipData(int32 mipIndex, BytesContainer& data) const override
Parameters
int32
mipIndex
Mip map index |
BytesContainer
data
Result data |
Overrides
GetMipData(int32 mipIndex, int32& rowPitch, int32& slicePitch)
Gets the mip data.
Declaration
public BytesContainer GetMipData(int32 mipIndex, int32& rowPitch, int32& slicePitch)
Parameters
int32
mipIndex
The mip index (zero-based). |
int32
rowPitch
The data row pitch (in bytes). |
int32
slicePitch
The data slice pitch (in bytes). |
Returns
BytesContainer
The mip-map data or empty if failed to get it. |
GetMipDataCustomPitch(int32 mipIndex, uint32& rowPitch, uint32& slicePitch)
Gets texture mip map data row and slice pitch. Cna be used to override the default values.
Declaration
public virtual bool GetMipDataCustomPitch(int32 mipIndex, uint32& rowPitch, uint32& slicePitch) const override
Parameters
int32
mipIndex
Mip map index |
uint32
rowPitch
Data row pitch (in bytes). |
uint32
slicePitch
Data slice pitch (in bytes). |
Returns
bool
True if has a custom row/slice pitch values, otherwise false (to use default values). |
Overrides
GetMipDataWithLoading(int32 mipIndex, BytesContainer& data)
Gets texture mip map data. Performs loading if data is not in memory (may stall the callee thread).
Declaration
public virtual void GetMipDataWithLoading(int32 mipIndex, BytesContainer& data) const override
Parameters
int32
mipIndex
Mip map index |
BytesContainer
data
Result data |
Overrides
GetMipLevels()
Gets the total mip levels count of the texture. Actual resident mipmaps count may be different due to dynamic content streaming.
Declaration
public int32 GetMipLevels() const
Returns
int32
|
GetOwnerLocker()
Gets the texture owner mutex used to synchronize texture logic.
Declaration
public virtual CriticalSection GetOwnerLocker() const override
Returns
CriticalSection
|
Overrides
GetPixels(Array<Color>& pixels, int32 mipIndex = 0, int32 arrayIndex = 0)
Gets the texture pixels as Color array.
Supported only for 'basic' texture formats (uncompressed, single plane).
Declaration
public bool GetPixels(Array<Color>& pixels, int32 mipIndex = 0, int32 arrayIndex = 0)
Parameters
Array<Color>
pixels
The result texture pixels array. |
int32
mipIndex
The mip index (zero-based). |
int32
arrayIndex
The array or depth slice index (zero-based). |
Returns
bool
True if failed, otherwise false. |
GetPixels(Array<Color32>& pixels, int32 mipIndex = 0, int32 arrayIndex = 0)
Gets the texture pixels as Color32 array.
Supported only for 'basic' texture formats (uncompressed, single plane).
Declaration
public bool GetPixels(Array<Color32>& pixels, int32 mipIndex = 0, int32 arrayIndex = 0)
Parameters
Array<Color32>
pixels
The result texture pixels array. |
int32
mipIndex
The mip index (zero-based). |
int32
arrayIndex
The array or depth slice index (zero-based). |
Returns
bool
True if failed, otherwise false. |
GetResidentMipLevels()
Gets the current mip levels count of the texture that are on GPU ready to use.
Declaration
public int32 GetResidentMipLevels() const
Returns
int32
|
GetTexture()
Gets GPU texture object allocated by the asset.
Declaration
public GPUTexture* GetTexture() const
Returns
GPUTexture
|
GetTextureData(TextureData& result, bool copyData=true)
Loads the texture data from the asset.
Declaration
public bool GetTextureData(TextureData& result, bool copyData=true)
Parameters
TextureData
result
The result data. |
bool
copyData
True if copy asset data to the result buffer, otherwise texture data will be linked to the internal storage (then the data is valid while asset is loaded and there is no texture data copy operations - faster). |
Returns
bool
True if cannot load data, otherwise false. |
GetTextureGroup()
Gets the index of the texture group used by this texture.
Declaration
public int32 GetTextureGroup() const
Returns
int32
|
GetTextureMipData(TextureMipData& result, int32 mipIndex = 0, int32 arrayIndex = 0, bool copyData=true)
Loads the texture data from the asset (single mip).
Declaration
public bool GetTextureMipData(TextureMipData& result, int32 mipIndex = 0, int32 arrayIndex = 0, bool copyData=true)
Parameters
TextureMipData
result
The result data. |
int32
mipIndex
The mip index (zero-based). |
int32
arrayIndex
The array or depth slice index (zero-based). |
bool
copyData
True if copy asset data to the result buffer, otherwise texture data will be linked to the internal storage (then the data is valid while asset is loaded and there is no texture data copy operations - faster). |
Returns
bool
True if cannot load data, otherwise false. |
GetTotalMemoryUsage()
Gets the total memory usage that texture may have in use (if loaded to the maximum quality). Exact value may differ due to memory alignment and resource allocation policy.
Declaration
public uint64 GetTotalMemoryUsage() const
Returns
uint64
|
HasStreamingError()
Returns true if texture streaming failed (eg. pixel format is unsupported or texture data cannot be uploaded to GPU due to memory limit).
Declaration
public bool HasStreamingError() const
Returns
bool
|
Height()
Gets the total height of the texture. Actual resident size may be different due to dynamic content streaming. Returns 0 if texture is not loaded.
Declaration
public int32 Height() const
Returns
int32
|
init(AssetInitData& initData)
Initializes the specified asset.
Declaration
protected virtual bool init(AssetInitData& initData) override
Parameters
AssetInitData
initData
The initialize data. |
Returns
bool
True if cannot init, otherwise false |
Overrides
Init(InitData&& initData)
Initializes the texture with specified initialize data source (asset must be virtual).
Declaration
public bool Init(InitData&& initData)
Parameters
InitData
initData
The initializer data. It will be used and released by the asset internal layer (memory allocation will be swapped). |
Returns
bool
True if failed, otherwise false. |
Init(InitData* initData)
Initializes the texture with specified initialize data source (asset must be virtual).
Declaration
public bool Init(InitData* initData)
Parameters
InitData
initData
The initializer data allocated by the caller with New. It will be owned and released by the asset internal layer. |
Returns
bool
True if failed, otherwise false. |
load()
Load data from the chunks
Declaration
protected virtual LoadResult load() override
Returns
LoadResult
Loading result |
Overrides
LockData()
Prepares texture data. May lock data chunks to be keep in cache for a while.
Declaration
public virtual FlaxStorage::LockData LockData() override
Returns
FlaxStorage::LockData
|
Overrides
RequestMipDataAsync(int32 mipIndex)
Get texture mip map data
Declaration
public virtual Task* RequestMipDataAsync(int32 mipIndex) override
Parameters
int32
mipIndex
Mip map index |
Returns
Task
Task that will get asset data (may be null if data already loaded). |
Overrides
SetPixels(const Span<Color>& pixels, int32 mipIndex = 0, int32 arrayIndex = 0, bool generateMips=false)
Sets the texture pixels as Color array (asset must be virtual and already initialized).
Supported only for 'basic' texture formats (uncompressed, single plane).
Declaration
public bool SetPixels(const Span<Color>& pixels, int32 mipIndex = 0, int32 arrayIndex = 0, bool generateMips=false)
Parameters
Span<Color>
pixels
The texture pixels array. |
int32
mipIndex
The mip index (zero-based). |
int32
arrayIndex
The array or depth slice index (zero-based). |
bool
generateMips
Enables automatic mip-maps generation (fast point filter) based on the current mip (will generate lower mips). |
Returns
bool
True if failed, otherwise false. |
SetPixels(const Span<Color32>& pixels, int32 mipIndex = 0, int32 arrayIndex = 0, bool generateMips=false)
Sets the texture pixels as Color32 array (asset must be virtual and already initialized).
Supported only for 'basic' texture formats (uncompressed, single plane).
Declaration
public bool SetPixels(const Span<Color32>& pixels, int32 mipIndex = 0, int32 arrayIndex = 0, bool generateMips=false)
Parameters
Span<Color32>
pixels
The texture pixels array. |
int32
mipIndex
The mip index (zero-based). |
int32
arrayIndex
The array or depth slice index (zero-based). |
bool
generateMips
Enables automatic mip-maps generation (fast point filter) based on the current mip (will generate lower mips). |
Returns
bool
True if failed, otherwise false. |
SetTextureGroup(int32 textureGroup)
Sets the index of the texture group used by this texture.
Declaration
public void SetTextureGroup(int32 textureGroup)
Parameters
int32
textureGroup
|
Size()
Gets the total size of the texture. Actual resident size may be different due to dynamic content streaming. Returns Float2::Zero if texture is not loaded.
Declaration
public Float2 Size() const
Returns
Float2
|
StreamingTexture()
Gets the streaming texture object handle.
Declaration
public StreamingTexture* StreamingTexture() const
Returns
StreamingTexture
|
unload(bool isReloading)
Unloads asset data
Declaration
protected virtual void unload(bool isReloading) override
Parameters
bool
isReloading
True if asset is reloading data, otherwise false. |
Overrides
Width()
Gets the total width of the texture. Actual resident size may be different due to dynamic content streaming. Returns 0 if texture is not loaded.
Declaration
public int32 Width() const
Returns
int32
|