Multithreaded scene initialization

This commit is contained in:
Emil Axelsson
2017-12-17 17:34:46 +01:00
parent 7cc05ba2e0
commit df259f6d02
11 changed files with 199 additions and 11 deletions
+9 -2
View File
@@ -33,13 +33,14 @@
#include <mutex>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/scene/sceneinitializer.h>
#include <openspace/scene/scenelicense.h>
#include <openspace/scene/scenelicensewriter.h>
#include <openspace/scripting/scriptengine.h>
#include <openspace/util/camera.h>
#include <openspace/util/updatestructures.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/programobject.h>
namespace ghoul { class Dictionary; }
@@ -65,7 +66,7 @@ public:
};
// constructors & destructor
Scene();
Scene(std::unique_ptr<SceneInitializer> initializer);
~Scene();
/**
@@ -160,6 +161,11 @@ public:
*/
SceneGraphNode* loadNode(const ghoul::Dictionary& nodeDictionary);
/**
* Initialize a scene graph node.
*/
void initializeNode(SceneGraphNode* node);
/**
* Returns the Lua library that contains all Lua functions available to change the
* scene graph. The functions contained are
@@ -188,6 +194,7 @@ private:
std::unordered_map<std::string, SceneGraphNode*> _nodesByName;
bool _dirtyNodeRegistry;
SceneGraphNode _rootDummy;
std::unique_ptr<SceneInitializer> _initializer;
std::vector<SceneLicense> _licenses;
+7
View File
@@ -54,6 +54,12 @@ namespace documentation { struct Documentation; }
class SceneGraphNode : public properties::PropertyOwner {
public:
enum class State : int {
Loaded,
Initialized,
GLInitialized
};
using UpdateScene = ghoul::Boolean;
struct PerformanceRecord {
@@ -138,6 +144,7 @@ private:
glm::dmat3 calculateWorldRotation() const;
double calculateWorldScale() const;
std::atomic<State> _state;
std::vector<std::unique_ptr<SceneGraphNode>> _children;
SceneGraphNode* _parent;
std::vector<SceneGraphNode*> _dependencies;
@@ -0,0 +1,65 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_CORE___SCENEINITIALIZER___H__
#define __OPENSPACE_CORE___SCENEINITIALIZER___H__
#include <openspace/scene/scenegraphnode.h>
#include <ghoul/misc/threadpool.h>
#include <mutex>
namespace openspace {
class SceneInitializer {
public:
virtual ~SceneInitializer() = default;
virtual void initializeNode(SceneGraphNode* node) = 0;
virtual std::vector<SceneGraphNode*> getInitializedNodes() = 0;
};
class SingleThreadedSceneInitializer : public SceneInitializer {
public:
void initializeNode(SceneGraphNode* node) override;
std::vector<SceneGraphNode*> getInitializedNodes() override;
private:
std::vector<SceneGraphNode*> _initializedNodes;
};
class MultiThreadedSceneInitializer : public SceneInitializer {
public:
MultiThreadedSceneInitializer(unsigned int nThreads);
void initializeNode(SceneGraphNode* node) override;
std::vector<SceneGraphNode*> getInitializedNodes() override;
private:
std::vector<SceneGraphNode*> _initializedNodes;
ghoul::ThreadPool _threadPool;
std::mutex _mutex;
};
} // namespace openspace
#endif // __OPENSPACE_CORE___SCENEINITIALIZER___H__