| [3341] | 1 | /*! | 
|---|
| [5768] | 2 |  * @file texture.h | 
|---|
 | 3 |  * @brief Contains the texture class, that handles the reading of Images into Texutre-files. | 
|---|
 | 4 |  */ | 
|---|
| [3341] | 5 |  | 
|---|
 | 6 | #ifndef _TEXTURE_H | 
|---|
 | 7 | #define _TEXTURE_H | 
|---|
 | 8 |  | 
|---|
| [5304] | 9 | #include "base_object.h" | 
|---|
| [3548] | 10 |  | 
|---|
| [5768] | 11 | #include "glincl.h" | 
|---|
| [7785] | 12 | #include "count_pointer.h" | 
|---|
| [3548] | 13 |  | 
|---|
| [5768] | 14 | /* Forward Declaration */ | 
|---|
| [5239] | 15 | struct SDL_Surface; | 
|---|
 | 16 |  | 
|---|
| [7785] | 17 |  | 
|---|
 | 18 | class TextureData | 
|---|
 | 19 | { | 
|---|
 | 20 |   public: | 
|---|
 | 21 |     TextureData(); | 
|---|
 | 22 |     ~TextureData(); | 
|---|
 | 23 |  | 
|---|
 | 24 |     inline GLuint getTexture() const { return this->texture; }; | 
|---|
 | 25 |     /** @returns true if texture has alpha, false otherwise */ | 
|---|
 | 26 |     inline bool hasAlpha() const  {return this->bAlpha; } | 
|---|
 | 27 |     /** @returns the stored image of this Texture */ | 
|---|
 | 28 |     const SDL_Surface* const getStoredImage() const { return this->image; }; | 
|---|
 | 29 |  | 
|---|
 | 30 |     bool loadSurface(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D); | 
|---|
 | 31 |  | 
|---|
 | 32 |     bool rebuild(); | 
|---|
 | 33 |  | 
|---|
 | 34 |     bool setSurface(SDL_Surface* newSurface); | 
|---|
| [7788] | 35 |     /** @returns true if the Surface has an Alpha Value. */ | 
|---|
| [8145] | 36 |     bool setAlpha(bool hasAlpha) { this->bAlpha = hasAlpha; return this->bAlpha; }; | 
|---|
| [7785] | 37 |     bool setTexture(GLuint texture); | 
|---|
 | 38 |  | 
|---|
 | 39 |   private: | 
|---|
 | 40 |     GLuint           texture;            //!< The Texture-ID of opengl from this Texture. | 
|---|
 | 41 |     bool             bAlpha;             //!< if the texture has an alpha channel. | 
|---|
 | 42 |     SDL_Surface*     image;              //!< The SDL_Surfce that stores the Texture on it. | 
|---|
 | 43 | }; | 
|---|
 | 44 |  | 
|---|
 | 45 |  | 
|---|
| [3341] | 46 | //! A Class, that reads in Textures from different fileformats. | 
|---|
| [7785] | 47 | class Texture : public BaseObject | 
|---|
 | 48 | { | 
|---|
 | 49 | public: | 
|---|
| [7790] | 50 |   Texture(); | 
|---|
| [7788] | 51 |   Texture(const Texture& texture); | 
|---|
| [8312] | 52 |   Texture(GLenum target, unsigned int width, unsigned int height, unsigned int channels, GLenum type); | 
|---|
| [7785] | 53 |   Texture(const std::string& imageName, GLenum target = GL_TEXTURE_2D); | 
|---|
 | 54 |   Texture(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D); | 
|---|
| [5753] | 55 |  | 
|---|
| [7785] | 56 |   virtual ~Texture(); | 
|---|
| [3341] | 57 |  | 
|---|
| [7785] | 58 |   bool loadImage(const std::string& imageName, GLenum target = GL_TEXTURE_2D); | 
|---|
 | 59 |   bool loadSurface(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D); | 
|---|
 | 60 |   virtual bool rebuild(); | 
|---|
| [5856] | 61 |  | 
|---|
| [7785] | 62 |   /** @returns The textureID of this texture.  */ | 
|---|
 | 63 |   inline GLuint getTexture() const { return this->data->getTexture(); }; | 
|---|
 | 64 |   /** @returns true if texture has alpha, false otherwise */ | 
|---|
 | 65 |   inline bool hasAlpha() const  { return this->data->hasAlpha(); } | 
|---|
 | 66 |   /** @returns the stored image of this Texture */ | 
|---|
 | 67 |   const SDL_Surface* const getStoredImage() const { return this->data->getStoredImage(); }; | 
|---|
| [5856] | 68 |  | 
|---|
| [5857] | 69 |  | 
|---|
| [5858] | 70 |  | 
|---|
| [7785] | 71 |   static void setTextureEnableState(bool texturesEnabled); | 
|---|
 | 72 |   /** @returns true if Textures are enabled */ | 
|---|
 | 73 |   inline static bool getTextureEnableState() { return Texture::texturesEnabled; }; | 
|---|
 | 74 |   // Utility functionality: | 
|---|
 | 75 |   static SDL_Surface* prepareSurface(SDL_Surface* input, bool& hasAlpha); | 
|---|
 | 76 |   static GLuint loadTexToGL (const SDL_Surface* surface, GLenum target = GL_TEXTURE_2D); | 
|---|
| [4466] | 77 |  | 
|---|
| [7785] | 78 | protected: | 
|---|
 | 79 |   bool setSurface(SDL_Surface* newSurface) { return this->data->setSurface(newSurface); }; | 
|---|
 | 80 |   bool setAlpha(bool hasAlpha) { return this->data->setAlpha(hasAlpha); }; | 
|---|
 | 81 |   bool setTexture(GLuint texture) { return this->data->setTexture(texture); }; | 
|---|
| [5857] | 82 |  | 
|---|
| [7785] | 83 | private: | 
|---|
 | 84 |   void init(); | 
|---|
 | 85 |   static void generateTexture(GLuint& texture, GLenum target); | 
|---|
| [5768] | 86 |  | 
|---|
| [7785] | 87 | private: | 
|---|
 | 88 |   CountPointer<TextureData>     data;               //!< The TextureData | 
|---|
 | 89 |   GLclampf                      priority;           //!< the priority of the current texture (used for garphics cards with limited mem) | 
|---|
 | 90 |  | 
|---|
 | 91 |   static bool                   texturesEnabled;    //!< If the Textures are enabled. | 
|---|
 | 92 | }; | 
|---|
 | 93 |  | 
|---|
| [3341] | 94 | #endif /* _TEXTURE_H */ | 
|---|