VTK  9.3.20240502
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
105#ifndef vtkOpenGLPolyDataMapper_h
106#define vtkOpenGLPolyDataMapper_h
107
108#include "vtkInformation.h" // for prim struct
109#include "vtkNew.h" // For vtkNew
110#include "vtkOpenGLHelper.h" // used for ivars
111#include "vtkPolyDataMapper.h"
112#include "vtkRenderingOpenGL2Module.h" // For export macro
113#include "vtkShader.h" // for methods
114#include "vtkStateStorage.h" // used for ivars
115#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
116
117#include <map> // for map
118#include <tuple> // for tuple
119#include <vector> // for vector
120
121VTK_ABI_NAMESPACE_BEGIN
122class vtkCellArray;
124class vtkMatrix4x4;
125class vtkMatrix3x3;
128class vtkOpenGLTexture;
132class vtkPoints;
133class vtkTexture;
134class vtkTextureObject;
135class vtkTransform;
137
138class VTKRENDERINGOPENGL2_EXPORT VTK_MARSHALAUTO vtkOpenGLPolyDataMapper : public vtkPolyDataMapper
139{
140public:
143 void PrintSelf(ostream& os, vtkIndent indent) override;
144
148 void RenderPiece(vtkRenderer* ren, vtkActor* act) override;
149
156
158
161 virtual void RenderPieceStart(vtkRenderer* ren, vtkActor* act);
162 virtual void RenderPieceDraw(vtkRenderer* ren, vtkActor* act);
163 virtual void RenderPieceFinish(vtkRenderer* ren, vtkActor* act);
165
172
174 vtkGetMacro(PopulateSelectionSettings, int);
176 void SetPopulateSelectionSettings(int v) { this->PopulateSelectionSettings = v; }
177
184 bool GetSupportsSelection() override { return true; }
185
186 // used by RenderPiece and functions it calls to reduce
187 // calls to get the input and allow for rendering of
188 // other polydata (not the input)
190
192
198 vtkSetStringMacro(PointIdArrayName);
199 vtkGetStringMacro(PointIdArrayName);
200 vtkSetStringMacro(CellIdArrayName);
201 vtkGetStringMacro(CellIdArrayName);
203
205
210 vtkSetStringMacro(ProcessIdArrayName);
211 vtkGetStringMacro(ProcessIdArrayName);
213
215
224 vtkSetStringMacro(CompositeIdArrayName);
225 vtkGetStringMacro(CompositeIdArrayName);
227
232
234 vtkGetObjectMacro(VBOs, vtkOpenGLVertexBufferObjectGroup);
235
239 void SetVBOShiftScaleMethod(int method) override;
240
249 vtkGetMacro(UseProgramPointSize, bool);
250 vtkSetMacro(UseProgramPointSize, bool);
251 vtkBooleanMacro(UseProgramPointSize, bool);
252
254 {
255 PrimitiveStart = 0,
256 PrimitivePoints = 0,
261 PrimitiveEnd
262 };
263
275 void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
276 int fieldAssociation, int componentno = -1) override;
277
278 // This method will Map the specified data array for use as
279 // a texture coordinate for texture tname. The actual
280 // attribute will be named tname_coord so as to not
281 // conflict with the texture sampler definition which will
282 // be tname.
283 void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
284 int fieldAssociation, int componentno = -1) override;
285
289 void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
290
295
301 vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
302
303protected:
306
308
309 void MapDataArray(const char* vertexAttributeName, const char* dataArrayName,
310 const char* texturename, int fieldAssociation, int componentno);
311
312 // what coordinate should be used for this texture
313 std::string GetTextureCoordinateName(const char* tname);
314
315 // handle updating shift scale based on pose changes
316 virtual void UpdateCameraShiftScale(vtkRenderer* ren, vtkActor* actor);
317
321 void GetCoincidentParameters(vtkRenderer* ren, vtkActor* actor, float& factor, float& offset);
322
328 void ComputeBounds() override;
329
334 virtual void UpdateShaders(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
335
340
344 virtual void BuildShaders(
345 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
346
350 virtual void GetShaderTemplate(
351 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
352
357 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
358
360
365 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act, bool prePass);
367 std::map<vtkShader::Type, vtkShader*> shaders, vtkActor* act);
368 virtual void ReplaceShaderColor(
369 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
370 virtual void ReplaceShaderEdges(
371 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
372 virtual void ReplaceShaderLight(
373 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
375 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
377 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
379 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
381 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
382 virtual void ReplaceShaderClip(
383 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
385 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
387 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
388 virtual void ReplaceShaderDepth(
389 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
391
395 virtual void SetCustomUniforms(vtkOpenGLHelper& cellBO, vtkActor* actor);
396
401
406 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
407
412
417 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
418
422 virtual void UpdateBufferObjects(vtkRenderer* ren, vtkActor* act);
423
428
432 virtual void BuildBufferObjects(vtkRenderer* ren, vtkActor* act);
433
437 virtual void BuildIBO(vtkRenderer* ren, vtkActor* act, vtkPolyData* poly);
438
442 virtual void BuildSelectionIBO(
443 vtkPolyData* poly, std::vector<unsigned int> (&indices)[4], vtkIdType offset);
444
448 virtual void BuildSelectionCache(const char* arrayName, bool selectingPoints, vtkPolyData* poly);
449
450 // The VBO and its layout.
452
453 // Structures for the various cell types we render.
454 vtkOpenGLHelper Primitives[PrimitiveEnd];
455 vtkOpenGLHelper SelectionPrimitives[PrimitiveEnd];
458 bool DrawingSelection = false;
460 vtkMTimeType SelectionTime = 0;
461
462 std::map<std::tuple<unsigned int, unsigned int, vtkIdType>, std::vector<vtkIdType>>
465 bool SelectionCacheForPoints = false;
466 vtkMTimeType SelectionCacheTime = 0;
467 vtkPolyData* SelectionPolyData = nullptr;
468
469 // do we have wide lines that require special handling
471
472 // do we have textures that require special handling
473 virtual bool HaveTextures(vtkActor* actor);
474
475 // how many textures do we have
476 virtual unsigned int GetNumberOfTextures(vtkActor* actor);
477
478 // populate a vector with the textures we have
479 // the order is always
480 // ColorInternalTexture
481 // Actors texture
482 // Properties textures
483 virtual std::vector<std::pair<vtkTexture*, std::string>> GetTextures(vtkActor* actor);
484
485 // do we have textures coordinates that require special handling
486 virtual bool HaveTCoords(vtkPolyData* poly);
487
488 // values we use to determine if we need to rebuild shaders
489 // stored in a map keyed on the vtkOpenGLHelper, so one
490 // typically entry per type of primitive we render which
491 // matches the shader programs we use
493 {
494 public:
498
499 // Caches the vtkOpenGLRenderPass::RenderPasses() information.
500 // Note: Do not dereference the pointers held by this object. There is no
501 // guarantee that they are still valid!
503 };
504 std::map<const vtkOpenGLHelper*, primitiveInfo> PrimitiveInfo;
505
509
510 // Check the renderpasses in actor's property keys to see if they've changed
511 // render stages:
513
515 vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
516 vtkStateStorage VBOBuildState; // used for determining when to rebuild the VBO
517 vtkStateStorage IBOBuildState; // used for determining whento rebuild the IBOs
519 vtkStateStorage TempState; // can be used to avoid constant allocs/deallocs
521
524
530
531 // if set to true, tcoords will be passed to the
532 // VBO even if the mapper knows of no texture maps
533 // normally tcoords are only added to the VBO if the
534 // mapper has identified a texture map as well.
536
537 virtual void BuildCellTextures(
538 vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation);
539
540 void AppendCellTextures(vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation,
541 std::vector<unsigned char>& colors, std::vector<float>& normals, vtkPolyData* pd,
543
550
553 std::vector<unsigned char> EdgeValues;
555
556 // additional picking indirection
561
563 {
564 public:
565 std::string DataArrayName;
568 std::string TextureName;
569 };
570 std::map<std::string, ExtraAttributeValue> ExtraAttributes;
571
573
574 // are we currently drawing spheres/tubes
576 bool DrawingTubes(vtkOpenGLHelper& cellBO, vtkActor* actor);
578
579 // get which opengl mode to use to draw the primitive
580 int GetOpenGLMode(int representation, int primType);
581
582 // get how big to make the points when doing point picking
583 // typically 2 for points, 4 for lines, 6 for surface
585
586 // used to occasionally invoke timers
587 unsigned int TimerQueryCounter;
588
589 // stores the mapping from OpenGL primitives IDs (gl_PrimitiveId) to VTK cells IDs
591
592 // compute and set the maximum point and cell ID used in selection
594
595 virtual void AddPointIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
596 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
597 virtual void AddCellIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
598 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
599
600 vtkNew<vtkCellArray> SelectionArrays[4];
601
602 vtkMTimeType EnvironmentTextureTime = 0;
603 vtkTexture* EnvironmentTexture = nullptr;
604
605private:
607 void operator=(const vtkOpenGLPolyDataMapper&) = delete;
608};
609
610VTK_ABI_NAMESPACE_END
611#endif
abstract class specifies interface to map data
represents an object (geometry & properties) in a rendered scene
Definition vtkActor.h:151
object to represent cell connectivity
a simple class to control print indentation
Definition vtkIndent.h:108
represent and manipulate 3x3 transformation matrices
represent and manipulate 4x4 transformation matrices
Allocate and hold a VTK object.
Definition vtkNew.h:160
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:139
map vtkPolyData to graphics primitives
std::uintptr_t MapperHashType
concrete dataset represents vertices, lines, polygons, and triangle strips
abstract superclass for all actors, volumes and annotations
Definition vtkProp.h:66
abstract specification for renderers
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:167
record modification and/or execution time
describes linear transformations via a 4x4 matrix
window superclass for vtkRenderWindow
Definition vtkWindow.h:48
int vtkIdType
Definition vtkType.h:315
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:270
#define VTK_MARSHAL_EXCLUDE_REASON_IS_INTERNAL
#define VTK_MARSHALAUTO
#define VTK_MARSHALEXCLUDE(reason)