Small cleanup
This commit is contained in:
5
project/src/Buffers/DX11Viewport.cpp
Normal file
5
project/src/Buffers/DX11Viewport.cpp
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
//
|
||||||
|
// Created by Bram on 16/01/2025.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "DX11Viewport.h"
|
||||||
51
project/src/Buffers/DX11Viewport.h
Normal file
51
project/src/Buffers/DX11Viewport.h
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
#ifndef GP1_DIRECTX_DX11VIEWPORT_H
|
||||||
|
#define GP1_DIRECTX_DX11VIEWPORT_H
|
||||||
|
|
||||||
|
#include <d3d11.h>
|
||||||
|
|
||||||
|
class DX11Viewport
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DX11Viewport(float width, float height, float topLeftX = 0.0f, float topLeftY = 0.0f, float minDepth = 0.0f, float maxDepth = 1.0f)
|
||||||
|
{
|
||||||
|
viewport.Width = width;
|
||||||
|
viewport.Height = height;
|
||||||
|
viewport.TopLeftX = topLeftX;
|
||||||
|
viewport.TopLeftY = topLeftY;
|
||||||
|
viewport.MinDepth = minDepth;
|
||||||
|
viewport.MaxDepth = maxDepth;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Apply(ID3D11DeviceContext* context)
|
||||||
|
{
|
||||||
|
if (context)
|
||||||
|
{
|
||||||
|
context->RSSetViewports(1, &viewport);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetDimensions(float width, float height)
|
||||||
|
{
|
||||||
|
viewport.Width = width;
|
||||||
|
viewport.Height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetPosition(float topLeftX, float topLeftY)
|
||||||
|
{
|
||||||
|
viewport.TopLeftX = topLeftX;
|
||||||
|
viewport.TopLeftY = topLeftY;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetDepthRange(float minDepth, float maxDepth)
|
||||||
|
{
|
||||||
|
viewport.MinDepth = minDepth;
|
||||||
|
viewport.MaxDepth = maxDepth;
|
||||||
|
}
|
||||||
|
|
||||||
|
const D3D11_VIEWPORT& GetViewport() const { return viewport; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
D3D11_VIEWPORT viewport;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //GP1_DIRECTX_DX11VIEWPORT_H
|
||||||
@@ -9,7 +9,6 @@ public:
|
|||||||
SamplerState(ID3D11Device* device);
|
SamplerState(ID3D11Device* device);
|
||||||
~SamplerState();
|
~SamplerState();
|
||||||
|
|
||||||
|
|
||||||
bool Initialize();
|
bool Initialize();
|
||||||
ID3D11SamplerState* GetSamplerState() const { return m_samplerState; }
|
ID3D11SamplerState* GetSamplerState() const { return m_samplerState; }
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "../Utils.h"
|
#include "../Utils.h"
|
||||||
#include "../Effects/ShadowEffect.h"
|
#include "../Effects/ShadowEffect.h"
|
||||||
#include "../Effects/Effect.h"
|
#include "../Effects/Effect.h"
|
||||||
|
#include "../Buffers/DX11Viewport.h"
|
||||||
|
|
||||||
void ShadowTestScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr, Camera *camera) {
|
void ShadowTestScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr, Camera *camera) {
|
||||||
// Initialize shadow map buffer
|
// Initialize shadow map buffer
|
||||||
@@ -82,12 +83,8 @@ void ShadowTestScene::Render(ID3D11DeviceContext *devicePtr, ID3D11RenderTargetV
|
|||||||
// Shadow map pass
|
// Shadow map pass
|
||||||
|
|
||||||
// Set the viewport to match the shadow map size
|
// Set the viewport to match the shadow map size
|
||||||
D3D11_VIEWPORT shadowViewport = {};
|
DX11Viewport ShadowViewport(1024 * 4, 1024 * 4);
|
||||||
shadowViewport.Width = static_cast<float>(1024 * 4);
|
ShadowViewport.Apply(devicePtr);
|
||||||
shadowViewport.Height = static_cast<float>(1024 * 4);
|
|
||||||
shadowViewport.MinDepth = 0.0f;
|
|
||||||
shadowViewport.MaxDepth = 1.0f;
|
|
||||||
devicePtr->RSSetViewports(1, &shadowViewport);
|
|
||||||
|
|
||||||
devicePtr->OMSetRenderTargets(0, nullptr, m_ShadowMapBuffer->GetDepthStencilView()); // Set the shadow map as the render target
|
devicePtr->OMSetRenderTargets(0, nullptr, m_ShadowMapBuffer->GetDepthStencilView()); // Set the shadow map as the render target
|
||||||
devicePtr->ClearDepthStencilView(m_ShadowMapBuffer->GetDepthStencilView(), D3D11_CLEAR_DEPTH, 1.0f, 0); // Clear the shadow map
|
devicePtr->ClearDepthStencilView(m_ShadowMapBuffer->GetDepthStencilView(), D3D11_CLEAR_DEPTH, 1.0f, 0); // Clear the shadow map
|
||||||
@@ -111,11 +108,8 @@ void ShadowTestScene::Render(ID3D11DeviceContext *devicePtr, ID3D11RenderTargetV
|
|||||||
|
|
||||||
// Set the depthmap correctly
|
// Set the depthmap correctly
|
||||||
|
|
||||||
shadowViewport.Width = static_cast<float>(640);
|
DX11Viewport ColorViewport(640, 480);
|
||||||
shadowViewport.Height = static_cast<float>(480);
|
ColorViewport.Apply(devicePtr);
|
||||||
shadowViewport.MinDepth = 0.0f;
|
|
||||||
shadowViewport.MaxDepth = 1.0f;
|
|
||||||
devicePtr->RSSetViewports(1, &shadowViewport);
|
|
||||||
|
|
||||||
|
|
||||||
devicePtr->OMSetRenderTargets(1, &renderTargetViewPtr, depthStencilViewPtr);
|
devicePtr->OMSetRenderTargets(1, &renderTargetViewPtr, depthStencilViewPtr);
|
||||||
|
|||||||
Reference in New Issue
Block a user