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:
51  static vtkOpenGLPolyDataMapper* New();
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 
151  void AddShaderReplacement(
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);
157  void ClearShaderReplacement(
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
182  static vtkPolyData *HandleAppleBug(
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 
218  void SetVBOShiftScaleMethod(int m);
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 
238  void GetCoincidentParameters(
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 
258  virtual bool GetNeedToRebuildShaders(
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 
287  virtual void ReplaceShaderRenderPass(
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);
311  virtual void ReplaceShaderPositionVC(
312  std::map<vtkShader::Type, vtkShader *> shaders,
313  vtkRenderer *ren, vtkActor *act);
314  virtual void ReplaceShaderCoincidentOffset(
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 
325  virtual void SetMapperShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
326 
330  virtual void SetLightingShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
331 
335  virtual void SetCameraShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
336 
340  virtual void SetPropertyShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
341 
345  virtual void UpdateBufferObjects(vtkRenderer *ren, vtkActor *act);
346 
350  virtual bool GetNeedToRebuildBufferObjects(vtkRenderer *ren, vtkActor *act);
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:
408  vtkMTimeType GetRenderPassStageMTime(vtkActor *actor);
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 
431  void BuildCellTextures(
432  vtkRenderer *ren,
433  vtkActor *,
434  vtkCellArray *prims[4],
435  int representation);
436 
437  void AppendCellTextures(
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
void ForceHaveAppleBugOn()
Override the normal test for the apple bug.
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
Type
Available shader types.
Definition: vtkShader.h:49
record modification and/or execution time
Definition: vtkTimeStamp.h:35
vtkTextureObject * CellScalarTexture
vtkOpenGLBufferObject * CellNormalBuffer
vtkTextureObject * CellNormalTexture
abstract specification for renderers
Definition: vtkRenderer.h:63
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:60
std::map< const ReplacementSpec, ReplacementValue > UserShaderReplacements
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
vtkOpenGLVertexBufferObject * VBO
vtkTypeUInt64 vtkMTimeType
Definition: vtkType.h:248
bool operator<(const ReplacementSpec &v1) const
vtkSmartPointer< vtkValuePassHelper > ValuePassHelper
Implementation of both rendering modes of vtkValuePass for the vtkOpenGLPolyDataMapper.
std::vector< float > AppleBugPrimIDs
OpenGL texture map.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
bool operator>(const ReplacementSpec &v1) const
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.
virtual void ComputeBounds()
Called in GetBounds().
virtual bool GetSupportsSelection()
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THIS METHOD OUTSIDE OF THE RENDERI...
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.
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
vtkNew< vtkInformation > LastRenderPassInfo
void ForceHaveAppleBugOff()
Override the normal test for the apple bug.
vtkOpenGLBufferObject * AppleBugPrimIDBuffer