star-3d

Surface structuring for efficient 3D geometric queries
git clone git://git.meso-star.fr/star-3d.git
Log | Files | Refs | README | LICENSE

commit d9e8cabe258130741b8f2103b3efcaf495e579d7
parent d80f604129e3d8a1daa6f464edd63d9084428103
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 11 Mar 2015 09:38:01 +0100

Begin the implementation of the scene back-end

Diffstat:
Msrc/s3d_scene.c | 36++++++++++++++++++++++++++++++++++++
Msrc/s3d_shape_c.h | 2+-
2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/src/s3d_scene.c b/src/s3d_scene.c @@ -34,11 +34,13 @@ #include "s3d_device_c.h" #include "s3d_shape_c.h" +#include <embree2/rtcore.h> #include <rsys/mem_allocator.h> struct s3d_scene { struct list_node shapes; /* List of attached shapes */ struct s3d_device* dev; + RTCScene rtc_scn; ref_T ref; }; @@ -46,6 +48,31 @@ struct s3d_scene { * Helper functions ******************************************************************************/ static void +scene_setup(struct s3d_scene* scn) +{ + struct list_node* node; + + LIST_FOR_EACH(node, &scn->shapes) { + struct s3d_shape* shape = CONTAINER_OF + (node, struct s3d_shape, scene_attachment); + uint32_t* ids = darray_u32_data_get(&shape->indices); + float* pos = darray_float_data_get(&shape->positions); + const size_t ntris = darray_u32_size_get(&shape->indices) / 3; + const size_t nverts = darray_float_size_get(&shape->positions) / 3; + ASSERT(IS_ALIGNED(ids, 16)); + + ASSERT(shape->type == SHAPE_TRIMESH); + shape->rtc_geom = rtcNewTriangleMesh + (scn->rtc_scn, RTC_GEOMETRY_STATIC, ntris, nverts); + rtcSetBuffer(scn->rtc_scn, shape->rtc_geom, RTC_INDEX_BUFFER, ids, 0, + sizeof(uint32_t[3])); + rtcSetBuffer(scn->rtc_scn, shape->rtc_geom, RTC_VERTEX_BUFFER, pos, 0, + sizeof(float[3])); + } + rtcCommit(scn->rtc_scn); +} + +static void scene_release(ref_T* ref) { struct s3d_scene* scn; @@ -54,6 +81,8 @@ scene_release(ref_T* ref) scn = CONTAINER_OF(ref, struct s3d_scene, ref); S3D(scene_clear(scn)); dev = scn->dev; + if(scn->rtc_scn) + rtcDeleteScene(scn->rtc_scn); MEM_FREE(dev->allocator, scn); S3D(device_ref_put(dev)); } @@ -81,6 +110,13 @@ s3d_scene_create(struct s3d_device* dev, struct s3d_scene** out_scn) ref_init(&scn->ref); S3D(device_ref_get(dev)); scn->dev = dev; + scn->rtc_scn = rtcNewScene + (RTC_SCENE_STATIC | RTC_SCENE_INCOHERENT, + RTC_INTERSECT1 | RTC_INTERSECT4); + if(!scn->rtc_scn) { + res = RES_MEM_ERR; + goto error; + } exit: if(out_scn) *out_scn = scn; diff --git a/src/s3d_shape_c.h b/src/s3d_shape_c.h @@ -48,7 +48,7 @@ enum shape_type { struct s3d_shape { struct list_node scene_attachment; enum shape_type type; - unsigned igeom; /* Embree geometry id */ + unsigned rtc_geom; /* Embree geometry id */ darray_u32 indices; darray_float positions; /* list of 3 floats */