VTK  9.5.2
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
12
13#ifndef vtkOpenGLPolyDataMapper_h
14#define vtkOpenGLPolyDataMapper_h
15
16#include "vtkInformation.h" // for prim struct
17#include "vtkNew.h" // For vtkNew
18#include "vtkOpenGLHelper.h" // used for ivars
19#include "vtkPolyDataMapper.h"
20#include "vtkRenderingOpenGL2Module.h" // For export macro
21#include "vtkShader.h" // for methods
22#include "vtkStateStorage.h" // used for ivars
23#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
24
25#include <map> // for map
26#include <tuple> // for tuple
27#include <vector> // for vector
28
29VTK_ABI_NAMESPACE_BEGIN
30class vtkCellArray;
32class vtkMatrix4x4;
33class vtkMatrix3x3;
40class vtkPoints;
41class vtkTexture;
43class vtkTransform;
45
46class VTKRENDERINGOPENGL2_EXPORT VTK_MARSHALAUTO vtkOpenGLPolyDataMapper : public vtkPolyDataMapper
47{
48public:
51 void PrintSelf(ostream& os, vtkIndent indent) override;
52
56 void RenderPiece(vtkRenderer* ren, vtkActor* act) override;
57
64
66
69 virtual void RenderPieceStart(vtkRenderer* ren, vtkActor* act);
70 virtual void RenderPieceDraw(vtkRenderer* ren, vtkActor* act);
71 virtual void RenderPieceFinish(vtkRenderer* ren, vtkActor* act);
73
80
82 vtkGetMacro(PopulateSelectionSettings, int);
84 void SetPopulateSelectionSettings(int v) { this->PopulateSelectionSettings = v; }
85
92 bool GetSupportsSelection() override { return true; }
93
94 // used by RenderPiece and functions it calls to reduce
95 // calls to get the input and allow for rendering of
96 // other polydata (not the input)
98
103
106
110 void SetVBOShiftScaleMethod(int method) override;
111
120 vtkGetMacro(UseProgramPointSize, bool);
121 vtkSetMacro(UseProgramPointSize, bool);
122 vtkBooleanMacro(UseProgramPointSize, bool);
123
134
146 void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
147 int fieldAssociation, int componentno = -1) override;
148
149 // This method will Map the specified data array for use as
150 // a texture coordinate for texture tname. The actual
151 // attribute will be named tname_coord so as to not
152 // conflict with the texture sampler definition which will
153 // be tname.
154 void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
155 int fieldAssociation, int componentno = -1) override;
156
160 void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
161
166
172 vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
173
174protected:
177
179
180 void MapDataArray(const char* vertexAttributeName, const char* dataArrayName,
181 const char* texturename, int fieldAssociation, int componentno);
182
183 // what coordinate should be used for this texture
184 std::string GetTextureCoordinateName(const char* tname);
185
186 // handle updating shift scale based on pose changes
187 virtual void UpdateCameraShiftScale(vtkRenderer* ren, vtkActor* actor);
188
192 void GetCoincidentParameters(vtkRenderer* ren, vtkActor* actor, float& factor, float& offset);
193
199 void ComputeBounds() override;
200
205 virtual void UpdateShaders(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
206
211
215 virtual void BuildShaders(
216 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
217
221 virtual void GetShaderTemplate(
222 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
223
228 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
229
231
236 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act, bool prePass);
238 std::map<vtkShader::Type, vtkShader*> shaders, vtkActor* act);
239 virtual void ReplaceShaderColor(
240 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
241 virtual void ReplaceShaderEdges(
242 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
243 virtual void ReplaceShaderLight(
244 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
246 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
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);
253 virtual void ReplaceShaderClip(
254 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
256 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
258 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
259 virtual void ReplaceShaderDepth(
260 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
262
266 virtual void SetCustomUniforms(vtkOpenGLHelper& cellBO, vtkActor* actor);
267
272
277 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
278
283
288 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
289
293 virtual void UpdateBufferObjects(vtkRenderer* ren, vtkActor* act);
294
299
303 virtual void BuildBufferObjects(vtkRenderer* ren, vtkActor* act);
304
308 virtual void BuildIBO(vtkRenderer* ren, vtkActor* act, vtkPolyData* poly);
309
313 virtual void BuildSelectionIBO(
314 vtkPolyData* poly, std::vector<unsigned int> (&indices)[4], vtkIdType offset);
315
319 virtual void BuildSelectionCache(const char* arrayName, bool selectingPoints, vtkPolyData* poly);
320
321 // The VBO and its layout.
323
324 // Structures for the various cell types we render.
329 bool DrawingSelection = false;
332
333 std::map<std::tuple<unsigned int, unsigned int, vtkIdType>, std::vector<vtkIdType>>
339
340 // do we have wide lines that require special handling
342
343 // do we have textures that require special handling
344 virtual bool HaveTextures(vtkActor* actor);
345
346 // how many textures do we have
347 virtual unsigned int GetNumberOfTextures(vtkActor* actor);
348
349 // populate a vector with the textures we have
350 // the order is always
351 // ColorInternalTexture
352 // Actors texture
353 // Properties textures
354 typedef std::pair<vtkTexture*, std::string> texinfo;
355 virtual std::vector<texinfo> GetTextures(vtkActor* actor);
356
357 // do we have textures coordinates that require special handling
358 virtual bool HaveTCoords(vtkPolyData* poly);
359
360 // values we use to determine if we need to rebuild shaders
361 // stored in a map keyed on the vtkOpenGLHelper, so one
362 // typically entry per type of primitive we render which
363 // matches the shader programs we use
365 {
366 public:
380
382
384
385 // Caches the vtkOpenGLRenderPass::RenderPasses() information.
386 // Note: Do not dereference the pointers held by this object. There is no
387 // guarantee that they are still valid!
389 };
390 std::map<const vtkOpenGLHelper*, primitiveInfo> PrimitiveInfo;
391
395
396 // Check the renderpasses in actor's property keys to see if they've changed
397 // render stages:
399
401 vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
402 vtkStateStorage VBOBuildState; // used for determining when to rebuild the VBO
403 vtkStateStorage IBOBuildState; // used for determining whento rebuild the IBOs
405 vtkStateStorage TempState; // can be used to avoid constant allocs/deallocs
407
410
416
417 // if set to true, tcoords will be passed to the
418 // VBO even if the mapper knows of no texture maps
419 // normally tcoords are only added to the VBO if the
420 // mapper has identified a texture map as well.
422
423 virtual void BuildCellTextures(
424 vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation);
425
426 void AppendCellTextures(vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation,
427 std::vector<unsigned char>& colors, std::vector<float>& normals, vtkPolyData* pd,
429
436
439 std::vector<unsigned char> EdgeValues;
441
443 {
444 public:
445 std::string DataArrayName;
448 std::string TextureName;
449 };
450 std::map<std::string, ExtraAttributeValue> ExtraAttributes;
451
453
454 // are we currently drawing spheres/tubes
456 bool DrawingTubes(vtkOpenGLHelper& cellBO, vtkActor* actor);
458
459 // get which opengl mode to use to draw the primitive
460 int GetOpenGLMode(int representation, int primType);
461
462 // get how big to make the points when doing point picking
463 // typically 2 for points, 4 for lines, 6 for surface
465
466 // used to occasionally invoke timers
467 unsigned int TimerQueryCounter;
468
469 // stores the mapping from OpenGL primitives IDs (gl_PrimitiveId) to VTK cells IDs
471
472 // compute and set the maximum point and cell ID used in selection
474
475 virtual void AddPointIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
476 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
477 virtual void AddCellIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
478 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
479
481
484
485private:
487 void operator=(const vtkOpenGLPolyDataMapper&) = delete;
488};
489
490VTK_ABI_NAMESPACE_END
491#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.
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.
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.
virtual std::vector< texinfo > GetTextures(vtkActor *actor)
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 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: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:44
abstract specification for renderers
Definition vtkRenderer.h:60
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:26
int vtkIdType
Definition vtkType.h:332
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:287
#define VTK_MARSHAL_EXCLUDE_REASON_IS_INTERNAL
#define VTK_MARSHALAUTO
#define VTK_MARSHALEXCLUDE(reason)