1 /*
2     Copyright (c) 2008-2009 NetAllied Systems GmbH
3 
4     This file is part of COLLADAStreamWriter.
5 
6     Licensed under the MIT Open Source License,
7     for details please see LICENSE file or the website
8     http://www.opensource.org/licenses/mit-license.php
9 */
10 
11 #ifndef __COLLADASTREAMWRITER_FORMAT_HINT_H__
12 #define __COLLADASTREAMWRITER_FORMAT_HINT_H__
13 
14 #include "COLLADASWPrerequisites.h"
15 #include "COLLADASWElementWriter.h"
16 #include "COLLADASWExtraTechnique.h"
17 
18 namespace COLLADASW
19 {
20 
21     /** <format_hint> is a child element of <surface>.
22     An application uses <format_hint> if <format> does
23     not exist or is not understood by the application and
24     <format_hint> exists. This element describes the
25     important features intended by the author so that the
26     application can pick a format that best represents what
27     the author wanted. */
28     class FormatHint : public ElementWriter, public BaseExtraTechnique
29     {
30 
31     public:
32 
33         /** Contains an enumeration value that describes the per-texel
34         layout of the format. The length of the enumeration string
35         indicates how many channels there are and each letter
36         represents the name of a channel. There are typically 1 to 4
37         channels. This element has no attributes.
38         Valid enumeration values are:
39         - RGB: Red/Green/Blue color map.
40         - RGBA: Red/Green/Blue/Alpha map, often used
41         for color and transparency or other things packed
42         into channel A, such as specular power.
43         - L: Luminance map, often used for light mapping.
44         - LA: Luminance/Alpha map, often used for light
45         mapping.
46         - D: Depth map, often used for displacement,
47         parallax, relief, or shadow mapping.
48         - XYZ: Typically used for normal maps or threecomponent
49         displacement maps.
50         - XYZW: Typically used for normal maps, where W
51         is the depth for relief or parallax mapping. */
52         enum Channels
53         {
54             RGB,
55             RGBA,
56             L,
57             LA,
58             D,
59             XYZ,
60             XYZW,
61             UNKNOWN_CHANNEL
62         };
63 
64         /** Contains an enumeration that describes the range of texel
65         channel values. Each channel represents a range of values.
66         Some example ranges are signed or unsigned integers, or
67         are within a clamped range such as 0.0f to 1.0f, or are a
68         high dynamic range via floating point. This element has no
69         attributes.
70         Valid enumeration values are:
71         - SNORM: Format represents a decimal value that
72         remains within the -1 to 1 range. Implementation
73         could be integer, fixed-point, or float.
74         - UNORM: Format represents a decimal value that
75         remains within the 0 to 1 range. Implementation
76         could be integer, fixed-point, or float.
77         - SINT: Format represents signed integer numbers;
78         for example, 8 bits can represent -128 to 127.
79         - UINT: Format represents unsigned integer
80         numbers. For example, 8 bits can represent 0 to
81         255.
82         - FLOAT: Format should support full floating-point
83         ranges typically used for high dynamic range. */
84         enum Range
85         {
86             SNORM,
87             UNORM,
88             SINT,
89             UINT,
90             FLOAT,
91             UNKNOWN_RANGE
92         };
93 
94         /** Contains an enumeration that identifies the precision of the
95         texel channel value.Each channel of the texel has a
96         precision. Typically, channels have the same precision. An
97         exact format may lower the precision of an individual
98         channel but applying a higher precision by linking the
99         channels may still convey the same information. This
100         element has no attributes.
101         Valid enumeration values are:
102         - LOW: For integers, this typically represents 8 bits.
103         For floats, typically 16 bits.
104         - MID: For integers, this typically represents 8 to 24
105         bits. For floats, typically 16 to 32 bits.
106         - HIGH: For integers, this typically represents 16 to
107         32 bits. For floats, typically 24 to 32 bits. */
108         enum Precision
109         {
110             LOW,
111             MID,
112             HIGH,
113             UNKNOWN_PRECISION
114         };
115 
116         /** Contains additional hints about data relationships and other
117         things to help an application pick the best format. This
118         element has no attributes.
119         Valid enumeration values are:
120         - SRGB_GAMMA: Colors are stored with respect
121         to the sRGB 2.2 gamma curve rather than linear.
122         - NORMALIZED3: The texel's XYZ/RGB should be
123         normalized such as in a normal map.
124         - NORMALIZED4: The texel's XYZW/RGBA should
125         be normalized such as in a normal map.
126         - COMPRESSABLE: The surface may use run-time
127         compression. Consider the best compression
128         based on desired <channels>, <range>,
129         <precision>, and <option>s. */
130         enum Option
131         {
132             SRGB_GAMMA,
133             NORMALIZED3,
134             NORMALIZED4,
135             COMPRESSABLE,
136             UNKNOWN_OPTIONS
137         };
138 
139     private:
140 
141         /** Contains an enumeration value that describes the per-texel
142         layout of the format. The length of the enumeration string
143         indicates how many channels there are and each letter
144         represents the name of a channel. There are typically 1 to 4
145         channels. */
146         Channels mChannels;
147 
148         /** Contains an enumeration that describes the range of texel
149         channel values. Each channel represents a range of values.
150         Some example ranges are signed or unsigned integers, or
151         are within a clamped range such as 0.0f to 1.0f, or are a
152         high dynamic range via floating point.  */
153         Range mRange;
154 
155         /** Contains an enumeration that identifies the precision of the
156         texel channel value.Each channel of the texel has a
157         precision. Typically, channels have the same precision. An
158         exact format may lower the precision of an individual
159         channel but applying a higher precision by linking the
160         channels may still convey the same information. */
161         Precision mPrecision;
162 
163         /** Contains additional hints about data relationships and other
164         things to help an application pick the best format. */
165         std::vector<Option> mOptions;
166 
167         /** Flag, if the format hint is initialized. */
168         bool mIsInitialized;
169 
170     public:
171 
172         /** Constructor. */
173         FormatHint ();
174 
175         /** Constructor. */
176         FormatHint ( StreamWriter* streamWriter, Channels channels, Range range );
177 
178         /** Destructor. */
~FormatHint()179         virtual ~FormatHint () {}
180 
181         /** Flag, if the format hint is initialized. */
getIsInitialized()182         const bool getIsInitialized () const { return mIsInitialized; }
183 
184         /** Flag, if the format hint is initialized. */
setIsInitialized(const bool val)185         void setIsInitialized ( const bool val ) { mIsInitialized = val; }
186 
187         /** Set the current precision. */
188         void setPrecision ( Precision precision );
189 
190         /** Set the current options. */
191         void addOption ( Option option );
192 
193         /** Returns the string value of the current channel. */
194         static const String& getChannelsString ( Channels channel );
195 
196         /** Returns the string value of the current range. */
197         static const String& getRangeString ( Range range );
198 
199         /** Returns the string value of the current precision. */
200         static const String& getPrecisionString ( Precision precision );
201 
202         /** Returns the string value of the current option. */
203         static const String& getOptionString ( Option option );
204 
205         /** Write the <format_hint> element to the collada stream. */
206         void add () const;
207     };
208 
209 }
210 
211 #endif // __COLLADASTREAMWRITER_FORMAT_HINT_H__
212