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 "GUITextureD3D.h"
11 #include "D3DResource.h"
12 #include "GUIShaderDX.h"
13 #include "TextureDX.h"
14 #include "rendering/dx/RenderContext.h"
16 #include <DirectXMath.h>
18 using namespace DirectX
;
20 void CGUITextureD3D::Register()
22 CGUITexture::Register(CGUITextureD3D::CreateTexture
, CGUITextureD3D::DrawQuad
);
25 CGUITexture
* CGUITextureD3D::CreateTexture(
26 float posX
, float posY
, float width
, float height
, const CTextureInfo
& texture
)
28 return new CGUITextureD3D(posX
, posY
, width
, height
, texture
);
31 CGUITextureD3D::CGUITextureD3D(
32 float posX
, float posY
, float width
, float height
, const CTextureInfo
& texture
)
33 : CGUITexture(posX
, posY
, width
, height
, texture
)
37 CGUITextureD3D
* CGUITextureD3D::Clone() const
39 return new CGUITextureD3D(*this);
42 void CGUITextureD3D::Begin(UTILS::COLOR::Color color
)
44 CTexture
* texture
= m_texture
.m_textures
[m_currentFrame
].get();
48 m_diffuse
.m_textures
[0]->LoadToGPU();
52 DX::Windowing()->SetAlphaBlendEnable(true);
55 void CGUITextureD3D::End()
59 void CGUITextureD3D::Draw(float *x
, float *y
, float *z
, const CRect
&texture
, const CRect
&diffuse
, int orientation
)
62 CD3DHelper::XMStoreColor(&xcolor
, m_col
);
65 verts
[0].pos
.x
= x
[0]; verts
[0].pos
.y
= y
[0]; verts
[0].pos
.z
= z
[0];
66 verts
[0].texCoord
.x
= texture
.x1
; verts
[0].texCoord
.y
= texture
.y1
;
67 verts
[0].texCoord2
.x
= diffuse
.x1
; verts
[0].texCoord2
.y
= diffuse
.y1
;
68 verts
[0].color
= xcolor
;
70 verts
[1].pos
.x
= x
[1]; verts
[1].pos
.y
= y
[1]; verts
[1].pos
.z
= z
[1];
73 verts
[1].texCoord
.x
= texture
.x1
;
74 verts
[1].texCoord
.y
= texture
.y2
;
78 verts
[1].texCoord
.x
= texture
.x2
;
79 verts
[1].texCoord
.y
= texture
.y1
;
81 if (m_info
.orientation
& 4)
83 verts
[1].texCoord2
.x
= diffuse
.x1
;
84 verts
[1].texCoord2
.y
= diffuse
.y2
;
88 verts
[1].texCoord2
.x
= diffuse
.x2
;
89 verts
[1].texCoord2
.y
= diffuse
.y1
;
91 verts
[1].color
= xcolor
;
93 verts
[2].pos
.x
= x
[2]; verts
[2].pos
.y
= y
[2]; verts
[2].pos
.z
= z
[2];
94 verts
[2].texCoord
.x
= texture
.x2
; verts
[2].texCoord
.y
= texture
.y2
;
95 verts
[2].texCoord2
.x
= diffuse
.x2
; verts
[2].texCoord2
.y
= diffuse
.y2
;
96 verts
[2].color
= xcolor
;
98 verts
[3].pos
.x
= x
[3]; verts
[3].pos
.y
= y
[3]; verts
[3].pos
.z
= z
[3];
101 verts
[3].texCoord
.x
= texture
.x2
;
102 verts
[3].texCoord
.y
= texture
.y1
;
106 verts
[3].texCoord
.x
= texture
.x1
;
107 verts
[3].texCoord
.y
= texture
.y2
;
109 if (m_info
.orientation
& 4)
111 verts
[3].texCoord2
.x
= diffuse
.x2
;
112 verts
[3].texCoord2
.y
= diffuse
.y1
;
116 verts
[3].texCoord2
.x
= diffuse
.x1
;
117 verts
[3].texCoord2
.y
= diffuse
.y2
;
119 verts
[3].color
= xcolor
;
121 CDXTexture
* tex
= static_cast<CDXTexture
*>(m_texture
.m_textures
[m_currentFrame
].get());
122 CGUIShaderDX
* pGUIShader
= DX::Windowing()->GetGUIShader();
124 pGUIShader
->Begin(m_diffuse
.size() ? SHADER_METHOD_RENDER_MULTI_TEXTURE_BLEND
: SHADER_METHOD_RENDER_TEXTURE_BLEND
);
126 if (m_diffuse
.size())
128 CDXTexture
* diff
= static_cast<CDXTexture
*>(m_diffuse
.m_textures
[0].get());
129 ID3D11ShaderResourceView
* resource
[] = { tex
->GetShaderResource(), diff
->GetShaderResource() };
130 pGUIShader
->SetShaderViews(ARRAYSIZE(resource
), resource
);
134 ID3D11ShaderResourceView
* resource
= tex
->GetShaderResource();
135 pGUIShader
->SetShaderViews(1, &resource
);
137 pGUIShader
->DrawQuad(verts
[0], verts
[1], verts
[2], verts
[3]);
140 void CGUITextureD3D::DrawQuad(const CRect
& rect
,
141 UTILS::COLOR::Color color
,
143 const CRect
* texCoords
)
145 unsigned numViews
= 0;
146 ID3D11ShaderResourceView
* views
= nullptr;
150 texture
->LoadToGPU();
152 views
= ((CDXTexture
*)texture
)->GetShaderResource();
155 CD3DTexture::DrawQuad(rect
, color
, numViews
, &views
, texCoords
, texture
? SHADER_METHOD_RENDER_TEXTURE_BLEND
: SHADER_METHOD_RENDER_DEFAULT
);