Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
Divide::Texture Class Referenceabstract

An API-independent representation of a texture. More...

#include <Texture.h>

+ Inheritance diagram for Divide::Texture:

Public Member Functions

 Texture (PlatformContext &context, const ResourceDescriptor< Texture > &descriptor)
 
virtual ~Texture () override
 
void createWithData (const ImageTools::ImageData &imageData, const PixelAlignment &pixelUnpackAlignment)
 API-dependent loading function that uploads ptr data to the GPU using the specified parameters.
 
void createWithData (const Byte *data, size_t dataSize, const vec2< U16 > &dimensions, const PixelAlignment &pixelUnpackAlignment)
 
void createWithData (const Byte *data, size_t dataSize, const vec3< U16 > &dimensions, const PixelAlignment &pixelUnpackAlignment)
 
void replaceData (const Byte *data, size_t dataSize, const vec3< U16 > &offset, const vec3< U16 > &range, const PixelAlignment &pixelUnpackAlignment)
 
void setSampleCount (U8 newSampleCount)
 Change the number of MSAA samples for this current texture.
 
ImageView getView () const noexcept
 
ImageView getView (TextureType targetType) const noexcept
 
ImageView getView (SubRange mipRange) const noexcept
 
ImageView getView (SubRange mipRange, SubRange layerRange) const noexcept
 
ImageView getView (TextureType targetType, SubRange mipRange) const noexcept
 
ImageView getView (TextureType targetType, SubRange mipRange, SubRange layerRange) const noexcept
 
virtual ImageReadbackData readData (U8 mipLevel, const PixelAlignment &pixelPackAlignment) const =0
 
 PROPERTY_R (TextureDescriptor, descriptor)
 
 PROPERTY_R (U16, mipCount, 1u)
 Get the number of mips.
 
 PROPERTY_R (U16, width, 0u)
 Texture width as returned by STB/DDS loader.
 
 PROPERTY_R (U16, height, 0u)
 Texture height as returned by STB/DDS loader.
 
 PROPERTY_R (U16, depth, 1u)
 Depth for TEXTURE_3D, layer count for TEXTURE_1/2D/CUBE_ARRAY. For cube arrays, numSlices = depth * 6u.
 
 PROPERTY_R (bool, hasTranslucency, false)
 If the texture has an alpha channel and at least one pixel is translucent, return true.
 
 PROPERTY_R (bool, hasTransparency, false)
 If the texture has an alpha channel and at least on pixel is fully transparent and no pixels are partially transparent, return true.
 
 PROPERTY_R (bool, loadedFromFile, false)
 
U8 numChannels () const noexcept
 
bool load (PlatformContext &context) override
 Loading and unloading interface.
 
bool postLoad () override
 
- Public Member Functions inherited from Divide::CachedResource
 CachedResource (const ResourceDescriptorBase &descriptor, std::string_view typeName)
 
virtual bool load (PlatformContext &context)
 Loading and unloading interface.
 
virtual bool postLoad ()
 
virtual bool unload ()
 
void setState (ResourceState currentState) final
 
- Public Member Functions inherited from Divide::Resource
 Resource (std::string_view resourceName, std::string_view typeName)
 
ResourceState getState () const noexcept
 
 PROPERTY_R (Str< 32 >, typeName)
 
 PROPERTY_R (Str< 256 >, resourceName)
 
- Public Member Functions inherited from Divide::GUIDWrapper
 GUIDWrapper () noexcept
 
 GUIDWrapper (const GUIDWrapper &old) noexcept
 
 GUIDWrapper (GUIDWrapper &&old) noexcept
 
virtual ~GUIDWrapper ()=default
 
FORCE_INLINE I64 getGUID () const noexcept
 
GUIDWrapperoperator= (const GUIDWrapper &old)=delete
 
GUIDWrapperoperator= (GUIDWrapper &&other)=delete
 
- Public Member Functions inherited from Divide::GraphicsResource
virtual ~GraphicsResource ()
 
GFXDevicecontext () const noexcept
 
U64 nameHash () const noexcept
 
- Public Member Functions inherited from Divide::NonCopyable
 NonCopyable (const NonCopyable &)=delete
 
NonCopyableoperator= (const NonCopyable &)=delete
 
 NonCopyable (NonCopyable &&)=default
 
NonCopyableoperator= (NonCopyable &&)=default
 
- Public Member Functions inherited from Divide::NonMovable
 NonMovable (NonMovable &&)=delete
 
NonMovableoperator= (NonMovable &&)=delete
 
 NonMovable (const NonMovable &)=default
 
NonMovableoperator= (const NonMovable &)=default
 

Static Public Member Functions

static void OnStartup (GFXDevice &gfx)
 
static void OnShutdown () noexcept
 
static bool UseTextureDDSCache () noexcept
 
static Handle< TextureDefaultTexture2D () noexcept
 
static Handle< TextureDefaultTexture2DArray () noexcept
 
static const SamplerDescriptor DefaultSampler () noexcept
 
static U8 GetBytesPerPixel (GFXDataFormat format, GFXImageFormat baseFormat, GFXImagePacking packing) noexcept
 
- Static Public Member Functions inherited from Divide::GUIDWrapper
static I64 generateGUID () noexcept
 

Protected Member Functions

bool loadFile (const ResourcePath &path, std::string_view name, ImageTools::ImageData &fileData)
 Use STB to load a file into a Texture Object.
 
bool checkTransparency (const ResourcePath &path, std::string_view name, ImageTools::ImageData &fileData)
 
bool loadInternal ()
 Load texture data using the specified file name.
 
void validateDescriptor ()
 
virtual void loadDataInternal (const ImageTools::ImageData &imageData, const vec3< U16 > &offset, const PixelAlignment &pixelUnpackAlignment)=0
 
virtual void loadDataInternal (const Byte *data, size_t size, U8 targetMip, const vec3< U16 > &offset, const vec3< U16 > &dimensions, const PixelAlignment &pixelUnpackAlignment)=0
 
virtual void prepareTextureData (U16 width, U16 height, U16 depth, bool emptyAllocation)
 
virtual void submitTextureData ()
 
- Protected Member Functions inherited from Divide::CachedResource
 PROPERTY_RW (ResourcePath, assetLocation)
 
 PROPERTY_RW (Str< 256 >, assetName)
 
 PROPERTY_R (size_t, descriptorHash)
 
virtual void setState (ResourceState currentState)
 
- Protected Member Functions inherited from Divide::GraphicsResource
 GraphicsResource (GFXDevice &context, Type type, I64 GUID, U64 nameHash)
 
- Protected Member Functions inherited from Divide::NonCopyable
 NonCopyable ()=default
 
 ~NonCopyable ()=default
 
- Protected Member Functions inherited from Divide::NonMovable
 NonMovable ()=default
 
 ~NonMovable ()=default
 

Static Protected Attributes

static bool s_useDDSCache = true
 
static SamplerDescriptor s_defaultSampler
 
static Handle< Textures_defaultTexture2D = INVALID_HANDLE<Texture>
 
static Handle< Textures_defaultTexture2DArray = INVALID_HANDLE<Texture>
 
static Str< 64 > s_missingTextureFileName
 

Friends

class ResourceCache
 
struct ResourceLoader
 
template<typename T >
class ImplResourceLoader
 
class Attorney::TextureKernel
 

Additional Inherited Members

- Public Types inherited from Divide::GraphicsResource
enum class  Type : U8 {
  RENDER_TARGET , SHADER_BUFFER , BUFFER , SHADER ,
  SHADER_PROGRAM , TEXTURE , COUNT
}
 
- Protected Attributes inherited from Divide::CachedResource
Mutex _callbackLock {}
 
- Protected Attributes inherited from Divide::Resource
std::atomic< ResourceState_resourceState
 
- Protected Attributes inherited from Divide::GUIDWrapper
const I64 _guid
 
- Protected Attributes inherited from Divide::GraphicsResource
GFXDevice_context
 

Detailed Description

An API-independent representation of a texture.

Definition at line 82 of file Texture.h.

Constructor & Destructor Documentation

◆ Texture()

Texture::Texture ( PlatformContext context,
const ResourceDescriptor< Texture > &  descriptor 
)
explicit

Definition at line 128 of file Texture.cpp.

◆ ~Texture()

Texture::~Texture ( )
overridevirtual

Definition at line 194 of file Texture.cpp.

Member Function Documentation

◆ checkTransparency()

bool Texture::checkTransparency ( const ResourcePath path,
std::string_view  name,
ImageTools::ImageData fileData 
)
protected

Definition at line 422 of file Texture.cpp.

◆ createWithData() [1/3]

void Texture::createWithData ( const Byte data,
size_t  dataSize,
const vec2< U16 > &  dimensions,
const PixelAlignment pixelUnpackAlignment 
)

Definition at line 334 of file Texture.cpp.

◆ createWithData() [2/3]

void Texture::createWithData ( const Byte data,
size_t  dataSize,
const vec3< U16 > &  dimensions,
const PixelAlignment pixelUnpackAlignment 
)

Definition at line 344 of file Texture.cpp.

◆ createWithData() [3/3]

void Texture::createWithData ( const ImageTools::ImageData imageData,
const PixelAlignment pixelUnpackAlignment 
)

API-dependent loading function that uploads ptr data to the GPU using the specified parameters.

Definition at line 394 of file Texture.cpp.

◆ DefaultSampler()

const SamplerDescriptor Texture::DefaultSampler ( )
staticnoexcept

Definition at line 100 of file Texture.cpp.

◆ DefaultTexture2D()

Handle< Texture > Texture::DefaultTexture2D ( )
staticnoexcept

Definition at line 90 of file Texture.cpp.

◆ DefaultTexture2DArray()

Handle< Texture > Texture::DefaultTexture2DArray ( )
staticnoexcept

Definition at line 95 of file Texture.cpp.

◆ GetBytesPerPixel()

U8 Texture::GetBytesPerPixel ( GFXDataFormat  format,
GFXImageFormat  baseFormat,
GFXImagePacking  packing 
)
staticnoexcept

Definition at line 105 of file Texture.cpp.

◆ getView() [1/6]

ImageView Texture::getView ( ) const
noexcept

Definition at line 597 of file Texture.cpp.

◆ getView() [2/6]

ImageView Texture::getView ( SubRange  mipRange) const
noexcept

Definition at line 620 of file Texture.cpp.

◆ getView() [3/6]

ImageView Texture::getView ( SubRange  mipRange,
SubRange  layerRange 
) const
noexcept

Definition at line 627 of file Texture.cpp.

◆ getView() [4/6]

ImageView Texture::getView ( TextureType  targetType) const
noexcept

Definition at line 613 of file Texture.cpp.

◆ getView() [5/6]

ImageView Texture::getView ( TextureType  targetType,
SubRange  mipRange 
) const
noexcept

Definition at line 634 of file Texture.cpp.

◆ getView() [6/6]

ImageView Texture::getView ( TextureType  targetType,
SubRange  mipRange,
SubRange  layerRange 
) const
noexcept

Definition at line 641 of file Texture.cpp.

◆ load()

bool Texture::load ( PlatformContext context)
overridevirtual

Loading and unloading interface.

Reimplemented from Divide::CachedResource.

Definition at line 198 of file Texture.cpp.

◆ loadDataInternal() [1/2]

virtual void Divide::Texture::loadDataInternal ( const Byte data,
size_t  size,
U8  targetMip,
const vec3< U16 > &  offset,
const vec3< U16 > &  dimensions,
const PixelAlignment pixelUnpackAlignment 
)
protectedpure virtual

◆ loadDataInternal() [2/2]

virtual void Divide::Texture::loadDataInternal ( const ImageTools::ImageData imageData,
const vec3< U16 > &  offset,
const PixelAlignment pixelUnpackAlignment 
)
protectedpure virtual

◆ loadFile()

bool Texture::loadFile ( const ResourcePath path,
std::string_view  name,
ImageTools::ImageData fileData 
)
protected

Use STB to load a file into a Texture Object.

Definition at line 296 of file Texture.cpp.

◆ loadInternal()

bool Texture::loadInternal ( )
protected

Load texture data using the specified file name.

Definition at line 218 of file Texture.cpp.

◆ numChannels()

U8 Texture::numChannels ( ) const
noexcept

Definition at line 282 of file Texture.cpp.

◆ OnShutdown()

void Texture::OnShutdown ( )
staticnoexcept

Definition at line 78 of file Texture.cpp.

◆ OnStartup()

void Texture::OnStartup ( GFXDevice gfx)
static

Definition at line 41 of file Texture.cpp.

◆ postLoad()

bool Texture::postLoad ( )
overridevirtual

Reimplemented from Divide::CachedResource.

Definition at line 212 of file Texture.cpp.

◆ prepareTextureData()

void Texture::prepareTextureData ( U16  width,
U16  height,
U16  depth,
bool  emptyAllocation 
)
protectedvirtual

Reimplemented in Divide::glTexture, and Divide::vkTexture.

Definition at line 324 of file Texture.cpp.

◆ PROPERTY_R() [1/8]

Divide::Texture::PROPERTY_R ( bool  ,
hasTranslucency  ,
false   
)

If the texture has an alpha channel and at least one pixel is translucent, return true.

◆ PROPERTY_R() [2/8]

Divide::Texture::PROPERTY_R ( bool  ,
hasTransparency  ,
false   
)

If the texture has an alpha channel and at least on pixel is fully transparent and no pixels are partially transparent, return true.

◆ PROPERTY_R() [3/8]

Divide::Texture::PROPERTY_R ( bool  ,
loadedFromFile  ,
false   
)

◆ PROPERTY_R() [4/8]

Divide::Texture::PROPERTY_R ( TextureDescriptor  ,
descriptor   
)

◆ PROPERTY_R() [5/8]

Divide::Texture::PROPERTY_R ( U16  ,
depth  ,
1u   
)

Depth for TEXTURE_3D, layer count for TEXTURE_1/2D/CUBE_ARRAY. For cube arrays, numSlices = depth * 6u.

◆ PROPERTY_R() [6/8]

Divide::Texture::PROPERTY_R ( U16  ,
height  ,
0u   
)

Texture height as returned by STB/DDS loader.

◆ PROPERTY_R() [7/8]

Divide::Texture::PROPERTY_R ( U16  ,
mipCount  ,
1u   
)

Get the number of mips.

◆ PROPERTY_R() [8/8]

Divide::Texture::PROPERTY_R ( U16  ,
width  ,
0u   
)

Texture width as returned by STB/DDS loader.

◆ readData()

virtual ImageReadbackData Divide::Texture::readData ( U8  mipLevel,
const PixelAlignment pixelPackAlignment 
) const
pure virtual

◆ replaceData()

void Texture::replaceData ( const Byte data,
size_t  dataSize,
const vec3< U16 > &  offset,
const vec3< U16 > &  range,
const PixelAlignment pixelUnpackAlignment 
)

Definition at line 371 of file Texture.cpp.

◆ setSampleCount()

void Texture::setSampleCount ( U8  newSampleCount)

Change the number of MSAA samples for this current texture.

Definition at line 531 of file Texture.cpp.

◆ submitTextureData()

void Texture::submitTextureData ( )
protectedvirtual

Reimplemented in Divide::glTexture.

Definition at line 339 of file Texture.cpp.

◆ UseTextureDDSCache()

bool Texture::UseTextureDDSCache ( )
staticnoexcept

Definition at line 85 of file Texture.cpp.

◆ validateDescriptor()

void Texture::validateDescriptor ( )
protected

Definition at line 541 of file Texture.cpp.

Friends And Related Function Documentation

◆ Attorney::TextureKernel

friend class Attorney::TextureKernel
friend

Definition at line 88 of file Texture.h.

◆ ImplResourceLoader

template<typename T >
friend class ImplResourceLoader
friend

Definition at line 87 of file Texture.h.

◆ ResourceCache

friend class ResourceCache
friend

Definition at line 84 of file Texture.h.

◆ ResourceLoader

friend struct ResourceLoader
friend

Definition at line 85 of file Texture.h.

Member Data Documentation

◆ s_defaultSampler

SamplerDescriptor Texture::s_defaultSampler
staticprotected

Definition at line 156 of file Texture.h.

◆ s_defaultTexture2D

Handle< Texture > Texture::s_defaultTexture2D = INVALID_HANDLE<Texture>
staticprotected

Definition at line 157 of file Texture.h.

◆ s_defaultTexture2DArray

Handle< Texture > Texture::s_defaultTexture2DArray = INVALID_HANDLE<Texture>
staticprotected

Definition at line 158 of file Texture.h.

◆ s_missingTextureFileName

Str< 64 > Texture::s_missingTextureFileName
staticprotected

Definition at line 159 of file Texture.h.

◆ s_useDDSCache

bool Texture::s_useDDSCache = true
staticprotected

Definition at line 155 of file Texture.h.


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