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 =========================================================================*/
23 #ifndef vtkOpenGLPolyDataMapper_h
24 #define vtkOpenGLPolyDataMapper_h
25 
26 #include "vtkRenderingOpenGL2Module.h" // For export macro
27 #include "vtkPolyDataMapper.h"
28 #include "vtkShader.h" // for methods
29 #include "vtkOpenGLHelper.h" // used for ivars
30 #include <vector> //for ivars
31 #include <map> //for methods
32 
33 class vtkCellArray;
34 class vtkMatrix4x4;
35 class vtkMatrix3x3;
36 class vtkOpenGLTexture;
39 class vtkTextureObject;
40 
42 {
43 public:
44  static vtkOpenGLPolyDataMapper* New();
46  void PrintSelf(ostream& os, vtkIndent indent);
47 
49  virtual void RenderPiece(vtkRenderer *ren, vtkActor *act);
50 
52 
53  virtual void RenderPieceStart(vtkRenderer *ren, vtkActor *act);
54  virtual void RenderPieceDraw(vtkRenderer *ren, vtkActor *act);
55  virtual void RenderPieceFinish(vtkRenderer *ren, vtkActor *act);
56  virtual void RenderEdges(vtkRenderer *ren, vtkActor *act);
58 
62  void ReleaseGraphicsResources(vtkWindow *);
63 
64  vtkGetMacro(PopulateSelectionSettings,int);
65  void SetPopulateSelectionSettings(int v) { this->PopulateSelectionSettings = v; };
66 
71  virtual bool GetSupportsSelection() { return true; }
72 
81  virtual bool GetIsOpaque();
82 
83  // used by RenderPiece and functions it calls to reduce
84  // calls to get the input and allow for rendering of
85  // other polydata (not the input)
87 
89 
93  vtkSetStringMacro(PointIdArrayName);
94  vtkGetStringMacro(PointIdArrayName);
95  vtkSetStringMacro(CellIdArrayName);
96  vtkGetStringMacro(CellIdArrayName);
98 
100 
103  vtkSetStringMacro(ProcessIdArrayName);
104  vtkGetStringMacro(ProcessIdArrayName);
106 
108 
115  vtkSetStringMacro(CompositeIdArrayName);
116  vtkGetStringMacro(CompositeIdArrayName);
118 
119 
121 
126  void AddShaderReplacement(
127  vtkShader::Type shaderType, // vertex, fragment, etc
128  std::string originalValue,
129  bool replaceFirst, // do this replacement before the default
130  std::string replacementValue,
131  bool replaceAll);
132  void ClearShaderReplacement(
133  vtkShader::Type shaderType, // vertex, fragment, etc
134  std::string originalValue,
135  bool replaceFirst);
137 
139 
142  vtkSetStringMacro(VertexShaderCode);
143  vtkGetStringMacro(VertexShaderCode);
144  vtkSetStringMacro(FragmentShaderCode);
145  vtkGetStringMacro(FragmentShaderCode);
146  vtkSetStringMacro(GeometryShaderCode);
147  vtkGetStringMacro(GeometryShaderCode);
149 
150  // the following is all extra stuff to work around the
151  // fact that gl_PrimitiveID does not work correctly on
152  // Apple devices with AMD graphics hardware. See apple
153  // bug ID 20747550
154  static vtkPolyData *HandleAppleBug(
155  vtkPolyData *poly,
156  std::vector<float> &buffData);
157 
160 
161 
162 protected:
165 
166  // the following is all extra stuff to work around the
167  // fact that gl_PrimitiveID does not work correctly on
168  // Apple devices with AMD graphics hardware. See apple
169  // bug ID 20747550
171  std::vector<float> AppleBugPrimIDs;
173 
175  void GetCoincidentParameters(vtkActor *actor, float &factor, float &offset);
176 
181  virtual void ComputeBounds();
182 
184 
187  virtual void UpdateShaders(
188  vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
190 
192 
193  virtual bool GetNeedToRebuildShaders(
194  vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
196 
198 
199  virtual void BuildShaders(
200  std::map<vtkShader::Type, vtkShader *> shaders,
201  vtkRenderer *ren, vtkActor *act);
203 
205 
206  virtual void GetShaderTemplate(
207  std::map<vtkShader::Type, vtkShader *> shaders,
208  vtkRenderer *ren, vtkActor *act);
210 
212 
213  virtual void ReplaceShaderValues(
214  std::map<vtkShader::Type, vtkShader *> shaders,
215  vtkRenderer *ren, vtkActor *act);
217 
219 
221  virtual void ReplaceShaderColor(
222  std::map<vtkShader::Type, vtkShader *> shaders,
223  vtkRenderer *ren, vtkActor *act);
224  virtual void ReplaceShaderLight(
225  std::map<vtkShader::Type, vtkShader *> shaders,
226  vtkRenderer *ren, vtkActor *act);
227  virtual void ReplaceShaderTCoord(
228  std::map<vtkShader::Type, vtkShader *> shaders,
229  vtkRenderer *ren, vtkActor *act);
230  virtual void ReplaceShaderPicking(
231  std::map<vtkShader::Type, vtkShader *> shaders,
232  vtkRenderer *ren, vtkActor *act);
233  virtual void ReplaceShaderDepthPeeling(
234  std::map<vtkShader::Type, vtkShader *> shaders,
235  vtkRenderer *ren, vtkActor *act);
236  virtual void ReplaceShaderPrimID(
237  std::map<vtkShader::Type, vtkShader *> shaders,
238  vtkRenderer *ren, vtkActor *act);
239  virtual void ReplaceShaderNormal(
240  std::map<vtkShader::Type, vtkShader *> shaders,
241  vtkRenderer *ren, vtkActor *act);
242  virtual void ReplaceShaderClip(
243  std::map<vtkShader::Type, vtkShader *> shaders,
244  vtkRenderer *ren, vtkActor *act);
245  virtual void ReplaceShaderPositionVC(
246  std::map<vtkShader::Type, vtkShader *> shaders,
247  vtkRenderer *ren, vtkActor *act);
248  virtual void ReplaceShaderCoincidentOffset(
249  std::map<vtkShader::Type, vtkShader *> shaders,
250  vtkRenderer *ren, vtkActor *act);
252 
255  virtual void SetMapperShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
256 
259  virtual void SetLightingShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
260 
263  virtual void SetCameraShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
264 
267  virtual void SetPropertyShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
268 
270  virtual void UpdateBufferObjects(vtkRenderer *ren, vtkActor *act);
271 
273  virtual bool GetNeedToRebuildBufferObjects(vtkRenderer *ren, vtkActor *act);
274 
276  virtual void BuildBufferObjects(vtkRenderer *ren, vtkActor *act);
277 
279  virtual void BuildIBO(vtkRenderer *ren, vtkActor *act, vtkPolyData *poly);
280 
281  // The VBO and its layout.
283 
284  // Structures for the various cell types we render.
293 
294  // do we have wide lines that require special handling
295  virtual bool HaveWideLines(vtkRenderer *, vtkActor *);
296 
297  // values we use to determine if we need to rebuild shaders
298  std::map<const vtkOpenGLHelper *, int> LastLightComplexity;
299  std::map<const vtkOpenGLHelper *, vtkTimeStamp> LightComplexityChanged;
300 
303 
306 
308  vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
309  std::string VBOBuildString; // used for determining whento rebuild the VBO
310  std::string IBOBuildString; // used for determining whento rebuild the IBOs
311  vtkOpenGLTexture* InternalColorTexture;
312 
315 
318 
319  // if set to true, tcoords will be passed to the
320  // VBO even if the mapper knows of no texture maps
321  // normally tcoords are only added to the VBO if the
322  // mapper has indentified a texture map as well.
324 
325  void BuildCellTextures(
326  vtkRenderer *ren,
327  vtkActor *,
328  vtkCellArray *prims[4],
329  int representation);
330 
331  void AppendCellTextures(
332  vtkRenderer *ren,
333  vtkActor *,
334  vtkCellArray *prims[4],
335  int representation,
336  std::vector<unsigned char> &colors,
337  std::vector<float> &normals,
338  vtkPolyData *pd);
339 
347 
348  // aditional picking indirection
353 
355 
357  {
358  public:
362  bool operator<(const ReplacementSpec &v1) const
363  {
364  if (this->OriginalValue != v1.OriginalValue) { return this->OriginalValue < v1.OriginalValue; }
365  if (this->ShaderType != v1.ShaderType) { return this->ShaderType < v1.ShaderType; }
366  return (this->ReplaceFirst < v1.ReplaceFirst);
367  }
368  bool operator>(const ReplacementSpec &v1) const
369  {
370  if (this->OriginalValue != v1.OriginalValue) { return this->OriginalValue > v1.OriginalValue; }
371  if (this->ShaderType != v1.ShaderType) { return this->ShaderType > v1.ShaderType; }
372  return (this->ReplaceFirst > v1.ReplaceFirst);
373  }
374  };
376  {
377  public:
380  };
381 
382  std::map<const ReplacementSpec,ReplacementValue> UserShaderReplacements;
383 
387 
388 private:
389  vtkOpenGLPolyDataMapper(const vtkOpenGLPolyDataMapper&); // Not implemented.
390  void operator=(const vtkOpenGLPolyDataMapper&); // Not implemented.
391 };
392 
393 #endif
a PolyDataMapper for the OpenGL library
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:50
vtkOpenGLBufferObject * CellScalarBuffer
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:38
Type
Available shader types.
Definition: vtkShader.h:48
#define VTKRENDERINGOPENGL2_EXPORT
record modification and/or execution time
Definition: vtkTimeStamp.h:34
vtkTextureObject * CellScalarTexture
vtkOpenGLBufferObject * CellNormalBuffer
vtkTextureObject * CellNormalTexture
abstract specification for renderers
Definition: vtkRenderer.h:62
std::map< const ReplacementSpec, ReplacementValue > UserShaderReplacements
virtual bool GetIsOpaque()
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:84
vtkOpenGLVertexBufferObject * VBO
bool operator<(const ReplacementSpec &v1) const
std::vector< float > AppleBugPrimIDs
OpenGL texture map.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:36
bool operator>(const ReplacementSpec &v1) const
a simple class to control print indentation
Definition: vtkIndent.h:38
std::map< const vtkOpenGLHelper *, vtkTimeStamp > LightComplexityChanged
virtual void ComputeBounds()
abstract class specifies interface to map data
void ShallowCopy(vtkAbstractMapper *m)
std::map< const vtkOpenGLHelper *, int > LastLightComplexity
abstracts an OpenGL texture object.
map vtkPolyData to graphics primitives
object to represent cell connectivity
Definition: vtkCellArray.h:49
static vtkPolyDataMapper * New()
OpenGL buffer object.
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:35
vtkOpenGLBufferObject * AppleBugPrimIDBuffer