You.i Engine
CYIAssetTextureRaw Class Reference

Detailed Description

A texture asset representing an image which will be loaded into the GPU.

Unlike CYIAssetTexture which makes use of a CYIBitmap, this asset has its raw data set directly.

See also
CYIAssetManager
CYIAssetTexture

#include <asset/YiAssetTextureRaw.h>

Inheritance diagram for CYIAssetTextureRaw:

Public Types

enum  MemoryAccess {
  MemoryAccess::Private,
  MemoryAccess::Shared,
  MemoryAccess::Direct,
  MemoryAccess::Volatile
}
 
- Public Types inherited from CYIAssetTextureBase
enum  Filtering {
  Filtering::Linear,
  Filtering::Nearest
}
 
enum  WrapMode {
  WrapMode::ClampToEdge,
  WrapMode::Mirror,
  WrapMode::Repeat
}
 
enum  Usage {
  Usage::Static,
  Usage::Dynamic,
  Usage::RenderTarget
}
 
- Public Types inherited from CYIAssetHardware
enum  RetentionPolicy {
  RetentionPolicy::Retain = 0,
  RetentionPolicy::Unload
}
 The CYIAssetHardware::RetentionPolicy enum specifies the retention policy of static hardware assets from the CPU memory once they are loaded onto the GPU. It is globally configurable, where new CYIAssetHardware will be making use of it and the can also change directly per assets. Be aware that on some platform, it is best to leave the assets retained on the CPU side when the platform lifecycle has the ability to destroy the graphic context while the app still runs, giving You.i Engine the ability to re-load every assets back onto GPU memory really fast. A good example of such platform would be Android. More...
 
- Public Types inherited from CYIAsset
enum  PathType {
  PathType::Absolute = 0,
  PathType::Relative
}
 

Public Member Functions

 CYIAssetTextureRaw (Usage usage=Usage::Static, IYIMaterialFactory::ColorSpace colorSpace=IYIMaterialFactory::ColorSpace::RGBA8888)
 
virtual ~CYIAssetTextureRaw ()
 
void SetData (uint8_t *pData, int32_t width, int32_t height, MemoryAccess memoryAccess)
 
void SetData (uint8_t *pData, int32_t width, int32_t height, int32_t pitch, MemoryAccess memoryAccess)
 
const uint8_t * GetData () const
 
uint8_t * GetData ()
 
MemoryAccess GetMemoryAccess () const
 
int32_t GetPitch () const
 
void ClearPixelData ()
 
- Public Member Functions inherited from CYIAssetTextureBase
 CYIAssetTextureBase (Usage usage=Usage::Static)
 
virtual ~CYIAssetTextureBase () override
 
void AddDirtyRegion (const YI_RECT_REL &dirtyRectangle)
 
void GrowDirtyRegion (const YI_RECT_REL &dirtyRectangle)
 
void ClearDirtyRegions ()
 
const std::vector< YI_RECT_REL > & GetDirtyRegions () const
 
const TextureConfigGetConfiguration () const
 
virtual int32_t GetWidth () const
 
virtual int32_t GetHeight () const
 
IYIMaterialFactory::ColorSpace GetColorSpace () const
 
void SetConfiguration (const TextureConfig &config)
 
void SetMinificationFilter (Filtering minFilter=Filtering::Linear, Filtering magFilter=Filtering::Linear)
 
void SetMipmappingEnabled (bool enable)
 
bool IsMipmappingEnabled () const
 
void SetTextureWrap (WrapMode wrapS=WrapMode::ClampToEdge, WrapMode wrapT=WrapMode::ClampToEdge)
 
virtual bool HasExtendedDimensions () const
 
Usage GetUsage () const
 
virtual void ApplyRetainmentPolicy () override
 
- Public Member Functions inherited from CYIAssetHardware
 CYIAssetHardware ()
 
virtual ~CYIAssetHardware () override
 
virtual bool RequestHardwareLoad ()
 
virtual bool RequestHardwareUnload ()
 
virtual bool RequestInvalidate ()
 
virtual bool RequestRestore ()
 
virtual bool Prepare () override
 
const std::shared_ptr< IYIGPUObject > & GetGPUObject () const
 
bool IsLoadedOnGPU () const
 
RetentionPolicy GetRetentionPolicy () const
 
void SetRetentionPolicy (RetentionPolicy policy)
 
- Public Member Functions inherited from CYIAsset
virtual ~CYIAsset ()
 
const CYIStringGetPath () const
 
CYIAssetLoadParamsGetLoadParameters () const
 
bool SetName (const CYIString &name)
 
const CYIStringGetName () const
 
bool Load ()
 
void Unload ()
 
bool IsLoaded () const
 
bool Equals (const std::shared_ptr< CYIAsset > &pAsset)
 

Protected Member Functions

virtual std::shared_ptr< IYIGPUObjectCreateGPUObject () const override
 
virtual std::pair< size_t, size_tGetApproximateSize () const override
 
virtual void OnUnload () override
 
- Protected Member Functions inherited from CYIAssetTextureBase
virtual void DirtyEntireTexture ()
 
void SetWidth (int32_t width)
 
void SetHeight (int32_t height)
 
void SetColorSpace (IYIMaterialFactory::ColorSpace colorSpace)
 
- Protected Member Functions inherited from CYIAssetHardware
virtual void OnLoad () override
 
- Protected Member Functions inherited from CYIAsset
 CYIAsset ()
 
ssize_t GetID () const
 
void SetPath (const CYIString &path, PathType pathType)
 
void SetApproximateSize (size_t size)
 
void SetLoaded (bool assetLoaded)
 
void SetLoadParameters (std::unique_ptr< CYIAssetLoadParams > pParams)
 

Additional Inherited Members

- Protected Attributes inherited from CYIAssetHardware
bool m_hardwareLoadRequested
 
std::shared_ptr< IYIGPUObjectm_pGPUObject
 
RetentionPolicy m_retentionPolicy
 
- Static Protected Attributes inherited from CYIAsset
static ssize_t INVALID_ID
 

Member Enumeration Documentation

◆ MemoryAccess

Raw data memory usage.

Enumerator
Private 

Memory is managed by the asset and must not be deleted

Shared 

Memory is managed by the application and it is responsible for deleting it

Direct 

Direct video memory. Only relevant on certain platforms, on other platforms this will have the same effect as CYIAssetTextureRaw::MemoryAccess::Shared. The application is responsible for freeing.

Volatile 

The data passed in will be invalid after the call. The texture will be updated immediately

Constructor & Destructor Documentation

◆ CYIAssetTextureRaw()

CYIAssetTextureRaw::CYIAssetTextureRaw ( Usage  usage = Usage::Static,
IYIMaterialFactory::ColorSpace  colorSpace = IYIMaterialFactory::ColorSpace::RGBA8888 
)

Construct a new CYIAssetTextureRaw with specified usage and colorSpace.

◆ ~CYIAssetTextureRaw()

virtual CYIAssetTextureRaw::~CYIAssetTextureRaw ( )
virtual

Member Function Documentation

◆ ClearPixelData()

void CYIAssetTextureRaw::ClearPixelData ( )

Clears the memory used by the pixel data. If memory access rule is not CYIAssetTextureRaw::MemoryAccess::Private, this call only removes its reference to the data and the application is responsible for freeing.

◆ CreateGPUObject()

virtual std::shared_ptr<IYIGPUObject> CYIAssetTextureRaw::CreateGPUObject ( ) const
overrideprotectedvirtual

Each sub-type must implement this function and returns an IYIGPUObject representing the hardware type.

Implements CYIAssetTextureBase.

◆ GetApproximateSize()

virtual std::pair<size_t, size_t> CYIAssetTextureRaw::GetApproximateSize ( ) const
overrideprotectedvirtual

Calculates and returns the approximate number of bytes currently used by this asset. The first item of the returned pair object represents the memory currently taken in the CPU main memory, and the second item of the returned pair object represents the memory currently taken in the GPU memory.

Note
This function only returns an approximate memory consumption as the exact memory consumption changes depending on the used C++ libraries and on the specific GPU infrastructure and drivers used by the system.

Reimplemented from CYIAsset.

◆ GetData() [1/2]

const uint8_t* CYIAssetTextureRaw::GetData ( ) const

Returns the data currently set on this raw texture. If the data is not set, nullptr will be returned. This could be the case if it was set using CYIAssetTextureRaw::MemoryAccess::Volatile, has not been set yet or CYIAssetTextureRaw::ClearPixelData() was called prior to this.

See also
SetData

◆ GetData() [2/2]

uint8_t* CYIAssetTextureRaw::GetData ( )

Returns the data currently set on this raw texture. If the data is not set, nullptr will be returned. This could be the case if it was set using CYIAssetTextureRaw::MemoryAccess::Volatile, has not been set yet or CYIAssetTextureRaw::ClearPixelData() was called prior to this.

See also
SetData

◆ GetMemoryAccess()

MemoryAccess CYIAssetTextureRaw::GetMemoryAccess ( ) const

Return the memory access rule currently set on this raw texture.

See also
SetData

◆ GetPitch()

int32_t CYIAssetTextureRaw::GetPitch ( ) const

Get the texture's pitch.

See also
SetData

◆ OnUnload()

virtual void CYIAssetTextureRaw::OnUnload ( )
overrideprotectedvirtual

Implements CYIAssetTextureBase.

◆ SetData() [1/2]

void CYIAssetTextureRaw::SetData ( uint8_t *  pData,
int32_t  width,
int32_t  height,
MemoryAccess  memoryAccess 
)

Sets raw data directly to the texture.

The pData pointer has to be of size "\a width * \a height * the number of bytes in each pixel". The number of bytes per pixel is determined by the color space set in the asset's constructor.

If the memory access rule is MemoryAccess::Private, it has to have been allocated using YI_MALLOC.

See also
CYIAssetTextureRaw::MemoryAccess
Note
If the memory access rule passed in is MemoryAccess::Volatile, this call must be called from the main application thread.
If the memory access rule passed in is MemoryAccess::Direct, this call will assert because a Pitch must to be passed. The overloaded SetData function with Pitch argument should be used instead.

◆ SetData() [2/2]

void CYIAssetTextureRaw::SetData ( uint8_t *  pData,
int32_t  width,
int32_t  height,
int32_t  pitch,
MemoryAccess  memoryAccess 
)

Sets raw data directly to the texture. A texture pitch can be specified. If set to zero, the pitch will be equal to width. pitch represents the number of pixels in a row.

The pData pointer has to be of size "\a pitch * \a height * the number of bytes in each pixel". The number of bytes per pixel is determined by the color space set in the asset's constructor.

If the memory access rule is MemoryAccess::Private, it has to have been allocated using YI_MALLOC.

See also
CYIAssetTextureRaw::MemoryAccess
Note
If the memory access rule passed in is MemoryAccess::Volatile, this call must be called from the main application thread.
If the memory access rule passed in is MemoryAccess::Direct, a valid pitch must be passed.

The documentation for this class was generated from the following file: