Skip to content

Commit 577dbb1

Browse files
committed
Replaced Vulkan extents for window
1 parent 9e63f60 commit 577dbb1

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

engine/render/renderer/Renderer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Renderer::Renderer(Window& window) : window {window}
2626

2727
if (instance == nullptr) instance = this;
2828

29-
auto extent = window.GetExtent();
29+
auto extent = window.GetExtents();
3030

3131
context.Init({extent.width, extent.height},
3232
Window::GetRequiredExtensions,
@@ -63,11 +63,11 @@ void Renderer::DrawFrame()
6363
void Renderer::RecreateSwapChain()
6464
{
6565
ClearDeviceQueue();
66-
auto extent = window.GetExtent();
66+
auto extent = window.GetExtents();
6767

6868
while (!window.IsVisible() || extent.width == 0.0 || extent.height == 0.0)
6969
{
70-
extent = window.GetExtent();
70+
extent = window.GetExtents();
7171
window.WaitEvents();
7272
}
7373

engine/render/window/Window.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ MHArray<const char*> Window::GetRequiredExtensions()
4040
void Window::ResizeCallback(GLFWwindow* windowPtr, int width, int height)
4141
{
4242
auto windowContext = reinterpret_cast<Window*>(glfwGetWindowUserPointer(windowPtr));
43-
4443
windowContext->wasResized = true;
45-
46-
windowContext->width = width;
47-
windowContext->height = height;
44+
windowContext->extents = {static_cast<uint32_t>(width), static_cast<uint32_t>(height)};
4845
}
4946
} // namespace Siege

engine/render/window/Window.h

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,26 @@
1313

1414
#include <cstdint>
1515

16-
// Include Vulkan headers through GLFW
1716
#include <GLFW/glfw3.h>
1817
#include <utils/collections/HeapArray.h>
1918

2019
namespace Siege
2120
{
21+
22+
23+
struct WindowExtents
24+
{
25+
uint32_t width {0};
26+
uint32_t height {0};
27+
};
28+
2229
class Window
2330
{
2431
public:
2532

2633
// 'Structors
2734

28-
Window(char const* name, int width, int height) : width(width), height(height)
35+
Window(char const* name, WindowExtents extents) : extents(extents)
2936
{
3037
if (!glfwInitialised)
3138
{
@@ -36,7 +43,7 @@ class Window
3643
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
3744
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
3845

39-
if (!window) window = glfwCreateWindow(width, height, name, nullptr, nullptr);
46+
if (!window) window = glfwCreateWindow(extents.width, extents.height, name, nullptr, nullptr);
4047

4148
if (glfwRawMouseMotionSupported())
4249
{
@@ -55,7 +62,7 @@ class Window
5562
glfwGetMonitorContentScale(glfwGetPrimaryMonitor(), &DPI.width, &DPI.height);
5663
}
5764

58-
Window() : Window("Window", 800, 600) {}
65+
Window() : Window("Window", {800, 600}) {}
5966

6067
~Window()
6168
{
@@ -67,12 +74,12 @@ class Window
6774

6875
const int GetHeight() const
6976
{
70-
return height;
77+
return extents.height;
7178
}
7279

7380
const int GetWidth() const
7481
{
75-
return width;
82+
return extents.width;
7683
}
7784

7885
const bool IsVisible() const
@@ -89,17 +96,17 @@ class Window
8996

9097
const uint32_t GetScaledWidth() const
9198
{
92-
return width * DPI.width;
99+
return extents.width * DPI.width;
93100
}
94101

95102
const uint32_t GetScaledHeight() const
96103
{
97-
return height * DPI.height;
104+
return extents.height * DPI.height;
98105
}
99106

100-
VkExtent2D GetExtent() const
107+
WindowExtents GetExtents() const
101108
{
102-
return {static_cast<uint32_t>(width), static_cast<uint32_t>(height)};
109+
return extents;
103110
}
104111

105112
GLFWwindow* GetGlfwWindow()
@@ -166,8 +173,7 @@ class Window
166173

167174
static GLFWwindow* window;
168175

169-
int width;
170-
int height;
176+
WindowExtents extents;
171177

172178
MonitorPixelScale DPI {};
173179
bool wasResized {false};

examples/render/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ int main()
4040
{
4141
WINDOWS_ATTACH_CONSOLE
4242

43-
Siege::Window window("Render Example", WIDTH, HEIGHT);
43+
Siege::Window window("Render Example", {WIDTH, HEIGHT});
4444

4545
window.DisableCursor();
4646

0 commit comments

Comments
 (0)