light/Engine/src/Platform/GraphicsAPI/DirectX/dxVertexLayout.cpp
Light 2ab97d3863 Major Maintenance
- Major tidying
- Moved 'RendererProgram' classes out of the 'Renderer' class
- Moved 'RenderCommand' member variable out of 'GraphicsContext' and into
       the 'Renderer' class as a unique_ptr. results in 'Renderer' taking a
       windowHandle for construction
- Defined new macros for max quads in 'Renderer.h'
- Added the 'Stringifier' to 'Base.h'
- Added the 'ResourceManager' to the 'LightEngine.h'
- Application now logs the current file directory
- Fixed the forward declaration in GraphicsContext
- Fixed the debug break in Base.h
- Fixed 'dxShader' not logging compile errors
- 'glVertexLayout' now takes in a shared_ptr for 'VertexBuffer'
- 'glShader' now logs the shader compilation errors properly
- 'dxVertexLayout' now takes in a shared_ptr for 'Shader"
- Modified 'dxSharedContext' members to be private and made getters for them
- 'dxRenderCommand::SwapBuffers' now throws dxException for
       DXGI_ERROR_DEVICE_REMOD error
2021-07-01 19:25:46 +04:30

85 lines
No EOL
3 KiB
C++

#include "ltpch.h"
#include "dxVertexLayout.h"
#include "dxSharedContext.h"
#include "dxShader.h"
namespace Light {
dxVertexLayout::dxVertexLayout(std::shared_ptr<Shader> shader, const std::vector<std::pair<std::string, VertexElementType>>& elements, std::shared_ptr<dxSharedContext> sharedContext)
: m_Context(sharedContext)
{
// 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(),
0u,
GetDxgiFormat(element.second),
0u,
D3D11_APPEND_ALIGNED_ELEMENT,
D3D11_INPUT_PER_VERTEX_DATA,
0u });
}
std::shared_ptr<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));
}
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)
{
// #todo: add char
// 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;
// #todo:
case Light::VertexElementType::Double1:
case Light::VertexElementType::Double2:
case Light::VertexElementType::Double3:
case Light::VertexElementType::Double4:
default: LT_ENGINE_ASSERT(false, "dxVertexLayout::GetDxgiFormat: invalid 'VertexElementType'");
}
}
}