VTK  9.7.20260828
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
139 void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
140 int fieldAssociation, int componentno = -1) override;
141
142 // This method will Map the specified data array for use as
143 // a texture coordinate for texture tname. The actual
144 // attribute will be named tname_coord so as to not
145 // conflict with the texture sampler definition which will
146 // be tname.
147 void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
148 int fieldAssociation, int componentno = -1) override;
149
153 void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
154
159
165 vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
166
167protected:
170
172 {
173 // Color is obtained by mapping point scalar array. shader will interpolate colors.
175 // Color is obtained by mapping cell scalar array. entire cell will have the same color.
176 Cell,
177 // Similar to `Point`, in addition, mapper already interpolated the scalars and provided a
178 // ColorTextureCoordinate and a ColorTexture.
179 PointTexture,
180 // The color of the entire geometry is specified by the actor's vtkProperty instance.
181 Uniform
182 };
183
185 {
186 // Uses point normals.
188 // Uses cell normals.
189 Cell,
190 // Shader computes a normal for the provoking vertex and passes it down to fragment shader.
191 Primitive
192 };
193
196
197 void MapDataArray(const char* vertexAttributeName, const char* dataArrayName,
198 const char* texturename, int fieldAssociation, int componentno);
199 bool IsUpToDate(vtkRenderer* renderer, vtkActor* actor);
200 bool IsShaderUpToDate(vtkRenderer* renderer, vtkActor* actor);
201 virtual bool IsDataObjectUpToDate();
205 virtual bool BindArraysToTextureBuffers(vtkRenderer* renderer, vtkActor* actor,
208 virtual void UpdateShaders(vtkRenderer* renderer, vtkActor* actor);
210 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
212 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
214 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
215 virtual void ReplaceShaderColor(
216 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
218 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
220 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
222 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
224 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
226 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
228 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
230 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
231 void SetShaderParameters(vtkRenderer* renderer, vtkActor* actor);
232 // compute and set the maximum point and cell ID used in selection
234
237 void SetShiftValues(double x, double y, double z);
238 void SetScaleValues(double x, double y, double z);
239 void ComputeShiftScale(vtkRenderer* renderer, vtkActor* actor, vtkDataArray* arrays);
242 virtual void UpdateShiftScale(vtkRenderer* renderer, vtkActor* actor);
243
250
251 using TextureInfo = std::pair<vtkTexture*, std::string>;
252 bool HaveTextures(vtkActor* actor);
253 unsigned int GetNumberOfTextures(vtkActor* actor);
254 virtual std::vector<TextureInfo> GetTextures(vtkActor* actor);
255 std::pair<std::string, std::string> GetTextureCoordinateAndSamplerBufferNames(const char* tname);
256
257 void UpdatePBRStateCache(vtkRenderer* renderer, vtkActor* actor);
258 void UpdateGLSLMods(vtkRenderer* renderer, vtkActor* actor);
259
261 {
262 public:
263 std::vector<std::string> DataArrayNames;
266 std::string TextureName;
267 };
268 std::map<std::string, ExtraAttributeValue> ExtraAttributes;
269
273
277 std::vector<std::string> ModNames;
278 std::set<std::string> ModNamesUnique;
279
285 std::vector<vtkOpenGLShaderDeclaration> ShaderDecls;
286
294
296 std::array<double, 3> ShiftValues;
297 std::array<double, 3> ScaleValues;
299 vtkNew<vtkTransform> SSInverseTransform; // Inverse transform which can undo shift + scale.
300 vtkNew<vtkMatrix4x4> SSMatrix; // Transpose of the above inverse transform.
301
303 {
306 bool CanRender = false;
308 bool UsesCellMapBuffer = false;
309 friend std::ostream& operator<<(std::ostream& os, const CellGroupInformation& cg)
310 {
311 os << cg.Offsets << '\n'
312 << "NumberOfElements: " << cg.NumberOfElements << '\n'
313 << "CanRender: " << cg.CanRender << '\n'
314 << "UsesEdgeValueBuffer: " << cg.UsesEdgeValueBuffer << '\n'
315 << "UsesCellMapBuffer: " << cg.UsesCellMapBuffer << '\n';
316 return os;
317 }
318 };
319
323 {
324 std::unique_ptr<vtkOpenGLLowMemoryCellTypeAgent> Agent;
326 std::vector<CellGroupInformation> CellGroups;
327 };
328 std::array<PrimitiveInformation, 4> Primitives;
329
332 bool DrawingVertices = false;
333 bool HasColors = false;
334 bool HasTangents = false;
335 bool HasPointNormals = false;
336 bool HasCellNormals = false;
338 // if set to true, tcoords will be passed to the
339 // VBO even if the mapper knows of no texture maps
340 // normally tcoords are only added to the VBO if the
341 // mapper has identified a texture map as well.
343
346
349 bool PointPicking = false;
350
352 bool HasAnisotropy = false;
353 bool HasClearCoat = false;
354 bool UsesNormalMap = false;
355 bool UsesCoatNormalMap = false;
356 bool UsesRotationMap = false;
358
366 const CellGroupInformation& cellGroup, int numberOfPointsPerPrimitive,
367 int numberOfPseudoPrimitivesPerElement, bool inVertexVisibilityPass) const;
368
376 {
377 // SetShaderParameters
379 int LineWidth = -1;
382 int PointPicking = -1;
383 int VertexColor = -1;
384 int EdgeColor = -1;
385 int EdgeOpacity = -1;
387 int Wireframe = -1;
388 int EdgeWidth = -1;
390 int ZCalcR = -1;
391 int ZCalcS = -1;
393 int ClipPlanes = -1;
394 int MapperIndex = -1;
395 // cell-type agent
396 int CellType = -1;
397 int EnableLights = -1;
398 int VertexPass = -1;
400 int PointCount = -1;
401 int PointSize = -1;
402 int CellIdOffset = -1;
407 int UsesCellMap = -1;
410 } UniformLocs;
412 unsigned int CachedLocLinkCount = 0;
416
417private:
419 void operator=(const vtkOpenGLLowMemoryPolyDataMapper&) = delete;
424
425 vtkNew<vtkMatrix4x4> TempMatrix4;
426};
427
428#define vtkOpenGLLowMemoryPolyDataMapper_OVERRIDE_ATTRIBUTES \
429 vtkOpenGLLowMemoryPolyDataMapper::CreateOverrideAttributes()
430VTK_ABI_NAMESPACE_END
431#endif // vtkOpenGLLowMemoryPolyDataMapper_h
abstract class specifies interface to map data
represents an object (geometry & properties) in a rendered scene
Definition vtkActor.h:151
@ Point
Send points to the shader.
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.
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:68
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:62
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