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