[Windows] Fix driver version detection of AMD RDNA+ GPU on Windows 10
[xbmc.git] / xbmc / pictures / SlideShowPictureGL.cpp
blobee7ddb2a9f63722b70954ffa3d7306c55beebac9
1 /*
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.
7 */
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());
24 if (pTexture)
26 pTexture->LoadToGPU();
27 pTexture->BindToUnit(0);
29 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
30 glEnable(GL_BLEND);
32 renderSystem->EnableShader(ShaderMethodGL::SM_TEXTURE);
34 else
36 renderSystem->EnableShader(ShaderMethodGL::SM_DEFAULT);
39 float u1 = 0, u2 = 1, v1 = 0, v2 = 1;
40 if (pTexture)
42 u2 = (float)pTexture->GetWidth() / pTexture->GetTextureWidth();
43 v2 = (float)pTexture->GetHeight() / pTexture->GetTextureHeight();
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
52 float x, y, z;
53 float u1, v1;
54 } vertex[4];
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;
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;
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;
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;
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();