source: OGRE/trunk/ogrenew/Tests/OgreMain/src/EdgeBuilderTests.cpp @ 657

Revision 657, 12.0 KB checked in by mattausch, 19 years ago (diff)

added ogre dependencies and patched ogre sources

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-2005 The OGRE Team
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-----------------------------------------------------------------------------
24*/
25#include "EdgeBuilderTests.h"
26#include "OgreDefaultHardwareBufferManager.h"
27
28// Regsiter the suite
29CPPUNIT_TEST_SUITE_REGISTRATION( EdgeBuilderTests );
30
31void EdgeBuilderTests::setUp()
32{
33    mBufMgr = new DefaultHardwareBufferManager();
34    mLogMgr = new LogManager();
35    mLogMgr->createLog("EdgeBuilderTests.log", true);
36}
37void EdgeBuilderTests::tearDown()
38{
39    delete mBufMgr;
40    delete mLogMgr;
41}
42
43void EdgeBuilderTests::testSingleIndexBufSingleVertexBuf()
44{
45    /* This tests the edge builders ability to find shared edges in the simple case
46    of a single index buffer referencing a single vertex buffer
47    */
48    VertexData vd;
49    IndexData id;
50    // Test pyramid
51    vd.vertexCount = 4;
52    vd.vertexStart = 0;
53    vd.vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
54    vd.vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
55    HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 4, HardwareBuffer::HBU_STATIC,true);
56    vd.vertexBufferBinding->setBinding(0, vbuf);
57    float* pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
58    *pFloat++ = 0  ; *pFloat++ = 0  ; *pFloat++ = 0  ;
59    *pFloat++ = 50 ; *pFloat++ = 0  ; *pFloat++ = 0  ;
60    *pFloat++ = 0  ; *pFloat++ = 100; *pFloat++ = 0  ;
61    *pFloat++ = 0  ; *pFloat++ = 0  ; *pFloat++ = -50;
62    vbuf->unlock();
63
64    id.indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
65        HardwareIndexBuffer::IT_16BIT, 12, HardwareBuffer::HBU_STATIC, true);
66    id.indexCount = 12;
67    id.indexStart = 0;
68    unsigned short* pIdx = static_cast<unsigned short*>(id.indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
69    *pIdx++ = 0; *pIdx++ = 1; *pIdx++ = 2;
70    *pIdx++ = 0; *pIdx++ = 2; *pIdx++ = 3;
71    *pIdx++ = 1; *pIdx++ = 3; *pIdx++ = 2;
72    *pIdx++ = 0; *pIdx++ = 3; *pIdx++ = 1;
73    id.indexBuffer->unlock();
74
75    EdgeListBuilder edgeBuilder;
76    edgeBuilder.addVertexData(&vd);
77    edgeBuilder.addIndexData(&id);
78    EdgeData* edgeData = edgeBuilder.build();
79
80    // Should be only one group, since only one vertex buffer
81    CPPUNIT_ASSERT(edgeData->edgeGroups.size() == 1);
82    // 4 tris
83    CPPUNIT_ASSERT(edgeData->triangles.size() == 4);
84    EdgeData::EdgeGroup& eg = edgeData->edgeGroups[0];
85    // 6 edges
86    CPPUNIT_ASSERT(eg.edges.size() == 6);
87
88    delete edgeData;
89
90
91}
92
93void EdgeBuilderTests::testMultiIndexBufSingleVertexBuf()
94{
95    /* This tests the edge builders ability to find shared edges when there are
96    multiple index sets (submeshes) using a single vertex buffer.
97    */
98    VertexData vd;
99    IndexData id[4];
100    // Test pyramid
101    vd.vertexCount = 4;
102    vd.vertexStart = 0;
103    vd.vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
104    vd.vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
105    HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 4, HardwareBuffer::HBU_STATIC,true);
106    vd.vertexBufferBinding->setBinding(0, vbuf);
107    float* pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
108    *pFloat++ = 0  ; *pFloat++ = 0  ; *pFloat++ = 0  ;
109    *pFloat++ = 50 ; *pFloat++ = 0  ; *pFloat++ = 0  ;
110    *pFloat++ = 0  ; *pFloat++ = 100; *pFloat++ = 0  ;
111    *pFloat++ = 0  ; *pFloat++ = 0  ; *pFloat++ = -50;
112    vbuf->unlock();
113
114    id[0].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
115        HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
116    id[0].indexCount = 3;
117    id[0].indexStart = 0;
118    unsigned short* pIdx = static_cast<unsigned short*>(id[0].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
119    *pIdx++ = 0; *pIdx++ = 1; *pIdx++ = 2;
120    id[0].indexBuffer->unlock();
121
122    id[1].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
123        HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
124    id[1].indexCount = 3;
125    id[1].indexStart = 0;
126    pIdx = static_cast<unsigned short*>(id[1].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
127    *pIdx++ = 0; *pIdx++ = 2; *pIdx++ = 3;
128    id[1].indexBuffer->unlock();
129
130    id[2].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
131        HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
132    id[2].indexCount = 3;
133    id[2].indexStart = 0;
134    pIdx = static_cast<unsigned short*>(id[2].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
135    *pIdx++ = 1; *pIdx++ = 3; *pIdx++ = 2;
136    id[2].indexBuffer->unlock();
137
138    id[3].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
139        HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
140    id[3].indexCount = 3;
141    id[3].indexStart = 0;
142    pIdx = static_cast<unsigned short*>(id[3].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
143    *pIdx++ = 0; *pIdx++ = 3; *pIdx++ = 1;
144    id[3].indexBuffer->unlock();
145
146    EdgeListBuilder edgeBuilder;
147    edgeBuilder.addVertexData(&vd);
148    edgeBuilder.addIndexData(&id[0]);
149    edgeBuilder.addIndexData(&id[1]);
150    edgeBuilder.addIndexData(&id[2]);
151    edgeBuilder.addIndexData(&id[3]);
152    EdgeData* edgeData = edgeBuilder.build();
153
154    // Should be only one group, since only one vertex buffer
155    CPPUNIT_ASSERT(edgeData->edgeGroups.size() == 1);
156    // 4 tris
157    CPPUNIT_ASSERT(edgeData->triangles.size() == 4);
158    EdgeData::EdgeGroup& eg = edgeData->edgeGroups[0];
159    // 6 edges
160    CPPUNIT_ASSERT(eg.edges.size() == 6);
161
162    delete edgeData;
163
164
165}
166
167
168void EdgeBuilderTests::testMultiIndexBufMultiVertexBuf()
169{
170    /* This tests the edge builders ability to find shared edges when there are
171    both multiple index sets (submeshes) each using a different vertex buffer
172    (not using shared geoemtry).
173    */
174
175    VertexData vd[4];
176    IndexData id[4];
177    // Test pyramid
178    vd[0].vertexCount = 3;
179    vd[0].vertexStart = 0;
180    vd[0].vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
181    vd[0].vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
182    HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 3, HardwareBuffer::HBU_STATIC,true);
183    vd[0].vertexBufferBinding->setBinding(0, vbuf);
184    float* pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
185    *pFloat++ = 0  ; *pFloat++ = 0  ; *pFloat++ = 0  ;
186    *pFloat++ = 50 ; *pFloat++ = 0  ; *pFloat++ = 0  ;
187    *pFloat++ = 0  ; *pFloat++ = 100; *pFloat++ = 0  ;
188    vbuf->unlock();
189
190    vd[1].vertexCount = 3;
191    vd[1].vertexStart = 0;
192    vd[1].vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
193    vd[1].vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
194    vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 3, HardwareBuffer::HBU_STATIC,true);
195    vd[1].vertexBufferBinding->setBinding(0, vbuf);
196    pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
197    *pFloat++ = 0  ; *pFloat++ = 0  ; *pFloat++ = 0  ;
198    *pFloat++ = 0  ; *pFloat++ = 100; *pFloat++ = 0  ;
199    *pFloat++ = 0  ; *pFloat++ = 0  ; *pFloat++ = -50;
200    vbuf->unlock();
201
202    vd[2].vertexCount = 3;
203    vd[2].vertexStart = 0;
204    vd[2].vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
205    vd[2].vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
206    vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 3, HardwareBuffer::HBU_STATIC,true);
207    vd[2].vertexBufferBinding->setBinding(0, vbuf);
208    pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
209    *pFloat++ = 50 ; *pFloat++ = 0  ; *pFloat++ = 0  ;
210    *pFloat++ = 0  ; *pFloat++ = 100; *pFloat++ = 0  ;
211    *pFloat++ = 0  ; *pFloat++ = 0  ; *pFloat++ = -50;
212    vbuf->unlock();
213
214    vd[3].vertexCount = 3;
215    vd[3].vertexStart = 0;
216    vd[3].vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
217    vd[3].vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
218    vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 3, HardwareBuffer::HBU_STATIC,true);
219    vd[3].vertexBufferBinding->setBinding(0, vbuf);
220    pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
221    *pFloat++ = 0  ; *pFloat++ = 0  ; *pFloat++ = 0  ;
222    *pFloat++ = 50 ; *pFloat++ = 0  ; *pFloat++ = 0  ;
223    *pFloat++ = 0  ; *pFloat++ = 0  ; *pFloat++ = -50;
224    vbuf->unlock();
225
226    id[0].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
227        HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
228    id[0].indexCount = 3;
229    id[0].indexStart = 0;
230    unsigned short* pIdx = static_cast<unsigned short*>(id[0].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
231    *pIdx++ = 0; *pIdx++ = 1; *pIdx++ = 2;
232    id[0].indexBuffer->unlock();
233
234    id[1].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
235        HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
236    id[1].indexCount = 3;
237    id[1].indexStart = 0;
238    pIdx = static_cast<unsigned short*>(id[1].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
239    *pIdx++ = 0; *pIdx++ = 1; *pIdx++ = 2;
240    id[1].indexBuffer->unlock();
241
242    id[2].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
243        HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
244    id[2].indexCount = 3;
245    id[2].indexStart = 0;
246    pIdx = static_cast<unsigned short*>(id[2].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
247    *pIdx++ = 0; *pIdx++ = 2; *pIdx++ = 1;
248    id[2].indexBuffer->unlock();
249
250    id[3].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
251        HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
252    id[3].indexCount = 3;
253    id[3].indexStart = 0;
254    pIdx = static_cast<unsigned short*>(id[3].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
255    *pIdx++ = 0; *pIdx++ = 2; *pIdx++ = 1;
256    id[3].indexBuffer->unlock();
257
258    EdgeListBuilder edgeBuilder;
259    edgeBuilder.addVertexData(&vd[0]);
260    edgeBuilder.addVertexData(&vd[1]);
261    edgeBuilder.addVertexData(&vd[2]);
262    edgeBuilder.addVertexData(&vd[3]);
263    edgeBuilder.addIndexData(&id[0], 0);
264    edgeBuilder.addIndexData(&id[1], 1);
265    edgeBuilder.addIndexData(&id[2], 2);
266    edgeBuilder.addIndexData(&id[3], 3);
267    EdgeData* edgeData = edgeBuilder.build();
268
269    // Should be 4 groups
270    CPPUNIT_ASSERT(edgeData->edgeGroups.size() == 4);
271    // 4 tris
272    CPPUNIT_ASSERT(edgeData->triangles.size() == 4);
273    // 6 edges in total
274    CPPUNIT_ASSERT(
275        (edgeData->edgeGroups[0].edges.size() +
276        edgeData->edgeGroups[1].edges.size() +
277        edgeData->edgeGroups[2].edges.size() +
278        edgeData->edgeGroups[3].edges.size())
279                    == 6);
280
281    delete edgeData;
282
283
284}
Note: See TracBrowser for help on using the repository browser.