diff --git a/Engine/dxgidebug.dll b/Engine/dxgidebug.dll new file mode 100644 index 0000000..12139cd Binary files /dev/null and b/Engine/dxgidebug.dll differ diff --git a/Engine/premake5.lua b/Engine/premake5.lua index 949b4b6..8d87102 100644 --- a/Engine/premake5.lua +++ b/Engine/premake5.lua @@ -68,15 +68,15 @@ project "Engine" -- debug filter "configurations:Debug" - defines "LT_DEBUG" + defines "LIGHT_DEBUG" symbols "on" -- release filter "configurations:Release" - defines "LT_RELEASE" + defines "LIGHT_RELEASE" optimize "on" -- distribution filter "configurations:Distribution" - defines "LT_DIST" + defines "LIGHT_DIST" optimize "on" \ No newline at end of file diff --git a/Engine/src/Engine/Base.h b/Engine/src/Engine/Base.h index 8df70ec..e306895 100644 --- a/Engine/src/Engine/Base.h +++ b/Engine/src/Engine/Base.h @@ -13,12 +13,14 @@ #if defined(LIGHT_PLATFORM_WINDOWS) #define LT_BUILD_PLATFORM "Windows" #define LT_WIN(x) x -#elif defined(LT_PLATFORM_LINUX) +#elif defined(LIGHT_PLATFORM_LINUX) #error "Unsupported platform: UNIX" #define LT_LIN(x) +#elif defined(LIGHT_PLATFORM_MAC) + #error "Unsupported platform: MAC" + #define LT_MAC(x) x #else #error "Unsupported platform: Unknown" - #define LT_MAC(x) x #endif #define BIT(x) 1 << x diff --git a/Engine/src/Engine/Core/Application.cpp b/Engine/src/Engine/Core/Application.cpp index 92b975f..494438b 100644 --- a/Engine/src/Engine/Core/Application.cpp +++ b/Engine/src/Engine/Core/Application.cpp @@ -31,6 +31,7 @@ namespace Light { LT_ENGINE_ASSERT(!m_LayerStack.IsEmpty(), "Application::GameLoop: Layerstack is empty"); // Log window data + LogDebugData(); m_Window->GetGfxContext()->LogDebugData(); m_Window->GetGfxContext()->GetUserInterface()->LogDebugData(); @@ -78,4 +79,12 @@ namespace Light { m_LayerStack.OnEvent(event); } + void Application::LogDebugData() + { + LT_ENGINE_INFO("________________________________________"); + LT_ENGINE_INFO("Platform::"); + LT_ENGINE_INFO(" OS: {}", LT_BUILD_PLATFORM); + LT_ENGINE_INFO("________________________________________"); + } + } \ No newline at end of file diff --git a/Engine/src/Engine/Core/Application.h b/Engine/src/Engine/Core/Application.h index c6b32f6..1df588e 100644 --- a/Engine/src/Engine/Core/Application.h +++ b/Engine/src/Engine/Core/Application.h @@ -33,6 +33,8 @@ namespace Light { private: void OnEvent(const Event& event); + + void LogDebugData(); }; } \ No newline at end of file diff --git a/Engine/src/Engine/Core/Logger.h b/Engine/src/Engine/Core/Logger.h index 517144b..4dc2955 100644 --- a/Engine/src/Engine/Core/Logger.h +++ b/Engine/src/Engine/Core/Logger.h @@ -5,7 +5,7 @@ #include // LOGGER MACROS // -#ifndef LT_DIST +#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__) diff --git a/Engine/src/Engine/Graphics/Renderer.cpp b/Engine/src/Engine/Graphics/Renderer.cpp index 9adf95d..cb6051e 100644 --- a/Engine/src/Engine/Graphics/Renderer.cpp +++ b/Engine/src/Engine/Graphics/Renderer.cpp @@ -18,7 +18,7 @@ namespace Light { m_QuadRenderer.shader = std::unique_ptr(Shader::Create("res/vertex.vertex", "res/fragment.fragment", m_SharedContext)); m_QuadRenderer.vertexBuffer = std::unique_ptr(VertexBuffer::Create(nullptr, sizeof(QuadRendererProgram::QuadVertexData), LT_MAX_QUAD * 4, m_SharedContext)); m_QuadRenderer.vertexLayout = std::unique_ptr(VertexLayout::Create(m_QuadRenderer.vertexBuffer.get(), m_QuadRenderer.shader.get(), { { "POSITION", VertexElementType::Float3 },{ "COLOR", VertexElementType::Float4 } }, m_SharedContext)); - m_QuadRenderer.indexBuffer = std::unique_ptr(IndexBuffer::Create(nullptr, LT_MAX_QUAD * 3, m_SharedContext)); + m_QuadRenderer.indexBuffer = std::unique_ptr(IndexBuffer::Create(nullptr, LT_MAX_QUAD * 6, m_SharedContext)); // QUADRENDERER // } @@ -49,27 +49,21 @@ namespace Light { const float xMax = position.x + size.x; const float yMax = position.y + size.y; - // TOP LEFT - m_QuadRenderer.mapCurrent->position = { xMin, yMin, position.z }; - m_QuadRenderer.mapCurrent->tint = glm::vec4(1.0f, 0.1f, 0.1f, 1.0f); - m_QuadRenderer.mapCurrent++; + + m_QuadRenderer.mapCurrent[0].position = { xMin, yMin, position.z }; + m_QuadRenderer.mapCurrent[0].tint = glm::vec4(0.1f, 0.1f, 1.0f, 1.0f); - // TOP RIGHT - m_QuadRenderer.mapCurrent->position = { xMax, yMin, position.z }; - m_QuadRenderer.mapCurrent->tint = glm::vec4(0.1f, 1.0f, 0.1f, 1.0f); - m_QuadRenderer.mapCurrent++; + m_QuadRenderer.mapCurrent[1].position = { xMax, yMin, position.z }; + m_QuadRenderer.mapCurrent[1].tint = glm::vec4(0.3f, 0.3f, 0.3f, 1.0f); - // BOTTOM RIGHT - m_QuadRenderer.mapCurrent->position = { xMax, yMax, position.z }; - m_QuadRenderer.mapCurrent->tint = glm::vec4(0.3f, 0.3f, 0.3f, 1.0f); - m_QuadRenderer.mapCurrent++; + m_QuadRenderer.mapCurrent[2].position = { xMax, yMax, position.z }; + m_QuadRenderer.mapCurrent[2].tint = glm::vec4(0.1f, 1.0f, 0.1f, 1.0f); - // BOTTOM LEFT - m_QuadRenderer.mapCurrent->position = { xMin, yMax, position.z }; - m_QuadRenderer.mapCurrent->tint = glm::vec4(0.1f, 0.1f, 1.0f, 1.0f); - m_QuadRenderer.mapCurrent++; + m_QuadRenderer.mapCurrent[3].position = { xMin, yMax, position.z }; + m_QuadRenderer.mapCurrent[3].tint = glm::vec4(1.0f, 0.1f, 0.1f, 1.0f); // advance + m_QuadRenderer.mapCurrent += 4; m_QuadRenderer.quadCount++; } @@ -81,9 +75,13 @@ namespace Light { void Renderer::EndScene() { - m_QuadRenderer.Bind(); - m_RenderCommand->DrawIndexed(m_QuadRenderer.quadCount * 6); - m_QuadRenderer.quadCount = 0; + if (m_QuadRenderer.quadCount) + { + m_QuadRenderer.Bind(); + + m_RenderCommand->DrawIndexed(m_QuadRenderer.quadCount * 6); + m_QuadRenderer.quadCount = 0; + } } } \ No newline at end of file diff --git a/Engine/src/Engine/Graphics/Shader.cpp b/Engine/src/Engine/Graphics/Shader.cpp index 7d91648..6ebb6a5 100644 --- a/Engine/src/Engine/Graphics/Shader.cpp +++ b/Engine/src/Engine/Graphics/Shader.cpp @@ -15,16 +15,22 @@ namespace Light { Shader* Shader::Create(const std::string& vertexPath, const std::string& pixelPath, void* sharedContext) { // load shader source - const std::string vertexSource = FileManager::ReadTXTFile(vertexPath); - const std::string pixelSource = FileManager::ReadTXTFile(pixelPath); + std::string vertexSource = FileManager::ReadTXTFile(vertexPath); + std::string pixelSource = FileManager::ReadTXTFile(pixelPath); switch (GraphicsContext::GetGraphicsAPI()) { case GraphicsAPI::OpenGL: + ExtractShaderSource(vertexSource, "GLSL"); + ExtractShaderSource(pixelSource, "GLSL"); + return new glShader(vertexSource, pixelSource); - case GraphicsAPI::DirectX: - return new dxShader(vertexSource, pixelSource, sharedContext); + case GraphicsAPI::DirectX: LT_WIN( + ExtractShaderSource(vertexSource, "HLSL"); + ExtractShaderSource(pixelSource, "HLSL"); + + return new dxShader(vertexSource, pixelSource, sharedContext);) default: LT_ENGINE_ASSERT(false, "Shader::Create: invalid/unsupported GraphicsAPI {}", GraphicsContext::GetGraphicsAPI()); @@ -32,4 +38,23 @@ namespace Light { } } + void Shader::ExtractShaderSource(std::string& src, const std::string& delim) + { + size_t begDelimPos, endDelimPos; + + begDelimPos = src.find('+' + delim) + 5; + endDelimPos = src.find('-' + delim); + + LT_ENGINE_ASSERT(begDelimPos != std::string::npos + 5, + "Shader::ExtractShaderSource: failed to find the start delimeter in shader source, delim: {}, shader:\n{}", + delim, src); + + + LT_ENGINE_ASSERT(endDelimPos != std::string::npos, + "Shader::ExtractShaderSource: failed to find the end delimeter in shader source, delim: {}, shader:\n{}", + delim, src); + + src = src.substr(begDelimPos, endDelimPos - begDelimPos); + } + } \ No newline at end of file diff --git a/Engine/src/Engine/Graphics/Shader.h b/Engine/src/Engine/Graphics/Shader.h index 6b13b83..f4af5b2 100644 --- a/Engine/src/Engine/Graphics/Shader.h +++ b/Engine/src/Engine/Graphics/Shader.h @@ -16,6 +16,9 @@ namespace Light { protected: Shader() = default; + + private: + static void ExtractShaderSource(std::string& src, const std::string& delim); }; } \ No newline at end of file diff --git a/Engine/src/Engine/Layer/LayerStack.h b/Engine/src/Engine/Layer/LayerStack.h index 3ca1471..1e4dabd 100644 --- a/Engine/src/Engine/Layer/LayerStack.h +++ b/Engine/src/Engine/Layer/LayerStack.h @@ -7,13 +7,10 @@ namespace Light { class Layer; class Event; - template - using Raw = T*; - class LayerStack { private: - static Raw s_Context; + static LayerStack* s_Context; std::vector m_Layers; diff --git a/Engine/src/Engine/Utility/FileManager.h b/Engine/src/Engine/Utility/FileManager.h index e1e6650..c5019f1 100644 --- a/Engine/src/Engine/Utility/FileManager.h +++ b/Engine/src/Engine/Utility/FileManager.h @@ -4,7 +4,7 @@ namespace Light { - // TODO: optimize + // TODO: optimize!! class FileManager { public: diff --git a/Engine/src/Platform/GraphicsAPI/DirectX/dxBuffers.cpp b/Engine/src/Platform/GraphicsAPI/DirectX/dxBuffers.cpp index 1b7fa7c..d60b9e0 100644 --- a/Engine/src/Platform/GraphicsAPI/DirectX/dxBuffers.cpp +++ b/Engine/src/Platform/GraphicsAPI/DirectX/dxBuffers.cpp @@ -53,7 +53,6 @@ namespace Light { { } - dxIndexBuffer::dxIndexBuffer(unsigned int* indices, unsigned int count, void* sharedContext) { HRESULT hr; @@ -69,7 +68,7 @@ namespace Light { { if (count % 6 != 0) { - LT_ENGINE_WARN("dxIndexBuffer::dxIndexBuffer: count should be divisible by 6 when no indices is provided"); + 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)); } @@ -79,11 +78,11 @@ namespace Light { for (unsigned int i = 0; i < count; i += 6) { indices[i + 0] = offset + 0; - indices[i + 1] = offset + 1; + indices[i + 1] = offset + 3; indices[i + 2] = offset + 2; indices[i + 3] = offset + 2; - indices[i + 4] = offset + 3; + indices[i + 4] = offset + 1; indices[i + 5] = offset + 0; offset += 4; @@ -103,7 +102,10 @@ namespace Light { DXC(m_Device->CreateBuffer(&bufferDesc, &sd, &m_Buffer)); if (!hasIndices) + { delete[] indices; + indices = nullptr; + } } dxIndexBuffer::~dxIndexBuffer() diff --git a/Engine/src/Platform/GraphicsAPI/DirectX/dxGraphicsContext.cpp b/Engine/src/Platform/GraphicsAPI/DirectX/dxGraphicsContext.cpp index 5358dff..86bb1ed 100644 --- a/Engine/src/Platform/GraphicsAPI/DirectX/dxGraphicsContext.cpp +++ b/Engine/src/Platform/GraphicsAPI/DirectX/dxGraphicsContext.cpp @@ -26,17 +26,36 @@ namespace Light { HRESULT hr; DXGI_SWAP_CHAIN_DESC sd = { 0 }; - sd.BufferCount = 1u; - sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + sd.OutputWindow = static_cast(glfwGetWin32Window(windowHandle)); + sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; - sd.OutputWindow = glfwGetWin32Window(m_WindowHandle); + sd.BufferCount = 1u; + + sd.BufferDesc.Width = 800u; + sd.BufferDesc.Height = 600u; + sd.BufferDesc.RefreshRate.Denominator = NULL; + sd.BufferDesc.RefreshRate.Numerator = NULL; + sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; + sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; + + sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; + sd.SampleDesc.Count = 1u; + sd.SampleDesc.Quality = 0u; + sd.Windowed = true; + sd.Flags = NULL; + + UINT flags = NULL; + +#ifdef LIGHT_DEBUG + flags = D3D11_CREATE_DEVICE_DEBUG; +#endif DXC(D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_HARDWARE, - NULL, NULL, NULL, NULL, D3D11_SDK_VERSION, + NULL, flags, NULL, NULL, D3D11_SDK_VERSION, &sd, &m_SwapChain, &m_Device, NULL, &m_DeviceContext)); - m_DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); Microsoft::WRL::ComPtr backBuffer; @@ -44,6 +63,24 @@ namespace Light { DXC(m_Device->CreateRenderTargetView(backBuffer.Get(), nullptr, &m_RenderTargetView)); m_DeviceContext->OMSetRenderTargets(1u, m_RenderTargetView.GetAddressOf(), nullptr); + Microsoft::WRL::ComPtr infoQueue; + + DXC(m_Device.As(&debugInterface)); + DXC(debugInterface.As(&infoQueue)); + + D3D11_MESSAGE_ID hide[] = + { + D3D11_MESSAGE_ID_DEVICE_DRAW_SAMPLER_NOT_SET, + + // #todo: add more message IDs here as needed + }; + + D3D11_INFO_QUEUE_FILTER filter; + memset(&filter, 0, sizeof(filter)); + filter.DenyList.NumIDs = _countof(hide); + filter.DenyList.pIDList = hide; + infoQueue->AddStorageFilterEntries(&filter); + D3D11_VIEWPORT viewport; @@ -60,6 +97,16 @@ namespace Light { dxSharedContext* sharedContext = new dxSharedContext({m_DeviceContext, m_SwapChain, m_RenderTargetView, m_Device}); m_SharedContext = sharedContext; + + } + + void dxGraphicsContext::OnWindowResize(const WindowResizedEvent& event) + { + + } + + void dxGraphicsContext::LogDebugData() + { // log some information about dx context // // locals IDXGIDevice* DXGIDevice; @@ -82,18 +129,10 @@ namespace Light { DXGIAdapter->Release(); // log info // #todo: log more information + LT_ENGINE_INFO("________________________________________"); LT_ENGINE_INFO("dxGraphicsContext:"); LT_ENGINE_INFO(" Renderer: {}", adapterDesc); - } - - void dxGraphicsContext::OnWindowResize(const WindowResizedEvent& event) - { - - } - - void dxGraphicsContext::LogDebugData() - { - + LT_ENGINE_INFO("________________________________________"); } } \ No newline at end of file diff --git a/Engine/src/Platform/GraphicsAPI/DirectX/dxGraphicsContext.h b/Engine/src/Platform/GraphicsAPI/DirectX/dxGraphicsContext.h index afb9fac..fdeb540 100644 --- a/Engine/src/Platform/GraphicsAPI/DirectX/dxGraphicsContext.h +++ b/Engine/src/Platform/GraphicsAPI/DirectX/dxGraphicsContext.h @@ -21,6 +21,8 @@ namespace Light { Microsoft::WRL::ComPtr m_SwapChain; Microsoft::WRL::ComPtr m_RenderTargetView; + Microsoft::WRL::ComPtr debugInterface; + public: dxGraphicsContext(GLFWwindow* windowHandle); diff --git a/Engine/src/Platform/GraphicsAPI/DirectX/dxRenderCommand.cpp b/Engine/src/Platform/GraphicsAPI/DirectX/dxRenderCommand.cpp index 66a27d5..5016b98 100644 --- a/Engine/src/Platform/GraphicsAPI/DirectX/dxRenderCommand.cpp +++ b/Engine/src/Platform/GraphicsAPI/DirectX/dxRenderCommand.cpp @@ -36,7 +36,7 @@ namespace Light { void dxRenderCommand::DrawIndexed(unsigned int count) { - + m_DeviceContext->DrawIndexed(count, 0u, 0u); } } \ No newline at end of file diff --git a/Engine/src/Platform/GraphicsAPI/DirectX/dxVertexLayout.cpp b/Engine/src/Platform/GraphicsAPI/DirectX/dxVertexLayout.cpp index d704c3b..119ec6f 100644 --- a/Engine/src/Platform/GraphicsAPI/DirectX/dxVertexLayout.cpp +++ b/Engine/src/Platform/GraphicsAPI/DirectX/dxVertexLayout.cpp @@ -39,7 +39,6 @@ namespace Light { dxVertexLayout::~dxVertexLayout() { - } void dxVertexLayout::Bind() diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.cpp b/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.cpp index 80cd161..51c40b8 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.cpp +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.cpp @@ -32,6 +32,12 @@ namespace Light { void glGraphicsContext::OnWindowResize(const WindowResizedEvent& event) { + if (event.GetSize().x < 0 || event.GetSize().y < 0) + { + LT_ENGINE_ERROR("glGraphicsContext::OnWindowResize: width/height cannot be negative: [{}x{}]", event.GetSize().x, event.GetSize().y); + return; + } + glViewport(0, 0, event.GetSize().x, event.GetSize().y); } @@ -71,6 +77,7 @@ namespace Light { Stringifier::glDebugMsgSource(source), Stringifier::glDebugMsgType(type), id); + __debugbreak(); LT_ENGINE_CRITICAL(" {}", message); return; case GL_DEBUG_SEVERITY_MEDIUM: case GL_DEBUG_SEVERITY_LOW: diff --git a/Engine/src/Platform/OS/Windows/wWindow.cpp b/Engine/src/Platform/OS/Windows/wWindow.cpp index 20777dd..f64800c 100644 --- a/Engine/src/Platform/OS/Windows/wWindow.cpp +++ b/Engine/src/Platform/OS/Windows/wWindow.cpp @@ -30,7 +30,7 @@ namespace Light { glfwSetWindowUserPointer(m_Handle, &m_EventCallback); BindGlfwEvents(); - m_GraphicsContext = std::unique_ptr(GraphicsContext::Create(GraphicsAPI::OpenGL, m_Handle)); + m_GraphicsContext = std::unique_ptr(GraphicsContext::Create(GraphicsAPI::DirectX, m_Handle)); LT_ENGINE_ASSERT(m_GraphicsContext, "wWindow::wWindow: graphics context creation failed"); } diff --git a/Sandbox/premake5.lua b/Sandbox/premake5.lua index b111012..e40641e 100644 --- a/Sandbox/premake5.lua +++ b/Sandbox/premake5.lua @@ -53,15 +53,15 @@ project "Sandbox" -- debug filter "configurations:Debug" - defines "LT_DEBUG" + defines "LIGHT_DEBUG" symbols "on" -- release filter "configurations:Release" - defines "LT_RELEASE" + defines "LIGHT_RELEASE" optimize "on" -- distribution filter "configurations:Distribution" - defines "LT_DIST" + defines "LIGHT_DIST" optimize "on" \ No newline at end of file diff --git a/Sandbox/res/fragment.fragment b/Sandbox/res/fragment.fragment index 945034e..7d9b08c 100644 --- a/Sandbox/res/fragment.fragment +++ b/Sandbox/res/fragment.fragment @@ -1,3 +1,4 @@ ++GLSL #version 440 core in vec4 fragColor; @@ -7,4 +8,11 @@ out vec4 FragmentColor; void main() { FragmentColor = fragColor; -} \ No newline at end of file +} +-GLSL ++HLSL +float4 main(float4 Color : COLOR) : SV_Target +{ + return Color; +} +-HLSL \ No newline at end of file diff --git a/Sandbox/res/vertex.vertex b/Sandbox/res/vertex.vertex index a82c3c0..8eade4c 100644 --- a/Sandbox/res/vertex.vertex +++ b/Sandbox/res/vertex.vertex @@ -1,3 +1,4 @@ ++GLSL #version 440 core layout(location = 0) in vec3 a_Position; @@ -9,4 +10,20 @@ void main() { gl_Position = vec4(a_Position, 1.0); fragColor = a_Color; -} \ No newline at end of file +} +-GLSL ++HLSL +struct VertexOut +{ + float4 Color : COLOR; + float4 Position : SV_Position; +}; + +VertexOut main(float3 InPosition : POSITION, float4 InColor : COLOR) +{ + VertexOut vso; + vso.Position = float4(InPosition.x, InPosition.y, InPosition.z, 1.0); + vso.Color = InColor; + return vso; +} +-HLSL \ No newline at end of file