sg2d_sdisXd_helper.h (2633B)
1 /* Copyright (C) 2019, 2020, 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 2 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 #ifndef SG2D_SDISXD_HELPER_H__ 17 #define SG2D_SDISXD_HELPER_H__ 18 19 #include "sg2d.h" 20 21 #include <rsys/rsys.h> 22 23 struct sdis_interface; 24 25 /* The type to used as the void* parameter in the sdis_scene_2d_create call */ 26 struct sg2d_sdisXd_scene_create_context { 27 struct sg2d_geometry* geometry; 28 struct sdis_interface* (*app_interface_getter)(const size_t iseg, void* data); 29 void* app_interface_data; 30 }; 31 32 /* Get vertex indices for the itri_th triangle. 33 * Suitable for use as get_indices callback in sdis_scene_create calls. */ 34 static FINLINE void 35 sg2d_sdisXd_geometry_get_indices 36 (const size_t itri, 37 size_t indices[SG2D_GEOMETRY_DIMENSION], 38 void* ctx__) 39 { 40 const struct sg2d_sdisXd_scene_create_context* ctx = ctx__; 41 unsigned i, tmp[2]; 42 ASSERT(indices && ctx && ctx->geometry && itri <= UINT_MAX); 43 SG2D(geometry_get_unique_triangle_vertices(ctx->geometry, (unsigned)itri, tmp)); 44 FOR_EACH(i, 0, SG2D_GEOMETRY_DIMENSION) indices[i] = tmp[i]; 45 } 46 47 /* Get vertex indices for the itri_th triangle. 48 * Suitable for use as get_position callback in sdis_scene_create calls. */ 49 static FINLINE void 50 sg2d_sdisXd_geometry_get_position 51 (const size_t ivert, 52 double coord[SG2D_GEOMETRY_DIMENSION], 53 void* ctx__) 54 { 55 const struct sg2d_sdisXd_scene_create_context* ctx = ctx__; 56 ASSERT(coord && ctx && ctx->geometry && ivert <= UINT_MAX); 57 SG2D(geometry_get_unique_vertex(ctx->geometry, (unsigned)ivert, coord)); 58 } 59 60 /* Get vertex indices for the itri_th triangle. 61 * Suitable for use as get_indices callback in sdis_scene_create calls. */ 62 static FINLINE void 63 sg2d_sdisXd_geometry_get_interface 64 (const size_t itri, 65 struct sdis_interface** bound, 66 void* ctx__) 67 { 68 const struct sg2d_sdisXd_scene_create_context* ctx = ctx__; 69 ASSERT(bound && ctx && ctx->app_interface_getter && itri < UINT_MAX); 70 *bound = ctx->app_interface_getter(itri, ctx->app_interface_data); 71 } 72 73 #endif /* SG2D_SDISXD_HELPER_H__ */