test_sg3d_many_triangles.c (2998B)
1 /* Copyright (C) 2019, 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 #include "sg3d.h" 17 #include "test_sg3d_utils.h" 18 #include "test_sg3d_utils2.h" 19 20 #include <rsys/double3.h> 21 22 #include <star/s3dut.h> 23 24 #include <stdio.h> 25 #include <limits.h> 26 27 #define NB_CYL 2 28 29 int 30 main(int argc, char** argv) 31 { 32 struct mem_allocator allocator; 33 struct sg3d_device* dev; 34 struct sg3d_geometry* geom; 35 struct sg3d_geometry_add_callbacks callbacks = SG3D_ADD_CALLBACKS_NULL__; 36 unsigned cyl_trg_count, cyl_vrtx_count, i, count; 37 unsigned m0 = 0, m1, itf = 0; 38 struct s3dut_context ctx = { {NULL,NULL,0,0}, CONTEXT_NULL__ }; 39 struct s3dut_mesh* cyl = NULL; 40 (void)argc, (void)argv; 41 42 OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); 43 OK(sg3d_device_create(NULL, &allocator, 1, &dev)); 44 OK(sg3d_geometry_create(dev, &geom)); 45 SG3D(device_ref_put(dev)); 46 47 callbacks.get_indices = get_s3dut_indices; 48 callbacks.get_properties = get_s3dut_properties; 49 callbacks.get_position = get_s3dut_position; 50 51 ctx.ctx.positions = box_vertices; 52 ctx.ctx.indices = cube_indices; 53 ctx.ctx.front_media = &m1; 54 ctx.ctx.back_media = &m0; 55 ctx.ctx.intface = &itf; 56 57 /* A 2,562,560 triangles 1,281,282 vertices cylinder template */ 58 S3DUT(create_cylinder(&allocator, 1, 2, 1280, 1000, &cyl)); 59 S3DUT(mesh_get_data(cyl, &ctx.data)); 60 ASSERT(ctx.data.nprimitives <= UINT_MAX); 61 ASSERT(ctx.data.nvertices <= UINT_MAX); 62 cyl_trg_count = (unsigned)ctx.data.nprimitives; 63 cyl_vrtx_count = (unsigned)ctx.data.nvertices; 64 OK(sg3d_geometry_reserve(geom, NB_CYL * cyl_vrtx_count, NB_CYL * cyl_trg_count, 0)); 65 FOR_EACH(i, 0, NB_CYL) { 66 m1 = i; 67 d3(ctx.ctx.offset, 0, 0, (double)i * 10); 68 OK(sg3d_geometry_add(geom, cyl_vrtx_count, cyl_trg_count, &callbacks, &ctx)); 69 } 70 S3DUT(mesh_ref_put(cyl)); 71 72 OK(sg3d_geometry_get_unique_triangles_with_merge_conflict_count(geom, &count)); 73 CHK(count == 0); 74 OK(sg3d_geometry_get_unique_triangles_with_unspecified_interface_count(geom, &count)); 75 CHK(count == 0); 76 OK(sg3d_geometry_get_unique_triangles_with_unspecified_side_count(geom, &count)); 77 CHK(count == 0); 78 OK(sg3d_geometry_dump_as_obj(geom, stdout, SG3D_OBJ_DUMP_ALL)); 79 80 SG3D(geometry_ref_put(geom)); 81 82 check_memory_allocator(&allocator); 83 mem_shutdown_proxy_allocator(&allocator); 84 CHK(mem_allocated_size() == 0); 85 return 0; 86 }