Khaotic Engine Reborn
Loading...
Searching...
No Matches
shadow_map Class Reference

Public Member Functions

bool initialize (ID3D11Device *device, int width, int height)
 
void shutdown ()
 
void set_render_target (ID3D11DeviceContext *context)
 
void clear_render_target (ID3D11DeviceContext *context, float depth=1.0f)
 
ID3D11ShaderResourceView * get_shader_resource_view ()
 

Detailed Description

Definition at line 5 of file shadow_map.h.

Constructor & Destructor Documentation

◆ shadow_map()

shadow_map::shadow_map ( )

Definition at line 3 of file shadow_map.cpp.

4 : depth_texture_(nullptr), depth_stencil_view_(nullptr), shader_resource_view_(nullptr), width_(0), height_(0) {}

◆ ~shadow_map()

shadow_map::~shadow_map ( )

Definition at line 6 of file shadow_map.cpp.

6 {
7 shutdown();
8}

Member Function Documentation

◆ clear_render_target()

void shadow_map::clear_render_target ( ID3D11DeviceContext * context,
float depth = 1.0f )

Definition at line 56 of file shadow_map.cpp.

56 {
57 context->ClearDepthStencilView(depth_stencil_view_, D3D11_CLEAR_DEPTH, depth, 0);
58}

◆ get_shader_resource_view()

ID3D11ShaderResourceView * shadow_map::get_shader_resource_view ( )

Definition at line 60 of file shadow_map.cpp.

60 {
61 return shader_resource_view_;
62}

◆ initialize()

bool shadow_map::initialize ( ID3D11Device * device,
int width,
int height )

Definition at line 10 of file shadow_map.cpp.

10 {
11 width_ = width;
12 height_ = height;
13
14 D3D11_TEXTURE2D_DESC texDesc = {};
15 texDesc.Width = width;
16 texDesc.Height = height;
17 texDesc.MipLevels = 1;
18 texDesc.ArraySize = 1;
19 texDesc.Format = DXGI_FORMAT_R24G8_TYPELESS;
20 texDesc.SampleDesc.Count = 1;
21 texDesc.Usage = D3D11_USAGE_DEFAULT;
22 texDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE;
23
24 if (FAILED(device->CreateTexture2D(&texDesc, nullptr, &depth_texture_)))
25 return false;
26
27 D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc = {};
28 dsvDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
29 dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
30 dsvDesc.Texture2D.MipSlice = 0;
31
32 if (FAILED(device->CreateDepthStencilView(depth_texture_, &dsvDesc, &depth_stencil_view_)))
33 return false;
34
35 D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
36 srvDesc.Format = DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
37 srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
38 srvDesc.Texture2D.MipLevels = 1;
39
40 if (FAILED(device->CreateShaderResourceView(depth_texture_, &srvDesc, &shader_resource_view_)))
41 return false;
42
43 return true;
44}

◆ set_render_target()

void shadow_map::set_render_target ( ID3D11DeviceContext * context)

Definition at line 52 of file shadow_map.cpp.

52 {
53 context->OMSetRenderTargets(0, nullptr, depth_stencil_view_);
54}

◆ shutdown()

void shadow_map::shutdown ( )

Definition at line 46 of file shadow_map.cpp.

46 {
47 if (shader_resource_view_) { shader_resource_view_->Release(); shader_resource_view_ = nullptr; }
48 if (depth_stencil_view_) { depth_stencil_view_->Release(); depth_stencil_view_ = nullptr; }
49 if (depth_texture_) { depth_texture_->Release(); depth_texture_ = nullptr; }
50}

The documentation for this class was generated from the following files: