VTK  9.3.1
vtkOpenGLContextDevice2D.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3 
21 #ifndef vtkOpenGLContextDevice2D_h
22 #define vtkOpenGLContextDevice2D_h
23 
24 #include "vtkContextDevice2D.h"
25 #include "vtkRenderingContextOpenGL2Module.h" // For export macro
26 
27 #include <cstdint> // For std::uintptr_t
28 #include <list> // For std::list
29 #include <vector> // For std::vector
30 
31 VTK_ABI_NAMESPACE_BEGIN
32 class vtkMatrix4x4;
33 class vtkOpenGLExtensionManager;
34 class vtkOpenGLHelper;
36 class vtkPath;
37 class vtkRenderer;
38 class vtkShaderProgram;
39 class vtkStringToImage;
40 class vtkTransform;
42 class vtkViewport;
43 class vtkWindow;
45 
46 class VTKRENDERINGCONTEXTOPENGL2_EXPORT vtkOpenGLContextDevice2D : public vtkContextDevice2D
47 {
48 public:
50  void PrintSelf(ostream& os, vtkIndent indent) override;
51 
55  static vtkOpenGLContextDevice2D* New();
56 
62  void DrawPoly(float* f, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
63 
70  void DrawLines(float* f, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
71 
77  void DrawPoints(float* points, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
78  void DrawPoints(
79  vtkDataArray* positions, vtkUnsignedCharArray* colors, std::uintptr_t cacheIdentifier) override;
80 
87  void DrawPointSprites(vtkImageData* sprite, float* points, int n, unsigned char* colors = nullptr,
88  int nc_comps = 0) override;
89  void DrawPointSprites(vtkImageData* sprite, vtkDataArray* positions, vtkUnsignedCharArray* colors,
90  std::uintptr_t cacheIdentifier) override;
91 
107  void DrawMarkers(int shape, bool highlight, float* points, int n, unsigned char* colors = nullptr,
108  int nc_comps = 0) override;
109  void DrawMarkers(int shape, bool highlight, vtkDataArray* positions, vtkUnsignedCharArray* colors,
110  std::uintptr_t cacheIdentifier) override;
111 
113 
118  vtkSetMacro(MaximumMarkerCacheSize, int);
119  vtkGetMacro(MaximumMarkerCacheSize, int);
121 
125  void DrawQuad(float* points, int n) override;
126 
130  void DrawQuadStrip(float* points, int n) override;
131 
135  void DrawPolygon(float*, int) override;
136  void DrawColoredPolygon(
137  float* points, int numPoints, unsigned char* colors = nullptr, int nc_comps = 0) override;
138 
150  void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy,
151  float startAngle, float stopAngle) override;
152 
159  void DrawEllipticArc(
160  float x, float y, float rX, float rY, float startAngle, float stopAngle) override;
161 
165  void DrawString(float* point, const vtkStdString& string) override;
166 
175  void ComputeStringBounds(const vtkStdString& string, float bounds[4]) override;
176 
182  void ComputeJustifiedStringBounds(const char* string, float bounds[4]) override;
183 
188  void DrawMathTextString(float point[2], const vtkStdString& string) override;
189 
194  void DrawImage(float p[2], float scale, vtkImageData* image) override;
195 
201  void DrawImage(const vtkRectf& pos, vtkImageData* image) override;
202 
207  void DrawPolyData(float p[2], float scale, vtkPolyData* polyData, vtkUnsignedCharArray* colors,
208  int scalarMode) override;
209 
213  void SetColor4(unsigned char color[4]) override;
214 
218  virtual void SetColor(unsigned char color[3]);
219 
223  void SetTexture(vtkImageData* image, int properties = 0) override;
224 
228  void SetPointSize(float size) override;
229 
233  void SetLineWidth(float width) override;
234 
238  void SetLineType(int type) override;
239 
243  void MultiplyMatrix(vtkMatrix3x3* m) override;
244 
248  void SetMatrix(vtkMatrix3x3* m) override;
249 
253  void GetMatrix(vtkMatrix3x3* m) override;
254 
258  void PushMatrix() override;
259 
263  void PopMatrix() override;
264 
265  /*
266  * Supply an int array of length 4 with x1, y1, width, height specifying
267  * clipping region for the device in pixels.
268  */
269  void SetClipping(int* x) override;
270 
274  void EnableClipping(bool enable) override;
275 
279  void Begin(vtkViewport* viewport) override;
280 
284  void End() override;
285 
293  void BufferIdModeBegin(vtkAbstractContextBufferId* bufferId) override;
294 
302  void BufferIdModeEnd() override;
303 
309  bool SetStringRendererToFreeType();
310 
315  bool SetStringRendererToQt();
316 
320  bool HasGLSL();
321 
323 
326  vtkGetObjectMacro(RenderWindow, vtkOpenGLRenderWindow);
328 
334  virtual void ReleaseGraphicsResources(vtkWindow* window);
335 
337 
340  vtkMatrix4x4* GetProjectionMatrix();
341  vtkMatrix4x4* GetModelMatrix();
343 
344 protected:
346  ~vtkOpenGLContextDevice2D() override;
347 
355  int GetNumberOfArcIterations(float rX, float rY, float startAngle, float stopAngle);
356 
361 
365  bool InRender;
366 
368 
371  class Private;
372  Private* Storage;
373 
377 
382 
383  vtkOpenGLHelper* LinesCBO; // vertex + color
384  void ReadyLinesCBOProgram();
386  void ReadyLinesBOProgram();
387  vtkOpenGLHelper* VCBO; // vertex + color
388  void ReadyVCBOProgram();
389  vtkOpenGLHelper* VBO; // vertex
390  void ReadyVBOProgram();
391  vtkOpenGLHelper* VTBO; // vertex + tcoord
392  void ReadyVTBOProgram();
393  vtkOpenGLHelper* SCBO; // sprite + color
394  void ReadySCBOProgram();
395  vtkOpenGLHelper* SBO; // sprite
396  void ReadySBOProgram();
397 
398  void SetMatrices(vtkShaderProgram* prog);
399  void BuildVBO(
400  vtkOpenGLHelper* cbo, float* v, int nv, unsigned char* coolors, int nc, float* tcoords);
401  void CoreDrawTriangles(
402  std::vector<float>& tverts, unsigned char* colors = nullptr, int numComp = 0);
403  // used for stipples
404  unsigned short LinePattern;
405 
407 
411  void DrawMarkersGL2PS(
412  int shape, bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
413  void DrawCrossMarkersGL2PS(
414  bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
415  void DrawPlusMarkersGL2PS(
416  bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
417  void DrawSquareMarkersGL2PS(
418  bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
419  void DrawCircleMarkersGL2PS(
420  bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
421  void DrawDiamondMarkersGL2PS(
422  bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
424 
426 
429  void DrawImageGL2PS(float p[2], vtkImageData* image);
430  void DrawImageGL2PS(float p[2], float scale, vtkImageData* image);
431  void DrawImageGL2PS(const vtkRectf& rect, vtkImageData* image);
433 
435 
438  void DrawCircleGL2PS(float x, float y, float rX, float rY);
439  void DrawWedgeGL2PS(float x, float y, float outRx, float outRy, float inRx, float inRy);
441 
445  void AddEllipseToPath(vtkPath* path, float x, float y, float rx, float ry, bool reverse);
446 
450  void TransformPath(vtkPath* path) const;
451 
455  void TransformPoint(float& x, float& y) const;
456 
460  void TransformSize(float& dx, float& dy) const;
461 
465  void ReleaseCache(std::uintptr_t cacheIdentifier) override;
466 
467 private:
469  void operator=(const vtkOpenGLContextDevice2D&) = delete;
470 
477  vtkImageData* GetMarker(int shape, int size, bool highlight);
478 
479  class vtkMarkerCacheObject
480  {
481  public:
482  vtkTypeUInt64 Key;
483  vtkImageData* Value;
484  bool operator==(vtkTypeUInt64 key) { return this->Key == key; }
485  };
486 
487  void ComputeStringBoundsInternal(const std::string& string, float bounds[4]);
488 
489  vtkTransform* ProjectionMatrix;
490  vtkTransform* ModelMatrix;
491 
492  std::list<vtkMarkerCacheObject> MarkerCache;
493  int MaximumMarkerCacheSize;
494 
499  vtkImageData* GenerateMarker(int shape, int size, bool highlight);
500 };
501 
502 VTK_ABI_NAMESPACE_END
503 #endif // vtkOpenGLContextDevice2D_h
OpenGL rendering window.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:28
virtual void SetMatrix(vtkMatrix3x3 *m)=0
Set the model view matrix for the display.
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:30
virtual void DrawPointSprites(vtkImageData *sprite, float *points, int n, unsigned char *colors=nullptr, int nc_comps=0)=0
Draw a series of point sprites, images centred at the points supplied.
virtual void SetClipping(int *x)=0
Supply an int array of length 4 with x1, y1, width, height specifying clipping region for the device ...
virtual void BufferIdModeEnd()
Finalize BufferId creation Mode.
virtual void ComputeJustifiedStringBounds(const char *string, float bounds[4])=0
Compute the bounds of the supplied string while taking into account the justification of the currentl...
virtual void DrawPoly(float *points, int n, unsigned char *colors=nullptr, int nc_comps=0)=0
Draw a poly line using the points - fastest code path due to memory layout of the coordinates...
concrete dataset representing a path defined by Bezier curves.
Definition: vtkPath.h:24
abstract specification for Viewports
Definition: vtkViewport.h:44
virtual void DrawPolygon(float *p, int n)
Draw a polygon using the specified number of points.
Class for drawing 2D primitives using OpenGL 1.1+.
Internal buffer object builder that maintains a cache of VBO groups.
virtual void BufferIdModeBegin(vtkAbstractContextBufferId *bufferId)
Start BufferId creation Mode.
abstract specification for renderers
Definition: vtkRenderer.h:61
static vtkContextDevice2D * New()
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:49
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:79
bool VTKCOMMONCORE_EXPORT operator==(const std::string &a, const vtkStringToken &b)
virtual void DrawPolyData(float p[2], float scale, vtkPolyData *polyData, vtkUnsignedCharArray *colors, int scalarMode)
Draw the supplied PolyData at the given x, y (p[0], p[1]) (bottom corner), scaled by scale (1...
virtual void Begin(vtkViewport *)
Begin drawing, pass in the viewport to set up the view.
base class for classes that render supplied text to an image.
virtual void SetColor4(unsigned char color[4])=0
Set the color for the device using unsigned char of length 4, RGBA.
bool InRender
Is the device currently rendering? Prevent multiple End() calls.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:27
virtual void EnableClipping(bool enable)=0
Enable or disable the clipping of the scene.
virtual void SetLineWidth(float width)=0
Set the line width.
virtual void ReleaseCache(std::uintptr_t vtkNotUsed(cacheIdentifier))
Concrete graphics implementations maintain a cache of heavy-weight buffer objects to achieve higher i...
virtual void DrawPoints(float *points, int n, unsigned char *colors=nullptr, int nc_comps=0)=0
Draw a series of points - fastest code path due to memory layout of the coordinates.
vtkOpenGLRenderWindow * RenderWindow
The OpenGL render window being used by the device.
a simple class to control print indentation
Definition: vtkIndent.h:28
virtual void DrawMarkers(int shape, bool highlight, float *points, int n, unsigned char *colors=nullptr, int nc_comps=0)
Draw a series of markers centered at the points supplied.
topologically and geometrically regular array of data
Definition: vtkImageData.h:42
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
virtual void DrawQuadStrip(float *, int)
Draw a quad using the specified number of points.
Abstract class for drawing 2D primitives.
virtual void PopMatrix()=0
Pop the current matrix off of the stack.
virtual void DrawLines(float *f, int n, unsigned char *colors=nullptr, int nc_comps=0)=0
Draw lines using the points - memory layout is as follows: l1p1,l1p2,l2p1,l2p2... ...
virtual void SetTexture(vtkImageData *image, int properties)=0
Set the texture for the device, it is used to fill the polygons.
virtual void DrawMathTextString(float *point, const vtkStdString &string)=0
Draw text using MathText markup for mathematical equations.
virtual void SetPointSize(float size)=0
Set the point size for glyphs/sprites.
dynamic, self-adjusting array of unsigned char
virtual void DrawQuad(float *, int)
Draw a quad using the specified number of points.
2D array of ids, used for picking.
virtual void DrawEllipticArc(float x, float y, float rX, float rY, float startAngle, float stopAngle)=0
Draw an elliptic arc with center at x,y with radii rX and rY between angles startAngle and stopAngle ...
virtual void MultiplyMatrix(vtkMatrix3x3 *m)=0
Multiply the current model view matrix by the supplied one.
virtual void DrawString(float *point, const vtkStdString &string)=0
Draw some text to the screen.
virtual void End()
End drawing, clean up the view.
virtual void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy, float startAngle, float stopAngle)=0
Draw an elliptic wedge with center at x, y, outer radii outRx, outRy, inner radii inRx...
virtual void DrawColoredPolygon(float *points, int numPoints, unsigned char *colors=nullptr, int nc_comps=0)
Draw a polygon using the specified number of points.
vtkRenderer * Renderer
We need to store a pointer to the renderer for the text rendering.
virtual void GetMatrix(vtkMatrix3x3 *m)=0
Set the model view matrix for the display.
virtual void ComputeStringBounds(const vtkStdString &string, float bounds[4])=0
Compute the bounds of the supplied string.
virtual void PushMatrix()=0
Push the current matrix onto the stack.
virtual void DrawImage(float p[2], float scale, vtkImageData *image)=0
Draw the supplied image at the given x, y (p[0], p[1]) (bottom corner), scaled by scale (1...
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:25
virtual void SetLineType(int type)=0
Set the line type type (using anonymous enum in vtkPen).
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
The ShaderProgram uses one or more Shader objects.