You.i Engine
CYIAssetTextureBase Class Referenceabstract

Detailed Description

This asset represents the base class for POT (Power Of Two) and NPOT (Non-Power Of Two) textures.

A derived class must delete any underlying resources and the associated texture, unless those resources are shared.

See also
CYIAssetHardware
CYIAssetTexture

#include <asset/YiAssetTextureBase.h>

Inheritance diagram for CYIAssetTextureBase:

Classes

struct  YI_TEXTURE_CONFIG
 

Public Types

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

 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
 
virtual std::pair< uint32_t, uint32_t > GetApproximateSize () 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=0
 
virtual void OnUnload () override=0
 
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

Texture usage.

Enumerator
USAGE_STATIC 

A static texture will never be modified again.

USAGE_DYNAMIC 

A dynamic texture can be modified.

USAGE_RENDER_TARGET 

A texture that is to be used in a render target/frame buffer.

Minification and magnification rules.

Enumerator
YI_LINEAR 

Linear interpolation (used when the image is scaled).

YI_NEAREST 

Nearest neighbor interpolation (used when image is scaled).

Texture wrapping rules.

Warning
Not all devices support the use of YI_MIRROR or YI_REPEAT with non-power-of-two texture sizes. A power-of-two texture size is a texture which has a height and width that are a power-of-two, for example a 256x128 texture. If a device does not support this and the texture has a non-power-of-two texture size the texture will not be rendered. It is recommended when using these modes that the texture width and height are power-of-two.
Enumerator
YI_CLAMP_TO_EDGE 

Clamp texture to edge of image. This wrap mode will repeat the last pixel on the edge in the direction for the texture coordinate to which it is applied.

YI_MIRROR 

Mirror texture coordinates. This wrap mode will draw the same image but mirrored horizontally or vectically in the direction for the texture coordinate to which it is applied.

YI_REPEAT 

Repeats the texture – often used for tiling a background. This wrap mode will repeat the image in the direction for the texture coordinate to which it is applied.

Constructor & Destructor Documentation

CYIAssetTextureBase::CYIAssetTextureBase ( USAGE  usage = USAGE_STATIC)
virtual CYIAssetTextureBase::~CYIAssetTextureBase ( )
virtual

Member Function Documentation

void CYIAssetTextureBase::AddDirtyRegion ( const YI_RECT_REL dirtyRectangle)

Dirty a specific sub-image of the data. This function allows for users writing performance-critical applications to update the texture asset without requiring a copy of the entirety of the bitmap information.

Multiple calls to this function will result in multiple regions being updated, there is no overwrite. This object will not check for intersection of dirty rectangles, it is up to the user to provide the most efficient series of rectangles to be updated.

Note
All other modifications to the texture asset will dirty the entire image region. This function is the only means by which a specific subregion can be dirtied.
virtual void CYIAssetTextureBase::ApplyRetainmentPolicy ( )
overrideprotectedvirtual

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
YI_HW_ASSET_RETENTION_POLICY
SetRetentionPolicy
GetRetentionPolicy

Reimplemented from CYIAssetHardware.

void CYIAssetTextureBase::ClearDirtyRegions ( )

Clear the dirty regions.

virtual std::shared_ptr<IYIGPUObject> CYIAssetTextureBase::CreateGPUObject ( ) const
overrideprotectedpure virtual

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

Implements CYIAssetHardware.

Implemented in CYIAssetTextureRaw, CYIAssetTexture, and CYIAssetTextureFramebuffer.

virtual void CYIAssetTextureBase::DirtyEntireTexture ( )
protectedvirtual

Marks the texture as dirty, meaning the associated texture resource needs to be updated.

IYIMaterialFactory::YI_COLORSPACE CYIAssetTextureBase::GetColorSpace ( ) const

Returns the color space used by this texture.

const YI_TEXTURE_CONFIG& CYIAssetTextureBase::GetConfiguration ( ) const

Returns a reference to the YI_TEXTURE_CONFIG structure of this asset. This structure contains all of the texture configuration properties.

const std::vector<YI_RECT_REL>& CYIAssetTextureBase::GetDirtyRegions ( ) const

Returns the dirty regions added using AddDirtyRegion().

virtual int32_t CYIAssetTextureBase::GetHeight ( ) const
virtual

Returns the height of the textured region. In the case of POT textures, this must return the height of the actual textured region and not the actual height of the texture.

Reimplemented in CYIAssetTexture.

USAGE CYIAssetTextureBase::GetUsage ( ) const

Returns the usage for this texture. This value is immutable and is set in the CYIAssetTextureBase constructor.

virtual int32_t CYIAssetTextureBase::GetWidth ( ) const
virtual

Returns the width of the textured region. In the case of POT textures, this must return the width of the actual textured region and not the actual width of the texture.

Reimplemented in CYIAssetTexture.

virtual bool CYIAssetTextureBase::HasExtendedDimensions ( ) const
virtual

Returns true if the texture's dimensions are different than the source dimensions. For example, if the texture is required to be power-of-two but the originating asset size is different, then this should return true.

bool CYIAssetTextureBase::IsMipmappingEnabled ( ) const
virtual void CYIAssetTextureBase::OnUnload ( )
overrideprotectedpure virtual

Reimplemented from CYIAsset.

Implemented in CYIAssetTextureRaw, CYIAssetTexture, and CYIAssetTextureFramebuffer.

void CYIAssetTextureBase::SetColorSpace ( IYIMaterialFactory::YI_COLORSPACE  eColorSpace)
protected

Sets the color space of this texture. This does not perform color space conversions on the underlying data. Calling this function is used to instruct the renderer on how this texture should be loaded onto the GPU.

void CYIAssetTextureBase::SetConfiguration ( const YI_TEXTURE_CONFIG config)

Convenience function for setting the texture configuration all at once

void CYIAssetTextureBase::SetHeight ( int32_t  nHeight)
protected

Sets the height of the textured region. In POT texture implmentations, this should be the height of the textured sub-region and not necessarily the actual height.

void CYIAssetTextureBase::SetMinificationFilter ( YI_MIN_MAG_FILTER  minFilter = YI_LINEAR,
YI_MIN_MAG_FILTER  magFilter = YI_LINEAR 
)

Sets the rules for how the texture should be scaled. Magnification applies scaling to a texel when the size is caculated to be larger than a pixel. When a texel is calculated to be smaller than a pixel, the process is called minification. minFilter determines the rule to use for minifying the texture, and magFilter determines the rule to use for magnifying the texture. Both parameters default to YI_LINEAR.

See also
YI_LINEAR means that adjacent pixels will be bilinearly filtered.
YI_NEAREST means that the nearest pixel will be selected.
void CYIAssetTextureBase::SetMipmappingEnabled ( bool  bEnable)

Enables or disables the generation and usage of mipmaps. Mipmapping is disabled by default.

Mipmapping is a technique in graphics rendering that improves the quality of textures when they are displayed on screen at a size significantly smaller than their original resolution. The texture is internally duplicated multiple times at smaller and smaller resolutions until a texture size of 1x1 is reached. This causes the texture to use approximately 1/3 more space than the original texture. Non power-of-two textures may use significantly more memory. The GPU will then choose the texture with the size that is closest to what will be displayed on screen.

Mipmapping should be used on textures that look pixelated and jagged due to being drawn at a smaller size than the original texture.

This will adjust the minification filter setting internally to allow the use of the generated mipmaps.

Disabling mipmapping on a texture which is already loaded with mipmapping enabled will have no effect.

See also
SetMinificationFilter
void CYIAssetTextureBase::SetTextureWrap ( YI_TEXTURE_WRAP  wrapS = YI_CLAMP_TO_EDGE,
YI_TEXTURE_WRAP  wrapT = YI_CLAMP_TO_EDGE 
)

Sets the rules for how the texture coordinates should be wrapped if they extend past the bounds (< 0 or > 1). wrapS determines how to wrap on the s axis (horizontal axis), wrapT determines how to wrap on the t axis (vertical axis). Both parameters default to YI_CLAMP_TO_EDGE.

See also
YI_CLAMP_TO_EDGE will clamp to the last pixel value on the edge.
YI_REPEAT will result in tiling
YI_MIRROR will result in mirrored tiling
void CYIAssetTextureBase::SetWidth ( int32_t  nWidth)
protected

Sets the width of the textured region. In POT texture implmentations, this should be the width of the textured sub-region and not necessarily the actual width.


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