2#include "mesh_render_info.h"
37 std::unique_ptr<std::vector<idx_type>> permutation;
40 if (sort_by_groups || sort_by_materials) {
41 permutation = std::make_unique<std::vector<idx_type>>();
42 mesh.
sort_faces(*permutation, sort_by_groups, sort_by_materials);
59 vbe.
replace(ctx, 0, &edge_element_buffer.front(), edge_element_buffer.size());
60 vbe.
replace(ctx,
sizeof(
idx_type)*edge_element_buffer.size(), &triangle_element_buffer.front(), triangle_element_buffer.size());
69 for (
int dvi : dynamic_vbos) {
75 for (
attribute_type at = attribute_type::begin; at < attribute_type::end; ++(
int&)at) {
76 if (attribute_to_vbo_index_map.find(at) != attribute_to_vbo_index_map.end()) {
77 if (!mesh.has_attribute(at)) {
78 ctx.
error(std::string(
"attempt to add attribute ") + mesh.get_attribute_name(at) +
" to mesh_render_info although missing in mesh");
81 uint32_t vi = attribute_to_vbo_index_map.at(at);
86 vbo_config[vi].stride += uint32_t(mesh.get_attribute_size(at));
90 for (
size_t vi = 0; vi <
vbo_config.size(); ++vi) {
110 int aa_index = (int)
ref_aas().size();
114 auto& aa =
ref_aas()[aa_index];
115 auto& wire_aa =
ref_aas()[aa_index + 1];
118 aa.aab_ptr->create(ctx);
121 wire_aa.aab_ptr->create(ctx);
124 aa.aab_ptr->set_element_array(ctx, *
ref_vbos().back());
125 wire_aa.aab_ptr->set_element_array(ctx, *
ref_vbos().back());
147 static int nr_comps[] = { 4,4,3,4 };
151 aa.add_attribute(ctd, avc.vbo_index, avc.offset,
nr_vertices,
vbo_config[avc.vbo_index].stride, cgv::render::VA_COLOR);
152 wire_aa.add_attribute(ctd, avc.vbo_index, avc.offset,
nr_vertices,
vbo_config[avc.vbo_index].stride, cgv::render::VA_COLOR);
156 dc.aa_index = aa_index;
157 dc.primitive_type = PT_TRIANGLES;
158 dc.vertex_offset = 0;
159 dc.draw_call_type = cgv::render::RCT_INDEXED;
161 dc.instance_count = 1;
163 dc.material_index = -1;
164 dc.alpha_mode = AM_OPAQUE;
179 dc.count = uint32_t(next_start - mps[2]);
181 dc.material_index = mps[0];
182 if (dc.material_index != -1) {
184 if ((mat.transparency_index != -1) ||
185 (mat.transparency > 0.01f)) {
186 dc.alpha_mode = AM_MASK_AND_BLEND;
187 dc.alpha_cutoff = 0.02f;
190 dc.alpha_mode = AM_OPAQUE;
211 dc.instance_count = nr;
212 switch (dc.draw_call_type) {
215 dc.draw_call_type = RCT_ARRAYS_INSTANCED;
219 dc.draw_call_type = RCT_INDEXED_INSTANCED;
221 case RCT_ARRAYS_INSTANCED:
223 dc.draw_call_type = RCT_ARRAYS;
225 case RCT_INDEXED_INSTANCED:
227 dc.draw_call_type = RCT_INDEXED;
235 std::vector<size_t> dcis;
253 for (
size_t i = 0; i < dcis.size(); ++i) {
the attribute_array_binding allows to define vertex attributes (i.e.
base class for all drawables, which is independent of the used rendering API.
virtual void error(const std::string &message, const render_component *rc=0) const
error handling
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::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
void draw_wireframe(cgv::render::context &ctx)
draw array elements forming the edges of the wireframe
cgv::render::type_descriptor tex_coords_descr
type description of tex coordinate attribute
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.
bool include_tex_coords
store whether tex coords are in vbo
bool include_normals
store whether normals are in vbo
void set_nr_instances(unsigned nr)
set the number of to be drawn instances - in case of 0, instanced drawing is turned off
bool include_tangents
store whether tangents are in vbo
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 dyna...
cgv::render::type_descriptor position_descr
type description of position attribute
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.
size_t nr_vertices
number of vertices
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
bool bind_wireframe(context &ctx, shader_program &prog, bool force_success)
bind all or specific aa to the passed shader program
cgv::media::ColorType ct
color type
bool attribute_is_used(attribute_type at) const
check whether a mesh attribute is used
mesh_render_info()
set vbo and vbe types
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)
size_t nr_edge_elements
number of edges in the wireframe representation
size_t element_size
size of single coordinate
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
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 destruct(cgv::render::context &ctx)
destruct render mesh info and free vertex buffer objects
size_t nr_triangle_elements
number of triangles in the triangulation
std::vector< vertex_buffer * > & ref_vbos()
give write access to vbos
virtual bool bind(context &ctx, shader_program &prog, bool force_success, int aa_index=-1)
bind all or specific aa to the passed shader program
std::vector< textured_material * > & ref_materials()
give write access to materials
std::vector< draw_call > & ref_draw_calls()
give write access to draw calls
std::vector< attribute_array > & ref_aas()
give write access to aabs
void destruct(cgv::render::context &ctx)
destruct render mesh info and free vertex buffer objects
std::vector< draw_call > draw_calls
store vector of render calls
cgv::type::uint32_type idx_type
define index type
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
a shader program combines several shader code fragments to a complete definition of the shading pipel...
class that extends obj_material with the management of textures
a vertex buffer is an unstructured memory block on the GPU.
bool create(const context &ctx, size_t size_in_bytes)
create empty vertex buffer of size size given in bytes
bool replace(const context &ctx, size_t buffer_offset_in_bytes, const T *array_ptr, size_t nr_elements)
replace part (starting at byte offset buffer_offset_in_bytes) or whole vertex buffer content from nr_...
@ VBT_INDICES
The buffer contains indices and will be bound to GL_ELEMENT_ARRAY_BUFFER.
TypeId
ids for the different types and type constructs
@ TI_FLT32
floating point type stored in 16 bits
@ TI_UINT32
unsigned integer stored in 16 bits
@ TI_UINT8
signed integer stored in 64 bits
std::string to_string(const std::string &v, unsigned int w, unsigned int p, bool)
specialization of conversion from string to strings
this header is dependency free
compact type description of data that can be sent to the context; convertible to int