Debian Codegraph @

xbmc/pictures/SlideShowPictureGL.cpp

raw
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 "SlideShowPictureGL.h"
10
11 #include "ServiceBroker.h"
12 #include "guilib/Texture.h"
13 #include "rendering/gl/RenderSystemGL.h"
14 #include "utils/GLUtils.h"
15
16 std::unique_ptr<CSlideShowPic> CSlideShowPic::CreateSlideShowPicture()
17 {
18 return std::make_unique<CSlideShowPicGL>();
19 }
20
21 void CSlideShowPicGL::Render(float* x, float* y, CTexture* pTexture, UTILS::COLOR::Color color)
22 {
23 CRenderSystemGL* renderSystem = dynamic_cast<CRenderSystemGL*>(CServiceBroker::GetRenderSystem());
24 if (pTexture)
25 {
26 pTexture->LoadToGPU();
27 pTexture->BindToUnit(0);
28
29 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
30 glEnable(GL_BLEND);
31
32 renderSystem->EnableShader(ShaderMethodGL::SM_TEXTURE);
33 }
34 else
35 {
36 renderSystem->EnableShader(ShaderMethodGL::SM_DEFAULT);
37 }
38
39 float u1 = 0, u2 = 1, v1 = 0, v2 = 1;
40 if (pTexture)
41 {
42 u2 = (float)pTexture->GetWidth() / pTexture->GetTextureWidth();
43 v2 = (float)pTexture->GetHeight() / pTexture->GetTextureHeight();
44 }
45
46 GLubyte colour[4];
47 GLubyte idx[4] = {0, 1, 3, 2}; //determines order of the vertices
48 GLuint vertexVBO;
49 GLuint indexVBO;
50 struct PackedVertex
51 {
52 float x, y, z;
53 float u1, v1;
54 } vertex[4];
55
56 // Setup vertex position values
57 vertex[0].x = x[0];
58 vertex[0].y = y[0];
59 vertex[0].z = 0;
60 vertex[0].u1 = u1;
61 vertex[0].v1 = v1;
62
63 vertex[1].x = x[1];
64 vertex[1].y = y[1];
65 vertex[1].z = 0;
66 vertex[1].u1 = u2;
67 vertex[1].v1 = v1;
68
69 vertex[2].x = x[2];
70 vertex[2].y = y[2];
71 vertex[2].z = 0;
72 vertex[2].u1 = u2;
73 vertex[2].v1 = v2;
74
75 vertex[3].x = x[3];
76 vertex[3].y = y[3];
77 vertex[3].z = 0;
78 vertex[3].u1 = u1;
79 vertex[3].v1 = v2;
80
81 GLint posLoc = renderSystem->ShaderGetPos();
82 GLint tex0Loc = renderSystem->ShaderGetCoord0();
83 GLint uniColLoc = renderSystem->ShaderGetUniCol();
84
85 glGenBuffers(1, &vertexVBO);
86 glBindBuffer(GL_ARRAY_BUFFER, vertexVBO);
87 glBufferData(GL_ARRAY_BUFFER, sizeof(PackedVertex) * 4, &vertex[0], GL_STATIC_DRAW);
88
89 glVertexAttribPointer(posLoc, 3, GL_FLOAT, 0, sizeof(PackedVertex),
90 reinterpret_cast<const GLvoid*>(offsetof(PackedVertex, x)));
91 glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, sizeof(PackedVertex),
92 reinterpret_cast<const GLvoid*>(offsetof(PackedVertex, u1)));
93
94 glEnableVertexAttribArray(posLoc);
95 glEnableVertexAttribArray(tex0Loc);
96
97 // Setup Colour values
98 colour[0] = KODI::UTILS::GL::GetChannelFromARGB(KODI::UTILS::GL::ColorChannel::R, color);
99 colour[1] = KODI::UTILS::GL::GetChannelFromARGB(KODI::UTILS::GL::ColorChannel::G, color);
100 colour[2] = KODI::UTILS::GL::GetChannelFromARGB(KODI::UTILS::GL::ColorChannel::B, color);
101 colour[3] = KODI::UTILS::GL::GetChannelFromARGB(KODI::UTILS::GL::ColorChannel::A, color);
102
103 glUniform4f(uniColLoc, (colour[0] / 255.0f), (colour[1] / 255.0f), (colour[2] / 255.0f),
104 (colour[3] / 255.0f));
105
106 glGenBuffers(1, &indexVBO);
107 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVBO);
108 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLubyte) * 4, idx, GL_STATIC_DRAW);
109
110 glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, 0);
111
112 glDisableVertexAttribArray(posLoc);
113 glDisableVertexAttribArray(tex0Loc);
114
115 glBindBuffer(GL_ARRAY_BUFFER, 0);
116 glDeleteBuffers(1, &vertexVBO);
117 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
118 glDeleteBuffers(1, &indexVBO);
119
120 renderSystem->DisableShader();
121 }