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 "SlideShowPictureGL.h"
11 #include "ServiceBroker.h"
12 #include "guilib/Texture.h"
13 #include "rendering/gl/RenderSystemGL.h"
14 #include "utils/GLUtils.h"
16 std::unique_ptr
<CSlideShowPic
> CSlideShowPic::CreateSlideShowPicture()
18 return std::make_unique
<CSlideShowPicGL
>();
21 void CSlideShowPicGL::Render(float* x
, float* y
, CTexture
* pTexture
, UTILS::COLOR::Color color
)
23 CRenderSystemGL
* renderSystem
= dynamic_cast<CRenderSystemGL
*>(CServiceBroker::GetRenderSystem());
26 pTexture
->LoadToGPU();
27 pTexture
->BindToUnit(0);
29 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
32 renderSystem
->EnableShader(ShaderMethodGL::SM_TEXTURE
);
36 renderSystem
->EnableShader(ShaderMethodGL::SM_DEFAULT
);
39 float u1
= 0, u2
= 1, v1
= 0, v2
= 1;
42 u2
= (float)pTexture
->GetWidth() / pTexture
->GetTextureWidth();
43 v2
= (float)pTexture
->GetHeight() / pTexture
->GetTextureHeight();
47 GLubyte idx
[4] = {0, 1, 3, 2}; //determines order of the vertices
56 // Setup vertex position values
81 GLint posLoc
= renderSystem
->ShaderGetPos();
82 GLint tex0Loc
= renderSystem
->ShaderGetCoord0();
83 GLint uniColLoc
= renderSystem
->ShaderGetUniCol();
84 GLint depthLoc
= renderSystem
->ShaderGetDepth();
86 glGenBuffers(1, &vertexVBO
);
87 glBindBuffer(GL_ARRAY_BUFFER
, vertexVBO
);
88 glBufferData(GL_ARRAY_BUFFER
, sizeof(PackedVertex
) * 4, &vertex
[0], GL_STATIC_DRAW
);
90 glVertexAttribPointer(posLoc
, 3, GL_FLOAT
, 0, sizeof(PackedVertex
),
91 reinterpret_cast<const GLvoid
*>(offsetof(PackedVertex
, x
)));
92 glVertexAttribPointer(tex0Loc
, 2, GL_FLOAT
, 0, sizeof(PackedVertex
),
93 reinterpret_cast<const GLvoid
*>(offsetof(PackedVertex
, u1
)));
95 glEnableVertexAttribArray(posLoc
);
96 glEnableVertexAttribArray(tex0Loc
);
98 // Setup Colour values
99 colour
[0] = KODI::UTILS::GL::GetChannelFromARGB(KODI::UTILS::GL::ColorChannel::R
, color
);
100 colour
[1] = KODI::UTILS::GL::GetChannelFromARGB(KODI::UTILS::GL::ColorChannel::G
, color
);
101 colour
[2] = KODI::UTILS::GL::GetChannelFromARGB(KODI::UTILS::GL::ColorChannel::B
, color
);
102 colour
[3] = KODI::UTILS::GL::GetChannelFromARGB(KODI::UTILS::GL::ColorChannel::A
, color
);
104 glUniform4f(uniColLoc
, (colour
[0] / 255.0f
), (colour
[1] / 255.0f
), (colour
[2] / 255.0f
),
105 (colour
[3] / 255.0f
));
106 glUniform1f(depthLoc
, -1.0f
);
108 glGenBuffers(1, &indexVBO
);
109 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER
, indexVBO
);
110 glBufferData(GL_ELEMENT_ARRAY_BUFFER
, sizeof(GLubyte
) * 4, idx
, GL_STATIC_DRAW
);
112 glDrawElements(GL_TRIANGLE_STRIP
, 4, GL_UNSIGNED_BYTE
, 0);
114 glDisableVertexAttribArray(posLoc
);
115 glDisableVertexAttribArray(tex0Loc
);
117 glBindBuffer(GL_ARRAY_BUFFER
, 0);
118 glDeleteBuffers(1, &vertexVBO
);
119 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER
, 0);
120 glDeleteBuffers(1, &indexVBO
);
122 renderSystem
->DisableShader();