kodi
FrameBufferObject.h
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 #pragma once
10 
11 #include "system_gl.h"
12 
13 //
14 // CFrameBufferObject
15 // A class that abstracts FBOs to facilitate Render To Texture
16 //
17 // Requires OpenGL 1.5+ or the GL_EXT_framebuffer_object extension.
18 //
19 // Usage:
20 //
21 // CFrameBufferObject *fbo = new CFrameBufferObject();
22 // fbo->Initialize();
23 // fbo->CreateAndBindToTexture(GL_TEXTURE_2D, 256, 256, GL_RGBA);
24 // OR fbo->BindToTexture(GL_TEXTURE_2D, <existing texture ID>);
25 // fbo->BeginRender();
26 // <normal GL rendering calls>
27 // fbo->EndRender();
28 // bind and use texture anywhere
29 // glBindTexture(GL_TEXTURE_2D, fbo->Texture());
30 //
31 
33 {
34 public:
35  // Constructor
37 
38  // returns true if FBO support is detected
39  bool IsSupported();
40 
41  // returns true if FBO has been initialized
42  bool IsValid() const { return m_valid; }
43 
44  // returns true if FBO has a texture bound to it
45  bool IsBound() const { return m_bound; }
46 
47  // initialize the FBO
48  bool Initialize();
49 
50  // Cleanup
51  void Cleanup();
52 
53  // Set texture filtering
54  void SetFiltering(GLenum target, GLenum mode);
55 
56  // Create a new texture and bind to it
57  bool CreateAndBindToTexture(GLenum target, int width, int height, GLenum format, GLenum type=GL_UNSIGNED_BYTE,
58  GLenum filter=GL_LINEAR, GLenum clampmode=GL_CLAMP_TO_EDGE);
59 
60  // Return the internally created texture ID
61  GLuint Texture() const { return m_texid; }
62 
63  // Begin rendering to FBO
64  bool BeginRender();
65  // Finish rendering to FBO
66  void EndRender() const;
67 
68 private:
69  GLuint m_fbo = 0;
70  bool m_valid;
71  bool m_bound;
72  bool m_supported;
73  GLuint m_texid = 0;
74 };
75 
76 
Definition: FrameBufferObject.h:32