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 =========================================================================*/
24 #ifndef vtkOpenGLPolyDataMapper_h
25 #define vtkOpenGLPolyDataMapper_h
26 
27 #include "vtkNew.h" // For vtkNew
28 #include "vtkNew.h" // for ivars
29 #include "vtkOpenGLHelper.h" // used for ivars
30 #include "vtkPolyDataMapper.h"
31 #include "vtkRenderingOpenGL2Module.h" // For export macro
32 #include "vtkShader.h" // for methods
33 #include "vtkStateStorage.h" // used for ivars
34 
35 #include <map> //for methods
36 #include <vector> //for ivars
37 
38 class vtkCellArray;
40 class vtkMatrix4x4;
41 class vtkMatrix3x3;
44 class vtkOpenGLTexture;
48 class vtkPoints;
49 class vtkTexture;
50 class vtkTextureObject;
51 class vtkTransform;
53 
54 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLPolyDataMapper : public vtkPolyDataMapper
55 {
56 public:
57  static vtkOpenGLPolyDataMapper* New();
59  void PrintSelf(ostream& os, vtkIndent indent) override;
60 
64  void RenderPiece(vtkRenderer* ren, vtkActor* act) override;
65 
67 
70  virtual void RenderPieceStart(vtkRenderer* ren, vtkActor* act);
71  virtual void RenderPieceDraw(vtkRenderer* ren, vtkActor* act);
72  virtual void RenderPieceFinish(vtkRenderer* ren, vtkActor* act);
74 
80  void ReleaseGraphicsResources(vtkWindow*) override;
81 
82  vtkGetMacro(PopulateSelectionSettings, int);
83  void SetPopulateSelectionSettings(int v) { this->PopulateSelectionSettings = v; }
84 
91  bool GetSupportsSelection() override { return true; }
92 
93  // used by RenderPiece and functions it calls to reduce
94  // calls to get the input and allow for rendering of
95  // other polydata (not the input)
97 
99 
105  vtkSetStringMacro(PointIdArrayName);
106  vtkGetStringMacro(PointIdArrayName);
107  vtkSetStringMacro(CellIdArrayName);
108  vtkGetStringMacro(CellIdArrayName);
110 
112 
117  vtkSetStringMacro(ProcessIdArrayName);
118  vtkGetStringMacro(ProcessIdArrayName);
120 
122 
131  vtkSetStringMacro(CompositeIdArrayName);
132  vtkGetStringMacro(CompositeIdArrayName);
134 
135 #ifndef VTK_LEGACY_REMOVE
136 
137 
147  VTK_LEGACY(void AddShaderReplacement(vtkShader::Type shaderType, // vertex, fragment, etc
148  const std::string& originalValue,
149  bool replaceFirst, // do this replacement before the default
150  const std::string& replacementValue, bool replaceAll);)
151  VTK_LEGACY(void ClearShaderReplacement(vtkShader::Type shaderType, // vertex, fragment, etc
152  const std::string& originalValue, bool replaceFirst);)
153  VTK_LEGACY(void ClearAllShaderReplacements(vtkShader::Type shaderType);)
154  VTK_LEGACY(void ClearAllShaderReplacements();)
156 
158 
166  VTK_LEGACY(virtual void SetVertexShaderCode(const char* code);)
167  VTK_LEGACY(virtual char* GetVertexShaderCode();)
168  VTK_LEGACY(virtual void SetFragmentShaderCode(const char* code);)
169  VTK_LEGACY(virtual char* GetFragmentShaderCode();)
170  VTK_LEGACY(virtual void SetGeometryShaderCode(const char* code);)
171  VTK_LEGACY(virtual char* GetGeometryShaderCode();)
173 #endif
174 
178  void ShallowCopy(vtkAbstractMapper* m) override;
179 
181  vtkGetObjectMacro(VBOs, vtkOpenGLVertexBufferObjectGroup);
182 
186  void SetVBOShiftScaleMethod(int m);
187 
189  {
190  PrimitiveStart = 0,
191  PrimitivePoints = 0,
198  PrimitiveEnd
199  };
200 
212  void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
213  int fieldAssociation, int componentno = -1) override;
214 
215  // This method will Map the specified data array for use as
216  // a texture coordinate for texture tname. The actual
217  // attribute will be named tname_coord so as to not
218  // conflict with the texture sampler definition which will
219  // be tname.
220  void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
221  int fieldAssociation, int componentno = -1) override;
222 
226  void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
227 
231  void RemoveAllVertexAttributeMappings() override;
232 
238  vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
239 
240 protected:
242  ~vtkOpenGLPolyDataMapper() override;
243 
245 
246  void MapDataArray(const char* vertexAttributeName, const char* dataArrayName,
247  const char* texturename, int fieldAssociation, int componentno);
248 
249  // what coordinate should be used for this texture
250  std::string GetTextureCoordinateName(const char* tname);
251 
255  void GetCoincidentParameters(vtkRenderer* ren, vtkActor* actor, float& factor, float& offset);
256 
262  void ComputeBounds() override;
263 
268  virtual void UpdateShaders(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
269 
273  virtual bool GetNeedToRebuildShaders(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
274 
278  virtual void BuildShaders(
279  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
280 
284  virtual void GetShaderTemplate(
285  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
286 
290  virtual void ReplaceShaderValues(
291  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
292 
294 
298  virtual void ReplaceShaderRenderPass(
299  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act, bool prePass);
300  virtual void ReplaceShaderCustomUniforms(
301  std::map<vtkShader::Type, vtkShader*> shaders, vtkActor* act);
302  virtual void ReplaceShaderColor(
303  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
304  virtual void ReplaceShaderLight(
305  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
306  virtual void ReplaceShaderTCoord(
307  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
308  virtual void ReplaceShaderPicking(
309  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
310  virtual void ReplaceShaderPrimID(
311  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
312  virtual void ReplaceShaderNormal(
313  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
314  virtual void ReplaceShaderClip(
315  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
316  virtual void ReplaceShaderPositionVC(
317  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
318  virtual void ReplaceShaderCoincidentOffset(
319  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
320  virtual void ReplaceShaderDepth(
321  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
323 
327  virtual void SetCustomUniforms(vtkOpenGLHelper& cellBO, vtkActor* actor);
328 
332  virtual void SetMapperShaderParameters(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
333 
337  virtual void SetLightingShaderParameters(
338  vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
339 
343  virtual void SetCameraShaderParameters(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
344 
348  virtual void SetPropertyShaderParameters(
349  vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
350 
354  virtual void UpdateBufferObjects(vtkRenderer* ren, vtkActor* act);
355 
359  virtual bool GetNeedToRebuildBufferObjects(vtkRenderer* ren, vtkActor* act);
360 
364  virtual void BuildBufferObjects(vtkRenderer* ren, vtkActor* act);
365 
369  virtual void BuildIBO(vtkRenderer* ren, vtkActor* act, vtkPolyData* poly);
370 
371  // The VBO and its layout.
373 
374  // Structures for the various cell types we render.
375  vtkOpenGLHelper Primitives[PrimitiveEnd];
378 
379  // do we have wide lines that require special handling
380  virtual bool HaveWideLines(vtkRenderer*, vtkActor*);
381 
382  // do we have textures that require special handling
383  virtual bool HaveTextures(vtkActor* actor);
384 
385  // how many textures do we have
386  virtual unsigned int GetNumberOfTextures(vtkActor* actor);
387 
388  // populate a vector with the textures we have
389  // the order is always
390  // ColorInternalTexture
391  // Actors texture
392  // Properties textures
393  virtual std::vector<std::pair<vtkTexture*, std::string> > GetTextures(vtkActor* actor);
394 
395  // do we have textures coordinates that require special handling
396  virtual bool HaveTCoords(vtkPolyData* poly);
397 
398  // values we use to determine if we need to rebuild shaders
399  std::map<const vtkOpenGLHelper*, int> LastLightComplexity;
400  std::map<const vtkOpenGLHelper*, int> LastLightCount;
401  std::map<const vtkOpenGLHelper*, vtkTimeStamp> LightComplexityChanged;
402 
405 
406  // Caches the vtkOpenGLRenderPass::RenderPasses() information.
407  // Note: Do not dereference the pointers held by this object. There is no
408  // guarantee that they are still valid!
410 
411  // Check the renderpasses in actor's property keys to see if they've changed
412  // render stages:
413  vtkMTimeType GetRenderPassStageMTime(vtkActor* actor);
414 
416  vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
417  vtkStateStorage VBOBuildState; // used for determining when to rebuild the VBO
418  vtkStateStorage IBOBuildState; // used for determining whento rebuild the IBOs
420  vtkStateStorage TempState; // can be used to avoid constant allocs/deallocs
422 
425 
430  int ShiftScaleMethod; // for points
431 
432  // if set to true, tcoords will be passed to the
433  // VBO even if the mapper knows of no texture maps
434  // normally tcoords are only added to the VBO if the
435  // mapper has identified a texture map as well.
437 
438  virtual void BuildCellTextures(
439  vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation);
440 
441  void AppendCellTextures(vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation,
442  std::vector<unsigned char>& colors, std::vector<float>& normals, vtkPolyData* pd,
444 
451 
452  // additional picking indirection
457 
459  {
460  public:
465  };
466  std::map<std::string, ExtraAttributeValue> ExtraAttributes;
467 
468  // Store shader properties on this class by legacy shader replacement functions
469  // This should disappear when the functions are deprecated
470 #ifndef VTK_LEGACY_REMOVE
471  vtkOpenGLShaderProperty* GetLegacyShaderProperty();
473 #endif
474 
476 
477  // are we currently drawing spheres/tubes
478  bool DrawingSpheres(vtkOpenGLHelper& cellBO, vtkActor* actor);
479  bool DrawingTubes(vtkOpenGLHelper& cellBO, vtkActor* actor);
480  bool DrawingTubesOrSpheres(vtkOpenGLHelper& cellBO, vtkActor* actor);
481 
482  // get which opengl mode to use to draw the primitive
483  int GetOpenGLMode(int representation, int primType);
484 
485  // get how big to make the points when doing point picking
486  // typically 2 for points, 4 for lines, 6 for surface
487  int GetPointPickingPrimitiveSize(int primType);
488 
489  // used to occasionally invoke timers
490  unsigned int TimerQueryCounter;
491 
492  // stores the mapping from vtk cells to gl_PrimitiveId
494 
495  // compute and set the maximum point and cell ID used in selection
496  virtual void UpdateMaximumPointCellIds(vtkRenderer* ren, vtkActor* actor);
497 
498 private:
500  void operator=(const vtkOpenGLPolyDataMapper&) = delete;
501 };
502 
503 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:50
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:45
vtkOpenGLBufferObject * CellScalarBuffer
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:35
std::map< const vtkOpenGLHelper *, int > LastLightComplexity
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:293
Type
Available shader types.
Definition: vtkShader.h:45
record modification and/or execution time
Definition: vtkTimeStamp.h:32
vtkNew< vtkOpenGLCellToVTKCellMap > CellCellMap
vtkTextureObject * CellScalarTexture
vtkOpenGLBufferObject * CellNormalBuffer
vtkTextureObject * CellNormalTexture
OpenGL rendering utility functions.
std::map< const vtkOpenGLHelper *, vtkTimeStamp > LightComplexityChanged
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:54
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:470
represent GPU shader properties
std::map< std::string, ExtraAttributeValue > ExtraAttributes
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:84
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:37
vtkOpenGLVertexBufferObjectGroup * VBOs
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkNew< vtkMatrix4x4 > VBOShiftScale
handles properties associated with a texture map
Definition: vtkTexture.h:65
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.
std::map< const vtkOpenGLHelper *, int > LastLightCount
map vtkPolyData to graphics primitives
object to represent cell connectivity
Definition: vtkCellArray.h:179
vtkGenericOpenGLResourceFreeCallback * ResourceCallback
vtkNew< vtkTransform > VBOInverseTransform
vtkSmartPointer< vtkOpenGLShaderProperty > LegacyShaderProperty
static vtkPolyDataMapper * New()
OpenGL buffer object.
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:33
manage vertex buffer objects shared within a mapper
vtkOpenGLTexture * InternalColorTexture
vtkNew< vtkInformation > LastRenderPassInfo
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:33
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources that are being consumed by this mapper.
Definition: vtkMapper.h:108