VTK  9.4.20250219
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 virtual void ResetModsToDefault();
86 void AddMod(const std::string& className);
87 void AddMods(const std::vector<std::string>& classNames);
88 void RemoveMod(const std::string& className);
90
102 void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
103 int fieldAssociation, int componentno = -1) override;
104
105 // This method will Map the specified data array for use as
106 // a texture coordinate for texture tname. The actual
107 // attribute will be named tname_coord so as to not
108 // conflict with the texture sampler definition which will
109 // be tname.
110 void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
111 int fieldAssociation, int componentno = -1) override;
112
116 void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
117
122
128 vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
129
130protected:
133
135 {
136 // Color is obtained by mapping point scalar array. shader will interpolate colors.
137 Point,
138 // Color is obtained by mapping cell scalar array. entire cell will have the same color.
139 Cell,
140 // Similar to `Point`, in addition, mapper already interpolated the scalars and provided a
141 // ColorTextureCoordinate and a ColorTexture.
142 PointTexture,
143 // The color of the entire geometry is specified by the actor's vtkProperty instance.
144 Uniform
145 };
146
148 {
149 // Uses point normals.
150 Point,
151 // Uses cell normals.
152 Cell,
153 // Shader computes a normal for the provoking vertex and passes it down to fragment shader.
154 Primitive
155 };
156
159
160 void MapDataArray(const char* vertexAttributeName, const char* dataArrayName,
161 const char* texturename, int fieldAssociation, int componentno);
162 bool IsUpToDate(vtkRenderer* renderer, vtkActor* actor);
163 bool IsShaderUpToDate(vtkRenderer* renderer, vtkActor* actor);
164 virtual bool IsDataObjectUpToDate();
168 virtual bool BindArraysToTextureBuffers(vtkRenderer* renderer, vtkActor* actor,
171 virtual void UpdateShaders(vtkRenderer* renderer, vtkActor* actor);
173 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
175 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
177 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
178 virtual void ReplaceShaderColor(
179 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
181 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
183 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
185 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
187 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
189 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
191 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
192 void SetShaderParameters(vtkRenderer* renderer, vtkActor* actor);
193 // compute and set the maximum point and cell ID used in selection
195
198 void SetShiftValues(double x, double y, double z);
199 void SetScaleValues(double x, double y, double z);
200 void ComputeShiftScale(vtkRenderer* renderer, vtkActor* actor, vtkDataArray* arrays);
203 virtual void UpdateShiftScale(vtkRenderer* renderer, vtkActor* actor);
204
211
212 using TextureInfo = std::pair<vtkTexture*, std::string>;
213 bool HaveTextures(vtkActor* actor);
214 unsigned int GetNumberOfTextures(vtkActor* actor);
215 std::vector<TextureInfo> GetTextures(vtkActor* actor);
216 std::pair<std::string, std::string> GetTextureCoordinateAndSamplerBufferNames(const char* tname);
217
218 void UpdatePBRStateCache(vtkRenderer* renderer, vtkActor* actor);
219 void UpdateGLSLMods(vtkRenderer* renderer, vtkActor* actor);
220
222 {
223 public:
224 std::string DataArrayName;
227 std::string TextureName;
228 };
229 std::map<std::string, ExtraAttributeValue> ExtraAttributes;
230
232 ShaderColorSourceAttribute ShaderColorSource = ShaderColorSourceAttribute::Uniform;
233 ShaderNormalSourceAttribute ShaderNormalSource = ShaderNormalSourceAttribute::Primitive;
234
238 std::vector<std::string> ModNames;
239 std::set<std::string> ModNamesUnique;
240 static std::vector<std::string> DefaultModNames;
241
247 std::vector<vtkOpenGLShaderDeclaration> ShaderDecls;
248
251 int LastSelectionState = vtkHardwareSelector::MIN_KNOWN_PASS - 1;
256
258 std::array<double, 3> ShiftValues;
259 std::array<double, 3> ScaleValues;
261 vtkNew<vtkTransform> SSInverseTransform; // Inverse transform which can undo shift + scale.
262 vtkNew<vtkMatrix4x4> SSMatrix; // Transpose of the above inverse transform.
263
265 {
267 vtkIdType NumberOfElements = 0;
268 bool CanRender = false;
269 bool UsesEdgeValueBuffer = false;
270 bool UsesCellMapBuffer = false;
271 friend std::ostream& operator<<(std::ostream& os, const CellGroupInformation& cg)
272 {
273 os << cg.Offsets << '\n'
274 << "NumberOfElements: " << cg.NumberOfElements << '\n'
275 << "CanRender: " << cg.CanRender << '\n'
276 << "UsesEdgeValueBuffer: " << cg.UsesEdgeValueBuffer << '\n'
277 << "UsesCellMapBuffer: " << cg.UsesCellMapBuffer << '\n';
278 return os;
279 }
280 };
285 {
286 std::unique_ptr<vtkOpenGLLowMemoryCellTypeAgent> Agent;
288 std::vector<CellGroupInformation> CellGroups;
289 };
290 std::array<PrimitiveInformation, 4> Primitives;
291 bool DrawingVertices = false;
292 bool HasColors = false;
293 bool HasTangents = false;
294 bool HasPointNormals = false;
295 bool HasCellNormals = false;
296 bool HasPointTextureCoordinates = false;
297 // if set to true, tcoords will be passed to the
298 // VBO even if the mapper knows of no texture maps
299 // normally tcoords are only added to the VBO if the
300 // mapper has identified a texture map as well.
301 bool ForceTextureCoordinates = false;
302
304 vtkOpenGLTexture* InternalColorTexture = nullptr;
305
307 bool PopulateSelectionSettings = true;
308 bool PointPicking = false;
309
311 bool HasAnisotropy = false;
312 bool HasClearCoat = false;
313 bool UsesNormalMap = false;
314 bool UsesCoatNormalMap = false;
315 bool UsesRotationMap = false;
317
318private:
320 void operator=(const vtkOpenGLLowMemoryPolyDataMapper&) = delete;
325};
326
327VTK_ABI_NAMESPACE_END
328#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.
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)
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)
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.
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)
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)
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)