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);
68 
74  void ReleaseGraphicsResources(vtkWindow *);
75 
76  vtkGetMacro(PopulateSelectionSettings,int);
77  void SetPopulateSelectionSettings(int v) { this->PopulateSelectionSettings = v; };
78 
85  virtual bool GetSupportsSelection() { return true; }
86 
97  virtual bool GetIsOpaque();
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  std::string originalValue,
153  bool replaceFirst, // do this replacement before the default
154  std::string replacementValue,
155  bool replaceAll);
156  void ClearShaderReplacement(
157  vtkShader::Type shaderType, // vertex, fragment, etc
158  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(VBO,vtkOpenGLVertexBufferObject);
213 
217  void SetVBOShiftScaleMethod(int m);
218 
220  PrimitiveStart = 0,
221  PrimitivePoints = 0,
228  PrimitiveEnd
229  };
230 
231 protected:
234 
236 
237  // the following is all extra stuff to work around the
238  // fact that gl_PrimitiveID does not work correctly on
239  // Apple devices with AMD graphics hardware. See apple
240  // bug ID 20747550
242  int HaveAppleBugForce; // 0 = default 1 = 0ff 2 = on
243  std::vector<float> AppleBugPrimIDs;
245 
249  void GetCoincidentParameters(
250  vtkRenderer *ren, vtkActor *actor, float &factor, float &offset);
251 
257  virtual void ComputeBounds();
258 
263  virtual void UpdateShaders(
264  vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
265 
269  virtual bool GetNeedToRebuildShaders(
270  vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
271 
275  virtual void BuildShaders(
276  std::map<vtkShader::Type, vtkShader *> shaders,
277  vtkRenderer *ren, vtkActor *act);
278 
282  virtual void GetShaderTemplate(
283  std::map<vtkShader::Type, vtkShader *> shaders,
284  vtkRenderer *ren, vtkActor *act);
285 
289  virtual void ReplaceShaderValues(
290  std::map<vtkShader::Type, vtkShader *> shaders,
291  vtkRenderer *ren, vtkActor *act);
292 
294 
298  virtual void ReplaceShaderRenderPass(
299  std::map<vtkShader::Type, vtkShader *> shaders,
300  vtkRenderer *ren, vtkActor *act);
301  virtual void ReplaceShaderColor(
302  std::map<vtkShader::Type, vtkShader *> shaders,
303  vtkRenderer *ren, vtkActor *act);
304  virtual void ReplaceShaderLight(
305  std::map<vtkShader::Type, vtkShader *> shaders,
306  vtkRenderer *ren, vtkActor *act);
307  virtual void ReplaceShaderTCoord(
308  std::map<vtkShader::Type, vtkShader *> shaders,
309  vtkRenderer *ren, vtkActor *act);
310  virtual void ReplaceShaderPicking(
311  std::map<vtkShader::Type, vtkShader *> shaders,
312  vtkRenderer *ren, vtkActor *act);
313  virtual void ReplaceShaderPrimID(
314  std::map<vtkShader::Type, vtkShader *> shaders,
315  vtkRenderer *ren, vtkActor *act);
316  virtual void ReplaceShaderNormal(
317  std::map<vtkShader::Type, vtkShader *> shaders,
318  vtkRenderer *ren, vtkActor *act);
319  virtual void ReplaceShaderClip(
320  std::map<vtkShader::Type, vtkShader *> shaders,
321  vtkRenderer *ren, vtkActor *act);
322  virtual void ReplaceShaderPositionVC(
323  std::map<vtkShader::Type, vtkShader *> shaders,
324  vtkRenderer *ren, vtkActor *act);
325  virtual void ReplaceShaderCoincidentOffset(
326  std::map<vtkShader::Type, vtkShader *> shaders,
327  vtkRenderer *ren, vtkActor *act);
328  virtual void ReplaceShaderDepth(
329  std::map<vtkShader::Type, vtkShader *> shaders,
330  vtkRenderer *ren, vtkActor *act);
332 
336  virtual void SetMapperShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
337 
341  virtual void SetLightingShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
342 
346  virtual void SetCameraShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
347 
351  virtual void SetPropertyShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
352 
356  virtual void UpdateBufferObjects(vtkRenderer *ren, vtkActor *act);
357 
361  virtual bool GetNeedToRebuildBufferObjects(vtkRenderer *ren, vtkActor *act);
362 
366  virtual void BuildBufferObjects(vtkRenderer *ren, vtkActor *act);
367 
371  virtual void BuildIBO(vtkRenderer *ren, vtkActor *act, vtkPolyData *poly);
372 
373  // The VBO and its layout.
375 
376  // Structures for the various cell types we render.
377  vtkOpenGLHelper Primitives[PrimitiveEnd];
380 
381  // do we have wide lines that require special handling
382  virtual bool HaveWideLines(vtkRenderer *, vtkActor *);
383 
384  // do we have textures that require special handling
385  virtual bool HaveTextures(vtkActor *actor);
386 
387  // how many textures do we have
388  virtual unsigned int GetNumberOfTextures(vtkActor *actor);
389 
390  // populate a vector with the textures we have
391  // the order is always
392  // ColorInternalTexture
393  // Actors texture
394  // Properies textures
395  virtual std::vector<vtkTexture *> GetTextures(vtkActor *actor);
396 
397  // do we have textures coordinates that require special handling
398  virtual bool HaveTCoords(vtkPolyData *poly);
399 
400  // values we use to determine if we need to rebuild shaders
401  std::map<const vtkOpenGLHelper *, int> LastLightComplexity;
402  std::map<const vtkOpenGLHelper *, vtkTimeStamp> LightComplexityChanged;
403 
406 
407  // Caches the vtkOpenGLRenderPass::RenderPasses() information.
408  // Note: Do not dereference the pointers held by this object. There is no
409  // guarantee that they are still valid!
411 
412  // Check the renderpasses in actor's property keys to see if they've changed
413  // render stages:
414  vtkMTimeType GetRenderPassStageMTime(vtkActor *actor);
415 
417  vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
418  std::string VBOBuildString; // used for determining whento rebuild the VBO
419  std::string IBOBuildString; // used for determining whento rebuild the IBOs
421  vtkOpenGLTexture* InternalColorTexture;
422 
425 
430 
431  // if set to true, tcoords will be passed to the
432  // VBO even if the mapper knows of no texture maps
433  // normally tcoords are only added to the VBO if the
434  // mapper has indentified a texture map as well.
436 
437  void BuildCellTextures(
438  vtkRenderer *ren,
439  vtkActor *,
440  vtkCellArray *prims[4],
441  int representation);
442 
443  void AppendCellTextures(
444  vtkRenderer *ren,
445  vtkActor *,
446  vtkCellArray *prims[4],
447  int representation,
448  std::vector<unsigned char> &colors,
449  std::vector<float> &normals,
450  vtkPolyData *pd);
451 
459 
460  // aditional picking indirection
465 
467  {
468  public:
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  bool operator>(const ReplacementSpec &v1) const
479  {
480  if (this->OriginalValue != v1.OriginalValue) { return this->OriginalValue > v1.OriginalValue; }
481  if (this->ShaderType != v1.ShaderType) { return this->ShaderType > v1.ShaderType; }
482  return (this->ReplaceFirst > v1.ReplaceFirst);
483  }
484  };
486  {
487  public:
490  };
491 
492  std::map<const ReplacementSpec,ReplacementValue> UserShaderReplacements;
493 
497  unsigned int TimerQuery;
498 
499 #if GL_ES_VERSION_3_0 != 1
501 #endif
502 
503  // are we currently drawing spheres/tubes
504  bool DrawingSpheres(vtkOpenGLHelper &cellBO, vtkActor *actor);
505  bool DrawingTubes(vtkOpenGLHelper &cellBO, vtkActor *actor);
506 
507  // get why opengl mode to use to draw the primitive
508  int GetOpenGLMode(int representation, int primType);
509 
510  // get how big to make the points when doing point picking
511  // typically 2 for points, 4 for lines, 6 for surface
512  int GetPointPickingPrimitiveSize(int primType);
513 
514 private:
515  vtkOpenGLPolyDataMapper(const vtkOpenGLPolyDataMapper&) VTK_DELETE_FUNCTION;
516  void operator=(const vtkOpenGLPolyDataMapper&) VTK_DELETE_FUNCTION;
517 };
518 
519 #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