Initial Linux Support

This commit is contained in:
Light3039 2021-06-26 13:09:11 +04:30
parent 49b4560351
commit a682523076
19 changed files with 173 additions and 48 deletions

16
.gitignore vendored
View file

@ -5,4 +5,18 @@ bin-int/
# VS Files # VS Files
**.vcxproj** **.vcxproj**
**.sln **.sln
.codelite/
.build-debug/
**.workspace
Makefile
**/**.mk
**/**.project
**/Engine.txt
**/GLAD.txt
**/Sandbox.txt

2
Dependencies/GLFW vendored

@ -1 +1 @@
Subproject commit 23f99263cdb8db054db5202f605e5730aec4e3c3 Subproject commit 59a32baf70eadf12bfc22234c3bb1c5c28931a2c

2
Dependencies/imgui vendored

@ -1 +1 @@
Subproject commit e401b8f2c0e89ddd783245a88549f5c5e23a2c21 Subproject commit b238424f840544f64b0597f86c59b8810ca2b933

View file

@ -31,15 +31,15 @@ project "Engine"
includedirs includedirs
{ {
-- engine -- engine
"%{prj.location}/src/" , "%{prj.location}/src" ,
"%{prj.location}/src/Engine/" , "%{prj.location}/src/Engine" ,
"%{prj.location}/src/Platform/GraphicsAPI" , "%{prj.location}/src/Platform/GraphicsAPI" ,
"%{prj.location}/src/Platform/OS" , "%{prj.location}/src/Platform/OS" ,
-- 3rd party -- 3rd party
(dependenciesdir .. "spdlog/include/"), (dependenciesdir .. "spdlog/include/"),
(dependenciesdir .. "glfw/include/" ), (dependenciesdir .. "GLFW/include/" ),
(dependenciesdir .. "glad/include" ), (dependenciesdir .. "GLAD/include" ),
(dependenciesdir .. "imgui/backends" ), (dependenciesdir .. "imgui/backends" ),
(dependenciesdir .. "imgui/" ), (dependenciesdir .. "imgui/" ),
(dependenciesdir .. "glm/" ), (dependenciesdir .. "glm/" ),
@ -65,6 +65,26 @@ project "Engine"
"dxguid.lib" , "dxguid.lib" ,
"D3DCompiler.lib" , "D3DCompiler.lib" ,
} }
-- linux
filter "system:linux"
defines "LIGHT_PLATFORM_LINUX"
links
{
"dl",
}
buildoptions
{
"-lgtest",
"-lpthread",
}
excludes
{
"%{prj.location}/src/Platform/GraphicsAPI/DirectX/**",
"%{prj.location}/src/Platform/OS/Windows/**",
}
-- debug -- debug
filter "configurations:Debug" filter "configurations:Debug"
@ -83,8 +103,7 @@ project "Engine"
--- Excludes --- --- Excludes ---
-- !windows -- !windows
filter "system:not windows" filter "system:not linux"
excludes "%{prj.location}/src/Platform/GraphicsAPI/DirectX**"
excludes "%{prj.location}/src/Platform/OS/Windows**"
-- !linux #todo: -- !linux #todo:
-- !mac #todo: -- !mac #todo:

View file

@ -13,11 +13,13 @@
#define LT_MAC(x) // Mac #define LT_MAC(x) // Mac
#if defined(LIGHT_PLATFORM_WINDOWS) #if defined(LIGHT_PLATFORM_WINDOWS)
#error "test"
#define LT_BUILD_PLATFORM "Windows" #define LT_BUILD_PLATFORM "Windows"
#define LT_WIN(x) x #define LT_WIN(x) x
#elif defined(LIGHT_PLATFORM_LINUX) #elif defined(LIGHT_PLATFORM_LINUX)
#error "Unsupported platform: UNIX" #define LT_BUILD_PLATFORM "Linux"
#define LT_LIN(x)
#define LT_LIN(x) x
#elif defined(LIGHT_PLATFORM_MAC) #elif defined(LIGHT_PLATFORM_MAC)
#error "Unsupported platform: MAC" #error "Unsupported platform: MAC"
#define LT_MAC(x) x #define LT_MAC(x) x
@ -28,5 +30,5 @@
#define BIT(x) 1 << x #define BIT(x) 1 << x
// #todo: log to file in distribution builds // #todo: log to file in distribution builds
#define LT_ENGINE_ASSERT(x, ...) { if(!(x)) { LT_ENGINE_CRITICAL(__VA_ARGS__); __debugbreak(); throw ::Light::FailedAssertion(__FILE__, __LINE__); } } #define LT_ENGINE_ASSERT(x, ...) { if(!(x)) { LT_ENGINE_CRITICAL(__VA_ARGS__); /* __builtin_trap() */; throw ::Light::FailedAssertion(__FILE__, __LINE__); } }
#define LT_CLIENT_ASSERT(x, ...) { if(!(x)) { LT_CLIENT_CRITICAL(__VA_ARGS__); __debugbreak(); } } #define LT_CLIENT_ASSERT(x, ...) { if(!(x)) { LT_CLIENT_CRITICAL(__VA_ARGS__); __builtin_trap(); } }

View file

@ -17,8 +17,11 @@ namespace Light {
void Light::Logger::Initialize() void Light::Logger::Initialize()
{ {
// set spdlog pattern // set spdlog pattern
#if defined(LIGHT_PLATFORM_WINDOWS)
spdlog::set_pattern("%^[%M:%S:%e] <%n>: %v%$"); spdlog::set_pattern("%^[%M:%S:%e] <%n>: %v%$");
#elif defined(LIGHT_PLATFORM_LINUX)
spdlog::set_pattern("%^{%l} - [%M:%S:%e] <%n>: %v%$");
#endif
// create loggers // create loggers
#ifndef LIGHT_DIST #ifndef LIGHT_DIST
s_EngineLogger = spdlog::stdout_color_mt("Engine"); s_EngineLogger = spdlog::stdout_color_mt("Engine");
@ -28,7 +31,7 @@ namespace Light {
s_FileLogger->set_pattern("%^[%M:%S:%e] <%l>: %v%$"); s_FileLogger->set_pattern("%^[%M:%S:%e] <%l>: %v%$");
// set level // set level
#if defined(LIGHT_DEBUG) #if defined(LIGHT_DEBUG)
s_EngineLogger->set_level(spdlog::level::trace); s_EngineLogger->set_level(spdlog::level::trace);
s_ClientLogger->set_level(spdlog::level::trace); s_ClientLogger->set_level(spdlog::level::trace);
#elif defined (LIGHT_RELEASE) #elif defined (LIGHT_RELEASE)

View file

@ -7,6 +7,7 @@
// To be defined in client project // To be defined in client project
extern Light::Application* Light::CreateApplication(); extern Light::Application* Light::CreateApplication();
// #todo: use windows specific stuff
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
Light::Application* application = nullptr; Light::Application* application = nullptr;
@ -39,4 +40,39 @@ int main(int argc, char** argv)
return exitCode; return exitCode;
} }
#elif defined(LIGHT_PLATFORM_LINUX)
#include <LightEngine.h>
// To be defined in client project
extern Light::Application* Light::CreateApplication();
// #todo: use linux specific stuff
int main(int argc, char* argv[])
{
Light::Application* application = nullptr;
int exitCode = 0;
try
{
application = Light::CreateApplication();
LT_ENGINE_ASSERT(application, "main: Light::Application is not intialized");
application->GameLoop();
}
catch (Light::FailedAssertion)
{
LT_ENGINE_CRITICAL("main: exitting due to unhandled FailedAssertion");
exitCode = -1;
}
catch(Light::glException)
{
LT_ENGINE_CRITICAL("main: exitting due to unhandled glException");
exitCode = -2;
}
delete application;
return exitCode;
}
#endif #endif

View file

@ -24,9 +24,9 @@ namespace Light {
InputEventCategory = BIT(1), InputEventCategory = BIT(1),
KeyboardEventCategory = BIT(2), KeyboardEventCategory = BIT(2),
MouseEventCategory = BIT(3), MouseEventCategory = BIT(3),
}; };
#define EVENT_TYPE(type) EventType GetEventType() const override { return EventType::##type; } #define EVENT_TYPE(type) EventType GetEventType() const override { return ::Light::EventType:: type; }
#define EVENT_CATEGORY(eCategory) inline bool HasCategory(EventCategory category) const override { return (eCategory) & category; } #define EVENT_CATEGORY(eCategory) inline bool HasCategory(EventCategory category) const override { return (eCategory) & category; }
class Event class Event

View file

@ -22,8 +22,8 @@ namespace Light {
case GraphicsAPI::OpenGL: case GraphicsAPI::OpenGL:
return new glVertexBuffer(vertices, count); return new glVertexBuffer(vertices, count);
case GraphicsAPI::DirectX: case GraphicsAPI::DirectX: LT_WIN(
return new dxVertexBuffer(vertices, stride, count, std::static_pointer_cast<dxSharedContext>(sharedContext)); return new dxVertexBuffer(vertices, stride, count, std::static_pointer_cast<dxSharedContext>(sharedContext));)
default: default:
LT_ENGINE_ASSERT(false, "VertexBuffer::Create: invalid/unsupported GraphicsAPI {}", GraphicsContext::GetGraphicsAPI()); LT_ENGINE_ASSERT(false, "VertexBuffer::Create: invalid/unsupported GraphicsAPI {}", GraphicsContext::GetGraphicsAPI());

View file

@ -18,6 +18,8 @@ namespace Light {
GraphicsContext* GraphicsContext::s_Context = nullptr; GraphicsContext* GraphicsContext::s_Context = nullptr;
GraphicsContext::~GraphicsContext() { }
GraphicsContext* GraphicsContext::Create(GraphicsAPI api, GLFWwindow* windowHandle) GraphicsContext* GraphicsContext::Create(GraphicsAPI api, GLFWwindow* windowHandle)
{ {
// terminate gfx context dependent classes // terminate gfx context dependent classes

View file

@ -42,7 +42,7 @@ namespace Light {
GraphicsContext(const GraphicsContext&) = delete; GraphicsContext(const GraphicsContext&) = delete;
GraphicsContext& operator=(const GraphicsContext&) = delete; GraphicsContext& operator=(const GraphicsContext&) = delete;
virtual ~GraphicsContext() = default; virtual ~GraphicsContext();
virtual void OnWindowResize(const WindowResizedEvent& event) = 0; virtual void OnWindowResize(const WindowResizedEvent& event) = 0;

View file

@ -51,19 +51,20 @@ namespace Light {
// TOP_LEFT // TOP_LEFT
m_QuadRenderer.mapCurrent[0].position = { xMin, yMin, position.z }; m_QuadRenderer.mapCurrent[0].position = { xMin, yMin, position.z };
m_QuadRenderer.mapCurrent[0].tint = tint; m_QuadRenderer.mapCurrent[0].tint = glm::vec4((float)(rand() % 100) / 100.0f, (float)(rand() % 100) / 100.0f, (float)(rand() % 100) / 100.0f, 1.0f);
// TOP_RIGHT // TOP_RIGHT
m_QuadRenderer.mapCurrent[1].position = { xMax, yMin, position.z }; m_QuadRenderer.mapCurrent[1].position = { xMax, yMin, position.z };
m_QuadRenderer.mapCurrent[1].tint = tint; m_QuadRenderer.mapCurrent[1].tint = glm::vec4((float)(rand() % 100) / 100.0f, (float)(rand() % 100) / 100.0f, (float)(rand() % 100) / 100.0f, 1.0f);
// BOTTOM_RIGHT // BOTTOM_RIGHT
m_QuadRenderer.mapCurrent[2].position = { xMax, yMax, position.z }; m_QuadRenderer.mapCurrent[2].position = { xMax, yMax, position.z };
m_QuadRenderer.mapCurrent[2].tint = tint; m_QuadRenderer.mapCurrent[2].tint = glm::vec4((float)(rand() % 100) / 100.0f, (float)(rand() % 100) / 100.0f, (float)(rand() % 100) / 100.0f, 1.0f);
// BOTTOM_LEFT // BOTTOM_LEFT
m_QuadRenderer.mapCurrent[3].position = { xMin, yMax, position.z }; m_QuadRenderer.mapCurrent[3].position = { xMin, yMax, position.z };
m_QuadRenderer.mapCurrent[3].tint = tint; m_QuadRenderer.mapCurrent[3].tint = glm::vec4((float)(rand() % 100) / 100.0f, (float)(rand() % 100) / 100.0f, (float)(rand() % 100) / 100.0f, 1.0f);
// advance // advance
m_QuadRenderer.mapCurrent += 4; m_QuadRenderer.mapCurrent += 4;

View file

@ -15,7 +15,7 @@ namespace Light {
static UserInterface* Create(GLFWwindow* windowHandle, std::shared_ptr<SharedContext> sharedContext); static UserInterface* Create(GLFWwindow* windowHandle, std::shared_ptr<SharedContext> sharedContext);
UserInterface(const UserInterface&) = delete; UserInterface(const UserInterface&) = delete;
UserInterface operator=(const UserInterface&) = delete; UserInterface& operator=(const UserInterface&) = delete;
virtual ~UserInterface() = default; virtual ~UserInterface() = default;

View file

@ -14,7 +14,7 @@
#include "Utility/Stringifier.h" #include "Utility/Stringifier.h"
#include <glad/glad.h> #include <glad/glad.h>
#include <glfw/glfw3.h> #include <GLFW/glfw3.h>
namespace Light { namespace Light {
@ -24,10 +24,11 @@ namespace Light {
m_GraphicsAPI = GraphicsAPI::OpenGL; m_GraphicsAPI = GraphicsAPI::OpenGL;
glfwMakeContextCurrent(windowHandle); glfwMakeContextCurrent(windowHandle);
LT_ENGINE_ASSERT(gladLoadGLLoader((GLADloadproc)glfwGetProcAddress),
"glGraphicsContext::glGraphicsContext: gladLoadGLLoader: failed to initialize opengl context"); if(!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{ exit(1); }
SetDebugMessageCallback();
} }
void glGraphicsContext::OnWindowResize(const WindowResizedEvent& event) void glGraphicsContext::OnWindowResize(const WindowResizedEvent& event)

View file

@ -36,6 +36,9 @@ namespace Light {
std::vector<char> errorLog(maxLength); std::vector<char> errorLog(maxLength);
glGetShaderInfoLog(vertexShader, maxLength, &maxLength, &errorLog[0]); glGetShaderInfoLog(vertexShader, maxLength, &maxLength, &errorLog[0]);
for(int i = 0; i < errorLog.size() -1; i++)
std::cout << errorLog[i];
glDeleteShader(vertexShader); glDeleteShader(vertexShader);
} }

View file

@ -24,8 +24,12 @@ namespace Light {
LT_ENGINE_ASSERT(glfwInit(), "wWindow::wWindow: failed to initialize glfw"); LT_ENGINE_ASSERT(glfwInit(), "wWindow::wWindow: failed to initialize glfw");
// create window // create window
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
m_Handle = glfwCreateWindow(1u, 1u, "", nullptr, nullptr); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
m_Handle = glfwCreateWindow(800u, 600u, "", nullptr, nullptr);
LT_ENGINE_ASSERT(m_Handle, "wWindow::wWindow: glfwCreateWindow: failed to create glfw window"); LT_ENGINE_ASSERT(m_Handle, "wWindow::wWindow: glfwCreateWindow: failed to create glfw window");
@ -34,7 +38,7 @@ namespace Light {
BindGlfwEvents(); BindGlfwEvents();
// create graphics context // create graphics context
m_GraphicsContext = std::unique_ptr<GraphicsContext>(GraphicsContext::Create(GraphicsAPI::DirectX, m_Handle)); m_GraphicsContext = std::unique_ptr<GraphicsContext>(GraphicsContext::Create(GraphicsAPI::OpenGL, m_Handle));
LT_ENGINE_ASSERT(m_GraphicsContext, "wWindow::wWindow: failed to create graphics context"); LT_ENGINE_ASSERT(m_GraphicsContext, "wWindow::wWindow: failed to create graphics context");
} }
@ -109,7 +113,8 @@ namespace Light {
glfwSetCursorPosCallback(m_Handle, [](GLFWwindow* window, double xpos, double ypos) glfwSetCursorPosCallback(m_Handle, [](GLFWwindow* window, double xpos, double ypos)
{ {
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window); std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
callback(MouseMovedEvent(xpos, ypos)); MouseMovedEvent event(xpos, ypos);
callback(event);
}); });
glfwSetMouseButtonCallback(m_Handle, [](GLFWwindow* window, int button, int action, int mods) glfwSetMouseButtonCallback(m_Handle, [](GLFWwindow* window, int button, int action, int mods)
@ -117,15 +122,25 @@ namespace Light {
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window); std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
if (action == GLFW_PRESS) if (action == GLFW_PRESS)
callback(ButtonPressedEvent(button)); {
ButtonPressedEvent event(button);
callback(event);
}
else else
callback(ButtonReleasedEvent(button)); {
ButtonReleasedEvent event(button);
callback(event);
}
}); });
glfwSetScrollCallback(m_Handle, [](GLFWwindow* window, double xoffset, double yoffset) glfwSetScrollCallback(m_Handle, [](GLFWwindow* window, double xoffset, double yoffset)
{ {
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window); std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
callback(WheelScrolledEvent(yoffset));
WheelScrolledEvent event(yoffset);
callback(event);
}); });
// Keyboard Events // // Keyboard Events //
@ -134,28 +149,41 @@ namespace Light {
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window); std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
if (action == GLFW_PRESS) if (action == GLFW_PRESS)
callback(KeyPressedEvent(key)); {
KeyPressedEvent event(key);
callback(event);
}
else else
callback(KeyReleasedEvent(key)); {
KeyReleasedEvent event(key);
callback(event);
}
}); });
// Window Events // // Window Events //
glfwSetWindowPosCallback(m_Handle, [](GLFWwindow* window, int xpos, int ypos) glfwSetWindowPosCallback(m_Handle, [](GLFWwindow* window, int xpos, int ypos)
{ {
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window); std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
callback(WindowMovedEvent(xpos, ypos)); WindowMovedEvent event(xpos, ypos);
callback(event);
}); });
glfwSetWindowSizeCallback(m_Handle, [](GLFWwindow* window, int width, int height) glfwSetWindowSizeCallback(m_Handle, [](GLFWwindow* window, int width, int height)
{ {
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window); std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
callback(WindowResizedEvent(width, height)); WindowResizedEvent event(width, height);
callback(event);
}); });
glfwSetWindowCloseCallback(m_Handle, [](GLFWwindow* window) glfwSetWindowCloseCallback(m_Handle, [](GLFWwindow* window)
{ {
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window); std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
callback(WindowClosedEvent()); WindowClosedEvent event;
callback(event);
}); });
glfwSetWindowFocusCallback(m_Handle, [](GLFWwindow* window, int focus) glfwSetWindowFocusCallback(m_Handle, [](GLFWwindow* window, int focus)
@ -163,10 +191,15 @@ namespace Light {
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window); std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
if(focus == GLFW_TRUE) if(focus == GLFW_TRUE)
callback(WindowGainFocusEvent()); {
WindowGainFocusEvent event;
callback(event);
}
else else
callback(WindowLostFocusEvent()); {
}); WindowLostFocusEvent event;
callback(event);
}
});
} }
} }

View file

@ -4,8 +4,8 @@ Size=400,400
Collapsed=0 Collapsed=0
[Window][Dear ImGui Demo] [Window][Dear ImGui Demo]
Pos=-16,5 Pos=556,321
Size=405,290 Size=241,281
Collapsed=0 Collapsed=0
[Window][Dear ImGui Metrics/Debugger] [Window][Dear ImGui Metrics/Debugger]

View file

@ -51,6 +51,16 @@ project "Sandbox"
systemversion "latest" systemversion "latest"
staticruntime "On" staticruntime "On"
-- linux
filter "system:linux"
defines "LIGHT_PLATFORM_LINUX"
links
{
"dl",
"pthread",
}
-- debug -- debug
filter "configurations:Debug" filter "configurations:Debug"
defines "LIGHT_DEBUG" defines "LIGHT_DEBUG"

View file

@ -1,5 +1,6 @@
#define LIGHT_ENTRY_POINT #define LIGHT_ENTRY_POINT
#include <LightEngine.h> #include <LightEngine.h>
#include <EntryPoint.h>
#include "SandboxLayer.h" #include "SandboxLayer.h"