NCBI C++ ToolKit
glframebuffer.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef GUI_WX_GL_FRAMEBUFFER__HPP
2 #define GUI_WX_GL_FRAMEBUFFER__HPP
3 
4 /* $Id: glframebuffer.hpp 42756 2019-04-10 16:43:22Z katargir $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Bob Falk
30  *
31  * File Description:
32  * A wrapper for a simple framebuffer that can be set as a rendering target
33  * using the opengl FrameBuffer extension
34  */
35 
36 #include <corelib/ncbiobj.hpp>
37 #include <gui/opengl.h>
38 #include <gui/gui.hpp>
39 
41 
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// CGLFrameBuffer
46 
48 {
49 public:
50  CGLFrameBuffer(size_t dim);
51  ~CGLFrameBuffer();
52 
53  /// Deletes the current framebuffer, if any
54  void Clear();
55 
56  ///
57  /// Set texture paramters, if needed. Call before calling CreateFrameBuffer
58  //
59 
60  /// Set texture wrap parameters (default: GL_CLAMP_TO_EDGE)
61  void SetTextureWrap(GLint wraps, GLint wrapt);
62  GLint GetWraps() const { return m_WrapS; }
63  GLint GetWrapT() const { return m_WrapT; }
64  /// Set texture filtering parameters (default: GL_LINEAR)
65  virtual void SetTextureFiltering(GLint min_filter, GLint mag_filter);
66  GLint GetTexMin() const { return m_TexMin; }
67  GLint GetTexMag() const { return m_TexMag; }
68 
69  ///
70  /// Create, set and validate framebuffer
71  ///
72 
73  /// Creates a new framebuffer, deleting the old one if present
74  virtual void CreateFrameBuffer();
75  virtual void SetClearColor(float red, float green, float blue, float alpha);
76 
77  /// Return an arrray of valid image output sizes
78  static std::vector<int> checkFramebufferAvailability(int start_size,
79  int count);
80  /// Returns true if framebuffer was created successfully
81  virtual bool IsValid();
82  /// Returns true and writes error message if framebuffer is invalid
83  static bool CheckFBOError();
84  /// Generates mipmaps for the texture rendering target
85  virtual void GenerateMipMaps();
86  /// Makes this framebuffer the current rendering target if b==true,
87  /// and if b==false, makes the rendering target the default buffer.
88  void MakeCurrent(bool b);
89 
90  virtual void Render(std::function<void()> renderer);
91 
92  virtual I3DTexture* Get3DTexture();
93  GLuint GetTexture() { return m_FbTex; }
94 
95  /// Returns the size of the framebuffer (w==h, so only return 1 value)
96  virtual size_t GetFrameSize() const { return m_FrameSize; }
97  /// Releases ownership of texture so it isn't deleted with framebuffer
98  virtual void ReleaseTexture() { m_TextureReleased = true; }
99 
100 protected:
101  ///
102  /// OpenGL IDs
103  ///
104 
105  /// Framebuffer id
106  GLuint m_Fb;
107  /// Depth renderbuffer id
108  GLuint m_DepthRb;
109  /// Texture target id
110  GLuint m_FbTex;
111  /// Size of framebuffer (in both dimensions).
112  size_t m_FrameSize;
113 
114  ///
115  /// Texture parameters
116  ///
117 
118  /// minification filter
119  GLint m_TexMin;
120  /// magnification filter
121  GLint m_TexMag;
122  /// wrap s
123  GLint m_WrapS;
124  /// wrap t
125  GLint m_WrapT;
126  /// if true, the texture is not deleted with the framebuffer
128 
133 };
134 
136 
137 #endif // GUI_WX_GL_FRAMEBUFFER__HPP
CGLFrameBuffer.
GLint m_TexMag
magnification filter
virtual void ReleaseTexture()
Releases ownership of texture so it isn't deleted with framebuffer.
GLuint GetTexture()
GLint m_WrapT
wrap t
GLint m_TexMin
Texture parameters.
GLuint m_FbTex
Texture target id.
GLint m_WrapS
wrap s
virtual size_t GetFrameSize() const
Returns the size of the framebuffer (w==h, so only return 1 value)
GLint GetTexMag() const
GLint GetTexMin() const
GLuint m_Fb
OpenGL IDs.
GLint GetWraps() const
size_t m_FrameSize
Size of framebuffer (in both dimensions).
GLuint m_DepthRb
Depth renderbuffer id.
bool m_TextureReleased
if true, the texture is not deleted with the framebuffer
GLint GetWrapT() const
CObject –.
Definition: ncbiobj.hpp:180
virtual I3DTexture * Get3DTexture()=0
virtual void Render(std::function< void()> renderer)=0
virtual void CreateFrameBuffer()=0
virtual void SetTextureFiltering(GLint min_filter, GLint mag_filter)=0
virtual void GenerateMipMaps()=0
virtual void SetClearColor(float red, float green, float blue, float alpha)=0
bool IsValid(const CSeq_point &pt, CScope *scope)
Checks that point >= 0 and point < length of Bioseq.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_GUIOPENGL_EXPORT
Definition: gui_export.h:514
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
Standard mechanism to include OpenGL headers for all platforms.
Modified on Mon May 20 05:04:53 2024 by modify_doxy.py rev. 669887