Style: Rename LT_* Log macros to LOG
This commit is contained in:
parent
b1e60d08b7
commit
dcedb1799c
47 changed files with 2890 additions and 3017 deletions
|
@ -4,40 +4,40 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
// Ref (Ref)
|
||||
template<typename T>
|
||||
using Ref = std::shared_ptr<T>;
|
||||
|
||||
template<typename T, typename... Args>
|
||||
constexpr Ref<T> CreateRef(Args&&... args)
|
||||
{
|
||||
return std::make_shared<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr Ref<T> MakeRef(T* rawPointer)
|
||||
{
|
||||
return std::shared_ptr<T>(rawPointer);
|
||||
}
|
||||
|
||||
// Scope (std::unique_ptr)
|
||||
template<typename T>
|
||||
using Scope = std::unique_ptr<T>;
|
||||
|
||||
template<typename T, typename... Args>
|
||||
constexpr std::unique_ptr<T> CreateScope(Args&&... args)
|
||||
{
|
||||
return std::make_unique<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr std::unique_ptr<T> MakeScope(T* rawPointer)
|
||||
{
|
||||
return std::unique_ptr<T>(rawPointer);
|
||||
}
|
||||
// Ref (Ref)
|
||||
template<typename T>
|
||||
using Ref = std::shared_ptr<T>;
|
||||
|
||||
template<typename T, typename... Args>
|
||||
constexpr Ref<T> CreateRef(Args&&... args)
|
||||
{
|
||||
return std::make_shared<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr Ref<T> MakeRef(T* rawPointer)
|
||||
{
|
||||
return std::shared_ptr<T>(rawPointer);
|
||||
}
|
||||
|
||||
// Scope (std::unique_ptr)
|
||||
template<typename T>
|
||||
using Scope = std::unique_ptr<T>;
|
||||
|
||||
template<typename T, typename... Args>
|
||||
constexpr std::unique_ptr<T> CreateScope(Args&&... args)
|
||||
{
|
||||
return std::make_unique<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr std::unique_ptr<T> MakeScope(T* rawPointer)
|
||||
{
|
||||
return std::unique_ptr<T>(rawPointer);
|
||||
}
|
||||
|
||||
} // namespace Light
|
||||
|
||||
//========== PLATFORM ==========//
|
||||
#define LT_WIN(x) // windows
|
||||
#define LT_LIN(x) // linux
|
||||
|
@ -45,32 +45,45 @@ namespace Light {
|
|||
|
||||
#if defined(LIGHT_PLATFORM_WINDOWS)
|
||||
#define LT_BUILD_PLATFORM "Windows"
|
||||
#define LT_WIN(x) x
|
||||
|
||||
#define LT_WIN(x) x
|
||||
|
||||
#elif defined(LIGHT_PLATFORM_LINUX)
|
||||
#define LT_BUILD_PLATFORM "Linux"
|
||||
#define LT_LIN(x) x
|
||||
|
||||
#define LT_LIN(x) x
|
||||
|
||||
#elif defined(LIGHT_PLATFORM_MAC)
|
||||
#error "Unsupported platform: MAC"
|
||||
#define LT_MAC(x) x
|
||||
|
||||
|
||||
#else
|
||||
// #error "Unsupported platform: Unknown"
|
||||
// #error "Unsupported platform: Unknown"
|
||||
#endif
|
||||
//========== PLATFORM ==========//
|
||||
|
||||
//====================================================================== OPERATIONS ======================================================================//
|
||||
/* assertions */
|
||||
#define LT_ENGINE_ASSERT(x, ...) { if(!(x)) { LT_ENGINE_CRITICAL(__VA_ARGS__); LT_DEBUG_TRAP(); throw ::Light::FailedEngineAssertion(__FILE__, __LINE__); } }
|
||||
#define LT_CLIENT_ASSERT(x, ...) { if(!(x)) { LT_CLIENT_CRITICAL(__VA_ARGS__); LT_DEBUG_TRAP(); throw ::Light::FailedClientAssertion(__FILE__, __LINE__); } }
|
||||
#define ASSERT(x, ...) \
|
||||
{ \
|
||||
if (!(x)) \
|
||||
{ \
|
||||
LOG(critical, __VA_ARGS__); \
|
||||
LT_DEBUG_TRAP(); \
|
||||
throw ::Light::FailedAssertion(__FILE__, __LINE__); \
|
||||
} \
|
||||
}
|
||||
|
||||
/* bit-wise */
|
||||
#define BIT(x) 1 << x
|
||||
|
||||
/* token */
|
||||
#define LT_PAIR_TOKEN_VALUE_TO_NAME(token) { token, #token }
|
||||
#define LT_PAIR_TOKEN_NAME_TO_VALUE(token) { #token, token }
|
||||
#define LT_PAIR_TOKEN_VALUE_TO_NAME(token) \
|
||||
{ \
|
||||
token, #token \
|
||||
}
|
||||
#define LT_PAIR_TOKEN_NAME_TO_VALUE(token) \
|
||||
{ \
|
||||
#token, token \
|
||||
}
|
||||
#define LT_TOKEN_NAME(token) #token
|
||||
//====================================================================== OPERATIONS ======================================================================//
|
||||
|
||||
|
@ -95,4 +108,4 @@ namespace Light {
|
|||
#ifndef LIGHT_STRINGIFIER_H
|
||||
#include "Utility/Stringifier.h"
|
||||
#endif
|
||||
//========== ESSENTIAL_HEADERS ==========//
|
||||
//========== ESSENTIAL_HEADERS ==========//
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#ifdef LIGHT_PLATFORM_WINDOWS
|
||||
|
||||
#include <LightEngine.h>
|
||||
#include <LightEngine.h>
|
||||
|
||||
// to be defined in client project
|
||||
extern Light::Application* Light::CreateApplication(std::string execName, std::vector<std::string> args);
|
||||
|
@ -11,7 +11,7 @@ extern Light::Application* Light::CreateApplication(std::string execName, std::v
|
|||
int main(int argc, char* argv[])
|
||||
{
|
||||
Light::Application* application = nullptr;
|
||||
int exitCode = 0;
|
||||
int exitCode = 0;
|
||||
|
||||
std::vector<std::string> args;
|
||||
|
||||
|
@ -21,35 +21,29 @@ int main(int argc, char* argv[])
|
|||
try
|
||||
{
|
||||
application = Light::CreateApplication(argv[0], args);
|
||||
LT_ENGINE_ASSERT(application, "main: Light::Application is not intialized");
|
||||
ASSERT(application, "Light::Application is not intialized");
|
||||
|
||||
for (int i = 0; i < argc; i++)
|
||||
LT_ENGINE_INFO("main: argv[{}]: {}", i, argv[i]);
|
||||
LOG(info, "argv[{}]: {}", i, argv[i]);
|
||||
|
||||
application->GameLoop();
|
||||
}
|
||||
// failed engine assertion
|
||||
catch (Light::FailedEngineAssertion)
|
||||
catch (Light::FailedAssertion)
|
||||
{
|
||||
LT_ENGINE_CRITICAL("main: exitting due to unhandled 'FailedEngineAssertion'");
|
||||
LOG(critical, "Terminating due to unhandled 'FailedEngineAssertion'");
|
||||
exitCode = -1;
|
||||
}
|
||||
// failed client assertion
|
||||
catch (Light::FailedClientAssertion)
|
||||
{
|
||||
LT_ENGINE_CRITICAL("main: exitting due to unhandled 'FailedClientAssertion'");
|
||||
exitCode = -2;
|
||||
}
|
||||
// gl exception
|
||||
catch(Light::glException)
|
||||
catch (Light::glException)
|
||||
{
|
||||
LT_ENGINE_CRITICAL("main: exitting due to unhandled 'glException'");
|
||||
LOG(critical, "Terminating due to unhandled 'glException'");
|
||||
exitCode = -3;
|
||||
}
|
||||
// dx exception
|
||||
catch (Light::dxException)
|
||||
{
|
||||
LT_ENGINE_CRITICAL("main: exitting due to unhandled 'dxException'");
|
||||
LOG(critical, "Terminating due to unhandled 'dxException'");
|
||||
exitCode = -4;
|
||||
}
|
||||
|
||||
|
@ -59,7 +53,7 @@ int main(int argc, char* argv[])
|
|||
|
||||
#elif defined(LIGHT_PLATFORM_LINUX)
|
||||
|
||||
#include <LightEngine.h>
|
||||
#include <LightEngine.h>
|
||||
|
||||
// to be defined in client project
|
||||
extern Light::Application* Light::CreateApplication();
|
||||
|
@ -68,31 +62,25 @@ extern Light::Application* Light::CreateApplication();
|
|||
int main(int argc, char* argv[])
|
||||
{
|
||||
Light::Application* application = nullptr;
|
||||
int exitCode = 0;
|
||||
int exitCode = 0;
|
||||
|
||||
try
|
||||
{
|
||||
application = Light::CreateApplication();
|
||||
LT_ENGINE_ASSERT(application, "main: Light::Application is not intialized");
|
||||
ASSERT(application, "Light::Application is not intialized");
|
||||
|
||||
application->GameLoop();
|
||||
}
|
||||
// failed engine assertion
|
||||
catch (Light::FailedEngineAssertion)
|
||||
catch (Light::FailedAssertion)
|
||||
{
|
||||
LT_ENGINE_CRITICAL("main: exitting due to unhandled 'FailedEngineAssertion'");
|
||||
LOG(critical, "Exitting due to unhandled 'FailedEngineAssertion'");
|
||||
exitCode = -1;
|
||||
}
|
||||
// failed client assertion
|
||||
catch (Light::FailedClientAssertion)
|
||||
{
|
||||
LT_ENGINE_CRITICAL("main: exitting due to unhandled 'FailedClientAssertion'");
|
||||
exitCode = -2;
|
||||
}
|
||||
// gl exception
|
||||
catch (Light::glException)
|
||||
{
|
||||
LT_ENGINE_CRITICAL("main: exitting due to unhandled 'glException'");
|
||||
LOG(critical, "main: exitting due to unhandled 'glException'");
|
||||
exitCode = -3;
|
||||
}
|
||||
|
||||
|
@ -100,4 +88,4 @@ int main(int argc, char* argv[])
|
|||
return exitCode;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -1,127 +1,149 @@
|
|||
#pragma once
|
||||
#ifndef LIGHT_DEBUG_TRAP_H
|
||||
#define LIGHT_DEBUG_TRAP_H
|
||||
#define LIGHT_DEBUG_TRAP_H
|
||||
|
||||
#include "Base/Base.h"
|
||||
#include "Base/Base.h"
|
||||
|
||||
// https://github.com/nemequ/portable-snippets/tree/master/debug-trap
|
||||
|
||||
#ifdef LIGHT_DIST
|
||||
#ifdef _MSC_VER
|
||||
#define LT_DEBUG_TRAP() \
|
||||
LT_FILE_CRITICAL("DEBUG_TRAP REQUESTED AT: {}, FILE: {}, LINE: {}", \
|
||||
__FUNCSIG__, __FILE__, __LINE__) // or __FUNCSIG__
|
||||
#ifdef LIGHT_DIST
|
||||
#ifdef _MSC_VER
|
||||
#define LT_DEBUG_TRAP() \
|
||||
LT_FILE_CRITICAL("DEBUG_TRAP REQUESTED AT: {}, FILE: {}, LINE: {}", \
|
||||
__FUNCSIG__, __FILE__, __LINE__) // or __FUNCSIG__
|
||||
|
||||
#else
|
||||
#define LT_DEBUG_TRAP() \
|
||||
LT_FILE_CRITICAL("DEBUG_TRAP REQUESTED AT: {}", __PRETTY_FUNCTION__)
|
||||
#else
|
||||
#define LT_DEBUG_TRAP() \
|
||||
LT_FILE_CRITICAL("DEBUG_TRAP REQUESTED AT: {}", __PRETTY_FUNCTION__)
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(LT_DEBUG_TRAP) && defined(__has_builtin) && !defined(__ibmxl__)
|
||||
#if __has_builtin(__builtin_debugtrap)
|
||||
#define LT_DEBUG_TRAP() __builtin_debugtrap()
|
||||
#if !defined(LT_DEBUG_TRAP) && defined(__has_builtin) && !defined(__ibmxl__)
|
||||
#if __has_builtin(__builtin_debugtrap)
|
||||
#define LT_DEBUG_TRAP() __builtin_debugtrap()
|
||||
|
||||
#elif __has_builtin(__debugbreak)
|
||||
#define LT_DEBUG_TRAP() __debugbreak()
|
||||
#elif __has_builtin(__debugbreak)
|
||||
#define LT_DEBUG_TRAP() __debugbreak()
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(LT_DEBUG_TRAP)
|
||||
#if defined(_MSC_VER) || defined(__INTEL_COMPILER)
|
||||
#define LT_DEBUG_TRAP() __debugbreak()
|
||||
#if !defined(LT_DEBUG_TRAP)
|
||||
#if defined(_MSC_VER) || defined(__INTEL_COMPILER)
|
||||
#define LT_DEBUG_TRAP() __debugbreak()
|
||||
|
||||
#elif defined(__ARMCC_VERSION)
|
||||
#define LT_DEBUG_TRAP() __breakpoint(42)
|
||||
#elif defined(__ARMCC_VERSION)
|
||||
#define LT_DEBUG_TRAP() __breakpoint(42)
|
||||
|
||||
#elif defined(__ibmxl__) || defined(__xlC__)
|
||||
#include <builtins.h>
|
||||
#define LT_DEBUG_TRAP() __trap(42)
|
||||
#elif defined(__ibmxl__) || defined(__xlC__)
|
||||
#include <builtins.h>
|
||||
#define LT_DEBUG_TRAP() __trap(42)
|
||||
|
||||
#elif defined(__DMC__) && defined(_M_IX86)
|
||||
static inline void LT_DEBUG_TRAP(void) { __asm int 3h; }
|
||||
|
||||
#elif defined(__i386__) || defined(__x86_64__)
|
||||
static inline void LT_DEBUG_TRAP(void) { __asm__ __volatile__("int3"); }
|
||||
|
||||
#elif defined(__thumb__)
|
||||
static inline void LT_DEBUG_TRAP(void) { __asm__ __volatile__(".inst 0xde01"); }
|
||||
|
||||
#elif defined(__aarch64__)
|
||||
static inline void LT_DEBUG_TRAP(void) {
|
||||
__asm__ __volatile__(".inst 0xd4200000");
|
||||
#elif defined(__DMC__) && defined(_M_IX86)
|
||||
static inline void LT_DEBUG_TRAP(void)
|
||||
{
|
||||
__asm int 3h;
|
||||
}
|
||||
|
||||
#elif defined(__arm__)
|
||||
static inline void LT_DEBUG_TRAP(void) {
|
||||
__asm__ __volatile__(".inst 0xe7f001f0");
|
||||
#elif defined(__i386__) || defined(__x86_64__)
|
||||
static inline void LT_DEBUG_TRAP(void)
|
||||
{
|
||||
__asm__ __volatile__("int3");
|
||||
}
|
||||
|
||||
#elif defined(__alpha__) && !defined(__osf__)
|
||||
static inline void LT_DEBUG_TRAP(void) { __asm__ __volatile__("bpt"); }
|
||||
|
||||
#elif defined(_54_)
|
||||
static inline void LT_DEBUG_TRAP(void) { __asm__ __volatile__("ESTOP"); }
|
||||
|
||||
#elif defined(_55_)
|
||||
static inline void LT_DEBUG_TRAP(void) {
|
||||
__asm__ __volatile__(
|
||||
";\n .if (.MNEMONIC)\n ESTOP_1\n .else\n ESTOP_1()\n .endif\n NOP");
|
||||
#elif defined(__thumb__)
|
||||
static inline void LT_DEBUG_TRAP(void)
|
||||
{
|
||||
__asm__ __volatile__(".inst 0xde01");
|
||||
}
|
||||
|
||||
#elif defined(_64P_)
|
||||
static inline void LT_DEBUG_TRAP(void) { __asm__ __volatile__("SWBP 0"); }
|
||||
|
||||
#elif defined(_6x_)
|
||||
static inline void LT_DEBUG_TRAP(void) {
|
||||
__asm__ __volatile__("NOP\n .word 0x10000000");
|
||||
#elif defined(__aarch64__)
|
||||
static inline void LT_DEBUG_TRAP(void)
|
||||
{
|
||||
__asm__ __volatile__(".inst 0xd4200000");
|
||||
}
|
||||
|
||||
#elif defined(__STDC_HOSTED__) && (__STDC_HOSTED__ == 0) && defined(__GNUC__)
|
||||
#define LT_DEBUG_TRAP() __builtin_trap()
|
||||
#elif defined(__arm__)
|
||||
static inline void LT_DEBUG_TRAP(void)
|
||||
{
|
||||
__asm__ __volatile__(".inst 0xe7f001f0");
|
||||
}
|
||||
|
||||
#else
|
||||
#include <signal.h>
|
||||
#elif defined(__alpha__) && !defined(__osf__)
|
||||
static inline void LT_DEBUG_TRAP(void)
|
||||
{
|
||||
__asm__ __volatile__("bpt");
|
||||
}
|
||||
|
||||
#if defined(SIGTRAP)
|
||||
#define LT_DEBUG_TRAP() raise(SIGTRAP)
|
||||
#elif defined(_54_)
|
||||
static inline void LT_DEBUG_TRAP(void)
|
||||
{
|
||||
__asm__ __volatile__("ESTOP");
|
||||
}
|
||||
|
||||
#else
|
||||
#define LT_DEBUG_TRAP() raise(SIGABRT)
|
||||
#elif defined(_55_)
|
||||
static inline void LT_DEBUG_TRAP(void)
|
||||
{
|
||||
__asm__ __volatile__(
|
||||
";\n .if (.MNEMONIC)\n ESTOP_1\n .else\n ESTOP_1()\n .endif\n NOP");
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(LT_DEBUG_TRAP)
|
||||
#if !defined(LIGHT_IGNORE_UNDEFINED_DEBUG_TRAP)
|
||||
#error \
|
||||
"failed to define LT_BREAK, define LIGHT_IGNORE_UNDEFINED_DEBUG_TRAP in Config.h to disable this error"
|
||||
|
||||
#elif defined(LIGHT_DIST)
|
||||
#ifdef _MSC_VER
|
||||
#define LT_DEBUG_TRAP() \
|
||||
LT_FILE_CRITICAL("DEBUG_TRAP REQUESTED AT: {}, FILE: {}, LINE: {}", \
|
||||
__FUNCSIG__, __FILE__, __LINE__) // or __FUNCSIG__
|
||||
|
||||
#else
|
||||
#define LT_DEBUG_TRAP() \
|
||||
LT_FILE_CRITICAL("DEBUG_TRAP REQUESTED AT: {}", __PRETTY_FUNCTION__)
|
||||
|
||||
#endif
|
||||
#else /* !defined(LIGHT_DIST) */
|
||||
#ifdef _MSC_VER
|
||||
#define LT_DEBUG_TRAP() \
|
||||
LT_ENGINE_CRITICAL("DEBUG_TRAP REQUESTED AT: {}, FILE: {}, LINE: {}", \
|
||||
__FUNCSIG__, __FILE__, __LINE__) // or __FUNCSIG__
|
||||
|
||||
#else
|
||||
#define LT_DEBUG_TRAP() \
|
||||
LT_ENGINE_CRITICAL("DEBUG_TRAP REQUESTED AT: {}", __PRETTY_FUNCTION__)
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#elif defined(_64P_)
|
||||
static inline void LT_DEBUG_TRAP(void)
|
||||
{
|
||||
__asm__ __volatile__("SWBP 0");
|
||||
}
|
||||
|
||||
#elif defined(_6x_)
|
||||
static inline void LT_DEBUG_TRAP(void)
|
||||
{
|
||||
__asm__ __volatile__("NOP\n .word 0x10000000");
|
||||
}
|
||||
|
||||
#elif defined(__STDC_HOSTED__) && (__STDC_HOSTED__ == 0) && defined(__GNUC__)
|
||||
#define LT_DEBUG_TRAP() __builtin_trap()
|
||||
|
||||
#else
|
||||
#include <signal.h>
|
||||
|
||||
#if defined(SIGTRAP)
|
||||
#define LT_DEBUG_TRAP() raise(SIGTRAP)
|
||||
|
||||
#else
|
||||
#define LT_DEBUG_TRAP() raise(SIGABRT)
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(LT_DEBUG_TRAP)
|
||||
#if !defined(LIGHT_IGNORE_UNDEFINED_DEBUG_TRAP)
|
||||
#error \
|
||||
"failed to define LT_BREAK, define LIGHT_IGNORE_UNDEFINED_DEBUG_TRAP in Config.h to disable this error"
|
||||
|
||||
#elif defined(LIGHT_DIST)
|
||||
#ifdef _MSC_VER
|
||||
#define LT_DEBUG_TRAP() \
|
||||
LOG(critical, "DEBUG_TRAP REQUESTED AT: {}, FILE: {}, LINE: {}", \
|
||||
__FUNCSIG__, __FILE__, __LINE__) // or __FUNCSIG__
|
||||
|
||||
#else
|
||||
#define LT_DEBUG_TRAP() \
|
||||
LOG(critical, "DEBUG_TRAP REQUESTED AT: {}", __PRETTY_FUNCTION__)
|
||||
|
||||
#endif
|
||||
#else /* !defined(LIGHT_DIST) */
|
||||
#ifdef _MSC_VER
|
||||
#define LT_DEBUG_TRAP() \
|
||||
LOG(critical, "DEBUG_TRAP REQUESTED AT: {}, FILE: {}, LINE: {}", \
|
||||
__FUNCSIG__, __FILE__, __LINE__) // or __FUNCSIG__
|
||||
|
||||
#else
|
||||
#define LT_DEBUG_TRAP() \
|
||||
LOG(critical, "DEBUG_TRAP REQUESTED AT: {}", __PRETTY_FUNCTION__)
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -1,156 +1,148 @@
|
|||
#include "Application.h"
|
||||
|
||||
#include "Window.h"
|
||||
|
||||
#include "Debug/Instrumentor.h"
|
||||
|
||||
#include "Events/Event.h"
|
||||
|
||||
#include "Graphics/GraphicsContext.h"
|
||||
#include "Graphics/Renderer.h"
|
||||
#include "Graphics/RenderCommand.h"
|
||||
|
||||
#include "Graphics/Renderer.h"
|
||||
#include "Layer/Layer.h"
|
||||
|
||||
#include "Time/Timer.h"
|
||||
|
||||
#include "UserInterface/UserInterface.h"
|
||||
#include "Window.h"
|
||||
|
||||
namespace Light {
|
||||
|
||||
Application* Application::s_Context = nullptr;
|
||||
Application* Application::s_Context = nullptr;
|
||||
|
||||
Application::Application(std::string execName, std::vector<std::string> args)
|
||||
: m_Instrumentor(nullptr),
|
||||
m_LayerStack(nullptr),
|
||||
m_Input(nullptr),
|
||||
m_Window(nullptr)
|
||||
Application::Application(std::string execName, std::vector<std::string> args)
|
||||
: m_Instrumentor(nullptr), m_LayerStack(nullptr), m_Input(nullptr), m_Window(nullptr)
|
||||
{
|
||||
ASSERT(!s_Context, "Repeated singleton construction");
|
||||
s_Context = this;
|
||||
|
||||
m_Logger = Logger::Create();
|
||||
LogDebugData();
|
||||
|
||||
m_Instrumentor = Instrumentor::Create();
|
||||
m_Instrumentor->BeginSession("Logs/ProfileResults_Startup.json");
|
||||
|
||||
m_LayerStack = LayerStack::Create();
|
||||
m_Input = Input::Create();
|
||||
|
||||
m_ResourceManager = ResourceManager::Create();
|
||||
|
||||
m_Window = Window::Create(std::bind(&Application::OnEvent, this, std::placeholders::_1));
|
||||
}
|
||||
|
||||
Application::~Application()
|
||||
{
|
||||
LOG(trace, "Application::~Application()");
|
||||
m_Instrumentor->EndSession(); // ProfileResults_Termination //
|
||||
}
|
||||
|
||||
void Application::GameLoop()
|
||||
{
|
||||
// check
|
||||
ASSERT(!m_LayerStack->IsEmpty(), "LayerStack is empty");
|
||||
|
||||
// log debug data
|
||||
m_Logger->LogDebugData();
|
||||
m_Window->GetGfxContext()->LogDebugData();
|
||||
m_Window->GetGfxContext()->GetUserInterface()->LogDebugData();
|
||||
|
||||
// reveal window
|
||||
m_Window->SetVisibility(true);
|
||||
|
||||
m_Instrumentor->EndSession(); // ProfileResults_GameLoop //
|
||||
m_Instrumentor->BeginSession("Logs/ProfileResults_GameLoop.json");
|
||||
|
||||
/* game loop */
|
||||
DeltaTimer deltaTimer;
|
||||
while (!m_Window->IsClosed())
|
||||
{
|
||||
LT_ENGINE_ASSERT(!s_Context, "Application::Application: repeated singleton construction");
|
||||
s_Context = this;
|
||||
|
||||
m_Logger = Logger::Create();
|
||||
LogDebugData();
|
||||
|
||||
m_Instrumentor = Instrumentor::Create();
|
||||
m_Instrumentor->BeginSession("Logs/ProfileResults_Startup.json");
|
||||
|
||||
m_LayerStack = LayerStack::Create();
|
||||
m_Input = Input::Create();
|
||||
|
||||
m_ResourceManager = ResourceManager::Create();
|
||||
|
||||
m_Window = Window::Create(std::bind(&Application::OnEvent, this, std::placeholders::_1));
|
||||
}
|
||||
|
||||
Application::~Application()
|
||||
{
|
||||
LT_ENGINE_TRACE("Application::~Application()");
|
||||
m_Instrumentor->EndSession(); // ProfileResults_Termination //
|
||||
}
|
||||
|
||||
void Application::GameLoop()
|
||||
{
|
||||
// check
|
||||
LT_ENGINE_ASSERT(!m_LayerStack->IsEmpty(), "Application::GameLoop(pre): LayerStack is empty");
|
||||
|
||||
// log debug data
|
||||
m_Logger->LogDebugData();
|
||||
m_Window->GetGfxContext()->LogDebugData();
|
||||
m_Window->GetGfxContext()->GetUserInterface()->LogDebugData();
|
||||
|
||||
// reveal window
|
||||
m_Window->SetVisibility(true);
|
||||
|
||||
m_Instrumentor->EndSession(); // ProfileResults_GameLoop //
|
||||
m_Instrumentor->BeginSession("Logs/ProfileResults_GameLoop.json");
|
||||
|
||||
/* game loop */
|
||||
DeltaTimer deltaTimer;
|
||||
while (!m_Window->IsClosed())
|
||||
{
|
||||
{
|
||||
// update layers
|
||||
LT_PROFILE_SCOPE("GameLoop::Update");
|
||||
// update layers
|
||||
LT_PROFILE_SCOPE("GameLoop::Update");
|
||||
|
||||
for (auto it = m_LayerStack->begin(); it != m_LayerStack->end(); it++)
|
||||
(*it)->OnUpdate(deltaTimer.GetDeltaTime());
|
||||
}
|
||||
|
||||
{
|
||||
// render layers
|
||||
LT_PROFILE_SCOPE("GameLoop::Render");
|
||||
m_Window->GetGfxContext()->GetRenderer()->BeginFrame();
|
||||
|
||||
for (auto it = m_LayerStack->begin(); it != m_LayerStack->end(); it++)
|
||||
(*it)->OnRender();
|
||||
|
||||
m_Window->GetGfxContext()->GetRenderer()->EndFrame();
|
||||
}
|
||||
|
||||
{
|
||||
// render user interface
|
||||
LT_PROFILE_SCOPE("GameLoop::UserInterface");
|
||||
m_Window->GetGfxContext()->GetUserInterface()->Begin();
|
||||
|
||||
for (auto it = m_LayerStack->begin(); it != m_LayerStack->end(); it++)
|
||||
(*it)->OnUserInterfaceUpdate();
|
||||
|
||||
m_Window->GetGfxContext()->GetUserInterface()->End();
|
||||
}
|
||||
|
||||
{
|
||||
// poll events
|
||||
LT_PROFILE_SCOPE("GameLoop::Events");
|
||||
m_Window->PollEvents();
|
||||
}
|
||||
|
||||
/// update delta time
|
||||
deltaTimer.Update();
|
||||
}
|
||||
|
||||
m_Instrumentor->EndSession(); // ProfileResults_GameLoop //
|
||||
m_Instrumentor->BeginSession("Logs/ProfileResults_Termination.json");
|
||||
}
|
||||
|
||||
void Application::Quit()
|
||||
{
|
||||
s_Context->m_Window->Close();
|
||||
}
|
||||
|
||||
void Application::OnEvent(const Event& event)
|
||||
{
|
||||
// window
|
||||
if (event.HasCategory(WindowEventCategory))
|
||||
{
|
||||
m_Window->OnEvent(event);
|
||||
|
||||
if(event.GetEventType() == EventType::WindowResized)
|
||||
m_Window->GetGfxContext()->GetRenderer()->OnWindowResize((const WindowResizedEvent&)event);
|
||||
for (auto it = m_LayerStack->begin(); it != m_LayerStack->end(); it++)
|
||||
(*it)->OnUpdate(deltaTimer.GetDeltaTime());
|
||||
}
|
||||
|
||||
// input
|
||||
if (event.HasCategory(InputEventCategory))
|
||||
{
|
||||
m_Input->OnEvent(event);
|
||||
// render layers
|
||||
LT_PROFILE_SCOPE("GameLoop::Render");
|
||||
m_Window->GetGfxContext()->GetRenderer()->BeginFrame();
|
||||
|
||||
if(!m_Input->IsReceivingGameEvents()) // return if the event is an input event and 'Input' has disabled the game events
|
||||
return;
|
||||
for (auto it = m_LayerStack->begin(); it != m_LayerStack->end(); it++)
|
||||
(*it)->OnRender();
|
||||
|
||||
m_Window->GetGfxContext()->GetRenderer()->EndFrame();
|
||||
}
|
||||
|
||||
/* layers */
|
||||
for (auto it = m_LayerStack->rbegin(); it != m_LayerStack->rend(); it++)
|
||||
if ((*it)->OnEvent(event)) return;
|
||||
{
|
||||
// render user interface
|
||||
LT_PROFILE_SCOPE("GameLoop::UserInterface");
|
||||
m_Window->GetGfxContext()->GetUserInterface()->Begin();
|
||||
|
||||
for (auto it = m_LayerStack->begin(); it != m_LayerStack->end(); it++)
|
||||
(*it)->OnUserInterfaceUpdate();
|
||||
|
||||
m_Window->GetGfxContext()->GetUserInterface()->End();
|
||||
}
|
||||
|
||||
{
|
||||
// poll events
|
||||
LT_PROFILE_SCOPE("GameLoop::Events");
|
||||
m_Window->PollEvents();
|
||||
}
|
||||
|
||||
/// update delta time
|
||||
deltaTimer.Update();
|
||||
}
|
||||
|
||||
void Application::LogDebugData()
|
||||
m_Instrumentor->EndSession(); // ProfileResults_GameLoop //
|
||||
m_Instrumentor->BeginSession("Logs/ProfileResults_Termination.json");
|
||||
}
|
||||
|
||||
void Application::Quit()
|
||||
{
|
||||
s_Context->m_Window->Close();
|
||||
}
|
||||
|
||||
void Application::OnEvent(const Event& event)
|
||||
{
|
||||
// window
|
||||
if (event.HasCategory(WindowEventCategory))
|
||||
{
|
||||
// #todo: log more information
|
||||
LT_ENGINE_INFO("________________________________________");
|
||||
LT_ENGINE_INFO("Platform::");
|
||||
LT_ENGINE_INFO(" OS: {}", LT_BUILD_PLATFORM);
|
||||
LT_ENGINE_INFO(" DIR: {}", std::filesystem::current_path().generic_string());
|
||||
LT_ENGINE_INFO("________________________________________");
|
||||
m_Window->OnEvent(event);
|
||||
|
||||
if (event.GetEventType() == EventType::WindowResized)
|
||||
m_Window->GetGfxContext()->GetRenderer()->OnWindowResize((const WindowResizedEvent&)event);
|
||||
}
|
||||
|
||||
}
|
||||
// input
|
||||
if (event.HasCategory(InputEventCategory))
|
||||
{
|
||||
m_Input->OnEvent(event);
|
||||
|
||||
if (!m_Input->IsReceivingGameEvents()) // return if the event is an input event and 'Input' has disabled the game events
|
||||
return;
|
||||
}
|
||||
|
||||
/* layers */
|
||||
for (auto it = m_LayerStack->rbegin(); it != m_LayerStack->rend(); it++)
|
||||
if ((*it)->OnEvent(event))
|
||||
return;
|
||||
}
|
||||
|
||||
void Application::LogDebugData()
|
||||
{
|
||||
// #todo: log more information
|
||||
LOG(info, "________________________________________");
|
||||
LOG(info, "Platform::");
|
||||
LOG(info, " OS: {}", LT_BUILD_PLATFORM);
|
||||
LOG(info, " DIR: {}", std::filesystem::current_path().generic_string());
|
||||
LOG(info, "________________________________________");
|
||||
}
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -10,52 +10,46 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
FailedEngineAssertion::FailedEngineAssertion(const char* file, int line)
|
||||
{
|
||||
LT_ENGINE_CRITICAL("FailedAssertion::FailedAssertion: engine assertion failed in: {} (line {})", file, line);
|
||||
}
|
||||
FailedAssertion::FailedAssertion(const char* file, int line)
|
||||
{
|
||||
LOG(critical, "Assertion failed in: {} (line {})", file, line);
|
||||
}
|
||||
|
||||
FailedClientAssertion::FailedClientAssertion(const char* file, int line)
|
||||
{
|
||||
LT_ENGINE_CRITICAL("FailedClientAssertion::FailedClientAssertion: client assertion failed in: {} (line {})", file, line);
|
||||
}
|
||||
|
||||
glException::glException(unsigned int source, unsigned int type, unsigned int id, const char* msg)
|
||||
{
|
||||
// #todo: improve
|
||||
LT_ENGINE_CRITICAL("________________________________________");
|
||||
LT_ENGINE_CRITICAL("glException::glException::");
|
||||
LT_ENGINE_CRITICAL(" Severity: {}", Stringifier::glDebugMsgSeverity(GL_DEBUG_SEVERITY_HIGH));
|
||||
LT_ENGINE_CRITICAL(" Source : {}", Stringifier::glDebugMsgSource(source));
|
||||
LT_ENGINE_CRITICAL(" Type : {}", Stringifier::glDebugMsgType(type));
|
||||
LT_ENGINE_CRITICAL(" ID : {}", id);
|
||||
LT_ENGINE_CRITICAL(" Vendor : {}", glGetString(GL_VENDOR));
|
||||
LT_ENGINE_CRITICAL(" Renderer: {}", glGetString(GL_RENDERER));
|
||||
LT_ENGINE_CRITICAL(" Version : {}", glGetString(GL_VERSION));
|
||||
LT_ENGINE_CRITICAL(" SVersion: {}", glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||
LT_ENGINE_CRITICAL(" {}", msg);
|
||||
|
||||
LT_ENGINE_CRITICAL("________________________________________");
|
||||
}
|
||||
glException::glException(unsigned int source, unsigned int type, unsigned int id, const char* msg)
|
||||
{
|
||||
// #todo: improve
|
||||
LOG(critical, "________________________________________");
|
||||
LOG(critical, "glException::glException::");
|
||||
LOG(critical, " Severity: {}", Stringifier::glDebugMsgSeverity(GL_DEBUG_SEVERITY_HIGH));
|
||||
LOG(critical, " Source : {}", Stringifier::glDebugMsgSource(source));
|
||||
LOG(critical, " Type : {}", Stringifier::glDebugMsgType(type));
|
||||
LOG(critical, " ID : {}", id);
|
||||
LOG(critical, " Vendor : {}", glGetString(GL_VENDOR));
|
||||
LOG(critical, " Renderer: {}", glGetString(GL_RENDERER));
|
||||
LOG(critical, " Version : {}", glGetString(GL_VERSION));
|
||||
LOG(critical, " critical, SVersion: {}", glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||
LOG(critical, " {}", msg);
|
||||
LOG(critical, "________________________________________");
|
||||
}
|
||||
|
||||
#ifdef LIGHT_PLATFORM_WINDOWS
|
||||
dxException::dxException(long hr, const char* file, int line)
|
||||
{
|
||||
char* message;
|
||||
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
nullptr, hr,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPSTR)(&message), NULL, nullptr);
|
||||
dxException::dxException(long hr, const char* file, int line)
|
||||
{
|
||||
char* message;
|
||||
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
nullptr, hr,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPSTR)(&message), NULL, nullptr);
|
||||
|
||||
// #todo: improve
|
||||
LT_ENGINE_CRITICAL("________________________________________");
|
||||
LT_ENGINE_CRITICAL("dxException::dxException::");
|
||||
LT_ENGINE_CRITICAL(" File: {}, Line: {}", file, line);
|
||||
LT_ENGINE_CRITICAL(" {}", message);
|
||||
LT_ENGINE_CRITICAL("________________________________________");
|
||||
// #todo: improve
|
||||
LOG(critical, "________________________________________");
|
||||
LOG(critical, "dxException::dxException::");
|
||||
LOG(critical, " File: {}, Line: {}", file, line);
|
||||
LOG(critical, " {}", message);
|
||||
LOG(critical, "________________________________________");
|
||||
|
||||
LocalFree(message);
|
||||
}
|
||||
LocalFree(message);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,33 +1,33 @@
|
|||
#pragma once
|
||||
|
||||
#define DXC(x) DXC_NO_REDIFINITION(x, __LINE__)
|
||||
|
||||
#define DXC_NO_REDIFINITION(x, line) DXC_NO_REDIFINITION2(x, line)
|
||||
#define DXC_NO_REDIFINITION2(x, line) HRESULT hr##line; if(FAILED(hr##line = x)) throw dxException(hr##line, __FILE__, line)
|
||||
|
||||
#define DXC_NO_REDIFINITION2(x, line) \
|
||||
HRESULT hr##line; \
|
||||
if (FAILED(hr##line = x)) \
|
||||
throw dxException(hr##line, __FILE__, line)
|
||||
|
||||
namespace Light {
|
||||
|
||||
struct FailedEngineAssertion : std::exception
|
||||
{
|
||||
FailedEngineAssertion(const char* file, int line);
|
||||
};
|
||||
|
||||
struct FailedClientAssertion : std::exception
|
||||
{
|
||||
FailedClientAssertion(const char* file, int line);
|
||||
};
|
||||
struct FailedAssertion: std::exception
|
||||
{
|
||||
FailedAssertion(const char* file, int line);
|
||||
};
|
||||
|
||||
// OpenGL
|
||||
struct glException : std::exception
|
||||
{
|
||||
glException(unsigned int source, unsigned int type, unsigned int id, const char* msg);
|
||||
};
|
||||
// OpenGL
|
||||
struct glException: std::exception
|
||||
{
|
||||
glException(unsigned int source, unsigned int type, unsigned int id, const char* msg);
|
||||
};
|
||||
|
||||
#ifdef LIGHT_PLATFORM_WINDOWS
|
||||
// DirectX
|
||||
struct dxException : std::exception
|
||||
{
|
||||
dxException(long hr, const char* file, int line);
|
||||
};
|
||||
// DirectX
|
||||
struct dxException: std::exception
|
||||
{
|
||||
dxException(long hr, const char* file, int line);
|
||||
};
|
||||
#endif
|
||||
|
||||
}
|
||||
} // namespace Light
|
||||
|
|
|
@ -2,71 +2,71 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
Instrumentor* Instrumentor::s_Context = nullptr;
|
||||
Instrumentor* Instrumentor::s_Context = nullptr;
|
||||
|
||||
Scope<Instrumentor> Instrumentor::Create()
|
||||
{
|
||||
return MakeScope<Instrumentor>(new Instrumentor);
|
||||
}
|
||||
|
||||
Instrumentor::Instrumentor()
|
||||
: m_CurrentSessionCount(0u)
|
||||
{
|
||||
// #todo: maintenance
|
||||
LT_ENGINE_ASSERT(!s_Context, "Instrumentor::Instrumentor: an instance of 'Instrumentor' already exists, do not construct this class!");
|
||||
s_Context = this;
|
||||
}
|
||||
Scope<Instrumentor> Instrumentor::Create()
|
||||
{
|
||||
return MakeScope<Instrumentor>(new Instrumentor);
|
||||
}
|
||||
|
||||
void Instrumentor::BeginSessionImpl(const std::string& outputPath)
|
||||
{
|
||||
std::filesystem::create_directory(outputPath.substr(0, outputPath.find_last_of('/') + 1));
|
||||
Instrumentor::Instrumentor()
|
||||
: m_CurrentSessionCount(0u)
|
||||
{
|
||||
// #todo: maintenance
|
||||
ASSERT(!s_Context, "An instance of 'Instrumentor' already exists, do not construct this class!");
|
||||
s_Context = this;
|
||||
}
|
||||
|
||||
m_OutputFileStream.open(outputPath);
|
||||
m_OutputFileStream << "{\"traceEvents\":[";
|
||||
}
|
||||
void Instrumentor::BeginSessionImpl(const std::string& outputPath)
|
||||
{
|
||||
std::filesystem::create_directory(outputPath.substr(0, outputPath.find_last_of('/') + 1));
|
||||
|
||||
void Instrumentor::EndSessionImpl()
|
||||
{
|
||||
if (m_CurrentSessionCount == 0u)
|
||||
LT_ENGINE_WARN("Instrumentor::EndSessionImpl: 0 profiling for the ended session");
|
||||
m_OutputFileStream.open(outputPath);
|
||||
m_OutputFileStream << "{\"traceEvents\":[";
|
||||
}
|
||||
|
||||
m_CurrentSessionCount = 0u;
|
||||
void Instrumentor::EndSessionImpl()
|
||||
{
|
||||
if (m_CurrentSessionCount == 0u)
|
||||
LOG(warn, "0 profiling for the ended session");
|
||||
|
||||
m_OutputFileStream << "]}";
|
||||
m_OutputFileStream.flush();
|
||||
m_OutputFileStream.close();
|
||||
}
|
||||
m_CurrentSessionCount = 0u;
|
||||
|
||||
void Instrumentor::SubmitScopeProfileImpl(const ScopeProfileResult& profileResult)
|
||||
{
|
||||
if (m_CurrentSessionCount++ == 0u)
|
||||
m_OutputFileStream << "{";
|
||||
else
|
||||
m_OutputFileStream << ",{";
|
||||
m_OutputFileStream << "]}";
|
||||
m_OutputFileStream.flush();
|
||||
m_OutputFileStream.close();
|
||||
}
|
||||
|
||||
m_OutputFileStream << "\"name\":\"" << profileResult.name << "\",";
|
||||
m_OutputFileStream << "\"cat\": \"scope\",";
|
||||
m_OutputFileStream << "\"ph\": \"X\",";
|
||||
m_OutputFileStream << "\"ts\":" << profileResult.start << ",";
|
||||
m_OutputFileStream << "\"dur\":" << profileResult.duration << ",";
|
||||
m_OutputFileStream << "\"pid\":0,";
|
||||
m_OutputFileStream << "\"tid\":" << profileResult.threadID<< "";
|
||||
m_OutputFileStream << "}";
|
||||
}
|
||||
void Instrumentor::SubmitScopeProfileImpl(const ScopeProfileResult& profileResult)
|
||||
{
|
||||
if (m_CurrentSessionCount++ == 0u)
|
||||
m_OutputFileStream << "{";
|
||||
else
|
||||
m_OutputFileStream << ",{";
|
||||
|
||||
InstrumentorTimer::InstrumentorTimer(const std::string& scopeName)
|
||||
: m_Result( { scopeName, 0, 0, 0 } ), m_Start(std::chrono::steady_clock::now())
|
||||
{
|
||||
}
|
||||
m_OutputFileStream << "\"name\":\"" << profileResult.name << "\",";
|
||||
m_OutputFileStream << "\"cat\": \"scope\",";
|
||||
m_OutputFileStream << "\"ph\": \"X\",";
|
||||
m_OutputFileStream << "\"ts\":" << profileResult.start << ",";
|
||||
m_OutputFileStream << "\"dur\":" << profileResult.duration << ",";
|
||||
m_OutputFileStream << "\"pid\":0,";
|
||||
m_OutputFileStream << "\"tid\":" << profileResult.threadID << "";
|
||||
m_OutputFileStream << "}";
|
||||
}
|
||||
|
||||
InstrumentorTimer::~InstrumentorTimer()
|
||||
{
|
||||
auto end = std::chrono::steady_clock::now();
|
||||
InstrumentorTimer::InstrumentorTimer(const std::string& scopeName)
|
||||
: m_Result({ scopeName, 0, 0, 0 }), m_Start(std::chrono::steady_clock::now())
|
||||
{
|
||||
}
|
||||
|
||||
m_Result.start = std::chrono::time_point_cast<std::chrono::microseconds>(m_Start).time_since_epoch().count();
|
||||
m_Result.duration = std::chrono::time_point_cast<std::chrono::microseconds>(end).time_since_epoch().count() - m_Result.start;
|
||||
InstrumentorTimer::~InstrumentorTimer()
|
||||
{
|
||||
auto end = std::chrono::steady_clock::now();
|
||||
|
||||
Instrumentor::SubmitScopeProfile(m_Result);
|
||||
}
|
||||
m_Result.start = std::chrono::time_point_cast<std::chrono::microseconds>(m_Start).time_since_epoch().count();
|
||||
m_Result.duration = std::chrono::time_point_cast<std::chrono::microseconds>(end).time_since_epoch().count() - m_Result.start;
|
||||
|
||||
}
|
||||
Instrumentor::SubmitScopeProfile(m_Result);
|
||||
}
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,60 +1,53 @@
|
|||
#include "Logger.h"
|
||||
|
||||
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||
#include <spdlog/sinks/basic_file_sink.h>
|
||||
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||
|
||||
namespace Light {
|
||||
|
||||
Logger* Logger::s_Context = nullptr;
|
||||
Logger* Logger::s_Context = nullptr;
|
||||
|
||||
Scope<Logger> Logger::Create()
|
||||
{
|
||||
return MakeScope<Logger>(new Logger());
|
||||
}
|
||||
Scope<Logger> Logger::Create()
|
||||
{
|
||||
return MakeScope<Logger>(new Logger());
|
||||
}
|
||||
|
||||
Logger::Logger()
|
||||
: m_EngineLogger(nullptr),
|
||||
m_ClientLogger(nullptr),
|
||||
m_FileLogger(nullptr),
|
||||
m_LogFilePath(LT_LOG_FILE_LOCATION)
|
||||
{
|
||||
LT_ENGINE_ASSERT(!s_Context, "Logger::Logger: an instance of 'Logger' already exists, do not construct this class!");
|
||||
s_Context = this;
|
||||
Logger::Logger()
|
||||
: m_EngineLogger(nullptr), m_FileLogger(nullptr), m_LogFilePath(LT_LOG_FILE_LOCATION)
|
||||
{
|
||||
ASSERT(!s_Context, "An instance of 'Logger' already exists, do not construct this class!");
|
||||
s_Context = this;
|
||||
|
||||
// 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
|
||||
// set spdlog pattern
|
||||
// create loggers
|
||||
spdlog::set_pattern("%^[%H:%M:%S]%g@%! ==> %v%$");
|
||||
#ifndef LIGHT_DIST
|
||||
m_EngineLogger = spdlog::stdout_color_mt("Engine");
|
||||
m_ClientLogger = spdlog::stdout_color_mt("Client");
|
||||
spdlog::set_pattern("%^[%H:%M:%S]%! ==> %v%$");
|
||||
m_EngineLogger = spdlog::stdout_color_mt("Engine");
|
||||
#endif
|
||||
m_FileLogger = spdlog::basic_logger_mt("File", m_LogFilePath);
|
||||
m_FileLogger->set_pattern("%^[%M:%S:%e] <%l>: %v%$");
|
||||
|
||||
// set level
|
||||
#if defined(LIGHT_DEBUG)
|
||||
m_EngineLogger->set_level(spdlog::level::trace);
|
||||
m_ClientLogger->set_level(spdlog::level::trace);
|
||||
#elif defined (LIGHT_RELEASE)
|
||||
s_EngineLogger->set_level(spdlog::level::info);
|
||||
s_ClientLogger->set_level(spdlog::level::info);
|
||||
m_FileLogger = spdlog::basic_logger_mt("File", m_LogFilePath);
|
||||
m_FileLogger->set_pattern("%^[%M:%S:%e] <%l>: %v%$");
|
||||
|
||||
// set level
|
||||
#if defined(LIGHT_DEBUG)
|
||||
m_EngineLogger->set_level(spdlog::level::trace);
|
||||
m_ClientLogger->set_level(spdlog::level::trace);
|
||||
#elif defined(LIGHT_RELEASE)
|
||||
s_EngineLogger->set_level(spdlog::level::info);
|
||||
s_ClientLogger->set_level(spdlog::level::info);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::LogDebugData()
|
||||
{
|
||||
// #todo: improve
|
||||
LT_ENGINE_INFO("________________________________________");
|
||||
LT_ENGINE_INFO("Logger::");
|
||||
LT_ENGINE_INFO(" ClientLevel : {}", Stringifier::spdlogLevel(m_ClientLogger->level()));
|
||||
LT_ENGINE_INFO(" EngineLevel : {}", Stringifier::spdlogLevel(m_EngineLogger->level()));
|
||||
LT_ENGINE_INFO(" FileLevel : {}", Stringifier::spdlogLevel(m_FileLogger->level()));
|
||||
LT_ENGINE_INFO(" DefaultLevel: {}", Stringifier::spdlogLevel(spdlog::get_level()));
|
||||
LT_ENGINE_INFO("________________________________________");
|
||||
}
|
||||
void Logger::LogDebugData()
|
||||
{
|
||||
// #todo: improve
|
||||
LOG(info, "________________________________________");
|
||||
LOG(info, "Logger::");
|
||||
LOG(info, " EngineLevel : {}", Stringifier::spdlogLevel(m_EngineLogger->level()));
|
||||
LOG(info, " FileLevel : {}", Stringifier::spdlogLevel(m_FileLogger->level()));
|
||||
LOG(info, " DefaultLevel: {}", Stringifier::spdlogLevel(spdlog::get_level()));
|
||||
LOG(info, "________________________________________");
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,73 +1,43 @@
|
|||
#pragma once
|
||||
#ifndef LIGHT_LOGGER_H
|
||||
#define LIGHT_LOGGER_H
|
||||
#define LIGHT_LOGGER_H
|
||||
|
||||
#include "Base/Base.h"
|
||||
#include "Base/Base.h"
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
// LOGGER MACROS //
|
||||
#define LT_LOG_FILE_LOCATION "Logs/Logger.txt"
|
||||
|
||||
#define LT_LOG_FILE_LOCATION "Logs/Logger.txt"
|
||||
|
||||
// File
|
||||
#define LT_FILE_INFO(...) ::Light::Logger::GetFileLogger()->log(spdlog::level::info , __VA_ARGS__)
|
||||
#define LT_FILE_WARN(...) ::Light::Logger::GetFileLogger()->log(spdlog::level::warn , __VA_ARGS__)
|
||||
#define LT_FILE_ERROR(...) ::Light::Logger::GetFileLogger()->log(spdlog::level::err , __VA_ARGS__)
|
||||
#define LT_FILE_CRITICAL(...) ::Light::Logger::GetFileLogger()->log(spdlog::level::critical, __VA_ARGS__)
|
||||
|
||||
#ifndef LIGHT_DIST
|
||||
// Engine
|
||||
#define LT_ENGINE_TRACE(...) ::Light::Logger::GetEngineLogger()->log(spdlog::level::trace , __VA_ARGS__)
|
||||
#define LT_ENGINE_INFO(...) ::Light::Logger::GetEngineLogger()->log(spdlog::level::info , __VA_ARGS__)
|
||||
#define LT_ENGINE_WARN(...) ::Light::Logger::GetEngineLogger()->log(spdlog::level::warn , __VA_ARGS__)
|
||||
#define LT_ENGINE_ERROR(...) ::Light::Logger::GetEngineLogger()->log(spdlog::level::err , __VA_ARGS__)
|
||||
#define LT_ENGINE_CRITICAL(...) ::Light::Logger::GetEngineLogger()->log(spdlog::level::critical, __VA_ARGS__)
|
||||
|
||||
// Client
|
||||
#define LT_CLIENT_TRACE(...) ::Light::Logger::GetClientLogger()->log(spdlog::level::trace , __VA_ARGS__)
|
||||
#define LT_CLIENT_INFO(...) ::Light::Logger::GetClientLogger()->log(spdlog::level::info , __VA_ARGS__)
|
||||
#define LT_CLIENT_WARN(...) ::Light::Logger::GetClientLogger()->log(spdlog::level::warn , __VA_ARGS__)
|
||||
#define LT_CLIENT_ERROR(...) ::Light::Logger::GetClientLogger()->log(spdlog::level::err , __VA_ARGS__)
|
||||
#define LT_CLIENT_CRITICAL(...) ::Light::Logger::GetClientLogger()->log(spdlog::level::critical, __VA_ARGS__)
|
||||
#else
|
||||
#define LT_ENGINE_TRACE(...)
|
||||
#define LT_ENGINE_INFO(...)
|
||||
#define LT_ENGINE_WARN(...)
|
||||
#define LT_ENGINE_ERROR(...)
|
||||
#define LT_ENGINE_CRITICAL(...)
|
||||
#define LT_CLIENT_TRACE(...)
|
||||
#define LT_CLIENT_INFO(...)
|
||||
#define LT_CLIENT_WARN(...)
|
||||
#define LT_CLIENT_ERROR(...)
|
||||
#define LT_CLIENT_CRITICAL(...)
|
||||
#endif
|
||||
#ifndef LIGHT_DIST
|
||||
#define LOG(logLevel, ...) SPDLOG_LOGGER_CALL(::Light::Logger::GetEngineLogger(), spdlog::level::logLevel, __VA_ARGS__)
|
||||
#else
|
||||
#define LOG(logLevel, ...) SPDLOG_LOGGER_CALL(::Light::Logger::GetFileLogger(), spdlog::level::logLevel, __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
namespace Light {
|
||||
|
||||
// #todo: extend
|
||||
class Logger /* singleton */
|
||||
{
|
||||
private:
|
||||
static Logger* s_Context;
|
||||
// #todo: extend
|
||||
class Logger /* singleton */
|
||||
{
|
||||
private:
|
||||
static Logger* s_Context;
|
||||
|
||||
private:
|
||||
Ref<spdlog::logger> m_EngineLogger, m_ClientLogger, m_FileLogger;
|
||||
std::string m_LogFilePath;
|
||||
private:
|
||||
Ref<spdlog::logger> m_EngineLogger, m_FileLogger;
|
||||
std::string m_LogFilePath;
|
||||
|
||||
public:
|
||||
static Scope<Logger> Create();
|
||||
public:
|
||||
static Scope<Logger> Create();
|
||||
|
||||
static inline Ref<spdlog::logger> GetEngineLogger() { return s_Context->m_EngineLogger; }
|
||||
static inline Ref<spdlog::logger> GetClientLogger() { return s_Context->m_ClientLogger; }
|
||||
static inline Ref<spdlog::logger> GetFileLogger() { return s_Context->m_FileLogger; }
|
||||
static inline Ref<spdlog::logger> GetEngineLogger() { return s_Context->m_EngineLogger; }
|
||||
static inline Ref<spdlog::logger> GetFileLogger() { return s_Context->m_FileLogger; }
|
||||
|
||||
void LogDebugData();
|
||||
void LogDebugData();
|
||||
|
||||
private:
|
||||
Logger();
|
||||
};
|
||||
private:
|
||||
Logger();
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Light
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "Blender.h"
|
||||
|
||||
#include "OpenGL/glBlender.h"
|
||||
|
||||
#ifdef LIGHT_PLATFORM_WINDOWS
|
||||
|
@ -10,19 +11,19 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
Scope<Blender> Blender::Create(Ref<SharedContext> sharedContext)
|
||||
Scope<Blender> Blender::Create(Ref<SharedContext> sharedContext)
|
||||
{
|
||||
switch (GraphicsContext::GetGraphicsAPI())
|
||||
{
|
||||
switch (GraphicsContext::GetGraphicsAPI())
|
||||
{
|
||||
case GraphicsAPI::OpenGL:
|
||||
return CreateScope<glBlender>();
|
||||
case GraphicsAPI::OpenGL:
|
||||
return CreateScope<glBlender>();
|
||||
|
||||
case GraphicsAPI::DirectX: LT_WIN(
|
||||
return CreateScope<dxBlender>(std::static_pointer_cast<dxSharedContext>(sharedContext));)
|
||||
case GraphicsAPI::DirectX: LT_WIN(
|
||||
return CreateScope<dxBlender>(std::static_pointer_cast<dxSharedContext>(sharedContext));)
|
||||
|
||||
default:
|
||||
LT_ENGINE_ASSERT(false, "Blender::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
|
||||
}
|
||||
default:
|
||||
ASSERT(false, "Invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "Buffers.h"
|
||||
#include "OpenGL/glBuffers.h"
|
||||
|
||||
#include "OpenGL/glBuffers.h"
|
||||
#include "SharedContext.h"
|
||||
|
||||
#ifdef LIGHT_PLATFORM_WINDOWS
|
||||
|
@ -12,58 +12,58 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
//================================================== CONSTANT_BUFFER ==================================================//
|
||||
Scope<ConstantBuffer> ConstantBuffer::Create(ConstantBufferIndex index, unsigned int size, Ref<SharedContext> sharedContext)
|
||||
//================================================== CONSTANT_BUFFER ==================================================//
|
||||
Scope<ConstantBuffer> ConstantBuffer::Create(ConstantBufferIndex index, unsigned int size, Ref<SharedContext> sharedContext)
|
||||
{
|
||||
switch (GraphicsContext::GetGraphicsAPI())
|
||||
{
|
||||
switch (GraphicsContext::GetGraphicsAPI())
|
||||
{
|
||||
case GraphicsAPI::OpenGL:
|
||||
return CreateScope<glConstantBuffer>(index, size);
|
||||
case GraphicsAPI::OpenGL:
|
||||
return CreateScope<glConstantBuffer>(index, size);
|
||||
|
||||
case GraphicsAPI::DirectX: LT_WIN(
|
||||
return CreateScope<dxConstantBuffer>(index, size, std::static_pointer_cast<dxSharedContext>(sharedContext));)
|
||||
case GraphicsAPI::DirectX: LT_WIN(
|
||||
return CreateScope<dxConstantBuffer>(index, size, std::static_pointer_cast<dxSharedContext>(sharedContext));)
|
||||
|
||||
default:
|
||||
LT_ENGINE_ASSERT(false, "ConstantBuffer::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
|
||||
return nullptr;
|
||||
}
|
||||
default:
|
||||
ASSERT(false, "Invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
|
||||
return nullptr;
|
||||
}
|
||||
//================================================== CONSTANT_BUFFER ==================================================//
|
||||
}
|
||||
//================================================== CONSTANT_BUFFER ==================================================//
|
||||
|
||||
//================================================== VERTEX_BUFFER ==================================================//
|
||||
Ref<VertexBuffer> VertexBuffer::Create(float* vertices, unsigned int stride, unsigned int count, Ref<SharedContext> sharedContext)
|
||||
//================================================== VERTEX_BUFFER ==================================================//
|
||||
Ref<VertexBuffer> VertexBuffer::Create(float* vertices, unsigned int stride, unsigned int count, Ref<SharedContext> sharedContext)
|
||||
{
|
||||
switch (GraphicsContext::GetGraphicsAPI())
|
||||
{
|
||||
switch (GraphicsContext::GetGraphicsAPI())
|
||||
{
|
||||
case GraphicsAPI::OpenGL:
|
||||
return CreateRef<glVertexBuffer>(vertices, stride, count);
|
||||
|
||||
case GraphicsAPI::DirectX: LT_WIN(
|
||||
return CreateRef<dxVertexBuffer>(vertices, stride, count, std::static_pointer_cast<dxSharedContext>(sharedContext));)
|
||||
case GraphicsAPI::OpenGL:
|
||||
return CreateRef<glVertexBuffer>(vertices, stride, count);
|
||||
|
||||
default:
|
||||
LT_ENGINE_ASSERT(false, "VertexBuffer::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
|
||||
return nullptr;
|
||||
}
|
||||
case GraphicsAPI::DirectX: LT_WIN(
|
||||
return CreateRef<dxVertexBuffer>(vertices, stride, count, std::static_pointer_cast<dxSharedContext>(sharedContext));)
|
||||
|
||||
default:
|
||||
ASSERT(false, "Invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
|
||||
return nullptr;
|
||||
}
|
||||
//================================================== VERTEX_BUFFER ==================================================//
|
||||
}
|
||||
//================================================== VERTEX_BUFFER ==================================================//
|
||||
|
||||
//======================================== INDEX_BUFFER ========================================//
|
||||
Ref<IndexBuffer> IndexBuffer::Create(unsigned int* indices, unsigned int count, Ref<SharedContext> sharedContext)
|
||||
//======================================== INDEX_BUFFER ========================================//
|
||||
Ref<IndexBuffer> IndexBuffer::Create(unsigned int* indices, unsigned int count, Ref<SharedContext> sharedContext)
|
||||
{
|
||||
switch (GraphicsContext::GetGraphicsAPI())
|
||||
{
|
||||
switch (GraphicsContext::GetGraphicsAPI())
|
||||
{
|
||||
case GraphicsAPI::OpenGL:
|
||||
return CreateRef<glIndexBuffer>(indices, count);
|
||||
case GraphicsAPI::OpenGL:
|
||||
return CreateRef<glIndexBuffer>(indices, count);
|
||||
|
||||
case GraphicsAPI::DirectX: LT_WIN(
|
||||
return CreateRef<dxIndexBuffer>(indices, count, std::dynamic_pointer_cast<dxSharedContext>(sharedContext));)
|
||||
case GraphicsAPI::DirectX: LT_WIN(
|
||||
return CreateRef<dxIndexBuffer>(indices, count, std::dynamic_pointer_cast<dxSharedContext>(sharedContext));)
|
||||
|
||||
default:
|
||||
LT_ENGINE_ASSERT(false, "IndexBuffer::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
|
||||
return nullptr;
|
||||
}
|
||||
default:
|
||||
ASSERT(false, "Invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
|
||||
return nullptr;
|
||||
}
|
||||
//======================================== INDEX_BUFFER ========================================//
|
||||
}
|
||||
//======================================== INDEX_BUFFER ========================================//
|
||||
|
||||
}
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "Framebuffer.h"
|
||||
|
||||
#include "OpenGL/glFramebuffer.h"
|
||||
|
||||
#ifdef LIGHT_PLATFORM_WINDOWS
|
||||
|
@ -10,20 +11,20 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
Ref<Framebuffer> Framebuffer::Create(const FramebufferSpecification& specification, Ref<SharedContext> sharedContext)
|
||||
Ref<Framebuffer> Framebuffer::Create(const FramebufferSpecification& specification, Ref<SharedContext> sharedContext)
|
||||
{
|
||||
switch (GraphicsContext::GetGraphicsAPI())
|
||||
{
|
||||
switch (GraphicsContext::GetGraphicsAPI())
|
||||
{
|
||||
case GraphicsAPI::OpenGL:
|
||||
return CreateRef<glFramebuffer>(specification);
|
||||
case GraphicsAPI::OpenGL:
|
||||
return CreateRef<glFramebuffer>(specification);
|
||||
|
||||
case GraphicsAPI::DirectX: LT_WIN(
|
||||
return CreateRef<dxFramebuffer>(specification, std::static_pointer_cast<dxSharedContext>(sharedContext));)
|
||||
case GraphicsAPI::DirectX: LT_WIN(
|
||||
return CreateRef<dxFramebuffer>(specification, std::static_pointer_cast<dxSharedContext>(sharedContext));)
|
||||
|
||||
default:
|
||||
LT_ENGINE_ASSERT(false, "Shader::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
|
||||
return nullptr;
|
||||
}
|
||||
default:
|
||||
ASSERT(false, "Invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "GraphicsContext.h"
|
||||
|
||||
#include "OpenGL/glGraphicsContext.h"
|
||||
|
||||
#ifdef LIGHT_PLATFORM_WINDOWS
|
||||
|
@ -6,75 +7,73 @@
|
|||
#include "DirectX/dxSharedContext.h"
|
||||
#endif
|
||||
|
||||
#include "Blender.h" // required for forward declaration
|
||||
#include "Buffers.h" // required for forward declaration
|
||||
#include "Renderer.h" // required for forward declaration
|
||||
#include "RenderCommand.h" // required for forward declaration
|
||||
|
||||
#include "Blender.h" // required for forward declaration
|
||||
#include "Buffers.h" // required for forward declaration
|
||||
#include "RenderCommand.h" // required for forward declaration
|
||||
#include "Renderer.h" // required for forward declaration
|
||||
#include "UserInterface/UserInterface.h" // required for forward declaration
|
||||
|
||||
#include "Utility/ResourceManager.h" // required for forward declaration
|
||||
#include "Utility/ResourceManager.h" // required for forward declaration
|
||||
|
||||
namespace Light {
|
||||
|
||||
GraphicsContext* GraphicsContext::s_Context = nullptr;
|
||||
GraphicsContext* GraphicsContext::s_Context = nullptr;
|
||||
|
||||
GraphicsContext::~GraphicsContext()
|
||||
GraphicsContext::~GraphicsContext()
|
||||
{
|
||||
}
|
||||
|
||||
Scope<GraphicsContext> GraphicsContext::Create(GraphicsAPI api, GLFWwindow* windowHandle)
|
||||
{
|
||||
// terminate 'GraphicsContext' dependent classes
|
||||
if (s_Context)
|
||||
{
|
||||
s_Context->m_Renderer.reset();
|
||||
s_Context->m_UserInterface.reset();
|
||||
|
||||
delete s_Context;
|
||||
}
|
||||
|
||||
Scope<GraphicsContext> GraphicsContext::Create(GraphicsAPI api, GLFWwindow* windowHandle)
|
||||
// determine the default api
|
||||
if (api == GraphicsAPI::Default)
|
||||
{
|
||||
// terminate 'GraphicsContext' dependent classes
|
||||
if (s_Context)
|
||||
{
|
||||
s_Context->m_Renderer.reset();
|
||||
s_Context->m_UserInterface.reset();
|
||||
|
||||
delete s_Context;
|
||||
}
|
||||
|
||||
// determine the default api
|
||||
if (api == GraphicsAPI::Default)
|
||||
{
|
||||
#if defined(LIGHT_PLATFORM_WINDOWS)
|
||||
api = GraphicsAPI::DirectX;
|
||||
api = GraphicsAPI::DirectX;
|
||||
#elif defined(LIGHT_PLATFORM_LINUX)
|
||||
api = GraphicsAPI::OpenGL;
|
||||
api = GraphicsAPI::OpenGL;
|
||||
#elif defined(LIGHT_PLATFORM_MAC)
|
||||
api = GraphicsAPI::OpenGL;
|
||||
api = GraphicsAPI::OpenGL;
|
||||
#endif
|
||||
}
|
||||
|
||||
// create gfx context
|
||||
Scope<GraphicsContext> scopeGfx;
|
||||
switch (api)
|
||||
{
|
||||
// opengl
|
||||
case GraphicsAPI::OpenGL:
|
||||
scopeGfx = CreateScope<glGraphicsContext>(windowHandle);
|
||||
s_Context = scopeGfx.get();
|
||||
break;
|
||||
// directx
|
||||
case GraphicsAPI::DirectX: LT_WIN(
|
||||
scopeGfx = CreateScope<dxGraphicsContext>(windowHandle);
|
||||
s_Context = scopeGfx.get();
|
||||
break;)
|
||||
|
||||
default:
|
||||
LT_ENGINE_ASSERT(false, "GraphicsContext::Create: invalid/unsupported 'GraphicsAPI' {}", Stringifier::GraphicsAPIToString(api));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// create 'GraphicsContext' dependent classes
|
||||
s_Context->m_UserInterface = UserInterface::Create(windowHandle, s_Context->m_SharedContext);
|
||||
s_Context->m_Renderer = Renderer::Create(windowHandle, s_Context->m_SharedContext);
|
||||
|
||||
// check
|
||||
LT_ENGINE_ASSERT(s_Context->m_UserInterface, "GraphicsContext::Create: failed to create UserInterface");
|
||||
LT_ENGINE_ASSERT(s_Context->m_Renderer, "GraphicsContext::Create: failed to create Renderer");
|
||||
|
||||
return std::move(scopeGfx);
|
||||
}
|
||||
|
||||
}
|
||||
// create gfx context
|
||||
Scope<GraphicsContext> scopeGfx;
|
||||
switch (api)
|
||||
{
|
||||
// opengl
|
||||
case GraphicsAPI::OpenGL:
|
||||
scopeGfx = CreateScope<glGraphicsContext>(windowHandle);
|
||||
s_Context = scopeGfx.get();
|
||||
break;
|
||||
// directx
|
||||
case GraphicsAPI::DirectX: LT_WIN(
|
||||
scopeGfx = CreateScope<dxGraphicsContext>(windowHandle);
|
||||
s_Context = scopeGfx.get();
|
||||
break;)
|
||||
|
||||
default:
|
||||
ASSERT(false, "Invalid/unsupported 'GraphicsAPI' {}", Stringifier::GraphicsAPIToString(api));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// create 'GraphicsContext' dependent classes
|
||||
s_Context->m_UserInterface = UserInterface::Create(windowHandle, s_Context->m_SharedContext);
|
||||
s_Context->m_Renderer = Renderer::Create(windowHandle, s_Context->m_SharedContext);
|
||||
|
||||
// check
|
||||
ASSERT(s_Context->m_UserInterface, "Failed to create UserInterface");
|
||||
ASSERT(s_Context->m_Renderer, "Failed to create Renderer");
|
||||
|
||||
return std::move(scopeGfx);
|
||||
}
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "RenderCommand.h"
|
||||
|
||||
#include "OpenGL/glRenderCommand.h"
|
||||
|
||||
#ifdef LIGHT_PLATFORM_WINDOWS
|
||||
|
@ -10,20 +11,20 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
Scope<RenderCommand> RenderCommand::Create(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext)
|
||||
Scope<RenderCommand> RenderCommand::Create(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext)
|
||||
{
|
||||
switch (GraphicsContext::GetGraphicsAPI())
|
||||
{
|
||||
switch (GraphicsContext::GetGraphicsAPI())
|
||||
{
|
||||
case GraphicsAPI::OpenGL:
|
||||
return CreateScope<glRenderCommand>(windowHandle);
|
||||
case GraphicsAPI::OpenGL:
|
||||
return CreateScope<glRenderCommand>(windowHandle);
|
||||
|
||||
case GraphicsAPI::DirectX: LT_WIN(
|
||||
return CreateScope<dxRenderCommand>((std::static_pointer_cast<dxSharedContext>)(sharedContext));)
|
||||
case GraphicsAPI::DirectX: LT_WIN(
|
||||
return CreateScope<dxRenderCommand>((std::static_pointer_cast<dxSharedContext>)(sharedContext));)
|
||||
|
||||
default:
|
||||
LT_ENGINE_ASSERT(false, "RenderCommand::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
|
||||
return nullptr;
|
||||
}
|
||||
default:
|
||||
ASSERT(false, "Invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Light
|
||||
|
|
|
@ -19,7 +19,7 @@ Renderer* Renderer::s_Context = nullptr;
|
|||
Renderer::Renderer(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext)
|
||||
: m_QuadRenderer(LT_MAX_QUAD_RENDERER_VERTICES, sharedContext), m_TextureRenderer(LT_MAX_TEXTURE_RENDERER_VERTICES, sharedContext), m_TintedTextureRenderer(LT_MAX_TINTED_TEXTURE_RENDERER_VERTICES, sharedContext), m_ViewProjectionBuffer(nullptr), m_RenderCommand(nullptr), m_Blender(nullptr), m_DefaultFramebufferCamera(nullptr), m_TargetFramebuffer(nullptr), m_ShouldClearBackbuffer(false)
|
||||
{
|
||||
LT_ENGINE_ASSERT(!s_Context, "Renderer::Renderer: an instance of 'Renderer' already exists, do not construct this class!");
|
||||
ASSERT(!s_Context, "An instance of 'Renderer' already exists, do not construct this class!");
|
||||
s_Context = this;
|
||||
|
||||
m_ViewProjectionBuffer = ConstantBuffer::Create(ConstantBufferIndex::ViewProjection, sizeof(glm::mat4), sharedContext);
|
||||
|
@ -87,7 +87,7 @@ void Renderer::DrawQuadImpl(const glm::mat4& transform, const glm::vec4& tint)
|
|||
// advance
|
||||
if (!m_QuadRenderer.Advance())
|
||||
{
|
||||
LT_ENGINE_WARN("Renderer::DrawQuadImpl: exceeded LT_MAX_QUAD_RENDERER_VERTICES: {}", LT_MAX_QUAD_RENDERER_VERTICES);
|
||||
LOG(warn, "Exceeded LT_MAX_QUAD_RENDERER_VERTICES: {}", LT_MAX_QUAD_RENDERER_VERTICES);
|
||||
FlushScene();
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ void Renderer::DrawQuadImpl(const glm::mat4& transform, const glm::vec4& tint)
|
|||
void Renderer::DrawQuadImpl(const glm::mat4& transform, Ref<Texture> texture)
|
||||
{
|
||||
// #todo: implement a proper binding
|
||||
LT_ENGINE_ASSERT(texture, "Invalid texture passed to Renderer::DrawQuadImpl");
|
||||
ASSERT(texture, "Texture passed to Renderer::DrawQuadImpl");
|
||||
texture->Bind();
|
||||
|
||||
// locals
|
||||
|
@ -122,7 +122,7 @@ void Renderer::DrawQuadImpl(const glm::mat4& transform, Ref<Texture> texture)
|
|||
// advance
|
||||
if (!m_TextureRenderer.Advance())
|
||||
{
|
||||
LT_ENGINE_WARN("Renderer::DrawQuadImpl: exceeded LT_MAX_TEXTURE_RENDERER_VERTICES: {}", LT_MAX_TEXTURE_RENDERER_VERTICES);
|
||||
LOG(warn, "Exceeded LT_MAX_TEXTURE_RENDERER_VERTICES: {}", LT_MAX_TEXTURE_RENDERER_VERTICES);
|
||||
FlushScene();
|
||||
}
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ void Renderer::DrawQuadImpl(const glm::mat4& transform, Ref<Texture> texture)
|
|||
void Renderer::DrawQuadImpl(const glm::mat4& transform, const glm::vec4& tint, Ref<Texture> texture)
|
||||
{
|
||||
// #todo: implement a proper binding
|
||||
LT_ENGINE_ASSERT(texture, "Invalid texture passed to Renderer::DrawQuadImpl");
|
||||
ASSERT(texture, "Texture passed to Renderer::DrawQuadImpl");
|
||||
texture->Bind();
|
||||
|
||||
// locals
|
||||
|
@ -159,7 +159,7 @@ void Renderer::DrawQuadImpl(const glm::mat4& transform, const glm::vec4& tint, R
|
|||
// advance
|
||||
if (!m_TintedTextureRenderer.Advance())
|
||||
{
|
||||
LT_ENGINE_WARN("Renderer::DrawQuadImpl: exceeded LT_MAX_TEXTURE_RENDERER_VERTICES: {}", LT_MAX_TEXTURE_RENDERER_VERTICES);
|
||||
LOG(warn, "Exceeded LT_MAX_TEXTURE_RENDERER_VERTICES: {}", LT_MAX_TEXTURE_RENDERER_VERTICES);
|
||||
FlushScene();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,67 +1,58 @@
|
|||
#include "QuadRendererProgram.h"
|
||||
|
||||
#include "Camera/Camera.h"
|
||||
|
||||
#include "Graphics/Shader.h"
|
||||
#include "Graphics/Buffers.h"
|
||||
#include "Graphics/Shader.h"
|
||||
#include "Graphics/VertexLayout.h"
|
||||
|
||||
#include "Utility/ResourceManager.h"
|
||||
|
||||
namespace Light {
|
||||
|
||||
QuadRendererProgram::QuadRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext)
|
||||
: m_Shader(nullptr),
|
||||
m_IndexBuffer(nullptr),
|
||||
m_VertexLayout(nullptr),
|
||||
m_MapCurrent(nullptr),
|
||||
m_MapEnd(nullptr),
|
||||
m_QuadCount(0u),
|
||||
m_MaxVertices(maxVertices)
|
||||
{
|
||||
// #todo: don't use relative path
|
||||
ResourceManager::LoadShader("LT_ENGINE_RESOURCES_QUAD_SHADER", "Assets/Shaders/Quad/Quad_VS.glsl", "Assets/Shaders/Quad/Quad_PS.glsl");
|
||||
|
||||
m_Shader = ResourceManager::GetShader("LT_ENGINE_RESOURCES_QUAD_SHADER");
|
||||
m_VertexBuffer = Ref<VertexBuffer>(VertexBuffer::Create(nullptr, sizeof(QuadVertexData), maxVertices, sharedContext));
|
||||
m_IndexBuffer = Ref<IndexBuffer>(IndexBuffer::Create(nullptr, (maxVertices / 4) * 6, sharedContext));
|
||||
m_VertexLayout = Ref<VertexLayout>(VertexLayout::Create(m_VertexBuffer, m_Shader, { { "POSITION", VertexElementType::Float4 },
|
||||
{ "COLOR" , VertexElementType::Float4 }}, sharedContext));
|
||||
}
|
||||
|
||||
bool QuadRendererProgram::Advance()
|
||||
{
|
||||
m_MapCurrent += 4;
|
||||
|
||||
if (m_MapCurrent >= m_MapEnd)
|
||||
{
|
||||
LT_ENGINE_WARN("QuadRendererProgram::Advance: 'VertexBuffer' map went beyond 'MaxVertices': {}", m_MaxVertices);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_QuadCount++;
|
||||
return true;
|
||||
}
|
||||
|
||||
void QuadRendererProgram::Map()
|
||||
{
|
||||
m_QuadCount = 0u;
|
||||
|
||||
m_MapCurrent = (QuadRendererProgram::QuadVertexData*)m_VertexBuffer->Map();
|
||||
m_MapEnd = m_MapCurrent + m_MaxVertices;
|
||||
}
|
||||
|
||||
void QuadRendererProgram::UnMap()
|
||||
{
|
||||
m_VertexBuffer->UnMap();
|
||||
}
|
||||
|
||||
void QuadRendererProgram::Bind()
|
||||
{
|
||||
m_Shader->Bind();
|
||||
m_VertexLayout->Bind();
|
||||
m_VertexBuffer->Bind();
|
||||
m_IndexBuffer->Bind();
|
||||
}
|
||||
QuadRendererProgram::QuadRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext)
|
||||
: m_Shader(nullptr), m_IndexBuffer(nullptr), m_VertexLayout(nullptr), m_MapCurrent(nullptr), m_MapEnd(nullptr), m_QuadCount(0u), m_MaxVertices(maxVertices)
|
||||
{
|
||||
// #todo: don't use relative path
|
||||
ResourceManager::LoadShader("LT_ENGINE_RESOURCES_QUAD_SHADER", "Assets/Shaders/Quad/Quad_VS.glsl", "Assets/Shaders/Quad/Quad_PS.glsl");
|
||||
|
||||
m_Shader = ResourceManager::GetShader("LT_ENGINE_RESOURCES_QUAD_SHADER");
|
||||
m_VertexBuffer = Ref<VertexBuffer>(VertexBuffer::Create(nullptr, sizeof(QuadVertexData), maxVertices, sharedContext));
|
||||
m_IndexBuffer = Ref<IndexBuffer>(IndexBuffer::Create(nullptr, (maxVertices / 4) * 6, sharedContext));
|
||||
m_VertexLayout = Ref<VertexLayout>(VertexLayout::Create(m_VertexBuffer, m_Shader, { { "POSITION", VertexElementType::Float4 }, { "COLOR", VertexElementType::Float4 } }, sharedContext));
|
||||
}
|
||||
|
||||
bool QuadRendererProgram::Advance()
|
||||
{
|
||||
m_MapCurrent += 4;
|
||||
|
||||
if (m_MapCurrent >= m_MapEnd)
|
||||
{
|
||||
LOG(warn, "'VertexBuffer' map went beyond 'MaxVertices': {}", m_MaxVertices);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_QuadCount++;
|
||||
return true;
|
||||
}
|
||||
|
||||
void QuadRendererProgram::Map()
|
||||
{
|
||||
m_QuadCount = 0u;
|
||||
|
||||
m_MapCurrent = (QuadRendererProgram::QuadVertexData*)m_VertexBuffer->Map();
|
||||
m_MapEnd = m_MapCurrent + m_MaxVertices;
|
||||
}
|
||||
|
||||
void QuadRendererProgram::UnMap()
|
||||
{
|
||||
m_VertexBuffer->UnMap();
|
||||
}
|
||||
|
||||
void QuadRendererProgram::Bind()
|
||||
{
|
||||
m_Shader->Bind();
|
||||
m_VertexLayout->Bind();
|
||||
m_VertexBuffer->Bind();
|
||||
m_IndexBuffer->Bind();
|
||||
}
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,66 +1,57 @@
|
|||
#include "TextureRendererProgram.h"
|
||||
|
||||
#include "Camera/Camera.h"
|
||||
|
||||
#include "Graphics/Shader.h"
|
||||
#include "Graphics/Buffers.h"
|
||||
#include "Graphics/Shader.h"
|
||||
#include "Graphics/VertexLayout.h"
|
||||
|
||||
#include "Utility/ResourceManager.h"
|
||||
|
||||
namespace Light {
|
||||
|
||||
TextureRendererProgram::TextureRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext)
|
||||
: m_Shader(nullptr),
|
||||
m_IndexBuffer(nullptr),
|
||||
m_VertexLayout(nullptr),
|
||||
m_MapCurrent(nullptr),
|
||||
m_MapEnd(nullptr),
|
||||
m_QuadCount(0u),
|
||||
m_MaxVertices(maxVertices)
|
||||
{
|
||||
// #todo: don't use relative path
|
||||
ResourceManager::LoadShader("LT_ENGINE_RESOURCES_TEXTURE_SHADER", "Assets/Shaders/Texture/Texture_VS.glsl", "Assets/Shaders/Texture/Texture_PS.glsl");
|
||||
|
||||
m_Shader = ResourceManager::GetShader("LT_ENGINE_RESOURCES_TEXTURE_SHADER");
|
||||
m_VertexBuffer = Ref<VertexBuffer>(VertexBuffer::Create(nullptr, sizeof(TextureVertexData), maxVertices, sharedContext));
|
||||
m_IndexBuffer = Ref<IndexBuffer>(IndexBuffer::Create(nullptr, (maxVertices / 4) * 6, sharedContext));
|
||||
m_VertexLayout = Ref<VertexLayout>(VertexLayout::Create(m_VertexBuffer, m_Shader, { { "POSITION", VertexElementType::Float4 },
|
||||
{ "TEXCOORD", VertexElementType::Float2 }}, sharedContext));
|
||||
}
|
||||
|
||||
bool TextureRendererProgram::Advance()
|
||||
{
|
||||
if (m_MapCurrent + 4 >= m_MapEnd)
|
||||
{
|
||||
LT_ENGINE_WARN("TextureRendererProgram::Advance: 'VertexBuffer' map went beyond 'MaxVertices': {}", m_MaxVertices);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_MapCurrent += 4;
|
||||
m_QuadCount++;
|
||||
return true;
|
||||
}
|
||||
|
||||
void TextureRendererProgram::Map()
|
||||
{
|
||||
m_QuadCount = 0u;
|
||||
|
||||
m_MapCurrent = (TextureRendererProgram::TextureVertexData*)m_VertexBuffer->Map();
|
||||
m_MapEnd = m_MapCurrent + m_MaxVertices;
|
||||
}
|
||||
|
||||
void TextureRendererProgram::UnMap()
|
||||
{
|
||||
m_VertexBuffer->UnMap();
|
||||
}
|
||||
|
||||
void TextureRendererProgram::Bind()
|
||||
{
|
||||
m_Shader->Bind();
|
||||
m_VertexLayout->Bind();
|
||||
m_VertexBuffer->Bind();
|
||||
m_IndexBuffer->Bind();
|
||||
}
|
||||
TextureRendererProgram::TextureRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext)
|
||||
: m_Shader(nullptr), m_IndexBuffer(nullptr), m_VertexLayout(nullptr), m_MapCurrent(nullptr), m_MapEnd(nullptr), m_QuadCount(0u), m_MaxVertices(maxVertices)
|
||||
{
|
||||
// #todo: don't use relative path
|
||||
ResourceManager::LoadShader("LT_ENGINE_RESOURCES_TEXTURE_SHADER", "Assets/Shaders/Texture/Texture_VS.glsl", "Assets/Shaders/Texture/Texture_PS.glsl");
|
||||
|
||||
m_Shader = ResourceManager::GetShader("LT_ENGINE_RESOURCES_TEXTURE_SHADER");
|
||||
m_VertexBuffer = Ref<VertexBuffer>(VertexBuffer::Create(nullptr, sizeof(TextureVertexData), maxVertices, sharedContext));
|
||||
m_IndexBuffer = Ref<IndexBuffer>(IndexBuffer::Create(nullptr, (maxVertices / 4) * 6, sharedContext));
|
||||
m_VertexLayout = Ref<VertexLayout>(VertexLayout::Create(m_VertexBuffer, m_Shader, { { "POSITION", VertexElementType::Float4 }, { "TEXCOORD", VertexElementType::Float2 } }, sharedContext));
|
||||
}
|
||||
|
||||
bool TextureRendererProgram::Advance()
|
||||
{
|
||||
if (m_MapCurrent + 4 >= m_MapEnd)
|
||||
{
|
||||
LOG(warn, "'VertexBuffer' map went beyond 'MaxVertices': {}", m_MaxVertices);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_MapCurrent += 4;
|
||||
m_QuadCount++;
|
||||
return true;
|
||||
}
|
||||
|
||||
void TextureRendererProgram::Map()
|
||||
{
|
||||
m_QuadCount = 0u;
|
||||
|
||||
m_MapCurrent = (TextureRendererProgram::TextureVertexData*)m_VertexBuffer->Map();
|
||||
m_MapEnd = m_MapCurrent + m_MaxVertices;
|
||||
}
|
||||
|
||||
void TextureRendererProgram::UnMap()
|
||||
{
|
||||
m_VertexBuffer->UnMap();
|
||||
}
|
||||
|
||||
void TextureRendererProgram::Bind()
|
||||
{
|
||||
m_Shader->Bind();
|
||||
m_VertexLayout->Bind();
|
||||
m_VertexBuffer->Bind();
|
||||
m_IndexBuffer->Bind();
|
||||
}
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,68 +1,58 @@
|
|||
#include "TintedTextureRendererProgram.h"
|
||||
|
||||
#include "Camera/Camera.h"
|
||||
|
||||
#include "Graphics/Shader.h"
|
||||
#include "Graphics/Buffers.h"
|
||||
#include "Graphics/Shader.h"
|
||||
#include "Graphics/VertexLayout.h"
|
||||
|
||||
#include "Utility/ResourceManager.h"
|
||||
|
||||
namespace Light {
|
||||
|
||||
TintedTextureRendererProgram::TintedTextureRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext)
|
||||
: m_Shader(nullptr),
|
||||
m_IndexBuffer(nullptr),
|
||||
m_VertexLayout(nullptr),
|
||||
m_MapCurrent(nullptr),
|
||||
m_MapEnd(nullptr),
|
||||
m_QuadCount(0u),
|
||||
m_MaxVertices(maxVertices)
|
||||
{
|
||||
// #todo: don't use relative path
|
||||
ResourceManager::LoadShader("LT_ENGINE_RESOURCES_TINTED_TEXTURE_SHADER", "Assets/Shaders/TintedTexture/TintedTexture_VS.glsl", "Assets/Shaders/TintedTexture/TintedTexture_PS.glsl");
|
||||
|
||||
m_Shader = ResourceManager::GetShader("LT_ENGINE_RESOURCES_TINTED_TEXTURE_SHADER");
|
||||
m_VertexBuffer = Ref<VertexBuffer>(VertexBuffer::Create(nullptr, sizeof(TintedTextureVertexData), maxVertices, sharedContext));
|
||||
m_IndexBuffer = Ref<IndexBuffer>(IndexBuffer::Create(nullptr, (maxVertices / 4) * 6, sharedContext));
|
||||
m_VertexLayout = Ref<VertexLayout>(VertexLayout::Create(m_VertexBuffer, m_Shader, { { "POSITION", VertexElementType::Float4 },
|
||||
{ "TINT" , VertexElementType::Float4 },
|
||||
{ "TEXCOORD", VertexElementType::Float2 }}, sharedContext));
|
||||
}
|
||||
|
||||
bool TintedTextureRendererProgram::Advance()
|
||||
{
|
||||
m_MapCurrent += 4;
|
||||
|
||||
if (m_MapCurrent >= m_MapEnd)
|
||||
{
|
||||
LT_ENGINE_WARN("TintedTextureRendererProgram::Advance: 'VertexBuffer' map went beyond 'MaxVertices': {}", m_MaxVertices);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_QuadCount++;
|
||||
return true;
|
||||
}
|
||||
|
||||
void TintedTextureRendererProgram::Map()
|
||||
{
|
||||
m_QuadCount = 0u;
|
||||
|
||||
m_MapCurrent = (TintedTextureRendererProgram::TintedTextureVertexData*)m_VertexBuffer->Map();
|
||||
m_MapEnd = m_MapCurrent + m_MaxVertices;
|
||||
}
|
||||
|
||||
void TintedTextureRendererProgram::UnMap()
|
||||
{
|
||||
m_VertexBuffer->UnMap();
|
||||
}
|
||||
|
||||
void TintedTextureRendererProgram::Bind()
|
||||
{
|
||||
m_Shader->Bind();
|
||||
m_VertexLayout->Bind();
|
||||
m_VertexBuffer->Bind();
|
||||
m_IndexBuffer->Bind();
|
||||
}
|
||||
TintedTextureRendererProgram::TintedTextureRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext)
|
||||
: m_Shader(nullptr), m_IndexBuffer(nullptr), m_VertexLayout(nullptr), m_MapCurrent(nullptr), m_MapEnd(nullptr), m_QuadCount(0u), m_MaxVertices(maxVertices)
|
||||
{
|
||||
// #todo: don't use relative path
|
||||
ResourceManager::LoadShader("LT_ENGINE_RESOURCES_TINTED_TEXTURE_SHADER", "Assets/Shaders/TintedTexture/TintedTexture_VS.glsl", "Assets/Shaders/TintedTexture/TintedTexture_PS.glsl");
|
||||
|
||||
m_Shader = ResourceManager::GetShader("LT_ENGINE_RESOURCES_TINTED_TEXTURE_SHADER");
|
||||
m_VertexBuffer = Ref<VertexBuffer>(VertexBuffer::Create(nullptr, sizeof(TintedTextureVertexData), maxVertices, sharedContext));
|
||||
m_IndexBuffer = Ref<IndexBuffer>(IndexBuffer::Create(nullptr, (maxVertices / 4) * 6, sharedContext));
|
||||
m_VertexLayout = Ref<VertexLayout>(VertexLayout::Create(m_VertexBuffer, m_Shader, { { "POSITION", VertexElementType::Float4 }, { "TINT", VertexElementType::Float4 }, { "TEXCOORD", VertexElementType::Float2 } }, sharedContext));
|
||||
}
|
||||
|
||||
bool TintedTextureRendererProgram::Advance()
|
||||
{
|
||||
m_MapCurrent += 4;
|
||||
|
||||
if (m_MapCurrent >= m_MapEnd)
|
||||
{
|
||||
LOG(warn, "'VertexBuffer' map went beyond 'MaxVertices': {}", m_MaxVertices);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_QuadCount++;
|
||||
return true;
|
||||
}
|
||||
|
||||
void TintedTextureRendererProgram::Map()
|
||||
{
|
||||
m_QuadCount = 0u;
|
||||
|
||||
m_MapCurrent = (TintedTextureRendererProgram::TintedTextureVertexData*)m_VertexBuffer->Map();
|
||||
m_MapEnd = m_MapCurrent + m_MaxVertices;
|
||||
}
|
||||
|
||||
void TintedTextureRendererProgram::UnMap()
|
||||
{
|
||||
m_VertexBuffer->UnMap();
|
||||
}
|
||||
|
||||
void TintedTextureRendererProgram::Bind()
|
||||
{
|
||||
m_Shader->Bind();
|
||||
m_VertexLayout->Bind();
|
||||
m_VertexBuffer->Bind();
|
||||
m_IndexBuffer->Bind();
|
||||
}
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "Shader.h"
|
||||
|
||||
#include "OpenGL/glShader.h"
|
||||
|
||||
#ifdef LIGHT_PLATFORM_WINDOWS
|
||||
|
@ -10,21 +11,21 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
Ref<Shader> Shader::Create(BasicFileHandle vertexFile, BasicFileHandle pixelFile, Ref<SharedContext> sharedContext)
|
||||
Ref<Shader> Shader::Create(BasicFileHandle vertexFile, BasicFileHandle pixelFile, Ref<SharedContext> sharedContext)
|
||||
{
|
||||
// load shader source
|
||||
switch (GraphicsContext::GetGraphicsAPI())
|
||||
{
|
||||
// load shader source
|
||||
switch (GraphicsContext::GetGraphicsAPI())
|
||||
{
|
||||
case GraphicsAPI::OpenGL:
|
||||
return CreateRef<glShader>(vertexFile, pixelFile);
|
||||
case GraphicsAPI::OpenGL:
|
||||
return CreateRef<glShader>(vertexFile, pixelFile);
|
||||
|
||||
case GraphicsAPI::DirectX: LT_WIN(
|
||||
return CreateRef<dxShader>(vertexFile, pixelFile, std::static_pointer_cast<dxSharedContext>(sharedContext));)
|
||||
case GraphicsAPI::DirectX: LT_WIN(
|
||||
return CreateRef<dxShader>(vertexFile, pixelFile, std::static_pointer_cast<dxSharedContext>(sharedContext));)
|
||||
|
||||
default:
|
||||
LT_ENGINE_ASSERT(false, "Shader::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
|
||||
return nullptr;
|
||||
}
|
||||
default:
|
||||
ASSERT(false, "Invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "Texture.h"
|
||||
|
||||
#include "OpenGL/glTexture.h"
|
||||
|
||||
#ifdef LIGHT_PLATFORM_WINDOWS
|
||||
|
@ -10,25 +11,25 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
Ref<Texture>Texture::Create(unsigned int width, unsigned int height, unsigned int components, unsigned char* pixels, Ref<SharedContext> sharedContext, const std::string& filePath)
|
||||
Ref<Texture> Texture::Create(unsigned int width, unsigned int height, unsigned int components, unsigned char* pixels, Ref<SharedContext> sharedContext, const std::string& filePath)
|
||||
{
|
||||
switch (GraphicsContext::GetGraphicsAPI())
|
||||
{
|
||||
switch (GraphicsContext::GetGraphicsAPI())
|
||||
{
|
||||
case GraphicsAPI::OpenGL:
|
||||
return CreateRef<glTexture>(width, height, components, pixels, filePath);
|
||||
case GraphicsAPI::OpenGL:
|
||||
return CreateRef<glTexture>(width, height, components, pixels, filePath);
|
||||
|
||||
case GraphicsAPI::DirectX: LT_WIN(
|
||||
return CreateRef<dxTexture>(width, height, components, pixels, std::static_pointer_cast<dxSharedContext>(sharedContext), filePath);)
|
||||
case GraphicsAPI::DirectX: LT_WIN(
|
||||
return CreateRef<dxTexture>(width, height, components, pixels, std::static_pointer_cast<dxSharedContext>(sharedContext), filePath);)
|
||||
|
||||
default:
|
||||
LT_ENGINE_ASSERT(false, "Texture::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
|
||||
return nullptr;
|
||||
}
|
||||
default:
|
||||
ASSERT(false, "Invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Texture::Texture(const std::string& filePath):
|
||||
m_FilePath(filePath)
|
||||
{
|
||||
}
|
||||
Texture::Texture(const std::string& filePath)
|
||||
: m_FilePath(filePath)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "VertexLayout.h"
|
||||
|
||||
#include "OpenGL/glVertexLayout.h"
|
||||
|
||||
#ifdef LIGHT_PLATFORM_WINDOWS
|
||||
|
@ -10,20 +11,20 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
Ref<VertexLayout> VertexLayout::Create(Ref<VertexBuffer> vertexBuffer, Ref<Shader> shader, const std::vector<std::pair<std::string, VertexElementType>>& elements, Ref<SharedContext> sharedContext)
|
||||
Ref<VertexLayout> VertexLayout::Create(Ref<VertexBuffer> vertexBuffer, Ref<Shader> shader, const std::vector<std::pair<std::string, VertexElementType>>& elements, Ref<SharedContext> sharedContext)
|
||||
{
|
||||
switch (GraphicsContext::GetGraphicsAPI())
|
||||
{
|
||||
switch (GraphicsContext::GetGraphicsAPI())
|
||||
{
|
||||
case GraphicsAPI::OpenGL:
|
||||
return CreateRef<glVertexLayout>(vertexBuffer, elements);
|
||||
case GraphicsAPI::OpenGL:
|
||||
return CreateRef<glVertexLayout>(vertexBuffer, elements);
|
||||
|
||||
case GraphicsAPI::DirectX: LT_WIN(
|
||||
return CreateRef<dxVertexLayout>(shader, elements, std::static_pointer_cast<dxSharedContext>(sharedContext));)
|
||||
case GraphicsAPI::DirectX: LT_WIN(
|
||||
return CreateRef<dxVertexLayout>(shader, elements, std::static_pointer_cast<dxSharedContext>(sharedContext));)
|
||||
|
||||
default:
|
||||
LT_ENGINE_ASSERT(false, "VertexLayout::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
|
||||
return nullptr;
|
||||
}
|
||||
default:
|
||||
ASSERT(false, "Invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,160 +1,153 @@
|
|||
#include "ltpch.h"
|
||||
#include "Input.h"
|
||||
|
||||
#include "Events/Event.h"
|
||||
#include "Events/CharEvent.h"
|
||||
#include "Events/MouseEvents.h"
|
||||
#include "Events/Event.h"
|
||||
#include "Events/KeyboardEvents.h"
|
||||
#include "Events/MouseEvents.h"
|
||||
#include "Input/KeyCodes.h"
|
||||
#include "ltpch.h"
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
#include "Input/KeyCodes.h"
|
||||
|
||||
namespace Light {
|
||||
|
||||
Input* Input::s_Context = nullptr;
|
||||
Input* Input::s_Context = nullptr;
|
||||
|
||||
Scope<Input> Input::Create()
|
||||
{
|
||||
return MakeScope(new Input);
|
||||
}
|
||||
Scope<Input> Input::Create()
|
||||
{
|
||||
return MakeScope(new Input);
|
||||
}
|
||||
|
||||
Input::Input()
|
||||
: m_KeyboadKeys{},
|
||||
m_MouseButtons{},
|
||||
m_MousePosition{},
|
||||
m_MouseDelta{},
|
||||
m_MouseWheelDelta{},
|
||||
m_UserInterfaceEvents(true),
|
||||
m_GameEvents(true)
|
||||
{
|
||||
LT_ENGINE_ASSERT(!s_Context, "Input::Input: an instance of 'Input' already exists, do not construct this class!");
|
||||
s_Context = this;
|
||||
Input::Input()
|
||||
: m_KeyboadKeys {}, m_MouseButtons {}, m_MousePosition {}, m_MouseDelta {}, m_MouseWheelDelta {}, m_UserInterfaceEvents(true), m_GameEvents(true)
|
||||
{
|
||||
ASSERT(!s_Context, "Input::Input: an instance of 'Input' already exists, do not construct this class!");
|
||||
s_Context = this;
|
||||
|
||||
RestartInputState();
|
||||
}
|
||||
|
||||
void Input::ReceiveUserInterfaceEventsImpl(bool receive, bool toggle /* = false */)
|
||||
{
|
||||
m_UserInterfaceEvents = toggle ? !m_UserInterfaceEvents : receive;
|
||||
}
|
||||
|
||||
void Input::ReceieveGameEventsImpl(bool receive, bool toggle /*= false*/)
|
||||
{
|
||||
bool prev = m_GameEvents;
|
||||
m_GameEvents = toggle ? !m_UserInterfaceEvents : receive;
|
||||
|
||||
if (m_GameEvents != prev)
|
||||
RestartInputState();
|
||||
}
|
||||
}
|
||||
|
||||
void Input::ReceiveUserInterfaceEventsImpl(bool receive, bool toggle /* = false */)
|
||||
void Input::RestartInputState()
|
||||
{
|
||||
m_KeyboadKeys.fill(false);
|
||||
m_MouseButtons.fill(false);
|
||||
|
||||
m_MousePosition = glm::vec2(0.0f);
|
||||
m_MouseDelta = glm::vec2(0.0f);
|
||||
m_MouseWheelDelta = 0.0f;
|
||||
}
|
||||
|
||||
void Input::OnEvent(const Event& inputEvent)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
switch (inputEvent.GetEventType())
|
||||
{
|
||||
m_UserInterfaceEvents = toggle ? !m_UserInterfaceEvents : receive;
|
||||
}
|
||||
|
||||
void Input::ReceieveGameEventsImpl(bool receive, bool toggle /*= false*/)
|
||||
//** MOUSE_EVENTS **//
|
||||
case EventType::MouseMoved:
|
||||
{
|
||||
bool prev = m_GameEvents;
|
||||
m_GameEvents = toggle ? !m_UserInterfaceEvents : receive;
|
||||
const MouseMovedEvent& event = (const MouseMovedEvent&)inputEvent;
|
||||
|
||||
if(m_GameEvents != prev)
|
||||
RestartInputState();
|
||||
if (m_GameEvents)
|
||||
{
|
||||
m_MouseDelta = event.GetPosition() - m_MousePosition;
|
||||
m_MousePosition = event.GetPosition();
|
||||
}
|
||||
|
||||
if (m_UserInterfaceEvents)
|
||||
io.MousePos = ImVec2(event.GetX(), event.GetY());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void Input::RestartInputState()
|
||||
case EventType::ButtonPressed:
|
||||
{
|
||||
m_KeyboadKeys.fill(false);
|
||||
m_MouseButtons.fill(false);
|
||||
const ButtonPressedEvent& event = (const ButtonPressedEvent&)inputEvent;
|
||||
|
||||
m_MousePosition = glm::vec2(0.0f);
|
||||
m_MouseDelta = glm::vec2(0.0f);
|
||||
m_MouseWheelDelta = 0.0f;
|
||||
if (m_GameEvents)
|
||||
m_MouseButtons[event.GetButton()] = true;
|
||||
|
||||
if (m_UserInterfaceEvents)
|
||||
io.MouseDown[event.GetButton()] = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void Input::OnEvent(const Event& inputEvent)
|
||||
case EventType::ButtonReleased:
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
switch (inputEvent.GetEventType())
|
||||
{
|
||||
//** MOUSE_EVENTS **//
|
||||
case EventType::MouseMoved:
|
||||
{
|
||||
const MouseMovedEvent& event = (const MouseMovedEvent&)inputEvent;
|
||||
const ButtonReleasedEvent& event = (const ButtonReleasedEvent&)inputEvent;
|
||||
|
||||
if (m_GameEvents)
|
||||
{
|
||||
m_MouseDelta = event.GetPosition() - m_MousePosition;
|
||||
m_MousePosition = event.GetPosition();
|
||||
}
|
||||
if (m_GameEvents)
|
||||
m_MouseButtons[event.GetButton()] = false;
|
||||
|
||||
if(m_UserInterfaceEvents)
|
||||
io.MousePos = ImVec2(event.GetX(), event.GetY());
|
||||
if (m_UserInterfaceEvents)
|
||||
io.MouseDown[event.GetButton()] = false;
|
||||
|
||||
return;
|
||||
}
|
||||
case EventType::ButtonPressed:
|
||||
{
|
||||
const ButtonPressedEvent& event = (const ButtonPressedEvent&)inputEvent;
|
||||
|
||||
if(m_GameEvents)
|
||||
m_MouseButtons[event.GetButton()] = true;
|
||||
|
||||
if (m_UserInterfaceEvents)
|
||||
io.MouseDown[event.GetButton()] = true;
|
||||
|
||||
return;
|
||||
}
|
||||
case EventType::ButtonReleased:
|
||||
{
|
||||
const ButtonReleasedEvent& event = (const ButtonReleasedEvent&)inputEvent;
|
||||
|
||||
if (m_GameEvents)
|
||||
m_MouseButtons[event.GetButton()] = false;
|
||||
|
||||
if (m_UserInterfaceEvents)
|
||||
io.MouseDown[event.GetButton()] = false;
|
||||
|
||||
return;
|
||||
}
|
||||
case EventType::WheelScrolled:
|
||||
{
|
||||
const WheelScrolledEvent& event = (const WheelScrolledEvent&)inputEvent;
|
||||
|
||||
if (m_GameEvents)
|
||||
m_MouseWheelDelta = event.GetOffset();
|
||||
|
||||
if (m_UserInterfaceEvents)
|
||||
io.MouseWheel = event.GetOffset();
|
||||
|
||||
return;
|
||||
}
|
||||
//** KEYBOARD_EVENTS **//
|
||||
case EventType::KeyPressed:
|
||||
{
|
||||
const KeyPressedEvent& event = (const KeyPressedEvent&)inputEvent;
|
||||
|
||||
if (m_GameEvents)
|
||||
m_KeyboadKeys[event.GetKey()] = true;
|
||||
|
||||
if (m_UserInterfaceEvents)
|
||||
{
|
||||
io.KeysDown[event.GetKey()] = true;
|
||||
//if (event.GetKey() == Key::BackSpace)
|
||||
// io.AddInputCharacter(Key::BackSpace);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
case EventType::KeyReleased:
|
||||
{
|
||||
const KeyReleasedEvent& event = (const KeyReleasedEvent&)inputEvent;
|
||||
|
||||
if (m_GameEvents)
|
||||
m_KeyboadKeys[event.GetKey()] = false;
|
||||
|
||||
if (m_UserInterfaceEvents)
|
||||
io.KeysDown[event.GetKey()] = false;
|
||||
|
||||
return;
|
||||
}
|
||||
case EventType::SetChar:
|
||||
{
|
||||
if(m_UserInterfaceEvents)
|
||||
{
|
||||
const SetCharEvent& event = (const SetCharEvent&)inputEvent;
|
||||
io.AddInputCharacter(event.GetCharacter());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
case EventType::WheelScrolled:
|
||||
{
|
||||
const WheelScrolledEvent& event = (const WheelScrolledEvent&)inputEvent;
|
||||
|
||||
}
|
||||
if (m_GameEvents)
|
||||
m_MouseWheelDelta = event.GetOffset();
|
||||
|
||||
if (m_UserInterfaceEvents)
|
||||
io.MouseWheel = event.GetOffset();
|
||||
|
||||
return;
|
||||
}
|
||||
//** KEYBOARD_EVENTS **//
|
||||
case EventType::KeyPressed:
|
||||
{
|
||||
const KeyPressedEvent& event = (const KeyPressedEvent&)inputEvent;
|
||||
|
||||
if (m_GameEvents)
|
||||
m_KeyboadKeys[event.GetKey()] = true;
|
||||
|
||||
if (m_UserInterfaceEvents)
|
||||
{
|
||||
io.KeysDown[event.GetKey()] = true;
|
||||
//if (event.GetKey() == Key::BackSpace)
|
||||
// io.AddInputCharacter(Key::BackSpace);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
case EventType::KeyReleased:
|
||||
{
|
||||
const KeyReleasedEvent& event = (const KeyReleasedEvent&)inputEvent;
|
||||
|
||||
if (m_GameEvents)
|
||||
m_KeyboadKeys[event.GetKey()] = false;
|
||||
|
||||
if (m_UserInterfaceEvents)
|
||||
io.KeysDown[event.GetKey()] = false;
|
||||
|
||||
return;
|
||||
}
|
||||
case EventType::SetChar:
|
||||
{
|
||||
if (m_UserInterfaceEvents)
|
||||
{
|
||||
const SetCharEvent& event = (const SetCharEvent&)inputEvent;
|
||||
io.AddInputCharacter(event.GetCharacter());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,54 +1,51 @@
|
|||
#include "LayerStack.h"
|
||||
|
||||
#include "Layer.h"
|
||||
|
||||
#include "Events/Event.h"
|
||||
#include "Events/MouseEvents.h"
|
||||
#include "Events/KeyboardEvents.h"
|
||||
#include "Events/MouseEvents.h"
|
||||
#include "Events/WindowEvents.h"
|
||||
#include "Layer.h"
|
||||
|
||||
namespace Light {
|
||||
|
||||
LayerStack* LayerStack::s_Context = nullptr;
|
||||
LayerStack* LayerStack::s_Context = nullptr;
|
||||
|
||||
Scope<LayerStack> LayerStack::Create()
|
||||
{
|
||||
return MakeScope<LayerStack>(new LayerStack());
|
||||
}
|
||||
Scope<LayerStack> LayerStack::Create()
|
||||
{
|
||||
return MakeScope<LayerStack>(new LayerStack());
|
||||
}
|
||||
|
||||
LayerStack::LayerStack()
|
||||
: m_Layers{},
|
||||
m_Begin(),
|
||||
m_End()
|
||||
{
|
||||
LT_ENGINE_ASSERT(!s_Context, "LayerStack::LayerStack: an instance of 'LayerStack' already exists, do not construct this class!")
|
||||
s_Context = this;
|
||||
}
|
||||
LayerStack::LayerStack()
|
||||
: m_Layers {}, m_Begin(), m_End()
|
||||
{
|
||||
ASSERT(!s_Context, "An instance of 'LayerStack' already exists, do not construct this class!")
|
||||
s_Context = this;
|
||||
}
|
||||
|
||||
LayerStack::~LayerStack()
|
||||
{
|
||||
for (Layer* layer : m_Layers)
|
||||
delete layer;
|
||||
}
|
||||
LayerStack::~LayerStack()
|
||||
{
|
||||
for (Layer* layer : m_Layers)
|
||||
delete layer;
|
||||
}
|
||||
|
||||
void LayerStack::AttachLayerImpl(Layer* layer)
|
||||
{
|
||||
// #todo: handle attaching layer inside a for loop
|
||||
m_Layers.push_back(layer);
|
||||
m_Begin = m_Layers.begin();
|
||||
m_End = m_Layers.end();
|
||||
void LayerStack::AttachLayerImpl(Layer* layer)
|
||||
{
|
||||
// #todo: handle attaching layer inside a for loop
|
||||
m_Layers.push_back(layer);
|
||||
m_Begin = m_Layers.begin();
|
||||
m_End = m_Layers.end();
|
||||
|
||||
LT_ENGINE_TRACE("LayerStack::PushLayer: Attached [{}]", layer->GetName());
|
||||
}
|
||||
LOG(trace, "Attached [{}]", layer->GetName());
|
||||
}
|
||||
|
||||
void LayerStack::DetachLayerImpl(Layer* layer)
|
||||
{
|
||||
// #todo: handle detaching layer inside a for loop
|
||||
m_Layers.erase(std::find(m_Layers.begin(), m_Layers.end(), layer));
|
||||
m_Begin = m_Layers.begin();
|
||||
m_End = m_Layers.end();
|
||||
void LayerStack::DetachLayerImpl(Layer* layer)
|
||||
{
|
||||
// #todo: handle detaching layer inside a for loop
|
||||
m_Layers.erase(std::find(m_Layers.begin(), m_Layers.end(), layer));
|
||||
m_Begin = m_Layers.begin();
|
||||
m_End = m_Layers.end();
|
||||
|
||||
LT_ENGINE_TRACE("LayerStack::PushLayer: Detached[{}]", layer->GetName());
|
||||
}
|
||||
LOG(trace, "Detached [{}]", layer->GetName());
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Light
|
||||
|
|
|
@ -2,122 +2,109 @@
|
|||
|
||||
#include "Components.h"
|
||||
#include "Entity.h"
|
||||
|
||||
#include "Graphics/Renderer.h"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
namespace Light {
|
||||
|
||||
Scene::Scene()
|
||||
: m_Registry()
|
||||
{
|
||||
}
|
||||
|
||||
Scene::~Scene()
|
||||
{
|
||||
}
|
||||
|
||||
void Scene::OnCreate()
|
||||
{
|
||||
/* native scripts */
|
||||
{
|
||||
m_Registry.view<NativeScriptComponent>().
|
||||
each([](NativeScriptComponent& nsc)
|
||||
{
|
||||
if (nsc.instance == nullptr)
|
||||
{
|
||||
nsc.instance = nsc.CreateInstance();
|
||||
nsc.instance->OnCreate();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void Scene::OnUpdate(float deltaTime)
|
||||
{
|
||||
/* native scripts */
|
||||
{
|
||||
m_Registry.view<NativeScriptComponent>().
|
||||
each([=](NativeScriptComponent& nsc)
|
||||
{
|
||||
nsc.instance->OnUpdate(deltaTime);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void Scene::OnRender(const Ref<Framebuffer>& targetFrameBuffer /* = nullptr */)
|
||||
{
|
||||
Camera* sceneCamera = nullptr;
|
||||
TransformComponent* sceneCameraTransform;
|
||||
|
||||
/* scene camera */
|
||||
{
|
||||
m_Registry.group(entt::get<TransformComponent, CameraComponent>).
|
||||
each([&](TransformComponent& transformComp, CameraComponent& cameraComp)
|
||||
{
|
||||
|
||||
if (cameraComp.isPrimary)
|
||||
{
|
||||
sceneCamera = &cameraComp.camera;
|
||||
sceneCameraTransform = &transformComp;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* draw quads */
|
||||
{
|
||||
if (sceneCamera)
|
||||
{
|
||||
Renderer::BeginScene(sceneCamera, *sceneCameraTransform, targetFrameBuffer);
|
||||
|
||||
m_Registry.group(entt::get<TransformComponent, SpriteRendererComponent>).
|
||||
each([](TransformComponent& transformComp, SpriteRendererComponent& spriteRendererComp)
|
||||
{
|
||||
Renderer::DrawQuad(transformComp, spriteRendererComp.tint, spriteRendererComp.texture);
|
||||
});
|
||||
|
||||
Renderer::EndScene();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Entity Scene::CreateEntity(const std::string& name, const TransformComponent& transform)
|
||||
{
|
||||
return CreateEntityWithUUID(name, UUID(), transform);
|
||||
}
|
||||
|
||||
Entity Scene::GetEntityByTag(const std::string& tag)
|
||||
{
|
||||
// TagComponent tagComp(tag);
|
||||
// entt::entity entity = entt::to_entity(m_Registry, tagComp);
|
||||
Entity entity;
|
||||
|
||||
m_Registry.view<TagComponent>().
|
||||
each([&](TagComponent& tagComp)
|
||||
{
|
||||
if (tagComp.tag == tag)
|
||||
entity = Entity(entt::to_entity(m_Registry, tagComp), this);
|
||||
});
|
||||
|
||||
if (entity.IsValid())
|
||||
return entity;
|
||||
else {
|
||||
LT_ENGINE_ERROR("Scene::GetEntityByTag: failed to find entity by tag: {}", tag);
|
||||
return Entity();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Entity Scene::CreateEntityWithUUID(const std::string& name, UUID uuid, const TransformComponent& transform)
|
||||
{
|
||||
Entity entity { m_Registry.create(), this };
|
||||
entity.AddComponent<TagComponent>(name);
|
||||
entity.AddComponent<TransformComponent>(transform);
|
||||
entity.AddComponent<UUIDComponent>(uuid);
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
Scene::Scene()
|
||||
: m_Registry()
|
||||
{
|
||||
}
|
||||
|
||||
Scene::~Scene()
|
||||
{
|
||||
}
|
||||
|
||||
void Scene::OnCreate()
|
||||
{
|
||||
/* native scripts */
|
||||
{
|
||||
m_Registry.view<NativeScriptComponent>().each([](NativeScriptComponent& nsc) {
|
||||
if (nsc.instance == nullptr)
|
||||
{
|
||||
nsc.instance = nsc.CreateInstance();
|
||||
nsc.instance->OnCreate();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void Scene::OnUpdate(float deltaTime)
|
||||
{
|
||||
/* native scripts */
|
||||
{
|
||||
m_Registry.view<NativeScriptComponent>().each([=](NativeScriptComponent& nsc) {
|
||||
nsc.instance->OnUpdate(deltaTime);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void Scene::OnRender(const Ref<Framebuffer>& targetFrameBuffer /* = nullptr */)
|
||||
{
|
||||
Camera* sceneCamera = nullptr;
|
||||
TransformComponent* sceneCameraTransform;
|
||||
|
||||
/* scene camera */
|
||||
{
|
||||
m_Registry.group(entt::get<TransformComponent, CameraComponent>).each([&](TransformComponent& transformComp, CameraComponent& cameraComp) {
|
||||
if (cameraComp.isPrimary)
|
||||
{
|
||||
sceneCamera = &cameraComp.camera;
|
||||
sceneCameraTransform = &transformComp;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* draw quads */
|
||||
{
|
||||
if (sceneCamera)
|
||||
{
|
||||
Renderer::BeginScene(sceneCamera, *sceneCameraTransform, targetFrameBuffer);
|
||||
|
||||
m_Registry.group(entt::get<TransformComponent, SpriteRendererComponent>).each([](TransformComponent& transformComp, SpriteRendererComponent& spriteRendererComp) {
|
||||
Renderer::DrawQuad(transformComp, spriteRendererComp.tint, spriteRendererComp.texture);
|
||||
});
|
||||
|
||||
Renderer::EndScene();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Entity Scene::CreateEntity(const std::string& name, const TransformComponent& transform)
|
||||
{
|
||||
return CreateEntityWithUUID(name, UUID(), transform);
|
||||
}
|
||||
|
||||
Entity Scene::GetEntityByTag(const std::string& tag)
|
||||
{
|
||||
// TagComponent tagComp(tag);
|
||||
// entt::entity entity = entt::to_entity(m_Registry, tagComp);
|
||||
Entity entity;
|
||||
|
||||
m_Registry.view<TagComponent>().each([&](TagComponent& tagComp) {
|
||||
if (tagComp.tag == tag)
|
||||
entity = Entity(entt::to_entity(m_Registry, tagComp), this);
|
||||
});
|
||||
|
||||
if (entity.IsValid())
|
||||
return entity;
|
||||
else
|
||||
{
|
||||
ASSERT("Scene::GetEntityByTag: failed to find entity by tag: {}", tag);
|
||||
return Entity();
|
||||
}
|
||||
}
|
||||
|
||||
Entity Scene::CreateEntityWithUUID(const std::string& name, UUID uuid, const TransformComponent& transform)
|
||||
{
|
||||
Entity entity { m_Registry.create(), this };
|
||||
entity.AddComponent<TagComponent>(name);
|
||||
entity.AddComponent<TransformComponent>(transform);
|
||||
entity.AddComponent<UUIDComponent>(uuid);
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "UserInterface.h"
|
||||
|
||||
#include "OpenGL/glUserInterface.h"
|
||||
|
||||
#ifdef LIGHT_PLATFORM_WINDOWS
|
||||
|
@ -6,217 +7,216 @@
|
|||
#include "DirectX/dxSharedContext.h"
|
||||
#endif
|
||||
|
||||
#include "Events/Event.h"
|
||||
#include "Events/CharEvent.h"
|
||||
#include "Events/MouseEvents.h"
|
||||
#include "Events/Event.h"
|
||||
#include "Events/KeyboardEvents.h"
|
||||
|
||||
#include "Events/MouseEvents.h"
|
||||
#include "Graphics/GraphicsContext.h"
|
||||
|
||||
#include "Input/KeyCodes.h"
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
namespace Light {
|
||||
|
||||
UserInterface* UserInterface::s_Context = nullptr;
|
||||
UserInterface* UserInterface::s_Context = nullptr;
|
||||
|
||||
Scope<UserInterface> UserInterface::Create(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext)
|
||||
Scope<UserInterface> UserInterface::Create(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext)
|
||||
{
|
||||
Scope<UserInterface> scopeUserInterface = nullptr;
|
||||
|
||||
switch (GraphicsContext::GetGraphicsAPI())
|
||||
{
|
||||
Scope<UserInterface> scopeUserInterface = nullptr;
|
||||
case GraphicsAPI::OpenGL:
|
||||
scopeUserInterface = CreateScope<glUserInterface>();
|
||||
break;
|
||||
|
||||
switch (GraphicsContext::GetGraphicsAPI())
|
||||
{
|
||||
case GraphicsAPI::OpenGL:
|
||||
scopeUserInterface = CreateScope<glUserInterface>();
|
||||
break;
|
||||
case GraphicsAPI::DirectX:
|
||||
LT_WIN(
|
||||
scopeUserInterface = CreateScope<dxUserInterface>();)
|
||||
break;
|
||||
|
||||
case GraphicsAPI::DirectX: LT_WIN(
|
||||
scopeUserInterface = CreateScope<dxUserInterface>();)
|
||||
break;
|
||||
|
||||
default:
|
||||
LT_ENGINE_ASSERT(false, "UserInterface::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
scopeUserInterface->Init(windowHandle, sharedContext);
|
||||
return std::move(scopeUserInterface);
|
||||
default:
|
||||
ASSERT(false, "UserInterface::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UserInterface::UserInterface()
|
||||
: m_DockspaceFlags(ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar |
|
||||
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove |
|
||||
ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus )
|
||||
{
|
||||
LT_ENGINE_ASSERT(!s_Context, "UserInterface::UserInterface: an instance of 'UserInterface' already exists, do not construct this class!");
|
||||
s_Context = this;
|
||||
}
|
||||
scopeUserInterface->Init(windowHandle, sharedContext);
|
||||
return std::move(scopeUserInterface);
|
||||
}
|
||||
|
||||
void UserInterface::Init(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext)
|
||||
{
|
||||
// create context
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
UserInterface::UserInterface()
|
||||
: m_DockspaceFlags(ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar |
|
||||
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove |
|
||||
ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus)
|
||||
{
|
||||
ASSERT(!s_Context, "UserInterface::UserInterface: an instance of 'UserInterface' already exists, do not construct this class!");
|
||||
s_Context = this;
|
||||
}
|
||||
|
||||
// configure io
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
||||
void UserInterface::Init(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext)
|
||||
{
|
||||
// create context
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
|
||||
// configure io
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
||||
|
||||
io.ConfigFlags |= ImGuiBackendFlags_PlatformHasViewports;
|
||||
io.ConfigFlags |= ImGuiBackendFlags_RendererHasViewports;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
|
||||
|
||||
// #todo: handle this in a better way
|
||||
if (std::filesystem::exists("user_gui_layout.ini"))
|
||||
io.IniFilename = "user_gui_layout.ini";
|
||||
else
|
||||
io.IniFilename = "default_gui_layout.ini";
|
||||
io.ConfigFlags |= ImGuiBackendFlags_PlatformHasViewports;
|
||||
io.ConfigFlags |= ImGuiBackendFlags_RendererHasViewports;
|
||||
|
||||
// style
|
||||
ImGui::StyleColorsDark();
|
||||
// #todo: handle this in a better way
|
||||
if (std::filesystem::exists("user_gui_layout.ini"))
|
||||
io.IniFilename = "user_gui_layout.ini";
|
||||
else
|
||||
io.IniFilename = "default_gui_layout.ini";
|
||||
|
||||
PlatformImplementation(windowHandle, sharedContext);
|
||||
// style
|
||||
ImGui::StyleColorsDark();
|
||||
|
||||
// keyboard map
|
||||
io.KeyMap[ImGuiKey_Tab] = Key::Tab;
|
||||
io.KeyMap[ImGuiKey_LeftArrow] = Key::LeftArrow;
|
||||
io.KeyMap[ImGuiKey_RightArrow] = Key::RightArrow;
|
||||
io.KeyMap[ImGuiKey_UpArrow] = Key::UpArrow;
|
||||
io.KeyMap[ImGuiKey_DownArrow] = Key::DownArrow;
|
||||
io.KeyMap[ImGuiKey_PageUp] = Key::PageUp;
|
||||
io.KeyMap[ImGuiKey_PageDown] = Key::PageDown;
|
||||
io.KeyMap[ImGuiKey_Home] = Key::Home;
|
||||
io.KeyMap[ImGuiKey_End] = Key::End;
|
||||
io.KeyMap[ImGuiKey_Insert] = Key::Insert;
|
||||
io.KeyMap[ImGuiKey_Delete] = Key::Delete;
|
||||
io.KeyMap[ImGuiKey_Backspace] = Key::BackSpace;
|
||||
io.KeyMap[ImGuiKey_Space] = Key::Space;
|
||||
io.KeyMap[ImGuiKey_Enter] = Key::Enter;
|
||||
io.KeyMap[ImGuiKey_Escape] = Key::Escape;
|
||||
io.KeyMap[ImGuiKey_KeyPadEnter] = Key::Enter;
|
||||
io.KeyMap[ImGuiKey_A] = Key::A;
|
||||
io.KeyMap[ImGuiKey_C] = Key::C;
|
||||
io.KeyMap[ImGuiKey_V] = Key::V;
|
||||
io.KeyMap[ImGuiKey_X] = Key::X;
|
||||
io.KeyMap[ImGuiKey_Y] = Key::Y;
|
||||
io.KeyMap[ImGuiKey_Z] = Key::Z;
|
||||
PlatformImplementation(windowHandle, sharedContext);
|
||||
|
||||
io.Fonts->AddFontFromFileTTF("Assets//Fonts/OpenSans/OpenSans-Bold.ttf", 18.0f);
|
||||
io.FontDefault = io.Fonts->AddFontFromFileTTF("Assets/Fonts/OpenSans/OpenSans-Regular.ttf", 18.0f);
|
||||
// keyboard map
|
||||
io.KeyMap[ImGuiKey_Tab] = Key::Tab;
|
||||
io.KeyMap[ImGuiKey_LeftArrow] = Key::LeftArrow;
|
||||
io.KeyMap[ImGuiKey_RightArrow] = Key::RightArrow;
|
||||
io.KeyMap[ImGuiKey_UpArrow] = Key::UpArrow;
|
||||
io.KeyMap[ImGuiKey_DownArrow] = Key::DownArrow;
|
||||
io.KeyMap[ImGuiKey_PageUp] = Key::PageUp;
|
||||
io.KeyMap[ImGuiKey_PageDown] = Key::PageDown;
|
||||
io.KeyMap[ImGuiKey_Home] = Key::Home;
|
||||
io.KeyMap[ImGuiKey_End] = Key::End;
|
||||
io.KeyMap[ImGuiKey_Insert] = Key::Insert;
|
||||
io.KeyMap[ImGuiKey_Delete] = Key::Delete;
|
||||
io.KeyMap[ImGuiKey_Backspace] = Key::BackSpace;
|
||||
io.KeyMap[ImGuiKey_Space] = Key::Space;
|
||||
io.KeyMap[ImGuiKey_Enter] = Key::Enter;
|
||||
io.KeyMap[ImGuiKey_Escape] = Key::Escape;
|
||||
io.KeyMap[ImGuiKey_KeyPadEnter] = Key::Enter;
|
||||
io.KeyMap[ImGuiKey_A] = Key::A;
|
||||
io.KeyMap[ImGuiKey_C] = Key::C;
|
||||
io.KeyMap[ImGuiKey_V] = Key::V;
|
||||
io.KeyMap[ImGuiKey_X] = Key::X;
|
||||
io.KeyMap[ImGuiKey_Y] = Key::Y;
|
||||
io.KeyMap[ImGuiKey_Z] = Key::Z;
|
||||
|
||||
SetDarkThemeColors();
|
||||
}
|
||||
io.Fonts->AddFontFromFileTTF("Assets//Fonts/OpenSans/OpenSans-Bold.ttf", 18.0f);
|
||||
io.FontDefault = io.Fonts->AddFontFromFileTTF("Assets/Fonts/OpenSans/OpenSans-Regular.ttf", 18.0f);
|
||||
|
||||
void UserInterface::DockspaceBegin()
|
||||
{
|
||||
ImGuiViewport* viewport = ImGui::GetMainViewport();
|
||||
ImGui::SetNextWindowPos(viewport->Pos);
|
||||
ImGui::SetNextWindowSize(viewport->Size);
|
||||
ImGui::SetNextWindowViewport(viewport->ID);
|
||||
SetDarkThemeColors();
|
||||
}
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
|
||||
ImGui::Begin("Dockspace", (bool*)0, s_Context->m_DockspaceFlags);
|
||||
ImGui::PopStyleVar(3);
|
||||
void UserInterface::DockspaceBegin()
|
||||
{
|
||||
ImGuiViewport* viewport = ImGui::GetMainViewport();
|
||||
ImGui::SetNextWindowPos(viewport->Pos);
|
||||
ImGui::SetNextWindowSize(viewport->Size);
|
||||
ImGui::SetNextWindowViewport(viewport->ID);
|
||||
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
float minWinSizeX = style.WindowMinSize.x;
|
||||
style.WindowMinSize.x = 370.0f;
|
||||
ImGui::DockSpace(ImGui::GetID("MyDockSpace"), ImVec2(0.0f, 0.0f), ImGuiDockNodeFlags_None | ImGuiWindowFlags_NoBackground);
|
||||
style.WindowMinSize.x = minWinSizeX;
|
||||
}
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
|
||||
ImGui::Begin("Dockspace", (bool*)0, s_Context->m_DockspaceFlags);
|
||||
ImGui::PopStyleVar(3);
|
||||
|
||||
void UserInterface::DockspaceEnd()
|
||||
{
|
||||
ImGui::End();
|
||||
}
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
float minWinSizeX = style.WindowMinSize.x;
|
||||
style.WindowMinSize.x = 370.0f;
|
||||
ImGui::DockSpace(ImGui::GetID("MyDockSpace"), ImVec2(0.0f, 0.0f), ImGuiDockNodeFlags_None | ImGuiWindowFlags_NoBackground);
|
||||
style.WindowMinSize.x = minWinSizeX;
|
||||
}
|
||||
|
||||
void UserInterface::SetDarkThemeColors()
|
||||
{
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
ImVec4 (&colors)[55] = style.Colors;
|
||||
void UserInterface::DockspaceEnd()
|
||||
{
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
style.WindowPadding = ImVec2(0.0f, 0.0f);
|
||||
void UserInterface::SetDarkThemeColors()
|
||||
{
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
ImVec4(&colors)[55] = style.Colors;
|
||||
|
||||
colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
|
||||
colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
|
||||
style.WindowPadding = ImVec2(0.0f, 0.0f);
|
||||
|
||||
colors[ImGuiCol_WindowBg] = ImVec4(0.10f, 0.10f, 0.11f, 1.00f);
|
||||
colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||
colors[ImGuiCol_PopupBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f);
|
||||
colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
|
||||
colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
|
||||
|
||||
colors[ImGuiCol_Border] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f);
|
||||
colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||
colors[ImGuiCol_WindowBg] = ImVec4(0.10f, 0.10f, 0.11f, 1.00f);
|
||||
colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||
colors[ImGuiCol_PopupBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f);
|
||||
|
||||
colors[ImGuiCol_FrameBg] = ImVec4(0.20f, 0.20f, 0.21f, 1.00f);
|
||||
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.30f, 0.31f, 0.31f, 1.00f);
|
||||
colors[ImGuiCol_FrameBgActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
||||
colors[ImGuiCol_Border] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f);
|
||||
colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||
|
||||
colors[ImGuiCol_TitleBg] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
||||
colors[ImGuiCol_TitleBgActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
||||
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
||||
colors[ImGuiCol_FrameBg] = ImVec4(0.20f, 0.20f, 0.21f, 1.00f);
|
||||
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.30f, 0.31f, 0.31f, 1.00f);
|
||||
colors[ImGuiCol_FrameBgActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
||||
|
||||
colors[ImGuiCol_MenuBarBg] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f);
|
||||
colors[ImGuiCol_TitleBg] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
||||
colors[ImGuiCol_TitleBgActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
||||
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
||||
|
||||
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.02f, 0.02f, 0.02f, 0.53f);
|
||||
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.31f, 0.31f, 0.31f, 1.00f);
|
||||
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f);
|
||||
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.51f, 0.51f, 0.51f, 1.00f);
|
||||
colors[ImGuiCol_MenuBarBg] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f);
|
||||
|
||||
colors[ImGuiCol_CheckMark] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
|
||||
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.02f, 0.02f, 0.02f, 0.53f);
|
||||
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.31f, 0.31f, 0.31f, 1.00f);
|
||||
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f);
|
||||
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.51f, 0.51f, 0.51f, 1.00f);
|
||||
|
||||
colors[ImGuiCol_SliderGrab] = ImVec4(0.24f, 0.52f, 0.88f, 1.00f);
|
||||
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
|
||||
colors[ImGuiCol_CheckMark] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
|
||||
|
||||
colors[ImGuiCol_Button] = ImVec4(0.20f, 0.20f, 0.21f, 1.00f);
|
||||
colors[ImGuiCol_ButtonHovered] = ImVec4(0.30f, 0.31f, 0.31f, 1.00f);
|
||||
colors[ImGuiCol_ButtonActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
||||
colors[ImGuiCol_SliderGrab] = ImVec4(0.24f, 0.52f, 0.88f, 1.00f);
|
||||
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
|
||||
|
||||
colors[ImGuiCol_Header] = ImVec4(0.20f, 0.20f, 0.21f, 1.00f);
|
||||
colors[ImGuiCol_HeaderHovered] = ImVec4(0.30f, 0.31f, 0.31f, 1.00f);
|
||||
colors[ImGuiCol_HeaderActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
||||
colors[ImGuiCol_Button] = ImVec4(0.20f, 0.20f, 0.21f, 1.00f);
|
||||
colors[ImGuiCol_ButtonHovered] = ImVec4(0.30f, 0.31f, 0.31f, 1.00f);
|
||||
colors[ImGuiCol_ButtonActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
||||
|
||||
colors[ImGuiCol_Separator] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f);
|
||||
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.10f, 0.40f, 0.75f, 0.78f);
|
||||
colors[ImGuiCol_SeparatorActive] = ImVec4(0.10f, 0.40f, 0.75f, 1.00f);
|
||||
colors[ImGuiCol_Header] = ImVec4(0.20f, 0.20f, 0.21f, 1.00f);
|
||||
colors[ImGuiCol_HeaderHovered] = ImVec4(0.30f, 0.31f, 0.31f, 1.00f);
|
||||
colors[ImGuiCol_HeaderActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
||||
|
||||
colors[ImGuiCol_ResizeGrip] = ImVec4(0.26f, 0.59f, 0.98f, 0.20f);
|
||||
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f);
|
||||
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f);
|
||||
colors[ImGuiCol_Separator] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f);
|
||||
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.10f, 0.40f, 0.75f, 0.78f);
|
||||
colors[ImGuiCol_SeparatorActive] = ImVec4(0.10f, 0.40f, 0.75f, 1.00f);
|
||||
|
||||
colors[ImGuiCol_Tab] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
||||
colors[ImGuiCol_TabHovered] = ImVec4(0.38f, 0.38f, 0.38f, 1.00f);
|
||||
colors[ImGuiCol_TabActive] = ImVec4(0.28f, 0.28f, 0.28f, 1.00f);
|
||||
colors[ImGuiCol_TabUnfocused] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
||||
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.20f, 0.20f, 0.21f, 1.00f);
|
||||
colors[ImGuiCol_ResizeGrip] = ImVec4(0.26f, 0.59f, 0.98f, 0.20f);
|
||||
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f);
|
||||
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f);
|
||||
|
||||
colors[ImGuiCol_DockingPreview] = ImVec4(0.26f, 0.59f, 0.98f, 0.70f);
|
||||
colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
|
||||
colors[ImGuiCol_Tab] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
||||
colors[ImGuiCol_TabHovered] = ImVec4(0.38f, 0.38f, 0.38f, 1.00f);
|
||||
colors[ImGuiCol_TabActive] = ImVec4(0.28f, 0.28f, 0.28f, 1.00f);
|
||||
colors[ImGuiCol_TabUnfocused] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
||||
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.20f, 0.20f, 0.21f, 1.00f);
|
||||
|
||||
colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f);
|
||||
colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f);
|
||||
colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
|
||||
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
|
||||
colors[ImGuiCol_DockingPreview] = ImVec4(0.26f, 0.59f, 0.98f, 0.70f);
|
||||
colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
|
||||
|
||||
colors[ImGuiCol_TableHeaderBg] = ImVec4(0.19f, 0.19f, 0.20f, 1.00f);
|
||||
colors[ImGuiCol_TableBorderStrong] = ImVec4(0.31f, 0.31f, 0.35f, 1.00f);
|
||||
colors[ImGuiCol_TableBorderLight] = ImVec4(0.23f, 0.23f, 0.25f, 1.00f);
|
||||
colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||
colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.06f);
|
||||
colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f);
|
||||
colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f);
|
||||
colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
|
||||
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
|
||||
|
||||
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
|
||||
colors[ImGuiCol_TableHeaderBg] = ImVec4(0.19f, 0.19f, 0.20f, 1.00f);
|
||||
colors[ImGuiCol_TableBorderStrong] = ImVec4(0.31f, 0.31f, 0.35f, 1.00f);
|
||||
colors[ImGuiCol_TableBorderLight] = ImVec4(0.23f, 0.23f, 0.25f, 1.00f);
|
||||
colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||
colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.06f);
|
||||
|
||||
colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f);
|
||||
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
|
||||
|
||||
colors[ImGuiCol_NavHighlight] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
|
||||
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
|
||||
colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
|
||||
colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f);
|
||||
|
||||
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f);
|
||||
}
|
||||
colors[ImGuiCol_NavHighlight] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
|
||||
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
|
||||
colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
|
||||
|
||||
}
|
||||
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f);
|
||||
}
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -4,56 +4,56 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
BasicFileHandle FileManager::ReadTextFile(const std::string& path)
|
||||
BasicFileHandle FileManager::ReadTextFile(const std::string& path)
|
||||
{
|
||||
// parse path info
|
||||
std::string name = path.substr(0, path.find('.') + -1);
|
||||
std::string extension = path.substr(path.find('.') + 1);
|
||||
|
||||
// open file
|
||||
std::ifstream file(path.c_str(), std::ios_base::in | std::ios_base::binary);
|
||||
|
||||
// check
|
||||
if (!file)
|
||||
{
|
||||
// parse path info
|
||||
std::string name = path.substr(0, path.find('.') + -1);
|
||||
std::string extension = path.substr(path.find('.') + 1);
|
||||
|
||||
// open file
|
||||
std::ifstream file(path.c_str(), std::ios_base::in | std::ios_base::binary);
|
||||
|
||||
// check
|
||||
if (!file)
|
||||
{
|
||||
LT_ENGINE_WARN("FileManager::ReadTextFile: failed to load text file: {}", path);
|
||||
file.close();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// fetch file size
|
||||
file.seekg(0, std::ios::end);
|
||||
uint32_t size = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
if (!size)
|
||||
LT_ENGINE_WARN("FileManager::ReadTextFile: empty text file: {}", path);
|
||||
|
||||
// read file
|
||||
uint8_t* data = new uint8_t[size];
|
||||
file.read(reinterpret_cast<char*>(data), size);
|
||||
|
||||
LOG(warn, "Failed to load text file: {}", path);
|
||||
file.close();
|
||||
return BasicFileHandle(data, size, path, name, extension);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ImageFileHandle FileManager::ReadImageFile(const std::string& path, int32_t desiredComponents)
|
||||
{
|
||||
// parse path info
|
||||
std::string name = path.substr(0, path.find('.') + -1);
|
||||
std::string extension = path.substr(path.find('.') + 1);
|
||||
// fetch file size
|
||||
file.seekg(0, std::ios::end);
|
||||
uint32_t size = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
// load image
|
||||
int32_t width = 0, height = 0, fetchedComponents = 0;
|
||||
uint8_t* pixels = stbi_load(path.c_str(), &width, &height, &fetchedComponents, desiredComponents);
|
||||
if (!size)
|
||||
LOG(warn, "Empty text file: {}", path);
|
||||
|
||||
// check
|
||||
if(!pixels)
|
||||
LT_ENGINE_WARN("FileManager::LoadImageFile: failed to load image file: <{}>", path);
|
||||
else if (fetchedComponents != desiredComponents)
|
||||
LT_ENGINE_WARN("FileManager::LoadImageFile: mismatch of fetched/desired components: <{}> ({}/{})", name + '.' + extension, fetchedComponents, desiredComponents);
|
||||
// read file
|
||||
uint8_t* data = new uint8_t[size];
|
||||
file.read(reinterpret_cast<char*>(data), size);
|
||||
|
||||
return ImageFileHandle(pixels, width * height, path, name, extension, width, height, fetchedComponents, desiredComponents);
|
||||
}
|
||||
file.close();
|
||||
return BasicFileHandle(data, size, path, name, extension);
|
||||
}
|
||||
|
||||
}
|
||||
ImageFileHandle FileManager::ReadImageFile(const std::string& path, int32_t desiredComponents)
|
||||
{
|
||||
// parse path info
|
||||
std::string name = path.substr(0, path.find('.') + -1);
|
||||
std::string extension = path.substr(path.find('.') + 1);
|
||||
|
||||
// load image
|
||||
int32_t width = 0, height = 0, fetchedComponents = 0;
|
||||
uint8_t* pixels = stbi_load(path.c_str(), &width, &height, &fetchedComponents, desiredComponents);
|
||||
|
||||
// check
|
||||
if (!pixels)
|
||||
LOG(warn, "Failed to load image file: <{}>", path);
|
||||
else if (fetchedComponents != desiredComponents)
|
||||
LOG(warn, "Mismatch of fetched/desired components: <{}> ({}/{})", name + '.' + extension, fetchedComponents, desiredComponents);
|
||||
|
||||
return ImageFileHandle(pixels, width * height, path, name, extension, width, height, fetchedComponents, desiredComponents);
|
||||
}
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,74 +1,72 @@
|
|||
#include "ResourceManager.h"
|
||||
|
||||
#include "FileManager.h"
|
||||
|
||||
#include "Graphics/GraphicsContext.h"
|
||||
#include "Graphics/Shader.h"
|
||||
#include "Graphics/Texture.h"
|
||||
|
||||
namespace Light {
|
||||
|
||||
ResourceManager* ResourceManager::s_Context = nullptr;
|
||||
ResourceManager* ResourceManager::s_Context = nullptr;
|
||||
|
||||
Scope<ResourceManager> ResourceManager::Create()
|
||||
Scope<ResourceManager> ResourceManager::Create()
|
||||
{
|
||||
return MakeScope(new ResourceManager());
|
||||
}
|
||||
|
||||
ResourceManager::ResourceManager()
|
||||
: m_Shaders {}, m_Textures {}
|
||||
{
|
||||
ASSERT(!s_Context, "Repeated singleton construction");
|
||||
s_Context = this;
|
||||
}
|
||||
|
||||
void ResourceManager::LoadShaderImpl(const std::string& name, const std::string& vertexPath, const std::string& pixelPath)
|
||||
{
|
||||
// check
|
||||
ASSERT(s_Context, "Uninitliazed singleton");
|
||||
ASSERT(!vertexPath.empty(), "Empty 'vertexPath'");
|
||||
ASSERT(!pixelPath.empty(), "Empty 'pixelPath'");
|
||||
|
||||
// load files
|
||||
BasicFileHandle vertexFile = FileManager::ReadTextFile(vertexPath);
|
||||
BasicFileHandle pixelFile = FileManager::ReadTextFile(pixelPath);
|
||||
|
||||
// check
|
||||
ASSERT(vertexFile.IsValid(), "Failed to read vertex file: {}", vertexPath);
|
||||
ASSERT(pixelFile.IsValid(), "Failed to read vertex file: {}", pixelPath);
|
||||
|
||||
// create shader
|
||||
m_Shaders[name] = Ref<Shader>(Shader::Create(vertexFile, pixelFile, GraphicsContext::GetSharedContext()));
|
||||
|
||||
// free file
|
||||
vertexFile.Release();
|
||||
pixelFile.Release();
|
||||
}
|
||||
|
||||
void ResourceManager::LoadTextureImpl(const std::string& name, const std::string& path, unsigned int desiredComponents /* = 4u */)
|
||||
{
|
||||
ASSERT(s_Context, "Uninitliazed singleton");
|
||||
|
||||
// load file
|
||||
ImageFileHandle imgFile = FileManager::ReadImageFile(path, desiredComponents);
|
||||
|
||||
// create texture
|
||||
m_Textures[name] = Ref<Texture>(Texture::Create(imgFile.GetWidth(), imgFile.GetHeight(), imgFile.GetComponents(), imgFile.GetData(), GraphicsContext::GetSharedContext(), path));
|
||||
|
||||
// free file
|
||||
imgFile.Release();
|
||||
}
|
||||
|
||||
void ResourceManager::ReleaseTextureImpl(const std::string& name)
|
||||
{
|
||||
if (!m_Textures[name])
|
||||
{
|
||||
return MakeScope(new ResourceManager());
|
||||
LOG(warn, "Failed to find texture named: {}", name);
|
||||
return;
|
||||
}
|
||||
|
||||
ResourceManager::ResourceManager() :
|
||||
m_Shaders{},
|
||||
m_Textures{}
|
||||
{
|
||||
LT_ENGINE_ASSERT(!s_Context, "ResourceManager::ResourceManager: repeated singleton construction");
|
||||
s_Context = this;
|
||||
}
|
||||
m_Textures[name] = nullptr;
|
||||
}
|
||||
|
||||
void ResourceManager::LoadShaderImpl(const std::string& name, const std::string& vertexPath, const std::string& pixelPath)
|
||||
{
|
||||
// check
|
||||
LT_ENGINE_ASSERT(s_Context, "ResourceManager::LoadShaderImpl: uninitliazed singleton");
|
||||
LT_ENGINE_ASSERT(!vertexPath.empty(), "ResourceManager::LoadShaderImpl: empty 'vertexPath'");
|
||||
LT_ENGINE_ASSERT(!pixelPath.empty(), "ResourceManager::LoadShaderImpl: empty 'pixelPath'");
|
||||
|
||||
// load files
|
||||
BasicFileHandle vertexFile = FileManager::ReadTextFile(vertexPath);
|
||||
BasicFileHandle pixelFile = FileManager::ReadTextFile(pixelPath);
|
||||
|
||||
// check
|
||||
LT_ENGINE_ASSERT(vertexFile.IsValid(), "ResourceManager::LoadShaderImpl: failed to read vertex file: {}", vertexPath);
|
||||
LT_ENGINE_ASSERT(pixelFile.IsValid(), "ResourceManager::LoadShaderImpl: failed to read vertex file: {}", pixelPath);
|
||||
|
||||
// create shader
|
||||
m_Shaders[name] = Ref<Shader>(Shader::Create(vertexFile, pixelFile, GraphicsContext::GetSharedContext()));
|
||||
|
||||
// free file
|
||||
vertexFile.Release();
|
||||
pixelFile.Release();
|
||||
}
|
||||
|
||||
void ResourceManager::LoadTextureImpl(const std::string& name, const std::string& path, unsigned int desiredComponents /* = 4u */)
|
||||
{
|
||||
LT_ENGINE_ASSERT(s_Context, "ResourceManager::LoadShaderImpl: uninitliazed singleton");
|
||||
|
||||
// load file
|
||||
ImageFileHandle imgFile = FileManager::ReadImageFile(path, desiredComponents);
|
||||
|
||||
// create texture
|
||||
m_Textures[name] = Ref<Texture>(Texture::Create(imgFile.GetWidth(), imgFile.GetHeight(), imgFile.GetComponents(), imgFile.GetData(), GraphicsContext::GetSharedContext(), path));
|
||||
|
||||
// free file
|
||||
imgFile.Release();
|
||||
}
|
||||
|
||||
void ResourceManager::ReleaseTextureImpl(const std::string& name)
|
||||
{
|
||||
if (!m_Textures[name])
|
||||
{
|
||||
LT_ENGINE_WARN("ResourceManager::ReleaseTextureImpl: failed to find texture named: {}", name);
|
||||
return;
|
||||
}
|
||||
|
||||
m_Textures[name] = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,285 +1,282 @@
|
|||
#include "Serializer.h"
|
||||
|
||||
#include "Scene/Components.h"
|
||||
|
||||
#include "Graphics/Texture.h"
|
||||
|
||||
#include "Scene/Components.h"
|
||||
#include "Utility/ResourceManager.h"
|
||||
|
||||
namespace YAML {
|
||||
|
||||
template<>
|
||||
struct convert<glm::vec3>
|
||||
template<>
|
||||
struct convert<glm::vec3>
|
||||
{
|
||||
static Node encode(const glm::vec3& rhs)
|
||||
{
|
||||
static Node encode(const glm::vec3 & rhs)
|
||||
{
|
||||
Node node;
|
||||
node.push_back(rhs.x);
|
||||
node.push_back(rhs.y);
|
||||
node.push_back(rhs.z);
|
||||
return node;
|
||||
}
|
||||
Node node;
|
||||
node.push_back(rhs.x);
|
||||
node.push_back(rhs.y);
|
||||
node.push_back(rhs.z);
|
||||
return node;
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, glm::vec3& rhs)
|
||||
{
|
||||
if (!node.IsSequence() || node.size() != 3)
|
||||
return false;
|
||||
|
||||
rhs.x = node[0].as<float>();
|
||||
rhs.y = node[1].as<float>();
|
||||
rhs.z = node[2].as<float>();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct convert<glm::vec4>
|
||||
static bool decode(const Node& node, glm::vec3& rhs)
|
||||
{
|
||||
static Node encode(const glm::vec4& rhs)
|
||||
{
|
||||
Node node;
|
||||
node.push_back(rhs.x);
|
||||
node.push_back(rhs.y);
|
||||
node.push_back(rhs.z);
|
||||
node.push_back(rhs.w);
|
||||
return node;
|
||||
}
|
||||
if (!node.IsSequence() || node.size() != 3)
|
||||
return false;
|
||||
|
||||
static bool decode(const Node& node, glm::vec4& rhs)
|
||||
{
|
||||
if (!node.IsSequence() || node.size() != 4)
|
||||
return false;
|
||||
rhs.x = node[0].as<float>();
|
||||
rhs.y = node[1].as<float>();
|
||||
rhs.z = node[2].as<float>();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
rhs.x = node[0].as<float>();
|
||||
rhs.y = node[1].as<float>();
|
||||
rhs.z = node[2].as<float>();
|
||||
rhs.w = node[3].as<float>();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
template<>
|
||||
struct convert<glm::vec4>
|
||||
{
|
||||
static Node encode(const glm::vec4& rhs)
|
||||
{
|
||||
Node node;
|
||||
node.push_back(rhs.x);
|
||||
node.push_back(rhs.y);
|
||||
node.push_back(rhs.z);
|
||||
node.push_back(rhs.w);
|
||||
return node;
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, glm::vec4& rhs)
|
||||
{
|
||||
if (!node.IsSequence() || node.size() != 4)
|
||||
return false;
|
||||
|
||||
rhs.x = node[0].as<float>();
|
||||
rhs.y = node[1].as<float>();
|
||||
rhs.z = node[2].as<float>();
|
||||
rhs.w = node[3].as<float>();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
} // namespace YAML
|
||||
|
||||
namespace Light {
|
||||
|
||||
static YAML::Emitter& operator << (YAML::Emitter& out, const glm::vec3& v)
|
||||
{
|
||||
out << YAML::Flow;
|
||||
out << YAML::BeginSeq << v.x << v.y << v.z << YAML::EndSeq;
|
||||
return out;
|
||||
}
|
||||
static YAML::Emitter& operator<<(YAML::Emitter& out, const glm::vec3& v)
|
||||
{
|
||||
out << YAML::Flow;
|
||||
out << YAML::BeginSeq << v.x << v.y << v.z << YAML::EndSeq;
|
||||
return out;
|
||||
}
|
||||
|
||||
static YAML::Emitter& operator << (YAML::Emitter& out, const glm::vec4& v)
|
||||
{
|
||||
out << YAML::Flow;
|
||||
out << YAML::BeginSeq << v.x << v.y << v.z << v.w << YAML::EndSeq;
|
||||
return out;
|
||||
}
|
||||
static YAML::Emitter& operator<<(YAML::Emitter& out, const glm::vec4& v)
|
||||
{
|
||||
out << YAML::Flow;
|
||||
out << YAML::BeginSeq << v.x << v.y << v.z << v.w << YAML::EndSeq;
|
||||
return out;
|
||||
}
|
||||
|
||||
SceneSerializer::SceneSerializer(const Ref<Scene>& scene):
|
||||
m_Scene(scene)
|
||||
{
|
||||
}
|
||||
SceneSerializer::SceneSerializer(const Ref<Scene>& scene)
|
||||
: m_Scene(scene)
|
||||
{
|
||||
}
|
||||
|
||||
void SceneSerializer::Serialize(const std::string& filePath)
|
||||
{
|
||||
YAML::Emitter out;
|
||||
out << YAML::BeginMap; // Scene
|
||||
out << YAML::Key << "Scene" << YAML::Value << "Untitled";
|
||||
void SceneSerializer::Serialize(const std::string& filePath)
|
||||
{
|
||||
YAML::Emitter out;
|
||||
out << YAML::BeginMap; // Scene
|
||||
out << YAML::Key << "Scene" << YAML::Value << "Untitled";
|
||||
|
||||
out << YAML::Key << "Entities" << YAML::Value << YAML::BeginSeq;
|
||||
m_Scene->m_Registry.each([&](auto entityID)
|
||||
out << YAML::Key << "Entities" << YAML::Value << YAML::BeginSeq;
|
||||
m_Scene->m_Registry.each([&](auto entityID) {
|
||||
Entity entity = { entityID, m_Scene.get() };
|
||||
if (!entity.IsValid())
|
||||
return;
|
||||
|
||||
SerializeEntity(out, entity);
|
||||
});
|
||||
out << YAML::EndSeq;
|
||||
out << YAML::EndMap;
|
||||
|
||||
std::filesystem::create_directories(filePath.substr(0ull, filePath.find_last_of('\\')));
|
||||
|
||||
std::ofstream fout(filePath);
|
||||
if (!fout.is_open())
|
||||
LOG(trace, "Failed to create fout at: {}", filePath);
|
||||
fout << out.c_str();
|
||||
}
|
||||
|
||||
bool SceneSerializer::Deserialize(const std::string& filePath)
|
||||
{
|
||||
std::ifstream stream(filePath);
|
||||
std::stringstream ss;
|
||||
ss << stream.rdbuf();
|
||||
|
||||
YAML::Node data = YAML::Load(ss.str());
|
||||
if (!data["Scene"])
|
||||
return false;
|
||||
|
||||
std::string sceneName = data["Scene"].as<std::string>();
|
||||
LOG(trace, "Deserializing scene: '{}'", sceneName);
|
||||
|
||||
auto entities = data["Entities"];
|
||||
if (entities)
|
||||
{
|
||||
/* #TEMPORARY SOLUTION# */
|
||||
std::unordered_set<std::string> texturePaths;
|
||||
/* #TEMPORARY SOLUTION# */
|
||||
|
||||
|
||||
for (auto entity : entities)
|
||||
{
|
||||
Entity entity = { entityID, m_Scene.get() };
|
||||
if (!entity.IsValid())
|
||||
return;
|
||||
uint64_t uuid = entity["Entity"].as<uint64_t>(); // #todo
|
||||
|
||||
SerializeEntity(out, entity);
|
||||
});
|
||||
out << YAML::EndSeq;
|
||||
out << YAML::EndMap;
|
||||
std::string name;
|
||||
auto tagComponent = entity["TagComponent"];
|
||||
if (tagComponent)
|
||||
name = tagComponent["Tag"].as<std::string>();
|
||||
|
||||
std::filesystem::create_directories(filePath.substr(0ull, filePath.find_last_of('\\')));
|
||||
LOG(trace, "Deserialized entity '{}' : '{}'", uuid, name);
|
||||
|
||||
std::ofstream fout(filePath);
|
||||
if (!fout.is_open())
|
||||
LT_ENGINE_ERROR("SceneSerializer::Serialize: failed to create fout at: {}", filePath);
|
||||
fout << out.c_str();
|
||||
}
|
||||
Entity deserializedEntity = m_Scene->CreateEntityWithUUID(name, uuid);
|
||||
|
||||
bool SceneSerializer::Deserialize(const std::string& filePath)
|
||||
{
|
||||
std::ifstream stream(filePath);
|
||||
std::stringstream ss;
|
||||
ss << stream.rdbuf();
|
||||
|
||||
YAML::Node data = YAML::Load(ss.str());
|
||||
if (!data["Scene"])
|
||||
return false;
|
||||
|
||||
std::string sceneName = data["Scene"].as<std::string>();
|
||||
LT_ENGINE_TRACE("SceneSerializer::Deserialize: Deserializing scene: '{}'", sceneName);
|
||||
|
||||
auto entities = data["Entities"];
|
||||
if (entities)
|
||||
{
|
||||
/* #TEMPORARY SOLUTION# */
|
||||
std::unordered_set<std::string> texturePaths;
|
||||
/* #TEMPORARY SOLUTION# */
|
||||
|
||||
|
||||
for (auto entity : entities)
|
||||
TagComponent gg = deserializedEntity.GetComponent<TagComponent>();
|
||||
LOG(trace, gg.tag);
|
||||
auto transformComponent = entity["TransformComponent"];
|
||||
if (transformComponent)
|
||||
{
|
||||
uint64_t uuid = entity["Entity"].as<uint64_t>(); // #todo
|
||||
auto& entityTransforomComponent = deserializedEntity.GetComponent<TransformComponent>();
|
||||
|
||||
std::string name;
|
||||
auto tagComponent = entity["TagComponent"];
|
||||
if (tagComponent)
|
||||
name = tagComponent["Tag"].as<std::string>();
|
||||
|
||||
LT_ENGINE_TRACE("SceneSerializer::Deserialize: Deserialized entity '{}' : '{}'", uuid, name);
|
||||
|
||||
Entity deserializedEntity = m_Scene->CreateEntityWithUUID(name, uuid);
|
||||
|
||||
TagComponent gg = deserializedEntity.GetComponent<TagComponent>();
|
||||
LT_ENGINE_TRACE(gg.tag);
|
||||
auto transformComponent = entity["TransformComponent"];
|
||||
if (transformComponent)
|
||||
{
|
||||
auto& entityTransforomComponent = deserializedEntity.GetComponent<TransformComponent>();
|
||||
|
||||
entityTransforomComponent.translation = transformComponent["Translation"].as<glm::vec3>();
|
||||
entityTransforomComponent.rotation = transformComponent["Rotation"].as<glm::vec3>();
|
||||
entityTransforomComponent.scale = transformComponent["Scale"].as<glm::vec3>();
|
||||
}
|
||||
|
||||
/* #TEMPORARY SOLUTION# */
|
||||
auto spriteRendererComponent = entity["SpriteRendererComponent"];
|
||||
if (spriteRendererComponent)
|
||||
{
|
||||
auto& entitySpriteRendererComponent = deserializedEntity.AddComponent<SpriteRendererComponent>();
|
||||
entitySpriteRendererComponent.tint = spriteRendererComponent["Tint"].as<glm::vec4>();
|
||||
|
||||
std::string texturePath = spriteRendererComponent["Texture"].as<std::string>();
|
||||
|
||||
if (!texturePaths.contains(texturePath))
|
||||
{
|
||||
ResourceManager::LoadTexture(texturePath, texturePath);
|
||||
texturePaths.insert(texturePath);
|
||||
}
|
||||
|
||||
entitySpriteRendererComponent.texture = ResourceManager::GetTexture(texturePath);
|
||||
}
|
||||
/* #TEMPORARY SOLUTION# */
|
||||
|
||||
auto cameraComponent = entity["CameraComponent"];
|
||||
if(cameraComponent)
|
||||
{
|
||||
auto& entityCameraComponent = deserializedEntity.AddComponent<CameraComponent>();
|
||||
|
||||
const auto& cameraSpecifications = cameraComponent["Camera"];
|
||||
entityCameraComponent.camera.SetProjectionType((SceneCamera::ProjectionType)cameraSpecifications["ProjectionType"].as<int>());
|
||||
|
||||
entityCameraComponent.camera.SetOrthographicSize(cameraSpecifications["OrthographicSize"].as<float>());
|
||||
entityCameraComponent.camera.SetOrthographicNearPlane(cameraSpecifications["OrthographicNearPlane"].as<float>());
|
||||
entityCameraComponent.camera.SetOrthographicFarPlane(cameraSpecifications["OrthographicFarPlane"].as<float>());
|
||||
|
||||
entityCameraComponent.camera.SetPerspectiveVerticalFOV(cameraSpecifications["PerspectiveVerticalFOV"].as<float>());
|
||||
entityCameraComponent.camera.SetPerspectiveNearPlane(cameraSpecifications["PerspectiveNearPlane"].as<float>());
|
||||
entityCameraComponent.camera.SetPerspectiveFarPlane(cameraSpecifications["PerspectiveFarPlane"].as<float>());
|
||||
|
||||
entityCameraComponent.camera.SetBackgroundColor(cameraSpecifications["BackgroundColor"].as<glm::vec4>());
|
||||
|
||||
entityCameraComponent.isPrimary = cameraComponent["IsPrimary"].as<bool>();
|
||||
}
|
||||
entityTransforomComponent.translation = transformComponent["Translation"].as<glm::vec3>();
|
||||
entityTransforomComponent.rotation = transformComponent["Rotation"].as<glm::vec3>();
|
||||
entityTransforomComponent.scale = transformComponent["Scale"].as<glm::vec3>();
|
||||
}
|
||||
|
||||
return true;
|
||||
/* #TEMPORARY SOLUTION# */
|
||||
auto spriteRendererComponent = entity["SpriteRendererComponent"];
|
||||
if (spriteRendererComponent)
|
||||
{
|
||||
auto& entitySpriteRendererComponent = deserializedEntity.AddComponent<SpriteRendererComponent>();
|
||||
entitySpriteRendererComponent.tint = spriteRendererComponent["Tint"].as<glm::vec4>();
|
||||
|
||||
std::string texturePath = spriteRendererComponent["Texture"].as<std::string>();
|
||||
|
||||
if (!texturePaths.contains(texturePath))
|
||||
{
|
||||
ResourceManager::LoadTexture(texturePath, texturePath);
|
||||
texturePaths.insert(texturePath);
|
||||
}
|
||||
|
||||
entitySpriteRendererComponent.texture = ResourceManager::GetTexture(texturePath);
|
||||
}
|
||||
/* #TEMPORARY SOLUTION# */
|
||||
|
||||
auto cameraComponent = entity["CameraComponent"];
|
||||
if (cameraComponent)
|
||||
{
|
||||
auto& entityCameraComponent = deserializedEntity.AddComponent<CameraComponent>();
|
||||
|
||||
const auto& cameraSpecifications = cameraComponent["Camera"];
|
||||
entityCameraComponent.camera.SetProjectionType((SceneCamera::ProjectionType)cameraSpecifications["ProjectionType"].as<int>());
|
||||
|
||||
entityCameraComponent.camera.SetOrthographicSize(cameraSpecifications["OrthographicSize"].as<float>());
|
||||
entityCameraComponent.camera.SetOrthographicNearPlane(cameraSpecifications["OrthographicNearPlane"].as<float>());
|
||||
entityCameraComponent.camera.SetOrthographicFarPlane(cameraSpecifications["OrthographicFarPlane"].as<float>());
|
||||
|
||||
entityCameraComponent.camera.SetPerspectiveVerticalFOV(cameraSpecifications["PerspectiveVerticalFOV"].as<float>());
|
||||
entityCameraComponent.camera.SetPerspectiveNearPlane(cameraSpecifications["PerspectiveNearPlane"].as<float>());
|
||||
entityCameraComponent.camera.SetPerspectiveFarPlane(cameraSpecifications["PerspectiveFarPlane"].as<float>());
|
||||
|
||||
entityCameraComponent.camera.SetBackgroundColor(cameraSpecifications["BackgroundColor"].as<glm::vec4>());
|
||||
|
||||
entityCameraComponent.isPrimary = cameraComponent["IsPrimary"].as<bool>();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void SceneSerializer::SerializeBinary(const std::string& filePath)
|
||||
return false;
|
||||
}
|
||||
|
||||
void SceneSerializer::SerializeBinary(const std::string& filePath)
|
||||
{
|
||||
LOG(err, "NO_IMPLEMENT");
|
||||
}
|
||||
|
||||
bool SceneSerializer::DeserializeBinary(const std::string& filePath)
|
||||
{
|
||||
LOG(err, "NO_IMPLEMENT");
|
||||
return false;
|
||||
}
|
||||
|
||||
void SceneSerializer::SerializeEntity(YAML::Emitter& out, Entity entity)
|
||||
{
|
||||
out << YAML::BeginMap; // entity
|
||||
out << YAML::Key << "Entity" << YAML::Value << entity.GetUUID(); // dummy uuid
|
||||
|
||||
if (entity.HasComponent<TagComponent>())
|
||||
{
|
||||
LT_ENGINE_ERROR("SceneSerializer::SerializeRuntime: NO_IMPLEMENT");
|
||||
out << YAML::Key << "TagComponent";
|
||||
out << YAML::BeginMap; // tag component
|
||||
|
||||
auto& tagComponent = entity.GetComponent<TagComponent>().tag;
|
||||
out << YAML::Key << "Tag" << YAML::Value << tagComponent;
|
||||
|
||||
out << YAML::EndMap; // tag component
|
||||
}
|
||||
|
||||
bool SceneSerializer::DeserializeBinary(const std::string& filePath)
|
||||
if (entity.HasComponent<TransformComponent>())
|
||||
{
|
||||
LT_ENGINE_ERROR("SceneSerializer::DeserializeBinary: NO_IMPLEMENT");
|
||||
return false;
|
||||
out << YAML::Key << "TransformComponent";
|
||||
out << YAML::BeginMap; // transform component
|
||||
|
||||
auto& transformComponent = entity.GetComponent<TransformComponent>();
|
||||
|
||||
out << YAML::Key << "Translation" << YAML::Value << transformComponent.translation;
|
||||
out << YAML::Key << "Rotation" << YAML::Value << transformComponent.rotation;
|
||||
out << YAML::Key << "Scale" << YAML::Value << transformComponent.scale;
|
||||
|
||||
out << YAML::EndMap; // transform component;
|
||||
}
|
||||
|
||||
void SceneSerializer::SerializeEntity(YAML::Emitter& out, Entity entity)
|
||||
if (entity.HasComponent<SpriteRendererComponent>())
|
||||
{
|
||||
out << YAML::BeginMap; // entity
|
||||
out << YAML::Key << "Entity" << YAML::Value << entity.GetUUID(); // dummy uuid
|
||||
out << YAML::Key << "SpriteRendererComponent";
|
||||
out << YAML::BeginMap; // sprite renderer component;
|
||||
|
||||
if (entity.HasComponent<TagComponent>())
|
||||
{
|
||||
out << YAML::Key << "TagComponent";
|
||||
out << YAML::BeginMap; // tag component
|
||||
auto& spriteRendererComponent = entity.GetComponent<SpriteRendererComponent>();
|
||||
|
||||
auto& tagComponent = entity.GetComponent<TagComponent>().tag;
|
||||
out << YAML::Key << "Tag" << YAML::Value << tagComponent;
|
||||
out << YAML::Key << "Texture" << YAML::Value << spriteRendererComponent.texture->GetFilePath();
|
||||
out << YAML::Key << "Tint" << YAML::Value << spriteRendererComponent.tint;
|
||||
|
||||
out << YAML::EndMap; // tag component
|
||||
}
|
||||
|
||||
if (entity.HasComponent<TransformComponent>())
|
||||
{
|
||||
out << YAML::Key << "TransformComponent";
|
||||
out << YAML::BeginMap; // transform component
|
||||
|
||||
auto& transformComponent = entity.GetComponent<TransformComponent>();
|
||||
|
||||
out << YAML::Key << "Translation" << YAML::Value << transformComponent.translation;
|
||||
out << YAML::Key << "Rotation" << YAML::Value << transformComponent.rotation;
|
||||
out << YAML::Key << "Scale" << YAML::Value << transformComponent.scale;
|
||||
|
||||
out << YAML::EndMap; // transform component;
|
||||
}
|
||||
|
||||
if (entity.HasComponent<SpriteRendererComponent>())
|
||||
{
|
||||
out << YAML::Key << "SpriteRendererComponent";
|
||||
out << YAML::BeginMap; // sprite renderer component;
|
||||
|
||||
auto& spriteRendererComponent = entity.GetComponent<SpriteRendererComponent>();
|
||||
|
||||
out << YAML::Key << "Texture" << YAML::Value << spriteRendererComponent.texture->GetFilePath();
|
||||
out << YAML::Key << "Tint" << YAML::Value << spriteRendererComponent.tint;
|
||||
|
||||
out << YAML::EndMap; // sprite renderer component
|
||||
}
|
||||
|
||||
// #todo:
|
||||
// if(entity.HasComponent<NativeScriptComponent>())
|
||||
|
||||
if (entity.HasComponent<CameraComponent>())
|
||||
{
|
||||
out << YAML::Key << "CameraComponent";
|
||||
out << YAML::BeginMap; // camera component
|
||||
|
||||
auto& cameraComponent = entity.GetComponent<CameraComponent>();
|
||||
|
||||
out << YAML::Key << "Camera" << YAML::Value;
|
||||
out << YAML::BeginMap; // camera
|
||||
out << YAML::Key << "OrthographicSize" << YAML::Value << cameraComponent.camera.GetOrthographicSize();
|
||||
out << YAML::Key << "OrthographicFarPlane" << YAML::Value << cameraComponent.camera.GetOrthographicFarPlane();
|
||||
out << YAML::Key << "OrthographicNearPlane" << YAML::Value << cameraComponent.camera.GetOrthographicNearPlane();
|
||||
out << YAML::Key << "PerspectiveVerticalFOV" << YAML::Value << cameraComponent.camera.GetPerspectiveVerticalFOV();
|
||||
out << YAML::Key << "PerspectiveFarPlane" << YAML::Value << cameraComponent.camera.GetPerspectiveFarPlane();
|
||||
out << YAML::Key << "PerspectiveNearPlane" << YAML::Value << cameraComponent.camera.GetPerspectiveNearPlane();
|
||||
out << YAML::Key << "ProjectionType" << YAML::Value << (int)cameraComponent.camera.GetProjectionType();
|
||||
out << YAML::Key << "BackgroundColor" << YAML::Value << cameraComponent.camera.GetBackgroundColor();
|
||||
out << YAML::EndMap; // camera
|
||||
|
||||
out << YAML::Key << "IsPrimary" << YAML::Value << cameraComponent.isPrimary;
|
||||
|
||||
out << YAML::EndMap; // camera component
|
||||
}
|
||||
out << YAML::EndMap; // entity
|
||||
out << YAML::EndMap; // sprite renderer component
|
||||
}
|
||||
|
||||
}
|
||||
// #todo:
|
||||
// if(entity.HasComponent<NativeScriptComponent>())
|
||||
|
||||
if (entity.HasComponent<CameraComponent>())
|
||||
{
|
||||
out << YAML::Key << "CameraComponent";
|
||||
out << YAML::BeginMap; // camera component
|
||||
|
||||
auto& cameraComponent = entity.GetComponent<CameraComponent>();
|
||||
|
||||
out << YAML::Key << "Camera" << YAML::Value;
|
||||
out << YAML::BeginMap; // camera
|
||||
out << YAML::Key << "OrthographicSize" << YAML::Value << cameraComponent.camera.GetOrthographicSize();
|
||||
out << YAML::Key << "OrthographicFarPlane" << YAML::Value << cameraComponent.camera.GetOrthographicFarPlane();
|
||||
out << YAML::Key << "OrthographicNearPlane" << YAML::Value << cameraComponent.camera.GetOrthographicNearPlane();
|
||||
out << YAML::Key << "PerspectiveVerticalFOV" << YAML::Value << cameraComponent.camera.GetPerspectiveVerticalFOV();
|
||||
out << YAML::Key << "PerspectiveFarPlane" << YAML::Value << cameraComponent.camera.GetPerspectiveFarPlane();
|
||||
out << YAML::Key << "PerspectiveNearPlane" << YAML::Value << cameraComponent.camera.GetPerspectiveNearPlane();
|
||||
out << YAML::Key << "ProjectionType" << YAML::Value << (int)cameraComponent.camera.GetProjectionType();
|
||||
out << YAML::Key << "BackgroundColor" << YAML::Value << cameraComponent.camera.GetBackgroundColor();
|
||||
out << YAML::EndMap; // camera
|
||||
|
||||
out << YAML::Key << "IsPrimary" << YAML::Value << cameraComponent.isPrimary;
|
||||
|
||||
out << YAML::EndMap; // camera component
|
||||
}
|
||||
out << YAML::EndMap; // entity
|
||||
}
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,170 +1,164 @@
|
|||
#include "dxBuffers.h"
|
||||
|
||||
#include "dxSharedContext.h"
|
||||
|
||||
namespace Light {
|
||||
|
||||
//======================================== CONSTANT_BUFFER ========================================//
|
||||
dxConstantBuffer::dxConstantBuffer(ConstantBufferIndex index, unsigned int size, Ref<dxSharedContext> sharedContext)
|
||||
: m_Context(sharedContext),
|
||||
m_Buffer(nullptr),
|
||||
m_Map{},
|
||||
m_Index(static_cast<int>(index))
|
||||
//======================================== CONSTANT_BUFFER ========================================//
|
||||
dxConstantBuffer::dxConstantBuffer(ConstantBufferIndex index, unsigned int size, Ref<dxSharedContext> sharedContext)
|
||||
: m_Context(sharedContext), m_Buffer(nullptr), m_Map {}, m_Index(static_cast<int>(index))
|
||||
{
|
||||
D3D11_BUFFER_DESC bDesc = {};
|
||||
|
||||
bDesc.ByteWidth = size;
|
||||
bDesc.Usage = D3D11_USAGE_DYNAMIC;
|
||||
bDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
|
||||
bDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
|
||||
HRESULT hr;
|
||||
DXC(m_Context->GetDevice()->CreateBuffer(&bDesc, nullptr, &m_Buffer));
|
||||
m_Context->GetDeviceContext()->VSSetConstantBuffers(m_Index, 1u, m_Buffer.GetAddressOf());
|
||||
}
|
||||
|
||||
void dxConstantBuffer::Bind()
|
||||
{
|
||||
m_Context->GetDeviceContext()->VSSetConstantBuffers(m_Index, 1u, m_Buffer.GetAddressOf());
|
||||
}
|
||||
|
||||
void* dxConstantBuffer::Map()
|
||||
{
|
||||
m_Context->GetDeviceContext()->VSSetConstantBuffers(m_Index, 1u, m_Buffer.GetAddressOf());
|
||||
m_Context->GetDeviceContext()->Map(m_Buffer.Get(), NULL, D3D11_MAP_WRITE_DISCARD, NULL, &m_Map);
|
||||
return m_Map.pData;
|
||||
}
|
||||
|
||||
void dxConstantBuffer::UnMap()
|
||||
{
|
||||
m_Context->GetDeviceContext()->Unmap(m_Buffer.Get(), NULL);
|
||||
}
|
||||
//======================================== CONSTANT_BUFFER ========================================//
|
||||
|
||||
//================================================== VERTEX_BUFFER ==================================================//
|
||||
dxVertexBuffer::dxVertexBuffer(float* vertices, unsigned int stride, unsigned int count, Ref<dxSharedContext> sharedContext)
|
||||
: m_Context(sharedContext), m_Buffer(nullptr), m_Map {}, m_Stride(stride)
|
||||
{
|
||||
// buffer desc
|
||||
D3D11_BUFFER_DESC bDesc = {};
|
||||
|
||||
bDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||
bDesc.Usage = D3D11_USAGE_DYNAMIC;
|
||||
bDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
|
||||
bDesc.ByteWidth = count * stride;
|
||||
bDesc.StructureByteStride = stride;
|
||||
|
||||
// create buffer
|
||||
HRESULT hr;
|
||||
DXC(m_Context->GetDevice()->CreateBuffer(&bDesc, nullptr, &m_Buffer));
|
||||
}
|
||||
|
||||
dxVertexBuffer::~dxVertexBuffer()
|
||||
{
|
||||
UnBind();
|
||||
}
|
||||
|
||||
void* dxVertexBuffer::Map()
|
||||
{
|
||||
m_Context->GetDeviceContext()->Map(m_Buffer.Get(), NULL, D3D11_MAP_WRITE_DISCARD, NULL, &m_Map);
|
||||
return m_Map.pData;
|
||||
}
|
||||
|
||||
void dxVertexBuffer::UnMap()
|
||||
{
|
||||
m_Context->GetDeviceContext()->Unmap(m_Buffer.Get(), NULL);
|
||||
}
|
||||
|
||||
void dxVertexBuffer::Bind()
|
||||
{
|
||||
static const unsigned int offset = 0u;
|
||||
m_Context->GetDeviceContext()->IASetVertexBuffers(0u, 1u, m_Buffer.GetAddressOf(), &m_Stride, &offset);
|
||||
}
|
||||
|
||||
void dxVertexBuffer::UnBind()
|
||||
{
|
||||
static const unsigned int offset = 0u;
|
||||
static ID3D11Buffer* buffer = nullptr;
|
||||
|
||||
m_Context->GetDeviceContext()->IASetVertexBuffers(0u, 1u, &buffer, &m_Stride, &offset);
|
||||
}
|
||||
//================================================== VERTEX_BUFFER ==================================================//
|
||||
|
||||
//======================================== INDEX_BUFFER ========================================//
|
||||
dxIndexBuffer::dxIndexBuffer(unsigned int* indices, unsigned int count, Ref<dxSharedContext> sharedContext)
|
||||
: m_Context(sharedContext), m_Buffer(nullptr)
|
||||
{
|
||||
// generate indices if not provided
|
||||
bool hasIndices = !!indices;
|
||||
if (!hasIndices)
|
||||
{
|
||||
D3D11_BUFFER_DESC bDesc = {};
|
||||
|
||||
bDesc.ByteWidth = size;
|
||||
bDesc.Usage = D3D11_USAGE_DYNAMIC;
|
||||
bDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
|
||||
bDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
|
||||
HRESULT hr;
|
||||
DXC(m_Context->GetDevice()->CreateBuffer(&bDesc, nullptr, &m_Buffer));
|
||||
m_Context->GetDeviceContext()->VSSetConstantBuffers(m_Index, 1u, m_Buffer.GetAddressOf());
|
||||
}
|
||||
|
||||
void dxConstantBuffer::Bind()
|
||||
{
|
||||
m_Context->GetDeviceContext()->VSSetConstantBuffers(m_Index, 1u, m_Buffer.GetAddressOf());
|
||||
}
|
||||
|
||||
void* dxConstantBuffer::Map()
|
||||
{
|
||||
m_Context->GetDeviceContext()->VSSetConstantBuffers(m_Index, 1u, m_Buffer.GetAddressOf());
|
||||
m_Context->GetDeviceContext()->Map(m_Buffer.Get(), NULL, D3D11_MAP_WRITE_DISCARD, NULL, &m_Map);
|
||||
return m_Map.pData;
|
||||
}
|
||||
|
||||
void dxConstantBuffer::UnMap()
|
||||
{
|
||||
m_Context->GetDeviceContext()->Unmap(m_Buffer.Get(), NULL);
|
||||
}
|
||||
//======================================== CONSTANT_BUFFER ========================================//
|
||||
|
||||
//================================================== VERTEX_BUFFER ==================================================//
|
||||
dxVertexBuffer::dxVertexBuffer(float* vertices, unsigned int stride, unsigned int count, Ref<dxSharedContext> sharedContext)
|
||||
: m_Context(sharedContext),
|
||||
m_Buffer(nullptr),
|
||||
m_Map{},
|
||||
m_Stride(stride)
|
||||
{
|
||||
// buffer desc
|
||||
D3D11_BUFFER_DESC bDesc = {};
|
||||
|
||||
bDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||
bDesc.Usage = D3D11_USAGE_DYNAMIC;
|
||||
bDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
|
||||
bDesc.ByteWidth = count * stride;
|
||||
bDesc.StructureByteStride = stride;
|
||||
|
||||
// create buffer
|
||||
HRESULT hr;
|
||||
DXC(m_Context->GetDevice()->CreateBuffer(&bDesc, nullptr, &m_Buffer));
|
||||
}
|
||||
|
||||
dxVertexBuffer::~dxVertexBuffer()
|
||||
{
|
||||
UnBind();
|
||||
}
|
||||
|
||||
void* dxVertexBuffer::Map()
|
||||
{
|
||||
m_Context->GetDeviceContext()->Map(m_Buffer.Get(), NULL, D3D11_MAP_WRITE_DISCARD, NULL, &m_Map);
|
||||
return m_Map.pData;
|
||||
}
|
||||
|
||||
void dxVertexBuffer::UnMap()
|
||||
{
|
||||
m_Context->GetDeviceContext()->Unmap(m_Buffer.Get(), NULL);
|
||||
}
|
||||
|
||||
void dxVertexBuffer::Bind()
|
||||
{
|
||||
static const unsigned int offset = 0u;
|
||||
m_Context->GetDeviceContext()->IASetVertexBuffers(0u, 1u, m_Buffer.GetAddressOf(), &m_Stride, &offset);
|
||||
}
|
||||
|
||||
void dxVertexBuffer::UnBind()
|
||||
{
|
||||
static const unsigned int offset = 0u;
|
||||
static ID3D11Buffer* buffer = nullptr;
|
||||
|
||||
m_Context->GetDeviceContext()->IASetVertexBuffers(0u, 1u, &buffer, &m_Stride, &offset);
|
||||
}
|
||||
//================================================== VERTEX_BUFFER ==================================================//
|
||||
|
||||
//======================================== INDEX_BUFFER ========================================//
|
||||
dxIndexBuffer::dxIndexBuffer(unsigned int* indices, unsigned int count, Ref<dxSharedContext> sharedContext)
|
||||
: m_Context(sharedContext),
|
||||
m_Buffer(nullptr)
|
||||
{
|
||||
// generate indices if not provided
|
||||
bool hasIndices = !!indices;
|
||||
if (!hasIndices)
|
||||
// check
|
||||
if (count % 6 != 0)
|
||||
{
|
||||
// check
|
||||
if (count % 6 != 0)
|
||||
{
|
||||
LT_ENGINE_WARN("dxIndexBuffer::dxIndexBuffer: 'indices' can only be null if count is multiple of 6");
|
||||
LT_ENGINE_WARN("dxIndexBuffer::dxIndexBuffer: adding {} to 'count' -> {}", (6 - (count % 6)), count + (6 - (count % 6)));
|
||||
count = count + (6 - (count % 6));
|
||||
}
|
||||
|
||||
// create indices
|
||||
indices = new unsigned int[count];
|
||||
unsigned int offset = 0;
|
||||
for (unsigned int i = 0; i < count; i += 6)
|
||||
{
|
||||
indices[i + 0] = offset + 0u;
|
||||
indices[i + 1] = offset + 3u;
|
||||
indices[i + 2] = offset + 2u;
|
||||
|
||||
indices[i + 3] = offset + 2u;
|
||||
indices[i + 4] = offset + 1u;
|
||||
indices[i + 5] = offset + 0u;
|
||||
|
||||
offset += 4u;
|
||||
}
|
||||
LOG(warn, "'indices' can only be null if count is multiple of 6");
|
||||
LOG(warn, "Adding {} to 'count' -> {}", (6 - (count % 6)), count + (6 - (count % 6)));
|
||||
count = count + (6 - (count % 6));
|
||||
}
|
||||
|
||||
// buffer desc
|
||||
D3D11_BUFFER_DESC bDesc = {};
|
||||
bDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
||||
bDesc.Usage = D3D11_USAGE_DEFAULT;
|
||||
// create indices
|
||||
indices = new unsigned int[count];
|
||||
unsigned int offset = 0;
|
||||
for (unsigned int i = 0; i < count; i += 6)
|
||||
{
|
||||
indices[i + 0] = offset + 0u;
|
||||
indices[i + 1] = offset + 3u;
|
||||
indices[i + 2] = offset + 2u;
|
||||
|
||||
bDesc.ByteWidth = count * sizeof(unsigned int);
|
||||
bDesc.StructureByteStride = sizeof(unsigned int);
|
||||
indices[i + 3] = offset + 2u;
|
||||
indices[i + 4] = offset + 1u;
|
||||
indices[i + 5] = offset + 0u;
|
||||
|
||||
// subresource data
|
||||
D3D11_SUBRESOURCE_DATA sDesc = {};
|
||||
sDesc.pSysMem = indices;
|
||||
|
||||
// create buffer
|
||||
HRESULT hr;
|
||||
DXC(m_Context->GetDevice()->CreateBuffer(&bDesc, &sDesc, &m_Buffer));
|
||||
|
||||
// delete indices
|
||||
if (!hasIndices)
|
||||
delete[] indices;
|
||||
offset += 4u;
|
||||
}
|
||||
}
|
||||
|
||||
dxIndexBuffer::~dxIndexBuffer()
|
||||
{
|
||||
UnBind();
|
||||
}
|
||||
// buffer desc
|
||||
D3D11_BUFFER_DESC bDesc = {};
|
||||
bDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
||||
bDesc.Usage = D3D11_USAGE_DEFAULT;
|
||||
|
||||
void dxIndexBuffer::Bind()
|
||||
{
|
||||
m_Context->GetDeviceContext()->IASetIndexBuffer(m_Buffer.Get(), DXGI_FORMAT_R32_UINT, 0u);
|
||||
}
|
||||
bDesc.ByteWidth = count * sizeof(unsigned int);
|
||||
bDesc.StructureByteStride = sizeof(unsigned int);
|
||||
|
||||
void dxIndexBuffer::UnBind()
|
||||
{
|
||||
static const unsigned int offset = 0u;
|
||||
static ID3D11Buffer* buffer = nullptr;
|
||||
// subresource data
|
||||
D3D11_SUBRESOURCE_DATA sDesc = {};
|
||||
sDesc.pSysMem = indices;
|
||||
|
||||
m_Context->GetDeviceContext()->IASetIndexBuffer(buffer, DXGI_FORMAT_R32_UINT, offset);
|
||||
}
|
||||
//======================================== INDEX_BUFFER ========================================//
|
||||
// create buffer
|
||||
HRESULT hr;
|
||||
DXC(m_Context->GetDevice()->CreateBuffer(&bDesc, &sDesc, &m_Buffer));
|
||||
|
||||
}
|
||||
// delete indices
|
||||
if (!hasIndices)
|
||||
delete[] indices;
|
||||
}
|
||||
|
||||
dxIndexBuffer::~dxIndexBuffer()
|
||||
{
|
||||
UnBind();
|
||||
}
|
||||
|
||||
void dxIndexBuffer::Bind()
|
||||
{
|
||||
m_Context->GetDeviceContext()->IASetIndexBuffer(m_Buffer.Get(), DXGI_FORMAT_R32_UINT, 0u);
|
||||
}
|
||||
|
||||
void dxIndexBuffer::UnBind()
|
||||
{
|
||||
static const unsigned int offset = 0u;
|
||||
static ID3D11Buffer* buffer = nullptr;
|
||||
|
||||
m_Context->GetDeviceContext()->IASetIndexBuffer(buffer, DXGI_FORMAT_R32_UINT, offset);
|
||||
}
|
||||
//======================================== INDEX_BUFFER ========================================//
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,99 +1,94 @@
|
|||
#include "dxFramebuffer.h"
|
||||
|
||||
#include "dxSharedContext.h"
|
||||
|
||||
namespace Light {
|
||||
|
||||
dxFramebuffer::dxFramebuffer(const FramebufferSpecification& specification, Ref<dxSharedContext> sharedContext)
|
||||
: m_Context(sharedContext),
|
||||
m_Specification(specification),
|
||||
m_RenderTargetView(nullptr),
|
||||
m_ColorAttachment(nullptr),
|
||||
m_DepthStencilAttachment(nullptr),
|
||||
m_ShaderResourceView(nullptr),
|
||||
m_DepthStencilView(nullptr)
|
||||
{
|
||||
HRESULT hr;
|
||||
dxFramebuffer::dxFramebuffer(const FramebufferSpecification& specification, Ref<dxSharedContext> sharedContext)
|
||||
: m_Context(sharedContext), m_Specification(specification), m_RenderTargetView(nullptr), m_ColorAttachment(nullptr), m_DepthStencilAttachment(nullptr), m_ShaderResourceView(nullptr), m_DepthStencilView(nullptr)
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
D3D11_TEXTURE2D_DESC t2dDesc = {};
|
||||
t2dDesc.Width = specification.width;
|
||||
t2dDesc.Height = specification.height;
|
||||
t2dDesc.MipLevels = 1;
|
||||
t2dDesc.ArraySize = 1;
|
||||
t2dDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
t2dDesc.SampleDesc.Count = 1u;
|
||||
t2dDesc.SampleDesc.Quality = 0u;
|
||||
t2dDesc.Usage = D3D11_USAGE_DEFAULT;
|
||||
t2dDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
|
||||
t2dDesc.CPUAccessFlags = NULL;
|
||||
t2dDesc.MiscFlags = NULL;
|
||||
DXC(m_Context->GetDevice()->CreateTexture2D(&t2dDesc, nullptr, &m_ColorAttachment));
|
||||
D3D11_TEXTURE2D_DESC t2dDesc = {};
|
||||
t2dDesc.Width = specification.width;
|
||||
t2dDesc.Height = specification.height;
|
||||
t2dDesc.MipLevels = 1;
|
||||
t2dDesc.ArraySize = 1;
|
||||
t2dDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
t2dDesc.SampleDesc.Count = 1u;
|
||||
t2dDesc.SampleDesc.Quality = 0u;
|
||||
t2dDesc.Usage = D3D11_USAGE_DEFAULT;
|
||||
t2dDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
|
||||
t2dDesc.CPUAccessFlags = NULL;
|
||||
t2dDesc.MiscFlags = NULL;
|
||||
DXC(m_Context->GetDevice()->CreateTexture2D(&t2dDesc, nullptr, &m_ColorAttachment));
|
||||
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
|
||||
srvDesc.Format = t2dDesc.Format;
|
||||
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
||||
srvDesc.Texture2D.MipLevels = 1;
|
||||
srvDesc.Texture2D.MostDetailedMip = 0;
|
||||
DXC(m_Context->GetDevice()->CreateShaderResourceView(m_ColorAttachment.Get(), &srvDesc, &m_ShaderResourceView));
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
|
||||
srvDesc.Format = t2dDesc.Format;
|
||||
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
||||
srvDesc.Texture2D.MipLevels = 1;
|
||||
srvDesc.Texture2D.MostDetailedMip = 0;
|
||||
DXC(m_Context->GetDevice()->CreateShaderResourceView(m_ColorAttachment.Get(), &srvDesc, &m_ShaderResourceView));
|
||||
|
||||
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc = {};
|
||||
rtvDesc.Format = t2dDesc.Format;
|
||||
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
|
||||
rtvDesc.Texture2D.MipSlice = 0u;
|
||||
DXC(m_Context->GetDevice()->CreateRenderTargetView(m_ColorAttachment.Get(), &rtvDesc, &m_RenderTargetView));
|
||||
}
|
||||
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc = {};
|
||||
rtvDesc.Format = t2dDesc.Format;
|
||||
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
|
||||
rtvDesc.Texture2D.MipSlice = 0u;
|
||||
DXC(m_Context->GetDevice()->CreateRenderTargetView(m_ColorAttachment.Get(), &rtvDesc, &m_RenderTargetView));
|
||||
}
|
||||
|
||||
void dxFramebuffer::BindAsTarget(const glm::vec4& clearColor)
|
||||
{
|
||||
FLOAT color[] = {
|
||||
clearColor.r,
|
||||
clearColor.g,
|
||||
clearColor.b,
|
||||
clearColor.a,
|
||||
};
|
||||
void dxFramebuffer::BindAsTarget(const glm::vec4& clearColor)
|
||||
{
|
||||
FLOAT color[] = {
|
||||
clearColor.r,
|
||||
clearColor.g,
|
||||
clearColor.b,
|
||||
clearColor.a,
|
||||
};
|
||||
|
||||
m_Context->GetDeviceContext()->OMSetRenderTargets(1u, m_RenderTargetView.GetAddressOf(), nullptr);
|
||||
m_Context->GetDeviceContext()->ClearRenderTargetView(m_RenderTargetView.Get(), color);
|
||||
m_Context->GetDeviceContext()->OMSetRenderTargets(1u, m_RenderTargetView.GetAddressOf(), nullptr);
|
||||
m_Context->GetDeviceContext()->ClearRenderTargetView(m_RenderTargetView.Get(), color);
|
||||
|
||||
D3D11_VIEWPORT viewport;
|
||||
D3D11_VIEWPORT viewport;
|
||||
|
||||
viewport.TopLeftX = 0;
|
||||
viewport.TopLeftY = 0;
|
||||
viewport.TopLeftX = 0;
|
||||
viewport.TopLeftY = 0;
|
||||
|
||||
viewport.Width = m_Specification.width;
|
||||
viewport.Height = m_Specification.height;
|
||||
viewport.Width = m_Specification.width;
|
||||
viewport.Height = m_Specification.height;
|
||||
|
||||
viewport.MinDepth = 0.0f;
|
||||
viewport.MaxDepth = 1.0f;
|
||||
viewport.MinDepth = 0.0f;
|
||||
viewport.MaxDepth = 1.0f;
|
||||
|
||||
// set viewport
|
||||
m_Context->GetDeviceContext()->RSSetViewports(1u, &viewport);
|
||||
}
|
||||
// set viewport
|
||||
m_Context->GetDeviceContext()->RSSetViewports(1u, &viewport);
|
||||
}
|
||||
|
||||
void dxFramebuffer::BindAsResource()
|
||||
{
|
||||
LT_ENGINE_ERROR("dxFramebuffer::BindAsResource: NO_IMPLEMENT");
|
||||
}
|
||||
void dxFramebuffer::BindAsResource()
|
||||
{
|
||||
LOG(err, "NO_IMPLEMENT");
|
||||
}
|
||||
|
||||
void dxFramebuffer::Resize(const glm::uvec2& size)
|
||||
{
|
||||
m_Specification.width = std::clamp(size.x, 1u, 16384u);
|
||||
m_Specification.height= std::clamp(size.y, 1u, 16384u);
|
||||
void dxFramebuffer::Resize(const glm::uvec2& size)
|
||||
{
|
||||
m_Specification.width = std::clamp(size.x, 1u, 16384u);
|
||||
m_Specification.height = std::clamp(size.y, 1u, 16384u);
|
||||
|
||||
D3D11_TEXTURE2D_DESC textureDesc;
|
||||
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
|
||||
D3D11_TEXTURE2D_DESC textureDesc;
|
||||
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
|
||||
|
||||
m_ColorAttachment->GetDesc(&textureDesc);
|
||||
m_RenderTargetView->GetDesc(&rtvDesc);
|
||||
m_ShaderResourceView->GetDesc(&srvDesc);
|
||||
m_ColorAttachment->GetDesc(&textureDesc);
|
||||
m_RenderTargetView->GetDesc(&rtvDesc);
|
||||
m_ShaderResourceView->GetDesc(&srvDesc);
|
||||
|
||||
textureDesc.Width = m_Specification.width;
|
||||
textureDesc.Height = m_Specification.height;
|
||||
textureDesc.Width = m_Specification.width;
|
||||
textureDesc.Height = m_Specification.height;
|
||||
|
||||
HRESULT hr;
|
||||
DXC(m_Context->GetDevice()->CreateTexture2D(&textureDesc, nullptr, &m_ColorAttachment));
|
||||
DXC(m_Context->GetDevice()->CreateRenderTargetView(m_ColorAttachment.Get(), &rtvDesc, &m_RenderTargetView));
|
||||
DXC(m_Context->GetDevice()->CreateShaderResourceView(m_ColorAttachment.Get(), &srvDesc, &m_ShaderResourceView));
|
||||
}
|
||||
HRESULT hr;
|
||||
DXC(m_Context->GetDevice()->CreateTexture2D(&textureDesc, nullptr, &m_ColorAttachment));
|
||||
DXC(m_Context->GetDevice()->CreateRenderTargetView(m_ColorAttachment.Get(), &rtvDesc, &m_RenderTargetView));
|
||||
DXC(m_Context->GetDevice()->CreateShaderResourceView(m_ColorAttachment.Get(), &srvDesc, &m_ShaderResourceView));
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
#include "dxGraphicsContext.h"
|
||||
#include "dxSharedContext.h"
|
||||
|
||||
#include "Events/WindowEvents.h"
|
||||
|
||||
#include "Graphics/Blender.h" // required for forward declaration
|
||||
#include "Graphics/Buffers.h" // required for forward declaration
|
||||
#include "Graphics/Renderer.h" // required for forward declaration
|
||||
#include "Graphics/RenderCommand.h" // required for forward declaration
|
||||
|
||||
#include "Graphics/Blender.h" // required for forward declaration
|
||||
#include "Graphics/Buffers.h" // required for forward declaration
|
||||
#include "Graphics/RenderCommand.h" // required for forward declaration
|
||||
#include "Graphics/Renderer.h" // required for forward declaration
|
||||
#include "UserInterface/UserInterface.h" // required for forward declaration
|
||||
|
||||
#include "Utility/ResourceManager.h" // required for forward declaration
|
||||
#include "Utility/ResourceManager.h" // required for forward declaration
|
||||
#include "dxSharedContext.h"
|
||||
|
||||
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||
#include <glfw/glfw3.h>
|
||||
|
@ -18,149 +15,146 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
dxGraphicsContext::dxGraphicsContext(GLFWwindow* windowHandle)
|
||||
: m_WindowHandle(windowHandle),
|
||||
m_DebugInterface(nullptr)
|
||||
{
|
||||
// set 'GraphicsAPI';
|
||||
m_GraphicsAPI = GraphicsAPI::DirectX;
|
||||
|
||||
m_SharedContext = std::make_shared<dxSharedContext>();
|
||||
dxGraphicsContext::dxGraphicsContext(GLFWwindow* windowHandle)
|
||||
: m_WindowHandle(windowHandle), m_DebugInterface(nullptr)
|
||||
{
|
||||
// set 'GraphicsAPI';
|
||||
m_GraphicsAPI = GraphicsAPI::DirectX;
|
||||
|
||||
// setup stuff
|
||||
SetupDeviceAndSwapChain(windowHandle);
|
||||
SetupRenderTargets();
|
||||
SetupDebugInterface();
|
||||
}
|
||||
m_SharedContext = std::make_shared<dxSharedContext>();
|
||||
|
||||
void dxGraphicsContext::SetupDeviceAndSwapChain(GLFWwindow* windowHandle)
|
||||
{
|
||||
Ref<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_SharedContext);
|
||||
// setup stuff
|
||||
SetupDeviceAndSwapChain(windowHandle);
|
||||
SetupRenderTargets();
|
||||
SetupDebugInterface();
|
||||
}
|
||||
|
||||
// swap chain desc
|
||||
DXGI_SWAP_CHAIN_DESC sd = { 0 };
|
||||
void dxGraphicsContext::SetupDeviceAndSwapChain(GLFWwindow* windowHandle)
|
||||
{
|
||||
Ref<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_SharedContext);
|
||||
|
||||
// buffer desc
|
||||
sd.BufferDesc.Width = 1u;
|
||||
sd.BufferDesc.Height = 1u;
|
||||
sd.BufferDesc.RefreshRate.Numerator = NULL; // :#todo
|
||||
sd.BufferDesc.RefreshRate.Denominator = NULL; // :#todo
|
||||
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
|
||||
sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
|
||||
// swap chain desc
|
||||
DXGI_SWAP_CHAIN_DESC sd = { 0 };
|
||||
|
||||
// sample desc (for multi sampling) #todo: implement multi-samplingz
|
||||
sd.SampleDesc.Count = 1u;
|
||||
sd.SampleDesc.Quality = 0u;
|
||||
// buffer desc
|
||||
sd.BufferDesc.Width = 1u;
|
||||
sd.BufferDesc.Height = 1u;
|
||||
sd.BufferDesc.RefreshRate.Numerator = NULL; // :#todo
|
||||
sd.BufferDesc.RefreshRate.Denominator = NULL; // :#todo
|
||||
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
|
||||
sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
|
||||
|
||||
// #todo: support swap chains with more than 1 back-buffer
|
||||
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
sd.BufferCount = 1u;
|
||||
// sample desc (for multi sampling) #todo: implement multi-samplingz
|
||||
sd.SampleDesc.Count = 1u;
|
||||
sd.SampleDesc.Quality = 0u;
|
||||
|
||||
// #todo: don't handle Windows's window with glfw, create it yourself
|
||||
sd.OutputWindow = static_cast<HWND>(glfwGetWin32Window(windowHandle));
|
||||
sd.Windowed = true;
|
||||
// #todo: support swap chains with more than 1 back-buffer
|
||||
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
sd.BufferCount = 1u;
|
||||
|
||||
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
|
||||
// #todo: don't handle Windows's window with glfw, create it yourself
|
||||
sd.OutputWindow = static_cast<HWND>(glfwGetWin32Window(windowHandle));
|
||||
sd.Windowed = true;
|
||||
|
||||
sd.Flags = NULL;
|
||||
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
|
||||
|
||||
// determine device flags
|
||||
UINT flags = NULL;
|
||||
sd.Flags = NULL;
|
||||
|
||||
// determine device flags
|
||||
UINT flags = NULL;
|
||||
#ifdef LIGHT_DEBUG
|
||||
flags = D3D11_CREATE_DEVICE_DEBUG;
|
||||
flags = D3D11_CREATE_DEVICE_DEBUG;
|
||||
#endif
|
||||
|
||||
// create device and swap chain
|
||||
DXC(D3D11CreateDeviceAndSwapChain(nullptr,
|
||||
D3D_DRIVER_TYPE_HARDWARE,
|
||||
NULL,
|
||||
flags,
|
||||
nullptr,
|
||||
NULL,
|
||||
D3D11_SDK_VERSION,
|
||||
&sd,
|
||||
&context->GetSwapChainRef(),
|
||||
&context->GetDeviceRef(),
|
||||
nullptr,
|
||||
&context->GetDeviceContextRef()));
|
||||
// create device and swap chain
|
||||
DXC(D3D11CreateDeviceAndSwapChain(nullptr,
|
||||
D3D_DRIVER_TYPE_HARDWARE,
|
||||
NULL,
|
||||
flags,
|
||||
nullptr,
|
||||
NULL,
|
||||
D3D11_SDK_VERSION,
|
||||
&sd,
|
||||
&context->GetSwapChainRef(),
|
||||
&context->GetDeviceRef(),
|
||||
nullptr,
|
||||
&context->GetDeviceContextRef()));
|
||||
}
|
||||
|
||||
}
|
||||
void dxGraphicsContext::SetupRenderTargets()
|
||||
{
|
||||
Ref<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_SharedContext);
|
||||
|
||||
void dxGraphicsContext::SetupRenderTargets()
|
||||
{
|
||||
Ref<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_SharedContext);
|
||||
// set primitive topology
|
||||
context->GetDeviceContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
|
||||
// set primitive topology
|
||||
context->GetDeviceContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
// create render target view
|
||||
Microsoft::WRL::ComPtr<ID3D11Resource> backBuffer;
|
||||
|
||||
// create render target view
|
||||
Microsoft::WRL::ComPtr<ID3D11Resource> backBuffer;
|
||||
DXC(context->GetSwapChain()->GetBuffer(0u, __uuidof(ID3D11Resource), &backBuffer));
|
||||
DXC(context->GetDevice()->CreateRenderTargetView(backBuffer.Get(), nullptr, &context->GetRenderTargetViewRef()));
|
||||
|
||||
DXC(context->GetSwapChain()->GetBuffer(0u, __uuidof(ID3D11Resource), &backBuffer));
|
||||
DXC(context->GetDevice()->CreateRenderTargetView(backBuffer.Get(), nullptr, &context->GetRenderTargetViewRef()));
|
||||
// set render target view
|
||||
context->GetDeviceContext()->OMSetRenderTargets(1u, context->GetRenderTargetView().GetAddressOf(), nullptr);
|
||||
}
|
||||
|
||||
// set render target view
|
||||
context->GetDeviceContext()->OMSetRenderTargets(1u, context->GetRenderTargetView().GetAddressOf(), nullptr);
|
||||
}
|
||||
|
||||
void dxGraphicsContext::SetupDebugInterface()
|
||||
{
|
||||
void dxGraphicsContext::SetupDebugInterface()
|
||||
{
|
||||
#ifdef LIGHT_DEBUG
|
||||
Ref<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_SharedContext);
|
||||
Ref<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_SharedContext);
|
||||
|
||||
HRESULT hr;
|
||||
Microsoft::WRL::ComPtr<ID3D11Debug> debugInterface = nullptr;
|
||||
DXC(context->GetDevice()->QueryInterface(__uuidof(ID3D11Debug), &debugInterface));
|
||||
HRESULT hr;
|
||||
Microsoft::WRL::ComPtr<ID3D11Debug> debugInterface = nullptr;
|
||||
DXC(context->GetDevice()->QueryInterface(__uuidof(ID3D11Debug), &debugInterface));
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D11InfoQueue> infoQueue = nullptr;
|
||||
DXC(debugInterface->QueryInterface(__uuidof(ID3D11InfoQueue), &infoQueue));
|
||||
Microsoft::WRL::ComPtr<ID3D11InfoQueue> infoQueue = nullptr;
|
||||
DXC(debugInterface->QueryInterface(__uuidof(ID3D11InfoQueue), &infoQueue));
|
||||
|
||||
infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_CORRUPTION, true);
|
||||
infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_ERROR, true);
|
||||
infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_CORRUPTION, true);
|
||||
infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_ERROR, true);
|
||||
|
||||
D3D11_MESSAGE_ID hide[] =
|
||||
{
|
||||
D3D11_MESSAGE_ID_UNKNOWN,
|
||||
// #todo: add more messages here as needed
|
||||
};
|
||||
D3D11_MESSAGE_ID hide[] = {
|
||||
D3D11_MESSAGE_ID_UNKNOWN,
|
||||
// #todo: add more messages here as needed
|
||||
};
|
||||
|
||||
D3D11_INFO_QUEUE_FILTER filter = { };
|
||||
filter.DenyList.NumIDs = _countof(hide);
|
||||
filter.DenyList.pIDList = hide;
|
||||
infoQueue->AddStorageFilterEntries(&filter);
|
||||
infoQueue->Release();
|
||||
D3D11_INFO_QUEUE_FILTER filter = {};
|
||||
filter.DenyList.NumIDs = _countof(hide);
|
||||
filter.DenyList.pIDList = hide;
|
||||
infoQueue->AddStorageFilterEntries(&filter);
|
||||
infoQueue->Release();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void dxGraphicsContext::LogDebugData()
|
||||
{
|
||||
Ref<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_SharedContext);
|
||||
void dxGraphicsContext::LogDebugData()
|
||||
{
|
||||
Ref<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_SharedContext);
|
||||
|
||||
// locals
|
||||
IDXGIDevice* DXGIDevice;
|
||||
IDXGIAdapter* DXGIAdapter;
|
||||
DXGI_ADAPTER_DESC DXGIAdapterDesc;
|
||||
// locals
|
||||
IDXGIDevice* DXGIDevice;
|
||||
IDXGIAdapter* DXGIAdapter;
|
||||
DXGI_ADAPTER_DESC DXGIAdapterDesc;
|
||||
|
||||
context->GetDevice()->QueryInterface(__uuidof(IDXGIDevice), (void**)&DXGIDevice);
|
||||
DXGIDevice->GetAdapter(&DXGIAdapter);
|
||||
DXGIAdapter->GetDesc(&DXGIAdapterDesc);
|
||||
context->GetDevice()->QueryInterface(__uuidof(IDXGIDevice), (void**)&DXGIDevice);
|
||||
DXGIDevice->GetAdapter(&DXGIAdapter);
|
||||
DXGIAdapter->GetDesc(&DXGIAdapterDesc);
|
||||
|
||||
// get the adapter's description
|
||||
char DefChar = ' ';
|
||||
char ch[180];
|
||||
WideCharToMultiByte(CP_ACP, 0, DXGIAdapterDesc.Description, -1, ch, 180, &DefChar, NULL);
|
||||
std::string adapterDesc(ch);
|
||||
// get the adapter's description
|
||||
char DefChar = ' ';
|
||||
char ch[180];
|
||||
WideCharToMultiByte(CP_ACP, 0, DXGIAdapterDesc.Description, -1, ch, 180, &DefChar, NULL);
|
||||
std::string adapterDesc(ch);
|
||||
|
||||
// release memory
|
||||
DXGIDevice->Release();
|
||||
DXGIAdapter->Release();
|
||||
// release memory
|
||||
DXGIDevice->Release();
|
||||
DXGIAdapter->Release();
|
||||
|
||||
// #todo: log more information
|
||||
LT_ENGINE_INFO("________________________________________");
|
||||
LT_ENGINE_INFO("dxGraphicsContext:");
|
||||
LT_ENGINE_INFO(" Renderer: {}", adapterDesc);
|
||||
LT_ENGINE_INFO("________________________________________");
|
||||
}
|
||||
// #todo: log more information
|
||||
LOG(info, "________________________________________");
|
||||
LOG(info, "dxGraphicsContext:");
|
||||
LOG(info, " Renderer: {}", adapterDesc);
|
||||
LOG(info, "________________________________________");
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,91 +1,92 @@
|
|||
#include "dxRenderCommand.h"
|
||||
|
||||
#include "dxSharedContext.h"
|
||||
|
||||
namespace Light {
|
||||
|
||||
dxRenderCommand::dxRenderCommand(Ref<dxSharedContext> sharedContext)
|
||||
: m_Context(sharedContext)
|
||||
{
|
||||
}
|
||||
dxRenderCommand::dxRenderCommand(Ref<dxSharedContext> sharedContext)
|
||||
: m_Context(sharedContext)
|
||||
{
|
||||
}
|
||||
|
||||
void dxRenderCommand::SwapBuffers()
|
||||
{
|
||||
void dxRenderCommand::SwapBuffers()
|
||||
{
|
||||
#ifdef LIGHT_DEBUG
|
||||
HRESULT hr;
|
||||
if (FAILED(hr = m_Context->GetSwapChain()->Present(1u, 0u)))
|
||||
HRESULT hr;
|
||||
if (FAILED(hr = m_Context->GetSwapChain()->Present(1u, 0u)))
|
||||
{
|
||||
if (hr == DXGI_ERROR_DEVICE_REMOVED)
|
||||
{
|
||||
if (hr == DXGI_ERROR_DEVICE_REMOVED)
|
||||
{
|
||||
LT_ENGINE_CRITICAL("dxRenderCommand::SwapBuffers: DeviceRemoved:");
|
||||
LT_ENGINE_CRITICAL(" {}", m_Context->GetDevice()->GetDeviceRemovedReason());
|
||||
throw dxException(hr, __FILE__, __LINE__);
|
||||
}
|
||||
LOG(critical, "dxRenderCommand::SwapBuffers: DeviceRemoved:");
|
||||
LOG(critical, " {}", m_Context->GetDevice()->GetDeviceRemovedReason());
|
||||
throw dxException(hr, __FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
#else
|
||||
m_Context->GetSwapChain()->Present(0u, 0u);
|
||||
m_Context->GetSwapChain()->Present(0u, 0u);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void dxRenderCommand::ClearBackBuffer(const glm::vec4& clearColor)
|
||||
{
|
||||
m_Context->GetDeviceContext()->ClearRenderTargetView(m_Context->GetRenderTargetView().Get(), &clearColor[0]);
|
||||
}
|
||||
void dxRenderCommand::ClearBackBuffer(const glm::vec4& clearColor)
|
||||
{
|
||||
m_Context->GetDeviceContext()->ClearRenderTargetView(m_Context->GetRenderTargetView().Get(), &clearColor[0]);
|
||||
}
|
||||
|
||||
void dxRenderCommand::Draw(unsigned int count)
|
||||
{
|
||||
m_Context->GetDeviceContext()->Draw(count, 0u);
|
||||
}
|
||||
void dxRenderCommand::Draw(unsigned int count)
|
||||
{
|
||||
m_Context->GetDeviceContext()->Draw(count, 0u);
|
||||
}
|
||||
|
||||
void dxRenderCommand::DrawIndexed(unsigned int count)
|
||||
{
|
||||
m_Context->GetDeviceContext()->DrawIndexed(count, 0u, 0u);
|
||||
}
|
||||
void dxRenderCommand::DrawIndexed(unsigned int count)
|
||||
{
|
||||
m_Context->GetDeviceContext()->DrawIndexed(count, 0u, 0u);
|
||||
}
|
||||
|
||||
void dxRenderCommand::DefaultTargetFramebuffer()
|
||||
{
|
||||
m_Context->GetDeviceContext()->OMSetRenderTargets(1, m_Context->GetRenderTargetView().GetAddressOf(), nullptr);
|
||||
}
|
||||
void dxRenderCommand::DefaultTargetFramebuffer()
|
||||
{
|
||||
m_Context->GetDeviceContext()->OMSetRenderTargets(1, m_Context->GetRenderTargetView().GetAddressOf(), nullptr);
|
||||
}
|
||||
|
||||
void dxRenderCommand::SetViewport(unsigned int x, unsigned int y, unsigned int width, unsigned int height)
|
||||
{
|
||||
// #todo: maybe call this somewhere else??
|
||||
SetResolution(width, height);
|
||||
void dxRenderCommand::SetViewport(unsigned int x, unsigned int y, unsigned int width, unsigned int height)
|
||||
{
|
||||
// #todo: maybe call this somewhere else??
|
||||
SetResolution(width, height);
|
||||
|
||||
// create viewport
|
||||
D3D11_VIEWPORT viewport;
|
||||
// create viewport
|
||||
D3D11_VIEWPORT viewport;
|
||||
|
||||
viewport.TopLeftX = x;
|
||||
viewport.TopLeftY = y;
|
||||
viewport.TopLeftX = x;
|
||||
viewport.TopLeftY = y;
|
||||
|
||||
viewport.Width = width;
|
||||
viewport.Height = height;
|
||||
viewport.Width = width;
|
||||
viewport.Height = height;
|
||||
|
||||
viewport.MinDepth = 0.0f;
|
||||
viewport.MaxDepth = 1.0f;
|
||||
viewport.MinDepth = 0.0f;
|
||||
viewport.MaxDepth = 1.0f;
|
||||
|
||||
// set viewport
|
||||
m_Context->GetDeviceContext()->RSSetViewports(1u, &viewport);
|
||||
}
|
||||
// set viewport
|
||||
m_Context->GetDeviceContext()->RSSetViewports(1u, &viewport);
|
||||
}
|
||||
|
||||
void dxRenderCommand::SetResolution(unsigned int width, unsigned int height)
|
||||
{
|
||||
HRESULT hr;
|
||||
void dxRenderCommand::SetResolution(unsigned int width, unsigned int height)
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
// remove render target
|
||||
ID3D11RenderTargetView* nullViews[] = { nullptr };
|
||||
m_Context->GetDeviceContext()->OMSetRenderTargets(1u, nullViews, nullptr);
|
||||
m_Context->GetRenderTargetViewRef().Reset();
|
||||
// remove render target
|
||||
ID3D11RenderTargetView* nullViews[] = { nullptr };
|
||||
m_Context->GetDeviceContext()->OMSetRenderTargets(1u, nullViews, nullptr);
|
||||
m_Context->GetRenderTargetViewRef().Reset();
|
||||
|
||||
// resize buffer
|
||||
DXC(m_Context->GetSwapChain()->ResizeBuffers(0u, width, height, DXGI_FORMAT_R8G8B8A8_UNORM, NULL));
|
||||
// resize buffer
|
||||
DXC(m_Context->GetSwapChain()->ResizeBuffers(0u, width, height, DXGI_FORMAT_R8G8B8A8_UNORM, NULL));
|
||||
|
||||
// create render target
|
||||
Microsoft::WRL::ComPtr<ID3D11Resource> backBuffer = nullptr;
|
||||
DXC(m_Context->GetSwapChain()->GetBuffer(0u, __uuidof(ID3D11Resource), &backBuffer));
|
||||
DXC(m_Context->GetDevice()->CreateRenderTargetView(backBuffer.Get(), nullptr, &m_Context->GetRenderTargetViewRef()));
|
||||
// create render target
|
||||
Microsoft::WRL::ComPtr<ID3D11Resource> backBuffer = nullptr;
|
||||
DXC(m_Context->GetSwapChain()->GetBuffer(0u, __uuidof(ID3D11Resource), &backBuffer));
|
||||
DXC(m_Context->GetDevice()->CreateRenderTargetView(backBuffer.Get(), nullptr, &m_Context->GetRenderTargetViewRef()));
|
||||
|
||||
// set render target
|
||||
m_Context->GetDeviceContext()->OMSetRenderTargets(1u, m_Context->GetRenderTargetView().GetAddressOf(), nullptr);
|
||||
}
|
||||
// set render target
|
||||
m_Context->GetDeviceContext()->OMSetRenderTargets(1u, m_Context->GetRenderTargetView().GetAddressOf(), nullptr);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,47 +1,45 @@
|
|||
#include "dxShader.h"
|
||||
|
||||
#include "dxSharedContext.h"
|
||||
|
||||
#include <d3dcompiler.h>
|
||||
|
||||
namespace Light {
|
||||
|
||||
dxShader::dxShader(BasicFileHandle vertexFile, BasicFileHandle pixelFile, Ref<dxSharedContext> sharedContext)
|
||||
: m_Context(sharedContext),
|
||||
m_VertexShader(nullptr),
|
||||
m_PixelShader(nullptr),
|
||||
m_VertexBlob(nullptr)
|
||||
{
|
||||
Microsoft::WRL::ComPtr<ID3DBlob> ps = nullptr, vsErr = nullptr, psErr = nullptr;
|
||||
dxShader::dxShader(BasicFileHandle vertexFile, BasicFileHandle pixelFile, Ref<dxSharedContext> sharedContext)
|
||||
: m_Context(sharedContext), m_VertexShader(nullptr), m_PixelShader(nullptr), m_VertexBlob(nullptr)
|
||||
{
|
||||
Microsoft::WRL::ComPtr<ID3DBlob> ps = nullptr, vsErr = nullptr, psErr = nullptr;
|
||||
|
||||
// compile shaders (we don't use DXC here because if D3DCompile fails it throws a dxException without logging the vsErr/psErr
|
||||
D3DCompile(vertexFile.GetData(), vertexFile.GetSize(), NULL, nullptr, nullptr, "main", "vs_4_0", NULL, NULL, &m_VertexBlob, &vsErr);
|
||||
D3DCompile(pixelFile.GetData(), pixelFile.GetSize(), NULL, nullptr, nullptr, "main", "ps_4_0", NULL, NULL, &ps, &psErr);
|
||||
// compile shaders (we don't use DXC here because if D3DCompile fails it throws a dxException without logging the vsErr/psErr
|
||||
D3DCompile(vertexFile.GetData(), vertexFile.GetSize(), NULL, nullptr, nullptr, "main", "vs_4_0", NULL, NULL, &m_VertexBlob, &vsErr);
|
||||
D3DCompile(pixelFile.GetData(), pixelFile.GetSize(), NULL, nullptr, nullptr, "main", "ps_4_0", NULL, NULL, &ps, &psErr);
|
||||
|
||||
// check
|
||||
LT_ENGINE_ASSERT(!vsErr.Get(), "dxShader::dxShader: vertex shader compile error: {}", (char*)vsErr->GetBufferPointer());
|
||||
LT_ENGINE_ASSERT(!psErr.Get(), "dxShader::dxShader: pixels shader compile error: {}", (char*)psErr->GetBufferPointer());
|
||||
// check
|
||||
ASSERT(!vsErr.Get(), "Vertex shader compile error: {}", (char*)vsErr->GetBufferPointer());
|
||||
ASSERT(!psErr.Get(), "Pixels shader compile error: {}", (char*)psErr->GetBufferPointer());
|
||||
|
||||
// create shaders
|
||||
HRESULT hr;
|
||||
DXC(m_Context->GetDevice()->CreateVertexShader(m_VertexBlob->GetBufferPointer(), m_VertexBlob->GetBufferSize(), NULL, &m_VertexShader));
|
||||
DXC(m_Context->GetDevice()->CreatePixelShader(ps->GetBufferPointer(), ps->GetBufferSize(), NULL, &m_PixelShader));
|
||||
}
|
||||
// create shaders
|
||||
HRESULT hr;
|
||||
DXC(m_Context->GetDevice()->CreateVertexShader(m_VertexBlob->GetBufferPointer(), m_VertexBlob->GetBufferSize(), NULL, &m_VertexShader));
|
||||
DXC(m_Context->GetDevice()->CreatePixelShader(ps->GetBufferPointer(), ps->GetBufferSize(), NULL, &m_PixelShader));
|
||||
}
|
||||
|
||||
dxShader::~dxShader()
|
||||
{
|
||||
UnBind();
|
||||
}
|
||||
dxShader::~dxShader()
|
||||
{
|
||||
UnBind();
|
||||
}
|
||||
|
||||
void dxShader::Bind()
|
||||
{
|
||||
m_Context->GetDeviceContext()->VSSetShader(m_VertexShader.Get(), nullptr, 0u);
|
||||
m_Context->GetDeviceContext()->PSSetShader(m_PixelShader.Get(), nullptr, 0u);
|
||||
}
|
||||
void dxShader::Bind()
|
||||
{
|
||||
m_Context->GetDeviceContext()->VSSetShader(m_VertexShader.Get(), nullptr, 0u);
|
||||
m_Context->GetDeviceContext()->PSSetShader(m_PixelShader.Get(), nullptr, 0u);
|
||||
}
|
||||
|
||||
void dxShader::UnBind()
|
||||
{
|
||||
m_Context->GetDeviceContext()->VSSetShader(nullptr, nullptr, 0u);
|
||||
m_Context->GetDeviceContext()->PSSetShader(nullptr, nullptr, 0u);
|
||||
}
|
||||
void dxShader::UnBind()
|
||||
{
|
||||
m_Context->GetDeviceContext()->VSSetShader(nullptr, nullptr, 0u);
|
||||
m_Context->GetDeviceContext()->PSSetShader(nullptr, nullptr, 0u);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,65 +1,64 @@
|
|||
#include "dxUserInterface.h"
|
||||
#include "dxSharedContext.h"
|
||||
|
||||
#include "Input/KeyCodes.h"
|
||||
#include "dxSharedContext.h"
|
||||
|
||||
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||
#include <backends/imgui_impl_dx11.h>
|
||||
#include <backends/imgui_impl_win32.h>
|
||||
#include <glfw/glfw3.h>
|
||||
#include <glfw/glfw3native.h>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <backends/imgui_impl_win32.h>
|
||||
#include <backends/imgui_impl_dx11.h>
|
||||
|
||||
namespace Light {
|
||||
|
||||
void dxUserInterface::PlatformImplementation(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
Ref<dxSharedContext> context = std::dynamic_pointer_cast<dxSharedContext>(sharedContext);
|
||||
void dxUserInterface::PlatformImplementation(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
Ref<dxSharedContext> context = std::dynamic_pointer_cast<dxSharedContext>(sharedContext);
|
||||
|
||||
ImGui_ImplWin32_Init(glfwGetWin32Window(windowHandle));
|
||||
ImGui_ImplDX11_Init(context->GetDevice().Get(), context->GetDeviceContext().Get());
|
||||
}
|
||||
ImGui_ImplWin32_Init(glfwGetWin32Window(windowHandle));
|
||||
ImGui_ImplDX11_Init(context->GetDevice().Get(), context->GetDeviceContext().Get());
|
||||
}
|
||||
|
||||
dxUserInterface::~dxUserInterface()
|
||||
{
|
||||
// #todo: handle this in a better way
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
dxUserInterface::~dxUserInterface()
|
||||
{
|
||||
// #todo: handle this in a better way
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
if (io.IniFilename == "default_gui_layout.ini")
|
||||
io.IniFilename = "user_gui_layout.ini";
|
||||
if (io.IniFilename == "default_gui_layout.ini")
|
||||
io.IniFilename = "user_gui_layout.ini";
|
||||
|
||||
ImGui_ImplDX11_Shutdown();
|
||||
ImGui_ImplWin32_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
ImGui_ImplDX11_Shutdown();
|
||||
ImGui_ImplWin32_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
|
||||
void dxUserInterface::Begin()
|
||||
{
|
||||
ImGui_ImplDX11_NewFrame();
|
||||
ImGui_ImplWin32_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
}
|
||||
void dxUserInterface::Begin()
|
||||
{
|
||||
ImGui_ImplDX11_NewFrame();
|
||||
ImGui_ImplWin32_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
}
|
||||
|
||||
void dxUserInterface::End()
|
||||
{
|
||||
ImGui::Render();
|
||||
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
|
||||
void dxUserInterface::End()
|
||||
{
|
||||
ImGui::Render();
|
||||
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
|
||||
|
||||
ImGui::UpdatePlatformWindows();
|
||||
ImGui::RenderPlatformWindowsDefault();
|
||||
}
|
||||
ImGui::UpdatePlatformWindows();
|
||||
ImGui::RenderPlatformWindowsDefault();
|
||||
}
|
||||
|
||||
void dxUserInterface::LogDebugData()
|
||||
{
|
||||
// #todo: improve
|
||||
LT_ENGINE_INFO("________________________________________");
|
||||
LT_ENGINE_INFO("UserInterface::");
|
||||
LT_ENGINE_INFO(" API : ImGui");
|
||||
LT_ENGINE_INFO(" Version: {}", ImGui::GetVersion());
|
||||
LT_ENGINE_INFO(" GraphicsAPI : DirectX");
|
||||
LT_ENGINE_INFO("________________________________________");
|
||||
}
|
||||
void dxUserInterface::LogDebugData()
|
||||
{
|
||||
// #todo: improve
|
||||
LOG(info, "________________________________________");
|
||||
LOG(info, "UserInterface::");
|
||||
LOG(info, " API : ImGui");
|
||||
LOG(info, " Version: {}", ImGui::GetVersion());
|
||||
LOG(info, " GraphicsAPI : DirectX");
|
||||
LOG(info, "________________________________________");
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,89 +1,88 @@
|
|||
#include "dxVertexLayout.h"
|
||||
#include "dxSharedContext.h"
|
||||
|
||||
#include "dxShader.h"
|
||||
#include "dxSharedContext.h"
|
||||
|
||||
namespace Light {
|
||||
|
||||
dxVertexLayout::dxVertexLayout(Ref<Shader> shader, const std::vector<std::pair<std::string, VertexElementType>>& elements, Ref<dxSharedContext> sharedContext)
|
||||
: m_Context(sharedContext),
|
||||
m_InputLayout(nullptr)
|
||||
dxVertexLayout::dxVertexLayout(Ref<Shader> shader, const std::vector<std::pair<std::string, VertexElementType>>& elements, Ref<dxSharedContext> sharedContext)
|
||||
: m_Context(sharedContext), m_InputLayout(nullptr)
|
||||
{
|
||||
// occupy space for input elements
|
||||
std::vector<D3D11_INPUT_ELEMENT_DESC> inputElementsDesc;
|
||||
inputElementsDesc.reserve(elements.size());
|
||||
|
||||
// extract elements desc
|
||||
for (const auto& element : elements)
|
||||
{
|
||||
// occupy space for input elements
|
||||
std::vector<D3D11_INPUT_ELEMENT_DESC> inputElementsDesc;
|
||||
inputElementsDesc.reserve(elements.size());
|
||||
|
||||
// extract elements desc
|
||||
for (const auto& element : elements)
|
||||
{
|
||||
inputElementsDesc.emplace_back(D3D11_INPUT_ELEMENT_DESC{ element.first.c_str(),
|
||||
NULL,
|
||||
GetDxgiFormat(element.second),
|
||||
0u,
|
||||
D3D11_APPEND_ALIGNED_ELEMENT,
|
||||
D3D11_INPUT_PER_VERTEX_DATA,
|
||||
0u });
|
||||
}
|
||||
|
||||
Ref<dxShader> dxpShader = std::dynamic_pointer_cast<dxShader>(shader);
|
||||
LT_ENGINE_ASSERT(dxpShader, "dxVertexLayout::dxVertexLayout: failed to cast 'Shader' to 'dxShader'");
|
||||
|
||||
// create input layout (vertex layout)
|
||||
HRESULT hr;
|
||||
DXC(m_Context->GetDevice()->CreateInputLayout(&inputElementsDesc[0], inputElementsDesc.size(), dxpShader->GetVertexBlob().Get()->GetBufferPointer(), dxpShader->GetVertexBlob().Get()->GetBufferSize(), &m_InputLayout));
|
||||
inputElementsDesc.emplace_back(D3D11_INPUT_ELEMENT_DESC { element.first.c_str(),
|
||||
NULL,
|
||||
GetDxgiFormat(element.second),
|
||||
0u,
|
||||
D3D11_APPEND_ALIGNED_ELEMENT,
|
||||
D3D11_INPUT_PER_VERTEX_DATA,
|
||||
0u });
|
||||
}
|
||||
|
||||
dxVertexLayout::~dxVertexLayout()
|
||||
Ref<dxShader> dxpShader = std::dynamic_pointer_cast<dxShader>(shader);
|
||||
ASSERT(dxpShader, "Failed to cast 'Shader' to 'dxShader'");
|
||||
|
||||
// create input layout (vertex layout)
|
||||
HRESULT hr;
|
||||
DXC(m_Context->GetDevice()->CreateInputLayout(&inputElementsDesc[0], inputElementsDesc.size(), dxpShader->GetVertexBlob().Get()->GetBufferPointer(), dxpShader->GetVertexBlob().Get()->GetBufferSize(), &m_InputLayout));
|
||||
}
|
||||
|
||||
dxVertexLayout::~dxVertexLayout()
|
||||
{
|
||||
UnBind();
|
||||
}
|
||||
|
||||
void dxVertexLayout::Bind()
|
||||
{
|
||||
m_Context->GetDeviceContext()->IASetInputLayout(m_InputLayout.Get());
|
||||
}
|
||||
|
||||
void dxVertexLayout::UnBind()
|
||||
{
|
||||
m_Context->GetDeviceContext()->IASetInputLayout(nullptr);
|
||||
}
|
||||
|
||||
DXGI_FORMAT dxVertexLayout::GetDxgiFormat(VertexElementType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
UnBind();
|
||||
/* byte */
|
||||
case Light::VertexElementType::Byte1: return DXGI_FORMAT_R8_SINT;
|
||||
case Light::VertexElementType::Byte2: return DXGI_FORMAT_R8G8_SINT;
|
||||
case Light::VertexElementType::Byte4: return DXGI_FORMAT_R8_SINT;
|
||||
|
||||
/* ubyte */
|
||||
case Light::VertexElementType::UByte1: return DXGI_FORMAT_R8_UINT;
|
||||
case Light::VertexElementType::UByte2: return DXGI_FORMAT_R8G8_UINT;
|
||||
case Light::VertexElementType::UByte4: return DXGI_FORMAT_R8G8B8A8_UINT;
|
||||
|
||||
/* int */
|
||||
case Light::VertexElementType::Int1: return DXGI_FORMAT_R32_SINT;
|
||||
case Light::VertexElementType::Int2: return DXGI_FORMAT_R32G32_SINT;
|
||||
case Light::VertexElementType::Int3: return DXGI_FORMAT_R32G32B32_SINT;
|
||||
case Light::VertexElementType::Int4: return DXGI_FORMAT_R32G32B32A32_SINT;
|
||||
|
||||
/* uint */
|
||||
case Light::VertexElementType::UInt1: return DXGI_FORMAT_R32_UINT;
|
||||
case Light::VertexElementType::UInt2: return DXGI_FORMAT_R32G32_UINT;
|
||||
case Light::VertexElementType::UInt3: return DXGI_FORMAT_R32G32B32_UINT;
|
||||
case Light::VertexElementType::UInt4: return DXGI_FORMAT_R32G32B32A32_UINT;
|
||||
|
||||
/* float */
|
||||
case Light::VertexElementType::Float1: return DXGI_FORMAT_R32_FLOAT;
|
||||
case Light::VertexElementType::Float2: return DXGI_FORMAT_R32G32_FLOAT;
|
||||
case Light::VertexElementType::Float3: return DXGI_FORMAT_R32G32B32_FLOAT;
|
||||
case Light::VertexElementType::Float4: return DXGI_FORMAT_R32G32B32A32_FLOAT;
|
||||
|
||||
default:
|
||||
ASSERT(false, "Invalid 'VertexElementType'");
|
||||
return DXGI_FORMAT_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
void dxVertexLayout::Bind()
|
||||
{
|
||||
m_Context->GetDeviceContext()->IASetInputLayout(m_InputLayout.Get());
|
||||
}
|
||||
|
||||
void dxVertexLayout::UnBind()
|
||||
{
|
||||
m_Context->GetDeviceContext()->IASetInputLayout(nullptr);
|
||||
}
|
||||
|
||||
DXGI_FORMAT dxVertexLayout::GetDxgiFormat(VertexElementType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
/* byte */
|
||||
case Light::VertexElementType::Byte1: return DXGI_FORMAT_R8_SINT;
|
||||
case Light::VertexElementType::Byte2: return DXGI_FORMAT_R8G8_SINT;
|
||||
case Light::VertexElementType::Byte4: return DXGI_FORMAT_R8_SINT;
|
||||
|
||||
/* ubyte */
|
||||
case Light::VertexElementType::UByte1: return DXGI_FORMAT_R8_UINT;
|
||||
case Light::VertexElementType::UByte2: return DXGI_FORMAT_R8G8_UINT;
|
||||
case Light::VertexElementType::UByte4: return DXGI_FORMAT_R8G8B8A8_UINT;
|
||||
|
||||
/* int */
|
||||
case Light::VertexElementType::Int1: return DXGI_FORMAT_R32_SINT;
|
||||
case Light::VertexElementType::Int2: return DXGI_FORMAT_R32G32_SINT;
|
||||
case Light::VertexElementType::Int3: return DXGI_FORMAT_R32G32B32_SINT;
|
||||
case Light::VertexElementType::Int4: return DXGI_FORMAT_R32G32B32A32_SINT;
|
||||
|
||||
/* uint */
|
||||
case Light::VertexElementType::UInt1: return DXGI_FORMAT_R32_UINT;
|
||||
case Light::VertexElementType::UInt2: return DXGI_FORMAT_R32G32_UINT;
|
||||
case Light::VertexElementType::UInt3: return DXGI_FORMAT_R32G32B32_UINT;
|
||||
case Light::VertexElementType::UInt4: return DXGI_FORMAT_R32G32B32A32_UINT;
|
||||
|
||||
/* float */
|
||||
case Light::VertexElementType::Float1: return DXGI_FORMAT_R32_FLOAT;
|
||||
case Light::VertexElementType::Float2: return DXGI_FORMAT_R32G32_FLOAT;
|
||||
case Light::VertexElementType::Float3: return DXGI_FORMAT_R32G32B32_FLOAT;
|
||||
case Light::VertexElementType::Float4: return DXGI_FORMAT_R32G32B32A32_FLOAT;
|
||||
|
||||
default:
|
||||
LT_ENGINE_ASSERT(false, "dxVertexLayout::GetDxgiFormat: invalid 'VertexElementType'");
|
||||
return DXGI_FORMAT_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Light
|
||||
|
|
|
@ -4,129 +4,128 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
//==================== CONSTANT_BUFFER ====================//
|
||||
glConstantBuffer::glConstantBuffer(ConstantBufferIndex index, unsigned int size)
|
||||
: m_BufferID(NULL),
|
||||
m_Index(static_cast<int>(index))
|
||||
{
|
||||
glCreateBuffers(1, &m_BufferID);
|
||||
glNamedBufferData(m_BufferID, size, nullptr, GL_DYNAMIC_DRAW);
|
||||
//==================== CONSTANT_BUFFER ====================//
|
||||
glConstantBuffer::glConstantBuffer(ConstantBufferIndex index, unsigned int size)
|
||||
: m_BufferID(NULL), m_Index(static_cast<int>(index))
|
||||
{
|
||||
glCreateBuffers(1, &m_BufferID);
|
||||
glNamedBufferData(m_BufferID, size, nullptr, GL_DYNAMIC_DRAW);
|
||||
|
||||
Bind();
|
||||
}
|
||||
Bind();
|
||||
}
|
||||
|
||||
glConstantBuffer::~glConstantBuffer()
|
||||
{
|
||||
glDeleteBuffers(1, &m_BufferID);
|
||||
}
|
||||
glConstantBuffer::~glConstantBuffer()
|
||||
{
|
||||
glDeleteBuffers(1, &m_BufferID);
|
||||
}
|
||||
|
||||
void glConstantBuffer::Bind()
|
||||
{
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, m_Index, m_BufferID);
|
||||
}
|
||||
void glConstantBuffer::Bind()
|
||||
{
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, m_Index, m_BufferID);
|
||||
}
|
||||
|
||||
void* glConstantBuffer::Map()
|
||||
{
|
||||
void* map = glMapNamedBuffer(m_BufferID, GL_WRITE_ONLY);
|
||||
return map;
|
||||
}
|
||||
void* glConstantBuffer::Map()
|
||||
{
|
||||
void* map = glMapNamedBuffer(m_BufferID, GL_WRITE_ONLY);
|
||||
return map;
|
||||
}
|
||||
|
||||
void glConstantBuffer::UnMap()
|
||||
{
|
||||
glUnmapNamedBuffer(m_BufferID);
|
||||
}
|
||||
//==================== CONSTANT_BUFFER ====================//
|
||||
void glConstantBuffer::UnMap()
|
||||
{
|
||||
glUnmapNamedBuffer(m_BufferID);
|
||||
}
|
||||
//==================== CONSTANT_BUFFER ====================//
|
||||
|
||||
//==================== VERTEX_BUFFER ====================//
|
||||
glVertexBuffer::glVertexBuffer(float* vertices, unsigned int stride, unsigned int count)
|
||||
: m_BufferID(NULL)
|
||||
{
|
||||
glCreateBuffers(1, &m_BufferID);
|
||||
glNamedBufferData(m_BufferID, stride * count, vertices, GL_DYNAMIC_DRAW);
|
||||
}
|
||||
//==================== VERTEX_BUFFER ====================//
|
||||
glVertexBuffer::glVertexBuffer(float* vertices, unsigned int stride, unsigned int count)
|
||||
: m_BufferID(NULL)
|
||||
{
|
||||
glCreateBuffers(1, &m_BufferID);
|
||||
glNamedBufferData(m_BufferID, stride * count, vertices, GL_DYNAMIC_DRAW);
|
||||
}
|
||||
|
||||
glVertexBuffer::~glVertexBuffer()
|
||||
{
|
||||
glDeleteBuffers(1, &m_BufferID);
|
||||
}
|
||||
glVertexBuffer::~glVertexBuffer()
|
||||
{
|
||||
glDeleteBuffers(1, &m_BufferID);
|
||||
}
|
||||
|
||||
void glVertexBuffer::Bind()
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_BufferID);
|
||||
}
|
||||
void glVertexBuffer::Bind()
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_BufferID);
|
||||
}
|
||||
|
||||
void glVertexBuffer::UnBind()
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, NULL);
|
||||
}
|
||||
void glVertexBuffer::UnBind()
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, NULL);
|
||||
}
|
||||
|
||||
void* glVertexBuffer::Map()
|
||||
{
|
||||
return glMapNamedBuffer(m_BufferID, GL_WRITE_ONLY);
|
||||
}
|
||||
void* glVertexBuffer::Map()
|
||||
{
|
||||
return glMapNamedBuffer(m_BufferID, GL_WRITE_ONLY);
|
||||
}
|
||||
|
||||
void glVertexBuffer::UnMap()
|
||||
{
|
||||
glUnmapNamedBuffer(m_BufferID);
|
||||
}
|
||||
//==================== VERTEX_BUFFER ====================//
|
||||
void glVertexBuffer::UnMap()
|
||||
{
|
||||
glUnmapNamedBuffer(m_BufferID);
|
||||
}
|
||||
//==================== VERTEX_BUFFER ====================//
|
||||
|
||||
//==================== INDEX_BUFFER ====================//
|
||||
glIndexBuffer::glIndexBuffer(unsigned int* indices, unsigned int count)
|
||||
: m_BufferID(NULL)
|
||||
//==================== INDEX_BUFFER ====================//
|
||||
glIndexBuffer::glIndexBuffer(unsigned int* indices, unsigned int count)
|
||||
: m_BufferID(NULL)
|
||||
{
|
||||
// generate indices if not provided
|
||||
bool hasIndices = !!indices;
|
||||
if (!hasIndices)
|
||||
{
|
||||
// generate indices if not provided
|
||||
bool hasIndices = !!indices;
|
||||
if (!hasIndices)
|
||||
// check
|
||||
if (count % 6 != 0)
|
||||
{
|
||||
// check
|
||||
if (count % 6 != 0)
|
||||
{
|
||||
LT_ENGINE_WARN("glIndexBuffer::dxIndexBuffer: 'indices' can only be null if count is multiple of 6");
|
||||
LT_ENGINE_WARN("glIndexBuffer::glIndexBuffer: adding {} to 'count' -> {}", (6 - (count % 6)), count + (6 - (count % 6)));
|
||||
count = count + (6 - (count % 6));
|
||||
}
|
||||
|
||||
// create indices
|
||||
indices = new unsigned int[count];
|
||||
unsigned int offset = 0u;
|
||||
for (unsigned int i = 0u; i < count; i += 6u)
|
||||
{
|
||||
indices[i + 0] = offset + 0u;
|
||||
indices[i + 1] = offset + 1u;
|
||||
indices[i + 2] = offset + 2u;
|
||||
|
||||
indices[i + 3] = offset + 2u;
|
||||
indices[i + 4] = offset + 3u;
|
||||
indices[i + 5] = offset + 0u;
|
||||
|
||||
offset += 4u;
|
||||
}
|
||||
LOG(warn, "'indices' can only be null if count is multiple of 6");
|
||||
LOG(warn, "Adding {} to 'count' -> {}", (6 - (count % 6)), count + (6 - (count % 6)));
|
||||
count = count + (6 - (count % 6));
|
||||
}
|
||||
|
||||
// create buffer
|
||||
glCreateBuffers(1, &m_BufferID);
|
||||
glNamedBufferData(m_BufferID, count * sizeof(unsigned int), indices, GL_STATIC_DRAW);
|
||||
// create indices
|
||||
indices = new unsigned int[count];
|
||||
unsigned int offset = 0u;
|
||||
for (unsigned int i = 0u; i < count; i += 6u)
|
||||
{
|
||||
indices[i + 0] = offset + 0u;
|
||||
indices[i + 1] = offset + 1u;
|
||||
indices[i + 2] = offset + 2u;
|
||||
|
||||
// delete indices
|
||||
if (!hasIndices)
|
||||
delete[] indices;
|
||||
indices[i + 3] = offset + 2u;
|
||||
indices[i + 4] = offset + 3u;
|
||||
indices[i + 5] = offset + 0u;
|
||||
|
||||
offset += 4u;
|
||||
}
|
||||
}
|
||||
|
||||
glIndexBuffer::~glIndexBuffer()
|
||||
{
|
||||
glDeleteBuffers(1, &m_BufferID);
|
||||
}
|
||||
// create buffer
|
||||
glCreateBuffers(1, &m_BufferID);
|
||||
glNamedBufferData(m_BufferID, count * sizeof(unsigned int), indices, GL_STATIC_DRAW);
|
||||
|
||||
void glIndexBuffer::Bind()
|
||||
{
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_BufferID);
|
||||
}
|
||||
// delete indices
|
||||
if (!hasIndices)
|
||||
delete[] indices;
|
||||
}
|
||||
|
||||
void glIndexBuffer::UnBind()
|
||||
{
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, NULL);
|
||||
}
|
||||
//==================== INDEX_BUFFER ====================//
|
||||
glIndexBuffer::~glIndexBuffer()
|
||||
{
|
||||
glDeleteBuffers(1, &m_BufferID);
|
||||
}
|
||||
|
||||
}
|
||||
void glIndexBuffer::Bind()
|
||||
{
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_BufferID);
|
||||
}
|
||||
|
||||
void glIndexBuffer::UnBind()
|
||||
{
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, NULL);
|
||||
}
|
||||
//==================== INDEX_BUFFER ====================//
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,76 +1,72 @@
|
|||
#include "glFramebuffer.h"
|
||||
|
||||
#include <glad/glad.h>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
namespace Light {
|
||||
|
||||
glFramebuffer::glFramebuffer(const FramebufferSpecification& specification)
|
||||
: m_Specification(specification),
|
||||
m_BufferID(NULL),
|
||||
m_ColorAttachmentID(NULL),
|
||||
m_DepthStencilAttachmentID(NULL)
|
||||
{
|
||||
Resize({ specification.width, specification.height });
|
||||
}
|
||||
glFramebuffer::glFramebuffer(const FramebufferSpecification& specification)
|
||||
: m_Specification(specification), m_BufferID(NULL), m_ColorAttachmentID(NULL), m_DepthStencilAttachmentID(NULL)
|
||||
{
|
||||
Resize({ specification.width, specification.height });
|
||||
}
|
||||
|
||||
glFramebuffer::~glFramebuffer()
|
||||
glFramebuffer::~glFramebuffer()
|
||||
{
|
||||
glDeleteFramebuffers(1, &m_BufferID);
|
||||
glDeleteTextures(1, &m_ColorAttachmentID);
|
||||
// glDeleteTextures(1, &m_DepthStencilAttachmentID);
|
||||
}
|
||||
|
||||
void glFramebuffer::BindAsTarget(const glm::vec4& clearColor)
|
||||
{
|
||||
// #todo: use viewport instead of default x=0, y=0
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_BufferID);
|
||||
glViewport(0, 0, m_Specification.width, m_Specification.height);
|
||||
|
||||
glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void glFramebuffer::BindAsResource()
|
||||
{
|
||||
LOG(err, "NO_IMPLEMENT!");
|
||||
}
|
||||
|
||||
void glFramebuffer::Resize(const glm::uvec2& size)
|
||||
{
|
||||
if (m_BufferID)
|
||||
{
|
||||
glDeleteFramebuffers(1, &m_BufferID);
|
||||
glDeleteTextures(1, &m_ColorAttachmentID);
|
||||
// glDeleteTextures(1, &m_DepthStencilAttachmentID);
|
||||
}
|
||||
|
||||
void glFramebuffer::BindAsTarget(const glm::vec4& clearColor)
|
||||
{
|
||||
// #todo: use viewport instead of default x=0, y=0
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_BufferID);
|
||||
glViewport(0, 0, m_Specification.width, m_Specification.height);
|
||||
m_Specification.width = std::clamp(size.x, 1u, (unsigned int)GL_MAX_TEXTURE_SIZE);
|
||||
m_Specification.height = std::clamp(size.y, 1u, (unsigned int)GL_MAX_TEXTURE_SIZE);
|
||||
|
||||
glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
glCreateFramebuffers(1, &m_BufferID);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_BufferID);
|
||||
|
||||
void glFramebuffer::BindAsResource()
|
||||
{
|
||||
LT_ENGINE_ERROR("glFramebuffer::BindAsResource: NO_IMPLEMENT!");
|
||||
}
|
||||
// create color attachment
|
||||
glCreateTextures(GL_TEXTURE_2D, 1, &m_ColorAttachmentID);
|
||||
glBindTexture(GL_TEXTURE_2D, m_ColorAttachmentID);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Specification.width, m_Specification.height, NULL, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||
glTextureParameteri(m_ColorAttachmentID, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTextureParameteri(m_ColorAttachmentID, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_ColorAttachmentID, 0);
|
||||
|
||||
void glFramebuffer::Resize(const glm::uvec2& size)
|
||||
{
|
||||
if (m_BufferID)
|
||||
{
|
||||
glDeleteFramebuffers(1, &m_BufferID);
|
||||
glDeleteTextures(1, &m_ColorAttachmentID);
|
||||
// glDeleteTextures(1, &m_DepthStencilAttachmentID);
|
||||
}
|
||||
// glTextureStorage2D(m_ColorAttachmentID, 0, GL_RGBA8, m_Specification.width, m_Specification.height);
|
||||
|
||||
m_Specification.width = std::clamp(size.x, 1u, (unsigned int)GL_MAX_TEXTURE_SIZE);
|
||||
m_Specification.height = std::clamp(size.y, 1u, (unsigned int)GL_MAX_TEXTURE_SIZE);
|
||||
// glCreateTextures(GL_TEXTURE_2D, 1, &m_DepthStencilAttachmentID);
|
||||
// glBindTexture(GL_TEXTURE_2D, m_DepthStencilAttachmentID);
|
||||
// glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, m_Specification.width, m_Specification.height, NULL, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, nullptr);
|
||||
// // glTextureStorage2D(m_DepthStencilAttachmentID, 0, GL_DEPTH24_STENCIL8, m_Specification.width, m_Specification.height);
|
||||
// glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, m_DepthStencilAttachmentID, 0);
|
||||
|
||||
glCreateFramebuffers(1, &m_BufferID);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_BufferID);
|
||||
ASSERT((glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE), "Framebuffer is incomplete");
|
||||
|
||||
// create color attachment
|
||||
glCreateTextures(GL_TEXTURE_2D, 1, &m_ColorAttachmentID);
|
||||
glBindTexture(GL_TEXTURE_2D, m_ColorAttachmentID);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Specification.width, m_Specification.height, NULL, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||
glTextureParameteri(m_ColorAttachmentID, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTextureParameteri(m_ColorAttachmentID, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_ColorAttachmentID, 0);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
// glTextureStorage2D(m_ColorAttachmentID, 0, GL_RGBA8, m_Specification.width, m_Specification.height);
|
||||
|
||||
// glCreateTextures(GL_TEXTURE_2D, 1, &m_DepthStencilAttachmentID);
|
||||
// glBindTexture(GL_TEXTURE_2D, m_DepthStencilAttachmentID);
|
||||
// glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, m_Specification.width, m_Specification.height, NULL, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, nullptr);
|
||||
// // glTextureStorage2D(m_DepthStencilAttachmentID, 0, GL_DEPTH24_STENCIL8, m_Specification.width, m_Specification.height);
|
||||
// glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, m_DepthStencilAttachmentID, 0);
|
||||
|
||||
LT_ENGINE_ASSERT((glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE), "glFramebuffer::Validate: framebuffer is incomplete");
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,100 +1,100 @@
|
|||
#include "glGraphicsContext.h"
|
||||
|
||||
#include "Events/WindowEvents.h"
|
||||
|
||||
#include "Graphics/Blender.h" // required for forward declaration
|
||||
#include "Graphics/Buffers.h" // required for forward declaration
|
||||
#include "Graphics/Renderer.h" // required for forward declaration
|
||||
#include "Graphics/RenderCommand.h" // required for forward declaration
|
||||
|
||||
#include "Graphics/Blender.h" // required for forward declaration
|
||||
#include "Graphics/Buffers.h" // required for forward declaration
|
||||
#include "Graphics/RenderCommand.h" // required for forward declaration
|
||||
#include "Graphics/Renderer.h" // required for forward declaration
|
||||
#include "UserInterface/UserInterface.h" // required for forward declaration
|
||||
|
||||
#include "Utility/ResourceManager.h" // required for forward declaration
|
||||
#include "Utility/ResourceManager.h" // required for forward declaration
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#ifndef STOP_FUCKING_ORDERING_THESE_THE_WRONG_WAY_CLANG_FORMAT____
|
||||
#include <GLFW/glfw3.h>
|
||||
#endif
|
||||
|
||||
namespace Light {
|
||||
|
||||
glGraphicsContext::glGraphicsContext(GLFWwindow* windowHandle)
|
||||
: m_WindowHandle(windowHandle)
|
||||
{
|
||||
// set 'GraphicsAPI'
|
||||
m_GraphicsAPI = GraphicsAPI::OpenGL;
|
||||
glGraphicsContext::glGraphicsContext(GLFWwindow* windowHandle)
|
||||
: m_WindowHandle(windowHandle)
|
||||
{
|
||||
// set 'GraphicsAPI'
|
||||
m_GraphicsAPI = GraphicsAPI::OpenGL;
|
||||
|
||||
// make context current
|
||||
glfwMakeContextCurrent(windowHandle);
|
||||
|
||||
// load opengl (glad)
|
||||
LT_ENGINE_ASSERT(gladLoadGLLoader((GLADloadproc)glfwGetProcAddress), "glGraphicsContext::glGraphicsContext: failed to initialize opengl (glad)");
|
||||
// make context current
|
||||
glfwMakeContextCurrent(windowHandle);
|
||||
|
||||
SetDebugMessageCallback();
|
||||
}
|
||||
// load opengl (glad)
|
||||
ASSERT(gladLoadGLLoader((GLADloadproc)glfwGetProcAddress), "Failed to initialize opengl (glad)");
|
||||
|
||||
void glGraphicsContext::LogDebugData()
|
||||
{
|
||||
// #todo: log more information
|
||||
LT_ENGINE_INFO("________________________________________");
|
||||
LT_ENGINE_INFO("GraphicsContext::");
|
||||
LT_ENGINE_INFO(" API : OpenGL");
|
||||
LT_ENGINE_INFO(" Version : {}", glGetString(GL_VERSION));
|
||||
LT_ENGINE_INFO(" Renderer: {}", glGetString(GL_RENDERER));
|
||||
LT_ENGINE_INFO("________________________________________");
|
||||
}
|
||||
SetDebugMessageCallback();
|
||||
}
|
||||
|
||||
void glGraphicsContext::SetDebugMessageCallback()
|
||||
{
|
||||
// determine log level
|
||||
// #todo: set filters from config.h
|
||||
void glGraphicsContext::LogDebugData()
|
||||
{
|
||||
// #todo: log more information
|
||||
LOG(info, "________________________________________");
|
||||
LOG(info, "GraphicsContext::");
|
||||
LOG(info, " API : OpenGL");
|
||||
LOG(info, " Version : {}", glGetString(GL_VERSION));
|
||||
LOG(info, " Renderer: {}", glGetString(GL_RENDERER));
|
||||
LOG(info, "________________________________________");
|
||||
}
|
||||
|
||||
void glGraphicsContext::SetDebugMessageCallback()
|
||||
{
|
||||
// determine log level
|
||||
// #todo: set filters from config.h
|
||||
#if defined(LIGHT_DEBUG)
|
||||
glEnable(GL_DEBUG_OUTPUT);
|
||||
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr , GL_TRUE);
|
||||
glEnable(GL_DEBUG_OUTPUT);
|
||||
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE);
|
||||
|
||||
GLuint ids[] =
|
||||
{
|
||||
131185
|
||||
};
|
||||
glDebugMessageControl(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_OTHER, GL_DONT_CARE, _countof(ids), ids, GL_FALSE);
|
||||
GLuint ids[] = {
|
||||
131185
|
||||
};
|
||||
glDebugMessageControl(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_OTHER, GL_DONT_CARE, _countof(ids), ids, GL_FALSE);
|
||||
#elif defined(LIGHT_RELEASE)
|
||||
glEnable(GL_DEBUG_OUTPUT);
|
||||
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_FALSE);
|
||||
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_HIGH, 0, nullptr, GL_TRUE);
|
||||
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_MEDIUM, 0, nullptr, GL_TRUE);
|
||||
glEnable(GL_DEBUG_OUTPUT);
|
||||
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_FALSE);
|
||||
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_HIGH, 0, nullptr, GL_TRUE);
|
||||
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_MEDIUM, 0, nullptr, GL_TRUE);
|
||||
#else // LIGHT_DIST
|
||||
return;
|
||||
return;
|
||||
#endif
|
||||
|
||||
/* setup message callback */
|
||||
glDebugMessageCallback([](unsigned int source, unsigned int type,
|
||||
unsigned int id, unsigned int severity,
|
||||
int length, const char* message,
|
||||
const void* userParam)
|
||||
/* setup message callback */
|
||||
glDebugMessageCallback([](unsigned int source, unsigned int type,
|
||||
unsigned int id, unsigned int severity,
|
||||
int length, const char* message,
|
||||
const void* userParam) {
|
||||
switch (severity)
|
||||
{
|
||||
switch (severity)
|
||||
{
|
||||
case GL_DEBUG_SEVERITY_HIGH:
|
||||
// throw glException(source, type, id, message);
|
||||
return;
|
||||
case GL_DEBUG_SEVERITY_HIGH:
|
||||
// throw glException(source, type, id, message);
|
||||
return;
|
||||
|
||||
case GL_DEBUG_SEVERITY_MEDIUM: case GL_DEBUG_SEVERITY_LOW:
|
||||
LT_ENGINE_WARN("glMessageCallback: Severity: {} :: Source: {} :: Type: {} :: ID: {}",
|
||||
Stringifier::glDebugMsgSeverity(severity),
|
||||
Stringifier::glDebugMsgSource(source),
|
||||
Stringifier::glDebugMsgType(type),
|
||||
id);
|
||||
LT_ENGINE_WARN(" {}", message);
|
||||
return;
|
||||
|
||||
case GL_DEBUG_SEVERITY_NOTIFICATION:
|
||||
LT_ENGINE_TRACE("glMessageCallback: Severity: {} :: Source: {} :: Type: {} :: ID: {}",
|
||||
Stringifier::glDebugMsgSeverity(severity),
|
||||
Stringifier::glDebugMsgSource(source),
|
||||
Stringifier::glDebugMsgType(type),
|
||||
id);
|
||||
LT_ENGINE_TRACE(" {}", message);
|
||||
return;
|
||||
}
|
||||
}, nullptr);
|
||||
}
|
||||
case GL_DEBUG_SEVERITY_MEDIUM:
|
||||
case GL_DEBUG_SEVERITY_LOW:
|
||||
LOG(warn, "glMessageCallback: Severity: {} :: Source: {} :: Type: {} :: ID: {}",
|
||||
Stringifier::glDebugMsgSeverity(severity),
|
||||
Stringifier::glDebugMsgSource(source),
|
||||
Stringifier::glDebugMsgType(type),
|
||||
id);
|
||||
LOG(warn, " {}", message);
|
||||
return;
|
||||
|
||||
case GL_DEBUG_SEVERITY_NOTIFICATION:
|
||||
LOG(trace, "Severity: {} :: Source: {} :: Type: {} :: ID: {}",
|
||||
Stringifier::glDebugMsgSeverity(severity),
|
||||
Stringifier::glDebugMsgSource(source),
|
||||
Stringifier::glDebugMsgType(type),
|
||||
id);
|
||||
LOG(trace, " {}", message);
|
||||
return;
|
||||
}
|
||||
},
|
||||
nullptr);
|
||||
}
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -61,8 +61,8 @@ shaderc::SpvCompilationResult glShader::CompileGLSL(BasicFileHandle file, Shader
|
|||
// log error
|
||||
if (result.GetCompilationStatus() != shaderc_compilation_status_success)
|
||||
{
|
||||
LT_ENGINE_ERROR("Failed to compile {} shader at {}...", stage == Shader::Stage::VERTEX ? "vertex" : "pixel", file.GetPath());
|
||||
LT_ENGINE_ERROR(" {}", result.GetErrorMessage());
|
||||
LOG(err, "Failed to compile {} shader at {}...", stage == Shader::Stage::VERTEX ? "vertex" : "pixel", file.GetPath());
|
||||
LOG(err, " {}", result.GetErrorMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -92,7 +92,7 @@ unsigned int glShader::CompileShader(std::string source, Shader::Stage stage)
|
|||
char* errorLog = (char*)alloca(logLength);
|
||||
glGetShaderInfoLog(shader, logLength, &logLength, &errorLog[0]);
|
||||
|
||||
LT_ENGINE_ERROR("glShader::glShader: failed to compile {} shader:\n {}", stage == Shader::Stage::VERTEX ? "Vertex" : "Pixel", errorLog);
|
||||
LOG(err, "glShader::glShader: failed to compile {} shader:\n {}", stage == Shader::Stage::VERTEX ? "Vertex" : "Pixel", errorLog);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ unsigned int glShader::CompileShader(std::string source, Shader::Stage stage)
|
|||
char* infoLog = (char*)alloca(logLength);
|
||||
glGetShaderInfoLog(shader, logLength, &logLength, &infoLog[0]);
|
||||
|
||||
LT_ENGINE_WARN(infoLog);
|
||||
LOG(warn, infoLog);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -30,7 +30,7 @@ glTexture::glTexture(unsigned int width, unsigned int height, unsigned int compo
|
|||
NULL;
|
||||
|
||||
// check
|
||||
LT_ENGINE_ASSERT(format, "glTexture::glTexture: invalid number of components: {}", components);
|
||||
ASSERT(format, "Invalid number of components: {}", components);
|
||||
|
||||
|
||||
// #todo: isn't there something like glTextureImage2D ???
|
||||
|
|
|
@ -3,60 +3,59 @@
|
|||
#include "Input/KeyCodes.h"
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <backends/imgui_impl_glfw.h>
|
||||
#include <backends/imgui_impl_opengl3.h>
|
||||
#include <imgui.h>
|
||||
|
||||
namespace Light {
|
||||
|
||||
void glUserInterface::PlatformImplementation(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext)
|
||||
{
|
||||
m_WindowHandle = windowHandle;
|
||||
void glUserInterface::PlatformImplementation(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext)
|
||||
{
|
||||
m_WindowHandle = windowHandle;
|
||||
|
||||
ImGui_ImplGlfw_InitForOpenGL(windowHandle, false);
|
||||
ImGui_ImplOpenGL3_Init();
|
||||
}
|
||||
ImGui_ImplGlfw_InitForOpenGL(windowHandle, false);
|
||||
ImGui_ImplOpenGL3_Init();
|
||||
}
|
||||
|
||||
glUserInterface::~glUserInterface()
|
||||
{
|
||||
// #todo: handle this in a better way
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
glUserInterface::~glUserInterface()
|
||||
{
|
||||
// #todo: handle this in a better way
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
if (io.IniFilename == "default_gui_layout.ini")
|
||||
io.IniFilename = "user_gui_layout.ini";
|
||||
if (io.IniFilename == "default_gui_layout.ini")
|
||||
io.IniFilename = "user_gui_layout.ini";
|
||||
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
|
||||
void glUserInterface::Begin()
|
||||
{
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
}
|
||||
void glUserInterface::Begin()
|
||||
{
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
}
|
||||
|
||||
void glUserInterface::End()
|
||||
{
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
void glUserInterface::End()
|
||||
{
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
|
||||
ImGui::UpdatePlatformWindows();
|
||||
ImGui::RenderPlatformWindowsDefault();
|
||||
glfwMakeContextCurrent(m_WindowHandle);
|
||||
}
|
||||
ImGui::UpdatePlatformWindows();
|
||||
ImGui::RenderPlatformWindowsDefault();
|
||||
glfwMakeContextCurrent(m_WindowHandle);
|
||||
}
|
||||
|
||||
void glUserInterface::LogDebugData()
|
||||
{
|
||||
// #todo: improve
|
||||
LT_ENGINE_INFO("________________________________________");
|
||||
LT_ENGINE_INFO("UserInterface::");
|
||||
LT_ENGINE_INFO(" API : ImGui");
|
||||
LT_ENGINE_INFO(" Version: {}", ImGui::GetVersion());
|
||||
LT_ENGINE_INFO(" GraphicsAPI : OpenGL");
|
||||
LT_ENGINE_INFO("________________________________________");
|
||||
}
|
||||
void glUserInterface::LogDebugData()
|
||||
{
|
||||
// #todo: improve
|
||||
LOG(info, "________________________________________");
|
||||
LOG(info, "UserInterface::");
|
||||
LOG(info, " API : ImGui");
|
||||
LOG(info, " Version: {}", ImGui::GetVersion());
|
||||
LOG(info, " GraphicsAPI : OpenGL");
|
||||
LOG(info, "________________________________________");
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Light
|
||||
|
|
|
@ -6,92 +6,92 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
glVertexLayout::glVertexLayout(Ref<VertexBuffer> buffer, const std::vector<std::pair<std::string, VertexElementType>>& elements)
|
||||
: m_ArrayID(NULL)
|
||||
glVertexLayout::glVertexLayout(Ref<VertexBuffer> buffer, const std::vector<std::pair<std::string, VertexElementType>>& elements)
|
||||
: m_ArrayID(NULL)
|
||||
{
|
||||
// check
|
||||
ASSERT(std::dynamic_pointer_cast<glVertexBuffer>(buffer), "Failed to cast 'VertexBuffer' to 'glVertexBuffer'");
|
||||
ASSERT(!elements.empty(), "'elements' is empty");
|
||||
|
||||
// local
|
||||
std::vector<glVertexElementDesc> elementsDesc;
|
||||
elementsDesc.reserve(elements.size());
|
||||
unsigned int stride = 0u;
|
||||
|
||||
// extract elements desc
|
||||
for (const auto& element : elements)
|
||||
{
|
||||
// check
|
||||
LT_ENGINE_ASSERT(std::dynamic_pointer_cast<glVertexBuffer>(buffer), "glVertexLayout::glVertexLayout: failed to cast 'VertexBuffer' to 'glVertexBuffer'");
|
||||
LT_ENGINE_ASSERT(!elements.empty(), "glVertexLayout::glVertexLayout: 'elements' is empty");
|
||||
|
||||
// local
|
||||
std::vector<glVertexElementDesc> elementsDesc;
|
||||
elementsDesc.reserve(elements.size());
|
||||
unsigned int stride = 0u;
|
||||
|
||||
// extract elements desc
|
||||
for(const auto& element : elements)
|
||||
{
|
||||
elementsDesc.push_back(GetElementDesc(element.second, stride));
|
||||
stride += elementsDesc.back().typeSize * elementsDesc.back().count;
|
||||
}
|
||||
|
||||
// create vertex array
|
||||
glCreateVertexArrays(1, &m_ArrayID);
|
||||
|
||||
// bind buffer and array
|
||||
buffer->Bind();
|
||||
Bind();
|
||||
|
||||
// enable vertex attributes
|
||||
unsigned int index = 0u;
|
||||
for (const auto& elementDesc : elementsDesc)
|
||||
{
|
||||
glVertexAttribPointer(index, elementDesc.count, elementDesc.type, GL_FALSE, stride, (const void*)elementDesc.offset);
|
||||
glEnableVertexAttribArray(index++);
|
||||
}
|
||||
elementsDesc.push_back(GetElementDesc(element.second, stride));
|
||||
stride += elementsDesc.back().typeSize * elementsDesc.back().count;
|
||||
}
|
||||
|
||||
glVertexLayout::~glVertexLayout()
|
||||
// create vertex array
|
||||
glCreateVertexArrays(1, &m_ArrayID);
|
||||
|
||||
// bind buffer and array
|
||||
buffer->Bind();
|
||||
Bind();
|
||||
|
||||
// enable vertex attributes
|
||||
unsigned int index = 0u;
|
||||
for (const auto& elementDesc : elementsDesc)
|
||||
{
|
||||
glDeleteVertexArrays(1, &m_ArrayID);
|
||||
glVertexAttribPointer(index, elementDesc.count, elementDesc.type, GL_FALSE, stride, (const void*)elementDesc.offset);
|
||||
glEnableVertexAttribArray(index++);
|
||||
}
|
||||
}
|
||||
|
||||
void glVertexLayout::Bind()
|
||||
glVertexLayout::~glVertexLayout()
|
||||
{
|
||||
glDeleteVertexArrays(1, &m_ArrayID);
|
||||
}
|
||||
|
||||
void glVertexLayout::Bind()
|
||||
{
|
||||
glBindVertexArray(m_ArrayID);
|
||||
}
|
||||
|
||||
void glVertexLayout::UnBind()
|
||||
{
|
||||
glBindVertexArray(NULL);
|
||||
}
|
||||
|
||||
glVertexElementDesc glVertexLayout::GetElementDesc(VertexElementType type, unsigned int offset)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
glBindVertexArray(m_ArrayID);
|
||||
/* byte */
|
||||
case Light::VertexElementType::Byte1: return { GL_BYTE, 1u, sizeof(GLbyte), offset };
|
||||
case Light::VertexElementType::Byte2: return { GL_BYTE, 1u, sizeof(GLbyte), offset };
|
||||
case Light::VertexElementType::Byte4: return { GL_BYTE, 1u, sizeof(GLbyte), offset };
|
||||
|
||||
/* ubyte */
|
||||
case Light::VertexElementType::UByte1: return { GL_UNSIGNED_BYTE, 1u, sizeof(GLubyte), offset };
|
||||
case Light::VertexElementType::UByte2: return { GL_UNSIGNED_BYTE, 2u, sizeof(GLubyte), offset };
|
||||
case Light::VertexElementType::UByte4: return { GL_UNSIGNED_BYTE, 4u, sizeof(GLubyte), offset };
|
||||
|
||||
/* int */
|
||||
case VertexElementType::Int1: return { GL_INT, 1u, sizeof(GLint), offset };
|
||||
case VertexElementType::Int2: return { GL_INT, 2u, sizeof(GLint), offset };
|
||||
case VertexElementType::Int3: return { GL_INT, 3u, sizeof(GLint), offset };
|
||||
case VertexElementType::Int4: return { GL_INT, 4u, sizeof(GLint), offset };
|
||||
|
||||
/* uint */
|
||||
case VertexElementType::UInt1: return { GL_UNSIGNED_INT, 1u, sizeof(GLuint), offset };
|
||||
case VertexElementType::UInt2: return { GL_UNSIGNED_INT, 2u, sizeof(GLuint), offset };
|
||||
case VertexElementType::UInt3: return { GL_UNSIGNED_INT, 3u, sizeof(GLuint), offset };
|
||||
case VertexElementType::UInt4: return { GL_UNSIGNED_INT, 4u, sizeof(GLuint), offset };
|
||||
|
||||
/* float */
|
||||
case VertexElementType::Float1: return { GL_FLOAT, 1u, sizeof(GLfloat), offset };
|
||||
case VertexElementType::Float2: return { GL_FLOAT, 2u, sizeof(GLfloat), offset };
|
||||
case VertexElementType::Float3: return { GL_FLOAT, 3u, sizeof(GLfloat), offset };
|
||||
case VertexElementType::Float4: return { GL_FLOAT, 4u, sizeof(GLfloat), offset };
|
||||
|
||||
default:
|
||||
ASSERT(false, "Invalid 'VertexElementType'");
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
void glVertexLayout::UnBind()
|
||||
{
|
||||
glBindVertexArray(NULL);
|
||||
}
|
||||
|
||||
glVertexElementDesc glVertexLayout::GetElementDesc(VertexElementType type, unsigned int offset)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
/* byte */
|
||||
case Light::VertexElementType::Byte1: return { GL_BYTE, 1u, sizeof(GLbyte), offset };
|
||||
case Light::VertexElementType::Byte2: return { GL_BYTE, 1u, sizeof(GLbyte), offset };
|
||||
case Light::VertexElementType::Byte4: return { GL_BYTE, 1u, sizeof(GLbyte), offset };
|
||||
|
||||
/* ubyte */
|
||||
case Light::VertexElementType::UByte1: return { GL_UNSIGNED_BYTE, 1u, sizeof(GLubyte), offset };
|
||||
case Light::VertexElementType::UByte2: return { GL_UNSIGNED_BYTE, 2u, sizeof(GLubyte), offset };
|
||||
case Light::VertexElementType::UByte4: return { GL_UNSIGNED_BYTE, 4u, sizeof(GLubyte), offset };
|
||||
|
||||
/* int */
|
||||
case VertexElementType::Int1: return { GL_INT, 1u, sizeof(GLint), offset };
|
||||
case VertexElementType::Int2: return { GL_INT, 2u, sizeof(GLint), offset };
|
||||
case VertexElementType::Int3: return { GL_INT, 3u, sizeof(GLint), offset };
|
||||
case VertexElementType::Int4: return { GL_INT, 4u, sizeof(GLint), offset };
|
||||
|
||||
/* uint */
|
||||
case VertexElementType::UInt1: return { GL_UNSIGNED_INT, 1u, sizeof(GLuint), offset };
|
||||
case VertexElementType::UInt2: return { GL_UNSIGNED_INT, 2u, sizeof(GLuint), offset };
|
||||
case VertexElementType::UInt3: return { GL_UNSIGNED_INT, 3u, sizeof(GLuint), offset };
|
||||
case VertexElementType::UInt4: return { GL_UNSIGNED_INT, 4u, sizeof(GLuint), offset };
|
||||
|
||||
/* float */
|
||||
case VertexElementType::Float1: return { GL_FLOAT, 1u, sizeof(GLfloat), offset };
|
||||
case VertexElementType::Float2: return { GL_FLOAT, 2u, sizeof(GLfloat), offset };
|
||||
case VertexElementType::Float3: return { GL_FLOAT, 3u, sizeof(GLfloat), offset };
|
||||
case VertexElementType::Float4: return { GL_FLOAT, 4u, sizeof(GLfloat), offset };
|
||||
|
||||
default:
|
||||
LT_ENGINE_ASSERT(false, "glVertexLayout::GetElementDesc: invalid 'VertexElementType'");
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,237 +1,228 @@
|
|||
#include "lWindow.h"
|
||||
|
||||
#include "Events/Event.h"
|
||||
#include "Events/CharEvent.h"
|
||||
#include "Events/MouseEvents.h"
|
||||
#include "Events/Event.h"
|
||||
#include "Events/KeyboardEvents.h"
|
||||
#include "Events/MouseEvents.h"
|
||||
#include "Events/WindowEvents.h"
|
||||
|
||||
#include "Graphics/GraphicsContext.h"
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
namespace Light {
|
||||
|
||||
Scope<Window> Window::Create(std::function<void(Event&)> callback)
|
||||
{
|
||||
return CreateScope<lWindow>(callback);
|
||||
}
|
||||
|
||||
lWindow::lWindow(std::function<void(Event&)> callback)
|
||||
: m_Handle(nullptr),
|
||||
m_EventCallback(callback)
|
||||
{
|
||||
// init glfw
|
||||
LT_ENGINE_ASSERT(glfwInit(), "lWindow::lWindow: failed to initialize 'glfw'");
|
||||
|
||||
// create window
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
|
||||
|
||||
m_Handle = glfwCreateWindow(1u, 1u, "", nullptr, nullptr);
|
||||
LT_ENGINE_ASSERT(m_Handle, "lWindow::lWindow: failed to create 'GLFWwindow'");
|
||||
|
||||
// bind event stuff
|
||||
glfwSetWindowUserPointer(m_Handle, &m_EventCallback);
|
||||
BindGlfwEvents();
|
||||
|
||||
// create graphics context
|
||||
m_GraphicsContext = GraphicsContext::Create(GraphicsAPI::OpenGL, m_Handle);
|
||||
LT_ENGINE_ASSERT(m_GraphicsContext, "lWindow::lWindow: failed to create 'GraphicsContext'");
|
||||
}
|
||||
|
||||
lWindow::~lWindow()
|
||||
{
|
||||
glfwDestroyWindow(m_Handle);
|
||||
}
|
||||
|
||||
void lWindow::PollEvents()
|
||||
{
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
void lWindow::OnEvent(const Event& event)
|
||||
Scope<Window> Window::Create(std::function<void(Event&)> callback)
|
||||
{
|
||||
return CreateScope<lWindow>(callback);
|
||||
}
|
||||
|
||||
lWindow::lWindow(std::function<void(Event&)> callback)
|
||||
: m_Handle(nullptr), m_EventCallback(callback)
|
||||
{
|
||||
// init glfw
|
||||
ASSERT(glfwInit(), "lWindow::lWindow: failed to initialize 'glfw'");
|
||||
|
||||
// create window
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
|
||||
|
||||
m_Handle = glfwCreateWindow(1u, 1u, "", nullptr, nullptr);
|
||||
ASSERT(m_Handle, "lWindow::lWindow: failed to create 'GLFWwindow'");
|
||||
|
||||
// bind event stuff
|
||||
glfwSetWindowUserPointer(m_Handle, &m_EventCallback);
|
||||
BindGlfwEvents();
|
||||
|
||||
// create graphics context
|
||||
m_GraphicsContext = GraphicsContext::Create(GraphicsAPI::OpenGL, m_Handle);
|
||||
ASSERT(m_GraphicsContext, "lWindow::lWindow: failed to create 'GraphicsContext'");
|
||||
}
|
||||
|
||||
lWindow::~lWindow()
|
||||
{
|
||||
glfwDestroyWindow(m_Handle);
|
||||
}
|
||||
|
||||
void lWindow::PollEvents()
|
||||
{
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
void lWindow::OnEvent(const Event& event)
|
||||
{
|
||||
switch (event.GetEventType())
|
||||
{
|
||||
switch (event.GetEventType())
|
||||
/* closed */
|
||||
case EventType::WindowClosed:
|
||||
b_Closed = true;
|
||||
break;
|
||||
|
||||
/* resized */
|
||||
case EventType::WindowResized:
|
||||
OnWindowResize((const WindowResizedEvent&)event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void lWindow::OnWindowResize(const WindowResizedEvent& event)
|
||||
{
|
||||
m_Properties.size = event.GetSize();
|
||||
}
|
||||
|
||||
void lWindow::SetProperties(const WindowProperties& properties, bool overrideVisibility /* = false */)
|
||||
{
|
||||
// save the visibility status and re-assign if 'overrideVisibility' is false
|
||||
bool visible = overrideVisibility ? properties.visible : m_Properties.visible;
|
||||
m_Properties = properties;
|
||||
m_Properties.visible = visible;
|
||||
|
||||
// set properties
|
||||
SetTitle(properties.title);
|
||||
SetSize(properties.size);
|
||||
SetVSync(properties.vsync);
|
||||
SetVisibility(visible);
|
||||
}
|
||||
|
||||
void lWindow::SetTitle(const std::string& title)
|
||||
{
|
||||
m_Properties.title = title;
|
||||
|
||||
glfwSetWindowTitle(m_Handle, title.c_str());
|
||||
}
|
||||
|
||||
void lWindow::SetSize(const glm::uvec2& size, bool additive /* = false */)
|
||||
{
|
||||
m_Properties.size.x = size.x == 0u ? m_Properties.size.x : additive ? m_Properties.size.x + size.x :
|
||||
size.x;
|
||||
m_Properties.size.y = size.y == 0u ? m_Properties.size.y : additive ? m_Properties.size.y + size.y :
|
||||
size.y;
|
||||
|
||||
|
||||
glfwSetWindowSize(m_Handle, size.x, size.y);
|
||||
}
|
||||
|
||||
void lWindow::SetVSync(bool vsync, bool toggle /* = false */)
|
||||
{
|
||||
m_Properties.vsync = toggle ? !m_Properties.vsync : vsync;
|
||||
|
||||
glfwSwapInterval(m_Properties.vsync);
|
||||
}
|
||||
|
||||
void lWindow::SetVisibility(bool visible, bool toggle)
|
||||
{
|
||||
m_Properties.visible = toggle ? !m_Properties.visible : visible;
|
||||
|
||||
if (m_Properties.visible)
|
||||
glfwShowWindow(m_Handle);
|
||||
else
|
||||
glfwHideWindow(m_Handle);
|
||||
}
|
||||
|
||||
void lWindow::BindGlfwEvents()
|
||||
{
|
||||
//============================== MOUSE_EVENTS ==============================//
|
||||
/* cursor position */
|
||||
glfwSetCursorPosCallback(m_Handle, [](GLFWwindow* window, double xpos, double ypos) {
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
|
||||
MouseMovedEvent event(xpos, ypos);
|
||||
callback(event);
|
||||
});
|
||||
|
||||
/* mouse button */
|
||||
glfwSetMouseButtonCallback(m_Handle, [](GLFWwindow* window, int button, int action, int mods) {
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
|
||||
if (action == GLFW_PRESS)
|
||||
{
|
||||
/* closed */
|
||||
case EventType::WindowClosed:
|
||||
b_Closed = true;
|
||||
break;
|
||||
|
||||
/* resized */
|
||||
case EventType::WindowResized:
|
||||
OnWindowResize((const WindowResizedEvent&)event);
|
||||
break;
|
||||
ButtonPressedEvent event(button);
|
||||
callback(event);
|
||||
}
|
||||
}
|
||||
|
||||
void lWindow::OnWindowResize(const WindowResizedEvent& event)
|
||||
{
|
||||
m_Properties.size = event.GetSize();
|
||||
}
|
||||
else if (action == GLFW_RELEASE)
|
||||
{
|
||||
ButtonReleasedEvent event(button);
|
||||
callback(event);
|
||||
}
|
||||
});
|
||||
|
||||
void lWindow::SetProperties(const WindowProperties& properties, bool overrideVisibility /* = false */)
|
||||
{
|
||||
// save the visibility status and re-assign if 'overrideVisibility' is false
|
||||
bool visible = overrideVisibility ? properties.visible : m_Properties.visible;
|
||||
m_Properties = properties;
|
||||
m_Properties.visible = visible;
|
||||
/* scroll */
|
||||
glfwSetScrollCallback(m_Handle, [](GLFWwindow* window, double xoffset, double yoffset) {
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
|
||||
// set properties
|
||||
SetTitle(properties.title);
|
||||
SetSize(properties.size);
|
||||
SetVSync(properties.vsync);
|
||||
SetVisibility(visible);
|
||||
}
|
||||
|
||||
void lWindow::SetTitle(const std::string& title)
|
||||
{
|
||||
m_Properties.title = title;
|
||||
|
||||
glfwSetWindowTitle(m_Handle, title.c_str());
|
||||
}
|
||||
|
||||
void lWindow::SetSize(const glm::uvec2& size, bool additive /* = false */)
|
||||
{
|
||||
m_Properties.size.x = size.x == 0u ? m_Properties.size.x : additive ? m_Properties.size.x + size.x : size.x;
|
||||
m_Properties.size.y = size.y == 0u ? m_Properties.size.y : additive ? m_Properties.size.y + size.y : size.y;
|
||||
|
||||
|
||||
glfwSetWindowSize(m_Handle, size.x, size.y);
|
||||
}
|
||||
|
||||
void lWindow::SetVSync(bool vsync, bool toggle /* = false */)
|
||||
{
|
||||
m_Properties.vsync = toggle ? !m_Properties.vsync : vsync;
|
||||
|
||||
glfwSwapInterval(m_Properties.vsync);
|
||||
}
|
||||
|
||||
void lWindow::SetVisibility(bool visible, bool toggle)
|
||||
{
|
||||
m_Properties.visible = toggle ? !m_Properties.visible : visible;
|
||||
|
||||
if(m_Properties.visible)
|
||||
glfwShowWindow(m_Handle);
|
||||
WheelScrolledEvent event(yoffset);
|
||||
callback(event);
|
||||
});
|
||||
//============================== MOUSE_EVENTS ==============================//
|
||||
|
||||
//============================== KEYBOARD_EVENTS ==============================//
|
||||
/* key */
|
||||
glfwSetKeyCallback(m_Handle, [](GLFWwindow* window, int key, int scancode, int action, int mods) {
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
|
||||
if (action == GLFW_PRESS)
|
||||
{
|
||||
KeyPressedEvent event(key);
|
||||
callback(event);
|
||||
}
|
||||
else if (action == GLFW_RELEASE)
|
||||
{
|
||||
KeyReleasedEvent event(key);
|
||||
callback(event);
|
||||
}
|
||||
});
|
||||
/* char */
|
||||
glfwSetCharCallback(m_Handle, [](GLFWwindow* window, unsigned int character) {
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
|
||||
SetCharEvent event(character);
|
||||
callback(event);
|
||||
});
|
||||
|
||||
//============================== KEYBOARD_EVENTS ==============================//
|
||||
|
||||
//============================== WINDOW_EVENTS ==============================//
|
||||
/* window position */
|
||||
glfwSetWindowPosCallback(m_Handle, [](GLFWwindow* window, int xpos, int ypos) {
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
WindowMovedEvent event(xpos, ypos);
|
||||
|
||||
callback(event);
|
||||
});
|
||||
|
||||
/* window size */
|
||||
glfwSetWindowSizeCallback(m_Handle, [](GLFWwindow* window, int width, int height) {
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
WindowResizedEvent event(width, height);
|
||||
|
||||
callback(event);
|
||||
});
|
||||
|
||||
/* window close */
|
||||
glfwSetWindowCloseCallback(m_Handle, [](GLFWwindow* window) {
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
WindowClosedEvent event;
|
||||
|
||||
callback(event);
|
||||
});
|
||||
|
||||
/* window focus */
|
||||
glfwSetWindowFocusCallback(m_Handle, [](GLFWwindow* window, int focus) {
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
|
||||
if (focus == GLFW_TRUE)
|
||||
{
|
||||
WindowGainFocusEvent event;
|
||||
callback(event);
|
||||
}
|
||||
else
|
||||
glfwHideWindow(m_Handle);
|
||||
}
|
||||
|
||||
void lWindow::BindGlfwEvents()
|
||||
{
|
||||
//============================== MOUSE_EVENTS ==============================//
|
||||
/* cursor position */
|
||||
glfwSetCursorPosCallback(m_Handle, [](GLFWwindow* window, double xpos, double ypos)
|
||||
{
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
|
||||
MouseMovedEvent event(xpos, ypos);
|
||||
WindowLostFocusEvent event;
|
||||
callback(event);
|
||||
});
|
||||
|
||||
/* mouse button */
|
||||
glfwSetMouseButtonCallback(m_Handle, [](GLFWwindow* window, int button, int action, int mods)
|
||||
{
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
|
||||
if(action == GLFW_PRESS)
|
||||
{
|
||||
ButtonPressedEvent event(button);
|
||||
callback(event);
|
||||
}
|
||||
else if(action == GLFW_RELEASE)
|
||||
{
|
||||
ButtonReleasedEvent event(button);
|
||||
callback(event);
|
||||
}
|
||||
});
|
||||
|
||||
/* scroll */
|
||||
glfwSetScrollCallback(m_Handle, [](GLFWwindow* window, double xoffset, double yoffset)
|
||||
{
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
}
|
||||
});
|
||||
//============================== WINDOW_EVENTS ==============================//
|
||||
}
|
||||
|
||||
WheelScrolledEvent event(yoffset);
|
||||
callback(event);
|
||||
});
|
||||
//============================== MOUSE_EVENTS ==============================//
|
||||
|
||||
//============================== KEYBOARD_EVENTS ==============================//
|
||||
/* key */
|
||||
glfwSetKeyCallback(m_Handle, [](GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
|
||||
if(action == GLFW_PRESS)
|
||||
{
|
||||
KeyPressedEvent event(key);
|
||||
callback(event);
|
||||
}
|
||||
else if(action == GLFW_RELEASE)
|
||||
{
|
||||
KeyReleasedEvent event(key);
|
||||
callback(event);
|
||||
}
|
||||
});
|
||||
/* char */
|
||||
glfwSetCharCallback(m_Handle, [](GLFWwindow* window, unsigned int character)
|
||||
{
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
|
||||
SetCharEvent event(character);
|
||||
callback(event);
|
||||
});
|
||||
|
||||
//============================== KEYBOARD_EVENTS ==============================//
|
||||
|
||||
//============================== WINDOW_EVENTS ==============================//
|
||||
/* window position */
|
||||
glfwSetWindowPosCallback(m_Handle, [](GLFWwindow* window, int xpos, int ypos)
|
||||
{
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
WindowMovedEvent event(xpos, ypos);
|
||||
|
||||
callback(event);
|
||||
});
|
||||
|
||||
/* window size */
|
||||
glfwSetWindowSizeCallback(m_Handle, [](GLFWwindow* window, int width, int height)
|
||||
{
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
WindowResizedEvent event(width, height);
|
||||
|
||||
callback(event);
|
||||
});
|
||||
|
||||
/* window close */
|
||||
glfwSetWindowCloseCallback(m_Handle, [](GLFWwindow* window)
|
||||
{
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
WindowClosedEvent event;
|
||||
|
||||
callback(event);
|
||||
});
|
||||
|
||||
/* window focus */
|
||||
glfwSetWindowFocusCallback(m_Handle, [](GLFWwindow* window, int focus)
|
||||
{
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
|
||||
if(focus == GLFW_TRUE)
|
||||
{
|
||||
WindowGainFocusEvent event;
|
||||
callback(event);
|
||||
}
|
||||
else
|
||||
{
|
||||
WindowLostFocusEvent event;
|
||||
callback(event);
|
||||
}
|
||||
});
|
||||
//============================== WINDOW_EVENTS ==============================//
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Light
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
#include "wWindow.h"
|
||||
|
||||
#include "Events/Event.h"
|
||||
#include "Events/CharEvent.h"
|
||||
#include "Events/MouseEvents.h"
|
||||
#include "Events/Event.h"
|
||||
#include "Events/KeyboardEvents.h"
|
||||
#include "Events/MouseEvents.h"
|
||||
#include "Events/WindowEvents.h"
|
||||
|
||||
|
||||
#include "Graphics/GraphicsContext.h"
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
@ -14,231 +12,223 @@
|
|||
extern "C"
|
||||
{
|
||||
// Force Machine to use Dedicated Graphics
|
||||
__declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001; // NVidia
|
||||
__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; // AMD
|
||||
__declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001; // NVidia
|
||||
__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; // AMD
|
||||
}
|
||||
|
||||
namespace Light {
|
||||
|
||||
Scope<Window> Window::Create(std::function<void(Event&)> callback)
|
||||
Scope<Window> Window::Create(std::function<void(Event&)> callback)
|
||||
{
|
||||
return CreateScope<wWindow>(callback);
|
||||
}
|
||||
|
||||
wWindow::wWindow(std::function<void(Event&)> callback)
|
||||
: m_Handle(nullptr), m_EventCallback(callback)
|
||||
{
|
||||
// init glfw
|
||||
ASSERT(glfwInit(), "wWindow::wWindow: failed to initialize 'glfw'");
|
||||
|
||||
// create window
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
|
||||
|
||||
m_Handle = glfwCreateWindow(1u, 1u, "", nullptr, nullptr);
|
||||
ASSERT(m_Handle, "wWindow::wWindow: glfwCreateWindow: failed to create 'GLFWwindow'");
|
||||
|
||||
// bind event stuff
|
||||
glfwSetWindowUserPointer(m_Handle, &m_EventCallback);
|
||||
BindGlfwEvents();
|
||||
|
||||
// create graphics context
|
||||
m_GraphicsContext = GraphicsContext::Create(GraphicsAPI::DirectX, m_Handle);
|
||||
ASSERT(m_GraphicsContext, "wWindow::wWindow: failed to create 'GraphicsContext'");
|
||||
}
|
||||
|
||||
wWindow::~wWindow()
|
||||
{
|
||||
glfwDestroyWindow(m_Handle);
|
||||
}
|
||||
|
||||
void wWindow::PollEvents()
|
||||
{
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
void wWindow::OnEvent(const Event& event)
|
||||
{
|
||||
switch (event.GetEventType())
|
||||
{
|
||||
return CreateScope<wWindow>(callback);
|
||||
/* closed */
|
||||
case EventType::WindowClosed:
|
||||
b_Closed = true;
|
||||
break;
|
||||
|
||||
/* resized */
|
||||
case EventType::WindowResized:
|
||||
OnWindowResize((const WindowResizedEvent&)event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
wWindow::wWindow(std::function<void(Event&)> callback)
|
||||
: m_Handle(nullptr),
|
||||
m_EventCallback(callback)
|
||||
{
|
||||
// init glfw
|
||||
LT_ENGINE_ASSERT(glfwInit(), "wWindow::wWindow: failed to initialize 'glfw'");
|
||||
void wWindow::OnWindowResize(const WindowResizedEvent& event)
|
||||
{
|
||||
m_Properties.size = event.GetSize();
|
||||
}
|
||||
|
||||
// create window
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
|
||||
void wWindow::SetProperties(const WindowProperties& properties, bool overrideVisiblity /* = false */)
|
||||
{
|
||||
// save the visibility status and re-assign if 'overrideVisibility' is false
|
||||
bool visible = overrideVisiblity ? properties.visible : m_Properties.visible;
|
||||
m_Properties = properties;
|
||||
m_Properties.visible = visible;
|
||||
|
||||
m_Handle = glfwCreateWindow(1u, 1u, "", nullptr, nullptr);
|
||||
LT_ENGINE_ASSERT(m_Handle, "wWindow::wWindow: glfwCreateWindow: failed to create 'GLFWwindow'");
|
||||
// set properties
|
||||
SetTitle(properties.title);
|
||||
SetSize(properties.size);
|
||||
SetVSync(properties.vsync);
|
||||
SetVisibility(visible);
|
||||
}
|
||||
|
||||
// bind event stuff
|
||||
glfwSetWindowUserPointer(m_Handle, &m_EventCallback);
|
||||
BindGlfwEvents();
|
||||
void wWindow::SetTitle(const std::string& title)
|
||||
{
|
||||
m_Properties.title = title;
|
||||
|
||||
// create graphics context
|
||||
m_GraphicsContext = GraphicsContext::Create(GraphicsAPI::DirectX, m_Handle);
|
||||
LT_ENGINE_ASSERT(m_GraphicsContext, "wWindow::wWindow: failed to create 'GraphicsContext'");
|
||||
}
|
||||
glfwSetWindowTitle(m_Handle, m_Properties.title.c_str());
|
||||
}
|
||||
|
||||
wWindow::~wWindow()
|
||||
{
|
||||
glfwDestroyWindow(m_Handle);
|
||||
}
|
||||
void wWindow::SetSize(const glm::uvec2& size, bool additive /* = false */)
|
||||
{
|
||||
m_Properties.size.x = size.x == 0u ? m_Properties.size.x : additive ? m_Properties.size.x + size.x :
|
||||
size.x;
|
||||
m_Properties.size.y = size.y == 0u ? m_Properties.size.y : additive ? m_Properties.size.y + size.y :
|
||||
size.y;
|
||||
|
||||
void wWindow::PollEvents()
|
||||
{
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
void wWindow::OnEvent(const Event& event)
|
||||
{
|
||||
switch (event.GetEventType())
|
||||
glfwSetWindowSize(m_Handle, size.x, size.y);
|
||||
}
|
||||
|
||||
void wWindow::SetVSync(bool vsync, bool toggle /* = false */)
|
||||
{
|
||||
m_Properties.vsync = toggle ? !m_Properties.vsync : vsync;
|
||||
|
||||
glfwSwapInterval(m_Properties.vsync);
|
||||
}
|
||||
|
||||
void wWindow::SetVisibility(bool visible, bool toggle)
|
||||
{
|
||||
m_Properties.visible = toggle ? !m_Properties.visible : visible;
|
||||
|
||||
if (m_Properties.visible)
|
||||
glfwShowWindow(m_Handle);
|
||||
else
|
||||
glfwHideWindow(m_Handle);
|
||||
}
|
||||
|
||||
void wWindow::BindGlfwEvents()
|
||||
{
|
||||
//============================== MOUSE_EVENTS ==============================//
|
||||
/* cursor position */
|
||||
glfwSetCursorPosCallback(m_Handle, [](GLFWwindow* window, double xpos, double ypos) {
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
|
||||
MouseMovedEvent event(xpos, ypos);
|
||||
callback(event);
|
||||
});
|
||||
|
||||
/* mouse button */
|
||||
glfwSetMouseButtonCallback(m_Handle, [](GLFWwindow* window, int button, int action, int mods) {
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
|
||||
if (action == GLFW_PRESS)
|
||||
{
|
||||
/* closed */
|
||||
case EventType::WindowClosed:
|
||||
b_Closed = true;
|
||||
break;
|
||||
|
||||
/* resized */
|
||||
case EventType::WindowResized:
|
||||
OnWindowResize((const WindowResizedEvent&)event);
|
||||
break;
|
||||
ButtonPressedEvent event(button);
|
||||
callback(event);
|
||||
}
|
||||
}
|
||||
else if (action == GLFW_RELEASE)
|
||||
{
|
||||
ButtonReleasedEvent event(button);
|
||||
callback(event);
|
||||
}
|
||||
});
|
||||
|
||||
void wWindow::OnWindowResize(const WindowResizedEvent& event)
|
||||
{
|
||||
m_Properties.size = event.GetSize();
|
||||
}
|
||||
/* scroll */
|
||||
glfwSetScrollCallback(m_Handle, [](GLFWwindow* window, double xoffset, double yoffset) {
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
|
||||
void wWindow::SetProperties(const WindowProperties& properties, bool overrideVisiblity /* = false */)
|
||||
{
|
||||
// save the visibility status and re-assign if 'overrideVisibility' is false
|
||||
bool visible = overrideVisiblity ? properties.visible : m_Properties.visible;
|
||||
m_Properties = properties;
|
||||
m_Properties.visible = visible;
|
||||
WheelScrolledEvent event(yoffset);
|
||||
callback(event);
|
||||
});
|
||||
//============================== MOUSE_EVENTS ==============================//
|
||||
|
||||
// set properties
|
||||
SetTitle(properties.title);
|
||||
SetSize(properties.size);
|
||||
SetVSync(properties.vsync);
|
||||
SetVisibility(visible);
|
||||
}
|
||||
//============================== KEYBOARD_EVENTS ==============================//
|
||||
/* key */
|
||||
glfwSetKeyCallback(m_Handle, [](GLFWwindow* window, int key, int scancode, int action, int mods) {
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
|
||||
void wWindow::SetTitle(const std::string& title)
|
||||
{
|
||||
m_Properties.title = title;
|
||||
if (action == GLFW_PRESS)
|
||||
{
|
||||
KeyPressedEvent event(key);
|
||||
callback(event);
|
||||
}
|
||||
else if (action == GLFW_RELEASE)
|
||||
{
|
||||
KeyReleasedEvent event(key);
|
||||
callback(event);
|
||||
}
|
||||
});
|
||||
/* char */
|
||||
glfwSetCharCallback(m_Handle, [](GLFWwindow* window, unsigned int character) {
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
|
||||
glfwSetWindowTitle(m_Handle, m_Properties.title.c_str());
|
||||
}
|
||||
SetCharEvent event(character);
|
||||
callback(event);
|
||||
});
|
||||
|
||||
void wWindow::SetSize(const glm::uvec2& size, bool additive /* = false */)
|
||||
{
|
||||
m_Properties.size.x = size.x == 0u ? m_Properties.size.x : additive ? m_Properties.size.x + size.x : size.x;
|
||||
m_Properties.size.y = size.y == 0u ? m_Properties.size.y : additive ? m_Properties.size.y + size.y : size.y;
|
||||
//============================== KEYBOARD_EVENTS ==============================//
|
||||
|
||||
//============================== WINDOW_EVENTS ==============================//
|
||||
/* window position */
|
||||
glfwSetWindowPosCallback(m_Handle, [](GLFWwindow* window, int xpos, int ypos) {
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
WindowMovedEvent event(xpos, ypos);
|
||||
|
||||
glfwSetWindowSize(m_Handle, size.x, size.y);
|
||||
}
|
||||
callback(event);
|
||||
});
|
||||
|
||||
void wWindow::SetVSync(bool vsync, bool toggle /* = false */)
|
||||
{
|
||||
m_Properties.vsync = toggle ? !m_Properties.vsync : vsync;
|
||||
/* window size */
|
||||
glfwSetWindowSizeCallback(m_Handle, [](GLFWwindow* window, int width, int height) {
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
WindowResizedEvent event(width, height);
|
||||
|
||||
glfwSwapInterval(m_Properties.vsync);
|
||||
}
|
||||
callback(event);
|
||||
});
|
||||
|
||||
void wWindow::SetVisibility(bool visible, bool toggle)
|
||||
{
|
||||
m_Properties.visible = toggle ? !m_Properties.visible : visible;
|
||||
/* window close */
|
||||
glfwSetWindowCloseCallback(m_Handle, [](GLFWwindow* window) {
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
WindowClosedEvent event;
|
||||
|
||||
if (m_Properties.visible)
|
||||
glfwShowWindow(m_Handle);
|
||||
callback(event);
|
||||
});
|
||||
|
||||
/* window focus */
|
||||
glfwSetWindowFocusCallback(m_Handle, [](GLFWwindow* window, int focus) {
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
|
||||
if (focus == GLFW_TRUE)
|
||||
{
|
||||
WindowGainFocusEvent event;
|
||||
callback(event);
|
||||
}
|
||||
else
|
||||
glfwHideWindow(m_Handle);
|
||||
}
|
||||
|
||||
void wWindow::BindGlfwEvents()
|
||||
{
|
||||
//============================== MOUSE_EVENTS ==============================//
|
||||
/* cursor position */
|
||||
glfwSetCursorPosCallback(m_Handle, [](GLFWwindow* window, double xpos, double ypos)
|
||||
{
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
|
||||
MouseMovedEvent event(xpos, ypos);
|
||||
callback(event);
|
||||
});
|
||||
|
||||
/* mouse button */
|
||||
glfwSetMouseButtonCallback(m_Handle, [](GLFWwindow* window, int button, int action, int mods)
|
||||
{
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
|
||||
if (action == GLFW_PRESS)
|
||||
{
|
||||
ButtonPressedEvent event(button);
|
||||
callback(event);
|
||||
}
|
||||
else if (action == GLFW_RELEASE)
|
||||
{
|
||||
ButtonReleasedEvent event(button);
|
||||
callback(event);
|
||||
}
|
||||
});
|
||||
|
||||
/* scroll */
|
||||
glfwSetScrollCallback(m_Handle, [](GLFWwindow* window, double xoffset, double yoffset)
|
||||
{
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
|
||||
WheelScrolledEvent event(yoffset);
|
||||
callback(event);
|
||||
});
|
||||
//============================== MOUSE_EVENTS ==============================//
|
||||
|
||||
//============================== KEYBOARD_EVENTS ==============================//
|
||||
/* key */
|
||||
glfwSetKeyCallback(m_Handle, [](GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
|
||||
if (action == GLFW_PRESS)
|
||||
{
|
||||
KeyPressedEvent event(key);
|
||||
callback(event);
|
||||
}
|
||||
else if (action == GLFW_RELEASE)
|
||||
{
|
||||
KeyReleasedEvent event(key);
|
||||
callback(event);
|
||||
}
|
||||
});
|
||||
/* char */
|
||||
glfwSetCharCallback(m_Handle, [](GLFWwindow* window, unsigned int character)
|
||||
{
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
|
||||
SetCharEvent event(character);
|
||||
callback(event);
|
||||
});
|
||||
|
||||
//============================== KEYBOARD_EVENTS ==============================//
|
||||
|
||||
//============================== WINDOW_EVENTS ==============================//
|
||||
/* window position */
|
||||
glfwSetWindowPosCallback(m_Handle, [](GLFWwindow* window, int xpos, int ypos)
|
||||
{
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
WindowMovedEvent event(xpos, ypos);
|
||||
|
||||
callback(event);
|
||||
});
|
||||
|
||||
/* window size */
|
||||
glfwSetWindowSizeCallback(m_Handle, [](GLFWwindow* window, int width, int height)
|
||||
{
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
WindowResizedEvent event(width, height);
|
||||
|
||||
callback(event);
|
||||
});
|
||||
|
||||
/* window close */
|
||||
glfwSetWindowCloseCallback(m_Handle, [](GLFWwindow* window)
|
||||
{
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
WindowClosedEvent event;
|
||||
|
||||
callback(event);
|
||||
});
|
||||
|
||||
/* window focus */
|
||||
glfwSetWindowFocusCallback(m_Handle, [](GLFWwindow* window, int focus)
|
||||
{
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
|
||||
if (focus == GLFW_TRUE)
|
||||
{
|
||||
WindowGainFocusEvent event;
|
||||
callback(event);
|
||||
}
|
||||
else
|
||||
{
|
||||
WindowLostFocusEvent event;
|
||||
callback(event);
|
||||
}
|
||||
});
|
||||
//============================== WINDOW_EVENTS ==============================// }
|
||||
}
|
||||
}
|
||||
{
|
||||
WindowLostFocusEvent event;
|
||||
callback(event);
|
||||
}
|
||||
});
|
||||
//============================== WINDOW_EVENTS ==============================// }
|
||||
}
|
||||
} // namespace Light
|
||||
|
|
|
@ -27,7 +27,7 @@ EditorLayer::EditorLayer(const std::string& name, const std::vector<std::string>
|
|||
else
|
||||
{
|
||||
SceneSerializer serializer(m_Scene);
|
||||
LT_ENGINE_ASSERT(serializer.Deserialize(m_SceneDir), "EditorLayer::EditorLayer: failed to de-serialize: ", m_SceneDir);
|
||||
ASSERT(serializer.Deserialize(m_SceneDir), "Failed to de-serialize: {}", m_SceneDir);
|
||||
|
||||
m_CameraEntity = m_Scene->GetEntityByTag("Game Camera");
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include "EditorLayer.h"
|
||||
|
||||
#include "Utility/Serializer.h"
|
||||
|
||||
namespace Light {
|
||||
|
@ -27,7 +26,7 @@ EditorLayer::EditorLayer(const std::string& name, const std::vector<std::string>
|
|||
else
|
||||
{
|
||||
SceneSerializer serializer(m_Scene);
|
||||
LT_ENGINE_ASSERT(serializer.Deserialize(m_SceneDir), "EditorLayer::EditorLayer: failed to de-serialize: ", m_SceneDir);
|
||||
ASSERT(serializer.Deserialize(m_SceneDir), "EditorLayer::EditorLayer: failed to de-serialize: ", m_SceneDir);
|
||||
|
||||
m_CameraEntity = m_Scene->GetEntityByTag("Game Camera");
|
||||
}
|
||||
|
|
|
@ -38,7 +38,6 @@ void AssetBrowserPanel::OnUserInterfaceUpdate()
|
|||
m_DirectoryTexture->Bind(0u);
|
||||
for (auto& dirEntry : std::filesystem::directory_iterator(m_CurrentDirectory))
|
||||
{
|
||||
LT_ENGINE_TRACE("File: ", dirEntry.path().string());
|
||||
AssetType assetType;
|
||||
std::string extension = dirEntry.path().extension().string();
|
||||
|
||||
|
@ -71,7 +70,6 @@ void AssetBrowserPanel::OnUserInterfaceUpdate()
|
|||
if (ImGui::ImageButton(m_DirectoryTexture->GetTexture(), ImVec2(m_FileSize, m_FileSize), ImVec2 { 0.0f, 0.0f }, ImVec2 { 1.0f, 1.0f }, 0, ImVec4 { 0.0f, 0.0f, 0.0f, 0.0f }, ImVec4 { 1.0f, 1.0f, 1.0f, 1.0f }))
|
||||
{
|
||||
m_CurrentDirectory /= path.filename();
|
||||
LT_ENGINE_INFO(path.filename().string());
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue