diff --git a/examples/stencil/Stencil.cpp b/examples/stencil/Stencil.cpp index 7af35a40c..7efd76450 100644 --- a/examples/stencil/Stencil.cpp +++ b/examples/stencil/Stencil.cpp @@ -19,7 +19,7 @@ int main() "SFML Stencil", sf::Style::Titlebar | sf::Style::Close, sf::State::Windowed, - sf::ContextSettings(0, 8)); + sf::ContextSettings{0 /* depthBits */, 8 /* stencilBits */}); window.setVerticalSyncEnabled(true); sf::RectangleShape red({500, 50}); diff --git a/include/SFML/Graphics/RenderTexture.hpp b/include/SFML/Graphics/RenderTexture.hpp index e5c6fc07e..87575ce16 100644 --- a/include/SFML/Graphics/RenderTexture.hpp +++ b/include/SFML/Graphics/RenderTexture.hpp @@ -101,8 +101,7 @@ public: /// \return Render texture if creation has been successful, otherwise `std::nullopt` /// //////////////////////////////////////////////////////////// - [[nodiscard]] static std::optional create(const Vector2u& size, - const ContextSettings& settings = ContextSettings()); + [[nodiscard]] static std::optional create(const Vector2u& size, const ContextSettings& settings = {}); //////////////////////////////////////////////////////////// /// \brief Get the maximum anti-aliasing level supported by the system diff --git a/include/SFML/Graphics/StencilMode.hpp b/include/SFML/Graphics/StencilMode.hpp index d40e010db..70c14a6f2 100644 --- a/include/SFML/Graphics/StencilMode.hpp +++ b/include/SFML/Graphics/StencilMode.hpp @@ -214,7 +214,7 @@ SFML_GRAPHICS_API bool operator!=(const StencilMode& left, const StencilMode& ri /// Usage example: /// \code /// // Make sure we create a RenderTarget with a stencil buffer by specifying it via the context settings -/// sf::RenderWindow window(sf::VideoMode({250, 200}), "Stencil Window", sf::Style::Default, sf::ContextSettings(0, 8)); +/// sf::RenderWindow window(sf::VideoMode({250, 200}), "Stencil Window", sf::Style::Default, sf::ContextSettings{0, 8}); /// /// ... /// diff --git a/include/SFML/Window/ContextSettings.hpp b/include/SFML/Window/ContextSettings.hpp index 3c3cd36d1..c078fd8a9 100644 --- a/include/SFML/Window/ContextSettings.hpp +++ b/include/SFML/Window/ContextSettings.hpp @@ -48,46 +48,17 @@ struct ContextSettings Debug = 1 << 2 //!< Debug attribute }; - //////////////////////////////////////////////////////////// - /// \brief Default constructor - /// - /// \param depth Depth buffer bits - /// \param stencil Stencil buffer bits - /// \param antialiasing Antialiasing level - /// \param major Major number of the context version - /// \param minor Minor number of the context version - /// \param attributes Attribute flags of the context - /// \param sRgb sRGB capable framebuffer - /// - //////////////////////////////////////////////////////////// - constexpr explicit ContextSettings( - unsigned int depth = 0, - unsigned int stencil = 0, - unsigned int antialiasing = 0, - unsigned int major = 1, - unsigned int minor = 1, - unsigned int attributes = Default, - bool sRgb = false) : - depthBits(depth), - stencilBits(stencil), - antialiasingLevel(antialiasing), - majorVersion(major), - minorVersion(minor), - attributeFlags(attributes), - sRgbCapable(sRgb) - { - } //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - unsigned int depthBits; //!< Bits of the depth buffer - unsigned int stencilBits; //!< Bits of the stencil buffer - unsigned int antialiasingLevel; //!< Level of antialiasing - unsigned int majorVersion; //!< Major number of the context version to create - unsigned int minorVersion; //!< Minor number of the context version to create - std::uint32_t attributeFlags; //!< The attribute flags to create the context with - bool sRgbCapable; //!< Whether the context framebuffer is sRGB capable + unsigned int depthBits{}; //!< Bits of the depth buffer + unsigned int stencilBits{}; //!< Bits of the stencil buffer + unsigned int antialiasingLevel{}; //!< Level of antialiasing + unsigned int majorVersion{1}; //!< Major number of the context version to create + unsigned int minorVersion{1}; //!< Minor number of the context version to create + std::uint32_t attributeFlags{Attribute::Default}; //!< The attribute flags to create the context with + bool sRgbCapable{}; //!< Whether the context framebuffer is sRGB capable }; } // namespace sf diff --git a/src/SFML/Window/DRM/DRMContext.cpp b/src/SFML/Window/DRM/DRMContext.cpp index b86ecc0f9..93f89f54d 100644 --- a/src/SFML/Window/DRM/DRMContext.cpp +++ b/src/SFML/Window/DRM/DRMContext.cpp @@ -521,7 +521,7 @@ DRMContext::DRMContext(DRMContext* shared) m_display = getInitializedDisplay(); // Get the best EGL config matching the default video settings - m_config = getBestConfig(m_display, VideoMode::getDesktopMode().bitsPerPixel, ContextSettings()); + m_config = getBestConfig(m_display, VideoMode::getDesktopMode().bitsPerPixel, ContextSettings{}); updateSettings(); // Create EGL context diff --git a/src/SFML/Window/GlContext.cpp b/src/SFML/Window/GlContext.cpp index 6e0ca1f88..c23653ac1 100644 --- a/src/SFML/Window/GlContext.cpp +++ b/src/SFML/Window/GlContext.cpp @@ -206,7 +206,7 @@ struct GlContext::SharedContext const std::lock_guard lock(mutex); context.emplace(nullptr); - context->initialize(sf::ContextSettings()); + context->initialize(ContextSettings{}); loadExtensions(); @@ -572,7 +572,7 @@ std::unique_ptr GlContext::create() sharedContext->context->setActive(false); - context->initialize(ContextSettings()); + context->initialize(ContextSettings{}); return context; } @@ -594,7 +594,12 @@ std::unique_ptr GlContext::create(const ContextSettings& settings, co !(sharedContext->context->m_settings.attributeFlags & ContextSettings::Core)) { // Re-create our shared context as a core context - const ContextSettings sharedSettings(0, 0, 0, settings.majorVersion, settings.minorVersion, settings.attributeFlags); + const ContextSettings sharedSettings{/* depthBits */ 0, + /* stencilBits */ 0, + /* antialiasingLevel */ 0, + settings.majorVersion, + settings.minorVersion, + settings.attributeFlags}; sharedContext->context.emplace(nullptr, sharedSettings, Vector2u(1, 1)); sharedContext->context->initialize(sharedSettings); @@ -638,7 +643,12 @@ std::unique_ptr GlContext::create(const ContextSettings& settings, co !(sharedContext->context->m_settings.attributeFlags & ContextSettings::Core)) { // Re-create our shared context as a core context - const ContextSettings sharedSettings(0, 0, 0, settings.majorVersion, settings.minorVersion, settings.attributeFlags); + const ContextSettings sharedSettings{/* depthBits */ 0, + /* stencilBits */ 0, + /* antialiasingLevel */ 0, + settings.majorVersion, + settings.minorVersion, + settings.attributeFlags}; sharedContext->context.emplace(nullptr, sharedSettings, Vector2u(1, 1)); sharedContext->context->initialize(sharedSettings); diff --git a/src/SFML/Window/Unix/GlxContext.cpp b/src/SFML/Window/Unix/GlxContext.cpp index 1f1629f8d..b7e7d3723 100644 --- a/src/SFML/Window/Unix/GlxContext.cpp +++ b/src/SFML/Window/Unix/GlxContext.cpp @@ -110,7 +110,7 @@ namespace sf::priv GlxContext::GlxContext(GlxContext* shared) { // Save the creation settings - m_settings = ContextSettings(); + m_settings = ContextSettings{}; // Open the connection with the X server m_display = openDisplay(); diff --git a/src/SFML/Window/Win32/WglContext.cpp b/src/SFML/Window/Win32/WglContext.cpp index 9223cb517..acd925fe4 100644 --- a/src/SFML/Window/Win32/WglContext.cpp +++ b/src/SFML/Window/Win32/WglContext.cpp @@ -125,7 +125,7 @@ String getErrorString(DWORD errorCode) //////////////////////////////////////////////////////////// -WglContext::WglContext(WglContext* shared) : WglContext(shared, ContextSettings(), {1u, 1u}) +WglContext::WglContext(WglContext* shared) : WglContext(shared, ContextSettings{}, {1u, 1u}) { } diff --git a/src/SFML/Window/Window.cpp b/src/SFML/Window/Window.cpp index 7591b0608..4b00bc106 100644 --- a/src/SFML/Window/Window.cpp +++ b/src/SFML/Window/Window.cpp @@ -72,7 +72,7 @@ Window::~Window() //////////////////////////////////////////////////////////// void Window::create(VideoMode mode, const String& title, std::uint32_t style, State state) { - Window::create(mode, title, style, state, ContextSettings()); + Window::create(mode, title, style, state, ContextSettings{}); } @@ -96,7 +96,7 @@ void Window::create(VideoMode mode, const String& title, std::uint32_t style, St //////////////////////////////////////////////////////////// void Window::create(WindowHandle handle) { - Window::create(handle, ContextSettings()); + Window::create(handle, ContextSettings{}); } @@ -131,7 +131,7 @@ void Window::close() //////////////////////////////////////////////////////////// const ContextSettings& Window::getSettings() const { - static constexpr ContextSettings empty(0, 0, 0); + static constexpr ContextSettings empty{/* depthBits */ 0, /* stencilBits */ 0, /* antialiasingLevel */ 0}; return m_context ? m_context->getSettings() : empty; } diff --git a/src/SFML/Window/WindowBase.cpp b/src/SFML/Window/WindowBase.cpp index adf889f4f..e44124e6f 100644 --- a/src/SFML/Window/WindowBase.cpp +++ b/src/SFML/Window/WindowBase.cpp @@ -95,7 +95,17 @@ void WindowBase::create(VideoMode mode, const String& title, std::uint32_t style WindowBase::create(mode, style, state); // Recreate the window implementation - m_impl = priv::WindowImpl::create(mode, title, style, state, ContextSettings(0, 0, 0, 0, 0, 0xFFFFFFFF, false)); + m_impl = priv::WindowImpl::create(mode, + title, + style, + state, + ContextSettings{/* depthBits */ 0, + /* stencilBits */ 0, + /* antialiasingLevel */ 0, + /* majorVersion */ 0, + /* minorVersion */ 0, + /* attributeFlags */ 0xFFFFFFFF, + /* sRgbCapable */ false}); // Perform common initializations initialize(); diff --git a/src/SFML/Window/macOS/SFContext.mm b/src/SFML/Window/macOS/SFContext.mm index f55eacfb5..0bd5c0125 100644 --- a/src/SFML/Window/macOS/SFContext.mm +++ b/src/SFML/Window/macOS/SFContext.mm @@ -45,7 +45,9 @@ SFContext::SFContext(SFContext* shared) { const AutoreleasePool pool; // Create the context - createContext(shared, VideoMode::getDesktopMode().bitsPerPixel, ContextSettings(0, 0, 0)); + createContext(shared, + VideoMode::getDesktopMode().bitsPerPixel, + ContextSettings{0 /* depthBits */, 0 /* stencilBits */, 0 /* antialiasingLevel */}); } diff --git a/test/Graphics/Render.test.cpp b/test/Graphics/Render.test.cpp index c6c1e64c8..28c9da10c 100644 --- a/test/Graphics/Render.test.cpp +++ b/test/Graphics/Render.test.cpp @@ -12,7 +12,9 @@ TEST_CASE("[Graphics] Render Tests", runDisplayTests()) { SECTION("Stencil Tests") { - auto renderTexture = sf::RenderTexture::create({100, 100}, sf::ContextSettings(0, 8)).value(); + auto renderTexture = sf::RenderTexture::create({100, 100}, sf::ContextSettings{0 /* depthBits */, 8 /* stencilBits */}) + .value(); + renderTexture.clear(sf::Color::Red, 127); sf::RectangleShape shape1({100, 100}); diff --git a/test/Graphics/RenderTexture.test.cpp b/test/Graphics/RenderTexture.test.cpp index 8d47a8b74..9a03abaae 100644 --- a/test/Graphics/RenderTexture.test.cpp +++ b/test/Graphics/RenderTexture.test.cpp @@ -20,14 +20,15 @@ TEST_CASE("[Graphics] sf::RenderTexture", runDisplayTests()) { CHECK(!sf::RenderTexture::create({1'000'000, 1'000'000})); - CHECK(sf::RenderTexture::create({100, 100}, sf::ContextSettings(8, 0))); - CHECK(sf::RenderTexture::create({100, 100}, sf::ContextSettings(0, 8))); + CHECK(sf::RenderTexture::create({100, 100}, sf::ContextSettings{8 /* depthBits */, 0 /* stencilBits */})); + CHECK(sf::RenderTexture::create({100, 100}, sf::ContextSettings{0 /* depthBits */, 8 /* stencilBits */})); const auto renderTexture = sf::RenderTexture::create({360, 480}).value(); CHECK(renderTexture.getSize() == sf::Vector2u(360, 480)); CHECK(!renderTexture.isSmooth()); CHECK(!renderTexture.isRepeated()); CHECK(!renderTexture.isSrgb()); + const auto& texture = renderTexture.getTexture(); CHECK(texture.getSize() == sf::Vector2u(360, 480)); CHECK(!texture.isSmooth()); diff --git a/test/Graphics/RenderWindow.test.cpp b/test/Graphics/RenderWindow.test.cpp index f0c8d6861..c685da2a3 100644 --- a/test/Graphics/RenderWindow.test.cpp +++ b/test/Graphics/RenderWindow.test.cpp @@ -33,7 +33,7 @@ TEST_CASE("[Graphics] sf::RenderWindow", runDisplayTests()) "Window Title", sf::Style::Default, sf::State::Windowed, - sf::ContextSettings()); + sf::ContextSettings{}); CHECK(window.isOpen()); CHECK(window.getSize() == sf::Vector2u(256, 256)); CHECK(window.getNativeHandle() != sf::WindowHandle()); @@ -51,7 +51,7 @@ TEST_CASE("[Graphics] sf::RenderWindow", runDisplayTests()) const sf::RenderWindow window(sf::VideoMode(sf::Vector2u(240, 300), 24), "Window Title", sf::State::Windowed, - sf::ContextSettings()); + sf::ContextSettings{}); CHECK(window.isOpen()); CHECK(window.getSize() == sf::Vector2u(240, 300)); CHECK(window.getNativeHandle() != sf::WindowHandle()); @@ -72,7 +72,7 @@ TEST_CASE("[Graphics] sf::RenderWindow", runDisplayTests()) "Window Title", sf::Style::Default, sf::State::Windowed, - sf::ContextSettings()); + sf::ContextSettings{}); REQUIRE(window.getSize() == sf::Vector2u(256, 256)); sf::Texture texture; diff --git a/test/Window/ContextSettings.test.cpp b/test/Window/ContextSettings.test.cpp index e0b393ebe..5f87c9b55 100644 --- a/test/Window/ContextSettings.test.cpp +++ b/test/Window/ContextSettings.test.cpp @@ -16,7 +16,7 @@ TEST_CASE("[Window] sf::ContextSettings") SECTION("Construction") { - SECTION("Default constructor") + SECTION("Aggregate initialization -- Nothing") { constexpr sf::ContextSettings contextSettings; STATIC_CHECK(contextSettings.depthBits == 0); @@ -28,9 +28,9 @@ TEST_CASE("[Window] sf::ContextSettings") STATIC_CHECK(contextSettings.sRgbCapable == false); } - SECTION("Verbose constructor") + SECTION("Aggregate initialization -- Everything") { - constexpr sf::ContextSettings contextSettings(1, 1, 2, 3, 5, sf::ContextSettings::Core, true); + constexpr sf::ContextSettings contextSettings{1, 1, 2, 3, 5, sf::ContextSettings::Core, true}; STATIC_CHECK(contextSettings.depthBits == 1); STATIC_CHECK(contextSettings.stencilBits == 1); STATIC_CHECK(contextSettings.antialiasingLevel == 2); diff --git a/test/Window/Window.test.cpp b/test/Window/Window.test.cpp index 499b6c547..a2ce96bb1 100644 --- a/test/Window/Window.test.cpp +++ b/test/Window/Window.test.cpp @@ -72,7 +72,7 @@ TEST_CASE("[Window] sf::Window", runDisplayTests()) "Window Tests", sf::Style::Resize, sf::State::Windowed, - sf::ContextSettings(1, 1, 1)); + sf::ContextSettings{/* depthBits*/ 1, /* stencilBits */ 1, /* antialiasingLevel */ 1}); CHECK(window.isOpen()); CHECK(window.getSize() == sf::Vector2u(360, 240)); CHECK(window.getNativeHandle() != sf::WindowHandle()); @@ -95,7 +95,7 @@ TEST_CASE("[Window] sf::Window", runDisplayTests()) const sf::Window window(sf::VideoMode({360, 240}), "Window Tests", sf::State::Windowed, - sf::ContextSettings(1, 1, 1)); + sf::ContextSettings{/* depthBits*/ 1, /* stencilBits */ 1, /* antialiasingLevel */ 1}); CHECK(window.isOpen()); CHECK(window.getSize() == sf::Vector2u(360, 240)); CHECK(window.getNativeHandle() != sf::WindowHandle()); @@ -133,7 +133,7 @@ TEST_CASE("[Window] sf::Window", runDisplayTests()) "Window Tests", sf::Style::Resize, sf::State::Windowed, - sf::ContextSettings(1, 1, 1)); + sf::ContextSettings{/* depthBits*/ 1, /* stencilBits */ 1, /* antialiasingLevel */ 1}); CHECK(window.isOpen()); CHECK(window.getSize() == sf::Vector2u(240, 360)); CHECK(window.getNativeHandle() != sf::WindowHandle());