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
**.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
{
-- engine
"%{prj.location}/src/" ,
"%{prj.location}/src/Engine/" ,
"%{prj.location}/src" ,
"%{prj.location}/src/Engine" ,
"%{prj.location}/src/Platform/GraphicsAPI" ,
"%{prj.location}/src/Platform/OS" ,
-- 3rd party
(dependenciesdir .. "spdlog/include/"),
(dependenciesdir .. "glfw/include/" ),
(dependenciesdir .. "glad/include" ),
(dependenciesdir .. "GLFW/include/" ),
(dependenciesdir .. "GLAD/include" ),
(dependenciesdir .. "imgui/backends" ),
(dependenciesdir .. "imgui/" ),
(dependenciesdir .. "glm/" ),
@ -65,6 +65,26 @@ project "Engine"
"dxguid.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
filter "configurations:Debug"
@ -83,8 +103,7 @@ project "Engine"
--- Excludes ---
-- !windows
filter "system:not windows"
excludes "%{prj.location}/src/Platform/GraphicsAPI/DirectX**"
excludes "%{prj.location}/src/Platform/OS/Windows**"
filter "system:not linux"
-- !linux #todo:
-- !mac #todo:

View file

@ -13,11 +13,13 @@
#define LT_MAC(x) // Mac
#if defined(LIGHT_PLATFORM_WINDOWS)
#error "test"
#define LT_BUILD_PLATFORM "Windows"
#define LT_WIN(x) x
#elif defined(LIGHT_PLATFORM_LINUX)
#error "Unsupported platform: UNIX"
#define LT_LIN(x)
#define LT_BUILD_PLATFORM "Linux"
#define LT_LIN(x) x
#elif defined(LIGHT_PLATFORM_MAC)
#error "Unsupported platform: MAC"
#define LT_MAC(x) x
@ -28,5 +30,5 @@
#define BIT(x) 1 << x
// #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_CLIENT_ASSERT(x, ...) { if(!(x)) { LT_CLIENT_CRITICAL(__VA_ARGS__); __debugbreak(); } }
#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__); __builtin_trap(); } }

View file

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

View file

@ -7,6 +7,7 @@
// To be defined in client project
extern Light::Application* Light::CreateApplication();
// #todo: use windows specific stuff
int main(int argc, char** argv)
{
Light::Application* application = nullptr;
@ -39,4 +40,39 @@ int main(int argc, char** argv)
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

View file

@ -24,9 +24,9 @@ namespace Light {
InputEventCategory = BIT(1),
KeyboardEventCategory = BIT(2),
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; }
class Event

View file

@ -22,8 +22,8 @@ namespace Light {
case GraphicsAPI::OpenGL:
return new glVertexBuffer(vertices, count);
case GraphicsAPI::DirectX:
return new dxVertexBuffer(vertices, stride, count, std::static_pointer_cast<dxSharedContext>(sharedContext));
case GraphicsAPI::DirectX: LT_WIN(
return new dxVertexBuffer(vertices, stride, count, std::static_pointer_cast<dxSharedContext>(sharedContext));)
default:
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() { }
GraphicsContext* GraphicsContext::Create(GraphicsAPI api, GLFWwindow* windowHandle)
{
// terminate gfx context dependent classes

View file

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

View file

@ -51,19 +51,20 @@ namespace Light {
// TOP_LEFT
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
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
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
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
m_QuadRenderer.mapCurrent += 4;

View file

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

View file

@ -14,7 +14,7 @@
#include "Utility/Stringifier.h"
#include <glad/glad.h>
#include <glfw/glfw3.h>
#include <GLFW/glfw3.h>
namespace Light {
@ -24,10 +24,11 @@ namespace Light {
m_GraphicsAPI = GraphicsAPI::OpenGL;
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)

View file

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

View file

@ -24,8 +24,12 @@ namespace Light {
LT_ENGINE_ASSERT(glfwInit(), "wWindow::wWindow: failed to initialize glfw");
// 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");
@ -34,7 +38,7 @@ namespace Light {
BindGlfwEvents();
// 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");
}
@ -109,7 +113,8 @@ namespace Light {
glfwSetCursorPosCallback(m_Handle, [](GLFWwindow* window, double xpos, double ypos)
{
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)
@ -117,15 +122,25 @@ namespace Light {
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
if (action == GLFW_PRESS)
callback(ButtonPressedEvent(button));
{
ButtonPressedEvent event(button);
callback(event);
}
else
callback(ButtonReleasedEvent(button));
{
ButtonReleasedEvent event(button);
callback(event);
}
});
glfwSetScrollCallback(m_Handle, [](GLFWwindow* window, double xoffset, double yoffset)
{
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
callback(WheelScrolledEvent(yoffset));
WheelScrolledEvent event(yoffset);
callback(event);
});
// Keyboard Events //
@ -134,28 +149,41 @@ namespace Light {
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
if (action == GLFW_PRESS)
callback(KeyPressedEvent(key));
{
KeyPressedEvent event(key);
callback(event);
}
else
callback(KeyReleasedEvent(key));
{
KeyReleasedEvent event(key);
callback(event);
}
});
// Window Events //
glfwSetWindowPosCallback(m_Handle, [](GLFWwindow* window, int xpos, int ypos)
{
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)
{
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)
{
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
callback(WindowClosedEvent());
WindowClosedEvent event;
callback(event);
});
glfwSetWindowFocusCallback(m_Handle, [](GLFWwindow* window, int focus)
@ -163,10 +191,15 @@ namespace Light {
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
if(focus == GLFW_TRUE)
callback(WindowGainFocusEvent());
{
WindowGainFocusEvent event;
callback(event);
}
else
callback(WindowLostFocusEvent());
});
{
WindowLostFocusEvent event;
callback(event);
}
});
}
}

View file

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

View file

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

View file

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