OgreQueuedProgressiveMeshGenerator.h
Go to the documentation of this file.
00001 /*
00002  * -----------------------------------------------------------------------------
00003  * This source file is part of OGRE
00004  * (Object-oriented Graphics Rendering Engine)
00005  * For the latest info, see http://www.ogre3d.org/
00006  *
00007  * Copyright (c) 2000-2013 Torus Knot Software Ltd
00008  *
00009  * Permission is hereby granted, free of charge, to any person obtaining a copy
00010  * of this software and associated documentation files (the "Software"), to deal
00011  * in the Software without restriction, including without limitation the rights
00012  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013  * copies of the Software, and to permit persons to whom the Software is
00014  * furnished to do so, subject to the following conditions:
00015  *
00016  * The above copyright notice and this permission notice shall be included in
00017  * all copies or substantial portions of the Software.
00018  *
00019  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025  * THE SOFTWARE.
00026  * -----------------------------------------------------------------------------
00027  */
00028 
00029 #ifndef __QueuedProgressiveMeshGenerator_H_
00030 #define __QueuedProgressiveMeshGenerator_H_
00031 
00032 #include "OgreProgressiveMeshGenerator.h"
00033 #include "OgreSingleton.h"
00034 #include "OgreWorkQueue.h"
00035 #include "OgreFrameListener.h"
00036 
00037 namespace Ogre
00038 {
00039 
00043 struct PMGenRequest {
00044     struct VertexBuffer {
00045         size_t vertexCount;
00046         Vector3* vertexBuffer;
00047         VertexBuffer() :
00048             vertexBuffer(0) { }
00049     };
00050     struct IndexBuffer {
00051         size_t indexSize;
00052         size_t indexCount;
00053         unsigned char* indexBuffer; // size in bytes = indexSize * indexCount
00054         IndexBuffer() :
00055             indexBuffer(0) { }
00056     };
00057     struct SubmeshInfo {
00058         vector<IndexBuffer>::type genIndexBuffers; // order: lodlevel/generated index buffer
00059         IndexBuffer indexBuffer;
00060         VertexBuffer vertexBuffer;
00061         bool useSharedVertexBuffer;
00062     };
00063     vector<SubmeshInfo>::type submesh;
00064     VertexBuffer sharedVertexBuffer;
00065     LodConfig config;
00066     String meshName;
00067     ~PMGenRequest();
00068 };
00069 
00073 class _OgreExport PMWorker :
00074     public Singleton<PMWorker>,
00075     private WorkQueue::RequestHandler,
00076     private ProgressiveMeshGenerator,
00077     public LodAlloc
00078 {
00079 public:
00080     PMWorker();
00081     virtual ~PMWorker();
00082     void addRequestToQueue(PMGenRequest* request);
00083     void clearPendingLodRequests();
00084     
00100   static PMWorker& getSingleton(void);
00116   static PMWorker* getSingletonPtr(void);
00117         
00118 private:
00119     PMGenRequest* mRequest; // This is a copy of the current processed request from stack. This is needed to pass it to overloaded functions like bakeLods().
00120     ushort mChannelID;
00121 
00122     WorkQueue::Response* handleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
00123     void buildRequest(LodConfig& lodConfigs);
00124     void tuneContainerSize();
00125     void initialize();
00126     void addVertexBuffer(const PMGenRequest::VertexBuffer& vertexBuffer, bool useSharedVertexLookup);
00127     void addIndexBuffer(PMGenRequest::IndexBuffer& indexBuffer, bool useSharedVertexLookup, unsigned short submeshID);
00128     void bakeLods();
00129 };
00130 
00131 class _OgreExport PMInjectorListener
00132 {
00133 public:
00134     PMInjectorListener(){}
00135     virtual ~PMInjectorListener(){}
00136     virtual bool shouldInject(PMGenRequest* request) = 0;
00137     virtual void injectionCompleted(PMGenRequest* request) = 0;
00138 };
00139 
00143 class _OgreExport PMInjector :
00144     public Singleton<PMInjector>,
00145     public WorkQueue::ResponseHandler,
00146     public LodAlloc
00147 {
00148 public:
00149     PMInjector();
00150     virtual ~PMInjector();
00151     
00167   static PMInjector& getSingleton(void);
00183   static PMInjector* getSingletonPtr(void);
00184 
00185     void handleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
00186 
00187     void setInjectorListener(PMInjectorListener* injectorListener) {mInjectorListener = injectorListener;}
00188     void removeInjectorListener() {mInjectorListener = 0;}
00189 protected:
00190 
00191     // Copies every generated LOD level to the mesh.
00192     void inject(PMGenRequest* request);
00193 
00194     PMInjectorListener* mInjectorListener;
00195 };
00196 
00200 class _OgreExport QueuedProgressiveMeshGenerator :
00201     public ProgressiveMeshGeneratorBase
00202 {
00203 public:
00204 
00206     void generateLodLevels(LodConfig& lodConfig);
00207 
00208     virtual ~QueuedProgressiveMeshGenerator();
00209 
00210 private:
00211     void copyVertexBuffer(VertexData* data, PMGenRequest::VertexBuffer& out);
00212     void copyIndexBuffer(IndexData* data, PMGenRequest::IndexBuffer& out);
00213     void copyBuffers(Mesh* mesh, PMGenRequest* req);
00214 };
00215 
00216 }
00217 #endif

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:45