[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" |
---|
[8363] | 13 | #include "texture_data.h" |
---|
[3548] | 14 | |
---|
[8363] | 15 | |
---|
[5768] | 16 | /* Forward Declaration */ |
---|
[5239] | 17 | struct SDL_Surface; |
---|
| 18 | |
---|
[3341] | 19 | //! A Class, that reads in Textures from different fileformats. |
---|
[7785] | 20 | class Texture : public BaseObject |
---|
| 21 | { |
---|
[9715] | 22 | ObjectListDeclaration(Texture); |
---|
[7785] | 23 | public: |
---|
[7790] | 24 | Texture(); |
---|
[7788] | 25 | Texture(const Texture& texture); |
---|
[8312] | 26 | Texture(GLenum target, unsigned int width, unsigned int height, unsigned int channels, GLenum type); |
---|
[7785] | 27 | Texture(const std::string& imageName, GLenum target = GL_TEXTURE_2D); |
---|
| 28 | Texture(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D); |
---|
[5753] | 29 | |
---|
[8376] | 30 | Texture& operator=(const Texture& texture); |
---|
[9718] | 31 | Texture& operator=(const TextureData::Pointer& textureDataPointer); |
---|
[8376] | 32 | |
---|
[7785] | 33 | virtual ~Texture(); |
---|
[3341] | 34 | |
---|
[7785] | 35 | bool loadImage(const std::string& imageName, GLenum target = GL_TEXTURE_2D); |
---|
| 36 | bool loadSurface(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D); |
---|
| 37 | virtual bool rebuild(); |
---|
[5856] | 38 | |
---|
[7785] | 39 | /** @returns The textureID of this texture. */ |
---|
| 40 | inline GLuint getTexture() const { return this->data->getTexture(); }; |
---|
| 41 | /** @returns true if texture has alpha, false otherwise */ |
---|
| 42 | inline bool hasAlpha() const { return this->data->hasAlpha(); } |
---|
| 43 | /** @returns the stored image of this Texture */ |
---|
| 44 | const SDL_Surface* const getStoredImage() const { return this->data->getStoredImage(); }; |
---|
[5856] | 45 | |
---|
[5857] | 46 | |
---|
[5858] | 47 | |
---|
[7785] | 48 | static void setTextureEnableState(bool texturesEnabled); |
---|
| 49 | /** @returns true if Textures are enabled */ |
---|
| 50 | inline static bool getTextureEnableState() { return Texture::texturesEnabled; }; |
---|
| 51 | // Utility functionality: |
---|
| 52 | static SDL_Surface* prepareSurface(SDL_Surface* input, bool& hasAlpha); |
---|
| 53 | static GLuint loadTexToGL (const SDL_Surface* surface, GLenum target = GL_TEXTURE_2D); |
---|
[4466] | 54 | |
---|
[7785] | 55 | protected: |
---|
| 56 | bool setSurface(SDL_Surface* newSurface) { return this->data->setSurface(newSurface); }; |
---|
| 57 | bool setAlpha(bool hasAlpha) { return this->data->setAlpha(hasAlpha); }; |
---|
| 58 | bool setTexture(GLuint texture) { return this->data->setTexture(texture); }; |
---|
[5857] | 59 | |
---|
[7785] | 60 | private: |
---|
| 61 | void init(); |
---|
| 62 | static void generateTexture(GLuint& texture, GLenum target); |
---|
[5768] | 63 | |
---|
[7785] | 64 | private: |
---|
[9718] | 65 | TextureData::Pointer data; //!< The TextureData |
---|
[7785] | 66 | GLclampf priority; //!< the priority of the current texture (used for garphics cards with limited mem) |
---|
| 67 | |
---|
| 68 | static bool texturesEnabled; //!< If the Textures are enabled. |
---|
| 69 | }; |
---|
| 70 | |
---|
[3341] | 71 | #endif /* _TEXTURE_H */ |
---|