4#include <alicorn/std/vector.hpp>
5#include <d3dcompiler.h>
6#pragma comment(lib, "d3dcompiler.lib" )
8using Shader_t = ::covellite::api::renderer::DirectX::Shader;
10 auto Shader_t::Compile(
const BinaryData_t & _Header,
11 const BinaryData_t & _Body, LPCSTR _pEntryPoint, LPCSTR _pTarget) -> ComPtr_t<ID3DBlob>
13 using namespace ::alicorn::extension::std;
14 using ::alicorn::extension::cpp::IS_RELEASE_CONFIGURATION;
16 const auto FullShaderBody = _Header + _Body;
18 constexpr DWORD ShaderFlags = (IS_RELEASE_CONFIGURATION) ? 0 :
19 D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;
21 ::Microsoft::WRL::ComPtr<ID3DBlob> pCompiledEffect;
22 ::Microsoft::WRL::ComPtr<ID3DBlob> pError;
23 auto Result = D3DCompile(FullShaderBody.data(), FullShaderBody.size(),
24 (::std::string(
"[Covellite::Api]: ") + _pEntryPoint).c_str(),
25 NULL, NULL, _pEntryPoint, _pTarget, ShaderFlags, 0,
26 &pCompiledEffect, &pError);
29 throw STD_EXCEPTION <<
"Failed: " << Result <<
30 " [header line: " << GetHeaderLines(_Header) <<
", "
31 << (pError ? (
char *)pError->GetBufferPointer() :
"Unknown error")
35 return pCompiledEffect;
38 ::std::string Shader_t::GetVersion(
const String_t & _Kind)
40 return (_Kind == uT(
"Pixel")) ?
"ps_4_0" :
"vs_4_0";
43 auto Shader_t::Convert(const ::std::string & _Source) -> BinaryData_t
45 return BinaryData_t{ ::std::begin(_Source), ::std::end(_Source) };
48 ::std::size_t Shader_t::GetHeaderLines(
const BinaryData_t & _Header)
50 ::std::size_t Result = 0;
52 auto itPosition = _Header.cbegin();
55 itPosition = ::std::find(itPosition, _Header.cend(),
'\n');
56 if (itPosition == _Header.cend())
break;