#ifndef _IMGTEXTURE_H #define _IMGTEXTURE_H #include namespace IMG { // Forward declarations class _IMGExport Texture; namespace boost { void intrusive_ptr_add_ref(Texture * p); void intrusive_ptr_release(Texture * p); }; class _IMGExport Texture { private: long references; friend void boost::intrusive_ptr_add_ref(Texture * p); friend void boost::intrusive_ptr_release(Texture * p); protected: Ogre::Texture *mTexture; Ogre::Material *mMaterial; Ogre::Rectangle2D *mRectangle2D; unsigned int mWidth; unsigned int mHeight; Ogre::String mTextureName; Ogre::ColourValue mAvgColour; Ogre::ColourValue mBackgroundColour; bool mCalculatedAvgColour; Ogre::Camera *mCamera; Ogre::PixelFormat mPixelFormat; public: Texture(); virtual ~Texture(); void setRenderTargetListener(Ogre::RenderTargetListener *renderTargetListener); virtual void debug(); virtual void create(Ogre::String fileName, unsigned int width, unsigned int height, Ogre::PixelFormat pixelFormat, Ogre::Camera *camera, Ogre::ColourValue backgroundColour); Ogre::ColourValue getAvgColour(); void calculateAvgColour(); void setBackgroundColour(Ogre::ColourValue colour); Ogre::ColourValue getBackgroundColour(); virtual void load(Ogre::String folderName, Ogre::String filename); virtual void save(Ogre::String folderName, Ogre::String filename); virtual void update(); void setCorners(Ogre::Real left, Ogre::Real top, Ogre::Real right, Ogre::Real bottom); Ogre::Rectangle2D* getRectangle2D(); Ogre::Vector2 getMinTexCoord(); Ogre::Vector2 getMaxTexCoord(); void setWidth(unsigned int width); unsigned int getWidth(); void setHeight(unsigned int height); unsigned int getHeight(); void setTextureName(Ogre::String textureName); Ogre::String getTextureName(); void setMaterial(Ogre::Material *material); Ogre::Material* getMaterial(); void bind(Ogre::String textureName); void setCamera(Ogre::Camera *camera); void setFormat(Ogre::PixelFormat pixelFormat); }; // class specific addref/release implementation // the two function overloads must be in the boost namespace on most compilers: namespace boost { inline void intrusive_ptr_add_ref(Texture * p) { // increment reference count of object *p ++(p->references); } inline void intrusive_ptr_release(Texture * p) { // decrement reference count, and delete object when reference count reaches 0 if (--(p->references) == 0) delete p; } } // namespace boost typedef ::boost::intrusive_ptr TexturePtr; } #endif