VTK  9.2.6
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
24#ifndef vtkOpenGLPolyDataMapper_h
25#define vtkOpenGLPolyDataMapper_h
26
27#include "vtkInformation.h" // for prim struct
28#include "vtkNew.h" // For vtkNew
29#include "vtkOpenGLHelper.h" // used for ivars
30#include "vtkPolyDataMapper.h"
31#include "vtkRenderingOpenGL2Module.h" // For export macro
32#include "vtkShader.h" // for methods
33#include "vtkStateStorage.h" // used for ivars
34
35#include <map> // for map
36#include <tuple> // for tuple
37#include <vector> // for vector
38
39class vtkCellArray;
41class vtkMatrix4x4;
42class vtkMatrix3x3;
49class vtkPoints;
50class vtkTexture;
52class vtkTransform;
54
55class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLPolyDataMapper : public vtkPolyDataMapper
56{
57public:
60 void PrintSelf(ostream& os, vtkIndent indent) override;
61
65 void RenderPiece(vtkRenderer* ren, vtkActor* act) override;
66
68
71 virtual void RenderPieceStart(vtkRenderer* ren, vtkActor* act);
72 virtual void RenderPieceDraw(vtkRenderer* ren, vtkActor* act);
73 virtual void RenderPieceFinish(vtkRenderer* ren, vtkActor* act);
75
82
83 vtkGetMacro(PopulateSelectionSettings, int);
85
92 bool GetSupportsSelection() override { return true; }
93
94 // used by RenderPiece and functions it calls to reduce
95 // calls to get the input and allow for rendering of
96 // other polydata (not the input)
98
100
106 vtkSetStringMacro(PointIdArrayName);
107 vtkGetStringMacro(PointIdArrayName);
108 vtkSetStringMacro(CellIdArrayName);
109 vtkGetStringMacro(CellIdArrayName);
111
113
118 vtkSetStringMacro(ProcessIdArrayName);
119 vtkGetStringMacro(ProcessIdArrayName);
121
123
132 vtkSetStringMacro(CompositeIdArrayName);
133 vtkGetStringMacro(CompositeIdArrayName);
135
140
143
147 virtual void SetVBOShiftScaleMethod(int m);
148 virtual int GetVBOShiftScaleMethod() { return this->ShiftScaleMethod; }
149
164 virtual void SetPauseShiftScale(bool pauseShiftScale) { this->PauseShiftScale = pauseShiftScale; }
165 vtkGetMacro(PauseShiftScale, bool);
166 vtkBooleanMacro(PauseShiftScale, bool);
167
178
190 void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
191 int fieldAssociation, int componentno = -1) override;
192
193 // This method will Map the specified data array for use as
194 // a texture coordinate for texture tname. The actual
195 // attribute will be named tname_coord so as to not
196 // conflict with the texture sampler definition which will
197 // be tname.
198 void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
199 int fieldAssociation, int componentno = -1) override;
200
204 void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
205
210
216 vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
217
218protected:
221
223
224 void MapDataArray(const char* vertexAttributeName, const char* dataArrayName,
225 const char* texturename, int fieldAssociation, int componentno);
226
227 // what coordinate should be used for this texture
228 std::string GetTextureCoordinateName(const char* tname);
229
230 // handle updating shift scale based on pose changes
231 virtual void UpdateCameraShiftScale(vtkRenderer* ren, vtkActor* actor);
232
236 void GetCoincidentParameters(vtkRenderer* ren, vtkActor* actor, float& factor, float& offset);
237
243 void ComputeBounds() override;
244
249 virtual void UpdateShaders(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
250
255
259 virtual void BuildShaders(
260 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
261
265 virtual void GetShaderTemplate(
266 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
267
272 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
273
275
280 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act, bool prePass);
282 std::map<vtkShader::Type, vtkShader*> shaders, vtkActor* act);
283 virtual void ReplaceShaderColor(
284 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
285 virtual void ReplaceShaderEdges(
286 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
287 virtual void ReplaceShaderLight(
288 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
290 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
292 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
294 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
296 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
297 virtual void ReplaceShaderClip(
298 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
300 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
302 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
303 virtual void ReplaceShaderDepth(
304 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
306
310 virtual void SetCustomUniforms(vtkOpenGLHelper& cellBO, vtkActor* actor);
311
316
321 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
322
327
332 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
333
337 virtual void UpdateBufferObjects(vtkRenderer* ren, vtkActor* act);
338
343
347 virtual void BuildBufferObjects(vtkRenderer* ren, vtkActor* act);
348
352 virtual void BuildIBO(vtkRenderer* ren, vtkActor* act, vtkPolyData* poly);
353
357 virtual void BuildSelectionIBO(
358 vtkPolyData* poly, std::vector<unsigned int> (&indices)[4], vtkIdType offset);
359
363 virtual void BuildSelectionCache(const char* arrayName, bool selectingPoints, vtkPolyData* poly);
364
365 // The VBO and its layout.
367
368 // Structures for the various cell types we render.
373 bool DrawingSelection = false;
376
377 std::map<std::tuple<unsigned int, unsigned int, vtkIdType>, std::vector<vtkIdType>>
383
384 // do we have wide lines that require special handling
386
387 // do we have textures that require special handling
388 virtual bool HaveTextures(vtkActor* actor);
389
390 // how many textures do we have
391 virtual unsigned int GetNumberOfTextures(vtkActor* actor);
392
393 // populate a vector with the textures we have
394 // the order is always
395 // ColorInternalTexture
396 // Actors texture
397 // Properties textures
398 virtual std::vector<std::pair<vtkTexture*, std::string>> GetTextures(vtkActor* actor);
399
400 // do we have textures coordinates that require special handling
401 virtual bool HaveTCoords(vtkPolyData* poly);
402
403 // values we use to determine if we need to rebuild shaders
404 // stored in a map keyed on the vtkOpenGLHelper, so one
405 // typically entry per type of primitive we render which
406 // matches the shader programs we use
408 {
409 public:
413
414 // Caches the vtkOpenGLRenderPass::RenderPasses() information.
415 // Note: Do not dereference the pointers held by this object. There is no
416 // guarantee that they are still valid!
418 };
419 std::map<const vtkOpenGLHelper*, primitiveInfo> PrimitiveInfo;
420
424
425 // Check the renderpasses in actor's property keys to see if they've changed
426 // render stages:
428
430 vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
431 vtkStateStorage VBOBuildState; // used for determining when to rebuild the VBO
432 vtkStateStorage IBOBuildState; // used for determining whento rebuild the IBOs
434 vtkStateStorage TempState; // can be used to avoid constant allocs/deallocs
436
439
444 int ShiftScaleMethod; // for points
446
447 // if set to true, tcoords will be passed to the
448 // VBO even if the mapper knows of no texture maps
449 // normally tcoords are only added to the VBO if the
450 // mapper has identified a texture map as well.
452
453 virtual void BuildCellTextures(
454 vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation);
455
456 void AppendCellTextures(vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation,
457 std::vector<unsigned char>& colors, std::vector<float>& normals, vtkPolyData* pd,
459
466
469 std::vector<unsigned char> EdgeValues;
471
472 // additional picking indirection
477
479 {
480 public:
481 std::string DataArrayName;
484 std::string TextureName;
485 };
486 std::map<std::string, ExtraAttributeValue> ExtraAttributes;
487
489
490 // are we currently drawing spheres/tubes
492 bool DrawingTubes(vtkOpenGLHelper& cellBO, vtkActor* actor);
494
495 // get which opengl mode to use to draw the primitive
496 int GetOpenGLMode(int representation, int primType);
497
498 // get how big to make the points when doing point picking
499 // typically 2 for points, 4 for lines, 6 for surface
501
502 // used to occasionally invoke timers
503 unsigned int TimerQueryCounter;
504
505 // stores the mapping from vtk cells to gl_PrimitiveId
507
508 // compute and set the maximum point and cell ID used in selection
510
511 virtual void AddPointIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
512 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
513 virtual void AddCellIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
514 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
515
517
518private:
520 void operator=(const vtkOpenGLPolyDataMapper&) = delete;
521};
522
523#endif
abstract class specifies interface to map data
represents an object (geometry & properties) in a rendered scene
Definition vtkActor.h:46
object to represent cell connectivity
a simple class to control print indentation
Definition vtkIndent.h:34
represent and manipulate 3x3 transformation matrices
represent and manipulate 4x4 transformation matrices
Allocate and hold a VTK object.
Definition vtkNew.h:56
OpenGL buffer object.
OpenGL rendering utility functions.
virtual void BuildSelectionCache(const char *arrayName, bool selectingPoints, vtkPolyData *poly)
Build the selection cache, used to map value ids to indices values.
void MapDataArrayToMultiTextureAttribute(const char *tname, const char *dataArrayName, int fieldAssociation, int componentno=-1) override
vtkOpenGLHelper SelectionPrimitives[PrimitiveEnd]
virtual void ReplaceShaderRenderPass(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act, bool prePass)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
virtual void SetLightingShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act)
Set the shader parameters related to lighting, called by UpdateShader.
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources that are being consumed by this mapper.
virtual void ReplaceShaderPrimID(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
virtual void AddCellIdsToSelectionPrimitives(vtkPolyData *poly, const char *arrayName, unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId)
virtual void GetShaderTemplate(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Create the basic shaders before replacement.
std::map< const vtkOpenGLHelper *, primitiveInfo > PrimitiveInfo
virtual bool GetNeedToRebuildShaders(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act)
Does the shader source need to be recomputed.
bool DrawingTubes(vtkOpenGLHelper &cellBO, vtkActor *actor)
vtkOpenGLBufferObject * CellScalarBuffer
virtual void RenderPieceStart(vtkRenderer *ren, vtkActor *act)
Implemented by sub classes.
virtual void SetPauseShiftScale(bool pauseShiftScale)
Pause per-render updates to VBO shift+scale parameters.
void RenderPiece(vtkRenderer *ren, vtkActor *act) override
Implemented by sub classes.
virtual std::vector< std::pair< vtkTexture *, std::string > > GetTextures(vtkActor *actor)
void ComputeBounds() override
Called in GetBounds().
std::string GetTextureCoordinateName(const char *tname)
vtkOpenGLRenderTimer * TimerQuery
virtual void BuildIBO(vtkRenderer *ren, vtkActor *act, vtkPolyData *poly)
Build the IBO, called by BuildBufferObjects.
virtual void AddPointIdsToSelectionPrimitives(vtkPolyData *poly, const char *arrayName, unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId)
virtual void ReplaceShaderCustomUniforms(std::map< vtkShader::Type, vtkShader * > shaders, vtkActor *act)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
bool DrawingTubesOrSpheres(vtkOpenGLHelper &cellBO, vtkActor *actor)
virtual void ReplaceShaderTCoord(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
virtual void UpdateShaders(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act)
Make sure appropriate shaders are defined, compiled and bound.
vtkOpenGLHelper Primitives[PrimitiveEnd]
virtual void ReplaceShaderLight(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
virtual void ReplaceShaderCoincidentOffset(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
virtual void SetCustomUniforms(vtkOpenGLHelper &cellBO, vtkActor *actor)
Set the value of user-defined uniform variables, called by UpdateShader.
virtual void SetCameraShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act)
Set the shader parameters related to the Camera, called by UpdateShader.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void ReplaceShaderValues(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacements on the shader templates.
virtual bool GetNeedToRebuildBufferObjects(vtkRenderer *ren, vtkActor *act)
Does the VBO/IBO need to be rebuilt.
virtual void SetPropertyShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act)
Set the shader parameters related to the property, called by UpdateShader.
virtual void ReplaceShaderEdges(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
virtual bool HaveWideLines(vtkRenderer *, vtkActor *)
virtual void BuildShaders(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Build the shader source code, called by UpdateShader.
void AppendCellTextures(vtkRenderer *ren, vtkActor *, vtkCellArray *prims[4], int representation, std::vector< unsigned char > &colors, std::vector< float > &normals, vtkPolyData *pd, vtkOpenGLCellToVTKCellMap *ccmap)
virtual void SetMapperShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act)
Set the shader parameters related to the mapper/input data, called by UpdateShader.
vtkMTimeType GetRenderPassStageMTime(vtkActor *actor, const vtkOpenGLHelper *cellBO)
virtual void UpdateMaximumPointCellIds(vtkRenderer *ren, vtkActor *actor)
bool GetSupportsSelection() override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THIS METHOD OUTSIDE OF THE RENDERI...
bool DrawingSpheres(vtkOpenGLHelper &cellBO, vtkActor *actor)
vtkNew< vtkOpenGLCellToVTKCellMap > CellCellMap
virtual void RenderPieceFinish(vtkRenderer *ren, vtkActor *act)
Implemented by sub classes.
vtkNew< vtkCellArray > SelectionArrays[4]
virtual void ReplaceShaderDepth(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
vtkOpenGLTexture * InternalColorTexture
virtual void ReplaceShaderClip(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
int GetPointPickingPrimitiveSize(int primType)
vtkOpenGLBufferObject * CellNormalBuffer
virtual void BuildSelectionIBO(vtkPolyData *poly, std::vector< unsigned int >(&indices)[4], vtkIdType offset)
Build the selection IBO, called by UpdateBufferObjects.
std::vector< unsigned char > EdgeValues
std::map< std::string, ExtraAttributeValue > ExtraAttributes
virtual void RenderPieceDraw(vtkRenderer *ren, vtkActor *act)
Implemented by sub classes.
vtkOpenGLBufferObject * EdgeBuffer
virtual void UpdateCameraShiftScale(vtkRenderer *ren, vtkActor *actor)
virtual unsigned int GetNumberOfTextures(vtkActor *actor)
void ProcessSelectorPixelBuffers(vtkHardwareSelector *sel, std::vector< unsigned int > &pixeloffsets, vtkProp *prop) override
allows a mapper to update a selections color buffers Called from a prop which in turn is called from ...
virtual void ReplaceShaderPositionVC(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
virtual void ReplaceShaderNormal(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
vtkNew< vtkTransform > VBOInverseTransform
vtkOpenGLVertexBufferObjectGroup * VBOs
void MapDataArray(const char *vertexAttributeName, const char *dataArrayName, const char *texturename, int fieldAssociation, int componentno)
virtual bool DrawingEdges(vtkRenderer *, vtkActor *)
vtkNew< vtkMatrix4x4 > VBOShiftScale
virtual void BuildBufferObjects(vtkRenderer *ren, vtkActor *act)
Build the VBO/IBO, called by UpdateBufferObjects.
vtkGenericOpenGLResourceFreeCallback * ResourceCallback
void RemoveVertexAttributeMapping(const char *vertexAttributeName) override
Remove a vertex attribute mapping.
static vtkOpenGLPolyDataMapper * New()
void MapDataArrayToVertexAttribute(const char *vertexAttributeName, const char *dataArrayName, int fieldAssociation, int componentno=-1) override
Select a data array from the point/cell data and map it to a generic vertex attribute.
virtual void ReplaceShaderPicking(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
void GetCoincidentParameters(vtkRenderer *ren, vtkActor *actor, float &factor, float &offset)
helper function to get the appropriate coincident params
virtual void SetVBOShiftScaleMethod(int m)
A convenience method for enabling/disabling the VBO's shift+scale transform.
void ShallowCopy(vtkAbstractMapper *m) override
Make a shallow copy of this mapper.
virtual bool HaveTCoords(vtkPolyData *poly)
int GetOpenGLMode(int representation, int primType)
virtual void ReplaceShaderColor(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
void RemoveAllVertexAttributeMappings() override
Remove all vertex attributes.
~vtkOpenGLPolyDataMapper() override
std::map< std::tuple< unsigned int, unsigned int, vtkIdType >, std::vector< vtkIdType > > SelectionCache
virtual bool HaveTextures(vtkActor *actor)
virtual void UpdateBufferObjects(vtkRenderer *ren, vtkActor *act)
Update the VBO/IBO to be current.
virtual void BuildCellTextures(vtkRenderer *ren, vtkActor *, vtkCellArray *prims[4], int representation)
Asynchronously measures GPU execution time for a single event.
represent GPU shader properties
OpenGL texture map.
manage vertex buffer objects shared within a mapper
represent and manipulate 3D points
Definition vtkPoints.h:34
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition vtkPolyData.h:85
abstract superclass for all actors, volumes and annotations
Definition vtkProp.h:51
abstract specification for renderers
Definition vtkRenderer.h:67
Class to make storing and comparing state quick and easy.
abstracts an OpenGL texture object.
handles properties associated with a texture map
Definition vtkTexture.h:66
record modification and/or execution time
describes linear transformations via a 4x4 matrix
window superclass for vtkRenderWindow
Definition vtkWindow.h:39
int vtkIdType
Definition vtkType.h:332
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:287