cgv
Loading...
Searching...
No Matches
gltf_support.cxx
1#include <cgv/utils/file.h>
2#include <cgv/media/image/image_reader.h>
3#include <cgv_gl/gl/gl.h>
4#include "gltf_support.h"
5
6namespace cgv {
7 namespace render {
8
9cgv::render::TextureFilter map_gl_to_tex_filter(GLenum tf)
10{
11 switch (tf) {
12 case GL_NEAREST: return cgv::render::TF_NEAREST;
13 case GL_LINEAR: return cgv::render::TF_LINEAR;
14 case GL_NEAREST_MIPMAP_NEAREST: return cgv::render::TF_NEAREST_MIPMAP_NEAREST;
15 case GL_LINEAR_MIPMAP_NEAREST: return cgv::render::TF_LINEAR_MIPMAP_NEAREST;
16 case GL_NEAREST_MIPMAP_LINEAR: return cgv::render::TF_NEAREST_MIPMAP_LINEAR;
17 case GL_LINEAR_MIPMAP_LINEAR: return cgv::render::TF_LINEAR_MIPMAP_LINEAR;
18 case GL_TEXTURE_MAX_ANISOTROPY_EXT: return cgv::render::TF_ANISOTROP;
19 }
20 return cgv::render::TF_LAST;
21}
22
23cgv::render::TextureWrap map_gl_to_tex_wrap(GLenum tw)
24{
25 switch (tw) {
26 case GL_REPEAT: return cgv::render::TW_REPEAT;
27 case GL_CLAMP: return cgv::render::TW_CLAMP;
28 case GL_CLAMP_TO_EDGE: return cgv::render::TW_CLAMP_TO_EDGE;
29 case GL_CLAMP_TO_BORDER: return cgv::render::TW_CLAMP_TO_BORDER;
30 case GL_MIRROR_CLAMP_EXT: return cgv::render::TW_MIRROR_CLAMP;
31 case GL_MIRROR_CLAMP_TO_EDGE_EXT: return cgv::render::TW_MIRROR_CLAMP_TO_EDGE;
32 case GL_MIRROR_CLAMP_TO_BORDER_EXT: return cgv::render::TW_MIRROR_CLAMP_TO_BORDER;
33 case GL_MIRRORED_REPEAT: return cgv::render::TW_MIRRORED_REPEAT;
34 }
35 return cgv::render::TW_LAST;
36}
37
38cgv::render::PrimitiveType map_gl_to_primitive_type(GLenum pt)
39{
40 switch (pt) {
41 case GL_POINTS: return cgv::render::PT_POINTS;
42 case GL_LINES: return cgv::render::PT_LINES;
43 case GL_LINES_ADJACENCY: return cgv::render::PT_LINES_ADJACENCY;
44 case GL_LINE_STRIP: return cgv::render::PT_LINE_STRIP;
45 case GL_LINE_STRIP_ADJACENCY: return cgv::render::PT_LINE_STRIP_ADJACENCY;
46 case GL_LINE_LOOP: return cgv::render::PT_LINE_LOOP;
47 case GL_TRIANGLES: return cgv::render::PT_TRIANGLES;
48 case GL_TRIANGLES_ADJACENCY: return cgv::render::PT_TRIANGLES_ADJACENCY;
49 case GL_TRIANGLE_STRIP: return cgv::render::PT_TRIANGLE_STRIP;
50 case GL_TRIANGLE_STRIP_ADJACENCY: return cgv::render::PT_TRIANGLE_STRIP_ADJACENCY;
51 case GL_TRIANGLE_FAN: return cgv::render::PT_TRIANGLE_FAN;
52 case GL_QUADS: return cgv::render::PT_QUADS;
53 case GL_QUAD_STRIP: return cgv::render::PT_QUAD_STRIP;
54 case GL_POLYGON: return cgv::render::PT_POLYGON;
55 }
56 return cgv::render::PT_LAST;
57}
58
59cgv::render::type_descriptor get_element_type(const fx::gltf::Accessor& accessor)
60{
62 switch (accessor.componentType) {
63 case fx::gltf::Accessor::ComponentType::Byte: td.coordinate_type = cgv::type::info::TI_INT8; break;
64 case fx::gltf::Accessor::ComponentType::UnsignedByte: td.coordinate_type = cgv::type::info::TI_UINT8; break;
65 case fx::gltf::Accessor::ComponentType::Short: td.coordinate_type = cgv::type::info::TI_INT16; break;
66 case fx::gltf::Accessor::ComponentType::UnsignedShort:td.coordinate_type = cgv::type::info::TI_UINT16; break;
67 case fx::gltf::Accessor::ComponentType::Float: td.coordinate_type = cgv::type::info::TI_FLT32; break;
68 case fx::gltf::Accessor::ComponentType::UnsignedInt: td.coordinate_type = cgv::type::info::TI_UINT32; break;
69 break;
70 }
71 switch (accessor.type)
72 {
73 case fx::gltf::Accessor::Type::Mat2: td.element_type = cgv::render::ET_MATRIX; td.nr_columns = td.nr_rows = 2; break;
74 case fx::gltf::Accessor::Type::Mat3: td.element_type = cgv::render::ET_MATRIX; td.nr_columns = td.nr_rows = 3; break;
75 case fx::gltf::Accessor::Type::Mat4: td.element_type = cgv::render::ET_MATRIX; td.nr_columns = td.nr_rows = 4; break;
76 case fx::gltf::Accessor::Type::Scalar:td.element_type = cgv::render::ET_VALUE; td.nr_columns = td.nr_rows = 1; break;
77 case fx::gltf::Accessor::Type::Vec2: td.element_type = cgv::render::ET_VECTOR; td.nr_columns = 1; td.nr_rows = 2; break;
78 case fx::gltf::Accessor::Type::Vec3: td.element_type = cgv::render::ET_VECTOR; td.nr_columns = 1; td.nr_rows = 3; break;
79 case fx::gltf::Accessor::Type::Vec4: td.element_type = cgv::render::ET_VECTOR; td.nr_columns = 1; td.nr_rows = 4; break;
80 }
81 td.normalize = accessor.normalized;
82 td.is_row_major = false;
83 td.is_array = false;
84 return td;
85}
86
87void add_attribute(cgv::render::attribute_array& aa,
88 const fx::gltf::Document& doc, const fx::gltf::Accessor& accessor,
89 cgv::render::VertexAttributeID va_id, const std::string& name = "")
90{
91 const fx::gltf::BufferView& bufferView = doc.bufferViews[accessor.bufferView];
92 aa.add_attribute(get_element_type(accessor), bufferView.buffer,
93 bufferView.byteOffset + accessor.byteOffset, accessor.count,
94 bufferView.byteStride, va_id, name);
95}
96
98 box3& box,
99 size_t& vertex_count)
100{
101 vertex_count = 0;
102 box.invalidate();
103 // construct meshes
104 for (const auto& M : doc.meshes) {
105 for (const auto& p : M.primitives) {
106 for (const auto& a : p.attributes) {
107 if (a.first == "POSITION") {
108 const fx::gltf::Accessor& accessor = doc.accessors[a.second];
109 if (accessor.componentType != fx::gltf::Accessor::ComponentType::Float)
110 continue;
111 const fx::gltf::BufferView& bufferView = doc.bufferViews[accessor.bufferView];
112 const uint8_t* data_ptr = &doc.buffers[bufferView.buffer].data[0] + accessor.byteOffset + bufferView.byteOffset;
113 vertex_count += accessor.count;
114 for (size_t i = 0; i < accessor.count; ++i) {
115 switch (accessor.type) {
116 case fx::gltf::Accessor::Type::Vec2:
117 box.add_point(vec3(reinterpret_cast<const vec2*>(data_ptr)[i], 0.0f));
118 break;
119 case fx::gltf::Accessor::Type::Vec3:
120 box.add_point(reinterpret_cast<const vec3*>(data_ptr)[i]);
121 break;
122 case fx::gltf::Accessor::Type::Vec4:
123 box.add_point(*reinterpret_cast<const vec3*>(
124 reinterpret_cast<const vec4*>(data_ptr) + i));
125 break;
126 }
127 }
128 }
129 }
130 }
131 }
132}
133
134bool build_render_info(const std::string& file_name, const fx::gltf::Document& doc,
136{
137 std::string file_path = cgv::utils::file::get_path(file_name);
138
139 if (!ctx.make_current()) {
140 std::cerr << "need valid context for read_gltf" << std::endl;
141 return false;
142 }
143
144 R.destruct(ctx);
145
146 // construct buffers
147 for (const auto& b : doc.buffers) {
149 vbo->create(ctx, &b.data[0], b.byteLength);
150 R.ref_vbos().push_back(vbo);
151 }
152
153 // read images images
154 std::vector<cgv::data::data_view*> dvs;
155 std::vector<cgv::data::data_format*> dfs;
156 for (const auto& i : doc.images) {
157 if (i.IsEmbeddedResource()) {
158 std::cerr << "could not deal with embedded image" << std::endl;
159 return false;
160 }
161 else {
162 dfs.push_back(new cgv::data::data_format());
163 cgv::media::image::image_reader ir(*dfs.back());
164 std::string image_file_name = file_path + "/" + i.uri;
165 if (!ir.open(image_file_name)) {
166 std::cerr << "could not open image " << image_file_name << std::endl;
167 return false;
168 }
169 dvs.push_back(new cgv::data::data_view(dfs.back()));
170 if (!ir.read_image(*dvs.back())) {
171 std::cerr << "could not read image " << image_file_name << std::endl;
172 return false;
173 }
174 ir.close();
175 }
176 }
177
178 // construct textures
179 for (const auto& t : doc.textures) {
181 tex->create(ctx, *dvs[t.source]);
182 const auto& s = doc.samplers[t.sampler];
183 if (s.magFilter != fx::gltf::Sampler::MagFilter::None)
184 tex->set_mag_filter(map_gl_to_tex_filter(GLenum(s.magFilter)));
185 if (s.minFilter != fx::gltf::Sampler::MinFilter::None)
186 tex->set_min_filter(map_gl_to_tex_filter(GLenum(s.minFilter)));
187 tex->set_wrap_s(map_gl_to_tex_wrap(GLenum(s.wrapS)));
188 tex->set_wrap_t(map_gl_to_tex_wrap(GLenum(s.wrapT)));
189 R.ref_textures().push_back(tex);
190 }
191
192 // construct materials
193 for (const auto& m : doc.materials) {
195 tm->set_name(m.name);
196
197 bool found_KHR_mat = false;
198 m.extensionsAndExtras.count("extensions");
199 if (m.extensionsAndExtras.count("extensions")) {
200 auto& ext = m.extensionsAndExtras["extensions"];
201 if (ext.count("KHR_materials_pbrSpecularGlossiness")) {
202 auto& mat = ext["KHR_materials_pbrSpecularGlossiness"];
203 found_KHR_mat = true;
204 if (mat.count("diffuseFactor")) {
205 auto& df = mat["diffuseFactor"];
206 tm->set_diffuse_reflectance(rgb(
207 df[0].get<float>(), df[1].get<float>(), df[2].get<float>()));
208 tm->set_transparency(1.0f - df[3].get<float>());
209 }
210 if (mat.count("diffuseTexture")) {
211 int ti = tm->add_texture_reference(*R.ref_textures()[mat["diffuseTexture"]["index"].get<int>()]);
212 tm->set_diffuse_index(ti);
213 }
214 if (mat.count("glossinessFactor"))
215 tm->set_roughness(1 - mat["glossinessFactor"].get<float>());
216 if (mat.count("specularFactor")) {
217 auto& sf = mat["specularFactor"];
218 tm->set_diffuse_reflectance(rgb(
219 sf[0].get<float>(), sf[1].get<float>(), sf[2].get<float>()));
220 }
221 if (mat.count("specularGlossinessTexture")) {
222 int ti = tm->add_texture_reference(*R.ref_textures()[mat["specularGlossinessTexture"]["index"].get<int>()]);
223 tm->set_specular_index(ti);
224 }
225 }
226 }
227 if (!found_KHR_mat) {
228 tm->set_diffuse_reflectance(rgb(
229 m.pbrMetallicRoughness.baseColorFactor[0],
230 m.pbrMetallicRoughness.baseColorFactor[1],
231 m.pbrMetallicRoughness.baseColorFactor[2]));
232 tm->set_transparency(1.0f - m.pbrMetallicRoughness.baseColorFactor[3]);
233 if (m.pbrMetallicRoughness.baseColorTexture.index != -1) {
234 int ti = tm->add_texture_reference(*R.ref_textures()[m.pbrMetallicRoughness.baseColorTexture.index]);
235 tm->set_diffuse_index(ti);
236 }
237 tm->set_roughness(m.pbrMetallicRoughness.roughnessFactor);
238 tm->set_metalness(m.pbrMetallicRoughness.metallicFactor);
239 if (m.pbrMetallicRoughness.metallicRoughnessTexture.index != -1) {
240 int ti = tm->add_texture_reference(*R.ref_textures()[m.pbrMetallicRoughness.metallicRoughnessTexture.index]);
241 tm->set_roughness_index(ti);
242 tm->set_metalness_index(ti);
243 }
244 if (m.alphaMode == fx::gltf::Material::AlphaMode::Mask)
245 tm->set_alpha_test(cgv::render::textured_material::AT_GREATER, m.alphaCutoff);
246 tm->set_emission(rgba(
247 m.emissiveFactor[0],
248 m.emissiveFactor[1],
249 m.emissiveFactor[2]));
250 if (m.emissiveTexture.index != -1) {
251 int ti = tm->add_texture_reference(*R.ref_textures()[m.emissiveTexture.index]);
252 tm->set_emission_index(ti);
253 }
254 }
255 R.ref_materials().push_back(tm);
256 }
257
258 // construct meshes
259 for (const auto& M : doc.meshes) {
260 for (const auto& p : M.primitives) {
261 R.ref_aas().push_back(cgv::render::attribute_array());
262 auto& aa = R.ref_aas().back();
263 aa.aab_ptr = new cgv::render::attribute_array_binding();
264 aa.aab_ptr->create(ctx);
266 for (const auto& a : p.attributes) {
267 if (a.first == "POSITION") {
268 add_attribute(aa, doc, doc.accessors[a.second], cgv::render::VA_POSITION);
269 dc.count = doc.accessors[a.second].count;
270 }
271 else if (a.first == "NORMAL")
272 add_attribute(aa, doc, doc.accessors[a.second], cgv::render::VA_NORMAL);
273 else if (a.first == "TANGENT")
274 add_attribute(aa, doc, doc.accessors[a.second], cgv::render::VA_BY_NAME, "tangent");
275 else if (a.first == "TEXCOORD_0")
276 add_attribute(aa, doc, doc.accessors[a.second], cgv::render::VA_TEXCOORD);
277 }
278 dc.indices = 0;
279 dc.aa_index = uint32_t(R.ref_aas().size() - 1);
280 dc.instance_count = 1;
281 dc.draw_call_type = cgv::render::RCT_ARRAYS;
282 dc.vertex_offset = 0;
283 if (p.indices >= 0) {
284 dc.draw_call_type = cgv::render::RCT_INDEXED;
285 const fx::gltf::Accessor& accessor = doc.accessors[p.indices];
286 const fx::gltf::BufferView& bufferView = doc.bufferViews[accessor.bufferView];
287 dc.count = accessor.count;
288 R.ref_aas().back().aab_ptr->set_element_array(ctx, *R.ref_vbos()[bufferView.buffer]);
289 if (accessor.type != fx::gltf::Accessor::Type::Scalar) {
290 std::cerr << "index type must by scalar" << std::endl;
291 return false;
292 }
293 switch (accessor.componentType) {
294 case fx::gltf::Accessor::ComponentType::UnsignedByte:
295 dc.index_type = cgv::type::info::TI_UINT8;
296 break;
297 case fx::gltf::Accessor::ComponentType::UnsignedShort:
298 dc.index_type = cgv::type::info::TI_UINT16;
299 break;
300 case fx::gltf::Accessor::ComponentType::UnsignedInt:
301 dc.index_type = cgv::type::info::TI_UINT32;
302 break;
303 default:
304 std::cerr << "index component type must be unsigned integer type" << std::endl;
305 return false;
306 }
307 dc.indices = (void*)(unsigned long long)(accessor.byteOffset + bufferView.byteOffset);
308 }
309 dc.primitive_type = map_gl_to_primitive_type(GLenum(p.mode));
310 if (p.material >= 0) {
311 dc.material_index = p.material;
312 dc.alpha_mode = cgv::render::AlphaMode(doc.materials[p.material].alphaMode);
313 dc.alpha_cutoff = doc.materials[p.material].alphaCutoff;
314 // std::cout << doc.materials[p.material].name << ": " << (int)doc.materials[p.material].alphaMode << "|" << doc.materials[p.material].alphaCutoff << std::endl;
315 }
316 else {
317 dc.material_index = -1;
318 dc.alpha_mode = cgv::render::AM_OPAQUE;
319 dc.alpha_cutoff = 0.0f;
320 }
321 dc.prog = 0;
322 R.ref_draw_calls().push_back(dc);
323 }
324 }
325 return true;
326}
327
328void extract_mesh(const std::string& file_name, const fx::gltf::Document& doc,
329 cgv::media::mesh::simple_mesh<float>& mesh, int mesh_index, int primitive_index)
330{
331 std::string file_path = cgv::utils::file::get_path(file_name);
332 mesh.clear();
333
334 // read images images
335 std::vector<std::string> image_file_names;
336 for (const auto& i : doc.images) {
337 if (i.IsEmbeddedResource()) {
338 std::cerr << "cannot not deal with embedded image" << std::endl;
339 return;
340 }
341 else
342 image_file_names.push_back(file_path + "/" + i.uri);
343 }
344
345 // construct materials
346 for (const auto& m : doc.materials) {
347 auto& mm = mesh.ref_material(mesh.new_material());
348 mm.set_name(m.name);
349 mm.set_diffuse_reflectance(rgba(
350 m.pbrMetallicRoughness.baseColorFactor[0],
351 m.pbrMetallicRoughness.baseColorFactor[1],
352 m.pbrMetallicRoughness.baseColorFactor[2],
353 m.pbrMetallicRoughness.baseColorFactor[3]));
354 if (m.pbrMetallicRoughness.baseColorTexture.index != -1) {
355 int ii = mm.add_image_file(image_file_names[
356 doc.textures[m.pbrMetallicRoughness.baseColorTexture.index].source]);
357 mm.set_diffuse_index(ii);
358 }
359 mm.set_roughness(m.pbrMetallicRoughness.roughnessFactor);
360 mm.set_metalness(m.pbrMetallicRoughness.metallicFactor);
361 if (m.pbrMetallicRoughness.metallicRoughnessTexture.index != -1) {
362 int ii = mm.add_image_file(image_file_names[
363 doc.textures[m.pbrMetallicRoughness.metallicRoughnessTexture.index].source]);
364 mm.set_roughness_index(ii);
365 mm.set_metalness_index(ii);
366 }
367 mm.set_emission(rgba(
368 m.emissiveFactor[0],
369 m.emissiveFactor[1],
370 m.emissiveFactor[2]));
371 if (m.emissiveTexture.index != -1) {
372 int ii = mm.add_image_file(image_file_names[
373 doc.textures[m.emissiveTexture.index].source]);
374 mm.set_emission_index(ii);
375 }
376 }
377
378 // construct mesh
379 int prim = 0;
380 for (const auto& M : doc.meshes) {
381 if (mesh_index != -1 && (&M - &doc.meshes[0]) != mesh_index)
382 continue;
383
384 for (const auto& p : M.primitives) {
385 if (primitive_index != -1 && (&p - &M.primitives[0]) != primitive_index)
386 continue;
387
388 int gi = mesh.new_group(M.name + "[" + cgv::utils::to_string(prim) + "]");
389 int pi = mesh.get_nr_positions();
390 int ni = mesh.get_nr_normals();
391 int ti = mesh.get_nr_tex_coords();
392
393 bool has_nmls = false;
394 bool has_tcs = false;
395 for (const auto& a : p.attributes) {
396 const fx::gltf::Accessor& accessor = doc.accessors[a.second];
397 const fx::gltf::BufferView& bufferView = doc.bufferViews[accessor.bufferView];
398 const fx::gltf::Buffer& buffer = doc.buffers[bufferView.buffer];
399 const uint8_t* data_ptr = &buffer.data[accessor.byteOffset + bufferView.byteOffset];
400 const float* float_ptr = reinterpret_cast<const float*>(data_ptr);
401 if (a.first == "POSITION") {
402 for (size_t i = 0; i < accessor.count; ++i) {
404 float_ptr += 3;
405 }
406 }
407 else if (a.first == "NORMAL") {
408 has_nmls = true;
409 for (size_t i = 0; i < accessor.count; ++i) {
411 float_ptr += 3;
412 }
413 }
414 else if (a.first == "TEXCOORD_0") {
415 has_tcs = true;
416 for (size_t i = 0; i < accessor.count; ++i) {
418 float_ptr += 2;
419 }
420 }
421 }
422 int mi = p.material;
423 if (p.indices >= 0) {
424 const fx::gltf::Accessor& accessor = doc.accessors[p.indices];
425 const fx::gltf::BufferView& bufferView = doc.bufferViews[accessor.bufferView];
426 const fx::gltf::Buffer& buffer = doc.buffers[bufferView.buffer];
427 const uint8_t* data_ptr = &buffer.data[accessor.byteOffset + bufferView.byteOffset];
428 const uint16_t* ushort_ptr = reinterpret_cast<const uint16_t*>(data_ptr);
429 const uint32_t* uint_ptr = reinterpret_cast<const uint32_t*>(data_ptr);
430 if (p.mode == fx::gltf::Primitive::Mode::Triangles) {
431 int fi;
432 for (size_t i = 0; i < accessor.count; ++i) {
433 if (i % 3 == 0) {
434 fi = mesh.start_face();
435 mesh.group_index(fi) = prim;
436 mesh.material_index(fi) = mi;
437 }
438 uint32_t idx = -1;
439 switch (accessor.componentType) {
440 case fx::gltf::Accessor::ComponentType::UnsignedByte: idx = data_ptr[i]; break;
441 case fx::gltf::Accessor::ComponentType::UnsignedShort: idx = ushort_ptr[i]; break;
442 case fx::gltf::Accessor::ComponentType::UnsignedInt: idx = uint_ptr[i]; break;
443 }
444 mesh.new_corner(pi + idx, has_nmls ? ni + idx : -1, has_tcs ? ti + idx : -1);
445 }
446 }
447 }
448 ++prim;
449 }
450 }
451}
452
453bool write_gltf(const std::string& file_name, const cgv::render::render_info& R)
454{
455 return false;
456}
457
458 }
459}
A data_format describes a multidimensional data block of data entries.
Definition data_format.h:17
the data view gives access to a data array of one, two, three or four dimensions.
Definition data_view.h:153
void invalidate()
set to invalid min and max points
void add_point(const fpnt_type &p)
extent box to include given point
void set_name(std::string o)
set the name of the material
the image reader chooses a specific reader automatically based on the extension of the given file nam...
bool read_image(const std::string &file_name, cgv::data::data_view &dv, std::vector< cgv::data::data_view > *palettes=0)
read the whole image into the given data view.
bool close()
close the image file
bool open(const std::string &file_name)
open the file and read the image header in order to determine the data format of the file,...
idx_type new_material()
add a new material and return its index
mat_type & ref_material(size_t i)
return reference to i-th material
const idx_type & material_index(idx_type fi) const
return material index of given face
idx_type start_face()
Create a new empty face to which new corners are added.
const idx_type & group_index(idx_type fi) const
return group index of given face
idx_type new_group(const std::string &name)
add a new group and return its index
idx_type new_corner(idx_type position_index, idx_type normal_index=-1, idx_type tex_coord_index=-1)
Create a new corner with the given attributes.
the simple_mesh class is templated over the coordinate type that defaults to float
idx_type get_nr_positions() const
access to positions
void clear()
clear simple mesh
idx_type new_tex_coord(const vec2_type &tc)
add a new texture coordinate and return texture coordinate index
idx_type new_position(const vec3_type &p)
add a new position and return position index
idx_type new_normal(const vec3_type &n)
add a new normal and return normal index
the attribute_array_binding allows to define vertex attributes (i.e.
bool create(const context &ctx)
create the attribute array binding object
base class for all drawables, which is independent of the used rendering API.
Definition context.h:621
virtual bool make_current() const =0
make the current context current if possible
the mesh_render_info structure manages vertex buffer objects for attribute and element buffers as wel...
Definition render_info.h:76
std::vector< vertex_buffer * > & ref_vbos()
give write access to vbos
std::vector< texture * > & ref_textures()
give write access to texture
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
the texture class encapsulates all functionality independent of the rendering api.
Definition texture.h:15
void set_mag_filter(TextureFilter _mag_filter)
set the magnification filter
Definition texture.cxx:138
bool create(const context &ctx, TextureType _tt=TT_UNDEF, unsigned width=-1, unsigned height=-1, unsigned depth=-1)
create the texture of dimension and resolution specified in the data format base class.
Definition texture.cxx:208
void set_wrap_t(TextureWrap _wrap_t)
set the texture wrap behaviour in t direction
Definition texture.cxx:83
void set_wrap_s(TextureWrap _wrap_s)
set the texture wrap behaviour in s direction
Definition texture.cxx:77
void set_min_filter(TextureFilter _min_filter, float _anisotropy=2.0f)
set the minification filters, if minification is set to TF_ANISOTROP, the second floating point param...
Definition texture.cxx:120
class that extends obj_material with the management of textures
void set_alpha_test(AlphaTestFunc _alpha_test_func=AT_GREATER, float _alpha_threshold=0.0f)
configure the alpha test that is performed in case alpha values are given in the textures
int add_texture_reference(cgv::render::texture &tex)
add a reference to a new texture that is managed outside of this class and return its index
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
TextureFilter
different texture filter
Definition context.h:189
TextureWrap
different texture wrap modes
Definition context.h:173
bool build_render_info(const std::string &file_name, const fx::gltf::Document &doc, cgv::render::context &ctx, cgv::render::render_info &R)
construct render info from gltf document
void extract_mesh(const std::string &file_name, const fx::gltf::Document &doc, cgv::media::mesh::simple_mesh< float > &mesh, int mesh_index, int primitive_index)
extract simple mesh form gltf document
void extract_additional_information(const fx::gltf::Document &doc, box3 &box, size_t &vertex_count)
extract bounding box and vertex count from gltf document
bool write_gltf(const std::string &file_name, const cgv::render::render_info &R)
NOT IMPLEMENTED YET.
PrimitiveType
different primitive types
Definition context.h:225
@ TI_INT16
signed integer stored in 8 bits
Definition type_id.h:20
@ TI_INT8
boolean
Definition type_id.h:19
@ TI_FLT32
floating point type stored in 16 bits
Definition type_id.h:28
@ TI_UINT32
unsigned integer stored in 16 bits
Definition type_id.h:25
@ TI_UINT8
signed integer stored in 64 bits
Definition type_id.h:23
@ TI_UINT16
unsigned integer stored in 8 bits
Definition type_id.h:24
std::string to_string(const std::string &v, unsigned int w, unsigned int p, bool)
specialization of conversion from string to strings
the cgv namespace
Definition print.h:11
cgv::media::color< float, cgv::media::RGB, cgv::media::OPACITY > rgba
declare rgba color type with 32 bit components
Definition color.h:855
cgv::media::color< float, cgv::media::RGB > rgb
declare rgb color type with 32 bit components
Definition color.h:853
cgv::math::fvec< float, 3 > vec3
declare type of 3d single precision floating point vectors
Definition fvec.h:669
compact type description of data that can be sent to the context; convertible to int
Definition context.h:47