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

A collection of vertex arrays defining a geometry object. This class acts as a wrapper around multiple RE_VertexArray objects, similar to the way a framebuffer object contains multiple textures. Arrays can be attached to various attachments points, representing different vertex attribute data. More...

#include <RE_Geometry.h>

Public Member Functions

 RE_Geometry (int num_points=0, bool use_buffer_object=true)
 
 ~RE_Geometry ()
 
int64 getMemoryUsage (bool inclusive) const
 
void useBufferObjects (bool use_buf=true)
 Choose between buffer objects and client arrays By default, buffer objects are used if supported. This allows you to turn them off and use vertex arrays. This is useful if the geometry information is throw-away. If called when vertex arrays are attached, they will be cleared (and possibly deleted) More...
 
void useVertexState (bool use_state=true)
 Optimize this geometry with vertex array objects. Use an RE_VertexState (and GL Vertex Array Objects) to contain vertex arrays. Requires RE_EXT_VERTEX_ARRAY_OBJECT. More...
 
void purgeBuffers ()
 Clears all the attached buffers, and removes them from the cache. More...
 
void resizePointsToFit (RE_PrimType primtype, int num_primitives, bool shrink_if_smaller, RE_Shader *shader=nullptr)
 Calulcate the number of points required for some primitives This will ensure that the buffer is big enough to hold enough vertices for the given number of primitives of the specified type. The buffer size can be reduced if 'shrink_if_smaller' is true, otherwise this will only increase the size of the buffer if needed. If 'shader' is given, it will check if the shader has a geometry shader and modify the number of vertices by the output primitive type and maximum #vertices. Shaders without a geometry shader will have no effect (as if nullptr). For transform feedback, only POINTS, LINES or TRIANGLES are ever produced. More...
 
void initialize (RE_Render *r)
 Create buffers for all attached arrays When the above methods are called with attached arrays, these arrays might have their storage freed. This call will ensure that all arrays are initialized. More...
 
bool assignMaterialToConnectivty (RE_Render *r, int connect_index, const RE_MaterialPtr &mat)
 
RE_MaterialPtr getConnectivityMaterial (int connect_index, int subindex=0)
 
void resetVertexState (RE_Render *r)
 resets all VAOs so that on the next draw all VBOs are rebound More...
 
void unbindAllArrays (RE_Render *r)
 Remove all arrays and attributes from their GL bindings. More...
 
void print (std::ostream *out=nullptr) const
 
void setDebugDraw (bool dump_uniforms, bool dump_builtins, bool dump_gl_state)
 
bool setNumPoints (int num)
 Number of points in the geometry. Number of points for the arrays declared as RE_ARRAY_POINT. This will clear the data in all point arrays and reset the connectivty. More...
 
int getNumPoints () const
 Number of points in the geometry. Number of points for the arrays declared as RE_ARRAY_POINT. This will clear the data in all point arrays and reset the connectivty. More...
 
bool setNumVertices (int num)
 Sets the number of elements in arrays declared as RE_ARRAY_VERTEX. More...
 
int getNumVertices () const
 Sets the number of elements in arrays declared as RE_ARRAY_VERTEX. More...
 
bool setNumPrimitives (int num)
 Sets the number of elements in arrays declared as RE_ARRAY_PRIMITIVE. More...
 
int getNumPrimitives () const
 Sets the number of elements in arrays declared as RE_ARRAY_PRIMITIVE. More...
 
Generic Vertex Attributes

GL3 shaders use generic vertex attributes, which are identified by name. GL2 shaders can use a few generic vertex attributes along with the fixed builtin attributes. Generic attributes must be used for instanced, primitive or vertex atttributes.

void stashAttributes ()
 
int clearStashedAttributes (bool purge_from_cache)
 
RE_VertexArrayrecallStashedAttribute (const char *name)
 fetch stashed attribute 'name', placing it back into the geometry's list More...
 
RE_VertexArrayrecallStashedVaryingAttribute (const char *attrib_name)
 fetch stashed attribute 'name', but only if it is a const buffer. More...
 
RE_VertexArrayrecallStashedConstAttribute (const char *attrib_name)
 fetch stashed attribute 'name', but only if it is a const buffer. More...
 
RE_VertexArrayfetchStashedAttribute (const char *name)
 
bool hasStashedAttribute (const char *name)
 
RE_VertexArraycreateAttribute (RE_Render *r, const char *attrib_name, RE_GPUType data_format, int vectorsize, const void *data, RE_ArrayType atype=RE_ARRAY_POINT, int array_size=0, RE_BufferUsageHint h=RE_BUFFER_WRITE_FREQUENT, const char *cache_prefix=nullptr, int capacity=-1)
 Create a generic vertex attribute attached to 'attrib_name' Attributes are referenced by name, rather than buffer type. Array size is required if array type is RANDOM or INSTANCED. More...
 
RE_VertexArraycreateInstancedAttribute (RE_Render *r, const char *attrib_name, RE_GPUType data_format, int vectorsize, int instance_stride, int num_instances, const void *data, const char *cache_prefix=nullptr, int capacity=-1)
 Create an instanced vertex attribute attached to 'attrib_name' Create an attribute which advances once every 'instance_stride' instances rather than once per vertex. RE_EXT_INSTANCED_ARRAYS is required, and an instanced drawing method must be used (or it acts as a uniform). More...
 
RE_VertexArraycreateConstAttribute (RE_Render *r, const char *attrib_name, RE_GPUType data_format, int vectorsize, const void *data)
 Create a constant attribute value Only RE_GPU_FLOAT32 and _FLOAT64 are supported for constant data. The 'data' point must hold at least 1 element (sizeof(type)*vectorsize). More...
 
RE_VertexArrayassignAttributeDefault (RE_Render *r, const char *attrib_name, RE_GPUType data_format, int vectorsize, const void *default_value)
 Create a constant attribute if varying attribute is not found Ensures that there is at least a constant attribute value available if the attribute doesn't exist already. Only returns an array if one was created. More...
 
bool attachAttribute (RE_VertexArray *attrib)
 Attach an existing attribute using its name as the binding. More...
 
RE_VertexArraydetachAttribute (const char *name)
 Detatch an attribute from this object by name. More...
 
bool clearAttribute (const char *name, bool purge_cache=false)
 Delete an attached vertex attribute by name delete the RE_VertexArray, and if purge_cache is true, remove the underlying data buffer from the GL cache. More...
 
bool clearAttributeByIndex (int i, bool purge_cache=false)
 Delete an attached vertex attribute by index delete the RE_VertexArray, and if purge_cache is true, remove the underlying data buffer from the GL cache. More...
 
RE_VertexArraygetAttribute (const char *name) const
 Fetch an attribute by name. More...
 
int getAttributeIndex (const char *name) const
 
RE_VertexArraygetAttribute (RE_GenericAttribID attrib_id) const
 Fetch an attribute by known type. More...
 
int getNumAttributes () const
 Return the number of generic attributes currently attached. More...
 
RE_VertexArraygetAttributeByIndex (int i) const
 Return currently attached vertex attribute 'i'. More...
 
const RE_VertexMapgetVertexMap () const
 Return a vertex map representing the layout locations of the attributes. More...
 
Addressable attributes

Addressable attributes allow you to use buffers, but sample them like textures using texelFetch on samplerBuffer uniforms. Only buffer objects are supported.

RE_VertexArraycreateAddressableAttribute (RE_Render *r, const char *attrib_name, int length, RE_GPUType data_format, int vectorsize, const void *data, RE_ArrayType atype=RE_ARRAY_RANDOM, const char *cache_prefix=nullptr)
 Create a randomly addressable attribute (texture buffer object) Attributes can be stored in texture buffers, and accessed out of the normal vertex flow, such as for vertex or primitive attributes. Unlike normal attributes, addressable attributes can have a different array size than the RE_Geometry's number of vertices. More...
 
RE_TexturecreateAddressableAttribute (RE_Render *r, const char *attrib_name, RE_VertexArray *data)
 Create a randomly addressable attribute from an existing vertex array. More...
 
RE_VertexArraygetAddressableAttribute (const char *attrib_name) const
 Fetch an addressable attribute by name. More...
 
int getAddressableAttributeIndex (const char *attrib_name) const
 Return the index of the named addressable attribute, or -1 if not found. More...
 
void clearAddressableAttribute (const char *attrib_name)
 Delete the addressable attribute named 'attrib_name'. More...
 
int getNumAddressableAttributes () const
 Return the number of addressable attributes. More...
 
RE_TexturegetAddressableAttributeTexture (int index) const
 Return the texture buffer object representing addressable attribute 'i'. More...
 
RE_VertexArraygetAddressableAttributeByIndex (int index) const
 Return the vertex arrayrepresenting addressable attribute 'i'. More...
 
bool cacheBuffers (const char *name)
 Caching
. More...
 
const char * getCacheName () const
 Return the base cache name. More...
 
bool isCaching () const
 Check if this geometry object is caching. More...
 
void purgeOnDelete (bool purge=true)
 Remove all buffers from the cache when this geometry object is deleted. More...
 
void setCacheVersion (RE_CacheVersion v)
 set the cache version for all arrays attached to this geometry object. More...
 
void setCacheTag (RE_CacheTagHandle h)
 Assign a cache tag to monitor cache changes on this object The tag will be bumped if this or any of its vertex buffers are removed from the cache. More...
 
RE_VertexArrayfindCachedAttrib (RE_Render *r, const char *attrib_name, RE_GPUType data_format, int vectorsize, RE_ArrayType array_type, bool create_if_missing=false, int random_array_size=-1, const RE_CacheVersion *cv=nullptr, RE_BufferUsageHint h=RE_BUFFER_WRITE_FREQUENT, const char *cache_prefix=nullptr, int capacity=-1)
 Find an attribute or array in the GL cache, possibly creating it Returns the cached array, if it exists, for the array named 'attrib_name'. The name may be one of the gl-builtin attributes, like gl_Position or gl_Color. 'array_size' is the size of an INSTANCE or RANDOM array_type. More...
 
RE_VertexArrayfindCachedInstancedAttrib (RE_Render *r, const char *attrib_name, RE_GPUType data_format, int vectorsize, int instance_step, int array_size, bool create_if_missing=false, const RE_CacheVersion *v=nullptr, RE_BufferUsageHint h=RE_BUFFER_WRITE_FREQUENT, const char *cache_prefix=nullptr, int capacity=-1)
 Find an instanced attribute in the GL cache, possibly creating it. The instance_step parameter defines how often the attribute is advanced when the instance ID changes - 1 is once per instance. More...
 
void useAttribute (int connect_group, const char *name, bool enable)
 Toggles the use of a generic vertex attribute for a connect group. Index group version of useAttribute(); toggles the attribute named 'name' on or off. More...
 
void useAttribute (int connect_group, RE_VertexArray *attrib, bool enable)
 Toggles the use of a generic vertex attribute for a connect group. Index group version of useAttribute(); toggles the attribute specified by 'attrib' on or off. More...
 
void useMaterialTextures (bool enable=true)
 Enables or disables textures on materials when drawn. More...
 
void setNumMaterialLayers (int num)
 Clamp the number of layers to draw with a multi-layer material. More...
 
Drawing

These methods draw connectivity groups that were previously set up, with some modifications available. If 'primtype' is not INVALID, it overrides the connectivity group's primitive type. 'attrib_overrides' is a list of string pairs which defines a mapping from shader attribute names (indices 0,2,4,6...) to geometry attribute names (indices 1,3,5,7...).

void draw (RE_Render *r, int connect_idx, RE_PrimType prim_type=RE_PRIM_AS_IS, RE_OverrideList *attrib_overrides=nullptr)
 
void drawAll (RE_Render *r, RE_PrimType prim_type=RE_PRIM_AS_IS, RE_OverrideList *attrib_overrides=nullptr)
 Draw all connectivity groups. Draws all connect_groups. Same as looping through all groups and calling draw(). The draw order is undefined; if you need a specific order, use multiple draw calls. More...
 
void drawRange (RE_Render *r, int connect_group_start, int num_connect_groups, RE_PrimType ptype=RE_PRIM_AS_IS, RE_OverrideList *attrib_overrides=nullptr, const int *material_offset=nullptr)
 
void drawInstanced (RE_Render *r, int connect_idx, int num_instances, RE_PrimType prim_type=RE_PRIM_AS_IS, RE_OverrideList *attrib_overrides=nullptr)
 Draw with Instancing Draws the same connect group 'num_instances' times. It is up to the shader to differentiate the instances, using an instanced attribute (createInstancedAttribute()) or GLSL's gl_InstanceID. More...
 
void drawAllInstanced (RE_Render *r, int num_instances, RE_PrimType prim_type=RE_PRIM_AS_IS, RE_OverrideList *attrib_overrides=nullptr)
 Draw all connectivity groups using instancing, num_instance times. More...
 
void drawRangeInstanced (RE_Render *r, int connect_start, int num_connect, int num_instances, RE_PrimType prim_type=RE_PRIM_AS_IS, RE_OverrideList *attrib_overrides=nullptr, const int *material_offset=nullptr)
 Draw a range of connectivity index groups with instancing. More...
 
void drawInstanceGroup (RE_Render *r, int connect_idx, int instance_group, RE_PrimType prim_type=RE_PRIM_AS_IS, RE_OverrideList *attrib_over=nullptr)
 Draw an instance group using a given connectivity. More...
 
void drawInstanceGroupRange (RE_Render *r, int connect_start, int num_connect, int instance_group, RE_PrimType prim_type=RE_PRIM_AS_IS, RE_OverrideList *attrib_over=nullptr, const int *material_offset=nullptr)
 Draw an instance group using a given connectivity. More...
 
void drawIndirect (RE_Render *r, int connect_group, RE_VertexArray &indirect_buffer)
 
void enableArrays (RE_Render *r, int connect_group, unsigned int stride=0)
 
void disableArrays (RE_Render *r, int connect_group)
 

Friends

class re_InstanceGroup
 

Instance groups

Instance groups allow for rendering of the geometry with different attributes, generally InstanceTransform, but others can be overriden as well. The base (default) group is instance group 0. Higher groups will substitute their attributes for the ones in instance group 0. Note that the attribute need not exist in the base group to be overriden. If an attribute is not overriden, the base group attribute is used.

void createInstanceGroup (int instance_group)
 Create a new instance group. instance_group must be a positive int. More...
 
void removeInstanceGroup (int instance_group)
 
bool hasInstanceGroup (int instance_group) const
 Returns true if the specified instance group exists. More...
 
int getNumInstanceGroups () const
 Create a new instance group. instance_group must be a positive int. More...
 
void setInstanceGroupNesting (int instance_group, const UT_IntArray &count_per_level)
 
void clearInstanceGroupNesting (int instance_group)
 Create a new instance group. instance_group must be a positive int. More...
 
void setInstanceGroupIndexList (RE_Render *r, int instance_group, bool trivial, const UT_IntArray *indices=nullptr, int max_capacity=-1)
 
void setInstanceGroupConstIndex (RE_Render *r, int instance_group, int instance_to_draw)
 Set to draw a single instance in the group. More...
 
void setInstanceGroupDrawEverything (RE_Render *r, int instance_group)
 Set to draw all instances (based on the # transforms). More...
 
void setInstanceGroupDrawNothing (RE_Render *r, int instance_group)
 Draw none of the instances. More...
 
RE_VertexArraycreateConstInstanceGroupAttrib (RE_Render *r, int instance_group, const char *name, RE_GPUType data_format, int vectorsize, const void *data)
 Create a constant for an attribute in 'instance_group'. More...
 
void setConstInstanceGroupTransform (int instance_group, const UT_Matrix4D &xform, bool remove_instanced_xform)
 Create a constant transform for an instance group. More...
 
void setConstInstanceGroupTransform (int instance_group, const UT_Matrix4F &xform, bool remove_instanced_xform)
 Create a new instance group. instance_group must be a positive int. More...
 
RE_VertexArrayfindCachedInstanceGroupAttrib (RE_Render *r, int instance_group, const char *name, RE_GPUType data_type, int vector_size, int instance_step, int num_instances, bool create=false, const RE_CacheVersion *v=nullptr, RE_BufferUsageHint h=RE_BUFFER_WRITE_FREQUENT, const char *view_name=nullptr, int capacity=-1)
 Find an instance-group attribute in the cache Creates an instanced attribute for an instance-group, which overrides the base attribute on the RE_Geometry. instance_group zero is the base level ("Cd"), all other groups have the group appended ("Cd1" for group 1). When drawn with drawInstanceGroup(), attributes in the specified instance group will be used (if present) instead of the base attributes. More...
 
RE_VertexArraygetInstanceGroupAttrib (int instance_group, RE_GenericAttribID attrib_id, const char *name)
 
bool clearInstanceGroupAttrib (int instance_group, RE_GenericAttribID attrib_id, const char *name)
 Remove and delete the array. More...
 
RE_VertexArraygetInstanceGroupTextureBufferForShader (RE_Render *r, RE_Shader *sh, int instance_group, RE_GenericAttribID attr_id, const char *name)
 
int getInstanceGroupCount (int instance_group) const
 Returns the number of instances to be drawn in an instance group. More...
 
int connectAllPrims (RE_Render *r, int connect_index, RE_PrimType prim, const RE_MaterialPtr &mat=nullptr, bool replace=false, int vertices_per_patch=0)
 Primitive Connectivity
. More...
 
int connectSomePrims (RE_Render *r, int connect_group, RE_PrimType prim, int start, int length, unsigned int stride=0, const RE_MaterialPtr &mat=nullptr, bool replace=false, int vertices_per_patch=0)
 Connect a subrange of vertices and place in index group 'connect_index'. More...
 
int connectIndexedPrims (RE_Render *r, int connect_group, RE_PrimType prim, int num, const unsigned int *prims, const RE_MaterialPtr &mat=nullptr, bool replace=false, int vertices_per_patch=0)
 Connect vertices using an indexed vertex list, add to 'connect_group'. 'num' is the size of the list, not the number of primitives. If any index is greater than the number of points in the geometry, the results will be undefined. This is added to connect_group. More...
 
int connectIndexedPrims (RE_Render *r, int connect_group, RE_PrimType prim, RE_VertexArray *elements, const RE_MaterialPtr &mat=nullptr, bool replace=false, int vertices_per_patch=0)
 Connect vertices using the indices in the buffer object 'elements'. More...
 
int connectIndexedPrims (RE_Render *r, int connect_group, RE_ElementArray *elements, const RE_MaterialPtr &mat=nullptr, bool replace=false)
 Connect vertices using the indices in the element array 'elements'. More...
 
int getConnectNumElementArrays (int connect_group)
 Returns the number of discrete connectivities in 'connect_group'. More...
 
RE_ElementArraygetConnectElementArray (int connect_group, int index=0)
 Returns the element array associated with connect_group, if any. More...
 
bool hasConnectGroup (int connect_group) const
 Returns true if the connectivity index 'connect_group' exists. More...
 
bool hasNonEmptyConnectGroup (int connect_group) const
 Create a new instance group. instance_group must be a positive int. More...
 
int getMaxConnectGroup () const
 
bool removeConnectedPrims (int connect_group)
 
void resetConnectedPrims ()
 Removes and deletes all connectivity groups. More...
 
static void getInstanceGroupName (UT_WorkBuffer &inst_name, const char *base_name, int instance_group)
 Return a full instance group name based on an original base attrib name. More...
 
static void getInstanceGroupName (UT_WorkBuffer &inst_name, RE_GenericAttribID attrib_type, int instance_group)
 Return a full instance group name based on the known attribute type. More...
 

Detailed Description

A collection of vertex arrays defining a geometry object. This class acts as a wrapper around multiple RE_VertexArray objects, similar to the way a framebuffer object contains multiple textures. Arrays can be attached to various attachments points, representing different vertex attribute data.

Examples:
DM/DM_BackgroundHook.C, DM/DM_LightBloomHook.C, DM/DM_ObjectPathHook.C, DM/DM_SceneBoundsHook.C, GUI/GUI_PolySoupBox.C, GUI/GUI_PolySoupBox.h, tetprim/GR_PrimTetra.C, and tetprim/GR_PrimTetra.h.

Definition at line 53 of file RE_Geometry.h.

Constructor & Destructor Documentation

RE_Geometry::RE_Geometry ( int  num_points = 0,
bool  use_buffer_object = true 
)
RE_Geometry::~RE_Geometry ( )

Member Function Documentation

RE_VertexArray* RE_Geometry::assignAttributeDefault ( RE_Render r,
const char *  attrib_name,
RE_GPUType  data_format,
int  vectorsize,
const void default_value 
)

Create a constant attribute if varying attribute is not found Ensures that there is at least a constant attribute value available if the attribute doesn't exist already. Only returns an array if one was created.

bool RE_Geometry::assignMaterialToConnectivty ( RE_Render r,
int  connect_index,
const RE_MaterialPtr mat 
)

Assign a new material to connectivity group 'connect_index'. The connectivity group must exist or it will do nothing but return false.

bool RE_Geometry::attachAttribute ( RE_VertexArray attrib)

Attach an existing attribute using its name as the binding.

bool RE_Geometry::cacheBuffers ( const char *  name)

Caching
.

Use caching for all vertex and element arrays stored by this object. If any vertex arrays are attached, they are cleared unless the name matches the previous cache name. Set the base cache name. Attribute names will be concatenated to the base name to form the full cache name. Passing nullptr will disable caching. Returns true if the cachename changed, in which case all existing buffers will be purged from the cache.

Examples:
tetprim/GR_PrimTetra.C.
void RE_Geometry::clearAddressableAttribute ( const char *  attrib_name)

Delete the addressable attribute named 'attrib_name'.

bool RE_Geometry::clearAttribute ( const char *  name,
bool  purge_cache = false 
)

Delete an attached vertex attribute by name delete the RE_VertexArray, and if purge_cache is true, remove the underlying data buffer from the GL cache.

bool RE_Geometry::clearAttributeByIndex ( int  i,
bool  purge_cache = false 
)

Delete an attached vertex attribute by index delete the RE_VertexArray, and if purge_cache is true, remove the underlying data buffer from the GL cache.

bool RE_Geometry::clearInstanceGroupAttrib ( int  instance_group,
RE_GenericAttribID  attrib_id,
const char *  name 
)

Remove and delete the array.

void RE_Geometry::clearInstanceGroupNesting ( int  instance_group)

Create a new instance group. instance_group must be a positive int.

int RE_Geometry::clearStashedAttributes ( bool  purge_from_cache)

Remove all remaining stashed attributes. If purge is true, remove them from the GL cache as well.

int RE_Geometry::connectAllPrims ( RE_Render r,
int  connect_index,
RE_PrimType  prim,
const RE_MaterialPtr mat = nullptr,
bool  replace = false,
int  vertices_per_patch = 0 
)

Primitive Connectivity
.

These methods allow you to set up and cache primitive connectivity. Each bit of primitive connectivity is added to a named group, like 'wireframe' or 'shaded'. A connectivity group can have multiple types of primitives or materials. Groups are indexed, using int ids. You can pass an optional material to each set of connected prims. If the material is null, it will use the last used material (which may be the material of earlier connected primitives). Materials are not owned by this class; the element arrays are. If 'replace' is true, any previous connectivity established with the name 'connect_group' will be removed and replaced with the new connectivity. Connect all primitives and place them in indexed group 'connect_index'

Examples:
DM/DM_SceneBoundsHook.C, and tetprim/GR_PrimTetra.C.
int RE_Geometry::connectIndexedPrims ( RE_Render r,
int  connect_group,
RE_PrimType  prim,
int  num,
const unsigned int prims,
const RE_MaterialPtr mat = nullptr,
bool  replace = false,
int  vertices_per_patch = 0 
)

Connect vertices using an indexed vertex list, add to 'connect_group'. 'num' is the size of the list, not the number of primitives. If any index is greater than the number of points in the geometry, the results will be undefined. This is added to connect_group.

int RE_Geometry::connectIndexedPrims ( RE_Render r,
int  connect_group,
RE_PrimType  prim,
RE_VertexArray elements,
const RE_MaterialPtr mat = nullptr,
bool  replace = false,
int  vertices_per_patch = 0 
)

Connect vertices using the indices in the buffer object 'elements'.

int RE_Geometry::connectIndexedPrims ( RE_Render r,
int  connect_group,
RE_ElementArray elements,
const RE_MaterialPtr mat = nullptr,
bool  replace = false 
)

Connect vertices using the indices in the element array 'elements'.

int RE_Geometry::connectSomePrims ( RE_Render r,
int  connect_group,
RE_PrimType  prim,
int  start,
int  length,
unsigned int  stride = 0,
const RE_MaterialPtr mat = nullptr,
bool  replace = false,
int  vertices_per_patch = 0 
)

Connect a subrange of vertices and place in index group 'connect_index'.

RE_VertexArray* RE_Geometry::createAddressableAttribute ( RE_Render r,
const char *  attrib_name,
int  length,
RE_GPUType  data_format,
int  vectorsize,
const void data,
RE_ArrayType  atype = RE_ARRAY_RANDOM,
const char *  cache_prefix = nullptr 
)

Create a randomly addressable attribute (texture buffer object) Attributes can be stored in texture buffers, and accessed out of the normal vertex flow, such as for vertex or primitive attributes. Unlike normal attributes, addressable attributes can have a different array size than the RE_Geometry's number of vertices.

RE_Texture* RE_Geometry::createAddressableAttribute ( RE_Render r,
const char *  attrib_name,
RE_VertexArray data 
)

Create a randomly addressable attribute from an existing vertex array.

RE_VertexArray* RE_Geometry::createAttribute ( RE_Render r,
const char *  attrib_name,
RE_GPUType  data_format,
int  vectorsize,
const void data,
RE_ArrayType  atype = RE_ARRAY_POINT,
int  array_size = 0,
RE_BufferUsageHint  h = RE_BUFFER_WRITE_FREQUENT,
const char *  cache_prefix = nullptr,
int  capacity = -1 
)

Create a generic vertex attribute attached to 'attrib_name' Attributes are referenced by name, rather than buffer type. Array size is required if array type is RANDOM or INSTANCED.

Examples:
DM/DM_SceneBoundsHook.C.
RE_VertexArray* RE_Geometry::createConstAttribute ( RE_Render r,
const char *  attrib_name,
RE_GPUType  data_format,
int  vectorsize,
const void data 
)

Create a constant attribute value Only RE_GPU_FLOAT32 and _FLOAT64 are supported for constant data. The 'data' point must hold at least 1 element (sizeof(type)*vectorsize).

Examples:
tetprim/GR_PrimTetra.C.
RE_VertexArray* RE_Geometry::createConstInstanceGroupAttrib ( RE_Render r,
int  instance_group,
const char *  name,
RE_GPUType  data_format,
int  vectorsize,
const void data 
)

Create a constant for an attribute in 'instance_group'.

RE_VertexArray* RE_Geometry::createInstancedAttribute ( RE_Render r,
const char *  attrib_name,
RE_GPUType  data_format,
int  vectorsize,
int  instance_stride,
int  num_instances,
const void data,
const char *  cache_prefix = nullptr,
int  capacity = -1 
)

Create an instanced vertex attribute attached to 'attrib_name' Create an attribute which advances once every 'instance_stride' instances rather than once per vertex. RE_EXT_INSTANCED_ARRAYS is required, and an instanced drawing method must be used (or it acts as a uniform).

void RE_Geometry::createInstanceGroup ( int  instance_group)

Create a new instance group. instance_group must be a positive int.

RE_VertexArray* RE_Geometry::detachAttribute ( const char *  name)

Detatch an attribute from this object by name.

void RE_Geometry::disableArrays ( RE_Render r,
int  connect_group 
)

Manually enable and disable arrays. This is useful for determining which ones are actually enabled via r->dumpNewState().

void RE_Geometry::draw ( RE_Render r,
int  connect_idx,
RE_PrimType  prim_type = RE_PRIM_AS_IS,
RE_OverrideList attrib_overrides = nullptr 
)
inline

Draw an indexed connectivity group. Draws the primitives specified by the cached connectibity info.

Examples:
DM/DM_SceneBoundsHook.C, and tetprim/GR_PrimTetra.C.

Definition at line 627 of file RE_Geometry.h.

void RE_Geometry::drawAll ( RE_Render r,
RE_PrimType  prim_type = RE_PRIM_AS_IS,
RE_OverrideList attrib_overrides = nullptr 
)

Draw all connectivity groups. Draws all connect_groups. Same as looping through all groups and calling draw(). The draw order is undefined; if you need a specific order, use multiple draw calls.

void RE_Geometry::drawAllInstanced ( RE_Render r,
int  num_instances,
RE_PrimType  prim_type = RE_PRIM_AS_IS,
RE_OverrideList attrib_overrides = nullptr 
)

Draw all connectivity groups using instancing, num_instance times.

void RE_Geometry::drawIndirect ( RE_Render r,
int  connect_group,
RE_VertexArray indirect_buffer 
)

Draw an indexed connectivity group. Draws the primitives specified by the cached connectibity info.

void RE_Geometry::drawInstanced ( RE_Render r,
int  connect_idx,
int  num_instances,
RE_PrimType  prim_type = RE_PRIM_AS_IS,
RE_OverrideList attrib_overrides = nullptr 
)

Draw with Instancing Draws the same connect group 'num_instances' times. It is up to the shader to differentiate the instances, using an instanced attribute (createInstancedAttribute()) or GLSL's gl_InstanceID.

void RE_Geometry::drawInstanceGroup ( RE_Render r,
int  connect_idx,
int  instance_group,
RE_PrimType  prim_type = RE_PRIM_AS_IS,
RE_OverrideList attrib_over = nullptr 
)

Draw an instance group using a given connectivity.

Examples:
tetprim/GR_PrimTetra.C.
void RE_Geometry::drawInstanceGroupRange ( RE_Render r,
int  connect_start,
int  num_connect,
int  instance_group,
RE_PrimType  prim_type = RE_PRIM_AS_IS,
RE_OverrideList attrib_over = nullptr,
const int material_offset = nullptr 
)

Draw an instance group using a given connectivity.

void RE_Geometry::drawRange ( RE_Render r,
int  connect_group_start,
int  num_connect_groups,
RE_PrimType  ptype = RE_PRIM_AS_IS,
RE_OverrideList attrib_overrides = nullptr,
const int material_offset = nullptr 
)

Draws all indexed connect groups in the range if 'material_offset' is non-null, it acts as a offset when setting the MATERIAL_GROUP uniform, which is added to (index-connect_group_start) when drawing indexed connect groups. If num_connected_groups is negative, all valid groups >= 'connect_group_start' are drawn, otherwise it only draws up to start+num-1.

void RE_Geometry::drawRangeInstanced ( RE_Render r,
int  connect_start,
int  num_connect,
int  num_instances,
RE_PrimType  prim_type = RE_PRIM_AS_IS,
RE_OverrideList attrib_overrides = nullptr,
const int material_offset = nullptr 
)

Draw a range of connectivity index groups with instancing.

void RE_Geometry::enableArrays ( RE_Render r,
int  connect_group,
unsigned int  stride = 0 
)

Manually enable and disable arrays. This is useful for determining which ones are actually enabled via r->dumpNewState().

RE_VertexArray* RE_Geometry::fetchStashedAttribute ( const char *  name)

fetch stashed attribute 'name' from the stash list, removing it from the list and returning it if found. This does not place it back in the geometry's list of attributes.

RE_VertexArray * RE_Geometry::findCachedAttrib ( RE_Render r,
const char *  attrib_name,
RE_GPUType  data_format,
int  vectorsize,
RE_ArrayType  array_type,
bool  create_if_missing = false,
int  random_array_size = -1,
const RE_CacheVersion cv = nullptr,
RE_BufferUsageHint  h = RE_BUFFER_WRITE_FREQUENT,
const char *  cache_prefix = nullptr,
int  capacity = -1 
)
inline

Find an attribute or array in the GL cache, possibly creating it Returns the cached array, if it exists, for the array named 'attrib_name'. The name may be one of the gl-builtin attributes, like gl_Position or gl_Color. 'array_size' is the size of an INSTANCE or RANDOM array_type.

Examples:
tetprim/GR_PrimTetra.C.

Definition at line 880 of file RE_Geometry.h.

RE_VertexArray * RE_Geometry::findCachedInstancedAttrib ( RE_Render r,
const char *  attrib_name,
RE_GPUType  data_format,
int  vectorsize,
int  instance_step,
int  array_size,
bool  create_if_missing = false,
const RE_CacheVersion v = nullptr,
RE_BufferUsageHint  h = RE_BUFFER_WRITE_FREQUENT,
const char *  cache_prefix = nullptr,
int  capacity = -1 
)
inline

Find an instanced attribute in the GL cache, possibly creating it. The instance_step parameter defines how often the attribute is advanced when the instance ID changes - 1 is once per instance.

Definition at line 899 of file RE_Geometry.h.

RE_VertexArray* RE_Geometry::findCachedInstanceGroupAttrib ( RE_Render r,
int  instance_group,
const char *  name,
RE_GPUType  data_type,
int  vector_size,
int  instance_step,
int  num_instances,
bool  create = false,
const RE_CacheVersion v = nullptr,
RE_BufferUsageHint  h = RE_BUFFER_WRITE_FREQUENT,
const char *  view_name = nullptr,
int  capacity = -1 
)

Find an instance-group attribute in the cache Creates an instanced attribute for an instance-group, which overrides the base attribute on the RE_Geometry. instance_group zero is the base level ("Cd"), all other groups have the group appended ("Cd1" for group 1). When drawn with drawInstanceGroup(), attributes in the specified instance group will be used (if present) instead of the base attributes.

RE_VertexArray* RE_Geometry::getAddressableAttribute ( const char *  attrib_name) const

Fetch an addressable attribute by name.

RE_VertexArray* RE_Geometry::getAddressableAttributeByIndex ( int  index) const
inline

Return the vertex arrayrepresenting addressable attribute 'i'.

Definition at line 288 of file RE_Geometry.h.

int RE_Geometry::getAddressableAttributeIndex ( const char *  attrib_name) const

Return the index of the named addressable attribute, or -1 if not found.

RE_Texture* RE_Geometry::getAddressableAttributeTexture ( int  index) const
inline

Return the texture buffer object representing addressable attribute 'i'.

Definition at line 285 of file RE_Geometry.h.

RE_VertexArray* RE_Geometry::getAttribute ( const char *  name) const

Fetch an attribute by name.

RE_VertexArray * RE_Geometry::getAttribute ( RE_GenericAttribID  attrib_id) const
inline

Fetch an attribute by known type.

Definition at line 918 of file RE_Geometry.h.

RE_VertexArray* RE_Geometry::getAttributeByIndex ( int  i) const

Return currently attached vertex attribute 'i'.

int RE_Geometry::getAttributeIndex ( const char *  name) const

Return an attribute's index byattribute name. Can change if attributes are removed or added.

const char* RE_Geometry::getCacheName ( ) const
inline

Return the base cache name.

Definition at line 309 of file RE_Geometry.h.

RE_ElementArray* RE_Geometry::getConnectElementArray ( int  connect_group,
int  index = 0 
)

Returns the element array associated with connect_group, if any.

RE_MaterialPtr RE_Geometry::getConnectivityMaterial ( int  connect_index,
int  subindex = 0 
)

Returns the material attached to the given connectivity group, if any. If multiple connectivities were assigned to a group with different materials, the subindex is used to select which connectivity is queried.

int RE_Geometry::getConnectNumElementArrays ( int  connect_group)

Returns the number of discrete connectivities in 'connect_group'.

RE_VertexArray* RE_Geometry::getInstanceGroupAttrib ( int  instance_group,
RE_GenericAttribID  attrib_id,
const char *  name 
)

Return the attribute in the instance group with type 'attrib_id', or if it's not a known type, by name.

int RE_Geometry::getInstanceGroupCount ( int  instance_group) const

Returns the number of instances to be drawn in an instance group.

static void RE_Geometry::getInstanceGroupName ( UT_WorkBuffer inst_name,
const char *  base_name,
int  instance_group 
)
static

Return a full instance group name based on an original base attrib name.

static void RE_Geometry::getInstanceGroupName ( UT_WorkBuffer inst_name,
RE_GenericAttribID  attrib_type,
int  instance_group 
)
static

Return a full instance group name based on the known attribute type.

RE_VertexArray* RE_Geometry::getInstanceGroupTextureBufferForShader ( RE_Render r,
RE_Shader sh,
int  instance_group,
RE_GenericAttribID  attr_id,
const char *  name 
)

This is the same as getInstanceGroupAttrib(), but it used mainly by RE_Shader to do additional prep on the attrib.

int RE_Geometry::getMaxConnectGroup ( ) const

Returns the largest index of all the indexed connect groups. Some may be nullptr.

int64 RE_Geometry::getMemoryUsage ( bool  inclusive) const

Returns the amount of main memory (NOT graphics memory!) owned by this RE_Geometry.

int RE_Geometry::getNumAddressableAttributes ( ) const
inline

Return the number of addressable attributes.

Definition at line 281 of file RE_Geometry.h.

int RE_Geometry::getNumAttributes ( ) const

Return the number of generic attributes currently attached.

int RE_Geometry::getNumInstanceGroups ( ) const
inline

Create a new instance group. instance_group must be a positive int.

Definition at line 383 of file RE_Geometry.h.

int RE_Geometry::getNumPoints ( ) const
inline

Number of points in the geometry. Number of points for the arrays declared as RE_ARRAY_POINT. This will clear the data in all point arrays and reset the connectivty.

Definition at line 84 of file RE_Geometry.h.

int RE_Geometry::getNumPrimitives ( ) const
inline

Sets the number of elements in arrays declared as RE_ARRAY_PRIMITIVE.

Definition at line 96 of file RE_Geometry.h.

int RE_Geometry::getNumVertices ( ) const
inline

Sets the number of elements in arrays declared as RE_ARRAY_VERTEX.

Definition at line 90 of file RE_Geometry.h.

const RE_VertexMap* RE_Geometry::getVertexMap ( ) const
inline

Return a vertex map representing the layout locations of the attributes.

Definition at line 239 of file RE_Geometry.h.

bool RE_Geometry::hasConnectGroup ( int  connect_group) const

Returns true if the connectivity index 'connect_group' exists.

bool RE_Geometry::hasInstanceGroup ( int  instance_group) const

Returns true if the specified instance group exists.

bool RE_Geometry::hasNonEmptyConnectGroup ( int  connect_group) const

Create a new instance group. instance_group must be a positive int.

bool RE_Geometry::hasStashedAttribute ( const char *  name)

place all attributes in a stashed list, which clears them externally but keeps them available internally. If createAttribute() or findCached...() are called, attributes will be fetched from the stashed list. This should not be called without a clearStashedAttributes() pairing it, nor called twice in a row.

void RE_Geometry::initialize ( RE_Render r)

Create buffers for all attached arrays When the above methods are called with attached arrays, these arrays might have their storage freed. This call will ensure that all arrays are initialized.

bool RE_Geometry::isCaching ( ) const
inline

Check if this geometry object is caching.

Definition at line 312 of file RE_Geometry.h.

void RE_Geometry::print ( std::ostream *  out = nullptr) const
void RE_Geometry::purgeBuffers ( )

Clears all the attached buffers, and removes them from the cache.

Examples:
DM/DM_ObjectPathHook.C.
void RE_Geometry::purgeOnDelete ( bool  purge = true)
inline

Remove all buffers from the cache when this geometry object is deleted.

Definition at line 315 of file RE_Geometry.h.

RE_VertexArray* RE_Geometry::recallStashedAttribute ( const char *  name)

fetch stashed attribute 'name', placing it back into the geometry's list

RE_VertexArray* RE_Geometry::recallStashedConstAttribute ( const char *  attrib_name)

fetch stashed attribute 'name', but only if it is a const buffer.

RE_VertexArray* RE_Geometry::recallStashedVaryingAttribute ( const char *  attrib_name)

fetch stashed attribute 'name', but only if it is a const buffer.

bool RE_Geometry::removeConnectedPrims ( int  connect_group)

Remove and delete the connection group specified, return false only if the group doesn't exist.

void RE_Geometry::removeInstanceGroup ( int  instance_group)

Remove an existing instance group. Will not remove any attached attribute to that group, but the instance group can no longer be rendered.

void RE_Geometry::resetConnectedPrims ( )

Removes and deletes all connectivity groups.

void RE_Geometry::resetVertexState ( RE_Render r)

resets all VAOs so that on the next draw all VBOs are rebound

void RE_Geometry::resizePointsToFit ( RE_PrimType  primtype,
int  num_primitives,
bool  shrink_if_smaller,
RE_Shader shader = nullptr 
)

Calulcate the number of points required for some primitives This will ensure that the buffer is big enough to hold enough vertices for the given number of primitives of the specified type. The buffer size can be reduced if 'shrink_if_smaller' is true, otherwise this will only increase the size of the buffer if needed. If 'shader' is given, it will check if the shader has a geometry shader and modify the number of vertices by the output primitive type and maximum #vertices. Shaders without a geometry shader will have no effect (as if nullptr). For transform feedback, only POINTS, LINES or TRIANGLES are ever produced.

void RE_Geometry::setCacheTag ( RE_CacheTagHandle  h)

Assign a cache tag to monitor cache changes on this object The tag will be bumped if this or any of its vertex buffers are removed from the cache.

void RE_Geometry::setCacheVersion ( RE_CacheVersion  v)

set the cache version for all arrays attached to this geometry object.

void RE_Geometry::setConstInstanceGroupTransform ( int  instance_group,
const UT_Matrix4D xform,
bool  remove_instanced_xform 
)

Create a constant transform for an instance group.

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

Create a new instance group. instance_group must be a positive int.

void RE_Geometry::setDebugDraw ( bool  dump_uniforms,
bool  dump_builtins,
bool  dump_gl_state 
)
void RE_Geometry::setInstanceGroupConstIndex ( RE_Render r,
int  instance_group,
int  instance_to_draw 
)

Set to draw a single instance in the group.

void RE_Geometry::setInstanceGroupDrawEverything ( RE_Render r,
int  instance_group 
)

Set to draw all instances (based on the # transforms).

void RE_Geometry::setInstanceGroupDrawNothing ( RE_Render r,
int  instance_group 
)

Draw none of the instances.

void RE_Geometry::setInstanceGroupIndexList ( RE_Render r,
int  instance_group,
bool  trivial,
const UT_IntArray indices = nullptr,
int  max_capacity = -1 
)

For instanced drawing, create indirection list to render only some of the instances. The base instance group can also be indexed.

void RE_Geometry::setInstanceGroupNesting ( int  instance_group,
const UT_IntArray count_per_level 
)

Use nested instancing, rather than flattening data into arrays of length N*M (for M instances nested within N instances). This requires data arrays of size N+M. Element 0 contains the count of the instances in the topmost level (N). Up to 9 levels are supported. Instance indices are still expected in the range [0, N*M)

void RE_Geometry::setNumMaterialLayers ( int  num)
inline

Clamp the number of layers to draw with a multi-layer material.

Definition at line 874 of file RE_Geometry.h.

bool RE_Geometry::setNumPoints ( int  num)

Number of points in the geometry. Number of points for the arrays declared as RE_ARRAY_POINT. This will clear the data in all point arrays and reset the connectivty.

Examples:
tetprim/GR_PrimTetra.C.
bool RE_Geometry::setNumPrimitives ( int  num)

Sets the number of elements in arrays declared as RE_ARRAY_PRIMITIVE.

bool RE_Geometry::setNumVertices ( int  num)

Sets the number of elements in arrays declared as RE_ARRAY_VERTEX.

void RE_Geometry::stashAttributes ( )

place all attributes in a stashed list, which clears them externally but keeps them available internally. If createAttribute() or findCached...() are called, attributes will be fetched from the stashed list. This should not be called without a clearStashedAttributes() pairing it, nor called twice in a row.

void RE_Geometry::unbindAllArrays ( RE_Render r)

Remove all arrays and attributes from their GL bindings.

void RE_Geometry::useAttribute ( int  connect_group,
const char *  name,
bool  enable 
)

Toggles the use of a generic vertex attribute for a connect group. Index group version of useAttribute(); toggles the attribute named 'name' on or off.

Methods to control which attributes are used when drawing a connect_group. By default, all are enabled. When disabling an array or attribute, it will return zero to the vertex shader.

void RE_Geometry::useAttribute ( int  connect_group,
RE_VertexArray attrib,
bool  enable 
)

Toggles the use of a generic vertex attribute for a connect group. Index group version of useAttribute(); toggles the attribute specified by 'attrib' on or off.

void RE_Geometry::useBufferObjects ( bool  use_buf = true)

Choose between buffer objects and client arrays By default, buffer objects are used if supported. This allows you to turn them off and use vertex arrays. This is useful if the geometry information is throw-away. If called when vertex arrays are attached, they will be cleared (and possibly deleted)

void RE_Geometry::useMaterialTextures ( bool  enable = true)
inline

Enables or disables textures on materials when drawn.

Definition at line 868 of file RE_Geometry.h.

void RE_Geometry::useVertexState ( bool  use_state = true)

Optimize this geometry with vertex array objects. Use an RE_VertexState (and GL Vertex Array Objects) to contain vertex arrays. Requires RE_EXT_VERTEX_ARRAY_OBJECT.

Friends And Related Function Documentation

friend class re_InstanceGroup
friend

Definition at line 864 of file RE_Geometry.h.


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