Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
Loading...
Searching...
No Matches
CTexture Class Referenceabstract

Texture loader class, subclasses of which depend on the render spec (DX, GL etc.) More...

#include <Texture.h>

Inheritance diagram for CTexture:
CTextureBase CDXTexture CGLESTexture CGLTexture

Public Member Functions

 CTexture (unsigned int width=0, unsigned int height=0, XB_FMT format=XB_FMT_A8R8G8B8)
 
virtual ~CTexture ()
 
bool LoadFromMemory (unsigned int width, unsigned int height, unsigned int pitch, XB_FMT format, bool hasAlpha, const unsigned char *pixels)
 
bool UploadFromMemory (unsigned int width, unsigned int height, unsigned int pitch, unsigned char *pixels, KD_TEX_FMT format=KD_TEX_FMT_SDR_RGBA8, KD_TEX_ALPHA alpha=KD_TEX_ALPHA_OPAQUE, KD_TEX_SWIZ swizzle=KD_TEX_SWIZ_RGBA)
 Attempts to upload a texture directly from a provided buffer Unlike LoadFromMemory() which copies the texture into an intermediate buffer, the texture gets uploaded directly to the GPU if circumstances allow.
 
bool LoadPaletted (unsigned int width, unsigned int height, unsigned int pitch, XB_FMT format, const unsigned char *pixels, const COLOR *palette)
 
void Update (unsigned int width, unsigned int height, unsigned int pitch, XB_FMT format, const unsigned char *pixels, bool loadToGPU)
 
void LoadToGPUAsync ()
 Uploads the texture to the GPU.
 
virtual void CreateTextureObject ()=0
 
virtual void DestroyTextureObject ()=0
 
virtual void LoadToGPU ()=0
 
virtual void SyncGPU ()
 Blocks execution until the previous GFX commands have been processed.
 
virtual void BindToUnit (unsigned int unit)=0
 
virtual bool SupportsFormat (KD_TEX_FMT textureFormat, KD_TEX_SWIZ textureSwizzle)
 Checks if the processing pipeline can handle the texture format/swizzle.
 
- Public Member Functions inherited from CTextureBase
 CTextureBase ()=default
 
 ~CTextureBase ()=default
 
bool HasAlpha () const
 
void SetAlpha (bool hasAlpha)
 
void SetMipmapping ()
 sets mipmapping. do not use in new code. will be replaced with proper scaling.
 
bool IsMipmapped () const
 return true if we want to mipmap
 
void SetScalingMethod (TEXTURE_SCALING scalingMethod)
 sets the scaling method. scanout systems might support more than NN/linear.
 
TEXTURE_SCALING GetScalingMethod () const
 returns the scaling method.
 
int32_t GetOrientation () const
 
void SetOrientation (int orientation)
 
void SetCacheMemory (bool bCacheMemory)
 retains a shadow copy of the texture on the CPU side.
 
bool GetCacheMemory () const
 returns true if a shadow copy is kept on the CPU side.
 
uint8_tGetPixels () const
 returns a pointer to the staging texture.
 
uint32_t GetPitch () const
 return the size of one row in bytes.
 
uint32_t GetRows () const
 return the number of rows (number of blocks in the Y direction).
 
uint32_t GetTextureWidth () const
 return the total width of the texture, which might be scaled to fit its displayed size.
 
uint32_t GetTextureHeight () const
 return the total height of the texture, which might be scaled to fit its displayed size.
 
uint32_t GetWidth () const
 return the total width of "active" area, which might be equal or lower than the texture width due to alignment.
 
uint32_t GetHeight () const
 return the total height of "active" area, which might be equal or lower than the texture height due to alignment.
 
uint32_t GetOriginalWidth () const
 return the original width of the image, before scaling/cropping
 
uint32_t GetOriginalHeight () const
 return the original height of the image, before scaling/cropping
 
KD_TEX_SWIZ GetSwizzle () const
 return the texture swizzle
 
void Allocate (uint32_t width, uint32_t height, XB_FMT format)
 
void ClampToEdge ()
 

Static Public Member Functions

static std::unique_ptr< CTextureCreateTexture (unsigned int width=0, unsigned int height=0, XB_FMT format=XB_FMT_A8R8G8B8)
 
static std::unique_ptr< CTextureLoadFromFile (const std::string &texturePath, unsigned int idealWidth=0, unsigned int idealHeight=0, CAspectRatio::AspectRatio aspectRatio=CAspectRatio::CENTER, const std::string &strMimeType="")
 Load a texture from a file Loads a texture from a file, restricting in size if needed based on maxHeight and maxWidth. Note that these are the ideal size to load at - the returned texture may be smaller or larger than these.
 
static std::unique_ptr< CTextureLoadFromFileInMemory (unsigned char *buffer, size_t bufferSize, const std::string &mimeType, unsigned int idealWidth=0, unsigned int idealHeight=0, CAspectRatio::AspectRatio aspectRatio=CAspectRatio::CENTER)
 Load a texture from a file in memory Loads a texture from a file in memory, restricting in size if needed based on maxHeight and maxWidth. Note that these are the ideal size to load at - the returned texture may be smaller or larger than these.
 
- Static Public Member Functions inherited from CTextureBase
static uint32_t PadPow2 (uint32_t x)
 rounds to power of two. deprecated.
 
static bool SwapBlueRed (uint8_t *pixels, uint32_t height, uint32_t pitch, uint32_t elements=4, uint32_t offset=0)
 swaps the blue/red channel. deprecated in this form.
 

Protected Member Functions

bool LoadFromFileInMem (unsigned char *buffer, size_t size, const std::string &mimeType, unsigned int idealWidth, unsigned int idealHeight, CAspectRatio::AspectRatio aspectRatio)
 
bool LoadFromFileInternal (const std::string &texturePath, unsigned int idealWidth, unsigned int idealHeight, CAspectRatio::AspectRatio aspectRatio, const std::string &strMimeType="")
 
bool LoadIImage (IImage *pImage, unsigned char *buffer, unsigned int bufSize, unsigned int idealWidth, unsigned int idealHeight, CAspectRatio::AspectRatio aspectRatio)
 
- Protected Member Functions inherited from CTextureBase
uint32_t GetPitch (uint32_t width) const
 
uint32_t GetRows (uint32_t height) const
 
uint32_t GetBlockWidth () const
 
uint32_t GetBlockHeight () const
 
uint32_t GetBlockSize () const
 return the size of a compression block (tile) in bytes.
 
void SetKDFormat (XB_FMT xbFMT)
 
bool ConvertToLegacy (uint32_t width, uint32_t height, uint8_t *src)
 Textures might be in a single/dual channel format with L/A/I/LA swizzle. DX and GLES 2.0 don't handle some/all at the moment. This function can convert the texture into a traditional BGRA format.
 

Additional Inherited Members

- Protected Attributes inherited from CTextureBase
uint32_t m_imageWidth {0}
 
uint32_t m_imageHeight {0}
 
uint32_t m_textureWidth {0}
 
uint32_t m_textureHeight {0}
 
uint32_t m_originalWidth {0}
 original image width before scaling or cropping
 
uint32_t m_originalHeight {0}
 original image height before scaling or cropping
 
uint8_tm_pixels {nullptr}
 
bool m_loadedToGPU {false}
 
KD_TEX_FMT m_textureFormat {KD_TEX_FMT_UNKNOWN}
 
KD_TEX_SWIZ m_textureSwizzle {KD_TEX_SWIZ_RGBA}
 
KD_TEX_COL m_textureColorspace {KD_TEX_COL_REC709}
 
KD_TEX_TRANSFER m_textureTransfer {KD_TEX_TRANSFER_SRGB}
 
KD_TEX_ALPHA m_textureAlpha {KD_TEX_ALPHA_STRAIGHT}
 
XB_FMT m_format {XB_FMT_UNKNOWN}
 
int32_t m_orientation {0}
 
bool m_mipmapping {false}
 
TEXTURE_SCALING m_scalingMethod {TEXTURE_SCALING::LINEAR}
 
bool m_bCacheMemory {false}
 

Detailed Description

Texture loader class, subclasses of which depend on the render spec (DX, GL etc.)

Constructor & Destructor Documentation

◆ CTexture()

CTexture::CTexture ( unsigned int width = 0,
unsigned int height = 0,
XB_FMT format = XB_FMT_A8R8G8B8 )

◆ ~CTexture()

CTexture::~CTexture ( )
virtual

Member Function Documentation

◆ BindToUnit()

virtual void CTexture::BindToUnit ( unsigned int unit)
pure virtual

Implemented in CDXTexture, CGLESTexture, and CGLTexture.

◆ CreateTexture()

std::unique_ptr< CTexture > CTexture::CreateTexture ( unsigned int width = 0,
unsigned int height = 0,
XB_FMT format = XB_FMT_A8R8G8B8 )
static

◆ CreateTextureObject()

virtual void CTexture::CreateTextureObject ( )
pure virtual

Implemented in CDXTexture, CGLESTexture, and CGLTexture.

◆ DestroyTextureObject()

virtual void CTexture::DestroyTextureObject ( )
pure virtual

Implemented in CDXTexture, CGLESTexture, and CGLTexture.

◆ LoadFromFile()

std::unique_ptr< CTexture > CTexture::LoadFromFile ( const std::string & texturePath,
unsigned int idealWidth = 0,
unsigned int idealHeight = 0,
CAspectRatio::AspectRatio aspectRatio = CAspectRatio::CENTER,
const std::string & strMimeType = "" )
static

Load a texture from a file Loads a texture from a file, restricting in size if needed based on maxHeight and maxWidth. Note that these are the ideal size to load at - the returned texture may be smaller or larger than these.

Parameters
texturePaththe path of the texture to load.
idealWidththe ideal width of the texture (defaults to 0, no ideal width).
idealHeightthe ideal height of the texture (defaults to 0, no ideal height).
aspectRatiothe aspect ratio mode of the texture (defaults to "center").
strMimeTypemimetype of the given texture if available (defaults to empty)
Returns
a CTexture std::unique_ptr to the created texture - nullptr if the texture failed to load.

◆ LoadFromFileInMem()

bool CTexture::LoadFromFileInMem ( unsigned char * buffer,
size_t size,
const std::string & mimeType,
unsigned int idealWidth,
unsigned int idealHeight,
CAspectRatio::AspectRatio aspectRatio )
protected

◆ LoadFromFileInMemory()

std::unique_ptr< CTexture > CTexture::LoadFromFileInMemory ( unsigned char * buffer,
size_t bufferSize,
const std::string & mimeType,
unsigned int idealWidth = 0,
unsigned int idealHeight = 0,
CAspectRatio::AspectRatio aspectRatio = CAspectRatio::CENTER )
static

Load a texture from a file in memory Loads a texture from a file in memory, restricting in size if needed based on maxHeight and maxWidth. Note that these are the ideal size to load at - the returned texture may be smaller or larger than these.

Parameters
bufferthe memory buffer holding the file.
bufferSizethe size of buffer.
mimeTypethe mime type of the file in buffer.
idealWidththe ideal width of the texture (defaults to 0, no ideal width).
idealHeightthe ideal height of the texture (defaults to 0, no ideal height).
aspectRatiothe aspect ratio mode of the texture (defaults to "center").
Returns
a CTexture std::unique_ptr to the created texture - nullptr if the texture failed to load.

◆ LoadFromFileInternal()

bool CTexture::LoadFromFileInternal ( const std::string & texturePath,
unsigned int idealWidth,
unsigned int idealHeight,
CAspectRatio::AspectRatio aspectRatio,
const std::string & strMimeType = "" )
protected

◆ LoadFromMemory()

bool CTexture::LoadFromMemory ( unsigned int width,
unsigned int height,
unsigned int pitch,
XB_FMT format,
bool hasAlpha,
const unsigned char * pixels )

◆ LoadIImage()

bool CTexture::LoadIImage ( IImage * pImage,
unsigned char * buffer,
unsigned int bufSize,
unsigned int idealWidth,
unsigned int idealHeight,
CAspectRatio::AspectRatio aspectRatio )
protected

◆ LoadPaletted()

bool CTexture::LoadPaletted ( unsigned int width,
unsigned int height,
unsigned int pitch,
XB_FMT format,
const unsigned char * pixels,
const COLOR * palette )

◆ LoadToGPU()

virtual void CTexture::LoadToGPU ( )
pure virtual

Implemented in CDXTexture, CGLESTexture, and CGLTexture.

◆ LoadToGPUAsync()

void CTexture::LoadToGPUAsync ( )

Uploads the texture to the GPU.

◆ SupportsFormat()

virtual bool CTexture::SupportsFormat ( KD_TEX_FMT textureFormat,
KD_TEX_SWIZ textureSwizzle )
inlinevirtual

Checks if the processing pipeline can handle the texture format/swizzle.

Parameters
formatthe format of the texture.
Returns
true if the texturing pipeline supports the format

Reimplemented in CGLESTexture, and CGLTexture.

◆ SyncGPU()

virtual void CTexture::SyncGPU ( )
inlinevirtual

Blocks execution until the previous GFX commands have been processed.

Reimplemented in CGLTexture.

◆ Update()

void CTexture::Update ( unsigned int width,
unsigned int height,
unsigned int pitch,
XB_FMT format,
const unsigned char * pixels,
bool loadToGPU )

◆ UploadFromMemory()

bool CTexture::UploadFromMemory ( unsigned int width,
unsigned int height,
unsigned int pitch,
unsigned char * pixels,
KD_TEX_FMT format = KD_TEX_FMT_SDR_RGBA8,
KD_TEX_ALPHA alpha = KD_TEX_ALPHA_OPAQUE,
KD_TEX_SWIZ swizzle = KD_TEX_SWIZ_RGBA )

Attempts to upload a texture directly from a provided buffer Unlike LoadFromMemory() which copies the texture into an intermediate buffer, the texture gets uploaded directly to the GPU if circumstances allow.

Parameters
widththe width of the texture.
heightthe height of the texture.
pitchthe pitch of the texture.
pixelspointer to the texture buffer.
formatthe format of the texture.
alphathe alpha type of the texture.
swizzlethe swizzle pattern of the texture.

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