Merge pull request #4687 from ruuk/textboxgettext
[vuplus_xbmc] / xbmc / guilib / FrameBufferObject.h
1 #ifndef __FRAMEBUFFEROBJECT_H__
2 #define __FRAMEBUFFEROBJECT_H__
3
4 /*
5  *      Copyright (C) 2005-2013 Team XBMC
6  *      http://xbmc.org
7  *
8  *  This Program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2, or (at your option)
11  *  any later version.
12  *
13  *  This Program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with XBMC; see the file COPYING.  If not, see
20  *  <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #include "system.h" // for HAS_GL
25
26 #if defined(HAS_GL) || HAS_GLES == 2
27 #include "system_gl.h"
28
29 //
30 // CFrameBufferObject
31 // A class that abstracts FBOs to facilitate Render To Texture
32 //
33 // Requires OpenGL 1.5+ or the GL_EXT_framebuffer_object extension.
34 //
35 // Usage:
36 //
37 //     CFrameBufferObject *fbo = new CFrameBufferObject();
38 //     fbo->Initialize();
39 //     fbo->CreateAndBindToTexture(GL_TEXTURE_2D, 256, 256, GL_RGBA);
40 //  OR fbo->BindToTexture(GL_TEXTURE_2D, <existing texture ID>);
41 //     fbo->BeginRender();
42 //     <normal GL rendering calls>
43 //     fbo->EndRender();
44 //     bind and use texture anywhere
45 //     glBindTexture(GL_TEXTURE_2D, fbo->Texture());
46 //
47
48 class CFrameBufferObject
49 {
50 public:
51   // Constructor
52   CFrameBufferObject();
53
54   // returns true if FBO support is detected
55   bool IsSupported();
56
57   // returns true if FBO has been initialized
58   bool IsValid() const { return m_valid; }
59
60   // returns true if FBO has a texture bound to it
61   bool IsBound() const { return m_bound; }
62
63   // initialize the FBO
64   bool Initialize();
65
66   // Cleanup
67   void Cleanup();
68
69   // Bind to an exiting texture
70   bool BindToTexture(GLenum target, GLuint texid);
71
72   // Set texture filtering
73   void SetFiltering(GLenum target, GLenum mode);
74
75   // Create a new texture and bind to it
76   bool CreateAndBindToTexture(GLenum target, int width, int height, GLenum format,
77                               GLenum filter=GL_LINEAR, GLenum clampmode=GL_CLAMP_TO_EDGE);
78
79   // Return the internally created texture ID
80   GLuint Texture() const { return m_texid; }
81
82   // Begin rendering to FBO
83   bool BeginRender();
84   // Finish rendering to FBO
85   void EndRender() const;
86
87 private:
88   GLuint m_fbo;
89   bool   m_valid;
90   bool   m_bound;
91   bool   m_supported;
92   GLuint m_texid;
93 };
94
95 #endif
96
97 #endif