diff --git a/include/RaZ/Render/RenderSystem.hpp b/include/RaZ/Render/RenderSystem.hpp index 0d421bfc..74ef9edb 100644 --- a/include/RaZ/Render/RenderSystem.hpp +++ b/include/RaZ/Render/RenderSystem.hpp @@ -28,16 +28,20 @@ class RenderSystem final : public System { RenderSystem(unsigned int sceneWidth, unsigned int sceneHeight) : RenderSystem() { resizeViewport(sceneWidth, sceneHeight); } #if !defined(RAZ_NO_WINDOW) /// Creates a render system along with a window. - /// \param sceneWidth Width of the scene. - /// \param sceneHeight Height of the scene. + /// \param windowWidth Width of the window. + /// \param windowHeight Height of the window. /// \param windowTitle Title of the window. /// \param settings Settings to create the window with. /// \param antiAliasingSampleCount Number of anti-aliasing samples. - RenderSystem(unsigned int sceneWidth, unsigned int sceneHeight, + /// \note The window's width & height are to be considered just hints; the window manager remains responsible for the actual dimensions, which may be lower. + /// This can notably happen when the requested window size exceeds what the screens can display. The actual window's size can be queried afterward. + /// \see getWindow(), Window::getWidth(), Window::getHeight() + RenderSystem(unsigned int windowWidth, unsigned int windowHeight, const std::string& windowTitle, - WindowSetting settings = WindowSetting::DEFAULT, + WindowSetting windowSettings = WindowSetting::DEFAULT, uint8_t antiAliasingSampleCount = 1) - : m_window{ Window::create(*this, sceneWidth, sceneHeight, windowTitle, settings, antiAliasingSampleCount) } { initialize(sceneWidth, sceneHeight); } + : m_window{ Window::create(*this, windowWidth, windowHeight, windowTitle, windowSettings, antiAliasingSampleCount) } { initialize(m_window->getWidth(), + m_window->getHeight()); } #endif #if !defined(RAZ_NO_WINDOW) diff --git a/include/RaZ/Render/Window.hpp b/include/RaZ/Render/Window.hpp index 95c83cbc..1a730f8d 100644 --- a/include/RaZ/Render/Window.hpp +++ b/include/RaZ/Render/Window.hpp @@ -61,6 +61,9 @@ class Window { /// \param title Title of the window. /// \param settings Settings to create the window with. /// \param antiAliasingSampleCount Number of anti-aliasing samples. + /// \note The width & height are to be considered just hints; the window manager remains responsible for the actual dimensions, which may be lower. + /// This can notably happen when the requested window size exceeds what the screens can display. The actual window's size can be queried afterward. + /// \see getWidth(), getHeight() Window(RenderSystem& renderSystem, unsigned int width, unsigned int height, const std::string& title = {}, @@ -88,6 +91,9 @@ class Window { /// Resizes the window. /// \param width New window width. /// \param height New window height. + /// \note The width & height are to be considered just hints; the window manager remains responsible for the actual dimensions, which may be lower. + /// This can notably happen when the requested window size exceeds what the screens can display. The actual window's size can be queried afterward. + /// \see getWidth(), getHeight() void resize(unsigned int width, unsigned int height); /// Sets the window in a fullscreen mode, taking the whole main monitor's screen. /// \note To quit fullscreen, call makeWindowed(). diff --git a/src/RaZ/Render/RenderGraph.cpp b/src/RaZ/Render/RenderGraph.cpp index 492b407d..cd5ccb38 100644 --- a/src/RaZ/Render/RenderGraph.cpp +++ b/src/RaZ/Render/RenderGraph.cpp @@ -36,9 +36,6 @@ void RenderGraph::updateShaders() const { } void RenderGraph::execute(RenderSystem& renderSystem) { - assert("Error: The render system needs a camera for the render graph to be executed." && (renderSystem.m_cameraEntity != nullptr)); - assert("Error: The camera referenced by the render system needs a transform component." && renderSystem.m_cameraEntity->hasComponent()); - ZoneScopedN("RenderGraph::execute"); { diff --git a/src/RaZ/Render/RenderSystem.cpp b/src/RaZ/Render/RenderSystem.cpp index 8ebdbf0f..acbfecd7 100644 --- a/src/RaZ/Render/RenderSystem.cpp +++ b/src/RaZ/Render/RenderSystem.cpp @@ -244,7 +244,8 @@ void RenderSystem::updateLight(const Entity& entity, unsigned int lightIndex) co } void RenderSystem::sendCameraInfo() const { - assert("Error: A camera must be given to a RenderSystem to send its info." && (m_cameraEntity != nullptr)); + assert("Error: The render system needs a camera to send its info." && (m_cameraEntity != nullptr)); + assert("Error: The camera must have a transform component to send its info." && m_cameraEntity->hasComponent()); ZoneScopedN("RenderSystem::sendCameraInfo"); diff --git a/src/RaZ/Render/Window.cpp b/src/RaZ/Render/Window.cpp index 65fd71e4..70504397 100644 --- a/src/RaZ/Render/Window.cpp +++ b/src/RaZ/Render/Window.cpp @@ -32,7 +32,7 @@ Window::Window(RenderSystem& renderSystem, unsigned int width, unsigned int height, const std::string& title, WindowSetting settings, - uint8_t antiAliasingSampleCount) : m_renderSystem{ &renderSystem }, m_width{ static_cast(width) }, m_height{ static_cast(height) } { + uint8_t antiAliasingSampleCount) : m_renderSystem{ &renderSystem } { ZoneScopedN("Window::Window"); Logger::debug("[Window] Initializing..."); @@ -90,7 +90,7 @@ Window::Window(RenderSystem& renderSystem, glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, major); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minor); - m_windowHandle = glfwCreateWindow(m_width, m_height, title.c_str(), nullptr, glfwGetCurrentContext()); + m_windowHandle = glfwCreateWindow(static_cast(width), static_cast(height), title.c_str(), nullptr, glfwGetCurrentContext()); if (m_windowHandle) break; @@ -104,10 +104,11 @@ Window::Window(RenderSystem& renderSystem, throw std::runtime_error("Error: Failed to create GLFW Window"); } #else - m_windowHandle = glfwCreateWindow(m_width, m_height, title.c_str(), nullptr, glfwGetCurrentContext()); + m_windowHandle = glfwCreateWindow(static_cast(width), static_cast(height), title.c_str(), nullptr, glfwGetCurrentContext()); #endif glfwSetWindowUserPointer(m_windowHandle, this); + glfwGetWindowSize(m_windowHandle, &m_width, &m_height); glfwGetWindowPos(m_windowHandle, &m_posX, &m_posY); if (glfwGetCurrentContext() == nullptr) @@ -161,10 +162,8 @@ void Window::setIcon(const Image& img) const { } void Window::resize(unsigned int width, unsigned int height) { - m_width = static_cast(width); - m_height = static_cast(height); - glfwSetWindowSize(m_windowHandle, static_cast(width), static_cast(height)); + glfwGetWindowSize(m_windowHandle, &m_width, &m_height); } void Window::makeFullscreen() { @@ -198,7 +197,7 @@ bool Window::recoverVerticalSyncState() const { return true; #elif defined(RAZ_PLATFORM_LINUX) if (glXQueryExtensionsString(glXGetCurrentDisplay(), 0)) { - unsigned int interval; + unsigned int interval {}; glXQueryDrawable(glXGetCurrentDisplay(), glXGetCurrentDrawable(), GLX_SWAP_INTERVAL_EXT, &interval); return static_cast(interval);