diff --git a/apps/OpenSpace/main.cpp b/apps/OpenSpace/main.cpp index 7757d0b47e..a56d0640fc 100644 --- a/apps/OpenSpace/main.cpp +++ b/apps/OpenSpace/main.cpp @@ -1138,10 +1138,21 @@ int main(int argc, char* argv[]) { std::filesystem::path base = configurationFilePath.parent_path(); FileSys.registerPathToken("${BASE}", base); + // For now, we just initialize glfw since we can't execute anything meaningfully + // after SGCT initializes glfw. There is a bit of startup delay because of this, + // but it shouldn't be too bad + glfwInit(); + GLFWmonitor* m = glfwGetPrimaryMonitor(); + const GLFWvidmode* mode = glfwGetVideoMode(m); + glm::ivec2 size = glm::ivec2(mode->width, mode->height); + glfwTerminate(); + + // Loading configuration from disk LDEBUG("Loading configuration from disk"); *global::configuration = configuration::loadConfigurationFromFile( configurationFilePath.string(), + size, commandlineArguments.configurationOverride ); diff --git a/include/openspace/engine/configuration.h b/include/openspace/engine/configuration.h index 5f541306ec..9831caf949 100644 --- a/include/openspace/engine/configuration.h +++ b/include/openspace/engine/configuration.h @@ -141,7 +141,7 @@ struct Configuration { std::filesystem::path findConfiguration(const std::string& filename = "openspace.cfg"); Configuration loadConfigurationFromFile(const std::filesystem::path& filename, - const std::string& overrideScript); + const glm::ivec2& primaryMonitorResolution, const std::string& overrideScript); } // namespace openspace::configuration diff --git a/scripts/configuration_helper.lua b/scripts/configuration_helper.lua index 0b55af825a..ba9514b9fc 100644 --- a/scripts/configuration_helper.lua +++ b/scripts/configuration_helper.lua @@ -357,21 +357,6 @@ end -function normalizeArg(arg) - arg = arg or {} - - check("number", arg, 1) - check("number", arg, 2) - - if type(arg[1]) == "number" and type(arg[2]) == "number" then - arg["size"] = { arg[1], arg[2] } - arg[1] = nil - arg[2] = nil - end -end - - - function sgct.makeConfig(config) local configFile = os.tmpname() .. ".json" local file = io.open(configFile, "w+") @@ -383,7 +368,21 @@ end function sgct.config.single(arg) - normalizeArg(arg) + arg = arg or {} + + if type(arg[1]) == "number" and type(arg[2]) == "number" then + arg["size"] = { arg[1], arg[2] } + arg[1] = nil + arg[2] = nil + else + -- No numbers specified, therefore we want to use the screen resolution of the primary + -- monitor to derive the resolution + -- ScreenResolution is a variable that got injected into the openspace.cfg by the + -- OpenSpace code prior to loading this file + + local scale_factor = 2.0/3.0; + arg["size"] = { ScreenResolution.x * scale_factor, ScreenResolution.y * scale_factor } + end check("table", arg, "size", "number") check("table", arg, "fov", "number") @@ -429,7 +428,24 @@ end function sgct.config.fisheye(arg) - normalizeArg(arg) + arg = arg or {} + + check("number", arg, 1) + check("number", arg, 2) + + if type(arg[1]) == "number" and type(arg[2]) == "number" then + arg["size"] = { arg[1], arg[2] } + arg[1] = nil + arg[2] = nil + else + -- No numbers specified, therefore we want to use the screen resolution of the primary + -- monitor to derive the resolution + -- ScreenResolution is a variable that got injected into the openspace.cfg by the + -- OpenSpace code prior to loading this file + + local scale_factor = 2.0/3.0; + arg["size"] = { ScreenResolution.x * scale_factor, ScreenResolution.y * scale_factor } + end check("number", arg, "fov") check("number", arg, "tilt") diff --git a/src/engine/configuration.cpp b/src/engine/configuration.cpp index 99b65f9a77..a1acf617cc 100644 --- a/src/engine/configuration.cpp +++ b/src/engine/configuration.cpp @@ -452,12 +452,20 @@ std::filesystem::path findConfiguration(const std::string& filename) { } Configuration loadConfigurationFromFile(const std::filesystem::path& filename, + const glm::ivec2& primaryMonitorResolution, const std::string& overrideScript) { ghoul_assert(std::filesystem::is_regular_file(filename), "File must exist"); Configuration result; + // Injecting the resolution of the primary screen into the Lua state + std::string script = fmt::format( + "ScreenResolution = {{ x = {}, y = {} }}", + primaryMonitorResolution.x, primaryMonitorResolution.y + ); + ghoul::lua::runScript(result.state, script); + // If there is an initial config helper file, load it into the state if (std::filesystem::is_regular_file(absPath(InitialConfigHelper))) { ghoul::lua::runScriptFile(result.state, absPath(InitialConfigHelper).string()); diff --git a/tests/main.cpp b/tests/main.cpp index 5265b65dca..8b07953769 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -67,6 +67,7 @@ int main(int argc, char** argv) { *global::configuration = configuration::loadConfigurationFromFile( configFile.string(), + glm::ivec2(0), "" ); global::openSpaceEngine->registerPathTokens(); diff --git a/tests/test_configuration.cpp b/tests/test_configuration.cpp index c69d9fbd91..9736c0e75b 100644 --- a/tests/test_configuration.cpp +++ b/tests/test_configuration.cpp @@ -53,15 +53,15 @@ FontSize = { Configuration loadConfiguration(const std::string& tag, const std::string& content) { std::string filename = fmt::format("test_configuration_{}.cfg", tag); std::filesystem::path path = std::filesystem::temp_directory_path(); - std::string configFile = (path / filename).string(); - writeConfig(configFile, content); + std::string file = (path / filename).string(); + writeConfig(file, content); try { - Configuration conf = loadConfigurationFromFile(configFile, content); - std::filesystem::remove(configFile); + Configuration conf = loadConfigurationFromFile(file, glm::ivec2(0), content); + std::filesystem::remove(file); return conf; } catch (...) { - std::filesystem::remove(configFile); + std::filesystem::remove(file); throw; } }