diff --git a/src/hello_imgui/doc_params.md b/src/hello_imgui/doc_params.md index 68c88571..30a18f05 100644 --- a/src/hello_imgui/doc_params.md +++ b/src/hello_imgui/doc_params.md @@ -873,8 +873,9 @@ Source: [dpi_aware.h](https://github.com/pthom/hello_imgui/blob/master/src/hello // // Hello ImGui will try its best to automatically handle DPI scaling for you. -// It does this by setting two values: // +// Parameters to change the scaling behavior: +// ------------------------------------------ // - `dpiWindowSizeFactor`: // factor by which window size should be multiplied // @@ -885,22 +886,22 @@ Source: [dpi_aware.h](https://github.com/pthom/hello_imgui/blob/master/src/hello // By default, Hello ImGui will compute them automatically, // when dpiWindowSizeFactor and fontRenderingScale are set to 0. // +// Parameters to improve font rendering quality: +// --------------------------------------------- +// - `fontOversampleH` and `fontOversampleV` : Font oversampling parameters +// Rasterize at higher quality for sub-pixel positioning. Probably unused if freeType is used. +// If not zero, these values will be used to set the oversampling factor when loading fonts. +// +// // How to set those values manually: // --------------------------------- // If it fails (i.e. your window and/or fonts are too big or too small), // you may set them manually: // (1) Either by setting them programmatically in your application // (set their values in `runnerParams.dpiAwareParams`) -// (2) Either by setting them in a `hello_imgui.ini` file in the current folder, or any of its parent folders. -// (this is useful when you want to set them for a specific app or set of apps, without modifying the app code) +// (2) Either by setting them in a `hello_imgui.ini` file. See hello_imgui/hello_imgui_example.ini for more info // Note: if several methods are used, the order of priority is (1) > (2) // -// Example content of a ini file: -// ------------------------------ -// [DpiAwareParams] -// dpiWindowSizeFactor=2 -// fontRenderingScale=0.5 -// // For more information, see the documentation on DPI handling, here: https://pthom.github.io/hello_imgui/book/doc_api.html#handling-screens-with-high-dpi // struct DpiAwareParams @@ -934,10 +935,22 @@ struct DpiAwareParams // (This parameter will be used to set ImGui::GetIO().FontGlobalScale at startup) float fontRenderingScale = 0.0f; - // `onlyUseFontDpiResponsive` - // If true, guarantees that only HelloImGui::LoadDpiResponsiveFont will be used to load fonts. - // (also for the default font) - bool onlyUseFontDpiResponsive = false; + // `onlyUseFontDpiResponsive` + // If true, guarantees that only HelloImGui::LoadDpiResponsiveFont will be used to load fonts. + // (also for the default font) + bool onlyUseFontDpiResponsive = false; + + // `fontOversampleH` and `fontOversampleV` : Font oversampling parameters + // Rasterize at higher quality for sub-pixel positioning. Probably unused if freeType is used. + // If not zero, these values will be used to set the oversampling factor when loading fonts. + // (i.e. they will be set in ImFontConfig::OversampleH and ImFontConfig::OversampleV) + // OversampleH: The difference between 2 and 3 for OversampleH is minimal. + // You can reduce this to 1 for large glyphs save memory. + // OversampleV: This is not really useful as we don't use sub-pixel positions on the Y axis. + // Read https://github.com/nothings/stb/blob/master/tests/oversample/README.md for details. + int fontOversampleH = 0; // Default is 2 in ImFontConfig + int fontOversampleV = 0; // Default is 1 in ImFontConfig + // `dpiFontLoadingFactor` // factor by which font size should be multiplied at loading time to get a similar @@ -1368,7 +1381,7 @@ struct RendererBackendOptions // `openGlOptions`: // Advanced options for OpenGL. Use at your own risk. - std::optional openGlOptions = std::nullopt; + OpenGlOptions openGlOptions; }; diff --git a/src/hello_imgui/internal/backend_impls/abstract_runner.cpp b/src/hello_imgui/internal/backend_impls/abstract_runner.cpp index 18970c0c..2a2782b0 100644 --- a/src/hello_imgui/internal/backend_impls/abstract_runner.cpp +++ b/src/hello_imgui/internal/backend_impls/abstract_runner.cpp @@ -234,63 +234,6 @@ bool AbstractRunner::ShallSizeWindowRelativeTo96Ppi() return shallSizeRelativeTo96Ppi; } -void AbstractRunner::ReadOpenGlOptions() -{ - // cf renderer_backend_options.h: - // - // OpenGlOptions contains advanced options used at the startup of OpenGL. - // These parameters are reserved for advanced users. - // By default, Hello ImGui will select reasonable default values, and these parameters are not used. - // Use at your own risk, as they make break the multi-platform compatibility of your application! - // All these parameters are platform dependent. - // For real multiplatform examples, see - // hello_imgui/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_glfw.cpp - // and - // hello_imgui/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_sdl.cpp - // - // How to set those values manually: - // --------------------------------- - // you may set them manually: - // (1) Either by setting them programmatically in your application - // (set their values in `runnerParams.rendererBackendOptions.openGlOptions`) - // (2) Either by setting them in a `hello_imgui.ini` file. See hello_imgui/hello_imgui_example.ini for more info - // Note: if several methods are used, the order of priority is (1) > (2) - - // If options specified by the program, do not read them. - if (params.rendererBackendOptions.openGlOptions.has_value()) - return; - - std::string openGlSection = "OpenGlOptions"; - - auto majorVersion = HelloImGuiIniAnyParentFolder::readIntValue(openGlSection, "MajorVersion"); - auto minorVersion = HelloImGuiIniAnyParentFolder::readIntValue(openGlSection, "MinorVersion"); - auto useCoreProfile = HelloImGuiIniAnyParentFolder::readBoolValue(openGlSection, "UseCoreProfile"); - auto useForwardCompat = HelloImGuiIniAnyParentFolder::readBoolValue(openGlSection, "UseForwardCompat"); - auto glslVersion = HelloImGuiIniAnyParentFolder::readStringValue(openGlSection, "GlslVersion"); - auto antiAliasingSamples = HelloImGuiIniAnyParentFolder::readIntValue(openGlSection, "AntiAliasingSamples"); - - bool isAnySettingsSpecified = majorVersion.has_value() || minorVersion.has_value() || useCoreProfile.has_value() || useForwardCompat.has_value() || glslVersion.has_value() || antiAliasingSamples.has_value(); - - if (isAnySettingsSpecified) - { - params.rendererBackendOptions.openGlOptions = OpenGlOptions(); - auto& openGlOptions = params.rendererBackendOptions.openGlOptions.value(); - if (majorVersion.has_value()) - openGlOptions.MajorVersion = majorVersion.value(); - if (minorVersion.has_value()) - openGlOptions.MinorVersion = minorVersion.value(); - if (useCoreProfile.has_value()) - openGlOptions.UseCoreProfile = useCoreProfile.value(); - if (useForwardCompat.has_value()) - openGlOptions.UseForwardCompat = useForwardCompat.value(); - if (glslVersion.has_value()) - openGlOptions.GlslVersion = glslVersion.value(); - if (antiAliasingSamples.has_value()) - openGlOptions.AntiAliasingSamples = antiAliasingSamples.value(); - } - -} - void ReadDpiAwareParams(DpiAwareParams* dpiAwareParams) { // cf dpi_aware.h @@ -729,10 +672,6 @@ void AbstractRunner::Setup() InitImGuiContext(); SetImGuiPrefs(); - #ifdef HELLOIMGUI_HAS_OPENGL - ReadOpenGlOptions(); - #endif - // Init platform backend (SDL, Glfw) Impl_InitPlatformBackend(); diff --git a/src/hello_imgui/internal/backend_impls/abstract_runner.h b/src/hello_imgui/internal/backend_impls/abstract_runner.h index 9f198655..20d804a3 100644 --- a/src/hello_imgui/internal/backend_impls/abstract_runner.h +++ b/src/hello_imgui/internal/backend_impls/abstract_runner.h @@ -86,7 +86,6 @@ class AbstractRunner void SetImGuiPrefs(); void InitRenderBackendCallbacks(); - void ReadOpenGlOptions(); void SetupDpiAwareParams(); bool CheckDpiAwareParamsChanges(); void PrepareWindowGeometry(); diff --git a/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_api.cpp b/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_api.cpp index 02a06e56..2a77c869 100644 --- a/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_api.cpp +++ b/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_api.cpp @@ -1,9 +1,94 @@ #include "opengl_setup_api.h" #include "hello_imgui/hello_imgui_include_opengl.h" +#include "hello_imgui/hello_imgui.h" +#include "hello_imgui/internal/hello_imgui_ini_any_parent_folder.h" #include namespace HelloImGui { namespace BackendApi { + void ModifyOpenGlOptionsFromUserSettingsInParams(OpenGlOptionsFilled_ *openGlOptions) + { + OpenGlOptions& userOptions =HelloImGui::GetRunnerParams()->rendererBackendOptions.openGlOptions; + + if (userOptions.MajorVersion.has_value()) + openGlOptions->MajorVersion = userOptions.MajorVersion.value(); + if (userOptions.MinorVersion.has_value()) + openGlOptions->MinorVersion = userOptions.MinorVersion.value(); + if (userOptions.UseCoreProfile.has_value()) + openGlOptions->UseCoreProfile = userOptions.UseCoreProfile.value(); + if (userOptions.UseForwardCompat.has_value()) + openGlOptions->UseForwardCompat = userOptions.UseForwardCompat.value(); + if (userOptions.AntiAliasingSamples.has_value()) + openGlOptions->AntiAliasingSamples = userOptions.AntiAliasingSamples.value(); + } + + + void ModifyOpenGlOptionsFromUserSettingsInHelloImGuiIniFile(OpenGlOptionsFilled_ *openGlOptions) + { + // cf renderer_backend_options.h: + // + // OpenGlOptions contains advanced options used at the startup of OpenGL. + // These parameters are reserved for advanced users. + // By default, Hello ImGui will select reasonable default values, and these parameters are not used. + // Use at your own risk, as they make break the multi-platform compatibility of your application! + // All these parameters are platform dependent. + // For real multiplatform examples, see + // hello_imgui/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_glfw.cpp + // and + // hello_imgui/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_sdl.cpp + // + // How to set those values manually: + // --------------------------------- + // you may set them manually: + // (1) Either by setting them programmatically in your application + // (set their values in `runnerParams.rendererBackendOptions.openGlOptions`) + // (2) Either by setting them in a `hello_imgui.ini` file. See hello_imgui/hello_imgui_example.ini for more info + // Note: if several methods are used, the order of priority is (1) > (2) + + std::string openGlSection = "OpenGlOptions"; + + auto majorVersion = HelloImGuiIniAnyParentFolder::readIntValue(openGlSection, "MajorVersion"); + if (majorVersion.has_value()) + openGlOptions->MajorVersion = majorVersion.value(); + + auto minorVersion = HelloImGuiIniAnyParentFolder::readIntValue(openGlSection, "MinorVersion"); + if (minorVersion.has_value()) + openGlOptions->MinorVersion = minorVersion.value(); + + auto useCoreProfile = HelloImGuiIniAnyParentFolder::readBoolValue(openGlSection, "UseCoreProfile"); + if (useCoreProfile.has_value()) + openGlOptions->UseCoreProfile = useCoreProfile.value(); + + auto useForwardCompat = HelloImGuiIniAnyParentFolder::readBoolValue(openGlSection, "UseForwardCompat"); + if (useForwardCompat.has_value()) + openGlOptions->UseForwardCompat = useForwardCompat.value(); + + auto glslVersion = HelloImGuiIniAnyParentFolder::readStringValue(openGlSection, "GlslVersion"); + if (glslVersion.has_value()) + openGlOptions->GlslVersion = glslVersion.value(); + + auto antiAliasingSamples = HelloImGuiIniAnyParentFolder::readIntValue(openGlSection, "AntiAliasingSamples"); + if (antiAliasingSamples.has_value()) + openGlOptions->AntiAliasingSamples = antiAliasingSamples.value(); + } + + OpenGlOptionsFilled_ IOpenGlSetup::OpenGlOptionsWithUserSettings() + { + // We compute this only once + static OpenGlOptionsFilled_ openGlOptions; + static bool wasFilled = false; + if (! wasFilled) + { + openGlOptions = Impl_MakeDefaultOpenGlOptionsForPlatform(); + ModifyOpenGlOptionsFromUserSettingsInHelloImGuiIniFile(&openGlOptions); + ModifyOpenGlOptionsFromUserSettingsInParams(&openGlOptions); + wasFilled = true; + } + + OpenGlOptionsFilled_ r = openGlOptions; + return r; + } + }} // namespace HelloImGui { namespace BackendApi diff --git a/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_api.h b/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_api.h index 4c02584b..6586872d 100644 --- a/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_api.h +++ b/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_api.h @@ -1,5 +1,6 @@ #pragma once #include "hello_imgui/screen_bounds.h" +#include "hello_imgui/renderer_backend_options.h" #include @@ -12,8 +13,10 @@ namespace HelloImGui { namespace BackendApi IOpenGlSetup() {} virtual ~IOpenGlSetup() {} - virtual void SelectOpenGlVersion() = 0; + virtual void SelectOpenGlVersion(const OpenGlOptionsFilled_& options) = 0; virtual void InitGlLoader() = 0; - virtual std::string GlslVersion() = 0; + virtual OpenGlOptionsFilled_ Impl_MakeDefaultOpenGlOptionsForPlatform() = 0; + + OpenGlOptionsFilled_ OpenGlOptionsWithUserSettings(); }; }} // namespace HelloImGui { namespace BackendApi diff --git a/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_glfw.cpp b/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_glfw.cpp index adc51145..6205a8d2 100644 --- a/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_glfw.cpp +++ b/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_glfw.cpp @@ -19,7 +19,7 @@ namespace HelloImGui { namespace BackendApi glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); - return glfwCreateWindow(64, 32, "Dummy", NULL, NULL); + return glfwCreateWindow(64, 32, "Dummy", nullptr, nullptr); }(); if (!dummyWindow) @@ -38,7 +38,7 @@ namespace HelloImGui { namespace BackendApi return maxSamples; } - static void ApplyAntiAliasingSamples(OpenGlOptions& openGlOptions) + static void ApplyAntiAliasingSamples(const OpenGlOptionsFilled_& openGlOptions) { int userQuerySamples = openGlOptions.AntiAliasingSamples; int maxGpuSamples = QueryMaxAntiAliasingSamples(); @@ -69,7 +69,7 @@ namespace HelloImGui { namespace BackendApi } #endif // #ifdef HELLOIMGUI_HAS_OPENGL3 - static void ApplyOpenGlOptions(OpenGlOptions& openGlOptions) + static void ApplyOpenGlOptions(const OpenGlOptionsFilled_& openGlOptions) { glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, openGlOptions.MajorVersion); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, openGlOptions.MinorVersion); @@ -80,18 +80,14 @@ namespace HelloImGui { namespace BackendApi #ifdef HELLOIMGUI_HAS_OPENGL3 ApplyAntiAliasingSamples(openGlOptions); -#endif // #ifdef HELLOIMGUI_HAS_OPENGL3 +#endif } - static OpenGlOptions MakeOpenGlOptions() + OpenGlOptionsFilled_ OpenGlSetupGlfw::Impl_MakeDefaultOpenGlOptionsForPlatform() { - auto* runnerParams = HelloImGui::GetRunnerParams(); - if (runnerParams->rendererBackendOptions.openGlOptions.has_value()) - return runnerParams->rendererBackendOptions.openGlOptions.value(); - - OpenGlOptions openGlOptions; + OpenGlOptionsFilled_ openGlOptions; - openGlOptions.AntiAliasingSamples = -1; // -1 <=> not set, will use the default value of 8 + openGlOptions.AntiAliasingSamples = 8; // // Compute MajorVersion, MinorVersion, UseCoreProfile, UseForwardCompat @@ -137,10 +133,9 @@ namespace HelloImGui { namespace BackendApi return openGlOptions; } - void OpenGlSetupGlfw::SelectOpenGlVersion() + void OpenGlSetupGlfw::SelectOpenGlVersion(const OpenGlOptionsFilled_& options) { - OpenGlOptions openGlOptions = MakeOpenGlOptions(); - ApplyOpenGlOptions(openGlOptions); + ApplyOpenGlOptions(options); } void OpenGlSetupGlfw::InitGlLoader() @@ -163,12 +158,6 @@ namespace HelloImGui { namespace BackendApi } #endif // #ifndef __EMSCRIPTEN__ } - - std::string OpenGlSetupGlfw::GlslVersion() - { - OpenGlOptions openGlOptions = MakeOpenGlOptions(); - return std::string("#version ") + openGlOptions.GlslVersion; - } }} // namespace HelloImGui { namespace BackendApi #endif // #ifdef HELLOIMGUI_USE_GLFW3 diff --git a/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_glfw.h b/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_glfw.h index a5c51dd2..dcc3ed96 100644 --- a/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_glfw.h +++ b/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_glfw.h @@ -10,9 +10,9 @@ namespace HelloImGui { namespace BackendApi public: virtual ~OpenGlSetupGlfw() {} - void SelectOpenGlVersion() override; + void SelectOpenGlVersion(const OpenGlOptionsFilled_& options) override; void InitGlLoader() override; - std::string GlslVersion() override; + OpenGlOptionsFilled_ Impl_MakeDefaultOpenGlOptionsForPlatform() override; }; }} // namespace HelloImGui { namespace BackendApi diff --git a/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_sdl.cpp b/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_sdl.cpp index 9b4c6972..7b47eafb 100644 --- a/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_sdl.cpp +++ b/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_sdl.cpp @@ -10,7 +10,7 @@ namespace HelloImGui { namespace BackendApi { - static void ApplyOpenGlOptions(OpenGlOptions& openGlOptions) + static void ApplyOpenGlOptions(const OpenGlOptionsFilled_& openGlOptions) { #ifndef __EMSCRIPTEN__ // Gl version not set in Emscripten, for legacy reasons that are not clear @@ -24,13 +24,12 @@ namespace HelloImGui { namespace BackendApi SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); } - static OpenGlOptions MakeOpenGlOptions() + OpenGlOptionsFilled_ OpenGlSetupSdl::Impl_MakeDefaultOpenGlOptionsForPlatform() { - auto* runnerParams = HelloImGui::GetRunnerParams(); - if (runnerParams->rendererBackendOptions.openGlOptions.has_value()) - return runnerParams->rendererBackendOptions.openGlOptions.value(); + OpenGlOptionsFilled_ openGlOptions; - OpenGlOptions openGlOptions; + // This SDL backend does not handle antialiasing at the moment! + // openGlOptions.AntiAliasingSamples = 8; // // Compute MajorVersion, MinorVersion, UseCoreProfile, UseForwardCompat @@ -113,13 +112,10 @@ namespace HelloImGui { namespace BackendApi } - void OpenGlSetupSdl::SelectOpenGlVersion() + void OpenGlSetupSdl::SelectOpenGlVersion(const OpenGlOptionsFilled_& options) { AdditionalOpenGlPreSetup(); - - OpenGlOptions openGlOptions = MakeOpenGlOptions(); - ApplyOpenGlOptions(openGlOptions); - + ApplyOpenGlOptions(options); AdditionalOpenGlPostSetup(); } @@ -142,12 +138,6 @@ namespace HelloImGui { namespace BackendApi BACKEND_THROW("Failed to initialize OpenGL loader!"); #endif } - - std::string OpenGlSetupSdl::GlslVersion() - { - OpenGlOptions openGlOptions = MakeOpenGlOptions(); - return std::string("#version ") + openGlOptions.GlslVersion; - } }} // namespace HelloImGui { namespace BackendApi #endif // #ifdef HELLOIMGUI_USE_SDL2 diff --git a/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_sdl.h b/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_sdl.h index 32e416e5..72d7f3b7 100644 --- a/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_sdl.h +++ b/src/hello_imgui/internal/backend_impls/opengl_setup_helper/opengl_setup_sdl.h @@ -11,9 +11,9 @@ namespace HelloImGui { namespace BackendApi public: virtual ~OpenGlSetupSdl() {} - void SelectOpenGlVersion() override; + void SelectOpenGlVersion(const OpenGlOptionsFilled_& options) override; void InitGlLoader() override; - std::string GlslVersion() override; + OpenGlOptionsFilled_ Impl_MakeDefaultOpenGlOptionsForPlatform() override; }; }} // namespace HelloImGui { namespace BackendApi diff --git a/src/hello_imgui/internal/backend_impls/runner_glfw3.cpp b/src/hello_imgui/internal/backend_impls/runner_glfw3.cpp index c4677046..c84dcfc8 100644 --- a/src/hello_imgui/internal/backend_impls/runner_glfw3.cpp +++ b/src/hello_imgui/internal/backend_impls/runner_glfw3.cpp @@ -179,9 +179,16 @@ namespace HelloImGui glfwSwapInterval(1); // Enable vsync (openGL only, not vulkan) } - void RunnerGlfw3::Impl_Select_Gl_Version() { gOpenGlSetupGlfw.SelectOpenGlVersion(); } + void RunnerGlfw3::Impl_Select_Gl_Version() + { + auto openGlOptions = gOpenGlSetupGlfw.OpenGlOptionsWithUserSettings(); + gOpenGlSetupGlfw.SelectOpenGlVersion(openGlOptions); + } - std::string RunnerGlfw3::Impl_GlslVersion() const { return gOpenGlSetupGlfw.GlslVersion(); } + std::string RunnerGlfw3::Impl_GlslVersion() const + { + return std::string("#version ") + gOpenGlSetupGlfw.OpenGlOptionsWithUserSettings().GlslVersion; + } void RunnerGlfw3::Impl_InitGlLoader() { gOpenGlSetupGlfw.InitGlLoader(); } #endif // HELLOIMGUI_HAS_OPENGL diff --git a/src/hello_imgui/internal/backend_impls/runner_sdl2.cpp b/src/hello_imgui/internal/backend_impls/runner_sdl2.cpp index 6138f2fc..4f166ffd 100644 --- a/src/hello_imgui/internal/backend_impls/runner_sdl2.cpp +++ b/src/hello_imgui/internal/backend_impls/runner_sdl2.cpp @@ -259,8 +259,16 @@ namespace HelloImGui params.backendPointers.sdlGlContext = mGlContext; } void RunnerSdl2::Impl_InitGlLoader() { gOpenGlSetupSdl.InitGlLoader(); } - void RunnerSdl2::Impl_Select_Gl_Version() { gOpenGlSetupSdl.SelectOpenGlVersion(); } - std::string RunnerSdl2::Impl_GlslVersion() const { return gOpenGlSetupSdl.GlslVersion(); } + void RunnerSdl2::Impl_Select_Gl_Version() + { + auto openGlOptions = gOpenGlSetupSdl.OpenGlOptionsWithUserSettings(); + gOpenGlSetupSdl.SelectOpenGlVersion(openGlOptions); + } + + std::string RunnerSdl2::Impl_GlslVersion() const + { + return std::string("#version ") + gOpenGlSetupSdl.OpenGlOptionsWithUserSettings().GlslVersion; + } #endif // HELLOIMGUI_HAS_OPENGL #ifdef HELLOIMGUI_HAS_METAL diff --git a/src/hello_imgui/renderer_backend_options.h b/src/hello_imgui/renderer_backend_options.h index a714157f..52253f8f 100644 --- a/src/hello_imgui/renderer_backend_options.h +++ b/src/hello_imgui/renderer_backend_options.h @@ -34,16 +34,16 @@ struct OpenGlOptions // "150" on macOS // "130" on Windows // "300es" on GLES - std::string GlslVersion = "130"; + std::optional GlslVersion = std::nullopt; // OpenGL 3.3 (these options won't work for GlEs) - int MajorVersion = 3; - int MinorVersion = 3; + std::optional MajorVersion = std::nullopt; + std::optional MinorVersion = std::nullopt; // OpenGL Core Profile (i.e. only includes the newer, maintained features of OpenGL) - bool UseCoreProfile = true; + std::optional UseCoreProfile = std::nullopt; // OpenGL Forward Compatibility (required on macOS) - bool UseForwardCompat = true; + std::optional UseForwardCompat = std::nullopt; // `AntiAliasingSamples` // If > 0, this value will be used to set the number of samples used for anti-aliasing. @@ -52,19 +52,17 @@ struct OpenGlOptions // - we query the maximum number of samples supported by the hardware, via glGetIntegerv(GL_MAX_SAMPLES) // - if you set this value to a non-zero value, it will be used instead of the default value of 8 // (except if it is greater than the maximum supported value, in which case a warning will be issued) - // - if you set this value to 0, anti-aliasing will be disabled + // - if you set this value to 0, antialiasing will be disabled // // AntiAliasingSamples has a strong impact on the quality of the text rendering - // - 0: no anti-aliasing + // - 0: no antialiasing // - 8: optimal // - 16: optimal if using imgui-node-editor and you want to render very small text when unzooming - int AntiAliasingSamples = -1; // -1 <=> not set (will use the default value of 8) + std::optional AntiAliasingSamples = std::nullopt; }; - // @@md - // @@md#RendererBackendOptions // `bool hasEdrSupport()`: @@ -91,7 +89,7 @@ struct RendererBackendOptions // `openGlOptions`: // Advanced options for OpenGL. Use at your own risk. - std::optional openGlOptions = std::nullopt; + OpenGlOptions openGlOptions; }; @@ -104,4 +102,17 @@ struct RendererBackendOptions // @@md + +// (Private structure, not part of the public API) +// OpenGlOptions after selecting the default platform-dependent values + after applying the user settings +struct OpenGlOptionsFilled_ +{ + std::string GlslVersion = "150"; + int MajorVersion = 3; + int MinorVersion = 3; + bool UseCoreProfile = true; + bool UseForwardCompat = true; + int AntiAliasingSamples = 8; +}; + } // namespace HelloImGui \ No newline at end of file