Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/Tests/OgreMain/src/EdgeBuilderTests.cpp @ 1

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