Skip to content

Commit

Permalink
Renderer API abstration complete
Browse files Browse the repository at this point in the history
  • Loading branch information
yugansharora01 committed Oct 5, 2021
1 parent 4b50adf commit 40ef5c3
Show file tree
Hide file tree
Showing 29 changed files with 177 additions and 128 deletions.
1 change: 1 addition & 0 deletions Aurora/Aurora.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
<ClInclude Include="src\Aurora\Core\AuTimer.h" />
<ClInclude Include="src\Aurora\Drawables\Geometry\Cone.h" />
<ClInclude Include="src\Aurora\Drawables\Geometry\Cube.h" />
<ClInclude Include="src\Aurora\Drawables\Geometry\Geometry.h" />
<ClInclude Include="src\Aurora\Drawables\Geometry\IndexedTriangleList.h" />
<ClInclude Include="src\Aurora\Drawables\Geometry\Plane.h" />
<ClInclude Include="src\Aurora\Drawables\Geometry\Prism.h" />
Expand Down
1 change: 1 addition & 0 deletions Aurora/Aurora.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
<ClInclude Include="src\Aurora\Renderer\Renderer.h" />
<ClInclude Include="src\Aurora\Renderer\RendererAPI.h" />
<ClInclude Include="src\Aurora\Renderer\EditorCamera.h" />
<ClInclude Include="src\Aurora\Drawables\Geometry\Geometry.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\Aurora\Application.cpp">
Expand Down
7 changes: 7 additions & 0 deletions Aurora/src/Aurora.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@

#include "Aurora/Imgui/ImguiLayer.h"
#include "Aurora/Renderer/Renderer.h"
#include "Aurora/Renderer/BindableBase.h"
#include "Aurora/Drawables/Geometry/Geometry.h"

#include "Platform/Windows/AuroraException.h"
#include "Aurora/Renderer/EditorCamera.h"

#include "imgui.h"

// ------Entry Point--------------
#include "Aurora/EntryPoint.h"
Expand Down
57 changes: 37 additions & 20 deletions Aurora/src/Aurora/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Aurora/Events/ApplicationEvents.h"
#include "Aurora/Log.h"
#include "Platform/Windows/Win32_Window.h"
#include "Platform/Windows/AuroraException.h"

#include "imgui.h"

Expand Down Expand Up @@ -36,36 +37,52 @@ namespace Aurora {

void Application::Run()
{
float i = 0.0f;
float inc = 0.01f;
float inc1 = 0.01f;

while (m_Running)
try
{
m_EditorLayer->Get(i,inc,inc1);
float i = 0.0f;
float inc = 0.01f;
float inc1 = 0.01f;

auto wnd = (Win32_Window*)m_Window->GetNativeWindow();
wnd->Gfx().ClearBuffer(i, inc, inc1);
while (m_Running)
{
m_EditorLayer->Get(i,inc,inc1);

for (Layer* layer : m_LayerStack)
layer->OnUpdate();
auto wnd = (Win32_Window*)m_Window->GetNativeWindow();
wnd->Gfx().ClearBuffer(i, inc, inc1);

m_EditorLayer->GetPos(i,inc,inc1);

for (Layer* layer : m_LayerStack)
layer->OnUpdate();

m_ImGuiLayer->Begin();
m_EditorLayer->GetPos(i,inc,inc1);


for (Layer* layer : m_LayerStack)
{
layer->OnImGuiRender();
}
m_ImGuiLayer->Begin();

for (Layer* layer : m_LayerStack)
{
layer->OnImGuiRender();
}

m_ImGuiLayer->End();
m_ImGuiLayer->End();

m_Window->OnUpdate(m_Running);
m_Window->OnUpdate(m_Running);


wnd->Gfx().EndFrame();
wnd->Gfx().EndFrame();
}
}
catch (const AuroraException& e)
{
AU_CORE_FATAL("{0}", e.what());
MessageBoxA(nullptr, e.what(), e.GetType(), MB_OK | MB_ICONEXCLAMATION);
}
catch (const std::exception& e)
{
MessageBoxA(nullptr, e.what(), "Standard Exception", MB_OK | MB_ICONEXCLAMATION);
}
catch (...)
{
MessageBoxA(nullptr, "No Details Available", "Unknown Exception", MB_OK | MB_ICONEXCLAMATION);
}
}

Expand Down
6 changes: 6 additions & 0 deletions Aurora/src/Aurora/Drawables/Geometry/Geometry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once
#include "Cube.h"
#include "Cone.h"
#include "Plane.h"
#include "Prism.h"
#include "Sphere.h"
2 changes: 1 addition & 1 deletion Aurora/src/Aurora/Drawables/Geometry/Prism.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Prism
// near center
std::vector<V> vertices;
vertices.emplace_back();
vertices.back().pos = { 0.0f,0.0f,-1.0ff };
vertices.back().pos = { 0.0f,0.0f,-1.0f };
const auto iCenterNear = (unsigned short)(vertices.size() - 1);

//far center
Expand Down
2 changes: 2 additions & 0 deletions Aurora/src/Aurora/EntryPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#ifdef AU_PLATFORM_WINDOWS


extern Aurora::Application* Aurora::CreateApplication();

int main(int argc,char** argv)
Expand All @@ -15,6 +16,7 @@ int main(int argc,char** argv)
auto app = Aurora::CreateApplication();
app->Run();
delete app;

return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions Aurora/src/Aurora/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ namespace Aurora {
#define AU_CORE_INFO(...) ::Aurora::Log::GetCoreLogger()->info(__VA_ARGS__)
#define AU_CORE_ERROR(...) ::Aurora::Log::GetCoreLogger()->error(__VA_ARGS__)
#define AU_CORE_WARN(...) ::Aurora::Log::GetCoreLogger()->warn(__VA_ARGS__)
#define AU_CORE_FATAL(...) ::Aurora::Log::GetCoreLogger()->fatal(__VA_ARGS__)
#define AU_CORE_FATAL(...) ::Aurora::Log::GetCoreLogger()->critical(__VA_ARGS__)


//Client Log macros
#define AU_TRACE(...) ::Aurora::Log::GetClientLogger()->trace(__VA_ARGS__)
#define AU_INFO(...) ::Aurora::Log::GetClientLogger()->info(__VA_ARGS__)
#define AU_ERROR(...) ::Aurora::Log::GetClientLogger()->error(__VA_ARGS__)
#define AU_WARN(...) ::Aurora::Log::GetClientLogger()->warn(__VA_ARGS__)
#define AU_FATAL(...) ::Aurora::Log::GetClientLogger()->fatal(__VA_ARGS__)
#define AU_FATAL(...) ::Aurora::Log::GetClientLogger()->critical(__VA_ARGS__)



Expand Down
5 changes: 2 additions & 3 deletions Aurora/src/Aurora/Renderer/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ namespace Aurora
virtual void Unbind() = 0;
virtual void SetData(void* data,unsigned int size) = 0;


virtual void SetLayout(std::vector<LayoutBuffer> layout,std::shared_ptr<class VertexShader> vShader) = 0;

virtual void SetTopology(TopologyType type) = 0;
static std::shared_ptr<VertexBuffer> Create(
const std::vector<DirectX::XMFLOAT3>& vertices);

Expand Down Expand Up @@ -78,7 +77,7 @@ namespace Aurora

class Topology : public Bindables
{

public:
virtual ~Topology() = default;

Expand Down
30 changes: 17 additions & 13 deletions Aurora/src/Aurora/Renderer/EditorCamera.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
#include "pch.h"
#include "EditorCamera.h"

EditorCamera::EditorCamera(float fov, float aspectRatio, float nearClip, float farClip)
:m_fov(fov),m_aspectRatio(aspectRatio),m_nearClip(nearClip),m_farClip(farClip)
{
m_proj = DirectX::XMMatrixPerspectiveFovLH(fov, aspectRatio, nearClip, farClip);
}
namespace Aurora {

DirectX::XMMATRIX EditorCamera::GetProjection()
{
return m_proj;
}
EditorCamera::EditorCamera(float fov, float aspectRatio, float nearClip, float farClip)
:m_fov(fov), m_aspectRatio(aspectRatio), m_nearClip(nearClip), m_farClip(farClip)
{
m_proj = DirectX::XMMatrixPerspectiveLH(fov, aspectRatio, nearClip, farClip);
}

void EditorCamera::UpdateProjection()
{
m_proj = DirectX::XMMatrixPerspectiveFovLH(m_fov, m_aspectRatio, m_nearClip, m_farClip);
}
DirectX::XMMATRIX EditorCamera::GetProjection() noexcept
{
return m_proj;
}

void EditorCamera::UpdateProjection()
{
m_proj = DirectX::XMMatrixPerspectiveLH(m_fov, m_aspectRatio, m_nearClip, m_farClip);
}

}
28 changes: 15 additions & 13 deletions Aurora/src/Aurora/Renderer/EditorCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

#include <DirectXMath.h>

class EditorCamera
{
public:
EditorCamera(float fov, float aspectRatio, float nearClip, float farClip);
DirectX::XMMATRIX GetProjection();
void UpdateProjection();
private:
DirectX::XMMATRIX m_proj;
float m_fov;
float m_aspectRatio;
float m_nearClip;
float m_farClip;
};
namespace Aurora {

class EditorCamera
{
public:
EditorCamera(float fov, float aspectRatio, float nearClip, float farClip);
void UpdateProjection();
DirectX::XMMATRIX GetProjection() noexcept;
private:
DirectX::XMMATRIX m_proj;
float m_fov;
float m_aspectRatio;
float m_nearClip;
float m_farClip;
};
}
2 changes: 1 addition & 1 deletion Aurora/src/Aurora/Renderer/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ namespace Aurora {

void Renderer::Submit(std::shared_ptr<VertexShader> vShader, std::shared_ptr<PixelShader> pShader, std::shared_ptr<VertexBuffer> vBuffer, std::shared_ptr<IndexBuffer> iBuffer)
{
vBuffer->Bind();
vShader->Bind();
pShader->Bind();
vBuffer->Bind();
iBuffer->Bind();
count = iBuffer->GetCount();
}
Expand Down
1 change: 1 addition & 0 deletions Aurora/src/Aurora/Renderer/Shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace Aurora {
public:
virtual ~VertexShader() = default;

virtual ID3DBlob* GetBytecode() const noexcept = 0;
static std::shared_ptr<VertexShader> Create(const std::wstring& path);
};

Expand Down
1 change: 0 additions & 1 deletion Aurora/src/Platform/DirectX/D3D11IndexBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ namespace Aurora {
private:
UINT count;
Microsoft::WRL::ComPtr<ID3D11Buffer> pIndexBuffer;

};
}
23 changes: 17 additions & 6 deletions Aurora/src/Platform/DirectX/D3D11InputLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,14 @@ namespace Aurora {
std::vector<D3D11_INPUT_ELEMENT_DESC> GetLayoutDesc(const std::vector<LayoutBuffer>& layout)
{
std::vector<D3D11_INPUT_ELEMENT_DESC> layoutdesc;
for (auto Layout : layout)
{
//D3D11_INPUT_ELEMENT_DESC desc = { Layout.name.c_str(),0,GetFormat(Layout),0,Layout.offset,D3D11_INPUT_PER_VERTEX_DATA ,0 };
layoutdesc.push_back(D3D11_INPUT_ELEMENT_DESC({ Layout.name.c_str(),0,GetFormat(Layout),0,Layout.offset,D3D11_INPUT_PER_VERTEX_DATA ,0 }));
}

int i = 0;
//for (auto Layout : layout)

D3D11_INPUT_ELEMENT_DESC desc = { layout[0].name.c_str(),0,GetFormat(layout[0]),0,layout[0].offset,D3D11_INPUT_PER_VERTEX_DATA ,0 };
layoutdesc.push_back(desc);
i++;

AU_CORE_INFO("{0}", i);
return layoutdesc;
}

Expand All @@ -142,6 +144,15 @@ namespace Aurora {
{

auto layoutdesc = GetLayoutDesc(layout);
std::vector<D3D11_INPUT_ELEMENT_DESC> lay;
D3D11_INPUT_ELEMENT_DESC i = { "Position",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0 };

lay.push_back(i);

/*if (lay == layoutdesc)
AU_CORE_INFO("LOL");*/


INFOMAN;
GFX_THROW_INFO(Getgfx().GetDevice()->CreateInputLayout(
layoutdesc.data(), (UINT)layout.size(),
Expand Down
12 changes: 10 additions & 2 deletions Aurora/src/Platform/DirectX/D3D11VertexBuffer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "pch.h"
#include "D3D11VertexBuffer.h"
#include "D3D11VertexShader.h"
#include "D3D11Topology.h"
#include "D3D11InputLayout.h"

namespace Aurora {

Expand Down Expand Up @@ -30,6 +32,7 @@ namespace Aurora {
const UINT offset = 0u;
Getgfx().GetContext()->IASetVertexBuffers(0u, 1u, pVertexBuffer.GetAddressOf(), &stride, &offset);
m_layout->Bind();
m_topology->Bind();
}
void D3D11VertexBuffer::SetData(void* data, unsigned int size)
{
Expand All @@ -53,8 +56,13 @@ namespace Aurora {

void D3D11VertexBuffer::SetLayout(std::vector<LayoutBuffer> layout, std::shared_ptr<VertexShader> vShader)
{
ID3DBlob* blob = std::dynamic_pointer_cast<D3D11VertexShader>(vShader)->GetBytecode();
m_layout = InputLayout::Create(layout,blob);
//ID3DBlob* blob = std::dynamic_pointer_cast<D3D11VertexShader>(vShader)->GetBytecode();
m_layout = std::make_shared<D3D11InputLayout>(layout,vShader->GetBytecode());
}

void D3D11VertexBuffer::SetTopology(TopologyType type)
{
m_topology = std::make_shared<D3D11Topology>(type);
}


Expand Down
6 changes: 4 additions & 2 deletions Aurora/src/Platform/DirectX/D3D11VertexBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "Aurora/Renderer/Buffer.h"
#include "Platform/Windows/GraphicsThrowMacros.h"


namespace Aurora {

class D3D11VertexBuffer : public VertexBuffer
Expand All @@ -18,11 +19,12 @@ namespace Aurora {


virtual void SetLayout(std::vector<LayoutBuffer> layout, std::shared_ptr<class VertexShader> vShader) override;

virtual void SetTopology(TopologyType type) override;

private:
UINT stride;
Microsoft::WRL::ComPtr<ID3D11Buffer> pVertexBuffer;
std::shared_ptr<InputLayout> m_layout;
std::shared_ptr<class D3D11InputLayout> m_layout;
std::shared_ptr<class D3D11Topology> m_topology;
};
}
5 changes: 4 additions & 1 deletion Aurora/src/Platform/DirectX/D3D11VertexShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ namespace Aurora {
void D3D11VertexShader::Bind()
{
Getgfx().GetContext()->VSSetShader(pVertexShader.Get(), nullptr, 0u);
vConst->Bind();
}

ID3DBlob* D3D11VertexShader::GetBytecode() const noexcept
ID3DBlob* D3D11VertexShader::GetBytecode() const noexcept
{
return pBytecodeBlob.Get();
}
Expand All @@ -42,6 +43,8 @@ namespace Aurora {
}
void D3D11VertexShader::UploadMat4(DirectX::XMMATRIX mat4)
{
vConst = std::make_shared<D3D11VertexConstantBuffer>();
vConst->Create<DirectX::XMMATRIX>(mat4);
}

void D3D11VertexShader::UploadMat4X8(std::array<DirectX::XMFLOAT4, 8> arr)
Expand Down
Loading

0 comments on commit 40ef5c3

Please sign in to comment.