commit a42461fd0e24dbe31e1e396032321123f6464af2
parent 6e2148c786dec3dc51fd8da03ebc707cfe859119
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Wed, 15 Apr 2026 16:15:46 +0200
Meet star-cpr 0.3+ requirements
Diffstat:
3 files changed, 52 insertions(+), 11 deletions(-)
diff --git a/src/ssol_device.c b/src/ssol_device.c
@@ -59,6 +59,7 @@ device_release(ref_T* ref)
}
if(dev->s3d) S3D(device_ref_put(dev->s3d));
if(dev->scpr_mesh) SCPR(mesh_ref_put(dev->scpr_mesh));
+ if(dev->scpr_device) SCPR(device_ref_put(dev->scpr_device));
MEM_RM(dev->allocator, dev);
}
@@ -76,6 +77,7 @@ ssol_device_create
struct ssol_device* dev = NULL;
struct mem_allocator* allocator;
unsigned i;
+ struct scpr_device_create_args scpr_args = SCPR_DEVICE_CREATE_ARGS_DEFAULT;
res_T res = RES_OK;
if(nthreads_hint == 0 || !out_dev) {
@@ -93,7 +95,7 @@ ssol_device_create
darray_tile_init(allocator, &dev->tiles);
dev->logger = logger ? logger : LOGGER_DEFAULT;
dev->allocator = allocator;
- dev->verbose = verbose;
+ dev->verbose = verbose; /* TODO: check if verbosity levels match */
dev->nthreads = MMIN(nthreads_hint, (unsigned)omp_get_num_procs());
omp_set_num_threads((int)dev->nthreads);
@@ -109,12 +111,17 @@ ssol_device_create
(&dev->bsdf_allocators[i], dev->allocator, 4096);
if(res != RES_OK) goto error;
}
-
+
res = darray_tile_resize(&dev->tiles, dev->nthreads);
if(res != RES_OK) goto error;
res = s3d_device_create(logger, mem_allocator, 0, &dev->s3d);
if(res != RES_OK) goto error;
- res = scpr_mesh_create(mem_allocator, &dev->scpr_mesh);
+ scpr_args.allocator = allocator;
+ scpr_args.logger = logger;
+ scpr_args.verbosity_level = dev->verbose;
+ res = scpr_device_create(&scpr_args, &dev->scpr_device);
+ if(res != RES_OK) goto error;
+ res = scpr_mesh_create(dev->scpr_device, &dev->scpr_mesh);
if(res != RES_OK) goto error;
exit:
diff --git a/src/ssol_device_c.h b/src/ssol_device_c.h
@@ -49,6 +49,7 @@ struct ssol_device {
struct s3d_device* s3d;
struct scpr_mesh* scpr_mesh; /* Use to clip quadric mesh */
+ struct scpr_device* scpr_device;
ref_T ref;
};
diff --git a/src/ssol_shape.c b/src/ssol_shape.c
@@ -539,19 +539,44 @@ error:
goto exit;
}
+static void
+get_carving_count
+ (const size_t ic,
+ size_t *count,
+ void* ctx)
+{
+ const struct ssol_carving* carving = (const struct ssol_carving*)ctx;
+ ASSERT(ic == 1 && count); (void)ic;
+ *count = carving->nb_vertices;
+}
+
+static void
+get_carving_pos
+ (const size_t ic,
+ const size_t iv,
+ double pos[2],
+ void* ctx)
+{
+ struct ssol_carving* carving = (struct ssol_carving*)ctx;
+ ASSERT(ic == 1); (void)ic;
+ carving->get(iv, pos, carving->context);
+}
+
static res_T
clip_triangulated_sheet
(struct darray_double* coords,
struct darray_size_t* ids,
struct scpr_mesh* mesh,
const struct ssol_carving* carvings,
- const size_t ncarvings)
+ const size_t ncarvings,
+ struct scpr_device* scpr)
{
struct mesh_context msh;
size_t nverts;
size_t ntris;
size_t icarving;
size_t i;
+ struct scpr_polygon* polygon = NULL;
res_T res = RES_OK;
ASSERT(coords && ids && carvings && ncarvings);
ASSERT(darray_double_size_get(coords) % 2 == 0);
@@ -570,15 +595,19 @@ clip_triangulated_sheet
/* Apply each carving operation to the Star-CliPpeR mesh */
FOR_EACH(icarving, 0, ncarvings) {
- struct scpr_polygon polygon;
enum scpr_operation op = ssol_to_scpr_clip_op(carvings[icarving].operation);
- polygon.get_position = carvings[icarving].get;
- polygon.nvertices = carvings[icarving].nb_vertices;
- polygon.context = carvings[icarving].context;
+ SCPR(polygon_create(scpr, &polygon));
+ res = scpr_polygon_setup_indexed_vertices(polygon, 1,
+ get_carving_count,
+ get_carving_pos,
+ (void*)&carvings[icarving]);
+ if(res != RES_OK) goto error;
- res = scpr_mesh_clip(mesh, op, &polygon);
+ res = scpr_mesh_clip(mesh, op, polygon);
if(res != RES_OK) goto error;
+ SCPR(polygon_ref_put(polygon));
+ polygon = NULL;
}
/* Reserve the output index/vertex buffer memory space */
@@ -611,6 +640,9 @@ clip_triangulated_sheet
exit:
return res;
error:
+ if(polygon) {
+ SCPR(polygon_ref_put(polygon));
+ }
goto exit;
}
@@ -1536,7 +1568,7 @@ ssol_punched_surface_setup
nslices = psurf->quadric->slices_count_hint;
} else if(psurf->quadric->type == SSOL_QUADRIC_HEMISPHERE) {
nslices = hemisphere_compute_slices_count
- (&shape->private_data.hemisphere, radius);
+ (&shape->private_data.hemisphere, radius);
} else {
nslices = priv_quadric_data_compute_slices_count
(shape->quadric_type, &shape->private_data, lower, upper);
@@ -1553,7 +1585,8 @@ ssol_punched_surface_setup
/* Clip the quadric mesh if necessary */
if(psurf->nb_carvings) {
res = clip_triangulated_sheet
- (&coords, &ids, shape->dev->scpr_mesh, psurf->carvings, psurf->nb_carvings);
+ (&coords, &ids, shape->dev->scpr_mesh, psurf->carvings, psurf->nb_carvings,
+ shape->dev->scpr_device);
if(res != RES_OK) goto error;
}