mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-13 06:49:05 -05:00
Cleanup of WindowWrapper classes
This commit is contained in:
@@ -29,34 +29,24 @@
|
||||
|
||||
namespace openspace {
|
||||
|
||||
/**
|
||||
* DummyWindowWrapper that can be used if no actual rendering output is required, such as
|
||||
* for console applications. The window sizes and resolutions will all be set to
|
||||
* <code>0</code> and all graphics operations will be <code>no-op</code>s.
|
||||
*/
|
||||
class DummyWindowWrapper : public WindowWrapper {
|
||||
public:
|
||||
void setBarrier(bool enabled) override;
|
||||
void clearAllWindows() override;
|
||||
void clearAllWindows(const glm::vec4& clearColor) override;
|
||||
bool windowHasResized() const override;
|
||||
double time() const override;
|
||||
double averageDeltaTime() const override;
|
||||
uint32_t mouseButtons(int maxNumber = 8) const override;
|
||||
glm::vec2 mousePosition() const override;
|
||||
glm::ivec2 currentWindowSize() const override;
|
||||
glm::ivec2 currentWindowResolution() const override;
|
||||
bool isRegularRendering() const override;
|
||||
|
||||
glm::mat4 viewProjectionMatrix() const override;
|
||||
void setNearFarClippingPlane(float near, float far) override;
|
||||
|
||||
glm::ivec4 viewportPixelCoordinates() const override;
|
||||
|
||||
bool isExternalControlConnected() const override;
|
||||
void sendMessageToExternalControl(const std::vector<char>& message) const override;
|
||||
|
||||
// true for single viewport, single window; false otherwise
|
||||
bool isSimpleRendering() const override;
|
||||
|
||||
void takeScreenshot() const override;
|
||||
|
||||
//virtual void forEachWindow(std::function<void (void)> function) = 0;
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -29,13 +29,17 @@
|
||||
|
||||
namespace openspace {
|
||||
|
||||
/**
|
||||
* WindowWrapper subclass wrapping the Simple Graphics Cluster Toolkit, forwarding all
|
||||
* method calls to the specific functions in the Engine and SGCTWindow classes.
|
||||
* \sa https://c-student.itn.liu.se/wiki/develop:sgct:sgct
|
||||
*/
|
||||
class SGCTWindowWrapper : public WindowWrapper {
|
||||
public:
|
||||
void setBarrier(bool enabled) override;
|
||||
void clearAllWindows() override;
|
||||
void clearAllWindows(const glm::vec4& clearColor) override;
|
||||
bool windowHasResized() const override;
|
||||
|
||||
double time() const override;
|
||||
double averageDeltaTime() const override;
|
||||
glm::vec2 mousePosition() const override;
|
||||
uint32_t mouseButtons(int maxNumber) const override;
|
||||
@@ -55,9 +59,6 @@ public:
|
||||
bool isSimpleRendering() const override;
|
||||
|
||||
void takeScreenshot() const override;
|
||||
|
||||
|
||||
// void forEachWindow(std::function<void (void)> function) override;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -33,34 +33,124 @@
|
||||
|
||||
namespace openspace {
|
||||
|
||||
/**
|
||||
* A WindowWrapper is a class that handles the abstraction between OpenSpace and a
|
||||
* specific window creation framework.<br>
|
||||
* Every new windowing framework needs to have its own WindowWrapper subclass exposing the
|
||||
* required features.
|
||||
*/
|
||||
class WindowWrapper {
|
||||
public:
|
||||
virtual void setBarrier(bool enabled) = 0;
|
||||
virtual void clearAllWindows() = 0;
|
||||
/**
|
||||
* This method enables or disables a framelock barrier. If the specific windowing
|
||||
* framework does not provide a framelock, this method defaults to a no-op.
|
||||
* \param enabled If <code>true</code> the framelock is enabled, <code>false</code>
|
||||
* disables it
|
||||
*/
|
||||
virtual void setBarrier(bool enabled);
|
||||
|
||||
/**
|
||||
* This method clears all the rendering windows with the specified \p clearColor. In
|
||||
* most OpenGL cases, this will end up with one or mode <code>glClear</code> calls.
|
||||
* \param clearColor The color with which to clear all windows
|
||||
*/
|
||||
virtual void clearAllWindows(const glm::vec4& clearColor) = 0;
|
||||
|
||||
/**
|
||||
* Returns whether the current window has been resized recently.
|
||||
* \return <code>true</code> if the current window has been resized recently,
|
||||
* <code>false</code> otherwise
|
||||
*/
|
||||
virtual bool windowHasResized() const = 0;
|
||||
virtual double time() const = 0;
|
||||
virtual double averageDeltaTime() const = 0;
|
||||
virtual uint32_t mouseButtons(int maxNumber = 8) const = 0;
|
||||
virtual glm::vec2 mousePosition() const = 0;
|
||||
virtual glm::ivec2 currentWindowSize() const = 0;
|
||||
virtual glm::ivec2 currentWindowResolution() const = 0;
|
||||
virtual bool isRegularRendering() const = 0;
|
||||
|
||||
/**
|
||||
* Returns the average frametime in seconds.
|
||||
* \return The average frametime in seconds
|
||||
*/
|
||||
virtual double averageDeltaTime() const = 0;
|
||||
|
||||
/**
|
||||
* Returns the location of the mouse cursor in pixel screen coordinates.
|
||||
* \return The location of the mouse cursor in pixel screen coordinates
|
||||
*/
|
||||
virtual glm::vec2 mousePosition() const = 0;
|
||||
|
||||
/**
|
||||
* Returns a bitmask of the status of all available mouse buttons. Bit <code>i</code>
|
||||
* is <code>1</code> if mouse button <code>i</code> is pressed down;
|
||||
* <code>false</code> otherwise.
|
||||
* \param maxNumber The maximum number of mouse buttons that should be queried
|
||||
* \return A bitmask showing the status of all mouse buttons (up to \p maxNumber)
|
||||
*/
|
||||
virtual uint32_t mouseButtons(int maxNumber = 8) const = 0;
|
||||
|
||||
/**
|
||||
* Returns the size of the currently active window in pixel coordinates.
|
||||
* \return The size of the currently active window in pixel coordinates
|
||||
*/
|
||||
virtual glm::ivec2 currentWindowSize() const = 0;
|
||||
|
||||
/**
|
||||
* Returns the resolution of the currently active window in pixel coordinates.
|
||||
* \return The resolution of the currently active window in pixel coordinates
|
||||
*/
|
||||
virtual glm::ivec2 currentWindowResolution() const;
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the current rendering method is regular, i.e., it is
|
||||
* a flat projection without non-linear distortions. Returns <code>false</code> in
|
||||
* other cases, for example fisheye projections.
|
||||
* \return Whether the current rendering method is a regular method
|
||||
*/
|
||||
virtual bool isRegularRendering() const;
|
||||
|
||||
/**
|
||||
* Returns the currently employed view-projection matrix.
|
||||
* \return The currently employed view-projection matrix
|
||||
*/
|
||||
virtual glm::mat4 viewProjectionMatrix() const = 0;
|
||||
|
||||
/**
|
||||
* Sets the near and far clipping planes of the rendering window.
|
||||
* \param near The near clipping plane
|
||||
* \param far The far clipping plane
|
||||
*/
|
||||
virtual void setNearFarClippingPlane(float near, float far) = 0;
|
||||
|
||||
virtual glm::ivec4 viewportPixelCoordinates() const = 0;
|
||||
/**
|
||||
* Returns the location and size of the current viewport (<code>x</code>,
|
||||
* <code>width</code>, <code>y</code>, and <code>height</code>). If there is only a
|
||||
* single viewport, <code>x</code> and <code>y</code> are <code>0</code> whereas
|
||||
* <code>width</code> and <code>height</code> are equal to #currentWindowResolution.
|
||||
* \return The location and size of the current viewport
|
||||
*/
|
||||
virtual glm::ivec4 viewportPixelCoordinates() const;
|
||||
|
||||
virtual bool isExternalControlConnected() const = 0;
|
||||
virtual void sendMessageToExternalControl(const std::vector<char>& message) const = 0;
|
||||
/**
|
||||
* Returns <code>true</code> if there is an external control connected, i.e., an
|
||||
* application that can receive control commands.
|
||||
* \return If there is an external control connected
|
||||
*/
|
||||
virtual bool isExternalControlConnected() const;
|
||||
|
||||
// true for single viewport, single window; false otherwise
|
||||
virtual bool isSimpleRendering() const = 0;
|
||||
/**
|
||||
* Sends a \p message to an external control.
|
||||
* \param message The message to be sent
|
||||
*/
|
||||
virtual void sendMessageToExternalControl(const std::vector<char>& message) const;
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the rendering is a single viewport with an single
|
||||
* window; <code>false</code> otherwise.
|
||||
* \returns <code>true</code> if the rendering is a single viewport with an single
|
||||
* widnow; <code>false</code> otherwise
|
||||
*/
|
||||
virtual bool isSimpleRendering() const;
|
||||
|
||||
/**
|
||||
* Advises the windowing system to take a screenshot.
|
||||
*/
|
||||
virtual void takeScreenshot() const = 0;
|
||||
|
||||
//virtual void forEachWindow(std::function<void (void)> function) = 0;
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
#include <utility> // pair
|
||||
#include <chrono>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
@@ -34,9 +35,9 @@ public:
|
||||
//typedef std::tuple<ghoul::logging::LogManager::LogLevel, std::string, std::string> LogEntry;
|
||||
|
||||
struct LogEntry {
|
||||
LogEntry(ghoul::logging::LogManager::LogLevel l, double t, std::string ts, std::string c, std::string m) : level(l), timeStamp(t), timeString(ts), category(c), message(m) {};
|
||||
LogEntry(ghoul::logging::LogManager::LogLevel l, std::chrono::time_point<std::chrono::steady_clock> t, std::string ts, std::string c, std::string m) : level(l), timeStamp(t), timeString(ts), category(c), message(m) {};
|
||||
ghoul::logging::LogManager::LogLevel level;
|
||||
double timeStamp;
|
||||
std::chrono::time_point<std::chrono::steady_clock> timeStamp;
|
||||
std::string timeString;
|
||||
std::string category;
|
||||
std::string message;
|
||||
@@ -52,16 +53,18 @@ public:
|
||||
|
||||
const size_t MaximumSize = 1000;
|
||||
|
||||
ScreenLog();
|
||||
|
||||
ScreenLog(std::chrono::seconds timeToLive);
|
||||
|
||||
void removeExpiredEntries();
|
||||
|
||||
virtual void log(ghoul::logging::LogManager::LogLevel level, const std::string& category,
|
||||
const std::string& message);
|
||||
|
||||
const_range last(size_t n = 10);
|
||||
|
||||
private:
|
||||
|
||||
std::vector<LogEntry> _entries;
|
||||
|
||||
std::chrono::seconds _timeToLive;
|
||||
};
|
||||
}
|
||||
@@ -36,6 +36,7 @@ set(OPENSPACE_SOURCE
|
||||
${OPENSPACE_BASE_DIR}/src/engine/openspaceengine.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/engine/wrapper/dummywindowwrapper.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/engine/wrapper/sgctwindowwrapper.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/engine/wrapper/windowwrapper.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/interaction/controller.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/interaction/deviceidentifier.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/interaction/interactionhandler.cpp
|
||||
|
||||
@@ -397,7 +397,7 @@ bool OpenSpaceEngine::isInitialized() {
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::clearAllWindows() {
|
||||
_windowWrapper->clearAllWindows();
|
||||
_windowWrapper->clearAllWindows(glm::vec4(0.f, 0.f, 0.f, 1.f));
|
||||
}
|
||||
|
||||
bool OpenSpaceEngine::gatherCommandlineArguments() {
|
||||
|
||||
@@ -26,18 +26,12 @@
|
||||
|
||||
namespace openspace {
|
||||
|
||||
void DummyWindowWrapper::setBarrier(bool enabled) {}
|
||||
|
||||
void DummyWindowWrapper::clearAllWindows() {}
|
||||
void DummyWindowWrapper::clearAllWindows(const glm::vec4&) {}
|
||||
|
||||
bool DummyWindowWrapper::windowHasResized() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
double DummyWindowWrapper::time() const {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
double DummyWindowWrapper::averageDeltaTime() const {
|
||||
return 0.0;
|
||||
}
|
||||
@@ -54,36 +48,12 @@ glm::ivec2 DummyWindowWrapper::currentWindowSize() const {
|
||||
return glm::ivec2(0);
|
||||
}
|
||||
|
||||
glm::ivec2 DummyWindowWrapper::currentWindowResolution() const {
|
||||
return glm::ivec2(0);
|
||||
}
|
||||
|
||||
bool DummyWindowWrapper::isRegularRendering() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::mat4 DummyWindowWrapper::viewProjectionMatrix() const {
|
||||
return glm::mat4(1.f);
|
||||
}
|
||||
|
||||
void DummyWindowWrapper::setNearFarClippingPlane(float near, float far) {}
|
||||
|
||||
glm::ivec4 DummyWindowWrapper::viewportPixelCoordinates() const {
|
||||
return glm::ivec4(0);
|
||||
}
|
||||
|
||||
bool DummyWindowWrapper::isExternalControlConnected() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void DummyWindowWrapper::sendMessageToExternalControl(const std::vector<char>& message) const {
|
||||
}
|
||||
|
||||
bool DummyWindowWrapper::isSimpleRendering() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void DummyWindowWrapper::takeScreenshot() const {}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
|
||||
@@ -36,10 +36,10 @@ void SGCTWindowWrapper::setBarrier(bool enabled) {
|
||||
sgct::SGCTWindow::setBarrier(enabled);
|
||||
}
|
||||
|
||||
void SGCTWindowWrapper::clearAllWindows() {
|
||||
void SGCTWindowWrapper::clearAllWindows(const glm::vec4& clearColor) {
|
||||
size_t n = sgct::Engine::instance()->getNumberOfWindows();
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
glClearColor(0, 0, 0, 0);
|
||||
glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
GLFWwindow* win = sgct::Engine::instance()->getWindowPtr(i)->getWindowHandle();
|
||||
glfwSwapBuffers(win);
|
||||
@@ -50,10 +50,6 @@ bool SGCTWindowWrapper::windowHasResized() const {
|
||||
return sgct::Engine::instance()->getCurrentWindowPtr()->isWindowResized();
|
||||
}
|
||||
|
||||
double SGCTWindowWrapper::time() const {
|
||||
return sgct::Engine::instance()->getTime();
|
||||
}
|
||||
|
||||
double SGCTWindowWrapper::averageDeltaTime() const {
|
||||
return sgct::Engine::instance()->getAvgDt();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2015 *
|
||||
* *
|
||||
* 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/engine/wrapper/windowwrapper.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
glm::ivec2 WindowWrapper::currentWindowResolution() const {
|
||||
return currentWindowSize();
|
||||
}
|
||||
|
||||
bool WindowWrapper::isRegularRendering() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::ivec4 WindowWrapper::viewportPixelCoordinates() const {
|
||||
return glm::ivec4(
|
||||
0,
|
||||
currentWindowResolution().x,
|
||||
0,
|
||||
currentWindowResolution().y
|
||||
);
|
||||
}
|
||||
|
||||
void WindowWrapper::setBarrier(bool) {}
|
||||
|
||||
bool WindowWrapper::isExternalControlConnected() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void WindowWrapper::sendMessageToExternalControl(const std::vector<char>& message) const {
|
||||
}
|
||||
|
||||
bool WindowWrapper::isSimpleRendering() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
@@ -85,6 +85,8 @@ namespace {
|
||||
|
||||
const std::string KeyRenderingMethod = "RenderingMethod";
|
||||
const std::string DefaultRenderingMethod = "ABufferSingleLinked";
|
||||
|
||||
std::chrono::seconds ScreenLogTimeToLive(15);
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
@@ -291,7 +293,7 @@ bool RenderEngine::initializeGL() {
|
||||
_abuffer->initialize();
|
||||
|
||||
LINFO("Initializing Log");
|
||||
std::unique_ptr<ScreenLog> log = std::make_unique<ScreenLog>();
|
||||
std::unique_ptr<ScreenLog> log = std::make_unique<ScreenLog>(ScreenLogTimeToLive);
|
||||
_log = log.get();
|
||||
ghoul::logging::LogManager::ref().addLog(std::move(log));
|
||||
|
||||
@@ -625,11 +627,12 @@ void RenderEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &vi
|
||||
#endif
|
||||
}
|
||||
if (_showScreenLog) {
|
||||
_log->removeExpiredEntries();
|
||||
|
||||
const int max = 10;
|
||||
const int category_length = 20;
|
||||
const int msg_length = 140;
|
||||
const float ttl = 15.f;
|
||||
const float fade = 5.f;
|
||||
std::chrono::seconds fade(5);
|
||||
auto entries = _log->last(max);
|
||||
|
||||
const glm::vec4 white(0.9, 0.9, 0.9, 1);
|
||||
@@ -639,21 +642,18 @@ void RenderEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &vi
|
||||
const glm::vec4 blue(0, 0, 1, 1);
|
||||
|
||||
size_t nr = 1;
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
for (auto& it = entries.first; it != entries.second; ++it) {
|
||||
const ScreenLog::LogEntry* e = &(*it);
|
||||
|
||||
const double t = OsEng.windowWrapper().time();
|
||||
float diff = static_cast<float>(t - e->timeStamp);
|
||||
|
||||
// Since all log entries are ordered, once one is exceeding TTL, all have
|
||||
// if (diff > ttl)
|
||||
// break;
|
||||
|
||||
std::chrono::duration<double> diff = now - e->timeStamp;
|
||||
|
||||
float alpha = 1;
|
||||
float ttf = ttl - fade;
|
||||
std::chrono::duration<double> ttf = ScreenLogTimeToLive - fade;
|
||||
if (diff > ttf) {
|
||||
diff = diff - ttf;
|
||||
float p = 0.8f - diff / fade;
|
||||
auto d = (diff - ttf).count();
|
||||
auto t = static_cast<float>(d) / static_cast<float>(fade.count());
|
||||
float p = 0.8f - t;
|
||||
alpha = (p <= 0.f) ? 0.f : pow(p, 0.3f);
|
||||
}
|
||||
|
||||
|
||||
+26
-3
@@ -31,11 +31,34 @@
|
||||
|
||||
namespace openspace {
|
||||
|
||||
ScreenLog::ScreenLog() {}
|
||||
ScreenLog::ScreenLog(std::chrono::seconds timeToLive)
|
||||
: _timeToLive(std::move(timeToLive))
|
||||
{}
|
||||
|
||||
void ScreenLog::removeExpiredEntries() {
|
||||
auto t = std::chrono::steady_clock::now();
|
||||
auto ttl = _timeToLive;
|
||||
|
||||
_entries.erase(
|
||||
std::remove_if(
|
||||
_entries.begin(),
|
||||
_entries.end(),
|
||||
[t, ttl](const LogEntry& e) { return (t - e.timeStamp) > ttl; }
|
||||
),
|
||||
_entries.end()
|
||||
);
|
||||
}
|
||||
|
||||
void ScreenLog::log(ghoul::logging::LogManager::LogLevel level, const std::string& category, const std::string& message) {
|
||||
if (level >= ghoul::logging::LogManager::LogLevel::Info)
|
||||
_entries.emplace_back(level, OsEng.windowWrapper().time(), Log::getTimeString(), category, message);
|
||||
if (level >= ghoul::logging::LogManager::LogLevel::Info) {
|
||||
_entries.emplace_back(
|
||||
level,
|
||||
std::chrono::steady_clock::now(),
|
||||
Log::getTimeString(),
|
||||
category,
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
// Once reaching maximum size, reduce to half
|
||||
if (_entries.size() > MaximumSize) {
|
||||
|
||||
Reference in New Issue
Block a user