Commit 86468e94 authored by Robert Menzel's avatar Robert Menzel

added more Sampler wrappers

parent 4cf80dd6
......@@ -12,6 +12,7 @@
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/OpenGL/Tools.hh>
#include <ACGL/Math/Math.hh>
namespace ACGL{
namespace OpenGL{
......@@ -58,10 +59,38 @@ public:
openGLRareError();
}
//! unbinds the texture sampler (if there is one bound) from _textureUnit
inline static void unBind( GLuint _textureUnit ) { glBindSampler( _textureUnit, 0 ); }
//! generic parameter setting
inline void parameter( GLenum _parameterName, GLint _parameter ) { glSamplerParameteri( mObjectName, _parameterName, _parameter ); }
inline void parameter( GLenum _parameterName, GLfloat _parameter ) { glSamplerParameterf( mObjectName, _parameterName, _parameter ); }
inline void setBorderColor( glm::vec4 _color = glm::vec4(0.0f,0.0f,0.0f,0.0f) ) {
glSamplerParameterfv( mObjectName, GL_TEXTURE_BORDER_COLOR, glm::value_ptr(_color) );
}
inline void setMinFilter(GLenum _value = GL_NEAREST_MIPMAP_LINEAR) { glSamplerParameteri( mObjectName, GL_TEXTURE_MIN_FILTER, _value); }
inline void setMagFilter(GLenum _value = GL_LINEAR) { glSamplerParameteri( mObjectName, GL_TEXTURE_MAG_FILTER, _value); }
inline void setWrapS( GLenum _wrapS = GL_REPEAT ) { glSamplerParameteri( mObjectName, GL_TEXTURE_WRAP_S, _wrapS); }
inline void setWrapT( GLenum _wrapT = GL_REPEAT ) { glSamplerParameteri( mObjectName, GL_TEXTURE_WRAP_T, _wrapT); }
inline void setWrapR( GLenum _wrapR = GL_REPEAT ) { glSamplerParameteri( mObjectName, GL_TEXTURE_WRAP_R, _wrapR); }
void setWrap(GLenum _wrapS, GLenum _wrapT = 0, GLenum _wrapR = 0)
{
setWrapS(_wrapS);
if (_wrapT != 0) setWrapT(_wrapT);
if (_wrapR != 0) setWrapR(_wrapR);
}
inline void setMinLOD( GLint _lod = -1000 ) { glSamplerParameteri( mObjectName, GL_TEXTURE_MIN_LOD, _lod); }
inline void setMaxLOD( GLint _lod = 1000 ) { glSamplerParameteri( mObjectName, GL_TEXTURE_MAX_LOD, _lod); }
inline void setLODBias( GLfloat _bias = 0.0f ) { glSamplerParameterf( mObjectName, GL_TEXTURE_LOD_BIAS, _bias); }
inline void setCompareMode( GLenum _mode = GL_NONE ) { glSamplerParameteri( mObjectName, GL_TEXTURE_COMPARE_MODE, _mode); }
inline void setCompareFunc( GLenum _func = GL_LEQUAL ) { glSamplerParameteri( mObjectName, GL_TEXTURE_COMPARE_FUNC, _func); }
//! _sampleCount = 1.0 to deactivate anisotrop filtering, maximum is often 16. If a value is too high it will get clamped to the maximum
void setMaxAnisotropy( GLfloat _sampleCount = 1.0f );
private:
GLuint mObjectName;
};
......
......@@ -119,48 +119,10 @@ public:
}
//! Note: The function is not const, because it changes the corresponding GPU data
inline void setWrap(GLenum _wrapS, GLenum _wrapT = 0, GLenum _wrapR = 0)
{
glBindTexture(mTarget, mObjectName);
mWrapS = _wrapS;
glTexParameteri(mTarget, GL_TEXTURE_WRAP_S, mWrapS);
if(_wrapT != 0)
{
mWrapT = _wrapT;
glTexParameteri(mTarget, GL_TEXTURE_WRAP_T, mWrapT);
}
if(_wrapR != 0)
{
mWrapR = _wrapR;
glTexParameteri(mTarget, GL_TEXTURE_WRAP_R, mWrapR);
}
openGLRareError();
}
void setWrap(GLenum _wrapS, GLenum _wrapT = 0, GLenum _wrapR = 0);
//! _sampleCount = 1.0 to deactivate anisotrop filtering, maximum is often 16. If a value is too high it will get clamped to the maximum
void setAnisotropicFilter( GLfloat _sampleCount )
{
#ifdef ACGL_USE_GLEW
if (GLEW_EXT_texture_filter_anisotropic) {
GLfloat maxAnisotropicSamples;
glGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropicSamples );
_sampleCount = std::max( 1.0f, _sampleCount );
_sampleCount = std::min( maxAnisotropicSamples, _sampleCount );
glBindTexture(mTarget, mObjectName);
glTexParameterf( mTarget, GL_TEXTURE_MAX_ANISOTROPY_EXT, _sampleCount);
openGLRareError();
} else
#endif
{
// anisotropic filtering will just increase the image quality, so this is just
// a warning and no error
ACGL::Utils::warning() << "Anisotropic filtering is not supported, ignored" << std::endl;
}
}
void setAnisotropicFilter( GLfloat _sampleCount );
//! Set texture data for 1D, 2D or 3D textures
inline void setImageData(const GLvoid* _pData = NULL)
......
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2012, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#include <ACGL/OpenGL/Objects/Sampler.hh>
using namespace ACGL::OpenGL;
Sampler::Sampler()
{
glGenSamplers(1, &mObjectName);
if (openGLCriticalErrorOccured() ) {
ACGL::Utils::error() << "could not generate sampler!" << std::endl;
mObjectName = 0;
return;
}
}
Sampler::~Sampler(void)
{
// sampler 0 will get ignored by OpenGL
glDeleteSamplers(1, &mObjectName);
}
void Sampler::setMaxAnisotropy( GLfloat _sampleCount )
{
#ifdef ACGL_USE_GLEW
if (GLEW_EXT_texture_filter_anisotropic) {
// anisotrophic filtering is supported:
GLfloat maxAnisotropicSamples;
glGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropicSamples );
_sampleCount = std::max( 1.0f, _sampleCount );
_sampleCount = std::min( maxAnisotropicSamples, _sampleCount );
glSamplerParameterf( mObjectName, GL_TEXTURE_MAX_ANISOTROPY_EXT, _sampleCount );
openGLRareError();
} else
#endif
{
if (_sampleCount != 1.0f ) {
// anisotropic filtering will just increase the image quality, so this is just
// a warning and no error, 1 sample is equal to no anisotrophic filtering, so ignore
// that case entirely!
ACGL::Utils::warning() << "Anisotropic filtering is not supported, ignored" << std::endl;
}
}
}
......@@ -6,3 +6,49 @@
#include <ACGL/OpenGL/Objects/Texture.hh>
using namespace ACGL::OpenGL;
void Texture::setWrap( GLenum _wrapS, GLenum _wrapT, GLenum _wrapR )
{
glBindTexture(mTarget, mObjectName);
mWrapS = _wrapS;
glTexParameteri(mTarget, GL_TEXTURE_WRAP_S, mWrapS);
if(_wrapT != 0)
{
mWrapT = _wrapT;
glTexParameteri(mTarget, GL_TEXTURE_WRAP_T, mWrapT);
}
if(_wrapR != 0)
{
mWrapR = _wrapR;
glTexParameteri(mTarget, GL_TEXTURE_WRAP_R, mWrapR);
}
openGLRareError();
}
void Texture::setAnisotropicFilter( GLfloat _sampleCount )
{
#ifdef ACGL_USE_GLEW
if (GLEW_EXT_texture_filter_anisotropic) {
// anisotrophic filtering is supported:
GLfloat maxAnisotropicSamples;
glGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropicSamples );
_sampleCount = std::max( 1.0f, _sampleCount );
_sampleCount = std::min( maxAnisotropicSamples, _sampleCount );
glBindTexture( mTarget, mObjectName );
glTexParameterf( mTarget, GL_TEXTURE_MAX_ANISOTROPY_EXT, _sampleCount );
openGLRareError();
} else
#endif
{
if (_sampleCount != 1.0f ) {
// anisotropic filtering will just increase the image quality, so this is just
// a warning and no error, 1 sample is equal to no anisotrophic filtering, so ignore
// that case entirely!
ACGL::Utils::warning() << "Anisotropic filtering is not supported, ignored" << std::endl;
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment