Compare commits
13 commits
7ff3b41c04
...
cb6b84e639
Author | SHA1 | Date | |
---|---|---|---|
cb6b84e639 | |||
e186a17be6 | |||
518fe7f51c | |||
e3da25eaab | |||
2b044f002a | |||
551997fadc | |||
d4c773aa05 | |||
bdad516740 | |||
6a7e8b6807 | |||
802055f6d0 | |||
6285945eec | |||
f121cc7318 | |||
ede3e9d82e |
10 changed files with 24 additions and 298 deletions
|
@ -12,11 +12,9 @@ class LightRecipe(ConanFile):
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
"enable_static_analysis": [True, False],
|
"enable_static_analysis": [True, False],
|
||||||
"export_compile_commands": [True, False],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default_options = {
|
default_options = {
|
||||||
"export_compile_commands": True,
|
|
||||||
"enable_static_analysis": False,
|
"enable_static_analysis": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +39,7 @@ class LightRecipe(ConanFile):
|
||||||
|
|
||||||
tc.variables["CMAKE_BUILD_TYPE"] = self.settings.build_type
|
tc.variables["CMAKE_BUILD_TYPE"] = self.settings.build_type
|
||||||
|
|
||||||
tc.cache_variables["CMAKE_EXPORT_COMPILE_COMMANDS"] = self.options.export_compile_commands
|
tc.cache_variables["CMAKE_EXPORT_COMPILE_COMMANDS"] = True
|
||||||
tc.cache_variables["ENABLE_STATIC_ANALYSIS"] = self.options.enable_static_analysis
|
tc.cache_variables["ENABLE_STATIC_ANALYSIS"] = self.options.enable_static_analysis
|
||||||
|
|
||||||
repo = git.Repo(search_parent_directories=True)
|
repo = git.Repo(search_parent_directories=True)
|
||||||
|
|
|
@ -55,12 +55,10 @@ enum class Platform : uint8_t
|
||||||
namespace constants {
|
namespace constants {
|
||||||
|
|
||||||
#if defined(LIGHT_PLATFORM_WINDOWS)
|
#if defined(LIGHT_PLATFORM_WINDOWS)
|
||||||
#define lt_win(x)
|
#define lt_win(x) x
|
||||||
constexpr auto platform = Platform::windows;
|
constexpr auto platform = Platform::windows;
|
||||||
constexpr auto platform_name = "windows";
|
constexpr auto platform_name = "windows";
|
||||||
|
|
||||||
#undef LIGHT_PLATFORM_WINDOWS
|
|
||||||
|
|
||||||
#elif defined(LIGHT_PLATFORM_LINUX)
|
#elif defined(LIGHT_PLATFORM_LINUX)
|
||||||
#define lt_lin(x) x
|
#define lt_lin(x) x
|
||||||
constexpr auto platform = Platform::gnu;
|
constexpr auto platform = Platform::gnu;
|
||||||
|
@ -79,6 +77,18 @@ constexpr auto platform_name = "mac";
|
||||||
|
|
||||||
} // namespace constants
|
} // namespace constants
|
||||||
|
|
||||||
|
template<typename T = void>
|
||||||
|
concept is_linux = true;
|
||||||
|
|
||||||
|
auto linux_only(auto value)
|
||||||
|
requires is_linux<void>
|
||||||
|
{
|
||||||
|
if constexpr (is_linux)
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* bit-wise */
|
/* bit-wise */
|
||||||
constexpr auto bit(auto x)
|
constexpr auto bit(auto x)
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <span>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
|
@ -33,8 +33,8 @@ void Scene::on_update(float deltaTime)
|
||||||
|
|
||||||
void Scene::on_render(const Ref<Framebuffer> &targetFrameBuffer /* = nullptr */)
|
void Scene::on_render(const Ref<Framebuffer> &targetFrameBuffer /* = nullptr */)
|
||||||
{
|
{
|
||||||
auto *sceneCamera = (Camera *)nullptr;
|
auto *sceneCamera = (Camera *) {};
|
||||||
auto *sceneCameraTransform = (TransformComponent *)nullptr;
|
auto *sceneCameraTransform = (TransformComponent *) {};
|
||||||
|
|
||||||
/* scene camera */
|
/* scene camera */
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,22 +29,22 @@ public:
|
||||||
return m_render_target_view;
|
return m_render_target_view;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto GetDeviceRef() -> Microsoft::WRL::ComPtr<ID3D11Device>
|
[[nodiscard]] auto &GetDeviceRef() -> Microsoft::WRL::ComPtr<ID3D11Device>
|
||||||
{
|
{
|
||||||
return m_device;
|
return m_device;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto GetDeviceContextRef() -> Microsoft::WRL::ComPtr<ID3D11DeviceContext>
|
[[nodiscard]] auto &GetDeviceContextRef() -> Microsoft::WRL::ComPtr<ID3D11DeviceContext>
|
||||||
{
|
{
|
||||||
return m_deviceContext;
|
return m_deviceContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto GetSwapChainRef() -> Microsoft::WRL::ComPtr<IDXGISwapChain>
|
[[nodiscard]] auto &GetSwapChainRef() -> Microsoft::WRL::ComPtr<IDXGISwapChain>
|
||||||
{
|
{
|
||||||
return m_swap_chain;
|
return m_swap_chain;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto GetRenderTargetViewRef() -> Microsoft::WRL::ComPtr<ID3D11RenderTargetView>
|
[[nodiscard]] auto &GetRenderTargetViewRef() -> Microsoft::WRL::ComPtr<ID3D11RenderTargetView>
|
||||||
{
|
{
|
||||||
return m_render_target_view;
|
return m_render_target_view;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <renderer/programs/renderer_program.hpp>
|
#include <renderer/programs/renderer_program.hpp>
|
||||||
#include <span>
|
|
||||||
|
|
||||||
namespace lt {
|
namespace lt {
|
||||||
|
|
||||||
|
|
|
@ -23,13 +23,13 @@ glShader::glShader(
|
||||||
pixel_asset->unpack_blob(pixel_blob_metadata.tag, pixel_blob.data(), pixel_blob.size());
|
pixel_asset->unpack_blob(pixel_blob_metadata.tag, pixel_blob.data(), pixel_blob.size());
|
||||||
|
|
||||||
auto vertex_source = std::string {
|
auto vertex_source = std::string {
|
||||||
reinterpret_cast<char *>(vertex_blob.data()),
|
vertex_blob.data(),
|
||||||
reinterpret_cast<char *>(vertex_blob.data()) + vertex_blob.size(), // NOLINT
|
vertex_blob.data() + vertex_blob.size(), // NOLINT
|
||||||
};
|
};
|
||||||
|
|
||||||
auto pixel_source = std::string {
|
auto pixel_source = std::string {
|
||||||
reinterpret_cast<char *>(pixel_blob.data()),
|
pixel_blob.data(),
|
||||||
reinterpret_cast<char *>(pixel_blob.data()) + pixel_blob.size(), // NOLINT
|
pixel_blob.data() + pixel_blob.size(), // NOLINT
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto vertex_shader = compile_shader(vertex_source, Shader::Stage::vertex);
|
const auto vertex_shader = compile_shader(vertex_source, Shader::Stage::vertex);
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#include <renderer/renderer.hpp>
|
#include <renderer/renderer.hpp>
|
||||||
#include <renderer/shader.hpp>
|
#include <renderer/shader.hpp>
|
||||||
#include <renderer/texture.hpp>
|
#include <renderer/texture.hpp>
|
||||||
#include <span>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace lt {
|
namespace lt {
|
||||||
|
|
|
@ -1,51 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <window/window.hpp>
|
|
||||||
|
|
||||||
struct GLFWwindow;
|
|
||||||
|
|
||||||
namespace lt {
|
|
||||||
|
|
||||||
class Event;
|
|
||||||
class WindowResizedEvent;
|
|
||||||
|
|
||||||
class wWindow: public Window
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
wWindow(std::function<void(Event &)> callback);
|
|
||||||
|
|
||||||
~wWindow() override;
|
|
||||||
|
|
||||||
void poll_events() override;
|
|
||||||
|
|
||||||
void on_event(const Event &event) override;
|
|
||||||
|
|
||||||
void set_properties(
|
|
||||||
const WindowProperties &properties,
|
|
||||||
bool overrideVisibility = false
|
|
||||||
) override;
|
|
||||||
|
|
||||||
void set_title(const std::string &title) override;
|
|
||||||
|
|
||||||
void set_size(const glm::uvec2 &size, bool additive = false) override;
|
|
||||||
|
|
||||||
void set_v_sync(bool vsync, bool toggle = false) override;
|
|
||||||
|
|
||||||
void set_visibility(bool visible, bool toggle = false) override;
|
|
||||||
|
|
||||||
[[nodiscard]] auto get_handle() -> void * override
|
|
||||||
{
|
|
||||||
return m_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
GLFWwindow *m_handle { nullptr };
|
|
||||||
|
|
||||||
std::function<void(Event &)> m_event_callback;
|
|
||||||
|
|
||||||
void on_window_resize(const WindowResizedEvent &event);
|
|
||||||
|
|
||||||
void bind_glfw_events();
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace lt
|
|
|
@ -1,228 +0,0 @@
|
||||||
#include <GLFW/glfw3.h>
|
|
||||||
#include <input/events/char.hpp>
|
|
||||||
#include <input/events/event.hpp>
|
|
||||||
#include <input/events/keyboard.hpp>
|
|
||||||
#include <input/events/mouse.hpp>
|
|
||||||
#include <input/events/window.hpp>
|
|
||||||
#include <window/windows/window.hpp>
|
|
||||||
|
|
||||||
namespace lt {
|
|
||||||
|
|
||||||
Window::~Window()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
auto Window::create(const std::function<void(Event &)> &callback) -> Scope<Window>
|
|
||||||
{
|
|
||||||
return create_scope<wWindow>(callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
wWindow::wWindow(std::function<void(Event &)> callback)
|
|
||||||
: m_event_callback(std::move(std::move(callback)))
|
|
||||||
{
|
|
||||||
// init glfw
|
|
||||||
ensure(glfwInit(), "wWindow::wWindow: failed to initialize 'glfw'");
|
|
||||||
|
|
||||||
// create window
|
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
|
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
||||||
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
|
|
||||||
|
|
||||||
m_handle = glfwCreateWindow(1u, 1u, "", nullptr, nullptr);
|
|
||||||
ensure(m_handle, "wWindow::wWindow: failed to create 'GLFWwindow'");
|
|
||||||
|
|
||||||
glfwSetWindowUserPointer(m_handle, &m_event_callback);
|
|
||||||
bind_glfw_events();
|
|
||||||
}
|
|
||||||
|
|
||||||
wWindow::~wWindow()
|
|
||||||
{
|
|
||||||
glfwDestroyWindow(m_handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
void wWindow::poll_events()
|
|
||||||
{
|
|
||||||
glfwPollEvents();
|
|
||||||
}
|
|
||||||
|
|
||||||
void wWindow::on_event(const Event &event)
|
|
||||||
{
|
|
||||||
switch (event.get_event_type())
|
|
||||||
{
|
|
||||||
/* closed */
|
|
||||||
case EventType::WindowClosed: b_Closed = true; break;
|
|
||||||
|
|
||||||
/* resized */
|
|
||||||
case EventType::WindowResized:
|
|
||||||
on_window_resize(dynamic_cast<const WindowResizedEvent &>(event));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void wWindow::on_window_resize(const WindowResizedEvent &event)
|
|
||||||
{
|
|
||||||
m_properties.size = event.get_size();
|
|
||||||
}
|
|
||||||
|
|
||||||
void wWindow::
|
|
||||||
set_properties(const WindowProperties &properties, bool overrideVisibility /* = false */)
|
|
||||||
{
|
|
||||||
// save the visibility status and re-assign if 'overrideVisibility' is false
|
|
||||||
auto visible = overrideVisibility ? properties.visible : m_properties.visible;
|
|
||||||
m_properties = properties;
|
|
||||||
m_properties.visible = visible;
|
|
||||||
|
|
||||||
// set properties
|
|
||||||
set_title(properties.title);
|
|
||||||
set_size(properties.size);
|
|
||||||
set_v_sync(properties.vsync);
|
|
||||||
set_visibility(visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
void wWindow::set_title(const std::string &title)
|
|
||||||
{
|
|
||||||
m_properties.title = title;
|
|
||||||
|
|
||||||
glfwSetWindowTitle(m_handle, title.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void wWindow::set_size(const glm::uvec2 &size, bool additive /* = false */)
|
|
||||||
{
|
|
||||||
m_properties.size.x = size.x == 0u ? m_properties.size.x :
|
|
||||||
additive ? m_properties.size.x + size.x :
|
|
||||||
size.x;
|
|
||||||
m_properties.size.y = size.y == 0u ? m_properties.size.y :
|
|
||||||
additive ? m_properties.size.y + size.y :
|
|
||||||
size.y;
|
|
||||||
|
|
||||||
|
|
||||||
glfwSetWindowSize(m_handle, size.x, size.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void wWindow::set_v_sync(bool vsync, bool toggle /* = false */)
|
|
||||||
{
|
|
||||||
m_properties.vsync = toggle ? !m_properties.vsync : vsync;
|
|
||||||
|
|
||||||
glfwSwapInterval(m_properties.vsync);
|
|
||||||
}
|
|
||||||
|
|
||||||
void wWindow::set_visibility(bool visible, bool toggle)
|
|
||||||
{
|
|
||||||
m_properties.visible = toggle ? !m_properties.visible : visible;
|
|
||||||
|
|
||||||
if (m_properties.visible)
|
|
||||||
{
|
|
||||||
glfwShowWindow(m_handle);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
glfwHideWindow(m_handle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void wWindow::bind_glfw_events()
|
|
||||||
{
|
|
||||||
glfwSetCursorPosCallback(m_handle, [](GLFWwindow *window, double xpos, double ypos) {
|
|
||||||
auto callback = *(std::function<void(Event &)> *)glfwGetWindowUserPointer(window);
|
|
||||||
|
|
||||||
auto event = MouseMovedEvent {
|
|
||||||
static_cast<float>(xpos),
|
|
||||||
static_cast<float>(ypos),
|
|
||||||
};
|
|
||||||
callback(event);
|
|
||||||
});
|
|
||||||
|
|
||||||
glfwSetMouseButtonCallback(
|
|
||||||
m_handle,
|
|
||||||
[](GLFWwindow *window, int button, int action, int /*mods*/) {
|
|
||||||
std::function<void(Event &)> const callback = *(
|
|
||||||
std::function<void(Event &)> *
|
|
||||||
)glfwGetWindowUserPointer(window);
|
|
||||||
|
|
||||||
if (action == GLFW_PRESS)
|
|
||||||
{
|
|
||||||
auto event = ButtonPressedEvent { button };
|
|
||||||
callback(event);
|
|
||||||
}
|
|
||||||
else if (action == GLFW_RELEASE)
|
|
||||||
{
|
|
||||||
auto event = ButtonReleasedEvent { button };
|
|
||||||
callback(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
glfwSetScrollCallback(m_handle, [](GLFWwindow *window, double /*xoffset*/, double yoffset) {
|
|
||||||
auto callback = *(std::function<void(Event &)> *)glfwGetWindowUserPointer(window);
|
|
||||||
|
|
||||||
auto event = WheelScrolledEvent { static_cast<float>(yoffset) };
|
|
||||||
callback(event);
|
|
||||||
});
|
|
||||||
|
|
||||||
glfwSetKeyCallback(
|
|
||||||
m_handle,
|
|
||||||
[](GLFWwindow *window, int key, int /*scancode*/, int action, int /*mods*/) {
|
|
||||||
auto callback = *(std::function<void(Event &)> *)glfwGetWindowUserPointer(window);
|
|
||||||
|
|
||||||
if (action == GLFW_PRESS)
|
|
||||||
{
|
|
||||||
auto event = KeyPressedEvent { key };
|
|
||||||
callback(event);
|
|
||||||
}
|
|
||||||
else if (action == GLFW_RELEASE)
|
|
||||||
{
|
|
||||||
auto event = KeyReleasedEvent { key };
|
|
||||||
callback(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
glfwSetCharCallback(m_handle, [](GLFWwindow *window, unsigned int character) {
|
|
||||||
auto callback = *(std::function<void(Event &)> *)glfwGetWindowUserPointer(window);
|
|
||||||
|
|
||||||
auto event = SetCharEvent { character };
|
|
||||||
callback(event);
|
|
||||||
});
|
|
||||||
|
|
||||||
glfwSetWindowPosCallback(m_handle, [](GLFWwindow *window, int xpos, int ypos) {
|
|
||||||
auto callback = *(std::function<void(Event &)> *)glfwGetWindowUserPointer(window);
|
|
||||||
auto event = WindowMovedEvent { xpos, ypos };
|
|
||||||
|
|
||||||
callback(event);
|
|
||||||
});
|
|
||||||
|
|
||||||
glfwSetWindowSizeCallback(m_handle, [](GLFWwindow *window, int width, int height) {
|
|
||||||
auto callback = *(std::function<void(Event &)> *)glfwGetWindowUserPointer(window);
|
|
||||||
auto event = WindowResizedEvent {
|
|
||||||
static_cast<unsigned int>(width),
|
|
||||||
static_cast<unsigned int>(height),
|
|
||||||
};
|
|
||||||
|
|
||||||
callback(event);
|
|
||||||
});
|
|
||||||
|
|
||||||
glfwSetWindowCloseCallback(m_handle, [](GLFWwindow *window) {
|
|
||||||
auto callback = *(std::function<void(Event &)> *)glfwGetWindowUserPointer(window);
|
|
||||||
auto event = WindowClosedEvent {};
|
|
||||||
|
|
||||||
callback(event);
|
|
||||||
});
|
|
||||||
|
|
||||||
glfwSetWindowFocusCallback(m_handle, [](GLFWwindow *window, int focus) {
|
|
||||||
auto callback = *(std::function<void(Event &)> *)glfwGetWindowUserPointer(window);
|
|
||||||
|
|
||||||
if (focus == GLFW_TRUE)
|
|
||||||
{
|
|
||||||
auto event = WindowGainFocusEvent {};
|
|
||||||
callback(event);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
auto event = WindowLostFocusEvent {};
|
|
||||||
callback(event);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace lt
|
|
Loading…
Add table
Reference in a new issue