5using Microsoft::WRL::ComPtr;
10 raster.FillMode=D3D11_FILL_SOLID;
raster.CullMode=D3D11_CULL_BACK;
raster.FrontCounterClockwise=TRUE;
11 raster.DepthClipEnable=TRUE;
raster.MultisampleEnable=TRUE;
12 depth.DepthEnable=TRUE;
depth.DepthWriteMask=D3D11_DEPTH_WRITE_MASK_ALL;
depth.DepthFunc=D3D11_COMPARISON_LESS_EQUAL;
13 depth.StencilReadMask=
depth.StencilWriteMask=255;
14 depth.FrontFace=
depth.BackFace={D3D11_STENCIL_OP_KEEP,D3D11_STENCIL_OP_KEEP,D3D11_STENCIL_OP_KEEP,D3D11_COMPARISON_ALWAYS};
15 for(
auto& target:
blend.RenderTarget)
16 target={FALSE,D3D11_BLEND_ONE,D3D11_BLEND_ZERO,D3D11_BLEND_OP_ADD,D3D11_BLEND_ONE,D3D11_BLEND_ZERO,D3D11_BLEND_OP_ADD,D3D11_COLOR_WRITE_ENABLE_ALL};
24 status=
"native draw context not initialized";
37 const D3D11_VIEWPORT next{0,0,float(desc.Width),float(desc.Height),0,1};
47 if(!
owner || !newColor)
return E_INVALIDARG;
48 if(!std::isfinite(next.Width) || !std::isfinite(next.Height) || next.Width<1 || next.Height<1
49 || !std::isfinite(next.TopLeftX) || !std::isfinite(next.TopLeftY) || next.TopLeftX<0 || next.TopLeftY<0
50 || !std::isfinite(next.MinDepth) || !std::isfinite(next.MaxDepth)
51 || next.MinDepth<0 || next.MaxDepth>1 || next.MinDepth>next.MaxDepth)
return E_INVALIDARG;
52 ComPtr<ID3D11Device> device;newColor->GetDevice(&device);
if(device.Get()!=
owner->
Device())
return E_INVALIDARG;
53 if(newDepth){device.Reset();newDepth->GetDevice(&device);
if(device.Get()!=
owner->
Device())
return E_INVALIDARG;}
74 if(fixedPoints)rasterDescription.CullMode=D3D11_CULL_NONE;
80 ComPtr<ID3D11RasterizerState> created;
if(FAILED(hr=
owner->
Device()->CreateRasterizerState(&rasterDescription,&created)))
return hr;
90 ComPtr<ID3D11DepthStencilState> created;
if(FAILED(hr=
owner->
Device()->CreateDepthStencilState(&
pipeline.
depth,&created)))
return hr;
100 ComPtr<ID3D11BlendState> created;
if(FAILED(hr=
owner->
Device()->CreateBlendState(&
pipeline.
blend,&created)))
return hr;
112 Geometry11* indices,INT baseVertex,UINT streamOffset)
115 if(!count)
return S_FALSE;
116 uint64_t elements=0;D3D11_PRIMITIVE_TOPOLOGY topology{};
120 case Primitive11::Lines:elements=uint64_t(count)*2;topology=D3D11_PRIMITIVE_TOPOLOGY_LINELIST;
break;
122 case Primitive11::Triangles:elements=uint64_t(count)*3;topology=D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
break;
125 default:
return E_INVALIDARG;
127 if(!layout.
Valid() || streamOffset>vertices.
Size() || elements>UINT_MAX)
return E_INVALIDARG;
128 const size_t vertexCount=(vertices.
Size()-streamOffset)/layout.
stride;
131 const UINT indexSize=indices->
Indices32() ? 4 : 2;
132 if(uint64_t(first)+elements>indices->
Size()/indexSize)
return E_INVALIDARG;
134 for(
size_t i=first;i<size_t(first)+elements;++i)
136 uint32_t indexValue=0;memcpy(&indexValue,indices->
Bytes().data()+i*indexSize,indexSize);
137 const int64_t adjusted=int64_t(indexValue)+baseVertex;
138 if(adjusted<0 || uint64_t(adjusted)>=vertexCount)
return E_INVALIDARG;
141 else if(uint64_t(first)+elements>vertexCount)
return E_INVALIDARG;
154 if(FAILED(hr))
return hr;context->IASetPrimitiveTopology(topology);
157 if(uint64_t(count)*3*
sizeof(uint32_t)>UINT_MAX)
return E_INVALIDARG;
158 const UINT size=count*3*
sizeof(uint32_t);
160 uint32_t* output=
nullptr;
if(FAILED(hr=
fanIndices.
Lock(0,size,
reinterpret_cast<void**
>(&output),
false,
true)))
return hr;
161 const auto at=[&](UINT n){uint32_t value=first+n;
if(indices){value=0;
const UINT stride=indices->
Indices32() ? 4 : 2;
162 memcpy(&value,indices->
Bytes().data()+
size_t(first+n)*stride,stride);}
return value;};
163 for(UINT i=0;i<count;++i){output[i*3]=at(0);output[i*3+1]=at(i+1);output[i*3+2]=at(i+2);}
166 else if(indices){
if(FAILED(hr=indices->
BindIndices(context)))
return hr;context->DrawIndexed(UINT(elements),first,baseVertex);}
167 else context->Draw(UINT(elements),first);
173 if(!
owner || !source || !size)
return E_INVALIDARG;
HRESULT hr;
174 uint64_t required=count;
179 if(!layout.
Valid() || required>size/layout.
stride)
return E_INVALIDARG;
181 void* output=
nullptr;
if(FAILED(hr=
immediate.
Lock(0,size,&output,
false,
true)))
return hr;
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
void UnbindShaderResources()
ID3D11DeviceContext * Context() const
ID3D11RenderTargetView * SceneTarget() const
ID3D11Device * Device() const
const SceneDepth11 & Depth() const
Microsoft::WRL::ComPtr< ID3D11RenderTargetView > color
const RECT & Scissor() const
Pipeline11 cachedPipeline
ID3D11DepthStencilState * cachedDepth
std::map< Key< D3D11_RASTERIZER_DESC >, Microsoft::WRL::ComPtr< ID3D11RasterizerState > > rasterStates
HRESULT ApplyPipeline(bool fixedPoints=false)
void Scissor(const RECT &value)
std::map< Key< D3D11_DEPTH_STENCIL_DESC >, Microsoft::WRL::ComPtr< ID3D11DepthStencilState > > depthStates
std::map< Key< D3D11_BLEND_DESC >, Microsoft::WRL::ComPtr< ID3D11BlendState > > blendStates
HRESULT Restore(const Saved &saved)
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)
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)
HRESULT Initialize(ID3D11Device *device, const std::filesystem::path &shaderDirectory={})
const std::string & Status() const
HRESULT Bind(ID3D11DeviceContext *context, const FixedState11 &state, bool pointList=false)
void GeometryDraw(UINT primitives)
static FrameProfiler11 & Get()
HRESULT Create(ID3D11Device *device, UINT bytes, bool dynamic, bool index=false, bool indices32=false)
HRESULT BindIndices(ID3D11DeviceContext *context)
HRESULT Lock(UINT offset, UINT size, void **destination, bool readOnly=false, bool discard=false)
HRESULT BindVertices(ID3D11DeviceContext *context, const VertexLayout11 &layout, UINT byteOffset, bool canonical)
const std::vector< uint8_t > & Bytes() const
HRESULT Bind(ID3D11DeviceContext *context, UINT pass, const VertexLayout11 &layout, const D3D11_VIEWPORT &viewport)
const std::string & Status() const
HRESULT Initialize(ID3D11Device *device, const std::filesystem::path &shaderDirectory={})
const D3D11_TEXTURE2D_DESC & Description() const
ID3D11DepthStencilView * WriteView() const
Microsoft::WRL::ComPtr< ID3D11DepthStencilView > depth
Microsoft::WRL::ComPtr< ID3D11RenderTargetView > color
DirectX::XMFLOAT4 viewport
D3D11_DEPTH_STENCIL_DESC depth
D3D11_RASTERIZER_DESC raster
static constexpr UINT Absent
UINT PackedColors() const