MetalCompute 1.0
An API to make GPU compute calls easier
Loading...
Searching...
No Matches
MTLCompute::Texture< T > Class Template Reference

#include <MTLComputeTexture.hpp>

Public Member Functions

 Texture (MTL::Device *gpu, int width, int height, TextureType tt)
 Constructor for the Texture class.
 
 Texture (MTL::Device *gpu, int width, int height)
 Constructor for the Texture class.
 
 Texture (const Texture &other)
 Copy constructor for the Texture class.
 
 Texture ()
 Default constructor for the Texture class.
 
 ~Texture ()
 Destructor for the Texture class.
 
void operator= (std::vector< std::vector< T > > data)
 Overload the = operator to set texture contents from a vector.
 
Textureoperator= (const Texture &other)
 Overload the = operator to set texture contents from another texture.
 
std::vector< T > operator[] (size_t index) const
 Overload the [] operator to get a row from the texture.
 
std::vector< std::vector< T > > getData ()
 Get the data from the texture as a vector.
 
MTL::Texture * getTexture ()
 Get the MTL::Texture object.
 
MTL::Device * getGPU ()
 Get the GPU device.
 
bool getFreed ()
 Get whether the texture has been freed.
 
MTL::TextureDescriptor * getDescriptor ()
 Get the texture descriptor.
 
int getWidth ()
 Get the width of the texture.
 
int getHeight ()
 Get the height of the texture.
 

Private Member Functions

void swap (Texture &tex) noexcept
 Swap the contents of two Textures.
 
std::vector< T > flatten (std::vector< std::vector< T > > &v) const
 Flatten a 2D vector into a 1D vector.
 
std::vector< std::vector< T > > unflatten (std::vector< T > &v, int width, int height) const
 Unflatten a 1D vector into a 2D vector.
 

Private Attributes

MTL::Device * gpu
 The Metal device object.
 
MTL::Texture * texture
 The Metal texture object.
 
MTL::TextureDescriptor * descriptor
 The Metal texture descriptor object.
 
int width = -1
 The width and height of the texture.
 
int height = -1
 The width and height of the texture.
 
bool freed = false
 Whether the texture has been freed.
 

Constructor & Destructor Documentation

◆ Texture() [1/4]

template<typename T >
MTLCompute::Texture< T >::Texture ( MTL::Device * gpu,
int width,
int height,
TextureType tt )
inline

Constructor for the Texture class.

Constructs a new texture object

Parameters
gpuThe Metal device object
widthThe width of the texture
heightThe height of the texture
ttThe texture type

◆ Texture() [2/4]

template<typename T >
MTLCompute::Texture< T >::Texture ( MTL::Device * gpu,
int width,
int height )
inline

Constructor for the Texture class.

Constructs a new texture object and tries to infer the texture type

Parameters
gpuThe Metal device object
widthThe width of the texture
heightThe height of the texture

◆ Texture() [3/4]

template<typename T >
MTLCompute::Texture< T >::Texture ( const Texture< T > & other)
inline

Copy constructor for the Texture class.

Constructs a new texture from an existing texture

Parameters
otherThe texture to copy

◆ Texture() [4/4]

template<typename T >
MTLCompute::Texture< T >::Texture ( )
inline

Default constructor for the Texture class.

Creates a new empty texture object

◆ ~Texture()

template<typename T >
MTLCompute::Texture< T >::~Texture ( )
inline

Destructor for the Texture class.

Calls autorelease on the texture and descriptor objects and sets the freed flag to true

Member Function Documentation

◆ flatten()

template<typename T >
std::vector< T > MTLCompute::Texture< T >::flatten ( std::vector< std::vector< T > > & v) const
inlineprivate

Flatten a 2D vector into a 1D vector.

Parameters
vThe 2D vector to flatten
Returns
std::vector<T> The flattened vector

◆ getData()

template<typename T >
std::vector< std::vector< T > > MTLCompute::Texture< T >::getData ( )
inline

Get the data from the texture as a vector.

Returns
std::vector<std::vector<T>> The data from the texture

◆ getDescriptor()

template<typename T >
MTL::TextureDescriptor * MTLCompute::Texture< T >::getDescriptor ( )
inline

Get the texture descriptor.

Returns
MTL::TextureDescriptor* The texture descriptor

◆ getFreed()

template<typename T >
bool MTLCompute::Texture< T >::getFreed ( )
inline

Get whether the texture has been freed.

Returns
bool Whether the texture has been freed

◆ getGPU()

template<typename T >
MTL::Device * MTLCompute::Texture< T >::getGPU ( )
inline

Get the GPU device.

Returns
MTL::Device* The GPU device

◆ getHeight()

template<typename T >
int MTLCompute::Texture< T >::getHeight ( )
inline

Get the height of the texture.

Returns
int The height of the texture

◆ getTexture()

template<typename T >
MTL::Texture * MTLCompute::Texture< T >::getTexture ( )
inline

Get the MTL::Texture object.

Returns
MTL::Texture* The MTL::Texture object

◆ getWidth()

template<typename T >
int MTLCompute::Texture< T >::getWidth ( )
inline

Get the width of the texture.

Returns
int The width of the texture

◆ operator=() [1/2]

template<typename T >
Texture & MTLCompute::Texture< T >::operator= ( const Texture< T > & other)
inline

Overload the = operator to set texture contents from another texture.

Parameters
otherThe texture to set the contents from

◆ operator=() [2/2]

template<typename T >
void MTLCompute::Texture< T >::operator= ( std::vector< std::vector< T > > data)
inline

Overload the = operator to set texture contents from a vector.

Parameters
dataThe data to set the texture contents to

◆ operator[]()

template<typename T >
std::vector< T > MTLCompute::Texture< T >::operator[] ( size_t index) const
inline

Overload the [] operator to get a row from the texture.

Parameters
indexThe index of the row to get
Returns
std::vector<T> The row from the texture

◆ swap()

template<typename T >
void MTLCompute::Texture< T >::swap ( Texture< T > & tex)
inlineprivatenoexcept

Swap the contents of two Textures.

Parameters
bufThe texture to swap with

◆ unflatten()

template<typename T >
std::vector< std::vector< T > > MTLCompute::Texture< T >::unflatten ( std::vector< T > & v,
int width,
int height ) const
inlineprivate

Unflatten a 1D vector into a 2D vector.

Parameters
vThe 1D vector to unflatten
widthThe width of the 2D vector
heightThe height of the 2D vector
Returns
std::vector<std::vector<T>> The unflattened vector

Member Data Documentation

◆ descriptor

template<typename T >
MTL::TextureDescriptor* MTLCompute::Texture< T >::descriptor
private

The Metal texture descriptor object.

◆ freed

template<typename T >
bool MTLCompute::Texture< T >::freed = false
private

Whether the texture has been freed.

◆ gpu

template<typename T >
MTL::Device* MTLCompute::Texture< T >::gpu
private

The Metal device object.

◆ height

template<typename T >
int MTLCompute::Texture< T >::height = -1
private

The width and height of the texture.

◆ texture

template<typename T >
MTL::Texture* MTLCompute::Texture< T >::texture
private

The Metal texture object.

◆ width

template<typename T >
int MTLCompute::Texture< T >::width = -1
private

The width and height of the texture.


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