test_sg3d_cube_behind_cube.c (4612B)
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 19 #include <rsys/double3.h> 20 21 #include <stdio.h> 22 23 /* 24 cube_2 cube_3 25 26 +-----------------------+ 27 | 3 28 | | 29 m1 | m0 | 30 | | 31 | | 32 | | 33 | |--> N 34 | | 35 | | 36 +-----------------------+ 37 +------------+ +------------+ 38 | 2 | 2 39 m0 | m1 | m0 | m1 | 40 | | | | 41 | |--> N | |--> N 42 | | | | 43 +------------+ +------------+ 44 +-----+ +-----+ 45 m0 | m1 1 m0 | m1 1 46 | |--> N | |--> N 47 +-----+ +-----+ 48 */ 49 50 int 51 main(int argc, char** argv) 52 { 53 struct mem_allocator allocator; 54 struct sg3d_device* dev; 55 struct sg3d_geometry* geom; 56 struct context ctx = CONTEXT_NULL__; 57 struct sg3d_geometry_add_callbacks callbacks = SG3D_ADD_CALLBACKS_NULL__; 58 unsigned count; 59 (void)argc, (void)argv; 60 61 OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); 62 OK(sg3d_device_create(NULL, &allocator, 1, &dev)); 63 OK(sg3d_geometry_create(dev, &geom)); 64 SG3D(device_ref_put(dev)); 65 66 callbacks.get_indices = get_indices; 67 callbacks.get_properties = get_properties; 68 callbacks.get_position = get_position; 69 70 ctx.positions = box_vertices; 71 ctx.indices = cube_indices; 72 ctx.front_media = medium0; 73 ctx.back_media = medium1; 74 ctx.intface = intface0; 75 76 /* First cube (front: 0, back: 1), right-handed normal outside */ 77 OK(sg3d_geometry_add(geom, nvertices, ntriangles, &callbacks, &ctx)); 78 79 d3(ctx.offset, -2, -2, 20); 80 d3_splat(ctx.scale, 5); 81 82 /* Second cube (front: 0, back: 1), right-handed normal outside */ 83 OK(sg3d_geometry_add(geom, nvertices, ntriangles, &callbacks, &ctx)); 84 85 OK(sg3d_geometry_get_unique_triangles_with_merge_conflict_count(geom, &count)); 86 CHK(count == 0); 87 OK(sg3d_geometry_get_unique_triangles_with_unspecified_interface_count(geom, &count)); 88 CHK(count == 0); 89 OK(sg3d_geometry_get_unique_triangles_with_unspecified_side_count(geom, &count)); 90 CHK(count == 0); 91 OK(sg3d_geometry_dump_as_c_code(geom, stdout, "cube_behind_cube_2", 92 SG3D_C_DUMP_CONST | SG3D_C_DUMP_STATIC)); 93 94 d3(ctx.offset, -3, -3, 30); 95 d3_splat(ctx.scale, 7); 96 ctx.front_media = medium1; 97 ctx.back_media = medium0; 98 99 /* Third cube (front: 1, back: 0), right-handed normal outside */ 100 OK(sg3d_geometry_add(geom, nvertices, ntriangles, &callbacks, &ctx)); 101 102 OK(sg3d_geometry_get_unique_triangles_with_merge_conflict_count(geom, &count)); 103 CHK(count == 0); 104 OK(sg3d_geometry_get_unique_triangles_with_unspecified_interface_count(geom, &count)); 105 CHK(count == 0); 106 OK(sg3d_geometry_get_unique_triangles_with_unspecified_side_count(geom, &count)); 107 CHK(count == 0); 108 OK(sg3d_geometry_dump_as_c_code(geom, stdout, "cube_behind_cube_3", 109 SG3D_C_DUMP_CONST | SG3D_C_DUMP_STATIC)); 110 111 SG3D(geometry_ref_put(geom)); 112 113 check_memory_allocator(&allocator); 114 mem_shutdown_proxy_allocator(&allocator); 115 CHK(mem_allocated_size() == 0); 116 return 0; 117 }