Textures
Typedefs
-
typedef BaseTexture Texture
-
typedef BaseTexture CubeTexture
-
typedef BaseTexture VolTexture
-
typedef BaseTexture ArrayTexture
-
typedef void (*on_tex_slice_loaded_cb_t)()
load texture content from DDSx stream using DDSx header for previously allocated texture
Enums
-
enum class ChannelDType
Values:
-
enumerator NONE
-
enumerator UNORM
-
enumerator SNORM
-
enumerator UFLOAT
-
enumerator SFLOAT
-
enumerator UINT
-
enumerator SINT
-
enumerator NONE
-
enum [anonymous]
Values:
-
enumerator TEXLOCK_DISCARD
-
enumerator TEXLOCK_RAWDATA
-
enumerator TEXLOCK_NO_DIRTY_UPDATE
-
enumerator TEXLOCK_NOSYSLOCK
-
enumerator TEXLOCK_READ
-
enumerator TEXLOCK_WRITE
-
enumerator TEXLOCK_READWRITE
-
enumerator TEXLOCK_RWMASK
-
enumerator TEXLOCK_NOOVERWRITE
-
enumerator TEXLOCK_DELSYSMEMCOPY
-
enumerator TEXLOCK_SYSTEXLOCK
-
enumerator TEXLOCK_UPDATEFROMSYSTEX
-
enumerator TEXLOCK_DONOTUPDATEON9EXBYDEFAULT
-
enumerator TEXLOCK_COPY_STAGING
-
enumerator TEXLOCK_DEFAULT
-
enumerator TEXLOCK_DISCARD
Functions
-
bool is_alpha_texformat(unsigned flags)
-
bool is_bc_texformat(unsigned flags)
-
uint32_t auto_mip_levels_count(uint32_t w, uint32_t min_size)
-
uint32_t auto_mip_levels_count(uint32_t w, uint32_t h, uint32_t min_size)
-
uint32_t auto_mip_levels_count(uint32_t w, uint32_t h, uint32_t d, uint32_t min_size)
-
void apply_gen_tex_props(BaseTexture *t, const struct TextureMetaData &tmd, bool force_addr_from_tmd = true)
-
uint32_t parse_tex_format(const char *name, uint32_t default_fmt)
-
const TextureFormatDesc &get_tex_format_desc(uint32_t fmt)
-
const char *get_tex_format_name(uint32_t fmt)
-
uint32_t get_tex_channel_value(const void *pixel, const TextureChannelFormatDesc &channel)
Extracts a the bits from a pixel at memory location
pixel
that correspond to a particular channel in the specified format.Note
Bits unused by the channel are set to 0, even for signed formats
Warning
This is extremely slow!
- Parameters:
pixel – Memory location of the pixel
channel – Description of the channel’s format
- Returns:
A uint32_t whose lowest bits contain the bits of the channel
-
void set_tex_channel_value(void *pixel, const TextureChannelFormatDesc &channel, uint32_t bits)
Sets the bits for a pixel at memory location
pixel
that correspond to a particular channel in the specified format.Warning
This is extremely slow!
- Parameters:
pixel – Memory location of the pixel
channel – Description of the channel’s format
bits – The bits to assign to the channel (only the lowest bits are used)
-
float channel_bits_to_float(uint32_t bits, ChannelDType type, const TextureChannelFormatDesc &channel)
Converts raw bits of a channel in a certain format into a floating point value that matches the logical value of the channel as closely as possible.
Note
Conversion is done as per section 3.9 of Vulkan API specification
Warning
This is extremely slow!
- Parameters:
bits – The bits of the channel
type – The type of the value stored in the channel
channel – The description of the channel’s format
- Returns:
A float that matches the logical value of the channel
-
uint32_t float_to_channel_bits(float value, ChannelDType type, const TextureChannelFormatDesc &channel)
Converts a float into raw bits of a channel in a certain format that match the provided float as closely as possible.
Note
Conversion is done as per section 3.9 of Vulkan API specification
Note
Bits unused by the channel are set to 0, even for signed formats
Warning
This is extremely slow!
- Parameters:
value – The floating point value to convert
type – The type of the value stored in the channel
channel – The description of the channel’s format
- Returns:
A uint32_t that contains the bits of the channel
-
inline TexLoadRes d3d_load_ddsx_tex_contents(BaseTexture *tex, TEXTUREID tid, TEXTUREID paired_tid, const ddsx::Header &hdr, IGenLoad &crd, int q_id, int start_lev = 0, unsigned tex_ld_lev = 0, on_tex_slice_loaded_cb_t on_tex_slice_loaded_cb = nullptr)
-
bool convert_image_line(const void *input, int width, int in_channels, int in_bits_per_channel, bool in_float, void *output, int out_channels, int out_bits_per_channel, bool out_float, bool swap_rb)
Variables
-
TexLoadRes (*d3d_load_ddsx_tex_contents_impl)(BaseTexture *tex, TEXTUREID tid, TEXTUREID paired_tid, const ddsx::Header &hdr, IGenLoad &crd, int q_id, int start_lev, unsigned tex_ld_lev, on_tex_slice_loaded_cb_t)
-
TexLoadRes (*d3d_load_ddsx_to_slice)(BaseTexture *tex, int slice, const ddsx::Header &hdr, IGenLoad &crd, int q_id, int start_lev, unsigned tex_ld_lev)
load texture content from DDSx stream using DDSx header to specified slice of previously allocated array texture
-
struct TextureChannelFormatDesc
-
struct TextureFormatDesc
Public Functions
-
inline bool hasAlpha() const
-
inline bool isDepth() const
-
inline int rgbaChannelsCount() const
-
inline int channelsCount() const
Public Members
-
uint32_t dagorTextureFormat
-
uint16_t bytesPerElement
-
bool isBlockFormat
-
uint8_t elementWidth
-
uint8_t elementHeight
-
ChannelDType mainChannelsType
-
ChannelDType stencilChannelType
-
TextureChannelFormatDesc stencil
-
inline bool hasAlpha() const
-
struct TextureInfo
Public Members
-
unsigned short w = 1
width, height, depth (for VOLTEX), array slices (slice count for ARRTEX or 6 for CUBETEX)
-
unsigned short h = 1
-
unsigned short d = 1
-
unsigned short a = 1
-
unsigned short mipLevels = 0
all mips and res type
-
unsigned short resType = 0
-
unsigned cflg = 0
texture creation flags
-
unsigned short w = 1
-
class BaseTexture : public D3dResource
Public Functions
-
inline virtual bool setReloadCallback(IReloadData*)
-
virtual int generateMips() = 0
-
virtual int update(BaseTexture *src) = 0
-
inline int calcSubResIdx(int level, int slice = 0) const
-
virtual int updateSubRegion(BaseTexture *src, int src_subres_idx, int src_x, int src_y, int src_z, int src_w, int src_h, int src_d, int dest_subres_idx, int dest_x, int dest_y, int dest_z) = 0
-
inline virtual int updateSubRegionNoOrder(BaseTexture *src, int src_subres_idx, int src_x, int src_y, int src_z, int src_w, int src_h, int src_d, int dest_subres_idx, int dest_x, int dest_y, int dest_z)
-
virtual int level_count() const = 0
-
inline int texaddr(int addrmode)
-
inline int texaddru(int addrmode)
-
inline int texaddrv(int addrmode)
-
inline int texaddrw(int addrmode)
-
inline int texbordercolor(E3DCOLOR color)
-
inline int texfilter(int filtermode)
-
inline int texmipmap(int mipmapmode)
-
inline int texlod(float mipmaplod)
-
inline int setAnisotropy(int level)
-
inline void disableSampler()
-
inline bool isSamplerEnabled()
-
virtual int texmiplevel(int minlevel, int maxlevel) = 0
-
inline virtual bool isCubeArray() const
-
inline virtual void setReadStencil(bool)
-
inline const char *getTexName() const
-
inline virtual void setResApiName(const char*) const
-
virtual int lockimg(void**, int &stride_bytes, int level, unsigned flags) = 0
-
virtual int lockimg(void**, int &stride_bytes, int layer, int level, unsigned flags) = 0
-
inline virtual int unlockimg()
-
inline int unlock()
-
inline virtual int lockbox(void**, int&, int&, int, unsigned)
-
inline virtual int unlockbox()
-
virtual int getinfo(TextureInfo &info, int level = 0) const = 0
-
template<typename T>
inline int lockimgEx(T **p, int &stride_bytes, int level = 0, unsigned flags = TEXLOCK_DEFAULT)
-
inline virtual BaseTexture *makeTmpTexResCopy(int, int, int, int, bool = false)
created temporary BaseTexture with texture res object with given dimensions (texture format and texture subtype is used from original)
-
inline virtual void replaceTexResObject(BaseTexture *&new_tex)
replaces texture res object with new one of new_tex and then destroys new_tex (destruction may be delayed by driver)
-
inline virtual bool allocateTex()
forces allocation of texture resource; return true if tex allocated and ready for use
-
inline virtual void discardTex()
discards texture and returns it to STUB state
-
inline virtual bool downSize(int width, int height, int depth, int mips, unsigned start_src_level, unsigned level_offset)
-
inline virtual bool upSize(int width, int height, int depth, int mips, unsigned start_src_level, unsigned level_offset)
-
BaseTexture() = default
-
BaseTexture(BaseTexture&&) = default
-
BaseTexture &operator=(BaseTexture&&) = default
Public Static Functions
-
static inline int calcSubResIdx(int level, int slice, int mip_levels)
Protected Functions
-
inline ~BaseTexture() override
-
virtual int texaddrImpl(int addrmode) = 0
-
virtual int texaddruImpl(int addrmode) = 0
-
virtual int texaddrvImpl(int addrmode) = 0
-
inline virtual int texaddrwImpl(int)
-
virtual int texbordercolorImpl(E3DCOLOR) = 0
-
virtual int texfilterImpl(int filtermode) = 0
-
virtual int texmipmapImpl(int mipmapmode) = 0
-
virtual int texlodImpl(float mipmaplod) = 0
-
virtual int setAnisotropyImpl(int level) = 0
Protected Attributes
-
bool samplerEnabled = true
Protected Static Attributes
-
static constexpr int TEX_COPIED = 1 << 30
-
struct IReloadData
Public Functions
-
inline virtual ~IReloadData()
-
virtual void reloadD3dRes(BaseTexture *t) = 0
-
virtual void destroySelf() = 0
-
inline virtual ~IReloadData()
-
inline virtual bool setReloadCallback(IReloadData*)
-
namespace ddsx
-
namespace d3d
Functions
-
bool check_texformat(int cflg)
Check whether the specified texture format is available.
- Parameters:
cflg – The texture format to check.
- Returns:
Returns false if a texture of the specified format cannot be created, otherwise returns true.
-
int get_max_sample_count(int cflg)
Get the maximum sample count for the given texture format.
- Parameters:
cflg – The texture format.
- Returns:
The maximum sample count for the given texture format.
-
unsigned get_texformat_usage(int cflg, int restype = RES3D_TEX)
Get the texture format usage for the given texture format.
- Todo:
Use enum class as a returned type.
- Parameters:
cflg – The texture format.
restype – The resource type (default value is RES3D_TEX).
- Returns:
The texture format usage. One of the USAGE_XXX flags.
-
bool issame_texformat(int cflg1, int cflg2)
Check whether two texture creation flags result in the same format.
- Parameters:
cflg1 – The first texture creation flag.
cflg2 – The second texture creation flag.
- Returns:
Returns true if the two texture creation flags result in the same format, otherwise returns false.
-
bool check_cubetexformat(int cflg)
Check whether the specified cube texture format is available.
- Parameters:
cflg – The cube texture format to check.
- Returns:
Returns false if a cube texture of the specified format cannot be created, otherwise returns true.
-
bool check_voltexformat(int cflg)
Check whether the specified volume texture format is available.
- Parameters:
cflg – The volume texture format to check.
- Returns:
Returns false if a volume texture of the specified format cannot be created, otherwise returns true.
-
BaseTexture *create_tex(TexImage32 *img, int w, int h, int flg, int levels, const char *stat_name = nullptr)
Create a texture.
- Parameters:
img – 32-bit image data. nullptr if there are no image data.
w – The width of the texture.
h – The height of the texture.
flg – The texture creation flags.
levels – The maximum number of mipmap levels.
stat_name – The name of the texture for statistics purposes (optional).
- Returns:
A pointer to the created texture, or nullptr on error.
-
BaseTexture *create_ddsx_tex(IGenLoad &crd, int flg, int quality_id, int levels = 0, const char *stat_name = nullptr)
Create a texture from a DDSx stream.
- Parameters:
crd – The DDSx stream.
flg – The texture creation flags.
quality_id – The quality index.
levels – The number of loaded mipmaps (0=all, >0=only first ‘levels’ mipmaps).
stat_name – The name of the texture for statistics purposes (optional).
- Returns:
A pointer to the created texture, or nullptr on error.
-
BaseTexture *alloc_ddsx_tex(const ddsx::Header &hdr, int flg, int quality_id, int levels = 0, const char *stat_name = nullptr, int stub_tex_idx = -1)
Allocate a texture object using a DDSx header (not texture contents loaded at this time).
- Parameters:
hdr – The DDSx header.
flg – The texture creation flags.
quality_id – The quality index.
levels – The maximum number of mipmap levels.
stat_name – The name of the texture for statistics purposes (optional).
stub_tex_idx – The index of the stub texture (default value is -1).
- Returns:
A pointer to the allocated texture, or nullptr on error.
-
inline TexLoadRes load_ddsx_tex_contents(BaseTexture *t, const ddsx::Header &hdr, IGenLoad &crd, int q_id)
Load the texture content from a DDSx stream using a DDSx header for a previously allocated texture.
- Parameters:
t – The previously allocated texture.
hdr – The DDSx header.
crd – The DDSx stream.
q_id – The quality index.
- Returns:
Returns true if the texture content was successfully loaded, otherwise returns false.
-
BaseTexture *create_cubetex(int size, int flg, int levels, const char *stat_name = nullptr)
Create a cubic texture.
- Parameters:
size – The size of the texture. (6 faces size x size)
flg – The texture creation flags.
levels – The maximum number of mipmap levels.
stat_name – The name of the texture for statistics purposes (optional).
- Returns:
A pointer to the created texture, or nullptr on error.
-
BaseTexture *create_voltex(int w, int h, int d, int flg, int levels, const char *stat_name = nullptr)
Create a volume texture.
- Parameters:
w – The width of the texture.
h – The height of the texture.
d – The depth of the texture.
flg – The texture creation flags.
levels – The maximum number of mipmap levels.
stat_name – The name of the texture for statistics purposes (optional).
- Returns:
A pointer to the created texture, or nullptr on error.
-
BaseTexture *create_array_tex(int w, int h, int d, int flg, int levels, const char *stat_name)
Create a texture2d array.
- Parameters:
w – The width of the texture.
h – The height of the texture.
d – Amount of textures in the array.
flg – The texture creation flags.
levels – The maximum number of mipmap levels.
stat_name – The name of the texture for statistics purposes.
- Returns:
A pointer to the created texture, or nullptr on error.
-
BaseTexture *create_cube_array_tex(int side, int d, int flg, int levels, const char *stat_name)
Create a cube array tex object.
- Parameters:
side – The size of the texture. (6 faces size x size)
d – Amount of textures in the array.
flg – The texture creation flags.
levels – The maximum number of mipmap levels.
stat_name – The name of the texture for statistics purposes.
- Returns:
A pointer to the created texture, or nullptr on error.
-
BaseTexture *alias_tex(BaseTexture *baseTexture, TexImage32 *img, int w, int h, int flg, int levels, const char *stat_name = nullptr)
Create a texture alias, a texture using the same memory as another texture but with a different format.
- Parameters:
baseTexture – The base texture to alias.
img – 32-bit image data.
w – The width of the texture.
h – The height of the texture.
flg – The texture creation flags.
levels – The maximum number of mipmap levels.
stat_name – The name of the texture for statistics purposes (optional).
- Returns:
A pointer to the created texture alias, or nullptr on error.
-
BaseTexture *alias_cubetex(BaseTexture *baseTexture, int size, int flg, int levels, const char *stat_name = nullptr)
Create a cube texture alias, a texture using the same memory as another cube texture but with a different format.
- Parameters:
baseTexture – The base cube texture to alias.
size – The size of the texture.
flg – The texture creation flags.
levels – The maximum number of mipmap levels.
stat_name – The name of the texture for statistics purposes (optional).
- Returns:
A pointer to the created cube texture alias, or nullptr on error.
-
BaseTexture *alias_voltex(BaseTexture *baseTexture, int w, int h, int d, int flg, int levels, const char *stat_name = nullptr)
Create a volume texture alias, a texture using the same memory as another volume texture but with a different format.
- Parameters:
baseTexture – The base volume texture to alias.
w – The width of the texture.
h – The height of the texture.
d – The depth of the texture.
flg – The texture creation flags.
levels – The maximum number of mipmap levels.
stat_name – The name of the texture for statistics purposes (optional).
- Returns:
A pointer to the created volume texture alias, or nullptr on error.
-
BaseTexture *alias_array_tex(BaseTexture *baseTexture, int w, int h, int d, int flg, int levels, const char *stat_name)
Create a texture2d array alias, a texture using the same memory as another texture2d array but with a different format.
- Parameters:
baseTexture – The base texture2d array to alias.
w – The width of the texture.
h – The height of the texture.
d – Amount of textures in the array.
flg – The texture creation flags.
levels – The maximum number of mipmap levels.
stat_name – The name of the texture for statistics purposes (optional).
- Returns:
A pointer to the created texture2d array alias, or nullptr on error.
-
BaseTexture *alias_cube_array_tex(BaseTexture *baseTexture, int side, int d, int flg, int levels, const char *stat_name)
Create a cube array texture alias, a texture using the same memory as another cube array texture but with a different format.
- Parameters:
baseTexture – The base cube array texture to alias.
side – The side of the cube texture.
d – Amount of textures in the array.
flg – The texture creation flags.
levels – The maximum number of mipmap levels.
stat_name – The name of the texture for statistics purposes (optional).
- Returns:
A pointer to the created cube array texture alias, or nullptr on error.
-
bool stretch_rect(BaseTexture *src, BaseTexture *dst, RectInt *rsrc = nullptr, RectInt *rdst = nullptr)
Stretch a rectangle from the source texture to the destination texture.
Under the hood it is a call of CopySubresourceRegion if source and destination textures are the same type and their texel could be mapped one to one. Otherwise it is an execution of a shader that does the stretching.
- Parameters:
src – The source texture.
dst – The destination texture.
rsrc – The source rectangle (optional).
rdst – The destination rectangle (optional).
- Returns:
Returns true if the stretch operation was successful, otherwise returns false.
-
void get_texture_statistics(uint32_t *num_textures, uint64_t *total_mem, String *out_dump)
Get the texture statistics.
- Parameters:
num_textures – Pointer to store the number of textures.
total_mem – Pointer to store the total memory used by textures.
out_dump – Pointer to store the texture statistics dump.
-
bool set_tex(unsigned shader_stage, unsigned slot, BaseTexture *tex, bool use_sampler = true)
Set a texture for a shader stage and slot.
- Parameters:
shader_stage – The shader stage. One of the STAGE_XXX flags.
slot – The slot.
tex – The texture to set.
use_sampler – Whether to use the sampler (default value is true).
- Returns:
Returns true if the texture was successfully set, otherwise returns false.
-
inline bool settex(int slot, BaseTexture *tex)
Set a texture for a pixel shader slot.
- Parameters:
slot – The slot.
tex – The texture to set.
- Returns:
Returns true if the texture was successfully set, otherwise returns false.
-
inline bool settex_vs(int slot, BaseTexture *tex)
Set a texture for a vertex shader slot.
- Parameters:
slot – The slot.
tex – The texture to set.
- Returns:
Returns true if the texture was successfully set, otherwise returns false.
-
bool check_texformat(int cflg)