HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RV_Geometry Class Reference

Object that represents drawable geometry. This object holds vertex, instancing and index buffers for drawing. The normal workflow is to: More...

#include <RV_Geometry.h>

Public Member Functions

 RV_Geometry ()
 
 ~RV_Geometry ()
 
void reset ()
 clear & free resources More...
 
void unload ()
 remove from VRAM; move to back in RAM (not implemented yet) More...
 
void setNumPoints (exint num_points)
 Set number of points in geometry for vertex shader inputs. More...
 
exint getNumPoints () const
 Number of points in geometry for vertex shader inputs. More...
 
void setPrimitiveBufferSize (exint prim_buffer_element_size)
 
exint getPrimitiveBufferSize () const
 Number of per-primitive elements, accessed in fragment shader. More...
 
bool createAttribute (const UT_StringHolder &name, RV_GPUType data_format, int vector_size, exint capacity=-1, bool allow_gpu_write=false)
 Create an attribute definition Create an attribute definition for a vertex shader input Capacity - optional buffer capacity in elements, in case of resizes. More...
 
bool createConstant (const UT_StringHolder &name, RV_GPUType data_format, int vector_size)
 Creates a single value for a vertex shader input. More...
 
bool createPrimitiveBuffer (const UT_StringHolder &name, RV_GPUType data_format, int vector_size)
 Create a buffer view for fragment shader indexing via gl_PrimitiveID. More...
 
bool createBufferAttribute (const UT_StringHolder &name, RV_GPUType data_format, int vector_size, exint buffer_size)
 
RV_BuffercreateAllocatedAttribute (RV_Render *r, const UT_StringHolder &name, RV_GPUType data_format, int vector_size, RV_AttributeType usage, exint capacity=-1)
 
RV_BuffergetAttribute (const UT_StringHolder &name) const
 Fetch a buffer for an attribute. Return the RV buffer for attribute name. Will not exist until populateBuffers() is called. More...
 
void setAttributeVersion (const UT_StringHolder &name, const RE_CacheVersion &ver)
 Tag the attribute with version information. More...
 
void setAttributeUsage (const UT_StringHolder &name, RV_AttributeType ver)
 Set the attribute type (point, primitive, constant, random). More...
 
void setAttributeConstValue (const UT_StringHolder &name, fpreal64 val)
 Set a vertex shader input to a constant value. More...
 
bool freeAttribute (RV_Render *r, const UT_StringHolder &name)
 Remove attribute and free its resource. More...
 
bool getAttributeType (const UT_StringHolder &name, RV_AttributeType &out_type) const
 Get an attribute's usage Get the type of an attribute (point, prim, const, random, null). May be null if the attribute was freed. More...
 
bool getAttributeFormat (const UT_StringHolder &name, RV_GPUType &out_type, int &out_vec_size) const
 Get the format of an attribute (return false if it does not exist). More...
 
bool getAttributeLength (const UT_StringHolder &name, exint &out_len) const
 Get the length of an attribute Get the length, in elements (not bytes) of an attribute (return false if it does not exist). More...
 
bool getAttributeVersion (const UT_StringHolder &name, RE_CacheVersion &out_ver) const
 Get the version of an attribute (return false if it does not exist). More...
 
bool getAttributeUsage (const UT_StringHolder &name, RV_AttributeType &out_ver) const
 Get an attribute's usage Get the version of an attribute (return false if it does not exist). Will always return the usage it was defined with, even if freed. More...
 
fpreal64 getAttributeConstValue (const UT_StringHolder &name) const
 Get the constant value for the vertex input 'name'. More...
 
bool hasAttribute (const UT_StringHolder &name, int instance_group=-1) const
 True if the attribute exists in the geometry. More...
 
bool createInstanceGroup (int group_index)
 Create a instance group for instanced drawing. More...
 
void removeInstanceGroup (int group_index)
 Remove an instance group. More...
 
bool hasInstanceGroup (int group_index) const
 Return true if the instance group exists. More...
 
int getMaxInstanceGroup () const
 Return the maximum index of all instance groups. More...
 
void setInstanceGroupCount (int instance_group, int count)
 Set the numbers of instances drawn in a group. More...
 
int getInstanceGroupCount (int instance_group) const
 Fetch the numbers of instances drawn in a group. More...
 
void setInstanceGroupIndexList (int group_index, const UT_IntArray &indices, int max_capacity=-1)
 Select a subset of instance indices for an instance group (eg, culling) More...
 
void setInstanceGroupConstIndex (int instance_group, int instance_to_draw)
 Draw one instance with a specific index. More...
 
void setInstanceGroupDrawEverything (int instance_group)
 Draw all instances. More...
 
void setInstanceGroupDrawNothing (int instance_group)
 Draw none of the instances. More...
 
void setConstInstanceGroupTransform (int instance_group, const UT_Matrix4F &xform, bool remove_instanced_xform)
 Single transform for all instances (or additional transform if. More...
 
bool setInstanceGroupAttrib (int instance_group, const UT_StringHolder &name, RV_GPUType data_type, int vector_size, int instance_step, int num_instances, exint capacity=-1)
 Create an per-instance attribute Reserve an buffer for per-instance data (call populateBuffers() to create the RV_Buffer for it). More...
 
bool createSharedInstanceGroupAttrib (int instance_group, const UT_StringHolder &name, RV_GPUType data_type, int vector_size, int instance_step, int num_instances, exint capacity=-1)
 Create per-instance attribute that can be shared by multiple RV_Geometrys. More...
 
bool assignSharedInstanceGroupAttrib (int instance_group, const UT_StringHolder &name, RV_VKBuffer *buffer)
 Assign a buffer for the per-instance shared attribute. More...
 
bool freeInstanceGroupAttrib (int instance_group, const UT_StringHolder &name)
 Remove per-instance attribute and free its resource. More...
 
RV_BuffergetInstanceGroupAttrib (int instance_group, const UT_StringHolder &name) const
 Fetch the buffer backing an per-instance attribute, usually to fill it. More...
 
bool getInstanceAttribVersion (int instance_group, const UT_StringHolder &name, RE_CacheVersion &out_ver) const
 Fetch the per-instance attribute version (to avoid refilling) More...
 
void setInstanceAttribVersion (int instance_group, const UT_StringHolder &name, const RE_CacheVersion &ver)
 Set the per-instance attribute version (to avoid refilling) More...
 
void connectAllPrims (int connect_index, RV_PrimType prim, int patch_size=0)
 Connect all points to form prims of prim type. More...
 
void connectSomePrims (int connect_index, RV_PrimType prim, int start, int length, unsigned int stride=0, int patch_size=0)
 Connect a range of points to form prims of prim type. More...
 
void connectIndexedPrims (int connect_index, RV_PrimType prim, int num_prims, bool need_prim_info=false, int patch_size=0)
 
void setConnectDivisor (int connect_index, int divisor, int base_prim=0)
 
void setConnectUsePrimInfo (int connect_index, int base_prim=0)
 
void setPrimitiveInfoAttrib (RV_TopologyClass prim_type, const UT_StringHolder &name)
 
int getNumRenderPrims (int connect_index) const
 return the number of primitives that are rendered for a connect group More...
 
RV_PrimType getRenderPrimType (int connect_index) const
 return the type of primitives that are rendered for a connect group More...
 
RV_BuffergetIndexBuffer (int connect_index) const
 Fetch the index buffer to fill (after populateBuffers()) More...
 
RV_BuffergetPrimBuffer (int connect_index) const
 Fetch the primitive buffer to fill (after populateBuffers()) More...
 
RV_BuffergetPrimVertexBuffer (int connect_index) const
 Fetch the primitive/vertex buffer to fill (after populateBuffers()) More...
 
bool hasConnectGroup (int connect_index) const
 Return true if the connect group exists. More...
 
bool hasNonEmptyConnectGroup (int connect_index) const
 Return true if the connect group isn't empty. More...
 
int getMaxConnectGroup () const
 Return the maximum connect group index. More...
 
bool removeConnectedPrims (int connect_index)
 Remove a connect group. More...
 
void resetConnectedPrims ()
 Remove all connect groups. More...
 
bool populateBuffers (RV_Render *r)
 Populates all RV_Buffers declared above which haven't been populated yet. More...
 
void prepareForDraw (RV_Render *r, int connect_index, const RV_OverrideList *overrides=nullptr)
 Setup Uniform buffers and Descriptor Set to be used by current shader. More...
 
void prepareForDrawInstance (RV_Render *r, int connect_index, int instance_group, const RV_OverrideList *overrides=nullptr)
 
void draw (RV_Render *r, int connect_index, const RV_OverrideList *overrides=nullptr, bool force_point_prims=false)
 draw a single connection group More...
 
void drawInstanceGroup (RV_Render *r, int connect_index, int instance_group, const RV_OverrideList *overrides=nullptr, bool force_point_prims=false)
 
void drawRange (RV_Render *r, int connect_index_start, int num_connect_indexs, const RV_OverrideList *overrides=nullptr, bool force_point_prims=false)
 draw multiple connection groups (really just a loop over draw()). More...
 
void drawInstanceGroupRange (RV_Render *r, int connect_start, int num_connect, int instance_group, const RV_OverrideList *overrides=nullptr, bool force_point_prims=false)
 draw instanced over multiple connection groups. More...
 
void drawIndirect (RV_Render *r, int connect_index, RV_Buffer &indirect_buffer)
 draw indirectly from a buffer More...
 
void dispatch (RV_Render *r, int connect_index, int instance_group, const RV_OverrideList *overrides=nullptr)
 dispatch a compute shader for a single connect group More...
 
void dispatchRange (RV_Render *r, int connect_index, int num_connect, int instance_group, const RV_OverrideList *overrides=nullptr)
 dispatch compute shader for multiple connect groups More...
 
void print () const
 Debug output Debug methd to print information about all attributes, connect groups, and instance groups. More...
 

Static Public Member Functions

static RV_VKBufferallocateSharedInstanceBuffer (RV_Render *r, RV_GPUType data_type, int vector_size, exint length, const char *name=nullptr)
 Helper to allocate a shared per-instance buffer. More...
 
static void initResources (RV_Instance *inst)
 
static void cleanupResources ()
 

Detailed Description

Object that represents drawable geometry. This object holds vertex, instancing and index buffers for drawing. The normal workflow is to:

Definition at line 164 of file RV_Geometry.h.

Constructor & Destructor Documentation

RV_Geometry::RV_Geometry ( )
RV_Geometry::~RV_Geometry ( )

Member Function Documentation

static RV_VKBuffer* RV_Geometry::allocateSharedInstanceBuffer ( RV_Render r,
RV_GPUType  data_type,
int  vector_size,
exint  length,
const char *  name = nullptr 
)
static

Helper to allocate a shared per-instance buffer.

bool RV_Geometry::assignSharedInstanceGroupAttrib ( int  instance_group,
const UT_StringHolder name,
RV_VKBuffer buffer 
)

Assign a buffer for the per-instance shared attribute.

static void RV_Geometry::cleanupResources ( )
static
void RV_Geometry::connectAllPrims ( int  connect_index,
RV_PrimType  prim,
int  patch_size = 0 
)

Connect all points to form prims of prim type.

void RV_Geometry::connectIndexedPrims ( int  connect_index,
RV_PrimType  prim,
int  num_prims,
bool  need_prim_info = false,
int  patch_size = 0 
)

Connect points form num_prims prims of prim type from a list of point indices. The index buffer must be populated after a populateBuffers() call with getIndexBuffer()->uploadData().

void RV_Geometry::connectSomePrims ( int  connect_index,
RV_PrimType  prim,
int  start,
int  length,
unsigned int  stride = 0,
int  patch_size = 0 
)

Connect a range of points to form prims of prim type.

RV_Buffer* RV_Geometry::createAllocatedAttribute ( RV_Render r,
const UT_StringHolder name,
RV_GPUType  data_format,
int  vector_size,
RV_AttributeType  usage,
exint  capacity = -1 
)

Create an attribute that is allocated immediately separate from those allocated during 'populateBuffers'

bool RV_Geometry::createAttribute ( const UT_StringHolder name,
RV_GPUType  data_format,
int  vector_size,
exint  capacity = -1,
bool  allow_gpu_write = false 
)

Create an attribute definition Create an attribute definition for a vertex shader input Capacity - optional buffer capacity in elements, in case of resizes.

bool RV_Geometry::createBufferAttribute ( const UT_StringHolder name,
RV_GPUType  data_format,
int  vector_size,
exint  buffer_size 
)

Create a random-access attribute for instancing and other random access Uses a buffer view.

bool RV_Geometry::createConstant ( const UT_StringHolder name,
RV_GPUType  data_format,
int  vector_size 
)

Creates a single value for a vertex shader input.

bool RV_Geometry::createInstanceGroup ( int  group_index)

Create a instance group for instanced drawing.

bool RV_Geometry::createPrimitiveBuffer ( const UT_StringHolder name,
RV_GPUType  data_format,
int  vector_size 
)

Create a buffer view for fragment shader indexing via gl_PrimitiveID.

bool RV_Geometry::createSharedInstanceGroupAttrib ( int  instance_group,
const UT_StringHolder name,
RV_GPUType  data_type,
int  vector_size,
int  instance_step,
int  num_instances,
exint  capacity = -1 
)

Create per-instance attribute that can be shared by multiple RV_Geometrys.

void RV_Geometry::dispatch ( RV_Render r,
int  connect_index,
int  instance_group,
const RV_OverrideList overrides = nullptr 
)

dispatch a compute shader for a single connect group

void RV_Geometry::dispatchRange ( RV_Render r,
int  connect_index,
int  num_connect,
int  instance_group,
const RV_OverrideList overrides = nullptr 
)

dispatch compute shader for multiple connect groups

void RV_Geometry::draw ( RV_Render r,
int  connect_index,
const RV_OverrideList overrides = nullptr,
bool  force_point_prims = false 
)

draw a single connection group

void RV_Geometry::drawIndirect ( RV_Render r,
int  connect_index,
RV_Buffer indirect_buffer 
)

draw indirectly from a buffer

void RV_Geometry::drawInstanceGroup ( RV_Render r,
int  connect_index,
int  instance_group,
const RV_OverrideList overrides = nullptr,
bool  force_point_prims = false 
)

draw a single connection group using with instancing, using the indices in instance_group

void RV_Geometry::drawInstanceGroupRange ( RV_Render r,
int  connect_start,
int  num_connect,
int  instance_group,
const RV_OverrideList overrides = nullptr,
bool  force_point_prims = false 
)

draw instanced over multiple connection groups.

void RV_Geometry::drawRange ( RV_Render r,
int  connect_index_start,
int  num_connect_indexs,
const RV_OverrideList overrides = nullptr,
bool  force_point_prims = false 
)

draw multiple connection groups (really just a loop over draw()).

bool RV_Geometry::freeAttribute ( RV_Render r,
const UT_StringHolder name 
)

Remove attribute and free its resource.

bool RV_Geometry::freeInstanceGroupAttrib ( int  instance_group,
const UT_StringHolder name 
)

Remove per-instance attribute and free its resource.

RV_Buffer* RV_Geometry::getAttribute ( const UT_StringHolder name) const

Fetch a buffer for an attribute. Return the RV buffer for attribute name. Will not exist until populateBuffers() is called.

fpreal64 RV_Geometry::getAttributeConstValue ( const UT_StringHolder name) const

Get the constant value for the vertex input 'name'.

bool RV_Geometry::getAttributeFormat ( const UT_StringHolder name,
RV_GPUType out_type,
int out_vec_size 
) const

Get the format of an attribute (return false if it does not exist).

bool RV_Geometry::getAttributeLength ( const UT_StringHolder name,
exint out_len 
) const

Get the length of an attribute Get the length, in elements (not bytes) of an attribute (return false if it does not exist).

bool RV_Geometry::getAttributeType ( const UT_StringHolder name,
RV_AttributeType out_type 
) const

Get an attribute's usage Get the type of an attribute (point, prim, const, random, null). May be null if the attribute was freed.

bool RV_Geometry::getAttributeUsage ( const UT_StringHolder name,
RV_AttributeType out_ver 
) const

Get an attribute's usage Get the version of an attribute (return false if it does not exist). Will always return the usage it was defined with, even if freed.

bool RV_Geometry::getAttributeVersion ( const UT_StringHolder name,
RE_CacheVersion out_ver 
) const

Get the version of an attribute (return false if it does not exist).

RV_Buffer* RV_Geometry::getIndexBuffer ( int  connect_index) const

Fetch the index buffer to fill (after populateBuffers())

bool RV_Geometry::getInstanceAttribVersion ( int  instance_group,
const UT_StringHolder name,
RE_CacheVersion out_ver 
) const

Fetch the per-instance attribute version (to avoid refilling)

RV_Buffer* RV_Geometry::getInstanceGroupAttrib ( int  instance_group,
const UT_StringHolder name 
) const

Fetch the buffer backing an per-instance attribute, usually to fill it.

int RV_Geometry::getInstanceGroupCount ( int  instance_group) const

Fetch the numbers of instances drawn in a group.

int RV_Geometry::getMaxConnectGroup ( ) const

Return the maximum connect group index.

int RV_Geometry::getMaxInstanceGroup ( ) const

Return the maximum index of all instance groups.

exint RV_Geometry::getNumPoints ( ) const

Number of points in geometry for vertex shader inputs.

int RV_Geometry::getNumRenderPrims ( int  connect_index) const

return the number of primitives that are rendered for a connect group

RV_Buffer* RV_Geometry::getPrimBuffer ( int  connect_index) const

Fetch the primitive buffer to fill (after populateBuffers())

exint RV_Geometry::getPrimitiveBufferSize ( ) const

Number of per-primitive elements, accessed in fragment shader.

RV_Buffer* RV_Geometry::getPrimVertexBuffer ( int  connect_index) const

Fetch the primitive/vertex buffer to fill (after populateBuffers())

RV_PrimType RV_Geometry::getRenderPrimType ( int  connect_index) const

return the type of primitives that are rendered for a connect group

bool RV_Geometry::hasAttribute ( const UT_StringHolder name,
int  instance_group = -1 
) const

True if the attribute exists in the geometry.

bool RV_Geometry::hasConnectGroup ( int  connect_index) const

Return true if the connect group exists.

bool RV_Geometry::hasInstanceGroup ( int  group_index) const

Return true if the instance group exists.

bool RV_Geometry::hasNonEmptyConnectGroup ( int  connect_index) const

Return true if the connect group isn't empty.

static void RV_Geometry::initResources ( RV_Instance inst)
static
bool RV_Geometry::populateBuffers ( RV_Render r)

Populates all RV_Buffers declared above which haven't been populated yet.

void RV_Geometry::prepareForDraw ( RV_Render r,
int  connect_index,
const RV_OverrideList overrides = nullptr 
)

Setup Uniform buffers and Descriptor Set to be used by current shader.

void RV_Geometry::prepareForDrawInstance ( RV_Render r,
int  connect_index,
int  instance_group,
const RV_OverrideList overrides = nullptr 
)

Setup Uniform buffers and Descriptor Set to be used by current shader, when drawing with instances

void RV_Geometry::print ( ) const

Debug output Debug methd to print information about all attributes, connect groups, and instance groups.

bool RV_Geometry::removeConnectedPrims ( int  connect_index)

Remove a connect group.

void RV_Geometry::removeInstanceGroup ( int  group_index)

Remove an instance group.

void RV_Geometry::reset ( )

clear & free resources

void RV_Geometry::resetConnectedPrims ( )

Remove all connect groups.

void RV_Geometry::setAttributeConstValue ( const UT_StringHolder name,
fpreal64  val 
)

Set a vertex shader input to a constant value.

void RV_Geometry::setAttributeUsage ( const UT_StringHolder name,
RV_AttributeType  ver 
)

Set the attribute type (point, primitive, constant, random).

void RV_Geometry::setAttributeVersion ( const UT_StringHolder name,
const RE_CacheVersion ver 
)

Tag the attribute with version information.

void RV_Geometry::setConnectDivisor ( int  connect_index,
int  divisor,
int  base_prim = 0 
)

Set the primitive to GPU primitive ratio for acessing primitive attrinbutes. For example, if all polygons are quads, the divisor would be 2 as the GPU creates 2 triangles for each quad.

void RV_Geometry::setConnectUsePrimInfo ( int  connect_index,
int  base_prim = 0 
)

Generate a primitive info buffer for accessing primtive attribute data if the polygon vertex counts vary (use getPrimVertexBuffer() after

void RV_Geometry::setConstInstanceGroupTransform ( int  instance_group,
const UT_Matrix4F xform,
bool  remove_instanced_xform 
)

Single transform for all instances (or additional transform if.

void RV_Geometry::setInstanceAttribVersion ( int  instance_group,
const UT_StringHolder name,
const RE_CacheVersion ver 
)

Set the per-instance attribute version (to avoid refilling)

bool RV_Geometry::setInstanceGroupAttrib ( int  instance_group,
const UT_StringHolder name,
RV_GPUType  data_type,
int  vector_size,
int  instance_step,
int  num_instances,
exint  capacity = -1 
)

Create an per-instance attribute Reserve an buffer for per-instance data (call populateBuffers() to create the RV_Buffer for it).

void RV_Geometry::setInstanceGroupConstIndex ( int  instance_group,
int  instance_to_draw 
)

Draw one instance with a specific index.

void RV_Geometry::setInstanceGroupCount ( int  instance_group,
int  count 
)

Set the numbers of instances drawn in a group.

void RV_Geometry::setInstanceGroupDrawEverything ( int  instance_group)

Draw all instances.

void RV_Geometry::setInstanceGroupDrawNothing ( int  instance_group)

Draw none of the instances.

void RV_Geometry::setInstanceGroupIndexList ( int  group_index,
const UT_IntArray indices,
int  max_capacity = -1 
)

Select a subset of instance indices for an instance group (eg, culling)

void RV_Geometry::setNumPoints ( exint  num_points)

Set number of points in geometry for vertex shader inputs.

void RV_Geometry::setPrimitiveBufferSize ( exint  prim_buffer_element_size)

Set number of per-primitive elements, accessed in fragment shader/ Must match the numver of primitives drawn.

void RV_Geometry::setPrimitiveInfoAttrib ( RV_TopologyClass  prim_type,
const UT_StringHolder name 
)

Set a PrimInfo buffer to be shared across connect groups with same primitive type. Attribute must already exist in geometry.

void RV_Geometry::unload ( )

remove from VRAM; move to back in RAM (not implemented yet)


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