VTK  9.6.1
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
106
109
113 void SetVBOShiftScaleMethod(int method) override;
114
123 vtkGetMacro(UseProgramPointSize, bool);
124 vtkSetMacro(UseProgramPointSize, bool);
125 vtkBooleanMacro(UseProgramPointSize, bool);
126
127 // NOLINTNEXTLINE(readability-enum-initial-value)
138
150 void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
151 int fieldAssociation, int componentno = -1) override;
152
153 // This method will Map the specified data array for use as
154 // a texture coordinate for texture tname. The actual
155 // attribute will be named tname_coord so as to not
156 // conflict with the texture sampler definition which will
157 // be tname.
158 void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
159 int fieldAssociation, int componentno = -1) override;
160
164 void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
165
170
176 vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
177
178protected:
181
183
184 void MapDataArray(const char* vertexAttributeName, const char* dataArrayName,
185 const char* texturename, int fieldAssociation, int componentno);
186
187 // what coordinate should be used for this texture
188 std::string GetTextureCoordinateName(const char* tname);
189
190 // handle updating shift scale based on pose changes
191 virtual void UpdateCameraShiftScale(vtkRenderer* ren, vtkActor* actor);
192
196 void GetCoincidentParameters(vtkRenderer* ren, vtkActor* actor, float& factor, float& offset);
197
203 void ComputeBounds() override;
204
209 virtual void UpdateShaders(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
210
215
219 virtual void BuildShaders(
220 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
221
225 virtual void GetShaderTemplate(
226 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
227
232 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
233
235
240 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act, bool prePass);
242 std::map<vtkShader::Type, vtkShader*> shaders, vtkActor* act);
243 virtual void ReplaceShaderColor(
244 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
245 virtual void ReplaceShaderEdges(
246 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
247 virtual void ReplaceShaderLight(
248 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
250 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
252 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
254 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
256 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
257 virtual void ReplaceShaderClip(
258 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
260 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
262 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
263 virtual void ReplaceShaderDepth(
264 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
266
270 virtual void SetCustomUniforms(vtkOpenGLHelper& cellBO, vtkActor* actor);
271
276
281 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
282
287
292 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
293
297 virtual void UpdateBufferObjects(vtkRenderer* ren, vtkActor* act);
298
303
307 virtual void BuildBufferObjects(vtkRenderer* ren, vtkActor* act);
308
312 virtual void BuildIBO(vtkRenderer* ren, vtkActor* act, vtkPolyData* poly);
313
317 virtual void BuildSelectionIBO(
318 vtkPolyData* poly, std::vector<unsigned int> (&indices)[4], vtkIdType offset);
319
323 virtual void BuildSelectionCache(const char* arrayName, bool selectingPoints, vtkPolyData* poly);
324
325 // The VBO and its layout.
327
328 // Structures for the various cell types we render.
333 bool DrawingSelection = false;
336
337 std::map<std::tuple<unsigned int, unsigned int, vtkIdType>, std::vector<vtkIdType>>
343
344 // do we have wide lines that require special handling
346
347 // do we have textures that require special handling
348 bool HaveTextures(vtkActor* actor);
349
350 // how many textures do we have
351 unsigned int GetNumberOfTextures(vtkActor* actor);
352
353 typedef std::pair<vtkTexture*, std::string> texinfo;
362 virtual std::vector<texinfo> GetTextures(vtkActor* actor);
363
364 // do we have textures coordinates that require special handling
365 virtual bool HaveTCoords(vtkPolyData* poly);
366
367 // values we use to determine if we need to rebuild shaders
368 // stored in a map keyed on the vtkOpenGLHelper, so one
369 // typically entry per type of primitive we render which
370 // matches the shader programs we use
372 {
373 public:
387
389
391
392 // Caches the vtkOpenGLRenderPass::RenderPasses() information.
393 // Note: Do not dereference the pointers held by this object. There is no
394 // guarantee that they are still valid!
396 };
397 std::map<const vtkOpenGLHelper*, primitiveInfo> PrimitiveInfo;
398
402
403 // Check the renderpasses in actor's property keys to see if they've changed
404 // render stages:
406
408 vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
409 vtkStateStorage VBOBuildState; // used for determining when to rebuild the VBO
410 vtkStateStorage IBOBuildState; // used for determining whento rebuild the IBOs
412 vtkStateStorage TempState; // can be used to avoid constant allocs/deallocs
414
417
423
424 // if set to true, tcoords will be passed to the
425 // VBO even if the mapper knows of no texture maps
426 // normally tcoords are only added to the VBO if the
427 // mapper has identified a texture map as well.
429
430 virtual void BuildCellTextures(
431 vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation);
432
433 void AppendCellTextures(vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation,
434 std::vector<unsigned char>& colors, std::vector<float>& normals, vtkPolyData* pd,
436
443
446 std::vector<unsigned char> EdgeValues;
448
450 {
451 public:
452 std::string DataArrayName;
455 std::string TextureName;
456 };
457 std::map<std::string, ExtraAttributeValue> ExtraAttributes;
458
460
461 // are we currently drawing spheres/tubes
463 bool DrawingTubes(vtkOpenGLHelper& cellBO, vtkActor* actor);
466
467 // get which opengl mode to use to draw the primitive
468 int GetOpenGLMode(int representation, int primType);
469
470 // get how big to make the points when doing point picking
471 // typically 2 for points, 4 for lines, 6 for surface
473
474 // used to occasionally invoke timers
475 unsigned int TimerQueryCounter;
476
477 // stores the mapping from OpenGL primitives IDs (gl_PrimitiveId) to VTK cells IDs
479
480 // compute and set the maximum point and cell ID used in selection
482
483 virtual void AddPointIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
484 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
485 virtual void AddCellIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
486 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
487
489
492
493private:
495 void operator=(const vtkOpenGLPolyDataMapper&) = delete;
496};
497
498VTK_ABI_NAMESPACE_END
499#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.
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)
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
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:50
abstract specification for renderers
Definition vtkRenderer.h:64
Class to make storing and comparing state quick and easy.
In case DepthTextureCompare is true, specify the comparison function in use.
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:368
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:323
#define VTK_MARSHAL_EXCLUDE_REASON_IS_INTERNAL
#define VTK_MARSHALAUTO
#define VTK_MARSHALEXCLUDE(reason)