2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "D3DResource.h"
13 #include "utils/Geometry.h"
14 #include "utils/MemUtils.h"
16 #include <DirectXMath.h>
17 #include <wrl/client.h>
22 Vertex(DirectX::XMFLOAT3 p
, DirectX::XMFLOAT4 c
)
25 Vertex(DirectX::XMFLOAT3 p
, DirectX::XMFLOAT4 c
, DirectX::XMFLOAT2 t1
, DirectX::XMFLOAT2 t2
)
26 : pos(p
), color(c
), texCoord(t1
), texCoord2(t2
) {}
28 DirectX::XMFLOAT3 pos
;
29 DirectX::XMFLOAT4 color
;
30 DirectX::XMFLOAT2 texCoord
;
31 DirectX::XMFLOAT2 texCoord2
;
43 void Begin(unsigned int flags
);
45 void ApplyStateBlock(void);
46 void RestoreBuffers(void);
48 void SetShaderViews(unsigned int numViews
, ID3D11ShaderResourceView
** views
);
49 void SetViewPort(D3D11_VIEWPORT viewPort
);
51 void XM_CALLCONV
GetWVP(DirectX::XMMATRIX
&w
, DirectX::XMMATRIX
&v
, DirectX::XMMATRIX
&p
)
53 w
= m_cbWorldViewProj
.world
;
54 v
= m_cbWorldViewProj
.view
;
55 p
= m_cbWorldViewProj
.projection
;
57 DirectX::XMMATRIX XM_CALLCONV
GetWorld() const { return m_cbWorldViewProj
.world
; }
58 DirectX::XMMATRIX XM_CALLCONV
GetView() const { return m_cbWorldViewProj
.view
; }
59 DirectX::XMMATRIX XM_CALLCONV
GetProjection() const { return m_cbWorldViewProj
.projection
; }
60 void XM_CALLCONV
SetWVP(const DirectX::XMMATRIX
&w
, const DirectX::XMMATRIX
&v
, const DirectX::XMMATRIX
&p
);
61 void XM_CALLCONV
SetWorld(const DirectX::XMMATRIX
&value
);
62 void XM_CALLCONV
SetView(const DirectX::XMMATRIX
&value
);
63 void XM_CALLCONV
SetProjection(const DirectX::XMMATRIX
&value
);
64 void Project(float &x
, float &y
, float &z
);
66 void DrawQuad(Vertex
& v1
, Vertex
& v2
, Vertex
& v3
, Vertex
& v4
);
67 void DrawIndexed(unsigned int indexCount
, unsigned int startIndex
, unsigned int startVertex
);
68 void Draw(unsigned int vertexCount
, unsigned int startVertex
);
70 bool HardwareClipIsPossible(void) const { return m_clipPossible
; }
71 float GetClipXFactor(void) const { return m_clipXFactor
; }
72 float GetClipXOffset(void) const { return m_clipXOffset
; }
73 float GetClipYFactor(void) const { return m_clipYFactor
; }
74 float GetClipYOffset(void) const { return m_clipYOffset
; }
76 // need to use aligned allocation because we use XMMATRIX in structures.
77 void* operator new (size_t size
)
79 void* ptr
= KODI::MEMORY::AlignedMalloc(size
, __alignof(CGUIShaderDX
));
81 throw std::bad_alloc();
84 // free aligned memory.
85 void operator delete (void* ptr
)
87 KODI::MEMORY::AlignedFree(ptr
);
91 struct cbWorldViewProj
93 DirectX::XMMATRIX world
;
94 DirectX::XMMATRIX view
;
95 DirectX::XMMATRIX projection
;
106 DirectX::XMMATRIX wvp
;
114 bool CreateBuffers(void);
115 bool CreateSamplers(void);
116 void ApplyChanges(void);
117 void ClipToScissorParams(void);
120 cbViewPort m_cbViewPort
= {};
121 cbWorldViewProj m_cbWorldViewProj
= {};
124 size_t m_currentShader
;
125 CD3DVertexShader m_vertexShader
;
126 CD3DPixelShader m_pixelShader
[SHADER_METHOD_RENDER_COUNT
];
127 Microsoft::WRL::ComPtr
<ID3D11SamplerState
> m_pSampLinear
;
132 Microsoft::WRL::ComPtr
<ID3D11Buffer
> m_pWVPBuffer
;
133 Microsoft::WRL::ComPtr
<ID3D11Buffer
> m_pVPBuffer
;
134 Microsoft::WRL::ComPtr
<ID3D11Buffer
> m_pVertexBuffer
;
136 // clip to scissors params