Rise
The Vieneo Province
Loading...
Searching...
No Matches
DrawContext11.h
Go to the documentation of this file.
1#pragma once
2#include "Device11.h"
3#include "Materials11.h"
4#include <array>
5#include <cstring>
6
7namespace Rendering
8{
11 {
12 D3D11_RASTERIZER_DESC raster{};
13 D3D11_DEPTH_STENCIL_DESC depth{};
14 D3D11_BLEND_DESC blend{};
16 float blendFactor[4]{1,1,1,1};
17 Pipeline11();
18 };
19
20 // Owns the production draw state. Buffers, input layouts, shaders and all
21 // raster/depth/blend work stay native; there is no D3D9 device underneath.
23 {
24 public:
25 HRESULT Initialize(Device11& device,const std::filesystem::path& shaderDirectory={});
26 void Reset();
27 void BindScene();
28 void ReleaseTargets();
29 HRESULT Target(ID3D11RenderTargetView* color,ID3D11DepthStencilView* depth,const D3D11_VIEWPORT& viewport);
30 HRESULT Draw(Geometry11& vertices,const VertexLayout11& layout,Primitive11 primitive,UINT first,UINT primitiveCount,
31 Geometry11* indices=nullptr,INT baseVertex=0,UINT streamOffset=0);
32 HRESULT DrawImmediate(const void* vertices,UINT bytes,const VertexLayout11& layout,Primitive11 primitive,UINT primitiveCount);
33 HRESULT ApplyPipeline(bool fixedPoints=false);
37 void Material(int pass) {material=pass;}
38 int Material() const {return material;}
39 void Scissor(const RECT& value);
40 const RECT& Scissor() const {return scissor;}
41 const D3D11_VIEWPORT& Viewport() const {return viewport;}
42 Device11* Owner() const {return owner;}
43 const std::string& Status() const {return status;}
44 struct Saved
45 {
48 int material=-1;
49 RECT scissor{};
50 D3D11_VIEWPORT viewport{};
51 Microsoft::WRL::ComPtr<ID3D11RenderTargetView> color;
52 Microsoft::WRL::ComPtr<ID3D11DepthStencilView> depth;
53 };
54 Saved Capture() const;
55 HRESULT Restore(const Saved& saved);
56 private:
57 template<class Description> using Key=std::array<unsigned char,sizeof(Description)>;
58 template<class Description> static Key<Description> Bytes(const Description& value)
59 {Key<Description> key{};memcpy(key.data(),&value,sizeof(value));return key;}
60 std::map<Key<D3D11_RASTERIZER_DESC>,Microsoft::WRL::ComPtr<ID3D11RasterizerState>> rasterStates;
61 std::map<Key<D3D11_DEPTH_STENCIL_DESC>,Microsoft::WRL::ComPtr<ID3D11DepthStencilState>> depthStates;
62 std::map<Key<D3D11_BLEND_DESC>,Microsoft::WRL::ComPtr<ID3D11BlendState>> blendStates;
63 Device11* owner=nullptr;
69 // Map-owned objects; Reset clears these before clearing their owners.
70 ID3D11RasterizerState* cachedRaster=nullptr;
71 ID3D11DepthStencilState* cachedDepth=nullptr;
72 ID3D11BlendState* cachedBlend=nullptr;
73 int material=-1;
74 RECT scissor{};
75 D3D11_VIEWPORT viewport{};
76 Microsoft::WRL::ComPtr<ID3D11RenderTargetView> color;
77 Microsoft::WRL::ComPtr<ID3D11DepthStencilView> depth;
80 std::string status;
81 };
82}
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
Microsoft::WRL::ComPtr< ID3D11RenderTargetView > color
const D3D11_VIEWPORT & Viewport() const
const RECT & Scissor() const
ID3D11DepthStencilState * cachedDepth
std::map< Key< D3D11_RASTERIZER_DESC >, Microsoft::WRL::ComPtr< ID3D11RasterizerState > > rasterStates
const std::string & Status() const
HRESULT ApplyPipeline(bool fixedPoints=false)
std::map< Key< D3D11_DEPTH_STENCIL_DESC >, Microsoft::WRL::ComPtr< ID3D11DepthStencilState > > depthStates
Materials11 & Materials()
std::map< Key< D3D11_BLEND_DESC >, Microsoft::WRL::ComPtr< ID3D11BlendState > > blendStates
FixedState11 & Fixed()
HRESULT DrawImmediate(const void *vertices, UINT bytes, const VertexLayout11 &layout, Primitive11 primitive, UINT primitiveCount)
ID3D11RasterizerState * cachedRaster
HRESULT Initialize(Device11 &device, const std::filesystem::path &shaderDirectory={})
ID3D11BlendState * cachedBlend
Microsoft::WRL::ComPtr< ID3D11DepthStencilView > depth
HRESULT Target(ID3D11RenderTargetView *color, ID3D11DepthStencilView *depth, const D3D11_VIEWPORT &viewport)
Device11 * Owner() const
HRESULT Draw(Geometry11 &vertices, const VertexLayout11 &layout, Primitive11 primitive, UINT first, UINT primitiveCount, Geometry11 *indices=nullptr, INT baseVertex=0, UINT streamOffset=0)
static Key< Description > Bytes(const Description &value)
std::array< unsigned char, sizeof(Description)> Key
Model.
Microsoft::WRL::ComPtr< ID3D11DepthStencilView > depth
Microsoft::WRL::ComPtr< ID3D11RenderTargetView > color
D3D11_DEPTH_STENCIL_DESC depth
D3D11_RASTERIZER_DESC raster
D3D11_BLEND_DESC blend