VTK  9.4.20251007
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
15
16#ifndef vtkOpenGLPolyDataMapper_h
17#define vtkOpenGLPolyDataMapper_h
18
19#include "vtkInformation.h" // for prim struct
20#include "vtkNew.h" // For vtkNew
21#include "vtkOpenGLHelper.h" // used for ivars
22#include "vtkPolyDataMapper.h"
23#include "vtkRenderingOpenGL2Module.h" // For export macro
24#include "vtkShader.h" // for methods
25#include "vtkStateStorage.h" // used for ivars
26#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
27
28#include <map> // for map
29#include <tuple> // for tuple
30#include <vector> // for vector
31
32VTK_ABI_NAMESPACE_BEGIN
33class vtkCellArray;
35class vtkMatrix4x4;
36class vtkMatrix3x3;
43class vtkPoints;
44class vtkTexture;
46class vtkTransform;
48
49class VTKRENDERINGOPENGL2_EXPORT VTK_MARSHALAUTO vtkOpenGLPolyDataMapper : public vtkPolyDataMapper
50{
51public:
54 void PrintSelf(ostream& os, vtkIndent indent) override;
55
59 void RenderPiece(vtkRenderer* ren, vtkActor* act) override;
60
67
69
72 virtual void RenderPieceStart(vtkRenderer* ren, vtkActor* act);
73 virtual void RenderPieceDraw(vtkRenderer* ren, vtkActor* act);
74 virtual void RenderPieceFinish(vtkRenderer* ren, vtkActor* act);
76
83
85 vtkGetMacro(PopulateSelectionSettings, int);
87 void SetPopulateSelectionSettings(int v) { this->PopulateSelectionSettings = v; }
88
95 bool GetSupportsSelection() override { return true; }
96
97 // used by RenderPiece and functions it calls to reduce
98 // calls to get the input and allow for rendering of
99 // other polydata (not the input)
101
103
109 vtkSetStringMacro(PointIdArrayName);
110 vtkGetStringMacro(PointIdArrayName);
111 vtkSetStringMacro(CellIdArrayName);
112 vtkGetStringMacro(CellIdArrayName);
114
116
122 vtkSetStringMacro(ProcessIdArrayName);
123 vtkGetStringMacro(ProcessIdArrayName);
125
127
137 vtkSetStringMacro(CompositeIdArrayName);
138 vtkGetStringMacro(CompositeIdArrayName);
140
145
148
152 void SetVBOShiftScaleMethod(int method) override;
153
162 vtkGetMacro(UseProgramPointSize, bool);
163 vtkSetMacro(UseProgramPointSize, bool);
164 vtkBooleanMacro(UseProgramPointSize, bool);
165
176
188 void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
189 int fieldAssociation, int componentno = -1) override;
190
191 // This method will Map the specified data array for use as
192 // a texture coordinate for texture tname. The actual
193 // attribute will be named tname_coord so as to not
194 // conflict with the texture sampler definition which will
195 // be tname.
196 void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
197 int fieldAssociation, int componentno = -1) override;
198
202 void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
203
208
214 vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
215
216protected:
219
221
222 void MapDataArray(const char* vertexAttributeName, const char* dataArrayName,
223 const char* texturename, int fieldAssociation, int componentno);
224
225 // what coordinate should be used for this texture
226 std::string GetTextureCoordinateName(const char* tname);
227
228 // handle updating shift scale based on pose changes
229 virtual void UpdateCameraShiftScale(vtkRenderer* ren, vtkActor* actor);
230
234 void GetCoincidentParameters(vtkRenderer* ren, vtkActor* actor, float& factor, float& offset);
235
241 void ComputeBounds() override;
242
247 virtual void UpdateShaders(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
248
253
257 virtual void BuildShaders(
258 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
259
263 virtual void GetShaderTemplate(
264 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
265
270 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
271
273
278 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act, bool prePass);
280 std::map<vtkShader::Type, vtkShader*> shaders, vtkActor* act);
281 virtual void ReplaceShaderColor(
282 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
283 virtual void ReplaceShaderEdges(
284 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
285 virtual void ReplaceShaderLight(
286 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
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);
295 virtual void ReplaceShaderClip(
296 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
298 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
300 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
301 virtual void ReplaceShaderDepth(
302 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
304
308 virtual void SetCustomUniforms(vtkOpenGLHelper& cellBO, vtkActor* actor);
309
314
319 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
320
325
330 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
331
335 virtual void UpdateBufferObjects(vtkRenderer* ren, vtkActor* act);
336
341
345 virtual void BuildBufferObjects(vtkRenderer* ren, vtkActor* act);
346
350 virtual void BuildIBO(vtkRenderer* ren, vtkActor* act, vtkPolyData* poly);
351
355 virtual void BuildSelectionIBO(
356 vtkPolyData* poly, std::vector<unsigned int> (&indices)[4], vtkIdType offset);
357
361 virtual void BuildSelectionCache(const char* arrayName, bool selectingPoints, vtkPolyData* poly);
362
363 // The VBO and its layout.
365
366 // Structures for the various cell types we render.
371 bool DrawingSelection = false;
374
375 std::map<std::tuple<unsigned int, unsigned int, vtkIdType>, std::vector<vtkIdType>>
381
382 // do we have wide lines that require special handling
384
385 // do we have textures that require special handling
386 virtual bool HaveTextures(vtkActor* actor);
387
388 // how many textures do we have
389 virtual unsigned int GetNumberOfTextures(vtkActor* actor);
390
391 // populate a vector with the textures we have
392 // the order is always
393 // ColorInternalTexture
394 // Actors texture
395 // Properties textures
396 typedef std::pair<vtkTexture*, std::string> texinfo;
397 virtual std::vector<texinfo> 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:
422
424
426
427 // Caches the vtkOpenGLRenderPass::RenderPasses() information.
428 // Note: Do not dereference the pointers held by this object. There is no
429 // guarantee that they are still valid!
431 };
432 std::map<const vtkOpenGLHelper*, primitiveInfo> PrimitiveInfo;
433
437
438 // Check the renderpasses in actor's property keys to see if they've changed
439 // render stages:
441
443 vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
444 vtkStateStorage VBOBuildState; // used for determining when to rebuild the VBO
445 vtkStateStorage IBOBuildState; // used for determining whento rebuild the IBOs
447 vtkStateStorage TempState; // can be used to avoid constant allocs/deallocs
449
452
458
459 // if set to true, tcoords will be passed to the
460 // VBO even if the mapper knows of no texture maps
461 // normally tcoords are only added to the VBO if the
462 // mapper has identified a texture map as well.
464
465 virtual void BuildCellTextures(
466 vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation);
467
468 void AppendCellTextures(vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation,
469 std::vector<unsigned char>& colors, std::vector<float>& normals, vtkPolyData* pd,
471
478
481 std::vector<unsigned char> EdgeValues;
483
484 // additional picking indirection
489
491 {
492 public:
493 std::string DataArrayName;
496 std::string TextureName;
497 };
498 std::map<std::string, ExtraAttributeValue> ExtraAttributes;
499
501
502 // are we currently drawing spheres/tubes
504 bool DrawingTubes(vtkOpenGLHelper& cellBO, vtkActor* actor);
506
507 // get which opengl mode to use to draw the primitive
508 int GetOpenGLMode(int representation, int primType);
509
510 // get how big to make the points when doing point picking
511 // typically 2 for points, 4 for lines, 6 for surface
513
514 // used to occasionally invoke timers
515 unsigned int TimerQueryCounter;
516
517 // stores the mapping from OpenGL primitives IDs (gl_PrimitiveId) to VTK cells IDs
519
520 // compute and set the maximum point and cell ID used in selection
522
523 virtual void AddPointIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
524 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
525 virtual void AddCellIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
526 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
527
529
532
533private:
535 void operator=(const vtkOpenGLPolyDataMapper&) = delete;
536};
537
538VTK_ABI_NAMESPACE_END
539#endif
abstract class specifies interface to map data
represents an object (geometry & properties) in a rendered scene
Definition vtkActor.h:42
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:58
OpenGL buffer object.
OpenGL rendering utility functions.
LightingTypeEnum
Represent the type of lighting used.
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.
void RenderPiece(vtkRenderer *ren, vtkActor *act) override
Implemented by sub classes.
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)
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)
std::pair< vtkTexture *, std::string > texinfo
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)
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.
virtual std::vector< texinfo > GetTextures(vtkActor *actor)
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:30
std::uintptr_t MapperHashType
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition vtkPolyData.h:72
abstract superclass for all actors, volumes and annotations
Definition vtkProp.h:47
abstract specification for renderers
Definition vtkRenderer.h:63
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:59
record modification and/or execution time
describes linear transformations via a 4x4 matrix
window superclass for vtkRenderWindow
Definition vtkWindow.h:29
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)