X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FTexture.cc;h=a701424d5dd7588537dce06511cfb9e1f0fa6c1e;hp=341b5598f13f9b8c7d42f93643f26ca3f4727568;hb=e495074443d9fd7bc16137084cf9de3d031b75c4;hpb=c9e20ac06383b20ceb5404c9237e319c2e90d157 diff --git a/src/Moof/Texture.cc b/src/Moof/Texture.cc index 341b559..a701424 100644 --- a/src/Moof/Texture.cc +++ b/src/Moof/Texture.cc @@ -33,7 +33,8 @@ #include #include -#include "Dispatcher.hh" +#include "Dispatch.hh" +#include "Engine.hh" #include "Exception.hh" #include "Library.hh" #include "Log.hh" @@ -64,9 +65,9 @@ class Texture::Impl : public Library { if (mObject) { - if (mObject == globalObject_) + if (mObject == gObject) { - globalObject_ = 0; + gObject = 0; } glDeleteTextures(1, &mObject); @@ -80,9 +81,9 @@ class Texture::Impl : public Library * to cache it if the client has plenty of RAM. */ - void contextRecreated(const Notification* note) + void contextRecreated() { - mObject = globalObject_ = 0; + mObject = gObject = 0; uploadToGL(); } @@ -143,11 +144,16 @@ public: mWrapT(GL_CLAMP), mObject(0) { - loadFromFile(); + // make sure the engine is initialized + Engine& engine = Engine::getInstance(); + VideoP video = engine.getVideo(); + ASSERT(video && "cannot load textures without a current video context"); // we want to know when the GL context is recreated - Dispatcher::getInstance().addHandler("video.context_recreated", - boost::bind(&Impl::contextRecreated, this, _1), this); + mDispatchHandler = engine.addHandler("video.newcontext", + boost::bind(&Impl::contextRecreated, this)); + + loadFromFile(); } ~Impl() @@ -158,8 +164,6 @@ public: } unloadFromGL(); - - Dispatcher::getInstance().removeHandler(this); } @@ -246,7 +250,7 @@ public: if (!surface) { logWarning("texture not found: %s", getName().c_str()); - throw Exception(ErrorCode::FILE_NOT_FOUND, getName().c_str()); + throw Exception(ErrorCode::FILE_NOT_FOUND, getName()); } SDL_Surface* temp = prepareImageForGL(surface); @@ -254,7 +258,7 @@ public: if (!temp) { - throw Exception(ErrorCode::UNKNOWN_IMAGE_FORMAT); + throw Exception(ErrorCode::UNKNOWN_IMAGE_FORMAT, getName()); } if (temp->format->BytesPerPixel == 3) @@ -268,7 +272,7 @@ public: else { SDL_FreeSurface(temp); - throw Exception(ErrorCode::UNKNOWN_IMAGE_FORMAT); + throw Exception(ErrorCode::UNKNOWN_IMAGE_FORMAT, getName()); } mWidth = temp->w; @@ -366,29 +370,31 @@ public: { uploadToGL(); } - if (mObject != globalObject_) + if (mObject != gObject) { glBindTexture(GL_TEXTURE_2D, mObject); - globalObject_ = mObject; + gObject = mObject; } } - SDL_Surface* mContext; - unsigned mWidth; ///< Horizontal dimension of the image. - unsigned mHeight; ///< Vertical dimension. + SDL_Surface* mContext; + unsigned mWidth; ///< Horizontal dimension of the image. + unsigned mHeight; ///< Vertical dimension. + + GLuint mMode; ///< GL_RGB or GL_RGBA. + GLuint mMinFilter; ///< Minifcation filter. + GLuint mMagFilter; ///< Magnification filter. + GLuint mWrapS; ///< Wrapping behavior horizontally. + GLuint mWrapT; ///< 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 mObject; ///< GL texture handle. + static GLuint gObject; ///< Global GL texture handle. - GLuint mObject; ///< GL texture handle. - static GLuint globalObject_; ///< Global GL texture handle. + Dispatch::Handler mDispatchHandler; }; -GLuint Texture::Impl::globalObject_ = 0; +GLuint Texture::Impl::gObject = 0; Texture::Texture(const std::string& name) : @@ -421,7 +427,7 @@ GLuint Texture::getObject() const void Texture::resetBind() { glBindTexture(GL_TEXTURE_2D, 0); - Impl::globalObject_ = 0; + Impl::gObject = 0; }