/xbmc/guilib/GUITextureD3D.cpp

http://github.com/xbmc/xbmc · C++ · 140 lines · 111 code · 22 blank · 7 comment · 7 complexity · eea629989d389ebeff5e892580748e2f MD5 · raw file

  1. /*
  2. * Copyright (C) 2005-2018 Team Kodi
  3. * This file is part of Kodi - https://kodi.tv
  4. *
  5. * SPDX-License-Identifier: GPL-2.0-or-later
  6. * See LICENSES/README.md for more information.
  7. */
  8. #include "GUITextureD3D.h"
  9. #include "D3DResource.h"
  10. #include "GUIShaderDX.h"
  11. #include "Texture.h"
  12. #include "rendering/dx/RenderContext.h"
  13. #include <DirectXMath.h>
  14. using namespace DirectX;
  15. CGUITextureD3D::CGUITextureD3D(float posX, float posY, float width, float height, const CTextureInfo &texture)
  16. : CGUITextureBase(posX, posY, width, height, texture)
  17. {
  18. }
  19. CGUITextureD3D::~CGUITextureD3D()
  20. {
  21. }
  22. void CGUITextureD3D::Begin(UTILS::Color color)
  23. {
  24. CBaseTexture* texture = m_texture.m_textures[m_currentFrame];
  25. texture->LoadToGPU();
  26. if (m_diffuse.size())
  27. m_diffuse.m_textures[0]->LoadToGPU();
  28. m_col = color;
  29. DX::Windowing()->SetAlphaBlendEnable(true);
  30. }
  31. void CGUITextureD3D::End()
  32. {
  33. }
  34. void CGUITextureD3D::Draw(float *x, float *y, float *z, const CRect &texture, const CRect &diffuse, int orientation)
  35. {
  36. XMFLOAT4 xcolor;
  37. CD3DHelper::XMStoreColor(&xcolor, m_col);
  38. Vertex verts[4];
  39. verts[0].pos.x = x[0]; verts[0].pos.y = y[0]; verts[0].pos.z = z[0];
  40. verts[0].texCoord.x = texture.x1; verts[0].texCoord.y = texture.y1;
  41. verts[0].texCoord2.x = diffuse.x1; verts[0].texCoord2.y = diffuse.y1;
  42. verts[0].color = xcolor;
  43. verts[1].pos.x = x[1]; verts[1].pos.y = y[1]; verts[1].pos.z = z[1];
  44. if (orientation & 4)
  45. {
  46. verts[1].texCoord.x = texture.x1;
  47. verts[1].texCoord.y = texture.y2;
  48. }
  49. else
  50. {
  51. verts[1].texCoord.x = texture.x2;
  52. verts[1].texCoord.y = texture.y1;
  53. }
  54. if (m_info.orientation & 4)
  55. {
  56. verts[1].texCoord2.x = diffuse.x1;
  57. verts[1].texCoord2.y = diffuse.y2;
  58. }
  59. else
  60. {
  61. verts[1].texCoord2.x = diffuse.x2;
  62. verts[1].texCoord2.y = diffuse.y1;
  63. }
  64. verts[1].color = xcolor;
  65. verts[2].pos.x = x[2]; verts[2].pos.y = y[2]; verts[2].pos.z = z[2];
  66. verts[2].texCoord.x = texture.x2; verts[2].texCoord.y = texture.y2;
  67. verts[2].texCoord2.x = diffuse.x2; verts[2].texCoord2.y = diffuse.y2;
  68. verts[2].color = xcolor;
  69. verts[3].pos.x = x[3]; verts[3].pos.y = y[3]; verts[3].pos.z = z[3];
  70. if (orientation & 4)
  71. {
  72. verts[3].texCoord.x = texture.x2;
  73. verts[3].texCoord.y = texture.y1;
  74. }
  75. else
  76. {
  77. verts[3].texCoord.x = texture.x1;
  78. verts[3].texCoord.y = texture.y2;
  79. }
  80. if (m_info.orientation & 4)
  81. {
  82. verts[3].texCoord2.x = diffuse.x2;
  83. verts[3].texCoord2.y = diffuse.y1;
  84. }
  85. else
  86. {
  87. verts[3].texCoord2.x = diffuse.x1;
  88. verts[3].texCoord2.y = diffuse.y2;
  89. }
  90. verts[3].color = xcolor;
  91. CDXTexture* tex = (CDXTexture *)m_texture.m_textures[m_currentFrame];
  92. CGUIShaderDX* pGUIShader = DX::Windowing()->GetGUIShader();
  93. pGUIShader->Begin(m_diffuse.size() ? SHADER_METHOD_RENDER_MULTI_TEXTURE_BLEND : SHADER_METHOD_RENDER_TEXTURE_BLEND);
  94. if (m_diffuse.size())
  95. {
  96. CDXTexture* diff = (CDXTexture *)m_diffuse.m_textures[0];
  97. ID3D11ShaderResourceView* resource[] = { tex->GetShaderResource(), diff->GetShaderResource() };
  98. pGUIShader->SetShaderViews(ARRAYSIZE(resource), resource);
  99. }
  100. else
  101. {
  102. ID3D11ShaderResourceView* resource = tex->GetShaderResource();
  103. pGUIShader->SetShaderViews(1, &resource);
  104. }
  105. pGUIShader->DrawQuad(verts[0], verts[1], verts[2], verts[3]);
  106. }
  107. void CGUITextureD3D::DrawQuad(const CRect &rect, UTILS::Color color, CBaseTexture *texture, const CRect *texCoords)
  108. {
  109. unsigned numViews = 0;
  110. ID3D11ShaderResourceView* views = nullptr;
  111. if (texture)
  112. {
  113. texture->LoadToGPU();
  114. numViews = 1;
  115. views = ((CDXTexture *)texture)->GetShaderResource();
  116. }
  117. CD3DTexture::DrawQuad(rect, color, numViews, &views, texCoords, texture ? SHADER_METHOD_RENDER_TEXTURE_BLEND : SHADER_METHOD_RENDER_DEFAULT);
  118. }