VTK  9.7.1
vtkDrawTexturedElements.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
15 #ifndef vtkDrawTexturedElements_h
16 #define vtkDrawTexturedElements_h
17 
18 #include "vtkRenderingOpenGL2Module.h" // For export macro
19 
20 #include "vtkNew.h" // for ivar
21 #include "vtkOpenGLArrayTextureBufferAdapter.h" // for ivar
22 #include "vtkOpenGLTexture.h" // for ivar
23 #include "vtkOpenGLVertexArrayObject.h" // for ivar
24 #include "vtkShader.h" // for ivar
25 #include "vtkSmartPointer.h" // for ivar
26 #include "vtkStringToken.h" // for passing shader and array names
27 
28 #include <unordered_map>
29 
30 VTK_ABI_NAMESPACE_BEGIN
31 
32 class vtkActor;
33 class vtkDataArray;
34 class vtkGLSLRuntimeModBase;
35 class vtkMapper;
36 class vtkMatrix3x3;
37 class vtkMatrix4x4;
40 class vtkOpenGLTexture;
41 class vtkRenderer;
42 class vtkScalarsToColors;
43 class vtkShaderProgram;
44 class vtkTextureObject;
45 class vtkWindow;
46 
47 class VTKRENDERINGOPENGL2_EXPORT vtkDrawTexturedElements
48 {
49 public:
51  virtual ~vtkDrawTexturedElements();
52 
55  {
57  Line,
62  AbstractPatches
63  };
64 
67  {
71  };
72 
74  vtkShader* GetShader(vtkShader::Type shaderType);
75 
82  void BindArrayToTexture(vtkStringToken textureName, vtkDataArray* array, bool asScalars = false);
83  void AppendArrayToTexture(
84  vtkStringToken textureName, vtkDataArray* array, bool asScalars = false);
85  bool UnbindArray(vtkStringToken);
86 
96  void BeginArrayRebuild();
97 
99  vtkIdType GetNumberOfInstances() { return this->NumberOfInstances; }
100  virtual bool SetNumberOfInstances(vtkIdType numberOfInstances);
101 
103  vtkIdType GetNumberOfElements() { return this->NumberOfElements; }
104  virtual bool SetNumberOfElements(vtkIdType numberOfElements);
105 
112  int GetElementType() { return this->ElementType; }
113  virtual bool SetElementType(int elementType);
115 
122  int GetPatchType() { return this->PatchType; }
123  virtual bool SetPatchType(int patchType);
125 
131  bool GetIncludeColormap() { return this->IncludeColormap; }
132  virtual bool SetIncludeColormap(bool includeColormap);
134 
138  void DrawInstancedElements(vtkRenderer* ren, vtkActor* a, vtkMapper* mapper);
139 
159  void SetElementIndexBuffer(vtkDataArray* indices);
160 
166  void AppendElementIndexBuffer(vtkDataArray* indices);
167 
168  void ClearElementIndexBuffer();
169  bool GetUsesIndexBuffer() const;
170 
178  void SetIndexedDrawEnabled(bool enabled);
180 
182  void ReleaseResources(vtkWindow* window);
183 
185  vtkShaderProgram* GetShaderProgram();
186 
188  vtkCollection* GetGLSLModCollection() const;
189 
191  static vtkIdType PatchVertexCountFromPrimitive(int element);
192 
193 protected:
195  void SetCustomUniforms(vtkRenderer* ren, vtkActor* a);
196  void ReadyShaderProgram(vtkRenderer* ren);
197  void ReportUnsupportedLineWidth(float width, float maxWidth, vtkMapper* mapper);
198  void PreDraw(vtkRenderer* ren, vtkActor* a, vtkMapper* mapper);
199  void DrawInstancedElementsImpl(vtkRenderer* ren, vtkActor* a, vtkMapper* mapper);
200  void PostDraw(vtkRenderer* ren, vtkActor* a, vtkMapper* mapper);
201 
202  using ShaderMap = std::map<vtkShader::Type, vtkShader*>;
203  struct Internal;
204 
206  Internal* P{ nullptr };
207  vtkIdType FirstVertexId{ 0 };
208  vtkIdType NumberOfInstances{ 1 };
209  vtkIdType NumberOfElements{ 1 };
210  int ElementType{ ElementShape::TriangleStrip };
211  int PatchType{ PatchShape::PatchTriangle };
212  bool IncludeColormap{ true };
213  std::unordered_map<vtkStringToken, vtkOpenGLArrayTextureBufferAdapter> Arrays;
221  bool ShaderProgramBuilt{ false };
225 
226 private:
228  void operator=(const vtkDrawTexturedElements&) = delete;
229 };
230 
231 VTK_ABI_NAMESPACE_END
232 
233 #endif // vtkDrawTexturedElements_h
234 
235 // Need to skip header testing since we do not inherit vtkObject:
236 // VTK-HeaderTest-Exclude: vtkDrawTexturedElements.h
OpenGL rendering window.
ElementShape
The type of primitive to output.
Input to the essellation control shader is a quadrilateral.
Send triangles to the shader (moving window of 3 vertices).
vtkNew< vtkOpenGLTexture > ColorTextureGL
Send line segments to the shader.
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:41
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:31
Send triangles to the shader.
Type
Available shader types.
Definition: vtkShader.h:38
Input to the essellation control shader is a line segment.
abstract specification for renderers
Definition: vtkRenderer.h:63
int vtkIdType
Definition: vtkType.h:363
OpenGL texture map.
Superclass for mapping scalar values to colors.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:41
Input to the essellation control shader is a triangle.
static const unsigned int numberOfElements
Send triangle fans to the shader (first vertex is constant).
vtkIdType GetNumberOfElements()
Set/get the number of elements (primitives) to draw per instance.
The VertexArrayObject class uses, or emulates, vertex array objects.
vtkNew< vtkOpenGLVertexArrayObject > VAO
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
std::unordered_map< vtkStringToken, vtkOpenGLArrayTextureBufferAdapter > Arrays
Represent a string by its integer hash.
abstract class specifies interface to map data to graphics primitives
Definition: vtkMapper.h:77
std::map< vtkShader::Type, vtkShader * > ShaderMap
PatchShape
The type of primitive that abstract patches are tessellated into.
abstracts an OpenGL texture object.
vtkSmartPointer< vtkShaderProgram > ShaderProgram
A base class for mappers or render responders that need to draw primitives via vertex-pulling.
Vertex or Fragment shader, combined into a ShaderProgram.
Definition: vtkShader.h:30
create and manipulate ordered lists of objects
Definition: vtkCollection.h:39
vtkNew< vtkCollection > GLSLMods
Send line segments to the shader.
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:26
Send points to the shader.
vtkIdType GetNumberOfInstances()
Set/get the number of element instances to draw.
The ShaderProgram uses one or more Shader objects.