Thanks to visit codestin.com
Credit goes to vtk.org

VTK  9.5.20251008
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
195
197 vtkGetObjectMacro(VBOs, vtkOpenGLVertexBufferObjectGroup);
198
202 void SetVBOShiftScaleMethod(int method) override;
203
212 vtkGetMacro(UseProgramPointSize, bool);
213 vtkSetMacro(UseProgramPointSize, bool);
214 vtkBooleanMacro(UseProgramPointSize, bool);
215
216 // NOLINTNEXTLINE(readability-enum-initial-value)
218 {
219 PrimitiveStart = 0,
220 PrimitivePoints = 0,
225 PrimitiveEnd
226 };
227
239 void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
240 int fieldAssociation, int componentno = -1) override;
241
242 // This method will Map the specified data array for use as
243 // a texture coordinate for texture tname. The actual
244 // attribute will be named tname_coord so as to not
245 // conflict with the texture sampler definition which will
246 // be tname.
247 void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
248 int fieldAssociation, int componentno = -1) override;
249
253 void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
254
259
265 vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
266
267protected:
270
272
273 void MapDataArray(const char* vertexAttributeName, const char* dataArrayName,
274 const char* texturename, int fieldAssociation, int componentno);
275
276 // what coordinate should be used for this texture
277 std::string GetTextureCoordinateName(const char* tname);
278
279 // handle updating shift scale based on pose changes
280 virtual void UpdateCameraShiftScale(vtkRenderer* ren, vtkActor* actor);
281
285 void GetCoincidentParameters(vtkRenderer* ren, vtkActor* actor, float& factor, float& offset);
286
292 void ComputeBounds() override;
293
298 virtual void UpdateShaders(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
299
304
308 virtual void BuildShaders(
309 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
310
314 virtual void GetShaderTemplate(
315 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
316
321 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
322
324
329 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act, bool prePass);
331 std::map<vtkShader::Type, vtkShader*> shaders, vtkActor* act);
332 virtual void ReplaceShaderColor(
333 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
334 virtual void ReplaceShaderEdges(
335 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
336 virtual void ReplaceShaderLight(
337 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
339 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
341 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
343 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
345 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
346 virtual void ReplaceShaderClip(
347 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
349 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
351 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
352 virtual void ReplaceShaderDepth(
353 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
355
359 virtual void SetCustomUniforms(vtkOpenGLHelper& cellBO, vtkActor* actor);
360
365
370 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
371
376
381 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
382
386 virtual void UpdateBufferObjects(vtkRenderer* ren, vtkActor* act);
387
392
396 virtual void BuildBufferObjects(vtkRenderer* ren, vtkActor* act);
397
401 virtual void BuildIBO(vtkRenderer* ren, vtkActor* act, vtkPolyData* poly);
402
406 virtual void BuildSelectionIBO(
407 vtkPolyData* poly, std::vector<unsigned int> (&indices)[4], vtkIdType offset);
408
412 virtual void BuildSelectionCache(const char* arrayName, bool selectingPoints, vtkPolyData* poly);
413
414 // The VBO and its layout.
416
417 // Structures for the various cell types we render.
418 vtkOpenGLHelper Primitives[PrimitiveEnd];
419 vtkOpenGLHelper SelectionPrimitives[PrimitiveEnd];
422 bool DrawingSelection = false;
424 vtkMTimeType SelectionTime = 0;
425
426 std::map<std::tuple<unsigned int, unsigned int, vtkIdType>, std::vector<vtkIdType>>
429 bool SelectionCacheForPoints = false;
430 vtkMTimeType SelectionCacheTime = 0;
431 vtkPolyData* SelectionPolyData = nullptr;
432
433 // do we have wide lines that require special handling
435
436 // do we have textures that require special handling
437 virtual bool HaveTextures(vtkActor* actor);
438
439 // how many textures do we have
440 virtual unsigned int GetNumberOfTextures(vtkActor* actor);
441
442 // populate a vector with the textures we have
443 // the order is always
444 // ColorInternalTexture
445 // Actors texture
446 // Properties textures
447 typedef std::pair<vtkTexture*, std::string> texinfo;
448 virtual std::vector<texinfo> GetTextures(vtkActor* actor);
449
450 // do we have textures coordinates that require special handling
451 virtual bool HaveTCoords(vtkPolyData* poly);
452
453 // values we use to determine if we need to rebuild shaders
454 // stored in a map keyed on the vtkOpenGLHelper, so one
455 // typically entry per type of primitive we render which
456 // matches the shader programs we use
458 {
459 public:
466 {
467 NoLighting = 0,
468 Headlight = 1,
469 Directional = 2,
470 Positional = 3
471 };
472 LightingTypeEnum LastLightComplexity = NoLighting;
473
475
477
478 // Caches the vtkOpenGLRenderPass::RenderPasses() information.
479 // Note: Do not dereference the pointers held by this object. There is no
480 // guarantee that they are still valid!
482 };
483 std::map<const vtkOpenGLHelper*, primitiveInfo> PrimitiveInfo;
484
488
489 // Check the renderpasses in actor's property keys to see if they've changed
490 // render stages:
492
494 vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
495 vtkStateStorage VBOBuildState; // used for determining when to rebuild the VBO
496 vtkStateStorage IBOBuildState; // used for determining whento rebuild the IBOs
498 vtkStateStorage TempState; // can be used to avoid constant allocs/deallocs
500
503
509
510 // if set to true, tcoords will be passed to the
511 // VBO even if the mapper knows of no texture maps
512 // normally tcoords are only added to the VBO if the
513 // mapper has identified a texture map as well.
515
516 virtual void BuildCellTextures(
517 vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation);
518
519 void AppendCellTextures(vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation,
520 std::vector<unsigned char>& colors, std::vector<float>& normals, vtkPolyData* pd,
522
529
532 std::vector<unsigned char> EdgeValues;
534
536 {
537 public:
538 std::string DataArrayName;
541 std::string TextureName;
542 };
543 std::map<std::string, ExtraAttributeValue> ExtraAttributes;
544
546
547 // are we currently drawing spheres/tubes
549 bool DrawingTubes(vtkOpenGLHelper& cellBO, vtkActor* actor);
551
552 // get which opengl mode to use to draw the primitive
553 int GetOpenGLMode(int representation, int primType);
554
555 // get how big to make the points when doing point picking
556 // typically 2 for points, 4 for lines, 6 for surface
558
559 // used to occasionally invoke timers
560 unsigned int TimerQueryCounter;
561
562 // stores the mapping from OpenGL primitives IDs (gl_PrimitiveId) to VTK cells IDs
564
565 // compute and set the maximum point and cell ID used in selection
567
568 virtual void AddPointIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
569 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
570 virtual void AddCellIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
571 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
572
573 vtkNew<vtkCellArray> SelectionArrays[4];
574
575 vtkMTimeType EnvironmentTextureTime = 0;
576 vtkTexture* EnvironmentTexture = nullptr;
577
578private:
580 void operator=(const vtkOpenGLPolyDataMapper&) = delete;
581};
582
583VTK_ABI_NAMESPACE_END
584#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.
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.
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)
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.
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: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: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:48
int vtkIdType
Definition vtkType.h:367
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:322
#define VTK_MARSHAL_EXCLUDE_REASON_IS_INTERNAL
#define VTK_MARSHALAUTO
#define VTK_MARSHALEXCLUDE(reason)