VTK  9.2.6
vtkOpenGLPolyDataMapper.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4
5 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
6 All rights reserved.
7 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notice for more information.
12
13=========================================================================*/
116#ifndef vtkOpenGLPolyDataMapper_h
117#define vtkOpenGLPolyDataMapper_h
118
119#include "vtkInformation.h" // for prim struct
120#include "vtkNew.h" // For vtkNew
121#include "vtkOpenGLHelper.h" // used for ivars
122#include "vtkPolyDataMapper.h"
123#include "vtkRenderingOpenGL2Module.h" // For export macro
124#include "vtkShader.h" // for methods
125#include "vtkStateStorage.h" // used for ivars
126
127#include <map> // for map
128#include <tuple> // for tuple
129#include <vector> // for vector
130
131class vtkCellArray;
133class vtkMatrix4x4;
134class vtkMatrix3x3;
137class vtkOpenGLTexture;
141class vtkPoints;
142class vtkTexture;
143class vtkTextureObject;
144class vtkTransform;
146
147class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLPolyDataMapper : public vtkPolyDataMapper
148{
149public:
152 void PrintSelf(ostream& os, vtkIndent indent) override;
153
157 void RenderPiece(vtkRenderer* ren, vtkActor* act) override;
158
160
163 virtual void RenderPieceStart(vtkRenderer* ren, vtkActor* act);
164 virtual void RenderPieceDraw(vtkRenderer* ren, vtkActor* act);
165 virtual void RenderPieceFinish(vtkRenderer* ren, vtkActor* act);
167
174
175 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
210 vtkSetStringMacro(ProcessIdArrayName);
211 vtkGetStringMacro(ProcessIdArrayName);
213
215
224 vtkSetStringMacro(CompositeIdArrayName);
225 vtkGetStringMacro(CompositeIdArrayName);
227
232
234 vtkGetObjectMacro(VBOs, vtkOpenGLVertexBufferObjectGroup);
235
239 virtual void SetVBOShiftScaleMethod(int m);
240 virtual int GetVBOShiftScaleMethod() { return this->ShiftScaleMethod; }
241
256 virtual void SetPauseShiftScale(bool pauseShiftScale) { this->PauseShiftScale = pauseShiftScale; }
257 vtkGetMacro(PauseShiftScale, bool);
258 vtkBooleanMacro(PauseShiftScale, bool);
259
261 {
262 PrimitiveStart = 0,
263 PrimitivePoints = 0,
268 PrimitiveEnd
269 };
270
282 void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
283 int fieldAssociation, int componentno = -1) override;
284
285 // This method will Map the specified data array for use as
286 // a texture coordinate for texture tname. The actual
287 // attribute will be named tname_coord so as to not
288 // conflict with the texture sampler definition which will
289 // be tname.
290 void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
291 int fieldAssociation, int componentno = -1) override;
292
296 void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
297
302
308 vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
309
310protected:
313
315
316 void MapDataArray(const char* vertexAttributeName, const char* dataArrayName,
317 const char* texturename, int fieldAssociation, int componentno);
318
319 // what coordinate should be used for this texture
321
322 // handle updating shift scale based on pose changes
323 virtual void UpdateCameraShiftScale(vtkRenderer* ren, vtkActor* actor);
324
328 void GetCoincidentParameters(vtkRenderer* ren, vtkActor* actor, float& factor, float& offset);
329
335 void ComputeBounds() override;
336
341 virtual void UpdateShaders(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
342
347
351 virtual void BuildShaders(
352 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
353
357 virtual void GetShaderTemplate(
358 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
359
364 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
365
367
372 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act, bool prePass);
374 std::map<vtkShader::Type, vtkShader*> shaders, vtkActor* act);
375 virtual void ReplaceShaderColor(
376 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
377 virtual void ReplaceShaderEdges(
378 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
379 virtual void ReplaceShaderLight(
380 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
382 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
384 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
386 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
388 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
389 virtual void ReplaceShaderClip(
390 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
392 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
394 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
395 virtual void ReplaceShaderDepth(
396 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
398
402 virtual void SetCustomUniforms(vtkOpenGLHelper& cellBO, vtkActor* actor);
403
408
413 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
414
419
424 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
425
429 virtual void UpdateBufferObjects(vtkRenderer* ren, vtkActor* act);
430
435
439 virtual void BuildBufferObjects(vtkRenderer* ren, vtkActor* act);
440
444 virtual void BuildIBO(vtkRenderer* ren, vtkActor* act, vtkPolyData* poly);
445
449 virtual void BuildSelectionIBO(
450 vtkPolyData* poly, std::vector<unsigned int> (&indices)[4], vtkIdType offset);
451
455 virtual void BuildSelectionCache(const char* arrayName, bool selectingPoints, vtkPolyData* poly);
456
457 // The VBO and its layout.
459
460 // Structures for the various cell types we render.
461 vtkOpenGLHelper Primitives[PrimitiveEnd];
462 vtkOpenGLHelper SelectionPrimitives[PrimitiveEnd];
465 bool DrawingSelection = false;
467 vtkMTimeType SelectionTime = 0;
468
469 std::map<std::tuple<unsigned int, unsigned int, vtkIdType>, std::vector<vtkIdType>>
472 bool SelectionCacheForPoints = false;
473 vtkMTimeType SelectionCacheTime = 0;
474 vtkPolyData* SelectionPolyData = nullptr;
475
476 // do we have wide lines that require special handling
478
479 // do we have textures that require special handling
480 virtual bool HaveTextures(vtkActor* actor);
481
482 // how many textures do we have
483 virtual unsigned int GetNumberOfTextures(vtkActor* actor);
484
485 // populate a vector with the textures we have
486 // the order is always
487 // ColorInternalTexture
488 // Actors texture
489 // Properties textures
490 virtual std::vector<std::pair<vtkTexture*, std::string>> GetTextures(vtkActor* actor);
491
492 // do we have textures coordinates that require special handling
493 virtual bool HaveTCoords(vtkPolyData* poly);
494
495 // values we use to determine if we need to rebuild shaders
496 // stored in a map keyed on the vtkOpenGLHelper, so one
497 // typically entry per type of primitive we render which
498 // matches the shader programs we use
500 {
501 public:
505
506 // Caches the vtkOpenGLRenderPass::RenderPasses() information.
507 // Note: Do not dereference the pointers held by this object. There is no
508 // guarantee that they are still valid!
510 };
511 std::map<const vtkOpenGLHelper*, primitiveInfo> PrimitiveInfo;
512
516
517 // Check the renderpasses in actor's property keys to see if they've changed
518 // render stages:
520
522 vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
523 vtkStateStorage VBOBuildState; // used for determining when to rebuild the VBO
524 vtkStateStorage IBOBuildState; // used for determining whento rebuild the IBOs
526 vtkStateStorage TempState; // can be used to avoid constant allocs/deallocs
528
531
536 int ShiftScaleMethod; // for points
538
539 // if set to true, tcoords will be passed to the
540 // VBO even if the mapper knows of no texture maps
541 // normally tcoords are only added to the VBO if the
542 // mapper has identified a texture map as well.
544
545 virtual void BuildCellTextures(
546 vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation);
547
548 void AppendCellTextures(vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation,
549 std::vector<unsigned char>& colors, std::vector<float>& normals, vtkPolyData* pd,
551
558
561 std::vector<unsigned char> EdgeValues;
563
564 // additional picking indirection
569
571 {
572 public:
577 };
578 std::map<std::string, ExtraAttributeValue> ExtraAttributes;
579
581
582 // are we currently drawing spheres/tubes
584 bool DrawingTubes(vtkOpenGLHelper& cellBO, vtkActor* actor);
586
587 // get which opengl mode to use to draw the primitive
588 int GetOpenGLMode(int representation, int primType);
589
590 // get how big to make the points when doing point picking
591 // typically 2 for points, 4 for lines, 6 for surface
593
594 // used to occasionally invoke timers
595 unsigned int TimerQueryCounter;
596
597 // stores the mapping from vtk cells to gl_PrimitiveId
599
600 // compute and set the maximum point and cell ID used in selection
602
603 virtual void AddPointIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
604 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
605 virtual void AddCellIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
606 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
607
608 vtkNew<vtkCellArray> SelectionArrays[4];
609
610private:
612 void operator=(const vtkOpenGLPolyDataMapper&) = delete;
613};
614
615#endif
abstract class specifies interface to map data
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:161
object to represent cell connectivity
Definition: vtkCellArray.h:296
a simple class to control print indentation
Definition: vtkIndent.h:119
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:66
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:151
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.
virtual void SetPauseShiftScale(bool pauseShiftScale)
Pause per-render updates to VBO shift+scale parameters.
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.
vtkTextureObject * CellScalarTexture
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)
vtkTextureObject * CellNormalTexture
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)
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
virtual void SetVBOShiftScaleMethod(int m)
A convenience method for enabling/disabling the VBO's shift+scale transform.
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:149
map vtkPolyData to graphics primitives
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:200
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:76
abstract specification for renderers
Definition: vtkRenderer.h:182
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:178
record modification and/or execution time
Definition: vtkTimeStamp.h:55
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:170
window superclass for vtkRenderWindow
Definition: vtkWindow.h:39
@ offset
Definition: vtkX3D.h:444
@ string
Definition: vtkX3D.h:496
int vtkIdType
Definition: vtkType.h:332
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:287