Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
glfTexture2D.hh
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2008, 2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10  BIAS is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 2.1 of the License, or
13  (at your option) any later version.
14 
15  BIAS is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with BIAS; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */
24 
25 #ifndef __glfTexture2D_hh__
26 #define __glfTexture2D_hh__
27 
28 #include "glfTexture.hh"
29 
30 namespace BIAS {
31 
32  /**
33  * \brief A 2D texture.
34  *
35  * \note The <code>Allocate</code> methods need not be called, if one
36  * of the <code>Upload...</code> methods is used.
37  * \ingroup g_openglframework
38  * \author jkollmann
39  */
40  class BIASOpenGLFramework_EXPORT glfTexture2D : public glfTexture {
41  public:
42  glfTexture2D();
43 
44  /** Convenience wrapper **/
45  void Set(GLenum minFilter = GL_NEAREST,
46  GLenum magFilter = GL_NEAREST,
47  GLenum wrapS = GL_CLAMP,
48  GLenum wrapT = GL_CLAMP,
49  GLint textureNr = GL_TEXTURE0);
50 
51  /**
52  * Uploads a BIAS::Image to a mipmap of the texture.
53  * If the given <code>internalFormat</code> is 0, the internal format is
54  * chosen based on the storage type and color model of the image.
55  *
56  * \attention The uploaded texture will contain the image upside down
57  * according to the OpenGL specifications. You can fix this by either
58  * flipping the image before uploading it, or by adjusting the texture
59  * coordinates.
60  */
61  void UploadImage(const BIAS::ImageBase& image,
62  GLenum internalFormat = 0,
63  int mipmap = 0);
64 
65  /**
66  * Uploads an image loaded from a file to a mipmap of the texture.
67  * If the given <code>internalFormat</code> is 0, the internal format is
68  * chosen based on the storage type and color model of the image.
69  *
70  * \attention The uploaded texture will contain the image upside down
71  * according to the OpenGL specifications. You can fix this by either
72  * flipping the image before uploading it, or by adjusting the texture
73  * coordinates.
74  */
75  void UploadImageFromFile(const std::string& fileName,
76  GLenum internalFormat = 0,
77  int mipmap = 0);
78 
79  /**
80  * Creates a texture with undefined content. This can be used
81  * for textures in conjuction with framebuffer objects.
82  *
83  * See <code>glTexImage2D</code> documentation for a list of
84  * valid internal formats.
85  */
86  void Allocate(int width, int height,
87  GLenum internalFormat, int mipmap = 0);
88 
89  /**
90  * Creates a texture with undefined content. This can be used
91  * for textures in conjuction with framebuffer objects.
92  *
93  * The internal format is chosen based on the given BIAS storage
94  * type and color model.
95  */
96  void Allocate(int width, int height,
97  ImageBase::EStorageType storageType,
98  ImageBase::EColorModel colorModel,
99  int mipmap = 0);
100 
101  /**
102  * Copies the pixels of a mipmap of the texture to a BIAS::ImageBase.
103  * The image will be initialized with the size of the texture and the appropriate
104  * number of channels based on the textures internal format.
105  *
106  * \attention The given image must have a valid storage type. The easiest way
107  * is to pass a BIAS::Image<T>. Storage type ST_double is not supported.
108  *
109  * \attention The color model of the image is not modified! (TODO?)
110  *
111  * \attention The returned image will contain the texture upside down
112  * according to the OpenGL specifications. You can fix this by either
113  * flipping the image after calling this method or by rendering the
114  * scene upside down.
115  */
116  void CopyToImage(ImageBase& image, int mipmap = 0);
117 
118  /**
119  * Uses CopyToImage to dump a Unsigned Char image comprising RGBA channels to file.
120  */
121  void DumpUC_RGBA(const std::string& fileName);
122 
123  /**
124  * Copies the pixels of a mipmap of the texture to a BIAS::ImageBase
125  * and interprets the texture using the given format. Can be used to
126  * only copy one channel of the texture to an image.
127  * Valid formats are:
128  * GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA,
129  * GL_RGB, GL_BGR, GL_RGBA, GL_BGRA,
130  * GL_LUMINANCE, GL_LUMINANCE_ALPHA
131  *
132  * \attention The returned image will contain the texture upside down
133  * according to the OpenGL specifications. You can fix this by either
134  * flipping the image after calling this method or by rendering the
135  * scene upside down.
136  */
137  void CopyChannelsToImage(ImageBase& image, GLenum format, int mipmap = 0);
138 
139  /**
140  * Returns the width of a mipmap of the texture.
141  */
142  int GetWidth(int mipmap = 0) const;
143 
144  /**
145  * Returns the height of a mipmap of the texture.
146  */
147  int GetHeight(int mipmap = 0) const;
148  private:
149  /** An intuitive assignment operator should generate a copy, as long as nobody is willing to implement
150  * the generation of a copy in gl controlled memory this operator cannot be used.
151  */
152  glfTexture2D& operator=(const glfTexture2D& b);
153 
154  /** An intuitive copy constructor should generate a copy, as long as nobody is willing to implement
155  * the generation of a copy in gl controlled memory this constructor cannot be used.
156  */
157  glfTexture2D(const glfTexture2D& t);
158  };
159 
160 } // namespace BIAS
161 
162 #endif // __glfTexture2D_hh__
EColorModel
These are the most often used color models.
Definition: ImageBase.hh:127
A 2D texture.
Definition: glfTexture2D.hh:40
Base class for textures.
Definition: glfTexture.hh:42
This is the base class for images in BIAS.
Definition: ImageBase.hh:102