VTK  9.7.1
Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
vtkDrawTexturedElements Class Reference

A base class for mappers or render responders that need to draw primitives via vertex-pulling. More...

#include <vtkDrawTexturedElements.h>

Inheritance diagram for vtkDrawTexturedElements:
[legend]
Collaboration diagram for vtkDrawTexturedElements:
[legend]

Public Types

enum  ElementShape {
  Point, Line, LineStrip, Triangle,
  TriangleStrip, TriangleFan, AbstractPatches
}
 The type of primitive to output. More...
 
enum  PatchShape { PatchLine, PatchTriangle, PatchQuadrilateral }
 The type of primitive that abstract patches are tessellated into. More...
 

Public Member Functions

 vtkDrawTexturedElements ()
 
virtual ~vtkDrawTexturedElements ()
 
vtkShader * GetShader (vtkShader::Type shaderType)
 Return a shader of the given type (creating as needed). More...
 
void BindArrayToTexture (vtkStringToken textureName, vtkDataArray *array, bool asScalars=false)
 Bind a data array to the given textureName (used in shader program texelFetch calls). More...
 
void AppendArrayToTexture (vtkStringToken textureName, vtkDataArray *array, bool asScalars=false)
 
bool UnbindArray (vtkStringToken)
 
void BeginArrayRebuild ()
 Begin re-listing the bound arrays without discarding their uploaded textures. More...
 
vtkIdType GetNumberOfInstances ()
 Set/get the number of element instances to draw. More...
 
virtual bool SetNumberOfInstances (vtkIdType numberOfInstances)
 
vtkIdType GetNumberOfElements ()
 Set/get the number of elements (primitives) to draw per instance. More...
 
virtual bool SetNumberOfElements (vtkIdType numberOfElements)
 
void DrawInstancedElements (vtkRenderer *ren, vtkActor *a, vtkMapper *mapper)
 Render geometry. More...
 
void ReleaseResources (vtkWindow *window)
 Release any graphics resources associated with the window. More...
 
vtkShaderProgram * GetShaderProgram ()
 Return the internal shader program so subclasses can create/replace shaders. More...
 
vtkCollection * GetGLSLModCollection () const
 Return the GLSL mods. More...
 
int GetElementType ()
 
virtual bool SetElementType (int elementType)
 
int GetPatchType ()
 
virtual bool SetPatchType (int patchType)
 
bool GetIncludeColormap ()
 
virtual bool SetIncludeColormap (bool includeColormap)
 
void SetElementIndexBuffer (vtkDataArray *indices)
 
void AppendElementIndexBuffer (vtkDataArray *indices)
 Append connectivity to the element (index) buffer, concatenating in memory order. More...
 
void ClearElementIndexBuffer ()
 
bool GetUsesIndexBuffer () const
 
void SetIndexedDrawEnabled (bool enabled)
 Per-draw selector for the hybrid surface/expansion dispatch. More...
 

Static Public Member Functions

static vtkIdType PatchVertexCountFromPrimitive (int element)
 Return the number of vertices in the patch primitive. More...
 

Protected Types

using ShaderMap = std::map< vtkShader::Type, vtkShader * >
 

Protected Member Functions

void SetCustomUniforms (vtkRenderer *ren, vtkActor *a)
 Set any custom uniforms provided by the actor. More...
 
void ReadyShaderProgram (vtkRenderer *ren)
 
void ReportUnsupportedLineWidth (float width, float maxWidth, vtkMapper *mapper)
 
void PreDraw (vtkRenderer *ren, vtkActor *a, vtkMapper *mapper)
 
void DrawInstancedElementsImpl (vtkRenderer *ren, vtkActor *a, vtkMapper *mapper)
 
void PostDraw (vtkRenderer *ren, vtkActor *a, vtkMapper *mapper)
 

Protected Attributes

Internal * P { nullptr }
 Private data for this class. More...
 
vtkIdType FirstVertexId { 0 }
 
vtkIdType NumberOfInstances { 1 }
 
vtkIdType NumberOfElements { 1 }
 
int ElementType { ElementShape::TriangleStrip }
 
int PatchType { PatchShape::PatchTriangle }
 
bool IncludeColormap { true }
 
std::unordered_map< vtkStringToken, vtkOpenGLArrayTextureBufferAdapter > Arrays
 
ShaderMap Shaders
 
vtkSmartPointer< vtkShaderProgram > ShaderProgram
 
bool ShaderProgramBuilt { false }
 True once ShaderProgram has been resolved from the current Shaders sources. More...
 
vtkNew< vtkOpenGLVertexArrayObject > VAO
 
vtkNew< vtkOpenGLTexture > ColorTextureGL
 
vtkNew< vtkCollection > GLSLMods
 

Detailed Description

A base class for mappers or render responders that need to draw primitives via vertex-pulling.

Since this class is intended to be inherited by other classes that must also inherit a VTK mapper or responder class, it is not a subclass of vtkObject; instead, it provides methods your subclass can invoke during rendering.

This currently handles hexahedra and tetrahedra.

Definition at line 47 of file vtkDrawTexturedElements.h.

Member Typedef Documentation

Definition at line 202 of file vtkDrawTexturedElements.h.

Member Enumeration Documentation

The type of primitive to output.

Enumerator
Point 

Send points to the shader.

Line 

Send line segments to the shader.

LineStrip 

Send line segments to the shader.

Triangle 

Send triangles to the shader.

TriangleStrip 

Send triangles to the shader (moving window of 3 vertices).

TriangleFan 

Send triangle fans to the shader (first vertex is constant).

AbstractPatches 

Send abstract patches to the shader.

Definition at line 54 of file vtkDrawTexturedElements.h.

The type of primitive that abstract patches are tessellated into.

Enumerator
PatchLine 

Input to the essellation control shader is a line segment.

PatchTriangle 

Input to the essellation control shader is a triangle.

PatchQuadrilateral 

Input to the essellation control shader is a quadrilateral.

Definition at line 66 of file vtkDrawTexturedElements.h.

Constructor & Destructor Documentation

vtkDrawTexturedElements::vtkDrawTexturedElements ( )
virtual vtkDrawTexturedElements::~vtkDrawTexturedElements ( )
virtual

Member Function Documentation

vtkShader* vtkDrawTexturedElements::GetShader ( vtkShader::Type  shaderType)

Return a shader of the given type (creating as needed).

void vtkDrawTexturedElements::BindArrayToTexture ( vtkStringToken  textureName,
vtkDataArray *  array,
bool  asScalars = false 
)

Bind a data array to the given textureName (used in shader program texelFetch calls).

If asScalars is false (the default), then the array's components are treated as components of single texture values. If asScalars is true, then a 2-d texture image is uploaded where each value is a scalar (row indices are tuple IDs, column indices are component IDs).

void vtkDrawTexturedElements::AppendArrayToTexture ( vtkStringToken  textureName,
vtkDataArray *  array,
bool  asScalars = false 
)
bool vtkDrawTexturedElements::UnbindArray ( vtkStringToken  )
void vtkDrawTexturedElements::BeginArrayRebuild ( )

Begin re-listing the bound arrays without discarding their uploaded textures.

A mapper that rebuilds its array bindings every frame (e.g. the batched mapper, which concatenates one texture per attribute across all its blocks) calls this before the Bind/Append calls. Each existing texture is marked so that the first Bind/Append of this cycle clears its previously-listed source arrays while keeping the GPU texture/buffer and the per-sub-array layout records intact. The subsequent Upload() can then diff the new arrays against the last upload and re-transfer only the slices that changed. Any texture that is not repopulated during the cycle stays marked and is skipped at draw time.

vtkIdType vtkDrawTexturedElements::GetNumberOfInstances ( )
inline

Set/get the number of element instances to draw.

Definition at line 99 of file vtkDrawTexturedElements.h.

virtual bool vtkDrawTexturedElements::SetNumberOfInstances ( vtkIdType  numberOfInstances)
virtual
vtkIdType vtkDrawTexturedElements::GetNumberOfElements ( )
inline

Set/get the number of elements (primitives) to draw per instance.

Definition at line 103 of file vtkDrawTexturedElements.h.

virtual bool vtkDrawTexturedElements::SetNumberOfElements ( vtkIdType  numberOfElements)
virtual
int vtkDrawTexturedElements::GetElementType ( )
inline

Set/get the type of elements to draw.

This determines the number of vertices rendered per element. Values must come from the ElementShape enum; the default is ElementShape::TriangleStrip.

Definition at line 112 of file vtkDrawTexturedElements.h.

virtual bool vtkDrawTexturedElements::SetElementType ( int  elementType)
virtual

Set/get the type of elements to draw.

This determines the number of vertices rendered per element. Values must come from the ElementShape enum; the default is ElementShape::TriangleStrip.

int vtkDrawTexturedElements::GetPatchType ( )
inline

Set/get the type of primitive an abstract patch gets tessellated into.

This determines the number of input patch vertices to the tessellation shaders. Values must come from the PatchShape enum; the default is PatchShape::Triangle.

Definition at line 122 of file vtkDrawTexturedElements.h.

virtual bool vtkDrawTexturedElements::SetPatchType ( int  patchType)
virtual

Set/get the type of primitive an abstract patch gets tessellated into.

This determines the number of input patch vertices to the tessellation shaders. Values must come from the PatchShape enum; the default is PatchShape::Triangle.

bool vtkDrawTexturedElements::GetIncludeColormap ( )
inline

Set/get whether to upload a colormap texture.

If enabled (the default), then create (if needed) and upload a colormap texture image bound to a "color_map" uniform sampler.

Definition at line 131 of file vtkDrawTexturedElements.h.

virtual bool vtkDrawTexturedElements::SetIncludeColormap ( bool  includeColormap)
virtual

Set/get whether to upload a colormap texture.

If enabled (the default), then create (if needed) and upload a colormap texture image bound to a "color_map" uniform sampler.

void vtkDrawTexturedElements::DrawInstancedElements ( vtkRenderer *  ren,
vtkActor *  a,
vtkMapper *  mapper 
)

Render geometry.

This just calls glDrawElementInstanced().

void vtkDrawTexturedElements::SetElementIndexBuffer ( vtkDataArray *  indices)

Enable indexed vertex-pulling by supplying an index (element) buffer.

When an index buffer is set, DrawInstancedElements issues glDrawElementsInstanced rather than glDrawArraysInstanced. With glDrawElements, the shader's gl_VertexID is the fetched index value, so the post-transform vertex cache can reuse vertices shared between primitives (a triangle-mesh vertex shared by ~6 triangles runs the vertex shader roughly once instead of ~6 times). The shader should therefore use gl_VertexID directly as the point id instead of fetching it from a connectivity texture buffer.

indices must hold 32-bit (or smaller) integer connectivity; values are copied and uploaded as GL_UNSIGNED_INT. Passing nullptr (or calling ClearElementIndexBuffer) reverts to non-indexed pulling.

The draw also honors FirstVertexId as the offset (in elements) of the slice to draw within the supplied connectivity, so a single concatenated buffer can back several draws.

void vtkDrawTexturedElements::AppendElementIndexBuffer ( vtkDataArray *  indices)

Append connectivity to the element (index) buffer, concatenating in memory order.

Use this (instead of SetElementIndexBuffer, which replaces) to build a single element buffer from several meshes, e.g. composite/batched input. The accumulated values must stay aligned with the matching connectivity texture so a draw's FirstVertexId indexes both the same way.

void vtkDrawTexturedElements::ClearElementIndexBuffer ( )

Enable indexed vertex-pulling by supplying an index (element) buffer.

When an index buffer is set, DrawInstancedElements issues glDrawElementsInstanced rather than glDrawArraysInstanced. With glDrawElements, the shader's gl_VertexID is the fetched index value, so the post-transform vertex cache can reuse vertices shared between primitives (a triangle-mesh vertex shared by ~6 triangles runs the vertex shader roughly once instead of ~6 times). The shader should therefore use gl_VertexID directly as the point id instead of fetching it from a connectivity texture buffer.

indices must hold 32-bit (or smaller) integer connectivity; values are copied and uploaded as GL_UNSIGNED_INT. Passing nullptr (or calling ClearElementIndexBuffer) reverts to non-indexed pulling.

The draw also honors FirstVertexId as the offset (in elements) of the slice to draw within the supplied connectivity, so a single concatenated buffer can back several draws.

bool vtkDrawTexturedElements::GetUsesIndexBuffer ( ) const

Enable indexed vertex-pulling by supplying an index (element) buffer.

When an index buffer is set, DrawInstancedElements issues glDrawElementsInstanced rather than glDrawArraysInstanced. With glDrawElements, the shader's gl_VertexID is the fetched index value, so the post-transform vertex cache can reuse vertices shared between primitives (a triangle-mesh vertex shared by ~6 triangles runs the vertex shader roughly once instead of ~6 times). The shader should therefore use gl_VertexID directly as the point id instead of fetching it from a connectivity texture buffer.

indices must hold 32-bit (or smaller) integer connectivity; values are copied and uploaded as GL_UNSIGNED_INT. Passing nullptr (or calling ClearElementIndexBuffer) reverts to non-indexed pulling.

The draw also honors FirstVertexId as the offset (in elements) of the slice to draw within the supplied connectivity, so a single concatenated buffer can back several draws.

void vtkDrawTexturedElements::SetIndexedDrawEnabled ( bool  enabled)

Per-draw selector for the hybrid surface/expansion dispatch.

SetElementIndexBuffer leaves indexed drawing enabled by default. A caller that shares one uploaded buffer across draws with mixed eligibility (e.g. plain triangles indexed, surface-with-edges expanded) toggles this before each DrawInstancedElements call. It has no effect unless an index buffer is present.

void vtkDrawTexturedElements::ReleaseResources ( vtkWindow *  window)

Release any graphics resources associated with the window.

vtkShaderProgram* vtkDrawTexturedElements::GetShaderProgram ( )

Return the internal shader program so subclasses can create/replace shaders.

vtkCollection* vtkDrawTexturedElements::GetGLSLModCollection ( ) const

Return the GLSL mods.

static vtkIdType vtkDrawTexturedElements::PatchVertexCountFromPrimitive ( int  element)
static

Return the number of vertices in the patch primitive.

void vtkDrawTexturedElements::SetCustomUniforms ( vtkRenderer *  ren,
vtkActor *  a 
)
protected

Set any custom uniforms provided by the actor.

void vtkDrawTexturedElements::ReadyShaderProgram ( vtkRenderer *  ren)
protected
void vtkDrawTexturedElements::ReportUnsupportedLineWidth ( float  width,
float  maxWidth,
vtkMapper *  mapper 
)
protected
void vtkDrawTexturedElements::PreDraw ( vtkRenderer *  ren,
vtkActor *  a,
vtkMapper *  mapper 
)
protected
void vtkDrawTexturedElements::DrawInstancedElementsImpl ( vtkRenderer *  ren,
vtkActor *  a,
vtkMapper *  mapper 
)
protected
void vtkDrawTexturedElements::PostDraw ( vtkRenderer *  ren,
vtkActor *  a,
vtkMapper *  mapper 
)
protected

Member Data Documentation

Internal* vtkDrawTexturedElements::P { nullptr }
protected

Private data for this class.

Definition at line 206 of file vtkDrawTexturedElements.h.

vtkIdType vtkDrawTexturedElements::FirstVertexId { 0 }
protected

Definition at line 207 of file vtkDrawTexturedElements.h.

vtkIdType vtkDrawTexturedElements::NumberOfInstances { 1 }
protected

Definition at line 208 of file vtkDrawTexturedElements.h.

vtkIdType vtkDrawTexturedElements::NumberOfElements { 1 }
protected

Definition at line 209 of file vtkDrawTexturedElements.h.

int vtkDrawTexturedElements::ElementType { ElementShape::TriangleStrip }
protected

Definition at line 210 of file vtkDrawTexturedElements.h.

int vtkDrawTexturedElements::PatchType { PatchShape::PatchTriangle }
protected

Definition at line 211 of file vtkDrawTexturedElements.h.

bool vtkDrawTexturedElements::IncludeColormap { true }
protected

Definition at line 212 of file vtkDrawTexturedElements.h.

std::unordered_map<vtkStringToken, vtkOpenGLArrayTextureBufferAdapter> vtkDrawTexturedElements::Arrays
protected

Definition at line 213 of file vtkDrawTexturedElements.h.

ShaderMap vtkDrawTexturedElements::Shaders
protected

Definition at line 214 of file vtkDrawTexturedElements.h.

vtkSmartPointer<vtkShaderProgram> vtkDrawTexturedElements::ShaderProgram
protected

Definition at line 215 of file vtkDrawTexturedElements.h.

bool vtkDrawTexturedElements::ShaderProgramBuilt { false }
protected

True once ShaderProgram has been resolved from the current Shaders sources.

While set, ReadyShaderProgram rebinds the cached program directly instead of re-running the (expensive) source substitution + MD5 lookup every draw. Cleared by GetShader (the only path through which a caller can mutate a shader source), forcing a rebuild on the next draw.

Definition at line 221 of file vtkDrawTexturedElements.h.

vtkNew<vtkOpenGLVertexArrayObject> vtkDrawTexturedElements::VAO
protected

Definition at line 222 of file vtkDrawTexturedElements.h.

vtkNew<vtkOpenGLTexture> vtkDrawTexturedElements::ColorTextureGL
protected

Definition at line 223 of file vtkDrawTexturedElements.h.

vtkNew<vtkCollection> vtkDrawTexturedElements::GLSLMods
protected

Definition at line 224 of file vtkDrawTexturedElements.h.


The documentation for this class was generated from the following file: