VTK  9.6.20260223
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
104
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;
138
139class VTKRENDERINGOPENGL2_EXPORT VTK_MARSHALAUTO vtkOpenGLPolyDataMapper : public vtkPolyDataMapper
140{
141public:
146 void PrintSelf(ostream& os, vtkIndent indent) override;
147
151 void RenderPiece(vtkRenderer* ren, vtkActor* act) override;
152
159
165
167
170 virtual void RenderPieceStart(vtkRenderer* ren, vtkActor* act);
171 virtual void RenderPieceDraw(vtkRenderer* ren, vtkActor* act);
172 virtual void RenderPieceFinish(vtkRenderer* ren, vtkActor* act);
174
181
183 vtkGetMacro(PopulateSelectionSettings, int);
185 void SetPopulateSelectionSettings(int v) { this->PopulateSelectionSettings = v; }
186
193 bool GetSupportsSelection() override { return true; }
194
195 // used by RenderPiece and functions it calls to reduce
196 // calls to get the input and allow for rendering of
197 // other polydata (not the input)
199
204
207
211 void SetVBOShiftScaleMethod(int method) override;
212
221 vtkGetMacro(UseProgramPointSize, bool);
222 vtkSetMacro(UseProgramPointSize, bool);
223 vtkBooleanMacro(UseProgramPointSize, bool);
224
225 // NOLINTNEXTLINE(readability-enum-initial-value)
236
248 void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
249 int fieldAssociation, int componentno = -1) override;
250
251 // This method will Map the specified data array for use as
252 // a texture coordinate for texture tname. The actual
253 // attribute will be named tname_coord so as to not
254 // conflict with the texture sampler definition which will
255 // be tname.
256 void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
257 int fieldAssociation, int componentno = -1) override;
258
262 void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
263
268
274 vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
275
276protected:
279
281
282 void MapDataArray(const char* vertexAttributeName, const char* dataArrayName,
283 const char* texturename, int fieldAssociation, int componentno);
284
285 // what coordinate should be used for this texture
286 std::string GetTextureCoordinateName(const char* tname);
287
288 // handle updating shift scale based on pose changes
289 virtual void UpdateCameraShiftScale(vtkRenderer* ren, vtkActor* actor);
290
294 void GetCoincidentParameters(vtkRenderer* ren, vtkActor* actor, float& factor, float& offset);
295
301 void ComputeBounds() override;
302
307 virtual void UpdateShaders(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
308
313
317 virtual void BuildShaders(
318 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
319
323 virtual void GetShaderTemplate(
324 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
325
330 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
331
333
338 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act, bool prePass);
340 std::map<vtkShader::Type, vtkShader*> shaders, vtkActor* act);
341 virtual void ReplaceShaderColor(
342 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
343 virtual void ReplaceShaderEdges(
344 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
345 virtual void ReplaceShaderLight(
346 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
348 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
350 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
352 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
354 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
355 virtual void ReplaceShaderClip(
356 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
358 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
360 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
361 virtual void ReplaceShaderDepth(
362 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
364
368 virtual void SetCustomUniforms(vtkOpenGLHelper& cellBO, vtkActor* actor);
369
374
379 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
380
385
390 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
391
395 virtual void UpdateBufferObjects(vtkRenderer* ren, vtkActor* act);
396
401
405 virtual void BuildBufferObjects(vtkRenderer* ren, vtkActor* act);
406
410 virtual void BuildIBO(vtkRenderer* ren, vtkActor* act, vtkPolyData* poly);
411
415 virtual void BuildSelectionIBO(
416 vtkPolyData* poly, std::vector<unsigned int> (&indices)[4], vtkIdType offset);
417
421 virtual void BuildSelectionCache(const char* arrayName, bool selectingPoints, vtkPolyData* poly);
422
423 // The VBO and its layout.
425
426 // Structures for the various cell types we render.
431 bool DrawingSelection = false;
434
435 std::map<std::tuple<unsigned int, unsigned int, vtkIdType>, std::vector<vtkIdType>>
441
442 // do we have wide lines that require special handling
444
445 // do we have textures that require special handling
446 bool HaveTextures(vtkActor* actor);
447
448 // how many textures do we have
449 unsigned int GetNumberOfTextures(vtkActor* actor);
450
451 typedef std::pair<vtkTexture*, std::string> texinfo;
460 virtual std::vector<texinfo> GetTextures(vtkActor* actor);
461
462 // do we have textures coordinates that require special handling
463 virtual bool HaveTCoords(vtkPolyData* poly);
464
465 // values we use to determine if we need to rebuild shaders
466 // stored in a map keyed on the vtkOpenGLHelper, so one
467 // typically entry per type of primitive we render which
468 // matches the shader programs we use
470 {
471 public:
485
487
489
490 // Caches the vtkOpenGLRenderPass::RenderPasses() information.
491 // Note: Do not dereference the pointers held by this object. There is no
492 // guarantee that they are still valid!
494 };
495 std::map<const vtkOpenGLHelper*, primitiveInfo> PrimitiveInfo;
496
500
501 // Check the renderpasses in actor's property keys to see if they've changed
502 // render stages:
504
506 vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
507 vtkStateStorage VBOBuildState; // used for determining when to rebuild the VBO
508 vtkStateStorage IBOBuildState; // used for determining whento rebuild the IBOs
510 vtkStateStorage TempState; // can be used to avoid constant allocs/deallocs
512
515
521
522 // if set to true, tcoords will be passed to the
523 // VBO even if the mapper knows of no texture maps
524 // normally tcoords are only added to the VBO if the
525 // mapper has identified a texture map as well.
527
528 virtual void BuildCellTextures(
529 vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation);
530
531 void AppendCellTextures(vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation,
532 std::vector<unsigned char>& colors, std::vector<float>& normals, vtkPolyData* pd,
534
541
544 std::vector<unsigned char> EdgeValues;
546
548 {
549 public:
550 std::string DataArrayName;
553 std::string TextureName;
554 };
555 std::map<std::string, ExtraAttributeValue> ExtraAttributes;
556
558
559 // are we currently drawing spheres/tubes
561 bool DrawingTubes(vtkOpenGLHelper& cellBO, vtkActor* actor);
564
565 // get which opengl mode to use to draw the primitive
566 int GetOpenGLMode(int representation, int primType);
567
568 // get how big to make the points when doing point picking
569 // typically 2 for points, 4 for lines, 6 for surface
571
572 // used to occasionally invoke timers
573 unsigned int TimerQueryCounter;
574
575 // stores the mapping from OpenGL primitives IDs (gl_PrimitiveId) to VTK cells IDs
577
578 // compute and set the maximum point and cell ID used in selection
580
581 virtual void AddPointIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
582 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
583 virtual void AddCellIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
584 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
585
587
590
591private:
593 void operator=(const vtkOpenGLPolyDataMapper&) = delete;
594};
595
596#define vtkOpenGLPolyDataMapper_OVERRIDE_ATTRIBUTES \
597 vtkOpenGLPolyDataMapper::CreateOverrideAttributes()
598VTK_ABI_NAMESPACE_END
599#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:167
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
static vtkOverrideAttribute * CreateOverrideAttributes()
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.
bool HaveTextures(vtkActor *actor)
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.
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.
unsigned int GetNumberOfTextures(vtkActor *actor)
virtual std::vector< texinfo > GetTextures(vtkActor *actor)
Recover current texture informations on the provided actor into a vector.
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)
vtkIdType GetMaximumNumberOfTriangles(vtkRenderer *ren) override
Returns the maximum number of triangles renderable based on OpenGL limits.
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 void UpdateBufferObjects(vtkRenderer *ren, vtkActor *act)
Update the VBO/IBO to be current.
virtual void BuildCellTextures(vtkRenderer *ren, vtkActor *, vtkCellArray *prims[4], int representation)
bool DrawingPoints(vtkOpenGLHelper &cellBO, vtkActor *actor)
Asynchronously measures GPU execution time for a single event.
represent GPU shader properties
OpenGL texture map.
manage vertex buffer objects shared within a mapper
Attribute for vtkObjectFactory overrides.
represent and manipulate 3D points
Definition vtkPoints.h:140
std::uintptr_t MapperHashType
concrete dataset represents vertices, lines, polygons, and triangle strips
abstract superclass for all actors, volumes and annotations
Definition vtkProp.h:69
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:168
record modification and/or execution time
describes linear transformations via a 4x4 matrix
window superclass for vtkRenderWindow
Definition vtkWindow.h:61
int vtkIdType
Definition vtkType.h:363
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:318
#define VTK_MARSHAL_EXCLUDE_REASON_IS_INTERNAL
#define VTK_MARSHALAUTO
#define VTK_MARSHALEXCLUDE(reason)
#define VTK_NEWINSTANCE