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  YI_MEMORY_ACCESS {
  YI_MEMORY_PRIVATE,
  YI_MEMORY_SHARED,
  YI_MEMORY_DIRECT,
  YI_MEMORY_VOLATILE
}
 
- Public Types inherited from CYIAssetTextureBase
enum  YI_MIN_MAG_FILTER {
  YI_LINEAR,
  YI_NEAREST
}
 
enum  YI_TEXTURE_WRAP {
  YI_CLAMP_TO_EDGE,
  YI_MIRROR,
  YI_REPEAT
}
 
enum  USAGE {
  USAGE_STATIC,
  USAGE_DYNAMIC,
  USAGE_RENDER_TARGET
}
 
- Public Types inherited from CYIAssetHardware
enum  RETENTION_POLICY {
  RETAIN = 0,
  UNLOAD
}
 The YI_HW_ASSET_RETENTION_POLICY 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  PATH_TYPE {
  PATH_ABSOLUTE = 0,
  PATH_RELATIVE
}
 

Public Member Functions

 CYIAssetTextureRaw (USAGE usage=USAGE_STATIC, IYIMaterialFactory::YI_COLORSPACE colorSpace=IYIMaterialFactory::YI_RGBA8888)
 
virtual ~CYIAssetTextureRaw ()
 
void SetData (uint8_t *pData, int32_t nWidth, int32_t nHeight, YI_MEMORY_ACCESS memoryAccess)
 
void SetData (uint8_t *pData, int32_t nWidth, int32_t nHeight, int32_t nPitch, YI_MEMORY_ACCESS memoryAccess)
 
const uint8_t * GetData () const
 
uint8_t * GetData ()
 
YI_MEMORY_ACCESS GetMemoryAccess () const
 
int32_t GetPitch () const
 
void ClearPixelData ()
 
- Public Member Functions inherited from CYIAssetTextureBase
 CYIAssetTextureBase (USAGE usage=USAGE_STATIC)
 
virtual ~CYIAssetTextureBase ()
 
void AddDirtyRegion (const YI_RECT_REL &dirtyRectangle)
 
void ClearDirtyRegions ()
 
const std::vector< YI_RECT_REL > & GetDirtyRegions () const
 
const YI_TEXTURE_CONFIGGetConfiguration () const
 
virtual int32_t GetWidth () const
 
virtual int32_t GetHeight () const
 
IYIMaterialFactory::YI_COLORSPACE GetColorSpace () const
 
void SetConfiguration (const YI_TEXTURE_CONFIG &config)
 
void SetMinificationFilter (YI_MIN_MAG_FILTER minFilter=YI_LINEAR, YI_MIN_MAG_FILTER magFilter=YI_LINEAR)
 
void SetMipmappingEnabled (bool bEnable)
 
bool IsMipmappingEnabled () const
 
void SetTextureWrap (YI_TEXTURE_WRAP wrapS=YI_CLAMP_TO_EDGE, YI_TEXTURE_WRAP wrapT=YI_CLAMP_TO_EDGE)
 
virtual bool HasExtendedDimensions () const
 
USAGE GetUsage () const
 
- Public Member Functions inherited from CYIAssetHardware
 CYIAssetHardware ()
 
virtual ~CYIAssetHardware ()
 
virtual bool RequestHardwareLoad ()
 
virtual bool RequestHardwareUnload ()
 
virtual bool RequestInvalidate ()
 
virtual bool RequestRestore ()
 
virtual bool Prepare () override
 
std::shared_ptr< IYIGPUObjectGetGPUObject () const
 
bool IsLoadedOnGPU () const
 
RETENTION_POLICY GetRetentionPolicy () const
 
void SetRetentionPolicy (RETENTION_POLICY ePolicy)
 
- 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)
 
- Public Member Functions inherited from CYIScriptableRTTIObject
 CYIScriptableRTTIObject ()
 
virtual ~CYIScriptableRTTIObject ()
 
virtual const CYIRuntimeTypeInfoGetRuntimeTypeInfoForScriptObject () const override
 
- Public Member Functions inherited from CYIScriptableObject
 CYIScriptableObject ()
 
 CYIScriptableObject (const CYIScriptableObject &other)
 
CYIScriptableObjectoperator= (const CYIScriptableObject &other)
 
virtual ~CYIScriptableObject ()
 
CYIBindingImplementationGetBindingImplementation () const
 
void SetBindingImplementation (CYIBindingImplementation *pBindingImplementation)
 

Protected Member Functions

virtual std::shared_ptr< IYIGPUObjectCreateGPUObject () const override
 
virtual std::pair< uint32_t, uint32_t > GetApproximateSize () const override
 
virtual void OnUnload () override
 
- Protected Member Functions inherited from CYIAssetTextureBase
virtual void DirtyEntireTexture ()
 
void SetWidth (int32_t nWidth)
 
void SetHeight (int32_t nHeight)
 
void SetColorSpace (IYIMaterialFactory::YI_COLORSPACE eColorSpace)
 
virtual void ApplyRetainmentPolicy () override
 
- 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, PATH_TYPE ePathType)
 
void SetApproximateSize (uint32_t nSize)
 
void SetLoaded (bool bAssetLoaded)
 
void SetLoadParameters (std::unique_ptr< CYIAssetLoadParams > pParams)
 
- Protected Member Functions inherited from CYIScriptableRTTIObject
virtual std::pair< const CYIRuntimeTypeInfo *, const void * > GetRuntimeTypeInfoWithObject () const =0
 

Additional Inherited Members

- Protected Attributes inherited from CYIAssetHardware
bool m_bHardwareLoadRequested
 
std::shared_ptr< IYIGPUObjectm_pGPUObject
 
RETENTION_POLICY m_eRetentionPolicy
 
- Static Protected Attributes inherited from CYIAsset
static ssize_t INVALID_ID
 

Member Enumeration Documentation

Raw data memory usage.

Enumerator
YI_MEMORY_PRIVATE 

Memory is managed by the asset and must not be deleted

YI_MEMORY_SHARED 

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

YI_MEMORY_DIRECT 

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

YI_MEMORY_VOLATILE 

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

Constructor & Destructor Documentation

CYIAssetTextureRaw::CYIAssetTextureRaw ( USAGE  usage = USAGE_STATIC,
IYIMaterialFactory::YI_COLORSPACE  colorSpace = IYIMaterialFactory::YI_RGBA8888 
)

Construct a new CYIAssetTextureRaw with specified usage and colorSpace.

virtual CYIAssetTextureRaw::~CYIAssetTextureRaw ( )
virtual

Member Function Documentation

void CYIAssetTextureRaw::ClearPixelData ( )

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

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.

virtual std::pair<uint32_t, uint32_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.

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::YI_MEMORY_VOLATILE, has not been set yet or CYIAssetTextureRaw::ClearPixelData() was called prior to this.

See also
SetData
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::YI_MEMORY_VOLATILE, has not been set yet or CYIAssetTextureRaw::ClearPixelData() was called prior to this.

See also
SetData
YI_MEMORY_ACCESS CYIAssetTextureRaw::GetMemoryAccess ( ) const

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

See also
SetData
int32_t CYIAssetTextureRaw::GetPitch ( ) const

Get the texture's pitch.

See also
SetData
virtual void CYIAssetTextureRaw::OnUnload ( )
overrideprotectedvirtual

Implements CYIAssetTextureBase.

void CYIAssetTextureRaw::SetData ( uint8_t *  pData,
int32_t  nWidth,
int32_t  nHeight,
YI_MEMORY_ACCESS  memoryAccess 
)

Sets raw data directly to the texture.

The pData pointer has to be of size "\a nWidth * \a nHeight * 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 YI_MEMORY_PRIVATE, it has to have been allocated using YI_MALLOC.

See also
CYIAssetTextureRaw::YI_MEMORY_ACCESS
Note
If the memory access rule passed in is YI_MEMORY_VOLATILE, this call must be called from the main application thread.
If the memory access rule passed in is YI_MEMORY_DIRECT, this call will assert because a Pitch must to be passed. The overloaded SetData function with Pitch argument should be used instead.
void CYIAssetTextureRaw::SetData ( uint8_t *  pData,
int32_t  nWidth,
int32_t  nHeight,
int32_t  nPitch,
YI_MEMORY_ACCESS  memoryAccess 
)

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

The pData pointer has to be of size "\a nPitch * \a nHeight * 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 YI_MEMORY_PRIVATE, it has to have been allocated using YI_MALLOC.

See also
CYIAssetTextureRaw::YI_MEMORY_ACCESS
Note
If the memory access rule passed in is YI_MEMORY_VOLATILE, this call must be called from the main application thread.
If the memory access rule passed in is YI_MEMORY_DIRECT, a valid nPitch must be passed.

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