1 #ifndef _RRGENERICVECTOR_HPP
2 #define _RRGENERICVECTOR_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 Generic vetor
24  *//*--------------------------------------------------------------------*/
25 
26 #include "rrDefs.hpp"
27 #include "tcuVector.hpp"
28 
29 namespace rr
30 {
31 
32 enum GenericVecType
33 {
34 	GENERICVECTYPE_FLOAT = 0,
35 	GENERICVECTYPE_UINT32,
36 	GENERICVECTYPE_INT32,
37 
38 	GENERICVECTYPE_LAST
39 };
40 
41 /*--------------------------------------------------------------------*//*!
42  * \brief Generic vertex attrib
43  *
44  * Generic vertex attributes hold 4 32-bit scalar values that can be accessed
45  * as floating-point or integer values.
46  *
47  * Aliasing rules must be adhered when accessing data (ie. writing as float
48  * and reading as int has undefined result).
49  *//*--------------------------------------------------------------------*/
50 class GenericVec4
51 {
52 private:
53 	union
54 	{
55 		deUint32 uData[4];
56 		deInt32  iData[4];
57 		float    fData[4];
58 	} v;
59 
60 public:
GenericVec4(void)61 	inline GenericVec4 (void)
62 	{
63 		v.iData[0] = 0;
64 		v.iData[1] = 0;
65 		v.iData[2] = 0;
66 		v.iData[3] = 0;
67 	}
68 
69 	template<typename ScalarType>
GenericVec4(const tcu::Vector<ScalarType,4> & value)70 	explicit GenericVec4 (const tcu::Vector<ScalarType, 4>& value)
71 	{
72 		*this = value;
73 	}
74 
operator =(const GenericVec4 & value)75 	GenericVec4& operator= (const GenericVec4& value)
76 	{
77 		v.iData[0] = value.v.iData[0];
78 		v.iData[1] = value.v.iData[1];
79 		v.iData[2] = value.v.iData[2];
80 		v.iData[3] = value.v.iData[3];
81 		return *this;
82 	}
83 
84 	template<typename ScalarType>
operator =(const tcu::Vector<ScalarType,4> & value)85 	GenericVec4& operator= (const tcu::Vector<ScalarType, 4>& value)
86 	{
87 		getAccess<ScalarType>()[0] = value[0];
88 		getAccess<ScalarType>()[1] = value[1];
89 		getAccess<ScalarType>()[2] = value[2];
90 		getAccess<ScalarType>()[3] = value[3];
91 		return *this;
92 	}
93 
94 	template<typename ScalarType>
get(void) const95 	inline tcu::Vector<ScalarType, 4> get (void) const
96 	{
97 		return tcu::Vector<ScalarType, 4>(
98 			getAccess<ScalarType>()[0],
99 			getAccess<ScalarType>()[1],
100 			getAccess<ScalarType>()[2],
101 			getAccess<ScalarType>()[3]);
102 	}
103 
104 	template<typename ScalarType>
105 	inline ScalarType* getAccess ();
106 
107 	template<typename ScalarType>
108 	inline const ScalarType* getAccess () const;
109 } DE_WARN_UNUSED_TYPE;
110 
111 template<>
getAccess()112 inline float* GenericVec4::getAccess<float> ()
113 {
114 	return v.fData;
115 }
116 
117 template<>
getAccess() const118 inline const float* GenericVec4::getAccess<float> () const
119 {
120 	return v.fData;
121 }
122 
123 template<>
getAccess()124 inline deUint32* GenericVec4::getAccess<deUint32> ()
125 {
126 	return v.uData;
127 }
128 
129 template<>
getAccess() const130 inline const deUint32* GenericVec4::getAccess<deUint32> () const
131 {
132 	return v.uData;
133 }
134 
135 template<>
getAccess()136 inline deInt32* GenericVec4::getAccess<deInt32> ()
137 {
138 	return v.iData;
139 }
140 
141 template<>
getAccess() const142 inline const deInt32* GenericVec4::getAccess<deInt32> () const
143 {
144 	return v.iData;
145 }
146 
147 } // rr
148 
149 #endif // _RRGENERICVECTOR_HPP
150