Initial Commit
This commit is contained in:
commit
d0e0718b1e
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
cmake-build-debug/
|
||||
.idea/
|
||||
19
CMakeLists.txt
Normal file
19
CMakeLists.txt
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
cmake_minimum_required(VERSION 3.31)
|
||||
project(Dyn)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 26)
|
||||
|
||||
file(GLOB_RECURSE sourceFiles "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/inc/*.h")
|
||||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/inc")
|
||||
|
||||
find_package(Vulkan REQUIRED)
|
||||
find_package(glfw3 CONFIG REQUIRED)
|
||||
|
||||
foreach (file ${sourceFiles})
|
||||
message("Source File Found ${file}")
|
||||
endforeach ()
|
||||
|
||||
add_executable(Dyn ${sourceFiles})
|
||||
|
||||
target_link_libraries(Dyn PRIVATE Vulkan::Vulkan)
|
||||
target_link_libraries(Dyn PRIVATE glfw)
|
||||
48
inc/dyn/core/assertion.h
Normal file
48
inc/dyn/core/assertion.h
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
//
|
||||
// Created by nepge on 2/23/2025.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <dyn/core/logging.h>
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define DYN_DEBUG
|
||||
#endif
|
||||
|
||||
#define DYN_FATAL_LOG(...) ::dyn::core::fatalln(__VA_ARGS__)
|
||||
|
||||
#ifdef _WIN_VER
|
||||
#define DYN_BREAKPOINT __debugbreak()
|
||||
#elif __has_builtin(__builtin_debugtrap)
|
||||
#define DYN_BREAKPOINT __builtin_debugtrap()
|
||||
#elif __has_builtin(__builtin_trap)
|
||||
#define DYN_BREAKPOINT __builtin_trap()
|
||||
#else
|
||||
#define DYN_BREAKPOINT DYN_FATAL_LOG("Breakpoint occured at", __FILE__, "at line", __LINE__); exit(1)
|
||||
#endif
|
||||
|
||||
#ifndef DYN_BREAKPOINT
|
||||
#error "Breakpoints where not able to be created"
|
||||
#endif
|
||||
|
||||
#ifdef DYN_DEBUG
|
||||
#define DYN_ENABLE_ASSERTIONS
|
||||
|
||||
#define DYN_DEBUG_LOG(...) ::dyn::core::debugln(__VA_ARGS__)
|
||||
|
||||
#else
|
||||
|
||||
#define DYN_DEBUG_LOG(...)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef DYN_ENABLE_ASSERTIONS
|
||||
|
||||
#define DYN_ASSERT(cond, ...) if (!cond) { DYN_FATAL_LOG("Assert failed", ##__VA_ARGS__); DYN_BREAKPOINT; }
|
||||
|
||||
#else
|
||||
|
||||
#define DYN_ASSERT(...)
|
||||
|
||||
#endif
|
||||
31
inc/dyn/core/base.h
Normal file
31
inc/dyn/core/base.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
//
|
||||
// Created by nepge on 2/21/2025.
|
||||
//
|
||||
#pragma once
|
||||
#include <memory>
|
||||
|
||||
#include <dyn/core/logging.h>
|
||||
|
||||
namespace dyn {
|
||||
template <typename T>
|
||||
using ref = std::shared_ptr<T>;
|
||||
|
||||
template <typename To, typename From>
|
||||
ref<To> ref_as(ref<From> from) {
|
||||
return std::dynamic_pointer_cast<To>(from);
|
||||
}
|
||||
|
||||
namespace core {
|
||||
enum class RenderPlatform {
|
||||
None,
|
||||
Vulkan
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#define DYN_PLATFORM_CREATE_BEGIN(platform) switch (platform) {
|
||||
#define DYN_PLATFORM_CREATE_VK(obj, ...) case RenderPlatform::Vulkan: \
|
||||
return std::make_shared<obj>(__VA_ARGS__)
|
||||
#define DYN_PLATFORM_CREATE_END(type) default: \
|
||||
::dyn::core::logln("platform not defined for creating the object {}", #type); \
|
||||
return nullptr; }
|
||||
30
inc/dyn/core/command_queue.h
Normal file
30
inc/dyn/core/command_queue.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
//
|
||||
// Created by nepge on 2/23/2025.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
namespace dyn::core {
|
||||
template<typename FuncT, typename = std::is_function<FuncT>>
|
||||
class command_queue {
|
||||
public:
|
||||
command_queue() = default;
|
||||
|
||||
void submit(FuncT func) {
|
||||
_command_list.push_back(func);
|
||||
}
|
||||
|
||||
template<typename ...Args>
|
||||
void execute(Args&&... args) {
|
||||
for (auto command : _command_list) {
|
||||
command(args...);
|
||||
}
|
||||
_command_list.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<FuncT> _command_list;
|
||||
};
|
||||
}
|
||||
65
inc/dyn/core/logging.h
Normal file
65
inc/dyn/core/logging.h
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
//
|
||||
// Created by nepge on 2/21/2025.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
namespace dyn::core {
|
||||
class logger {
|
||||
public:
|
||||
explicit logger(const std::string& name) : m_name(name) {}
|
||||
virtual ~logger() = default;
|
||||
|
||||
template <typename... Args>
|
||||
void log(const std::string& msg, Args&&... args) {
|
||||
print("info", msg, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void fatal(const std::string& msg, Args&&... args) {
|
||||
print("fatal", msg, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void debug(const std::string& msg, Args&&... args) {
|
||||
print("debug", msg, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
[[nodiscard]] static logger& def();
|
||||
|
||||
private:
|
||||
template <typename... Args>
|
||||
void print(const std::string& type, const std::string& msg, Args&&... args) {
|
||||
std::array<char, sizeof...(Args) * 3 + 4> buffer{};
|
||||
constexpr char c[4] = "{} ";
|
||||
for (auto i = 0; i != buffer.size() - 1; ++i) {
|
||||
buffer[i] = c[i % 3];
|
||||
}
|
||||
buffer.back() = '\0';
|
||||
|
||||
std::string_view format{buffer.data()};
|
||||
|
||||
std::cout << std::format("[{}, {}] ", m_name, type) << std::vformat(format, std::make_format_args(msg, args...)) << "\n";
|
||||
}
|
||||
|
||||
std::string m_name;
|
||||
static logger m_default;
|
||||
};
|
||||
template <typename... Args>
|
||||
void logln(const std::string& msg, Args&&... args) {
|
||||
logger::def().log(msg, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void fatalln(const std::string& msg, Args&&... args) {
|
||||
logger::def().fatal(msg, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void debugln(const std::string& msg, Args&&... args) {
|
||||
logger::def().debug(msg, std::forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
28
inc/dyn/core/window.h
Normal file
28
inc/dyn/core/window.h
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
//
|
||||
// Created by nepge on 2/23/2025.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#define GLFW_INCLUDE_VULKAN
|
||||
#include <glfw/glfw3.h>
|
||||
|
||||
namespace dyn::core {
|
||||
struct window_spec {
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
std::string title;
|
||||
bool fullscreen;
|
||||
};
|
||||
|
||||
class window {
|
||||
public:
|
||||
window(const window_spec& spec);
|
||||
~window();
|
||||
|
||||
static std::vector<const char*> get_required_extensions();
|
||||
private:
|
||||
window_spec spec;
|
||||
};
|
||||
}
|
||||
23
inc/dyn/dyn.h
Normal file
23
inc/dyn/dyn.h
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
//
|
||||
// Created by nepge on 2/22/2025.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <dyn/core/base.h>
|
||||
#include <dyn/core/logging.h>
|
||||
#include <dyn/core/window.h>
|
||||
|
||||
namespace dyn {
|
||||
struct app_spec {
|
||||
window_spec* window;
|
||||
};
|
||||
|
||||
class application {
|
||||
public:
|
||||
dyn_application();
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
12
inc/dyn/platform/vulkan/vulkan.h
Normal file
12
inc/dyn/platform/vulkan/vulkan.h
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
//
|
||||
// Created by nepge on 2/23/2025.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <dyn/core/assertion.h>
|
||||
|
||||
#define dyn_vk_verify(f) { \
|
||||
VkResult res = f; \
|
||||
DYN_ASSERT(res == VK_SUCCESS, __FILE__, "at line", __LINE__); }
|
||||
33
inc/dyn/platform/vulkan/vulkan_context.h
Normal file
33
inc/dyn/platform/vulkan/vulkan_context.h
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
//
|
||||
// Created by nepge on 2/23/2025.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <dyn/renderer/render_context.h>
|
||||
|
||||
namespace dyn::core {
|
||||
|
||||
class vulkan_context : public render_context {
|
||||
public:
|
||||
vulkan_context();
|
||||
~vulkan_context() override;
|
||||
|
||||
void init() override;
|
||||
|
||||
void cmd_begin() override;
|
||||
|
||||
void render_mesh_source(ref<mesh_source> mesh) override;
|
||||
|
||||
void cmd_end() override;
|
||||
|
||||
VkInstance get_instance();
|
||||
|
||||
static bool check_api_version_support(uint32_t api_version);
|
||||
|
||||
private:
|
||||
VkInstance _instance = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
14
inc/dyn/renderer/mesh.h
Normal file
14
inc/dyn/renderer/mesh.h
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
//
|
||||
// Created by nepge on 2/22/2025.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace dyn::core {
|
||||
class mesh_source {
|
||||
public:
|
||||
mesh_source();
|
||||
|
||||
void get_vertices();
|
||||
};
|
||||
}
|
||||
49
inc/dyn/renderer/render_context.h
Normal file
49
inc/dyn/renderer/render_context.h
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
//
|
||||
// Created by nepge on 2/22/2025.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <dyn/core/command_queue.h>
|
||||
#include <dyn/core/base.h>
|
||||
#include <dyn/renderer/mesh.h>
|
||||
|
||||
namespace dyn::core {
|
||||
class render_context;
|
||||
|
||||
using render_command = std::function<void(ref<render_context>)>;
|
||||
using render_command_queue = command_queue<render_command>;
|
||||
|
||||
class render_context {
|
||||
public:
|
||||
render_context() = default;
|
||||
virtual ~render_context() = default;
|
||||
|
||||
virtual void init() = 0;
|
||||
|
||||
// begin a new render command
|
||||
virtual void cmd_begin() = 0;
|
||||
|
||||
// submit a render cmd to the queue
|
||||
void submit(render_command func);
|
||||
|
||||
// submit a mesh source to be renderered
|
||||
virtual void render_mesh_source(ref<mesh_source> mesh) = 0;
|
||||
|
||||
// end the frame, render to the screen
|
||||
virtual void cmd_end() = 0;
|
||||
|
||||
static void set_api(RenderPlatform platform);
|
||||
static RenderPlatform get_api();
|
||||
|
||||
static ref<render_context> create();
|
||||
|
||||
protected:
|
||||
render_command_queue _render_command_queue;
|
||||
|
||||
private:
|
||||
static RenderPlatform s_api;
|
||||
};
|
||||
}
|
||||
13
src/core/logging.cpp
Normal file
13
src/core/logging.cpp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
//
|
||||
// Created by nepge on 2/21/2025.
|
||||
//
|
||||
|
||||
#include <dyn/core/logging.h>
|
||||
|
||||
namespace dyn::core {
|
||||
logger logger::m_default = logger("default");
|
||||
|
||||
logger &logger::def() {
|
||||
return m_default;
|
||||
}
|
||||
}
|
||||
30
src/core/window.cpp
Normal file
30
src/core/window.cpp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
//
|
||||
// Created by nepge on 2/23/2025.
|
||||
//
|
||||
|
||||
#include <cstdint>
|
||||
#include <dyn/core/window.h>
|
||||
|
||||
#include "dyn/core/assertion.h"
|
||||
|
||||
namespace dyn::core {
|
||||
window::window(const window_spec &spec) {
|
||||
DYN_ASSERT(glfwInit(), "GLFW failed to initialize");
|
||||
}
|
||||
|
||||
window::~window() {
|
||||
}
|
||||
|
||||
std::vector<const char *> window::get_required_extensions() {
|
||||
uint32_t extensions_count = 0;
|
||||
const char** extensions;
|
||||
|
||||
extensions = glfwGetRequiredInstanceExtensions(&extensions_count);
|
||||
std::vector<const char *> result;
|
||||
result.reserve(extensions_count);
|
||||
result.insert(result.begin(), extensions, extensions + extensions_count);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
32
src/main.cpp
Normal file
32
src/main.cpp
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#include <functional>
|
||||
#include <iostream>
|
||||
|
||||
#include <dyn/core/logging.h>
|
||||
#include <dyn/core/command_queue.h>
|
||||
|
||||
#include "../inc/dyn/core/assertion.h"
|
||||
#include "dyn/core/window.h"
|
||||
#include "dyn/renderer/render_context.h"
|
||||
|
||||
using namespace dyn;
|
||||
using namespace dyn::core;
|
||||
|
||||
int main() {
|
||||
// render_context::set_api(RenderPlatform::Vulkan);
|
||||
// ref<render_context> ctx = render_context::create();
|
||||
//
|
||||
// ctx->init();
|
||||
|
||||
window win = window({
|
||||
.width = 1280,
|
||||
.height = 720,
|
||||
.title = "Dyn Engine",
|
||||
.fullscreen = false
|
||||
});
|
||||
|
||||
auto extensions = window::get_required_extensions();
|
||||
DYN_DEBUG_LOG("Extensions Found:", extensions.size());
|
||||
for (auto extension : extensions) {
|
||||
DYN_DEBUG_LOG("Extension Found:", extension);
|
||||
}
|
||||
}
|
||||
75
src/platform/vulkan/vulkan_context.cpp
Normal file
75
src/platform/vulkan/vulkan_context.cpp
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
//
|
||||
// Created by nepge on 2/23/2025.
|
||||
//
|
||||
|
||||
|
||||
#include <dyn/platform/vulkan/vulkan_context.h>
|
||||
#include <dyn/platform/vulkan/vulkan.h>
|
||||
#include <dyn/core/window.h>
|
||||
|
||||
namespace dyn::core {
|
||||
|
||||
vulkan_context::vulkan_context() {}
|
||||
|
||||
vulkan_context::~vulkan_context() {
|
||||
vkDestroyInstance(_instance, nullptr);
|
||||
}
|
||||
|
||||
void vulkan_context::init() {
|
||||
if (!check_api_version_support(VK_API_VERSION_1_2)) {
|
||||
|
||||
}
|
||||
// create vulkan instance
|
||||
{
|
||||
DYN_DEBUG_LOG("Creating Vulkan context");
|
||||
VkApplicationInfo app_info{};
|
||||
app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
||||
app_info.apiVersion = VK_API_VERSION_1_2;
|
||||
app_info.pApplicationName = "Dyn";
|
||||
app_info.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
|
||||
app_info.pEngineName = "Dyn";
|
||||
app_info.engineVersion = VK_MAKE_VERSION(1, 0, 0);
|
||||
|
||||
VkInstanceCreateInfo create_info{};
|
||||
create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||
create_info.pApplicationInfo = &app_info;
|
||||
|
||||
// extensions
|
||||
{
|
||||
auto extensions = window::get_required_extensions();
|
||||
create_info.enabledExtensionCount = static_cast<uint32_t>(extensions.size());
|
||||
create_info.ppEnabledExtensionNames = extensions.data();
|
||||
}
|
||||
|
||||
create_info.enabledLayerCount = 0;
|
||||
create_info.ppEnabledLayerNames = nullptr;
|
||||
|
||||
dyn_vk_verify(vkCreateInstance(&create_info, nullptr, &_instance));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void vulkan_context::cmd_begin() {
|
||||
}
|
||||
|
||||
void vulkan_context::render_mesh_source(ref<mesh_source> mesh) {
|
||||
}
|
||||
|
||||
void vulkan_context::cmd_end() {
|
||||
}
|
||||
|
||||
VkInstance vulkan_context::get_instance() {
|
||||
return _instance;
|
||||
}
|
||||
|
||||
bool vulkan_context::check_api_version_support(uint32_t requested_version) {
|
||||
uint32_t supported_version;
|
||||
vkEnumerateInstanceVersion(&supported_version);
|
||||
|
||||
if (supported_version < requested_version) {
|
||||
DYN_FATAL_LOG("Vulkan API version is too low to continue. Please make sure your drivers correctly installed.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
28
src/renderer/render_context.cpp
Normal file
28
src/renderer/render_context.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
//
|
||||
// Created by nepge on 2/23/2025.
|
||||
//
|
||||
#include <dyn/renderer/render_context.h>
|
||||
|
||||
#include <dyn/platform/vulkan/vulkan_context.h>
|
||||
|
||||
namespace dyn::core {
|
||||
RenderPlatform render_context::s_api = RenderPlatform::None;
|
||||
|
||||
void render_context::submit(render_command func) {
|
||||
_render_command_queue.submit(func);
|
||||
}
|
||||
|
||||
void render_context::set_api(RenderPlatform platform) {
|
||||
s_api = platform;
|
||||
}
|
||||
|
||||
RenderPlatform render_context::get_api() {
|
||||
return s_api;
|
||||
}
|
||||
|
||||
ref<render_context> render_context::create() {
|
||||
DYN_PLATFORM_CREATE_BEGIN(get_api())
|
||||
DYN_PLATFORM_CREATE_VK(vulkan_context);
|
||||
DYN_PLATFORM_CREATE_END(render_context)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user