cgv
Loading...
Searching...
No Matches
cgv::render::mesh_render_info Class Reference

the mesh_render_info structure manages vertex buffer objects for attribute and element buffers as well as an attribute array binding object. More...

#include <mesh_render_info.h>

Inheritance diagram for cgv::render::mesh_render_info:
cgv::render::render_info

Classes

struct  attribute_configuration
 information needed per mesh attribute to know where it is stored in vbos More...
 
struct  vbo_configuration
 information stored per vbo More...
 

Public Types

typedef cgv::media::mesh::simple_mesh_base::attribute_type attribute_type
 redeclare attribute type for shorter name
 
typedef cgv::math::fvec< idx_type, 3 > idx3_type
 index triple type
 
typedef cgv::math::fvec< idx_type, 4 > idx4_type
 index quadruple type
 
typedef std::map< attribute_type, uint32_t > attribute_map
 type of map from mesh attribute to vbo index
 
- Public Types inherited from cgv::render::render_info
typedef cgv::type::uint32_type idx_type
 define index type
 

Public Member Functions

 mesh_render_info ()
 set vbo and vbe types
 
bool is_constructed () const
 check whether vbos are constructed
 
bool is_bound () const
 check whether attribute array binding is bound
 
template<typename T >
void construct (cgv::render::context &ctx, cgv::media::mesh::simple_mesh< T > &mesh, std::vector< idx_type > *tuple_pos_indices=nullptr, std::vector< idx_type > *tuple_normal_indices=nullptr, int *num_floats_in_vertex=nullptr)
 Construct mesh render info from a given simple mesh and store all vertex attributes in interleaved in one vertex buffer object that does not allow dynamic updates.
 
template<typename T >
void construct_dynamic (cgv::render::context &ctx, cgv::media::mesh::simple_mesh< T > &mesh, const attribute_map &va_vbo_idx, const std::vector< int > &dynamic_vbo_idx)
 Construct mesh render info from a given simple mesh and store vertex attributes flexibly in multiple vertex buffer objects which allow for dynamic updates.
 
template<typename T >
void update_vbo (cgv::render::context &ctx, cgv::media::mesh::simple_mesh< T > &mesh, int vbo_index)
 replace the content of one vbo from a mesh
 
void set_nr_instances (unsigned nr)
 set the number of to be drawn instances - in case of 0, instanced drawing is turned off
 
size_t get_nr_primitives () const
 return number of mesh primitives
 
const std::string & get_primitive_name (size_t i) const
 return name of i-th mesh primitive
 
size_t get_nr_fragments () const
 return number of mesh fragments that are of distinct primitive and material
 
size_t get_material_index (size_t i) const
 return material index of i-th fragment
 
size_t get_primitive_index (size_t i) const
 return group index of i-th fragment
 
size_t get_nr_vertices () const
 Returns how many vertices the mesh has.
 
size_t get_nr_edge_elements () const
 Returns how many edge-indices are recorded in the element buffer.
 
size_t get_nr_triangle_elements () const
 Returns how many triangle-indices are recorded in the element buffer.
 
size_t get_element_size () const
 Returns how many bytes on index value takes up in the element buffer.
 
void draw_primitive (cgv::render::context &ctx, size_t primitive_index, bool skip_opaque=false, bool skip_blended=false, bool use_materials=true)
 draw triangles of given mesh part or whole mesh in case part_index is not given (=-1)
 
bool bind (context &ctx, shader_program &prog, bool force_success, int aa_index=-1)
 override to restrict bind function to first aa as second is used for wireframe rendering
 
bool bind_wireframe (context &ctx, shader_program &prog, bool force_success)
 bind all or specific aa to the passed shader program
 
void draw_wireframe (cgv::render::context &ctx)
 draw array elements forming the edges of the wireframe
 
void destruct (cgv::render::context &ctx)
 destruct render mesh info and free vertex buffer objects
 
- Public Member Functions inherited from cgv::render::render_info
 render_info ()
 set vbo and vbe types
 
const std::vector< textured_material * > & get_materials () const
 give read access to materials
 
const std::vector< vertex_buffer * > & get_vbos () const
 give read access to vbos
 
const std::vector< attribute_array > & get_aas () const
 give read access to aabs
 
const std::vector< texture * > & get_textures () const
 give read access to texture
 
const std::vector< draw_call > & get_draw_calls () const
 give read access to draw calls
 
std::vector< textured_material * > & ref_materials ()
 give write access to materials
 
std::vector< vertex_buffer * > & ref_vbos ()
 give write access to vbos
 
std::vector< attribute_array > & ref_aas ()
 give write access to aabs
 
std::vector< texture * > & ref_textures ()
 give write access to texture
 
std::vector< draw_call > & ref_draw_calls ()
 give write access to draw calls
 
void draw_all (context &ctx, bool skip_opaque=false, bool skip_blended=false, bool use_materials=true)
 execute all draw calls
 
void destruct (cgv::render::context &ctx)
 destruct render mesh info and free vertex buffer objects
 

Protected Member Functions

bool attribute_is_used (attribute_type at) const
 check whether a mesh attribute is used
 
bool configure_vbos (cgv::render::context &ctx, const cgv::media::mesh::simple_mesh_base &mesh, const attribute_map &attribute_to_vbo_index_map, const std::vector< int > &dynamic_vbo_idx)
 configure which attributes should be stored, in which vbos they go and which vbos should support dynamic updates
 
void construct_index_buffers (cgv::render::context &ctx, const cgv::media::mesh::simple_mesh_base &mesh, std::vector< idx4_type > &unique_quadruples, std::vector< idx_type > &per_corner_vertex_index, std::vector< idx_type > &edges_element_buffer, std::vector< idx_type > &triangles_element_buffer)
 Prepare vertex attribute data creation by extraction of unique combinations of attribute indices.
 
void construct_element_vbo (cgv::render::context &ctx, const std::vector< idx_type > &edge_element_buffer, const std::vector< idx_type > &triangle_element_buffer)
 Uploads the given element buffers into EBOs on the GPU.
 
void construct_draw_calls (cgv::render::context &ctx)
 for each combination of primitive (face group of mesh) and material create and store one draw call
 
- Protected Member Functions inherited from cgv::render::render_info
void draw (context &ctx, const draw_call &dc, const draw_call *prev_dc=0, const draw_call *next_dc=0, bool use_materials=true)
 perform a single render call
 

Protected Attributes

std::vector< std::string > primitive_names
 store list of primitive names
 
std::vector< idx3_typematerial_primitive_start
 index triple storing the material index, the primitive index and the offset (element index) in the triangle element buffer
 
bool include_tex_coords
 store whether tex coords are in vbo
 
bool include_normals
 store whether normals are in vbo
 
bool include_tangents
 store whether tangents are in vbo
 
bool include_colors
 store whether colors are in vbo
 
size_t nr_vertices
 number of vertices
 
size_t nr_edge_elements
 number of edges in the wireframe representation
 
size_t nr_triangle_elements
 number of triangles in the triangulation
 
size_t element_size
 size of single coordinate
 
draw_call wire_draw_call
 draw call for wireframe rendering
 
cgv::render::type_descriptor position_descr
 type description of position attribute
 
cgv::render::type_descriptor tex_coords_descr
 type description of tex coordinate attribute
 
size_t color_increment
 color type size in bytes
 
cgv::media::ColorType ct
 color type
 
std::vector< vbo_configurationvbo_config
 store for each vbo its configuration
 
std::map< attribute_type, attribute_configurationper_attribute_vbo_config
 for each mesh attribute that is used, map attribute type to the vbo index
 
std::vector< idx4_typeunique_quadruples
 in case that at least one vbo is replaceable, store per vertex the unique quadruple of attribute indices
 
- Protected Attributes inherited from cgv::render::render_info
std::vector< textured_material * > materials
 store materials
 
std::vector< texture * > textures
 store textures
 
std::vector< vertex_buffer * > vbos
 store buffers
 
std::vector< attribute_arrayaas
 store attribute bindings
 
std::vector< draw_calldraw_calls
 store vector of render calls
 

Detailed Description

the mesh_render_info structure manages vertex buffer objects for attribute and element buffers as well as an attribute array binding object.

The vertex buffer can be constructed from a simple mesh and the attribute array binding is bound to a specific shader program which defines the attribute locations.

Definition at line 15 of file mesh_render_info.h.

Member Typedef Documentation

◆ attribute_map

type of map from mesh attribute to vbo index

Definition at line 25 of file mesh_render_info.h.

◆ attribute_type

redeclare attribute type for shorter name

Definition at line 19 of file mesh_render_info.h.

◆ idx3_type

index triple type

Definition at line 21 of file mesh_render_info.h.

◆ idx4_type

index quadruple type

Definition at line 23 of file mesh_render_info.h.

Constructor & Destructor Documentation

◆ mesh_render_info()

cgv::render::mesh_render_info::mesh_render_info ( )

set vbo and vbe types

Definition at line 6 of file mesh_render_info.cxx.

References nr_edge_elements, and nr_triangle_elements.

Member Function Documentation

◆ attribute_is_used()

bool cgv::render::mesh_render_info::attribute_is_used ( attribute_type  at) const
protected

check whether a mesh attribute is used

Definition at line 62 of file mesh_render_info.cxx.

References per_attribute_vbo_config.

Referenced by construct_draw_calls(), and construct_index_buffers().

◆ bind()

bool cgv::render::mesh_render_info::bind ( context ctx,
shader_program prog,
bool  force_success,
int  aa_index = -1 
)
virtual

override to restrict bind function to first aa as second is used for wireframe rendering

Reimplemented from cgv::render::render_info.

Definition at line 98 of file mesh_render_info.cxx.

References cgv::render::render_info::bind().

Referenced by cgv::render::gl::gl_implicit_surface_drawable_base::draw(), vr_test::init(), and cgv::render::gl::mesh_drawable::init_frame().

◆ bind_wireframe()

bool cgv::render::mesh_render_info::bind_wireframe ( context ctx,
shader_program prog,
bool  force_success 
)

bind all or specific aa to the passed shader program

Definition at line 102 of file mesh_render_info.cxx.

References cgv::render::render_info::bind(), and wire_draw_call.

Referenced by cgv::render::gl::gl_implicit_surface_drawable_base::draw().

◆ configure_vbos()

bool cgv::render::mesh_render_info::configure_vbos ( cgv::render::context ctx,
const cgv::media::mesh::simple_mesh_base mesh,
const attribute_map attribute_to_vbo_index_map,
const std::vector< int > &  dynamic_vbo_idx 
)
protected

configure which attributes should be stored, in which vbos they go and which vbos should support dynamic updates

Definition at line 66 of file mesh_render_info.cxx.

References cgv::render::context::error(), per_attribute_vbo_config, cgv::utils::to_string(), and vbo_config.

◆ construct()

template<typename T >
void cgv::render::mesh_render_info::construct ( cgv::render::context ctx,
cgv::media::mesh::simple_mesh< T > &  mesh,
std::vector< idx_type > *  tuple_pos_indices = nullptr,
std::vector< idx_type > *  tuple_normal_indices = nullptr,
int *  num_floats_in_vertex = nullptr 
)
inline

Construct mesh render info from a given simple mesh and store all vertex attributes in interleaved in one vertex buffer object that does not allow dynamic updates.

Template Parameters
TThe coordinate type which is used in the cgv::media::mesh::simple_mesh
Parameters
ctxThe CGV rendering context.
meshThe general mesh which will be translated into appropriately formatted GPU buffers.
tuple_pos_indicesIf not nullptr, will be filled the mapping from unique vertex attribute tuples to the original position buffers of the mesh.
tuple_normal_indicesIf not nullptr, will be filled the mapping from unique vertex attribute tuples to the original normal buffers of the mesh.
num_floats_in_vertexIf not nullptr will be set to the number of floats which make up one vertex with all its attributes.

Definition at line 131 of file mesh_render_info.h.

References cgv::media::mesh::simple_mesh_base::extract_vertex_attribute_buffer_base(), cgv::media::colored_model::has_colors(), cgv::media::mesh::simple_mesh< T >::has_normals(), cgv::media::mesh::simple_mesh< T >::has_tangents(), cgv::media::mesh::simple_mesh< T >::has_tex_coords(), and cgv::render::VBT_VERTICES.

Referenced by cgv::render::gl::gl_implicit_surface_drawable_base::draw(), vr_test::init(), and cgv::render::gl::mesh_drawable::init_frame().

◆ construct_draw_calls()

◆ construct_dynamic()

template<typename T >
void cgv::render::mesh_render_info::construct_dynamic ( cgv::render::context ctx,
cgv::media::mesh::simple_mesh< T > &  mesh,
const attribute_map va_vbo_idx,
const std::vector< int > &  dynamic_vbo_idx 
)
inline

Construct mesh render info from a given simple mesh and store vertex attributes flexibly in multiple vertex buffer objects which allow for dynamic updates.

Definition at line 171 of file mesh_render_info.h.

References cgv::media::mesh::simple_mesh_base::extract_vertex_attribute_buffer_base(), and cgv::render::VBT_VERTICES.

◆ construct_element_vbo()

void cgv::render::mesh_render_info::construct_element_vbo ( cgv::render::context ctx,
const std::vector< idx_type > &  edge_element_buffer,
const std::vector< idx_type > &  triangle_element_buffer 
)
protected

Uploads the given element buffers into EBOs on the GPU.

Parameters
[in]ctxThe CGV drawing context.
[in]edge_element_bufferThe vector of indices which make up the edges of faces.
[in]triangle_element_bufferThe vector of indices which make up triangles.
See also
mesh_render_info::configure_vbos()

Definition at line 54 of file mesh_render_info.cxx.

References cgv::render::vertex_buffer::create(), nr_edge_elements, nr_triangle_elements, cgv::render::render_info::ref_vbos(), cgv::render::vertex_buffer::replace(), and cgv::render::VBT_INDICES.

◆ construct_index_buffers()

void cgv::render::mesh_render_info::construct_index_buffers ( cgv::render::context ctx,
const cgv::media::mesh::simple_mesh_base mesh,
std::vector< idx4_type > &  unique_quadruples,
std::vector< idx_type > &  per_corner_vertex_index,
std::vector< idx_type > &  edges_element_buffer,
std::vector< idx_type > &  triangles_element_buffer 
)
protected

Prepare vertex attribute data creation by extraction of unique combinations of attribute indices.

Parameters
[in]ctxThe render context.
[in]meshThe mesh which shall be transformed.
[out]vertex_indicesper face corner the vertex index or index of attribute index tuple
[out]unique_quadruplesthe list of attribute index tuples which aggregate unique combinations of vertex attribute indices
[out]triangle_element_bufferthe buffer with successive vertex index triples, which make up mesh triangles.
[out]edge_element_bufferthe buffer with successive vertex index pairs, which make up the mesh edges
See also
mesh_render_info::finish_construct_vbos_base()

Definition at line 24 of file mesh_render_info.cxx.

References attribute_is_used(), ct, cgv::media::mesh::simple_mesh_base::extract_triangle_element_buffer(), cgv::media::mesh::simple_mesh_base::extract_wireframe_element_buffer(), cgv::media::colored_model::get_color_storage_type(), cgv::media::mesh::simple_mesh_base::get_material(), cgv::media::mesh::simple_mesh_base::get_nr_groups(), cgv::media::mesh::simple_mesh_base::get_nr_materials(), include_colors, include_normals, include_tangents, include_tex_coords, material_primitive_start, cgv::media::mesh::simple_mesh_base::merge_indices(), nr_edge_elements, nr_triangle_elements, nr_vertices, cgv::render::render_info::ref_materials(), and cgv::media::mesh::simple_mesh_base::sort_faces().

◆ destruct()

◆ draw_primitive()

void cgv::render::mesh_render_info::draw_primitive ( cgv::render::context ctx,
size_t  primitive_index,
bool  skip_opaque = false,
bool  skip_blended = false,
bool  use_materials = true 
)

draw triangles of given mesh part or whole mesh in case part_index is not given (=-1)

Definition at line 232 of file mesh_render_info.cxx.

References cgv::render::render_info::draw(), cgv::render::render_info::draw_calls, and material_primitive_start.

Referenced by cgv::render::gl::mesh_drawable::draw_mesh_primitive().

◆ draw_wireframe()

void cgv::render::mesh_render_info::draw_wireframe ( cgv::render::context ctx)

draw array elements forming the edges of the wireframe

Definition at line 260 of file mesh_render_info.cxx.

References cgv::render::render_info::draw(), and wire_draw_call.

Referenced by cgv::render::gl::gl_implicit_surface_drawable_base::draw_implicit_surface().

◆ get_element_size()

size_t cgv::render::mesh_render_info::get_element_size ( ) const
inline

Returns how many bytes on index value takes up in the element buffer.

Definition at line 228 of file mesh_render_info.h.

◆ get_material_index()

size_t cgv::render::mesh_render_info::get_material_index ( size_t  i) const
inline

return material index of i-th fragment

Definition at line 217 of file mesh_render_info.h.

◆ get_nr_edge_elements()

size_t cgv::render::mesh_render_info::get_nr_edge_elements ( ) const
inline

Returns how many edge-indices are recorded in the element buffer.

Definition at line 224 of file mesh_render_info.h.

◆ get_nr_fragments()

size_t cgv::render::mesh_render_info::get_nr_fragments ( ) const
inline

return number of mesh fragments that are of distinct primitive and material

Definition at line 215 of file mesh_render_info.h.

◆ get_nr_primitives()

size_t cgv::render::mesh_render_info::get_nr_primitives ( ) const
inline

return number of mesh primitives

Definition at line 211 of file mesh_render_info.h.

◆ get_nr_triangle_elements()

size_t cgv::render::mesh_render_info::get_nr_triangle_elements ( ) const
inline

Returns how many triangle-indices are recorded in the element buffer.

Definition at line 226 of file mesh_render_info.h.

◆ get_nr_vertices()

size_t cgv::render::mesh_render_info::get_nr_vertices ( ) const
inline

Returns how many vertices the mesh has.

Definition at line 222 of file mesh_render_info.h.

◆ get_primitive_index()

size_t cgv::render::mesh_render_info::get_primitive_index ( size_t  i) const
inline

return group index of i-th fragment

Definition at line 219 of file mesh_render_info.h.

◆ get_primitive_name()

const std::string & cgv::render::mesh_render_info::get_primitive_name ( size_t  i) const
inline

return name of i-th mesh primitive

Definition at line 213 of file mesh_render_info.h.

◆ is_bound()

bool cgv::render::mesh_render_info::is_bound ( ) const
inline

check whether attribute array binding is bound

Definition at line 119 of file mesh_render_info.h.

◆ is_constructed()

bool cgv::render::mesh_render_info::is_constructed ( ) const
inline

check whether vbos are constructed

Definition at line 117 of file mesh_render_info.h.

Referenced by vr_test::draw().

◆ set_nr_instances()

void cgv::render::mesh_render_info::set_nr_instances ( unsigned  nr)

set the number of to be drawn instances - in case of 0, instanced drawing is turned off

Definition at line 208 of file mesh_render_info.cxx.

References cgv::render::render_info::ref_draw_calls().

◆ update_vbo()

template<typename T >
void cgv::render::mesh_render_info::update_vbo ( cgv::render::context ctx,
cgv::media::mesh::simple_mesh< T > &  mesh,
int  vbo_index 
)
inline

replace the content of one vbo from a mesh

Definition at line 200 of file mesh_render_info.h.

References cgv::media::mesh::simple_mesh_base::extract_vertex_attribute_buffer_base().

Member Data Documentation

◆ color_increment

size_t cgv::render::mesh_render_info::color_increment
protected

color type size in bytes

Definition at line 54 of file mesh_render_info.h.

◆ ct

cgv::media::ColorType cgv::render::mesh_render_info::ct
protected

color type

Definition at line 56 of file mesh_render_info.h.

Referenced by construct_draw_calls(), and construct_index_buffers().

◆ element_size

size_t cgv::render::mesh_render_info::element_size
protected

size of single coordinate

Definition at line 46 of file mesh_render_info.h.

Referenced by destruct().

◆ include_colors

bool cgv::render::mesh_render_info::include_colors
protected

store whether colors are in vbo

Definition at line 38 of file mesh_render_info.h.

Referenced by construct_index_buffers().

◆ include_normals

bool cgv::render::mesh_render_info::include_normals
protected

store whether normals are in vbo

Definition at line 34 of file mesh_render_info.h.

Referenced by construct_index_buffers().

◆ include_tangents

bool cgv::render::mesh_render_info::include_tangents
protected

store whether tangents are in vbo

Definition at line 36 of file mesh_render_info.h.

Referenced by construct_index_buffers().

◆ include_tex_coords

bool cgv::render::mesh_render_info::include_tex_coords
protected

store whether tex coords are in vbo

Definition at line 32 of file mesh_render_info.h.

Referenced by construct_index_buffers().

◆ material_primitive_start

std::vector<idx3_type> cgv::render::mesh_render_info::material_primitive_start
protected

index triple storing the material index, the primitive index and the offset (element index) in the triangle element buffer

Definition at line 30 of file mesh_render_info.h.

Referenced by construct_draw_calls(), construct_index_buffers(), destruct(), and draw_primitive().

◆ nr_edge_elements

size_t cgv::render::mesh_render_info::nr_edge_elements
protected

number of edges in the wireframe representation

Definition at line 42 of file mesh_render_info.h.

Referenced by construct_draw_calls(), construct_element_vbo(), construct_index_buffers(), destruct(), and mesh_render_info().

◆ nr_triangle_elements

size_t cgv::render::mesh_render_info::nr_triangle_elements
protected

number of triangles in the triangulation

Definition at line 44 of file mesh_render_info.h.

Referenced by construct_draw_calls(), construct_element_vbo(), construct_index_buffers(), destruct(), and mesh_render_info().

◆ nr_vertices

size_t cgv::render::mesh_render_info::nr_vertices
protected

number of vertices

Definition at line 40 of file mesh_render_info.h.

Referenced by construct_draw_calls(), construct_index_buffers(), and destruct().

◆ per_attribute_vbo_config

std::map<attribute_type, attribute_configuration> cgv::render::mesh_render_info::per_attribute_vbo_config
protected

for each mesh attribute that is used, map attribute type to the vbo index

Definition at line 76 of file mesh_render_info.h.

Referenced by attribute_is_used(), configure_vbos(), construct_draw_calls(), and destruct().

◆ position_descr

cgv::render::type_descriptor cgv::render::mesh_render_info::position_descr
protected

type description of position attribute

Definition at line 50 of file mesh_render_info.h.

Referenced by construct_draw_calls().

◆ primitive_names

std::vector<std::string> cgv::render::mesh_render_info::primitive_names
protected

store list of primitive names

Definition at line 28 of file mesh_render_info.h.

◆ tex_coords_descr

cgv::render::type_descriptor cgv::render::mesh_render_info::tex_coords_descr
protected

type description of tex coordinate attribute

Definition at line 52 of file mesh_render_info.h.

Referenced by construct_draw_calls().

◆ unique_quadruples

std::vector<idx4_type> cgv::render::mesh_render_info::unique_quadruples
protected

in case that at least one vbo is replaceable, store per vertex the unique quadruple of attribute indices

Definition at line 78 of file mesh_render_info.h.

◆ vbo_config

std::vector<vbo_configuration> cgv::render::mesh_render_info::vbo_config
protected

store for each vbo its configuration

Definition at line 68 of file mesh_render_info.h.

Referenced by configure_vbos(), construct_draw_calls(), and destruct().

◆ wire_draw_call

draw_call cgv::render::mesh_render_info::wire_draw_call
protected

draw call for wireframe rendering

Definition at line 48 of file mesh_render_info.h.

Referenced by bind_wireframe(), construct_draw_calls(), and draw_wireframe().


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