texturecube.h
Go to the documentation of this file.
00001 #ifndef GLW_TEXTURECUBE_H
00002 #define GLW_TEXTURECUBE_H
00003 
00004 #include "./texture.h"
00005 
00006 namespace glw
00007 {
00008 
00009 class TextureCubeArguments : public TextureArguments
00010 {
00011         public:
00012 
00013                 typedef TextureArguments   BaseType;
00014                 typedef TextureCubeArguments ThisType;
00015 
00016                 GLsizei           size;
00017                 GLenum            dataFormat;
00018                 GLenum            dataType;
00019                 const void *      data;
00020                 TextureSampleMode sampler;
00021 
00022                 TextureCubeArguments(void)
00023                 {
00024                         this->clear();
00025                 }
00026 
00027                 void clear(void)
00028                 {
00029                         BaseType::clear();
00030                         this->size       = 0;
00031                         this->dataFormat = GL_NONE;
00032                         this->dataType   = GL_NONE;
00033                         this->data       = 0;
00034                         this->sampler.clear();
00035                 }
00036 };
00037 
00038 class TextureCube : public Texture
00039 {
00040         friend class Context;
00041 
00042         public:
00043 
00044                 typedef Texture   BaseType;
00045                 typedef TextureCube ThisType;
00046 
00047                 virtual Type type(void) const
00048                 {
00049                         return TextureCubeType;
00050                 }
00051 
00052                 virtual int imageDimensions(void) const
00053                 {
00054                         return 2;
00055                 }
00056 
00057                 virtual bool isArray(void) const
00058                 {
00059                         return false;
00060                 }
00061 
00062                 GLsizei size(void) const
00063                 {
00064                         return this->m_size;
00065                 }
00066 
00067                 GLsizei width(void) const
00068                 {
00069                         return this->size();
00070                 }
00071 
00072                 GLsizei height(void) const
00073                 {
00074                         return this->size();
00075                 }
00076 
00077                 void setImage(GLenum target, GLint unit, GLint level, GLsizei size, GLenum dataFormat, GLenum dataType, const void * data)
00078                 {
00079                         (void)unit;
00080                         GLW_ASSERT(this->isValid());
00081                         glTexImage2D(target, level, this->m_format, size, size, 0, dataFormat, dataType, data);
00082                 }
00083 
00084                 void getImage(GLenum target, GLint unit, GLint level, GLenum dataFormat, GLenum dataType, void * data)
00085                 {
00086                         (void)unit;
00087                         GLW_ASSERT(this->isValid());
00088                         glGetTexImage(target, level, dataFormat, dataType, data);
00089                 }
00090 
00091                 void setSubImage(GLenum target, GLint unit, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum dataFormat, GLenum dataType, const void * data)
00092                 {
00093                         (void)unit;
00094                         GLW_ASSERT(this->isValid());
00095                         glTexSubImage2D(target, level, xoffset, yoffset, width, height, dataFormat, dataType, data);
00096                 }
00097 
00098                 void generateMipmap(GLenum target, GLint unit)
00099                 {
00100                         (void)unit;
00101                         GLW_ASSERT(this->isValid());
00102                         glGenerateMipmap(target);
00103                 }
00104 
00105                 void setSampleMode(GLenum target, GLint unit, const TextureSampleMode & sampler)
00106                 {
00107                         (void)unit;
00108                         GLW_ASSERT(this->isValid());
00109                         if (GLW_CARE_OF(sampler.minFilter)) glTexParameteri(target, GL_TEXTURE_MIN_FILTER, sampler.minFilter);
00110                         if (GLW_CARE_OF(sampler.magFilter)) glTexParameteri(target, GL_TEXTURE_MAG_FILTER, sampler.magFilter);
00111                         if (GLW_CARE_OF(sampler.wrapS    )) glTexParameteri(target, GL_TEXTURE_WRAP_S,     sampler.wrapS    );
00112                         if (GLW_CARE_OF(sampler.wrapT    )) glTexParameteri(target, GL_TEXTURE_WRAP_T,     sampler.wrapT    );
00113                 }
00114 
00115         protected:
00116 
00117                 GLsizei m_size;
00118 
00119                 TextureCube(Context * ctx)
00120                         : BaseType (ctx)
00121                         , m_size   (0)
00122                 {
00123                         ;
00124                 }
00125 
00126                 bool create(const TextureCubeArguments & args)
00127                 {
00128                         this->destroy();
00129                         GLint boundName = 0;
00130                         glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP, &boundName);
00131                         glGenTextures(1, &(this->m_name));
00132                         glBindTexture(GL_TEXTURE_CUBE_MAP, this->m_name);
00133                         for (int f=0; f<6; ++f)
00134                         {
00135                                 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, 0, args.format, args.size, args.size, 0, args.dataFormat, args.dataType, args.data);
00136                         }
00137                         this->m_format = args.format;
00138                         this->m_size   = args.size;
00139                         this->setSampleMode(GL_TEXTURE_CUBE_MAP, 0, args.sampler);
00140                         glBindTexture(GL_TEXTURE_CUBE_MAP, boundName);
00141                         return true;
00142                 }
00143 
00144                 virtual void doDestroy(void)
00145                 {
00146                         BaseType::doDestroy();
00147                         this->m_format = GL_NONE;
00148                         this->m_size   = 0;
00149                 }
00150 
00151                 virtual bool doIsValid(void) const
00152                 {
00153                         return ((this->m_format != GL_NONE) && (this->m_size > 0));
00154                 }
00155 };
00156 
00157 namespace detail { template <> struct BaseOf <TextureCube> { typedef Texture Type; }; };
00158 typedef   detail::ObjectSharedPointerTraits  <TextureCube> ::Type TextureCubePtr;
00159 
00160 class SafeTextureCube : public SafeTexture
00161 {
00162         friend class Context;
00163         friend class BoundTextureCube;
00164 
00165         public:
00166 
00167                 typedef SafeTexture   BaseType;
00168                 typedef SafeTextureCube ThisType;
00169 
00170                 SafeTextureCube(void)
00171                         : BaseType()
00172                 {
00173                         ;
00174                 }
00175 
00176                 GLsizei size(void) const
00177                 {
00178                         return this->object()->size();
00179                 }
00180 
00181                 GLsizei width(void) const
00182                 {
00183                         return this->object()->width();
00184                 }
00185 
00186                 GLsizei height(void) const
00187                 {
00188                         return this->object()->height();
00189                 }
00190 
00191         protected:
00192 
00193                 SafeTextureCube(const TextureCubePtr & texture2D)
00194                         : BaseType(texture2D)
00195                 {
00196                         ;
00197                 }
00198 
00199                 const TextureCubePtr & object(void) const
00200                 {
00201                         return static_cast<const TextureCubePtr &>(BaseType::object());
00202                 }
00203 
00204                 TextureCubePtr & object(void)
00205                 {
00206                         return static_cast<TextureCubePtr &>(BaseType::object());
00207                 }
00208 };
00209 
00210 namespace detail { template <> struct BaseOf     <SafeTextureCube> { typedef SafeTexture   Type; }; };
00211 namespace detail { template <> struct ObjectBase <SafeTextureCube> { typedef TextureCube     Type; }; };
00212 namespace detail { template <> struct ObjectSafe <TextureCube    > { typedef SafeTextureCube Type; }; };
00213 typedef   detail::ObjectSharedPointerTraits      <SafeTextureCube> ::Type TextureCubeHandle;
00214 
00215 class TextureCubeBindingParams : public TextureBindingParams
00216 {
00217         public:
00218 
00219                 typedef TextureBindingParams   BaseType;
00220                 typedef TextureCubeBindingParams ThisType;
00221 
00222                 TextureCubeBindingParams(void)
00223                         : BaseType()
00224                 {
00225                         ;
00226                 }
00227 
00228                 TextureCubeBindingParams(GLenum aUnit)
00229                         : BaseType(GL_TEXTURE_CUBE_MAP, aUnit)
00230                 {
00231                         ;
00232                 }
00233 };
00234 
00235 class BoundTextureCube : public BoundTexture
00236 {
00237         friend class Context;
00238 
00239         public:
00240 
00241                 typedef BoundTexture   BaseType;
00242                 typedef BoundTextureCube ThisType;
00243 
00244                 BoundTextureCube(void)
00245                         : BaseType()
00246                 {
00247                         ;
00248                 }
00249 
00250                 const TextureCubeHandle & handle(void) const
00251                 {
00252                         return static_cast<const TextureCubeHandle &>(BaseType::handle());
00253                 }
00254 
00255                 TextureCubeHandle & handle(void)
00256                 {
00257                         return static_cast<TextureCubeHandle &>(BaseType::handle());
00258                 }
00259 
00260                 void setSampleMode(const TextureSampleMode & sampler)
00261                 {
00262                         this->object()->setSampleMode(this->m_target, this->m_unit, sampler);
00263                 }
00264 
00265                 void setImage(GLenum face, GLint level, GLsizei size, GLenum dataFormat, GLenum dataType, const void * data)
00266                 {
00267                         this->object()->setImage(face, this->m_unit, level, size, dataFormat, dataType, data);
00268                 }
00269 
00270                 void getImage(GLenum face, GLint level, GLenum dataFormat, GLenum dataType, void * data)
00271                 {
00272                         this->object()->getImage(face, this->m_unit, level, dataFormat, dataType, data);
00273                 }
00274 
00275                 void setSubImage(GLenum face, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum dataFormat, GLenum dataType, const void * data)
00276                 {
00277                         this->object()->setSubImage(face, this->m_unit, level, xoffset, yoffset, width, height, dataFormat, dataType, data);
00278                 }
00279 
00280                 void generateMipmap(void)
00281                 {
00282                         this->object()->generateMipmap(this->m_target, this->m_unit);
00283                 }
00284 
00285         protected:
00286 
00287                 BoundTextureCube(const TextureCubeHandle & handle, const TextureCubeBindingParams & params)
00288                         : BaseType(handle, params)
00289                 {
00290                         ;
00291                 }
00292 
00293                 const TextureCubePtr & object(void) const
00294                 {
00295                         return this->handle()->object();
00296                 }
00297 
00298                 TextureCubePtr & object(void)
00299                 {
00300                         return this->handle()->object();
00301                 }
00302 };
00303 
00304 namespace detail { template <> struct ParamsOf    <BoundTextureCube> { typedef TextureCubeBindingParams Type; }; };
00305 namespace detail { template <> struct BaseOf      <BoundTextureCube> { typedef BoundObject Type; }; };
00306 namespace detail { template <> struct ObjectBase  <BoundTextureCube> { typedef TextureCube      Type; }; };
00307 namespace detail { template <> struct ObjectBound <TextureCube     > { typedef BoundTextureCube Type; }; };
00308 typedef   detail::ObjectSharedPointerTraits       <BoundTextureCube> ::Type  BoundTextureCubeHandle;
00309 
00310 };
00311 
00312 #endif // GLW_TEXTURECUBE_H


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:37:20