VTK  9.7.1
vtkOpenGLPolyDataMapper.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
16 #ifndef vtkOpenGLPolyDataMapper_h
17 #define vtkOpenGLPolyDataMapper_h
18 
19 #include "vtkInformation.h" // for prim struct
20 #include "vtkNew.h" // For vtkNew
21 #include "vtkOpenGLHelper.h" // used for ivars
22 #include "vtkPolyDataMapper.h"
23 #include "vtkRenderingOpenGL2Module.h" // For export macro
24 #include "vtkShader.h" // for methods
25 #include "vtkStateStorage.h" // used for ivars
26 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
27 
28 #include <map> // for map
29 #include <tuple> // for tuple
30 #include <vector> // for vector
31 
32 VTK_ABI_NAMESPACE_BEGIN
33 class vtkCellArray;
35 class vtkMatrix4x4;
36 class vtkMatrix3x3;
39 class vtkOpenGLTexture;
43 class vtkPoints;
44 class vtkTexture;
45 class vtkTextureObject;
46 class vtkTransform;
49 
50 class VTKRENDERINGOPENGL2_EXPORT VTK_MARSHALAUTO vtkOpenGLPolyDataMapper : public vtkPolyDataMapper
51 {
52 public:
53  static vtkOpenGLPolyDataMapper* New();
55  static vtkOverrideAttribute* CreateOverrideAttributes();
57  void PrintSelf(ostream& os, vtkIndent indent) override;
58 
62  void RenderPiece(vtkRenderer* ren, vtkActor* act) override;
63 
69  MapperHashType GenerateHash(vtkPolyData* polydata) override;
70 
76 
78 
81  virtual void RenderPieceStart(vtkRenderer* ren, vtkActor* act);
82  virtual void RenderPieceDraw(vtkRenderer* ren, vtkActor* act);
83  virtual void RenderPieceFinish(vtkRenderer* ren, vtkActor* act);
85 
91  void ReleaseGraphicsResources(vtkWindow*) override;
92 
94  vtkGetMacro(PopulateSelectionSettings, int);
96  void SetPopulateSelectionSettings(int v) { this->PopulateSelectionSettings = v; }
97 
104  bool GetSupportsSelection() override { return true; }
105 
106  // used by RenderPiece and functions it calls to reduce
107  // calls to get the input and allow for rendering of
108  // other polydata (not the input)
110 
114  void ShallowCopy(vtkAbstractMapper* m) override;
115 
117  vtkGetObjectMacro(VBOs, vtkOpenGLVertexBufferObjectGroup);
118 
122  void SetVBOShiftScaleMethod(int method) override;
123 
132  vtkGetMacro(UseProgramPointSize, bool);
133  vtkSetMacro(UseProgramPointSize, bool);
134  vtkBooleanMacro(UseProgramPointSize, bool);
135 
136  // NOLINTNEXTLINE(readability-enum-initial-value)
138  {
139  PrimitiveStart = 0,
140  PrimitivePoints = 0,
145  PrimitiveEnd
146  };
147 
159  void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
160  int fieldAssociation, int componentno = -1) override;
161 
162  // This method will Map the specified data array for use as
163  // a texture coordinate for texture tname. The actual
164  // attribute will be named tname_coord so as to not
165  // conflict with the texture sampler definition which will
166  // be tname.
167  void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
168  int fieldAssociation, int componentno = -1) override;
169 
173  void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
174 
178  void RemoveAllVertexAttributeMappings() override;
179 
185  vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
186 
187 protected:
189  ~vtkOpenGLPolyDataMapper() override;
190 
192 
193  void MapDataArray(const char* vertexAttributeName, const char* dataArrayName,
194  const char* texturename, int fieldAssociation, int componentno);
195 
196  // what coordinate should be used for this texture
197  std::string GetTextureCoordinateName(const char* tname);
198 
199  // handle updating shift scale based on pose changes
200  virtual void UpdateCameraShiftScale(vtkRenderer* ren, vtkActor* actor);
201 
205  void GetCoincidentParameters(vtkRenderer* ren, vtkActor* actor, float& factor, float& offset);
206 
212  void ComputeBounds() override;
213 
218  virtual void UpdateShaders(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
219 
223  virtual bool GetNeedToRebuildShaders(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
224 
228  virtual void BuildShaders(
229  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
230 
234  virtual void GetShaderTemplate(
235  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
236 
240  virtual void ReplaceShaderValues(
241  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
242 
244 
248  virtual void ReplaceShaderRenderPass(
249  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act, bool prePass);
250  virtual void ReplaceShaderCustomUniforms(
251  std::map<vtkShader::Type, vtkShader*> shaders, vtkActor* act);
252  virtual void ReplaceShaderColor(
253  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
254  virtual void ReplaceShaderEdges(
255  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
256  virtual void ReplaceShaderLight(
257  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
258  virtual void ReplaceShaderTCoord(
259  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
260  virtual void ReplaceShaderPicking(
261  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
262  virtual void ReplaceShaderPrimID(
263  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
264  virtual void ReplaceShaderNormal(
265  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
266  virtual void ReplaceShaderClip(
267  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
268  virtual void ReplaceShaderPositionVC(
269  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
270  virtual void ReplaceShaderCoincidentOffset(
271  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
272  virtual void ReplaceShaderDepth(
273  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
275 
279  virtual void SetCustomUniforms(vtkOpenGLHelper& cellBO, vtkActor* actor);
280 
284  virtual void SetMapperShaderParameters(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
285 
289  virtual void SetLightingShaderParameters(
290  vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
291 
295  virtual void SetCameraShaderParameters(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
296 
300  virtual void SetPropertyShaderParameters(
301  vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
302 
306  virtual void UpdateBufferObjects(vtkRenderer* ren, vtkActor* act);
307 
311  virtual bool GetNeedToRebuildBufferObjects(vtkRenderer* ren, vtkActor* act);
312 
316  virtual void BuildBufferObjects(vtkRenderer* ren, vtkActor* act);
317 
321  virtual void BuildIBO(vtkRenderer* ren, vtkActor* act, vtkPolyData* poly);
322 
326  virtual void BuildSelectionIBO(
327  vtkPolyData* poly, std::vector<unsigned int> (&indices)[4], vtkIdType offset);
328 
332  virtual void BuildSelectionCache(const char* arrayName, bool selectingPoints, vtkPolyData* poly);
333 
334  // The VBO and its layout.
336 
337  // Structures for the various cell types we render.
338  vtkOpenGLHelper Primitives[PrimitiveEnd];
339  vtkOpenGLHelper SelectionPrimitives[PrimitiveEnd];
342  bool DrawingSelection = false;
344  vtkMTimeType SelectionTime = 0;
345 
346  std::map<std::tuple<unsigned int, unsigned int, vtkIdType>, std::vector<vtkIdType>>
349  bool SelectionCacheForPoints = false;
350  vtkMTimeType SelectionCacheTime = 0;
351  vtkPolyData* SelectionPolyData = nullptr;
352 
353  // do we have wide lines that require special handling
354  virtual bool HaveWideLines(vtkRenderer*, vtkActor*);
355 
356  // do we have textures that require special handling
357  bool HaveTextures(vtkActor* actor);
358 
359  // how many textures do we have
360  unsigned int GetNumberOfTextures(vtkActor* actor);
361 
362  typedef std::pair<vtkTexture*, std::string> texinfo;
371  virtual std::vector<texinfo> GetTextures(vtkActor* actor);
372 
373  // do we have textures coordinates that require special handling
374  virtual bool HaveTCoords(vtkPolyData* poly);
375 
376  // values we use to determine if we need to rebuild shaders
377  // stored in a map keyed on the vtkOpenGLHelper, so one
378  // typically entry per type of primitive we render which
379  // matches the shader programs we use
381  {
382  public:
389  {
390  NoLighting = 0,
391  Headlight = 1,
392  Directional = 2,
393  Positional = 3
394  };
395  LightingTypeEnum LastLightComplexity = NoLighting;
396 
398 
400 
401  // Caches the vtkOpenGLRenderPass::RenderPasses() information.
402  // Note: Do not dereference the pointers held by this object. There is no
403  // guarantee that they are still valid!
405  };
406  std::map<const vtkOpenGLHelper*, primitiveInfo> PrimitiveInfo;
407 
411 
412  // Check the renderpasses in actor's property keys to see if they've changed
413  // render stages:
414  vtkMTimeType GetRenderPassStageMTime(vtkActor* actor, const vtkOpenGLHelper* cellBO);
415 
417  vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
418  vtkStateStorage VBOBuildState; // used for determining when to rebuild the VBO
419  vtkStateStorage IBOBuildState; // used for determining whento rebuild the IBOs
421  vtkStateStorage TempState; // can be used to avoid constant allocs/deallocs
423 
426 
432 
433  // if set to true, tcoords will be passed to the
434  // VBO even if the mapper knows of no texture maps
435  // normally tcoords are only added to the VBO if the
436  // mapper has identified a texture map as well.
438 
439  virtual void BuildCellTextures(
440  vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation);
441 
442  void AppendCellTextures(vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation,
443  std::vector<unsigned char>& colors, std::vector<float>& normals, vtkPolyData* pd,
445 
452 
455  std::vector<unsigned char> EdgeValues;
456  virtual bool DrawingEdges(vtkRenderer*, vtkActor*);
457 
459  {
460  public:
465  };
466  std::map<std::string, ExtraAttributeValue> ExtraAttributes;
467 
469 
470  // are we currently drawing spheres/tubes
471  bool DrawingSpheres(vtkOpenGLHelper& cellBO, vtkActor* actor);
472  bool DrawingLines(vtkOpenGLHelper& cellBO, vtkActor* actor);
473  bool DrawingTubes(vtkOpenGLHelper& cellBO, vtkActor* actor);
474  bool DrawingTubesOrSpheres(vtkOpenGLHelper& cellBO, vtkActor* actor);
475  bool DrawingPoints(vtkOpenGLHelper& cellBO, vtkActor* actor);
476 
477  // get which opengl mode to use to draw the primitive
478  int GetOpenGLMode(int representation, int primType);
479 
480  // get how big to make the points when doing point picking
481  // typically 2 for points, 4 for lines, 6 for surface
482  int GetPointPickingPrimitiveSize(int primType);
483 
484  // used to occasionally invoke timers
485  unsigned int TimerQueryCounter;
486 
487  // stores the mapping from OpenGL primitives IDs (gl_PrimitiveId) to VTK cells IDs
489 
490  // compute and set the maximum point and cell ID used in selection
491  virtual void UpdateMaximumPointCellIds(vtkRenderer* ren, vtkActor* actor);
492 
493  virtual void AddPointIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
494  unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
495  virtual void AddCellIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
496  unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
497 
498  vtkNew<vtkCellArray> SelectionArrays[4];
499 
500  vtkMTimeType EnvironmentTextureTime = 0;
501  vtkTexture* EnvironmentTexture = nullptr;
502 
503 private:
505  void operator=(const vtkOpenGLPolyDataMapper&) = delete;
506 };
507 
508 #define vtkOpenGLPolyDataMapper_OVERRIDE_ATTRIBUTES \
509  vtkOpenGLPolyDataMapper::CreateOverrideAttributes()
510 VTK_ABI_NAMESPACE_END
511 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:49
PolyDataMapper using OpenGL to render.
Attribute for vtkObjectFactory overrides.
void ShallowCopy(vtkAbstractMapper *m) override
Make a shallow copy of this mapper.
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:41
vtkOpenGLBufferObject * CellScalarBuffer
virtual MapperHashType GenerateHash(vtkPolyData *)
This hash integer is computed by concrete graphics implementation of this class.
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:31
std::pair< vtkTexture *, std::string > texinfo
virtual void MapDataArrayToMultiTextureAttribute(const char *textureName, const char *dataArrayName, int fieldAssociation, int componentno=-1)
virtual void RemoveAllVertexAttributeMappings()
Remove all vertex attributes.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:318
record modification and/or execution time
Definition: vtkTimeStamp.h:24
vtkNew< vtkOpenGLCellToVTKCellMap > CellCellMap
vtkTextureObject * CellScalarTexture
vtkOpenGLBufferObject * CellNormalBuffer
vtkTextureObject * CellNormalTexture
OpenGL rendering utility functions.
abstract specification for renderers
Definition: vtkRenderer.h:63
virtual void RenderPiece(vtkRenderer *, vtkActor *)
Implemented by sub classes.
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:50
virtual void ProcessSelectorPixelBuffers(vtkHardwareSelector *, std::vector< unsigned int > &, vtkProp *)
allows a mapper to update a selections color buffers Called from a prop which in turn is called from ...
Definition: vtkMapper.h:469
int vtkIdType
Definition: vtkType.h:363
represent GPU shader properties
std::map< std::string, ExtraAttributeValue > ExtraAttributes
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:71
vtkOpenGLBufferObject * EdgeBuffer
virtual void RemoveVertexAttributeMapping(const char *vertexAttributeName)
Remove a vertex attribute mapping.
bool GetSupportsSelection() override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THIS METHOD OUTSIDE OF THE RENDERI...
OpenGL texture map.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:41
std::map< std::tuple< unsigned int, unsigned int, vtkIdType >, std::vector< vtkIdType > > SelectionCache
std::uintptr_t MapperHashType
vtkOpenGLVertexBufferObjectGroup * VBOs
a simple class to control print indentation
Definition: vtkIndent.h:28
LightingTypeEnum
Represent the type of lighting used.
vtkNew< vtkMatrix4x4 > VBOShiftScale
handles properties associated with a texture map
Definition: vtkTexture.h:58
vtkOpenGLRenderTimer * TimerQuery
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
#define VTK_NEWINSTANCE
#define VTK_MARSHALEXCLUDE(reason)
virtual void ComputeBounds()
Called in GetBounds().
abstract class specifies interface to map data
abstracts an OpenGL texture object.
virtual void MapDataArrayToVertexAttribute(const char *vertexAttributeName, const char *dataArrayName, int fieldAssociation, int componentno=-1)
Select a data array from the point/cell data and map it to a generic vertex attribute.
map vtkPolyData to graphics primitives
object to represent cell connectivity
Definition: vtkCellArray.h:177
vtkGenericOpenGLResourceFreeCallback * ResourceCallback
vtkNew< vtkTransform > VBOInverseTransform
std::vector< unsigned char > EdgeValues
static vtkPolyDataMapper * New()
virtual vtkIdType GetMaximumNumberOfTriangles(vtkRenderer *)
Returns an estimate of the number of triangles that can be rendered by the underlying graphics implem...
#define VTK_MARSHALAUTO
OpenGL buffer object.
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:26
manage vertex buffer objects shared within a mapper
std::map< const vtkOpenGLHelper *, primitiveInfo > PrimitiveInfo
vtkOpenGLTexture * InternalColorTexture
virtual void SetVBOShiftScaleMethod(int)
A convenience method for enabling/disabling the VBO's shift+scale transform.
Asynchronously measures GPU execution time for a single event.
Class to make storing and comparing state quick and easy.
represent and manipulate 3D points
Definition: vtkPoints.h:30
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources that are being consumed by this mapper.
Definition: vtkMapper.h:105
#define VTK_MARSHAL_EXCLUDE_REASON_IS_INTERNAL