• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //Copyright (c) 2008-2016 Emil Dotchevski and Reverge Studios, Inc.
2 //Copyright (c) 2018 agate-pris
3 
4 //Distributed under the Boost Software License, Version 1.0. (See accompanying
5 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 
7 #include <boost/core/lightweight_test.hpp>
8 #include <boost/qvm/vec_register.hpp>
9 
10 struct v2
11 {
12     float x;
13     float y;
14 };
15 
16 struct v3 : v2
17 {
18     float z;
19 };
20 
21 struct v4 : v3
22 {
23     float w;
24 };
25 
26 struct v2r
27 {
28     float xr;
29     float yr;
30 };
31 
32 struct v3r : v2r
33 {
34     float zr;
35 };
36 
37 struct v4r : v3r
38 {
39     float wr;
40 };
41 
42 struct v2rw : v2, v2r { };
43 struct v3rw : v3, v3r { };
44 struct v4rw : v4, v4r { };
45 
BOOST_QVM_REGISTER_VEC_2(v2,float,x,y)46 BOOST_QVM_REGISTER_VEC_2(v2, float, x, y)
47 BOOST_QVM_REGISTER_VEC_3(v3, float, x, y, z)
48 BOOST_QVM_REGISTER_VEC_4(v4, float, x, y, z, w)
49 
50 BOOST_QVM_REGISTER_VEC_2_READ(v2r, float, xr, yr)
51 BOOST_QVM_REGISTER_VEC_3_READ(v3r, float, xr, yr, zr)
52 BOOST_QVM_REGISTER_VEC_4_READ(v4r, float, xr, yr, zr, wr)
53 
54 BOOST_QVM_REGISTER_VEC_2_READ_WRITE(v2rw, float, xr, yr, x, y)
55 BOOST_QVM_REGISTER_VEC_3_READ_WRITE(v3rw, float, xr, yr, zr, x, y, z)
56 BOOST_QVM_REGISTER_VEC_4_READ_WRITE(v4rw, float, xr, yr, zr, wr, x, y, z, w)
57 
58 int main()
59 {
60     using namespace boost::qvm;
61 
62     v2  v_v2;
63     v3  v_v3;
64     v4  v_v4;
65     v2r v_v2r;
66     v3r v_v3r;
67     v4r v_v4r;
68     v2rw v_v2rw;
69     v3rw v_v3rw;
70     v4rw v_v4rw;
71 
72     v_v2.x = 41.f;
73     v_v3.x = 42.f;
74     v_v4.x = 43.f;
75     v_v2.y = 44.f;
76     v_v3.y = 45.f;
77     v_v4.y = 46.f;
78     v_v3.z = 47.f;
79     v_v4.z = 48.f;
80     v_v4.w = 49.f;
81 
82     v_v2r.xr = 51.f;
83     v_v3r.xr = 52.f;
84     v_v4r.xr = 53.f;
85     v_v2r.yr = 54.f;
86     v_v3r.yr = 55.f;
87     v_v4r.yr = 56.f;
88     v_v3r.zr = 57.f;
89     v_v4r.zr = 58.f;
90     v_v4r.wr = 59.f;
91 
92     v_v2rw.x = 61.f;
93     v_v3rw.x = 62.f;
94     v_v4rw.x = 63.f;
95     v_v2rw.y = 64.f;
96     v_v3rw.y = 65.f;
97     v_v4rw.y = 66.f;
98     v_v3rw.z = 67.f;
99     v_v4rw.z = 68.f;
100     v_v4rw.w = 69.f;
101 
102     v_v2rw.xr = 71.f;
103     v_v3rw.xr = 72.f;
104     v_v4rw.xr = 73.f;
105     v_v2rw.yr = 74.f;
106     v_v3rw.yr = 75.f;
107     v_v4rw.yr = 76.f;
108     v_v3rw.zr = 77.f;
109     v_v4rw.zr = 78.f;
110     v_v4rw.wr = 79.f;
111 
112     BOOST_TEST(vec_traits<v2  >::read_element<0>(v_v2  ) == v_v2  .x );
113     BOOST_TEST(vec_traits<v3  >::read_element<0>(v_v3  ) == v_v3  .x );
114     BOOST_TEST(vec_traits<v4  >::read_element<0>(v_v4  ) == v_v4  .x );
115     BOOST_TEST(vec_traits<v2r >::read_element<0>(v_v2r ) == v_v2r .xr);
116     BOOST_TEST(vec_traits<v3r >::read_element<0>(v_v3r ) == v_v3r .xr);
117     BOOST_TEST(vec_traits<v4r >::read_element<0>(v_v4r ) == v_v4r .xr);
118     BOOST_TEST(vec_traits<v2rw>::read_element<0>(v_v2rw) == v_v2rw.xr);
119     BOOST_TEST(vec_traits<v3rw>::read_element<0>(v_v3rw) == v_v3rw.xr);
120     BOOST_TEST(vec_traits<v4rw>::read_element<0>(v_v4rw) == v_v4rw.xr);
121     BOOST_TEST(vec_traits<v2  >::read_element<1>(v_v2  ) == v_v2  .y );
122     BOOST_TEST(vec_traits<v3  >::read_element<1>(v_v3  ) == v_v3  .y );
123     BOOST_TEST(vec_traits<v4  >::read_element<1>(v_v4  ) == v_v4  .y );
124     BOOST_TEST(vec_traits<v2r >::read_element<1>(v_v2r ) == v_v2r .yr);
125     BOOST_TEST(vec_traits<v3r >::read_element<1>(v_v3r ) == v_v3r .yr);
126     BOOST_TEST(vec_traits<v4r >::read_element<1>(v_v4r ) == v_v4r .yr);
127     BOOST_TEST(vec_traits<v2rw>::read_element<1>(v_v2rw) == v_v2rw.yr);
128     BOOST_TEST(vec_traits<v3rw>::read_element<1>(v_v3rw) == v_v3rw.yr);
129     BOOST_TEST(vec_traits<v4rw>::read_element<1>(v_v4rw) == v_v4rw.yr);
130     BOOST_TEST(vec_traits<v3  >::read_element<2>(v_v3  ) == v_v3  .z );
131     BOOST_TEST(vec_traits<v4  >::read_element<2>(v_v4  ) == v_v4  .z );
132     BOOST_TEST(vec_traits<v3r >::read_element<2>(v_v3r ) == v_v3r .zr);
133     BOOST_TEST(vec_traits<v4r >::read_element<2>(v_v4r ) == v_v4r .zr);
134     BOOST_TEST(vec_traits<v3rw>::read_element<2>(v_v3rw) == v_v3rw.zr);
135     BOOST_TEST(vec_traits<v4rw>::read_element<2>(v_v4rw) == v_v4rw.zr);
136     BOOST_TEST(vec_traits<v4  >::read_element<3>(v_v4  ) == v_v4  .w );
137     BOOST_TEST(vec_traits<v4r >::read_element<3>(v_v4r ) == v_v4r .wr);
138     BOOST_TEST(vec_traits<v4rw>::read_element<3>(v_v4rw) == v_v4rw.wr);
139 
140     BOOST_TEST(vec_traits<v2  >::read_element_idx(0, v_v2  ) == v_v2  .x );
141     BOOST_TEST(vec_traits<v3  >::read_element_idx(0, v_v3  ) == v_v3  .x );
142     BOOST_TEST(vec_traits<v4  >::read_element_idx(0, v_v4  ) == v_v4  .x );
143     BOOST_TEST(vec_traits<v2r >::read_element_idx(0, v_v2r ) == v_v2r .xr);
144     BOOST_TEST(vec_traits<v3r >::read_element_idx(0, v_v3r ) == v_v3r .xr);
145     BOOST_TEST(vec_traits<v4r >::read_element_idx(0, v_v4r ) == v_v4r .xr);
146     BOOST_TEST(vec_traits<v2rw>::read_element_idx(0, v_v2rw) == v_v2rw.xr);
147     BOOST_TEST(vec_traits<v3rw>::read_element_idx(0, v_v3rw) == v_v3rw.xr);
148     BOOST_TEST(vec_traits<v4rw>::read_element_idx(0, v_v4rw) == v_v4rw.xr);
149     BOOST_TEST(vec_traits<v2  >::read_element_idx(1, v_v2  ) == v_v2  .y );
150     BOOST_TEST(vec_traits<v3  >::read_element_idx(1, v_v3  ) == v_v3  .y );
151     BOOST_TEST(vec_traits<v4  >::read_element_idx(1, v_v4  ) == v_v4  .y );
152     BOOST_TEST(vec_traits<v2r >::read_element_idx(1, v_v2r ) == v_v2r .yr);
153     BOOST_TEST(vec_traits<v3r >::read_element_idx(1, v_v3r ) == v_v3r .yr);
154     BOOST_TEST(vec_traits<v4r >::read_element_idx(1, v_v4r ) == v_v4r .yr);
155     BOOST_TEST(vec_traits<v2rw>::read_element_idx(1, v_v2rw) == v_v2rw.yr);
156     BOOST_TEST(vec_traits<v3rw>::read_element_idx(1, v_v3rw) == v_v3rw.yr);
157     BOOST_TEST(vec_traits<v4rw>::read_element_idx(1, v_v4rw) == v_v4rw.yr);
158     BOOST_TEST(vec_traits<v3  >::read_element_idx(2, v_v3  ) == v_v3  .z );
159     BOOST_TEST(vec_traits<v4  >::read_element_idx(2, v_v4  ) == v_v4  .z );
160     BOOST_TEST(vec_traits<v3r >::read_element_idx(2, v_v3r ) == v_v3r .zr);
161     BOOST_TEST(vec_traits<v4r >::read_element_idx(2, v_v4r ) == v_v4r .zr);
162     BOOST_TEST(vec_traits<v3rw>::read_element_idx(2, v_v3rw) == v_v3rw.zr);
163     BOOST_TEST(vec_traits<v4rw>::read_element_idx(2, v_v4rw) == v_v4rw.zr);
164     BOOST_TEST(vec_traits<v4  >::read_element_idx(3, v_v4  ) == v_v4  .w );
165     BOOST_TEST(vec_traits<v4r >::read_element_idx(3, v_v4r ) == v_v4r .wr);
166     BOOST_TEST(vec_traits<v4rw>::read_element_idx(3, v_v4rw) == v_v4rw.wr);
167 
168     BOOST_TEST(&vec_traits<v2  >::write_element<0>(v_v2  ) == &v_v2  .x );
169     BOOST_TEST(&vec_traits<v3  >::write_element<0>(v_v3  ) == &v_v3  .x );
170     BOOST_TEST(&vec_traits<v4  >::write_element<0>(v_v4  ) == &v_v4  .x );
171     BOOST_TEST_NOT(&vec_traits<v2rw>::write_element<0>(v_v2rw) == &v_v2rw.xr);
172     BOOST_TEST_NOT(&vec_traits<v3rw>::write_element<0>(v_v3rw) == &v_v3rw.xr);
173     BOOST_TEST_NOT(&vec_traits<v4rw>::write_element<0>(v_v4rw) == &v_v4rw.xr);
174     BOOST_TEST(&vec_traits<v2rw>::write_element<0>(v_v2rw) == &v_v2rw.x );
175     BOOST_TEST(&vec_traits<v3rw>::write_element<0>(v_v3rw) == &v_v3rw.x );
176     BOOST_TEST(&vec_traits<v4rw>::write_element<0>(v_v4rw) == &v_v4rw.x );
177     BOOST_TEST(&vec_traits<v2  >::write_element<1>(v_v2  ) == &v_v2  .y );
178     BOOST_TEST(&vec_traits<v3  >::write_element<1>(v_v3  ) == &v_v3  .y );
179     BOOST_TEST(&vec_traits<v4  >::write_element<1>(v_v4  ) == &v_v4  .y );
180     BOOST_TEST_NOT(&vec_traits<v2rw>::write_element<1>(v_v2rw) == &v_v2rw.yr);
181     BOOST_TEST_NOT(&vec_traits<v3rw>::write_element<1>(v_v3rw) == &v_v3rw.yr);
182     BOOST_TEST_NOT(&vec_traits<v4rw>::write_element<1>(v_v4rw) == &v_v4rw.yr);
183     BOOST_TEST(&vec_traits<v2rw>::write_element<1>(v_v2rw) == &v_v2rw.y );
184     BOOST_TEST(&vec_traits<v3rw>::write_element<1>(v_v3rw) == &v_v3rw.y );
185     BOOST_TEST(&vec_traits<v4rw>::write_element<1>(v_v4rw) == &v_v4rw.y );
186     BOOST_TEST(&vec_traits<v3  >::write_element<2>(v_v3  ) == &v_v3  .z );
187     BOOST_TEST(&vec_traits<v4  >::write_element<2>(v_v4  ) == &v_v4  .z );
188     BOOST_TEST_NOT(&vec_traits<v3rw>::write_element<2>(v_v3rw) == &v_v3rw.zr);
189     BOOST_TEST_NOT(&vec_traits<v4rw>::write_element<2>(v_v4rw) == &v_v4rw.zr);
190     BOOST_TEST(&vec_traits<v3rw>::write_element<2>(v_v3rw) == &v_v3rw.z );
191     BOOST_TEST(&vec_traits<v4rw>::write_element<2>(v_v4rw) == &v_v4rw.z );
192     BOOST_TEST(&vec_traits<v4  >::write_element<3>(v_v4  ) == &v_v4  .w );
193     BOOST_TEST_NOT(&vec_traits<v4rw>::write_element<3>(v_v4rw) == &v_v4rw.wr);
194     BOOST_TEST(&vec_traits<v4rw>::write_element<3>(v_v4rw) == &v_v4rw.w );
195 
196     BOOST_TEST(&vec_traits<v2  >::write_element_idx(0, v_v2  ) == &v_v2  .x );
197     BOOST_TEST(&vec_traits<v3  >::write_element_idx(0, v_v3  ) == &v_v3  .x );
198     BOOST_TEST(&vec_traits<v4  >::write_element_idx(0, v_v4  ) == &v_v4  .x );
199     BOOST_TEST_NOT(&vec_traits<v2rw>::write_element_idx(0, v_v2rw) == &v_v2rw.xr);
200     BOOST_TEST_NOT(&vec_traits<v3rw>::write_element_idx(0, v_v3rw) == &v_v3rw.xr);
201     BOOST_TEST_NOT(&vec_traits<v4rw>::write_element_idx(0, v_v4rw) == &v_v4rw.xr);
202     BOOST_TEST(&vec_traits<v2rw>::write_element_idx(0, v_v2rw) == &v_v2rw.x );
203     BOOST_TEST(&vec_traits<v3rw>::write_element_idx(0, v_v3rw) == &v_v3rw.x );
204     BOOST_TEST(&vec_traits<v4rw>::write_element_idx(0, v_v4rw) == &v_v4rw.x );
205     BOOST_TEST(&vec_traits<v2  >::write_element_idx(1, v_v2  ) == &v_v2  .y );
206     BOOST_TEST(&vec_traits<v3  >::write_element_idx(1, v_v3  ) == &v_v3  .y );
207     BOOST_TEST(&vec_traits<v4  >::write_element_idx(1, v_v4  ) == &v_v4  .y );
208     BOOST_TEST_NOT(&vec_traits<v2rw>::write_element_idx(1, v_v2rw) == &v_v2rw.yr);
209     BOOST_TEST_NOT(&vec_traits<v3rw>::write_element_idx(1, v_v3rw) == &v_v3rw.yr);
210     BOOST_TEST_NOT(&vec_traits<v4rw>::write_element_idx(1, v_v4rw) == &v_v4rw.yr);
211     BOOST_TEST(&vec_traits<v2rw>::write_element_idx(1, v_v2rw) == &v_v2rw.y );
212     BOOST_TEST(&vec_traits<v3rw>::write_element_idx(1, v_v3rw) == &v_v3rw.y );
213     BOOST_TEST(&vec_traits<v4rw>::write_element_idx(1, v_v4rw) == &v_v4rw.y );
214     BOOST_TEST(&vec_traits<v3  >::write_element_idx(2, v_v3  ) == &v_v3  .z );
215     BOOST_TEST(&vec_traits<v4  >::write_element_idx(2, v_v4  ) == &v_v4  .z );
216     BOOST_TEST_NOT(&vec_traits<v3rw>::write_element_idx(2, v_v3rw) == &v_v3rw.zr);
217     BOOST_TEST_NOT(&vec_traits<v4rw>::write_element_idx(2, v_v4rw) == &v_v4rw.zr);
218     BOOST_TEST(&vec_traits<v3rw>::write_element_idx(2, v_v3rw) == &v_v3rw.z );
219     BOOST_TEST(&vec_traits<v4rw>::write_element_idx(2, v_v4rw) == &v_v4rw.z );
220     BOOST_TEST(&vec_traits<v4  >::write_element_idx(3, v_v4  ) == &v_v4  .w );
221     BOOST_TEST_NOT(&vec_traits<v4rw>::write_element_idx(3, v_v4rw) == &v_v4rw.wr);
222     BOOST_TEST(&vec_traits<v4rw>::write_element_idx(3, v_v4rw) == &v_v4rw.w );
223 
224     return boost::report_errors();
225 }
226