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=========================================================================*/
113#ifndef vtkOpenGLPolyDataMapper_h
114#define vtkOpenGLPolyDataMapper_h
115
116#include "vtkInformation.h" // for prim struct
117#include "vtkNew.h" // For vtkNew
118#include "vtkOpenGLHelper.h" // used for ivars
119#include "vtkPolyDataMapper.h"
120#include "vtkRenderingOpenGL2Module.h" // For export macro
121#include "vtkShader.h" // for methods
122#include "vtkStateStorage.h" // used for ivars
123
124#include <map> // for map
125#include <tuple> // for tuple
126#include <vector> // for vector
127
128class vtkCellArray;
130class vtkMatrix4x4;
131class vtkMatrix3x3;
134class vtkOpenGLTexture;
138class vtkPoints;
139class vtkTexture;
140class vtkTextureObject;
141class vtkTransform;
143
144class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLPolyDataMapper : public vtkPolyDataMapper
145{
146public:
149 void PrintSelf(ostream& os, vtkIndent indent) override;
150
154 void RenderPiece(vtkRenderer* ren, vtkActor* act) override;
155
157
160 virtual void RenderPieceStart(vtkRenderer* ren, vtkActor* act);
161 virtual void RenderPieceDraw(vtkRenderer* ren, vtkActor* act);
162 virtual void RenderPieceFinish(vtkRenderer* ren, vtkActor* act);
164
171
172 vtkGetMacro(PopulateSelectionSettings, int);
173 void SetPopulateSelectionSettings(int v) { this->PopulateSelectionSettings = v; }
174
181 bool GetSupportsSelection() override { return true; }
182
183 // used by RenderPiece and functions it calls to reduce
184 // calls to get the input and allow for rendering of
185 // other polydata (not the input)
187
189
195 vtkSetStringMacro(PointIdArrayName);
196 vtkGetStringMacro(PointIdArrayName);
197 vtkSetStringMacro(CellIdArrayName);
198 vtkGetStringMacro(CellIdArrayName);
200
202
207 vtkSetStringMacro(ProcessIdArrayName);
208 vtkGetStringMacro(ProcessIdArrayName);
210
212
221 vtkSetStringMacro(CompositeIdArrayName);
222 vtkGetStringMacro(CompositeIdArrayName);
224
229
231 vtkGetObjectMacro(VBOs, vtkOpenGLVertexBufferObjectGroup);
232
236 virtual void SetVBOShiftScaleMethod(int m);
237 virtual int GetVBOShiftScaleMethod() { return this->ShiftScaleMethod; }
238
253 virtual void SetPauseShiftScale(bool pauseShiftScale) { this->PauseShiftScale = pauseShiftScale; }
254 vtkGetMacro(PauseShiftScale, bool);
255 vtkBooleanMacro(PauseShiftScale, bool);
256
258 {
259 PrimitiveStart = 0,
260 PrimitivePoints = 0,
265 PrimitiveEnd
266 };
267
279 void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
280 int fieldAssociation, int componentno = -1) override;
281
282 // This method will Map the specified data array for use as
283 // a texture coordinate for texture tname. The actual
284 // attribute will be named tname_coord so as to not
285 // conflict with the texture sampler definition which will
286 // be tname.
287 void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
288 int fieldAssociation, int componentno = -1) override;
289
293 void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
294
299
305 vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
306
307protected:
310
312
313 void MapDataArray(const char* vertexAttributeName, const char* dataArrayName,
314 const char* texturename, int fieldAssociation, int componentno);
315
316 // what coordinate should be used for this texture
318
319 // handle updating shift scale based on pose changes
320 virtual void UpdateCameraShiftScale(vtkRenderer* ren, vtkActor* actor);
321
325 void GetCoincidentParameters(vtkRenderer* ren, vtkActor* actor, float& factor, float& offset);
326
332 void ComputeBounds() override;
333
338 virtual void UpdateShaders(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
339
344
348 virtual void BuildShaders(
349 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
350
354 virtual void GetShaderTemplate(
355 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
356
361 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
362
364
369 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act, bool prePass);
371 std::map<vtkShader::Type, vtkShader*> shaders, vtkActor* act);
372 virtual void ReplaceShaderColor(
373 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
374 virtual void ReplaceShaderEdges(
375 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
376 virtual void ReplaceShaderLight(
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);
385 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
386 virtual void ReplaceShaderClip(
387 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
389 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
391 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
392 virtual void ReplaceShaderDepth(
393 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
395
399 virtual void SetCustomUniforms(vtkOpenGLHelper& cellBO, vtkActor* actor);
400
405
410 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
411
416
421 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
422
426 virtual void UpdateBufferObjects(vtkRenderer* ren, vtkActor* act);
427
432
436 virtual void BuildBufferObjects(vtkRenderer* ren, vtkActor* act);
437
441 virtual void BuildIBO(vtkRenderer* ren, vtkActor* act, vtkPolyData* poly);
442
446 virtual void BuildSelectionIBO(
447 vtkPolyData* poly, std::vector<unsigned int> (&indices)[4], vtkIdType offset);
448
452 virtual void BuildSelectionCache(const char* arrayName, bool selectingPoints, vtkPolyData* poly);
453
454 // The VBO and its layout.
456
457 // Structures for the various cell types we render.
458 vtkOpenGLHelper Primitives[PrimitiveEnd];
459 vtkOpenGLHelper SelectionPrimitives[PrimitiveEnd];
462 bool DrawingSelection = false;
464 vtkMTimeType SelectionTime = 0;
465
466 std::map<std::tuple<unsigned int, unsigned int, vtkIdType>, std::vector<vtkIdType>>
469 bool SelectionCacheForPoints = false;
470 vtkMTimeType SelectionCacheTime = 0;
471 vtkPolyData* SelectionPolyData = nullptr;
472
473 // do we have wide lines that require special handling
475
476 // do we have textures that require special handling
477 virtual bool HaveTextures(vtkActor* actor);
478
479 // how many textures do we have
480 virtual unsigned int GetNumberOfTextures(vtkActor* actor);
481
482 // populate a vector with the textures we have
483 // the order is always
484 // ColorInternalTexture
485 // Actors texture
486 // Properties textures
487 virtual std::vector<std::pair<vtkTexture*, std::string>> GetTextures(vtkActor* actor);
488
489 // do we have textures coordinates that require special handling
490 virtual bool HaveTCoords(vtkPolyData* poly);
491
492 // values we use to determine if we need to rebuild shaders
493 // stored in a map keyed on the vtkOpenGLHelper, so one
494 // typically entry per type of primitive we render which
495 // matches the shader programs we use
497 {
498 public:
502
503 // Caches the vtkOpenGLRenderPass::RenderPasses() information.
504 // Note: Do not dereference the pointers held by this object. There is no
505 // guarantee that they are still valid!
507 };
508 std::map<const vtkOpenGLHelper*, primitiveInfo> PrimitiveInfo;
509
513
514 // Check the renderpasses in actor's property keys to see if they've changed
515 // render stages:
517
519 vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
520 vtkStateStorage VBOBuildState; // used for determining when to rebuild the VBO
521 vtkStateStorage IBOBuildState; // used for determining whento rebuild the IBOs
523 vtkStateStorage TempState; // can be used to avoid constant allocs/deallocs
525
528
533 int ShiftScaleMethod; // for points
535
536 // if set to true, tcoords will be passed to the
537 // VBO even if the mapper knows of no texture maps
538 // normally tcoords are only added to the VBO if the
539 // mapper has identified a texture map as well.
541
542 virtual void BuildCellTextures(
543 vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation);
544
545 void AppendCellTextures(vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation,
546 std::vector<unsigned char>& colors, std::vector<float>& normals, vtkPolyData* pd,
548
555
558 std::vector<unsigned char> EdgeValues;
560
561 // additional picking indirection
566
568 {
569 public:
574 };
575 std::map<std::string, ExtraAttributeValue> ExtraAttributes;
576
578
579 // are we currently drawing spheres/tubes
581 bool DrawingTubes(vtkOpenGLHelper& cellBO, vtkActor* actor);
583
584 // get which opengl mode to use to draw the primitive
585 int GetOpenGLMode(int representation, int primType);
586
587 // get how big to make the points when doing point picking
588 // typically 2 for points, 4 for lines, 6 for surface
590
591 // used to occasionally invoke timers
592 unsigned int TimerQueryCounter;
593
594 // stores the mapping from vtk cells to gl_PrimitiveId
596
597 // compute and set the maximum point and cell ID used in selection
599
600 virtual void AddPointIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
601 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
602 virtual void AddCellIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
603 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
604
605 vtkNew<vtkCellArray> SelectionArrays[4];
606
607private:
609 void operator=(const vtkOpenGLPolyDataMapper&) = delete;
610};
611
612#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:73
abstract specification for renderers
Definition: vtkRenderer.h:179
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:36
@ offset
Definition: vtkX3D.h:444
@ string
Definition: vtkX3D.h:496
int vtkIdType
Definition: vtkType.h:332
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:287