1 #ifndef _RRVERTEXATTRIB_HPP
2 #define _RRVERTEXATTRIB_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program Reference Renderer
5 * -----------------------------------------------
6 *
7 * Copyright 2014 The Android Open Source Project
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 *//*!
22 * \file
23 * \brief Vertex attribute fetch.
24 *//*--------------------------------------------------------------------*/
25
26 #include "rrDefs.hpp"
27 #include "rrGenericVector.hpp"
28 #include "tcuVector.hpp"
29
30 namespace rr
31 {
32
33 enum VertexAttribType
34 {
35 // Can only be read as floats
36 VERTEXATTRIBTYPE_FLOAT = 0,
37 VERTEXATTRIBTYPE_HALF,
38 VERTEXATTRIBTYPE_FIXED,
39 VERTEXATTRIBTYPE_DOUBLE,
40
41 // Can only be read as floats, will be normalized
42 VERTEXATTRIBTYPE_NONPURE_UNORM8,
43 VERTEXATTRIBTYPE_NONPURE_UNORM16,
44 VERTEXATTRIBTYPE_NONPURE_UNORM32,
45 VERTEXATTRIBTYPE_NONPURE_UNORM_2_10_10_10_REV, //!< Packed format, only size = 4 is allowed
46
47 // Clamped formats, GLES3-style conversion: max{c / (2^(b-1) - 1), -1 }
48 VERTEXATTRIBTYPE_NONPURE_SNORM8_CLAMP,
49 VERTEXATTRIBTYPE_NONPURE_SNORM16_CLAMP,
50 VERTEXATTRIBTYPE_NONPURE_SNORM32_CLAMP,
51 VERTEXATTRIBTYPE_NONPURE_SNORM_2_10_10_10_REV_CLAMP, //!< Packed format, only size = 4 is allowed
52
53 // Scaled formats, GLES2-style conversion: (2c + 1) / (2^b - 1)
54 VERTEXATTRIBTYPE_NONPURE_SNORM8_SCALE,
55 VERTEXATTRIBTYPE_NONPURE_SNORM16_SCALE,
56 VERTEXATTRIBTYPE_NONPURE_SNORM32_SCALE,
57 VERTEXATTRIBTYPE_NONPURE_SNORM_2_10_10_10_REV_SCALE, //!< Packed format, only size = 4 is allowed
58
59 // can only be read as float, will not be normalized
60 VERTEXATTRIBTYPE_NONPURE_UINT8,
61 VERTEXATTRIBTYPE_NONPURE_UINT16,
62 VERTEXATTRIBTYPE_NONPURE_UINT32,
63
64 VERTEXATTRIBTYPE_NONPURE_INT8,
65 VERTEXATTRIBTYPE_NONPURE_INT16,
66 VERTEXATTRIBTYPE_NONPURE_INT32,
67
68 VERTEXATTRIBTYPE_NONPURE_UINT_2_10_10_10_REV, //!< Packed format, only size = 4 is allowed
69 VERTEXATTRIBTYPE_NONPURE_INT_2_10_10_10_REV, //!< Packed format, only size = 4 is allowed
70
71 // can only be read as integers
72 VERTEXATTRIBTYPE_PURE_UINT8,
73 VERTEXATTRIBTYPE_PURE_UINT16,
74 VERTEXATTRIBTYPE_PURE_UINT32,
75
76 VERTEXATTRIBTYPE_PURE_INT8,
77 VERTEXATTRIBTYPE_PURE_INT16,
78 VERTEXATTRIBTYPE_PURE_INT32,
79
80 // reordered formats of GL_ARB_vertex_array_bgra
81 VERTEXATTRIBTYPE_NONPURE_UNORM8_BGRA,
82 VERTEXATTRIBTYPE_NONPURE_UNORM_2_10_10_10_REV_BGRA,
83 VERTEXATTRIBTYPE_NONPURE_SNORM_2_10_10_10_REV_CLAMP_BGRA,
84 VERTEXATTRIBTYPE_NONPURE_SNORM_2_10_10_10_REV_SCALE_BGRA,
85
86 // can be read as anything
87 VERTEXATTRIBTYPE_DONT_CARE, //!< Do not enforce type checking when reading GENERIC attribute. Used for current client side attributes.
88
89 VERTEXATTRIBTYPE_LAST
90 };
91
92 /*--------------------------------------------------------------------*//*!
93 * \brief Vertex attribute slot
94 *
95 * Vertex attribute type specifies component type for attribute and it
96 * includes signed & normalized bits as well.
97 *
98 * Attribute size specifies how many components there are per vertex.
99 * If size is 0, no components are fetched, ie. vertex attribute slot
100 * is disabled.
101 *
102 * Divisor specifies the rate at which vertex attribute advances. If it is
103 * zero, attribute is advanced per vertex. If divisor is non-zero, attribute
104 * advances once per instanceDivisor instances.
105 *
106 * Pointer is used if not null, otherwise generic attribute is used instead
107 * and in such case only DONT_CARE is valid attribute type.
108 *//*--------------------------------------------------------------------*/
109 struct VertexAttrib
110 {
111 VertexAttribType type; //!< Attribute component type.
112 int size; //!< Number of components, valid range is [0,4].
113 int stride; //!< Number of bytes two consecutive elements differ by. Zero works as in GL. Valid range is [0, inf).
114 int instanceDivisor; //!< Vertex attribute divisor.
115 const void* pointer; //!< Data pointer.
116 GenericVec4 generic; //!< Generic attribute, used if pointer is null.
117
VertexAttribrr::VertexAttrib118 VertexAttrib (void)
119 : type (VERTEXATTRIBTYPE_FLOAT)
120 , size (0)
121 , stride (0)
122 , instanceDivisor (0)
123 , pointer (DE_NULL)
124 {
125 }
126 };
127
128 bool isValidVertexAttrib (const VertexAttrib& vertexAttrib);
129 // \todo [2013-04-01 pyry] Queries: isReadFloatValid(), isReadIntValid() ...
130
131 void readVertexAttrib (tcu::Vec4& dst, const VertexAttrib& vertexAttrib, const int instanceNdx, const int vertexNdx);
132 void readVertexAttrib (tcu::IVec4& dst, const VertexAttrib& vertexAttrib, const int instanceNdx, const int vertexNdx);
133 void readVertexAttrib (tcu::UVec4& dst, const VertexAttrib& vertexAttrib, const int instanceNdx, const int vertexNdx);
134
135 // Helpers that return by value (trivial for compiler to optimize).
136
readVertexAttribFloat(const VertexAttrib & vertexAttrib,const int instanceNdx,const int vertexNdx)137 inline tcu::Vec4 readVertexAttribFloat (const VertexAttrib& vertexAttrib, const int instanceNdx, const int vertexNdx)
138 {
139 tcu::Vec4 v;
140 readVertexAttrib(v, vertexAttrib, instanceNdx, vertexNdx);
141 return v;
142 }
143
readVertexAttribInt(const VertexAttrib & vertexAttrib,const int instanceNdx,const int vertexNdx)144 inline tcu::IVec4 readVertexAttribInt (const VertexAttrib& vertexAttrib, const int instanceNdx, const int vertexNdx)
145 {
146 tcu::IVec4 v;
147 readVertexAttrib(v, vertexAttrib, instanceNdx, vertexNdx);
148 return v;
149 }
150
readVertexAttribUint(const VertexAttrib & vertexAttrib,const int instanceNdx,const int vertexNdx)151 inline tcu::UVec4 readVertexAttribUint (const VertexAttrib& vertexAttrib, const int instanceNdx, const int vertexNdx)
152 {
153 tcu::UVec4 v;
154 readVertexAttrib(v, vertexAttrib, instanceNdx, vertexNdx);
155 return v;
156 }
157
158 } // rr
159
160 #endif // _RRVERTEXATTRIB_HPP
161