Debian Codegraph @

xbmc/cores/RetroPlayer/buffers/RenderBufferOpenGL.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 "RenderBufferOpenGL.h"
10
11 #include "cores/RetroPlayer/rendering/RenderContext.h"
12
13 using namespace KODI;
14 using namespace RETRO;
15
16 CRenderBufferOpenGL::CRenderBufferOpenGL(GLuint pixeltype,
17 GLuint internalformat,
18 GLuint pixelformat,
19 GLuint bpp)
20 : m_pixeltype(pixeltype), m_internalformat(internalformat), m_pixelformat(pixelformat), m_bpp(bpp)
21 {
22 }
23
24 CRenderBufferOpenGL::~CRenderBufferOpenGL()
25 {
26 DeleteTexture();
27 }
28
29 void CRenderBufferOpenGL::CreateTexture()
30 {
31 glGenTextures(1, &m_textureId);
32
33 glBindTexture(m_textureTarget, m_textureId);
34
35 glTexImage2D(m_textureTarget, 0, m_internalformat, m_width, m_height, 0, m_pixelformat,
36 m_pixeltype, NULL);
37
38 glTexParameteri(m_textureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
39 glTexParameteri(m_textureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
40 glTexParameteri(m_textureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
41 glTexParameteri(m_textureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
42
43 glBindTexture(m_textureTarget, 0);
44 }
45
46 bool CRenderBufferOpenGL::UploadTexture()
47 {
48 if (!glIsTexture(m_textureId))
49 CreateTexture();
50
51 glBindTexture(m_textureTarget, m_textureId);
52
53 const int stride = GetFrameSize() / m_height;
54
55 glPixelStorei(GL_UNPACK_ALIGNMENT, m_bpp);
56
57 glPixelStorei(GL_UNPACK_ROW_LENGTH, stride / m_bpp);
58
59 //! @todo This is subject to change:
60 //! We want to use PBO's instead of glTexSubImage2D!
61 //! This code has been borrowed from OpenGL ES in order
62 //! to remove GL dependencies on GLES.
63 glTexSubImage2D(m_textureTarget, 0, 0, 0, m_width, m_height, m_pixelformat, m_pixeltype,
64 m_data.data());
65 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
66
67 return true;
68 }
69
70 void CRenderBufferOpenGL::DeleteTexture()
71 {
72 if (glIsTexture(m_textureId))
73 glDeleteTextures(1, &m_textureId);
74
75 m_textureId = 0;
76 }