Developer Documentation
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 //
45 // OpenGL texture format info
46 //
47 //=============================================================================
48 
49 
50 #ifndef GL_FORMATINFO_HH
51 #define GL_FORMATINFO_HH
52 
53 
54 //== INCLUDES =================================================================
55 
56 // GL
57 #include <ACG/GL/acg_glew.hh>
58 #include <ACG/GL/gl.hh>
59 
60 // C++
61 #include <map>
62 
63 
64 //== NAMESPACES ===============================================================
65 
66 namespace ACG {
67 
68 //== CLASS DEFINITION =========================================================
69 
70 class ACGDLLEXPORT GLFormatInfo
71 {
72 public:
73  explicit GLFormatInfo(GLenum _internalFormat);
74 
75  GLFormatInfo();
76  ~GLFormatInfo();
77 
78  // size in bytes of the i'th channel
79  int channelSize(int i = 0) const {assert(i >= 0 && i < channelCount_); return channelBits_[i] >> 3;}
80 
81  // size in bits of the i'th channel
82  int channelBits(int i) const {assert(i >= 0 && i < channelCount_); return channelBits_[i];}
83 
84  // number of channels
85  int channelCount() const {return channelCount_;}
86 
87  // size in bytes of one element = num channels * channel size
88  int elemSize() const {return bpp_ >> 3;}
89 
90  // bits per pixel
91  int bpp() const {return bpp_;}
92 
93  // get internal format
94  GLenum internalFormat() const {return internalFormat_;}
95 
96  // get a fitting (external) format for the internalfmt, ie. GL_RED, GL_RGBA, GL_RGBA_INTEGER etc.
97  GLenum format() const {return format_;}
98 
99  // get a fitting data-type for the internalfmt, ie GL_UNSIGNED_BYTE, GL_FLOAT etc.
100  GLenum type() const {return type_;}
101 
102  // some formats such as GL_RGBA, GL_R8 etc. are normalized to [0,1] when sampled
103  bool isNormalized() const {return normalized_;}
104 
105  // data can be one of 3 unsized base types: floating pt, signed integer or unsigned integer
106  enum BaseType
107  {
108  FloatingPt,
109  SignedInt,
110  UnsignedInt
111  };
112 
113  bool isFloat() const {return baseType_ == FloatingPt;}
114  bool isUint() const {return baseType_ == UnsignedInt;}
115  bool isInt() const {return baseType_ == SignedInt;}
116 
117  bool isValid() const {return bpp_ != 0;}
118 
119  BaseType baseType() const {return baseType_;}
120 
121  // return string of the sized internalFormat, ie. GL_RGBA8, GL_RG32F etc.
122  const char* sizedFormatString() const {return sizedName_;}
123 
124 private:
125  GLFormatInfo( GLenum _intfmt, GLenum _fmt, GLenum _type, int _r, int _g, int _b, int _a, BaseType _bt, bool _nrm);
126  static void registerFmt(GLenum _intfmt, GLenum _fmt, GLenum _type, int _r, int _g, int _b, int _a, BaseType _bt, bool _nrm);
127 
128  GLenum internalFormat_,
129  format_,
130  type_;
131 
132  int channelBits_[4];
133 
134  int channelCount_,
135  bpp_;
136 
137  // 0 -> floating point, 1 -> unsigned integer, 2 -> signed integer
138  BaseType baseType_;
139 
140  bool normalized_;
141 
142  char sizedName_[32];
143 
144  // map from internalfmt to info
145  static std::map<GLenum, GLFormatInfo> formatMap_;
146 };
147 
148 
149 //=============================================================================
150 } // namespace ACG
151 //=============================================================================
152 #endif // GL_FORMATINFO_HH defined
153 //=============================================================================
Namespace providing different geometric functions concerning angles.