tess2_sys/lib.rs
1/* automatically generated by rust-bindgen */
2#![allow(dead_code,
3 non_camel_case_types,
4 non_upper_case_globals,
5 non_snake_case)]
6
7/// Determines how should tessTesselate interpret it's input, see [OpenGL tesselation docs](http://www.glprogramming.com/red/chapter11.html) for more
8#[derive(Copy, Clone)]
9#[repr(u32)]
10#[derive(Debug)]
11pub enum TessWindingRule {
12 TESS_WINDING_ODD = 0,
13 TESS_WINDING_NONZERO = 1,
14 TESS_WINDING_POSITIVE = 2,
15 TESS_WINDING_NEGATIVE = 3,
16 TESS_WINDING_ABS_GEQ_TWO = 4,
17}
18/// defines, what action tessTesselate is performing, tesselation, tesselation with neighboring polygons, or creating polygon contours
19#[derive(Copy, Clone)]
20#[repr(u32)]
21#[derive(Debug)]
22pub enum TessElementType {
23 TESS_POLYGONS = 0,
24 TESS_CONNECTED_POLYGONS = 1,
25 TESS_BOUNDARY_CONTOURS = 2,
26}
27/// typedef's from C
28pub type TESSreal = f32;
29pub type TESSindex = ::std::os::raw::c_int;
30/// Used only as opaque pointer to c structure
31pub enum TESStesselator { }
32#[repr(C)]
33#[derive(Copy, Clone)]
34#[derive(Debug)]
35pub struct TESSalloc {
36 pub memalloc: unsafe extern "C" fn(userData: *mut ::std::os::raw::c_void,
37 size: ::std::os::raw::c_uint) -> *mut ::std::os::raw::c_void,
38 pub memrealloc: unsafe extern "C" fn(userData: *mut ::std::os::raw::c_void,
39 ptr: *mut ::std::os::raw::c_void,
40 size: ::std::os::raw::c_uint) -> *mut ::std::os::raw::c_void,
41 pub memfree: unsafe extern "C" fn(userData: *mut ::std::os::raw::c_void,
42 ptr: *mut ::std::os::raw::c_void),
43 pub userData: *mut ::std::os::raw::c_void,
44 pub meshEdgeBucketSize: ::std::os::raw::c_int,
45 pub meshVertexBucketSize: ::std::os::raw::c_int,
46 pub meshFaceBucketSize: ::std::os::raw::c_int,
47 pub dictNodeBucketSize: ::std::os::raw::c_int,
48 pub regionBucketSize: ::std::os::raw::c_int,
49 pub extraVertices: ::std::os::raw::c_int,
50}
51impl ::std::default::Default for TESSalloc {
52 fn default() -> Self { unsafe { ::std::mem::zeroed() } }
53}
54#[link(name = "tess2", kind = "dylib")]
55extern "C" {
56 /// Creates new Tesselator object with specified or default allocator or uses default.
57 ///
58 /// # Arguments
59 /// * `alloc` - Tesselator allocation configuration, if null, then default is used
60 pub fn tessNewTess(alloc: *mut TESSalloc) -> *mut TESStesselator;
61 /// Destroys tesselator and all resources associated
62 pub fn tessDeleteTess(tess: *mut TESStesselator);
63 /// Adds new contour to tesselator, this function copies vertices into internal buffer
64 ///
65 /// # Arguments
66 /// * `size` - specifies number of floats per vertex
67 /// * `pointer` - pointer to data
68 /// * `stride` - stride between vertices ( in bytes )
69 /// * `count` - number of vertices to add
70 pub fn tessAddContour(tess: *mut TESStesselator,
71 size: ::std::os::raw::c_int,
72 pointer: *const ::std::os::raw::c_void,
73 stride: ::std::os::raw::c_int,
74 count: ::std::os::raw::c_int);
75 /// Tesselates stored paths
76 ///
77 /// # Arguments
78 /// * `windingRule` - see [OpenGL tesselation docs](http://www.glprogramming.com/red/chapter11.html) for more
79 /// * `elementType` - specifies output type
80 /// * `polySize` - maximum number of vertices per generated polygon
81 /// * `vertexSize` - numer of coordinates per vertex, can be 2 or 3
82 /// * `normal` - the normal of the input contours, if null the normal is calculated automatically.
83 ///
84 /// First call to this function invalidates internal input buffers, so every call to tessAddContour after calling tessTesselate
85 /// is not affected by previous data
86 pub fn tessTesselate(tess: *mut TESStesselator,
87 windingRule: TessWindingRule,
88 elementType: TessElementType,
89 polySize: ::std::os::raw::c_int,
90 vertexSize: ::std::os::raw::c_int,
91 normal: *const TESSreal) -> ::std::os::raw::c_int;
92 /// Returns number of vertices in internal output buffer
93 pub fn tessGetVertexCount(tess: *mut TESStesselator) -> ::std::os::raw::c_int;
94 /// Returns pointer to internal vertex output buffer
95 pub fn tessGetVertices(tess: *mut TESStesselator) -> *const TESSreal;
96 /// Returns pointer to vertex index buffer
97 ///
98 /// Vertex index buffer is used to map output vertices onto input vertices.
99 ///
100 /// internally generated vertices are assigned value of -1
101 pub fn tessGetVertexIndices(tess: *mut TESStesselator) -> *const TESSindex;
102 /// Returns number of generated elements
103 ///
104 /// Meaning of this number depends on elementType specified when calling tessTesselate
105 pub fn tessGetElementCount(tess: *mut TESStesselator) -> ::std::os::raw::c_int;
106 /// Returns element buffer
107 ///
108 /// # Warning!
109 /// Size of this buffer is not tessGetElementCount ints.
110 ///
111 /// Size of this buffer depends on values provided when calling tessTesselate
112 ///
113 /// if element type is TESS_POLYGONS, then this array contains tessGetElementCount * polySize integers.
114 /// array can be divided into tessGetElementCount slices of polySize length.
115 /// Each slice contains indices to vertices in tessGetVertices that create this polygon.
116 /// If polygon has less vertices than polySize, remaining indices are -1
117 ///
118 /// if element type is TESS_CONNECTED_POLYGONS, this array contains tessGetElementCount * polysize
119 ///
120 /// if element type is TESS_BOUNDARY_CONTOURS, this array contains tessGetElementCount * 2 integers
121 /// each pair of values determines [position, length] of polygon contours stored in vertices array
122 pub fn tessGetElements(tess: *mut TESStesselator) -> *const TESSindex;
123}
124
125#[test]
126fn test_link(){
127 unsafe {
128 let a = tessNewTess(0 as *mut _);
129 tessDeleteTess(a);
130 }
131}
132
133#[test]
134fn test_basic_tess(){
135 let mut data = [
136 0.0,0.0,
137 // 0.3,0.3f32,
138 1.0,0.0f32,
139 1.0,1.0,
140 0.0,1.0,
141 ];unsafe {
142 let nvp = 3usize;
143 let fpv = 2;
144 let bpv = 2 * std::mem::size_of::<f32>();
145 let mut tess = tessNewTess(0 as *mut _);
146 tessAddContour(tess,2,data.as_ptr() as _, 2 * std::mem::size_of::<f32>() as i32,(data.len()/2) as _);
147
148 /* tessAddContour(tess,2,data.as_ptr() as _, 2 * std::mem::size_of::<f32>() as i32,(data.len()/2) as _); data[0] = -1.0;
149 data[1] = -1.0;
150
151 tessAddContour(tess,2,data.as_ptr() as _, 2 * std::mem::size_of::<f32>() as i32,(data.len()/2) as _);
152 */
153 // tessAddContour(tess,2,data.as_ptr() as _,0,(data.len()/2) as _);
154
155 println!("STATUS:{:?}", tessTesselate(tess,TessWindingRule::TESS_WINDING_POSITIVE,TessElementType::TESS_POLYGONS,nvp as i32,2,0 as *const _));
156 println!("Elems:{:?} {:?}",tessGetElements(tess),tessGetElementCount(tess));
157 println!("Elems:{:?} {:?}",tessGetVertices(tess),tessGetVertexCount(tess));
158 println!("Elems:{:?} {:?}",tessGetVertexIndices(tess),tessGetVertexCount(tess));
159 println!("Elems:{:?}",std::slice::from_raw_parts(tessGetElements(tess),((tessGetElementCount(tess) as usize)*nvp)));
160 println!("Verts:{:?}",std::slice::from_raw_parts(tessGetVertices(tess) as *const f32,tessGetVertexCount(tess) as usize * fpv));
161 println!("Indis:{:?}",std::slice::from_raw_parts(tessGetVertexIndices(tess),tessGetVertexCount(tess) as _));
162
163
164 }
165}