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

Go to the SVN repository for this file.

1 #ifndef GUI_OPENGL___GL_RESOURCE_MANAGER__HPP
2 #define GUI_OPENGL___GL_RESOURCE_MANAGER__HPP
3 
4 /* $Id: glresmgr.hpp 43134 2019-05-20 18:13:11Z 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  *
33  */
34 
35 #include <corelib/ncbiobj.hpp>
36 #include <gui/opengl.h>
37 #include <gui/gui.hpp>
38 
39 #include <gui/opengl/globject.hpp>
40 #include <gui/opengl/glutils.hpp>
41 #include <gui/opengl/irender.hpp>
42 
43 /** @addtogroup GUI_OPENGL
44  *
45  * @{
46  */
47 
49 
50 class IVboGeom;
51 class I3DTexture;
52 class I3DFrameBuffer;
53 class CImage;
54 
56 {
57 public:
58  /// Needs active OpenGL context when created. Determines best api level.
59  CGlResMgr();
60 
61  /// Destroys all gl objects it created.
62  ~CGlResMgr();
63 
64  /// Deletes all objects. Since object is a singleton, don't want to call
65  /// dtors during program exit as this can fail
66  void Clear();
67 
68  /// Find GL object (add type option?) TBD
69  //CGlObject* FindObject(const string& name);
70 
71  /// Set api level by querying opengl
72  void SetApiLevel();
73  /// Set the api level directly (override ctor). Good for testing.
74  void SetApiLevel(ERenderTarget level);
75  /// Get api level
76  ERenderTarget GetApiLevel() const { return m_ApiLevel; }
77 
78  /// Get geometry object for a node that renders using vertex buffers.
79  IVboGeom* CreateVboGeom(GLenum drawMode, const string& name);
80  IVboGeom* CreateNarrowTreeEdgeVboGeom(IVboGeom* edgeGeom);
81  IVboGeom* CreateFillerPointVboGeom(IVboGeom* edgeGeom);
82  IVboGeom* CreateTreeNodeVboGeom(size_t numSegments);
83 
84 
85  ///
86  /// Get/Set Renderer
87  ///
88 
89  void AddRenderer(CIRef<IRender> rm);
90  CIRef<IRender> RemoveRenderer(CIRef<IRender> rm);
91 
92  /// Returns first renderer in m_Renderers that renders to 'target'
93  CIRef<IRender> GetRenderer(ERenderTarget target);
94 
95  /// Set current renderer (rm must already be in m_Renderers)
96  void SetCurrentRenderer(CIRef<IRender> rm);
97  /// Returns current renderer, or NULL
98  CIRef<IRender> GetCurrentRenderer() {return CIRef<IRender>(m_CurrentRenderer);}
99 
100  /// Clear all current rendering objects
101  void ClearRenderers();
102 
103 
104  // Get single instance of resource manager (singleton).
105  static CGlResMgr& Instance();
106  /// return true if static instance has been created (via a call to Instance()
107  static bool Initialized();
108 
109  I3DTexture* CreateTexture(CNcbiIstream& istr, const string& tag);
110  I3DTexture* CreateTexture(CImage* image);
111  I3DTexture* Create1DRGBATexture(size_t width, float* data);
112  I3DFrameBuffer* CreateFrameBuffer(size_t dim);
113 
114 protected:
116 
118 
119  std::vector<CIRef<IRender> > m_Renderers;
121 };
122 
124 
125 
126 #endif // GUI_OPENGL___GL_RESOURCE_MANAGER__HPP
CImage –.
Definition: Image.hpp:66
char data[12]
Definition: iconv.c:80
ERenderTarget GetApiLevel() const
Get api level.
Definition: glresmgr.hpp:76
CIRef< IRender > GetCurrentRenderer()
Returns current renderer, or NULL.
Definition: glresmgr.hpp:98
std::vector< CIRef< IRender > > m_Renderers
Definition: glresmgr.hpp:119
ERenderTarget m_ApiLevel
Definition: glresmgr.hpp:117
ERenderTarget
Different api levels based on information from OpenGL driver.
Definition: glstate.hpp:61
static CGlResMgr * m_StaticInstance
Definition: glresmgr.hpp:115
CIRef< IRender > m_CurrentRenderer
Definition: glresmgr.hpp:120
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
Definition: ncbistre.hpp:146
#define NCBI_GUIOPENGL_EXPORT
Definition: gui_export.h:514
const char * tag
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
Standard mechanism to include OpenGL headers for all platforms.
Modified on Sun Jun 23 05:20:05 2024 by modify_doxy.py rev. 669887