X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FTexture.cc;h=b778c1ccde0299b1e306d33724457728c563d65a;hp=8bd3c4a3ae00a16657d670fe55620f48b0c99af0;hb=5fa5f117f28922a7e539a432367960c1a61f837d;hpb=16d1a05b0777e97a45c48e2874aa4e5cc791282e diff --git a/src/Moof/Texture.cc b/src/Moof/Texture.cc index 8bd3c4a..b778c1c 100644 --- a/src/Moof/Texture.cc +++ b/src/Moof/Texture.cc @@ -34,6 +34,7 @@ #include #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 +class Texture::Impl : public Mippleton { /** @@ -78,7 +79,7 @@ class Texture::TextureImpl : public Mippleton * 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(name), + explicit Impl(const std::string& name) : + Mippleton(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,20 +385,19 @@ 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)) {} /** * Bind the GL texture for mapping, etc. */ -void Texture::bind() +void Texture::bind() const { // pass through impl_->bind(); @@ -407,20 +408,27 @@ void Texture::bind() * Get the texture object, for the curious. */ -GLuint Texture::getObject() +GLuint Texture::getObject() const { // pass through return impl_->object_; } -unsigned Texture::getWidth() +void Texture::resetBind() +{ + glBindTexture(GL_TEXTURE_2D, 0); + Impl::globalObject_ = 0; +} + + +unsigned Texture::getWidth() const { // pass through return impl_->width_; } -unsigned Texture::getHeight() +unsigned Texture::getHeight() const { // pass through return impl_->height_; @@ -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; }