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.
9 #include "SlideShowPictureDX.h"
11 #include "guilib/TextureDX.h"
12 #include "rendering/dx/DeviceResources.h"
13 #include "rendering/dx/RenderContext.h"
15 #include <DirectXMath.h>
16 using namespace DirectX
;
17 using namespace Microsoft::WRL
;
19 std::unique_ptr
<CSlideShowPic
> CSlideShowPic::CreateSlideShowPicture()
21 return std::make_unique
<CSlideShowPicDX
>();
24 bool CSlideShowPicDX::UpdateVertexBuffer(Vertex
* vertices
)
26 if (!m_vb
) // create new
28 CD3D11_BUFFER_DESC
desc(sizeof(Vertex
) * 5, D3D11_BIND_VERTEX_BUFFER
, D3D11_USAGE_DYNAMIC
,
29 D3D11_CPU_ACCESS_WRITE
);
30 D3D11_SUBRESOURCE_DATA initData
= {};
31 initData
.pSysMem
= vertices
;
32 initData
.SysMemPitch
= sizeof(Vertex
) * 5;
33 if (SUCCEEDED(DX::DeviceResources::Get()->GetD3DDevice()->CreateBuffer(
34 &desc
, &initData
, m_vb
.ReleaseAndGetAddressOf())))
39 ID3D11DeviceContext
* pContext
= DX::DeviceResources::Get()->GetD3DContext();
40 D3D11_MAPPED_SUBRESOURCE res
;
41 if (SUCCEEDED(pContext
->Map(m_vb
.Get(), 0, D3D11_MAP_WRITE_DISCARD
, 0, &res
)))
43 memcpy(res
.pData
, vertices
, sizeof(Vertex
) * 5);
44 pContext
->Unmap(m_vb
.Get(), 0);
52 void CSlideShowPicDX::Render(float* x
,
55 KODI::UTILS::COLOR::Color color
)
58 for (int i
= 0; i
< 4; i
++)
60 vertex
[i
].pos
= XMFLOAT3(x
[i
], y
[i
], 0);
61 CD3DHelper::XMStoreColor(&vertex
[i
].color
, color
);
62 vertex
[i
].texCoord
= XMFLOAT2(0.0f
, 0.0f
);
63 vertex
[i
].texCoord2
= XMFLOAT2(0.0f
, 0.0f
);
68 vertex
[1].texCoord
.x
= vertex
[2].texCoord
.x
=
69 (float)pTexture
->GetWidth() / pTexture
->GetTextureWidth();
70 vertex
[2].texCoord
.y
= vertex
[3].texCoord
.y
=
71 (float)pTexture
->GetHeight() / pTexture
->GetTextureHeight();
75 vertex
[1].texCoord
.x
= vertex
[2].texCoord
.x
= 1.0f
;
76 vertex
[2].texCoord
.y
= vertex
[3].texCoord
.y
= 1.0f
;
78 vertex
[4] = vertex
[0]; // Not used when pTexture != NULL
80 CGUIShaderDX
* pGUIShader
= DX::Windowing()->GetGUIShader();
81 pGUIShader
->Begin(SHADER_METHOD_RENDER_TEXTURE_BLEND
);
83 // Set state to render the image
86 pTexture
->LoadToGPU();
87 CDXTexture
* dxTexture
= reinterpret_cast<CDXTexture
*>(pTexture
);
88 ID3D11ShaderResourceView
* shaderRes
= dxTexture
->GetShaderResource();
89 pGUIShader
->SetShaderViews(1, &shaderRes
);
90 pGUIShader
->DrawQuad(vertex
[0], vertex
[1], vertex
[2], vertex
[3]);
94 if (!UpdateVertexBuffer(vertex
))
97 ComPtr
<ID3D11DeviceContext
> pContext
= DX::DeviceResources::Get()->GetD3DContext();
99 unsigned stride
= sizeof(Vertex
);
101 pContext
->IASetVertexBuffers(0, 1, m_vb
.GetAddressOf(), &stride
, &offset
);
102 pContext
->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP
);
104 pGUIShader
->Draw(5, 0);
105 pGUIShader
->RestoreBuffers();