VTK  9.7.20261008
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 <memory> // for unique_ptr
33#include <set> // for set
34#include <utility> // for pair
35#include <vector> // for TextureInfo
36
37VTK_ABI_NAMESPACE_BEGIN
46
47class VTKRENDERINGOPENGL2_EXPORT VTK_MARSHALAUTO vtkOpenGLLowMemoryPolyDataMapper
48 : public vtkPolyDataMapper
49#ifndef __VTK_WRAP__
51#endif
52{
53public:
58 void PrintSelf(ostream& os, vtkIndent indent) override;
59
63 void ShallowCopy(vtkAbstractMapper* m) override;
64
71
77
79 void RenderPiece(vtkRenderer* renderer, vtkActor* actor) override;
80 virtual void RenderPieceStart(vtkRenderer* renderer, vtkActor* actor);
81 virtual void RenderPieceDraw(vtkRenderer* renderer, vtkActor* actor);
82 virtual void RenderPieceFinish(vtkRenderer* renderer, vtkActor* actor);
83
86
88 vtkGetMacro(PopulateSelectionSettings, bool);
90 void SetPopulateSelectionSettings(bool v) { this->PopulateSelectionSettings = v; }
91 void SetVBOShiftScaleMethod(int method) override;
92
99 bool GetSupportsSelection() override { return true; }
100
102
113 vtkSetMacro(UseIndexedRendering, bool);
114 vtkGetMacro(UseIndexedRendering, bool);
115 vtkBooleanMacro(UseIndexedRendering, bool);
117
119 virtual void ResetModsToDefault();
120 void AddMod(const std::string& className);
121 void AddMods(const std::vector<std::string>& classNames);
122 void RemoveMod(const std::string& className);
124
141 void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
142 int fieldAssociation, int componentno = -1) override;
143
144 // This method will Map the specified data array for use as
145 // a texture coordinate for texture tname. The actual
146 // attribute will be named tname_coord so as to not
147 // conflict with the texture sampler definition which will
148 // be tname.
149 void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
150 int fieldAssociation, int componentno = -1) override;
151
155 void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
156
161
167 vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
168
169protected:
172
174 {
175 // Color is obtained by mapping point scalar array. shader will interpolate colors.
177 // Color is obtained by mapping cell scalar array. entire cell will have the same color.
178 Cell,
179 // Similar to `Point`, in addition, mapper already interpolated the scalars and provided a
180 // ColorTextureCoordinate and a ColorTexture.
181 PointTexture,
182 // The color of the entire geometry is specified by the actor's vtkProperty instance.
183 Uniform
184 };
185
187 {
188 // Uses point normals.
190 // Uses cell normals.
191 Cell,
192 // Shader computes a normal for the provoking vertex and passes it down to fragment shader.
193 Primitive
194 };
195
198
199 void MapDataArray(const char* vertexAttributeName, const char* dataArrayName,
200 const char* texturename, int fieldAssociation, int componentno);
201 bool IsUpToDate(vtkRenderer* renderer, vtkActor* actor);
202 bool IsShaderUpToDate(vtkRenderer* renderer, vtkActor* actor);
203 virtual bool IsDataObjectUpToDate();
207 virtual bool BindArraysToTextureBuffers(vtkRenderer* renderer, vtkActor* actor,
210 virtual void UpdateShaders(vtkRenderer* renderer, vtkActor* actor);
212 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
214 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
216 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
217 virtual void ReplaceShaderColor(
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);
232 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
233 void SetShaderParameters(vtkRenderer* renderer, vtkActor* actor);
234 // compute and set the maximum point and cell ID used in selection
236
239 void SetShiftValues(double x, double y, double z);
240 void SetScaleValues(double x, double y, double z);
241 void ComputeShiftScale(vtkRenderer* renderer, vtkActor* actor, vtkDataArray* arrays);
244 virtual void UpdateShiftScale(vtkRenderer* renderer, vtkActor* actor);
245
252
253 using TextureInfo = std::pair<vtkTexture*, std::string>;
254 bool HaveTextures(vtkActor* actor);
255 unsigned int GetNumberOfTextures(vtkActor* actor);
256 virtual std::vector<TextureInfo> GetTextures(vtkActor* actor);
257 std::pair<std::string, std::string> GetTextureCoordinateAndSamplerBufferNames(const char* tname);
258
259 void UpdatePBRStateCache(vtkRenderer* renderer, vtkActor* actor);
260 void UpdateGLSLMods(vtkRenderer* renderer, vtkActor* actor);
261
263 {
264 public:
265 std::vector<std::string> DataArrayNames;
268 std::string TextureName;
269 };
270 std::map<std::string, ExtraAttributeValue> ExtraAttributes;
271
275
279 std::vector<std::string> ModNames;
280 std::set<std::string> ModNamesUnique;
281
287 std::vector<vtkOpenGLShaderDeclaration> ShaderDecls;
288
296
298 std::array<double, 3> ShiftValues;
299 std::array<double, 3> ScaleValues;
301 vtkNew<vtkTransform> SSInverseTransform; // Inverse transform which can undo shift + scale.
302 vtkNew<vtkMatrix4x4> SSMatrix; // Transpose of the above inverse transform.
303
305 {
308 bool CanRender = false;
310 bool UsesCellMapBuffer = false;
311 friend std::ostream& operator<<(std::ostream& os, const CellGroupInformation& cg)
312 {
313 os << cg.Offsets << '\n'
314 << "NumberOfElements: " << cg.NumberOfElements << '\n'
315 << "CanRender: " << cg.CanRender << '\n'
316 << "UsesEdgeValueBuffer: " << cg.UsesEdgeValueBuffer << '\n'
317 << "UsesCellMapBuffer: " << cg.UsesCellMapBuffer << '\n';
318 return os;
319 }
320 };
321
325 {
326 std::unique_ptr<vtkOpenGLLowMemoryCellTypeAgent> Agent;
328 std::vector<CellGroupInformation> CellGroups;
329 };
330 std::array<PrimitiveInformation, 4> Primitives;
331
334 bool DrawingVertices = false;
335 bool HasColors = false;
336 bool HasTangents = false;
337 bool HasPointNormals = false;
338 bool HasCellNormals = false;
340 // if set to true, tcoords will be passed to the
341 // VBO even if the mapper knows of no texture maps
342 // normally tcoords are only added to the VBO if the
343 // mapper has identified a texture map as well.
345
348
351 bool PointPicking = false;
352
354 bool HasAnisotropy = false;
355 bool HasClearCoat = false;
356 bool UsesNormalMap = false;
357 bool UsesCoatNormalMap = false;
358 bool UsesRotationMap = false;
360
368 const CellGroupInformation& cellGroup, int numberOfPointsPerPrimitive,
369 int numberOfPseudoPrimitivesPerElement, bool inVertexVisibilityPass) const;
370
378 {
379 // SetShaderParameters
381 int LineWidth = -1;
384 int PointPicking = -1;
385 int VertexColor = -1;
386 int EdgeColor = -1;
387 int EdgeOpacity = -1;
389 int Wireframe = -1;
390 int EdgeWidth = -1;
392 int ZCalcR = -1;
393 int ZCalcS = -1;
395 int ClipPlanes = -1;
396 int MapperIndex = -1;
397 // cell-type agent
398 int CellType = -1;
399 int EnableLights = -1;
400 int VertexPass = -1;
402 int PointCount = -1;
403 int PointSize = -1;
404 int CellIdOffset = -1;
409 int UsesCellMap = -1;
412 } UniformLocs;
414 unsigned int CachedLocLinkCount = 0;
418
419private:
421 void operator=(const vtkOpenGLLowMemoryPolyDataMapper&) = delete;
426
427 vtkNew<vtkMatrix4x4> TempMatrix4;
428 // used to occasionally invoke timers
429 unsigned int TimerQueryCounter = 1; // init to 1 as 0 indicates we have initiated a request
430 std::unique_ptr<vtkOpenGLRenderTimer> TimerQuery;
431};
432
433#define vtkOpenGLLowMemoryPolyDataMapper_OVERRIDE_ATTRIBUTES \
434 vtkOpenGLLowMemoryPolyDataMapper::CreateOverrideAttributes()
435VTK_ABI_NAMESPACE_END
436#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.
Asynchronously measures GPU execution time for a single event.
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