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-2013 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 | |
---|
32 | #include "OgreProgressiveMeshGenerator.h" |
---|
33 | #include "OgreSingleton.h" |
---|
34 | #include "OgreWorkQueue.h" |
---|
35 | #include "OgreFrameListener.h" |
---|
36 | |
---|
37 | namespace Ogre |
---|
38 | { |
---|
39 | |
---|
40 | /** |
---|
41 | * @brief Request data structure. |
---|
42 | */ |
---|
43 | struct PMGenRequest { |
---|
44 | struct VertexBuffer { |
---|
45 | size_t vertexCount; |
---|
46 | Vector3* vertexBuffer; |
---|
47 | VertexBuffer() : |
---|
48 | vertexBuffer(0) { } |
---|
49 | }; |
---|
50 | struct IndexBuffer { |
---|
51 | size_t indexSize; |
---|
52 | size_t indexCount; |
---|
53 | unsigned char* indexBuffer; // size in bytes = indexSize * indexCount |
---|
54 | IndexBuffer() : |
---|
55 | indexBuffer(0) { } |
---|
56 | }; |
---|
57 | struct SubmeshInfo { |
---|
58 | vector<IndexBuffer>::type genIndexBuffers; // order: lodlevel/generated index buffer |
---|
59 | IndexBuffer indexBuffer; |
---|
60 | VertexBuffer vertexBuffer; |
---|
61 | bool useSharedVertexBuffer; |
---|
62 | }; |
---|
63 | vector<SubmeshInfo>::type submesh; |
---|
64 | VertexBuffer sharedVertexBuffer; |
---|
65 | LodConfig config; |
---|
66 | String meshName; |
---|
67 | ~PMGenRequest(); |
---|
68 | }; |
---|
69 | |
---|
70 | /** |
---|
71 | * @brief Processes requests. |
---|
72 | */ |
---|
73 | class _OgreExport PMWorker : |
---|
74 | public Singleton<PMWorker>, |
---|
75 | private WorkQueue::RequestHandler, |
---|
76 | private ProgressiveMeshGenerator, |
---|
77 | public LodAlloc |
---|
78 | { |
---|
79 | public: |
---|
80 | PMWorker(); |
---|
81 | virtual ~PMWorker(); |
---|
82 | void addRequestToQueue(PMGenRequest* request); |
---|
83 | void clearPendingLodRequests(); |
---|
84 | |
---|
85 | /** Override standard Singleton retrieval. |
---|
86 | @remarks |
---|
87 | Why do we do this? Well, it's because the Singleton |
---|
88 | implementation is in a .h file, which means it gets compiled |
---|
89 | into anybody who includes it. This is needed for the |
---|
90 | Singleton template to work, but we actually only want it |
---|
91 | compiled into the implementation of the class based on the |
---|
92 | Singleton, not all of them. If we don't change this, we get |
---|
93 | link errors when trying to use the Singleton-based class from |
---|
94 | an outside dll. |
---|
95 | @par |
---|
96 | This method just delegates to the template version anyway, |
---|
97 | but the implementation stays in this single compilation unit, |
---|
98 | preventing link errors. |
---|
99 | */ |
---|
100 | static PMWorker& getSingleton(void); |
---|
101 | /** Override standard Singleton retrieval. |
---|
102 | @remarks |
---|
103 | Why do we do this? Well, it's because the Singleton |
---|
104 | implementation is in a .h file, which means it gets compiled |
---|
105 | into anybody who includes it. This is needed for the |
---|
106 | Singleton template to work, but we actually only want it |
---|
107 | compiled into the implementation of the class based on the |
---|
108 | Singleton, not all of them. If we don't change this, we get |
---|
109 | link errors when trying to use the Singleton-based class from |
---|
110 | an outside dll. |
---|
111 | @par |
---|
112 | This method just delegates to the template version anyway, |
---|
113 | but the implementation stays in this single compilation unit, |
---|
114 | preventing link errors. |
---|
115 | */ |
---|
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(). |
---|
120 | ushort mChannelID; |
---|
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 | |
---|
131 | class _OgreExport PMInjectorListener |
---|
132 | { |
---|
133 | public: |
---|
134 | PMInjectorListener(){} |
---|
135 | virtual ~PMInjectorListener(){} |
---|
136 | virtual bool shouldInject(PMGenRequest* request) = 0; |
---|
137 | virtual void injectionCompleted(PMGenRequest* request) = 0; |
---|
138 | }; |
---|
139 | |
---|
140 | /** |
---|
141 | * @brief Injects the output of a request to the mesh in a thread safe way. |
---|
142 | */ |
---|
143 | class _OgreExport PMInjector : |
---|
144 | public Singleton<PMInjector>, |
---|
145 | public WorkQueue::ResponseHandler, |
---|
146 | public LodAlloc |
---|
147 | { |
---|
148 | public: |
---|
149 | PMInjector(); |
---|
150 | virtual ~PMInjector(); |
---|
151 | |
---|
152 | /** Override standard Singleton retrieval. |
---|
153 | @remarks |
---|
154 | Why do we do this? Well, it's because the Singleton |
---|
155 | implementation is in a .h file, which means it gets compiled |
---|
156 | into anybody who includes it. This is needed for the |
---|
157 | Singleton template to work, but we actually only want it |
---|
158 | compiled into the implementation of the class based on the |
---|
159 | Singleton, not all of them. If we don't change this, we get |
---|
160 | link errors when trying to use the Singleton-based class from |
---|
161 | an outside dll. |
---|
162 | @par |
---|
163 | This method just delegates to the template version anyway, |
---|
164 | but the implementation stays in this single compilation unit, |
---|
165 | preventing link errors. |
---|
166 | */ |
---|
167 | static PMInjector& getSingleton(void); |
---|
168 | /** Override standard Singleton retrieval. |
---|
169 | @remarks |
---|
170 | Why do we do this? Well, it's because the Singleton |
---|
171 | implementation is in a .h file, which means it gets compiled |
---|
172 | into anybody who includes it. This is needed for the |
---|
173 | Singleton template to work, but we actually only want it |
---|
174 | compiled into the implementation of the class based on the |
---|
175 | Singleton, not all of them. If we don't change this, we get |
---|
176 | link errors when trying to use the Singleton-based class from |
---|
177 | an outside dll. |
---|
178 | @par |
---|
179 | This method just delegates to the template version anyway, |
---|
180 | but the implementation stays in this single compilation unit, |
---|
181 | preventing link errors. |
---|
182 | */ |
---|
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 | |
---|
194 | PMInjectorListener* mInjectorListener; |
---|
195 | }; |
---|
196 | |
---|
197 | /** |
---|
198 | * @brief Creates a request for the worker. The interface is compatible with ProgressiveMeshGenerator. |
---|
199 | */ |
---|
200 | class _OgreExport QueuedProgressiveMeshGenerator : |
---|
201 | public ProgressiveMeshGeneratorBase |
---|
202 | { |
---|
203 | public: |
---|
204 | |
---|
205 | /// @copydoc ProgressiveMeshGeneratorBase::generateLodLevels |
---|
206 | void generateLodLevels(LodConfig& lodConfig); |
---|
207 | |
---|
208 | virtual ~QueuedProgressiveMeshGenerator(); |
---|
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 |
---|