Go to the documentation of this file.00001 #ifndef GLW_TEXTURE_H
00002 #define GLW_TEXTURE_H
00003
00004 #include "./renderable.h"
00005
00006 namespace glw
00007 {
00008
00009 class TextureSampleMode
00010 {
00011 public:
00012
00013 typedef void BaseType;
00014 typedef TextureSampleMode ThisType;
00015
00016 GLenum minFilter;
00017 GLenum magFilter;
00018 GLenum wrapS;
00019 GLenum wrapT;
00020 GLenum wrapR;
00021
00022 TextureSampleMode(void)
00023 {
00024 this->clear();
00025 }
00026
00027 TextureSampleMode(GLenum rMinFilter, GLenum rMagFilter, GLenum rWrapS, GLenum rWrapT, GLenum rWrapR)
00028 : minFilter (rMinFilter)
00029 , magFilter (rMagFilter)
00030 , wrapS (rWrapS)
00031 , wrapT (rWrapT)
00032 , wrapR (rWrapR)
00033 {
00034 ;
00035 }
00036
00037 void clear(void)
00038 {
00039 this->minFilter = GLW_DONT_CARE;
00040 this->magFilter = GLW_DONT_CARE;
00041 this->wrapS = GLW_DONT_CARE;
00042 this->wrapT = GLW_DONT_CARE;
00043 this->wrapR = GLW_DONT_CARE;
00044 }
00045
00046 static TextureSampleMode dontCare(void)
00047 {
00048 return ThisType();
00049 }
00050
00051 static TextureSampleMode texelFetch(void)
00052 {
00053 return ThisType(GL_NEAREST, GL_NEAREST, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
00054 }
00055 };
00056
00057 inline TextureSampleMode textureSampleMode(GLenum minFilter = GLW_DONT_CARE, GLenum magFilter = GLW_DONT_CARE, GLenum wrapS = GLW_DONT_CARE, GLenum wrapT = GLW_DONT_CARE, GLenum wrapR = GLW_DONT_CARE)
00058 {
00059 return TextureSampleMode(minFilter, magFilter, wrapS, wrapT, wrapR);
00060 }
00061
00062 class TextureArguments : public RenderableArguments
00063 {
00064 public:
00065
00066 typedef RenderableArguments BaseType;
00067 typedef TextureArguments ThisType;
00068
00069 TextureArguments(void)
00070 {
00071 this->clear();
00072 }
00073
00074 void clear(void)
00075 {
00076 BaseType::clear();
00077 }
00078 };
00079
00080 class Texture : public Renderable
00081 {
00082 friend class Context;
00083
00084 public:
00085
00086 typedef Renderable BaseType;
00087 typedef Texture ThisType;
00088
00089 virtual ~Texture(void)
00090 {
00091 this->destroy();
00092 }
00093
00094 protected:
00095
00096 Texture(Context * ctx)
00097 : BaseType(ctx)
00098 {
00099 ;
00100 }
00101
00102 virtual void doDestroy(void)
00103 {
00104 glDeleteTextures(1, &(this->m_name));
00105 }
00106 };
00107
00108 namespace detail { template <> struct BaseOf <Texture> { typedef Renderable Type; }; };
00109 typedef detail::ObjectSharedPointerTraits <Texture> ::Type TexturePtr;
00110
00111 class SafeTexture : public SafeRenderable
00112 {
00113 friend class Context;
00114 friend class BoundTexture;
00115
00116 public:
00117
00118 typedef SafeRenderable BaseType;
00119 typedef SafeTexture ThisType;
00120
00121 SafeTexture(void)
00122 : BaseType()
00123 {
00124 ;
00125 }
00126
00127 protected:
00128
00129 SafeTexture(const TexturePtr & texture)
00130 : BaseType(texture)
00131 {
00132 ;
00133 }
00134
00135 const TexturePtr & object(void) const
00136 {
00137 return static_cast<const TexturePtr &>(BaseType::object());
00138 }
00139
00140 TexturePtr & object(void)
00141 {
00142 return static_cast<TexturePtr &>(BaseType::object());
00143 }
00144 };
00145
00146 namespace detail { template <> struct BaseOf <SafeTexture> { typedef SafeRenderable Type; }; };
00147 namespace detail { template <> struct ObjectBase <SafeTexture> { typedef Texture Type; }; };
00148 namespace detail { template <> struct ObjectSafe <Texture > { typedef SafeTexture Type; }; };
00149 typedef detail::ObjectSharedPointerTraits <SafeTexture> ::Type TextureHandle;
00150
00151 class TextureBindingParams : public RenderableBindingParams
00152 {
00153 public:
00154
00155 typedef RenderableBindingParams BaseType;
00156 typedef TextureBindingParams ThisType;
00157
00158 TextureBindingParams(void)
00159 : BaseType()
00160 {
00161 ;
00162 }
00163
00164 TextureBindingParams(GLenum aTarget, GLenum aUnit)
00165 : BaseType(aTarget, aUnit)
00166 {
00167 ;
00168 }
00169 };
00170
00171 class BoundTexture : public BoundRenderable
00172 {
00173 friend class Context;
00174
00175 public:
00176
00177 typedef BoundRenderable BaseType;
00178 typedef BoundTexture ThisType;
00179
00180 BoundTexture(void)
00181 : BaseType()
00182 {
00183 ;
00184 }
00185
00186 const TextureHandle & handle(void) const
00187 {
00188 return static_cast<const TextureHandle &>(BaseType::handle());
00189 }
00190
00191 TextureHandle & handle(void)
00192 {
00193 return static_cast<TextureHandle &>(BaseType::handle());
00194 }
00195
00196 protected:
00197
00198 BoundTexture(const TextureHandle & handle, const TextureBindingParams & params)
00199 : BaseType(handle, params)
00200 {
00201 ;
00202 }
00203
00204 const TexturePtr & object(void) const
00205 {
00206 return this->handle()->object();
00207 }
00208
00209 TexturePtr & object(void)
00210 {
00211 return this->handle()->object();
00212 }
00213
00214 virtual void bind(void)
00215 {
00216 glActiveTexture(GL_TEXTURE0 + this->m_unit);
00217 glBindTexture(this->m_target, this->object()->name());
00218 }
00219
00220 virtual void unbind(void)
00221 {
00222 glActiveTexture(GL_TEXTURE0 + this->m_unit);
00223 glBindTexture(this->m_target, 0);
00224 }
00225 };
00226
00227 namespace detail { template <> struct ParamsOf <BoundTexture> { typedef TextureBindingParams Type; }; };
00228 namespace detail { template <> struct BaseOf <BoundTexture> { typedef BoundObject Type; }; };
00229 namespace detail { template <> struct ObjectBase <BoundTexture> { typedef Texture Type; }; };
00230 namespace detail { template <> struct ObjectBound <Texture > { typedef BoundTexture Type; }; };
00231 typedef detail::ObjectSharedPointerTraits <BoundTexture> ::Type BoundTextureHandle;
00232
00233 };
00234
00235 #endif // GLW_TEXTURE_H