test_sg2d_many_segments.c (2814B)
1 /* Copyright (C) 2019, 2020, 2023 |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 "sg2d.h" 17 #include "test_sg2d_utils.h" 18 #include "test_sg2d_utils2.h" 19 20 #include <rsys/double2.h> 21 22 #include <stdio.h> 23 24 #define NB_CIRC 2 25 26 int 27 main(int argc, char** argv) 28 { 29 struct mem_allocator allocator; 30 struct sg2d_device* dev; 31 struct sg2d_geometry* geom; 32 struct sg2d_geometry_add_callbacks callbacks = SG2D_ADD_CALLBACKS_NULL__; 33 unsigned circ_seg_count, circ_vrtx_count, i, count; 34 unsigned m0 = 0, m1, itf = 0; 35 struct context ctx = CONTEXT_NULL__; 36 (void)argc, (void)argv; 37 38 OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); 39 OK(sg2d_device_create(NULL, &allocator, 1, &dev)); 40 OK(sg2d_geometry_create(dev, &geom)); 41 SG2D(device_ref_put(dev)); 42 43 callbacks.get_indices = get_indices; 44 callbacks.get_position = get_position; 45 callbacks.get_properties = get_uniform_properties; 46 47 ctx.front_media = &m1; 48 ctx.back_media = &m0; 49 ctx.intface = &itf; 50 51 /* A 1,048,576 segments circle template */ 52 create_circle(1, 1048576, &ctx); 53 ASSERT(sa_size(ctx.positions) % 2 == 0); 54 ASSERT(sa_size(ctx.indices) % 2 == 0); 55 ASSERT(sa_size(ctx.indices) <= UINT_MAX); 56 ASSERT(sa_size(ctx.positions) <= UINT_MAX); 57 circ_seg_count = (unsigned)sa_size(ctx.indices) / 2; 58 circ_vrtx_count = (unsigned)sa_size(ctx.positions) / 2; 59 OK(sg2d_geometry_reserve(geom, NB_CIRC * circ_vrtx_count, 60 NB_CIRC * circ_seg_count, 0)); 61 FOR_EACH(i, 0, NB_CIRC) { 62 m1 = i; 63 d2(ctx.offset, 0, (double)i * 10); 64 OK(sg2d_geometry_add(geom, circ_vrtx_count, circ_seg_count, &callbacks, 65 &ctx)); 66 } 67 circle_release(&ctx); 68 69 OK(sg2d_geometry_get_unique_segments_with_merge_conflict_count(geom, &count)); 70 CHK(count == 0); 71 OK(sg2d_geometry_get_unique_segments_with_unspecified_interface_count(geom, &count)); 72 CHK(count == 0); 73 OK(sg2d_geometry_get_unique_segments_with_unspecified_side_count(geom, &count)); 74 CHK(count == 0); 75 OK(sg2d_geometry_dump_as_obj(geom, stdout, SG2D_OBJ_DUMP_ALL)); 76 77 SG2D(geometry_ref_put(geom)); 78 79 check_memory_allocator(&allocator); 80 mem_shutdown_proxy_allocator(&allocator); 81 CHK(mem_allocated_size() == 0); 82 return 0; 83 }