VTK  9.4.2
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
211 vtkSetStringMacro(ProcessIdArrayName);
212 vtkGetStringMacro(ProcessIdArrayName);
214
216
226 vtkSetStringMacro(CompositeIdArrayName);
227 vtkGetStringMacro(CompositeIdArrayName);
229
234
236 vtkGetObjectMacro(VBOs, vtkOpenGLVertexBufferObjectGroup);
237
241 void SetVBOShiftScaleMethod(int method) override;
242
251 vtkGetMacro(UseProgramPointSize, bool);
252 vtkSetMacro(UseProgramPointSize, bool);
253 vtkBooleanMacro(UseProgramPointSize, bool);
254
256 {
257 PrimitiveStart = 0,
258 PrimitivePoints = 0,
263 PrimitiveEnd
264 };
265
277 void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
278 int fieldAssociation, int componentno = -1) override;
279
280 // This method will Map the specified data array for use as
281 // a texture coordinate for texture tname. The actual
282 // attribute will be named tname_coord so as to not
283 // conflict with the texture sampler definition which will
284 // be tname.
285 void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
286 int fieldAssociation, int componentno = -1) override;
287
291 void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
292
297
303 vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
304
305protected:
308
310
311 void MapDataArray(const char* vertexAttributeName, const char* dataArrayName,
312 const char* texturename, int fieldAssociation, int componentno);
313
314 // what coordinate should be used for this texture
315 std::string GetTextureCoordinateName(const char* tname);
316
317 // handle updating shift scale based on pose changes
318 virtual void UpdateCameraShiftScale(vtkRenderer* ren, vtkActor* actor);
319
323 void GetCoincidentParameters(vtkRenderer* ren, vtkActor* actor, float& factor, float& offset);
324
330 void ComputeBounds() override;
331
336 virtual void UpdateShaders(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
337
342
346 virtual void BuildShaders(
347 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
348
352 virtual void GetShaderTemplate(
353 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
354
359 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
360
362
367 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act, bool prePass);
369 std::map<vtkShader::Type, vtkShader*> shaders, vtkActor* act);
370 virtual void ReplaceShaderColor(
371 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
372 virtual void ReplaceShaderEdges(
373 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
374 virtual void ReplaceShaderLight(
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);
383 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
384 virtual void ReplaceShaderClip(
385 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
387 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
389 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
390 virtual void ReplaceShaderDepth(
391 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
393
397 virtual void SetCustomUniforms(vtkOpenGLHelper& cellBO, vtkActor* actor);
398
403
408 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
409
414
419 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
420
424 virtual void UpdateBufferObjects(vtkRenderer* ren, vtkActor* act);
425
430
434 virtual void BuildBufferObjects(vtkRenderer* ren, vtkActor* act);
435
439 virtual void BuildIBO(vtkRenderer* ren, vtkActor* act, vtkPolyData* poly);
440
444 virtual void BuildSelectionIBO(
445 vtkPolyData* poly, std::vector<unsigned int> (&indices)[4], vtkIdType offset);
446
450 virtual void BuildSelectionCache(const char* arrayName, bool selectingPoints, vtkPolyData* poly);
451
452 // The VBO and its layout.
454
455 // Structures for the various cell types we render.
456 vtkOpenGLHelper Primitives[PrimitiveEnd];
457 vtkOpenGLHelper SelectionPrimitives[PrimitiveEnd];
460 bool DrawingSelection = false;
462 vtkMTimeType SelectionTime = 0;
463
464 std::map<std::tuple<unsigned int, unsigned int, vtkIdType>, std::vector<vtkIdType>>
467 bool SelectionCacheForPoints = false;
468 vtkMTimeType SelectionCacheTime = 0;
469 vtkPolyData* SelectionPolyData = nullptr;
470
471 // do we have wide lines that require special handling
473
474 // do we have textures that require special handling
475 virtual bool HaveTextures(vtkActor* actor);
476
477 // how many textures do we have
478 virtual unsigned int GetNumberOfTextures(vtkActor* actor);
479
480 // populate a vector with the textures we have
481 // the order is always
482 // ColorInternalTexture
483 // Actors texture
484 // Properties textures
485 typedef std::pair<vtkTexture*, std::string> texinfo;
486 virtual std::vector<texinfo> GetTextures(vtkActor* actor);
487
488 // do we have textures coordinates that require special handling
489 virtual bool HaveTCoords(vtkPolyData* poly);
490
491 // values we use to determine if we need to rebuild shaders
492 // stored in a map keyed on the vtkOpenGLHelper, so one
493 // typically entry per type of primitive we render which
494 // matches the shader programs we use
496 {
497 public:
504 {
505 NoLighting = 0,
506 Headlight = 1,
507 Directional = 2,
508 Positional = 3
509 };
510 LightingTypeEnum LastLightComplexity = NoLighting;
511
513
515
516 // Caches the vtkOpenGLRenderPass::RenderPasses() information.
517 // Note: Do not dereference the pointers held by this object. There is no
518 // guarantee that they are still valid!
520 };
521 std::map<const vtkOpenGLHelper*, primitiveInfo> PrimitiveInfo;
522
526
527 // Check the renderpasses in actor's property keys to see if they've changed
528 // render stages:
530
532 vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
533 vtkStateStorage VBOBuildState; // used for determining when to rebuild the VBO
534 vtkStateStorage IBOBuildState; // used for determining whento rebuild the IBOs
536 vtkStateStorage TempState; // can be used to avoid constant allocs/deallocs
538
541
547
548 // if set to true, tcoords will be passed to the
549 // VBO even if the mapper knows of no texture maps
550 // normally tcoords are only added to the VBO if the
551 // mapper has identified a texture map as well.
553
554 virtual void BuildCellTextures(
555 vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation);
556
557 void AppendCellTextures(vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation,
558 std::vector<unsigned char>& colors, std::vector<float>& normals, vtkPolyData* pd,
560
567
570 std::vector<unsigned char> EdgeValues;
572
573 // additional picking indirection
578
580 {
581 public:
582 std::string DataArrayName;
585 std::string TextureName;
586 };
587 std::map<std::string, ExtraAttributeValue> ExtraAttributes;
588
590
591 // are we currently drawing spheres/tubes
593 bool DrawingTubes(vtkOpenGLHelper& cellBO, vtkActor* actor);
595
596 // get which opengl mode to use to draw the primitive
597 int GetOpenGLMode(int representation, int primType);
598
599 // get how big to make the points when doing point picking
600 // typically 2 for points, 4 for lines, 6 for surface
602
603 // used to occasionally invoke timers
604 unsigned int TimerQueryCounter;
605
606 // stores the mapping from OpenGL primitives IDs (gl_PrimitiveId) to VTK cells IDs
608
609 // compute and set the maximum point and cell ID used in selection
611
612 virtual void AddPointIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
613 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
614 virtual void AddCellIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
615 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
616
617 vtkNew<vtkCellArray> SelectionArrays[4];
618
619 vtkMTimeType EnvironmentTextureTime = 0;
620 vtkTexture* EnvironmentTexture = nullptr;
621
622private:
624 void operator=(const vtkOpenGLPolyDataMapper&) = delete;
625};
626
627VTK_ABI_NAMESPACE_END
628#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: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)