Cleaning up window delegate

This commit is contained in:
Alexander Bock
2020-05-10 15:17:51 +02:00
parent 1b60ab1038
commit 3b427bfd15
9 changed files with 27 additions and 144 deletions

View File

@@ -884,15 +884,6 @@ void setSgctDelegateFunctions() {
sgct::ClusterManager::instance().setUseIgnoreSync(enabled);
};
sgctDelegate.clearAllWindows = [](const glm::vec4& clearColor) {
ZoneScoped
for (const std::unique_ptr<Window>& window : Engine::instance().windows()) {
glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glfwSwapBuffers(window->windowHandle());
}
};
sgctDelegate.windowHasResized = []() {
ZoneScoped
@@ -925,26 +916,6 @@ void setSgctDelegateFunctions() {
return sgct::Engine::getTime();
};
sgctDelegate.mousePosition = []() {
ZoneScoped
double xPos;
double yPos;
glfwGetCursorPos(currentWindow->windowHandle(), &xPos, &yPos);
return glm::vec2(xPos, yPos);
};
sgctDelegate.mouseButtons = [](int maxNumber) {
ZoneScoped
uint32_t result = 0;
for (int i = 0; i < maxNumber; ++i) {
bool button = (glfwGetMouseButton(currentWindow->windowHandle(), i) != 0);
if (button) {
result |= (1 << i);
}
}
return result;
};
sgctDelegate.currentWindowSize = []() {
ZoneScoped
@@ -980,12 +951,6 @@ void setSgctDelegateFunctions() {
);
}
};
sgctDelegate.currentWindowResolution = []() {
ZoneScoped
ivec2 dim = currentWindow->finalFBODimensions();
return glm::ivec2(dim.x, dim.y);
};
sgctDelegate.currentDrawBufferResolution = []() {
ZoneScoped
@@ -1023,11 +988,6 @@ void setSgctDelegateFunctions() {
vec2 scale = currentWindow->scale();
return glm::vec2(scale.x, scale.y);
};
sgctDelegate.currentNumberOfAaSamples = []() {
ZoneScoped
return currentWindow->numberOfAASamples();
};
sgctDelegate.hasGuiWindow = []() {
ZoneScoped
@@ -1048,21 +1008,6 @@ void setSgctDelegateFunctions() {
return Engine::instance().isMaster();
};
sgctDelegate.isUsingSwapGroups = []() {
ZoneScoped
return Window::isUsingSwapGroups();
};
sgctDelegate.isSwapGroupMaster = []() {
ZoneScoped
return Window::isSwapGroupMaster();
};
sgctDelegate.viewProjectionMatrix = []() {
ZoneScoped
return currentModelViewProjectionMatrix;
};
sgctDelegate.modelMatrix = []() {
ZoneScoped
@@ -1073,31 +1018,6 @@ void setSgctDelegateFunctions() {
Engine::instance().setNearAndFarClippingPlanes(nearPlane, farPlane);
};
sgctDelegate.setEyeSeparationDistance = [](float distance) {
ZoneScoped
Engine::instance().setEyeSeparation(distance);
};
//sgctDelegate.viewportPixelCoordinates = []() {
// ZoneScoped
// if (!currentWindow|| !currentViewport) {
// return glm::ivec4(0);
// }
// else {
// const int* data = cur sgct::Engine::instance()->getCurrentViewportPixelCoords();
// return glm::ivec4(data[0], data[2], data[1], data[3]);
// }
//};
//sgctDelegate.sendMessageToExternalControl = [](const std::vector<char>& message) {
// ZoneScoped
//
// sgct::Engine::instance()->sendMessageToExternalControl(
// message.data(),
// static_cast<int>(message.size())
// );
//};
sgctDelegate.isFisheyeRendering = []() {
ZoneScoped

View File

@@ -120,6 +120,8 @@ private:
bool _hasScheduledAssetLoading = false;
std::string _scheduledAssetPathToLoad;
glm::vec2 _mousePosition;
//grabs json from each module to pass to the documentation engine.
std::string _documentationJson;

View File

@@ -40,8 +40,6 @@ struct WindowDelegate {
void (*setSynchronization)(bool enabled) = [](bool) {};
void (*clearAllWindows)(const glm::vec4& clearColor) = [](const glm::vec4&) {};
bool (*windowHasResized)() = []() { return false; };
double (*averageDeltaTime)() = []() { return 0.0; };
@@ -56,47 +54,29 @@ struct WindowDelegate {
double (*applicationTime)() = []() { return 0.0; };
glm::vec2 (*mousePosition)() = []() { return glm::vec2(0.f); };
uint32_t (*mouseButtons)(int maxNumber) = [](int) { return uint32_t(0); };
glm::ivec2 (*currentWindowSize)() = []() { return glm::ivec2(0); };
glm::ivec2 (*currentSubwindowSize)() = []() { return glm::ivec2(0); };
glm::ivec2 (*currentWindowResolution)() = []() { return glm::ivec2(0); };
glm::ivec2 (*currentDrawBufferResolution)() = []() { return glm::ivec2(0); };
glm::ivec2 (*currentViewportSize)() = []() { return glm::ivec2(0); };
glm::vec2 (*dpiScaling)() = []() { return glm::vec2(1.f); };
int (*currentNumberOfAaSamples)() = []() { return 1; };
bool (*hasGuiWindow)() = []() { return false; };
bool (*isGuiWindow)() = []() { return false; };
bool (*isMaster)() = []() { return false; };
int (*clusterId)() = []() { return 0; };
bool (*isUsingSwapGroups)() = []() { return false; };
bool (*isSwapGroupMaster)() = []() { return false; };
glm::mat4 (*viewProjectionMatrix)() = []() { return glm::mat4(1.f); };
bool (*isMaster)() = []() { return true; };
glm::mat4 (*modelMatrix)() = []() { return glm::mat4(1.f); };
void (*setNearFarClippingPlane)(float near, float far) = [](float, float) {};
void (*setEyeSeparationDistance)(float distance) = [](float) {};
bool (*isFisheyeRendering)() = []() { return false; };
unsigned int(*takeScreenshot)(bool applyWarping) = [](bool) { return 0u; };
unsigned int (*takeScreenshot)(bool applyWarping) = [](bool) { return 0u; };
void (*swapBuffer)() = []() {};

View File

@@ -154,9 +154,6 @@ ImGUIModule::ImGUIModule() : OpenSpaceModule(Name) {
global::callback::draw2D.emplace_back([&]() {
ZoneScopedN("ImGUI")
// TODO emiax: Make sure this is only called for one of the eyes, in the case
// of side-by-side / top-bottom stereo.
WindowDelegate& delegate = global::windowDelegate;
const bool showGui = delegate.hasGuiWindow() ? delegate.isGuiWindow() : true;
if (delegate.isMaster() && showGui) {
@@ -167,9 +164,6 @@ ImGUIModule::ImGUIModule() : OpenSpaceModule(Name) {
return;
}
glm::vec2 mousePosition = delegate.mousePosition();
uint32_t mouseButtons = delegate.mouseButtons(2);
const double dt = std::max(delegate.averageDeltaTime(), 0.0);
// We don't do any collection of immediate mode user interface, so it
// is fine to open and close a frame immediately
@@ -177,8 +171,8 @@ ImGUIModule::ImGUIModule() : OpenSpaceModule(Name) {
static_cast<float>(dt),
glm::vec2(windowSize),
resolution / windowSize,
mousePosition,
mouseButtons
_mousePosition,
_mouseButtons
);
gui.endFrame();
@@ -217,10 +211,23 @@ ImGUIModule::ImGUIModule() : OpenSpaceModule(Name) {
}
);
global::callback::mousePosition.emplace_back(
[&](double x, double y) {
_mousePosition = glm::vec2(static_cast<float>(x), static_cast<float>(y));
}
);
global::callback::mouseButton.emplace_back(
[&](MouseButton button, MouseAction action, KeyModifier) -> bool {
ZoneScopedN("ImGUI")
if (action == MouseAction::Press) {
_mouseButtons |= (1 << static_cast<int>(button));
}
else if (action == MouseAction::Release) {
_mouseButtons &= ~(1 << static_cast<int>(button));
}
// A list of all the windows that can show up by themselves
if (gui.isEnabled() || gui._performance.isEnabled() ||
gui._sceneProperty.isEnabled())

View File

@@ -38,6 +38,10 @@ public:
ImGUIModule();
gui::GUI gui;
private:
glm::vec2 _mousePosition = glm::vec2(0.f);
uint32_t _mouseButtons = 0;
};
} // namespace openspace

View File

@@ -180,15 +180,6 @@ Win32TouchHook::Win32TouchHook(void* nativeWindow) {
return;
}
// HACK: This hack is required as long as our GLFW version is based on the touch
// branch. There is no convenient way to set a GLFWBool (uint32_t) which sets the
// state of touch-to-mouseinput interpretation. It happens to be 116 bytes into an
// internal glfw struct...
uint32_t* HACKY_PTR = (uint32_t *)GetPropW(hWnd, L"GLFW");
HACKY_PTR += 116/sizeof(uint32_t);
*HACKY_PTR = 1;
// Test for touch:
int value = GetSystemMetrics(SM_DIGITIZER);
if ((value & NID_READY) == 0) {

View File

@@ -420,11 +420,6 @@ void OpenSpaceEngine::initializeGL() {
rendering::helper::initialize();
// clear the screen so the user doesn't have to see old buffer contents left on the
// graphics card
LDEBUG("Clearing all Windows");
global::windowDelegate.clearAllWindows(glm::vec4(0.f, 0.f, 0.f, 1.f));
LDEBUG("Adding system components");
// Detect and log OpenCL and OpenGL versions and available devices
SysCap.addComponent(
@@ -1378,10 +1373,7 @@ void OpenSpaceEngine::mouseButtonCallback(MouseButton button,
// Check if the user clicked on one of the 'buttons' the RenderEngine is drawing
if (action == MouseAction::Press) {
bool isConsumed = global::renderEngine.mouseActivationCallback(
global::windowDelegate.mousePosition()
);
bool isConsumed = global::renderEngine.mouseActivationCallback(_mousePosition);
if (isConsumed) {
return;
}
@@ -1401,6 +1393,8 @@ void OpenSpaceEngine::mousePositionCallback(double x, double y) {
global::navigationHandler.mousePositionCallback(x, y);
global::interactionMonitor.markInteraction();
_mousePosition = glm::vec2(static_cast<float>(x), static_cast<float>(y));
}
void OpenSpaceEngine::mouseScrollWheelCallback(double posX, double posY) {
@@ -1547,15 +1541,6 @@ scripting::LuaLibrary OpenSpaceEngine::luaLibrary() {
"Returns whether the current OpenSpace instance is the master node of a "
"cluster configuration. If this instance is not part of a cluster, this "
"function also returns 'true'."
},
{
"clusterId",
&luascriptfunctions::clusterId,
{},
"",
"Returns the zero-based identifier for this OpenSpace instance in a "
"cluster configuration. If this instance is not part of a cluster, this "
"identifier is always 0."
}
},
{

View File

@@ -272,10 +272,4 @@ int isMaster(lua_State* L) {
return 1;
}
int clusterId(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::clusterId");
ghoul::lua::push(L, global::windowDelegate.clusterId());
return 1;
}
} // namespace openspace::luascriptfunctions