1 | /*! |
---|
2 | * @file texture.h |
---|
3 | * @brief Contains the texture class, that handles the reading of Images into Texutre-files. |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef _TEXTURE_H |
---|
7 | #define _TEXTURE_H |
---|
8 | |
---|
9 | #include "base_object.h" |
---|
10 | |
---|
11 | #include "glincl.h" |
---|
12 | #include "count_pointer.h" |
---|
13 | #include "texture_data.h" |
---|
14 | |
---|
15 | |
---|
16 | /* Forward Declaration */ |
---|
17 | struct SDL_Surface; |
---|
18 | |
---|
19 | //! A Class, that reads in Textures from different fileformats. |
---|
20 | class Texture : public BaseObject |
---|
21 | { |
---|
22 | public: |
---|
23 | Texture(); |
---|
24 | Texture(const Texture& texture); |
---|
25 | Texture(GLenum target, unsigned int width, unsigned int height, unsigned int channels, GLenum type); |
---|
26 | Texture(const std::string& imageName, GLenum target = GL_TEXTURE_2D); |
---|
27 | Texture(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D); |
---|
28 | |
---|
29 | virtual ~Texture(); |
---|
30 | |
---|
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(); |
---|
34 | |
---|
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(); }; |
---|
41 | |
---|
42 | |
---|
43 | |
---|
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); |
---|
50 | |
---|
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); }; |
---|
55 | |
---|
56 | private: |
---|
57 | void init(); |
---|
58 | static void generateTexture(GLuint& texture, GLenum target); |
---|
59 | |
---|
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 | |
---|
67 | #endif /* _TEXTURE_H */ |
---|