You.i Engine
CYIAssetHardware Class Referenceabstract

Detailed Description

Hardware-mirrored asset. These assets contain IYIGPUObject counterparts.

Assets will automatically be marked for loading into video memory when their data setters are called. Users may also manually load and unload them into/from video memory using the CYIAssetHardware::RequestHardwareLoad() and CYIAssetHardware::RequestHardwareUnload() functions.

#include <asset/YiAssetHardware.h>

Inheritance diagram for CYIAssetHardware:

Public Types

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

 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
 
virtual std::pair< size_t, size_tGetApproximateSize () 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 =0
 
virtual void ApplyRetainmentPolicy ()
 
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)
 
virtual void OnUnload ()
 

Protected Attributes

bool m_hardwareLoadRequested
 
std::shared_ptr< IYIGPUObjectm_pGPUObject
 
RetentionPolicy m_retentionPolicy
 

Friends

class CYIGPULoadBufferEvent
 

Additional Inherited Members

- Static Protected Attributes inherited from CYIAsset
static ssize_t INVALID_ID
 

Member Enumeration Documentation

◆ RetentionPolicy

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.

Note
Please note that this retension mode only affects static assets since dynamic assets are meant to be update on a regular basis.
Warning
The default retention policy varies per platform.
Enumerator
Retain 

Indicates that the asset data should be retained on CPU memory after is is uploaded onto GPU memory.

Unload 

Indicate that the asset data should not be retained on CPU memory and unloaded/reclaimed after is is uploaded onto GPU memory.

Constructor & Destructor Documentation

◆ CYIAssetHardware()

CYIAssetHardware::CYIAssetHardware ( )

◆ ~CYIAssetHardware()

virtual CYIAssetHardware::~CYIAssetHardware ( )
overridevirtual

Member Function Documentation

◆ ApplyRetainmentPolicy()

virtual void CYIAssetHardware::ApplyRetainmentPolicy ( )
inlineprotectedvirtual

Unloads CPU-side data buffer memory if the retainment policy is configured to unload instead of retaining it.

This function should only be used internally by the GPU object after the data has been uploaded onto the GPU. that some asset may chose to retain/unload cpu assets with additional conditions. For example, CYIAssetTextureBase won't unload the cpu asset if the asset is marked as being dynamic.

See also
SetRetentionPolicy
GetRetentionPolicy

Reimplemented in CYIAssetTextureBase, and CYIAssetBufferObjectData.

◆ CreateGPUObject()

virtual std::shared_ptr<IYIGPUObject> CYIAssetHardware::CreateGPUObject ( ) const
protectedpure virtual

Subclasses must implement this function to instance a new IYIGPUObject concrete type corresponding to the asset container. This function will be called by the CreateGPUObject implementation of CYIAssetHardware

Warning
This function may not return null!

Implemented in CYIAssetTextureBase, CYIAssetBufferObjectData, CYIAssetTextureRaw, CYIAssetShaderProgram, CYIAssetFramebuffer, CYIAssetTexture, and CYIAssetTextureFramebuffer.

◆ GetGPUObject()

const std::shared_ptr<IYIGPUObject>& CYIAssetHardware::GetGPUObject ( ) const

Returns the hardware version of this object, if available, or a null version if the asset is not being managed or if a hardware version is unavailable.

◆ GetRetentionPolicy()

RetentionPolicy CYIAssetHardware::GetRetentionPolicy ( ) const

Returns the hardware asset retention policy for this asset.

See also
CYIAssetHardware::RetentionPolicy

◆ IsLoadedOnGPU()

bool CYIAssetHardware::IsLoadedOnGPU ( ) const

Helper function that returns true when the asset data has been successfully loaded into video memory. It will return false if the GPUObject hasn't been instantiated by CreateGPUObject(), or if the GPUObject is not in the correct 'loaded' state.

◆ OnLoad()

virtual void CYIAssetHardware::OnLoad ( )
overrideprotectedvirtual

Reimplemented from CYIAsset.

◆ Prepare()

virtual bool CYIAssetHardware::Prepare ( )
overridevirtual

Generates the hardware version of this object.

Reimplemented from CYIAsset.

◆ RequestHardwareLoad()

virtual bool CYIAssetHardware::RequestHardwareLoad ( )
virtual

Will initiate a load request of the software data into video memory.

Reimplemented in CYIAssetFramebuffer.

◆ RequestHardwareUnload()

virtual bool CYIAssetHardware::RequestHardwareUnload ( )
virtual

Will initiate an unload request from video memory.

Reimplemented in CYIAssetFramebuffer.

◆ RequestInvalidate()

virtual bool CYIAssetHardware::RequestInvalidate ( )
virtual

In the event that the hardware context is lost, this method can be called to invalidate the resource.

Will be called automatically if this asset is registered with the asset manager.

Reimplemented in CYIAssetFramebuffer.

◆ RequestRestore()

virtual bool CYIAssetHardware::RequestRestore ( )
virtual

In the event that the hardware context is restored, this method can be called to restore the resources after it was invalidated using Invalidate.

Will be called automatically if this asset is registered with the asset manager.

Reimplemented in CYIAssetFramebuffer.

◆ SetRetentionPolicy()

void CYIAssetHardware::SetRetentionPolicy ( RetentionPolicy  policy)

Sets the hardware asset retention policy for this asset.

See also
CYIAssetHardware::RetentionPolicy

Friends And Related Function Documentation

◆ CYIGPULoadBufferEvent

friend class CYIGPULoadBufferEvent
friend

Member Data Documentation

◆ m_hardwareLoadRequested

bool CYIAssetHardware::m_hardwareLoadRequested
protected

◆ m_pGPUObject

std::shared_ptr<IYIGPUObject> CYIAssetHardware::m_pGPUObject
protected

◆ m_retentionPolicy

RetentionPolicy CYIAssetHardware::m_retentionPolicy
protected

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