mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
Turn 'ContextSettings' into an aggregate and update usages
This commit is contained in:
parent
ad03953795
commit
e53f4d62af
@ -19,7 +19,7 @@ int main()
|
|||||||
"SFML Stencil",
|
"SFML Stencil",
|
||||||
sf::Style::Titlebar | sf::Style::Close,
|
sf::Style::Titlebar | sf::Style::Close,
|
||||||
sf::State::Windowed,
|
sf::State::Windowed,
|
||||||
sf::ContextSettings(0, 8));
|
sf::ContextSettings{0 /* depthBits */, 8 /* stencilBits */});
|
||||||
window.setVerticalSyncEnabled(true);
|
window.setVerticalSyncEnabled(true);
|
||||||
|
|
||||||
sf::RectangleShape red({500, 50});
|
sf::RectangleShape red({500, 50});
|
||||||
|
@ -101,8 +101,7 @@ public:
|
|||||||
/// \return Render texture if creation has been successful, otherwise `std::nullopt`
|
/// \return Render texture if creation has been successful, otherwise `std::nullopt`
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
[[nodiscard]] static std::optional<RenderTexture> create(const Vector2u& size,
|
[[nodiscard]] static std::optional<RenderTexture> create(const Vector2u& size, const ContextSettings& settings = {});
|
||||||
const ContextSettings& settings = ContextSettings());
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the maximum anti-aliasing level supported by the system
|
/// \brief Get the maximum anti-aliasing level supported by the system
|
||||||
|
@ -214,7 +214,7 @@ SFML_GRAPHICS_API bool operator!=(const StencilMode& left, const StencilMode& ri
|
|||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// // Make sure we create a RenderTarget with a stencil buffer by specifying it via the context settings
|
/// // 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});
|
||||||
///
|
///
|
||||||
/// ...
|
/// ...
|
||||||
///
|
///
|
||||||
|
@ -48,46 +48,17 @@ struct ContextSettings
|
|||||||
Debug = 1 << 2 //!< Debug attribute
|
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
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
unsigned int depthBits; //!< Bits of the depth buffer
|
unsigned int depthBits{}; //!< Bits of the depth buffer
|
||||||
unsigned int stencilBits; //!< Bits of the stencil buffer
|
unsigned int stencilBits{}; //!< Bits of the stencil buffer
|
||||||
unsigned int antialiasingLevel; //!< Level of antialiasing
|
unsigned int antialiasingLevel{}; //!< Level of antialiasing
|
||||||
unsigned int majorVersion; //!< Major number of the context version to create
|
unsigned int majorVersion{1}; //!< Major number of the context version to create
|
||||||
unsigned int minorVersion; //!< Minor number of the context version to create
|
unsigned int minorVersion{1}; //!< Minor number of the context version to create
|
||||||
std::uint32_t attributeFlags; //!< The attribute flags to create the context with
|
std::uint32_t attributeFlags{Attribute::Default}; //!< The attribute flags to create the context with
|
||||||
bool sRgbCapable; //!< Whether the context framebuffer is sRGB capable
|
bool sRgbCapable{}; //!< Whether the context framebuffer is sRGB capable
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
@ -521,7 +521,7 @@ DRMContext::DRMContext(DRMContext* shared)
|
|||||||
m_display = getInitializedDisplay();
|
m_display = getInitializedDisplay();
|
||||||
|
|
||||||
// Get the best EGL config matching the default video settings
|
// 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();
|
updateSettings();
|
||||||
|
|
||||||
// Create EGL context
|
// Create EGL context
|
||||||
|
@ -206,7 +206,7 @@ struct GlContext::SharedContext
|
|||||||
const std::lock_guard lock(mutex);
|
const std::lock_guard lock(mutex);
|
||||||
|
|
||||||
context.emplace(nullptr);
|
context.emplace(nullptr);
|
||||||
context->initialize(sf::ContextSettings());
|
context->initialize(ContextSettings{});
|
||||||
|
|
||||||
loadExtensions();
|
loadExtensions();
|
||||||
|
|
||||||
@ -572,7 +572,7 @@ std::unique_ptr<GlContext> GlContext::create()
|
|||||||
|
|
||||||
sharedContext->context->setActive(false);
|
sharedContext->context->setActive(false);
|
||||||
|
|
||||||
context->initialize(ContextSettings());
|
context->initialize(ContextSettings{});
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
@ -594,7 +594,12 @@ std::unique_ptr<GlContext> GlContext::create(const ContextSettings& settings, co
|
|||||||
!(sharedContext->context->m_settings.attributeFlags & ContextSettings::Core))
|
!(sharedContext->context->m_settings.attributeFlags & ContextSettings::Core))
|
||||||
{
|
{
|
||||||
// Re-create our shared context as a core context
|
// 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.emplace(nullptr, sharedSettings, Vector2u(1, 1));
|
||||||
sharedContext->context->initialize(sharedSettings);
|
sharedContext->context->initialize(sharedSettings);
|
||||||
@ -638,7 +643,12 @@ std::unique_ptr<GlContext> GlContext::create(const ContextSettings& settings, co
|
|||||||
!(sharedContext->context->m_settings.attributeFlags & ContextSettings::Core))
|
!(sharedContext->context->m_settings.attributeFlags & ContextSettings::Core))
|
||||||
{
|
{
|
||||||
// Re-create our shared context as a core context
|
// 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.emplace(nullptr, sharedSettings, Vector2u(1, 1));
|
||||||
sharedContext->context->initialize(sharedSettings);
|
sharedContext->context->initialize(sharedSettings);
|
||||||
|
@ -110,7 +110,7 @@ namespace sf::priv
|
|||||||
GlxContext::GlxContext(GlxContext* shared)
|
GlxContext::GlxContext(GlxContext* shared)
|
||||||
{
|
{
|
||||||
// Save the creation settings
|
// Save the creation settings
|
||||||
m_settings = ContextSettings();
|
m_settings = ContextSettings{};
|
||||||
|
|
||||||
// Open the connection with the X server
|
// Open the connection with the X server
|
||||||
m_display = openDisplay();
|
m_display = openDisplay();
|
||||||
|
@ -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})
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ Window::~Window()
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void Window::create(VideoMode mode, const String& title, std::uint32_t style, State state)
|
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)
|
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
|
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;
|
return m_context ? m_context->getSettings() : empty;
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,17 @@ void WindowBase::create(VideoMode mode, const String& title, std::uint32_t style
|
|||||||
WindowBase::create(mode, style, state);
|
WindowBase::create(mode, style, state);
|
||||||
|
|
||||||
// Recreate the window implementation
|
// 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
|
// Perform common initializations
|
||||||
initialize();
|
initialize();
|
||||||
|
@ -45,7 +45,9 @@ SFContext::SFContext(SFContext* shared)
|
|||||||
{
|
{
|
||||||
const AutoreleasePool pool;
|
const AutoreleasePool pool;
|
||||||
// Create the context
|
// Create the context
|
||||||
createContext(shared, VideoMode::getDesktopMode().bitsPerPixel, ContextSettings(0, 0, 0));
|
createContext(shared,
|
||||||
|
VideoMode::getDesktopMode().bitsPerPixel,
|
||||||
|
ContextSettings{0 /* depthBits */, 0 /* stencilBits */, 0 /* antialiasingLevel */});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,7 +12,9 @@ TEST_CASE("[Graphics] Render Tests", runDisplayTests())
|
|||||||
{
|
{
|
||||||
SECTION("Stencil Tests")
|
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);
|
renderTexture.clear(sf::Color::Red, 127);
|
||||||
|
|
||||||
sf::RectangleShape shape1({100, 100});
|
sf::RectangleShape shape1({100, 100});
|
||||||
|
@ -20,14 +20,15 @@ TEST_CASE("[Graphics] sf::RenderTexture", runDisplayTests())
|
|||||||
{
|
{
|
||||||
CHECK(!sf::RenderTexture::create({1'000'000, 1'000'000}));
|
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{8 /* depthBits */, 0 /* stencilBits */}));
|
||||||
CHECK(sf::RenderTexture::create({100, 100}, sf::ContextSettings(0, 8)));
|
CHECK(sf::RenderTexture::create({100, 100}, sf::ContextSettings{0 /* depthBits */, 8 /* stencilBits */}));
|
||||||
|
|
||||||
const auto renderTexture = sf::RenderTexture::create({360, 480}).value();
|
const auto renderTexture = sf::RenderTexture::create({360, 480}).value();
|
||||||
CHECK(renderTexture.getSize() == sf::Vector2u(360, 480));
|
CHECK(renderTexture.getSize() == sf::Vector2u(360, 480));
|
||||||
CHECK(!renderTexture.isSmooth());
|
CHECK(!renderTexture.isSmooth());
|
||||||
CHECK(!renderTexture.isRepeated());
|
CHECK(!renderTexture.isRepeated());
|
||||||
CHECK(!renderTexture.isSrgb());
|
CHECK(!renderTexture.isSrgb());
|
||||||
|
|
||||||
const auto& texture = renderTexture.getTexture();
|
const auto& texture = renderTexture.getTexture();
|
||||||
CHECK(texture.getSize() == sf::Vector2u(360, 480));
|
CHECK(texture.getSize() == sf::Vector2u(360, 480));
|
||||||
CHECK(!texture.isSmooth());
|
CHECK(!texture.isSmooth());
|
||||||
|
@ -33,7 +33,7 @@ TEST_CASE("[Graphics] sf::RenderWindow", runDisplayTests())
|
|||||||
"Window Title",
|
"Window Title",
|
||||||
sf::Style::Default,
|
sf::Style::Default,
|
||||||
sf::State::Windowed,
|
sf::State::Windowed,
|
||||||
sf::ContextSettings());
|
sf::ContextSettings{});
|
||||||
CHECK(window.isOpen());
|
CHECK(window.isOpen());
|
||||||
CHECK(window.getSize() == sf::Vector2u(256, 256));
|
CHECK(window.getSize() == sf::Vector2u(256, 256));
|
||||||
CHECK(window.getNativeHandle() != sf::WindowHandle());
|
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),
|
const sf::RenderWindow window(sf::VideoMode(sf::Vector2u(240, 300), 24),
|
||||||
"Window Title",
|
"Window Title",
|
||||||
sf::State::Windowed,
|
sf::State::Windowed,
|
||||||
sf::ContextSettings());
|
sf::ContextSettings{});
|
||||||
CHECK(window.isOpen());
|
CHECK(window.isOpen());
|
||||||
CHECK(window.getSize() == sf::Vector2u(240, 300));
|
CHECK(window.getSize() == sf::Vector2u(240, 300));
|
||||||
CHECK(window.getNativeHandle() != sf::WindowHandle());
|
CHECK(window.getNativeHandle() != sf::WindowHandle());
|
||||||
@ -72,7 +72,7 @@ TEST_CASE("[Graphics] sf::RenderWindow", runDisplayTests())
|
|||||||
"Window Title",
|
"Window Title",
|
||||||
sf::Style::Default,
|
sf::Style::Default,
|
||||||
sf::State::Windowed,
|
sf::State::Windowed,
|
||||||
sf::ContextSettings());
|
sf::ContextSettings{});
|
||||||
REQUIRE(window.getSize() == sf::Vector2u(256, 256));
|
REQUIRE(window.getSize() == sf::Vector2u(256, 256));
|
||||||
|
|
||||||
sf::Texture texture;
|
sf::Texture texture;
|
||||||
|
@ -16,7 +16,7 @@ TEST_CASE("[Window] sf::ContextSettings")
|
|||||||
|
|
||||||
SECTION("Construction")
|
SECTION("Construction")
|
||||||
{
|
{
|
||||||
SECTION("Default constructor")
|
SECTION("Aggregate initialization -- Nothing")
|
||||||
{
|
{
|
||||||
constexpr sf::ContextSettings contextSettings;
|
constexpr sf::ContextSettings contextSettings;
|
||||||
STATIC_CHECK(contextSettings.depthBits == 0);
|
STATIC_CHECK(contextSettings.depthBits == 0);
|
||||||
@ -28,9 +28,9 @@ TEST_CASE("[Window] sf::ContextSettings")
|
|||||||
STATIC_CHECK(contextSettings.sRgbCapable == false);
|
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.depthBits == 1);
|
||||||
STATIC_CHECK(contextSettings.stencilBits == 1);
|
STATIC_CHECK(contextSettings.stencilBits == 1);
|
||||||
STATIC_CHECK(contextSettings.antialiasingLevel == 2);
|
STATIC_CHECK(contextSettings.antialiasingLevel == 2);
|
||||||
|
@ -72,7 +72,7 @@ TEST_CASE("[Window] sf::Window", runDisplayTests())
|
|||||||
"Window Tests",
|
"Window Tests",
|
||||||
sf::Style::Resize,
|
sf::Style::Resize,
|
||||||
sf::State::Windowed,
|
sf::State::Windowed,
|
||||||
sf::ContextSettings(1, 1, 1));
|
sf::ContextSettings{/* depthBits*/ 1, /* stencilBits */ 1, /* antialiasingLevel */ 1});
|
||||||
CHECK(window.isOpen());
|
CHECK(window.isOpen());
|
||||||
CHECK(window.getSize() == sf::Vector2u(360, 240));
|
CHECK(window.getSize() == sf::Vector2u(360, 240));
|
||||||
CHECK(window.getNativeHandle() != sf::WindowHandle());
|
CHECK(window.getNativeHandle() != sf::WindowHandle());
|
||||||
@ -95,7 +95,7 @@ TEST_CASE("[Window] sf::Window", runDisplayTests())
|
|||||||
const sf::Window window(sf::VideoMode({360, 240}),
|
const sf::Window window(sf::VideoMode({360, 240}),
|
||||||
"Window Tests",
|
"Window Tests",
|
||||||
sf::State::Windowed,
|
sf::State::Windowed,
|
||||||
sf::ContextSettings(1, 1, 1));
|
sf::ContextSettings{/* depthBits*/ 1, /* stencilBits */ 1, /* antialiasingLevel */ 1});
|
||||||
CHECK(window.isOpen());
|
CHECK(window.isOpen());
|
||||||
CHECK(window.getSize() == sf::Vector2u(360, 240));
|
CHECK(window.getSize() == sf::Vector2u(360, 240));
|
||||||
CHECK(window.getNativeHandle() != sf::WindowHandle());
|
CHECK(window.getNativeHandle() != sf::WindowHandle());
|
||||||
@ -133,7 +133,7 @@ TEST_CASE("[Window] sf::Window", runDisplayTests())
|
|||||||
"Window Tests",
|
"Window Tests",
|
||||||
sf::Style::Resize,
|
sf::Style::Resize,
|
||||||
sf::State::Windowed,
|
sf::State::Windowed,
|
||||||
sf::ContextSettings(1, 1, 1));
|
sf::ContextSettings{/* depthBits*/ 1, /* stencilBits */ 1, /* antialiasingLevel */ 1});
|
||||||
CHECK(window.isOpen());
|
CHECK(window.isOpen());
|
||||||
CHECK(window.getSize() == sf::Vector2u(240, 360));
|
CHECK(window.getSize() == sf::Vector2u(240, 360));
|
||||||
CHECK(window.getNativeHandle() != sf::WindowHandle());
|
CHECK(window.getNativeHandle() != sf::WindowHandle());
|
||||||
|
Loading…
Reference in New Issue
Block a user