Added SyncBuffer class

- Added SyncBuffer class for easy and effecient synchronization
- Small changes to Camera class
- Forward declared a few classes to minimize dependencies
This commit is contained in:
Jonas Strandstedt
2014-10-22 16:37:54 +02:00
parent a8f3923659
commit a7da4d84cc
10 changed files with 198 additions and 35 deletions
+6 -9
View File
@@ -29,13 +29,11 @@
// sgct header has to be included before all others due to Windows header
#define SGCT_WINDOWS_INCLUDE
#include "sgct.h"
#include <sgct.h>
#include <openspace/interaction/interactionhandler.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/engine/configurationmanager.h>
#include <openspace/interaction/luaconsole.h>
//#include <ghoul/misc/dictionary.h>
#include <ghoul/opencl/clcontext.h>
#include <ghoul/opencl/clcommandqueue.h>
@@ -47,15 +45,14 @@
#include <openspace/flare/flare.h>
#define ABUFFER_SINGLE_LINKED 1
#define ABUFFER_FIXED 2
#define ABUFFER_DYNAMIC 3
#define ABUFFER_IMPLEMENTATION ABUFFER_SINGLE_LINKED
// #define OPENSPACE_VIDEO_EXPORT
namespace openspace {
// Forward declare to minimize dependencies
class SyncBuffer;
class LuaConsole;
namespace scripting {
class ScriptEngine;
}
@@ -117,7 +114,7 @@ private:
// ScriptEngine* _scriptEngine;
ghoul::opencl::CLContext _context;
sgct::SharedVector<char> _synchronizationBuffer;
SyncBuffer* _syncBuffer;
bool _inputCommand;
LuaConsole* _console;
+11 -15
View File
@@ -25,23 +25,21 @@
#ifndef __RENDERENGINE_H__
#define __RENDERENGINE_H__
#include <openspace/scenegraph/scenegraph.h>
#include <openspace/scripting/scriptengine.h>
#include <memory>
#include <string>
#include <openspace/abuffer/abuffer.h>
#include <openspace/util/screenlog.h>
#include <openspace/properties/propertyowner.h>
#include <openspace/properties/scalarproperty.h>
namespace openspace {
// Forward declare to minimize dependencies
class Camera;
class SyncBuffer;
class SceneGraph;
class ABuffer;
class ScreenLog;
class RenderEngine: public properties::PropertyOwner {
class RenderEngine {
public:
RenderEngine();
~RenderEngine();
@@ -62,13 +60,13 @@ public:
void takeScreenshot();
void serialize(std::vector<char>& dataStream, size_t& offset);
void deserialize(const std::vector<char>& dataStream, size_t& offset);
void serialize(SyncBuffer* syncBuffer);
void deserialize(SyncBuffer* syncBuffer);
/**
* Returns the Lua library that contains all Lua functions available to affect the
* rendering. The functions contained are
* - openspace::luascriptfunctions::printScreen
* - openspace::luascriptfunctions::printImage
* \return The Lua library that contains all Lua functions available to affect the
* rendering
*/
@@ -81,10 +79,8 @@ private:
ABuffer* _abuffer;
ScreenLog* _log;
properties::BoolProperty _showInfo;
properties::BoolProperty _showScreenLog;
bool _showInfo;
bool _showScreenLog;
bool _takeScreenshot;
void generateGlslConfig();
+4 -3
View File
@@ -111,7 +111,8 @@ public:
void setCameraDirection(glm::vec3 cameraDirection);
glm::vec3 cameraDirection() const;
glm::mat4 viewRotationMatrix() const;
void setViewRotationMatrix(glm::mat4 m);
const glm::mat4& viewRotationMatrix() const;
void compileViewRotationMatrix();
void rotate(const glm::quat& rotation);
@@ -119,7 +120,7 @@ public:
// const glm::quat& rotation() const;
void setRotation(glm::mat4 rotation);
const glm::vec3& viewDirection() const;
const glm::vec3& viewDirection() const;
const float& maxFov() const;
const float& sinMaxFov() const;
@@ -128,7 +129,7 @@ public:
const glm::vec2& scaling() const;
void setLookUpVector(glm::vec3 lookUp);
const glm::vec3 lookUpVector() const;
const glm::vec3& lookUpVector() const;
private:
float _maxFov;
+80
View File
@@ -0,0 +1,80 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* 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 SYNCBUFFER_H
#define SYNCBUFFER_H
#include <vector>
#include <sgct.h>
namespace openspace {
class SyncBuffer {
public:
SyncBuffer(size_t n);
template<typename T>
void encode(const T& v) {
const size_t size = sizeof(T);
assert(_encodeOffset + size < _n);
memcpy(_dataStream.data() + _encodeOffset, &v, size);
_encodeOffset += size;
}
template<typename T>
T decode() {
const size_t size = sizeof(T);
assert(_decodeOffset + size < _n);
T value;
memcpy(&value, _dataStream.data() + _decodeOffset, size);
_decodeOffset += size;
return value;
}
template<typename T>
void decode(T& value) {
const size_t size = sizeof(T);
assert(_decodeOffset + size < _n);
memcpy(&value, _dataStream.data() + _decodeOffset, size);
_decodeOffset += size;
}
void write();
void read();
private:
size_t _n;
size_t _encodeOffset;
size_t _decodeOffset;
std::vector<char> _dataStream;
sgct::SharedVector<char> _synchronizationBuffer;
};
} // namespace openspace
#endif // SYNCBUFFER_H