s3d_sphere.c (2124B)
1 /* Copyright (C) 2015-2023, 2026 |Méso|Star> (contact@meso-star.com) 2 * 3 * This file is part of Star-3D. 4 * 5 * Star-3D is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * Star-3D is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with Star-3D. If not, see <http://www.gnu.org/licenses/>. */ 17 18 #include "s3d_device_c.h" 19 #include "s3d_sphere.h" 20 21 /******************************************************************************* 22 * Helper functions 23 ******************************************************************************/ 24 static void 25 sphere_release(ref_T* ref) 26 { 27 struct sphere* sphre; 28 struct s3d_device* dev; 29 ASSERT(ref); 30 31 sphre = CONTAINER_OF(ref, struct sphere, ref); 32 dev = sphre->dev; 33 MEM_RM(dev->allocator, sphre); 34 S3D(device_ref_put(dev)); 35 } 36 37 /******************************************************************************* 38 * Local functions 39 ******************************************************************************/ 40 res_T 41 sphere_create(struct s3d_device* dev, struct sphere** out_sphere) 42 { 43 struct sphere* sphere = NULL; 44 res_T res = RES_OK; 45 ASSERT(dev && out_sphere); 46 47 sphere = (struct sphere*)MEM_CALLOC(dev->allocator, 1, sizeof(struct sphere)); 48 if(!sphere) { 49 res = RES_MEM_ERR; 50 goto error; 51 } 52 ref_init(&sphere->ref); 53 S3D(device_ref_get(dev)); 54 sphere->dev = dev; 55 sphere->radius = -1; 56 57 exit: 58 *out_sphere = sphere; 59 return res; 60 error: 61 if(sphere) { 62 sphere_ref_put(sphere); 63 sphere = NULL; 64 } 65 goto exit; 66 } 67 68 void 69 sphere_ref_get(struct sphere* sphere) 70 { 71 ASSERT(sphere); 72 ref_get(&sphere->ref); 73 } 74 75 void 76 sphere_ref_put(struct sphere* sphere) 77 { 78 ASSERT(sphere); 79 ref_put(&sphere->ref, sphere_release); 80 } 81