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

Go to the SVN repository for this file.

1 #ifndef GUI_OPENGL___GL_RENDER_NODE__HPP
2 #define GUI_OPENGL___GL_RENDER_NODE__HPP
3 
4 /* $Id: glrendernode.hpp 43891 2019-09-16 13:50:00Z evgeniev $
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/vect3.hpp>
40 #include <gui/utils/vect4.hpp>
41 #include <gui/utils/matrix3.hpp>
42 #include <gui/utils/matrix4.hpp>
43 
44 #include <gui/utils/rgba_color.hpp>
45 #include <gui/opengl/glstate.hpp>
46 #include <gui/opengl/globject.hpp>
47 
48 
49 /** @addtogroup GUI_OPENGL
50  *
51  * @{
52  */
53 
55 
56 //////////////////////////////////////////////////////////////////////////////
57 /// CGlRenderNode
58 /// A unit of renderable geometry and the associated state information needed
59 /// for rendering.
60 ///
62 {
63 public:
64  /// ctor
65  CGlRenderNode();
66 
67  /// Set state and call x_Render() to render geometry
68  virtual void Render();
69 
70  /// Set/get current OpenGL state
71  void SetState(CGlState* state);
72  CGlState& GetState();
73  CGlState const& GetState() const;
74 
75  /// Set/get node visibility.
76  void SetVisible(bool b) { m_Visible = b; }
77  bool IsVisible() const { return m_Visible; }
78 
79  /// Turn off visibility for individual render targets. Allows nodes to be
80  /// visible in OpenGL but hidden in PDF, for example. SetVisible(false)
81  /// applies to all targets.
82  void SkipTarget(ERenderTarget target, bool skip);
83  bool IsSkipped(ERenderTarget target) const;
84  /*
85  * A node can be rendered at multiple positions (transformations) for
86  * efficency. If no positions are given, it will not be rendered.
87  */
88 
89  /// Set 1 transformation and have it be the identity matrix
90  void SetDefaultPosition();
91  /// Set 1 transformation and have it be "mat"
92  void SetPosition(const CMatrix4<float>& mat);
93  /// Add a new position
94  void AddPosition(const CMatrix4<float>& mat) { m_Positions.push_back(mat); }
95  /// Apply scale-dependent rotation (radians) around z (to all instances)
96  void SetRotationZ(float a) { m_RotAngleZ = a; }
97  /// Set/Get offset in pixels
98  void SetPixelOffset(const CVect2<float>& off) { m_PixelOffset = off; }
99  CVect2<float> GetPixelOffset() const { return m_PixelOffset; }
100 
101  /// return the current set of transformations for thisnode
102  vector<CMatrix4<float> >& GetPositions() { return m_Positions; }
103  void ClearPositions() { m_Positions.clear(); }
104 
105  /// return the position with rotation and pixel offset baked in
106  CMatrix4<float> GetTransformedPosition(size_t idx);
107 
108 
109 protected:
110  /// Does actual rendering work
111  virtual void x_Render() {}
112 
113  /// If false, do not render node contents
114  bool m_Visible;
115 
116  /// Set of rendering targets for which this node will not be rendered
117  /// even if m_Visible is true
118  vector<ERenderTarget> m_SkippedTargets;
119 
120  /// OpenGL state
122 
123  /// Set of positions (transformations) at which to render this node
124  vector<CMatrix4<float> > m_Positions;
125 
126  /// Pixel offset to apply to object
128 
129  /// Optional rotation angle to rotate object around Z axis. Stored here
130  /// because it can be updated according to the current scale to get
131  /// correct scale-dependent rotation angle.
132  float m_RotAngleZ;
133 };
134 
136 
137 /* @} */
138 
139 #endif // GUI_OPENGL___GL_RENDER_NODE__HPP
CGlObject Base class for OpenGl objects like buffers and models.
Definition: globject.hpp:55
CGlRenderNode A unit of renderable geometry and the associated state information needed for rendering...
CGlState Class to encapsulate Rendering state so that a set of user-selected GL state options can be ...
Definition: glstate.hpp:195
void ClearPositions()
CVect2< float > GetPixelOffset() const
CVect2< float > m_PixelOffset
Pixel offset to apply to object.
vector< CMatrix4< float > > & GetPositions()
return the current set of transformations for thisnode
vector< CMatrix4< float > > m_Positions
Set of positions (transformations) at which to render this node.
bool IsVisible() const
void SetPixelOffset(const CVect2< float > &off)
Set/Get offset in pixels.
void SetRotationZ(float a)
Apply scale-dependent rotation (radians) around z (to all instances)
virtual void x_Render()
Does actual rendering work.
CRef< CGlState > m_State
OpenGL state.
void AddPosition(const CMatrix4< float > &mat)
Add a new position.
float m_RotAngleZ
Optional rotation angle to rotate object around Z axis.
ERenderTarget
Different api levels based on information from OpenGL driver.
Definition: glstate.hpp:61
vector< ERenderTarget > m_SkippedTargets
Set of rendering targets for which this node will not be rendered even if m_Visible is true.
void SetVisible(bool b)
Set/get node visibility.
bool m_Visible
If false, do not render node contents.
#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
unsigned int a
Definition: ncbi_localip.c:102
Standard mechanism to include OpenGL headers for all platforms.
Modified on Wed Apr 17 13:08:03 2024 by modify_doxy.py rev. 669887