test_senc2d_multi_media.c (3082B)
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 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 "senc2d.h" 22 #include "test_senc2d_utils.h" 23 24 #include <rsys/double2.h> 25 26 #include <stdio.h> 27 28 static const unsigned multi_media_vertices_count = 4; 29 static const double multi_media_vertices[8] = 30 { 31 0, 0, 32 1, 0, 33 0, 1, 34 1, 1 35 }; 36 static const unsigned multi_media_segments_count = 4; 37 static const unsigned multi_media_segments[8] = 38 { 39 0, 2, 40 2, 3, 41 3, 1, 42 1, 0 43 }; 44 static const unsigned multi_media_properties[12] = 45 { 46 0, 4, 4, 47 0, 3, 3, 48 0, 2, 2, 49 0, 1, 1 50 }; 51 52 int 53 main(int argc, char** argv) 54 { 55 struct mem_allocator allocator; 56 struct senc2d_device* dev = NULL; 57 struct senc2d_scene* scn = NULL; 58 struct context ctx = CONTEXT_NULL__; 59 unsigned ecount, scount, s, e; 60 struct senc2d_enclosure* enc; 61 (void)argc, (void)argv; 62 63 OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); 64 OK(senc2d_device_create(NULL, &allocator, SENC2D_NTHREADS_DEFAULT, 1, &dev)); 65 66 /* Degenerated triangle: duplicated vertex */ 67 ctx.positions = multi_media_vertices; 68 ctx.indices = multi_media_segments; 69 ctx.properties = multi_media_properties; 70 OK(senc2d_scene_create(dev, 71 SENC2D_CONVENTION_NORMAL_FRONT | SENC2D_CONVENTION_NORMAL_INSIDE, 72 multi_media_segments_count, get_indices, get_media_from_properties, 73 multi_media_vertices_count, get_position, &ctx, &scn)); 74 75 OK(senc2d_scene_get_segments_count(scn, &scount)); 76 CHK(scount == multi_media_segments_count); 77 FOR_EACH(s, 0, scount) { 78 unsigned ids[2]; 79 OK(senc2d_scene_get_segment_enclosures(scn, s, ids)); 80 CHK(ids[0] == 0 && ids[1] == 1); 81 } 82 OK(senc2d_scene_get_enclosure_count(scn, &ecount)); 83 CHK(ecount == 2); 84 FOR_EACH(e, 0, ecount) { 85 struct senc2d_enclosure_header header; 86 OK(senc2d_scene_get_enclosure(scn, e, &enc)); 87 OK(senc2d_enclosure_get_header(enc, &header)); 88 CHK(header.primitives_count == multi_media_segments_count); 89 CHK(header.enclosed_media_count == (header.is_infinite ? 1u : 4u)); 90 OK(senc2d_enclosure_ref_put(enc)); 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_proxy_allocator(&allocator); 98 CHK(mem_allocated_size() == 0); 99 return 0; 100 }