Cogs.Core
Public Member Functions | Public Attributes | List of all members
Cogs::Core::Texture Struct Reference

Texture resources contain raster bitmap data to use for texturing. More...

#include <Texture.h>

Inheritance diagram for Cogs::Core::Texture:
Cogs::Core::ResourceBase

Public Member Functions

 Texture ()=default
 Construct a texture resource.
 
 Texture (const Texture &other)=delete
 Copying disabled since copying a texture resource might be a resource-intensive operation.
 
 Texture (Texture &&other)=default
 Move construct a texture from the given texture other.
 
 ~Texture ()
 Destroy a texture.
 
Textureoperator= (Texture &&other)=default
 Move assign a texture from the given texture other.
 
MappedTexture< uint8_t > map (uint16_t width, uint16_t height, TextureFormat format, bool generateMipMap)
 Map the texture data, ensuring the data is sized to hold width * height * bpp of the format bytes.
 
template<typename Element >
MappedTexture< Element > map (uint16_t width, uint16_t height, bool generateMipMap)
 Map the texture data, ensuring the data is sized to hold width * height * sizeof(Element) bytes.
 
template<typename Element >
MappedTexture< Element > map (uint16_t width, uint16_t height, TextureFormat format, bool generateMipMap)
 Map the texture data, ensuring the data is sized to hold width * height * sizeof(Element) bytes.
 
void unmap ()
 Unmap the currently mapped texture data.
 
void setData (ResourceDimensions target, const void *data, size_t size, int width, int height, TextureFormat format, bool generateMipMap)
 Set the texture data.
 
void setData (ResourceDimensions target, const void *data, size_t size, int width, int height, int levels, TextureFormat format, bool generateMipMap)
 
void COGSCORE_DLL_API setData (ResourceDimensions target, const void *data, size_t size, uint32_t width, uint32_t height, uint32_t depth, uint32_t layers, uint32_t faces, uint32_t levels, TextureFormat format, bool generateMipMap)
 
void clearData ()
 
bool empty ()
 
void * mapInternal (uint16_t width, uint16_t height, TextureFormat format, bool mipMap)
 
- Public Member Functions inherited from Cogs::Core::ResourceBase
 ResourceBase ()=default
 Constructs a new resource base.
 
 ResourceBase (const ResourceBase &other)=delete
 Disable trivial copies of resources.
 
ResourceBaseoperator= (const ResourceBase &other)=delete
 Disable copy-assignment of resources.
 
 ResourceBase (ResourceBase &&other)
 Move constructs a resource base from other.
 
ResourceBaseoperator= (ResourceBase &&other)
 Move assign the resource from the given ResourceBase other.
 
 ~ResourceBase ()
 Destructs the resource.
 
void setInitialized ()
 
void setChanged ()
 
bool hasChanged () const
 
void setLoading ()
 
void setLoaded ()
 
void setFailedLoad ()
 
void setActive ()
 
void setResident ()
 
void setProxy ()
 
void setKeepStorage ()
 
bool isInitialized () const
 
bool isLoaded () const
 
bool isActive () const
 
bool isResident () const
 
bool isDependency () const
 
bool isDeleted () const
 
bool isOrphaned () const
 
bool isProxy () const
 
bool hasFailedLoad () const
 
bool hasFailedActivation () const
 
bool keepStorage () const
 
void setType (ResourceTypes type)
 Set the type enumeration of the resource.
 
ResourceTypes getType () const
 Gets the type enumeration of the resource.
 
void setId (ResourceId resourceId)
 Set the resource id of the resource.
 
ResourceId getId () const
 Get the resource id of this instance.
 
void setFlag (ResourceFlags flags)
 Set the given resource flag.
 
void setFlags (ResourceFlags flags)
 
void unsetFlag (ResourceFlags flag)
 Unset the given flag.
 
bool isSet (ResourceFlags flag) const
 Check if the given flag is currently set.
 
ResourceFlags getFlags () const
 Get the current flags of the resource.
 
void attachResource (RenderResource *attachment)
 Attach the given GPU resource to the resource.
 
bool hasAttachedResource () const
 Check if the resource has an attachment.
 
RenderResourcegetAttachedResource () const
 Get the attached resource.
 
void setOwner (IResourceManager *owner)
 Sets the owner of this resource instance.
 
IResourceManagergetOwner () const
 
void setName (const StringView &name)
 Set the user friendly name of the resource.
 
StringView getName () const
 Get the name of the resource.
 
void setSource (const StringView &source)
 
StringView getSource () const
 
void increment ()
 Increments the reference count of the resource.
 
void decrement ()
 Decrement the reference count of the resource.
 
uint32_t referenceCount () const
 Get the current reference count.
 
void incrementGeneration ()
 Increment the generation count.
 
uint32_t getGeneration () const
 Get the generation count.
 
void setSlot (uint32_t slot)
 Sets the slot at which the resource is internally tracked.
 
uint32_t getSlot () const
 Gets the slot where the resource is tracked internally.
 

Public Attributes

TextureDescription description
 
TextureData storage
 
intptr_t externalHandle = 0
 
UniqueValue< bool > ownsExternalTexture { false }
 
bool hasAlpha = false
 

Additional Inherited Members

- Static Public Attributes inherited from Cogs::Core::ResourceBase
static const uint32_t NoAttachment = 0xFFFFFFFF
 Constant used to signal no attachment.
 

Detailed Description

Texture resources contain raster bitmap data to use for texturing.

Textures can be used as input to materials defining surface properties of the material. In addition, textures are used to store bitmap fonts by the FontManager.

The texture may function as a wrapper to an externally defined texture, in which case the texture data is not contained by the texture itself, only an externalHandle to the actual texture is held.

Texture resources are loaded, processed and activated by the TextureManager.

Definition at line 90 of file Texture.h.

Constructor & Destructor Documentation

◆ Texture()

Cogs::Core::Texture::Texture ( Texture &&  other)
default

Move construct a texture from the given texture other.

Parameters
otherTexture resource to move from. Will leave the other resource in an empty, uninitialized state.

◆ ~Texture()

Cogs::Core::Texture::~Texture ( )

Destroy a texture.

Definition at line 47 of file Texture.cpp.

Member Function Documentation

◆ clearData()

void Cogs::Core::Texture::clearData ( )

Definition at line 126 of file Texture.cpp.

◆ empty()

bool Cogs::Core::Texture::empty ( )
inline

Definition at line 193 of file Texture.h.

◆ map() [1/3]

template<typename Element >
MappedTexture< Element > Cogs::Core::Texture::map ( uint16_t  width,
uint16_t  height,
bool  generateMipMap 
)
inline

Map the texture data, ensuring the data is sized to hold width * height * sizeof(Element) bytes.

Parameters
widthWidth of the texture in pixels.
heightHeight of the texture in pixels.
Template Parameters
ElementElement type of the texture. The texture format is automatically determined from the texture type.
Returns
A wrapper of the mapped data, automatically unmapping the data when the scope is exited.

Definition at line 145 of file Texture.h.

◆ map() [2/3]

MappedTexture< uint8_t > Cogs::Core::Texture::map ( uint16_t  width,
uint16_t  height,
TextureFormat  format,
bool  generateMipMap 
)
inline

Map the texture data, ensuring the data is sized to hold width * height * bpp of the format bytes.

Parameters
widthWidth of the texture in pixels.
heightHeight of the texture in pixels.
formatTexture data format.
Returns
A wrapper of the mapped data, automatically unmapping the data when the scope is exited.

Definition at line 129 of file Texture.h.

◆ map() [3/3]

template<typename Element >
MappedTexture< Element > Cogs::Core::Texture::map ( uint16_t  width,
uint16_t  height,
TextureFormat  format,
bool  generateMipMap 
)
inline

Map the texture data, ensuring the data is sized to hold width * height * sizeof(Element) bytes.

The data will be transferred to the graphics device using the given format.

Parameters
widthWidth of the texture in pixels.
heightHeight of the texture in pixels.
formatFormat of the texture to send to the graphics device.
Template Parameters
ElementElement type of the texture. The texture format is automatically determined from the texture type.
Returns
A wrapper of the mapped data, automatically unmapping the data when the scope is exited.

Definition at line 167 of file Texture.h.

◆ mapInternal()

void * Cogs::Core::Texture::mapInternal ( uint16_t  width,
uint16_t  height,
TextureFormat  format,
bool  mipMap 
)

Definition at line 109 of file Texture.cpp.

◆ operator=()

Texture & Cogs::Core::Texture::operator= ( Texture &&  other)
default

Move assign a texture from the given texture other.

Parameters
otherTexture resource to move from. Will be left in an empty, uninitialized state.
Returns
A reference to this texture.

◆ setData() [1/3]

void Cogs::Core::Texture::setData ( ResourceDimensions  target,
const void *  data,
size_t  size,
int  width,
int  height,
int  levels,
TextureFormat  format,
bool  generateMipMap 
)

Definition at line 59 of file Texture.cpp.

◆ setData() [2/3]

void Cogs::Core::Texture::setData ( ResourceDimensions  target,
const void *  data,
size_t  size,
int  width,
int  height,
TextureFormat  format,
bool  generateMipMap 
)

Set the texture data.

Definition at line 54 of file Texture.cpp.

Referenced by Cogs::Core::TextureManager::initialize().

◆ setData() [3/3]

void COGSCORE_DLL_API Cogs::Core::Texture::setData ( ResourceDimensions  target,
const void *  data,
size_t  size,
uint32_t  width,
uint32_t  height,
uint32_t  depth,
uint32_t  layers,
uint32_t  faces,
uint32_t  levels,
TextureFormat  format,
bool  generateMipMap 
)

Definition at line 64 of file Texture.cpp.

◆ unmap()

void Cogs::Core::Texture::unmap ( )
inline

Unmap the currently mapped texture data.

Will set the texture state to ResourceState::Changed.

Definition at line 177 of file Texture.h.

Member Data Documentation

◆ description

TextureDescription Cogs::Core::Texture::description

Definition at line 197 of file Texture.h.

◆ externalHandle

intptr_t Cogs::Core::Texture::externalHandle = 0

Definition at line 199 of file Texture.h.

◆ hasAlpha

bool Cogs::Core::Texture::hasAlpha = false

Definition at line 201 of file Texture.h.

◆ ownsExternalTexture

UniqueValue<bool> Cogs::Core::Texture::ownsExternalTexture { false }

Definition at line 200 of file Texture.h.

◆ storage

TextureData Cogs::Core::Texture::storage

Definition at line 198 of file Texture.h.


The documentation for this struct was generated from the following files: