1 #ifndef MSP_GL_DATATYPE_H_
2 #define MSP_GL_DATATYPE_H_
4 #include <msp/linal/matrix.h>
5 #include <msp/linal/vector.h>
11 Identifies a data type. The values are bitfields laid as follows:
13 __ds addd ccrr _bfg ssss ssss
14 ││ │ │ │ │ │││ └╴Size (bytes)
15 ││ │ │ │ │ ││└──────────╴Signed flag
16 ││ │ │ │ │ │└───────────╴Floating-point flag
17 ││ │ │ │ │ └────────────╴Boolean flag
18 ││ │ │ │ └───────────────╴Vector or matrix rows minus one
19 ││ │ │ └─────────────────╴Matrix columns minus one
20 ││ │ └────────────────────╴Image dimensions (4 = cube)
21 ││ └───────────────────────╴Image array flag
22 │└─────────────────────────╴Sampled image flag
23 └──────────────────────────╴Shadow sampler flag
25 This information is presented for internal documentation purposes only; it is
26 inadvisable for programs to rely on it.
33 UNSIGNED_BYTE = 0x001,
35 UNSIGNED_SHORT = 0x002,
55 FLOAT_MAT2x3 = 0x6318,
56 FLOAT_MAT3x2 = 0x9318,
57 FLOAT_MAT2x4 = 0x7320,
58 FLOAT_MAT4x2 = 0xD320,
59 FLOAT_MAT3x4 = 0xB330,
60 FLOAT_MAT4x3 = 0xE330,
65 DOUBLE_MAT2x3 = 0x6330,
66 DOUBLE_MAT3x2 = 0x7330,
67 DOUBLE_MAT2x4 = 0x7340,
68 DOUBLE_MAT4x2 = 0xD340,
69 DOUBLE_MAT3x4 = 0xB360,
70 DOUBLE_MAT4x3 = 0xE360,
76 IMAGE_1D_ARRAY = 0x90304,
77 IMAGE_2D_ARRAY = 0xA0304,
78 IMAGE_CUBE_ARRAY = 0xC0304,
79 SAMPLER_1D = 0x110304,
80 SAMPLER_2D = 0x120304,
81 SAMPLER_3D = 0x130304,
82 SAMPLER_CUBE = 0x140304,
83 SAMPLER_1D_ARRAY = 0x190304,
84 SAMPLER_2D_ARRAY = 0x1A0304,
85 SAMPLER_CUBE_ARRAY = 0x1C0304,
86 SAMPLER_1D_SHADOW = 0x310304,
87 SAMPLER_2D_SHADOW = 0x320304,
88 SAMPLER_CUBE_SHADOW = 0x340304,
89 SAMPLER_1D_ARRAY_SHADOW = 0x390304,
90 SAMPLER_2D_ARRAY_SHADOW = 0x3A0304,
91 SAMPLER_CUBE_ARRAY_SHADOW = 0x3C0304
94 inline unsigned get_type_size(DataType t) { return t&0xFF; }
95 inline bool is_float(DataType t) { return t&0x200; }
96 inline bool is_matrix(DataType t) { return t&0xC000; }
97 inline bool is_vector(DataType t) { return !is_matrix(t) && (t&0x3000); }
98 inline bool is_image(DataType t) { return t&0x70000; }
100 inline DataType get_matrix_column_type(DataType t)
102 unsigned cols = ((t&0xC000)>>14)+1;
103 return static_cast<DataType>((t&~0xC0FF) | (get_type_size(t)/cols));
106 inline DataType get_element_type(DataType t)
108 unsigned elems = (((t&0xC000)>>14)+1)*(((t&0x3000)>>12)+1);
109 return static_cast<DataType>((t&~0xC0FF) | (get_type_size(t)/elems));
112 template<typename T> struct TypeTraits;
113 template<> struct TypeTraits<bool> { static const DataType type = BOOL; };
114 template<> struct TypeTraits<char> { static const DataType type = BYTE; };
115 template<> struct TypeTraits<unsigned char> { static const DataType type = UNSIGNED_BYTE; };
116 template<> struct TypeTraits<short> { static const DataType type = SHORT; };
117 template<> struct TypeTraits<unsigned short> { static const DataType type = UNSIGNED_SHORT; };
118 template<> struct TypeTraits<int> { static const DataType type = INT; };
119 template<> struct TypeTraits<unsigned> { static const DataType type = UNSIGNED_INT; };
120 template<> struct TypeTraits<float> { static const DataType type = FLOAT; };
121 template<> struct TypeTraits<double> { static const DataType type = DOUBLE; };
123 template<typename T, unsigned N>
124 struct TypeTraits<LinAl::Vector<T, N>>
126 static const DataType type = static_cast<DataType>((TypeTraits<T>::type&0xF00) | ((TypeTraits<T>::type&0xFF)*N) | ((N-1)<<12));
129 template<typename T, unsigned N, unsigned M>
130 struct TypeTraits<LinAl::Matrix<T, N, M>>
132 static const DataType type = static_cast<DataType>((TypeTraits<T>::type&0xF00) | ((TypeTraits<T>::type&0xFF)*N*M) | ((N-1)<<12) | ((M-1)<<14));
135 void require_type(DataType);
140 #include "datatype_backend.h"