1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://www.ogre3d.org/
|
---|
6 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 | #include "EdgeBuilderTests.h"
|
---|
26 | #include "OgreDefaultHardwareBufferManager.h"
|
---|
27 | #include "OgreVertexIndexData.h"
|
---|
28 | #include "OgreEdgeListBuilder.h"
|
---|
29 |
|
---|
30 | // Regsiter the suite
|
---|
31 | CPPUNIT_TEST_SUITE_REGISTRATION( EdgeBuilderTests );
|
---|
32 |
|
---|
33 | void EdgeBuilderTests::setUp()
|
---|
34 | {
|
---|
35 | mBufMgr = new DefaultHardwareBufferManager();
|
---|
36 | //mLogMgr = new LogManager();
|
---|
37 | LogManager::getSingleton().createLog("EdgeBuilderTests.log", true);
|
---|
38 | }
|
---|
39 | void EdgeBuilderTests::tearDown()
|
---|
40 | {
|
---|
41 | delete mBufMgr;
|
---|
42 | //delete mLogMgr;
|
---|
43 | }
|
---|
44 |
|
---|
45 | void EdgeBuilderTests::testSingleIndexBufSingleVertexBuf()
|
---|
46 | {
|
---|
47 | /* This tests the edge builders ability to find shared edges in the simple case
|
---|
48 | of a single index buffer referencing a single vertex buffer
|
---|
49 | */
|
---|
50 | VertexData vd;
|
---|
51 | IndexData id;
|
---|
52 | // Test pyramid
|
---|
53 | vd.vertexCount = 4;
|
---|
54 | vd.vertexStart = 0;
|
---|
55 | vd.vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
|
---|
56 | vd.vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
|
---|
57 | HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 4, HardwareBuffer::HBU_STATIC,true);
|
---|
58 | vd.vertexBufferBinding->setBinding(0, vbuf);
|
---|
59 | float* pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
|
---|
60 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
61 | *pFloat++ = 50 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
62 | *pFloat++ = 0 ; *pFloat++ = 100; *pFloat++ = 0 ;
|
---|
63 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = -50;
|
---|
64 | vbuf->unlock();
|
---|
65 |
|
---|
66 | id.indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
67 | HardwareIndexBuffer::IT_16BIT, 12, HardwareBuffer::HBU_STATIC, true);
|
---|
68 | id.indexCount = 12;
|
---|
69 | id.indexStart = 0;
|
---|
70 | unsigned short* pIdx = static_cast<unsigned short*>(id.indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
71 | *pIdx++ = 0; *pIdx++ = 1; *pIdx++ = 2;
|
---|
72 | *pIdx++ = 0; *pIdx++ = 2; *pIdx++ = 3;
|
---|
73 | *pIdx++ = 1; *pIdx++ = 3; *pIdx++ = 2;
|
---|
74 | *pIdx++ = 0; *pIdx++ = 3; *pIdx++ = 1;
|
---|
75 | id.indexBuffer->unlock();
|
---|
76 |
|
---|
77 | EdgeListBuilder edgeBuilder;
|
---|
78 | edgeBuilder.addVertexData(&vd);
|
---|
79 | edgeBuilder.addIndexData(&id);
|
---|
80 | EdgeData* edgeData = edgeBuilder.build();
|
---|
81 |
|
---|
82 | // Should be only one group, since only one vertex buffer
|
---|
83 | CPPUNIT_ASSERT(edgeData->edgeGroups.size() == 1);
|
---|
84 | // 4 tris
|
---|
85 | CPPUNIT_ASSERT(edgeData->triangles.size() == 4);
|
---|
86 | EdgeData::EdgeGroup& eg = edgeData->edgeGroups[0];
|
---|
87 | // 6 edges
|
---|
88 | CPPUNIT_ASSERT(eg.edges.size() == 6);
|
---|
89 |
|
---|
90 | delete edgeData;
|
---|
91 |
|
---|
92 |
|
---|
93 | }
|
---|
94 |
|
---|
95 | void EdgeBuilderTests::testMultiIndexBufSingleVertexBuf()
|
---|
96 | {
|
---|
97 | /* This tests the edge builders ability to find shared edges when there are
|
---|
98 | multiple index sets (submeshes) using a single vertex buffer.
|
---|
99 | */
|
---|
100 | VertexData vd;
|
---|
101 | IndexData id[4];
|
---|
102 | // Test pyramid
|
---|
103 | vd.vertexCount = 4;
|
---|
104 | vd.vertexStart = 0;
|
---|
105 | vd.vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
|
---|
106 | vd.vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
|
---|
107 | HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 4, HardwareBuffer::HBU_STATIC,true);
|
---|
108 | vd.vertexBufferBinding->setBinding(0, vbuf);
|
---|
109 | float* pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
|
---|
110 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
111 | *pFloat++ = 50 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
112 | *pFloat++ = 0 ; *pFloat++ = 100; *pFloat++ = 0 ;
|
---|
113 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = -50;
|
---|
114 | vbuf->unlock();
|
---|
115 |
|
---|
116 | id[0].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
117 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
|
---|
118 | id[0].indexCount = 3;
|
---|
119 | id[0].indexStart = 0;
|
---|
120 | unsigned short* pIdx = static_cast<unsigned short*>(id[0].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
121 | *pIdx++ = 0; *pIdx++ = 1; *pIdx++ = 2;
|
---|
122 | id[0].indexBuffer->unlock();
|
---|
123 |
|
---|
124 | id[1].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
125 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
|
---|
126 | id[1].indexCount = 3;
|
---|
127 | id[1].indexStart = 0;
|
---|
128 | pIdx = static_cast<unsigned short*>(id[1].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
129 | *pIdx++ = 0; *pIdx++ = 2; *pIdx++ = 3;
|
---|
130 | id[1].indexBuffer->unlock();
|
---|
131 |
|
---|
132 | id[2].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
133 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
|
---|
134 | id[2].indexCount = 3;
|
---|
135 | id[2].indexStart = 0;
|
---|
136 | pIdx = static_cast<unsigned short*>(id[2].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
137 | *pIdx++ = 1; *pIdx++ = 3; *pIdx++ = 2;
|
---|
138 | id[2].indexBuffer->unlock();
|
---|
139 |
|
---|
140 | id[3].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
141 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
|
---|
142 | id[3].indexCount = 3;
|
---|
143 | id[3].indexStart = 0;
|
---|
144 | pIdx = static_cast<unsigned short*>(id[3].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
145 | *pIdx++ = 0; *pIdx++ = 3; *pIdx++ = 1;
|
---|
146 | id[3].indexBuffer->unlock();
|
---|
147 |
|
---|
148 | EdgeListBuilder edgeBuilder;
|
---|
149 | edgeBuilder.addVertexData(&vd);
|
---|
150 | edgeBuilder.addIndexData(&id[0]);
|
---|
151 | edgeBuilder.addIndexData(&id[1]);
|
---|
152 | edgeBuilder.addIndexData(&id[2]);
|
---|
153 | edgeBuilder.addIndexData(&id[3]);
|
---|
154 | EdgeData* edgeData = edgeBuilder.build();
|
---|
155 |
|
---|
156 | // Should be only one group, since only one vertex buffer
|
---|
157 | CPPUNIT_ASSERT(edgeData->edgeGroups.size() == 1);
|
---|
158 | // 4 tris
|
---|
159 | CPPUNIT_ASSERT(edgeData->triangles.size() == 4);
|
---|
160 | EdgeData::EdgeGroup& eg = edgeData->edgeGroups[0];
|
---|
161 | // 6 edges
|
---|
162 | CPPUNIT_ASSERT(eg.edges.size() == 6);
|
---|
163 |
|
---|
164 | delete edgeData;
|
---|
165 |
|
---|
166 |
|
---|
167 | }
|
---|
168 |
|
---|
169 |
|
---|
170 | void EdgeBuilderTests::testMultiIndexBufMultiVertexBuf()
|
---|
171 | {
|
---|
172 | /* This tests the edge builders ability to find shared edges when there are
|
---|
173 | both multiple index sets (submeshes) each using a different vertex buffer
|
---|
174 | (not using shared geoemtry).
|
---|
175 | */
|
---|
176 |
|
---|
177 | VertexData vd[4];
|
---|
178 | IndexData id[4];
|
---|
179 | // Test pyramid
|
---|
180 | vd[0].vertexCount = 3;
|
---|
181 | vd[0].vertexStart = 0;
|
---|
182 | vd[0].vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
|
---|
183 | vd[0].vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
|
---|
184 | HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 3, HardwareBuffer::HBU_STATIC,true);
|
---|
185 | vd[0].vertexBufferBinding->setBinding(0, vbuf);
|
---|
186 | float* pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
|
---|
187 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
188 | *pFloat++ = 50 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
189 | *pFloat++ = 0 ; *pFloat++ = 100; *pFloat++ = 0 ;
|
---|
190 | vbuf->unlock();
|
---|
191 |
|
---|
192 | vd[1].vertexCount = 3;
|
---|
193 | vd[1].vertexStart = 0;
|
---|
194 | vd[1].vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
|
---|
195 | vd[1].vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
|
---|
196 | vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 3, HardwareBuffer::HBU_STATIC,true);
|
---|
197 | vd[1].vertexBufferBinding->setBinding(0, vbuf);
|
---|
198 | pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
|
---|
199 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
200 | *pFloat++ = 0 ; *pFloat++ = 100; *pFloat++ = 0 ;
|
---|
201 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = -50;
|
---|
202 | vbuf->unlock();
|
---|
203 |
|
---|
204 | vd[2].vertexCount = 3;
|
---|
205 | vd[2].vertexStart = 0;
|
---|
206 | vd[2].vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
|
---|
207 | vd[2].vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
|
---|
208 | vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 3, HardwareBuffer::HBU_STATIC,true);
|
---|
209 | vd[2].vertexBufferBinding->setBinding(0, vbuf);
|
---|
210 | pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
|
---|
211 | *pFloat++ = 50 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
212 | *pFloat++ = 0 ; *pFloat++ = 100; *pFloat++ = 0 ;
|
---|
213 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = -50;
|
---|
214 | vbuf->unlock();
|
---|
215 |
|
---|
216 | vd[3].vertexCount = 3;
|
---|
217 | vd[3].vertexStart = 0;
|
---|
218 | vd[3].vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
|
---|
219 | vd[3].vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
|
---|
220 | vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 3, HardwareBuffer::HBU_STATIC,true);
|
---|
221 | vd[3].vertexBufferBinding->setBinding(0, vbuf);
|
---|
222 | pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
|
---|
223 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
224 | *pFloat++ = 50 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
225 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = -50;
|
---|
226 | vbuf->unlock();
|
---|
227 |
|
---|
228 | id[0].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
229 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
|
---|
230 | id[0].indexCount = 3;
|
---|
231 | id[0].indexStart = 0;
|
---|
232 | unsigned short* pIdx = static_cast<unsigned short*>(id[0].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
233 | *pIdx++ = 0; *pIdx++ = 1; *pIdx++ = 2;
|
---|
234 | id[0].indexBuffer->unlock();
|
---|
235 |
|
---|
236 | id[1].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
237 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
|
---|
238 | id[1].indexCount = 3;
|
---|
239 | id[1].indexStart = 0;
|
---|
240 | pIdx = static_cast<unsigned short*>(id[1].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
241 | *pIdx++ = 0; *pIdx++ = 1; *pIdx++ = 2;
|
---|
242 | id[1].indexBuffer->unlock();
|
---|
243 |
|
---|
244 | id[2].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
245 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
|
---|
246 | id[2].indexCount = 3;
|
---|
247 | id[2].indexStart = 0;
|
---|
248 | pIdx = static_cast<unsigned short*>(id[2].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
249 | *pIdx++ = 0; *pIdx++ = 2; *pIdx++ = 1;
|
---|
250 | id[2].indexBuffer->unlock();
|
---|
251 |
|
---|
252 | id[3].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
253 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
|
---|
254 | id[3].indexCount = 3;
|
---|
255 | id[3].indexStart = 0;
|
---|
256 | pIdx = static_cast<unsigned short*>(id[3].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
257 | *pIdx++ = 0; *pIdx++ = 2; *pIdx++ = 1;
|
---|
258 | id[3].indexBuffer->unlock();
|
---|
259 |
|
---|
260 | EdgeListBuilder edgeBuilder;
|
---|
261 | edgeBuilder.addVertexData(&vd[0]);
|
---|
262 | edgeBuilder.addVertexData(&vd[1]);
|
---|
263 | edgeBuilder.addVertexData(&vd[2]);
|
---|
264 | edgeBuilder.addVertexData(&vd[3]);
|
---|
265 | edgeBuilder.addIndexData(&id[0], 0);
|
---|
266 | edgeBuilder.addIndexData(&id[1], 1);
|
---|
267 | edgeBuilder.addIndexData(&id[2], 2);
|
---|
268 | edgeBuilder.addIndexData(&id[3], 3);
|
---|
269 | EdgeData* edgeData = edgeBuilder.build();
|
---|
270 |
|
---|
271 | // Should be 4 groups
|
---|
272 | CPPUNIT_ASSERT(edgeData->edgeGroups.size() == 4);
|
---|
273 | // 4 tris
|
---|
274 | CPPUNIT_ASSERT(edgeData->triangles.size() == 4);
|
---|
275 | // 6 edges in total
|
---|
276 | CPPUNIT_ASSERT(
|
---|
277 | (edgeData->edgeGroups[0].edges.size() +
|
---|
278 | edgeData->edgeGroups[1].edges.size() +
|
---|
279 | edgeData->edgeGroups[2].edges.size() +
|
---|
280 | edgeData->edgeGroups[3].edges.size())
|
---|
281 | == 6);
|
---|
282 |
|
---|
283 | delete edgeData;
|
---|
284 |
|
---|
285 |
|
---|
286 | }
|
---|