From 062817b7fb31fa024aab98b3e181270f50cf3fff Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 26 Oct 2015 11:20:48 -0500 Subject: [PATCH] More work moving code to window wrapper Removing capability to show SGCT rendering information --- include/openspace/engine/sgctwindowhandler.h | 8 +++-- include/openspace/engine/windowhandler.h | 5 +++ include/openspace/rendering/renderengine.h | 4 +-- src/engine/openspaceengine.cpp | 3 +- src/engine/sgctwindowhandler.cpp | 25 +++++++++++++- src/interaction/luaconsole.cpp | 10 ++++-- src/network/networkengine.cpp | 34 ++++++++++++-------- src/rendering/renderengine.cpp | 23 ++++++------- src/rendering/renderengine_lua.inl | 18 ----------- 9 files changed, 74 insertions(+), 56 deletions(-) diff --git a/include/openspace/engine/sgctwindowhandler.h b/include/openspace/engine/sgctwindowhandler.h index d7da63f406..70db4b4fb8 100644 --- a/include/openspace/engine/sgctwindowhandler.h +++ b/include/openspace/engine/sgctwindowhandler.h @@ -43,10 +43,14 @@ public: bool isRegularRendering() const override; glm::mat4 viewProjectionMatrix() const override; - + void setNearFarClippingPlane(float near, float far) override; - // void forEachWindow(std::function function) override; + glm::ivec4 viewportPixelCoordinates() const override; + + bool isExternalControlConnected() const override; + void sendMessageToExternalControl(const std::vector& message) const override; + // void forEachWindow(std::function function) override; }; } // namespace openspace diff --git a/include/openspace/engine/windowhandler.h b/include/openspace/engine/windowhandler.h index 82c44901f0..d247644a6c 100644 --- a/include/openspace/engine/windowhandler.h +++ b/include/openspace/engine/windowhandler.h @@ -44,7 +44,12 @@ public: virtual bool isRegularRendering() const = 0; virtual glm::mat4 viewProjectionMatrix() const = 0; + virtual void setNearFarClippingPlane(float near, float far) = 0; + virtual glm::ivec4 viewportPixelCoordinates() const = 0; + + virtual bool isExternalControlConnected() const = 0; + virtual void sendMessageToExternalControl(const std::vector& message) const = 0; //virtual void forEachWindow(std::function function) = 0; diff --git a/include/openspace/rendering/renderengine.h b/include/openspace/rendering/renderengine.h index cde17ace1b..df1a5651fa 100644 --- a/include/openspace/rendering/renderengine.h +++ b/include/openspace/rendering/renderengine.h @@ -89,8 +89,6 @@ public: float globalBlackOutFactor(); void setGlobalBlackOutFactor(float factor); - void setSGCTRenderStatistics(bool visible); - void setDisableRenderingOnMaster(bool enabled); /** @@ -140,7 +138,7 @@ private: float _fadeDuration; float _currentFadeTime; int _fadeDirection; - bool _sgctRenderStatisticsVisible; +// bool _sgctRenderStatisticsVisible; bool _visualizeABuffer; ABufferVisualizer* _visualizer; diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 9af7f581d6..045c7edb0d 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -686,8 +686,7 @@ void OpenSpaceEngine::postSynchronizationPreDraw() { _scriptEngine->postSynchronizationPreDraw(); _renderEngine->postSynchronizationPreDraw(); - - + if (_isMaster && _gui->isEnabled() && _windowHandler->isRegularRendering()) { glm::vec2 mousePosition = _windowHandler->mousePosition(); glm::ivec2 windowResolution = _windowHandler->currentWindowResolution(); diff --git a/src/engine/sgctwindowhandler.cpp b/src/engine/sgctwindowhandler.cpp index 737aaa6a06..3ae0fcaeb0 100644 --- a/src/engine/sgctwindowhandler.cpp +++ b/src/engine/sgctwindowhandler.cpp @@ -90,7 +90,30 @@ bool SGCTWindowHandler::isRegularRendering() const { glm::mat4 SGCTWindowHandler::viewProjectionMatrix() const { return sgct::Engine::instance()->getCurrentModelViewProjectionMatrix(); } - + +void SGCTWindowHandler::setNearFarClippingPlane(float near, float far) { + sgct::Engine::instance()->setNearAndFarClippingPlanes(near, far); +} + +glm::ivec4 SGCTWindowHandler::viewportPixelCoordinates() const { + int x1, xSize, y1, ySize; + sgct::Engine::instance()->getCurrentWindowPtr()->getCurrentViewportPixelCoords(x1, + y1, + xSize, + ySize); + return glm::ivec4(x1, xSize, y1, ySize); +} + +bool SGCTWindowHandler::isExternalControlConnected() const { + return sgct::Engine::instance()->isExternalControlConnected(); +} + +void SGCTWindowHandler::sendMessageToExternalControl(const std::vector& message) const { + sgct::Engine::instance()->sendMessageToExternalControl( + message.data(), + message.size()); +} + //void forEachWindow(std::function function) { // size_t n = sgct::Engine::instance()->getNumberOfWindows(); // for (size_t i = 0; i < n; ++i) diff --git a/src/interaction/luaconsole.cpp b/src/interaction/luaconsole.cpp index 3990ae1795..dbb2d8fb0d 100644 --- a/src/interaction/luaconsole.cpp +++ b/src/interaction/luaconsole.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -280,8 +281,13 @@ void LuaConsole::charCallback(unsigned int codepoint, KeyModifier modifier) { void LuaConsole::render() { const float font_size = 10.0f; - int x1, xSize, y1, ySize; - sgct::Engine::instance()->getCurrentWindowPtr()->getCurrentViewportPixelCoords(x1, y1, xSize, ySize); + + glm::ivec4 viewportPixelCoordinates = OsEng.windowWrapper()->viewportPixelCoordinates(); + int x1 = viewportPixelCoordinates.x; + int xSize = viewportPixelCoordinates.y; + int y1 = viewportPixelCoordinates.z; + int ySize = viewportPixelCoordinates.w; + float startY = static_cast(ySize) - 2.0f * font_size; startY = startY - font_size * 15.0f * 2.0f; diff --git a/src/network/networkengine.cpp b/src/network/networkengine.cpp index 747a78083a..6916acc8bc 100644 --- a/src/network/networkengine.cpp +++ b/src/network/networkengine.cpp @@ -87,7 +87,7 @@ bool NetworkEngine::handleMessage(const std::string& message) { } void NetworkEngine::publishStatusMessage() { - if (!_shouldPublishStatusMessage || !sgct::Engine::instance()->isExternalControlConnected()) + if (!_shouldPublishStatusMessage || !OsEng.windowWrapper()->isExternalControlConnected()) return; // Protocol: // 8 bytes: time as a ET double @@ -164,7 +164,7 @@ void NetworkEngine::publishMessage(MessageIdentifier identifier, std::vectorisExternalControlConnected()) + if (!OsEng.windowWrapper()->isExternalControlConnected()) return; for (Message& m : _messagesToSend) { @@ -180,10 +180,11 @@ void NetworkEngine::sendMessages() { // Prepending the message identifier to the front m.body.insert(m.body.begin(), identifier.data.begin(), identifier.data.end()); - sgct::Engine::instance()->sendMessageToExternalControl( - m.body.data(), - static_cast(m.body.size()) - ); + OsEng.windowWrapper()->sendMessageToExternalControl(m.body); +// sgct::Engine::instance()->sendMessageToExternalControl( +// m.body.data(), +// static_cast(m.body.size()) +// ); //LINFO("Sent message: (s=" << m.body.size() << "): " << std::string(m.body.begin(), m.body.end())); } @@ -202,10 +203,11 @@ void NetworkEngine::sendInitialInformation() { std::vector payload = m.body; payload.insert(payload.begin(), identifier.data.begin(), identifier.data.end()); - sgct::Engine::instance()->sendMessageToExternalControl( - payload.data(), - static_cast(payload.size()) - ); + OsEng.windowWrapper()->sendMessageToExternalControl(payload); +// sgct::Engine::instance()->sendMessageToExternalControl( +// payload.data(), +// static_cast(payload.size()) +// ); LINFO("Sent initial message: (s=" << m.body.size() << ") [i=" << identifier.value << "]"); std::this_thread::sleep_for(std::chrono::milliseconds(SleepTime)); @@ -220,10 +222,14 @@ void NetworkEngine::sendInitialInformation() { } identifier; identifier.value = _initialMessageFinishedIdentifier; - sgct::Engine::instance()->sendMessageToExternalControl( - identifier.data.data(), - 2 - ); + std::vector d; + d.insert(d.begin(), identifier.data.begin(), identifier.data.end()); + + OsEng.windowWrapper()->sendMessageToExternalControl(d); +// sgct::Engine::instance()->sendMessageToExternalControl( +// identifier.data.data(), +// 2 +// ); _shouldPublishStatusMessage = true; } diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index e79bd4677d..64b88f6158 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -103,7 +103,7 @@ RenderEngine::RenderEngine() , _fadeDuration(2.f) , _currentFadeTime(0.f) , _fadeDirection(0) - , _sgctRenderStatisticsVisible(false) + // , _sgctRenderStatisticsVisible(false) , _visualizeABuffer(false) , _visualizer(nullptr) { @@ -193,14 +193,20 @@ bool RenderEngine::initialize() { bool RenderEngine::initializeGL() { // LDEBUG("RenderEngine::initializeGL()"); - sgct::SGCTWindow* wPtr = sgct::Engine::instance()->getCurrentWindowPtr(); +// sgct::SGCTWindow* wPtr = sgct::Engine::instance()->getCurrentWindowPtr(); // TODO: Fix the power scaled coordinates in such a way that these // values can be set to more realistic values // set the close clip plane and the far clip plane to extreme values while in // development - sgct::Engine::instance()->setNearAndFarClippingPlanes(0.001f, 1000.0f); + OsEng.windowWrapper()->setNearFarClippingPlane(0.001f, 1000.f); + + // ALL OF THIS HAS TO BE CHECKED + // ---abock + + +// sgct::Engine::instance()->setNearAndFarClippingPlanes(0.001f, 1000.0f); // sgct::Engine::instance()->setNearAndFarClippingPlanes(0.1f, 30.0f); // calculating the maximum field of view for the camera, used to @@ -289,7 +295,6 @@ void RenderEngine::preSynchronization() { } void RenderEngine::postSynchronizationPreDraw() { - sgct::Engine::instance()->setStatsGraphVisibility(_sgctRenderStatisticsVisible); //temporary fade funtionality if (_fadeDirection != 0) { if (_currentFadeTime > _fadeDuration){ @@ -788,12 +793,6 @@ scripting::ScriptEngine::LuaLibrary RenderEngine::luaLibrary() { "bool", "Toggles the showing of render information on-screen text" }, - { - "showSGCTRenderStatistics", - &luascriptfunctions::showSGCTRenderStatistics, - "bool", - "Toggles the visibility of the SGCT rendering information" - }, { "setPerformanceMeasurement", &luascriptfunctions::setPerformanceMeasurement, @@ -1290,10 +1289,6 @@ void RenderEngine::changeViewPoint(std::string origin) { LFATAL("This function is being misused with an argument of '" << origin << "'"); } -void RenderEngine::setSGCTRenderStatistics(bool visible) { - _sgctRenderStatisticsVisible = visible; -} - void RenderEngine::setDisableRenderingOnMaster(bool enabled) { _disableMasterRendering = enabled; } diff --git a/src/rendering/renderengine_lua.inl b/src/rendering/renderengine_lua.inl index 70410eaa87..7d0ea22a00 100644 --- a/src/rendering/renderengine_lua.inl +++ b/src/rendering/renderengine_lua.inl @@ -87,24 +87,6 @@ int showRenderInformation(lua_State* L) { return 0; } -/** - * \ingroup LuaScripts - * showSGCTRenderStatistics(bool): - * Set the rendering of the SGCTRenderStatistics - */ -int showSGCTRenderStatistics(lua_State* L) { - int nArguments = lua_gettop(L); - if (nArguments != 1) - return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments); - - const int type = lua_type(L, -1); - if (type != LUA_TBOOLEAN) - return luaL_error(L, "Expected argument of type 'bool'"); - bool b = lua_toboolean(L, -1) != 0; - OsEng.renderEngine()->setSGCTRenderStatistics(b); - return 0; -} - /** * \ingroup LuaScripts * visualizeABuffer(bool):