3#include "render_info.h"
4#include <cgv/media/mesh/simple_mesh.h>
56 cgv::media::ColorType
ct;
63 bool is_dynamic =
false;
72 uint32_t vbo_index = 0;
83 const attribute_map& attribute_to_vbo_index_map,
const std::vector<int>& dynamic_vbo_idx);
99 std::vector<idx4_type>& unique_quadruples, std::vector<idx_type>& per_corner_vertex_index,
100 std::vector<idx_type>& edges_element_buffer, std::vector<idx_type>& triangles_element_buffer);
110 void construct_element_vbo(
cgv::render::context& ctx,
const std::vector<idx_type>& edge_element_buffer,
const std::vector<idx_type>& triangle_element_buffer);
119 bool is_bound()
const {
return get_aas().size() > 0; }
130 template <
typename T>
132 std::vector<idx_type>* tuple_pos_indices =
nullptr,
133 std::vector<idx_type>* tuple_normal_indices =
nullptr,
134 int* num_floats_in_vertex =
nullptr)
136 element_size =
sizeof(T);
141 attribute_map va_vbo_idx = { { attribute_type::position, 0 } };
143 va_vbo_idx[attribute_type::texcoords] = 0;
145 va_vbo_idx[attribute_type::normal] = 0;
147 va_vbo_idx[attribute_type::tangent] = 0;
149 va_vbo_idx[attribute_type::color] = 0;
150 configure_vbos(ctx, mesh, va_vbo_idx, {});
152 std::vector<idx_type> vertex_indices, edge_element_buffer, triangle_element_buffer;
153 std::vector<idx4_type> unique_quadruples;
154 construct_index_buffers(ctx, mesh, unique_quadruples, vertex_indices, edge_element_buffer, triangle_element_buffer);
156 for (
const auto& tuple : unique_quadruples) {
157 if (tuple_pos_indices)
158 tuple_pos_indices->push_back(tuple[0]);
159 if (tuple_normal_indices)
160 tuple_normal_indices->push_back(tuple[2]);
162 std::vector<uint8_t> attrib_buffer;
165 ref_vbos().back()->create(ctx, attrib_buffer);
166 construct_element_vbo(ctx, edge_element_buffer, triangle_element_buffer);
167 construct_draw_calls(ctx);
170 template <
typename T>
172 const attribute_map& va_vbo_idx,
const std::vector<int>& dynamic_vbo_idx)
174 element_size =
sizeof(T);
179 configure_vbos(ctx, mesh, va_vbo_idx, dynamic_vbo_idx);
180 bool keep_unique_quadrupels = !dynamic_vbo_idx.empty();
183 std::vector<idx4_type> tmp_unique_quadruples;
184 std::vector<idx4_type>& unique_quadruples_ref = keep_unique_quadrupels ? unique_quadruples : tmp_unique_quadruples;
185 std::vector<idx_type> per_corner_vertex_index, edge_element_buffer, triangle_element_buffer;
186 construct_index_buffers(ctx, mesh, unique_quadruples_ref, per_corner_vertex_index, edge_element_buffer, triangle_element_buffer);
188 for (
const auto& vc : vbo_config) {
189 std::vector<uint8_t> attrib_buffer;
190 auto vca = vc.attributes;
193 ref_vbos().back()->create(ctx, attrib_buffer);
195 construct_element_vbo(ctx, edge_element_buffer, triangle_element_buffer);
196 construct_draw_calls(ctx);
199 template <
typename T>
202 const auto& vc = vbo_config[vbo_index];
203 std::vector<uint8_t> attrib_buffer;
204 auto vca = vc.attributes;
206 ref_vbos()[vbo_index]->replace(ctx, 0, &attrib_buffer[0], attrib_buffer.size());
209 void set_nr_instances(
unsigned nr);
231 void draw_primitive(
cgv::render::context& ctx,
size_t primitive_index,
bool skip_opaque =
false,
bool skip_blended =
false,
bool use_materials =
true);
244#include <cgv/config/lib_end.h>
A vector with zero based index.
base class for all drawables, which is independent of the used rendering API.
the mesh_render_info structure manages vertex buffer objects for attribute and element buffers as wel...
cgv::math::fvec< idx_type, 3 > idx3_type
index triple type
size_t get_nr_edge_elements() const
Returns how many edge-indices are recorded in the element buffer.
size_t get_material_index(size_t i) const
return material index of i-th fragment
std::vector< idx3_type > material_primitive_start
index triple storing the material index, the primitive index and the offset (element index) in the tr...
std::vector< idx4_type > unique_quadruples
in case that at least one vbo is replaceable, store per vertex the unique quadruple of attribute indi...
size_t get_nr_fragments() const
return number of mesh fragments that are of distinct primitive and material
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
bool is_bound() const
check whether attribute array binding is bound
std::map< attribute_type, attribute_configuration > per_attribute_vbo_config
for each mesh attribute that is used, map attribute type to the vbo index
std::vector< vbo_configuration > vbo_config
store for each vbo its configuration
size_t get_primitive_index(size_t i) const
return group index of i-th fragment
cgv::render::type_descriptor tex_coords_descr
type description of tex coordinate attribute
bool include_tex_coords
store whether tex coords are in vbo
size_t color_increment
color type size in bytes
bool include_normals
store whether normals are in vbo
bool include_tangents
store whether tangents are in vbo
cgv::render::type_descriptor position_descr
type description of position attribute
size_t nr_vertices
number of vertices
size_t get_nr_vertices() const
Returns how many vertices the mesh has.
cgv::media::mesh::simple_mesh_base::attribute_type attribute_type
redeclare attribute type for shorter name
cgv::media::ColorType ct
color type
const std::string & get_primitive_name(size_t i) const
return name of i-th mesh primitive
std::vector< std::string > primitive_names
store list of primitive names
size_t get_nr_triangle_elements() const
Returns how many triangle-indices are recorded in the element buffer.
size_t nr_edge_elements
number of edges in the wireframe representation
size_t get_element_size() const
Returns how many bytes on index value takes up in the element buffer.
cgv::math::fvec< idx_type, 4 > idx4_type
index quadruple type
size_t element_size
size of single coordinate
size_t get_nr_primitives() const
return number of mesh primitives
draw_call wire_draw_call
draw call for wireframe rendering
bool include_colors
store whether colors are in vbo
std::map< attribute_type, uint32_t > attribute_map
type of map from mesh attribute to vbo index
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 ...
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...
size_t nr_triangle_elements
number of triangles in the triangulation
bool is_constructed() const
check whether vbos are constructed
the mesh_render_info structure manages vertex buffer objects for attribute and element buffers as wel...
a shader program combines several shader code fragments to a complete definition of the shading pipel...
a vertex buffer is an unstructured memory block on the GPU.
@ VBT_VERTICES
The buffer contains vertices and will be bound to GL_ARRAY_BUFFER.
this header is dependency free
information needed per mesh attribute to know where it is stored in vbos
information stored per vbo
compact type description of data that can be sent to the context; convertible to int