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