Compare commits
25 Commits
Author | SHA1 | Date |
---|---|---|
|
fffa1b81e9 | ago%!(EXTRA string=7 months) |
|
7a6c7d58c6 | ago%!(EXTRA string=8 months) |
|
b2ebd91bec | ago%!(EXTRA string=8 months) |
|
554bbe6567 | ago%!(EXTRA string=8 months) |
|
650e4584bd | ago%!(EXTRA string=8 months) |
|
b17c794999 | ago%!(EXTRA string=8 months) |
|
0ef47947fb | ago%!(EXTRA string=8 months) |
|
8778689229 | ago%!(EXTRA string=12 months) |
|
518ca85c85 | ago%!(EXTRA string=12 months) |
|
b61777f5d7 | ago%!(EXTRA string=12 months) |
|
5959834aca | ago%!(EXTRA string=12 months) |
|
90b04a50ef | ago%!(EXTRA string=12 months) |
|
06a1c6c246 | ago%!(EXTRA string=12 months) |
|
d40fa774c1 | ago%!(EXTRA string=12 months) |
|
e65aa30c31 | ago%!(EXTRA string=12 months) |
|
1698fd5176 | ago%!(EXTRA string=12 months) |
|
1f704b70d7 | ago%!(EXTRA string=12 months) |
|
b24ab05c8f | ago%!(EXTRA string=12 months) |
|
20994a3a9a | ago%!(EXTRA string=12 months) |
|
0144cf171e | ago%!(EXTRA string=12 months) |
|
d6addb993e | ago%!(EXTRA string=1 year) |
|
4961e461bc | ago%!(EXTRA string=1 year) |
|
d271f9422e | ago%!(EXTRA string=1 year) |
|
c7f7932d2f | ago%!(EXTRA string=1 year) |
|
9d782283f9 | ago%!(EXTRA string=1 year) |
105 changed files with 2385 additions and 7884 deletions
@ -1,12 +0,0 @@ |
||||
[submodule "bakara/vendor/glm"] |
||||
path = bakara/vendor/glm |
||||
url = https://github.com/g-truc/glm.git |
||||
[submodule "bakara/vendor/spdloglib"] |
||||
path = bakara/vendor/spdloglib |
||||
url = https://github.com/gabime/spdlog |
||||
[submodule "bakara/vendor/glfw"] |
||||
path = bakara/vendor/glfw |
||||
url = https://github.com/glfw/glfw |
||||
[submodule "bakara/vendor/imgui"] |
||||
path = bakara/vendor/imgui |
||||
url = https://github.com/ocornut/imgui |
@ -1,95 +0,0 @@ |
||||
project "bakara" |
||||
language "C++" |
||||
cppdialect "C++17" |
||||
|
||||
targetdir("%{wks.location}/bin/" .. outputdir .. "/%{prj.name}") |
||||
objdir("%{wks.location}/bin-int/" .. outputdir .. "/%{prj.name}") |
||||
|
||||
|
||||
files |
||||
{ |
||||
"vendor/glm/glm/**.hpp", |
||||
"vendor/glm/glm/**.inl", |
||||
"vendor/imgui/misc/cpp/imgui_stdlib.cpp", |
||||
"vendor/imgui/backends/imgui_impl_opengl3.cpp", |
||||
"vendor/imgui/backends/imgui_impl_glfw.cpp", |
||||
"src/**.h", |
||||
"src/**.cpp", |
||||
} |
||||
|
||||
defines |
||||
{ |
||||
"_CRT_SECURE_NO_WARNINGS", |
||||
"GLFW_INCLUDE_NONE", |
||||
"IMGUI_IMPL_OPENGL_LOADER_GLAD" |
||||
} |
||||
|
||||
includedirs |
||||
{ |
||||
"%{IncludeDirs.bakara}", |
||||
"%{IncludeDirs.glm}", |
||||
"%{IncludeDirs.spdlog}", |
||||
"%{IncludeDirs.glad}", |
||||
"%{IncludeDirs.glfw}", |
||||
"%{IncludeDirs.imgui}" |
||||
|
||||
} |
||||
|
||||
links |
||||
{ |
||||
"GLFW", |
||||
"GLAD", |
||||
"ImGui" |
||||
} |
||||
|
||||
filter "configurations:Debug" |
||||
defines |
||||
{ |
||||
"BK_DEBUG", |
||||
"DEBUG" |
||||
} |
||||
runtime "Debug" |
||||
symbols "on" |
||||
|
||||
|
||||
filter "configurations:Release" |
||||
defines |
||||
{ |
||||
"BK_RELEASE", |
||||
"NDEBUG" |
||||
} |
||||
runtime "Release" |
||||
optimize "on" |
||||
|
||||
filter "system:windows" |
||||
kind "StaticLib" |
||||
staticruntime "on" |
||||
defines |
||||
{ |
||||
"BK_PLATFORM_WINDOWS" |
||||
} |
||||
|
||||
links |
||||
{ |
||||
"opengl32.lib" |
||||
} |
||||
|
||||
filter "system:linux" |
||||
kind "SharedLib" |
||||
staticruntime "off" |
||||
|
||||
files |
||||
{ |
||||
"vendor/glm/glm/**.cpp" |
||||
} |
||||
|
||||
defines |
||||
{ |
||||
"BK_PLATFORM_LINUX" |
||||
} |
||||
|
||||
links |
||||
{ |
||||
"GL" |
||||
} |
||||
|
@ -1,24 +0,0 @@ |
||||
#pragma once |
||||
|
||||
/*! \file bakara.h
|
||||
Precompiled headers for external pragrams. |
||||
*/ |
||||
|
||||
/*! \namespace Bk
|
||||
Global namespace doc |
||||
*/ |
||||
namespace Bk {} |
||||
|
||||
/*! \namespace Bk::Plaform
|
||||
Plaform namespace doc |
||||
*/ |
||||
namespace Bk::Plaform {} |
||||
|
||||
#include <bakara/math/type.h> |
||||
#include <bakara/core/log.h> |
||||
#include <bakara/core/assert.h> |
||||
#include <bakara/io/io_codes.h> |
||||
|
||||
#include <bakara/events/events.h> |
||||
#include <bakara/core/application.h> |
||||
#include <bakara/core/layer.h> |
@ -1,49 +0,0 @@ |
||||
#include "application.h" |
||||
|
||||
namespace Bk { |
||||
Application* Application::p_instance = nullptr; |
||||
|
||||
Application::Application()
|
||||
{
|
||||
BK_CORE_MSG_ASSERT(p_instance == nullptr, "Application already exists, can not create two application.") |
||||
Application::p_instance = this; |
||||
h_window = std::shared_ptr<Window>(Window::create_window()); |
||||
h_window->set_event_callback(BK_BIND_EVENT_FN(on_event)); |
||||
p_running = true; |
||||
} |
||||
|
||||
Application::~Application() { } |
||||
|
||||
void Application::on_event(Event& e) |
||||
{ |
||||
EventDispatcher dispatcher(e); |
||||
if (!(dispatcher.dispatch<WindowCloseEvent>(BK_BIND_DISPACHER_FN(WindowCloseEvent, on_window_close)) || |
||||
dispatcher.dispatch<WindowResizeEvent>(BK_BIND_DISPACHER_FN(WindowResizeEvent, on_window_resize)))) |
||||
{ |
||||
for(auto it = p_layer_stack.rbegin(); it != p_layer_stack.rend(); it++) |
||||
{ |
||||
(*it)->on_event(e); |
||||
} |
||||
} |
||||
} |
||||
|
||||
bool Application::on_window_close(WindowCloseEvent& e) |
||||
{ |
||||
h_window->close(); |
||||
p_running = false; |
||||
return true; |
||||
} |
||||
|
||||
bool Application::on_window_resize(WindowResizeEvent& e) |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
void Application::run()
|
||||
{ |
||||
while (p_running) |
||||
{ |
||||
h_window->on_update(); |
||||
} |
||||
} |
||||
} |
@ -1,32 +0,0 @@ |
||||
#pragma once |
||||
|
||||
/*! \file assert.h
|
||||
This file contains the assert macros. CORE macros musn't be used by the application. |
||||
*/ |
||||
|
||||
#include "base.h" |
||||
#include <bakara/tools/string_fmt.h> |
||||
|
||||
#ifdef BK_ENABLE_ASSERT |
||||
/*! \def BK_CORE_VAMSG_ASSERT(check, msg, ...)
|
||||
Assertes a condition, and throw an error with the formatted message as description |
||||
@param check : Condionne to assert |
||||
@param msg : format string error message |
||||
@param ... : variable arguments to put in the string |
||||
*/ |
||||
#define BK_CORE_VAMSG_ASSERT(check, msg, ...) if(!(check)) { BK_CORE_ERROR(Tools::format("Assertion [%s] failed at %s:%d\n\tError : %s", BK_STRINGIFY(check), __FILE__, __LINE__, msg), __VA_ARGS__); BK_DEBUGBREAK(); } |
||||
#define BK_CORE_MSG_ASSERT(check, msg) if(!(check)) { BK_CORE_ERROR("Assertion [{0}] failed at {1}:{2}\n\tError : {3}", BK_STRINGIFY(check), __FILE__, __LINE__, msg); BK_DEBUGBREAK(); } |
||||
#define BK_CORE_ASSERT(check) if(!(check)) { BK_CORE_ERROR("Assertion [{0}] failed at {1}:{2}", BK_STRINGIFY(check), __FILE__, __LINE__); BK_DEBUGBREAK(); } |
||||
|
||||
#define BK_VAMSG_ASSERT(check, msg, ...) if(!(check)) { BK_ERROR(Bk::Tools::format("Assertion [%s] failed at %s:%d\n\tError : %s", BK_STRINGIFY(check), __FILE__, __LINE__, msg), __VA_ARGS__); BK_DEBUGBREAK(); } |
||||
#define BK_MSG_ASSERT(check, msg) if(!(check)) { BK_ERROR("Assertion [{0}] failed at {1}:{2}\n\tError : {3}", BK_STRINGIFY(check), __FILE__, __LINE__, msg); BK_DEBUGBREAK(); } |
||||
#define BK_ASSERT(check) if(!(check)) { BK_ERROR("Assertion [{0}] failed at {1}:{2}", BK_STRINGIFY(check), __FILE__, __LINE__); BK_DEBUGBREAK(); } |
||||
#else |
||||
#define BK_CORE_VAMSG_ASSERT(check, msg, ...) |
||||
#define BK_CORE_MSG_ASSERT(check, msg) |
||||
#define BK_CORE_ASSERT(check) |
||||
|
||||
#define BK_VAMSG_ASSERT(check, msg, ...) |
||||
#define BK_MSG_ASSERT(check, msg) |
||||
#define BK_ASSERT(check) |
||||
#endif |
@ -1,25 +0,0 @@ |
||||
#pragma once |
||||
|
||||
#include "log.h" |
||||
|
||||
#define BK_STRINGIFY(x) #x |
||||
#define BIT_SHIFT(x) (1 << x) |
||||
|
||||
#define BK_BIND_EVENT_FN(fn) [this](Event& e) { fn(e); } |
||||
#define BK_BIND_DISPACHER_FN(event, fn) [this](event& e) -> bool{ return fn(e); } |
||||
|
||||
#ifdef BK_DEBUG |
||||
#if defined(BK_PLATFORM_WINDOWS) |
||||
#define BK_DEBUGBREAK() __debugbreak() |
||||
#elif defined(BK_PLATFORM_LINUX) |
||||
#include <signal.h> |
||||
#define BK_DEBUGBREAK() raise(SIGTRAP) |
||||
#else |
||||
#error "Plaform doesn't support debug yet" |
||||
#endif |
||||
#define BK_ENABLE_ASSERT |
||||
#else |
||||
#define BK_DEBUGBREAK() |
||||
#endif |
||||
|
||||
|
@ -1,23 +0,0 @@ |
||||
#include <bkpch.h> |
||||
#include "log.h" |
||||
#include "application.h" |
||||
|
||||
/*! \file entry.cpp
|
||||
This file contains the entry point of the program. |
||||
*/ |
||||
|
||||
/*! \fn std::unique_ptr<Bk::Application> Bk::create_app()
|
||||
External function implemented client side. |
||||
*/ |
||||
extern std::unique_ptr<Bk::Application> Bk::create_app(); |
||||
|
||||
/*! \fn int main(int argc, char** argv)
|
||||
Entry of the program. |
||||
*/ |
||||
int main(int argc, char** argv) { |
||||
Bk::Log::init(); |
||||
BK_CORE_INFO("Bienvenue dans la sandbox {0} version {1}", "bakara", 1); |
||||
std::unique_ptr<Bk::Application> app = Bk::create_app(); |
||||
app->run(); |
||||
return 0; |
||||
} |
@ -1,20 +0,0 @@ |
||||
#pragma once |
||||
#include <bkpch.h> |
||||
#include <bakara/events/events.h> |
||||
|
||||
namespace Bk { |
||||
class Layer
|
||||
{ |
||||
public: |
||||
Layer(const std::string& name = "Layer"); |
||||
virtual ~Layer() {} |
||||
|
||||
virtual void on_attach() {} |
||||
virtual void on_detach() {} |
||||
virtual void on_event(Event& e) {} |
||||
virtual void on_update() {} |
||||
const std::string to_string() const { return name; } |
||||
protected: |
||||
std::string name; |
||||
};
|
||||
} |
@ -1,50 +0,0 @@ |
||||
#include "layer_stack.h" |
||||
|
||||
namespace Bk { |
||||
LayerStack::~LayerStack() |
||||
{ |
||||
std::for_each(p_layers.begin(), p_layers.end(), [](Layer* layer) |
||||
{ |
||||
layer->on_detach(); |
||||
delete layer; |
||||
}); |
||||
p_layers.clear(); |
||||
} |
||||
|
||||
void LayerStack::push_overlay(Layer* layer) |
||||
{ |
||||
layer->on_attach(); |
||||
p_layers.emplace_back(layer); |
||||
} |
||||
|
||||
std::unique_ptr<Layer> LayerStack::pop_overlay() |
||||
{ |
||||
if(auto layer = p_layers.back()) |
||||
{
|
||||
p_layers.pop_back(); |
||||
return std::make_unique<Layer>(*layer);
|
||||
} |
||||
return nullptr; |
||||
} |
||||
|
||||
void LayerStack::push_layer(Layer* layer) |
||||
{ |
||||
layer->on_attach(); |
||||
p_layers.emplace_front(layer); |
||||
} |
||||
|
||||
std::unique_ptr<Layer> LayerStack::pop_layer() |
||||
{ |
||||
if(auto layer = p_layers.front())
|
||||
{
|
||||
p_layers.pop_front(); |
||||
return std::make_unique<Layer>(*layer);
|
||||
} |
||||
return nullptr; |
||||
} |
||||
|
||||
void LayerStack::clear() |
||||
{ |
||||
p_layers.clear(); |
||||
} |
||||
} |
@ -1,29 +0,0 @@ |
||||
#pragma once |
||||
|
||||
#include <bkpch.h> |
||||
#include "layer.h" |
||||
|
||||
namespace Bk { |
||||
class LayerStack |
||||
{ |
||||
public: |
||||
LayerStack() = default; |
||||
~LayerStack(); |
||||
|
||||
void push_overlay(Layer* layer); |
||||
std::unique_ptr<Layer> pop_overlay(); |
||||
void push_layer(Layer* layer); |
||||
std::unique_ptr<Layer> pop_layer(); |
||||
void clear(); |
||||
|
||||
std::deque<Layer*>::iterator begin() { return p_layers.begin(); } |
||||
std::deque<Layer*>::iterator end() { return p_layers.end(); } |
||||
|
||||
std::deque<Layer*>::reverse_iterator rbegin() { return p_layers.rbegin(); } |
||||
std::deque<Layer*>::reverse_iterator rend() { return p_layers.rend(); } |
||||
|
||||
private: |
||||
std::deque<Layer*> p_layers; |
||||
uint p_layer_index = 0;
|
||||
}; |
||||
} |
@ -1,28 +0,0 @@ |
||||
#include "log.h" |
||||
|
||||
namespace Bk { |
||||
|
||||
std::shared_ptr<spdlog::logger> Log::p_core_logger; |
||||
std::shared_ptr<spdlog::logger> Log::p_app_logger; |
||||
|
||||
void Log::init() |
||||
{ |
||||
std::vector<spdlog::sink_ptr> log_sinks; |
||||
log_sinks.emplace_back(std::make_shared<spdlog::sinks::stdout_color_sink_mt>()); |
||||
log_sinks.emplace_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>("bakara.log", true)); |
||||
|
||||
log_sinks[0]->set_pattern("%^[%T] %n: %v%$"); |
||||
log_sinks[1]->set_pattern("[%T] [%l] %n: %v"); |
||||
|
||||
p_core_logger = std::make_shared<spdlog::logger>("BAKARA", begin(log_sinks), end(log_sinks)); |
||||
spdlog::register_logger(p_core_logger); |
||||
p_core_logger->set_level(spdlog::level::trace); |
||||
p_core_logger->flush_on(spdlog::level::trace); |
||||
|
||||
p_app_logger = std::make_shared<spdlog::logger>("APP", begin(log_sinks), end(log_sinks)); |
||||
spdlog::register_logger(p_app_logger); |
||||
p_app_logger->set_level(spdlog::level::trace); |
||||
p_app_logger->flush_on(spdlog::level::trace); |
||||
} |
||||
|
||||
} |
@ -1,47 +0,0 @@ |
||||
#pragma once |
||||
|
||||
#include <bkpch.h> |
||||
#include <spdlog/spdlog.h> |
||||
#include <spdlog/fmt/ostr.h> |
||||
#include <spdlog/sinks/stdout_color_sinks.h> |
||||
#include <spdlog/sinks/basic_file_sink.h> |
||||
|
||||
namespace Bk { |
||||
|
||||
class Log |
||||
{ |
||||
public: |
||||
static void init(); |
||||
|
||||
static std::shared_ptr<spdlog::logger>& get_core_logger() { return p_core_logger; } |
||||
static std::shared_ptr<spdlog::logger>& get_app_logger() { return p_app_logger; } |
||||
private: |
||||
static std::shared_ptr<spdlog::logger> p_core_logger; |
||||
static std::shared_ptr<spdlog::logger> p_app_logger; |
||||
}; |
||||
#ifdef BK_DEBUG |
||||
#define BK_CORE_TRACE(...) ::Bk::Log::get_core_logger()->trace(__VA_ARGS__) |
||||
#define BK_CORE_INFO(...) ::Bk::Log::get_core_logger()->info(__VA_ARGS__) |
||||
#define BK_CORE_WARN(...) ::Bk::Log::get_core_logger()->warn(__VA_ARGS__) |
||||
#define BK_CORE_ERROR(...) ::Bk::Log::get_core_logger()->error(__VA_ARGS__) |
||||
#define BK_CORE_CRITICAL(...) ::Bk::Log::get_core_logger()->critical(__VA_ARGS__) |
||||
|
||||
#define BK_TRACE(...) ::Bk::Log::get_app_logger()->trace(__VA_ARGS__) |
||||
#define BK_INFO(...) ::Bk::Log::get_app_logger()->info(__VA_ARGS__) |
||||
#define BK_WARN(...) ::Bk::Log::get_app_logger()->warn(__VA_ARGS__) |
||||
#define BK_ERROR(...) ::Bk::Log::get_app_logger()->error(__VA_ARGS__) |
||||
#define BK_CRITICAL(...) ::Bk::Log::get_app_logger()->critical(__VA_ARGS__) |
||||
#else |
||||
#define BK_CORE_TRACE(...) |
||||
#define BK_CORE_INFO(...) |
||||
#define BK_CORE_WARN(...) |
||||
#define BK_CORE_ERROR(...) |
||||
#define BK_CORE_CRITICAL(...) |
||||
|
||||
#define BK_TRACE(...) |
||||
#define BK_INFO(...) |
||||
#define BK_WARN(...) |
||||
#define BK_ERROR(...) |
||||
#define BK_CRITICAL(...) |
||||
#endif |
||||
} |
@ -1,32 +0,0 @@ |
||||
#include "imgui_layer.h" |
||||
|
||||
namespace Bk { |
||||
void ImguiLayer::on_attach()
|
||||
{ |
||||
ImGui::CreateContext(); |
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
|
||||
Application& app = Application::get(); |
||||
GLFWwindow* window = static_cast<GLFWwindow*>(app.get_window()->get_native_window()); |
||||
|
||||
// Setup Platform/Renderer bindings
|
||||
ImGui_ImplGlfw_InitForOpenGL(window, true); |
||||
ImGui_ImplOpenGL3_Init("#version 410"); |
||||
} |
||||
|
||||
void ImguiLayer::on_detach()
|
||||
{ |
||||
|
||||
} |
||||
|
||||
void ImguiLayer::on_event(Bk::Event& e)
|
||||
{ |
||||
|
||||
} |
||||
|
||||
void ImguiLayer::on_update() |
||||
{ |
||||
|
||||
} |
||||
} |
@ -1,23 +0,0 @@ |
||||
#pragma once |
||||
|
||||
#include <imgui.h> |
||||
#include <backends/imgui_impl_opengl3.h> |
||||
#include <backends/imgui_impl_glfw.h> |
||||
#include <bakara/core/application.h> |
||||
#include <bakara/core/layer.h> |
||||
|
||||
namespace Bk { |
||||
class ImguiLayer : public Layer
|
||||
{ |
||||
public: |
||||
ImguiLayer() |
||||
: Layer("Imgui") {} |
||||
|
||||
~ImguiLayer() = default; |
||||
|
||||
void on_attach() override; |
||||
void on_detach() override; |
||||
void on_event(Bk::Event& e) override; |
||||
void on_update() override; |
||||
}; |
||||
} |
@ -1,8 +0,0 @@ |
||||
#pragma once |
||||
|
||||
/*! \file mathpch.h
|
||||
Precompiled headers communly used in math functionnalitys. |
||||
*/ |
||||
|
||||
#include <glm/glm.hpp> |
||||
#include <glm/gtc/matrix_transform.hpp> |
@ -1,47 +0,0 @@ |
||||
#pragma once |
||||
#include <bkpch.h> |
||||
#include <bakara/io/window.h> |
||||
#include <bakara/events/events.h> |
||||
#include <mutex> |
||||
#include <GLFW/glfw3.h> |
||||
|
||||
namespace Bk::Plaform { |
||||
class WinGLFW : public Window |
||||
{ |
||||
public: |
||||
WinGLFW(const WindowProps& props); |
||||
virtual ~WinGLFW(); |
||||
|
||||
inline uint get_width() const override { return p_data.width; } |
||||
inline uint get_height() const override { return p_data.height; } |
||||
|
||||
void on_update() override; |
||||
void set_event_callback(const EventCallback callback) override; |
||||
|
||||
void set_vsync(bool enable) override; |
||||
bool is_vsync() const override; |
||||
|
||||
void close() override; |
||||
void open() override; |
||||
|
||||
void* get_native_window() override { return p_window; } |
||||
|
||||
private: |
||||
GLFWwindow* p_window; |
||||
bool p_shutdown; |
||||
|
||||
struct WindowData
|
||||
{ |
||||
std::string title; |
||||
uint width; |
||||
uint height; |
||||
bool vsync; |
||||
EventCallback callback; |
||||
}; |
||||
WindowData p_data; |
||||
|
||||
void init_event_callbacks(); |
||||
void init(); |
||||
void shutdown(); |
||||
}; |
||||
} |
@ -1,65 +0,0 @@ |
||||
#pragma once |
||||
|
||||
/*! \file string_fmt.h
|
||||
This file provides functions to do string formatting. |
||||
*/ |
||||
|
||||
#include <bkpch.h> |
||||
#include <type_traits> |
||||
#include <cctype> |
||||
|
||||
namespace Bk::Tools { |
||||
|
||||
inline void format_impl(std::stringstream& ss, const char* format) {
|
||||
while (*format) { |
||||
if (*format == '%' && *++format != '%') // %% == % (not a format directive)
|
||||
throw std::invalid_argument("not enough arguments !\n"); |
||||
ss << *format++; |
||||
} |
||||
} |
||||
|
||||
template <typename Arg, typename... Args> |
||||
void format_impl(std::stringstream& ss, const char* format, Arg arg, Args... args) { |
||||
while (*format) { |
||||
if (*format == '%' && *++format != '%') { |
||||
auto current_format_qualifier = *format; |
||||
switch(current_format_qualifier) { |
||||
case 'd' :
|
||||
if (!std::is_integral<Arg>()) throw std::invalid_argument("%d introduces integral argument"); |
||||
break; |
||||
case 'f' :
|
||||
if (!std::is_floating_point<Arg>()) throw std::invalid_argument("%f introduces floating point argument"); |
||||
break; |
||||
case 'b' : |
||||
if(arg) ss << "true"; |
||||
else ss << "false"; |
||||
return format_impl(ss, ++format, args...); |
||||
case 's' : |
||||
break; |
||||
// etc.
|
||||
default:
|
||||
throw std::invalid_argument("Not a standard format"); |
||||
break; |
||||
} |
||||
// it's true you'd have to handle many more format qualifiers, but on a safer basis
|
||||
ss << arg; // arg type is deduced
|
||||
return format_impl(ss, ++format, args...); // one arg less
|
||||
} |
||||
ss << *format++; |
||||
} // the format string is exhausted and we still have args : throw
|
||||
throw std::invalid_argument("Too many arguments\n"); |
||||
} |
||||
/*! \fn std::string Bk::Tools::format(const char* fmt, Args... args)
|
||||
Formats a string, printf like. Accepts integers, floating point numbers, strings, booléen. |
||||
@param fmt : string to format |
||||
@param args : variable arguments to put in the string |
||||
@return String formatted |
||||
*/ |
||||
template <typename... Args> |
||||
inline std::string format(const char* fmt, Args... args) { |
||||
std::stringstream ss; |
||||
format_impl(ss, fmt, args...); |
||||
return ss.str(); |
||||
} |
||||
} |
||||
|
@ -1,21 +0,0 @@ |
||||
#pragma once |
||||
|
||||
/*! \file bkpch.h
|
||||
Precompiled headers communly used in bakara.
|
||||
*/ |
||||
|
||||
#include <iostream> |
||||
#include <ostream> |
||||
#include <utility> |
||||
#include <memory> |
||||
#include <functional> |
||||
#include <string> |
||||
#include <sstream> |
||||
#include <array> |
||||
#include <vector> |
||||
#include <deque> |
||||
#include <exception> |
||||
|
||||
#include <bakara/core/log.h> |
||||
#include <bakara/core/assert.h> |
||||
#include <bakara/math/type.h> |
@ -1,311 +0,0 @@ |
||||
#ifndef __khrplatform_h_ |
||||
#define __khrplatform_h_ |
||||
|
||||
/*
|
||||
** Copyright (c) 2008-2018 The Khronos Group Inc. |
||||
** |
||||
** Permission is hereby granted, free of charge, to any person obtaining a |
||||
** copy of this software and/or associated documentation files (the |
||||
** "Materials"), to deal in the Materials without restriction, including |
||||
** without limitation the rights to use, copy, modify, merge, publish, |
||||
** distribute, sublicense, and/or sell copies of the Materials, and to |
||||
** permit persons to whom the Materials are furnished to do so, subject to |
||||
** the following conditions: |
||||
** |
||||
** The above copyright notice and this permission notice shall be included |
||||
** in all copies or substantial portions of the Materials. |
||||
** |
||||
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
||||
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
||||
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
||||
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
||||
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
||||
*/ |
||||
|
||||
/* Khronos platform-specific types and definitions.
|
||||
* |
||||
* The master copy of khrplatform.h is maintained in the Khronos EGL |
||||
* Registry repository at https://github.com/KhronosGroup/EGL-Registry
|
||||
* The last semantic modification to khrplatform.h was at commit ID: |
||||
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692 |
||||
* |
||||
* Adopters may modify this file to suit their platform. Adopters are |
||||
* encouraged to submit platform specific modifications to the Khronos |
||||
* group so that they can be included in future versions of this file. |
||||
* Please submit changes by filing pull requests or issues on |
||||
* the EGL Registry repository linked above. |
||||
* |
||||
* |
||||
* See the Implementer's Guidelines for information about where this file |
||||
* should be located on your system and for more details of its use: |
||||
* http://www.khronos.org/registry/implementers_guide.pdf
|
||||
* |
||||
* This file should be included as |
||||
* #include <KHR/khrplatform.h> |
||||
* by Khronos client API header files that use its types and defines. |
||||
* |
||||
* The types in khrplatform.h should only be used to define API-specific types. |
||||
* |
||||
* Types defined in khrplatform.h: |
||||
* khronos_int8_t signed 8 bit |
||||
* khronos_uint8_t unsigned 8 bit |
||||
* khronos_int16_t signed 16 bit |
||||
* khronos_uint16_t unsigned 16 bit |
||||
* khronos_int32_t signed 32 bit |
||||
* khronos_uint32_t unsigned 32 bit |
||||
* khronos_int64_t signed 64 bit |
||||
* khronos_uint64_t unsigned 64 bit |
||||
* khronos_intptr_t signed same number of bits as a pointer |
||||
* khronos_uintptr_t unsigned same number of bits as a pointer |
||||
* khronos_ssize_t signed size |
||||
* khronos_usize_t unsigned size |
||||
* khronos_float_t signed 32 bit floating point |
||||
* khronos_time_ns_t unsigned 64 bit time in nanoseconds |
||||
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in |
||||
* nanoseconds |
||||
* khronos_stime_nanoseconds_t signed time interval in nanoseconds |
||||
* khronos_boolean_enum_t enumerated boolean type. This should |
||||
* only be used as a base type when a client API's boolean type is |
||||
* an enum. Client APIs which use an integer or other type for |
||||
* booleans cannot use this as the base type for their boolean. |
||||
* |
||||
* Tokens defined in khrplatform.h: |
||||
* |
||||
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values. |
||||
* |
||||
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0. |
||||
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0. |
||||
* |
||||
* Calling convention macros defined in this file: |
||||
* KHRONOS_APICALL |
||||
* KHRONOS_APIENTRY |
||||
* KHRONOS_APIATTRIBUTES |
||||
* |
||||
* These may be used in function prototypes as: |
||||
* |
||||
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname( |
||||
* int arg1, |
||||
* int arg2) KHRONOS_APIATTRIBUTES; |
||||
*/ |
||||
|
||||
#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC) |
||||
# define KHRONOS_STATIC 1 |
||||
#endif |
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APICALL |
||||
*------------------------------------------------------------------------- |
||||
* This precedes the return type of the function in the function prototype. |
||||
*/ |
||||
#if defined(KHRONOS_STATIC) |
||||
/* If the preprocessor constant KHRONOS_STATIC is defined, make the
|
||||
* header compatible with static linking. */ |
||||
# define KHRONOS_APICALL |
||||
#elif defined(_WIN32) |
||||
# define KHRONOS_APICALL __declspec(dllimport) |
||||
#elif defined (__SYMBIAN32__) |
||||
# define KHRONOS_APICALL IMPORT_C |
||||
#elif defined(__ANDROID__) |
||||
# define KHRONOS_APICALL __attribute__((visibility("default"))) |
||||
#else |
||||
# define KHRONOS_APICALL |
||||
#endif |
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APIENTRY |
||||
*------------------------------------------------------------------------- |
||||
* This follows the return type of the function and precedes the function |
||||
* name in the function prototype. |
||||
*/ |
||||
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__) |
||||
/* Win32 but not WinCE */ |
||||
# define KHRONOS_APIENTRY __stdcall |
||||
#else |
||||
# define KHRONOS_APIENTRY |
||||
#endif |
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APIATTRIBUTES |
||||
*------------------------------------------------------------------------- |
||||
* This follows the closing parenthesis of the function prototype arguments. |
||||
*/ |
||||
#if defined (__ARMCC_2__) |
||||
#define KHRONOS_APIATTRIBUTES __softfp |
||||
#else |
||||
#define KHRONOS_APIATTRIBUTES |
||||
#endif |
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* basic type definitions |
||||
*-----------------------------------------------------------------------*/ |
||||
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__) |
||||
|
||||
|
||||
/*
|
||||
* Using <stdint.h> |
||||
*/ |
||||
#include <stdint.h> |
||||
typedef int32_t khronos_int32_t; |
||||
typedef uint32_t khronos_uint32_t; |
||||
typedef int64_t khronos_int64_t; |
||||
typedef uint64_t khronos_uint64_t; |
||||
#define KHRONOS_SUPPORT_INT64 1 |
||||
#define KHRONOS_SUPPORT_FLOAT 1 |
||||
/*
|
||||
* To support platform where unsigned long cannot be used interchangeably with |
||||
* inptr_t (e.g. CHERI-extended ISAs), we can use the stdint.h intptr_t. |
||||
* Ideally, we could just use (u)intptr_t everywhere, but this could result in |
||||
* ABI breakage if khronos_uintptr_t is changed from unsigned long to |
||||
* unsigned long long or similar (this results in different C++ name mangling). |
||||
* To avoid changes for existing platforms, we restrict usage of intptr_t to |
||||
* platforms where the size of a pointer is larger than the size of long. |
||||
*/ |
||||
#if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__) |
||||
#if __SIZEOF_POINTER__ > __SIZEOF_LONG__ |
||||
#define KHRONOS_USE_INTPTR_T |
||||
#endif |
||||
#endif |
||||
|
||||
#elif defined(__VMS ) || defined(__sgi) |
||||
|
||||
/*
|
||||
* Using <inttypes.h> |
||||
*/ |
||||
#include <inttypes.h> |
||||
typedef int32_t khronos_int32_t; |
||||
typedef uint32_t khronos_uint32_t; |
||||
typedef int64_t khronos_int64_t; |
||||
typedef uint64_t khronos_uint64_t; |
||||
#define KHRONOS_SUPPORT_INT64 1 |
||||
#define KHRONOS_SUPPORT_FLOAT 1 |
||||
|
||||
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__) |
||||
|
||||
/*
|
||||
* Win32 |
||||
*/ |
||||
typedef __int32 khronos_int32_t; |
||||
typedef unsigned __int32 khronos_uint32_t; |
||||
typedef __int64 khronos_int64_t; |
||||
typedef unsigned __int64 khronos_uint64_t; |
||||
#define KHRONOS_SUPPORT_INT64 1 |
||||
#define KHRONOS_SUPPORT_FLOAT 1 |
||||
|
||||
#elif defined(__sun__) || defined(__digital__) |
||||
|
||||
/*
|
||||
* Sun or Digital |
||||
*/ |
||||
typedef int khronos_int32_t; |
||||
typedef unsigned int khronos_uint32_t; |
||||
#if defined(__arch64__) || defined(_LP64) |
||||
typedef long int khronos_int64_t; |
||||
typedef unsigned long int khronos_uint64_t; |
||||
#else |
||||
typedef long long int khronos_int64_t; |
||||
typedef unsigned long long int khronos_uint64_t; |
||||
#endif /* __arch64__ */ |
||||
#define KHRONOS_SUPPORT_INT64 1 |
||||
#define KHRONOS_SUPPORT_FLOAT 1 |
||||
|
||||
#elif 0 |
||||
|
||||
/*
|
||||
* Hypothetical platform with no float or int64 support |
||||
*/ |
||||
typedef int khronos_int32_t; |
||||
typedef unsigned int khronos_uint32_t; |
||||
#define KHRONOS_SUPPORT_INT64 0 |
||||
#define KHRONOS_SUPPORT_FLOAT 0 |
||||
|
||||
#else |
||||
|
||||
/*
|
||||
* Generic fallback |
||||
*/ |
||||
#include <stdint.h> |
||||
typedef int32_t khronos_int32_t; |
||||
typedef uint32_t khronos_uint32_t; |
||||
typedef int64_t khronos_int64_t; |
||||
typedef uint64_t khronos_uint64_t; |
||||
#define KHRONOS_SUPPORT_INT64 1 |
||||
#define KHRONOS_SUPPORT_FLOAT 1 |
||||
|
||||
#endif |
||||
|
||||
|
||||
/*
|
||||
* Types that are (so far) the same on all platforms |
||||
*/ |
||||
typedef signed char khronos_int8_t; |
||||
typedef unsigned char khronos_uint8_t; |
||||
typedef signed short int khronos_int16_t; |
||||
typedef unsigned short int khronos_uint16_t; |
||||
|
||||
/*
|
||||
* Types that differ between LLP64 and LP64 architectures - in LLP64, |
||||
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears |
||||
* to be the only LLP64 architecture in current use. |
||||
*/ |
||||
#ifdef KHRONOS_USE_INTPTR_T |
||||
typedef intptr_t khronos_intptr_t; |
||||
typedef uintptr_t khronos_uintptr_t; |
||||
#elif defined(_WIN64) |
||||
typedef signed long long int khronos_intptr_t; |
||||
typedef unsigned long long int khronos_uintptr_t; |
||||
#else |
||||
typedef signed long int khronos_intptr_t; |
||||
typedef unsigned long int khronos_uintptr_t; |
||||
#endif |
||||
|
||||
#if defined(_WIN64) |
||||
typedef signed long long int khronos_ssize_t; |
||||
typedef unsigned long long int khronos_usize_t; |
||||
#else |
||||
typedef signed long int khronos_ssize_t; |
||||
typedef unsigned long int khronos_usize_t; |
||||
#endif |
||||
|
||||
#if KHRONOS_SUPPORT_FLOAT |
||||
/*
|
||||
* Float type |
||||
*/ |
||||
typedef float khronos_float_t; |
||||
#endif |
||||
|
||||
#if KHRONOS_SUPPORT_INT64 |
||||
/* Time types
|
||||
* |
||||
* These types can be used to represent a time interval in nanoseconds or |
||||
* an absolute Unadjusted System Time. Unadjusted System Time is the number |
||||
* of nanoseconds since some arbitrary system event (e.g. since the last |
||||
* time the system booted). The Unadjusted System Time is an unsigned |
||||
* 64 bit value that wraps back to 0 every 584 years. Time intervals |
||||
* may be either signed or unsigned. |
||||
*/ |
||||
typedef khronos_uint64_t khronos_utime_nanoseconds_t; |
||||
typedef khronos_int64_t khronos_stime_nanoseconds_t; |
||||
#endif |
||||
|
||||
/*
|
||||
* Dummy value used to pad enum types to 32 bits. |
||||
*/ |
||||
#ifndef KHRONOS_MAX_ENUM |
||||
#define KHRONOS_MAX_ENUM 0x7FFFFFFF |
||||
#endif |
||||
|
||||
/*
|
||||
* Enumerated boolean type |
||||
* |
||||
* Values other than zero should be considered to be true. Therefore |
||||
* comparisons should not be made against KHRONOS_TRUE. |
||||
*/ |
||||
typedef enum { |
||||
KHRONOS_FALSE = 0, |
||||
KHRONOS_TRUE = 1, |
||||
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM |
||||
} khronos_boolean_enum_t; |
||||
|
||||
#endif /* __khrplatform_h_ */ |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1 +0,0 @@ |
||||
Subproject commit 8e6c8d7effc54f8aecd30eda17069588298f4ada |
@ -1 +0,0 @@ |
||||
Subproject commit b06b775c1c80af51a1183c0e167f9de3b2351a79 |
@ -1 +0,0 @@ |
||||
Subproject commit 96839b445e32e46d87a44fd43a9cdd60c806f7e1 |
@ -1,157 +0,0 @@ |
||||
project "GLFW" |
||||
location "./glfw" |
||||
kind "StaticLib" |
||||
language "C" |
||||
|
||||
targetdir ("%{wks.location}/bin/" .. outputdir .. "/%{prj.name}") |
||||
objdir ("%{wks.location}/bin-int/" .. outputdir .. "/%{prj.name}") |
||||
|
||||
includedirs { "%{prj.location}/include" } |
||||
|
||||
files |
||||
{ |
||||
"%{prj.location}/src/internal.h", |
||||
"%{prj.location}/src/platform.h", |
||||
"%{prj.location}/src/mappings.h", |
||||
"%{prj.location}/src/context.c", |
||||
"%{prj.location}/src/init.c", |
||||
"%{prj.location}/src/input.c", |
||||
"%{prj.location}/src/monitor.c", |
||||
"%{prj.location}/src/window.c", |
||||
"%{prj.location}/src/platform.c", |
||||
"%{prj.location}/src/vulkan.c", |
||||
"%{prj.location}/src/null_init.c", |
||||
"%{prj.location}/src/null_monitor.c", |
||||
"%{prj.location}/src/null_window.c", |
||||
"%{prj.location}/src/null_joystick.c", |
||||
"%{prj.location}/src/glfw_config.h", |
||||
"%{prj.location}/include/GLFW/glfw3native.h", |
||||
"%{prj.location}/include/GLFW/glfw3.h", |
||||
"include/GLFW/glfw3.h", |
||||
"include/GLFW/glfw3native.h", |
||||
} |
||||
|
||||
filter "system:linux" |
||||
pic "On" |
||||
|
||||
systemversion "latest" |
||||
|
||||
files |
||||
{ |
||||
"%{prj.location}/src/x11_init.c", |
||||
"%{prj.location}/src/x11_monitor.c", |
||||
"%{prj.location}/src/x11_window.c", |
||||
"%{prj.location}/src/xkb_unicode.c", |
||||
"%{prj.location}/src/posix_time.c", |
||||
"%{prj.location}/src/posix_module.c", |
||||
"%{prj.location}/src/posix_poll.c", |
||||
"%{prj.location}/src/posix_thread.c", |
||||
"%{prj.location}/src/glx_context.c", |
||||
"%{prj.location}/src/egl_context.c", |
||||
"%{prj.location}/src/osmesa_context.c", |
||||
"%{prj.location}/src/linux_joystick.c" |
||||
} |
||||
|
||||
defines |
||||
{ |
||||
"_GLFW_X11" |
||||
} |
||||
|
||||
filter "system:windows" |
||||
systemversion "latest" |
||||
staticruntime "On" |
||||
|
||||
files |
||||
{ |
||||
"%{prj.location}/src/win32_init.c", |
||||
"%{prj.location}/src/win32_joystick.c", |
||||
"%{prj.location}/src/win32_monitor.c", |
||||
"%{prj.location}/src/win32_time.c", |
||||
"%{prj.location}/src/win32_module.c", |
||||
"%{prj.location}/src/win32_thread.c", |
||||
"%{prj.location}/src/win32_window.c", |
||||
"%{prj.location}/src/wgl_context.c", |
||||
"%{prj.location}/src/egl_context.c", |
||||
"%{prj.location}/src/osmesa_context.c" |
||||
} |
||||
|
||||
defines |
||||
{ |
||||
"_GLFW_WIN32", |
||||
"_CRT_SECURE_NO_WARNINGS" |
||||
} |
||||
|
||||
filter "configurations:Debug" |
||||
runtime "Debug" |
||||
symbols "on" |
||||
|
||||
filter "configurations:Release" |
||||
runtime "Release" |
||||
optimize "on" |
||||
|
||||
project "GLAD" |
||||
location "./glad" |
||||
kind "StaticLib" |
||||
language "C" |
||||
systemversion "latest" |
||||
|
||||
targetdir ("%{wks.location}/bin/" .. outputdir .. "/%{prj.name}") |
||||
objdir ("%{wks.location}/bin-int/" .. outputdir .. "/%{prj.name}") |
||||
|
||||
includedirs { "%{prj.location}/include" } |
||||
|
||||
buildoptions { "-fPIC" } |
||||
|
||||
files |
||||
{ |
||||
"%{prj.location}/src/glad.c", |
||||
"%{prj.location}/include/KHR/khrplatform.h", |
||||
"%{prj.location}/include/glad.h" |
||||
} |
||||
|
||||
filter "configurations:Debug" |
||||
runtime "Debug" |
||||
symbols "on" |
||||
|
||||
filter "configurations:Release" |
||||
runtime "Release" |
||||
optimize "on" |
||||
|
||||
project "ImGui" |
||||
location "./imgui" |
||||
kind "StaticLib" |
||||
language "C++" |
||||
systemversion "latest" |
||||
cppdialect "C++17" |
||||
staticruntime "On" |
||||
|
||||
targetdir ("%{wks.location}/bin/" .. outputdir .. "/%{prj.name}") |
||||
objdir ("%{wks.location}/bin-int/" .. outputdir .. "/%{prj.name}") |
||||
|
||||
files |
||||
{ |
||||
"%{prj.location}/imconfig.h", |
||||
"%{prj.location}/imgui.h", |
||||
"%{prj.location}/imgui.cpp", |
||||
"%{prj.location}/imgui_draw.cpp", |
||||
"%{prj.location}/imgui_internal.h", |
||||
"%{prj.location}/imgui_widgets.cpp", |
||||
"%{prj.location}/imstb_rectpack.h", |
||||
"%{prj.location}/imstb_textedit.h", |
||||
"%{prj.location}/imstb_truetype.h", |
||||
"%{prj.location}/imgui_demo.cpp", |
||||
"%{prj.location}/imgui_tables.cpp", |
||||
|
||||
} |
||||
|
||||
|
||||
filter "system:linux" |
||||
pic "On" |
||||
|
||||
filter "configurations:Debug" |
||||
runtime "Debug" |
||||
symbols "on" |
||||
|
||||
filter "configurations:Release" |
||||
runtime "Release" |
||||
optimize "on" |
@ -1 +0,0 @@ |
||||
Subproject commit 696db97f672e9082e50e50af315d0f4234c82397 |
@ -1,57 +0,0 @@ |
||||
clear |
||||
echo ================== |
||||
echo [BUILDING PROJECT] |
||||
echo ================== |
||||
echo number of lines : |
||||
find ./bakara/src -name *.cpp -or -name *.h -exec cat {} \; | wc -l |
||||
if [ -z ${clear} ]; then |
||||
clear=0 |
||||
else |
||||
clear=1 |
||||
fi |
||||
if [ -z ${exec} ]; then |
||||
exec=0 |
||||
else |
||||
exec=1 |
||||
fi |
||||
|
||||
if [ 1 -eq ${clear} ]; then |
||||
echo Clearing bin/bin-int dirs |
||||
rm -rf bin bin-int |
||||
else |
||||
echo Caching bin/bin-int dirs |
||||
fi |
||||
echo |
||||
premake5 gmake |
||||
echo |
||||
make $1 |
||||
if [ $? -eq 0 ]; then |
||||
echo Compilation Success |
||||
echo ================ |
||||
echo [FINISHED BUILD] |
||||
echo ================ |
||||
|
||||
if [ 1 -eq ${exec} ]; then |
||||
config=$1 |
||||
if [ -z "$config" ]; then |
||||
config="config=debug" |
||||
fi |
||||
if [ "config=debug" == "$config" ]; then |
||||
echo |
||||
echo ============== |
||||
echo [STARTING APP] |
||||
echo ============== |
||||
echo Config: Debug |
||||
bin/linux-x86_64-Debug/sandbox/sandbox |
||||
elif [ "config=release" == "$config" ]; then |
||||
echo [STARTING APP] |
||||
echo [Config: Release] |
||||
bin/linux-x86_64-Release/sandbox/sandbox |
||||
else |
||||
echo [Aborted Launch] |
||||
echo [Config Unknown] |
||||
fi |
||||
fi |
||||
else |
||||
echo Error will compiling |
||||
fi |
@ -0,0 +1,11 @@ |
||||
IncludeDirs["bakara"] = "%{wks.location}/vendor/bakara/src" |
||||
IncludeDirs["glm"] = "%{wks.location}/vendor/glm" |
||||
IncludeDirs["stb"] = "%{wks.location}/vendor/stb" |
||||
|
||||
group "Bakara" |
||||
include "vendor/bakara" |
||||
include "vendor/glfw" |
||||
include "vendor/glad" |
||||
include "vendor/imgui" |
||||
group "" |
||||
|
@ -0,0 +1,32 @@ |
||||
#include <memory> |
||||
#include <utility> |
||||
#include <string> |
||||
#include <bakara.h> |
||||
|
||||
class TestLayer : public Bk::Layer |
||||
{ |
||||
public: |
||||
TestLayer() |
||||
: Layer("Test") {} |
||||
void ImguiRender() override |
||||
{ |
||||
static bool show = true; |
||||
ImGui::ShowDemoWindow(&show); |
||||
} |
||||
|
||||
}; |
||||
|
||||
class Sandbox : public Bk::Application
|
||||
{ |
||||
public: |
||||
Sandbox()
|
||||
{
|
||||
PushLayer(new TestLayer()); |
||||
} |
||||
}; |
||||
|
||||
|
||||
|
||||
std::unique_ptr<Bk::Application> Bk::CreateApp() { |
||||
return std::unique_ptr<Bk::Application>(new Sandbox()); |
||||
} |
@ -0,0 +1,45 @@ |
||||
{ |
||||
"name": "Bakara", |
||||
"author": "anulax1225", |
||||
"git": "https://github.com/anulax1225/bakara", |
||||
"links": |
||||
[ |
||||
"bakara" |
||||
], |
||||
"includes": |
||||
[ |
||||
"bakara", |
||||
"glm" |
||||
], |
||||
"packages": |
||||
[ |
||||
{ |
||||
"author": "anulax1225", |
||||
"name": "bakatools" |
||||
}, |
||||
{ |
||||
"author": "anulax1225", |
||||
"name": "glm" |
||||
}, |
||||
{ |
||||
"author": "anulax1225", |
||||
"name": "glfw" |
||||
}, |
||||
{ |
||||
"author": "anulax1225", |
||||
"name": "glad" |
||||
}, |
||||
{ |
||||
"author": "anulax1225", |
||||
"name": "imgui-docking" |
||||
}, |
||||
{ |
||||
"author": "anulax1225", |
||||
"name": "imgui" |
||||
}, |
||||
{ |
||||
"author": "anulax1225", |
||||
"name": "stb" |
||||
} |
||||
] |
||||
} |
@ -1,39 +1,97 @@ |
||||
workspace "Bakara" |
||||
architecture "x64" |
||||
configurations { "Debug", "Release" } |
||||
startproject "sandbox" |
||||
project "bakara" |
||||
kind "StaticLib" |
||||
language "C++" |
||||
cppdialect "C++20" |
||||
|
||||
flags |
||||
{ |
||||
"MultiProcessorCompile" |
||||
} |
||||
targetdir("%{wks.location}/bin/" .. outputdir .. "/%{prj.name}") |
||||
objdir("%{wks.location}/bin-int/" .. outputdir .. "/%{prj.name}") |
||||
|
||||
linkgroups "On" |
||||
files |
||||
{ |
||||
"%{wks.location}/vendor/glm/glm/**.hpp", |
||||
"%{wks.location}/vendor/glm/glm/**.inl", |
||||
"%{wks.location}/vendor/stb/stb_image.h", |
||||
"%{wks.location}/vendor/stb/stb_image.cpp", |
||||
"src/bakara/**.h", |
||||
"src/bakara/**.cpp", |
||||
"src/platforms/**.h", |
||||
"src/platforms/**.cpp", |
||||
} |
||||
|
||||
outputdir = "%{cfg.system}-%{cfg.architecture}-%{cfg.buildcfg}" |
||||
defines |
||||
{ |
||||
"_CRT_SECURE_NO_WARNINGS", |
||||
"GLFW_INCLUDE_NONE", |
||||
} |
||||
|
||||
IncludeDirs = {} |
||||
IncludeDirs["bakara"] = "%{wks.location}/bakara/src" |
||||
IncludeDirs["vendor"] = "%{wks.location}/bakara/vendor" |
||||
IncludeDirs["spdlog"] = "%{wks.location}/bakara/vendor/spdloglib/include" |
||||
IncludeDirs["glm"] = "%{wks.location}/bakara/vendor/glm" |
||||
IncludeDirs["glfw"] = "%{wks.location}/bakara/vendor/glfw/include" |
||||
IncludeDirs["glad"] = "%{wks.location}/bakara/vendor/glad/include" |
||||
IncludeDirs["imgui"] = "%{wks.location}/bakara/vendor/imgui" |
||||
includedirs |
||||
{ |
||||
"%{IncludeDirs.bakara}", |
||||
"%{IncludeDirs.glm}", |
||||
"%{IncludeDirs.spdlog}", |
||||
"%{IncludeDirs.glad}", |
||||
"%{IncludeDirs.glfw}", |
||||
"%{IncludeDirs.imgui}", |
||||
"%{IncludeDirs.bakatools}", |
||||
"%{IncludeDirs.stb}" |
||||
} |
||||
|
||||
links |
||||
{ |
||||
"bakatools", |
||||
"GLFW", |
||||
"GLAD", |
||||
"ImGui" |
||||
} |
||||
|
||||
group "Dependencies" |
||||
include "bakara/vendor" |
||||
group "" |
||||
filter "configurations:Debug" |
||||
--buildoptions { "-Wall", "-Wextra" } |
||||
defines |
||||
{ |
||||
"BK_DEBUG", |
||||
"DEBUG" |
||||
} |
||||
runtime "Debug" |
||||
symbols "on" |
||||
|
||||
group "Core" |
||||
include "bakara" |
||||
group "" |
||||
|
||||
group "App" |
||||
include "sandbox" |
||||
group "" |
||||
filter "configurations:Release" |
||||
defines |
||||
{ |
||||
"BK_RELEASE", |
||||
"NDEBUG" |
||||
} |
||||
runtime "Release" |
||||
optimize "on" |
||||
|
||||
filter "system:windows" |
||||
buildoptions "/MT" |
||||
staticruntime "on" |
||||
defines |
||||
{ |
||||
"BK_PLATFORM_WINDOWS" |
||||
} |
||||
|
||||
links |
||||
{ |
||||
"opengl32.lib" |
||||
} |
||||
|
||||
filter "system:linux" |
||||
staticruntime "on" |
||||
buildoptions { "-fPIC" } |
||||
files |
||||
{ |
||||
"%{wks.location}/vendor/glm/glm/**.cpp" |
||||
} |
||||
|
||||
defines |
||||
{ |
||||
"BK_PLATFORM_LINUX" |
||||
} |
||||
|
||||
links |
||||
{ |
||||
"GL" |
||||
} |
||||
|
||||
|
@ -1,59 +0,0 @@ |
||||
project "sandbox" |
||||
kind "ConsoleApp" |
||||
language "C++" |
||||
cppdialect "C++17" |
||||
systemversion "latest" |
||||
|
||||
targetdir("%{wks.location}/bin/" .. outputdir .. "/%{prj.name}") |
||||
objdir("%{wks.location}/bin-int/" .. outputdir .. "/%{prj.name}") |
||||
files |
||||
{ |
||||
"src/**.h", |
||||
"src/**.cpp" |
||||
} |
||||
|
||||
includedirs |
||||
{ |
||||
"%{IncludeDirs.bakara}", |
||||
"%{IncludeDirs.spdlog}", |
||||
"%{IncludeDirs.glm}" |
||||
} |
||||
|
||||
links |
||||
{ |
||||
"bakara" |
||||
} |
||||
|
||||
|
||||
filter "configurations:Debug" |
||||
defines |
||||
{ |
||||
"BK_DEBUG", |
||||
"DEBUG" |
||||
} |
||||
runtime "Debug" |
||||
symbols "on" |
||||
|
||||
|
||||
filter "configurations:Release" |
||||
defines |
||||
{ |
||||
"BK_RELEASE", |
||||
"NDEBUG" |
||||
} |
||||
runtime "Release" |
||||
optimize "on" |
||||
|
||||
filter "system:windows" |
||||
staticruntime "on" |
||||
defines |
||||
{ |
||||
"BK_PLATFORM_WINDOWS" |
||||
} |
||||
|
||||
filter "system:linux" |
||||
staticruntime "on" |
||||
defines |
||||
{ |
||||
"BK_PLATFORM_LINUX" |
||||
} |
@ -0,0 +1,37 @@ |
||||
#pragma once |
||||
|
||||
/*! \file bakara.h
|
||||
Precompiled headers for external pragrams. |
||||
*/ |
||||
|
||||
/*! \namespace Bk
|
||||
Global namespace doc |
||||
*/ |
||||
namespace Bk {} |
||||
|
||||
/*! \namespace Bk::Plaform
|
||||
Plaform namespace doc |
||||
*/ |
||||
namespace Bk::Plaform {} |
||||
|
||||
#include <bakara/math/types.h> |
||||
|
||||
#include <bakara/io/io_codes.h> |
||||
#include <bakara/io/keyboard.h> |
||||
#include <bakara/io/mouse.h> |
||||
#include <bakara/events/events.h> |
||||
#include <bakara/core/application.h> |
||||
#include <bakara/core/layer.h> |
||||
|
||||
#include <bakara/renderer/cameras/ortho_camera.h> |
||||
#include <bakara/renderer/cameras/ortho_camera_controller.h> |
||||
|
||||
#include <bakara/renderer/render_command.h> |
||||
#include <bakara/renderer/renderer.h> |
||||
#include <bakara/renderer/renderer2D.h> |
||||
|
||||
#include <bakara/renderer/texture.h> |
||||
#include <bakara/renderer/buffer.h> |
||||
#include <bakara/renderer/buffer_layout.h> |
||||
#include <bakara/renderer/shader.h> |
||||
#include <bakara/renderer/vertex_array.h> |
@ -0,0 +1,73 @@ |
||||
#include "application.h" |
||||
#include "bakara/core/window.h" |
||||
#include "bakara/events/window_event.h" |
||||
#include "bakara/renderer/renderer.h" |
||||
#include "bakatools/logging/assert.h" |
||||
#include "bakara/events/dispacher.h" |
||||
|
||||
namespace Bk { |
||||
Application* Application::p_instance = nullptr; |
||||
|
||||
Application::Application(std::string title, u32 width, u32 height)
|
||||
{
|
||||
BK_CORE_MSG_ASSERT(p_instance == nullptr, "Application already exists, can not create two application.") |
||||
Application::p_instance = this; |
||||
|
||||
h_window = std::unique_ptr<Window>(Window::CreateWindow(WindowProps(title, width, height))); |
||||
h_window->SetEventCallback(BK_BIND_EVENT_FN(OnEvent)); |
||||
|
||||
Renderer::Init(); |
||||
|
||||
imgui_layer = new ImguiLayer(); |
||||
PushOverlay(imgui_layer); |
||||
} |
||||
|
||||
Application::~Application() { } |
||||
|
||||
void Application::OnEvent(Event& e) |
||||
{ |
||||
EventDispatcher dispatcher(e); |
||||
if (!dispatcher.dispatch<WindowCloseEvent>(BK_BIND_DISPACHER_FN(WindowCloseEvent, OnWindowClose))) |
||||
{ |
||||
dispatcher.dispatch<WindowResizeEvent>(BK_BIND_DISPACHER_FN(WindowResizeEvent, OnWindowResize)); |
||||
for(auto it = p_layer_stack.ReverseBegin(); it != p_layer_stack.ReverseEnd(); it++) |
||||
{ |
||||
(*it)->OnEvent(e); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void Application::Close() |
||||
{ |
||||
p_running = false; |
||||
} |
||||
|
||||
bool Application::OnWindowResize(WindowResizeEvent& e) |
||||
{ |
||||
isMinimized = !e.GetWidth() && !e.GetHeight(); |
||||
Renderer::ResizeFrame(e.GetWidth(), e.GetHeight()); |
||||
return false; |
||||
} |
||||
|
||||
bool Application::OnWindowClose(WindowCloseEvent& e) |
||||
{ |
||||
Close(); |
||||
return true; |
||||
} |
||||
|
||||
void Application::Run()
|
||||
{ |
||||
while (p_running) |
||||
{ |
||||
if (!isMinimized) |
||||
for (Layer* layer : p_layer_stack) |
||||
layer->OnUpdate(h_window->GetTime()); |
||||
|
||||
imgui_layer->Begin(); |
||||
for (Layer* layer : p_layer_stack) |
||||
layer->ImguiRender(); |
||||
imgui_layer->End(); |
||||
h_window->OnUpdate(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
#pragma once |
||||
|
||||
namespace Bk |
||||
{ |
||||
class DeltaTime |
||||
{ |
||||
public: |
||||
DeltaTime(float time = 0.0f) : time(time) |
||||
{} |
||||
operator float() { return time; } |
||||
float GetSeconds() { return time; } |
||||
float GetMilliseconds() { return time *1000.0f; } |
||||
|
||||
private: |
||||
float time; |
||||
};
|
||||
} |
@ -0,0 +1,21 @@ |
||||
#include "application.h" |
||||
|
||||
/*! \file entry.cpp
|
||||
This file contains the entry point of the program. |
||||
*/ |
||||
|
||||
/*! \fn std::unique_ptr<Bk::Application> Bk::CreateApp()
|
||||
External function implemented client side. |
||||
*/ |
||||
extern Bk::Application* Bk::CreateApp(int argc, char** argv); |
||||
|
||||
/*! \fn int main(int argc, char** argv)
|
||||
Entry of the program. |
||||
*/ |
||||
int main(int argc, char** argv) { |
||||
Bk::Log::Init("Bakara"); |
||||
Bk::Application* app = Bk::CreateApp(argc, argv); |
||||
app->Run(); |
||||
delete app; |
||||
return 0; |
||||
} |
@ -0,0 +1,23 @@ |
||||
#pragma once |
||||
|
||||
#include "bakara/core/deltatime.h" |
||||
#include "bakara/events/event.h" |
||||
#include <string> |
||||
|
||||
namespace Bk { |
||||
class Layer
|
||||
{ |
||||
public: |
||||
Layer(const std::string& name = "Layer"); |
||||
~Layer() {} |
||||
|
||||
virtual void OnAttach() {} |
||||
virtual void OnDetach() {} |
||||
virtual void OnEvent(Event& e) {} |
||||
virtual void OnUpdate(DeltaTime dt) {} |
||||
virtual void ImguiRender() {} |
||||
const std::string ToString() const { return name; } |
||||
protected: |
||||
std::string name; |
||||
};
|
||||
} |
@ -0,0 +1,50 @@ |
||||
#include "layer_stack.h" |
||||
|
||||
namespace Bk { |
||||
LayerStack::~LayerStack() { clear(); } |
||||
|
||||
void LayerStack::PushOverlay(Layer* layer) |
||||
{ |
||||
layer->OnAttach(); |
||||
p_layers.emplace_back(layer); |
||||
} |
||||
|
||||
void LayerStack::PopOverlay(Layer* layer) |
||||
{ |
||||
auto it = std::find(p_layers.begin() + p_layer_index, p_layers.end(), layer); |
||||
if (it != p_layers.end()) |
||||
{ |
||||
layer->OnDetach(); |
||||
p_layers.erase(it); |
||||
} |
||||
} |
||||
|
||||
void LayerStack::PushLayer(Layer* layer) |
||||
{ |
||||
layer->OnAttach(); |
||||
p_layers.emplace(p_layers.begin() + p_layer_index, layer); |
||||
p_layer_index++; |
||||
} |
||||
|
||||
void LayerStack::PopLayer(Layer* layer) |
||||
{ |
||||
auto it = std::find(p_layers.begin(), p_layers.begin() + p_layer_index, layer); |
||||
if (it != p_layers.begin() + p_layer_index) |
||||
{ |
||||
layer->OnDetach(); |
||||
p_layers.erase(it); |
||||
p_layer_index--; |
||||
} |
||||
} |
||||
|
||||
void LayerStack::clear() |
||||
{ |
||||
std::for_each(p_layers.begin(), p_layers.end(), [](Layer* layer) |
||||
{ |
||||
layer->OnDetach(); |
||||
delete layer; |
||||
}); |
||||
p_layers.clear(); |
||||
p_layer_index = 0; |
||||
} |
||||
} |
@ -0,0 +1,31 @@ |
||||
#pragma once |
||||
|
||||
#include "layer.h" |
||||
#include <vector> |
||||
|
||||
namespace Bk { |
||||
class LayerStack |
||||
{ |
||||
public: |
||||
LayerStack() = default; |
||||
~LayerStack(); |
||||
|
||||
void PushOverlay(Layer* layer); |
||||
void PopOverlay(Layer* layer); |
||||
void PushLayer(Layer* layer); |
||||
void PopLayer(Layer* layer); |
||||
void clear(); |
||||
|
||||
std::vector<Layer*>::iterator begin() { return p_layers.begin(); } |
||||
std::vector<Layer*>::iterator end() { return p_layers.end(); } |
||||
std::vector<Layer*>::iterator Begin() { return p_layers.begin(); } |
||||
std::vector<Layer*>::iterator End() { return p_layers.end(); } |
||||
|
||||
std::vector<Layer*>::reverse_iterator ReverseBegin() { return p_layers.rbegin(); } |
||||
std::vector<Layer*>::reverse_iterator ReverseEnd() { return p_layers.rend(); } |
||||
|
||||
private: |
||||
std::vector<Layer*> p_layers; |
||||
uint p_layer_index = 0;
|
||||
}; |
||||
} |
@ -0,0 +1,28 @@ |
||||
#pragma once |
||||
|
||||
#include "bakara/events/event.h" |
||||
|
||||
namespace Bk { |
||||
class EventDispatcher |
||||
{ |
||||
public: |
||||
EventDispatcher(Event& event) |
||||
: p_event(event) {} |
||||
|
||||
// F will be deduced by the compiler
|
||||
template<typename T, typename F> |
||||
bool dispatch(const F& func) |
||||
{ |
||||
if (p_event.get_event_type() == T::get_static_type()) |
||||
{ |
||||
p_event.handled |= func(static_cast<T&>(p_event)); |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
inline Event& get_event() { return p_event; } |
||||
private: |
||||
Event& p_event; |
||||
}; |
||||
} |
@ -0,0 +1,5 @@ |
||||
#include <misc/cpp/imgui_stdlib.cpp> |
||||
|
||||
#define IMGUI_IMPL_OPENGL_LOADER_GLAD |
||||
#include <backends/imgui_impl_glfw.cpp> |
||||
#include <backends/imgui_impl_opengl3.cpp> |
@ -0,0 +1,77 @@ |
||||
#include "imgui_layer.h" |
||||
#include "bakara/core/application.h" |
||||
#include <imgui.h> |
||||
#include <imgui_internal.h> |
||||
#include <backends/imgui_impl_glfw.h> |
||||
#include <backends/imgui_impl_opengl3.h> |
||||
#include <GLFW/glfw3.h> |
||||
#include <glad/glad.h> |
||||
|
||||
namespace Bk { |
||||
void ImguiLayer::OnAttach()
|
||||
{ |
||||
IMGUI_CHECKVERSION(); |
||||
ImGui::CreateContext(); |
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
io.IniFilename = NULL; |
||||
#if defined(BK_IMGUI_DOCKING) |
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
|
||||
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
|
||||
io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons; |
||||
io.ConfigViewportsNoAutoMerge = true; |
||||
// When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones.
|
||||
ImGuiStyle& style = ImGui::GetStyle(); |
||||
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) |
||||
{ |
||||
style.WindowRounding = 0.0f; |
||||
style.Colors[ImGuiCol_WindowBg].w = 1.0f; |
||||
} |
||||
#endif |
||||
|
||||
// Setup Dear ImGui style
|
||||
ImGui::StyleColorsDark(); |
||||
//ImGui::StyleColorsClassic();
|
||||
|
||||
Application& app = Application::Get(); |
||||
GLFWwindow* window = static_cast<GLFWwindow*>(app.GetWindow().GetNativeWindow()); |
||||
|
||||
// Setup Platform/Renderer bindings
|
||||
ImGui_ImplGlfw_InitForOpenGL(window, true); |
||||
ImGui_ImplOpenGL3_Init("#version 420"); |
||||
} |
||||
|
||||
void ImguiLayer::OnDetach()
|
||||
{ |
||||
ImGui_ImplOpenGL3_Shutdown(); |
||||
ImGui_ImplGlfw_Shutdown(); |
||||
ImGui::DestroyContext(); |
||||
} |
||||
|
||||
void ImguiLayer::Begin() |
||||
{ |
||||
ImGuiIO& io = ImGui::GetIO(); |
||||
Application& app = Application::Get(); |
||||
io.DisplaySize = ImVec2((float)app.GetWindow().GetWidth(), (float)app.GetWindow().GetHeight()); |
||||
ImGui_ImplOpenGL3_NewFrame(); |
||||
ImGui_ImplGlfw_NewFrame(); |
||||
ImGui::NewFrame(); |
||||
} |
||||
|
||||
void ImguiLayer::End() |
||||
{ |
||||
// Rendering
|
||||
ImGui::Render(); |
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); |
||||
#if defined(BK_IMGUI_DOCKING) |
||||
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) |
||||
{ |
||||
GLFWwindow* backup_current_context = glfwGetCurrentContext(); |
||||
ImGui::UpdatePlatformWindows(); |
||||
ImGui::RenderPlatformWindowsDefault(); |
||||
glfwMakeContextCurrent(backup_current_context); |
||||
} |
||||
#endif |
||||
} |
||||
} |
@ -0,0 +1,18 @@ |
||||
#pragma once |
||||
|
||||
#include <imgui.h> |
||||
#include "bakara/core/layer.h" |
||||
|
||||
namespace Bk { |
||||
class ImguiLayer : public Layer
|
||||
{ |
||||
public: |
||||
ImguiLayer() |
||||
: Layer("Imgui") {} |
||||
|
||||
void OnAttach() override; |
||||
void OnDetach() override; |
||||
void Begin(); |
||||
void End(); |
||||
}; |
||||
} |
@ -0,0 +1,18 @@ |
||||
#pragma once |
||||
|
||||
#include "controller_codes.h" |
||||
|
||||
namespace Bk
|
||||
{ |
||||
class Controller { |
||||
public: |
||||
virtual void Update() = 0; |
||||
virtual float Axes(Code axis) = 0; |
||||
virtual unsigned char Button(Code button) = 0; |
||||
virtual int GetAxesCount() = 0; |
||||
virtual int GetButtonCount() = 0; |
||||
virtual bool IsPresent() = 0; |
||||
virtual const char* GetName() = 0; |
||||
}; |
||||
|
||||
} |
@ -0,0 +1,47 @@ |
||||
#pragma once |
||||
|
||||
#include <cstdint> |
||||
|
||||
namespace Bk { |
||||
/*! \typedef Bk::ControllerCode
|
||||
Unsigned integer representing a unique controller button |
||||
*/ |
||||
using Code = uint16_t; |
||||
/*! \enum Bk::ControllerButton
|
||||
Enumerator made to bind every controller buttons with a Bk::ControllerCode |
||||
*/ |
||||
typedef enum : Code |
||||
{
|
||||
BTN_DOWN = 0, //!< Cross, A
|
||||
BTN_LEFT = 1, //!< Square, X
|
||||
BTN_UP = 2, //!< Triangle, Y
|
||||
BTN_RIGHT = 3, //!< Circle, B
|
||||
SHOULDER_LEFT = 4, //!< L1, LB
|
||||
SHOULDER_RIGHT = 5, //!< R1, RB
|
||||
TRIGGER_LEFT = 6, //!< L2, LT
|
||||
TRIGGER_RIGHT = 7, //!< R2, RT
|
||||
SELECT = 8, //!< Share, Address
|
||||
START = 9, //!< Options, Menu
|
||||
LEFT_STICK = 10, //!< L3, LS
|
||||
RIGHT_STICK = 11, //!< R3, RS
|
||||
HOME = 12, //!< Home, Home
|
||||
CLICK = 13, //!< Touch pad, n/a
|
||||
DPAD_UP = 14, //!< Dpad up, Dpad up
|
||||
DPAD_RIGHT = 15, //!< Dpad right, Dpad right
|
||||
DPAD_DOWN = 16, //!< Dpad down, Dpad down
|
||||
DPAD_LEFT = 17, //!< Dpad left, Dpad left
|
||||
} ControllerButton; |
||||
|
||||
/*! \enum Bk::ControllerJoystick
|
||||
Enum made to bind every controller axes with a Bk::ControllerAxesCode |
||||
*/ |
||||
typedef enum : Code |
||||
{ |
||||
AXES_LEFT_STICK_X = 0, |
||||
AXES_LEFT_STICK_Y = 1, |
||||
AXES_RIGHT_STICK_X = 2, |
||||
AXES_LEFT_TRIGGER = 3, |
||||
AXES_RIGHT_TRIGGER = 4, |
||||
AXES_RIGHT_STICK_Y = 5, |
||||
} ControllerAxes; |
||||
} |
@ -0,0 +1,10 @@ |
||||
#pragma once |
||||
|
||||
/*! \file io_codes.h
|
||||
Input codes abstraction to be able to use different window api. |
||||
Can be converte in the good code for the window api by using a lookup table or defines at compilation. |
||||
*/ |
||||
|
||||
#include "key_codes.h" |
||||
#include "mouse_codes.h" |
||||
#include "controller_codes.h" |
@ -0,0 +1,14 @@ |
||||
#pragma once |
||||
|
||||
#include "key_codes.h" |
||||
|
||||
namespace Bk
|
||||
{ |
||||
class Keyboard
|
||||
{ |
||||
public: |
||||
static bool KeyRepeat(Code key); |
||||
static bool KeyUp(Code key); |
||||
static bool KeyDown(Code key); |
||||
}; |
||||
} |
@ -0,0 +1,15 @@ |
||||
#pragma once |
||||
|
||||
#include "bakara/math/types.h" |
||||
#include "mouse_codes.h" |
||||
|
||||
namespace Bk
|
||||
{ |
||||
class Mouse { |
||||
public: |
||||
static Vec2 GetPosition(); |
||||
static bool ButtonUp(Code button); |
||||
static bool ButtonDown(Code button); |
||||
static bool ButtonRepeat(Code button); |
||||
}; |
||||
} |
@ -0,0 +1,30 @@ |
||||
#pragma once |
||||
|
||||
#include <cstdint> |
||||
|
||||
namespace Bk { |
||||
/*! \typedef Bk::MouseCode
|
||||
Unsigned integer representing a unique mouse button |
||||
*/ |
||||
using Code = uint16_t; |
||||
|
||||
/*! \enum Bk::MouseCodes
|
||||
Enumerator made to bind every mouse buttons with a Bk::MouseCode |
||||
*/ |
||||
typedef enum : Code |
||||
{ |
||||
Button0 = 0, /*!< Button left */ |
||||
Button1 = 1, /*!< Button right */ |
||||
Button2 = 2, /*!< Button middle */ |
||||
Button3 = 3, /*!< Macro1 */ |
||||
Button4 = 4, /*!< Macro2 */ |
||||
Button5 = 5, /*!< Macro3 */ |
||||
Button6 = 6, /*!< Macro4 */ |
||||
Button7 = 7, /*!< Button last */ |
||||
|
||||
ButtonLast = Button7, |
||||
ButtonLeft = Button0, |
||||
ButtonRight = Button1, |
||||
ButtonMiddle = Button2 |
||||
} MouseCode; |
||||
} |
@ -0,0 +1,30 @@ |
||||
#include "buffer.h" |
||||
#include "bakara/renderer/renderer.h" |
||||
#include "bakatools/container/types.h" |
||||
#include "bakatools/logging/assert.h" |
||||
#include "platforms/opengl/opengl_buffer.h" |
||||
|
||||
namespace Bk |
||||
{ |
||||
Ref<VertexBuffer> VertexBuffer::Create(float *vertices, u32 size) |
||||
{ |
||||
switch (Renderer::GetAPI())
|
||||
{ |
||||
case Renderer::API::None: BK_MSG_ASSERT(false, "API not supported"); return nullptr; |
||||
case Renderer::API::Opengl: return CreateRef<Platform::OpenglVertexBuffer>(vertices, size); |
||||
} |
||||
BK_MSG_ASSERT(false, "API not supported");
|
||||
return nullptr; |
||||
} |
||||
|
||||
Ref<IndexBuffer> IndexBuffer::Create(u32* indices, u32 count) |
||||
{ |
||||
switch (Renderer::GetAPI())
|
||||
{ |
||||
case Renderer::API::None: BK_MSG_ASSERT(false, "API not supported"); return nullptr; |
||||
case Renderer::API::Opengl: return CreateRef<Platform::OpenglIndexBuffer>(indices, count); |
||||
} |
||||
BK_MSG_ASSERT(false, "API not supported");
|
||||
return nullptr; |
||||
} |
||||
} |
@ -0,0 +1,27 @@ |
||||
#pragma once |
||||
#include "bakara/renderer/buffer_layout.h" |
||||
#include "bakatools/container/types.h" |
||||
|
||||
namespace Bk |
||||
{ |
||||
class VertexBuffer
|
||||
{ |
||||
public: |
||||
virtual ~VertexBuffer() {} |
||||
virtual void Bind() = 0; |
||||
virtual void Unbind() = 0; |
||||
virtual void SetLayout(BufferLayout layout) = 0; |
||||
virtual BufferLayout& GetLayout() = 0; |
||||
static Ref<VertexBuffer> Create(float* vertices, u32 size); |
||||
}; |
||||
|
||||
class IndexBuffer
|
||||
{ |
||||
public: |
||||
virtual ~IndexBuffer() {} |
||||
virtual void Bind() = 0; |
||||
virtual void Unbind() = 0; |
||||
virtual u32 GetCount() = 0; |
||||
static Ref<IndexBuffer> Create(u32* indices, u32 count); |
||||
}; |
||||
} |
@ -0,0 +1,56 @@ |
||||
#include "buffer_layout.h" |
||||
|
||||
namespace Bk
|
||||
{ |
||||
u32 ShaderType::Size() |
||||
{ |
||||
switch (type)
|
||||
{ |
||||
case None: return 0; |
||||
case Bool: return 1; |
||||
case Int: return 4; |
||||
case Int2: return 4 * 2; |
||||
case Int3: return 4 * 3; |
||||
case Int4: return 4 * 4; |
||||
case Float: return 4; |
||||
case Float2: return 4 * 2; |
||||
case Float3: return 4 * 3; |
||||
case Float4: return 4 * 4; |
||||
case Mat3: return 4 * 3 * 3; |
||||
case Mat4: return 4 * 4 * 4; |
||||
} |
||||
} |
||||
|
||||
u32 ShaderType::Count() |
||||
{ |
||||
switch (type)
|
||||
{ |
||||
case None: return 0; |
||||
case Bool: return 1; |
||||
case Int: return 1; |
||||
case Int2: return 2; |
||||
case Int3: return 3; |
||||
case Int4: return 4; |
||||
case Float: return 1; |
||||
case Float2: return 2; |
||||
case Float3: return 3; |
||||
case Float4: return 4; |
||||
case Mat3: return 3 * 3; |
||||
case Mat4: return 4 * 4; |
||||
} |
||||
} |
||||
|
||||
void BufferLayout::CalculteOffsetAndStride() |
||||
{ |
||||
u32 offset = 0; |
||||
stride = 0; |
||||
for(auto& element : elements) |
||||
{ |
||||
element.offset = offset; |
||||
offset += element.type.Size(); |
||||
stride += element.type.Size(); |
||||
|
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,70 @@ |
||||
#pragma once |
||||
|
||||
#include "bakatools/container/types.h" |
||||
#include <initializer_list> |
||||
#include <vector> |
||||
#include <string> |
||||
|
||||
namespace Bk |
||||
{ |
||||
class ShaderType |
||||
{ |
||||
public: |
||||
enum Type : u8 |
||||
{ |
||||
None = 0,
|
||||
Bool, Int, Int2, Int3, Int4, |
||||
Float, Float2, Float3, Float4, |
||||
Mat3, Mat4 |
||||
}; |
||||
ShaderType() : type(None) {} |
||||
ShaderType(Type type) : type(type) {} |
||||
|
||||
ShaderType& operator=(Type value) { type = value; return *this; } |
||||
operator Type() const { return type; } |
||||
bool operator==(Type type) { return type == this->type; } |
||||
bool operator!=(Type type) { return type != this->type; } |
||||
bool operator==(ShaderType value) { return value.type == this->type; } |
||||
bool operator!=(ShaderType value) { return value.type != this->type; } |
||||
|
||||
u32 Size(); |
||||
u32 Count(); |
||||
private: |
||||
Type type; |
||||
}; |
||||
|
||||
struct BufferElement |
||||
{
|
||||
std::string name; |
||||
u32 offset; |
||||
ShaderType type; |
||||
bool normelized; |
||||
|
||||
BufferElement() = default; |
||||
|
||||
BufferElement(std::string name, ShaderType type, bool normelized = false) |
||||
: name(name), type(type) {} |
||||
|
||||
BufferElement(ShaderType type, std::string name, bool normelized = false) |
||||
: name(name), type(type), normelized(normelized) {} |
||||
}; |
||||
|
||||
class BufferLayout
|
||||
{ |
||||
public: |
||||
BufferLayout() = default; |
||||
|
||||
BufferLayout(const std::initializer_list<BufferElement>& elements) |
||||
: elements(elements) { CalculteOffsetAndStride(); } |
||||
|
||||
inline u32 GetStride() { return stride; } |
||||
inline std::vector<BufferElement>& GetElements() { return elements; } |
||||
|
||||
std::vector<BufferElement>::iterator begin() { return elements.begin(); } |
||||
std::vector<BufferElement>::iterator end() { return elements.end(); } |
||||
private: |
||||
void CalculteOffsetAndStride(); |
||||
std::vector<BufferElement> elements; |
||||
u32 stride; |
||||
}; |
||||
} |
@ -0,0 +1,29 @@ |
||||
#include "ortho_camera.h" |
||||
#include "bakara/math/types.h" |
||||
#include "glm/ext/matrix_clip_space.hpp" |
||||
#include "glm/ext/matrix_transform.hpp" |
||||
#include "glm/matrix.hpp" |
||||
#include "glm/trigonometric.hpp" |
||||
|
||||
namespace Bk
|
||||
{ |
||||
OrthoCamera::OrthoCamera(float left, float right, float bottom, float top) |
||||
: projection(Math::ortho(left, right, bottom, top, -10.0f, 10.0f)) |
||||
{ |
||||
RecalculateView(); |
||||
} |
||||
|
||||
void OrthoCamera::SetProjection(float left, float right, float bottom, float top) |
||||
{ |
||||
projection = Math::ortho(left, right, bottom, top, -10.0f, 10.0f); |
||||
viewProjection = projection * view; |
||||
} |
||||
|
||||
void OrthoCamera::RecalculateView() |
||||
{ |
||||
Mat4 transform = Math::translate(Mat4(1.0f), position);
|
||||
transform = Math::rotate(transform, Math::radians(rotation) , Vec3(0.0f, 0.0f, 1.0f)); |
||||
view = Math::inverse(transform); |
||||
viewProjection = projection * view; |
||||
} |
||||
} |
@ -0,0 +1,31 @@ |
||||
#pragma once |
||||
|
||||
#include "bakara/math/types.h" |
||||
|
||||
namespace Bk
|
||||
{ |
||||
class OrthoCamera |
||||
{ |
||||
public: |
||||
OrthoCamera(float left, float right, float bottom, float top); |
||||
|
||||
void SetPosition(Vec3 position) { this->position = position; RecalculateView(); } |
||||
const Vec3& GetPosition() const { return position; } |
||||
void SetRotation(float rotation) { this->rotation = rotation; RecalculateView(); } |
||||
float GetRotaion() const { return rotation; } |
||||
|
||||
const Mat4 GetView() const { return view; } |
||||
void SetProjection(float left, float right, float bottom, float top); |
||||
const Mat4 GetProjection() const { return projection; } |
||||
const Mat4 GetViewProjection() const { return viewProjection; } |
||||
|
||||
private: |
||||
void RecalculateView(); |
||||
Mat4 view; |
||||
Mat4 projection; |
||||
Mat4 viewProjection; |
||||
|
||||
Vec3 position = { 0.0f, 0.0f, 0.0f }; |
||||
float rotation = 0.0f; |
||||
}; |
||||
} |
@ -0,0 +1,76 @@ |
||||
#include "ortho_camera_controller.h" |
||||
#include "bakara/events/dispacher.h" |
||||
#include "bakara/events/event.h" |
||||
#include "bakara/events/window_event.h" |
||||
#include "bakara/io/keyboard.h" |
||||
#include "glm/trigonometric.hpp" |
||||
#include <cmath> |
||||
|
||||
namespace Bk |
||||
{ |
||||
OrthoCameraController::OrthoCameraController(float aspectRatio, bool rotation, bool zoom) |
||||
: aspectRatio(aspectRatio),
|
||||
camera(-aspectRatio * zoomLevel, aspectRatio * zoomLevel, -zoomLevel, zoomLevel),
|
||||
rotation(rotation), zoom(zoom) {} |
||||
|
||||
void OrthoCameraController::OnEvent(Event& e) |
||||
{ |
||||
EventDispatcher dispatcher(e); |
||||
dispatcher.dispatch<WindowResizeEvent>(BK_BIND_DISPACHER_FN(WindowResizeEvent, OnWindowResize)); |
||||
dispatcher.dispatch<MouseScrollEvent>(BK_BIND_DISPACHER_FN(MouseScrollEvent, OnMouseScroll)); |
||||
} |
||||
|
||||
void OrthoCameraController::OnUpdate(DeltaTime dt) |
||||
{ |
||||
if (rotation)
|
||||
{ |
||||
if(Keyboard::KeyDown(KeyCode::Q)) |
||||
cameraRotation -= rotationSpeed * dt; |
||||
if(Keyboard::KeyDown(KeyCode::E)) |
||||
cameraRotation += rotationSpeed * dt; |
||||
camera.SetRotation(cameraRotation); |
||||
} |
||||
|
||||
if(Keyboard::KeyDown(KeyCode::W)) |
||||
{ |
||||
cameraPosition.x += -std::sin(Math::radians(cameraRotation)) * moveSpeed * dt; |
||||
cameraPosition.y += std::cos(Math::radians(cameraRotation)) * moveSpeed * dt; |
||||
} |
||||
if(Keyboard::KeyDown(KeyCode::S)) |
||||
{ |
||||
cameraPosition.x -= -std::sin(Math::radians(cameraRotation)) * moveSpeed * dt; |
||||
cameraPosition.y -= std::cos(Math::radians(cameraRotation)) * moveSpeed * dt; |
||||
} |
||||
if(Keyboard::KeyDown(KeyCode::D)) |
||||
{ |
||||
cameraPosition.x += std::cos(Math::radians(cameraRotation)) * moveSpeed * dt; |
||||
cameraPosition.y += std::sin(Math::radians(cameraRotation)) * moveSpeed * dt; |
||||
} |
||||
if(Keyboard::KeyDown(KeyCode::A))
|
||||
{ |
||||
cameraPosition.x -= std::cos(Math::radians(cameraRotation)) * moveSpeed * dt; |
||||
cameraPosition.y -= std::sin(Math::radians(cameraRotation)) * moveSpeed * dt; |
||||
} |
||||
camera.SetPosition(cameraPosition); |
||||
} |
||||
|
||||
bool OrthoCameraController::OnMouseScroll(MouseScrollEvent& e) |
||||
{ |
||||
if (zoom)
|
||||
{ |
||||
zoomLevel -= e.GetDY() * 0.01; |
||||
zoomLevel = std::max(zoomLevel, 0.5f); |
||||
zoomLevel = std::min(zoomLevel, 10.0f); |
||||
camera.SetProjection(-aspectRatio * zoomLevel, aspectRatio * zoomLevel, -zoomLevel, zoomLevel); |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
bool OrthoCameraController::OnWindowResize(WindowResizeEvent& e) |
||||
{ |
||||
aspectRatio = (float)e.GetWidth() / (float)e.GetHeight(); |
||||
camera.SetProjection(-aspectRatio * zoomLevel, aspectRatio * zoomLevel, -zoomLevel, zoomLevel); |
||||
return false; |
||||
} |
||||
} |
@ -0,0 +1,41 @@ |
||||
#pragma once |
||||
|
||||
#include "bakara/core/deltatime.h" |
||||
#include "bakara/events/event.h" |
||||
#include "bakara/events/mouse_event.h" |
||||
#include "bakara/events/window_event.h" |
||||
#include "ortho_camera.h" |
||||
|
||||
namespace Bk
|
||||
{ |
||||
class OrthoCameraController |
||||
{ |
||||
public: |
||||
OrthoCameraController(float aspectRatio, bool rotation = false, bool zoom = false); |
||||
|
||||
void OnUpdate(DeltaTime dt); |
||||
void OnEvent(Event& e); |
||||
|
||||
const OrthoCamera& GetCamera() { return camera; } |
||||
|
||||
void SetMoveSpeed(float moveSpeed) { this->moveSpeed = moveSpeed; } |
||||
void SetRotationSpeed(float rotationSpeed) { this->rotationSpeed = rotationSpeed; } |
||||
void SetZoomLevel(float level) { zoomLevel = level; } |
||||
void SetPosition(Vec3 cameraPosition) { this->cameraPosition = cameraPosition; } |
||||
|
||||
private: |
||||
float aspectRatio; |
||||
float zoomLevel = 1.0f; |
||||
|
||||
bool rotation, zoom; |
||||
float cameraRotation = 0.0f; |
||||
Vec3 cameraPosition = { 0, 0, 0 }; |
||||
float moveSpeed = 1.0f; |
||||
float rotationSpeed = 1.0f; |
||||
|
||||
OrthoCamera camera; |
||||
|
||||
bool OnMouseScroll(MouseScrollEvent& e); |
||||
bool OnWindowResize(WindowResizeEvent& e); |
||||
}; |
||||
} |
@ -0,0 +1,18 @@ |
||||
#include "graphics_context.h" |
||||
#include "bakara/renderer/renderer.h" |
||||
#include "bakatools/logging/assert.h" |
||||
#include "platforms/opengl/opengl_context.h" |
||||
|
||||
namespace Bk
|
||||
{ |
||||
Scope<GraphicsContext> GraphicsContext::Create(void *window_handle) |
||||
{ |
||||
switch (Renderer::GetAPI())
|
||||
{ |
||||
case Renderer::API::None: BK_MSG_ASSERT(false, "API not supported"); return nullptr; |
||||
case Renderer::API::Opengl: return CreateScope<Platform::OpenglContext>(window_handle); |
||||
} |
||||
BK_MSG_ASSERT(false, "API not supported");
|
||||
return nullptr; |
||||
} |
||||
} |
@ -0,0 +1,15 @@ |
||||
#pragma once |
||||
|
||||
#include "bakatools/container/types.h" |
||||
namespace Bk
|
||||
{ |
||||
class GraphicsContext |
||||
{ |
||||
public: |
||||
virtual ~GraphicsContext() {} |
||||
virtual void Init() = 0; |
||||
virtual void SwapBuffers() = 0; |
||||
|
||||
static Scope<GraphicsContext> Create(void* window_handle); |
||||
}; |
||||
} |
@ -0,0 +1,8 @@ |
||||
#include "render_command.h" |
||||
#include "bakara/renderer/renderer_api.h" |
||||
#include "platforms/opengl/opengl_renderer_api.h" |
||||
|
||||
namespace Bk
|
||||
{ |
||||
RendererAPI* RenderCommand::rendererAPI = new OpenglRendererAPI(); |
||||
} |
@ -0,0 +1,20 @@ |
||||
#pragma once |
||||
|
||||
#include "bakara/math/types.h" |
||||
#include "bakara/renderer/renderer_api.h" |
||||
#include "bakara/renderer/vertex_array.h" |
||||
|
||||
namespace Bk
|
||||
{ |
||||
class RenderCommand |
||||
{ |
||||
public: |
||||
static inline void Init() { rendererAPI->Init(); } |
||||
static inline void Clear(Vec4 color) { rendererAPI->Clear(color.r, color.g, color.b, color.a); } |
||||
static inline void Clear(float red, float green, float blue, float alpha) { rendererAPI->Clear(red, green, blue, alpha); } |
||||
static inline void SetViewport(u32 width, u32 height) { rendererAPI->SetViewport(width, height); } |
||||
static inline void DrawIndexed(Ref<VertexArray> va) { rendererAPI->DrawIndexed(va); } |
||||
private: |
||||
static RendererAPI* rendererAPI; |
||||
}; |
||||
} |
@ -0,0 +1,39 @@ |
||||
#include "renderer.h" |
||||
#include "bakara/renderer/cameras/ortho_camera.h" |
||||
#include "bakara/renderer/render_command.h" |
||||
#include "bakara/renderer/renderer2D.h" |
||||
namespace Bk
|
||||
{ |
||||
Renderer::API Renderer::s_RenderAPI = Renderer::API::Opengl; |
||||
Renderer::Storage* Renderer::data = new Renderer::Storage(); |
||||
|
||||
void Renderer::Init() |
||||
{ |
||||
RenderCommand::Init(); |
||||
Renderer2D::Init(); |
||||
} |
||||
|
||||
void Renderer::ResizeFrame(u32 width, u32 height) |
||||
{ |
||||
RenderCommand::SetViewport(width, height); |
||||
} |
||||
|
||||
void Renderer::BeginScene(const OrthoCamera& camera) |
||||
{ |
||||
data->viewProjection = camera.GetViewProjection(); |
||||
} |
||||
|
||||
void Renderer::EndScene() |
||||
{ |
||||
|
||||
} |
||||
|
||||
void Renderer::Submit(Ref<VertexArray> va, Ref<Shader> shader, Mat4 transform) |
||||
{ |
||||
va->Bind(); |
||||
shader->Bind(); |
||||
shader->Set("u_ViewProjection", data->viewProjection); |
||||
shader->Set("u_Transform", transform); |
||||
RenderCommand::DrawIndexed(va); |
||||
}
|
||||
} |
@ -0,0 +1,38 @@ |
||||
#pragma once |
||||
|
||||
#include "bakara/math/types.h" |
||||
#include "bakara/renderer/cameras/ortho_camera.h" |
||||
#include "bakara/renderer/shader.h" |
||||
#include "bakara/renderer/vertex_array.h" |
||||
#include "bakatools/container/types.h" |
||||
|
||||
namespace Bk
|
||||
{ |
||||
class Renderer |
||||
{ |
||||
public: |
||||
enum class API
|
||||
{ |
||||
None = 0, |
||||
Opengl = 1, |
||||
}; |
||||
|
||||
static API GetAPI() { return s_RenderAPI; } |
||||
|
||||
static void Init(); |
||||
|
||||
static void ResizeFrame(u32 width, u32 height); |
||||
|
||||
static void BeginScene(const OrthoCamera& camera); |
||||
static void EndScene(); |
||||
|
||||
static void Submit(Ref<VertexArray> va, Ref<Shader> shader, Mat4 transform = Mat4(1.0f));
|
||||
private: |
||||
struct Storage
|
||||
{ |
||||
Mat4 viewProjection; |
||||
}; |
||||
static Storage* data; |
||||
static API s_RenderAPI; |
||||
}; |
||||
} |
@ -0,0 +1,81 @@ |
||||
#include "renderer2D.h" |
||||
#include "bakara/renderer/buffer.h" |
||||
#include "bakara/renderer/buffer_layout.h" |
||||
#include "bakara/renderer/render_command.h" |
||||
#include "bakara/renderer/texture.h" |
||||
|
||||
namespace Bk
|
||||
{ |
||||
Renderer2D::Storage* Renderer2D::data = new Renderer2D::Storage(); |
||||
|
||||
void Renderer2D::Init() |
||||
{ |
||||
data->shaderLib.Load("assets/shaders/flatColor.glsl"); |
||||
data->shaderLib.Load("assets/shaders/texture.glsl"); |
||||
data->squareVA = VertexArray::Create(); |
||||
|
||||
float squareVertices[5 * 4] = { |
||||
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, |
||||
0.5f, -0.5f, 0.0f, 1.0f, 0.0f, |
||||
0.5f, 0.5f, 0.0f, 1.0f, 1.0f, |
||||
-0.5f, 0.5f, 0.0f, 0.0f, 1.0f |
||||
}; |
||||
Ref<VertexBuffer> squareVB = VertexBuffer::Create(squareVertices, sizeof(squareVertices)); |
||||
squareVB->SetLayout({ |
||||
{ ShaderType::Float3, "a_Position" }, |
||||
{ ShaderType::Float2, "a_TextCord" } |
||||
}); |
||||
data->squareVA->AddVertexBuffer(squareVB); |
||||
|
||||
u32 squareIndices[6] = { 0, 1, 2, 0, 2, 3 }; |
||||
data->squareVA->SetIndexbuffer(IndexBuffer::Create(squareIndices, sizeof(squareIndices) / sizeof(u32)));
|
||||
} |
||||
|
||||
void Renderer2D::Shutdown() |
||||
{ |
||||
delete data; |
||||
} |
||||
|
||||
void Renderer2D::BeginScene(const OrthoCamera &camera) |
||||
{ |
||||
data->viewProjection = camera.GetViewProjection();
|
||||
} |
||||
|
||||
void Renderer2D::EndScene() |
||||
{ |
||||
|
||||
} |
||||
|
||||
void Renderer2D::DrawQuad(const Vec2& position, const Vec2& size, const Color& color) |
||||
{ |
||||
Renderer2D::DrawQuad(Vec3(position, 0), size, color); |
||||
} |
||||
|
||||
void Renderer2D::DrawQuad(const Vec3& position, const Vec2& size, const Color& color) |
||||
{ |
||||
Ref<Shader> shader = data->shaderLib["flatColor"]; |
||||
data->squareVA->Bind(); |
||||
shader->Bind(); |
||||
shader->Set("u_FlatColor", color); |
||||
shader->Set("u_ViewProjection", data->viewProjection); |
||||
shader->Set("u_Transform", Math::scale(Math::translate(Mat4(1.0f), position), Vec3(size, 0))); |
||||
RenderCommand::DrawIndexed(data->squareVA); |
||||
} |
||||
|
||||
void Renderer2D::DrawQuad(const Vec2& position, const Vec2& size, const Ref<Texture2D>& texture) |
||||
{ |
||||
Renderer2D::DrawQuad(Vec3(position, 0), size, texture); |
||||
} |
||||
|
||||
void Renderer2D::DrawQuad(const Vec3& position, const Vec2& size, const Ref<Texture2D>& texture) |
||||
{ |
||||
Ref<Shader> shader = data->shaderLib["texture"]; |
||||
data->squareVA->Bind(); |
||||
texture->Bind(); |
||||
shader->Bind(); |
||||
shader->Set("u_Texture", 0); |
||||
shader->Set("u_ViewProjection", data->viewProjection); |
||||
shader->Set("u_Transform", Math::scale(Math::translate(Mat4(1.0f), position), Vec3(size, 0))); |
||||
RenderCommand::DrawIndexed(data->squareVA); |
||||
} |
||||
} |
@ -0,0 +1,33 @@ |
||||
#pragma once |
||||
|
||||
#include "bakara/renderer/shader.h" |
||||
#include "bakara/renderer/texture.h" |
||||
#include "bakara/renderer/vertex_array.h" |
||||
#include "cameras/ortho_camera.h" |
||||
|
||||
namespace Bk
|
||||
{ |
||||
class Renderer2D
|
||||
{ |
||||
public: |
||||
static void Init(); |
||||
static void Shutdown(); |
||||
|
||||
static void BeginScene(const OrthoCamera& camera); |
||||
static void EndScene(); |
||||
|
||||
static void DrawQuad(const Vec2& position, const Vec2& size, const Color& color); |
||||
static void DrawQuad(const Vec3& position, const Vec2& size, const Color& color); |
||||
static void DrawQuad(const Vec2& position, const Vec2& size, const Ref<Texture2D>& texture); |
||||
static void DrawQuad(const Vec3& position, const Vec2& size, const Ref<Texture2D>& texture); |
||||
private: |
||||
struct Storage |
||||
{ |
||||
Mat4 viewProjection; |
||||
Ref<VertexArray> squareVA; |
||||
ShaderLibrary shaderLib; |
||||
};
|
||||
|
||||
static Storage* data;
|
||||
}; |
||||
} |
@ -0,0 +1,17 @@ |
||||
#pragma once |
||||
|
||||
#include "bakara/renderer/vertex_array.h" |
||||
|
||||
namespace Bk
|
||||
{ |
||||
class RendererAPI |
||||
{ |
||||
public: |
||||
virtual ~RendererAPI() {} |
||||
|
||||
virtual void Init() = 0; |
||||
virtual void Clear(float red, float green, float blue, float alpha) = 0; |
||||
virtual void SetViewport(u32 width, u32 height) = 0; |
||||
virtual void DrawIndexed(Ref<VertexArray> va) = 0; |
||||
}; |
||||
} |
@ -0,0 +1,60 @@ |
||||
#include "shader.h" |
||||
#include "bakara/renderer/renderer.h" |
||||
#include "bakatools/logging/assert.h" |
||||
#include "platforms/opengl/opengl_shader.h" |
||||
|
||||
namespace Bk |
||||
{ |
||||
Ref<Shader> Shader::Create(const std::string& name, const std::string& vertexSrc, const std::string& fragSrc) |
||||
{ |
||||
switch(Renderer::GetAPI()) |
||||
{ |
||||
case Renderer::API::None: BK_MSG_ASSERT(false, "API not supported"); return nullptr; |
||||
case Renderer::API::Opengl: return CreateRef<Platform::OpenglShader>(name, vertexSrc, fragSrc); |
||||
} |
||||
BK_MSG_ASSERT(false, "API not supported");
|
||||
return nullptr; |
||||
} |
||||
Ref<Shader> Shader::Create(const std::string& filePath) |
||||
{ |
||||
switch(Renderer::GetAPI()) |
||||
{ |
||||
case Renderer::API::None: BK_MSG_ASSERT(false, "API not supported"); return nullptr; |
||||
case Renderer::API::Opengl: return CreateRef<Platform::OpenglShader>(filePath); |
||||
} |
||||
BK_MSG_ASSERT(false, "API not supported");
|
||||
return nullptr; |
||||
} |
||||
|
||||
void ShaderLibrary::Add(const std::string& name, const Ref<Shader>& shader) |
||||
{ |
||||
BK_CORE_MSG_ASSERT(!Exists(name), "Shader already exists in library") |
||||
shaders[name] = shader; |
||||
} |
||||
|
||||
void ShaderLibrary::Add(const Ref<Shader>& shader) |
||||
{ |
||||
const auto& name = shader->GetName(); |
||||
Add(shader->GetName(), shader); |
||||
} |
||||
|
||||
Ref<Shader> ShaderLibrary::Load(const std::string& filePath) |
||||
{ |
||||
Ref<Shader> shader = Shader::Create(filePath); |
||||
Add(shader); |
||||
return shader; |
||||
} |
||||
|
||||
Ref<Shader> ShaderLibrary::Load(const std::string& name, const std::string filePath) |
||||
{ |
||||
Ref<Shader> shader = Shader::Create(filePath); |
||||
Add(name, shader); |
||||
return shader; |
||||
} |
||||
|
||||
Ref<Shader> ShaderLibrary::Get(const std::string& name) |
||||
{ |
||||
BK_CORE_MSG_ASSERT(Exists(name), "Shader not found") |
||||
return shaders[name]; |
||||
} |
||||
} |
@ -0,0 +1,49 @@ |
||||
#pragma once |
||||
|
||||
#include "bakara/math/types.h" |
||||
#include "bakatools/container/types.h" |
||||
#include <string> |
||||
#include <unordered_map> |
||||
|
||||
namespace Bk |
||||
{ |
||||
class Shader
|
||||
{ |
||||
public: |
||||
virtual ~Shader() {} |
||||
|
||||
virtual const std::string& GetName() = 0; |
||||
|
||||
virtual void Bind() = 0; |
||||
virtual void Unbind() = 0; |
||||
|
||||
virtual void Set(const std::string name, int val) = 0; |
||||
virtual void Set(const std::string name, bool val) = 0; |
||||
virtual void Set(const std::string name, float val) = 0; |
||||
virtual void Set(const std::string name, float v1, float v2, float v3) = 0; |
||||
virtual void Set(const std::string name, Vec3 v) = 0; |
||||
virtual void Set(const std::string name, float v1, float v2, float v3, float v4) = 0; |
||||
virtual void Set(const std::string name, Vec4 v) = 0; |
||||
virtual void Set(const std::string name, Mat3 val) = 0; |
||||
virtual void Set(const std::string name, Mat4 val) = 0; |
||||
|
||||
static Ref<Shader> Create(const std::string& name, const std::string& vertexSrc, const std::string& fragSrc); |
||||
static Ref<Shader> Create(const std::string& filePath); |
||||
}; |
||||
|
||||
class ShaderLibrary |
||||
{ |
||||
public: |
||||
inline bool Exists(const std::string& name) { return shaders.find(name) != shaders.end(); } |
||||
|
||||
void Add(const std::string& name, const Ref<Shader>& shader); |
||||
void Add(const Ref<Shader>& shader); |
||||
Ref<Shader> Load(const std::string& filePath); |
||||
Ref<Shader> Load(const std::string& name, const std::string filePath); |
||||
|
||||
Ref<Shader> Get(const std::string& name); |
||||
inline Ref<Shader> operator[](const std::string& name) { return Get(name); } |
||||
private: |
||||
std::unordered_map<std::string, Ref<Shader>> shaders; |
||||
}; |
||||
} |
@ -0,0 +1,18 @@ |
||||
#include "bakara/renderer/renderer.h" |
||||
#include "bakatools/logging/assert.h" |
||||
#include "texture.h" |
||||
#include "platforms/opengl/opengl_texture.h" |
||||
|
||||
namespace Bk |
||||
{ |
||||
Ref<Texture2D> Texture2D::Create(const std::string& filePath) |
||||
{ |
||||
switch (Renderer::GetAPI())
|
||||
{ |
||||
case Renderer::API::None: BK_MSG_ASSERT(false, "API not supported"); return nullptr; |
||||
case Renderer::API::Opengl: return CreateRef<Platform::OpenglTexture2D>(filePath); |
||||
} |
||||
BK_MSG_ASSERT(false, "API not supported");
|
||||
return nullptr; |
||||
} |
||||
} |
@ -0,0 +1,22 @@ |
||||
#pragma once |
||||
|
||||
#include "bakatools/container/types.h" |
||||
#include <string> |
||||
|
||||
namespace Bk
|
||||
{ |
||||
class Texture
|
||||
{ |
||||
public: |
||||
virtual ~Texture() {} |
||||
virtual u32 GetWidth() = 0; |
||||
virtual u32 GetHeight() = 0; |
||||
virtual void Bind(u32 slot = 0) = 0; |
||||
}; |
||||
|
||||
class Texture2D : public Texture |
||||
{ |
||||
public: |
||||
static Ref<Texture2D> Create(const std::string& filePath); |
||||
}; |
||||
} |
@ -0,0 +1,18 @@ |
||||
#include "bakara/renderer/renderer.h" |
||||
#include "bakatools/logging/assert.h" |
||||
#include "vertex_array.h" |
||||
#include "platforms/opengl/opengl_vertex_array.h" |
||||
|
||||
namespace Bk |
||||
{ |
||||
Ref<VertexArray> VertexArray::Create() |
||||
{ |
||||
switch (Renderer::GetAPI())
|
||||
{ |
||||
case Renderer::API::None: BK_MSG_ASSERT(false, "API not supported"); return nullptr; |
||||
case Renderer::API::Opengl: return CreateRef<Platform::OpenglVertexArray>(); |
||||
} |
||||
BK_MSG_ASSERT(false, "API not supported");
|
||||
return nullptr; |
||||
} |
||||
} |
@ -0,0 +1,21 @@ |
||||
#pragma once |
||||
|
||||
#include "bakara/renderer/buffer.h" |
||||
#include "bakatools/container/types.h" |
||||
|
||||
namespace Bk |
||||
{ |
||||
class VertexArray
|
||||
{ |
||||
public: |
||||
virtual ~VertexArray() {} |
||||
virtual void Bind() = 0; |
||||
virtual void Unbind() = 0; |
||||
virtual void AddVertexBuffer(Ref<VertexBuffer> buf) = 0; |
||||
virtual void SetIndexbuffer(Ref<IndexBuffer> buf) = 0; |
||||
|
||||
virtual std::vector<Ref<VertexBuffer>> GetVertexBuffers() = 0; |
||||
virtual Ref<IndexBuffer> GetIndexbuffer() = 0; |
||||
static Ref<VertexArray> Create(); |
||||
}; |
||||
} |
@ -0,0 +1,4 @@ |
||||
#include "glfw_controller.h" |
||||
|
||||
#include <GLFW/glfw3.h> |
||||
|
@ -0,0 +1,35 @@ |
||||
#pragma once |
||||
|
||||
#include "bakara/io/controller.h" |
||||
|
||||
namespace Bk
|
||||
{ |
||||
namespace Platform
|
||||
{ |
||||
class ControllerGLFW : public Controller
|
||||
{ |
||||
public: |
||||
ControllerGLFW() = delete; |
||||
ControllerGLFW(int i); |
||||
|
||||
void Update() override; |
||||
float Axes(Code axis) override; |
||||
unsigned char Button(Code button) override; |
||||
int GetAxesCount() override; |
||||
int GetButtonCount() override; |
||||
bool IsPresent() override; |
||||
const char* GetName() override; |
||||
|
||||
private: |
||||
int present; |
||||
int id; |
||||
const char* name; |
||||
|
||||
int axesCount; |
||||
const float* axes; |
||||
|
||||
int buttonCount; |
||||
const unsigned char* buttons; |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,27 @@ |
||||
#include "bakara/io/keyboard.h" |
||||
#include "bakara/core/application.h" |
||||
#include <GLFW/glfw3.h> |
||||
|
||||
namespace Bk
|
||||
{ |
||||
bool Keyboard::KeyDown(Code key) |
||||
{ |
||||
auto* window = static_cast<GLFWwindow*>(Application::Get().GetWindow().GetNativeWindow()); |
||||
auto state = glfwGetKey(window, static_cast<int32_t>(key)); |
||||
return state == GLFW_PRESS; |
||||
} |
||||
|
||||
bool Keyboard::KeyUp(Code key) |
||||
{ |
||||
auto* window = static_cast<GLFWwindow*>(Application::Get().GetWindow().GetNativeWindow()); |
||||
auto state = glfwGetKey(window, static_cast<int32_t>(key)); |
||||
return state == GLFW_RELEASE; |
||||
} |
||||
|
||||
bool Keyboard::KeyRepeat(Code key) |
||||
{ |
||||
auto* window = static_cast<GLFWwindow*>(Application::Get().GetWindow().GetNativeWindow()); |
||||
auto state = glfwGetKey(window, static_cast<int32_t>(key)); |
||||
return state == GLFW_REPEAT; |
||||
} |
||||
} |
@ -0,0 +1,36 @@ |
||||
#include "bakara/io/mouse.h" |
||||
#include "bakara/core/application.h" |
||||
#include <GLFW/glfw3.h> |
||||
|
||||
namespace Bk
|
||||
{ |
||||
Vec2 Mouse::GetPosition() |
||||
{ |
||||
auto& window_handle = Application::Get().GetWindow(); |
||||
auto* window = static_cast<GLFWwindow*>(window_handle.GetNativeWindow()); |
||||
double xpos, ypos; |
||||
glfwGetCursorPos(window, &xpos, &ypos); |
||||
return { (float)xpos - (float)window_handle.GetWidth()/2, (float)ypos - (float)window_handle.GetHeight()/2 }; |
||||
} |
||||
|
||||
bool Mouse::ButtonUp(Code button) |
||||
{ |
||||
auto* window = static_cast<GLFWwindow*>(Application::Get().GetWindow().GetNativeWindow()); |
||||
auto state = glfwGetMouseButton(window, static_cast<int32_t>(button)); |
||||
return state == GLFW_RELEASE; |
||||
} |
||||
|
||||
bool Mouse::ButtonDown(Code button) |
||||
{ |
||||
auto* window = static_cast<GLFWwindow*>(Application::Get().GetWindow().GetNativeWindow()); |
||||
auto state = glfwGetMouseButton(window, static_cast<int32_t>(button)); |
||||
return state == GLFW_PRESS; |
||||
} |
||||
|
||||
bool Mouse::ButtonRepeat(Code button) |
||||
{ |
||||
auto* window = static_cast<GLFWwindow*>(Application::Get().GetWindow().GetNativeWindow()); |
||||
auto state = glfwGetMouseButton(window, static_cast<int32_t>(button)); |
||||
return state == GLFW_REPEAT; |
||||
} |
||||
} |
@ -0,0 +1,51 @@ |
||||
#pragma once |
||||
|
||||
#include "bakara/core/deltatime.h" |
||||
#include "bakara/core/window.h" |
||||
#include "bakara/renderer/graphics_context.h" |
||||
|
||||
struct GLFWwindow; |
||||
|
||||
namespace Bk::Platform { |
||||
struct GlfwWindowData
|
||||
{ |
||||
std::string title; |
||||
uint width; |
||||
uint height; |
||||
bool vsync; |
||||
EventCallback callback; |
||||
}; |
||||
|
||||
class GlfwWindow : public Window |
||||
{ |
||||
public: |
||||
GlfwWindow(const WindowProps& props); |
||||
virtual ~GlfwWindow(); |
||||
|
||||
inline uint GetWidth() const override { return p_data.width; } |
||||
inline uint GetHeight() const override { return p_data.height; } |
||||
|
||||
void OnUpdate() override; |
||||
void SetEventCallback(const EventCallback callback) override; |
||||
|
||||
void SetVsync(bool enable) override; |
||||
bool IsVsync() const override; |
||||
|
||||
void Close() override; |
||||
|
||||
void* GetNativeWindow() override { return p_window; } |
||||
|
||||
virtual DeltaTime GetTime() override { return dt; }
|
||||
private: |
||||
GLFWwindow* p_window; |
||||
GlfwWindowData p_data; |
||||
|
||||
Scope<GraphicsContext> context; |
||||
|
||||
float lastFrameTime = 0.0f; |
||||
DeltaTime dt = { 0.0f }; |
||||
|
||||
void InitEventCallbacks(); |
||||
void Init(); |
||||
}; |
||||
} |
@ -0,0 +1,56 @@ |
||||
#include "opengl_buffer.h" |
||||
#include <glad/glad.h> |
||||
|
||||
namespace Bk::Platform |
||||
{ |
||||
OpenglVertexBuffer::OpenglVertexBuffer(float* vertices, u32 size) |
||||
{ |
||||
glGenBuffers(1, &id); |
||||
glBindBuffer(GL_ARRAY_BUFFER, id);
|
||||
glBufferData(GL_ARRAY_BUFFER, size, vertices, GL_STATIC_DRAW);
|
||||
} |
||||
|
||||
OpenglVertexBuffer::~OpenglVertexBuffer()
|
||||
{ |
||||
glDeleteBuffers(1, &id); |
||||
} |
||||
|
||||
void OpenglVertexBuffer::Bind() |
||||
{ |
||||
glBindBuffer(GL_ARRAY_BUFFER, id);
|
||||
} |
||||
|
||||
void OpenglVertexBuffer::Unbind()
|
||||
{ |
||||
glBindBuffer(GL_ARRAY_BUFFER, 0); |
||||
} |
||||
|
||||
|
||||
OpenglIndexBuffer::OpenglIndexBuffer(u32* indices, u32 count) |
||||
: count(count) |
||||
{ |
||||
glGenBuffers(1, &id); |
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id); |
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(u32), indices, GL_STATIC_DRAW); |
||||
} |
||||
|
||||
OpenglIndexBuffer::~OpenglIndexBuffer()
|
||||
{ |
||||
glDeleteBuffers(1, &id); |
||||
} |
||||
|
||||
void OpenglIndexBuffer::Bind() |
||||
{ |
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
|
||||
} |
||||
|
||||
void OpenglIndexBuffer::Unbind()
|
||||
{ |
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
||||
} |
||||
|
||||
u32 OpenglIndexBuffer::GetCount() |
||||
{ |
||||
return count; |
||||
} |
||||
} |
@ -0,0 +1,35 @@ |
||||
#pragma once |
||||
|
||||
#include "bakara/renderer/buffer.h" |
||||
#include "bakara/renderer/buffer_layout.h" |
||||
|
||||
namespace Bk::Platform
|
||||
{ |
||||
class OpenglVertexBuffer : public VertexBuffer |
||||
{ |
||||
public: |
||||
OpenglVertexBuffer(float* vertices, u32 size); |
||||
virtual ~OpenglVertexBuffer(); |
||||
virtual void Bind() override; |
||||
virtual void Unbind() override; |
||||
virtual void SetLayout(BufferLayout layout) override { this->layout = layout; } |
||||
virtual BufferLayout& GetLayout() override { return layout; } |
||||
private: |
||||
BufferLayout layout; |
||||
u32 id; |
||||
};
|
||||
|
||||
class OpenglIndexBuffer : public IndexBuffer |
||||
{ |
||||
public: |
||||
OpenglIndexBuffer(u32* vertices, u32 count); |
||||
virtual ~OpenglIndexBuffer(); |
||||
virtual void Bind() override; |
||||
virtual void Unbind() override; |
||||
virtual u32 GetCount() override; |
||||
|
||||
private: |
||||
u32 id; |
||||
u32 count; |
||||
}; |
||||
} |
@ -0,0 +1,33 @@ |
||||
#include "bakatools/logging/assert.h" |
||||
#include "bakatools/logging/log.h" |
||||
#include "opengl_context.h" |
||||
#include <glad/glad.h> |
||||
#include <GLFW/glfw3.h> |
||||
|
||||
namespace Bk::Platform
|
||||
{ |
||||
OpenglContext::OpenglContext(void* window_handle) |
||||
: window_handle((GLFWwindow*)window_handle) {} |
||||
|
||||
void OpenglContext::Init()
|
||||
{ |
||||
glfwMakeContextCurrent(window_handle); |
||||
int success = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); |
||||
BK_CORE_MSG_ASSERT(success, "Couldn't load glad!") |
||||
|
||||
GLint majVers = 0, minVers = 0; |
||||
glGetIntegerv(GL_MAJOR_VERSION, &majVers); |
||||
glGetIntegerv(GL_MINOR_VERSION, &minVers); |
||||
BK_CORE_INFO("Hardware info "); |
||||
BK_CORE_INFO(" - Opengl Version {0}.{1}", majVers, minVers); |
||||
BK_CORE_INFO(" - GPU Vendor {0}", reinterpret_cast<const char*>(glGetString(GL_VENDOR))); |
||||
BK_CORE_INFO(" - Renderer {0}", reinterpret_cast<const char*>(glGetString(GL_RENDERER))); |
||||
BK_CORE_INFO(" - Renderer Version {0}", reinterpret_cast<const char*>(glGetString(GL_VERSION))); |
||||
BK_CORE_MSG_ASSERT(majVers > 4 || (majVers == 4 && minVers >= 2), "Bakara only support Opengl versions 4.2 or more.") |
||||
} |
||||
|
||||
void OpenglContext::SwapBuffers()
|
||||
{ |
||||
glfwSwapBuffers(window_handle); |
||||
} |
||||
} |
@ -0,0 +1,20 @@ |
||||
#pragma once |
||||
|
||||
|
||||
#include "bakara/renderer/graphics_context.h" |
||||
|
||||
struct GLFWwindow; |
||||
|
||||
namespace Bk::Platform
|
||||
{ |
||||
class OpenglContext : public GraphicsContext |
||||
{ |
||||
public: |
||||
OpenglContext(void* window_handle); |
||||
virtual ~OpenglContext() override { } |
||||
void Init() override; |
||||
void SwapBuffers() override; |
||||
private: |
||||
GLFWwindow* window_handle; |
||||
}; |
||||
} |
@ -0,0 +1,28 @@ |
||||
#include "opengl_renderer_api.h" |
||||
#include <glad/glad.h> |
||||
|
||||
namespace Bk
|
||||
{ |
||||
void OpenglRendererAPI::Init() |
||||
{ |
||||
glEnable(GL_BLEND); |
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
||||
glEnable(GL_DEPTH_TEST); |
||||
} |
||||
|
||||
void OpenglRendererAPI::Clear(float red, float green, float blue, float alpha) |
||||
{ |
||||
glClearColor(red, green, blue, alpha); |
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
||||
} |
||||
|
||||
void OpenglRendererAPI::SetViewport(u32 width, u32 height) |
||||
{ |
||||
glViewport(0, 0, width, height); |
||||
} |
||||
|
||||
void OpenglRendererAPI::DrawIndexed(Ref<VertexArray> va) |
||||
{ |
||||
glDrawElements(GL_TRIANGLES, va->GetIndexbuffer()->GetCount(), GL_UNSIGNED_INT, nullptr); |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
#pragma once |
||||
|
||||
#include "bakara/renderer/renderer_api.h" |
||||
#include "bakara/renderer/vertex_array.h" |
||||
#include "bakatools/container/types.h" |
||||
|
||||
namespace Bk
|
||||
{ |
||||
class OpenglRendererAPI : public RendererAPI |
||||
{ |
||||
public: |
||||
virtual void Init() override; |
||||
virtual void Clear(float red, float green, float blue, float alpha) override; |
||||
virtual void SetViewport(u32 width, u32 height) override; |
||||
virtual void DrawIndexed(Ref<VertexArray> va) override; |
||||
}; |
||||
} |
@ -0,0 +1,158 @@ |
||||
#include "opengl_shader.h" |
||||
#include "bakatools/file_system/file.h" |
||||
#include "bakatools/logging/assert.h" |
||||
#include "bakara/math/types.h" |
||||
#include "bakatools/logging/log.h" |
||||
#include <unordered_map> |
||||
|
||||
namespace Bk::Platform
|
||||
{
|
||||
static GLenum ShaderTypeFromString(std::string type) |
||||
{ |
||||
if (type == "vertex") return GL_VERTEX_SHADER; |
||||
else if (type == "fragment" || type == "pixel") return GL_FRAGMENT_SHADER; |
||||
BK_CORE_MSG_ASSERT(false, "An known shader type")
|
||||
return 0; |
||||
} |
||||
|
||||
OpenglShader::OpenglShader(const std::string& filePath) |
||||
{ |
||||
File file = File(filePath); |
||||
BK_CORE_MSG_ASSERT(file.exists(), "Shader file not found") |
||||
std::string filename = file.name(); |
||||
size_t pos = filename.find_last_of("."); |
||||
name = pos == std::string::npos ? filename : filename.substr(0, pos);
|
||||
std::string source = file.read(); |
||||
auto sources = PreProcess(source); |
||||
Compile(sources); |
||||
|
||||
} |
||||
|
||||
OpenglShader::OpenglShader(const std::string& name, const std::string& vertexSrc, const std::string& fragSrc) |
||||
: name(name) |
||||
{ |
||||
Compile({ |
||||
{ GL_VERTEX_SHADER, vertexSrc }, |
||||
{ GL_FRAGMENT_SHADER, fragSrc } |
||||
}); |
||||
} |
||||
|
||||
std::unordered_map<GLenum, std::string> OpenglShader::PreProcess(std::string source) |
||||
{ |
||||
std::unordered_map<GLenum, std::string> sources; |
||||
const std::string token("#type"); |
||||
size_t pos = source.find(token, 0); |
||||
BK_CORE_MSG_ASSERT(pos != std::string::npos, "Not shader found in file") |
||||
while (pos != std::string::npos) |
||||
{ |
||||
size_t eol = source.find_first_of("\n", pos); |
||||
BK_CORE_MSG_ASSERT(eol != std::string::npos, "Syntax Error in shader file"); |
||||
size_t begin = pos + token.length() + 1; |
||||
std::string type = source.substr(begin, eol - begin); |
||||
GLenum glType = ShaderTypeFromString(type); |
||||
size_t nextLine = source.find_first_not_of("\n", eol); |
||||
pos = source.find(token, nextLine); |
||||
sources[glType] = (pos == std::string::npos) ? source.substr(nextLine) : source.substr(nextLine, pos - nextLine); |
||||
} |
||||
return sources; |
||||
} |
||||
|
||||
void OpenglShader::Compile(std::unordered_map<GLenum, std::string> sources) |
||||
{ |
||||
std::vector<GLuint> shaders; |
||||
id = glCreateProgram(); |
||||
for(auto& kv : sources) |
||||
{ |
||||
GLenum type = kv.first; |
||||
const GLchar* shaderSrc = kv.second.c_str(); |
||||
GLuint shader = glCreateShader(type); |
||||
glShaderSource(shader, 1, &shaderSrc, NULL); |
||||
glCompileShader(shader); |
||||
int info; |
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &info); |
||||
if(!info) { |
||||
std::vector<char> infoLog; |
||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info); |
||||
infoLog.resize(info); |
||||
glGetShaderInfoLog(shader, infoLog.size(), NULL, infoLog.data()); |
||||
BK_CORE_ERROR("Shader Error : {0}", std::string(infoLog.data(),infoLog.size())); |
||||
BK_MSG_ASSERT(false, "Error with shader compilation") |
||||
} |
||||
glAttachShader(id, shader); |
||||
shaders.push_back(shader); |
||||
} |
||||
glLinkProgram(id); |
||||
int info; |
||||
glGetProgramiv(id, GL_LINK_STATUS, &info); |
||||
if(!info) { |
||||
std::vector<char> infoLog; |
||||
glGetShaderiv(id, GL_INFO_LOG_LENGTH, &info); |
||||
infoLog.resize(info); |
||||
glGetProgramInfoLog(id, infoLog.size(), NULL, infoLog.data()); |
||||
BK_CORE_ERROR("Shader Error : {0}", std::string(infoLog.data(),infoLog.size())); |
||||
BK_MSG_ASSERT(false, "Error when link sharder in a program") |
||||
} |
||||
for(auto shader : shaders) glDeleteShader(shader); |
||||
} |
||||
|
||||
OpenglShader::~OpenglShader() |
||||
{ |
||||
glDeleteProgram(id); |
||||
} |
||||
|
||||
void OpenglShader::Bind()
|
||||
{ |
||||
glUseProgram(id); |
||||
} |
||||
|
||||
void OpenglShader::Unbind()
|
||||
{ |
||||
glUseProgram(0); |
||||
} |
||||
|
||||
void OpenglShader::Set(const std::string name, int val)
|
||||
{ |
||||
glUniform1i(glGetUniformLocation(id, name.c_str()), val); |
||||
} |
||||
|
||||
void OpenglShader::Set(const std::string name, bool value)
|
||||
{ |
||||
glUniform1i(glGetUniformLocation(id, name.c_str()), (int)value); |
||||
} |
||||
|
||||
void OpenglShader::Set(const std::string name, float val)
|
||||
{ |
||||
glUniform1f(glGetUniformLocation(this->id, name.c_str()), val); |
||||
} |
||||
|
||||
void OpenglShader::Set(const std::string name, float v1, float v2, float v3)
|
||||
{ |
||||
glUniform3f(glGetUniformLocation(id, name.c_str()), v1, v2, v3); |
||||
} |
||||
|
||||
void OpenglShader::Set(const std::string name, Vec3 v)
|
||||
{ |
||||
this->Set(name, v.x, v.y, v.z); |
||||
} |
||||
|
||||
void OpenglShader::Set(const std::string name, float v1, float v2, float v3, float v4)
|
||||
{ |
||||
glUniform4f(glGetUniformLocation(id, name.c_str()), v1, v2, v3, v4); |
||||
} |
||||
|
||||
void OpenglShader::Set(const std::string name, Vec4 v)
|
||||
{ |
||||
this->Set(name, v.x, v.y, v.z, v.w); |
||||
} |
||||
|
||||
void OpenglShader::Set(const std::string name, Mat3 val)
|
||||
{ |
||||
glUniformMatrix3fv(glGetUniformLocation(this->id, name.c_str()), 1, GL_FALSE, glm::value_ptr(val)); |
||||
} |
||||
|
||||
void OpenglShader::Set(const std::string name, Mat4 val)
|
||||
{ |
||||
glUniformMatrix4fv(glGetUniformLocation(this->id, name.c_str()), 1, GL_FALSE, glm::value_ptr(val)); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,38 @@ |
||||
#pragma once |
||||
|
||||
#include "bakara/renderer/shader.h" |
||||
#include <glad/glad.h> |
||||
#include <string> |
||||
#include <unordered_map> |
||||
|
||||
namespace Bk::Platform
|
||||
{ |
||||
class OpenglShader : public Shader |
||||
{ |
||||
public: |
||||
OpenglShader(const std::string& filePath); |
||||
OpenglShader(const std::string& name, const std::string& vertexSrc, const std::string& fragSrc); |
||||
virtual ~OpenglShader(); |
||||
|
||||
virtual const std::string& GetName() override { return name; }
|
||||
|
||||
virtual void Bind() override; |
||||
virtual void Unbind() override; |
||||
|
||||
virtual void Set(const std::string name, int val) override; |
||||
virtual void Set(const std::string name, bool val) override; |
||||
virtual void Set(const std::string name, float val) override; |
||||
virtual void Set(const std::string name, float v1, float v2, float v3) override; |
||||
virtual void Set(const std::string name, Vec3 v) override; |
||||
virtual void Set(const std::string name, float v1, float v2, float v3, float v4) override; |
||||
virtual void Set(const std::string name, Vec4 v) override; |
||||
virtual void Set(const std::string name, Mat3 val) override; |
||||
virtual void Set(const std::string name, Mat4 val) override; |
||||
|
||||
private: |
||||
unsigned int id; |
||||
std::string name; |
||||
std::unordered_map<GLenum, std::string> PreProcess(std::string source); |
||||
void Compile(std::unordered_map<GLenum, std::string> sources); |
||||
}; |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue