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 
41 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLPolyDataMapper : public vtkPolyDataMapper
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 
94  vtkSetStringMacro(PointIdArrayName);
95  vtkGetStringMacro(PointIdArrayName);
96  vtkSetStringMacro(CellIdArrayName);
97  vtkGetStringMacro(CellIdArrayName);
99 
101 
104  vtkSetStringMacro(ProcessIdArrayName);
105  vtkGetStringMacro(ProcessIdArrayName);
107 
109 
116  vtkSetStringMacro(CompositeIdArrayName);
117  vtkGetStringMacro(CompositeIdArrayName);
119 
120  // the following is all extra stuff to work around the
121  // fact that gl_PrimitiveID does not work correctly on
122  // Apple devices with AMD graphics hardware. See apple
123  // bug ID 20747550
124  static vtkPolyData *HandleAppleBug(
125  vtkPolyData *poly,
126  std::vector<float> &buffData);
127 
128 protected:
131 
132  // the following is all extra stuff to work around the
133  // fact that gl_PrimitiveID does not work correctly on
134  // Apple devices with AMD graphics hardware. See apple
135  // bug ID 20747550
137  std::vector<float> AppleBugPrimIDs;
139 
144  virtual void ComputeBounds();
145 
147 
150  virtual void UpdateShaders(
151  vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
153 
155 
156  virtual bool GetNeedToRebuildShaders(
157  vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
159 
161 
162  virtual void BuildShaders(
163  std::map<vtkShader::Type, vtkShader *> shaders,
164  vtkRenderer *ren, vtkActor *act);
166 
168 
169  virtual void GetShaderTemplate(
170  std::map<vtkShader::Type, vtkShader *> shaders,
171  vtkRenderer *ren, vtkActor *act);
173 
175 
176  virtual void ReplaceShaderValues(
177  std::map<vtkShader::Type, vtkShader *> shaders,
178  vtkRenderer *ren, vtkActor *act);
180 
182 
184  virtual void ReplaceShaderColor(
185  std::map<vtkShader::Type, vtkShader *> shaders,
186  vtkRenderer *ren, vtkActor *act);
187  virtual void ReplaceShaderLight(
188  std::map<vtkShader::Type, vtkShader *> shaders,
189  vtkRenderer *ren, vtkActor *act);
190  virtual void ReplaceShaderTCoord(
191  std::map<vtkShader::Type, vtkShader *> shaders,
192  vtkRenderer *ren, vtkActor *act);
193  virtual void ReplaceShaderPicking(
194  std::map<vtkShader::Type, vtkShader *> shaders,
195  vtkRenderer *ren, vtkActor *act);
196  virtual void ReplaceShaderDepthPeeling(
197  std::map<vtkShader::Type, vtkShader *> shaders,
198  vtkRenderer *ren, vtkActor *act);
199  virtual void ReplaceShaderPrimID(
200  std::map<vtkShader::Type, vtkShader *> shaders,
201  vtkRenderer *ren, vtkActor *act);
202  virtual void ReplaceShaderNormal(
203  std::map<vtkShader::Type, vtkShader *> shaders,
204  vtkRenderer *ren, vtkActor *act);
205  virtual void ReplaceShaderClip(
206  std::map<vtkShader::Type, vtkShader *> shaders,
207  vtkRenderer *ren, vtkActor *act);
208  virtual void ReplaceShaderPositionVC(
209  std::map<vtkShader::Type, vtkShader *> shaders,
210  vtkRenderer *ren, vtkActor *act);
212 
215  virtual void SetMapperShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
216 
219  virtual void SetLightingShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
220 
223  virtual void SetCameraShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
224 
227  virtual void SetPropertyShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act);
228 
230  virtual void UpdateBufferObjects(vtkRenderer *ren, vtkActor *act);
231 
233  virtual bool GetNeedToRebuildBufferObjects(vtkRenderer *ren, vtkActor *act);
234 
236  virtual void BuildBufferObjects(vtkRenderer *ren, vtkActor *act);
237 
239  virtual void BuildIBO(vtkRenderer *ren, vtkActor *act, vtkPolyData *poly);
240 
241  // The VBO and its layout.
243 
244  // Structures for the various cell types we render.
253 
254  // do we have wide lines that require special handling
255  virtual bool HaveWideLines(vtkRenderer *, vtkActor *);
256 
257  // values we use to determine if we need to rebuild
260 
263 
266 
268  vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
269  vtkOpenGLTexture* InternalColorTexture;
270 
273 
276 
277  // this vector can be used while building
278  // the shader program to record specific variables
279  // that are being used by the program. This is
280  // useful later on when setting uniforms. At
281  // that point IsShaderVariableUsed can be called
282  // to see if the uniform should be set or not.
283  std::vector<std::string> ShaderVariablesUsed;
284 
285  // used to see if the shader building code indicated that
286  // a specific variable is being used. Only some variables
287  // are currently populated.
288  bool IsShaderVariableUsed(const char *);
289 
290  // if set to true, tcoords will be passed to the
291  // VBO even if the mapper knows of no texture maps
292  // normally tcoords are only added to the VBO if the
293  // mapper has indentified a texture map as well.
295 
296  void BuildCellTextures(
297  vtkRenderer *ren,
298  vtkActor *,
299  vtkCellArray *prims[4],
300  int representation);
301 
302  void AppendCellTextures(
303  vtkRenderer *ren,
304  vtkActor *,
305  vtkCellArray *prims[4],
306  int representation,
307  std::vector<unsigned char> &colors,
308  std::vector<float> &normals,
309  vtkPolyData *pd);
310 
318 
319  // aditional picking indirection
324 
326 
327 private:
328  vtkOpenGLPolyDataMapper(const vtkOpenGLPolyDataMapper&); // Not implemented.
329  void operator=(const vtkOpenGLPolyDataMapper&); // Not implemented.
330 };
331 
332 #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
record modification and/or execution time
Definition: vtkTimeStamp.h:34
vtkTextureObject * CellScalarTexture
vtkOpenGLBufferObject * CellNormalBuffer
vtkTextureObject * CellNormalTexture
abstract specification for renderers
Definition: vtkRenderer.h:63
virtual bool GetIsOpaque()
Definition: vtkMapper.h:422
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:83
vtkOpenGLVertexBufferObject * VBO
std::vector< float > AppleBugPrimIDs
OpenGL texture map.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:36
std::vector< std::string > ShaderVariablesUsed
a simple class to control print indentation
Definition: vtkIndent.h:38
virtual void ComputeBounds()
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