Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/importer/texture.h @ 7789

Last change on this file since 7789 was 7788, checked in by bensch, 18 years ago

orxonox/trunk: Material handles references… lets see if this works

File size: 3.2 KB
Line 
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
14/* Forward Declaration */
15struct SDL_Surface;
16
17
18class 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);
35    /** @returns true if the Surface has an Alpha Value. */
36    bool setAlpha(bool hasAlpha) { this->bAlpha = hasAlpha; };
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
46//! A Class, that reads in Textures from different fileformats.
47class Texture : public BaseObject
48{
49public:
50  Texture(const Texture& texture);
51  Texture(GLenum target = GL_TEXTURE_2D);
52  Texture(const std::string& imageName, GLenum target = GL_TEXTURE_2D);
53  Texture(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D);
54
55  virtual ~Texture();
56
57  bool loadImage(const std::string& imageName, GLenum target = GL_TEXTURE_2D);
58  bool loadSurface(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D);
59  virtual bool rebuild();
60
61  /** @returns The textureID of this texture.  */
62  inline GLuint getTexture() const { return this->data->getTexture(); };
63  /** @returns true if texture has alpha, false otherwise */
64  inline bool hasAlpha() const  { return this->data->hasAlpha(); }
65  /** @returns the stored image of this Texture */
66  const SDL_Surface* const getStoredImage() const { return this->data->getStoredImage(); };
67
68
69
70  static void setTextureEnableState(bool texturesEnabled);
71  /** @returns true if Textures are enabled */
72  inline static bool getTextureEnableState() { return Texture::texturesEnabled; };
73  // Utility functionality:
74  static SDL_Surface* prepareSurface(SDL_Surface* input, bool& hasAlpha);
75  static GLuint loadTexToGL (const SDL_Surface* surface, GLenum target = GL_TEXTURE_2D);
76
77protected:
78  bool setSurface(SDL_Surface* newSurface) { return this->data->setSurface(newSurface); };
79  bool setAlpha(bool hasAlpha) { return this->data->setAlpha(hasAlpha); };
80  bool setTexture(GLuint texture) { return this->data->setTexture(texture); };
81
82private:
83  void init();
84  static void generateTexture(GLuint& texture, GLenum target);
85
86private:
87  CountPointer<TextureData>     data;               //!< The TextureData
88  GLclampf                      priority;           //!< the priority of the current texture (used for garphics cards with limited mem)
89
90  static bool                   texturesEnabled;    //!< If the Textures are enabled.
91};
92
93#endif /* _TEXTURE_H */
Note: See TracBrowser for help on using the repository browser.