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 
34 #include <vector> //for ivars
35 #include <map> //for methods
36 
37 class vtkCellArray;
38 class vtkMatrix4x4;
39 class vtkMatrix3x3;
40 class vtkOpenGLTexture;
43 class vtkTextureObject;
44 class vtkTransform;
46 class vtkValuePassHelper;
47 
48 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLPolyDataMapper : public vtkPolyDataMapper
49 {
50 public:
53  void PrintSelf(ostream& os, vtkIndent indent);
54 
58  virtual void RenderPiece(vtkRenderer *ren, vtkActor *act);
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);
67  virtual void RenderEdges(vtkRenderer *ren, vtkActor *act);
69 
75  void ReleaseGraphicsResources(vtkWindow *);
76 
77  vtkGetMacro(PopulateSelectionSettings,int);
78  void SetPopulateSelectionSettings(int v) { this->PopulateSelectionSettings = v; };
79 
86  virtual bool GetSupportsSelection() { return true; }
87 
98  virtual bool GetIsOpaque();
99 
100  // used by RenderPiece and functions it calls to reduce
101  // calls to get the input and allow for rendering of
102  // other polydata (not the input)
104 
106 
112  vtkSetStringMacro(PointIdArrayName);
113  vtkGetStringMacro(PointIdArrayName);
114  vtkSetStringMacro(CellIdArrayName);
115  vtkGetStringMacro(CellIdArrayName);
117 
119 
124  vtkSetStringMacro(ProcessIdArrayName);
125  vtkGetStringMacro(ProcessIdArrayName);
127 
129 
138  vtkSetStringMacro(CompositeIdArrayName);
139  vtkGetStringMacro(CompositeIdArrayName);
141 
142 
144 
152  vtkShader::Type shaderType, // vertex, fragment, etc
153  std::string originalValue,
154  bool replaceFirst, // do this replacement before the default
155  std::string replacementValue,
156  bool replaceAll);
158  vtkShader::Type shaderType, // vertex, fragment, etc
159  std::string originalValue,
160  bool replaceFirst);
162 
164 
170  vtkSetStringMacro(VertexShaderCode);
171  vtkGetStringMacro(VertexShaderCode);
172  vtkSetStringMacro(FragmentShaderCode);
173  vtkGetStringMacro(FragmentShaderCode);
174  vtkSetStringMacro(GeometryShaderCode);
175  vtkGetStringMacro(GeometryShaderCode);
177 
178  // the following is all extra stuff to work around the
179  // fact that gl_PrimitiveID does not work correctly on
180  // Apple devices with AMD graphics hardware. See apple
181  // bug ID 20747550
183  vtkPolyData *poly,
184  std::vector<float> &buffData);
185 
190 
192 
196  {
197  this->HaveAppleBugForce = 1;
198  this->Modified();
199  }
201  {
202  this->HaveAppleBugForce = 2;
203  this->Modified();
204  }
206 
210  bool GetHaveAppleBug() { return this->HaveAppleBug; }
211 
213  vtkGetObjectMacro(VBO,vtkOpenGLVertexBufferObject);
214 
219 
220 protected:
223 
225 
226  // the following is all extra stuff to work around the
227  // fact that gl_PrimitiveID does not work correctly on
228  // Apple devices with AMD graphics hardware. See apple
229  // bug ID 20747550
231  int HaveAppleBugForce; // 0 = default 1 = 0ff 2 = on
232  std::vector<float> AppleBugPrimIDs;
234 
239  vtkRenderer *ren, vtkActor *actor, float &factor, float &offset);
240 
246  virtual void ComputeBounds();
247 
252  virtual void UpdateShaders(
253  vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
254 
259  vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
260 
264  virtual void BuildShaders(
265  std::map<vtkShader::Type, vtkShader *> shaders,
266  vtkRenderer *ren, vtkActor *act);
267 
271  virtual void GetShaderTemplate(
272  std::map<vtkShader::Type, vtkShader *> shaders,
273  vtkRenderer *ren, vtkActor *act);
274 
278  virtual void ReplaceShaderValues(
279  std::map<vtkShader::Type, vtkShader *> shaders,
280  vtkRenderer *ren, vtkActor *act);
281 
283 
288  std::map<vtkShader::Type, vtkShader *> shaders,
289  vtkRenderer *ren, vtkActor *act);
290  virtual void ReplaceShaderColor(
291  std::map<vtkShader::Type, vtkShader *> shaders,
292  vtkRenderer *ren, vtkActor *act);
293  virtual void ReplaceShaderLight(
294  std::map<vtkShader::Type, vtkShader *> shaders,
295  vtkRenderer *ren, vtkActor *act);
296  virtual void ReplaceShaderTCoord(
297  std::map<vtkShader::Type, vtkShader *> shaders,
298  vtkRenderer *ren, vtkActor *act);
299  virtual void ReplaceShaderPicking(
300  std::map<vtkShader::Type, vtkShader *> shaders,
301  vtkRenderer *ren, vtkActor *act);
302  virtual void ReplaceShaderPrimID(
303  std::map<vtkShader::Type, vtkShader *> shaders,
304  vtkRenderer *ren, vtkActor *act);
305  virtual void ReplaceShaderNormal(
306  std::map<vtkShader::Type, vtkShader *> shaders,
307  vtkRenderer *ren, vtkActor *act);
308  virtual void ReplaceShaderClip(
309  std::map<vtkShader::Type, vtkShader *> shaders,
310  vtkRenderer *ren, vtkActor *act);
312  std::map<vtkShader::Type, vtkShader *> shaders,
313  vtkRenderer *ren, vtkActor *act);
315  std::map<vtkShader::Type, vtkShader *> shaders,
316  vtkRenderer *ren, vtkActor *act);
317  virtual void ReplaceShaderDepth(
318  std::map<vtkShader::Type, vtkShader *> shaders,
319  vtkRenderer *ren, vtkActor *act);
321 
326 
331 
336 
341 
345  virtual void UpdateBufferObjects(vtkRenderer *ren, vtkActor *act);
346 
351 
355  virtual void BuildBufferObjects(vtkRenderer *ren, vtkActor *act);
356 
360  virtual void BuildIBO(vtkRenderer *ren, vtkActor *act, vtkPolyData *poly);
361 
362  // The VBO and its layout.
364 
365  // Structures for the various cell types we render.
374 
375  // do we have wide lines that require special handling
376  virtual bool HaveWideLines(vtkRenderer *, vtkActor *);
377 
378  // do we have textures that require special handling
379  virtual bool HaveTextures(vtkActor *actor);
380 
381  // how many textures do we have
382  virtual unsigned int GetNumberOfTextures(vtkActor *actor);
383 
384  // populate a vector with the textures we have
385  // the order is always
386  // ColorInternalTexture
387  // Actors texture
388  // Properies textures
389  virtual std::vector<vtkTexture *> GetTextures(vtkActor *actor);
390 
391  // do we have textures coordinates that require special handling
392  virtual bool HaveTCoords(vtkPolyData *poly);
393 
394  // values we use to determine if we need to rebuild shaders
395  std::map<const vtkOpenGLHelper *, int> LastLightComplexity;
396  std::map<const vtkOpenGLHelper *, vtkTimeStamp> LightComplexityChanged;
397 
400 
401  // Caches the vtkOpenGLRenderPass::RenderPasses() information.
402  // Note: Do not dereference the pointers held by this object. There is no
403  // guarantee that they are still valid!
405 
406  // Check the renderpasses in actor's property keys to see if they've changed
407  // render stages:
409 
411  vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
412  std::string VBOBuildString; // used for determining whento rebuild the VBO
413  std::string IBOBuildString; // used for determining whento rebuild the IBOs
415  vtkOpenGLTexture* InternalColorTexture;
416 
419 
424 
425  // if set to true, tcoords will be passed to the
426  // VBO even if the mapper knows of no texture maps
427  // normally tcoords are only added to the VBO if the
428  // mapper has indentified a texture map as well.
430 
432  vtkRenderer *ren,
433  vtkActor *,
434  vtkCellArray *prims[4],
435  int representation);
436 
438  vtkRenderer *ren,
439  vtkActor *,
440  vtkCellArray *prims[4],
441  int representation,
442  std::vector<unsigned char> &colors,
443  std::vector<float> &normals,
444  vtkPolyData *pd);
445 
453 
454  // aditional picking indirection
459 
461  {
462  public:
466  bool operator<(const ReplacementSpec &v1) const
467  {
468  if (this->OriginalValue != v1.OriginalValue) { return this->OriginalValue < v1.OriginalValue; }
469  if (this->ShaderType != v1.ShaderType) { return this->ShaderType < v1.ShaderType; }
470  return (this->ReplaceFirst < v1.ReplaceFirst);
471  }
472  bool operator>(const ReplacementSpec &v1) const
473  {
474  if (this->OriginalValue != v1.OriginalValue) { return this->OriginalValue > v1.OriginalValue; }
475  if (this->ShaderType != v1.ShaderType) { return this->ShaderType > v1.ShaderType; }
476  return (this->ReplaceFirst > v1.ReplaceFirst);
477  }
478  };
480  {
481  public:
484  };
485 
486  std::map<const ReplacementSpec,ReplacementValue> UserShaderReplacements;
487 
491  unsigned int TimerQuery;
492 
493 #if GL_ES_VERSION_2_0 != 1 && GL_ES_VERSION_3_0 != 1
495 #endif
496 
497  // are we currently drawing spheres/tubes
498  bool DrawingSpheres(vtkOpenGLHelper &cellBO, vtkActor *actor);
499  bool DrawingTubes(vtkOpenGLHelper &cellBO, vtkActor *actor);
500 
501 private:
502  vtkOpenGLPolyDataMapper(const vtkOpenGLPolyDataMapper&) VTK_DELETE_FUNCTION;
503  void operator=(const vtkOpenGLPolyDataMapper&) VTK_DELETE_FUNCTION;
504 };
505 
506 #endif
abstract class specifies interface to map data
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:52
object to represent cell connectivity
Definition: vtkCellArray.h:51
a simple class to control print indentation
Definition: vtkIndent.h:40
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:37
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:42
virtual void Modified()
Update the modification time for this object.
OpenGL buffer object.
bool operator<(const ReplacementSpec &v1) const
bool operator>(const ReplacementSpec &v1) const
a PolyDataMapper for the OpenGL library
std::map< const vtkOpenGLHelper *, int > LastLightComplexity
virtual void SetLightingShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act)
Set the shader parameteres related to lighting, called by UpdateShader.
void AddShaderReplacement(vtkShader::Type shaderType, std::string originalValue, bool replaceFirst, std::string replacementValue, bool replaceAll)
This function enables you to apply your own substitutions to the shader creation process.
virtual void ReplaceShaderPrimID(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
virtual void GetShaderTemplate(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Create the basic shaders before replacement.
vtkOpenGLVertexBufferObject * VBO
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
std::map< const vtkOpenGLHelper *, vtkTimeStamp > LightComplexityChanged
virtual void BuildIBO(vtkRenderer *ren, vtkActor *act, vtkPolyData *poly)
Build the IBO, called by BuildBufferObjects.
virtual void ReplaceShaderTCoord(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
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 SetCameraShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act)
Set the shader parameteres related to the Camera, called by UpdateShader.
virtual void ReplaceShaderValues(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacments 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.
vtkSmartPointer< vtkValuePassHelper > ValuePassHelper
static vtkOpenGLPolyDataMapper * New()
void BuildCellTextures(vtkRenderer *ren, vtkActor *, vtkCellArray *prims[4], int representation)
void ClearShaderReplacement(vtkShader::Type shaderType, std::string originalValue, bool replaceFirst)
vtkTextureObject * CellNormalTexture
virtual void SetMapperShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act)
Set the shader parameters related to the mapper/input data, called by UpdateShader.
void AppendCellTextures(vtkRenderer *ren, vtkActor *, vtkCellArray *prims[4], int representation, std::vector< unsigned char > &colors, std::vector< float > &normals, vtkPolyData *pd)
bool DrawingSpheres(vtkOpenGLHelper &cellBO, vtkActor *actor)
std::vector< float > AppleBugPrimIDs
void ShallowCopy(vtkAbstractMapper *m)
Make a shallow copy of this mapper.
vtkNew< vtkInformation > LastRenderPassInfo
virtual void ReplaceShaderDepth(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
virtual void ReplaceShaderClip(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
virtual bool GetIsOpaque()
Returns if the mapper does not expect to have translucent geometry.
vtkOpenGLBufferObject * CellNormalBuffer
void ForceHaveAppleBugOff()
Override the normal test for the apple bug.
std::map< const ReplacementSpec, ReplacementValue > UserShaderReplacements
virtual unsigned int GetNumberOfTextures(vtkActor *actor)
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.
vtkOpenGLBufferObject * AppleBugPrimIDBuffer
virtual void ComputeBounds()
Called in GetBounds().
static vtkPolyData * HandleAppleBug(vtkPolyData *poly, std::vector< float > &buffData)
virtual void ReplaceShaderNormal(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
vtkNew< vtkTransform > VBOInverseTransform
vtkNew< vtkMatrix4x4 > VBOShiftScale
virtual void BuildBufferObjects(vtkRenderer *ren, vtkActor *act)
Build the VBO/IBO, called by UpdateBufferObjects.
virtual void ReplaceShaderRenderPass(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacments on the shader templates, called from ReplaceShaderValues.
virtual bool GetSupportsSelection()
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THIS METHOD OUTSIDE OF THE RENDERI...
vtkGenericOpenGLResourceFreeCallback * ResourceCallback
virtual std::vector< vtkTexture * > GetTextures(vtkActor *actor)
bool GetHaveAppleBug()
Get the value of HaveAppleBug.
vtkMTimeType GetRenderPassStageMTime(vtkActor *actor)
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
virtual bool HaveTCoords(vtkPolyData *poly)
virtual void ReplaceShaderColor(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
virtual bool HaveTextures(vtkActor *actor)
virtual void UpdateBufferObjects(vtkRenderer *ren, vtkActor *act)
Update the VBO/IBO to be current.
OpenGL texture map.
map vtkPolyData to graphics primitives
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:86
abstract specification for renderers
Definition: vtkRenderer.h:64
Type
Available shader types.
Definition: vtkShader.h:49
abstracts an OpenGL texture object.
record modification and/or execution time
Definition: vtkTimeStamp.h:36
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:61
Implementation of both rendering modes of vtkValuePass for the vtkOpenGLPolyDataMapper.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:35
@ offset
Definition: vtkX3D.h:438
@ string
Definition: vtkX3D.h:490
vtkGetStringMacro(ExtensionsString)
Returns a string listing all available extensions.
vtkTypeUInt64 vtkMTimeType
Definition: vtkType.h:248