Major changes
This commit is contained in:
parent
0510712d6e
commit
bb604e9540
21 changed files with 172 additions and 62 deletions
BIN
Engine/dxgidebug.dll
Normal file
BIN
Engine/dxgidebug.dll
Normal file
Binary file not shown.
|
@ -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"
|
|
@ -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
|
||||
|
|
|
@ -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("________________________________________");
|
||||
}
|
||||
|
||||
}
|
|
@ -33,6 +33,8 @@ namespace Light {
|
|||
|
||||
private:
|
||||
void OnEvent(const Event& event);
|
||||
|
||||
void LogDebugData();
|
||||
};
|
||||
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
#include <spdlog/spdlog.h>
|
||||
|
||||
// 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__)
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace Light {
|
|||
m_QuadRenderer.shader = std::unique_ptr<Shader>(Shader::Create("res/vertex.vertex", "res/fragment.fragment", m_SharedContext));
|
||||
m_QuadRenderer.vertexBuffer = std::unique_ptr<VertexBuffer>(VertexBuffer::Create(nullptr, sizeof(QuadRendererProgram::QuadVertexData), LT_MAX_QUAD * 4, m_SharedContext));
|
||||
m_QuadRenderer.vertexLayout = std::unique_ptr<VertexLayout>(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>(IndexBuffer::Create(nullptr, LT_MAX_QUAD * 3, m_SharedContext));
|
||||
m_QuadRenderer.indexBuffer = std::unique_ptr<IndexBuffer>(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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -16,6 +16,9 @@ namespace Light {
|
|||
|
||||
protected:
|
||||
Shader() = default;
|
||||
|
||||
private:
|
||||
static void ExtractShaderSource(std::string& src, const std::string& delim);
|
||||
};
|
||||
|
||||
}
|
|
@ -7,13 +7,10 @@ namespace Light {
|
|||
class Layer;
|
||||
class Event;
|
||||
|
||||
template <typename T>
|
||||
using Raw = T*;
|
||||
|
||||
class LayerStack
|
||||
{
|
||||
private:
|
||||
static Raw<LayerStack> s_Context;
|
||||
static LayerStack* s_Context;
|
||||
|
||||
std::vector<Layer*> m_Layers;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
// TODO: optimize
|
||||
// TODO: optimize!!
|
||||
class FileManager
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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<HWND>(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<ID3D11Resource> 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<ID3D11InfoQueue> 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("________________________________________");
|
||||
}
|
||||
|
||||
}
|
|
@ -21,6 +21,8 @@ namespace Light {
|
|||
Microsoft::WRL::ComPtr<IDXGISwapChain> m_SwapChain;
|
||||
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_RenderTargetView;
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D11Debug> debugInterface;
|
||||
|
||||
public:
|
||||
dxGraphicsContext(GLFWwindow* windowHandle);
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace Light {
|
|||
|
||||
void dxRenderCommand::DrawIndexed(unsigned int count)
|
||||
{
|
||||
|
||||
m_DeviceContext->DrawIndexed(count, 0u, 0u);
|
||||
}
|
||||
|
||||
}
|
|
@ -39,7 +39,6 @@ namespace Light {
|
|||
|
||||
dxVertexLayout::~dxVertexLayout()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void dxVertexLayout::Bind()
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace Light {
|
|||
glfwSetWindowUserPointer(m_Handle, &m_EventCallback);
|
||||
BindGlfwEvents();
|
||||
|
||||
m_GraphicsContext = std::unique_ptr<GraphicsContext>(GraphicsContext::Create(GraphicsAPI::OpenGL, m_Handle));
|
||||
m_GraphicsContext = std::unique_ptr<GraphicsContext>(GraphicsContext::Create(GraphicsAPI::DirectX, m_Handle));
|
||||
LT_ENGINE_ASSERT(m_GraphicsContext, "wWindow::wWindow: graphics context creation failed");
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
|
@ -1,3 +1,4 @@
|
|||
+GLSL
|
||||
#version 440 core
|
||||
|
||||
in vec4 fragColor;
|
||||
|
@ -7,4 +8,11 @@ out vec4 FragmentColor;
|
|||
void main()
|
||||
{
|
||||
FragmentColor = fragColor;
|
||||
}
|
||||
}
|
||||
-GLSL
|
||||
+HLSL
|
||||
float4 main(float4 Color : COLOR) : SV_Target
|
||||
{
|
||||
return Color;
|
||||
}
|
||||
-HLSL
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
-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
|
Loading…
Add table
Reference in a new issue