Rise
The Vieneo Province
Toggle main menu visibility
Loading...
Searching...
No Matches
Materials11.cpp
Go to the documentation of this file.
1
#include "
Materials11.h
"
2
#include "
ShaderBytecode11.h
"
3
#include "
Shaders/Catalog11.generated.h
"
4
#include <cstring>
5
#include <cmath>
6
7
namespace
Rendering
8
{
9
void
Materials11::Reset
()
10
{
11
programs
.clear();
values
=
Parameters11
{};
samplers
.clear();
device
.Reset();
12
status
=
"native material programs not initialized"
;
13
}
14
HRESULT
Materials11::Initialize
(ID3D11Device* native,
const
std::filesystem::path& shaderDirectory)
15
{
16
Reset
();
if
(!native)
return
E_INVALIDARG;
device
=native;
directory
=shaderDirectory;
17
for
(
const
auto
& entry:
CustomUISamplers
)
18
{
19
Microsoft::WRL::ComPtr<ID3D11SamplerState> sampler;
20
const
HRESULT
hr=
device
->CreateSamplerState(&entry.description,&sampler);
21
if
(FAILED(hr))
return
hr;
values
.
Sampler
(entry.name,sampler.Get());
samplers
.push_back(std::move(sampler));
22
}
23
status
=
"native material programs ready"
;
return
S_OK;
24
}
25
HRESULT
Materials11::Bind
(ID3D11DeviceContext* context,UINT pass,
const
VertexLayout11
& layout,
const
D3D11_VIEWPORT& viewport)
26
{
27
if
(!
device
|| !context)
return
E_UNEXPECTED;
28
Microsoft::WRL::ComPtr<ID3D11Device> contextDevice;context->GetDevice(&contextDevice);
29
if
(contextDevice.Get()!=
device
.Get())
return
E_INVALIDARG;
30
if
(!layout.
Valid
() || !std::isfinite(viewport.Width) || !std::isfinite(viewport.Height) || viewport.Width<1 || viewport.Height<1)
return
E_INVALIDARG;
31
const
Key
key{pass,layout};
auto
found=
programs
.find(key);
32
if
(found==
programs
.end())
33
{
34
const
ShaderPass11
* selected=
nullptr
;
35
for
(
const
auto
& candidate:
CustomUIPasses
)
if
(!strcmp(candidate.technique,
"TShader"
) && candidate.index==pass){selected=&candidate;
break
;}
36
if
(!selected)
return
E_INVALIDARG;
37
auto
program=std::make_unique<Program11>();
38
const
auto
vertex=
ReadShaderBytecode11
(
directory
/(std::string(
"CustomUI-"
)+selected->
vertex
+
"-1.cso"
));
39
const
auto
pixel=
ReadShaderBytecode11
(
directory
/(std::string(
"CustomUI-"
)+selected->
pixel
+
"-1.cso"
));
40
const
auto
elements=layout.
Elements
();
41
const
HRESULT
hr=program->Create(
device
.Get(),vertex.data(),vertex.size(),pixel.data(),pixel.size(),
42
elements.data(),UINT(elements.size()),layout.
PackedColors
());
43
if
(FAILED(hr)){
status
=program->Status();
return
hr;}
44
found=
programs
.emplace(key,std::move(program)).first;
45
}
46
values
.
Set
(
"_risePixelCenterOffset"
,DirectX::XMFLOAT2(1/viewport.Width,-1/viewport.Height));
47
context->GSSetShader(
nullptr
,
nullptr
,0);context->HSSetShader(
nullptr
,
nullptr
,0);context->DSSetShader(
nullptr
,
nullptr
,0);
48
const
HRESULT
hr=found->second->Bind(context,
values
);
if
(FAILED(hr))
status
=found->second->Status();
return
hr;
49
}
50
}
Catalog11.generated.h
HRESULT
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
Materials11.h
ShaderBytecode11.h
Rendering::Materials11::values
Parameters11 values
Definition
Materials11.h:26
Rendering::Materials11::device
Microsoft::WRL::ComPtr< ID3D11Device > device
Definition
Materials11.h:24
Rendering::Materials11::Reset
void Reset()
Definition
Materials11.cpp:9
Rendering::Materials11::Bind
HRESULT Bind(ID3D11DeviceContext *context, UINT pass, const VertexLayout11 &layout, const D3D11_VIEWPORT &viewport)
Definition
Materials11.cpp:25
Rendering::Materials11::programs
std::map< Key, std::unique_ptr< Program11 > > programs
Definition
Materials11.h:27
Rendering::Materials11::samplers
std::vector< Microsoft::WRL::ComPtr< ID3D11SamplerState > > samplers
Definition
Materials11.h:28
Rendering::Materials11::Initialize
HRESULT Initialize(ID3D11Device *device, const std::filesystem::path &shaderDirectory={})
Definition
Materials11.cpp:14
Rendering::Materials11::status
std::string status
Definition
Materials11.h:29
Rendering::Materials11::directory
std::filesystem::path directory
Definition
Materials11.h:25
Rendering::Parameters11
Definition
Program11.h:15
Rendering::Parameters11::Set
void Set(const std::string &name, const void *data, size_t bytes)
Definition
Program11.cpp:45
Rendering::Parameters11::Sampler
void Sampler(const std::string &name, ID3D11SamplerState *value)
Definition
Program11.cpp:66
Rendering
Definition
AdDiagnostics11.cpp:16
Rendering::CustomUISamplers
const ShaderSampler11 CustomUISamplers[]
Definition
Catalog11.generated.h:26
Rendering::CustomUIPasses
const ShaderPass11 CustomUIPasses[]
Definition
Catalog11.generated.h:7
Rendering::ReadShaderBytecode11
std::vector< char > ReadShaderBytecode11(const std::filesystem::path &path, HMODULE resourceModule=nullptr)
Definition
ShaderBytecode11.h:48
Rendering::Materials11::Key
Definition
Materials11.h:19
Rendering::ShaderPass11
Definition
Catalog11.generated.h:5
Rendering::ShaderPass11::vertex
const char * vertex
Definition
Catalog11.generated.h:5
Rendering::ShaderPass11::pixel
const char * pixel
Definition
Catalog11.generated.h:5
Rendering::VertexLayout11
Definition
Geometry11.h:12
Rendering::VertexLayout11::Valid
bool Valid() const
Definition
Geometry11.cpp:10
Rendering::VertexLayout11::PackedColors
UINT PackedColors() const
Definition
Geometry11.h:19
Rendering::VertexLayout11::Elements
std::vector< D3D11_INPUT_ELEMENT_DESC > Elements() const
Definition
Geometry11.cpp:24
Rendering
Materials11.cpp
Generated on
for Rise by
1.18.0