Initial commit

master
Tranquillity Codes 10 months ago committed by itycodes
commit ca16469545

@ -0,0 +1,44 @@
SRC := src
CDEBUG := -g -fsanitize=address,undefined
CXXFLAGS := -Ilib $(CDEBUG)
CPP := c++
LIBS := -lvulkan -lglfw
OUT := ./out
BIN := $(OUT)/main
CXXCMD := $(CPP) $(CXXFLAGS) $(LIBS)
define linit
$(wordlist 2,$(words $(1)),x $(1))
endef
define llast
$(lastword $(1))
endef
SRCS=$(wildcard $(SRC)/*)
all: $(BIN)
run: all
VK_ADD_LAYER_PATH=/usr/share/vulkan/explicit_layer.d/VkLayer_khronos_validation.json VK_LOADER_LAYERS_ENABLE=*validation ./out/main
clean:
rm -f out/*
cleanlsp:
rm -f compile_commands.json
cleanall: clean cleanlsp
lsp: $(SRCS)
rm -f compile_commands.json # TODO figure out how to depend on cleanlsp
echo [ >> compile_commands.json
for src in $(call linit,$^) ; do \
echo {'"'directory'"': '"'$(PWD)'"', '"'command'"': '"'$(CXXCMD) $^ -o $(BIN)'"', '"'file'"': '"'$$src'"'}, >> compile_commands.json ;\
done
echo {'"'directory'"': '"'$(PWD)'"', '"'command'"': '"'$(CXXCMD) $^ -o $(BIN)'"', '"'file'"': '"'$(call llast,$^)'"'} >> compile_commands.json ;\
echo ] >> compile_commands.json
$(BIN): $(SRCS)
$(CXXCMD) $^ -o $@

@ -0,0 +1,28 @@
#pragma once
#include <cstdint>
#include <string>
#include <vector>
#include <GLFW/glfw3.h>
#include <vulkan/vulkan.h>
namespace ls {
class GlfwState {
public:
GlfwState();
std::vector<const char*> get_vulkan_exts();
};
class GlfwWindow {
private:
GLFWwindow* __window;
std::string __title;
public:
GlfwWindow(GlfwState* state, uint32_t x_size, uint32_t y_size, std::string title);
void show();
void set_title(const std::string title);
GLFWwindow* __get_backing();
VkResult __make_surface(VkInstance instance, VkSurfaceKHR* surface);
};
}

@ -0,0 +1,21 @@
#pragma once
#include <vulkan/vulkan.h>
#include <vulkan/vulkan_core.h>
namespace ls {
class VulkanState;
}
#include "window.hpp"
namespace ls {
class VulkanState {
private:
VkInstance __instance;
public:
VulkanState(GlfwState* state);
void __make_surface(GlfwWindow* win, VkSurfaceKHR* surf);
};
}

@ -0,0 +1,23 @@
#pragma once
namespace ls {
class Window;
}
#include "glfw.hpp"
#include "vulkan.hpp"
namespace ls {
class Window {
public:
Window(GlfwState* glfw_state);
~Window();
void show();
void set_title(const std::string title);
void init_surface(VulkanState* vulkan_state);
GlfwWindow* __get_native();
private:
GlfwWindow* __window;
VkSurfaceKHR __surface;
};
}

@ -0,0 +1,54 @@
// NOTE: Order matters.
// Including glfw before Vulkan makes glfw not load Vulkan-specific functions
#include <vulkan/vulkan.h>
#include <GLFW/glfw3.h>
#include <string>
#include <vector>
#include <assert.h>
#include <vulkan/vulkan_core.h>
#include "glfw.hpp"
namespace ls {
// GlfwState
GlfwState::GlfwState() {
assert(glfwInit() == GLFW_TRUE);
};
std::vector<const char*> GlfwState::get_vulkan_exts() {
std::vector<const char*> res;
uint32_t glfw_exts_count = 0;
const char** glfw_exts = glfwGetRequiredInstanceExtensions(&glfw_exts_count);
for(int i = 0; i < glfw_exts_count; i++) {
res.push_back(glfw_exts[i]);
}
return res;
}
// GlfwWindow
GlfwWindow::GlfwWindow(GlfwState* state, uint32_t x_size, uint32_t y_size, std::string title) {
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
this->__window = glfwCreateWindow(x_size, y_size, title.c_str(), NULL, NULL);
};
void GlfwWindow::show() {
glfwShowWindow(__window);
}
void GlfwWindow::set_title(const std::string title) {
this->__title = title;
glfwSetWindowTitle(this->__window, this->__title.c_str());
}
VkResult GlfwWindow::__make_surface(VkInstance instance, VkSurfaceKHR* surface) {
return glfwCreateWindowSurface(instance, this->__window, NULL, surface);
}
GLFWwindow* GlfwWindow::__get_backing() {
return __window;
}
}

@ -0,0 +1,18 @@
// Entry point.
// Should probably link the engine libs & run the editor but
// imma hack random shit together for now
#include "glfw.hpp"
#include "vulkan.hpp"
#include "window.hpp"
using namespace ls;
int main() {
auto glfw = GlfwState();
auto vulkan = VulkanState(&glfw);
auto window = Window(&glfw);
window.set_title("LightningStrike Hello World!");
window.init_surface(&vulkan);
window.show();
while(1) {}
}

@ -0,0 +1,39 @@
#include <vulkan/vulkan.h>
#include <vulkan/vulkan_core.h>
#include <assert.h>
#include "vulkan.hpp"
#include "glfw.hpp"
#include "window.hpp"
namespace ls {
VulkanState::VulkanState(GlfwState* state) {
VkApplicationInfo application_info = {
VK_STRUCTURE_TYPE_APPLICATION_INFO,
NULL,
"Game",
VK_MAKE_VERSION( 1, 0, 0 ),
"LightningStrike",
VK_MAKE_VERSION( 1, 0, 0 ),
VK_API_VERSION_1_3,
};
std::vector<const char*> vk_exts = state->get_vulkan_exts();
VkInstanceCreateInfo instance_create_info = {
VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
NULL,
0,
&application_info,
0,
NULL,
static_cast<uint32_t>(vk_exts.size()),
vk_exts.data()
};
VkResult res = vkCreateInstance(&instance_create_info, NULL, &__instance);
assert(res == VK_SUCCESS);
}
void VulkanState::__make_surface(GlfwWindow* win, VkSurfaceKHR* surf) {
VkResult res = win->__make_surface(__instance, surf);
assert(res == VK_SUCCESS);
}
}

@ -0,0 +1,31 @@
#include <GLFW/glfw3.h>
#include <cstdlib>
#include <vulkan/vulkan_core.h>
#include <assert.h>
#include "window.hpp"
#include "glfw.hpp"
#include "vulkan.hpp"
namespace ls {
Window::Window(GlfwState* glfw_state) {
this->__window = new GlfwWindow(glfw_state, 1920, 1080, "");
};
Window::~Window() {
std::free(this->__window);
}
void Window::init_surface(VulkanState* vulkan_state) {
vulkan_state->__make_surface(__window, &__surface);
}
void Window::show() {
__window->show();
}
void Window::set_title(const std::string title) {
__window->set_title(title);
}
GlfwWindow* Window::__get_native() {
return __window;
}
}
Loading…
Cancel
Save