]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Texture.cc
improved new vorbisfile compatibility
[chaz/yoink] / src / Moof / Texture.cc
index 128d54f3d7c8750b2087859a22b81aa6c5f18dc6..b778c1ccde0299b1e306d33724457728c563d65a 100644 (file)
@@ -34,6 +34,7 @@
 #include <SDL/SDL_image.h>
 
 #include "Dispatcher.hh"
+#include "Log.hh"
 #include "Mippleton.hh"
 #include "OpenGL.hh"
 #include "Texture.hh"
@@ -51,7 +52,7 @@ namespace Mf {
  * objects and avoid having duplicate textures loaded to GL.
  */
 
-class Texture::TextureImpl : public Mippleton<TextureImpl>
+class Texture::Impl : public Mippleton<Impl>
 {
 
        /**
@@ -78,7 +79,7 @@ class Texture::TextureImpl : public Mippleton<TextureImpl>
         * to cache it if the client has plenty of RAM.
         */
 
-       void contextRecreated(const Notification& note)
+       void contextRecreated(const Notification* note)
        {
                object_ = globalObject_ = 0;
                uploadToGL();
@@ -129,8 +130,8 @@ public:
         * Construction is initialization.
         */
 
-       explicit TextureImpl(const std::string& name) :
-               Mippleton<TextureImpl>(name),
+       explicit Impl(const std::string& name) :
+               Mippleton<Impl>(name),
                surface_(0),
                width_(0),
                height_(0),
@@ -144,11 +145,11 @@ public:
                loadFromFile();
 
                // we want to know when the GL context is recreated
-               Dispatcher::instance().addHandler("video.context_recreated",
-                               boost::bind(&TextureImpl::contextRecreated, this, _1), this);
+               Dispatcher::getInstance().addHandler("video.context_recreated",
+                               boost::bind(&Impl::contextRecreated, this, _1), this);
        }
 
-       ~TextureImpl()
+       ~Impl()
        {
                if (surface_)
                {
@@ -157,7 +158,7 @@ public:
 
                unloadFromGL();
 
-               Dispatcher::instance().removeHandler(this);
+               Dispatcher::getInstance().removeHandler(this);
        }
 
 
@@ -239,11 +240,12 @@ public:
        {
                SDL_Surface* surface;
 
-               surface = IMG_Load(Texture::getPathToResource(getName()).c_str());
+               surface = IMG_Load(Texture::getPath(getName()).c_str());
 
                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,7 +253,7 @@ public:
 
                if (!temp)
                {
-                       throw Texture::Exception("uploading to opengl failed");
+                       throw Exception(Exception::OPENGL_ERROR);
                }
 
                if (temp->format->BytesPerPixel == 3)
@@ -265,7 +267,7 @@ public:
                else
                {
                        SDL_FreeSurface(temp);
-                       throw Texture::Exception("incompatible color mode");
+                       throw Exception(Exception::BAD_IMAGE_FORMAT);
                }
 
                width_ = temp->w;
@@ -383,13 +385,12 @@ public:
        static GLuint   globalObject_;  ///< Global GL texture handle.
 };
 
-GLuint Texture::TextureImpl::globalObject_ = 0;
+GLuint Texture::Impl::globalObject_ = 0;
 
 
 Texture::Texture(const std::string& name) :
        // pass through
-       impl_(Texture::TextureImpl::retain(name), &Texture::TextureImpl::release)
-{}
+       impl_(Texture::Impl::getInstance(name)) {}
 
 
 /**
@@ -414,6 +415,13 @@ GLuint Texture::getObject() const
 }
 
 
+void Texture::resetBind()
+{
+       glBindTexture(GL_TEXTURE_2D, 0);
+       Impl::globalObject_ = 0;
+}
+
+
 unsigned Texture::getWidth() const
 {
        // pass through
@@ -452,10 +460,10 @@ void Texture::setWrapT(GLuint wrap)
 }
 
 
-std::string Texture::getPathToResource(const std::string& name)
+std::string Texture::getPath(const std::string& name)
 {
-       // TODO named resources must be png for now
-       return Resource::getPathToResource("textures/" + name + ".png");
+       std::string path = Resource::getPath("textures/" + name + ".png");
+       return path;
 }
 
 
This page took 0.021286 seconds and 4 git commands to generate.