]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Texture.cc
renamed mippleton to library
[chaz/yoink] / src / Moof / Texture.cc
index 8aa66c4f1ec7c64c95b3d35016f4ef1e9068593d..78dc0c8148b478c092f0375ac46c3ecff2d7f707 100644 (file)
@@ -34,7 +34,8 @@
 #include <SDL/SDL_image.h>
 
 #include "Dispatcher.hh"
-#include "Mippleton.hh"
+#include "Library.hh"
+#include "Log.hh"
 #include "OpenGL.hh"
 #include "Texture.hh"
 
@@ -51,7 +52,7 @@ namespace Mf {
  * objects and avoid having duplicate textures loaded to GL.
  */
 
-class Texture::Impl : public Mippleton<Impl>
+class Texture::Impl : public Library<Impl>
 {
 
        /**
@@ -60,15 +61,15 @@ class Texture::Impl : public Mippleton<Impl>
 
        void unloadFromGL()
        {
-               if (object_)
+               if (mObject)
                {
-                       if (object_ == globalObject_)
+                       if (mObject == globalObject_)
                        {
                                globalObject_ = 0;
                        }
 
-                       glDeleteTextures(1, &object_);
-                       object_ = 0;
+                       glDeleteTextures(1, &mObject);
+                       mObject = 0;
                }
        }
 
@@ -80,7 +81,7 @@ class Texture::Impl : public Mippleton<Impl>
 
        void contextRecreated(const Notification* note)
        {
-               object_ = globalObject_ = 0;
+               mObject = globalObject_ = 0;
                uploadToGL();
        }
 
@@ -130,34 +131,34 @@ public:
         */
 
        explicit Impl(const std::string& name) :
-               Mippleton<Impl>(name),
-               surface_(0),
-               width_(0),
-               height_(0),
-               mode_(0),
-               minFilter_(GL_NEAREST),
-               magFilter_(GL_NEAREST),
-               wrapS_(GL_CLAMP),
-               wrapT_(GL_CLAMP),
-               object_(0)
+               Library<Impl>(name),
+               mContext(0),
+               mWidth(0),
+               mHeight(0),
+               mMode(0),
+               mMinFilter(GL_NEAREST),
+               mMagFilter(GL_NEAREST),
+               mWrapS(GL_CLAMP),
+               mWrapT(GL_CLAMP),
+               mObject(0)
        {
                loadFromFile();
 
                // we want to know when the GL context is recreated
-               Dispatcher::instance().addHandler("video.context_recreated",
+               Dispatcher::getInstance().addHandler("video.context_recreated",
                                boost::bind(&Impl::contextRecreated, this, _1), this);
        }
 
        ~Impl()
        {
-               if (surface_)
+               if (mContext)
                {
-                       SDL_FreeSurface(surface_);
+                       SDL_FreeSurface(mContext);
                }
 
                unloadFromGL();
 
-               Dispatcher::instance().removeHandler(this);
+               Dispatcher::getInstance().removeHandler(this);
        }
 
 
@@ -243,7 +244,8 @@ public:
 
                if (!surface)
                {
-                       throw Texture::Exception("loading from file failed");
+                       logWarning("texture not found: %s", getName().c_str());
+                       throw Exception(Exception::FILE_NOT_FOUND);
                }
 
                SDL_Surface* temp = prepareImageForGL(surface);
@@ -251,27 +253,27 @@ public:
 
                if (!temp)
                {
-                       throw Texture::Exception("uploading to opengl failed");
+                       throw Exception(Exception::OPENGL_ERROR);
                }
 
                if (temp->format->BytesPerPixel == 3)
                {
-                       mode_ = GL_RGB;
+                       mMode = GL_RGB;
                }
                else if (temp->format->BytesPerPixel == 4)
                {
-                       mode_ = GL_RGBA;
+                       mMode = GL_RGBA;
                }
                else
                {
                        SDL_FreeSurface(temp);
-                       throw Texture::Exception("incompatible color mode");
+                       throw Exception(Exception::BAD_IMAGE_FORMAT);
                }
 
-               width_ = temp->w;
-               height_ = temp->h;
+               mWidth = temp->w;
+               mHeight = temp->h;
 
-               surface_ = temp;
+               mContext = temp;
        }
 
 
@@ -282,34 +284,36 @@ public:
 
        void uploadToGL()
        {
-               if (object_)
+               if (mObject)
                {
                        // already loaded
                        return;
                }
 
-               if (!surface_) loadFromFile();
+               if (!mContext) loadFromFile();
 
-               glGenTextures(1, &object_);
-               glBindTexture(GL_TEXTURE_2D, object_);
+               glGenTextures(1, &mObject);
+               glBindTexture(GL_TEXTURE_2D, mObject);
 
                glTexImage2D
+               //gluBuild2DMipmaps
                (
                        GL_TEXTURE_2D,
                        0,
-                       mode_,
-                       surface_->w,
-                       surface_->h,
+                       mMode,
+                       //3,
+                       mContext->w,
+                       mContext->h,
                        0,
-                       mode_,
+                       mMode,
                        GL_UNSIGNED_BYTE,
-                       surface_->pixels
+                       mContext->pixels
                );
 
                setProperties();
 
-               SDL_FreeSurface(surface_);
-               surface_ = 0;
+               SDL_FreeSurface(mContext);
+               mContext = 0;
        }
 
 
@@ -320,66 +324,66 @@ public:
 
        void setProperties()
        {
-               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter_);
-               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter_);
-               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapS_);
-               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapT_);
+               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mMinFilter);
+               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mMagFilter);
+               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mWrapS);
+               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mWrapT);
        }
 
        inline void setMinFilter(GLuint filter)
        {
                bind();
-               minFilter_ = filter;
-               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter_);
+               mMinFilter = filter;
+               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mMinFilter);
        }
 
        inline void setMagFilter(GLuint filter)
        {
                bind();
-               magFilter_ = filter;
-               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter_);
+               mMagFilter = filter;
+               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mMagFilter);
        }
 
        inline void setWrapS(GLuint wrap)
        {
                bind();
-               wrapS_ = wrap;
-               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapS_);
+               mWrapS = wrap;
+               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mWrapS);
        }
 
        inline void setWrapT(GLuint wrap)
        {
                bind();
-               wrapT_ = wrap;
-               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapT_);
+               mWrapT = wrap;
+               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mWrapT);
        }
 
 
        inline void bind()
        {
-               if (object_ == 0)
+               if (mObject == 0)
                {
                        uploadToGL();
                }
-               if (object_ != globalObject_)
+               if (mObject != globalObject_)
                {
-                       glBindTexture(GL_TEXTURE_2D, object_);
-                       globalObject_ = object_;
+                       glBindTexture(GL_TEXTURE_2D, mObject);
+                       globalObject_ = mObject;
                }
        }
 
 
-       SDL_Surface*    surface_;
-       unsigned                width_;                 ///< Horizontal dimension of the image.
-       unsigned                height_;                ///< Vertical dimension.
+       SDL_Surface*    mContext;
+       unsigned                mWidth;                 ///< Horizontal dimension of the image.
+       unsigned                mHeight;                ///< Vertical dimension.
 
-       GLuint                  mode_;                  ///< Depth of the image, GL_RGB or GL_RGBA.
-       GLuint                  minFilter_;             ///< Minifcation filter.
-       GLuint                  magFilter_;             ///< Magnification filter.
-       GLuint                  wrapS_;                 ///< Wrapping behavior horizontally.
-       GLuint                  wrapT_;                 ///< Wrapping behavior vertically.
+       GLuint                  mMode;                  ///< Depth of the image, GL_RGB or GL_RGBA.
+       GLuint                  mMinFilter;             ///< Minifcation filter.
+       GLuint                  mMagFilter;             ///< Magnification filter.
+       GLuint                  mWrapS;                 ///< Wrapping behavior horizontally.
+       GLuint                  mWrapT;                 ///< Wrapping behavior vertically.
 
-       GLuint                  object_;                ///< GL texture handle.
+       GLuint                  mObject;                ///< GL texture handle.
        static GLuint   globalObject_;  ///< Global GL texture handle.
 };
 
@@ -388,7 +392,7 @@ GLuint Texture::Impl::globalObject_ = 0;
 
 Texture::Texture(const std::string& name) :
        // pass through
-       impl_(Texture::Impl::retain(name), &Texture::Impl::release) {}
+       mImpl(Texture::Impl::getInstance(name)) {}
 
 
 /**
@@ -398,7 +402,7 @@ Texture::Texture(const std::string& name) :
 void Texture::bind() const
 {
        // pass through
-       impl_->bind();
+       mImpl->bind();
 }
 
 
@@ -409,7 +413,7 @@ void Texture::bind() const
 GLuint Texture::getObject() const
 {
        // pass through
-       return impl_->object_;
+       return mImpl->mObject;
 }
 
 
@@ -423,38 +427,38 @@ void Texture::resetBind()
 unsigned Texture::getWidth() const
 {
        // pass through
-       return impl_->width_;
+       return mImpl->mWidth;
 }
 
 unsigned Texture::getHeight() const
 {
        // pass through
-       return impl_->height_;
+       return mImpl->mHeight;
 }
 
 
 void Texture::setMinFilter(GLuint filter)
 {
        // pass through
-       impl_->setMinFilter(filter);
+       mImpl->setMinFilter(filter);
 }
 
 void Texture::setMagFilter(GLuint filter)
 {
        // pass through
-       impl_->setMagFilter(filter);
+       mImpl->setMagFilter(filter);
 }
 
 void Texture::setWrapS(GLuint wrap)
 {
        // pass through
-       impl_->setWrapS(wrap);
+       mImpl->setWrapS(wrap);
 }
 
 void Texture::setWrapT(GLuint wrap)
 {
        // pass through
-       impl_->setWrapT(wrap);
+       mImpl->setWrapT(wrap);
 }
 
 
This page took 0.035586 seconds and 4 git commands to generate.