test_senc2d_many_segments.c (3449B)
1 /* Copyright (C) |Meso|Star> 2016-2020 (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 is similar to test_senc2d_some_segments, but involves 4*2562560 17 * segments instead of 4*1054, thus making it impossible to define the geometry 18 * through static arrays. */ 19 20 #define NB_CIRC_X 2 21 #define NB_CIRC_Y 1 22 #define NB_CIRC_Z 1 23 /* 4 circles */ 24 #define NB_CIRC (NB_CIRC_X * NB_CIRC_Y * NB_CIRC_Z) 25 26 #include "senc2d.h" 27 #include "test_senc2d_utils.h" 28 #include "test_senc2d_utils2.h" 29 30 #include <rsys/clock_time.h> 31 #include <rsys/double2.h> 32 33 #include <stdio.h> 34 #include <limits.h> 35 36 int 37 main(int argc, char** argv) 38 { 39 struct mem_allocator allocator; 40 struct senc2d_device* dev = NULL; 41 struct senc2d_scene* scn = NULL; 42 struct context ctx = CONTEXT_NULL__; 43 unsigned m0 = 0; 44 unsigned count; 45 unsigned circ_seg_count, circ_vrtx_count, e; 46 char dump[64]; 47 struct time t0, t1; 48 (void)argc, (void)argv; 49 50 OK(mem_init_regular_allocator(&allocator)); 51 OK(senc2d_device_create (NULL, &allocator, SENC2D_NTHREADS_DEFAULT, 1, &dev)); 52 53 /* A 1,048,576 segments circle template */ 54 create_circle(1, 1048576, &ctx); 55 ASSERT(sa_size(ctx.positions) % 2 == 0 56 && sa_size(ctx.positions) / 2 < UINT_MAX); 57 ASSERT(sa_size(ctx.indices) % 2 == 0 58 && sa_size(ctx.indices) / 2 < UINT_MAX); 59 circ_seg_count = (unsigned)sa_size(ctx.indices) / 2; 60 circ_vrtx_count = (unsigned)sa_size(ctx.positions) / 2; 61 62 /* Create the scene with 4 circles. 63 * The get_ctx_xxx getters have to retrieve the circle from the 64 * primitive and vertice indexes. */ 65 ctx.back_media = &m0; 66 time_current(&t0); 67 OK(senc2d_scene_create(dev, 68 SENC2D_CONVENTION_NORMAL_FRONT | SENC2D_CONVENTION_NORMAL_INSIDE, 69 NB_CIRC* circ_seg_count, get_ctx_indices, get_ctx_media, 70 NB_CIRC* circ_vrtx_count, get_ctx_position, &ctx, &scn)); 71 time_sub(&t0, time_current(&t1), &t0); 72 time_dump(&t0, TIME_MSEC | TIME_SEC | TIME_MIN, NULL, dump, sizeof(dump)); 73 printf("Scene created in: %s\n", dump); 74 circle_release(&ctx); 75 76 OK(senc2d_scene_get_vertices_count(scn, &count)); 77 CHK(count == NB_CIRC * circ_vrtx_count); 78 OK(senc2d_scene_get_segments_count(scn, &count)); 79 CHK(count == NB_CIRC * circ_seg_count); 80 81 OK(senc2d_scene_get_enclosure_count(scn, &count)); 82 CHK(count == 1 + NB_CIRC); 83 FOR_EACH(e, 0, count) { 84 struct senc2d_enclosure* enclosure; 85 struct senc2d_enclosure_header header; 86 OK(senc2d_scene_get_enclosure(scn, e, &enclosure)); 87 OK(senc2d_enclosure_get_header(enclosure, &header)); 88 CHK(header.primitives_count == 89 e ? circ_seg_count : NB_CIRC * circ_seg_count); 90 OK(senc2d_enclosure_ref_put(enclosure)); 91 } 92 93 OK(senc2d_scene_ref_put(scn)); 94 OK(senc2d_device_ref_put(dev)); 95 96 check_memory_allocator(&allocator); 97 mem_shutdown_regular_allocator(&allocator); 98 CHK(mem_allocated_size() == 0); 99 return 0; 100 }