NAP
Public Member Functions | Public Attributes | Protected Attributes | List of all members
Texture2D Class Reference

#include <texture2d.h>

Public Member Functions

 Texture2D (Core &core)
 
 ~Texture2D () override
 
bool init (const SurfaceDescriptor &descriptor, bool generateMipMaps, const glm::vec4 &clearColor, VkImageUsageFlags requiredFlags, utility::ErrorState &errorState)
 
bool init (const SurfaceDescriptor &descriptor, bool generateMipMaps, VkImageUsageFlags requiredFlags, utility::ErrorState &errorState)
 
bool init (const SurfaceDescriptor &descriptor, bool generateMipMaps, void *initialData, VkImageUsageFlags requiredFlags, utility::ErrorState &errorState)
 
const glm::vec2 getSize () const
 
int getWidth () const
 
int getHeight () const
 
const SurfaceDescriptorgetDescriptor () const
 
void update (const void *data, int width, int height, int pitch, ESurfaceChannels channels)
 
void update (const void *data, const SurfaceDescriptor &surfaceDescriptor)
 
VkFormat getFormat () const
 
const ImageDatagetHandle () const
 
int getMipmapCount ()
 
RenderServicegetRenderService ()
 
const RenderServicegetRenderService () const
 
void asyncGetData (Bitmap &bitmap)
 
void asyncGetData (std::function< void(const void *, size_t)> copyFunction)
 
VkImageView getImageView () const
 
- Public Member Functions inherited from Resource
 Resource ()
 
- Public Member Functions inherited from Object
 Object ()
 
virtual ~Object ()
 
virtual bool init (utility::ErrorState &errorState)
 
virtual void onDestroy ()
 
 Object (Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object &&)=delete
 
Objectoperator= (Object &&)=delete
 

Public Attributes

ETextureUsage mUsage = ETextureUsage::Static
 Property: 'Usage' If this texture is updated frequently or considered static. More...
 
- Public Attributes inherited from Object
std::string mID
 Property: 'mID' unique name of the object. Used as an identifier by the system. More...
 

Protected Attributes

RenderServicemRenderService = nullptr
 

Additional Inherited Members

- Static Public Member Functions inherited from Object
static bool isIDProperty (rtti::Instance &object, const rtti::Property &property)
 

Description

GPU representation of a 2D image. This class does not own any CPU data. It offers the user an interface to upload & download texture data, from and to a bitmap. When usage is set to 'Static' (default) or 'DynamicRead' data can be uploaded only once. When usage is set to 'DynamicWrite' the texture be updated frequently from CPU to GPU.

Inheritance diagram for Texture2D:
[legend]
Collaboration diagram for Texture2D:
[legend]

Constructor & Destructor Documentation

◆ Texture2D()

Texture2D ( Core core)

◆ ~Texture2D()

~Texture2D ( )
override

Member Function Documentation

◆ asyncGetData() [1/2]

void asyncGetData ( Bitmap bitmap)

Starts a transfer of texture data from GPU to CPU. This is a non blocking call. When the transfer completes, the bitmap will be filled with the texture data.

Parameters
bitmapthe bitmap to download texture data into.

◆ asyncGetData() [2/2]

void asyncGetData ( std::function< void(const void *, size_t)>  copyFunction)

Starts a transfer of texture data from GPU to CPU. Use this overload to pass your own copy function. This is a non blocking call. When the transfer completes, the bitmap will be filled with the texture data.

Parameters
copyFunctionthe copy function to call when the texture data is available for download.

◆ getDescriptor()

const SurfaceDescriptor& getDescriptor ( ) const
Returns
the texture description

◆ getFormat()

VkFormat getFormat ( ) const
Returns
Vulkan texture format

◆ getHandle()

const ImageData& getHandle ( ) const
Returns
Vulkan GPU data handle, including image and view.

◆ getHeight()

int getHeight ( ) const
Returns
height of the texture in texels

◆ getImageView()

VkImageView getImageView ( ) const
Returns
Handle to Vulkan image view

◆ getMipmapCount()

int getMipmapCount ( )
Returns
number of mip-map levels

◆ getRenderService() [1/2]

RenderService& getRenderService ( )
Returns
render service

◆ getRenderService() [2/2]

const RenderService& getRenderService ( ) const
Returns
render service

◆ getSize()

const glm::vec2 getSize ( ) const
Returns
size of the texture in texels.

◆ getWidth()

int getWidth ( ) const
Returns
width of the texture in texels

◆ init() [1/3]

bool init ( const SurfaceDescriptor descriptor,
bool  generateMipMaps,
const glm::vec4 &  clearColor,
VkImageUsageFlags  requiredFlags,
utility::ErrorState errorState 
)

Creates the texture on the GPU using the provided settings. The texture is cleared to 'ClearColor'. The Vulkan image usage flags are derived from texture usage.

Parameters
descriptortexture description.
generateMipMapsif mip maps are generated when data is uploaded.
clearColorthe color to clear the texture with.
requiredFlagsimage usage flags that are required, 0 = no additional usage flags.
errorStatecontains the error if the texture can't be initialized.
Returns
if the texture initialized successfully.

◆ init() [2/3]

bool init ( const SurfaceDescriptor descriptor,
bool  generateMipMaps,
VkImageUsageFlags  requiredFlags,
utility::ErrorState errorState 
)

Creates the texture on the GPU using the provided settings. The texture is cleared to 'ClearColor'. Otherwise the layout of the texture on the GPU will be undefined until upload. The Vulkan image usage flags are derived from texture usage.

Parameters
descriptortexture description.
generateMipMapsif mip maps are generated when data is uploaded.
requiredFlagsimage usage flags that are required, 0 = no additional usage flags.
errorStatecontains the error if the texture can't be initialized.
Returns
if the texture initialized successfully.

◆ init() [3/3]

bool init ( const SurfaceDescriptor descriptor,
bool  generateMipMaps,
void *  initialData,
VkImageUsageFlags  requiredFlags,
utility::ErrorState errorState 
)

Creates the texture on the GPU using the provided settings and immediately requests a content upload. The Vulkan image usage flags are derived from texture usage.

Parameters
descriptortexture description.
generateMipMapsif mip maps are generated when data is uploaded.
initialDatathe data to upload, must be of size SurfaceDescriptor::getSizeInBytes().
requiredFlagsimage usage flags that are required, 0 = no additional usage flags
errorStatecontains the error if the texture can't be initialized.
Returns
if the texture initialized successfully.

◆ update() [1/2]

void update ( const void *  data,
const SurfaceDescriptor surfaceDescriptor 
)

Uploads CPU data to the texture on the GPU. Note that you can only update the contents of a texture once if 'Usage' is 'DynamicRead' or 'Static'.

Parameters
datapointer to the CPU data.
surfaceDescriptortexture description.

◆ update() [2/2]

void update ( const void *  data,
int  width,
int  height,
int  pitch,
ESurfaceChannels  channels 
)

Uploads CPU data to the texture on the GPU. Note that you can only update the contents of a texture once if 'Usage' is 'DynamicRead' or 'Static'.

Parameters
datapointer to the CPU data.
widthwidth of the image in pixels
heightheight of the image in pixels
pitchsize in bytes of a single row of pixel data.
channelstotal number of channels: 3 for RGB, 4 for RGBA etc.

Member Data Documentation

◆ mRenderService

RenderService* mRenderService = nullptr
protected

◆ mUsage

Property: 'Usage' If this texture is updated frequently or considered static.