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