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 =========================================================================*/
21 #ifndef vtkOpenGLPolyDataMapper_h
22 #define vtkOpenGLPolyDataMapper_h
23 
24 #include "vtkNew.h" // For vtkNew
25 #include "vtkRenderingOpenGL2Module.h" // For export macro
26 #include "vtkNew.h" // for ivars
27 #include "vtkPolyDataMapper.h"
28 #include "vtkShader.h" // for methods
29 #include "vtkOpenGLHelper.h" // used for ivars
30 
31 #include <vector> //for ivars
32 #include <map> //for methods
33 
34 class vtkCellArray;
36 class vtkMatrix4x4;
37 class vtkMatrix3x3;
39 class vtkOpenGLTexture;
43 class vtkPoints;
44 class vtkTextureObject;
45 class vtkTransform;
46 
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 
61 
64  virtual void RenderPieceStart(vtkRenderer *ren, vtkActor *act);
65  virtual void RenderPieceDraw(vtkRenderer *ren, vtkActor *act);
66  virtual void RenderPieceFinish(vtkRenderer *ren, vtkActor *act);
68 
74  void ReleaseGraphicsResources(vtkWindow *) override;
75 
76  vtkGetMacro(PopulateSelectionSettings,int);
77  void SetPopulateSelectionSettings(int v) { this->PopulateSelectionSettings = v; };
78 
85  bool GetSupportsSelection() override { return true; }
86 
97  bool GetIsOpaque() override;
98 
99  // used by RenderPiece and functions it calls to reduce
100  // calls to get the input and allow for rendering of
101  // other polydata (not the input)
103 
105 
111  vtkSetStringMacro(PointIdArrayName);
112  vtkGetStringMacro(PointIdArrayName);
113  vtkSetStringMacro(CellIdArrayName);
114  vtkGetStringMacro(CellIdArrayName);
116 
118 
123  vtkSetStringMacro(ProcessIdArrayName);
124  vtkGetStringMacro(ProcessIdArrayName);
126 
128 
137  vtkSetStringMacro(CompositeIdArrayName);
138  vtkGetStringMacro(CompositeIdArrayName);
140 
141 
143 
150  void AddShaderReplacement(
151  vtkShader::Type shaderType, // vertex, fragment, etc
152  const std::string& originalValue,
153  bool replaceFirst, // do this replacement before the default
154  const std::string& replacementValue,
155  bool replaceAll);
156  void ClearShaderReplacement(
157  vtkShader::Type shaderType, // vertex, fragment, etc
158  const std::string& originalValue,
159  bool replaceFirst);
161 
163 
169  vtkSetStringMacro(VertexShaderCode);
170  vtkGetStringMacro(VertexShaderCode);
171  vtkSetStringMacro(FragmentShaderCode);
172  vtkGetStringMacro(FragmentShaderCode);
173  vtkSetStringMacro(GeometryShaderCode);
174  vtkGetStringMacro(GeometryShaderCode);
176 
177  // the following is all extra stuff to work around the
178  // fact that gl_PrimitiveID does not work correctly on
179  // Apple devices with AMD graphics hardware. See apple
180  // bug ID 20747550
181  static vtkPolyData *HandleAppleBug(
182  vtkPolyData *poly,
183  std::vector<float> &buffData);
184 
189 
191 
195  {
196  this->HaveAppleBugForce = 1;
197  this->Modified();
198  }
200  {
201  this->HaveAppleBugForce = 2;
202  this->Modified();
203  }
205 
209  bool GetHaveAppleBug() { return this->HaveAppleBug; }
210 
212  vtkGetObjectMacro(VBOs, vtkOpenGLVertexBufferObjectGroup);
213 
217  void SetVBOShiftScaleMethod(int m);
218 
220  PrimitiveStart = 0,
221  PrimitivePoints = 0,
228  PrimitiveEnd
229  };
230 
234  static void MakeCellCellMap(std::vector<vtkIdType> &CellCellMap,
235  bool HaveAppleBug,
236  vtkPolyData *poly,
237  vtkCellArray **prims, int representation,
238  vtkPoints *points);
239 
252  const char* vertexAttributeName,
253  const char* dataArrayName,
254  int fieldAssociation,
255  int componentno = -1) override;
256 
260  void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
261 
265  void RemoveAllVertexAttributeMappings() override;
266 
267 protected:
269  ~vtkOpenGLPolyDataMapper() override;
270 
272 
273  // the following is all extra stuff to work around the
274  // fact that gl_PrimitiveID does not work correctly on
275  // Apple devices with AMD graphics hardware. See apple
276  // bug ID 20747550
278  int HaveAppleBugForce; // 0 = default 1 = 0ff 2 = on
279  std::vector<float> AppleBugPrimIDs;
281 
285  void GetCoincidentParameters(
286  vtkRenderer *ren, vtkActor *actor, float &factor, float &offset);
287 
293  void ComputeBounds() override;
294 
299  virtual void UpdateShaders(
300  vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
301 
305  virtual bool GetNeedToRebuildShaders(
306  vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
307 
311  virtual void BuildShaders(
312  std::map<vtkShader::Type, vtkShader *> shaders,
313  vtkRenderer *ren, vtkActor *act);
314 
318  virtual void GetShaderTemplate(
319  std::map<vtkShader::Type, vtkShader *> shaders,
320  vtkRenderer *ren, vtkActor *act);
321 
325  virtual void ReplaceShaderValues(
326  std::map<vtkShader::Type, vtkShader *> shaders,
327  vtkRenderer *ren, vtkActor *act);
328 
330 
334  virtual void ReplaceShaderRenderPass(
335  std::map<vtkShader::Type, vtkShader *> shaders,
336  vtkRenderer *ren, vtkActor *act, bool prePass);
337  virtual void ReplaceShaderColor(
338  std::map<vtkShader::Type, vtkShader *> shaders,
339  vtkRenderer *ren, vtkActor *act);
340  virtual void ReplaceShaderLight(
341  std::map<vtkShader::Type, vtkShader *> shaders,
342  vtkRenderer *ren, vtkActor *act);
343  virtual void ReplaceShaderTCoord(
344  std::map<vtkShader::Type, vtkShader *> shaders,
345  vtkRenderer *ren, vtkActor *act);
346  virtual void ReplaceShaderPicking(
347  std::map<vtkShader::Type, vtkShader *> shaders,
348  vtkRenderer *ren, vtkActor *act);
349  virtual void ReplaceShaderPrimID(
350  std::map<vtkShader::Type, vtkShader *> shaders,
351  vtkRenderer *ren, vtkActor *act);
352  virtual void ReplaceShaderNormal(
353  std::map<vtkShader::Type, vtkShader *> shaders,
354  vtkRenderer *ren, vtkActor *act);
355  virtual void ReplaceShaderClip(
356  std::map<vtkShader::Type, vtkShader *> shaders,
357  vtkRenderer *ren, vtkActor *act);
358  virtual void ReplaceShaderPositionVC(
359  std::map<vtkShader::Type, vtkShader *> shaders,
360  vtkRenderer *ren, vtkActor *act);
361  virtual void ReplaceShaderCoincidentOffset(
362  std::map<vtkShader::Type, vtkShader *> shaders,
363  vtkRenderer *ren, vtkActor *act);
364  virtual void ReplaceShaderDepth(
365  std::map<vtkShader::Type, vtkShader *> shaders,
366  vtkRenderer *ren, vtkActor *act);
368 
372  virtual void SetMapperShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
373 
377  virtual void SetLightingShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
378 
382  virtual void SetCameraShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
383 
387  virtual void SetPropertyShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
388 
392  virtual void UpdateBufferObjects(vtkRenderer *ren, vtkActor *act);
393 
397  virtual bool GetNeedToRebuildBufferObjects(vtkRenderer *ren, vtkActor *act);
398 
402  virtual void BuildBufferObjects(vtkRenderer *ren, vtkActor *act);
403 
407  virtual void BuildIBO(vtkRenderer *ren, vtkActor *act, vtkPolyData *poly);
408 
409  // The VBO and its layout.
411 
412  // Structures for the various cell types we render.
413  vtkOpenGLHelper Primitives[PrimitiveEnd];
416 
417  // do we have wide lines that require special handling
418  virtual bool HaveWideLines(vtkRenderer *, vtkActor *);
419 
420  // do we have textures that require special handling
421  virtual bool HaveTextures(vtkActor *actor);
422 
423  // how many textures do we have
424  virtual unsigned int GetNumberOfTextures(vtkActor *actor);
425 
426  // populate a vector with the textures we have
427  // the order is always
428  // ColorInternalTexture
429  // Actors texture
430  // Properies textures
431  virtual std::vector<vtkTexture *> GetTextures(vtkActor *actor);
432 
433  // do we have textures coordinates that require special handling
434  virtual bool HaveTCoords(vtkPolyData *poly);
435 
436  // values we use to determine if we need to rebuild shaders
437  std::map<const vtkOpenGLHelper *, int> LastLightComplexity;
438  std::map<const vtkOpenGLHelper *, int> LastLightCount;
439  std::map<const vtkOpenGLHelper *, vtkTimeStamp> LightComplexityChanged;
440 
443 
444  // Caches the vtkOpenGLRenderPass::RenderPasses() information.
445  // Note: Do not dereference the pointers held by this object. There is no
446  // guarantee that they are still valid!
448 
449  // Check the renderpasses in actor's property keys to see if they've changed
450  // render stages:
451  vtkMTimeType GetRenderPassStageMTime(vtkActor *actor);
452 
454  vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
455  std::string VBOBuildString; // used for determining whento rebuild the VBO
456  std::string IBOBuildString; // used for determining whento rebuild the IBOs
458  vtkOpenGLTexture* InternalColorTexture;
459 
462 
467  int ShiftScaleMethod; // for points
468 
469  // if set to true, tcoords will be passed to the
470  // VBO even if the mapper knows of no texture maps
471  // normally tcoords are only added to the VBO if the
472  // mapper has indentified a texture map as well.
474 
475  void BuildCellTextures(
476  vtkRenderer *ren,
477  vtkActor *,
478  vtkCellArray *prims[4],
479  int representation);
480 
481  void AppendCellTextures(
482  vtkRenderer *ren,
483  vtkActor *,
484  vtkCellArray *prims[4],
485  int representation,
486  std::vector<unsigned char> &colors,
487  std::vector<float> &normals,
488  vtkPolyData *pd);
489 
497 
498  // aditional picking indirection
503 
504  std::map<const vtkShader::ReplacementSpec, vtkShader::ReplacementValue>
506 
508  {
509  public:
513  };
514  std::map<std::string,ExtraAttributeValue> ExtraAttributes;
515 
520 
521  // are we currently drawing spheres/tubes
522  bool DrawingSpheres(vtkOpenGLHelper &cellBO, vtkActor *actor);
523  bool DrawingTubes(vtkOpenGLHelper &cellBO, vtkActor *actor);
524  bool DrawingTubesOrSpheres(vtkOpenGLHelper &cellBO, vtkActor *actor);
525 
526  // get which opengl mode to use to draw the primitive
527  int GetOpenGLMode(int representation, int primType);
528 
529  // get how big to make the points when doing point picking
530  // typically 2 for points, 4 for lines, 6 for surface
531  int GetPointPickingPrimitiveSize(int primType);
532 
533  // a map from drawn triangles back to containing cell id
534  std::vector<unsigned int> CellCellMap;
535 
536 private:
538  void operator=(const vtkOpenGLPolyDataMapper&) = delete;
539 };
540 
541 #endif
void ForceHaveAppleBugOn()
Override the normal test for the apple bug.
std::map< std::string, ExtraAttributeValue > ExtraAttributes
a PolyDataMapper for the OpenGL library
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 RemoveAllVertexAttributeMappings()
Remove all vertex attributes.
std::vector< unsigned int > CellCellMap
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:300
Type
Available shader types.
Definition: vtkShader.h:48
record modification and/or execution time
Definition: vtkTimeStamp.h:35
vtkTextureObject * CellScalarTexture
vtkOpenGLBufferObject * CellNormalBuffer
vtkTextureObject * CellNormalTexture
abstract specification for renderers
Definition: vtkRenderer.h:63
std::map< const vtkShader::ReplacementSpec, vtkShader::ReplacementValue > UserShaderReplacements
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:60
virtual bool GetIsOpaque()
Returns if the mapper does not expect to have translucent geometry.
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:85
virtual void RenderPiece(vtkRenderer *ren, vtkActor *act)=0
Implemented by sub classes.
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...
std::vector< float > AppleBugPrimIDs
OpenGL texture map.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
vtkOpenGLVertexBufferObjectGroup * VBOs
a simple class to control print indentation
Definition: vtkIndent.h:39
std::map< const vtkOpenGLHelper *, vtkTimeStamp > LightComplexityChanged
vtkNew< vtkMatrix4x4 > VBOShiftScale
vtkGetStringMacro(ExtensionsString)
Returns a string listing all available extensions.
virtual void Modified()
Update the modification time for this object.
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
void ShallowCopy(vtkAbstractMapper *m)
Make a shallow copy of this mapper.
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
bool GetHaveAppleBug()
Get the value of HaveAppleBug.
static vtkPolyDataMapper * New()
OpenGL buffer object.
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:36
manage vertex buffer objects shared within a mapper
vtkNew< vtkInformation > LastRenderPassInfo
Asynchronously measures GPU execution time for a single event.
represent and manipulate 3D points
Definition: vtkPoints.h:39
std::map< const vtkOpenGLHelper *, int > LastLightCount
void ForceHaveAppleBugOff()
Override the normal test for the apple bug.
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources that are being consumed by this mapper.
Definition: vtkMapper.h:111
vtkOpenGLBufferObject * AppleBugPrimIDBuffer