Overte C++ Documentation
Format.h
1 //
2 // Format.h
3 // interface/src/gpu
4 //
5 // Created by Sam Gateau on 10/29/2014.
6 // Copyright 2014 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 #ifndef hifi_gpu_Format_h
12 #define hifi_gpu_Format_h
13 
14 #include <assert.h>
15 #include <memory>
16 
17 #include "Forward.h"
18 
19 namespace gpu {
20 
21 class Backend;
22 
24 enum Type : uint8_t {
25 
26  FLOAT = 0,
27  INT32,
28  UINT32,
29  HALF,
30  INT16,
31  UINT16,
32  INT8,
33  UINT8,
34 
35  NINT32,
36  NUINT32,
37  NINT16,
38  NUINT16,
39  NINT8,
40  NUINT8,
41  NUINT2,
42  NINT2_10_10_10,
43 
44  COMPRESSED,
45 
46  NUM_TYPES,
47 
48  BOOL = UINT8,
49  NORMALIZED_START = NINT32,
50 };
52 static const int TYPE_SIZE[NUM_TYPES] = {
53  4, // FLOAT
54  4, // INT32
55  4, // UINT32
56  2, // HALF
57  2, // INT16
58  2, // UINT16
59  1, // INT8
60  1, // UINT8
61 
62  // normalized values
63  4, // NINT32
64  4, // NUINT32
65  2, // NINT16
66  2, // NUINT16
67  1, // NINT8
68  1, // NUINT8
69  1, // NUINT2
70  1, // NINT2_10_10_10
71 
72  1, // COMPRESSED
73 };
74 
76 static const bool TYPE_IS_INTEGER[NUM_TYPES] = {
77  false, // FLOAT
78  true, // INT32
79  true, // UINT32
80  false, // HALF
81  true, // INT16
82  true, // UINT16
83  true, // INT8
84  true, // UINT8
85 
86  // Normalized values
87  false, // NINT32
88  false, // NUINT32
89  false, // NINT16
90  false, // NUINT16
91  false, // NINT8
92  false, // NUINT8
93  false, // NUINT2
94  false, // NINT2_10_10_10
95 
96  false, // COMPRESSED
97 };
98 
100 enum Dimension : uint8_t {
101  SCALAR = 0,
102  VEC2,
103  VEC3,
104  VEC4,
105  MAT2,
106  MAT3,
107  MAT4,
108  TILE4x4, // Blob element's size is defined from the type and semantic, it s counted as 1 component
109  NUM_DIMENSIONS,
110 };
111 
113 static const int DIMENSION_LOCATION_COUNT[NUM_DIMENSIONS] = {
114  1,
115  1,
116  1,
117  1,
118  1,
119  3,
120  4,
121  1,
122 };
123 
125 static const int DIMENSION_SCALAR_COUNT_PER_LOCATION[NUM_DIMENSIONS] = {
126  1,
127  2,
128  3,
129  4,
130  4,
131  3,
132  4,
133  1,
134 };
135 
137 static const int DIMENSION_SCALAR_COUNT[NUM_DIMENSIONS] = {
138  1,
139  2,
140  3,
141  4,
142  4,
143  9,
144  16,
145  1,
146 };
147 
149 static const glm::ivec2 DIMENSION_TILE_DIM[NUM_DIMENSIONS] = {
150  { 1, 1 },
151  { 1, 1 },
152  { 1, 1 },
153  { 1, 1 },
154  { 1, 1 },
155  { 1, 1 },
156  { 1, 1 },
157  { 4, 4 },
158 };
159 
162 enum Semantic : uint8_t {
163  RAW = 0, // used as RAW memory
164 
165  RED,
166  RGB,
167  RGBA,
168  BGRA,
169 
170  XY,
171  XYZ,
172  XYZW,
173  QUAT,
174  UV,
175  INDEX, //used by index buffer of a mesh
176  PART, // used by part buffer of a mesh
177 
178  DEPTH, // Depth only buffer
179  STENCIL, // Stencil only buffer
180  DEPTH_STENCIL, // Depth Stencil buffer
181 
182  SRED,
183  SRGB,
184  SRGBA,
185  SBGRA,
186 
187  // These are generic compression format semantic for images
188  // THey must be used with Dim = BLOB and Type = Compressed
189  // THe size of a compressed element is defined from the semantic
190  _FIRST_COMPRESSED,
191 
192  COMPRESSED_BC1_SRGB,
193  COMPRESSED_BC1_SRGBA,
194  COMPRESSED_BC3_SRGBA,
195  COMPRESSED_BC4_RED,
196  COMPRESSED_BC5_XY,
197  COMPRESSED_BC6_RGB,
198  COMPRESSED_BC7_SRGBA,
199 
200  COMPRESSED_ETC2_RGB,
201  COMPRESSED_ETC2_SRGB,
202  COMPRESSED_ETC2_RGB_PUNCHTHROUGH_ALPHA,
203  COMPRESSED_ETC2_SRGB_PUNCHTHROUGH_ALPHA,
204  COMPRESSED_ETC2_RGBA,
205  COMPRESSED_ETC2_SRGBA,
206  COMPRESSED_EAC_RED,
207  COMPRESSED_EAC_RED_SIGNED,
208  COMPRESSED_EAC_XY,
209  COMPRESSED_EAC_XY_SIGNED,
210 
211  _LAST_COMPRESSED,
212 
213  R11G11B10,
214  RGB9E5,
215 
216  UNIFORM,
217  UNIFORM_BUFFER,
218  RESOURCE_BUFFER,
219  SAMPLER,
220  SAMPLER_MULTISAMPLE,
221  SAMPLER_SHADOW,
222 
223 
224  NUM_SEMANTICS, // total Number of semantics (not a valid Semantic)!
225 };
226 
228 static const int SEMANTIC_SIZE_FACTOR[NUM_SEMANTICS] = {
229  1, //RAW = 0, // used as RAW memory
230 
231  1, //RED,
232  1, //RGB,
233  1, //RGBA,
234  1, //BGRA,
235 
236  1, //XY,
237  1, //XYZ,
238  1, //XYZW,
239  1, //QUAT,
240  1, //UV,
241  1, //INDEX, //used by index buffer of a mesh
242  1, //PART, // used by part buffer of a mesh
243 
244  1, //DEPTH, // Depth only buffer
245  1, //STENCIL, // Stencil only buffer
246  1, //DEPTH_STENCIL, // Depth Stencil buffer
247 
248  1, //SRED,
249  1, //SRGB,
250  1, //SRGBA,
251  1, //SBGRA,
252 
253  // These are generic compression format smeantic for images
254  // THey must be used with Dim = BLOB and Type = Compressed
255  // THe size of a compressed element is defined from the semantic
256  1, //_FIRST_COMPRESSED,
257 
258  8, //COMPRESSED_BC1_SRGB, 1/2 byte/pixel * 4x4 pixels = 8 bytes
259  8, //COMPRESSED_BC1_SRGBA, 1/2 byte/pixel * 4x4 pixels = 8 bytes
260  16, //COMPRESSED_BC3_SRGBA, 1 byte/pixel * 4x4 pixels = 16 bytes
261  8, //COMPRESSED_BC4_RED, 1/2 byte/pixel * 4x4 pixels = 8 bytes
262  16, //COMPRESSED_BC5_XY, 1 byte/pixel * 4x4 pixels = 16 bytes
263  16, //COMPRESSED_BC6_RGB, 1 byte/pixel * 4x4 pixels = 16 bytes
264  16, //COMPRESSED_BC7_SRGBA, 1 byte/pixel * 4x4 pixels = 16 bytes
265 
266  8, //COMPRESSED_ETC2_RGB,
267  8, //COMPRESSED_ETC2_SRGB,
268  8, //COMPRESSED_ETC2_RGB_PUNCHTHROUGH_ALPHA,
269  8, //COMPRESSED_ETC2_SRGB_PUNCHTHROUGH_ALPHA,
270  16, //COMPRESSED_ETC2_RGBA,
271  16, //COMPRESSED_ETC2_SRGBA,
272  8, //COMPRESSED_EAC_RED,
273  8, //COMPRESSED_EAC_RED_SIGNED,
274  16, //COMPRESSED_EAC_XY,
275  16, //COMPRESSED_EAC_XY_SIGNED,
276 
277  1, //_LAST_COMPRESSED,
278 
279  1, //R11G11B10,
280  1, //RGB9E5
281 
282  1, //UNIFORM,
283  1, //UNIFORM_BUFFER,
284  1, //RESOURCE_BUFFER,
285  1, //SAMPLER,
286  1, //SAMPLER_MULTISAMPLE,
287  1, //SAMPLER_SHADOW,
288 };
289 
295 class Element {
296 public:
297  Element(Dimension dim, Type type, Semantic sem) :
298  _semantic(sem),
299  _dimension(dim),
300  _type(type)
301  {}
302  Element() :
303  _semantic(RAW),
304  _dimension(SCALAR),
305  _type(INT8)
306  {}
307 
311  Semantic getSemantic() const { return (Semantic)_semantic; }
312 
316  Dimension getDimension() const { return (Dimension)_dimension; }
317 
321  bool isCompressed() const { return uint8(getSemantic() - _FIRST_COMPRESSED) <= uint8(_LAST_COMPRESSED - _FIRST_COMPRESSED); }
322 
326  Type getType() const { return (Type)_type; }
327 
334  bool isNormalized() const { return (getType() >= NORMALIZED_START); }
335 
339  bool isInteger() const { return TYPE_IS_INTEGER[getType()]; }
340 
344  uint8 getScalarCount() const { return DIMENSION_SCALAR_COUNT[(Dimension)_dimension]; }
345 
349  uint32 getSize() const { return (DIMENSION_SCALAR_COUNT[_dimension] * TYPE_SIZE[_type] * SEMANTIC_SIZE_FACTOR[_semantic]); }
350 
356  const glm::ivec2& getTile() const { return (DIMENSION_TILE_DIM[_dimension]); }
357 
361  uint8 getLocationCount() const { return DIMENSION_LOCATION_COUNT[(Dimension)_dimension]; }
362 
366  uint8 getLocationScalarCount() const { return DIMENSION_SCALAR_COUNT_PER_LOCATION[(Dimension)_dimension]; }
367 
371  uint32 getLocationSize() const { return DIMENSION_SCALAR_COUNT_PER_LOCATION[_dimension] * TYPE_SIZE[_type]; }
372 
373  uint16 getRaw() const { return *((const uint16*) (this)); }
374 
375 
376  bool operator ==(const Element& right) const {
377  return getRaw() == right.getRaw();
378  }
379  bool operator !=(const Element& right) const {
380  return getRaw() != right.getRaw();
381  }
382 
383  static const Element COLOR_R_8;
384  static const Element COLOR_SR_8;
385  static const Element COLOR_RGBA_32;
386  static const Element COLOR_SRGBA_32;
387  static const Element COLOR_BGRA_32;
388  static const Element COLOR_SBGRA_32;
389  static const Element COLOR_RGBA_2;
390  static const Element COLOR_R11G11B10;
391  static const Element COLOR_RGB9E5;
392  static const Element COLOR_COMPRESSED_BCX_RED;
393  static const Element COLOR_COMPRESSED_BCX_SRGB;
394  static const Element COLOR_COMPRESSED_BCX_SRGBA_MASK;
395  static const Element COLOR_COMPRESSED_BCX_SRGBA;
396  static const Element COLOR_COMPRESSED_BCX_XY;
397  static const Element COLOR_COMPRESSED_BCX_SRGBA_HIGH;
398  static const Element COLOR_COMPRESSED_BCX_HDR_RGB;
399  static const Element COLOR_COMPRESSED_ETC2_RGB;
400  static const Element COLOR_COMPRESSED_ETC2_SRGB;
401  static const Element COLOR_COMPRESSED_ETC2_RGB_PUNCHTHROUGH_ALPHA;
402  static const Element COLOR_COMPRESSED_ETC2_SRGB_PUNCHTHROUGH_ALPHA;
403  static const Element COLOR_COMPRESSED_ETC2_RGBA;
404  static const Element COLOR_COMPRESSED_ETC2_SRGBA;
405  static const Element COLOR_COMPRESSED_EAC_RED;
406  static const Element COLOR_COMPRESSED_EAC_RED_SIGNED;
407  static const Element COLOR_COMPRESSED_EAC_XY;
408  static const Element COLOR_COMPRESSED_EAC_XY_SIGNED;
409  static const Element DEPTH24_STENCIL8;
410  static const Element VEC2NU8_XY;
411  static const Element VEC4F_COLOR_RGBA;
412  static const Element VEC2F_UV;
413  static const Element VEC2F_XY;
414  static const Element VEC3F_XYZ;
415  static const Element VEC4F_XYZW;
416  static const Element VEC4F_NORMALIZED_XYZ10W2;
417  static const Element INDEX_UINT16;
418  static const Element INDEX_INT32;
419  static const Element PART_DRAWCALL;
420 
421  protected:
422  uint16 _semantic : 7;
423  uint16 _dimension : 4;
424  uint16 _type : 5;
425 };
426 
427 enum Primitive {
428  POINTS = 0,
429  LINES,
430  LINE_STRIP,
431  TRIANGLES,
432  TRIANGLE_STRIP,
433  TRIANGLE_FAN,
434  NUM_PRIMITIVES,
435 };
436 
437 };
438 
439 
440 #endif
Definition: Format.h:295
const glm::ivec2 & getTile() const
Definition: Format.h:356
uint8 getLocationCount() const
Definition: Format.h:361
bool isInteger() const
Definition: Format.h:339
uint32 getSize() const
Definition: Format.h:349
bool isCompressed() const
Definition: Format.h:321
bool isNormalized() const
Definition: Format.h:334
uint8 getLocationScalarCount() const
Definition: Format.h:366
Dimension getDimension() const
Definition: Format.h:316
Type getType() const
Definition: Format.h:326
uint32 getLocationSize() const
Definition: Format.h:371
Semantic getSemantic() const
Definition: Format.h:311
uint8 getScalarCount() const
Definition: Format.h:344