star-3dut

Generate meshes of simple geometric shapes
git clone git://git.meso-star.fr/star-3dut.git
Log | Files | Refs | README | LICENSE

test_s3dut_sphere.c (3218B)


      1 /* Copyright (C) 2016, 2017, 2020, 2021, 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 "s3dut.h"
     17 #include "test_s3dut_utils.h"
     18 
     19 int
     20 main(int argc, char** argv)
     21 {
     22   struct mem_allocator allocator;
     23   struct s3dut_mesh* msh;
     24   struct s3dut_mesh_data data;
     25   (void)argc, (void)argv;
     26 
     27   CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK);
     28 
     29   CHK(s3dut_create_sphere(NULL, 0, 0, 0, NULL) == RES_BAD_ARG);
     30   CHK(s3dut_create_sphere(NULL, 1, 0, 0, NULL) == RES_BAD_ARG);
     31   CHK(s3dut_create_sphere(NULL, 0, 3, 0, NULL) == RES_BAD_ARG);
     32   CHK(s3dut_create_sphere(NULL, 1, 3, 0, NULL) == RES_BAD_ARG);
     33   CHK(s3dut_create_sphere(NULL, 0, 0, 2, NULL) == RES_BAD_ARG);
     34   CHK(s3dut_create_sphere(NULL, 1, 0, 2, NULL) == RES_BAD_ARG);
     35   CHK(s3dut_create_sphere(NULL, 0, 3, 2, NULL) == RES_BAD_ARG);
     36   CHK(s3dut_create_sphere(NULL, 1, 3, 2, NULL) == RES_BAD_ARG);
     37   CHK(s3dut_create_sphere(NULL, 0, 0, 0, &msh) == RES_BAD_ARG);
     38   CHK(s3dut_create_sphere(NULL, 1, 0, 0, &msh) == RES_BAD_ARG);
     39   CHK(s3dut_create_sphere(NULL, 0, 3, 0, &msh) == RES_BAD_ARG);
     40   CHK(s3dut_create_sphere(NULL, 1, 3, 0, &msh) == RES_BAD_ARG);
     41   CHK(s3dut_create_sphere(NULL, 0, 0, 2, &msh) == RES_BAD_ARG);
     42   CHK(s3dut_create_sphere(NULL, 1, 0, 2, &msh) == RES_BAD_ARG);
     43   CHK(s3dut_create_sphere(NULL, 0, 3, 2, &msh) == RES_BAD_ARG);
     44   CHK(s3dut_create_sphere(NULL, 1, 3, 2, &msh) == RES_OK);
     45 
     46   CHK(s3dut_mesh_ref_get(NULL) == RES_BAD_ARG);
     47   CHK(s3dut_mesh_ref_get(msh) == RES_OK);
     48   CHK(s3dut_mesh_ref_put(NULL) == RES_BAD_ARG);
     49   CHK(s3dut_mesh_ref_put(msh) == RES_OK);
     50   CHK(s3dut_mesh_ref_put(msh) == RES_OK);
     51 
     52   CHK(s3dut_create_sphere(&allocator, 1, 3, 2, &msh) == RES_OK);
     53   CHK(s3dut_mesh_ref_put(msh) == RES_OK);
     54 
     55   CHK(s3dut_create_sphere(&allocator, 1, 2, 2, &msh) == RES_BAD_ARG);
     56   CHK(s3dut_create_sphere(&allocator, 1, 3, 1, &msh) == RES_BAD_ARG);
     57   CHK(s3dut_create_sphere(&allocator,-1, 3, 2, &msh) == RES_BAD_ARG);
     58   CHK(s3dut_create_sphere(&allocator, 1, 32, 16, &msh) == RES_OK);
     59 
     60   CHK(s3dut_mesh_get_data(NULL, NULL) == RES_BAD_ARG);
     61   CHK(s3dut_mesh_get_data(msh, NULL) == RES_BAD_ARG);
     62   CHK(s3dut_mesh_get_data(NULL, &data) == RES_BAD_ARG);
     63   CHK(s3dut_mesh_get_data(msh, &data) == RES_OK);
     64   CHK(data.positions != NULL);
     65   CHK(data.indices != NULL);
     66   CHK(data.nvertices >= (32*(16-1)+2));
     67   CHK(data.nprimitives == (32*(16-2)*2) + 2*32);
     68 
     69   dump_mesh_data(stdout, &data);
     70 
     71   CHK(s3dut_mesh_ref_put(msh) == RES_OK);
     72 
     73   check_memory_allocator(&allocator);
     74   mem_shutdown_proxy_allocator(&allocator);
     75   CHK(mem_allocated_size() == 0);
     76   return 0;
     77 }
     78