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

Go to the SVN repository for this file.

1 #ifndef GUI_OPENGL___GL_RENDER_COMMON__HPP
2 #define GUI_OPENGL___GL_RENDER_COMMON__HPP
3 
4 /* $Id: render_common.hpp 45024 2020-05-09 02:03:16Z 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/opengl/irender.hpp>
39 
40 #include <gui/opengl/glvbonode.hpp>
41 
43 
45 {
46 public:
47  CRenderCommon();
48  virtual ~CRenderCommon() {}
49 
50  virtual void SetIsGreyscale(bool /*b*/) {};
51 
52  virtual bool IsSimplified() const { return false; };
53 
54  virtual bool IsPrinterFriendly() const { return false; };
55 
56  /// Clear/delete any graphics/OpenGL memory. Call this if you delete
57  /// the current OpenGL context
58  virtual void Clear();
59 
60  /// Overridden in subclasses to return the supported rendering target
61  virtual ERenderTarget GetApi() { return eApiUndefined; }
62 
63  /// Start rendering. "mode" may be one of:
64  /// GL_LINES, GL_LINE_STRIP, GL_LINE_LOOP, GL_TRIANGLES, GL_TRIANGLE_FAN,
65  /// GL_TRIANGLE_STRIP or GL_QUADS.
66  /// Start rendering - use state in existing 'state' object.
67  virtual void Begin(GLenum mode);
68 
69  /// Finish rendering (create buffer and send to renderer)
70  virtual void End();
71 
72  /// @name Polygon rendering interface
73  /// @{
74 
75  /// Explicit support not currently available for:
76  /// GLbyte, GlShort and GLint calls, e.g. glVertex2i(int x, int y);
77  /// Vertices with homgeneous coords, e.g.
78  /// glVertex4f(float x, float y, float z, float w);
79  /// 3&4-dimensional texture coords, e.g. glTexCoord4f
80  /// Generic attributes and mulitple texture coords per vertex
81 
82  /// Vertices
83  virtual void Vertex3f(GLfloat x, GLfloat y, GLfloat z);
84 
85  /// Rect() functions also do Begin() and End() (as in OpenGL)
86  virtual void Rectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2);
87 
88  /// Colors (also defined in IGlState since they can be set either before
89  /// or inside of Begin()/End(). Other state must be set before.
90  virtual void ColorC(const CRgbaColor& color);
91 
92  /// Texture coords
93  virtual void TexCoord2f(GLfloat s, GLfloat t);
94 
95  /// @name Text interface
96  /// @{
97 
98  /// Text is drawn is pixel coordinates. Its position is
99  /// transformed by the current ModelView matrix. The color and alpha for
100  /// text are set in BeginText() and can be changed with SetTextColor().
101  /// Other OpenGL state should not affect text (since BeginText sets
102  /// appropriate state)
103 
104  /// Set OpenGL state needed for writing text (call before DrawText)
105  virtual void BeginText(const CGlTextureFont* font,
106  const CRgbaColor& color);
107  /// Same as above, but get color from m_RenderNode.m_State
108  virtual void BeginText(const CGlTextureFont* font);
109  /// Pops matrices and attributes after writing text
110  virtual void EndText();
111 
112  /// Update text color and alpha
113  void SetTextColor(const CRgbaColor& color) { m_TextColor = color; }
114  CRgbaColor GetTextColor() const { return m_TextColor; }
115 
116  /// Write text at specified model coords
117  virtual void WriteText(TModelUnit x, TModelUnit y,
118  const char* text,
119  TModelUnit rotate_degrees = 0.0);
120  /// Write text at specified model coords inside box defined by
121  /// (x,y,width,height) with specified alignment, truncation and rotation
122  virtual void WriteText(TModelUnit x, TModelUnit y,
123  TModelUnit width, TModelUnit height,
124  const char* text,
127  TModelUnit rotate_degrees = 0.0f);
128 
129  /// Calls the standard font metric functions except for pdf in which case
130  /// it first replaces any bitmap fonts with texture fnots
131  virtual TModelUnit GetMetric(const CGlTextureFont* font,
132  IGlFont::EMetric metric,
133  const char* text = NULL,
134  int len = -1) const;
135  virtual TModelUnit TextWidth(const CGlTextureFont* font, const char* text) const;
136  virtual TModelUnit TextHeight(const CGlTextureFont* font) const;
137  virtual TModelUnit GetFontDescender(const CGlTextureFont* font) const;
138  virtual TModelUnit GetAdvance(const CGlTextureFont* font, char c) const;
139  virtual TModelUnit GetMaxWidth(const CGlTextureFont* font, int max_num) const;
140  /// @}
141 
142  /// @name Viewports, matrices and transformations
143  /// @{
144  virtual void Viewport(GLint x, GLint y, GLsizei width, GLsizei height);
145  virtual void GetViewport(GLint *params);
146  /// @}
147 
148  /// Allow caller to access state directly
149  virtual CRef<CGlState> GetState() { return m_State; }
150  virtual void ResetState()
151  {
152  if (m_State)
153  m_State->Reset();
154  }
155 
156  virtual void BeginClippingRect(GLint x, GLint y, GLsizei width, GLsizei height) {};
157  virtual void EndClippingRect() {};
158 
159  virtual void Render(CGlPane& pane, CGlModel2D* model);
160 
161 protected:
162  virtual void x_RenderBuffer(CGlVboNode* node);
163 
164  void x_SyncAttribs(vector<CRgbaColor>& colors);
165  void x_SyncAttribs(vector<CVect3<float> >& vecs);
166  void x_SyncAttribs(vector<CVect2<float> >& vecs);
167 
168  vector<CVect3<float> > m_VertexBuffer;
169  vector<CRgbaColor> m_ColorBuffer;
170  vector<CVect2<float> > m_TexCoord2DBuffer1;
171 
172  /// vertex buffer node for rendering all Begin()/End() renders
174  /// state used by all nodes
176 
177  /// current modelview matrix and matrix mode
178  GLenum m_MatrixMode;
179 
180  /// current projection set by Viewport()
181  GLint m_Viewport[4];
182 
183  /// rendering mode from Begin()
185 
186  /// text parameters
188  /// color and alpha for text only (other GL options do not apply to text)
190 
191 private:
192 };
193 
194 
196 
197 /* @} */
198 
199 #endif // GUI_OPENGL___GL_RENDER_COMMON__HPP
CGlModel2D Base class for a model set up for rendering purposes.
Definition: glmodel2d.hpp:64
class CGlPane
Definition: glpane.hpp:62
CGlVboNode A rendering node that holds a vertex buffer object.
Definition: glvbonode.hpp:64
virtual void EndClippingRect()
CGlVboNode m_RenderNode
vertex buffer node for rendering all Begin()/End() renders
CRef< CGlState > m_State
state used by all nodes
CRgbaColor m_TextColor
color and alpha for text only (other GL options do not apply to text)
GLenum m_CurrentMode
rendering mode from Begin()
virtual void SetIsGreyscale(bool)
const CGlTextureFont * m_CurrentFont
text parameters
virtual void BeginClippingRect(GLint x, GLint y, GLsizei width, GLsizei height)
virtual bool IsSimplified() const
vector< CVect2< float > > m_TexCoord2DBuffer1
void SetTextColor(const CRgbaColor &color)
Update text color and alpha.
virtual CRef< CGlState > GetState()
Allow caller to access state directly.
CRgbaColor GetTextColor() const
vector< CRgbaColor > m_ColorBuffer
GLenum m_MatrixMode
current modelview matrix and matrix mode
virtual void ResetState()
virtual ~CRenderCommon()
virtual ERenderTarget GetApi()
Overridden in subclasses to return the supported rendering target.
vector< CVect3< float > > m_VertexBuffer
virtual bool IsPrinterFriendly() const
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:58
static const Colors colors
Definition: cn3d_colors.cpp:50
static int trunc
Definition: array_out.c:8
#define NULL
Definition: ncbistd.hpp:225
virtual void Clear()=0
Clear/delete any graphics/OpenGL memory.
GLdouble TModelUnit
Definition: gltypes.hpp:48
virtual void Viewport(GLint x, GLint y, GLsizei width, GLsizei height)=0
virtual void TexCoord2f(GLfloat s, GLfloat t)=0
Colors (also defined in IGlState since they can be set either before or inside of Begin()/End().
virtual void Begin(GLenum mode)=0
Start rendering.
virtual void Render(CGlPane &pane, CGlModel2D *model)=0
virtual TModelUnit TextHeight(const CGlTextureFont *font) const =0
virtual void BeginText(const CGlTextureFont *font, const CRgbaColor &color)=0
Text is drawn is pixel coordinates.
virtual TModelUnit TextWidth(const CGlTextureFont *font, const char *text) const =0
virtual void EndText()=0
Pops matrices and attributes after writing text.
virtual TModelUnit GetMaxWidth(const CGlTextureFont *font, int max_num) const =0
ERenderTarget
Different api levels based on information from OpenGL driver.
Definition: glstate.hpp:61
virtual void End()=0
Finish rendering (create buffer and send to renderer)
virtual void WriteText(TModelUnit x, TModelUnit y, const char *text, TModelUnit rotate_degrees=0.0)=0
Write text at specified model coords.
virtual TModelUnit GetMetric(const CGlTextureFont *font, IGlFont::EMetric metric, const char *text=NULL, int len=-1) const =0
Calls the standard font metric functions except for pdf in which case it first replaces any bitmap fo...
virtual void Vertex3f(GLfloat x, GLfloat y, GLfloat z)=0
Explicit support not currently available for: GLbyte, GlShort and GLint calls, e.g.
virtual void Rectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)=0
Rect() functions also do Begin() and End() (as in OpenGL)
virtual void ColorC(const CRgbaColor &c)=0
Set current color (glColor{3,4}{f,d}{v,})
ETruncate
Definition: glfont.hpp:62
int TAlign
Definition: glfont.hpp:113
virtual void GetViewport(GLint *params)=0
@ eAlign_Center
Definition: glfont.hpp:111
@ eApiUndefined
Definition: glstate.hpp:61
@ eTruncate_Ellipsis
Definition: glfont.hpp:70
#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
n background color
int len
static void text(MDB_val *v)
Definition: mdb_dump.c:62
mdb_mode_t mode
Definition: lmdb++.h:38
EIPRangeType t
Definition: ncbi_localip.c:101
Standard mechanism to include OpenGL headers for all platforms.
Modified on Fri Sep 20 14:57:23 2024 by modify_doxy.py rev. 669887