VTK  9.6.20260208
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
13
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
38
39class VTKRENDERINGOPENGL2_EXPORT VTK_MARSHALAUTO vtkOpenGLLowMemoryPolyDataMapper
40 : public vtkPolyDataMapper
41#ifndef __VTK_WRAP__
43#endif
44{
45public:
50 void PrintSelf(ostream& os, vtkIndent indent) override;
51
55 void ShallowCopy(vtkAbstractMapper* m) override;
56
63
69
71 void RenderPiece(vtkRenderer* renderer, vtkActor* actor) override;
72 virtual void RenderPieceStart(vtkRenderer* renderer, vtkActor* actor);
73 virtual void RenderPieceDraw(vtkRenderer* renderer, vtkActor* actor);
74 virtual void RenderPieceFinish(vtkRenderer* renderer, vtkActor* actor);
75
78
80 vtkGetMacro(PopulateSelectionSettings, bool);
82 void SetPopulateSelectionSettings(bool v) { this->PopulateSelectionSettings = v; }
83 void SetVBOShiftScaleMethod(int method) override;
84
91 bool GetSupportsSelection() override { return true; }
92
94 virtual void ResetModsToDefault();
95 void AddMod(const std::string& className);
96 void AddMods(const std::vector<std::string>& classNames);
97 void RemoveMod(const std::string& className);
99
111 void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
112 int fieldAssociation, int componentno = -1) override;
113
114 // This method will Map the specified data array for use as
115 // a texture coordinate for texture tname. The actual
116 // attribute will be named tname_coord so as to not
117 // conflict with the texture sampler definition which will
118 // be tname.
119 void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
120 int fieldAssociation, int componentno = -1) override;
121
125 void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
126
131
137 vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
138
139protected:
142
144 {
145 // Color is obtained by mapping point scalar array. shader will interpolate colors.
147 // Color is obtained by mapping cell scalar array. entire cell will have the same color.
149 // Similar to `Point`, in addition, mapper already interpolated the scalars and provided a
150 // ColorTextureCoordinate and a ColorTexture.
152 // The color of the entire geometry is specified by the actor's vtkProperty instance.
154 };
155
157 {
158 // Uses point normals.
160 // Uses cell normals.
162 // Shader computes a normal for the provoking vertex and passes it down to fragment shader.
164 };
165
168
169 void MapDataArray(const char* vertexAttributeName, const char* dataArrayName,
170 const char* texturename, int fieldAssociation, int componentno);
171 bool IsUpToDate(vtkRenderer* renderer, vtkActor* actor);
172 bool IsShaderUpToDate(vtkRenderer* renderer, vtkActor* actor);
173 virtual bool IsDataObjectUpToDate();
177 virtual bool BindArraysToTextureBuffers(vtkRenderer* renderer, vtkActor* actor,
180 virtual void UpdateShaders(vtkRenderer* renderer, vtkActor* actor);
182 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
184 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
186 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
187 virtual void ReplaceShaderColor(
188 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
190 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
192 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
194 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
196 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
198 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
200 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
202 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
203 void SetShaderParameters(vtkRenderer* renderer, vtkActor* actor);
204 // compute and set the maximum point and cell ID used in selection
206
209 void SetShiftValues(double x, double y, double z);
210 void SetScaleValues(double x, double y, double z);
211 void ComputeShiftScale(vtkRenderer* renderer, vtkActor* actor, vtkDataArray* arrays);
214 virtual void UpdateShiftScale(vtkRenderer* renderer, vtkActor* actor);
215
222
223 using TextureInfo = std::pair<vtkTexture*, std::string>;
224 bool HaveTextures(vtkActor* actor);
225 unsigned int GetNumberOfTextures(vtkActor* actor);
226 virtual std::vector<TextureInfo> GetTextures(vtkActor* actor);
227 std::pair<std::string, std::string> GetTextureCoordinateAndSamplerBufferNames(const char* tname);
228
229 void UpdatePBRStateCache(vtkRenderer* renderer, vtkActor* actor);
230 void UpdateGLSLMods(vtkRenderer* renderer, vtkActor* actor);
231
233 {
234 public:
235 std::string DataArrayName;
238 std::string TextureName;
239 };
240 std::map<std::string, ExtraAttributeValue> ExtraAttributes;
241
245
249 std::vector<std::string> ModNames;
250 std::set<std::string> ModNamesUnique;
251 static std::vector<std::string> DefaultModNames;
252
258 std::vector<vtkOpenGLShaderDeclaration> ShaderDecls;
259
267
269 std::array<double, 3> ShiftValues;
270 std::array<double, 3> ScaleValues;
272 vtkNew<vtkTransform> SSInverseTransform; // Inverse transform which can undo shift + scale.
273 vtkNew<vtkMatrix4x4> SSMatrix; // Transpose of the above inverse transform.
274
276 {
279 bool CanRender = false;
281 bool UsesCellMapBuffer = false;
282 friend std::ostream& operator<<(std::ostream& os, const CellGroupInformation& cg)
283 {
284 os << cg.Offsets << '\n'
285 << "NumberOfElements: " << cg.NumberOfElements << '\n'
286 << "CanRender: " << cg.CanRender << '\n'
287 << "UsesEdgeValueBuffer: " << cg.UsesEdgeValueBuffer << '\n'
288 << "UsesCellMapBuffer: " << cg.UsesCellMapBuffer << '\n';
289 return os;
290 }
291 };
292
296 {
297 std::unique_ptr<vtkOpenGLLowMemoryCellTypeAgent> Agent;
299 std::vector<CellGroupInformation> CellGroups;
300 };
301 std::array<PrimitiveInformation, 4> Primitives;
302 bool DrawingVertices = false;
303 bool HasColors = false;
304 bool HasTangents = false;
305 bool HasPointNormals = false;
306 bool HasCellNormals = false;
308 // if set to true, tcoords will be passed to the
309 // VBO even if the mapper knows of no texture maps
310 // normally tcoords are only added to the VBO if the
311 // mapper has identified a texture map as well.
313
316
319 bool PointPicking = false;
320
322 bool HasAnisotropy = false;
323 bool HasClearCoat = false;
324 bool UsesNormalMap = false;
325 bool UsesCoatNormalMap = false;
326 bool UsesRotationMap = false;
328
329private:
331 void operator=(const vtkOpenGLLowMemoryPolyDataMapper&) = delete;
336
337 vtkNew<vtkMatrix4x4> TempMatrix4;
338};
339
340#define vtkOpenGLLowMemoryPolyDataMapper_OVERRIDE_ATTRIBUTES \
341 vtkOpenGLLowMemoryPolyDataMapper::CreateOverrideAttributes()
342VTK_ABI_NAMESPACE_END
343#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: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.
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)
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)
void ReplaceShaderEdges(vtkRenderer *renderer, vtkActor *actor, std::string &vsSource, std::string &fsSource)
void ReplaceShaderClip(vtkRenderer *renderer, vtkActor *actor, std::string &vsSource, std::string &fsSource)
std::pair< vtkTexture *, std::string > TextureInfo
void SetShiftValues(double x, double y, double z)
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)
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)
void ReplaceShaderTCoord(vtkRenderer *renderer, vtkActor *actor, std::string &vsSource, std::string &fsSource)
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 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
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.
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)
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)
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.
static vtkOverrideAttribute * CreateOverrideAttributes()
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)
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.
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
record modification and/or execution time
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:354
#define VTK_MARSHAL_EXCLUDE_REASON_IS_INTERNAL
#define VTK_MARSHALAUTO
#define VTK_MARSHALEXCLUDE(reason)
#define VTK_NEWINSTANCE