mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-23 05:19:18 -06:00
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:
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
include/openspace/util/syncbuffer.h
Normal file
80
include/openspace/util/syncbuffer.h
Normal 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
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <openspace/interaction/deviceidentifier.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/interaction/luaconsole.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
#include <openspace/util/time.h>
|
||||
@@ -33,6 +34,7 @@
|
||||
#include <openspace/util/factorymanager.h>
|
||||
#include <openspace/util/constants.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/util/syncbuffer.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
@@ -74,6 +76,7 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName)
|
||||
: _commandlineParser(programName, true)
|
||||
, _inputCommand(false)
|
||||
, _console(nullptr)
|
||||
, _syncBuffer(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -208,6 +211,7 @@ bool OpenSpaceEngine::create(int argc, char** argv,
|
||||
FileSys.createCacheManager("${CACHE}");
|
||||
|
||||
_engine->_console = new LuaConsole();
|
||||
_engine->_syncBuffer = new SyncBuffer(1024);
|
||||
|
||||
// Determining SGCT configuration file
|
||||
LDEBUG("Determining SGCT configuration file");
|
||||
@@ -494,6 +498,8 @@ void OpenSpaceEngine::encode()
|
||||
// _synchronizationBuffer.setVal(dataStream);
|
||||
// sgct::SharedData::instance()->writeVector(&_synchronizationBuffer);
|
||||
//#endif
|
||||
_renderEngine.serialize(_syncBuffer);
|
||||
_syncBuffer->write();
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::decode()
|
||||
@@ -508,6 +514,8 @@ void OpenSpaceEngine::decode()
|
||||
// // deserialize in the same order as done in serialization
|
||||
// _renderEngine->deserialize(dataStream, offset);
|
||||
//#endif
|
||||
_syncBuffer->read();
|
||||
_renderEngine.deserialize(_syncBuffer);
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::setInputCommand(bool b) {
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/util/powerscaledcoordinate.h>
|
||||
#include <openspace/util/kameleonwrapper.h>
|
||||
#include <openspace/abuffer/abuffer.h>
|
||||
|
||||
#include <ghoul/opengl/texturereader.h>
|
||||
#include <ghoul/opencl/clworksize.h>
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <openspace/util/constants.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/util/syncbuffer.h>
|
||||
#include "sgct.h"
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
@@ -41,9 +42,12 @@
|
||||
#include <array>
|
||||
#include <fstream>
|
||||
|
||||
#include <openspace/scenegraph/scenegraph.h>
|
||||
#include <openspace/abuffer/abuffer.h>
|
||||
#include <openspace/abuffer/abufferSingleLinked.h>
|
||||
#include <openspace/abuffer/abufferfixed.h>
|
||||
#include <openspace/abuffer/abufferdynamic.h>
|
||||
#include <openspace/util/screenlog.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "RenderEngine";
|
||||
@@ -75,10 +79,9 @@ RenderEngine::RenderEngine()
|
||||
, _abuffer(nullptr)
|
||||
, _takeScreenshot(false)
|
||||
, _log(nullptr)
|
||||
, _showInfo("info", "Display info", true)
|
||||
, _showScreenLog("log", "Display screen log", true)
|
||||
, _showInfo(true)
|
||||
, _showScreenLog(true)
|
||||
{
|
||||
setName("renderEngine");
|
||||
}
|
||||
|
||||
RenderEngine::~RenderEngine()
|
||||
@@ -387,7 +390,7 @@ void RenderEngine::setSceneGraph(SceneGraph* sceneGraph)
|
||||
_sceneGraph = sceneGraph;
|
||||
}
|
||||
|
||||
void RenderEngine::serialize(std::vector<char>& dataStream, size_t& offset) {
|
||||
void RenderEngine::serialize(SyncBuffer* syncBuffer) {
|
||||
// TODO: This has to be redone properly (ab) [new class providing methods to serialize
|
||||
// variables]
|
||||
|
||||
@@ -397,6 +400,12 @@ void RenderEngine::serialize(std::vector<char>& dataStream, size_t& offset) {
|
||||
// camera->viewRotationMatrix
|
||||
// camera->scaling
|
||||
|
||||
syncBuffer->encode(_mainCamera->scaling());
|
||||
syncBuffer->encode(_mainCamera->position());
|
||||
syncBuffer->encode(_mainCamera->viewRotationMatrix());
|
||||
//syncBuffer->encode(_mainCamera->lookUpVector());
|
||||
//syncBuffer->encode(_mainCamera->rotation());
|
||||
|
||||
|
||||
//const glm::vec2 scaling = _mainCamera->scaling();
|
||||
//const psc position = _mainCamera->position();
|
||||
@@ -476,8 +485,23 @@ void RenderEngine::serialize(std::vector<char>& dataStream, size_t& offset) {
|
||||
//dataStream[offset++] = s.representation[3];
|
||||
}
|
||||
|
||||
void RenderEngine::deserialize(const std::vector<char>& dataStream, size_t& offset) {
|
||||
void RenderEngine::deserialize(SyncBuffer* syncBuffer) {
|
||||
// TODO: This has to be redone properly (ab)
|
||||
|
||||
glm::vec2 scaling;
|
||||
psc position;
|
||||
glm::mat4 viewRotation;
|
||||
//glm::vec3 lookUpVector;
|
||||
syncBuffer->decode(scaling);
|
||||
syncBuffer->decode(position);
|
||||
syncBuffer->decode(viewRotation);
|
||||
|
||||
_mainCamera->setScaling(scaling);
|
||||
_mainCamera->setPosition(position);
|
||||
_mainCamera->setViewRotationMatrix(viewRotation);
|
||||
//_mainCamera->setLookUpVector(lookUpVector);
|
||||
//_mainCamera->compileViewRotationMatrix();
|
||||
|
||||
|
||||
// union storage {
|
||||
// float value;
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <openspace/util/constants.h>
|
||||
#include <openspace/query/query.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/abuffer/abuffer.h>
|
||||
|
||||
// ghoul includes
|
||||
#include "ghoul/opengl/programobject.h"
|
||||
|
||||
@@ -100,9 +100,13 @@ glm::vec3 Camera::cameraDirection() const
|
||||
return _cameraDirection;
|
||||
}
|
||||
|
||||
glm::mat4 Camera::viewRotationMatrix() const
|
||||
void Camera::setViewRotationMatrix(glm::mat4 m) {
|
||||
_viewRotationMatrix = m;
|
||||
}
|
||||
|
||||
const glm::mat4& Camera::viewRotationMatrix() const
|
||||
{
|
||||
return glm::mat4(_viewRotationMatrix);
|
||||
return _viewRotationMatrix;
|
||||
}
|
||||
|
||||
void Camera::compileViewRotationMatrix()
|
||||
@@ -176,7 +180,7 @@ void Camera::setLookUpVector(glm::vec3 lookUp)
|
||||
_lookUp = std::move(lookUp);
|
||||
}
|
||||
|
||||
const glm::vec3 Camera::lookUpVector() const
|
||||
const glm::vec3& Camera::lookUpVector() const
|
||||
{
|
||||
return _lookUp;
|
||||
}
|
||||
|
||||
51
src/util/syncbuffer.cpp
Normal file
51
src/util/syncbuffer.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <openspace/util/syncbuffer.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
SyncBuffer::SyncBuffer(size_t n)
|
||||
: _n(n)
|
||||
, _encodeOffset(0)
|
||||
, _decodeOffset(0)
|
||||
{
|
||||
_dataStream.resize(_n);
|
||||
}
|
||||
|
||||
void SyncBuffer::write() {
|
||||
_synchronizationBuffer.setVal(_dataStream);
|
||||
sgct::SharedData::instance()->writeVector(&_synchronizationBuffer);
|
||||
_encodeOffset = 0;
|
||||
_decodeOffset = 0;
|
||||
}
|
||||
|
||||
void SyncBuffer::read() {
|
||||
sgct::SharedData::instance()->readVector(&_synchronizationBuffer);
|
||||
_dataStream = std::move(_synchronizationBuffer.getVal());
|
||||
_encodeOffset = 0;
|
||||
_decodeOffset = 0;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
Reference in New Issue
Block a user