PageRenderTime 124ms CodeModel.GetById 95ms app.highlight 26ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  9#include "GUITextureD3D.h"
 10
 11#include "D3DResource.h"
 12#include "GUIShaderDX.h"
 13#include "Texture.h"
 14#include "rendering/dx/RenderContext.h"
 15
 16#include <DirectXMath.h>
 17
 18using namespace DirectX;
 19
 20CGUITextureD3D::CGUITextureD3D(float posX, float posY, float width, float height, const CTextureInfo &texture)
 21: CGUITextureBase(posX, posY, width, height, texture)
 22{
 23}
 24
 25CGUITextureD3D::~CGUITextureD3D()
 26{
 27}
 28
 29void CGUITextureD3D::Begin(UTILS::Color color)
 30{
 31  CBaseTexture* texture = m_texture.m_textures[m_currentFrame];
 32  texture->LoadToGPU();
 33
 34  if (m_diffuse.size())
 35	  m_diffuse.m_textures[0]->LoadToGPU();
 36
 37  m_col = color;
 38
 39  DX::Windowing()->SetAlphaBlendEnable(true);
 40}
 41
 42void CGUITextureD3D::End()
 43{
 44}
 45
 46void CGUITextureD3D::Draw(float *x, float *y, float *z, const CRect &texture, const CRect &diffuse, int orientation)
 47{
 48  XMFLOAT4 xcolor;
 49  CD3DHelper::XMStoreColor(&xcolor, m_col);
 50
 51  Vertex verts[4];
 52  verts[0].pos.x = x[0]; verts[0].pos.y = y[0]; verts[0].pos.z = z[0];
 53  verts[0].texCoord.x = texture.x1;   verts[0].texCoord.y = texture.y1;
 54  verts[0].texCoord2.x = diffuse.x1;  verts[0].texCoord2.y = diffuse.y1;
 55  verts[0].color = xcolor;
 56
 57  verts[1].pos.x = x[1]; verts[1].pos.y = y[1]; verts[1].pos.z = z[1];
 58  if (orientation & 4)
 59  {
 60    verts[1].texCoord.x = texture.x1;
 61    verts[1].texCoord.y = texture.y2;
 62  }
 63  else
 64  {
 65    verts[1].texCoord.x = texture.x2;
 66    verts[1].texCoord.y = texture.y1;
 67  }
 68  if (m_info.orientation & 4)
 69  {
 70    verts[1].texCoord2.x = diffuse.x1;
 71    verts[1].texCoord2.y = diffuse.y2;
 72  }
 73  else
 74  {
 75    verts[1].texCoord2.x = diffuse.x2;
 76    verts[1].texCoord2.y = diffuse.y1;
 77  }
 78  verts[1].color = xcolor;
 79
 80  verts[2].pos.x = x[2]; verts[2].pos.y = y[2]; verts[2].pos.z = z[2];
 81  verts[2].texCoord.x = texture.x2;   verts[2].texCoord.y = texture.y2;
 82  verts[2].texCoord2.x = diffuse.x2;  verts[2].texCoord2.y = diffuse.y2;
 83  verts[2].color = xcolor;
 84
 85  verts[3].pos.x = x[3]; verts[3].pos.y = y[3]; verts[3].pos.z = z[3];
 86  if (orientation & 4)
 87  {
 88    verts[3].texCoord.x = texture.x2;
 89    verts[3].texCoord.y = texture.y1;
 90  }
 91  else
 92  {
 93    verts[3].texCoord.x = texture.x1;
 94    verts[3].texCoord.y = texture.y2;
 95  }
 96  if (m_info.orientation & 4)
 97  {
 98    verts[3].texCoord2.x = diffuse.x2;
 99    verts[3].texCoord2.y = diffuse.y1;
100  }
101  else
102  {
103    verts[3].texCoord2.x = diffuse.x1;
104    verts[3].texCoord2.y = diffuse.y2;
105  }
106  verts[3].color = xcolor;
107
108  CDXTexture* tex = (CDXTexture *)m_texture.m_textures[m_currentFrame];
109  CGUIShaderDX* pGUIShader = DX::Windowing()->GetGUIShader();
110
111  pGUIShader->Begin(m_diffuse.size() ? SHADER_METHOD_RENDER_MULTI_TEXTURE_BLEND : SHADER_METHOD_RENDER_TEXTURE_BLEND);
112
113  if (m_diffuse.size())
114  {
115    CDXTexture* diff = (CDXTexture *)m_diffuse.m_textures[0];
116    ID3D11ShaderResourceView* resource[] = { tex->GetShaderResource(), diff->GetShaderResource() };
117    pGUIShader->SetShaderViews(ARRAYSIZE(resource), resource);
118  }
119  else
120  {
121    ID3D11ShaderResourceView* resource = tex->GetShaderResource();
122    pGUIShader->SetShaderViews(1, &resource);
123  }
124  pGUIShader->DrawQuad(verts[0], verts[1], verts[2], verts[3]);
125}
126
127void CGUITextureD3D::DrawQuad(const CRect &rect, UTILS::Color color, CBaseTexture *texture, const CRect *texCoords)
128{
129  unsigned numViews = 0;
130  ID3D11ShaderResourceView* views = nullptr;
131
132  if (texture)
133  {
134    texture->LoadToGPU();
135    numViews = 1;
136    views = ((CDXTexture *)texture)->GetShaderResource();
137  }
138
139  CD3DTexture::DrawQuad(rect, color, numViews, &views, texCoords, texture ? SHADER_METHOD_RENDER_TEXTURE_BLEND : SHADER_METHOD_RENDER_DEFAULT);
140}