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
13#ifndef vtkOpenGLPolyDataMapper_h
14#define vtkOpenGLPolyDataMapper_h
15
16#include "vtkInformation.h" // for prim struct
17#include "vtkNew.h" // For vtkNew
18#include "vtkOpenGLHelper.h" // used for ivars
19#include "vtkPolyDataMapper.h"
20#include "vtkRenderingOpenGL2Module.h" // For export macro
21#include "vtkShader.h" // for methods
22#include "vtkStateStorage.h" // used for ivars
23
24#include <map> // for map
25#include <tuple> // for tuple
26#include <vector> // for vector
27
28VTK_ABI_NAMESPACE_BEGIN
29class vtkCellArray;
31class vtkMatrix4x4;
32class vtkMatrix3x3;
39class vtkPoints;
40class vtkTexture;
42class vtkTransform;
44
45class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLPolyDataMapper : public vtkPolyDataMapper
46{
47public:
50 void PrintSelf(ostream& os, vtkIndent indent) override;
51
55 void RenderPiece(vtkRenderer* ren, vtkActor* act) override;
56
63
65
68 virtual void RenderPieceStart(vtkRenderer* ren, vtkActor* act);
69 virtual void RenderPieceDraw(vtkRenderer* ren, vtkActor* act);
70 virtual void RenderPieceFinish(vtkRenderer* ren, vtkActor* act);
72
79
80 vtkGetMacro(PopulateSelectionSettings, int);
81 void SetPopulateSelectionSettings(int v) { this->PopulateSelectionSettings = v; }
82
89 bool GetSupportsSelection() override { return true; }
90
91 // used by RenderPiece and functions it calls to reduce
92 // calls to get the input and allow for rendering of
93 // other polydata (not the input)
95
97
103 vtkSetStringMacro(PointIdArrayName);
104 vtkGetStringMacro(PointIdArrayName);
105 vtkSetStringMacro(CellIdArrayName);
106 vtkGetStringMacro(CellIdArrayName);
108
110
115 vtkSetStringMacro(ProcessIdArrayName);
116 vtkGetStringMacro(ProcessIdArrayName);
118
120
129 vtkSetStringMacro(CompositeIdArrayName);
130 vtkGetStringMacro(CompositeIdArrayName);
132
137
139 vtkGetObjectMacro(VBOs, vtkOpenGLVertexBufferObjectGroup);
140
144 void SetVBOShiftScaleMethod(int method) override;
145
154 vtkGetMacro(UseProgramPointSize, bool);
155 vtkSetMacro(UseProgramPointSize, bool);
156 vtkBooleanMacro(UseProgramPointSize, bool);
157
159 {
160 PrimitiveStart = 0,
161 PrimitivePoints = 0,
166 PrimitiveEnd
167 };
168
180 void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
181 int fieldAssociation, int componentno = -1) override;
182
183 // This method will Map the specified data array for use as
184 // a texture coordinate for texture tname. The actual
185 // attribute will be named tname_coord so as to not
186 // conflict with the texture sampler definition which will
187 // be tname.
188 void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
189 int fieldAssociation, int componentno = -1) override;
190
194 void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
195
200
206 vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
207
208protected:
211
213
214 void MapDataArray(const char* vertexAttributeName, const char* dataArrayName,
215 const char* texturename, int fieldAssociation, int componentno);
216
217 // what coordinate should be used for this texture
218 std::string GetTextureCoordinateName(const char* tname);
219
220 // handle updating shift scale based on pose changes
221 virtual void UpdateCameraShiftScale(vtkRenderer* ren, vtkActor* actor);
222
226 void GetCoincidentParameters(vtkRenderer* ren, vtkActor* actor, float& factor, float& offset);
227
233 void ComputeBounds() override;
234
239 virtual void UpdateShaders(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
240
245
249 virtual void BuildShaders(
250 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
251
255 virtual void GetShaderTemplate(
256 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
257
262 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
263
265
270 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act, bool prePass);
272 std::map<vtkShader::Type, vtkShader*> shaders, vtkActor* act);
273 virtual void ReplaceShaderColor(
274 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
275 virtual void ReplaceShaderEdges(
276 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
277 virtual void ReplaceShaderLight(
278 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
280 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
282 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
284 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
286 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
287 virtual void ReplaceShaderClip(
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);
293 virtual void ReplaceShaderDepth(
294 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
296
300 virtual void SetCustomUniforms(vtkOpenGLHelper& cellBO, vtkActor* actor);
301
306
311 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
312
317
322 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
323
327 virtual void UpdateBufferObjects(vtkRenderer* ren, vtkActor* act);
328
333
337 virtual void BuildBufferObjects(vtkRenderer* ren, vtkActor* act);
338
342 virtual void BuildIBO(vtkRenderer* ren, vtkActor* act, vtkPolyData* poly);
343
347 virtual void BuildSelectionIBO(
348 vtkPolyData* poly, std::vector<unsigned int> (&indices)[4], vtkIdType offset);
349
353 virtual void BuildSelectionCache(const char* arrayName, bool selectingPoints, vtkPolyData* poly);
354
355 // The VBO and its layout.
357
358 // Structures for the various cell types we render.
359 vtkOpenGLHelper Primitives[PrimitiveEnd];
360 vtkOpenGLHelper SelectionPrimitives[PrimitiveEnd];
363 bool DrawingSelection = false;
365 vtkMTimeType SelectionTime = 0;
366
367 std::map<std::tuple<unsigned int, unsigned int, vtkIdType>, std::vector<vtkIdType>>
370 bool SelectionCacheForPoints = false;
371 vtkMTimeType SelectionCacheTime = 0;
372 vtkPolyData* SelectionPolyData = nullptr;
373
374 // do we have wide lines that require special handling
376
377 // do we have textures that require special handling
378 virtual bool HaveTextures(vtkActor* actor);
379
380 // how many textures do we have
381 virtual unsigned int GetNumberOfTextures(vtkActor* actor);
382
383 // populate a vector with the textures we have
384 // the order is always
385 // ColorInternalTexture
386 // Actors texture
387 // Properties textures
388 virtual std::vector<std::pair<vtkTexture*, std::string>> GetTextures(vtkActor* actor);
389
390 // do we have textures coordinates that require special handling
391 virtual bool HaveTCoords(vtkPolyData* poly);
392
393 // values we use to determine if we need to rebuild shaders
394 // stored in a map keyed on the vtkOpenGLHelper, so one
395 // typically entry per type of primitive we render which
396 // matches the shader programs we use
398 {
399 public:
403
404 // Caches the vtkOpenGLRenderPass::RenderPasses() information.
405 // Note: Do not dereference the pointers held by this object. There is no
406 // guarantee that they are still valid!
408 };
409 std::map<const vtkOpenGLHelper*, primitiveInfo> PrimitiveInfo;
410
414
415 // Check the renderpasses in actor's property keys to see if they've changed
416 // render stages:
418
420 vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
421 vtkStateStorage VBOBuildState; // used for determining when to rebuild the VBO
422 vtkStateStorage IBOBuildState; // used for determining whento rebuild the IBOs
424 vtkStateStorage TempState; // can be used to avoid constant allocs/deallocs
426
429
435
436 // if set to true, tcoords will be passed to the
437 // VBO even if the mapper knows of no texture maps
438 // normally tcoords are only added to the VBO if the
439 // mapper has identified a texture map as well.
441
442 virtual void BuildCellTextures(
443 vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation);
444
445 void AppendCellTextures(vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation,
446 std::vector<unsigned char>& colors, std::vector<float>& normals, vtkPolyData* pd,
448
455
458 std::vector<unsigned char> EdgeValues;
460
461 // additional picking indirection
466
468 {
469 public:
470 std::string DataArrayName;
473 std::string TextureName;
474 };
475 std::map<std::string, ExtraAttributeValue> ExtraAttributes;
476
478
479 // are we currently drawing spheres/tubes
481 bool DrawingTubes(vtkOpenGLHelper& cellBO, vtkActor* actor);
483
484 // get which opengl mode to use to draw the primitive
485 int GetOpenGLMode(int representation, int primType);
486
487 // get how big to make the points when doing point picking
488 // typically 2 for points, 4 for lines, 6 for surface
490
491 // used to occasionally invoke timers
492 unsigned int TimerQueryCounter;
493
494 // stores the mapping from OpenGL primitives IDs (gl_PrimitiveId) to VTK cells IDs
496
497 // compute and set the maximum point and cell ID used in selection
499
500 virtual void AddPointIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
501 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
502 virtual void AddCellIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
503 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
504
505 vtkNew<vtkCellArray> SelectionArrays[4];
506
507private:
509 void operator=(const vtkOpenGLPolyDataMapper&) = delete;
510};
511
512VTK_ABI_NAMESPACE_END
513#endif
abstract class specifies interface to map data
represents an object (geometry & properties) in a rendered scene
Definition vtkActor.h:41
object to represent cell connectivity
a simple class to control print indentation
Definition vtkIndent.h:29
represent and manipulate 3x3 transformation matrices
represent and manipulate 4x4 transformation matrices
Allocate and hold a VTK object.
Definition vtkNew.h:51
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:29
map vtkPolyData to graphics primitives
std::uintptr_t MapperHashType
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition vtkPolyData.h:80
abstract superclass for all actors, volumes and annotations
Definition vtkProp.h:43
abstract specification for renderers
Definition vtkRenderer.h:59
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:58
record modification and/or execution time
describes linear transformations via a 4x4 matrix
window superclass for vtkRenderWindow
Definition vtkWindow.h:25
int vtkIdType
Definition vtkType.h:315
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:270