12 #include "utils/ColorUtils.h" 13 #include "utils/Geometry.h" 18 #include <d3dx11effect.h> 19 #include <DirectXMath.h> 20 #include <d3dx11effect.h> 21 #include <wrl/client.h> 23 #define KODI_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT 4 25 typedef enum SHADER_METHOD {
26 SHADER_METHOD_RENDER_DEFAULT,
27 SHADER_METHOD_RENDER_TEXTURE_NOBLEND,
28 SHADER_METHOD_RENDER_FONT,
29 SHADER_METHOD_RENDER_TEXTURE_BLEND,
30 SHADER_METHOD_RENDER_MULTI_TEXTURE_BLEND,
31 SHADER_METHOD_RENDER_STEREO_INTERLACED_LEFT,
32 SHADER_METHOD_RENDER_STEREO_INTERLACED_RIGHT,
33 SHADER_METHOD_RENDER_STEREO_CHECKERBOARD_LEFT,
34 SHADER_METHOD_RENDER_STEREO_CHECKERBOARD_RIGHT,
35 SHADER_METHOD_RENDER_COUNT
43 virtual void OnDestroyDevice(
bool fatal)=0;
44 virtual void OnCreateDevice()=0;
50 bool m_bRegistered =
false;
56 static inline void XMStoreColor(
float* floats, DWORD dword)
58 floats[0] = float((dword >> 16) & 0xFF) * (1.0f / 255.0f);
59 floats[1] = float((dword >> 8) & 0xFF) * (1.0f / 255.0f);
60 floats[2] = float((dword >> 0) & 0xFF) * (1.0f / 255.0f);
61 floats[3] = float((dword >> 24) & 0xFF) * (1.0f / 255.0f);
64 static inline void XMStoreColor(DirectX::XMFLOAT4* floats, DWORD dword)
66 XMStoreColor(reinterpret_cast<float*>(floats), dword);
69 static inline void XMStoreColor(
float* floats,
unsigned char a,
unsigned char r,
unsigned char g,
unsigned char b)
71 floats[0] = r * (1.0f / 255.0f);
72 floats[1] = g * (1.0f / 255.0f);
73 floats[2] = b * (1.0f / 255.0f);
74 floats[3] = a * (1.0f / 255.0f);
77 static inline void XMStoreColor(DirectX::XMFLOAT4* floats,
unsigned char a,
unsigned char r,
unsigned char g,
unsigned char b)
79 XMStoreColor(reinterpret_cast<float*>(floats), a, r, g, b);
83 static inline void PSClearShaderResources(ID3D11DeviceContext* pContext)
85 ID3D11ShaderResourceView* shader_resource_views[KODI_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT] = {};
86 pContext->PSSetShaderResources(0, ARRAYSIZE(shader_resource_views), shader_resource_views);
89 static size_t BitsPerPixel(DXGI_FORMAT
fmt);
98 bool Create(UINT width, UINT height, UINT mipLevels, D3D11_USAGE usage, DXGI_FORMAT format,
const void* pInitData =
nullptr,
unsigned int srcPitch = 0);
101 bool GetDesc(D3D11_TEXTURE2D_DESC *desc)
const;
102 bool LockRect(UINT subresource, D3D11_MAPPED_SUBRESOURCE *res, D3D11_MAP mapType)
const;
103 bool UnlockRect(UINT subresource)
const;
106 ID3D11Texture2D* Get()
const {
return m_texture.Get(); }
107 ID3D11ShaderResourceView* GetShaderResource(DXGI_FORMAT format = DXGI_FORMAT_UNKNOWN);
108 ID3D11ShaderResourceView** GetAddressOfSRV(DXGI_FORMAT format = DXGI_FORMAT_UNKNOWN);
109 ID3D11RenderTargetView* GetRenderTarget();
110 ID3D11RenderTargetView** GetAddressOfRTV();
111 UINT GetWidth()
const {
return m_width; }
112 UINT GetHeight()
const {
return m_height; }
113 DXGI_FORMAT GetFormat()
const {
return m_format; }
114 void GenerateMipmaps();
117 static void DrawQuad(
const CPoint points[4],
118 UTILS::COLOR::Color color,
120 const CRect* texCoords,
121 SHADER_METHOD options = SHADER_METHOD_RENDER_TEXTURE_BLEND);
123 static void DrawQuad(
const CPoint points[4],
124 UTILS::COLOR::Color color,
126 ID3D11ShaderResourceView** view,
127 const CRect* texCoords,
128 SHADER_METHOD options = SHADER_METHOD_RENDER_TEXTURE_BLEND);
130 static void DrawQuad(
const CRect& coords,
131 UTILS::COLOR::Color color,
133 const CRect* texCoords,
134 SHADER_METHOD options = SHADER_METHOD_RENDER_TEXTURE_BLEND);
136 static void DrawQuad(
const CRect& coords,
137 UTILS::COLOR::Color color,
139 ID3D11ShaderResourceView** view,
140 const CRect* texCoords,
141 SHADER_METHOD options = SHADER_METHOD_RENDER_TEXTURE_BLEND);
143 void OnDestroyDevice(
bool fatal)
override;
144 void OnCreateDevice()
override;
147 ID3D11RenderTargetView* GetRenderTargetInternal(
unsigned idx = 0);
148 unsigned int GetMemoryUsage(
unsigned int pitch)
const;
149 bool CreateInternal(
const void* pInitData =
nullptr,
unsigned int srcPitch = 0);
152 void RestoreTexture();
165 DXGI_FORMAT m_format;
168 Microsoft::WRL::ComPtr<ID3D11Texture2D> m_texture;
169 Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_renderTargets[2];
171 std::map<DXGI_FORMAT, Microsoft::WRL::ComPtr<ID3D11ShaderResourceView>> m_views;
174 typedef std::map<std::string, std::string> DefinesMap;
181 bool Create(
const std::string &effectString, DefinesMap* defines);
183 bool SetFloatArray(LPCSTR handle,
const float* val,
unsigned int count);
184 bool SetMatrix(LPCSTR handle,
const float* mat);
185 bool SetTechnique(LPCSTR handle);
186 bool SetTexture(LPCSTR handle,
CD3DTexture &texture);
187 bool SetTexture(LPCSTR handle, ID3D11ShaderResourceView* resourceView);
188 bool SetResources(LPCSTR handle, ID3D11ShaderResourceView** ppSRViews,
size_t count);
189 bool SetConstantBuffer(LPCSTR handle, ID3D11Buffer *buffer);
190 bool SetScalar(LPCSTR handle,
float value);
191 void AddIncludePath(
const std::string& includePath);
192 bool Begin(UINT *passes, DWORD flags);
193 bool BeginPass(UINT pass);
197 ID3DX11Effect* Get()
const {
return m_effect.Get(); }
199 void OnDestroyDevice(
bool fatal)
override;
200 void OnCreateDevice()
override;
203 __declspec(nothrow) HRESULT __stdcall Open(D3D_INCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID *ppData, UINT *pBytes)
override;
204 __declspec(nothrow) HRESULT __stdcall Close(LPCVOID pData)
override;
209 std::string m_effectString;
210 DefinesMap m_defines;
211 Microsoft::WRL::ComPtr<ID3DX11Effect> m_effect;
212 Microsoft::WRL::ComPtr<ID3DX11EffectTechnique> m_techniquie;
213 Microsoft::WRL::ComPtr<ID3DX11EffectPass> m_currentPass;
214 std::set<std::string> m_includePaths;
222 bool Create(D3D11_BIND_FLAG type, UINT count, UINT stride, DXGI_FORMAT format, D3D11_USAGE usage,
const void* initData =
nullptr);
223 bool Map(
void** resource);
226 unsigned int GetStride() {
return m_stride; }
227 DXGI_FORMAT GetFormat() {
return m_format; }
228 ID3D11Buffer* Get()
const {
return m_buffer.Get(); }
230 void OnDestroyDevice(
bool fatal)
override;
231 void OnCreateDevice()
override;
234 bool CreateBuffer(
const void *pData);
241 DXGI_FORMAT m_format;
243 D3D11_BIND_FLAG m_type;
244 Microsoft::WRL::ComPtr<ID3D11Buffer> m_buffer;
253 bool Create(
const std::wstring& vertexFile, D3D11_INPUT_ELEMENT_DESC* vertexLayout,
unsigned int vertexLayoutSize);
254 bool Create(
const void*
code,
size_t codeLength, D3D11_INPUT_ELEMENT_DESC* vertexLayout,
unsigned int vertexLayoutSize);
255 void ReleaseShader();
259 bool IsInited() {
return m_inited; }
261 void OnDestroyDevice(
bool fatal)
override;
262 void OnCreateDevice()
override;
265 bool CreateInternal();
268 unsigned int m_vertexLayoutSize;
269 D3D11_INPUT_ELEMENT_DESC* m_vertexLayout;
270 Microsoft::WRL::ComPtr<ID3DBlob> m_VSBuffer;
271 Microsoft::WRL::ComPtr<ID3D11VertexShader> m_VS;
272 Microsoft::WRL::ComPtr<ID3D11InputLayout> m_inputLayout;
281 bool Create(
const std::wstring& wstrFile);
282 bool Create(
const void*
code,
size_t codeLength);
283 void ReleaseShader();
287 bool IsInited() {
return m_inited; }
289 void OnDestroyDevice(
bool fatal)
override;
290 void OnCreateDevice()
override;
293 bool CreateInternal();
296 Microsoft::WRL::ComPtr<ID3DBlob> m_PSBuffer;
297 Microsoft::WRL::ComPtr<ID3D11PixelShader> m_PS;
Definition: D3DResource.h:92
Definition: D3DResource.h:176
Definition: D3DResource.h:275
Definition: D3DResource.h:38
Definition: inftrees.h:24
Definition: D3DResource.h:53
Definition: D3DResource.h:247
Definition: D3DResource.h:217