| 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 "SlideShowPictureGLES.h" |
| 10 |
|
| 11 |
#include "ServiceBroker.h" |
| 12 |
#include "guilib/Texture.h" |
| 13 |
#include "rendering/gles/RenderSystemGLES.h" |
| 14 |
#include "utils/GLUtils.h" |
| 15 |
#include "windowing/WinSystem.h" |
| 16 |
|
| 17 |
std::unique_ptr<CSlideShowPic> CSlideShowPic::CreateSlideShowPicture() |
| 18 |
{ |
| 19 |
return std::make_unique<CSlideShowPicGLES>(); |
| 20 |
} |
| 21 |
|
| 22 |
void CSlideShowPicGLES::Render(float* x, float* y, CTexture* pTexture, UTILS::COLOR::Color color) |
| 23 |
{ |
| 24 |
CRenderSystemGLES* renderSystem = |
| 25 |
dynamic_cast<CRenderSystemGLES*>(CServiceBroker::GetRenderSystem()); |
| 26 |
if (pTexture) |
| 27 |
{ |
| 28 |
pTexture->LoadToGPU(); |
| 29 |
pTexture->BindToUnit(0); |
| 30 |
|
| 31 |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 32 |
glEnable(GL_BLEND); // Turn Blending On |
| 33 |
|
| 34 |
renderSystem->EnableGUIShader(ShaderMethodGLES::SM_TEXTURE); |
| 35 |
} |
| 36 |
else |
| 37 |
{ |
| 38 |
renderSystem->EnableGUIShader(ShaderMethodGLES::SM_DEFAULT); |
| 39 |
} |
| 40 |
|
| 41 |
float u1 = 0, u2 = 1, v1 = 0, v2 = 1; |
| 42 |
if (pTexture) |
| 43 |
{ |
| 44 |
u2 = (float)pTexture->GetWidth() / pTexture->GetTextureWidth(); |
| 45 |
v2 = (float)pTexture->GetHeight() / pTexture->GetTextureHeight(); |
| 46 |
} |
| 47 |
|
| 48 |
GLubyte col[4]; |
| 49 |
GLfloat ver[4][3]; |
| 50 |
GLfloat tex[4][2]; |
| 51 |
GLubyte idx[4] = {0, 1, 3, 2}; //determines order of triangle strip |
| 52 |
|
| 53 |
GLint posLoc = renderSystem->GUIShaderGetPos(); |
| 54 |
GLint tex0Loc = renderSystem->GUIShaderGetCoord0(); |
| 55 |
GLint uniColLoc = renderSystem->GUIShaderGetUniCol(); |
| 56 |
|
| 57 |
glVertexAttribPointer(posLoc, 3, GL_FLOAT, 0, 0, ver); |
| 58 |
glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, 0, tex); |
| 59 |
|
| 60 |
glEnableVertexAttribArray(posLoc); |
| 61 |
glEnableVertexAttribArray(tex0Loc); |
| 62 |
|
| 63 |
// Setup Colour values |
| 64 |
col[0] = KODI::UTILS::GL::GetChannelFromARGB(KODI::UTILS::GL::ColorChannel::R, color); |
| 65 |
col[1] = KODI::UTILS::GL::GetChannelFromARGB(KODI::UTILS::GL::ColorChannel::G, color); |
| 66 |
col[2] = KODI::UTILS::GL::GetChannelFromARGB(KODI::UTILS::GL::ColorChannel::B, color); |
| 67 |
col[3] = KODI::UTILS::GL::GetChannelFromARGB(KODI::UTILS::GL::ColorChannel::A, color); |
| 68 |
|
| 69 |
if (CServiceBroker::GetWinSystem()->UseLimitedColor()) |
| 70 |
{ |
| 71 |
col[0] = (235 - 16) * col[0] / 255 + 16; |
| 72 |
col[1] = (235 - 16) * col[1] / 255 + 16; |
| 73 |
col[2] = (235 - 16) * col[2] / 255 + 16; |
| 74 |
} |
| 75 |
|
| 76 |
for (int i = 0; i < 4; i++) |
| 77 |
{ |
| 78 |
// Setup vertex position values |
| 79 |
ver[i][0] = x[i]; |
| 80 |
ver[i][1] = y[i]; |
| 81 |
ver[i][2] = 0.0f; |
| 82 |
} |
| 83 |
// Setup texture coordinates |
| 84 |
tex[0][0] = tex[3][0] = u1; |
| 85 |
tex[0][1] = tex[1][1] = v1; |
| 86 |
tex[1][0] = tex[2][0] = u2; |
| 87 |
tex[2][1] = tex[3][1] = v2; |
| 88 |
|
| 89 |
glUniform4f(uniColLoc, (col[0] / 255.0f), (col[1] / 255.0f), (col[2] / 255.0f), |
| 90 |
(col[3] / 255.0f)); |
| 91 |
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, idx); |
| 92 |
|
| 93 |
glDisableVertexAttribArray(posLoc); |
| 94 |
glDisableVertexAttribArray(tex0Loc); |
| 95 |
|
| 96 |
renderSystem->DisableGUIShader(); |
| 97 |
} |