Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
glfCubeMap.hh
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2003-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 __glfCubeMap_hh__
26 #define __glfCubeMap_hh__
27 
28 #include "glfTexture.hh"
29 
30 namespace BIAS {
31 
32  /**
33  * \brief A cube map 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 glfCubeMap : public glfTexture {
41  public:
42  glfCubeMap();
43 
44  /**
45  * Uploads a BIAS::Image to a mipmap of one side of the cube map.
46  * If the given <code>internalFormat</code> is 0, the internal format is
47  * chosen based on the storage type and color model of the image.
48  *
49  * \attention The uploaded texture will contain the image upside down
50  * according to the OpenGL specifications. You can fix this by either
51  * flipping the image before uploading it, or by adjusting the texture
52  * coordinates.
53  *
54  * The 'target' defines the side of the cube map, and must be one of
55  * the following values:
56  * GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
57  * GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
58  * GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
59  */
60  void UploadImage(GLenum target, const BIAS::ImageBase& image,
61  GLenum internalFormat = 0,
62  int mipmap = 0);
63 
64  /**
65  * Uploads an image loaded from a file to a mipmap of one side of the cube
66  * map. If the given <code>internalFormat</code> is 0, the internal format
67  * is chosen based on the storage type and color model of the image.
68  *
69  * \attention The uploaded texture will contain the image upside down
70  * according to the OpenGL specifications. You can fix this by either
71  * flipping the image before uploading it, or by adjusting the texture
72  * coordinates.
73  */
74  void UploadImageFromFile(GLenum target, const std::string& fileName,
75  GLenum internalFormat = 0,
76  int mipmap = 0);
77 
78  /**
79  * Creates a cube map with undefined content. This can be used
80  * for cube maps in conjuction with framebuffer objects.
81  *
82  * See <code>glTexImage2D</code> documentation for a list of
83  * valid internal formats.
84  */
85  void Allocate(int width, int height,
86  GLenum internalFormat, int mipmap = 0);
87 
88  /**
89  * Creates a cube map with undefined content. This can be used
90  * for cube maps in conjuction with framebuffer objects.
91  *
92  * The internal format is chosen based on the given BIAS storage
93  * type and color model.
94  */
95  void Allocate(int width, int height,
96  ImageBase::EStorageType storageType,
97  ImageBase::EColorModel colorModel,
98  int mipmap = 0);
99 
100  /**
101  * Copies the pixels of a mipmap of a side of the cube map to a BIAS::ImageBase.
102  * The image will be initialized with the size of the texture and the appropriate
103  * number of channels based on the textures internal format.
104  *
105  * \attention The given image must have a valid storage type. The easiest way
106  * is to pass a BIAS::Image<T>. Storage type ST_double is not supported.
107  *
108  * \attention The color model of the image is not modified! (TODO?)
109  *
110  * \attention The returned image will contain the texture upside down
111  * according to the OpenGL specifications. You can fix this by either
112  * flipping the image after calling this method or by rendering the
113  * scene upside down.
114  */
115  void CopyToImage(GLenum target, ImageBase& image, int mipmap = 0);
116 
117  /**
118  * Copies the pixels of a mipmap of a side of the cube map to a BIAS::ImageBase
119  * and interprets the texture using the given format. Can be used to
120  * only copy one channel of the texture to an image.
121  * Valid formats are:
122  * GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA,
123  * GL_RGB, GL_BGR, GL_RGBA, GL_BGRA,
124  * GL_LUMINANCE, GL_LUMINANCE_ALPHA
125  *
126  * \attention The returned image will contain the texture upside down
127  * according to the OpenGL specifications. You can fix this by either
128  * flipping the image after calling this method or by rendering the
129  * scene upside down.
130  */
131  void CopyChannelsToImage(GLenum target, ImageBase& image,
132  GLenum format, int mipmap = 0);
133 
134  /**
135  * Returns the width of a mipmap of each side of the cube map.
136  */
137  int GetWidth(int mipmap = 0) const;
138 
139  /**
140  * Returns the height of a mipmap of each side of the cube map.
141  */
142  int GetHeight(int mipmap = 0) const;
143  };
144 
145 } // namespace BIAS
146 
147 #endif // __glfCubeMap_hh__
EColorModel
These are the most often used color models.
Definition: ImageBase.hh:127
A cube map texture.
Definition: glfCubeMap.hh:40
Base class for textures.
Definition: glfTexture.hh:42
This is the base class for images in BIAS.
Definition: ImageBase.hh:102