VTK  9.3.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 
27 #include <map> // for map
28 #include <tuple> // for tuple
29 #include <vector> // for vector
30 
31 VTK_ABI_NAMESPACE_BEGIN
32 class vtkCellArray;
34 class vtkMatrix4x4;
35 class vtkMatrix3x3;
38 class vtkOpenGLTexture;
42 class vtkPoints;
43 class vtkTexture;
44 class vtkTextureObject;
45 class vtkTransform;
47 
48 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLPolyDataMapper : public vtkPolyDataMapper
49 {
50 public:
51  static vtkOpenGLPolyDataMapper* New();
53  void PrintSelf(ostream& os, vtkIndent indent) override;
54 
58  void RenderPiece(vtkRenderer* ren, vtkActor* act) override;
59 
65  MapperHashType GenerateHash(vtkPolyData* polydata) override;
66 
68 
71  virtual void RenderPieceStart(vtkRenderer* ren, vtkActor* act);
72  virtual void RenderPieceDraw(vtkRenderer* ren, vtkActor* act);
73  virtual void RenderPieceFinish(vtkRenderer* ren, vtkActor* act);
75 
81  void ReleaseGraphicsResources(vtkWindow*) override;
82 
83  vtkGetMacro(PopulateSelectionSettings, int);
84  void SetPopulateSelectionSettings(int v) { this->PopulateSelectionSettings = v; }
85 
92  bool GetSupportsSelection() override { return true; }
93 
94  // used by RenderPiece and functions it calls to reduce
95  // calls to get the input and allow for rendering of
96  // other polydata (not the input)
98 
100 
106  vtkSetStringMacro(PointIdArrayName);
107  vtkGetStringMacro(PointIdArrayName);
108  vtkSetStringMacro(CellIdArrayName);
109  vtkGetStringMacro(CellIdArrayName);
111 
113 
118  vtkSetStringMacro(ProcessIdArrayName);
119  vtkGetStringMacro(ProcessIdArrayName);
121 
123 
132  vtkSetStringMacro(CompositeIdArrayName);
133  vtkGetStringMacro(CompositeIdArrayName);
135 
139  void ShallowCopy(vtkAbstractMapper* m) override;
140 
142  vtkGetObjectMacro(VBOs, vtkOpenGLVertexBufferObjectGroup);
143 
147  void SetVBOShiftScaleMethod(int method) override;
148 
157  vtkGetMacro(UseProgramPointSize, bool);
158  vtkSetMacro(UseProgramPointSize, bool);
159  vtkBooleanMacro(UseProgramPointSize, bool);
160 
162  {
163  PrimitiveStart = 0,
164  PrimitivePoints = 0,
169  PrimitiveEnd
170  };
171 
183  void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
184  int fieldAssociation, int componentno = -1) override;
185 
186  // This method will Map the specified data array for use as
187  // a texture coordinate for texture tname. The actual
188  // attribute will be named tname_coord so as to not
189  // conflict with the texture sampler definition which will
190  // be tname.
191  void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
192  int fieldAssociation, int componentno = -1) override;
193 
197  void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
198 
202  void RemoveAllVertexAttributeMappings() override;
203 
209  vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
210 
211 protected:
213  ~vtkOpenGLPolyDataMapper() override;
214 
216 
217  void MapDataArray(const char* vertexAttributeName, const char* dataArrayName,
218  const char* texturename, int fieldAssociation, int componentno);
219 
220  // what coordinate should be used for this texture
221  std::string GetTextureCoordinateName(const char* tname);
222 
223  // handle updating shift scale based on pose changes
224  virtual void UpdateCameraShiftScale(vtkRenderer* ren, vtkActor* actor);
225 
229  void GetCoincidentParameters(vtkRenderer* ren, vtkActor* actor, float& factor, float& offset);
230 
236  void ComputeBounds() override;
237 
242  virtual void UpdateShaders(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
243 
247  virtual bool GetNeedToRebuildShaders(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
248 
252  virtual void BuildShaders(
253  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
254 
258  virtual void GetShaderTemplate(
259  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
260 
264  virtual void ReplaceShaderValues(
265  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
266 
268 
272  virtual void ReplaceShaderRenderPass(
273  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act, bool prePass);
274  virtual void ReplaceShaderCustomUniforms(
275  std::map<vtkShader::Type, vtkShader*> shaders, vtkActor* act);
276  virtual void ReplaceShaderColor(
277  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
278  virtual void ReplaceShaderEdges(
279  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
280  virtual void ReplaceShaderLight(
281  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
282  virtual void ReplaceShaderTCoord(
283  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
284  virtual void ReplaceShaderPicking(
285  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
286  virtual void ReplaceShaderPrimID(
287  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
288  virtual void ReplaceShaderNormal(
289  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
290  virtual void ReplaceShaderClip(
291  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
292  virtual void ReplaceShaderPositionVC(
293  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
294  virtual void ReplaceShaderCoincidentOffset(
295  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
296  virtual void ReplaceShaderDepth(
297  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
299 
303  virtual void SetCustomUniforms(vtkOpenGLHelper& cellBO, vtkActor* actor);
304 
308  virtual void SetMapperShaderParameters(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
309 
313  virtual void SetLightingShaderParameters(
314  vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
315 
319  virtual void SetCameraShaderParameters(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
320 
324  virtual void SetPropertyShaderParameters(
325  vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
326 
330  virtual void UpdateBufferObjects(vtkRenderer* ren, vtkActor* act);
331 
335  virtual bool GetNeedToRebuildBufferObjects(vtkRenderer* ren, vtkActor* act);
336 
340  virtual void BuildBufferObjects(vtkRenderer* ren, vtkActor* act);
341 
345  virtual void BuildIBO(vtkRenderer* ren, vtkActor* act, vtkPolyData* poly);
346 
350  virtual void BuildSelectionIBO(
351  vtkPolyData* poly, std::vector<unsigned int> (&indices)[4], vtkIdType offset);
352 
356  virtual void BuildSelectionCache(const char* arrayName, bool selectingPoints, vtkPolyData* poly);
357 
358  // The VBO and its layout.
360 
361  // Structures for the various cell types we render.
362  vtkOpenGLHelper Primitives[PrimitiveEnd];
363  vtkOpenGLHelper SelectionPrimitives[PrimitiveEnd];
366  bool DrawingSelection = false;
368  vtkMTimeType SelectionTime = 0;
369 
370  std::map<std::tuple<unsigned int, unsigned int, vtkIdType>, std::vector<vtkIdType>>
373  bool SelectionCacheForPoints = false;
374  vtkMTimeType SelectionCacheTime = 0;
375  vtkPolyData* SelectionPolyData = nullptr;
376 
377  // do we have wide lines that require special handling
378  virtual bool HaveWideLines(vtkRenderer*, vtkActor*);
379 
380  // do we have textures that require special handling
381  virtual bool HaveTextures(vtkActor* actor);
382 
383  // how many textures do we have
384  virtual unsigned int GetNumberOfTextures(vtkActor* actor);
385 
386  // populate a vector with the textures we have
387  // the order is always
388  // ColorInternalTexture
389  // Actors texture
390  // Properties textures
391  virtual std::vector<std::pair<vtkTexture*, std::string>> GetTextures(vtkActor* actor);
392 
393  // do we have textures coordinates that require special handling
394  virtual bool HaveTCoords(vtkPolyData* poly);
395 
396  // values we use to determine if we need to rebuild shaders
397  // stored in a map keyed on the vtkOpenGLHelper, so one
398  // typically entry per type of primitive we render which
399  // matches the shader programs we use
401  {
402  public:
406 
407  // Caches the vtkOpenGLRenderPass::RenderPasses() information.
408  // Note: Do not dereference the pointers held by this object. There is no
409  // guarantee that they are still valid!
411  };
412  std::map<const vtkOpenGLHelper*, primitiveInfo> PrimitiveInfo;
413 
417 
418  // Check the renderpasses in actor's property keys to see if they've changed
419  // render stages:
420  vtkMTimeType GetRenderPassStageMTime(vtkActor* actor, const vtkOpenGLHelper* cellBO);
421 
423  vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
424  vtkStateStorage VBOBuildState; // used for determining when to rebuild the VBO
425  vtkStateStorage IBOBuildState; // used for determining whento rebuild the IBOs
427  vtkStateStorage TempState; // can be used to avoid constant allocs/deallocs
429 
432 
438 
439  // if set to true, tcoords will be passed to the
440  // VBO even if the mapper knows of no texture maps
441  // normally tcoords are only added to the VBO if the
442  // mapper has identified a texture map as well.
444 
445  virtual void BuildCellTextures(
446  vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation);
447 
448  void AppendCellTextures(vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation,
449  std::vector<unsigned char>& colors, std::vector<float>& normals, vtkPolyData* pd,
451 
458 
461  std::vector<unsigned char> EdgeValues;
462  virtual bool DrawingEdges(vtkRenderer*, vtkActor*);
463 
464  // additional picking indirection
469 
471  {
472  public:
477  };
478  std::map<std::string, ExtraAttributeValue> ExtraAttributes;
479 
481 
482  // are we currently drawing spheres/tubes
483  bool DrawingSpheres(vtkOpenGLHelper& cellBO, vtkActor* actor);
484  bool DrawingTubes(vtkOpenGLHelper& cellBO, vtkActor* actor);
485  bool DrawingTubesOrSpheres(vtkOpenGLHelper& cellBO, vtkActor* actor);
486 
487  // get which opengl mode to use to draw the primitive
488  int GetOpenGLMode(int representation, int primType);
489 
490  // get how big to make the points when doing point picking
491  // typically 2 for points, 4 for lines, 6 for surface
492  int GetPointPickingPrimitiveSize(int primType);
493 
494  // used to occasionally invoke timers
495  unsigned int TimerQueryCounter;
496 
497  // stores the mapping from OpenGL primitives IDs (gl_PrimitiveId) to VTK cells IDs
499 
500  // compute and set the maximum point and cell ID used in selection
501  virtual void UpdateMaximumPointCellIds(vtkRenderer* ren, vtkActor* actor);
502 
503  virtual void AddPointIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
504  unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
505  virtual void AddCellIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
506  unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
507 
508  vtkNew<vtkCellArray> SelectionArrays[4];
509 
510 private:
512  void operator=(const vtkOpenGLPolyDataMapper&) = delete;
513 };
514 
515 VTK_ABI_NAMESPACE_END
516 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:45
PolyDataMapper using OpenGL to render.
void ShallowCopy(vtkAbstractMapper *m) override
Make a shallow copy of this mapper.
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:40
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:30
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:270
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:61
virtual void RenderPiece(vtkRenderer *, vtkActor *)
Implemented by sub classes.
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:49
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:466
int vtkIdType
Definition: vtkType.h:315
represent GPU shader properties
std::map< std::string, ExtraAttributeValue > ExtraAttributes
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:79
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:27
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
vtkNew< vtkMatrix4x4 > VBOShiftScale
handles properties associated with a texture map
Definition: vtkTexture.h:57
vtkOpenGLRenderTimer * TimerQuery
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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:175
vtkGenericOpenGLResourceFreeCallback * ResourceCallback
vtkNew< vtkTransform > VBOInverseTransform
std::vector< unsigned char > EdgeValues
static vtkPolyDataMapper * New()
OpenGL buffer object.
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:25
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:28
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources that are being consumed by this mapper.
Definition: vtkMapper.h:104