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 
GenericVec4(const GenericVec4 & other)75 	inline GenericVec4 (const GenericVec4& other)
76 	{
77 		v.iData[0] = other.v.iData[0];
78 		v.iData[1] = other.v.iData[1];
79 		v.iData[2] = other.v.iData[2];
80 		v.iData[3] = other.v.iData[3];
81 	}
82 
operator =(const GenericVec4 & value)83 	GenericVec4& operator= (const GenericVec4& value)
84 	{
85 		v.iData[0] = value.v.iData[0];
86 		v.iData[1] = value.v.iData[1];
87 		v.iData[2] = value.v.iData[2];
88 		v.iData[3] = value.v.iData[3];
89 		return *this;
90 	}
91 
92 	template<typename ScalarType>
operator =(const tcu::Vector<ScalarType,4> & value)93 	GenericVec4& operator= (const tcu::Vector<ScalarType, 4>& value)
94 	{
95 		getAccess<ScalarType>()[0] = value[0];
96 		getAccess<ScalarType>()[1] = value[1];
97 		getAccess<ScalarType>()[2] = value[2];
98 		getAccess<ScalarType>()[3] = value[3];
99 		return *this;
100 	}
101 
102 	template<typename ScalarType>
get(void) const103 	inline tcu::Vector<ScalarType, 4> get (void) const
104 	{
105 		return tcu::Vector<ScalarType, 4>(
106 			getAccess<ScalarType>()[0],
107 			getAccess<ScalarType>()[1],
108 			getAccess<ScalarType>()[2],
109 			getAccess<ScalarType>()[3]);
110 	}
111 
112 	template<typename ScalarType>
113 	inline ScalarType* getAccess ();
114 
115 	template<typename ScalarType>
116 	inline const ScalarType* getAccess () const;
117 } DE_WARN_UNUSED_TYPE;
118 
119 template<>
getAccess()120 inline float* GenericVec4::getAccess<float> ()
121 {
122 	return v.fData;
123 }
124 
125 template<>
getAccess() const126 inline const float* GenericVec4::getAccess<float> () const
127 {
128 	return v.fData;
129 }
130 
131 template<>
getAccess()132 inline deUint32* GenericVec4::getAccess<deUint32> ()
133 {
134 	return v.uData;
135 }
136 
137 template<>
getAccess() const138 inline const deUint32* GenericVec4::getAccess<deUint32> () const
139 {
140 	return v.uData;
141 }
142 
143 template<>
getAccess()144 inline deInt32* GenericVec4::getAccess<deInt32> ()
145 {
146 	return v.iData;
147 }
148 
149 template<>
getAccess() const150 inline const deInt32* GenericVec4::getAccess<deInt32> () const
151 {
152 	return v.iData;
153 }
154 
155 } // rr
156 
157 #endif // _RRGENERICVECTOR_HPP
158