Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/water/src/lib/graphics/importer/texture.h @ 7783

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

orxonox/trunk: image-data splitted out of Texture

File size: 3.1 KB
RevLine 
[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"
[7783]12#include "count_pointer.h"
[3548]13
[5768]14/* Forward Declaration */
[5239]15struct SDL_Surface;
16
[7783]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
33
34    bool rebuild();
35
36    bool setSurface(SDL_Surface* newSurface);
37    bool setAlpha(bool hasAlpha) { this->bAlpha = hasAlpha; };
38    bool setTexture(GLuint texture);
39
40  private:
41    GLuint           texture;            //!< The Texture-ID of opengl from this Texture.
42    bool             bAlpha;             //!< if the texture has an alpha channel.
43    SDL_Surface*     image;              //!< The SDL_Surfce that stores the Texture on it.
44};
45
46
[3341]47//! A Class, that reads in Textures from different fileformats.
[7783]48class Texture : public BaseObject
49{
50public:
[3905]51
[7783]52public:
53  Texture(GLenum target = GL_TEXTURE_2D);
54  Texture(const std::string& imageName, GLenum target = GL_TEXTURE_2D);
55  Texture(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D);
[5753]56
[7783]57  virtual ~Texture();
[3341]58
[7783]59  bool loadImage(const std::string& imageName, GLenum target = GL_TEXTURE_2D);
60  bool loadSurface(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D);
61  virtual bool rebuild();
[5856]62
[7783]63  /** @returns The textureID of this texture.  */
64  inline GLuint getTexture() const { return this->data->getTexture(); };
65  /** @returns true if texture has alpha, false otherwise */
66  inline bool hasAlpha() const  { return this->data->hasAlpha(); }
67  /** @returns the stored image of this Texture */
68  const SDL_Surface* const getStoredImage() const { return this->data->getStoredImage(); };
[5856]69
[5857]70
[5858]71
[7783]72  static void setTextureEnableState(bool texturesEnabled);
73  /** @returns true if Textures are enabled */
74  inline static bool getTextureEnableState() { return Texture::texturesEnabled; };
[4466]75
[7783]76  // Utility functionality:
77  static SDL_Surface* prepareSurface(SDL_Surface* input, bool& hasAlpha);
78  static GLuint loadTexToGL (const SDL_Surface* surface, GLenum target = GL_TEXTURE_2D);
[3341]79
[5857]80
[7783]81protected:
82  bool setSurface(SDL_Surface* newSurface) { return this->data->setSurface(newSurface); };
83  bool setAlpha(bool hasAlpha) { return this->data->setAlpha(hasAlpha); };
84  bool setTexture(GLuint texture) { return this->data->setTexture(texture); };
[5768]85
[7783]86private:
87  void init();
88  static void generateTexture(GLuint& texture, GLenum target);
89
90private:
91  CountPointer<TextureData>     data;               //!< The TextureData
92  GLclampf                      priority;           //!< the priority of the current texture (used for garphics cards with limited mem)
93
94  static bool                   texturesEnabled;    //!< If the Textures are enabled.
95};
96
[3341]97#endif /* _TEXTURE_H */
Note: See TracBrowser for help on using the repository browser.