-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShaderTextureGL.cpp
56 lines (46 loc) · 1.33 KB
/
ShaderTextureGL.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Copyright (C) 2019 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "ShaderTextureGL.h"
#include "utils/log.h"
using namespace KODI;
using namespace SHADER;
bool CShaderTextureGL::CreateFBO(int width, int height)
{
if (FBO == 0)
glGenFramebuffers(1, &FBO);
GLuint renderTargetID = GetPointer()->getMTexture();
if (renderTargetID == 0)
return false;
BindFBO();
glBindTexture(GL_TEXTURE_2D, renderTargetID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, renderTargetID, 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
{
CLog::Log(LOGERROR, "{}: Framebuffer is not complete!", __func__);
UnbindFBO();
return false;
}
UnbindFBO();
return true;
}
void CShaderTextureGL::BindFBO()
{
glBindFramebuffer(GL_FRAMEBUFFER, FBO);
}
void CShaderTextureGL::UnbindFBO()
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
CShaderTextureGL::~CShaderTextureGL()
{
if (FBO != 0)
glDeleteFramebuffers(1, &FBO);
}