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

Go to the SVN repository for this file.

1 #ifndef GUI_OPENGL___IRENDER__HPP
2 #define GUI_OPENGL___IRENDER__HPP
3 
4 /* $Id: irender.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/glstate.hpp>
40 #include <gui/opengl/gltypes.hpp>
41 
42 
43 /** @addtogroup GUI_OPENGL
44  *
45  * @{
46  */
47 
49 
50 class CGlModel2D;
51 class CGlPane;
52 
53 class IRender
54 {
55 public:
56  virtual ~IRender() {}
57 
58  /// Clear/delete any graphics/OpenGL memory. Call this if you delete
59  /// the current OpenGL context
60  virtual void Clear() = 0;
61 
62  virtual ERenderTarget GetApi() = 0;
63 
64  virtual void SetIsGreyscale(bool b) = 0;
65 
66  virtual bool IsSimplified() const = 0;
67 
68  virtual bool IsPrinterFriendly() const = 0;
69 
70  /// @name former (no more deriving from an interface) IGlState interface
71  /// @{
72  /// glEnable()
73  virtual void Enable(GLenum glstate) = 0;
74  /// glDisable()
75  virtual void Disable(GLenum glstate) = 0;
76 
77  virtual void Hint(GLenum target, GLenum mode) = 0;
78 
79  /// Set line width for drawing: glLineWidth()
80  virtual void LineWidth(GLfloat w) = 0;
81 
82  /// Set point size for drawing: glPointSize()
83  virtual void PointSize(GLfloat size) = 0;
84 
85  /// Set shade model for default lighting: glShadeModel(GL_FLAT or GL_SMOOTH)
86  virtual void ShadeModel(GLenum mode) = 0;
87 
88  /// Set clipping window: glScissor(x,y,width,height)
89  virtual void Scissor(GLint x, GLint y,
90  GLsizei width, GLsizei height) = 0;
91 
92  /// Set current color (glColor{3,4}{f,d}{v,})
93  virtual void ColorC(const CRgbaColor& c) = 0;
94 
95  void Color3f(GLfloat r, GLfloat g, GLfloat b) { ColorC(CRgbaColor(r, g, b, 1.0f)); }
96  void Color3fv(const GLfloat* v) { ColorC(CRgbaColor(v[0], v[1], v[2], 1.0f)); }
97  void Color4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a) { ColorC(CRgbaColor(r, g, b, a)); }
98  void Color4fv(const GLfloat* v) { ColorC(CRgbaColor(v[0], v[1], v[2], v[3])); }
99 
100  void Color3d(GLdouble r, GLdouble g, GLdouble b) { ColorC(CRgbaColor(float(r), float(g), float(b), 1.0f)); }
101  void Color3dv(const GLdouble* v) { ColorC(CRgbaColor(float(v[0]), float(v[1]), float(v[2]), 1.0f)); }
102  void Color4d(GLdouble r, GLdouble g, GLdouble b, GLdouble a) { ColorC(CRgbaColor(float(r), float(g), float(b), float(a))); }
103  void Color4dv(const GLdouble* v) { ColorC(CRgbaColor(float(v[0]), float(v[1]), float(v[2]), float(v[3]))); }
104 
105  /// Set the color mask (glColorMask)
106  virtual void ColorMask(GLboolean red,
107  GLboolean green,
108  GLboolean blue,
109  GLboolean alpha) = 0;
110 
111  /// Set the polygon rasterization mode. For the first parameter, GL_FRONT
112  /// and GL_BACK are deprecated so better to use GL_FRONT_AND_BACK
113  virtual void PolygonMode(GLenum face, GLenum mode) = 0;
114 
115  /// Set line stipple pattern: glLineStipple(). Deprecated in gl 3.2+
116  virtual void LineStipple(GLint factor, GLushort pattern) = 0;
117 
118  /// Set polygon stipple pattern: glPolygonStipple(). Deprecated in gl 3.2+
119  virtual void PolygonStipple(GLubyte* mask) = 0;
120 
121 
122  ///
123  /// Options to be used when GL_BLEND is enabled.
124  /// The options used at render time will be those most recently
125  /// given by SetBlendFunc() OR SetBlendFuncSeparate() prior
126  /// to calling MakeCurrent().
127  ///
128 
129  /// Options for glBlendFunc. Enable via Enable(GL_BLEND);
130  virtual void BlendFunc(GLenum sfactor, GLenum dfactor) = 0;
131 
132  virtual void TexEnvi(GLenum target, GLenum pname, GLint param) = 0;
133 
134  ///
135  /// PDF-specific rendering state. Will not have any effect on OpenGL output
136  /// Note that in PDF files, some or all of these options may be settable
137  /// pre-element (attributes), not just per-object (uniform)
138  ///
139 
140  /// Set path joing style for lines (pdf-only)
142 
143  /// Set line cap ending style (pdf only)
145 
146  /// Set (override defualt) shading style for polygons
148  /// @}
149 
150  virtual void PushAttrib(GLbitfield mask) = 0;
151  virtual void PopAttrib() = 0;
152 
153  virtual CRef<CGlState> GetState() = 0;
154  virtual void ResetState() = 0;
155 
156 
157  /// Start rendering. "mode" may be one of:
158  /// GL_LINES, GL_LINE_STRIP, GL_LINE_LOOP, GL_TRIANGLES, GL_TRIANGLE_FAN,
159  /// GL_TRIANGLE_STRIP or GL_QUADS.
160  /// Start rendering - use state in existing 'state' object.
161  virtual void Begin(GLenum mode) = 0;
162 
163  /// Finish rendering (create buffer and send to renderer)
164  virtual void End() = 0;
165 
166  /// For shaders. Only works with OpenGL 2.0+
167  virtual void UseProgram(GLuint program) = 0;
168 
169  /// @name Polygon rendering interface
170  /// @{
171 
172  /// Explicit support not currently available for:
173  /// GLbyte, GlShort and GLint calls, e.g. glVertex2i(int x, int y);
174  /// Vertices with homgeneous coords, e.g.
175  /// glVertex4f(float x, float y, float z, float w);
176  /// 3&4-dimensional texture coords, e.g. glTexCoord4f
177  /// Generic attributes and mulitple texture coords per vertex
178 
179  /// Vertices
180  virtual void Vertex3f(GLfloat x, GLfloat y, GLfloat z) = 0;
181 
182  void Vertex2f(GLfloat x, GLfloat y) { Vertex3f(x, y, 0.0f); }
183  void Vertex2fv(const GLfloat* v) { Vertex3f(v[0], v[1], 0.0f); }
184  void Vertex3fv(const GLfloat* v) { Vertex3f(v[0], v[1], v[2]); }
185  void Vertex2d(GLdouble x, GLdouble y) { Vertex3f(float(x), float(y), 0.0f); }
186  void Vertex2dv(const GLdouble* v) { Vertex3f(float(v[0]), float(v[1]), 0.0f); }
187  void Vertex3d(GLdouble x, GLdouble y, GLdouble z) { Vertex3f(float(x), float(y), float(z)); }
188  void Vertex3dv(const GLdouble* v) { Vertex3f(float(v[0]), float(v[1]), float(v[2])); }
189 
190  /// Rect() functions also do Begin() and End() (as in OpenGL)
191  virtual void Rectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2) = 0;
192 
193  void Rectd(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2)
194  {
195  Rectf(float(x1), float(y1), float(x2), float(y2));
196  }
197  void RectC(const TVPRect& rc)
198  {
199  Rectf(float(rc.Left()), float(rc.Bottom()), float(rc.Right()), float(rc.Top()));
200  }
201  void RectC(const TModelRect& rc)
202  {
203  Rectf(float(rc.Left()), float(rc.Bottom()), float(rc.Right()), float(rc.Top()));
204  }
205 
206  /// Colors (also defined in IGlState since they can be set either before
207  /// or inside of Begin()/End(). Other state must be set before.
208 
209  /// Texture coords
210  virtual void TexCoord2f(GLfloat s, GLfloat t) = 0;
211 
212  void TexCoord2fv(const GLfloat* v) { TexCoord2f(v[0], v[1]); }
213  void TexCoord2d(GLdouble s, GLdouble t) { TexCoord2f(float(s), float(t)); }
214  void TexCoord2dv(const GLdouble* v) { TexCoord2f(float(v[0]), float(v[1])); }
215  /// @}
216 
217  /// @name Text interface
218  /// @{
219 
220  /// Text is drawn is pixel coordinates. Its position is
221  /// transformed by the current ModelView matrix. The color and alpha for
222  /// text are set in BeginText() and can be changed with SetTextColor().
223  /// Other OpenGL state should not affect text (since BeginText sets
224  /// appropriate state)
225 
226  /// Set OpenGL state needed for writing text (call before DrawText)
227  virtual void BeginText(const CGlTextureFont* font,
228  const CRgbaColor& color) = 0;
229  /// Same as above, but get color from m_RenderNode.m_State
230  virtual void BeginText(const CGlTextureFont* font) = 0;
231  /// Pops matrices and attributes after writing text
232  virtual void EndText() = 0;
233 
234  /// Write text at specified model coords
235  virtual void WriteText(TModelUnit x, TModelUnit y,
236  const char* text,
237  TModelUnit rotate_degrees = 0.0) = 0;
238  /// Write text at specified model coords inside box defined by
239  /// (x,y,width,height) with specified alignment, truncation and rotation
240  virtual void WriteText(TModelUnit x, TModelUnit y,
241  TModelUnit width, TModelUnit height,
242  const char* text,
245  TModelUnit rotate_degrees = 0.0f) = 0;
246 
247  /// Calls the standard font metric functions except for pdf in which case
248  /// it first replaces any bitmap fonts with texture fnots
249  virtual TModelUnit GetMetric(const CGlTextureFont* font,
250  IGlFont::EMetric metric,
251  const char* text = NULL,
252  int len = -1) const = 0;
253  virtual TModelUnit TextWidth(const CGlTextureFont* font, const char* text) const = 0;
254  virtual TModelUnit TextHeight(const CGlTextureFont* font) const = 0;
255  virtual TModelUnit GetMaxWidth(const CGlTextureFont* font, int max_num) const = 0;
256  /// @}
257 
258 
259  /// @name Viewports, matrices and transformations
260  /// @{
261  virtual void Viewport(GLint x, GLint y, GLsizei width, GLsizei height) = 0;
262  virtual void GetViewport(GLint *params) = 0;
263 
264  virtual void MatrixMode(GLenum mode) = 0;
265 
266  virtual void PushMatrix() = 0;
267  virtual void PopMatrix() = 0;
268  virtual void LoadIdentity() = 0;
269  virtual void LoadMatrixf(const GLfloat *m) = 0;
270  virtual void LoadMatrixd(const GLdouble* m) = 0;
271  virtual CMatrix4<float> GetModelViewMatrix() const = 0;
273  virtual void GetModelViewMatrix(GLdouble* m) const = 0;
274  virtual void GetProjectionMatrix(GLdouble* m) const = 0;
275 
276  virtual void Rotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z) = 0;
277  virtual void Rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) = 0;
278  virtual void Scalef(GLfloat x, GLfloat y, GLfloat z) = 0;
279  virtual void Translated(GLdouble x, GLdouble y, GLdouble z) = 0;
280  virtual void Translatef(GLfloat x, GLfloat y, GLfloat z) = 0;
281 
282  virtual void Ortho(GLdouble left, GLdouble right,
283  GLdouble bottom, GLdouble top,
284  GLdouble nearVal, GLdouble farVal) = 0;
285  /// @}
286 
287  // Clipping rectangles (implemented in SVG only at the moment)
288  virtual void BeginClippingRect(GLint x, GLint y, GLsizei width, GLsizei height) = 0;
289  virtual void EndClippingRect() = 0;
290 
291  virtual void Render(CGlPane& pane, CGlModel2D* model) = 0;
292 };
293 
294 ///////////////////////////////////////////////////////////////////////////////
295 /// convenience function for getting current render manager
296 ///
298 
299 
301 
302 /* @} */
303 
304 #endif // GUI_OPENGL___IRENDER__HPP
ncbi::TMaskedQueryRegions mask
CGlModel2D Base class for a model set up for rendering purposes.
Definition: glmodel2d.hpp:64
class CGlPane
Definition: glpane.hpp:62
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:58
static int trunc
Definition: array_out.c:8
#define NULL
Definition: ncbistd.hpp:225
virtual void Translated(GLdouble x, GLdouble y, GLdouble z)=0
virtual bool IsSimplified() const =0
virtual void Clear()=0
Clear/delete any graphics/OpenGL memory.
GLdouble TModelUnit
Definition: gltypes.hpp:48
virtual void LoadMatrixd(const GLdouble *m)=0
virtual void GetModelViewMatrix(GLdouble *m) const =0
void Color4fv(const GLfloat *v)
Definition: irender.hpp:98
virtual void Scalef(GLfloat x, GLfloat y, GLfloat z)=0
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().
ELineJoinStyle
Enumerators for non-enumerated state values (e.g. pdf-only state values)
Definition: glstate.hpp:77
virtual void Translatef(GLfloat x, GLfloat y, GLfloat z)=0
virtual CMatrix4< float > GetProjectionMatrix() const =0
virtual void Enable(GLenum glstate)=0
virtual void LineStipple(GLint factor, GLushort pattern)=0
Set line stipple pattern: glLineStipple(). Deprecated in gl 3.2+.
virtual void UseProgram(GLuint program)=0
For shaders. Only works with OpenGL 2.0+.
void TexCoord2fv(const GLfloat *v)
Definition: irender.hpp:212
virtual void Begin(GLenum mode)=0
Start rendering.
virtual void Rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)=0
T Top() const
Definition: glrect.hpp:84
void Color3dv(const GLdouble *v)
Definition: irender.hpp:101
void Color4dv(const GLdouble *v)
Definition: irender.hpp:103
virtual void BlendFunc(GLenum sfactor, GLenum dfactor)=0
Options to be used when GL_BLEND is enabled.
virtual void BeginClippingRect(GLint x, GLint y, GLsizei width, GLsizei height)=0
void Color3f(GLfloat r, GLfloat g, GLfloat b)
Definition: irender.hpp:95
T Bottom() const
Definition: glrect.hpp:82
virtual void ColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)=0
Set the color mask (glColorMask)
virtual CMatrix4< float > GetModelViewMatrix() const =0
void RectC(const TModelRect &rc)
Definition: irender.hpp:201
virtual void MatrixMode(GLenum mode)=0
virtual void PointSize(GLfloat size)=0
Set point size for drawing: glPointSize()
void Color3d(GLdouble r, GLdouble g, GLdouble b)
Definition: irender.hpp:100
virtual void LineJoinStyle(IGlState::ELineJoinStyle s)=0
PDF-specific rendering state.
void Color3fv(const GLfloat *v)
Definition: irender.hpp:96
IRender & GetGl()
convenience function for getting current render manager
virtual void Scissor(GLint x, GLint y, GLsizei width, GLsizei height)=0
Set clipping window: glScissor(x,y,width,height)
void RectC(const TVPRect &rc)
Definition: irender.hpp:197
void Vertex2d(GLdouble x, GLdouble y)
Definition: irender.hpp:185
void TexCoord2dv(const GLdouble *v)
Definition: irender.hpp:214
virtual void ResetState()=0
T Right() const
Definition: glrect.hpp:83
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 void PdfShadeStyle(IGlState::EPdfShadeStyle s)=0
Set (override defualt) shading style for polygons.
virtual void SetIsGreyscale(bool b)=0
virtual TModelUnit TextWidth(const CGlTextureFont *font, const char *text) const =0
virtual void PopAttrib()=0
virtual void BeginText(const CGlTextureFont *font)=0
Same as above, but get color from m_RenderNode.m_State.
virtual void PushAttrib(GLbitfield mask)=0
void Color4d(GLdouble r, GLdouble g, GLdouble b, GLdouble a)
Definition: irender.hpp:102
virtual void LoadIdentity()=0
virtual void EndText()=0
Pops matrices and attributes after writing text.
virtual TModelUnit GetMaxWidth(const CGlTextureFont *font, int max_num) const =0
virtual ~IRender()
Definition: irender.hpp:56
virtual void PopMatrix()=0
virtual void ShadeModel(GLenum mode)=0
Set shade model for default lighting: glShadeModel(GL_FLAT or GL_SMOOTH)
T Left() const
Definition: glrect.hpp:81
ERenderTarget
Different api levels based on information from OpenGL driver.
Definition: glstate.hpp:61
virtual void Rotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z)=0
virtual void EndClippingRect()=0
virtual bool IsPrinterFriendly() const =0
virtual void TexEnvi(GLenum target, GLenum pname, GLint param)=0
virtual void GetProjectionMatrix(GLdouble *m) const =0
virtual void End()=0
Finish rendering (create buffer and send to renderer)
virtual ERenderTarget GetApi()=0
virtual void PolygonMode(GLenum face, GLenum mode)=0
Set the polygon rasterization mode.
void Vertex2fv(const GLfloat *v)
Definition: irender.hpp:183
void TexCoord2d(GLdouble s, GLdouble t)
Definition: irender.hpp:213
virtual void PolygonStipple(GLubyte *mask)=0
Set polygon stipple pattern: glPolygonStipple(). Deprecated in gl 3.2+.
void Color4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a)
Definition: irender.hpp:97
ELineCapStyle
Definition: glstate.hpp:78
virtual void WriteText(TModelUnit x, TModelUnit y, const char *text, TModelUnit rotate_degrees=0.0)=0
Write text at specified model coords.
virtual void LoadMatrixf(const GLfloat *m)=0
void Vertex3dv(const GLdouble *v)
Definition: irender.hpp:188
void Vertex3fv(const GLfloat *v)
Definition: irender.hpp:184
EPdfShadeStyle
Definition: glstate.hpp:79
virtual void LineCapStyle(IGlState::ELineCapStyle c)=0
Set line cap ending style (pdf only)
void Vertex2dv(const GLdouble *v)
Definition: irender.hpp:186
void Vertex3d(GLdouble x, GLdouble y, GLdouble z)
Definition: irender.hpp:187
void Vertex2f(GLfloat x, GLfloat y)
Definition: irender.hpp:182
virtual void Disable(GLenum glstate)=0
glDisable()
virtual void Ortho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearVal, GLdouble farVal)=0
virtual void Hint(GLenum target, GLenum mode)=0
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 LineWidth(GLfloat w)=0
Set line width for drawing: glLineWidth()
virtual void Vertex3f(GLfloat x, GLfloat y, GLfloat z)=0
Explicit support not currently available for: GLbyte, GlShort and GLint calls, e.g.
virtual CRef< CGlState > GetState()=0
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
void Rectd(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2)
Definition: irender.hpp:193
virtual void PushMatrix()=0
int TAlign
Definition: glfont.hpp:113
virtual void WriteText(TModelUnit x, TModelUnit y, TModelUnit width, TModelUnit height, const char *text, CGlTextureFont::TAlign align=CGlTextureFont::eAlign_Center, CGlTextureFont::ETruncate trunc=CGlTextureFont::eTruncate_Ellipsis, TModelUnit rotate_degrees=0.0f)=0
Write text at specified model coords inside box defined by (x,y,width,height) with specified alignmen...
virtual void GetViewport(GLint *params)=0
@ eAlign_Center
Definition: glfont.hpp:111
@ 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
const struct ncbi::grid::netcache::search::fields::SIZE size
unsigned int a
Definition: ncbi_localip.c:102
EIPRangeType t
Definition: ncbi_localip.c:101
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
Standard mechanism to include OpenGL headers for all platforms.
int g(Seg_Gsm *spe, Seq_Mtf *psm, Thd_Gsm *tdg)
Definition: thrddgri.c:44
Modified on Fri Sep 20 14:57:49 2024 by modify_doxy.py rev. 669887