VTK  9.4.20241103
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
14#ifndef vtkOpenGLLowMemoryPolyDataMapper_h
15#define vtkOpenGLLowMemoryPolyDataMapper_h
16
17#include "vtkPolyDataMapper.h"
18
19#include "vtkCellGraphicsPrimitiveMap.h" // For CellTypeMapperOffsets
20#include "vtkDrawTexturedElements.h" // For parent helper class
21#include "vtkHardwareSelector.h" // For ivar
22#include "vtkOpenGLShaderDeclaration.h" // For ivar
23#include "vtkRenderingOpenGL2Module.h" // For export macro
24#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
25
26#include <array> // for array
27#include <set> // for set
28#include <utility> // for pair
29#include <vector> // for TextureInfo
30
31VTK_ABI_NAMESPACE_BEGIN
37
38class VTKRENDERINGOPENGL2_EXPORT VTK_MARSHALAUTO vtkOpenGLLowMemoryPolyDataMapper
39 : public vtkPolyDataMapper
40#ifndef __VTK_WRAP__
42#endif
43{
44public:
47 void PrintSelf(ostream& os, vtkIndent indent) override;
48
52 void ShallowCopy(vtkAbstractMapper* m) override;
53
60
61 vtkPolyData* CurrentInput = nullptr;
62 void RenderPiece(vtkRenderer* renderer, vtkActor* actor) override;
63 virtual void RenderPieceStart(vtkRenderer* renderer, vtkActor* actor);
64 virtual void RenderPieceDraw(vtkRenderer* renderer, vtkActor* actor);
65 virtual void RenderPieceFinish(vtkRenderer* renderer, vtkActor* actor);
66
69
71 vtkGetMacro(PopulateSelectionSettings, bool);
73 void SetPopulateSelectionSettings(bool v) { this->PopulateSelectionSettings = v; }
74 void SetVBOShiftScaleMethod(int method) override;
75
82 bool GetSupportsSelection() override { return true; }
83
85
96
98
104 vtkSetStdStringFromCharMacro(ProcessIdArrayName);
105 vtkGetCharFromStdStringMacro(ProcessIdArrayName);
107
109
119 vtkSetStdStringFromCharMacro(CompositeIdArrayName);
120 vtkGetCharFromStdStringMacro(CompositeIdArrayName);
122
124 virtual void ResetModsToDefault();
125 void AddMod(const std::string& className);
126 void AddMods(const std::vector<std::string>& classNames);
127 void RemoveMod(const std::string& className);
129
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.
176 Point,
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.
189 Point,
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);
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 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::string DataArrayName;
266 std::string TextureName;
267 };
268 std::map<std::string, ExtraAttributeValue> ExtraAttributes;
269
271 ShaderColorSourceAttribute ShaderColorSource = ShaderColorSourceAttribute::Uniform;
272 ShaderNormalSourceAttribute ShaderNormalSource = ShaderNormalSourceAttribute::Primitive;
273
277 std::vector<std::string> ModNames;
278 std::set<std::string> ModNamesUnique;
279 static std::vector<std::string> DefaultModNames;
280
286 std::vector<vtkOpenGLShaderDeclaration> ShaderDecls;
287
290 int LastSelectionState = vtkHardwareSelector::MIN_KNOWN_PASS - 1;
295
297 std::array<double, 3> ShiftValues;
298 std::array<double, 3> ScaleValues;
300 vtkNew<vtkTransform> SSInverseTransform; // Inverse transform which can undo shift + scale.
301 vtkNew<vtkMatrix4x4> SSMatrix; // Transpose of the above inverse transform.
302
304 {
306 vtkIdType NumberOfElements = 0;
307 bool CanRender = false;
308 bool UsesEdgeValueBuffer = false;
309 bool UsesCellMapBuffer = false;
310 friend std::ostream& operator<<(std::ostream& os, const CellGroupInformation& cg)
311 {
312 os << cg.Offsets << '\n'
313 << "NumberOfElements: " << cg.NumberOfElements << '\n'
314 << "CanRender: " << cg.CanRender << '\n'
315 << "UsesEdgeValueBuffer: " << cg.UsesEdgeValueBuffer << '\n'
316 << "UsesCellMapBuffer: " << cg.UsesCellMapBuffer << '\n';
317 return os;
318 }
319 };
324 {
325 std::unique_ptr<vtkOpenGLLowMemoryCellTypeAgent> Agent;
327 std::vector<CellGroupInformation> CellGroups;
328 };
329 std::array<PrimitiveInformation, 4> Primitives;
330 bool DrawingVertices = false;
331 bool HasColors = false;
332 bool HasTangents = false;
333 bool HasPointNormals = false;
334 bool HasCellNormals = false;
335 bool HasPointTextureCoordinates = false;
336 // if set to true, tcoords will be passed to the
337 // VBO even if the mapper knows of no texture maps
338 // normally tcoords are only added to the VBO if the
339 // mapper has identified a texture map as well.
340 bool ForceTextureCoordinates = false;
341
343 vtkOpenGLTexture* InternalColorTexture = nullptr;
344
346 bool PopulateSelectionSettings = true;
347 bool PointPicking = false;
348 // additional picking indirection
349 std::string PointIdArrayName;
350 std::string CellIdArrayName;
353
355 bool HasAnisotropy = false;
356 bool HasClearCoat = false;
357 bool UsesNormalMap = false;
358 bool UsesCoatNormalMap = false;
359 bool UsesRotationMap = false;
361
362private:
364 void operator=(const vtkOpenGLLowMemoryPolyDataMapper&) = delete;
369};
370
371VTK_ABI_NAMESPACE_END
372#endif // vtkOpenGLLowMemoryPolyDataMapper_h
abstract class specifies interface to map data
represents an object (geometry & properties) in a rendered scene
Definition vtkActor.h:151
abstract superclass for arrays of numeric data
A base class for mappers or render responders that need to draw primitives via vertex-pulling.
@ 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:167
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.
PolyDataMapper using OpenGL to render surface meshes.
vtkSetStdStringFromCharMacro(ProcessIdArrayName)
If this class should override the process id using a data-array, set this variable to the name of the...
virtual void RenderPieceFinish(vtkRenderer *renderer, vtkActor *actor)
void AddMods(const std::vector< std::string > &classNames)
void ReplaceShaderSelection(vtkRenderer *renderer, vtkActor *actor, std::string &vsSource, std::string &fsSource)
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
virtual bool IsShaderColorSourceUpToDate(vtkActor *actor)
virtual void UpdateShiftScale(vtkRenderer *renderer, vtkActor *actor)
void SetShaderParameters(vtkRenderer *renderer, vtkActor *actor)
std::vector< TextureInfo > GetTextures(vtkActor *actor)
void ReplaceShaderEdges(vtkRenderer *renderer, vtkActor *actor, std::string &vsSource, std::string &fsSource)
std::pair< vtkTexture *, std::string > TextureInfo
void SetShiftValues(double x, double y, double z)
vtkSetStdStringFromCharMacro(PointIdArrayName)
By default, this class uses the dataset's point and cell ids during rendering.
ShaderColorSourceAttribute DetermineShaderColorSource(vtkPolyData *mesh)
void ReplaceShaderValues(vtkRenderer *renderer, vtkActor *actor, std::string &vsSource, std::string &fsSource)
void ReplaceShaderNormal(vtkRenderer *renderer, vtkActor *actor, std::string &vsSource, std::string &fsSource)
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)
void ReplaceShaderTCoord(vtkRenderer *renderer, vtkActor *actor, std::string &vsSource, std::string &fsSource)
vtkGetCharFromStdStringMacro(ProcessIdArrayName)
If this class should override the process id using a data-array, set this variable to the name of the...
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
vtkGetCharFromStdStringMacro(PointIdArrayName)
By default, this class uses the dataset's point and cell ids during rendering.
bool IsUpToDate(vtkRenderer *renderer, vtkActor *actor)
void ReplaceShaderWideLines(vtkRenderer *renderer, vtkActor *actor, std::string &vsSource, std::string &fsSource)
virtual vtkDataArray * GetColors(vtkPolyData *mesh)
vtkGetCharFromStdStringMacro(CompositeIdArrayName)
Generally, this class can render the composite id when iterating over composite datasets.
std::array< PrimitiveInformation, 4 > Primitives
static vtkOpenGLLowMemoryPolyDataMapper * New()
void SetScaleValues(double x, double y, double z)
void ComputeCameraBasedShiftScale(vtkRenderer *renderer, vtkActor *actor, vtkPolyData *mesh)
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.
void ComputeShiftScale(vtkRenderer *renderer, vtkActor *actor, vtkDataArray *arrays)
vtkSetStdStringFromCharMacro(CompositeIdArrayName)
Generally, this class can render the composite id when iterating over composite datasets.
vtkDataArray * GetTextureCoordinates(vtkPolyData *mesh)
void UpdateGLSLMods(vtkRenderer *renderer, vtkActor *actor)
vtkDataArray * GetPointTangents(vtkPolyData *mesh)
virtual bool IsShaderNormalSourceUpToDate(vtkActor *actor)
vtkGetCharFromStdStringMacro(CellIdArrayName)
By default, this class uses the dataset's point and cell ids during rendering.
void UpdatePBRStateCache(vtkRenderer *renderer, vtkActor *actor)
ShaderNormalSourceAttribute DetermineShaderNormalSource(vtkActor *actor, vtkPolyData *mesh)
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)
std::pair< std::string, std::string > GetTextureCoordinateAndSamplerBufferNames(const char *tname)
vtkDataArray * GetCellNormals(vtkPolyData *mesh)
void RemoveVertexAttributeMapping(const char *vertexAttributeName) override
Remove a vertex attribute mapping.
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...
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)
vtkSetStdStringFromCharMacro(CellIdArrayName)
By default, this class uses the dataset's point and cell ids during rendering.
vtkDataArray * GetPointNormals(vtkPolyData *mesh)
virtual void ResetModsToDefault()
If you removed all mods, call this to go back to default setting.
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.
map vtkPolyData to graphics primitives
std::uintptr_t MapperHashType
concrete dataset represents vertices, lines, polygons, and triangle strips
abstract superclass for all actors, volumes and annotations
Definition vtkProp.h:66
abstract specification for renderers
record modification and/or execution time
window superclass for vtkRenderWindow
Definition vtkWindow.h:48
vtkCellGraphicsPrimitiveMap::CellTypeMapperOffsets Offsets
friend std::ostream & operator<<(std::ostream &os, const CellGroupInformation &cg)
std::unique_ptr< vtkOpenGLLowMemoryCellTypeAgent > Agent
std::function< vtkCellGraphicsPrimitiveMap::PrimitiveDescriptor(vtkPolyData *)> GeneratorFunction
int vtkIdType
Definition vtkType.h:315
#define VTK_MARSHAL_EXCLUDE_REASON_IS_INTERNAL
#define VTK_MARSHALAUTO
#define VTK_MARSHALEXCLUDE(reason)