VTK  9.4.20250114
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
217 {
218 PrimitiveStart = 0,
219 PrimitivePoints = 0,
224 PrimitiveEnd
225 };
226
238 void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
239 int fieldAssociation, int componentno = -1) override;
240
241 // This method will Map the specified data array for use as
242 // a texture coordinate for texture tname. The actual
243 // attribute will be named tname_coord so as to not
244 // conflict with the texture sampler definition which will
245 // be tname.
246 void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
247 int fieldAssociation, int componentno = -1) override;
248
252 void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
253
258
264 vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
265
266protected:
269
271
272 void MapDataArray(const char* vertexAttributeName, const char* dataArrayName,
273 const char* texturename, int fieldAssociation, int componentno);
274
275 // what coordinate should be used for this texture
276 std::string GetTextureCoordinateName(const char* tname);
277
278 // handle updating shift scale based on pose changes
279 virtual void UpdateCameraShiftScale(vtkRenderer* ren, vtkActor* actor);
280
284 void GetCoincidentParameters(vtkRenderer* ren, vtkActor* actor, float& factor, float& offset);
285
291 void ComputeBounds() override;
292
297 virtual void UpdateShaders(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
298
303
307 virtual void BuildShaders(
308 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
309
313 virtual void GetShaderTemplate(
314 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
315
320 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
321
323
328 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act, bool prePass);
330 std::map<vtkShader::Type, vtkShader*> shaders, vtkActor* act);
331 virtual void ReplaceShaderColor(
332 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
333 virtual void ReplaceShaderEdges(
334 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
335 virtual void ReplaceShaderLight(
336 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
338 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
340 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
342 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
344 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
345 virtual void ReplaceShaderClip(
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);
351 virtual void ReplaceShaderDepth(
352 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
354
358 virtual void SetCustomUniforms(vtkOpenGLHelper& cellBO, vtkActor* actor);
359
364
369 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
370
375
380 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
381
385 virtual void UpdateBufferObjects(vtkRenderer* ren, vtkActor* act);
386
391
395 virtual void BuildBufferObjects(vtkRenderer* ren, vtkActor* act);
396
400 virtual void BuildIBO(vtkRenderer* ren, vtkActor* act, vtkPolyData* poly);
401
405 virtual void BuildSelectionIBO(
406 vtkPolyData* poly, std::vector<unsigned int> (&indices)[4], vtkIdType offset);
407
411 virtual void BuildSelectionCache(const char* arrayName, bool selectingPoints, vtkPolyData* poly);
412
413 // The VBO and its layout.
415
416 // Structures for the various cell types we render.
417 vtkOpenGLHelper Primitives[PrimitiveEnd];
418 vtkOpenGLHelper SelectionPrimitives[PrimitiveEnd];
421 bool DrawingSelection = false;
423 vtkMTimeType SelectionTime = 0;
424
425 std::map<std::tuple<unsigned int, unsigned int, vtkIdType>, std::vector<vtkIdType>>
428 bool SelectionCacheForPoints = false;
429 vtkMTimeType SelectionCacheTime = 0;
430 vtkPolyData* SelectionPolyData = nullptr;
431
432 // do we have wide lines that require special handling
434
435 // do we have textures that require special handling
436 virtual bool HaveTextures(vtkActor* actor);
437
438 // how many textures do we have
439 virtual unsigned int GetNumberOfTextures(vtkActor* actor);
440
441 // populate a vector with the textures we have
442 // the order is always
443 // ColorInternalTexture
444 // Actors texture
445 // Properties textures
446 virtual std::vector<std::pair<vtkTexture*, std::string>> GetTextures(vtkActor* actor);
447
448 // do we have textures coordinates that require special handling
449 virtual bool HaveTCoords(vtkPolyData* poly);
450
451 // values we use to determine if we need to rebuild shaders
452 // stored in a map keyed on the vtkOpenGLHelper, so one
453 // typically entry per type of primitive we render which
454 // matches the shader programs we use
456 {
457 public:
461
462 // Caches the vtkOpenGLRenderPass::RenderPasses() information.
463 // Note: Do not dereference the pointers held by this object. There is no
464 // guarantee that they are still valid!
466 };
467 std::map<const vtkOpenGLHelper*, primitiveInfo> PrimitiveInfo;
468
472
473 // Check the renderpasses in actor's property keys to see if they've changed
474 // render stages:
476
478 vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
479 vtkStateStorage VBOBuildState; // used for determining when to rebuild the VBO
480 vtkStateStorage IBOBuildState; // used for determining whento rebuild the IBOs
482 vtkStateStorage TempState; // can be used to avoid constant allocs/deallocs
484
487
493
494 // if set to true, tcoords will be passed to the
495 // VBO even if the mapper knows of no texture maps
496 // normally tcoords are only added to the VBO if the
497 // mapper has identified a texture map as well.
499
500 virtual void BuildCellTextures(
501 vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation);
502
503 void AppendCellTextures(vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation,
504 std::vector<unsigned char>& colors, std::vector<float>& normals, vtkPolyData* pd,
506
513
516 std::vector<unsigned char> EdgeValues;
518
520 {
521 public:
522 std::string DataArrayName;
525 std::string TextureName;
526 };
527 std::map<std::string, ExtraAttributeValue> ExtraAttributes;
528
530
531 // are we currently drawing spheres/tubes
533 bool DrawingTubes(vtkOpenGLHelper& cellBO, vtkActor* actor);
535
536 // get which opengl mode to use to draw the primitive
537 int GetOpenGLMode(int representation, int primType);
538
539 // get how big to make the points when doing point picking
540 // typically 2 for points, 4 for lines, 6 for surface
542
543 // used to occasionally invoke timers
544 unsigned int TimerQueryCounter;
545
546 // stores the mapping from OpenGL primitives IDs (gl_PrimitiveId) to VTK cells IDs
548
549 // compute and set the maximum point and cell ID used in selection
551
552 virtual void AddPointIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
553 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
554 virtual void AddCellIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
555 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
556
557 vtkNew<vtkCellArray> SelectionArrays[4];
558
559 vtkMTimeType EnvironmentTextureTime = 0;
560 vtkTexture* EnvironmentTexture = nullptr;
561
562private:
564 void operator=(const vtkOpenGLPolyDataMapper&) = delete;
565};
566
567VTK_ABI_NAMESPACE_END
568#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.
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: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:315
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:270
#define VTK_MARSHAL_EXCLUDE_REASON_IS_INTERNAL
#define VTK_MARSHALAUTO
#define VTK_MARSHALEXCLUDE(reason)