s3d_sphere.c (2097B)
1 /* Copyright (C) 2015-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 "s3d_device_c.h" 17 #include "s3d_sphere.h" 18 19 /******************************************************************************* 20 * Helper functions 21 ******************************************************************************/ 22 static void 23 sphere_release(ref_T* ref) 24 { 25 struct sphere* sphre; 26 struct s3d_device* dev; 27 ASSERT(ref); 28 29 sphre = CONTAINER_OF(ref, struct sphere, ref); 30 dev = sphre->dev; 31 MEM_RM(dev->allocator, sphre); 32 S3D(device_ref_put(dev)); 33 } 34 35 /******************************************************************************* 36 * Local functions 37 ******************************************************************************/ 38 res_T 39 sphere_create(struct s3d_device* dev, struct sphere** out_sphere) 40 { 41 struct sphere* sphere = NULL; 42 res_T res = RES_OK; 43 ASSERT(dev && out_sphere); 44 45 sphere = (struct sphere*)MEM_CALLOC(dev->allocator, 1, sizeof(struct sphere)); 46 if(!sphere) { 47 res = RES_MEM_ERR; 48 goto error; 49 } 50 ref_init(&sphere->ref); 51 S3D(device_ref_get(dev)); 52 sphere->dev = dev; 53 sphere->radius = -1; 54 55 exit: 56 *out_sphere = sphere; 57 return res; 58 error: 59 if(sphere) { 60 sphere_ref_put(sphere); 61 sphere = NULL; 62 } 63 goto exit; 64 } 65 66 void 67 sphere_ref_get(struct sphere* sphere) 68 { 69 ASSERT(sphere); 70 ref_get(&sphere->ref); 71 } 72 73 void 74 sphere_ref_put(struct sphere* sphere) 75 { 76 ASSERT(sphere); 77 ref_put(&sphere->ref, sphere_release); 78 } 79