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=========================================================================*/
36#ifndef vtkOpenGLPolyDataMapper_h
37#define vtkOpenGLPolyDataMapper_h
38
39#include "vtkInformation.h" // for prim struct
40#include "vtkNew.h" // For vtkNew
41#include "vtkOpenGLHelper.h" // used for ivars
42#include "vtkPolyDataMapper.h"
43#include "vtkRenderingOpenGL2Module.h" // For export macro
44#include "vtkShader.h" // for methods
45#include "vtkStateStorage.h" // used for ivars
46
47#include <map> // for map
48#include <tuple> // for tuple
49#include <vector> // for vector
50
51class vtkCellArray;
53class vtkMatrix4x4;
54class vtkMatrix3x3;
61class vtkPoints;
62class vtkTexture;
64class vtkTransform;
66
67class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLPolyDataMapper : public vtkPolyDataMapper
68{
69public:
72 void PrintSelf(ostream& os, vtkIndent indent) override;
73
77 void RenderPiece(vtkRenderer* ren, vtkActor* act) override;
78
80
83 virtual void RenderPieceStart(vtkRenderer* ren, vtkActor* act);
84 virtual void RenderPieceDraw(vtkRenderer* ren, vtkActor* act);
85 virtual void RenderPieceFinish(vtkRenderer* ren, vtkActor* act);
87
94
95 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
112
118 vtkSetStringMacro(PointIdArrayName);
119 vtkGetStringMacro(PointIdArrayName);
120 vtkSetStringMacro(CellIdArrayName);
121 vtkGetStringMacro(CellIdArrayName);
123
125
130 vtkSetStringMacro(ProcessIdArrayName);
131 vtkGetStringMacro(ProcessIdArrayName);
133
135
144 vtkSetStringMacro(CompositeIdArrayName);
145 vtkGetStringMacro(CompositeIdArrayName);
147
152
154 vtkGetObjectMacro(VBOs, vtkOpenGLVertexBufferObjectGroup);
155
159 virtual void SetVBOShiftScaleMethod(int m);
160 virtual int GetVBOShiftScaleMethod() { return this->ShiftScaleMethod; }
161
176 virtual void SetPauseShiftScale(bool pauseShiftScale) { this->PauseShiftScale = pauseShiftScale; }
177 vtkGetMacro(PauseShiftScale, bool);
178 vtkBooleanMacro(PauseShiftScale, bool);
179
181 {
182 PrimitiveStart = 0,
183 PrimitivePoints = 0,
188 PrimitiveEnd
189 };
190
202 void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
203 int fieldAssociation, int componentno = -1) override;
204
205 // This method will Map the specified data array for use as
206 // a texture coordinate for texture tname. The actual
207 // attribute will be named tname_coord so as to not
208 // conflict with the texture sampler definition which will
209 // be tname.
210 void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
211 int fieldAssociation, int componentno = -1) override;
212
216 void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
217
222
228 vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
229
230protected:
233
235
236 void MapDataArray(const char* vertexAttributeName, const char* dataArrayName,
237 const char* texturename, int fieldAssociation, int componentno);
238
239 // what coordinate should be used for this texture
240 std::string GetTextureCoordinateName(const char* tname);
241
242 // handle updating shift scale based on pose changes
243 virtual void UpdateCameraShiftScale(vtkRenderer* ren, vtkActor* actor);
244
248 void GetCoincidentParameters(vtkRenderer* ren, vtkActor* actor, float& factor, float& offset);
249
255 void ComputeBounds() override;
256
261 virtual void UpdateShaders(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
262
267
271 virtual void BuildShaders(
272 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
273
277 virtual void GetShaderTemplate(
278 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
279
284 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
285
287
292 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act, bool prePass);
294 std::map<vtkShader::Type, vtkShader*> shaders, vtkActor* act);
295 virtual void ReplaceShaderColor(
296 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
297 virtual void ReplaceShaderEdges(
298 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
299 virtual void ReplaceShaderLight(
300 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
302 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
304 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
306 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
308 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
309 virtual void ReplaceShaderClip(
310 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
312 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
314 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
315 virtual void ReplaceShaderDepth(
316 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
318
322 virtual void SetCustomUniforms(vtkOpenGLHelper& cellBO, vtkActor* actor);
323
328
333 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
334
339
344 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
345
349 virtual void UpdateBufferObjects(vtkRenderer* ren, vtkActor* act);
350
355
359 virtual void BuildBufferObjects(vtkRenderer* ren, vtkActor* act);
360
364 virtual void BuildIBO(vtkRenderer* ren, vtkActor* act, vtkPolyData* poly);
365
369 virtual void BuildSelectionIBO(
370 vtkPolyData* poly, std::vector<unsigned int> (&indices)[4], vtkIdType offset);
371
375 virtual void BuildSelectionCache(const char* arrayName, bool selectingPoints, vtkPolyData* poly);
376
377 // The VBO and its layout.
379
380 // Structures for the various cell types we render.
381 vtkOpenGLHelper Primitives[PrimitiveEnd];
382 vtkOpenGLHelper SelectionPrimitives[PrimitiveEnd];
385 bool DrawingSelection = false;
387 vtkMTimeType SelectionTime = 0;
388
389 std::map<std::tuple<unsigned int, unsigned int, vtkIdType>, std::vector<vtkIdType>>
392 bool SelectionCacheForPoints = false;
393 vtkMTimeType SelectionCacheTime = 0;
394 vtkPolyData* SelectionPolyData = nullptr;
395
396 // do we have wide lines that require special handling
398
399 // do we have textures that require special handling
400 virtual bool HaveTextures(vtkActor* actor);
401
402 // how many textures do we have
403 virtual unsigned int GetNumberOfTextures(vtkActor* actor);
404
405 // populate a vector with the textures we have
406 // the order is always
407 // ColorInternalTexture
408 // Actors texture
409 // Properties textures
410 virtual std::vector<std::pair<vtkTexture*, std::string>> GetTextures(vtkActor* actor);
411
412 // do we have textures coordinates that require special handling
413 virtual bool HaveTCoords(vtkPolyData* poly);
414
415 // values we use to determine if we need to rebuild shaders
416 // stored in a map keyed on the vtkOpenGLHelper, so one
417 // typically entry per type of primitive we render which
418 // matches the shader programs we use
420 {
421 public:
425
426 // Caches the vtkOpenGLRenderPass::RenderPasses() information.
427 // Note: Do not dereference the pointers held by this object. There is no
428 // guarantee that they are still valid!
430 };
431 std::map<const vtkOpenGLHelper*, primitiveInfo> PrimitiveInfo;
432
436
437 // Check the renderpasses in actor's property keys to see if they've changed
438 // render stages:
440
442 vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
443 vtkStateStorage VBOBuildState; // used for determining when to rebuild the VBO
444 vtkStateStorage IBOBuildState; // used for determining whento rebuild the IBOs
446 vtkStateStorage TempState; // can be used to avoid constant allocs/deallocs
448
451
456 int ShiftScaleMethod; // for points
458
459 // if set to true, tcoords will be passed to the
460 // VBO even if the mapper knows of no texture maps
461 // normally tcoords are only added to the VBO if the
462 // mapper has identified a texture map as well.
464
465 virtual void BuildCellTextures(
466 vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation);
467
468 void AppendCellTextures(vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation,
469 std::vector<unsigned char>& colors, std::vector<float>& normals, vtkPolyData* pd,
471
478
481 std::vector<unsigned char> EdgeValues;
483
484 // additional picking indirection
489
491 {
492 public:
493 std::string DataArrayName;
496 std::string TextureName;
497 };
498 std::map<std::string, ExtraAttributeValue> ExtraAttributes;
499
501
502 // are we currently drawing spheres/tubes
504 bool DrawingTubes(vtkOpenGLHelper& cellBO, vtkActor* actor);
506
507 // get which opengl mode to use to draw the primitive
508 int GetOpenGLMode(int representation, int primType);
509
510 // get how big to make the points when doing point picking
511 // typically 2 for points, 4 for lines, 6 for surface
513
514 // used to occasionally invoke timers
515 unsigned int TimerQueryCounter;
516
517 // stores the mapping from vtk cells to gl_PrimitiveId
519
520 // compute and set the maximum point and cell ID used in selection
522
523 virtual void AddPointIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
524 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
525 virtual void AddCellIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
526 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
527
528 vtkNew<vtkCellArray> SelectionArrays[4];
529
530private:
532 void operator=(const vtkOpenGLPolyDataMapper&) = delete;
533};
534
535#endif
abstract class specifies interface to map data
represents an object (geometry & properties) in a rendered scene
Definition vtkActor.h:61
object to represent cell connectivity
a simple class to control print indentation
Definition vtkIndent.h:49
represent and manipulate 3x3 transformation matrices
represent and manipulate 4x4 transformation matrices
Allocate and hold a VTK object.
Definition vtkNew.h:71
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.
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)
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:49
map vtkPolyData to graphics primitives
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
Definition vtkRenderer.h:82
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:78
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:332
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:287