1 #ifndef _RRVERTEXATTRIB_HPP
2 #define _RRVERTEXATTRIB_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program Reference Renderer
5 * -----------------------------------------------
7 * Copyright 2014 The Android Open Source Project
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * \brief Vertex attribute fetch.
24 *//*--------------------------------------------------------------------*/
27 #include "rrGenericVector.hpp"
28 #include "tcuVector.hpp"
35 // Can only be read as floats
36 VERTEXATTRIBTYPE_FLOAT = 0,
37 VERTEXATTRIBTYPE_HALF,
38 VERTEXATTRIBTYPE_FIXED,
39 VERTEXATTRIBTYPE_DOUBLE,
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
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
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
59 // can only be read as float, will not be normalized
60 VERTEXATTRIBTYPE_NONPURE_UINT8,
61 VERTEXATTRIBTYPE_NONPURE_UINT16,
62 VERTEXATTRIBTYPE_NONPURE_UINT32,
64 VERTEXATTRIBTYPE_NONPURE_INT8,
65 VERTEXATTRIBTYPE_NONPURE_INT16,
66 VERTEXATTRIBTYPE_NONPURE_INT32,
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
71 // can only be read as integers
72 VERTEXATTRIBTYPE_PURE_UINT8,
73 VERTEXATTRIBTYPE_PURE_UINT16,
74 VERTEXATTRIBTYPE_PURE_UINT32,
76 VERTEXATTRIBTYPE_PURE_INT8,
77 VERTEXATTRIBTYPE_PURE_INT16,
78 VERTEXATTRIBTYPE_PURE_INT32,
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,
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.
92 /*--------------------------------------------------------------------*//*!
93 * \brief Vertex attribute slot
95 * Vertex attribute type specifies component type for attribute and it
96 * includes signed & normalized bits as well.
98 * Attribute size specifies how many components there are per vertex.
99 * If size is 0, no components are fetched, ie. vertex attribute slot
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.
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 *//*--------------------------------------------------------------------*/
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.
119 : type (VERTEXATTRIBTYPE_FLOAT)
122 , instanceDivisor (0)
127 VertexAttrib (VertexAttribType type_, int size_, int stride_, int instanceDivisor_, const void* pointer_)
131 , instanceDivisor (instanceDivisor_)
136 template<typename ScalarType>
137 explicit VertexAttrib (const tcu::Vector<ScalarType, 4>& generic_)
138 : type (VERTEXATTRIBTYPE_DONT_CARE)
141 , instanceDivisor (0)
146 } DE_WARN_UNUSED_TYPE;
148 bool isValidVertexAttrib (const VertexAttrib& vertexAttrib);
149 // \todo [2013-04-01 pyry] Queries: isReadFloatValid(), isReadIntValid() ...
151 void readVertexAttrib (tcu::Vec4& dst, const VertexAttrib& vertexAttrib, const int instanceNdx, const int vertexNdx);
152 void readVertexAttrib (tcu::IVec4& dst, const VertexAttrib& vertexAttrib, const int instanceNdx, const int vertexNdx);
153 void readVertexAttrib (tcu::UVec4& dst, const VertexAttrib& vertexAttrib, const int instanceNdx, const int vertexNdx);
155 // Helpers that return by value (trivial for compiler to optimize).
157 inline tcu::Vec4 readVertexAttribFloat (const VertexAttrib& vertexAttrib, const int instanceNdx, const int vertexNdx)
160 readVertexAttrib(v, vertexAttrib, instanceNdx, vertexNdx);
164 inline tcu::IVec4 readVertexAttribInt (const VertexAttrib& vertexAttrib, const int instanceNdx, const int vertexNdx)
167 readVertexAttrib(v, vertexAttrib, instanceNdx, vertexNdx);
171 inline tcu::UVec4 readVertexAttribUint (const VertexAttrib& vertexAttrib, const int instanceNdx, const int vertexNdx)
174 readVertexAttrib(v, vertexAttrib, instanceNdx, vertexNdx);
180 #endif // _RRVERTEXATTRIB_HPP