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;
35 class vtkMatrix4x4;
36 class vtkMatrix3x3;
37 class vtkOpenGLTexture;
40 class vtkTextureObject;
41 class vtkTransform;
43 class vtkValuePassHelper;
44 
45 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLPolyDataMapper : public vtkPolyDataMapper
46 {
47 public:
48  static vtkOpenGLPolyDataMapper* New();
50  void PrintSelf(ostream& os, vtkIndent indent);
51 
55  virtual void RenderPiece(vtkRenderer *ren, vtkActor *act);
56 
58 
61  virtual void RenderPieceStart(vtkRenderer *ren, vtkActor *act);
62  virtual void RenderPieceDraw(vtkRenderer *ren, vtkActor *act);
63  virtual void RenderPieceFinish(vtkRenderer *ren, vtkActor *act);
64  virtual void RenderEdges(vtkRenderer *ren, vtkActor *act);
66 
73 
74  vtkGetMacro(PopulateSelectionSettings,int);
75  void SetPopulateSelectionSettings(int v) { this->PopulateSelectionSettings = v; };
76 
83  virtual bool GetSupportsSelection() { return true; }
84 
95  virtual bool GetIsOpaque();
96 
97  // used by RenderPiece and functions it calls to reduce
98  // calls to get the input and allow for rendering of
99  // other polydata (not the input)
101 
103 
109  vtkSetStringMacro(PointIdArrayName);
110  vtkGetStringMacro(PointIdArrayName);
111  vtkSetStringMacro(CellIdArrayName);
112  vtkGetStringMacro(CellIdArrayName);
114 
116 
121  vtkSetStringMacro(ProcessIdArrayName);
122  vtkGetStringMacro(ProcessIdArrayName);
124 
126 
135  vtkSetStringMacro(CompositeIdArrayName);
136  vtkGetStringMacro(CompositeIdArrayName);
138 
139 
141 
148  void AddShaderReplacement(
149  vtkShader::Type shaderType, // vertex, fragment, etc
150  std::string originalValue,
151  bool replaceFirst, // do this replacement before the default
152  std::string replacementValue,
153  bool replaceAll);
154  void ClearShaderReplacement(
155  vtkShader::Type shaderType, // vertex, fragment, etc
156  std::string originalValue,
157  bool replaceFirst);
159 
161 
167  vtkSetStringMacro(VertexShaderCode);
168  vtkGetStringMacro(VertexShaderCode);
169  vtkSetStringMacro(FragmentShaderCode);
170  vtkGetStringMacro(FragmentShaderCode);
171  vtkSetStringMacro(GeometryShaderCode);
172  vtkGetStringMacro(GeometryShaderCode);
174 
175  // the following is all extra stuff to work around the
176  // fact that gl_PrimitiveID does not work correctly on
177  // Apple devices with AMD graphics hardware. See apple
178  // bug ID 20747550
179  static vtkPolyData *HandleAppleBug(
180  vtkPolyData *poly,
181  std::vector<float> &buffData);
182 
187 
189 
193  {
194  this->HaveAppleBugForce = 1;
195  this->Modified();
196  }
198  {
199  this->HaveAppleBugForce = 2;
200  this->Modified();
201  }
203 
207  bool GetHaveAppleBug() { return this->HaveAppleBug; }
208 
210  vtkGetObjectMacro(VBO,vtkOpenGLVertexBufferObject);
211 
215  void SetVBOShiftScaleMethod(int m);
216 
217 protected:
220 
222 
223  // the following is all extra stuff to work around the
224  // fact that gl_PrimitiveID does not work correctly on
225  // Apple devices with AMD graphics hardware. See apple
226  // bug ID 20747550
228  int HaveAppleBugForce; // 0 = default 1 = 0ff 2 = on
229  std::vector<float> AppleBugPrimIDs;
231 
235  void GetCoincidentParameters(
236  vtkRenderer *ren, vtkActor *actor, float &factor, float &offset);
237 
243  virtual void ComputeBounds();
244 
249  virtual void UpdateShaders(
250  vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
251 
255  virtual bool GetNeedToRebuildShaders(
256  vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
257 
261  virtual void BuildShaders(
262  std::map<vtkShader::Type, vtkShader *> shaders,
263  vtkRenderer *ren, vtkActor *act);
264 
268  virtual void GetShaderTemplate(
269  std::map<vtkShader::Type, vtkShader *> shaders,
270  vtkRenderer *ren, vtkActor *act);
271 
275  virtual void ReplaceShaderValues(
276  std::map<vtkShader::Type, vtkShader *> shaders,
277  vtkRenderer *ren, vtkActor *act);
278 
280 
284  virtual void ReplaceShaderRenderPass(
285  std::map<vtkShader::Type, vtkShader *> shaders,
286  vtkRenderer *ren, vtkActor *act);
287  virtual void ReplaceShaderColor(
288  std::map<vtkShader::Type, vtkShader *> shaders,
289  vtkRenderer *ren, vtkActor *act);
290  virtual void ReplaceShaderLight(
291  std::map<vtkShader::Type, vtkShader *> shaders,
292  vtkRenderer *ren, vtkActor *act);
293  virtual void ReplaceShaderTCoord(
294  std::map<vtkShader::Type, vtkShader *> shaders,
295  vtkRenderer *ren, vtkActor *act);
296  virtual void ReplaceShaderPicking(
297  std::map<vtkShader::Type, vtkShader *> shaders,
298  vtkRenderer *ren, vtkActor *act);
299  virtual void ReplaceShaderPrimID(
300  std::map<vtkShader::Type, vtkShader *> shaders,
301  vtkRenderer *ren, vtkActor *act);
302  virtual void ReplaceShaderNormal(
303  std::map<vtkShader::Type, vtkShader *> shaders,
304  vtkRenderer *ren, vtkActor *act);
305  virtual void ReplaceShaderClip(
306  std::map<vtkShader::Type, vtkShader *> shaders,
307  vtkRenderer *ren, vtkActor *act);
308  virtual void ReplaceShaderPositionVC(
309  std::map<vtkShader::Type, vtkShader *> shaders,
310  vtkRenderer *ren, vtkActor *act);
311  virtual void ReplaceShaderCoincidentOffset(
312  std::map<vtkShader::Type, vtkShader *> shaders,
313  vtkRenderer *ren, vtkActor *act);
314  virtual void ReplaceShaderDepth(
315  std::map<vtkShader::Type, vtkShader *> shaders,
316  vtkRenderer *ren, vtkActor *act);
318 
322  virtual void SetMapperShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
323 
327  virtual void SetLightingShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
328 
332  virtual void SetCameraShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
333 
337  virtual void SetPropertyShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
338 
342  virtual void UpdateBufferObjects(vtkRenderer *ren, vtkActor *act);
343 
347  virtual bool GetNeedToRebuildBufferObjects(vtkRenderer *ren, vtkActor *act);
348 
352  virtual void BuildBufferObjects(vtkRenderer *ren, vtkActor *act);
353 
357  virtual void BuildIBO(vtkRenderer *ren, vtkActor *act, vtkPolyData *poly);
358 
359  // The VBO and its layout.
361 
362  // Structures for the various cell types we render.
371 
372  // do we have wide lines that require special handling
373  virtual bool HaveWideLines(vtkRenderer *, vtkActor *);
374 
375  // do we have textures that require special handling
376  virtual bool HaveTextures(vtkActor *actor);
377 
378  // how many textures do we have
379  virtual unsigned int GetNumberOfTextures(vtkActor *actor);
380 
381  // populate a vector with the textures we have
382  // the order is always
383  // ColorInternalTexture
384  // Actors texture
385  // Properies textures
386  virtual std::vector<vtkTexture *> GetTextures(vtkActor *actor);
387 
388  // do we have textures coordinates that require special handling
389  virtual bool HaveTCoords(vtkPolyData *poly);
390 
391  // values we use to determine if we need to rebuild shaders
392  std::map<const vtkOpenGLHelper *, int> LastLightComplexity;
393  std::map<const vtkOpenGLHelper *, vtkTimeStamp> LightComplexityChanged;
394 
397 
398  // Caches the vtkOpenGLRenderPass::RenderPasses() information.
399  // Note: Do not dereference the pointers held by this object. There is no
400  // guarantee that they are still valid!
402 
403  // Check the renderpasses in actor's property keys to see if they've changed
404  // render stages:
405  vtkMTimeType GetRenderPassStageMTime(vtkActor *actor);
406 
408  vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
409  std::string VBOBuildString; // used for determining whento rebuild the VBO
410  std::string IBOBuildString; // used for determining whento rebuild the IBOs
412  vtkOpenGLTexture* InternalColorTexture;
413 
416 
421 
422  // if set to true, tcoords will be passed to the
423  // VBO even if the mapper knows of no texture maps
424  // normally tcoords are only added to the VBO if the
425  // mapper has indentified a texture map as well.
427 
428  void BuildCellTextures(
429  vtkRenderer *ren,
430  vtkActor *,
431  vtkCellArray *prims[4],
432  int representation);
433 
434  void AppendCellTextures(
435  vtkRenderer *ren,
436  vtkActor *,
437  vtkCellArray *prims[4],
438  int representation,
439  std::vector<unsigned char> &colors,
440  std::vector<float> &normals,
441  vtkPolyData *pd);
442 
450 
451  // aditional picking indirection
456 
458  {
459  public:
463  bool operator<(const ReplacementSpec &v1) const
464  {
465  if (this->OriginalValue != v1.OriginalValue) { return this->OriginalValue < v1.OriginalValue; }
466  if (this->ShaderType != v1.ShaderType) { return this->ShaderType < v1.ShaderType; }
467  return (this->ReplaceFirst < v1.ReplaceFirst);
468  }
469  bool operator>(const ReplacementSpec &v1) const
470  {
471  if (this->OriginalValue != v1.OriginalValue) { return this->OriginalValue > v1.OriginalValue; }
472  if (this->ShaderType != v1.ShaderType) { return this->ShaderType > v1.ShaderType; }
473  return (this->ReplaceFirst > v1.ReplaceFirst);
474  }
475  };
477  {
478  public:
481  };
482 
483  std::map<const ReplacementSpec,ReplacementValue> UserShaderReplacements;
484 
488  unsigned int TimerQuery;
489 
490 #if GL_ES_VERSION_2_0 != 1 && GL_ES_VERSION_3_0 != 1
492 #endif
493 
494  // are we currently drawing spheres/tubes
495  bool DrawingSpheres(vtkOpenGLHelper &cellBO, vtkActor *actor);
496  bool DrawingTubes(vtkOpenGLHelper &cellBO, vtkActor *actor);
497 
498 private:
499  vtkOpenGLPolyDataMapper(const vtkOpenGLPolyDataMapper&) VTK_DELETE_FUNCTION;
500  void operator=(const vtkOpenGLPolyDataMapper&) VTK_DELETE_FUNCTION;
501 };
502 
503 #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
virtual void ReleaseGraphicsResources(vtkWindow *)
Release any graphics resources that are being consumed by this mapper.
Definition: vtkMapper.h:119
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
virtual void RenderPiece(vtkRenderer *ren, vtkActor *act)=0
Implemented by sub classes.
vtkOpenGLVertexBufferObject * VBO
vtkTypeUInt64 vtkMTimeType
Definition: vtkType.h:248
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:34
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.
bool operator>(const ReplacementSpec &v1) const
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.
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
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