Commit 9a69a927 authored by AL's avatar AL

on/off blur

parent 3178ade4
......@@ -177,6 +177,8 @@ ActionBox::TurnState ActionBox::UpdateTurnState(float dt)
{
return TurnState::Done;
}
assert(false && "invalid something in ActionBox::UpdateTurnState ");
return TurnState::Done;
}
bool ActionBox::UpgradeRandomSkill()
......
#pragma once
#include "Framework/ConditionalNoexcept.h"
class DXGraphics;
namespace Bind
{
class BufferResource
{
public:
virtual ~BufferResource() = default;
virtual void BindAsBuffer(DXGraphics&) noxnd = 0;
virtual void BindAsBuffer(DXGraphics&, BufferResource*) noxnd = 0;
virtual void Clear(DXGraphics&) noxnd = 0;
};
}
\ No newline at end of file
#include "DepthStencil.h"
#include "Framework/GraphicsThrowMacros.h"
namespace wrl = Microsoft::WRL;
DepthStencil::DepthStencil(DXGraphics& gfx, size_t width, size_t height, Mode mode)
{
INFOMAN(gfx);
// create depth stensil texture
wrl::ComPtr<ID3D11Texture2D> pDepthStencil;
D3D11_TEXTURE2D_DESC descDepth = {};
descDepth.Width = (UINT)width;
descDepth.Height = (UINT)height;
descDepth.MipLevels = 1u;
descDepth.ArraySize = 1u;
descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
descDepth.SampleDesc.Count = 1u;
descDepth.SampleDesc.Quality = 0u;
descDepth.Usage = D3D11_USAGE_DEFAULT;
descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
GFX_THROW_INFO(GetDevice(gfx)->CreateTexture2D(&descDepth, nullptr, &pDepthStencil));
// create target view of depth stensil texture
GFX_THROW_INFO(GetDevice(gfx)->CreateDepthStencilView(
pDepthStencil.Get(), nullptr, &pDepthStencilView
));
}
void DepthStencil::BindAsDepthStencil(DXGraphics& gfx) const noexcept
{
GetContext(gfx)->OMSetRenderTargets(0, nullptr, pDepthStencilView.Get());
}
void DepthStencil::Clear(DXGraphics& gfx) const noexcept
{
GetContext(gfx)->ClearDepthStencilView(pDepthStencilView.Get(), D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0u);
}
#pragma once
#include "Framework/DXGraphics.h"
#include "GraphicsResource.h"
class DepthStencil : public GraphicsResource
{
friend class RenderTarget;
friend class DXGraphics;
public:
enum class Mode
{
Default,
HUD,
ReadOnly
};
DepthStencil(DXGraphics& gfx, size_t width, size_t height, Mode mode = Mode::Default);
void BindAsDepthStencil(DXGraphics& gfx) const noexcept;
void Clear(DXGraphics& gfx) const noexcept;
private:
Microsoft::WRL::ComPtr<ID3D11DepthStencilView> pDepthStencilView;
Microsoft::WRL::ComPtr<ID3D11DepthStencilState> pStencil;
};
......@@ -179,7 +179,13 @@
<ClInclude Include="AchievementManager.h" />
<ClInclude Include="AchievementsScreen.h" />
<ClInclude Include="BlurManager.h" />
<ClInclude Include="BufferResource.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="CameraManager.h" />
<ClInclude Include="DepthStencil.h" />
<ClInclude Include="GraphicsResource.h" />
<ClInclude Include="HPBar.h" />
<ClInclude Include="Camera.h" />
<ClInclude Include="ChiliXM.h" />
......@@ -253,6 +259,7 @@
<ClInclude Include="IntentIcons.h" />
<ClInclude Include="Mesh.h" />
<ClInclude Include="PressableMenu.h" />
<ClInclude Include="RenderTarget.h" />
<ClInclude Include="SceneLight.h" />
<ClInclude Include="SideButtons.h" />
<ClInclude Include="LevelMap.h" />
......@@ -358,8 +365,10 @@
<ClCompile Include="ActionBox.cpp" />
<ClCompile Include="BlurManager.cpp" />
<ClCompile Include="CameraManager.cpp" />
<ClCompile Include="DepthStencil.cpp" />
<ClCompile Include="EffectHandler.cpp" />
<ClCompile Include="Framework\FrameCommander.cpp" />
<ClCompile Include="GraphicsResource.cpp" />
<ClCompile Include="HPBar.cpp" />
<ClCompile Include="Camera.cpp" />
<ClCompile Include="ChiliXM.cpp" />
......@@ -367,7 +376,6 @@
<ClCompile Include="CombatManager.cpp" />
<ClCompile Include="CombatTimers.cpp" />
<ClCompile Include="EnemyCombat.cpp" />
<ClCompile Include="Framework\Bindable.cpp" />
<ClCompile Include="Framework\Blender.cpp" />
<ClCompile Include="Framework\ChiliException.cpp" />
<ClCompile Include="Framework\ChiliUtil.cpp" />
......@@ -463,6 +471,7 @@
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="RenderTarget.cpp" />
<ClCompile Include="RewardMenu.cpp" />
<ClCompile Include="SceneLight.cpp" />
<ClCompile Include="SkillHandler.cpp" />
......@@ -559,6 +568,24 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</FxCompile>
<FxCompile Include="FullscreenVS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Vertex</ShaderType>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(RiftedTimes\Engine)%(Filename).cso</ObjectFileOutput>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(RiftedTimes\Engine)%(Filename).cso</ObjectFileOutput>
</FxCompile>
<FxCompile Include="FunkPS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(RiftedTimes\Engine)%(Filename).cso</ObjectFileOutput>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(RiftedTimes\Engine)%(Filename).cso</ObjectFileOutput>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">5.0</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">5.0</ShaderModel>
</FxCompile>
<FxCompile Include="HPBarPS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
......
......@@ -588,6 +588,18 @@
<ClInclude Include="BlurManager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RenderTarget.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="BufferResource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DepthStencil.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GraphicsResource.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Game.cpp">
......@@ -749,9 +761,6 @@
<ClCompile Include="Framework\Drawable.cpp">
<Filter>Header Files\Framework\Draws</Filter>
</ClCompile>
<ClCompile Include="Framework\Bindable.cpp">
<Filter>Header Files\Framework\Binds</Filter>
</ClCompile>
<ClCompile Include="Camera.cpp">
<Filter>Source Files</Filter>
</ClCompile>
......@@ -905,6 +914,15 @@
<ClCompile Include="BlurManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="RenderTarget.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DepthStencil.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GraphicsResource.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<FxCompile Include="PhongVSNormalMap.hlsl">
......@@ -1012,6 +1030,12 @@
<FxCompile Include="PhongPSOpac.hlsl">
<Filter>Shaders</Filter>
</FxCompile>
<FxCompile Include="FullscreenVS.hlsl">
<Filter>Shaders</Filter>
</FxCompile>
<FxCompile Include="FunkPS.hlsl">
<Filter>Shaders</Filter>
</FxCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Resource.rc">
......
#include "Bindable.h"
#include <stdexcept>
namespace Bind
{
ID3D11DeviceContext* Bindable::GetContext(DXGraphics& gfx) noexcept
{
return gfx.pContext.Get();
}
ID3D11Device* Bindable::GetDevice(DXGraphics& gfx) noexcept
{
return gfx.pDevice.Get();
}
DxgiInfoManager& Bindable::GetInfoManager(DXGraphics& gfx)
{
#ifndef NDEBUG
return gfx.infoManager;
#else
throw std::logic_error("YouFuckedUp! (tried to access gfx.infoManager in Release config)");
#endif
}
}
#pragma once
#include "DXGraphics.h"
#include "ConditionalNoexcept.h"
#include "../GraphicsResource.h"
class Drawable;
namespace Bind
{
class Bindable
class Bindable : public GraphicsResource
{
public:
virtual void Bind(DXGraphics& gfx) noexcept = 0;
......@@ -18,9 +19,5 @@ namespace Bind
return L"";
}
virtual ~Bindable() = default;
protected:
static ID3D11DeviceContext* GetContext(DXGraphics& gfx) noexcept;
static ID3D11Device* GetDevice(DXGraphics& gfx) noexcept;
static DxgiInfoManager& GetInfoManager(DXGraphics& gfx);
};
}
\ No newline at end of file
......@@ -7,6 +7,8 @@
#include <d3dcompiler.h>
#include "../imgui/imgui_impl_dx11.h"
#include "../imgui/imgui_impl_win32.h"
#include "../DepthStencil.h"
namespace wrl = Microsoft::WRL;
namespace dx = DirectX;
#pragma comment (lib,"d3d11.lib")
......@@ -57,38 +59,11 @@ DXGraphics::DXGraphics(HWND hWnd,int width,int height)
&pContext
));
// gain access to texture subresource in swap chain (back buffer)
wrl::ComPtr<ID3D11Resource> pBackBuffer;
GFX_THROW_INFO(pSwap->GetBuffer(0, __uuidof(ID3D11Resource), &pBackBuffer));
GFX_THROW_INFO(pDevice->CreateRenderTargetView(pBackBuffer.Get(), nullptr, &pTarget));
// create depth stensil texture
wrl::ComPtr<ID3D11Texture2D> pDepthStencil;
D3D11_TEXTURE2D_DESC descDepth = {};
descDepth.Width = width;
descDepth.Height = height;
descDepth.MipLevels = 1u;
descDepth.ArraySize = 1u;
descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
descDepth.SampleDesc.Count = 1u;
descDepth.SampleDesc.Quality = 0u;
descDepth.Usage = D3D11_USAGE_DEFAULT;
descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
GFX_THROW_INFO(pDevice->CreateTexture2D(&descDepth, nullptr, &pDepthStencil));
// create view of depth stensil texture
D3D11_DEPTH_STENCIL_VIEW_DESC descDSV = {};
descDSV.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
descDSV.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
descDSV.Texture2D.MipSlice = 0u;
GFX_THROW_INFO(pDevice->CreateDepthStencilView(
pDepthStencil.Get(), &descDSV, &pDSV
));
// bind depth stensil view to OM
pContext->OMSetRenderTargets(1u, pTarget.GetAddressOf(), pDSV.Get());
// configure viewport
// viewport always fullscreen (for now)
D3D11_VIEWPORT vp;
vp.Width = (float)width;
vp.Height = (float)height;
......@@ -142,9 +117,18 @@ void DXGraphics::BeginFrame(float red, float green, float blue) noexcept
ImGui::NewFrame();
}
const float color[] = { red,green,blue,1.0f };
const float color[] = { red,green,blue,0.0f };
pContext->ClearRenderTargetView(pTarget.Get(), color);
pContext->ClearDepthStencilView(pDSV.Get(), D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0u);
}
void DXGraphics::BindSwapBuffer() noexcept
{
pContext->OMSetRenderTargets(1u, pTarget.GetAddressOf(), nullptr);
}
void DXGraphics::BindSwapBuffer(const DepthStencil& ds) noexcept
{
pContext->OMSetRenderTargets(1u, pTarget.GetAddressOf(), ds.pDepthStencilView.Get());
}
void DXGraphics::DrawIndexed(UINT count) noxnd
......
......@@ -19,8 +19,7 @@ namespace Bind
class DXGraphics
{
friend Bind::Bindable;
friend class GraphicsResource;
public:
class Exception : public ChiliException
{
......@@ -74,6 +73,8 @@ public:
~DXGraphics();
void EndFrame();
void BeginFrame(float red, float green, float blue) noexcept;
void BindSwapBuffer() noexcept;
void BindSwapBuffer(const class DepthStencil& ds) noexcept;
size_t GetScreenWidth() { return screenWidth; }
size_t GetScreenHeight() { return screenHeight; }
......@@ -90,6 +91,6 @@ private:
Microsoft::WRL::ComPtr<ID3D11Device> pDevice;
Microsoft::WRL::ComPtr<IDXGISwapChain> pSwap ;
Microsoft::WRL::ComPtr<ID3D11DeviceContext> pContext ;
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> pTarget ;
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> pTarget;
Microsoft::WRL::ComPtr<ID3D11DepthStencilView> pDSV;
};
\ No newline at end of file
#include "FrameCommander.h"
//#include "../RenderTarget.h"
void FrameCommander::Execute(DXGraphics& gfx, float dt) const noxnd
{
ds.Clear(gfx);
//gfx.BindSwapBuffer(ds);
using namespace Bind;
Rasterizer::Resolve(gfx, true)->Bind(gfx); //backface culling is not needed, because there are literary no backfaces
Stencil::Resolve(gfx, Stencil::Mode::Default)->Bind(gfx);
gfx.BindSwapBuffer(ds);
if (blurMod == 0.0f)
{
{
passes[0].Execute(gfx); //most models
Stencil::Resolve(gfx, Stencil::Mode::ReadOnly)->Bind(gfx); //::HUD
passes[1].Execute(gfx);
}
else
{
//binding new targets
rt.BindAsTarget(gfx,ds);
passes[0].Execute(gfx); //most models
Stencil::Resolve(gfx, Stencil::Mode::ReadOnly)->Bind(gfx); //::HUD
passes[1].Execute(gfx);
// fullscreen funky pass
gfx.BindSwapBuffer();
rt.BindAsTexture(gfx, 0);
pVbFull->Bind(gfx);
pIbFull->Bind(gfx);
pVsFull->Bind(gfx);
pPsFull->Bind(gfx);
pLayoutFull->Bind(gfx);
gfx.DrawIndexed(pIbFull->GetCount());
}
Stencil::Resolve(gfx, Stencil::Mode::ReadOnly)->Bind(gfx); //::HUD
passes[1].Execute(gfx); //models that generally have alpha, so they are supposed to be drawn after normal models
Stencil::Resolve(gfx, Stencil::Mode::HUD)->Bind(gfx); //::HUD
passes[3].Execute(gfx);
passes[4].Execute(gfx); //text
} //if the passes need to be rearranged in some way
//than all darwables that depend on them should be ajusted accordingly
FrameCommander::FrameCommander(DXGraphics& gfx) :
gfx(gfx),
ds(gfx, gfx.GetScreenWidth(), gfx.GetScreenHeight()),
rt(gfx, gfx.GetScreenWidth(), gfx.GetScreenHeight())
{
namespace dx = DirectX;
// setup fullscreen geometry
Dvtx::VertexLayout lay;
lay.Append(Dvtx::VertexLayout::Position2D);
Dvtx::VertexBuffer bufFull{ lay };
bufFull.EmplaceBack(dx::XMFLOAT2{ -1,1 });
bufFull.EmplaceBack(dx::XMFLOAT2{ 1,1 });
bufFull.EmplaceBack(dx::XMFLOAT2{ -1,-1 });
bufFull.EmplaceBack(dx::XMFLOAT2{ 1,-1 });
pVbFull = Bind::VertexBuffer::Resolve(gfx, L"$Full", std::move(bufFull));
std::vector<unsigned short> indices = { 0,1,2,1,3,2 };
pIbFull = Bind::IndexBuffer::Resolve(gfx, L"$Full", std::move(indices));
// setup fullscreen shaders
pPsFull = Bind::PixelShader::Resolve(gfx, L"FunkPS.cso");
pVsFull = Bind::VertexShader::Resolve(gfx, L"FullscreenVS.cso");
pLayoutFull = Bind::InputLayout::Resolve(gfx, lay, pVsFull->GetBytecode());
}
void FrameCommander::Reset() noexcept
{
for (auto& p : passes)
......
......@@ -4,10 +4,13 @@
#include "DXGraphics.h"
#include "Job.h"
#include "Pass.h"
#include "../DepthStencil.h"
#include "../RenderTarget.h"
class FrameCommander //submits drawables
{
public:
FrameCommander(DXGraphics& gfx);;
void Accept( Job job,size_t target ) noexcept
{
passes[target].Accept( job );
......@@ -15,16 +18,15 @@ public:
void Execute(DXGraphics& gfx, float dt) const noxnd;
void Reset() noexcept;
static void SetBlurMod(float blur); //make friend of blur commander or something
private:
static float blurMod; //0.0f - no blur; 1.0f - very dank blur
private:
std::array<Pass, 5> passes;
DXGraphics& gfx;
DepthStencil ds;
RenderTarget rt;
std::shared_ptr<Bind::VertexBuffer> pVbFull;
std::shared_ptr<Bind::IndexBuffer> pIbFull;
std::shared_ptr<Bind::VertexShader> pVsFull;
std::shared_ptr<Bind::PixelShader> pPsFull;
std::shared_ptr<Bind::InputLayout> pLayoutFull;
};
\ No newline at end of file
......@@ -24,3 +24,9 @@
#else
#define INFOMAN(gfx) HRESULT hr; DxgiInfoManager& infoManager = GetInfoManager((gfx))
#endif
#ifdef NDEBUG
#define INFOMAN_NOHR(gfx)
#else
#define INFOMAN_NOHR(gfx) DxgiInfoManager& infoManager = GetInfoManager((gfx))
#endif
\ No newline at end of file
......@@ -86,12 +86,32 @@ namespace Bind
};
break;
}
case Bind::TransformCbuf::DataType::NotSpecified: assert(false && "please,specify data type fot transform constant buffer");
case Bind::TransformCbuf::DataType::NotSpecified:
assert(false && "please,specify data type fot transform constant buffer");
{
const auto modelView = pParent->GetTransformXM() * gfx.GetCamera();
return {
DirectX::XMMatrixTranspose(modelView),
DirectX::XMMatrixTranspose(
modelView *
gfx.GetProjection()
)
};
}
default:
assert(false && "programmer missed the case");
{
const auto modelView = pParent->GetTransformXM() * gfx.GetCamera();
return {
DirectX::XMMatrixTranspose(modelView),
DirectX::XMMatrixTranspose(
modelView *
gfx.GetProjection()
)
};
}
break;
}
}
}
std::unique_ptr<VertexConstantBuffer<TransformCbuf::Transforms>> TransformCbuf::pVcbuf;
}
\ No newline at end of file
struct VSOut
{
float2 uv : Texcoord;
float4 pos : SV_Position;
};
VSOut main(float2 pos : Position)
{
VSOut vso;
vso.pos = float4(pos, 0.0f, 1.0f);
vso.uv = float2((pos.x + 1) / 2.0f, -(pos.y - 1) / 2.0f);
return vso;
}
\ No newline at end of file
Texture2D tex;
SamplerState splr;
static const int r = 3;
static const float divisor = (2 * r + 1) * (2 * r + 1);
float4 main(float2 uv : Texcoord) : SV_Target
{
uint width, height;
tex.GetDimensions(width, height);
const float dx = 1.0f / width;
const float dy = 1.0f / height;
float3 acc = float3(0.0f, 0.0f, 0.0f);
for (int y = -r; y <= r; y++)
{
for (int x = -r; x <= r; x++)
{
const float2 tc = uv + float2(dx * x, dy * y);
acc += tex.Sample(splr, tc).rgb;
}
}
return float4(acc / divisor, 1.0f);
}
\ No newline at end of file
......@@ -22,7 +22,8 @@ Game::Game():
td(wnd.DXGfx(),fc),
hud(menu,fc, wnd.DXGfx(),cm.GetPlayerManager().GetActionBox(),cm),
menu(cm),
eh(wnd.DXGfx())
eh(wnd.DXGfx()),
fc(wnd.DXGfx())
//gfx( wnd.GetHWND() ),
//scene(gfx,map,menu)
{
......@@ -150,18 +151,6 @@ int Game::Go()
cm.UpdateCombatState(dt);
am.Update();
hud.Animate(dt);
TD::DrawString(std::to_wstring(FrameCommander::blurMod), Vec2{ 0.0f, 0.0f },Colors::Magenta,0.09f);
}
}
......
#include "GraphicsResource.h"
ID3D11DeviceContext* GraphicsResource::GetContext(DXGraphics& gfx) noexcept
{
return gfx.pContext.Get();
}
ID3D11Device* GraphicsResource::GetDevice(DXGraphics& gfx) noexcept
{
return gfx.pDevice.Get();
}
DxgiInfoManager& GraphicsResource::GetInfoManager(DXGraphics& gfx)
{
#ifndef NDEBUG
return gfx.infoManager;
#else
throw std::logic_error("YouFuckedUp! (tried to access gfx.infoManager in Release config)");
#endif
}
#pragma once
#include "Framework\DXGraphics.h"
class DXGraphics;
class GraphicsResource
{
protected:
static ID3D11DeviceContext* GetContext(DXGraphics& gfx) noexcept;
static ID3D11Device* GetDevice(DXGraphics& gfx) noexcept;
static DxgiInfoManager& GetInfoManager(DXGraphics& gfx);
};
\ No newline at end of file
#include "RenderTarget.h"
#include "Framework\GraphicsThrowMacros.h"
#include "DepthStencil.h"
namespace wrl = Microsoft::WRL;
RenderTarget::RenderTarget(DXGraphics& gfx, size_t width, size_t height)
{
INFOMAN(gfx);
// create texture resource
D3D11_TEXTURE2D_DESC textureDesc = {};
textureDesc.Width = (UINT)width;
textureDesc.Height = (UINT)height;
textureDesc.MipLevels = 1;
textureDesc.ArraySize = 1;
textureDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
textureDesc.SampleDesc.Count = 1;
textureDesc.SampleDesc.Quality = 0;
textureDesc.Usage = D3D11_USAGE_DEFAULT;
textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
textureDesc.CPUAccessFlags = 0;
textureDesc.MiscFlags = 0;
wrl::ComPtr<ID3D11Texture2D> pTexture;
GFX_THROW_INFO(GetDevice(gfx)->CreateTexture2D(
&textureDesc, nullptr, &pTexture
));
// create the resource view on the texture
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
srvDesc.Format = textureDesc.Format;
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MostDetailedMip = 0;
srvDesc.Texture2D.MipLevels = 1;
GFX_THROW_INFO(GetDevice(gfx)->CreateShaderResourceView(
pTexture.Get(), &srvDesc, &pTextureView
));
// create the target view on the texture
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc = {};
rtvDesc.Format = textureDesc.Format;
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
rtvDesc.Texture2D = D3D11_TEX2D_RTV{ 0 };
GFX_THROW_INFO(GetDevice(gfx)->CreateRenderTargetView(
pTexture.Get(), &rtvDesc, &pTargetView
));
}
void RenderTarget::BindAsTexture(DXGraphics& gfx, size_t slot) const noexcept
{
GetContext(gfx)->PSSetShaderResources((UINT)slot, 1u, pTextureView.GetAddressOf());
}
void RenderTarget::BindAsTarget(DXGraphics& gfx) const noexcept
{
GetContext(gfx)->OMSetRenderTargets(1, pTargetView.GetAddressOf(), nullptr);
}
void RenderTarget::BindAsTarget(DXGraphics& gfx, const DepthStencil& depthStencil) const noexcept
{
GetContext(gfx)->OMSetRenderTargets(1, pTargetView.GetAddressOf(), depthStencil.pDepthStencilView.Get());
}
#pragma once
#include "Framework/DXGraphics.h"
#include "GraphicsResource.h"
class DepthStencil;
class RenderTarget : public GraphicsResource
{
public:
RenderTarget(DXGraphics& gfx, size_t width, size_t height);
void BindAsTexture(DXGraphics& gfx, size_t slot) const noexcept;
void BindAsTarget(DXGraphics& gfx) const noexcept;
void BindAsTarget(DXGraphics& gfx, const DepthStencil& depthStencil) const noexcept;
private:
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> pTextureView;
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> pTargetView;
};
\ No newline at end of file