Support Forum       G3D Web Page     
Public Member Functions | List of all members
G3D::BindlessTextureHandle Class Reference


A wrapper for bindless texture handles, as introduced by https://www.opengl.org/registry/specs/ARB/bindless_texture.txt Only use this class if your OpenGL context supports ARB_bindless_texture. More...

Public Member Functions

 BindlessTextureHandle ()
 
 BindlessTextureHandle (shared_ptr< Texture > tex, const Sampler &sampler)
 Construct and call set() More...
 
 ~BindlessTextureHandle ()
 
uint64 glHandle () const
 The underlying bindless texture handle. More...
 
bool isResident () const
 
bool isValid () const
 Is the underlying texture handle valid? More...
 
void makeNonResident ()
 Does nothing if the handle is invalid or already non resident. More...
 
void makeResident ()
 Raises an assertion if the texture handle is invalid, and does nothing if the handle is already resident. More...
 
void set (shared_ptr< Texture > tex, const Sampler &sampler)
 If this object is already valid, make sure the handle is non-resident and then create a new handle from the specified texture and sampler. More...
 
shared_ptr< Texturetexture () const
 

Detailed Description


A wrapper for bindless texture handles, as introduced by https://www.opengl.org/registry/specs/ARB/bindless_texture.txt Only use this class if your OpenGL context supports ARB_bindless_texture.

We keep a shared_ptr to the texture and sampler objects that were used to create the underlying handle, so that it is valid until the destructor is run or set() is called again.

Common use:

Array<uint64> rawHandles; for (int i = 0; i < arrayOfRelevantTextures; ++i) { bindlessHandles.append(BindlessTextureHandle(arrayOfRelevantTextures[i], Sampler::defaults())); rawHandles.append(bindlessHandles.last().glHandle()); } shared_ptr<CPUPixelTransferBuffer> ptb = CPUPixelTransferBuffer::fromData(rawHandles.size(), 1, ImageFormat::RG32UI(), rawHandles.getCArray()); m_indirectionTexture = Texture::fromPixelTransferBuffer("Indirection Texture", ptb);

... later, in a shader with the indirection texture bound ...

sampler2D myTexture = sampler2D(texelFetch(indirectionTexture, ivec2(index, 0), 0).rg); Use myTexture as you would any other sampler2D ...

    It is up to the user to make sure this object does not go out of scope until the last use of the underlying GL handle.

    As of 7/12/2015, supported on most recent AMD and NVIDIA cards, but none of Intel's hardware.

     We expect to soon add support for bindless image handles; perhaps by augmenting this class, perhaps by a separate BindlessImageHandle.

Constructor & Destructor Documentation

◆ BindlessTextureHandle() [1/2]

G3D::BindlessTextureHandle::BindlessTextureHandle ( )

◆ ~BindlessTextureHandle()

G3D::BindlessTextureHandle::~BindlessTextureHandle ( )

◆ BindlessTextureHandle() [2/2]

G3D::BindlessTextureHandle::BindlessTextureHandle ( shared_ptr< Texture tex,
const Sampler sampler 
)

Construct and call set()

Member Function Documentation

◆ glHandle()

uint64 G3D::BindlessTextureHandle::glHandle ( ) const
inline

The underlying bindless texture handle.

Pass this into shaders to access textures without needing to bind them. Currently the easiest method for doing this is to use an RG32UI texture, texelFetch from it, and use the sampler2D(uvec) constructor.

We will hopefully soon add support for passing texture handles as uniforms and vertex attributes.

◆ isResident()

bool G3D::BindlessTextureHandle::isResident ( ) const

◆ isValid()

bool G3D::BindlessTextureHandle::isValid ( ) const
inline

Is the underlying texture handle valid?

◆ makeNonResident()

void G3D::BindlessTextureHandle::makeNonResident ( )

Does nothing if the handle is invalid or already non resident.

◆ makeResident()

void G3D::BindlessTextureHandle::makeResident ( )

Raises an assertion if the texture handle is invalid, and does nothing if the handle is already resident.

◆ set()

void G3D::BindlessTextureHandle::set ( shared_ptr< Texture tex,
const Sampler sampler 
)

If this object is already valid, make sure the handle is non-resident and then create a new handle from the specified texture and sampler.

Since this object holds on to a copy of the Texture and GLSamplerObjects, the underlying handle should be valid until the destructor is run or set() is called again.

◆ texture()

shared_ptr<Texture> G3D::BindlessTextureHandle::texture ( ) const
inline

documentation generated on Wed Nov 24 2021 08:01:53 using doxygen 1.8.15