Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GLFormatInfo.hh
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40  \*===========================================================================*/
41 
42 /*===========================================================================*\
43 * *
44  * $Revision$ *
45  * $LastChangedBy$ *
46  * $Date$ *
47  * *
48  \*===========================================================================*/
49 
50 
51 
52 //=============================================================================
53 //
54 // OpenGL texture format info
55 //
56 //=============================================================================
57 
58 
59 #ifndef GL_FORMATINFO_HH
60 #define GL_FORMATINFO_HH
61 
62 
63 //== INCLUDES =================================================================
64 
65 // GL
66 #include <ACG/GL/gl.hh>
67 
68 // C++
69 #include <map>
70 
71 
72 //== NAMESPACES ===============================================================
73 
74 namespace ACG {
75 
76 //== CLASS DEFINITION =========================================================
77 
78 class ACGDLLEXPORT GLFormatInfo
79 {
80 public:
81  GLFormatInfo(GLenum _internalFormat);
82 
83  GLFormatInfo();
84  ~GLFormatInfo();
85 
86  // size in bytes of the i'th channel
87  int channelSize(int i = 0) const {assert(i >= 0 && i < channelCount_); return channelBits_[i] >> 3;}
88 
89  // size in bits of the i'th channel
90  int channelBits(int i) const {assert(i >= 0 && i < channelCount_); return channelBits_[i];}
91 
92  // number of channels
93  int channelCount() const {return channelCount_;}
94 
95  // size in bytes of one element = num channels * channel size
96  int elemSize() const {return bpp_ >> 3;}
97 
98  // bits per pixel
99  int bpp() const {return bpp_;}
100 
101  // get internal format
102  GLenum internalFormat() const {return internalFormat_;}
103 
104  // get a fitting (external) format for the internalfmt, ie. GL_RED, GL_RGBA, GL_RGBA_INTEGER etc.
105  GLenum format() const {return format_;}
106 
107  // get a fitting data-type for the internalfmt, ie GL_UNSIGNED_BYTE, GL_FLOAT etc.
108  GLenum type() const {return type_;}
109 
110  // some formats such as GL_RGBA, GL_R8 etc. are normalized to [0,1] when sampled
111  bool isNormalized() const {return normalized_;}
112 
113  // data can be one of 3 unsized base types: floating pt, signed integer or unsigned integer
114  enum BaseType
115  {
116  FloatingPt,
117  SignedInt,
118  UnsignedInt
119  };
120 
121  bool isFloat() const {return baseType_ == FloatingPt;}
122  bool isUint() const {return baseType_ == UnsignedInt;}
123  bool isInt() const {return baseType_ == SignedInt;}
124 
125  bool isValid() const {return bpp_ != 0;}
126 
127  BaseType baseType() const {return baseType_;}
128 
129  // return string of the sized internalFormat, ie. GL_RGBA8, GL_RG32F etc.
130  const char* sizedFormatString() const {return sizedName_;}
131 
132 private:
133  GLFormatInfo( GLenum _intfmt, GLenum _fmt, GLenum _type, int _r, int _g, int _b, int _a, BaseType _bt, bool _nrm);
134  static void registerFmt(GLenum _intfmt, GLenum _fmt, GLenum _type, int _r, int _g, int _b, int _a, BaseType _bt, bool _nrm);
135 
136  GLenum internalFormat_,
137  format_,
138  type_;
139 
140  int channelBits_[4];
141 
142  int channelCount_,
143  bpp_;
144 
145  // 0 -> floating point, 1 -> unsigned integer, 2 -> signed integer
146  BaseType baseType_;
147 
148  bool normalized_;
149 
150  char sizedName_[32];
151 
152  // map from internalfmt to info
153  static std::map<GLenum, GLFormatInfo> formatMap_;
154 };
155 
156 
157 //=============================================================================
158 } // namespace ACG
159 //=============================================================================
160 #endif // GL_FORMATINFO_HH defined
161 //=============================================================================
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51