OGRE  1.9
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreQueuedProgressiveMeshGenerator.h
Go to the documentation of this file.
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-2014 Torus Knot Software Ltd
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy
10  * of this software and associated documentation files (the "Software"), to deal
11  * in the Software without restriction, including without limitation the rights
12  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13  * copies of the Software, and to permit persons to whom the Software is
14  * furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included in
17  * all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25  * THE SOFTWARE.
26  * -----------------------------------------------------------------------------
27  */
28 
29 #ifndef __QueuedProgressiveMeshGenerator_H_
30 #define __QueuedProgressiveMeshGenerator_H_
31 
33 #include "OgreSingleton.h"
34 #include "OgreWorkQueue.h"
35 #include "OgreFrameListener.h"
36 
37 namespace Ogre
38 {
39 
43 struct PMGenRequest {
44  struct VertexBuffer {
45  size_t vertexCount;
48  vertexBuffer(0) { }
49  };
50  struct IndexBuffer {
51  size_t indexSize;
52  size_t indexCount;
53  unsigned char* indexBuffer; // size in bytes = indexSize * indexCount
55  indexBuffer(0) { }
56  };
57  struct SubmeshInfo {
58  vector<IndexBuffer>::type genIndexBuffers; // order: lodlevel/generated index buffer
62  };
67  ~PMGenRequest();
68 };
69 
74  public Singleton<PMWorker>,
77  public LodAlloc
78 {
79 public:
80  PMWorker();
81  virtual ~PMWorker();
82  void addRequestToQueue(PMGenRequest* request);
83  void clearPendingLodRequests();
84 
100  static PMWorker& getSingleton(void);
116  static PMWorker* getSingletonPtr(void);
117 
118 private:
119  PMGenRequest* mRequest; // This is a copy of the current processed request from stack. This is needed to pass it to overloaded functions like bakeLods().
121 
122  WorkQueue::Response* handleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
123  void buildRequest(LodConfig& lodConfigs);
124  void tuneContainerSize();
125  void initialize();
126  void addVertexBuffer(const PMGenRequest::VertexBuffer& vertexBuffer, bool useSharedVertexLookup);
127  void addIndexBuffer(PMGenRequest::IndexBuffer& indexBuffer, bool useSharedVertexLookup, unsigned short submeshID);
128  void bakeLods();
129 };
130 
132 {
133 public:
136  virtual bool shouldInject(PMGenRequest* request) = 0;
137  virtual void injectionCompleted(PMGenRequest* request) = 0;
138 };
139 
144  public Singleton<PMInjector>,
146  public LodAlloc
147 {
148 public:
149  PMInjector();
150  virtual ~PMInjector();
151 
167  static PMInjector& getSingleton(void);
183  static PMInjector* getSingletonPtr(void);
184 
185  void handleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
186 
187  void setInjectorListener(PMInjectorListener* injectorListener) {mInjectorListener = injectorListener;}
188  void removeInjectorListener() {mInjectorListener = 0;}
189 protected:
190 
191  // Copies every generated LOD level to the mesh.
192  void inject(PMGenRequest* request);
193 
195 };
196 
202 {
203 public:
204 
206  void generateLodLevels(LodConfig& lodConfig);
207 
209 
210 private:
211  void copyVertexBuffer(VertexData* data, PMGenRequest::VertexBuffer& out);
212  void copyIndexBuffer(IndexData* data, PMGenRequest::IndexBuffer& out);
213  void copyBuffers(Mesh* mesh, PMGenRequest* req);
214 };
215 
216 }
217 #endif
void setInjectorListener(PMInjectorListener *injectorListener)
#define _OgreExport
Definition: OgrePlatform.h:260
std::vector< T, A > type
General purpose request structure.
Definition: OgreWorkQueue.h:83
Injects the output of a request to the mesh in a thread safe way.
Template class for creating single-instance global classes.
Definition: OgreSingleton.h:64
General purpose response structure.
vector< SubmeshInfo >::type submesh
Improved version of ProgressiveMesh.
Interface definition for a handler of requests.
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Summary class collecting together index data source information.
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
Interface definition for a handler of responses.
unsigned short ushort
Summary class collecting together vertex source information.
PMInjectorListener * mInjectorListener
_StringBase String
Resource holding data about 3D mesh.
Definition: OgreMesh.h:93
Interface to a general purpose request / response style background work queue.
Definition: OgreWorkQueue.h:70