#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
-#include "Dispatcher.hh"
+#include "Dispatch.hh"
+#include "Engine.hh"
#include "Exception.hh"
#include "Library.hh"
#include "Log.hh"
{
if (mObject)
{
- if (mObject == globalObject_)
+ if (mObject == gObject)
{
- globalObject_ = 0;
+ gObject = 0;
}
glDeleteTextures(1, &mObject);
* to cache it if the client has plenty of RAM.
*/
- void contextRecreated(const Notification* note)
+ void contextRecreated()
{
- mObject = globalObject_ = 0;
+ mObject = gObject = 0;
uploadToGL();
}
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()
}
unloadFromGL();
-
- Dispatcher::getInstance().removeHandler(this);
}
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);
if (!temp)
{
- throw Exception(ErrorCode::UNKNOWN_IMAGE_FORMAT);
+ throw Exception(ErrorCode::UNKNOWN_IMAGE_FORMAT, getName());
}
if (temp->format->BytesPerPixel == 3)
else
{
SDL_FreeSurface(temp);
- throw Exception(ErrorCode::UNKNOWN_IMAGE_FORMAT);
+ throw Exception(ErrorCode::UNKNOWN_IMAGE_FORMAT, getName());
}
mWidth = temp->w;
{
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) :
void Texture::resetBind()
{
glBindTexture(GL_TEXTURE_2D, 0);
- Impl::globalObject_ = 0;
+ Impl::gObject = 0;
}