VTK  9.3.0
vtkOpenGLPolyDataMapper.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
22#ifndef vtkOpenGLPolyDataMapper_h
23#define vtkOpenGLPolyDataMapper_h
24
25#include "vtkInformation.h" // for prim struct
26#include "vtkNew.h" // For vtkNew
27#include "vtkOpenGLHelper.h" // used for ivars
28#include "vtkPolyDataMapper.h"
29#include "vtkRenderingOpenGL2Module.h" // For export macro
30#include "vtkShader.h" // for methods
31#include "vtkStateStorage.h" // used for ivars
32
33#include <map> // for map
34#include <tuple> // for tuple
35#include <vector> // for vector
36
37VTK_ABI_NAMESPACE_BEGIN
38class vtkCellArray;
40class vtkMatrix4x4;
41class vtkMatrix3x3;
48class vtkPoints;
49class vtkTexture;
51class vtkTransform;
53
54class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLPolyDataMapper : public vtkPolyDataMapper
55{
56public:
59 void PrintSelf(ostream& os, vtkIndent indent) override;
60
64 void RenderPiece(vtkRenderer* ren, vtkActor* act) override;
65
72
74
77 virtual void RenderPieceStart(vtkRenderer* ren, vtkActor* act);
78 virtual void RenderPieceDraw(vtkRenderer* ren, vtkActor* act);
79 virtual void RenderPieceFinish(vtkRenderer* ren, vtkActor* act);
81
88
89 vtkGetMacro(PopulateSelectionSettings, int);
90 void SetPopulateSelectionSettings(int v) { this->PopulateSelectionSettings = v; }
91
98 bool GetSupportsSelection() override { return true; }
99
100 // used by RenderPiece and functions it calls to reduce
101 // calls to get the input and allow for rendering of
102 // other polydata (not the input)
104
106
112 vtkSetStringMacro(PointIdArrayName);
113 vtkGetStringMacro(PointIdArrayName);
114 vtkSetStringMacro(CellIdArrayName);
115 vtkGetStringMacro(CellIdArrayName);
117
119
124 vtkSetStringMacro(ProcessIdArrayName);
125 vtkGetStringMacro(ProcessIdArrayName);
127
129
138 vtkSetStringMacro(CompositeIdArrayName);
139 vtkGetStringMacro(CompositeIdArrayName);
141
146
148 vtkGetObjectMacro(VBOs, vtkOpenGLVertexBufferObjectGroup);
149
153 void SetVBOShiftScaleMethod(int method) override;
154
163 vtkGetMacro(UseProgramPointSize, bool);
164 vtkSetMacro(UseProgramPointSize, bool);
165 vtkBooleanMacro(UseProgramPointSize, bool);
166
168 {
169 PrimitiveStart = 0,
170 PrimitivePoints = 0,
175 PrimitiveEnd
176 };
177
189 void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
190 int fieldAssociation, int componentno = -1) override;
191
192 // This method will Map the specified data array for use as
193 // a texture coordinate for texture tname. The actual
194 // attribute will be named tname_coord so as to not
195 // conflict with the texture sampler definition which will
196 // be tname.
197 void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
198 int fieldAssociation, int componentno = -1) override;
199
203 void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
204
209
215 vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
216
217protected:
220
222
223 void MapDataArray(const char* vertexAttributeName, const char* dataArrayName,
224 const char* texturename, int fieldAssociation, int componentno);
225
226 // what coordinate should be used for this texture
227 std::string GetTextureCoordinateName(const char* tname);
228
229 // handle updating shift scale based on pose changes
230 virtual void UpdateCameraShiftScale(vtkRenderer* ren, vtkActor* actor);
231
235 void GetCoincidentParameters(vtkRenderer* ren, vtkActor* actor, float& factor, float& offset);
236
242 void ComputeBounds() override;
243
248 virtual void UpdateShaders(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
249
254
258 virtual void BuildShaders(
259 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
260
264 virtual void GetShaderTemplate(
265 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
266
271 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
272
274
279 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act, bool prePass);
281 std::map<vtkShader::Type, vtkShader*> shaders, vtkActor* act);
282 virtual void ReplaceShaderColor(
283 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
284 virtual void ReplaceShaderEdges(
285 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
286 virtual void ReplaceShaderLight(
287 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
289 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
291 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
293 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
295 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
296 virtual void ReplaceShaderClip(
297 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
299 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
301 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
302 virtual void ReplaceShaderDepth(
303 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
305
309 virtual void SetCustomUniforms(vtkOpenGLHelper& cellBO, vtkActor* actor);
310
315
320 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
321
326
331 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
332
336 virtual void UpdateBufferObjects(vtkRenderer* ren, vtkActor* act);
337
342
346 virtual void BuildBufferObjects(vtkRenderer* ren, vtkActor* act);
347
351 virtual void BuildIBO(vtkRenderer* ren, vtkActor* act, vtkPolyData* poly);
352
356 virtual void BuildSelectionIBO(
357 vtkPolyData* poly, std::vector<unsigned int> (&indices)[4], vtkIdType offset);
358
362 virtual void BuildSelectionCache(const char* arrayName, bool selectingPoints, vtkPolyData* poly);
363
364 // The VBO and its layout.
366
367 // Structures for the various cell types we render.
368 vtkOpenGLHelper Primitives[PrimitiveEnd];
369 vtkOpenGLHelper SelectionPrimitives[PrimitiveEnd];
372 bool DrawingSelection = false;
374 vtkMTimeType SelectionTime = 0;
375
376 std::map<std::tuple<unsigned int, unsigned int, vtkIdType>, std::vector<vtkIdType>>
379 bool SelectionCacheForPoints = false;
380 vtkMTimeType SelectionCacheTime = 0;
381 vtkPolyData* SelectionPolyData = nullptr;
382
383 // do we have wide lines that require special handling
385
386 // do we have textures that require special handling
387 virtual bool HaveTextures(vtkActor* actor);
388
389 // how many textures do we have
390 virtual unsigned int GetNumberOfTextures(vtkActor* actor);
391
392 // populate a vector with the textures we have
393 // the order is always
394 // ColorInternalTexture
395 // Actors texture
396 // Properties textures
397 virtual std::vector<std::pair<vtkTexture*, std::string>> GetTextures(vtkActor* actor);
398
399 // do we have textures coordinates that require special handling
400 virtual bool HaveTCoords(vtkPolyData* poly);
401
402 // values we use to determine if we need to rebuild shaders
403 // stored in a map keyed on the vtkOpenGLHelper, so one
404 // typically entry per type of primitive we render which
405 // matches the shader programs we use
407 {
408 public:
412
413 // Caches the vtkOpenGLRenderPass::RenderPasses() information.
414 // Note: Do not dereference the pointers held by this object. There is no
415 // guarantee that they are still valid!
417 };
418 std::map<const vtkOpenGLHelper*, primitiveInfo> PrimitiveInfo;
419
423
424 // Check the renderpasses in actor's property keys to see if they've changed
425 // render stages:
427
429 vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
430 vtkStateStorage VBOBuildState; // used for determining when to rebuild the VBO
431 vtkStateStorage IBOBuildState; // used for determining whento rebuild the IBOs
433 vtkStateStorage TempState; // can be used to avoid constant allocs/deallocs
435
438
444
445 // if set to true, tcoords will be passed to the
446 // VBO even if the mapper knows of no texture maps
447 // normally tcoords are only added to the VBO if the
448 // mapper has identified a texture map as well.
450
451 virtual void BuildCellTextures(
452 vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation);
453
454 void AppendCellTextures(vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation,
455 std::vector<unsigned char>& colors, std::vector<float>& normals, vtkPolyData* pd,
457
464
467 std::vector<unsigned char> EdgeValues;
469
470 // additional picking indirection
475
477 {
478 public:
479 std::string DataArrayName;
482 std::string TextureName;
483 };
484 std::map<std::string, ExtraAttributeValue> ExtraAttributes;
485
487
488 // are we currently drawing spheres/tubes
490 bool DrawingTubes(vtkOpenGLHelper& cellBO, vtkActor* actor);
492
493 // get which opengl mode to use to draw the primitive
494 int GetOpenGLMode(int representation, int primType);
495
496 // get how big to make the points when doing point picking
497 // typically 2 for points, 4 for lines, 6 for surface
499
500 // used to occasionally invoke timers
501 unsigned int TimerQueryCounter;
502
503 // stores the mapping from OpenGL primitives IDs (gl_PrimitiveId) to VTK cells IDs
505
506 // compute and set the maximum point and cell ID used in selection
508
509 virtual void AddPointIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
510 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
511 virtual void AddCellIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
512 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
513
514 vtkNew<vtkCellArray> SelectionArrays[4];
515
516private:
518 void operator=(const vtkOpenGLPolyDataMapper&) = delete;
519};
520
521VTK_ABI_NAMESPACE_END
522#endif
abstract class specifies interface to map data
represents an object (geometry & properties) in a rendered scene
Definition vtkActor.h:50
object to represent cell connectivity
a simple class to control print indentation
Definition vtkIndent.h:38
represent and manipulate 3x3 transformation matrices
represent and manipulate 4x4 transformation matrices
Allocate and hold a VTK object.
Definition vtkNew.h:60
OpenGL buffer object.
OpenGL rendering utility functions.
PolyDataMapper using OpenGL to render.
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
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.
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.
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)
MapperHashType GenerateHash(vtkPolyData *polydata) override
Unique hash based on availability of scalars, normals, tcoords, lookup tables and related attributes ...
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.
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)
void SetVBOShiftScaleMethod(int method) override
A convenience method for enabling/disabling the VBO's shift+scale transform.
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
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:38
map vtkPolyData to graphics primitives
std::uintptr_t MapperHashType
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition vtkPolyData.h:89
abstract superclass for all actors, volumes and annotations
Definition vtkProp.h:52
abstract specification for renderers
Definition vtkRenderer.h:68
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:67
record modification and/or execution time
describes linear transformations via a 4x4 matrix
window superclass for vtkRenderWindow
Definition vtkWindow.h:34
int vtkIdType
Definition vtkType.h:315
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:270