VTK  9.5.2
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
10
11#ifndef vtkOpenGLLowMemoryPolyDataMapper_h
12#define vtkOpenGLLowMemoryPolyDataMapper_h
13
14#include "vtkPolyDataMapper.h"
15
16#include "vtkCellGraphicsPrimitiveMap.h" // For CellTypeMapperOffsets
17#include "vtkDrawTexturedElements.h" // For parent helper class
18#include "vtkHardwareSelector.h" // For ivar
19#include "vtkOpenGLShaderDeclaration.h" // For ivar
20#include "vtkRenderingOpenGL2Module.h" // For export macro
21#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
22
23#include <array> // for array
24#include <set> // for set
25#include <utility> // for pair
26#include <vector> // for TextureInfo
27
28VTK_ABI_NAMESPACE_BEGIN
34
35class VTKRENDERINGOPENGL2_EXPORT VTK_MARSHALAUTO vtkOpenGLLowMemoryPolyDataMapper
36 : public vtkPolyDataMapper
37#ifndef __VTK_WRAP__
39#endif
40{
41public:
44 void PrintSelf(ostream& os, vtkIndent indent) override;
45
49 void ShallowCopy(vtkAbstractMapper* m) override;
50
57
59 void RenderPiece(vtkRenderer* renderer, vtkActor* actor) override;
60 virtual void RenderPieceStart(vtkRenderer* renderer, vtkActor* actor);
61 virtual void RenderPieceDraw(vtkRenderer* renderer, vtkActor* actor);
62 virtual void RenderPieceFinish(vtkRenderer* renderer, vtkActor* actor);
63
66
68 vtkGetMacro(PopulateSelectionSettings, bool);
70 void SetPopulateSelectionSettings(bool v) { this->PopulateSelectionSettings = v; }
71 void SetVBOShiftScaleMethod(int method) override;
72
79 bool GetSupportsSelection() override { return true; }
80
82 virtual void ResetModsToDefault();
83 void AddMod(const std::string& className);
84 void AddMods(const std::vector<std::string>& classNames);
85 void RemoveMod(const std::string& className);
87
99 void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
100 int fieldAssociation, int componentno = -1) override;
101
102 // This method will Map the specified data array for use as
103 // a texture coordinate for texture tname. The actual
104 // attribute will be named tname_coord so as to not
105 // conflict with the texture sampler definition which will
106 // be tname.
107 void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
108 int fieldAssociation, int componentno = -1) override;
109
113 void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
114
119
125 vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
126
127protected:
130
132 {
133 // Color is obtained by mapping point scalar array. shader will interpolate colors.
135 // Color is obtained by mapping cell scalar array. entire cell will have the same color.
136 Cell,
137 // Similar to `Point`, in addition, mapper already interpolated the scalars and provided a
138 // ColorTextureCoordinate and a ColorTexture.
139 PointTexture,
140 // The color of the entire geometry is specified by the actor's vtkProperty instance.
141 Uniform
142 };
143
145 {
146 // Uses point normals.
148 // Uses cell normals.
149 Cell,
150 // Shader computes a normal for the provoking vertex and passes it down to fragment shader.
151 Primitive
152 };
153
156
157 void MapDataArray(const char* vertexAttributeName, const char* dataArrayName,
158 const char* texturename, int fieldAssociation, int componentno);
159 bool IsUpToDate(vtkRenderer* renderer, vtkActor* actor);
160 bool IsShaderUpToDate(vtkRenderer* renderer, vtkActor* actor);
161 virtual bool IsDataObjectUpToDate();
165 virtual bool BindArraysToTextureBuffers(vtkRenderer* renderer, vtkActor* actor,
168 virtual void UpdateShaders(vtkRenderer* renderer, vtkActor* actor);
170 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
172 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
174 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
175 virtual void ReplaceShaderColor(
176 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
178 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
180 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
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);
188 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
190 vtkRenderer* renderer, vtkActor* actor, std::string& vsSource, std::string& fsSource);
191 void SetShaderParameters(vtkRenderer* renderer, vtkActor* actor);
192 // compute and set the maximum point and cell ID used in selection
194
197 void SetShiftValues(double x, double y, double z);
198 void SetScaleValues(double x, double y, double z);
199 void ComputeShiftScale(vtkRenderer* renderer, vtkActor* actor, vtkDataArray* arrays);
202 virtual void UpdateShiftScale(vtkRenderer* renderer, vtkActor* actor);
203
210
211 using TextureInfo = std::pair<vtkTexture*, std::string>;
212 bool HaveTextures(vtkActor* actor);
213 unsigned int GetNumberOfTextures(vtkActor* actor);
214 std::vector<TextureInfo> GetTextures(vtkActor* actor);
215 std::pair<std::string, std::string> GetTextureCoordinateAndSamplerBufferNames(const char* tname);
216
217 void UpdatePBRStateCache(vtkRenderer* renderer, vtkActor* actor);
218 void UpdateGLSLMods(vtkRenderer* renderer, vtkActor* actor);
219
221 {
222 public:
223 std::string DataArrayName;
226 std::string TextureName;
227 };
228 std::map<std::string, ExtraAttributeValue> ExtraAttributes;
229
233
237 std::vector<std::string> ModNames;
238 std::set<std::string> ModNamesUnique;
239 static std::vector<std::string> DefaultModNames;
240
246 std::vector<vtkOpenGLShaderDeclaration> ShaderDecls;
247
255
257 std::array<double, 3> ShiftValues;
258 std::array<double, 3> ScaleValues;
260 vtkNew<vtkTransform> SSInverseTransform; // Inverse transform which can undo shift + scale.
261 vtkNew<vtkMatrix4x4> SSMatrix; // Transpose of the above inverse transform.
262
264 {
267 bool CanRender = false;
269 bool UsesCellMapBuffer = false;
270 friend std::ostream& operator<<(std::ostream& os, const CellGroupInformation& cg)
271 {
272 os << cg.Offsets << '\n'
273 << "NumberOfElements: " << cg.NumberOfElements << '\n'
274 << "CanRender: " << cg.CanRender << '\n'
275 << "UsesEdgeValueBuffer: " << cg.UsesEdgeValueBuffer << '\n'
276 << "UsesCellMapBuffer: " << cg.UsesCellMapBuffer << '\n';
277 return os;
278 }
279 };
280
284 {
285 std::unique_ptr<vtkOpenGLLowMemoryCellTypeAgent> Agent;
287 std::vector<CellGroupInformation> CellGroups;
288 };
289 std::array<PrimitiveInformation, 4> Primitives;
290 bool DrawingVertices = false;
291 bool HasColors = false;
292 bool HasTangents = false;
293 bool HasPointNormals = false;
294 bool HasCellNormals = false;
296 // if set to true, tcoords will be passed to the
297 // VBO even if the mapper knows of no texture maps
298 // normally tcoords are only added to the VBO if the
299 // mapper has identified a texture map as well.
301
304
307 bool PointPicking = false;
308
310 bool HasAnisotropy = false;
311 bool HasClearCoat = false;
312 bool UsesNormalMap = false;
313 bool UsesCoatNormalMap = false;
314 bool UsesRotationMap = false;
316
317private:
319 void operator=(const vtkOpenGLLowMemoryPolyDataMapper&) = delete;
324
325 vtkNew<vtkMatrix4x4> TempMatrix4;
326};
327
328VTK_ABI_NAMESPACE_END
329#endif // vtkOpenGLLowMemoryPolyDataMapper_h
abstract class specifies interface to map data
represents an object (geometry & properties) in a rendered scene
Definition vtkActor.h:42
@ Point
Send points to the shader.
a simple class to control print indentation
Definition vtkIndent.h:29
Allocate and hold a VTK object.
Definition vtkNew.h:58
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)
std::vector< TextureInfo > GetTextures(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)
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...
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)
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.
std::uintptr_t MapperHashType
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition vtkPolyData.h:72
abstract superclass for all actors, volumes and annotations
Definition vtkProp.h:44
abstract specification for renderers
Definition vtkRenderer.h:60
record modification and/or execution time
window superclass for vtkRenderWindow
Definition vtkWindow.h:26
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:332
#define VTK_MARSHAL_EXCLUDE_REASON_IS_INTERNAL
#define VTK_MARSHALAUTO
#define VTK_MARSHALEXCLUDE(reason)