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
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( )
00045 :
00046 GLSampler()
00047 {
00048 if(m_name == 0)
00049 return;
00050 glSamplerParameteri(m_name, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
00051 glSamplerParameteri(m_name, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
00052
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( )
00064 :
00065 GLSampler( )
00066 {
00067 if(m_name == 0)
00068 return;
00069 glSamplerParameteri(m_name, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
00070 glSamplerParameteri(m_name, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
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 GLDepthSampler : public GLSampler
00079 {
00080 public:
00081 GLDepthSampler( )
00082 :
00083 GLSampler()
00084 {
00085 if(m_name == 0)
00086 return;
00087 glSamplerParameteri(m_name, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
00088 glSamplerParameteri(m_name, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
00089 glSamplerParameteri(m_name, GL_TEXTURE_COMPARE_MODE, GL_NONE);
00090 glSamplerParameteri(m_name, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
00091
00092 glSamplerParameteri(m_name, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00093 }
00094 };
00095
00096 }
00097
00098 #endif