VTK  9.7.0
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;
49
50class VTKRENDERINGOPENGL2_EXPORT VTK_MARSHALAUTO vtkOpenGLPolyDataMapper : public vtkPolyDataMapper
51{
52public:
57 void PrintSelf(ostream& os, vtkIndent indent) override;
58
62 void RenderPiece(vtkRenderer* ren, vtkActor* act) override;
63
70
76
78
81 virtual void RenderPieceStart(vtkRenderer* ren, vtkActor* act);
82 virtual void RenderPieceDraw(vtkRenderer* ren, vtkActor* act);
83 virtual void RenderPieceFinish(vtkRenderer* ren, vtkActor* act);
85
92
94 vtkGetMacro(PopulateSelectionSettings, int);
96 void SetPopulateSelectionSettings(int v) { this->PopulateSelectionSettings = v; }
97
104 bool GetSupportsSelection() override { return true; }
105
106 // used by RenderPiece and functions it calls to reduce
107 // calls to get the input and allow for rendering of
108 // other polydata (not the input)
110
115
118
122 void SetVBOShiftScaleMethod(int method) override;
123
132 vtkGetMacro(UseProgramPointSize, bool);
133 vtkSetMacro(UseProgramPointSize, bool);
134 vtkBooleanMacro(UseProgramPointSize, bool);
135
136 // NOLINTNEXTLINE(readability-enum-initial-value)
138 {
146 };
147
159 void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
160 int fieldAssociation, int componentno = -1) override;
161
162 // This method will Map the specified data array for use as
163 // a texture coordinate for texture tname. The actual
164 // attribute will be named tname_coord so as to not
165 // conflict with the texture sampler definition which will
166 // be tname.
167 void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
168 int fieldAssociation, int componentno = -1) override;
169
173 void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
174
179
185 vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
186
187protected:
190
192
193 void MapDataArray(const char* vertexAttributeName, const char* dataArrayName,
194 const char* texturename, int fieldAssociation, int componentno);
195
196 // what coordinate should be used for this texture
197 std::string GetTextureCoordinateName(const char* tname);
198
199 // handle updating shift scale based on pose changes
200 virtual void UpdateCameraShiftScale(vtkRenderer* ren, vtkActor* actor);
201
205 void GetCoincidentParameters(vtkRenderer* ren, vtkActor* actor, float& factor, float& offset);
206
212 void ComputeBounds() override;
213
218 virtual void UpdateShaders(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
219
224
228 virtual void BuildShaders(
229 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
230
234 virtual void GetShaderTemplate(
235 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
236
241 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
242
244
249 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act, bool prePass);
251 std::map<vtkShader::Type, vtkShader*> shaders, vtkActor* act);
252 virtual void ReplaceShaderColor(
253 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
254 virtual void ReplaceShaderEdges(
255 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
256 virtual void ReplaceShaderLight(
257 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
259 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
261 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
263 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
265 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
266 virtual void ReplaceShaderClip(
267 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
269 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
271 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
272 virtual void ReplaceShaderDepth(
273 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
275
279 virtual void SetCustomUniforms(vtkOpenGLHelper& cellBO, vtkActor* actor);
280
285
290 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
291
296
301 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
302
306 virtual void UpdateBufferObjects(vtkRenderer* ren, vtkActor* act);
307
312
316 virtual void BuildBufferObjects(vtkRenderer* ren, vtkActor* act);
317
321 virtual void BuildIBO(vtkRenderer* ren, vtkActor* act, vtkPolyData* poly);
322
326 virtual void BuildSelectionIBO(
327 vtkPolyData* poly, std::vector<unsigned int> (&indices)[4], vtkIdType offset);
328
332 virtual void BuildSelectionCache(const char* arrayName, bool selectingPoints, vtkPolyData* poly);
333
334 // The VBO and its layout.
336
337 // Structures for the various cell types we render.
342 bool DrawingSelection = false;
345
346 std::map<std::tuple<unsigned int, unsigned int, vtkIdType>, std::vector<vtkIdType>>
352
353 // do we have wide lines that require special handling
355
356 // do we have textures that require special handling
357 bool HaveTextures(vtkActor* actor);
358
359 // how many textures do we have
360 unsigned int GetNumberOfTextures(vtkActor* actor);
361
362 typedef std::pair<vtkTexture*, std::string> texinfo;
371 virtual std::vector<texinfo> GetTextures(vtkActor* actor);
372
373 // do we have textures coordinates that require special handling
374 virtual bool HaveTCoords(vtkPolyData* poly);
375
376 // values we use to determine if we need to rebuild shaders
377 // stored in a map keyed on the vtkOpenGLHelper, so one
378 // typically entry per type of primitive we render which
379 // matches the shader programs we use
381 {
382 public:
389 {
394 };
396
398
400
401 // Caches the vtkOpenGLRenderPass::RenderPasses() information.
402 // Note: Do not dereference the pointers held by this object. There is no
403 // guarantee that they are still valid!
405 };
406 std::map<const vtkOpenGLHelper*, primitiveInfo> PrimitiveInfo;
407
411
412 // Check the renderpasses in actor's property keys to see if they've changed
413 // render stages:
415
417 vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
418 vtkStateStorage VBOBuildState; // used for determining when to rebuild the VBO
419 vtkStateStorage IBOBuildState; // used for determining whento rebuild the IBOs
421 vtkStateStorage TempState; // can be used to avoid constant allocs/deallocs
423
426
432
433 // if set to true, tcoords will be passed to the
434 // VBO even if the mapper knows of no texture maps
435 // normally tcoords are only added to the VBO if the
436 // mapper has identified a texture map as well.
438
439 virtual void BuildCellTextures(
440 vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation);
441
442 void AppendCellTextures(vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation,
443 std::vector<unsigned char>& colors, std::vector<float>& normals, vtkPolyData* pd,
445
452
455 std::vector<unsigned char> EdgeValues;
457
459 {
460 public:
461 std::string DataArrayName;
464 std::string TextureName;
465 };
466 std::map<std::string, ExtraAttributeValue> ExtraAttributes;
467
469
470 // are we currently drawing spheres/tubes
472 bool DrawingLines(vtkOpenGLHelper& cellBO, vtkActor* actor);
473 bool DrawingTubes(vtkOpenGLHelper& cellBO, vtkActor* actor);
476
477 // get which opengl mode to use to draw the primitive
478 int GetOpenGLMode(int representation, int primType);
479
480 // get how big to make the points when doing point picking
481 // typically 2 for points, 4 for lines, 6 for surface
483
484 // used to occasionally invoke timers
485 unsigned int TimerQueryCounter;
486
487 // stores the mapping from OpenGL primitives IDs (gl_PrimitiveId) to VTK cells IDs
489
490 // compute and set the maximum point and cell ID used in selection
492
493 virtual void AddPointIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
494 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
495 virtual void AddCellIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
496 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
497
499
502
503private:
505 void operator=(const vtkOpenGLPolyDataMapper&) = delete;
506};
507
508#define vtkOpenGLPolyDataMapper_OVERRIDE_ATTRIBUTES \
509 vtkOpenGLPolyDataMapper::CreateOverrideAttributes()
510VTK_ABI_NAMESPACE_END
511#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:59
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
bool DrawingLines(vtkOpenGLHelper &cellBO, 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)
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:31
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:42
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