VTK
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 "vtkRenderingOpenGL2Module.h" // For export macro
29 #include "vtkNew.h" // for ivars
30 #include "vtkPolyDataMapper.h"
31 #include "vtkShader.h" // for methods
32 #include "vtkOpenGLHelper.h" // used for ivars
33 #include "vtkStateStorage.h" // used for ivars
34 
35 #include <vector> //for ivars
36 #include <map> //for methods
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 
55 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLPolyDataMapper : public vtkPolyDataMapper
56 {
57 public:
58  static vtkOpenGLPolyDataMapper* New();
60  void PrintSelf(ostream& os, vtkIndent indent) override;
61 
65  void RenderPiece(vtkRenderer *ren, vtkActor *act) 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 
136 #ifndef VTK_LEGACY_REMOVE
137 
138 
147  VTK_LEGACY(void AddShaderReplacement(
148  vtkShader::Type shaderType, // vertex, fragment, etc
149  const std::string& originalValue,
150  bool replaceFirst, // do this replacement before the default
151  const std::string& replacementValue,
152  bool replaceAll);)
153  VTK_LEGACY(void ClearShaderReplacement(
154  vtkShader::Type shaderType, // vertex, fragment, etc
155  const std::string& originalValue,
156  bool replaceFirst);)
157  VTK_LEGACY(void ClearAllShaderReplacements(vtkShader::Type shaderType);)
158  VTK_LEGACY(void ClearAllShaderReplacements();)
160 
162 
170  VTK_LEGACY(virtual void SetVertexShaderCode(const char* code);)
171  VTK_LEGACY(virtual char* GetVertexShaderCode();)
172  VTK_LEGACY(virtual void SetFragmentShaderCode(const char* code);)
173  VTK_LEGACY(virtual char* GetFragmentShaderCode();)
174  VTK_LEGACY(virtual void SetGeometryShaderCode(const char* code);)
175  VTK_LEGACY(virtual char* GetGeometryShaderCode();)
177 #endif
178 
182  void ShallowCopy(vtkAbstractMapper *m) override;
183 
185  vtkGetObjectMacro(VBOs, vtkOpenGLVertexBufferObjectGroup);
186 
190  void SetVBOShiftScaleMethod(int m);
191 
193  PrimitiveStart = 0,
194  PrimitivePoints = 0,
201  PrimitiveEnd
202  };
203 
216  const char* vertexAttributeName,
217  const char* dataArrayName,
218  int fieldAssociation,
219  int componentno = -1) override;
220 
221  // This method will Map the specified data array for use as
222  // a texture coordinate for texture tname. The actual
223  // attribute will be named tname_coord so as to not
224  // conflict with the texture sampler definition which will
225  // be tname.
227  const char *tname,
228  const char* dataArrayName, int fieldAssociation, int componentno = -1) override;
229 
233  void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
234 
238  void RemoveAllVertexAttributeMappings() override;
239 
245  std::vector<unsigned int> &pixeloffsets,
246  vtkProp *prop) override;
247 
248 protected:
250  ~vtkOpenGLPolyDataMapper() override;
251 
253 
254  void MapDataArray(
255  const char* vertexAttributeName,
256  const char* dataArrayName,
257  const char *texturename,
258  int fieldAssociation,
259  int componentno);
260 
261  // what coordinate should be used for this texture
262  std::string GetTextureCoordinateName(const char *tname);
263 
267  void GetCoincidentParameters(
268  vtkRenderer *ren, vtkActor *actor, float &factor, float &offset);
269 
275  void ComputeBounds() override;
276 
281  virtual void UpdateShaders(
282  vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
283 
287  virtual bool GetNeedToRebuildShaders(
288  vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
289 
293  virtual void BuildShaders(
294  std::map<vtkShader::Type, vtkShader *> shaders,
295  vtkRenderer *ren, vtkActor *act);
296 
300  virtual void GetShaderTemplate(
301  std::map<vtkShader::Type, vtkShader *> shaders,
302  vtkRenderer *ren, vtkActor *act);
303 
307  virtual void ReplaceShaderValues(
308  std::map<vtkShader::Type, vtkShader *> shaders,
309  vtkRenderer *ren, vtkActor *act);
310 
312 
316  virtual void ReplaceShaderRenderPass(
317  std::map<vtkShader::Type, vtkShader *> shaders,
318  vtkRenderer *ren, vtkActor *act, bool prePass);
319  virtual void ReplaceShaderCustomUniforms(
320  std::map<vtkShader::Type, vtkShader *> shaders,
321  vtkActor *act);
322  virtual void ReplaceShaderColor(
323  std::map<vtkShader::Type, vtkShader *> shaders,
324  vtkRenderer *ren, vtkActor *act);
325  virtual void ReplaceShaderLight(
326  std::map<vtkShader::Type, vtkShader *> shaders,
327  vtkRenderer *ren, vtkActor *act);
328  virtual void ReplaceShaderTCoord(
329  std::map<vtkShader::Type, vtkShader *> shaders,
330  vtkRenderer *ren, vtkActor *act);
331  virtual void ReplaceShaderPicking(
332  std::map<vtkShader::Type, vtkShader *> shaders,
333  vtkRenderer *ren, vtkActor *act);
334  virtual void ReplaceShaderPrimID(
335  std::map<vtkShader::Type, vtkShader *> shaders,
336  vtkRenderer *ren, vtkActor *act);
337  virtual void ReplaceShaderNormal(
338  std::map<vtkShader::Type, vtkShader *> shaders,
339  vtkRenderer *ren, vtkActor *act);
340  virtual void ReplaceShaderClip(
341  std::map<vtkShader::Type, vtkShader *> shaders,
342  vtkRenderer *ren, vtkActor *act);
343  virtual void ReplaceShaderPositionVC(
344  std::map<vtkShader::Type, vtkShader *> shaders,
345  vtkRenderer *ren, vtkActor *act);
346  virtual void ReplaceShaderCoincidentOffset(
347  std::map<vtkShader::Type, vtkShader *> shaders,
348  vtkRenderer *ren, vtkActor *act);
349  virtual void ReplaceShaderDepth(
350  std::map<vtkShader::Type, vtkShader *> shaders,
351  vtkRenderer *ren, vtkActor *act);
353 
357  virtual void SetCustomUniforms( vtkOpenGLHelper & cellBO, vtkActor *actor);
358 
362  virtual void SetMapperShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
363 
367  virtual void SetLightingShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
368 
372  virtual void SetCameraShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
373 
377  virtual void SetPropertyShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
378 
382  virtual void UpdateBufferObjects(vtkRenderer *ren, vtkActor *act);
383 
387  virtual bool GetNeedToRebuildBufferObjects(vtkRenderer *ren, vtkActor *act);
388 
392  virtual void BuildBufferObjects(vtkRenderer *ren, vtkActor *act);
393 
397  virtual void BuildIBO(vtkRenderer *ren, vtkActor *act, vtkPolyData *poly);
398 
399  // The VBO and its layout.
401 
402  // Structures for the various cell types we render.
403  vtkOpenGLHelper Primitives[PrimitiveEnd];
406 
407  // do we have wide lines that require special handling
408  virtual bool HaveWideLines(vtkRenderer *, vtkActor *);
409 
410  // do we have textures that require special handling
411  virtual bool HaveTextures(vtkActor *actor);
412 
413  // how many textures do we have
414  virtual unsigned int GetNumberOfTextures(vtkActor *actor);
415 
416  // populate a vector with the textures we have
417  // the order is always
418  // ColorInternalTexture
419  // Actors texture
420  // Properties textures
421  virtual std::vector<std::pair<vtkTexture *, std::string> > GetTextures(vtkActor *actor);
422 
423  // do we have textures coordinates that require special handling
424  virtual bool HaveTCoords(vtkPolyData *poly);
425 
426  // values we use to determine if we need to rebuild shaders
427  std::map<const vtkOpenGLHelper *, int> LastLightComplexity;
428  std::map<const vtkOpenGLHelper *, int> LastLightCount;
429  std::map<const vtkOpenGLHelper *, vtkTimeStamp> LightComplexityChanged;
430 
433 
434  // Caches the vtkOpenGLRenderPass::RenderPasses() information.
435  // Note: Do not dereference the pointers held by this object. There is no
436  // guarantee that they are still valid!
438 
439  // Check the renderpasses in actor's property keys to see if they've changed
440  // render stages:
441  vtkMTimeType GetRenderPassStageMTime(vtkActor *actor);
442 
444  vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
445  vtkStateStorage VBOBuildState; // used for determining when to rebuild the VBO
446  vtkStateStorage IBOBuildState; // used for determining whento rebuild the IBOs
448  vtkStateStorage TempState; // can be used to avoid constant allocs/deallocs
450 
453 
458  int ShiftScaleMethod; // for points
459 
460  // if set to true, tcoords will be passed to the
461  // VBO even if the mapper knows of no texture maps
462  // normally tcoords are only added to the VBO if the
463  // mapper has identified a texture map as well.
465 
466  virtual void BuildCellTextures(
467  vtkRenderer *ren,
468  vtkActor *,
469  vtkCellArray *prims[4],
470  int representation);
471 
472  void AppendCellTextures(
473  vtkRenderer *ren,
474  vtkActor *,
475  vtkCellArray *prims[4],
476  int representation,
477  std::vector<unsigned char> &colors,
478  std::vector<float> &normals,
479  vtkPolyData *pd,
481 
488 
489  // additional picking indirection
494 
496  {
497  public:
502  };
503  std::map<std::string,ExtraAttributeValue> ExtraAttributes;
504 
505  // Store shader properties on this class by legacy shader replacement functions
506  // This should disappear when the functions are deprecated
507 #ifndef VTK_LEGACY_REMOVE
508  vtkOpenGLShaderProperty * GetLegacyShaderProperty();
510 #endif
511 
513 
514  // are we currently drawing spheres/tubes
515  bool DrawingSpheres(vtkOpenGLHelper &cellBO, vtkActor *actor);
516  bool DrawingTubes(vtkOpenGLHelper &cellBO, vtkActor *actor);
517  bool DrawingTubesOrSpheres(vtkOpenGLHelper &cellBO, vtkActor *actor);
518 
519  // get which opengl mode to use to draw the primitive
520  int GetOpenGLMode(int representation, int primType);
521 
522  // get how big to make the points when doing point picking
523  // typically 2 for points, 4 for lines, 6 for surface
524  int GetPointPickingPrimitiveSize(int primType);
525 
526  // used to occasionally invoke timers
527  unsigned int TimerQueryCounter;
528 
529  // stores the mapping from vtk cells to gl_PrimitiveId
531 
532  // compute and set the maximum point and cell ID used in selection
533  virtual void UpdateMaximumPointCellIds(vtkRenderer* ren, vtkActor *actor);
534 
535 private:
537  void operator=(const vtkOpenGLPolyDataMapper&) = delete;
538 };
539 
540 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:50
std::map< std::string, ExtraAttributeValue > ExtraAttributes
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:51
vtkOpenGLBufferObject * CellScalarBuffer
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:41
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:304
Type
Available shader types.
Definition: vtkShader.h:45
record modification and/or execution time
Definition: vtkTimeStamp.h:35
vtkNew< vtkOpenGLCellToVTKCellMap > CellCellMap
vtkTextureObject * CellScalarTexture
vtkOpenGLBufferObject * CellNormalBuffer
vtkTextureObject * CellNormalTexture
OpenGL rendering utility functions.
abstract specification for renderers
Definition: vtkRenderer.h:64
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:60
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:497
represent GPU shader properties
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:34
vtkOpenGLVertexBufferObjectGroup * VBOs
a simple class to control print indentation
Definition: vtkIndent.h:39
std::map< const vtkOpenGLHelper *, vtkTimeStamp > LightComplexityChanged
vtkNew< vtkMatrix4x4 > VBOShiftScale
handles properties associated with a texture map
Definition: vtkTexture.h:71
vtkOpenGLRenderTimer * TimerQuery
virtual void ComputeBounds()
Called in GetBounds().
abstract class specifies interface to map data
std::map< const vtkOpenGLHelper *, int > LastLightComplexity
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:50
vtkGenericOpenGLResourceFreeCallback * ResourceCallback
vtkNew< vtkTransform > VBOInverseTransform
vtkSmartPointer< vtkOpenGLShaderProperty > LegacyShaderProperty
static vtkPolyDataMapper * New()
OpenGL buffer object.
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:36
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:39
std::map< const vtkOpenGLHelper *, int > LastLightCount