ImFusion SDK 4.3
Sampler Class Reference

#include <ImFusion/Core/GL/Sampler.h>

Sets texture sampling parameters for a specific texture unit. More...

+ Inheritance diagram for Sampler:

Detailed Description

Sets texture sampling parameters for a specific texture unit.

Instances of this class are usually supposed to be used together with a GL::Texture when calling GL::Program::setArgument(). You can use the same sampler for multiple textures at the same time.

// will have default sampling parameters (such as linear filtering)
GL::Texture texture = ...;
// configure a dedicated Sampler with nearest filtering:
GL::Sampler sampler;
GL::Program prog = ...;
prog.enable();
// pass both `texture` and `sampler` to use nearest filtering mode as configured for the sampler.
prog.setArgument("u_texture", texture, sampler);
OpenGL GLSL program with a fragment and optional vertex and geometry shader.
Definition Program.h:99
Sets texture sampling parameters for a specific texture unit.
Definition Sampler.h:40
@ Nearest
Select nearest texel without any filtering.
Definition Sampler.h:59
@ Nearest
Select nearest texel without any filtering.
Definition Sampler.h:71
void setFiltering(MinFilter min, MagFilter mag)
Sets the minification and magnification filters.
Wrapper of an OpenGL Texture to store image data on the GPU.
Definition Texture.h:34
See also
https://www.khronos.org/opengl/wiki/Sampler_Object

Public Types

enum class  Wrap { ClampToEdge = 0x812F , Repeat = 0x2901 , MirroredRepeat = 0x8370 , ClampToBorder = 0x812D }
 Describes the wrapping mode applied by an OpenGL texture sampler. More...
 
enum class  MinFilter {
  Nearest = 0x2600 , Linear = 0x2601 , NearestMipMapNearest = 0x2700 , LinearMipMapNearest = 0x2701 ,
  NearestMipMapLinear = 0x2702 , LinearMipMapLinear = 0x2703
}
 Describes the minification filter applied by an OpenGL texture sampler. More...
 
enum class  MagFilter { Nearest = 0x2600 , Linear = 0x2601 }
 Describes the magnification filter applied by an OpenGL texture sampler. More...
 
enum class  CompareMode { None = 0 , CompareToRefTexture = 0x884E }
 
enum class  CompareFunc {
  Never = 0x0200 , Less = 0x0201 , Equal = 0x0202 , LesserEqual = 0x0203 ,
  Greater = 0x0204 , NotEqual = 0x0205 , GreaterEqual = 0x0206 , Always = 0x0207
}
 

Public Member Functions

 Sampler ()
 Creates a sampler object using linear filtering and clamp-to-edge wrapping as default parameters.
 
void setFiltering (MinFilter min, MagFilter mag)
 Sets the minification and magnification filters.
 
void setWrapping (Wrap s, Wrap t, Wrap r)
 Sets the wrapping parameters for each dimension.
 
void setWrapping (Wrap all)
 Sets all wrapping parameters for all dimensions to the same value.
 
void setCompareMode (CompareMode mode, CompareFunc func)
 Sets compare mode for depth component textures.
 
void setLOD (float minLOD, float maxLOD, float bias=0.0f)
 Sets level-of-detail parameters used in mipmap selection.
 
void setBorderColor (const vec4f &color)
 Sets the border color that is used for Wrap::ClampToBorder.
 
void bind (uint32_t textureUnit) const
 Binds the sampler to the specified texture unit.
 
uint32_t id () const
 Return the OpenGL object ID of this sampler.
 

Static Public Member Functions

static void unbind (uint32_t textureUnit)
 Unbinds any potentially bound sampler from the specified texture unit (binds 0)
 

Member Enumeration Documentation

◆ Wrap

enum class Wrap
strong

Describes the wrapping mode applied by an OpenGL texture sampler.

See also
https://www.khronos.org/opengl/wiki/Sampler_Object#Edge_value_sampling
Enumerator
ClampToEdge 

Tex coordinates are clamped to [0, 1] range.

Repeat 

Tex coordinates wrap around the texture.

MirroredRepeat 

Tex coordinates wrap around the texture in a mirrored fashion.

ClampToBorder 

Tex coordinates are clamped to [0, 1], edge pixels use constant border color.

◆ MinFilter

enum class MinFilter
strong

Describes the minification filter applied by an OpenGL texture sampler.

Note
All MipMap options require mipmaps to be present in the texture, cf. GL::Texture::generateMipmaps()
See also
https://www.khronos.org/opengl/wiki/Sampler_Object#Filtering
Enumerator
Nearest 

Select nearest texel without any filtering.

Linear 

Use linear filtering without any mipmapping.

NearestMipMapNearest 

Use nearest texel on nearest mipmap.

LinearMipMapNearest 

Perform linear filtering on nearest mipmap.

NearestMipMapLinear 

Use nearest texel but linearly interpolate between mipmaps.

LinearMipMapLinear 

Perform linear filtering and linearly interpolate between mipmaps.

◆ MagFilter

enum class MagFilter
strong

Describes the magnification filter applied by an OpenGL texture sampler.

See also
https://www.khronos.org/opengl/wiki/Sampler_Object#Filtering
Enumerator
Nearest 

Select nearest texel without any filtering.

Linear 

Use linear filtering without any mipmapping.

◆ CompareMode

◆ CompareFunc

Constructor & Destructor Documentation

◆ Sampler()

Sampler ( )

Creates a sampler object using linear filtering and clamp-to-edge wrapping as default parameters.

Exceptions
std::runtime_errorif the corresponding OpenGL sampler object could not be created.

Member Function Documentation

◆ setFiltering()

void setFiltering ( MinFilter min,
MagFilter mag )

Sets the minification and magnification filters.

Mipmap types will only work when the texture bound to the same texture unit has mipmap levels.


The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close