OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreLodInputProviderBuffer.h
Go to the documentation of this file.
1 
2 /*
3  * -----------------------------------------------------------------------------
4  * This source file is part of OGRE
5  * (Object-oriented Graphics Rendering Engine)
6  * For the latest info, see http://www.ogre3d.org/
7  *
8  * Copyright (c) 2000-2014 Torus Knot Software Ltd
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a copy
11  * of this software and associated documentation files (the "Software"), to deal
12  * in the Software without restriction, including without limitation the rights
13  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14  * copies of the Software, and to permit persons to whom the Software is
15  * furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included in
18  * all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26  * THE SOFTWARE.
27  * -----------------------------------------------------------------------------
28  */
29 
30 #ifndef _LodInputProviderBuffer_H__
31 #define _LodInputProviderBuffer_H__
32 
33 #include "OgreLodPrerequisites.h"
34 #include "OgreLodInputProvider.h"
35 #include "OgreLodData.h"
36 #include "OgreLodBuffer.h"
37 #include "OgreLogManager.h"
38 
39 namespace Ogre
40 {
41 
43  public LodInputProvider
44 {
45 public:
48  virtual void initData(LodData* data);
49 
50 protected:
51 
53 
55  // This helps to find the vertex* in LodData for index buffer indices
58 
59 
60  void tuneContainerSize(LodData* data);
61  void initialize(LodData* data);
62  void addVertexData(LodData* data, LodVertexBuffer& vertexBuffer, bool useSharedVertexLookup);
63  void addIndexData(LodData* data, LodIndexBuffer& indexBuffer, bool useSharedVertexLookup, unsigned short submeshID);
64  template<typename IndexType>
65  void addIndexDataImpl(LodData* data, IndexType* iPos, const IndexType* iEnd, VertexLookupList& lookup, unsigned short submeshID)
66  {
67  // Loop through all triangles and connect them to the vertices.
68  for (; iPos < iEnd; iPos += 3) {
69  // It should never reallocate or every pointer will be invalid.
70  OgreAssert(data->mTriangleList.capacity() > data->mTriangleList.size(), "");
71  data->mTriangleList.push_back(LodData::Triangle());
72  LodData::Triangle* tri = &data->mTriangleList.back();
73  tri->isRemoved = false;
74  tri->submeshID = submeshID;
75  for (int i = 0; i < 3; i++) {
76  // Invalid index: Index is bigger then vertex buffer size.
77  OgreAssert(iPos[i] < lookup.size(), "");
78  tri->vertexID[i] = iPos[i];
79  tri->vertex[i] = lookup[iPos[i]];
80  }
81  if (tri->isMalformed()) {
82 #if OGRE_DEBUG_MODE
83  stringstream str;
84  str << "In " << data->mMeshName << " malformed triangle found with ID: " << LodData::getVectorIDFromPointer(data->mTriangleList, tri) << ". " <<
85  std::endl;
86  printTriangle(tri, str);
87  str << "It will be excluded from Lod level calculations.";
88  LogManager::getSingleton().stream() << str.str();
89 #endif
90  tri->isRemoved = true;
91  data->mIndexBufferInfoList[tri->submeshID].indexCount -= 3;
92  continue;
93  }
94  tri->computeNormal();
95  addTriangleToEdges(data, tri);
96  }
97  }
98 };
99 
100 }
101 #endif
102 
103 
Data representing all required information from a Mesh. Used by LodInputProviderBuffer.
Definition: OgreLodBuffer.h:54
unsigned int vertexID[3]
ID of the submesh. Usable with mMesh.getSubMesh() function.
Definition: OgreLodData.h:112
unsigned short submeshID
Definition: OgreLodData.h:111
#define OgreAssert(a, b)
Definition: OgreException.h:60
void addIndexDataImpl(LodData *data, IndexType *iPos, const IndexType *iEnd, VertexLookupList &lookup, unsigned short submeshID)
TriangleList mTriangleList
Definition: OgreLodData.h:139
Thread-safe buffer for storing Hardware vertex buffer.
Definition: OgreLodBuffer.h:47
static size_t getVectorIDFromPointer(const std::vector< T, A > &vec, const T *pointer)
Definition: OgreLodData.h:156
Log::Stream stream(LogMessageLevel lml=LML_NORMAL, bool maskDebug=false)
Get a stream on the default log.
IndexBufferInfoList mIndexBufferInfoList
Definition: OgreLodData.h:143
StringStream stringstream
vector< LodData::Vertex * >::type VertexLookupList
void computeNormal()
Vertex ID in the buffer associated with the submeshID.
#define _OgreLodExport
Thread-safe buffer for storing Hardware index buffer.
Definition: OgreLodBuffer.h:38
static LogManager & getSingleton(void)
Override standard Singleton retrieval.