Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain.old/src/lib/graphics/importer/texture.h @ 9337

Last change on this file since 9337 was 8376, checked in by bensch, 19 years ago

orxonox/trunk: no more seg-fault when copying a Texture

File size: 2.4 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#include "texture_data.h"
14
15
16/* Forward Declaration */
17struct SDL_Surface;
18
19//! A Class, that reads in Textures from different fileformats.
20class Texture : public BaseObject
21{
22public:
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  Texture& operator=(const Texture& texture);
30
31  virtual ~Texture();
32
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();
36
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(); };
43
44
45
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);
52
53protected:
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); };
57
58private:
59  void init();
60  static void generateTexture(GLuint& texture, GLenum target);
61
62private:
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
69#endif /* _TEXTURE_H */
Note: See TracBrowser for help on using the repository browser.