gKitGL
TPSampler.h
00001 
00002 #ifndef _TP_SAMPLER_H
00003 #define _TP_SAMPLER_H
00004 
00005 #include "GL/GLPlatform.h"
00006 #include "GLResource.h"
00007 
00008 
00009 namespace gk {
00010 
00011 class GLSampler : public GLResource
00012 {
00013     // non copyable
00014     GLSampler( const GLSampler& );
00015     GLSampler& operator= ( const GLSampler& );
00016     
00017 public:
00018     GLSampler( )
00019         :
00020         GLResource()
00021     {
00022         glGenSamplers(1, &m_name);
00023     }
00024 
00025     virtual ~GLSampler( )
00026     {
00027         glDeleteSamplers(1, &m_name);
00028     }
00029 
00030     int createGLResource( )
00031     {
00032         return (m_name != 0) ? 0 : -1;
00033     }
00034     
00035     int releaseGLResource( )
00036     {
00037         return (m_name != 0) ? 0 : -1;
00038     }
00039 };
00040 
00041 class GLNearestSampler : public GLSampler
00042 {
00043 public:
00044     GLNearestSampler( const GLenum wrap= GL_CLAMP_TO_BORDER )
00045         :
00046         GLSampler()
00047     {
00048         if(m_name == 0)
00049             return;
00050         glSamplerParameteri(m_name, GL_TEXTURE_WRAP_S, wrap);
00051         glSamplerParameteri(m_name, GL_TEXTURE_WRAP_T, wrap);
00052         //~ glSamplerParameteri(m_name, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
00053         glSamplerParameteri(m_name, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00054         glSamplerParameteri(m_name, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00055     }
00056     
00057     ~GLNearestSampler( ) {}
00058 };
00059 
00060 class GLLinearSampler : public GLSampler
00061 {
00062 public:
00063     GLLinearSampler( const GLenum wrap= GL_CLAMP_TO_BORDER )
00064         :
00065         GLSampler( )
00066     {
00067         if(m_name == 0)
00068             return;
00069         glSamplerParameteri(m_name, GL_TEXTURE_WRAP_S, wrap);
00070         glSamplerParameteri(m_name, GL_TEXTURE_WRAP_T, wrap);
00071         glSamplerParameteri(m_name, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
00072         glSamplerParameteri(m_name, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00073     }
00074 
00075     ~GLLinearSampler( ) {}
00076 };
00077 
00078 class GLAnisotropicSampler : public GLSampler
00079 {
00080 public:
00081     GLAnisotropicSampler( const float filter, const GLenum wrap= GL_CLAMP_TO_BORDER )
00082         :
00083         GLSampler( )
00084     {
00085         if(m_name == 0)
00086             return;
00087         glSamplerParameteri(m_name, GL_TEXTURE_WRAP_S, wrap);
00088         glSamplerParameteri(m_name, GL_TEXTURE_WRAP_T, wrap);
00089         glSamplerParameterf(m_name, GL_TEXTURE_MAX_ANISOTROPY_EXT, filter);
00090         glSamplerParameteri(m_name, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
00091         glSamplerParameteri(m_name, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00092     }
00093     
00094     ~GLAnisotropicSampler() {}
00095 };
00096 
00097 class GLDepthSampler : public GLSampler
00098 {
00099 public:
00100     GLDepthSampler( const GLenum wrap= GL_CLAMP_TO_EDGE )
00101         :
00102         GLSampler()
00103     {
00104         if(m_name == 0)
00105             return;
00106         glSamplerParameteri(m_name, GL_TEXTURE_WRAP_S, wrap);
00107         glSamplerParameteri(m_name, GL_TEXTURE_WRAP_T, wrap);
00108         glSamplerParameteri(m_name, GL_TEXTURE_COMPARE_MODE, GL_NONE);
00109         glSamplerParameteri(m_name, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
00110         //~ glSamplerParameteri(m_name, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00111         glSamplerParameteri(m_name, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00112     }
00113 };
00114 
00115 }
00116 
00117 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerator Friends