VTK  9.0.1
vtkOpenGLPolyDataMapper.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4 
5  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
6  All rights reserved.
7  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
21 #ifndef vtkOpenGLPolyDataMapper_h
22 #define vtkOpenGLPolyDataMapper_h
23 
24 #include "vtkNew.h" // For vtkNew
25 #include "vtkNew.h" // for ivars
26 #include "vtkOpenGLHelper.h" // used for ivars
27 #include "vtkPolyDataMapper.h"
28 #include "vtkRenderingOpenGL2Module.h" // For export macro
29 #include "vtkShader.h" // for methods
30 #include "vtkStateStorage.h" // used for ivars
31 
32 #include <map> //for methods
33 #include <vector> //for ivars
34 
35 class vtkCellArray;
37 class vtkMatrix4x4;
38 class vtkMatrix3x3;
41 class vtkOpenGLTexture;
45 class vtkPoints;
46 class vtkTexture;
47 class vtkTextureObject;
48 class vtkTransform;
50 
51 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLPolyDataMapper : public vtkPolyDataMapper
52 {
53 public:
56  void PrintSelf(ostream& os, vtkIndent indent) override;
57 
61  void RenderPiece(vtkRenderer* ren, vtkActor* act) override;
62 
64 
67  virtual void RenderPieceStart(vtkRenderer* ren, vtkActor* act);
68  virtual void RenderPieceDraw(vtkRenderer* ren, vtkActor* act);
69  virtual void RenderPieceFinish(vtkRenderer* ren, vtkActor* act);
71 
78 
79  vtkGetMacro(PopulateSelectionSettings, int);
80  void SetPopulateSelectionSettings(int v) { this->PopulateSelectionSettings = v; }
81 
88  bool GetSupportsSelection() override { return true; }
89 
90  // used by RenderPiece and functions it calls to reduce
91  // calls to get the input and allow for rendering of
92  // other polydata (not the input)
94 
96 
102  vtkSetStringMacro(PointIdArrayName);
103  vtkGetStringMacro(PointIdArrayName);
104  vtkSetStringMacro(CellIdArrayName);
105  vtkGetStringMacro(CellIdArrayName);
107 
109 
114  vtkSetStringMacro(ProcessIdArrayName);
115  vtkGetStringMacro(ProcessIdArrayName);
117 
119 
128  vtkSetStringMacro(CompositeIdArrayName);
129  vtkGetStringMacro(CompositeIdArrayName);
131 
132 #ifndef VTK_LEGACY_REMOVE
134 
144  VTK_LEGACY(void AddShaderReplacement(vtkShader::Type shaderType, // vertex, fragment, etc
145  const std::string& originalValue,
146  bool replaceFirst, // do this replacement before the default
147  const std::string& replacementValue, bool replaceAll);)
148  VTK_LEGACY(void ClearShaderReplacement(vtkShader::Type shaderType, // vertex, fragment, etc
149  const std::string& originalValue, bool replaceFirst);)
150  VTK_LEGACY(void ClearAllShaderReplacements(vtkShader::Type shaderType);)
151  VTK_LEGACY(void ClearAllShaderReplacements();)
153 
155 
163  VTK_LEGACY(virtual void SetVertexShaderCode(const char* code);)
164  VTK_LEGACY(virtual char* GetVertexShaderCode();)
165  VTK_LEGACY(virtual void SetFragmentShaderCode(const char* code);)
166  VTK_LEGACY(virtual char* GetFragmentShaderCode();)
167  VTK_LEGACY(virtual void SetGeometryShaderCode(const char* code);)
168  VTK_LEGACY(virtual char* GetGeometryShaderCode();)
170 #endif
171 
175  void ShallowCopy(vtkAbstractMapper* m) override;
176 
178  vtkGetObjectMacro(VBOs, vtkOpenGLVertexBufferObjectGroup);
179 
184 
186  {
187  PrimitiveStart = 0,
188  PrimitivePoints = 0,
195  PrimitiveEnd
196  };
197 
209  void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
210  int fieldAssociation, int componentno = -1) override;
211 
212  // This method will Map the specified data array for use as
213  // a texture coordinate for texture tname. The actual
214  // attribute will be named tname_coord so as to not
215  // conflict with the texture sampler definition which will
216  // be tname.
217  void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
218  int fieldAssociation, int componentno = -1) override;
219 
223  void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
224 
229 
235  vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
236 
237 protected:
240 
242 
243  void MapDataArray(const char* vertexAttributeName, const char* dataArrayName,
244  const char* texturename, int fieldAssociation, int componentno);
245 
246  // what coordinate should be used for this texture
248 
252  void GetCoincidentParameters(vtkRenderer* ren, vtkActor* actor, float& factor, float& offset);
253 
259  void ComputeBounds() override;
260 
265  virtual void UpdateShaders(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
266 
270  virtual bool GetNeedToRebuildShaders(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
271 
275  virtual void BuildShaders(
276  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
277 
281  virtual void GetShaderTemplate(
282  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
283 
287  virtual void ReplaceShaderValues(
288  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
289 
291 
296  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act, bool prePass);
298  std::map<vtkShader::Type, vtkShader*> shaders, vtkActor* act);
299  virtual void ReplaceShaderColor(
300  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
301  virtual void ReplaceShaderLight(
302  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
303  virtual void ReplaceShaderTCoord(
304  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
305  virtual void ReplaceShaderPicking(
306  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
307  virtual void ReplaceShaderPrimID(
308  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
309  virtual void ReplaceShaderNormal(
310  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
311  virtual void ReplaceShaderClip(
312  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
314  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
316  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
317  virtual void ReplaceShaderDepth(
318  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
320 
324  virtual void SetCustomUniforms(vtkOpenGLHelper& cellBO, vtkActor* actor);
325 
330 
335  vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
336 
341 
346  vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
347 
351  virtual void UpdateBufferObjects(vtkRenderer* ren, vtkActor* act);
352 
357 
361  virtual void BuildBufferObjects(vtkRenderer* ren, vtkActor* act);
362 
366  virtual void BuildIBO(vtkRenderer* ren, vtkActor* act, vtkPolyData* poly);
367 
368  // The VBO and its layout.
370 
371  // Structures for the various cell types we render.
372  vtkOpenGLHelper Primitives[PrimitiveEnd];
375 
376  // do we have wide lines that require special handling
378 
379  // do we have textures that require special handling
380  virtual bool HaveTextures(vtkActor* actor);
381 
382  // how many textures do we have
383  virtual unsigned int GetNumberOfTextures(vtkActor* actor);
384 
385  // populate a vector with the textures we have
386  // the order is always
387  // ColorInternalTexture
388  // Actors texture
389  // Properties textures
390  virtual std::vector<std::pair<vtkTexture*, std::string> > GetTextures(vtkActor* actor);
391 
392  // do we have textures coordinates that require special handling
393  virtual bool HaveTCoords(vtkPolyData* poly);
394 
395  // values we use to determine if we need to rebuild shaders
396  std::map<const vtkOpenGLHelper*, int> LastLightComplexity;
397  std::map<const vtkOpenGLHelper*, int> LastLightCount;
398  std::map<const vtkOpenGLHelper*, vtkTimeStamp> LightComplexityChanged;
399 
402 
403  // Caches the vtkOpenGLRenderPass::RenderPasses() information.
404  // Note: Do not dereference the pointers held by this object. There is no
405  // guarantee that they are still valid!
407 
408  // Check the renderpasses in actor's property keys to see if they've changed
409  // render stages:
411 
413  vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
414  vtkStateStorage VBOBuildState; // used for determining when to rebuild the VBO
415  vtkStateStorage IBOBuildState; // used for determining whento rebuild the IBOs
417  vtkStateStorage TempState; // can be used to avoid constant allocs/deallocs
419 
422 
427  int ShiftScaleMethod; // for points
428 
429  // if set to true, tcoords will be passed to the
430  // VBO even if the mapper knows of no texture maps
431  // normally tcoords are only added to the VBO if the
432  // mapper has identified a texture map as well.
434 
435  virtual void BuildCellTextures(
436  vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation);
437 
438  void AppendCellTextures(vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation,
439  std::vector<unsigned char>& colors, std::vector<float>& normals, vtkPolyData* pd,
441 
448 
449  // additional picking indirection
454 
456  {
457  public:
462  };
463  std::map<std::string, ExtraAttributeValue> ExtraAttributes;
464 
465  // Store shader properties on this class by legacy shader replacement functions
466  // This should disappear when the functions are deprecated
467 #ifndef VTK_LEGACY_REMOVE
470 #endif
471 
473 
474  // are we currently drawing spheres/tubes
475  bool DrawingSpheres(vtkOpenGLHelper& cellBO, vtkActor* actor);
476  bool DrawingTubes(vtkOpenGLHelper& cellBO, vtkActor* actor);
478 
479  // get which opengl mode to use to draw the primitive
480  int GetOpenGLMode(int representation, int primType);
481 
482  // get how big to make the points when doing point picking
483  // typically 2 for points, 4 for lines, 6 for surface
484  int GetPointPickingPrimitiveSize(int primType);
485 
486  // used to occasionally invoke timers
487  unsigned int TimerQueryCounter;
488 
489  // stores the mapping from vtk cells to gl_PrimitiveId
491 
492  // compute and set the maximum point and cell ID used in selection
493  virtual void UpdateMaximumPointCellIds(vtkRenderer* ren, vtkActor* actor);
494 
495 private:
497  void operator=(const vtkOpenGLPolyDataMapper&) = delete;
498 };
499 
500 #endif
abstract class specifies interface to map data
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:46
object to represent cell connectivity
Definition: vtkCellArray.h:180
a simple class to control print indentation
Definition: vtkIndent.h:34
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:34
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:36
OpenGL buffer object.
OpenGL rendering utility functions.
PolyDataMapper using OpenGL to render.
void MapDataArrayToMultiTextureAttribute(const char *tname, const char *dataArrayName, int fieldAssociation, int componentno=-1) override
virtual void ReplaceShaderRenderPass(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act, bool prePass)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
virtual void SetLightingShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act)
Set the shader parameteres related to lighting, called by UpdateShader.
virtual char * GetVertexShaderCode()
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources that are being consumed by this mapper.
virtual void ReplaceShaderPrimID(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
virtual std::vector< std::pair< vtkTexture *, std::string > > GetTextures(vtkActor *actor)
virtual void GetShaderTemplate(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Create the basic shaders before replacement.
std::map< const vtkOpenGLHelper *, int > LastLightComplexity
virtual bool GetNeedToRebuildShaders(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act)
Does the shader source need to be recomputed.
bool DrawingTubes(vtkOpenGLHelper &cellBO, vtkActor *actor)
vtkOpenGLBufferObject * CellScalarBuffer
virtual void RenderPieceStart(vtkRenderer *ren, vtkActor *act)
Implemented by sub classes.
void RenderPiece(vtkRenderer *ren, vtkActor *act) override
Implemented by sub classes.
void ComputeBounds() override
Called in GetBounds().
std::string GetTextureCoordinateName(const char *tname)
vtkOpenGLRenderTimer * TimerQuery
virtual void BuildIBO(vtkRenderer *ren, vtkActor *act, vtkPolyData *poly)
Build the IBO, called by BuildBufferObjects.
virtual void ReplaceShaderCustomUniforms(std::map< vtkShader::Type, vtkShader * > shaders, vtkActor *act)
bool DrawingTubesOrSpheres(vtkOpenGLHelper &cellBO, vtkActor *actor)
virtual void ReplaceShaderTCoord(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
std::map< const vtkOpenGLHelper *, vtkTimeStamp > LightComplexityChanged
virtual void UpdateShaders(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act)
Make sure appropriate shaders are defined, compiled and bound.
virtual void ReplaceShaderLight(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
virtual void ReplaceShaderCoincidentOffset(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
vtkTextureObject * CellScalarTexture
virtual void SetCustomUniforms(vtkOpenGLHelper &cellBO, vtkActor *actor)
Set the value of user-defined uniform variables, called by UpdateShader.
virtual void SetCameraShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act)
Set the shader parameteres related to the Camera, called by UpdateShader.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void ReplaceShaderValues(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacements on the shader templates.
virtual bool GetNeedToRebuildBufferObjects(vtkRenderer *ren, vtkActor *act)
Does the VBO/IBO need to be rebuilt.
virtual void SetPropertyShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act)
Set the shader parameteres related to the property, called by UpdateShader.
virtual bool HaveWideLines(vtkRenderer *, vtkActor *)
virtual void BuildShaders(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Build the shader source code, called by UpdateShader.
void AppendCellTextures(vtkRenderer *ren, vtkActor *, vtkCellArray *prims[4], int representation, std::vector< unsigned char > &colors, std::vector< float > &normals, vtkPolyData *pd, vtkOpenGLCellToVTKCellMap *ccmap)
vtkSmartPointer< vtkOpenGLShaderProperty > LegacyShaderProperty
virtual void SetFragmentShaderCode(const char *code)
static vtkOpenGLPolyDataMapper * New()
std::map< const vtkOpenGLHelper *, int > LastLightCount
vtkTextureObject * CellNormalTexture
virtual void SetMapperShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act)
Set the shader parameters related to the mapper/input data, called by UpdateShader.
virtual void UpdateMaximumPointCellIds(vtkRenderer *ren, vtkActor *actor)
bool GetSupportsSelection() override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THIS METHOD OUTSIDE OF THE RENDERI...
bool DrawingSpheres(vtkOpenGLHelper &cellBO, vtkActor *actor)
vtkNew< vtkOpenGLCellToVTKCellMap > CellCellMap
virtual void RenderPieceFinish(vtkRenderer *ren, vtkActor *act)
vtkNew< vtkInformation > LastRenderPassInfo
virtual void ReplaceShaderDepth(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
vtkOpenGLTexture * InternalColorTexture
virtual void ReplaceShaderClip(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
virtual void SetVertexShaderCode(const char *code)
Allow the program to set the shader codes used directly instead of using the built in templates.
int GetPointPickingPrimitiveSize(int primType)
vtkOpenGLBufferObject * CellNormalBuffer
std::map< std::string, ExtraAttributeValue > ExtraAttributes
virtual void RenderPieceDraw(vtkRenderer *ren, vtkActor *act)
vtkOpenGLShaderProperty * GetLegacyShaderProperty()
virtual unsigned int GetNumberOfTextures(vtkActor *actor)
void ProcessSelectorPixelBuffers(vtkHardwareSelector *sel, std::vector< unsigned int > &pixeloffsets, vtkProp *prop) override
allows a mapper to update a selections color buffers Called from a prop which in turn is called from ...
virtual char * GetFragmentShaderCode()
virtual void ReplaceShaderPositionVC(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
void SetVBOShiftScaleMethod(int m)
A convenience method for enabling/disabling the VBO's shift+scale transform.
virtual void ReplaceShaderNormal(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
vtkNew< vtkTransform > VBOInverseTransform
vtkOpenGLVertexBufferObjectGroup * VBOs
void MapDataArray(const char *vertexAttributeName, const char *dataArrayName, const char *texturename, int fieldAssociation, int componentno)
void ClearAllShaderReplacements(vtkShader::Type shaderType)
vtkNew< vtkMatrix4x4 > VBOShiftScale
virtual void BuildBufferObjects(vtkRenderer *ren, vtkActor *act)
Build the VBO/IBO, called by UpdateBufferObjects.
vtkGenericOpenGLResourceFreeCallback * ResourceCallback
void RemoveVertexAttributeMapping(const char *vertexAttributeName) override
Remove a vertex attribute mapping.
virtual void SetGeometryShaderCode(const char *code)
vtkMTimeType GetRenderPassStageMTime(vtkActor *actor)
void MapDataArrayToVertexAttribute(const char *vertexAttributeName, const char *dataArrayName, int fieldAssociation, int componentno=-1) override
Select a data array from the point/cell data and map it to a generic vertex attribute.
virtual void ReplaceShaderPicking(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
void GetCoincidentParameters(vtkRenderer *ren, vtkActor *actor, float &factor, float &offset)
helper function to get the appropriate coincident params
void ShallowCopy(vtkAbstractMapper *m) override
Make a shallow copy of this mapper.
virtual bool HaveTCoords(vtkPolyData *poly)
int GetOpenGLMode(int representation, int primType)
virtual void ReplaceShaderColor(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
virtual char * GetGeometryShaderCode()
void RemoveAllVertexAttributeMappings() override
Remove all vertex attributes.
~vtkOpenGLPolyDataMapper() override
virtual bool HaveTextures(vtkActor *actor)
virtual void UpdateBufferObjects(vtkRenderer *ren, vtkActor *act)
Update the VBO/IBO to be current.
virtual void BuildCellTextures(vtkRenderer *ren, vtkActor *, vtkCellArray *prims[4], int representation)
Asynchronously measures GPU execution time for a single event.
represent GPU shader properties
OpenGL texture map.
manage vertex buffer objects shared within a mapper
represent and manipulate 3D points
Definition: vtkPoints.h:34
map vtkPolyData to graphics primitives
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:85
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:48
abstract specification for renderers
Definition: vtkRenderer.h:59
Type
Available shader types.
Definition: vtkShader.h:46
Class to make storing and comparing state quick and easy.
abstracts an OpenGL texture object.
handles properties associated with a texture map
Definition: vtkTexture.h:66
record modification and/or execution time
Definition: vtkTimeStamp.h:33
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:55
window superclass for vtkRenderWindow
Definition: vtkWindow.h:35
@ offset
Definition: vtkX3D.h:444
@ string
Definition: vtkX3D.h:496
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:293