From d287b08c51e35b17798ad091bd24e84cc671bf5d Mon Sep 17 00:00:00 2001 From: Erik Broberg Date: Tue, 13 Sep 2016 11:52:54 -0400 Subject: [PATCH] Enable toggling use of doublebuffering for camera and time --- include/openspace/rendering/renderengine.h | 2 +- include/openspace/util/camera.h | 19 +++++++++++++++++-- include/openspace/util/time.h | 16 +++++++++++++++- src/engine/openspaceengine.cpp | 4 ++-- src/rendering/renderengine.cpp | 7 ++----- src/util/camera.cpp | 9 +++++++-- src/util/time.cpp | 9 +++++++-- 7 files changed, 51 insertions(+), 15 deletions(-) diff --git a/include/openspace/rendering/renderengine.h b/include/openspace/rendering/renderengine.h index 0faaf81bcb..680ac01263 100644 --- a/include/openspace/rendering/renderengine.h +++ b/include/openspace/rendering/renderengine.h @@ -116,7 +116,7 @@ public: performance::PerformanceManager* performanceManager(); void serialize(SyncBuffer* syncBuffer); - void deserialize(SyncBuffer* syncBuffer); + void deserialize(SyncBuffer* syncBuffer, bool useDoubleBuffering); float globalBlackOutFactor(); void setGlobalBlackOutFactor(float factor); diff --git a/include/openspace/util/camera.h b/include/openspace/util/camera.h index 255b2a0247..625e71e3ce 100644 --- a/include/openspace/util/camera.h +++ b/include/openspace/util/camera.h @@ -121,7 +121,23 @@ namespace openspace { // Synchronization void serialize(SyncBuffer* syncBuffer); - void deserialize(SyncBuffer* syncBuffer); + + /** + * Updates camera variables from data in syncbuffer. If \param useDoubleBuffering is + * false, values will be written directly into the camera state, overwriting any + * previous values. + * If \param useDoubleBuffering is true, values will be written and stored in local + * copies, keeping the state unchanged until updateDoubleBuffer has + * been called. + */ + void deserialize(SyncBuffer* syncBuffer, bool useDoubleBuffering); + + /** + * This method should be called from the SGCT postSynchronization stage if and only + * if method deserialize has previously been called with the argument + * useDoubleBuffering set to true. + */ + void updateDoubleBuffer(); void serialize(std::ostream& os) const; void deserialize(std::istream& is); @@ -176,7 +192,6 @@ namespace openspace { [[deprecated("Replaced by Camera::SgctInternal::viewProjectionMatrix()")]] const glm::mat4& viewProjectionMatrix() const; - void updateDoubleBuffer(); private: struct SyncData { diff --git a/include/openspace/util/time.h b/include/openspace/util/time.h index ac458b31ea..be63d90089 100644 --- a/include/openspace/util/time.h +++ b/include/openspace/util/time.h @@ -181,7 +181,16 @@ public: void serialize(SyncBuffer* syncBuffer); - void deserialize(SyncBuffer* syncBuffer); + + /** + * Updates time variables from data in syncbuffer. If \param useDoubleBuffering is + * false, values will be written directly into the time state, overwriting any + * previous values. + * If \param useDoubleBuffering is true, values will be written and stored in local + * copies, keeping the time state unchanged until updateDoubleBuffer has + * been called. + */ + void deserialize(SyncBuffer* syncBuffer, bool useDoubleBuffering); bool timeJumped() const; @@ -189,6 +198,11 @@ public: bool paused() const; + /** + * This method should be called from the SGCT postSynchronization stage if and only + * if method deserialize has previously been called with the argument + * useDoubleBuffering set to true. + */ void updateDoubleBuffer(); /** diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 093fcc5096..96a1a564c2 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -959,9 +959,9 @@ void OpenSpaceEngine::decode() { if (_syncBuffer) { _syncBuffer->read(); - Time::ref().deserialize(_syncBuffer.get()); + Time::ref().deserialize(_syncBuffer.get(), _settingsEngine->useDoubleBuffering()); _scriptEngine->deserialize(_syncBuffer.get()); - _renderEngine->deserialize(_syncBuffer.get()); + _renderEngine->deserialize(_syncBuffer.get(), _settingsEngine->useDoubleBuffering()); } } diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 4e4de3f28e..5d6a37d7cb 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -529,23 +529,20 @@ void RenderEngine::serialize(SyncBuffer* syncBuffer) { if (_mainCamera){ _mainCamera->serialize(syncBuffer); } - - syncBuffer->encode(_onScreenInformation._node); syncBuffer->encode(_onScreenInformation._position.x); syncBuffer->encode(_onScreenInformation._position.y); syncBuffer->encode(_onScreenInformation._size); } -void RenderEngine::deserialize(SyncBuffer* syncBuffer) { +void RenderEngine::deserialize(SyncBuffer* syncBuffer, bool useDoubleBuffering) { if (_mainCamera){ - _mainCamera->deserialize(syncBuffer); + _mainCamera->deserialize(syncBuffer, useDoubleBuffering); } syncBuffer->decode(_onScreenInformation._node); syncBuffer->decode(_onScreenInformation._position.x); syncBuffer->decode(_onScreenInformation._position.y); syncBuffer->decode(_onScreenInformation._size); - } Camera* RenderEngine::camera() const { diff --git a/src/util/camera.cpp b/src/util/camera.cpp index 2760df853e..c1cdc3ffa7 100644 --- a/src/util/camera.cpp +++ b/src/util/camera.cpp @@ -195,9 +195,14 @@ namespace openspace { local.serialize(syncBuffer); } - void Camera::deserialize(SyncBuffer* syncBuffer) { + void Camera::deserialize(SyncBuffer* syncBuffer, bool useDoubleBuffering) { std::lock_guard _lock(_mutex); - synced.deserialize(syncBuffer); + if (useDoubleBuffering) { + synced.deserialize(syncBuffer); + } + else { + local.deserialize(syncBuffer); + } } void Camera::invalidateCache() { diff --git a/src/util/time.cpp b/src/util/time.cpp index da8def29d5..b8efe90a07 100644 --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -156,9 +156,14 @@ void Time::serialize(SyncBuffer* syncBuffer) { _syncMutex.unlock(); } -void Time::deserialize(SyncBuffer* syncBuffer) { +void Time::deserialize(SyncBuffer* syncBuffer, bool useDoubleBuffering) { _syncMutex.lock(); - synced.deserialize(syncBuffer); + if (useDoubleBuffering) { + synced.deserialize(syncBuffer); + } + else { + local.deserialize(syncBuffer); + } _syncMutex.unlock(); }