VTK  9.6.20260626
vtkOpenGLLowMemoryPolyDataMapper.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
16
17#ifndef vtkOpenGLLowMemoryPolyDataMapper_h
18#define vtkOpenGLLowMemoryPolyDataMapper_h
19
20#include "vtkPolyDataMapper.h"
21
22#include "vtkCellGraphicsPrimitiveMap.h" // For CellTypeMapperOffsets
23#include "vtkDrawTexturedElements.h" // For parent helper class
24#include "vtkHardwareSelector.h" // For ivar
25#include "vtkOpenGLShaderDeclaration.h" // For ivar
26#include "vtkRenderingOpenGL2Module.h" // For export macro
27#include "vtkShaderProgram.h" // For vtkWeakPtr<vtkShaderProgram>
28#include "vtkWeakPtr.h" // For vtkWeakPtr
29#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
30
31#include <array> // for array
32#include <set> // for set
33#include <utility> // for pair
34#include <vector> // for TextureInfo
35
36VTK_ABI_NAMESPACE_BEGIN
44
45class VTKRENDERINGOPENGL2_EXPORT VTK_MARSHALAUTO vtkOpenGLLowMemoryPolyDataMapper
46 : public vtkPolyDataMapper
47#ifndef __VTK_WRAP__
49#endif
50{
51public:
56 void PrintSelf(ostream& os, vtkIndent indent) override;
57
61 void ShallowCopy(vtkAbstractMapper* m) override;
62
69
75
77 void RenderPiece(vtkRenderer* renderer, vtkActor* actor) override;
78 virtual void RenderPieceStart(vtkRenderer* renderer, vtkActor* actor);
79 virtual void RenderPieceDraw(vtkRenderer* renderer, vtkActor* actor);
80 virtual void RenderPieceFinish(vtkRenderer* renderer, vtkActor* actor);
81
84
86 vtkGetMacro(PopulateSelectionSettings, bool);
88 void SetPopulateSelectionSettings(bool v) { this->PopulateSelectionSettings = v; }
89 void SetVBOShiftScaleMethod(int method) override;
90
97 bool GetSupportsSelection() override { return true; }
98
100
111 vtkSetMacro(UseIndexedRendering, bool);
112 vtkGetMacro(UseIndexedRendering, bool);
113 vtkBooleanMacro(UseIndexedRendering, bool);
115
117 virtual void ResetModsToDefault();
118 void AddMod(const std::string& className);
119 void AddMods(const std::vector<std::string>& classNames);
120 void RemoveMod(const std::string& className);
122
134 void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
135 int fieldAssociation, int componentno = -1) override;
136
137 // This method will Map the specified data array for use as
138 // a texture coordinate for texture tname. The actual
139 // attribute will be named tname_coord so as to not
140 // conflict with the texture sampler definition which will
141 // be tname.
142 void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
143 int fieldAssociation, int componentno = -1) override;
144
148 void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
149
154
160 vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
161
162protected:
165
167 {
168 // Color is obtained by mapping point scalar array. shader will interpolate colors.
170 // Color is obtained by mapping cell scalar array. entire cell will have the same color.
172 // Similar to `Point`, in addition, mapper already interpolated the scalars and provided a
173 // ColorTextureCoordinate and a ColorTexture.
175 // The color of the entire geometry is specified by the actor's vtkProperty instance.
177 };
178
180 {
181 // Uses point normals.
183 // Uses cell normals.
185 // Shader computes a normal for the provoking vertex and passes it down to fragment shader.
187 };
188
191
192 void MapDataArray(const char* vertexAttributeName, const char* dataArrayName,
193 const char* texturename, int fieldAssociation, int componentno);
194 bool IsUpToDate(vtkRenderer* renderer, vtkActor* actor);
195 bool IsShaderUpToDate(vtkRenderer* renderer, vtkActor* actor);
196 virtual bool IsDataObjectUpToDate();
200 virtual bool BindArraysToTextureBuffers(vtkRenderer* renderer, vtkActor* actor,
203 virtual void UpdateShaders(vtkRenderer* renderer, vtkActor* actor);
205 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
207 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
209 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
210 virtual void ReplaceShaderColor(
211 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
213 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
215 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
217 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
219 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
221 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
223 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
225 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
226 void SetShaderParameters(vtkRenderer* renderer, vtkActor* actor);
227 // compute and set the maximum point and cell ID used in selection
229
232 void SetShiftValues(double x, double y, double z);
233 void SetScaleValues(double x, double y, double z);
234 void ComputeShiftScale(vtkRenderer* renderer, vtkActor* actor, vtkDataArray* arrays);
237 virtual void UpdateShiftScale(vtkRenderer* renderer, vtkActor* actor);
238
245
246 using TextureInfo = std::pair<vtkTexture*, std::string>;
247 bool HaveTextures(vtkActor* actor);
248 unsigned int GetNumberOfTextures(vtkActor* actor);
249 virtual std::vector<TextureInfo> GetTextures(vtkActor* actor);
250 std::pair<std::string, std::string> GetTextureCoordinateAndSamplerBufferNames(const char* tname);
251
252 void UpdatePBRStateCache(vtkRenderer* renderer, vtkActor* actor);
253 void UpdateGLSLMods(vtkRenderer* renderer, vtkActor* actor);
254
256 {
257 public:
258 std::string DataArrayName;
261 std::string TextureName;
262 };
263 std::map<std::string, ExtraAttributeValue> ExtraAttributes;
264
268
272 std::vector<std::string> ModNames;
273 std::set<std::string> ModNamesUnique;
274 static std::vector<std::string> DefaultModNames;
275
281 std::vector<vtkOpenGLShaderDeclaration> ShaderDecls;
282
290
292 std::array<double, 3> ShiftValues;
293 std::array<double, 3> ScaleValues;
295 vtkNew<vtkTransform> SSInverseTransform; // Inverse transform which can undo shift + scale.
296 vtkNew<vtkMatrix4x4> SSMatrix; // Transpose of the above inverse transform.
297
299 {
302 bool CanRender = false;
304 bool UsesCellMapBuffer = false;
305 friend std::ostream& operator<<(std::ostream& os, const CellGroupInformation& cg)
306 {
307 os << cg.Offsets << '\n'
308 << "NumberOfElements: " << cg.NumberOfElements << '\n'
309 << "CanRender: " << cg.CanRender << '\n'
310 << "UsesEdgeValueBuffer: " << cg.UsesEdgeValueBuffer << '\n'
311 << "UsesCellMapBuffer: " << cg.UsesCellMapBuffer << '\n';
312 return os;
313 }
314 };
315
319 {
320 std::unique_ptr<vtkOpenGLLowMemoryCellTypeAgent> Agent;
322 std::vector<CellGroupInformation> CellGroups;
323 };
324 std::array<PrimitiveInformation, 4> Primitives;
325
328 bool DrawingVertices = false;
329 bool HasColors = false;
330 bool HasTangents = false;
331 bool HasPointNormals = false;
332 bool HasCellNormals = false;
334 // if set to true, tcoords will be passed to the
335 // VBO even if the mapper knows of no texture maps
336 // normally tcoords are only added to the VBO if the
337 // mapper has identified a texture map as well.
339
342
345 bool PointPicking = false;
346
348 bool HasAnisotropy = false;
349 bool HasClearCoat = false;
350 bool UsesNormalMap = false;
351 bool UsesCoatNormalMap = false;
352 bool UsesRotationMap = false;
354
362 const CellGroupInformation& cellGroup, int numberOfPointsPerPrimitive,
363 int numberOfPseudoPrimitivesPerElement, bool inVertexVisibilityPass) const;
364
372 {
373 // SetShaderParameters
375 int LineWidth = -1;
378 int PointPicking = -1;
379 int VertexColor = -1;
380 int EdgeColor = -1;
381 int EdgeOpacity = -1;
383 int Wireframe = -1;
384 int EdgeWidth = -1;
386 int ZCalcR = -1;
387 int ZCalcS = -1;
389 int ClipPlanes = -1;
390 int MapperIndex = -1;
391 // cell-type agent
392 int CellType = -1;
393 int EnableLights = -1;
394 int VertexPass = -1;
396 int PointSize = -1;
397 int CellIdOffset = -1;
402 int UsesCellMap = -1;
405 } UniformLocs;
407 unsigned int CachedLocLinkCount = 0;
411
412private:
414 void operator=(const vtkOpenGLLowMemoryPolyDataMapper&) = delete;
419
420 vtkNew<vtkMatrix4x4> TempMatrix4;
421};
422
423#define vtkOpenGLLowMemoryPolyDataMapper_OVERRIDE_ATTRIBUTES \
424 vtkOpenGLLowMemoryPolyDataMapper::CreateOverrideAttributes()
425VTK_ABI_NAMESPACE_END
426#endif // vtkOpenGLLowMemoryPolyDataMapper_h
abstract class specifies interface to map data
represents an object (geometry & properties) in a rendered scene
Definition vtkActor.h:151
a simple class to control print indentation
Definition vtkIndent.h:108
Allocate and hold a VTK object.
Definition vtkNew.h:168
Helps vtkOpenGLLowMemoryPolyDataMapper map and draw cell types from vtkPolyData as OpenGL graphics pr...
Maps VTK_LINE and VTK_POLY_LINE into GL_LINES and draws GL_LINES or GL_POINTS.
virtual void RenderPieceFinish(vtkRenderer *renderer, vtkActor *actor)
vtkOpenGLShaderDeclaration::GLSLDataType GLSLDataType
void AddMods(const std::vector< std::string > &classNames)
void ReplaceShaderSelection(vtkRenderer *renderer, vtkActor *actor, std::string &vsSource, std::string &fsSource)
friend class vtkOpenGLLowMemoryPolygonsAgent
Resolve UniformLocs against the current ShaderProgram if it changed or was relinked since the last ca...
bool HaveTextures(vtkActor *actor)
void RemoveMod(const std::string &className)
void ReplaceShaderImplementationCustomUniforms(vtkRenderer *renderer, vtkActor *actor, std::string &vsSource, std::string &fsSource)
std::vector< vtkOpenGLShaderDeclaration > ShaderDecls
bool UsesRotationMap
Decide whether a particular cell-group draw may use the indexed (glDrawElementsInstanced) fast path.
virtual bool IsShaderColorSourceUpToDate(vtkActor *actor)
virtual void UpdateShiftScale(vtkRenderer *renderer, vtkActor *actor)
void SetShaderParameters(vtkRenderer *renderer, vtkActor *actor)
bool UsesNormalMap
Decide whether a particular cell-group draw may use the indexed (glDrawElementsInstanced) fast path.
bool DrawingVertices
Hybrid surface/expansion dispatch switch. See the public accessors.
void ReplaceShaderEdges(vtkRenderer *renderer, vtkActor *actor, std::string &vsSource, std::string &fsSource)
bool HasCellNormals
Hybrid surface/expansion dispatch switch. See the public accessors.
void ReplaceShaderClip(vtkRenderer *renderer, vtkActor *actor, std::string &vsSource, std::string &fsSource)
unsigned int CachedLocLinkCount
Resolve UniformLocs against the current ShaderProgram if it changed or was relinked since the last ca...
std::pair< vtkTexture *, std::string > TextureInfo
void SetShiftValues(double x, double y, double z)
bool HasTangents
Hybrid surface/expansion dispatch switch. See the public accessors.
ShaderColorSourceAttribute DetermineShaderColorSource(vtkPolyData *mesh)
bool ForceTextureCoordinates
Hybrid surface/expansion dispatch switch. See the public accessors.
void ReplaceShaderValues(vtkRenderer *renderer, vtkActor *actor, std::string &vsSource, std::string &fsSource)
void ReplaceShaderNormal(vtkRenderer *renderer, vtkActor *actor, std::string &vsSource, std::string &fsSource)
vtkOpenGLShaderDeclaration::GLSLPrecisionType GLSLPrecisionType
virtual void ReplaceShaderColor(vtkRenderer *renderer, vtkActor *actor, std::string &vsSource, std::string &fsSource)
virtual void UpdateShaders(vtkRenderer *renderer, vtkActor *actor)
void SetVBOShiftScaleMethod(int method) override
A convenience method for enabling/disabling the VBO's shift+scale transform.
virtual void RenderPieceDraw(vtkRenderer *renderer, vtkActor *actor)
bool ShouldUseIndexedRendering(vtkRenderer *renderer, vtkActor *actor, const CellGroupInformation &cellGroup, int numberOfPointsPerPrimitive, int numberOfPseudoPrimitivesPerElement, bool inVertexVisibilityPass) const
Decide whether a particular cell-group draw may use the indexed (glDrawElementsInstanced) fast path.
void ReplaceShaderTCoord(vtkRenderer *renderer, vtkActor *actor, std::string &vsSource, std::string &fsSource)
void UpdateUniformLocations()
Resolve UniformLocs against the current ShaderProgram if it changed or was relinked since the last ca...
vtkDataArray * GetColorTextureCoordinates(vtkPolyData *mesh)
bool IsShaderUpToDate(vtkRenderer *renderer, vtkActor *actor)
virtual bool BindArraysToTextureBuffers(vtkRenderer *renderer, vtkActor *actor, vtkCellGraphicsPrimitiveMap::CellTypeMapperOffsets &offsets)
void RemoveAllVertexAttributeMappings() override
Remove all vertex attributes.
void ReplaceShaderPosition(vtkRenderer *renderer, vtkActor *actor, std::string &vsSource, std::string &fsSource)
std::map< std::string, ExtraAttributeValue > ExtraAttributes
bool UseIndexedRendering
Hybrid surface/expansion dispatch switch. See the public accessors.
bool IsUpToDate(vtkRenderer *renderer, vtkActor *actor)
void ReplaceShaderWideLines(vtkRenderer *renderer, vtkActor *actor, std::string &vsSource, std::string &fsSource)
virtual vtkDataArray * GetColors(vtkPolyData *mesh)
std::array< PrimitiveInformation, 4 > Primitives
Hybrid surface/expansion dispatch switch. See the public accessors.
static vtkOpenGLLowMemoryPolyDataMapper * New()
void SetScaleValues(double x, double y, double z)
bool HasPointNormals
Hybrid surface/expansion dispatch switch. See the public accessors.
void ComputeCameraBasedShiftScale(vtkRenderer *renderer, vtkActor *actor, vtkPolyData *mesh)
bool HasColors
Hybrid surface/expansion dispatch switch. See the public accessors.
void RenderPiece(vtkRenderer *renderer, vtkActor *actor) override
Implemented by sub classes.
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.
vtkOpenGLShaderDeclaration::GLSLAttributeType GLSLAttributeType
void ComputeShiftScale(vtkRenderer *renderer, vtkActor *actor, vtkDataArray *arrays)
vtkDataArray * GetTextureCoordinates(vtkPolyData *mesh)
void UpdateGLSLMods(vtkRenderer *renderer, vtkActor *actor)
vtkDataArray * GetPointTangents(vtkPolyData *mesh)
vtkTimeStamp PBRStateTimeStamp
Decide whether a particular cell-group draw may use the indexed (glDrawElementsInstanced) fast path.
virtual bool IsShaderNormalSourceUpToDate(vtkActor *actor)
vtkIdType GetMaximumNumberOfTriangles(vtkRenderer *ren) override
Returns the maximum number of triangles renderable based on OpenGL limits.
void UpdatePBRStateCache(vtkRenderer *renderer, vtkActor *actor)
ShaderNormalSourceAttribute DetermineShaderNormalSource(vtkActor *actor, vtkPolyData *mesh)
bool HasAnisotropy
Decide whether a particular cell-group draw may use the indexed (glDrawElementsInstanced) fast path.
void ShallowCopy(vtkAbstractMapper *m) override
Make a shallow copy of this mapper.
void MapDataArrayToMultiTextureAttribute(const char *tname, const char *dataArrayName, int fieldAssociation, int componentno=-1) override
void ReplaceShaderPointSize(vtkRenderer *renderer, vtkActor *actor, std::string &vsSource, std::string &fsSource)
void UpdateMaximumPointCellIds(vtkRenderer *ren, vtkActor *actor)
friend class vtkOpenGLLowMemoryCellTypeAgent
Resolve UniformLocs against the current ShaderProgram if it changed or was relinked since the last ca...
std::pair< std::string, std::string > GetTextureCoordinateAndSamplerBufferNames(const char *tname)
vtkWeakPtr< vtkShaderProgram > CachedLocProgram
Resolve UniformLocs against the current ShaderProgram if it changed or was relinked since the last ca...
vtkDataArray * GetCellNormals(vtkPolyData *mesh)
friend class vtkOpenGLLowMemoryVerticesAgent
Resolve UniformLocs against the current ShaderProgram if it changed or was relinked since the last ca...
void RemoveVertexAttributeMapping(const char *vertexAttributeName) override
Remove a vertex attribute mapping.
static vtkOverrideAttribute * CreateOverrideAttributes()
friend class vtkOpenGLLowMemoryLinesAgent
Resolve UniformLocs against the current ShaderProgram if it changed or was relinked since the last ca...
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 RenderPieceStart(vtkRenderer *renderer, vtkActor *actor)
bool GetSupportsSelection() override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THIS METHOD OUTSIDE OF THE RENDERI...
vtkOpenGLShaderDeclaration::GLSLQualifierType GLSLQualifierType
void ComputeShiftScaleTransform(vtkRenderer *renderer, vtkActor *actor)
unsigned int GetNumberOfTextures(vtkActor *actor)
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources associated with the window.
void MapDataArray(const char *vertexAttributeName, const char *dataArrayName, const char *texturename, int fieldAssociation, int componentno)
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void AddMod(const std::string &className)
bool HasClearCoat
Decide whether a particular cell-group draw may use the indexed (glDrawElementsInstanced) fast path.
bool HasPointTextureCoordinates
Hybrid surface/expansion dispatch switch. See the public accessors.
virtual std::vector< TextureInfo > GetTextures(vtkActor *actor)
vtkDataArray * GetPointNormals(vtkPolyData *mesh)
virtual void ResetModsToDefault()
If you removed all mods, call this to go back to default setting.
bool UsesCoatNormalMap
Decide whether a particular cell-group draw may use the indexed (glDrawElementsInstanced) fast path.
static std::vector< std::string > DefaultModNames
MapperHashType GenerateHash(vtkPolyData *polydata) override
Unique hash based on availability of scalars, normals, tcoords, lookup tables and related attributes ...
Maps VTK_TRIANGLE and VTK_POLYGON into GL_TRIANGLES and draws GL_TRIANGLES or GL_LINES or GL_POINTS.
Maps VTK_VERTEX and VTK_POLY_VERTEX into GL_POINTS and draws GL_POINTS.
OpenGL texture map.
Attribute for vtkObjectFactory overrides.
std::uintptr_t MapperHashType
concrete dataset represents vertices, lines, polygons, and triangle strips
abstract superclass for all actors, volumes and annotations
Definition vtkProp.h:69
abstract specification for renderers
The ShaderProgram uses one or more Shader objects.
record modification and/or execution time
a weak reference to a vtkObjectBase.
Definition vtkWeakPtr.h:52
window superclass for vtkRenderWindow
Definition vtkWindow.h:61
vtkCellGraphicsPrimitiveMap::CellTypeMapperOffsets Offsets
friend std::ostream & operator<<(std::ostream &os, const CellGroupInformation &cg)
std::unique_ptr< vtkOpenGLLowMemoryCellTypeAgent > Agent
std::function< vtkCellGraphicsPrimitiveMap::PrimitiveDescriptor(vtkPolyData *)> GeneratorFunction
#define vtkDataArray
int vtkIdType
Definition vtkType.h:363
#define VTK_MARSHAL_EXCLUDE_REASON_IS_INTERNAL
#define VTK_MARSHALAUTO
#define VTK_MARSHALEXCLUDE(reason)
#define VTK_NEWINSTANCE