Skip to content

Commit 40ea0ff

Browse files
committed
Split out window into its own module
1 parent ee6effd commit 40ea0ff

File tree

12 files changed

+64
-18
lines changed

12 files changed

+64
-18
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export examplesDir := $(abspath examples)
4242

4343
# Set top level targets
4444
export utilsLib := $(libDir)/libutils.a
45+
export windowLib := $(libDir)/libwindow.a
4546
export coreLib := $(libDir)/libcore.a
4647
export renderLib := $(libDir)/librender.a
4748
export testApp := $(binDir)/tests/build/app
@@ -60,10 +61,13 @@ all: testapp package-gameapp package-renderapp
6061
$(utilsLib): buildFlags
6162
"$(MAKE)" -C $(engineDir)/utils CXXFLAGS="$(CXXFLAGS)"
6263

64+
$(windowLib): buildFlags $(utilsLib)
65+
"$(MAKE)" -C $(engineDir)/window CXXFLAGS="$(CXXFLAGS)"
66+
6367
$(coreLib): buildFlags $(utilsLib)
6468
"$(MAKE)" -C $(engineDir)/core CXXFLAGS="$(CXXFLAGS)"
6569

66-
$(renderLib): buildFlags $(utilsLib)
70+
$(renderLib): buildFlags $(utilsLib) $(windowLib)
6771
"$(MAKE)" -C $(engineDir)/render CXXFLAGS="$(CXXFLAGS)"
6872

6973
$(testApp): buildFlags $(utilsLib) $(coreLib)

engine/render/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ renderSources := $(call rwildcard,$(renderSrcDir)/,*.cpp)
1414
renderObjects := $(call findobjs,$(renderSrcDir),$(renderBinDir),$(renderSources))
1515
renderDepends := $(patsubst %.o, %.d, $(call rwildcard,$(renderBinDir)/,*.o))
1616
renderBuildDir := $(renderBinDir)/build
17-
renderLibs := $(vendorDir)/glfw/build/src/libglfw3.a $(vendorDir)/zlib/build/lib/libz.a \
18-
$(vendorDir)/libpng/build/libpng.a $(vendorDir)/freetype/build/libfreetype.a
17+
renderLibs := $(vendorDir)/zlib/build/lib/libz.a $(vendorDir)/libpng/build/libpng.a \
18+
$(vendorDir)/freetype/build/libfreetype.a
1919

2020
# Set shader build vars
2121
vertSources := $(call rwildcard,assets/shaders,*.vert)
2222
fragSources := $(call rwildcard,assets/shaders,*.frag)
2323
vertObjects := $(patsubst %.vert,$(renderBuildDir)/%.vert.spv,$(vertSources))
2424
fragObjects := $(patsubst %.frag,$(renderBuildDir)/%.frag.spv,$(fragSources))
2525

26-
linkFlags += -l utils
26+
linkFlags += -l utils -l window
2727

2828
compileFlags += -I $(vendorDir)/vulkan/include -I $(vendorDir)/glfw/include -I $(vendorDir)/glm \
2929
-I $(vendorDir)/tinyobjloader -I $(vendorDir)/stb_image -I $(vendorDir)/zlib/build/include \

engine/render/renderer/Renderer.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
#include "platform/vulkan/utils/Types.h"
1515
#include "statics/Statics.h"
1616

17+
// TODO look into why including via GLFW header + volk isn't defining this - JDM
18+
extern "C"
19+
{
20+
GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance,
21+
GLFWwindow* window,
22+
const VkAllocationCallbacks* allocator,
23+
VkSurfaceKHR* surface);
24+
}
25+
1726
namespace Siege
1827
{
1928
Renderer* Renderer::instance {nullptr};
@@ -27,13 +36,12 @@ Renderer::Renderer(Window& window) : window {window}
2736
if (instance == nullptr) instance = this;
2837

2938
auto createWindowSurface = [&window](VkInstance instance, VkSurfaceKHR* surface) -> bool {
30-
return glfwCreateWindowSurface(instance, window.GetGlfwWindow(), nullptr, surface) == VK_SUCCESS;
39+
return glfwCreateWindowSurface(instance, window.GetGlfwWindow(), nullptr, surface) ==
40+
VK_SUCCESS;
3141
};
3242

3343
auto extent = window.GetExtents();
34-
context.Init({extent.width, extent.height},
35-
Window::GetRequiredExtensions,
36-
createWindowSurface);
44+
context.Init({extent.width, extent.height}, Window::GetRequiredExtensions, createWindowSurface);
3745

3846
DescriptorPool::AddPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1024);
3947
DescriptorPool::AddPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1024);

engine/render/renderer/Renderer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
#define SIEGE_ENGINE_RENDERER_H
1111

1212
#include <utils/Logging.h>
13+
#include <window/Window.h>
1314

1415
#include "descriptor/DescriptorPool.h"
1516
#include "lights/PointLight.h"
1617
#include "model/Model.h"
1718
#include "render/renderer/platform/vulkan/CommandBuffer.h"
1819
#include "render/renderer/platform/vulkan/Context.h"
19-
#include "render/window/Window.h"
2020
#include "renderer/Renderer2D.h"
2121
#include "renderer/Renderer3D.h"
2222

File renamed without changes.

engine/render/input/Input.h renamed to engine/window/Input.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include <map>
1313

14-
#include "../window/Window.h"
14+
#include "Window.h"
1515

1616
#define KEY_W GLFW_KEY_W
1717
#define KEY_A GLFW_KEY_A

engine/window/Makefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright (c) 2022 Jonathan Moallem (@J-Mo63) & Aryeh Zinn (@Raelr)
2+
#
3+
# This code is released under an unmodified zlib license.
4+
# For conditions of distribution and use, please see:
5+
# https://opensource.org/licenses/Zlib
6+
7+
include $(makeDir)/Functions.mk
8+
include $(makeDir)/Platform.mk
9+
10+
# Set source build vars
11+
windowSrcDir := .
12+
windowBinDir := $(binDir)/engine/window
13+
windowSources := $(call rwildcard,$(windowSrcDir)/,*.cpp)
14+
windowObjects := $(call findobjs,$(windowSrcDir),$(windowBinDir),$(windowSources))
15+
windowDepends := $(patsubst %.o, %.d, $(call rwildcard,$(windowBinDir)/,*.o))
16+
windowLibs := $(vendorDir)/glfw/build/src/libglfw3.a
17+
18+
linkFlags += -l utils
19+
compileFlags += -I $(vendorDir)/glfw/include
20+
21+
# Build the static library
22+
$(windowLib): $(windowObjects)
23+
$(RM) $(call platformpth, $(windowLib))
24+
$(call COMBINE_LIBS, $(windowLibs), $(windowObjects), $(libDir), window)
25+
26+
# Add all rules from dependency files
27+
-include $(windowDepends)
28+
29+
# Compile object files to the bin directory
30+
$(windowBinDir)/%.o: $(windowSrcDir)/%.cpp
31+
$(MKDIR) $(call platformpth, $(@D))
32+
$(CXX) -MMD -MP -c $(compileFlags) -I $(engineDir) $< -o $@ $(CXXFLAGS)
File renamed without changes.

engine/render/window/Window.h renamed to engine/window/Window.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99
#ifndef SIEGE_ENGINE_RENDERER_WINDOW_H
1010
#define SIEGE_ENGINE_RENDERER_WINDOW_H
1111

12-
#include <cstdint>
13-
1412
#include <GLFW/glfw3.h>
1513
#include <utils/collections/HeapArray.h>
1614

15+
#include <cstdint>
16+
1717
namespace Siege
1818
{
1919

20-
2120
struct WindowExtents
2221
{
2322
uint32_t width {0};
@@ -41,7 +40,10 @@ class Window
4140
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
4241
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
4342

44-
if (!window) window = glfwCreateWindow(extents.width, extents.height, name, nullptr, nullptr);
43+
if (!window)
44+
{
45+
window = glfwCreateWindow(extents.width, extents.height, name, nullptr, nullptr);
46+
}
4547

4648
if (glfwRawMouseMotionSupported())
4749
{

examples/render/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ packagingFlags = $(ENV_VARS) --excludes "$(packagingExcludes)"
4141
# Set build vars
4242
compileFlags += -I $(vendorDir)/vulkan/include -I $(vendorDir)/glfw/include -I $(vendorDir)/glm \
4343
-I $(vendorDir)/tinyobjloader -I $(vendorDir)/freetype/include
44-
linkFlags += -l render -l utils
44+
linkFlags += -l render -l window -l utils
4545

4646
.PHONY: all render-assets
4747

0 commit comments

Comments
 (0)