test_senc3d_multi_media.c (3415B)
1 /* Copyright (C) 2018-2020, 2023, 2024 |Méso|Star> (contact@meso-star.com) 2 * 3 * This program is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 3 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 15 16 /* This test has been created using the sg3_geometry_dump_as_C_code feature 17 * of star-geometry. It uses output from test_sg3_cube_on_cube. */ 18 19 #define _POSIX_C_SOURCE 200112L /* snprintf */ 20 21 #include "senc3d.h" 22 #include "test_senc3d_utils.h" 23 24 #include <rsys/double3.h> 25 26 #include <stdio.h> 27 28 /* Dump of star-geometry-3d 'multi_media'. */ 29 static const unsigned multi_media_vertices_count = 8; 30 static const double multi_media_vertices[24] = 31 { 32 0, 0, 0, 33 1, 0, 0, 34 0, 1, 0, 35 1, 1, 0, 36 0, 0, 1, 37 1, 0, 1, 38 0, 1, 1, 39 1, 1, 1 40 }; 41 static const unsigned multi_media_triangles_count = 12; 42 static const unsigned multi_media_triangles[36] = 43 { 44 0, 2, 1, 45 1, 2, 3, 46 0, 4, 2, 47 2, 4, 6, 48 4, 5, 6, 49 6, 5, 7, 50 3, 7, 1, 51 1, 7, 5, 52 2, 6, 3, 53 3, 6, 7, 54 0, 1, 4, 55 4, 1, 5 56 }; 57 static const unsigned multi_media_properties[36] = 58 { 59 0, 4, 4, 60 0, 4, 4, 61 0, 3, 3, 62 0, 3, 3, 63 0, 3, 3, 64 0, 3, 3, 65 0, 2, 2, 66 0, 2, 2, 67 0, 2, 2, 68 0, 1, 1, 69 0, 1, 1, 70 0, 1, 1 71 }; 72 73 int 74 main(int argc, char** argv) 75 { 76 struct mem_allocator allocator; 77 struct senc3d_device* dev = NULL; 78 struct senc3d_scene* scn = NULL; 79 struct context ctx = CONTEXT_NULL__; 80 unsigned ecount, tcount, t, e; 81 struct senc3d_enclosure* enc; 82 (void)argc, (void)argv; 83 84 OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); 85 OK(senc3d_device_create(NULL, &allocator, SENC3D_NTHREADS_DEFAULT, 1, &dev)); 86 87 /* Degenerated triangle: duplicated vertex */ 88 ctx.positions = multi_media_vertices; 89 ctx.indices = multi_media_triangles; 90 ctx.properties = multi_media_properties; 91 OK(senc3d_scene_create(dev, 92 SENC3D_CONVENTION_NORMAL_FRONT | SENC3D_CONVENTION_NORMAL_INSIDE, 93 multi_media_triangles_count, get_indices, get_media_from_properties, 94 multi_media_vertices_count, get_position, &ctx, &scn)); 95 96 OK(senc3d_scene_get_triangles_count(scn, &tcount)); 97 CHK(tcount == multi_media_triangles_count); 98 FOR_EACH(t, 0, tcount) { 99 unsigned ids[2]; 100 OK(senc3d_scene_get_triangle_enclosures(scn, t, ids)); 101 CHK(ids[0] == 0 && ids[1] == 1); 102 } 103 OK(senc3d_scene_get_enclosure_count(scn, &ecount)); 104 CHK(ecount == 2); 105 FOR_EACH(e, 0, ecount) { 106 struct senc3d_enclosure_header header; 107 OK(senc3d_scene_get_enclosure(scn, e, &enc)); 108 OK(senc3d_enclosure_get_header(enc, &header)); 109 CHK(header.primitives_count == multi_media_triangles_count); 110 CHK(header.enclosed_media_count == (header.is_infinite ? 1u : 4u)); 111 OK(senc3d_enclosure_ref_put(enc)); 112 } 113 114 OK(senc3d_scene_ref_put(scn)); 115 OK(senc3d_device_ref_put(dev)); 116 117 check_memory_allocator(&allocator); 118 mem_shutdown_proxy_allocator(&allocator); 119 CHK(mem_allocated_size() == 0); 120 return 0; 121 }