1use std::ffi::c_void;
9use std::os::raw::{c_int, c_uint};
10
11pub const INTERSECTION: c_int = 0;
13pub const SUBTRACTION: c_int = 1;
15
16pub const ALGORITHM_AUTOMATIC: c_int = 0;
18pub const ALGORITHM_GOLDFEATHER: c_int = 1;
20pub const ALGORITHM_SCS: c_int = 2;
22
23pub const OPTION_ALGORITHM: c_int = 0;
25pub const OPTION_DEPTH_COMPLEXITY: c_int = 1;
27pub const OPTION_OFFSCREEN: c_int = 2;
29
30pub type RenderFn = unsafe extern "C" fn(*mut c_void);
32
33#[repr(C)]
35pub struct OcsgPrimitive {
36 _opaque: [u8; 0],
37}
38
39unsafe extern "C" {
40 pub safe fn opencsg_init_gl();
41
42 pub fn opencsg_primitive_new(
43 operation: c_int,
44 convexity: c_uint,
45 callback: RenderFn,
46 user_data: *mut c_void,
47 ) -> *mut OcsgPrimitive;
48
49 pub fn opencsg_primitive_free(prim: *mut OcsgPrimitive);
50
51 pub fn opencsg_primitive_set_bounding_box(
52 prim: *mut OcsgPrimitive,
53 minx: f32,
54 miny: f32,
55 minz: f32,
56 maxx: f32,
57 maxy: f32,
58 maxz: f32,
59 );
60
61 pub fn opencsg_render_primitives(
62 primitives: *mut *mut OcsgPrimitive,
63 count: c_int,
64 );
65
66 pub safe fn opencsg_set_option(option_type: c_int, setting: c_int);
67
68 pub safe fn opencsg_free_resources();
69}
70
71pub fn init_gl() {
75 opencsg_init_gl();
76}
77
78pub fn set_option(option_type: c_int, setting: c_int) {
80 opencsg_set_option(option_type, setting);
81}
82
83pub fn free_resources() {
85 opencsg_free_resources();
86}
87
88pub unsafe fn render(primitives: &mut [*mut OcsgPrimitive]) {
94 if primitives.is_empty() {
95 return;
96 }
97 unsafe {
98 opencsg_render_primitives(
99 primitives.as_mut_ptr(),
100 primitives.len() as c_int,
101 );
102 }
103}
104
105pub unsafe fn primitive_new(
111 operation: c_int,
112 convexity: u32,
113 callback: RenderFn,
114 user_data: *mut c_void,
115) -> *mut OcsgPrimitive {
116 unsafe {
117 opencsg_primitive_new(operation, convexity as c_uint, callback, user_data)
118 }
119}
120
121pub unsafe fn primitive_free(prim: *mut OcsgPrimitive) {
126 unsafe {
127 opencsg_primitive_free(prim);
128 }
129}
130
131pub unsafe fn primitive_set_bbox(
136 prim: *mut OcsgPrimitive,
137 minx: f32,
138 miny: f32,
139 minz: f32,
140 maxx: f32,
141 maxy: f32,
142 maxz: f32,
143) {
144 unsafe {
145 opencsg_primitive_set_bounding_box(
146 prim, minx, miny, minz, maxx, maxy, maxz,
147 );
148 }
149}