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

Go to the SVN repository for this file.

1 #ifndef GUI_OPENGL___GL_MODEL2D__HPP
2 #define GUI_OPENGL___GL_MODEL2D__HPP
3 
4 /* $Id: glmodel2d.hpp 42933 2019-04-26 20:12:15Z 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 <gui/opengl.h>
36 #include <gui/gui.hpp>
37 
38 #include <gui/utils/vect2.hpp>
39 #include <gui/utils/rgba_color.hpp>
40 #include <gui/opengl/glpane.hpp>
41 #include <gui/opengl/globject.hpp>
44 #include <gui/opengl/glvbonode.hpp>
45 //#include <gui/print/pdf.hpp>
46 
47 /** @addtogroup GUI_OPENGL
48  *
49  * @{
50  */
51 
53 
54 class CPdf;
55 
56 //////////////////////////////////////////////////////////////////////////////
57 /// CGlModel2D
58 /// Base class for a model set up for rendering purposes. Point of the class
59 /// is to hold a set of renderable geometry packaged into CGlRenderNode
60 /// subclasses. This base class does not do collision-detection, but
61 /// derived classes may.
62 ///
64 {
65 public:
66  CGlModel2D();
67  virtual ~CGlModel2D();
68 
69  /// Call immediately before rendering to copy data from temporary
70  /// buffers into vertex buffer objects
71  virtual void SyncBuffers();
72  /// clear everything - vectors and vertex buffers
73  virtual void ClearAll();
74  /// clear any geometry vectors but do not update vertex buffers
75  virtual void ClearArrays();
76 
77 
78  /// Draw to the screen
79  virtual void Render(CGlPane& pane);
80 
81  /// Draw to PDF file (base funcions in cpdf::PrintModel)
82  virtual void RenderPDF(CGlPane& pane, CRef<CPdf>& pdf) {}
83 
84  /// Find a geometry (vertex buffer object) node by name
85  CGlVboNode* FindGeomNode(const string& name);
86  /// Add a geometry (vertex buffer object) node. 'node_type' should be
87  /// one of GL_POINTS, GL_LINES, or GL_TRIANGLES
88  CGlVboNode* AddGeomNode(GLenum node_type,
89  const string& name,
90  bool visible = true);
91  /// Same as above, but insert node before specified index
92  CGlVboNode* AddGeomNode(GLenum node_type,
93  const string& name,
94  size_t idx,
95  bool visible = true);
96 
97  /// Add a geometry node of unspecified type (caller will have to allocate
98  /// appropriate buffer type for the node)
99  CGlVboNode* AddGeomNode(const string& name,
100  bool visible = true);
101  /// Same as above, but insert node before specified index
102  CGlVboNode* AddGeomNode(const string& name,
103  size_t idx,
104  bool visible = true);
105 
106  vector<CGlVboNode*>& GetNodes() { return m_GeomNodes; }
107 
108 
109  /// Find a geometry object (just geometry - not a render node) by name
110  CIRef<IVboGeom> FindGeomObject(const string& name);
111  /// Add a geometry (vertex buffer object) node. 'node_type' should be
112  /// one of GL_POINTS, GL_LINES, or GL_TRIANGLES
113  CIRef<IVboGeom> AddGeomObject(GLenum node_type,
114  const string& name);
115  vector<CIRef<IVboGeom> >& GetGeomObjects() { return m_GeomObjects; }
116 
117  /// Add a geometry node of unspecified type (caller will have to allocate
118  /// appropriate buffer type for the node)
119  CGlVboNode* AddTempGeomNode(const string& name,
120  bool visible = true);
121  CGlVboNode* AddTempGeomNode(GLenum node_type,
122  const string& name,
123  bool visible = true);
124  vector<CGlVboNode*>& GetTempNodes() { return m_TempGeomNodes; }
125 
126 
127 protected:
128 
129  /// For gluProject()
130  GLint m_Viewport[4];
131  GLdouble m_ModelviewMatrix[16];
132  GLdouble m_ProjectionMatrix[16];
133 
134  /// Set of rendernodes with vertex buffer objects. Not deleted
135  /// when ClearArrays() is called
136  vector<CGlVboNode*> m_GeomNodes;
137 
138  /// Geometry to use in nodes (can be shared between nodes)
139  vector<CIRef<IVboGeom> > m_GeomObjects;
140 
141  /// Set of single-use rendernodes (which may use geom from m_Geom)
142  /// These are deleted when ClearArrays is called.
143  vector<CGlVboNode*> m_TempGeomNodes;
144 };
145 
146 
147 
149 
150 /* @} */
151 
152 #endif // GUI_OPENGL___GL_MODEL2D__HPP
CGlModel2D Base class for a model set up for rendering purposes.
Definition: glmodel2d.hpp:64
CGlObject Base class for OpenGl objects like buffers and models.
Definition: globject.hpp:55
class CGlPane
Definition: glpane.hpp:62
CGlVboNode A rendering node that holds a vertex buffer object.
Definition: glvbonode.hpp:64
Definition: pdf.hpp:62
vector< CIRef< IVboGeom > > & GetGeomObjects()
Definition: glmodel2d.hpp:115
vector< CGlVboNode * > m_GeomNodes
Set of rendernodes with vertex buffer objects.
Definition: glmodel2d.hpp:136
vector< CGlVboNode * > & GetTempNodes()
Definition: glmodel2d.hpp:124
vector< CIRef< IVboGeom > > m_GeomObjects
Geometry to use in nodes (can be shared between nodes)
Definition: glmodel2d.hpp:139
vector< CGlVboNode * > m_TempGeomNodes
Set of single-use rendernodes (which may use geom from m_Geom) These are deleted when ClearArrays is ...
Definition: glmodel2d.hpp:143
virtual void RenderPDF(CGlPane &pane, CRef< CPdf > &pdf)
Draw to PDF file (base funcions in cpdf::PrintModel)
Definition: glmodel2d.hpp:82
vector< CGlVboNode * > & GetNodes()
Definition: glmodel2d.hpp:106
#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
Standard mechanism to include OpenGL headers for all platforms.
Modified on Tue May 28 05:52:31 2024 by modify_doxy.py rev. 669887