cogl/auto/
primitive.rs

1use crate::{
2    Attribute, Context, Framebuffer, Indices, Object, Pipeline, VertexP2, VertexP2C4, VertexP2T2,
3    VertexP2T2C4, VertexP3, VertexP3C4, VertexP3T2, VertexP3T2C4, VerticesMode,
4};
5
6use glib::object::IsA;
7use glib::translate::*;
8use std::fmt;
9
10glib_wrapper! {
11    pub struct Primitive(Object<ffi::CoglPrimitive, PrimitiveClass>) @extends Object;
12
13    match fn {
14        get_type => || ffi::cogl_primitive_get_gtype(),
15    }
16}
17
18impl Primitive {
19    //pub fn new(mode: VerticesMode, n_vertices: i32, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> Primitive {
20    //    unsafe { TODO: call cogl_sys:cogl_primitive_new() }
21    //}
22
23    /// Provides a convenient way to describe a primitive, such as a single
24    /// triangle strip or a triangle fan, that will internally allocate the
25    /// necessary `AttributeBuffer` storage, describe the position
26    /// attribute with a `Attribute` and upload your data.
27    ///
28    /// For example to draw a convex polygon you can do:
29    ///
30    /// ```text
31    /// CoglVertexP2 triangle[] =
32    /// {
33    ///   { 0,   300 },
34    ///   { 150, 0,  },
35    ///   { 300, 300 }
36    /// };
37    /// prim = cogl_primitive_new_p2 (COGL_VERTICES_MODE_TRIANGLE_FAN,
38    ///                               3, triangle);
39    /// cogl_primitive_draw (prim);
40    /// ```
41    ///
42    /// The value passed as `n_vertices` is initially used to determine how
43    /// much can be read from `data` but it will also be used to update the
44    /// `Primitive` `<structfield>`n_vertices`</structfield>` property as if
45    /// `Primitive::set_n_vertices` were called. This property defines
46    /// the number of vertices to read when drawing.
47    ///
48    /// `<note>`The primitive API doesn't support drawing with sliced
49    /// textures (since switching between slices implies changing state and
50    /// so that implies multiple primitives need to be submitted). You
51    /// should pass the `TextureFlags::NoSlicing` flag to all textures that
52    /// might be used while drawing with this API. If your hardware doesn't
53    /// support non-power of two textures (For example you are using GLES
54    /// 1.1) then you will need to make sure your assets are resized to a
55    /// power-of-two size (though they don't have to be square)`</note>`
56    /// ## `context`
57    /// A `Context`
58    /// ## `mode`
59    /// A `VerticesMode` defining how to draw the vertices
60    /// ## `n_vertices`
61    /// The number of vertices to read from `data` and also
62    ///  the number of vertices to read when later drawing.
63    /// ## `data`
64    /// An array
65    ///  of `VertexP2` vertices
66    ///
67    /// # Returns
68    ///
69    /// A newly allocated `Primitive`
70    /// with a reference of 1. This can be freed using `Object::unref`.
71    pub fn new_p2(context: &Context, mode: VerticesMode, data: &[&VertexP2]) -> Primitive {
72        let data: Vec<ffi::CoglVertexP2> = data
73            .iter()
74            .map(|e| unsafe { *e.to_glib_none().0 })
75            .collect();
76        let n_vertices = data.len() as i32;
77        unsafe {
78            from_glib_full(ffi::cogl_primitive_new_p2(
79                context.to_glib_none().0,
80                mode.to_glib(),
81                n_vertices,
82                data.as_ptr(),
83            ))
84        }
85    }
86
87    /// Provides a convenient way to describe a primitive, such as a single
88    /// triangle strip or a triangle fan, that will internally allocate the
89    /// necessary `AttributeBuffer` storage, describe the position
90    /// and color attributes with `Attribute`<!-- -->s and upload
91    /// your data.
92    ///
93    /// For example to draw a convex polygon with a linear gradient you
94    /// can do:
95    ///
96    /// ```text
97    /// CoglVertexP2C4 triangle[] =
98    /// {
99    ///   { 0,   300,  0xff, 0x00, 0x00, 0xff },
100    ///   { 150, 0,    0x00, 0xff, 0x00, 0xff },
101    ///   { 300, 300,  0xff, 0x00, 0x00, 0xff }
102    /// };
103    /// prim = cogl_primitive_new_p2c4 (COGL_VERTICES_MODE_TRIANGLE_FAN,
104    ///                                 3, triangle);
105    /// cogl_primitive_draw (prim);
106    /// ```
107    ///
108    /// The value passed as `n_vertices` is initially used to determine how
109    /// much can be read from `data` but it will also be used to update the
110    /// `Primitive` `<structfield>`n_vertices`</structfield>` property as if
111    /// `Primitive::set_n_vertices` were called. This property defines
112    /// the number of vertices to read when drawing.
113    ///
114    /// `<note>`The primitive API doesn't support drawing with sliced
115    /// textures (since switching between slices implies changing state and
116    /// so that implies multiple primitives need to be submitted). You
117    /// should pass the `TextureFlags::NoSlicing` flag to all textures that
118    /// might be used while drawing with this API. If your hardware doesn't
119    /// support non-power of two textures (For example you are using GLES
120    /// 1.1) then you will need to make sure your assets are resized to a
121    /// power-of-two size (though they don't have to be square)`</note>`
122    /// ## `context`
123    /// A `Context`
124    /// ## `mode`
125    /// A `VerticesMode` defining how to draw the vertices
126    /// ## `n_vertices`
127    /// The number of vertices to read from `data` and also
128    ///  the number of vertices to read when later drawing.
129    /// ## `data`
130    /// An array
131    ///  of `VertexP2C4` vertices
132    ///
133    /// # Returns
134    ///
135    /// A newly allocated `Primitive`
136    /// with a reference of 1. This can be freed using `Object::unref`.
137    pub fn new_p2c4(context: &Context, mode: VerticesMode, data: &[&VertexP2C4]) -> Primitive {
138        let data: Vec<ffi::CoglVertexP2C4> = data
139            .iter()
140            .map(|e| unsafe { *e.to_glib_none().0 })
141            .collect();
142        let n_vertices = data.len() as i32;
143        unsafe {
144            from_glib_full(ffi::cogl_primitive_new_p2c4(
145                context.to_glib_none().0,
146                mode.to_glib(),
147                n_vertices,
148                data.as_ptr(),
149            ))
150        }
151    }
152
153    /// Provides a convenient way to describe a primitive, such as a single
154    /// triangle strip or a triangle fan, that will internally allocate the
155    /// necessary `AttributeBuffer` storage, describe the position and
156    /// texture coordinate attributes with `Attribute`<!-- -->s and
157    /// upload your data.
158    ///
159    /// For example to draw a convex polygon with texture mapping you can
160    /// do:
161    ///
162    /// ```text
163    /// CoglVertexP2T2 triangle[] =
164    /// {
165    ///   { 0,   300,  0.0, 1.0},
166    ///   { 150, 0,    0.5, 0.0},
167    ///   { 300, 300,  1.0, 1.0}
168    /// };
169    /// prim = cogl_primitive_new_p2t2 (COGL_VERTICES_MODE_TRIANGLE_FAN,
170    ///                                 3, triangle);
171    /// cogl_primitive_draw (prim);
172    /// ```
173    ///
174    /// The value passed as `n_vertices` is initially used to determine how
175    /// much can be read from `data` but it will also be used to update the
176    /// `Primitive` `<structfield>`n_vertices`</structfield>` property as if
177    /// `Primitive::set_n_vertices` were called. This property defines
178    /// the number of vertices to read when drawing.
179    ///
180    /// `<note>`The primitive API doesn't support drawing with sliced
181    /// textures (since switching between slices implies changing state and
182    /// so that implies multiple primitives need to be submitted). You
183    /// should pass the `TextureFlags::NoSlicing` flag to all textures that
184    /// might be used while drawing with this API. If your hardware doesn't
185    /// support non-power of two textures (For example you are using GLES
186    /// 1.1) then you will need to make sure your assets are resized to a
187    /// power-of-two size (though they don't have to be square)`</note>`
188    /// ## `context`
189    /// A `Context`
190    /// ## `mode`
191    /// A `VerticesMode` defining how to draw the vertices
192    /// ## `n_vertices`
193    /// The number of vertices to read from `data` and also
194    ///  the number of vertices to read when later drawing.
195    /// ## `data`
196    /// An array
197    ///  of `VertexP2T2` vertices
198    ///
199    /// # Returns
200    ///
201    /// A newly allocated `Primitive`
202    /// with a reference of 1. This can be freed using `Object::unref`.
203    pub fn new_p2t2(context: &Context, mode: VerticesMode, data: &[&VertexP2T2]) -> Primitive {
204        let data: Vec<ffi::CoglVertexP2T2> = data
205            .iter()
206            .map(|e| unsafe { *e.to_glib_none().0 })
207            .collect();
208        let n_vertices = data.len() as i32;
209        unsafe {
210            from_glib_full(ffi::cogl_primitive_new_p2t2(
211                context.to_glib_none().0,
212                mode.to_glib(),
213                n_vertices,
214                data.as_ptr(),
215            ))
216        }
217    }
218
219    /// Provides a convenient way to describe a primitive, such as a single
220    /// triangle strip or a triangle fan, that will internally allocate the
221    /// necessary `AttributeBuffer` storage, describe the position, texture
222    /// coordinate and color attributes with `Attribute`<!-- -->s and
223    /// upload your data.
224    ///
225    /// For example to draw a convex polygon with texture mapping and a
226    /// linear gradient you can do:
227    ///
228    /// ```text
229    /// CoglVertexP2T2C4 triangle[] =
230    /// {
231    ///   { 0,   300,  0.0, 1.0,  0xff, 0x00, 0x00, 0xff},
232    ///   { 150, 0,    0.5, 0.0,  0x00, 0xff, 0x00, 0xff},
233    ///   { 300, 300,  1.0, 1.0,  0xff, 0x00, 0x00, 0xff}
234    /// };
235    /// prim = cogl_primitive_new_p2t2c4 (COGL_VERTICES_MODE_TRIANGLE_FAN,
236    ///                                   3, triangle);
237    /// cogl_primitive_draw (prim);
238    /// ```
239    ///
240    /// The value passed as `n_vertices` is initially used to determine how
241    /// much can be read from `data` but it will also be used to update the
242    /// `Primitive` `<structfield>`n_vertices`</structfield>` property as if
243    /// `Primitive::set_n_vertices` were called. This property defines
244    /// the number of vertices to read when drawing.
245    ///
246    /// `<note>`The primitive API doesn't support drawing with sliced
247    /// textures (since switching between slices implies changing state and
248    /// so that implies multiple primitives need to be submitted). You
249    /// should pass the `TextureFlags::NoSlicing` flag to all textures that
250    /// might be used while drawing with this API. If your hardware doesn't
251    /// support non-power of two textures (For example you are using GLES
252    /// 1.1) then you will need to make sure your assets are resized to a
253    /// power-of-two size (though they don't have to be square)`</note>`
254    /// ## `context`
255    /// A `Context`
256    /// ## `mode`
257    /// A `VerticesMode` defining how to draw the vertices
258    /// ## `n_vertices`
259    /// The number of vertices to read from `data` and also
260    ///  the number of vertices to read when later drawing.
261    /// ## `data`
262    /// An
263    ///  array of `VertexP2T2C4` vertices
264    ///
265    /// # Returns
266    ///
267    /// A newly allocated `Primitive`
268    /// with a reference of 1. This can be freed using `Object::unref`.
269    pub fn new_p2t2c4(context: &Context, mode: VerticesMode, data: &[&VertexP2T2C4]) -> Primitive {
270        let data: Vec<ffi::CoglVertexP2T2C4> = data
271            .iter()
272            .map(|e| unsafe { *e.to_glib_none().0 })
273            .collect();
274        let n_vertices = data.len() as i32;
275        unsafe {
276            from_glib_full(ffi::cogl_primitive_new_p2t2c4(
277                context.to_glib_none().0,
278                mode.to_glib(),
279                n_vertices,
280                data.as_ptr(),
281            ))
282        }
283    }
284
285    /// Provides a convenient way to describe a primitive, such as a single
286    /// triangle strip or a triangle fan, that will internally allocate the
287    /// necessary `AttributeBuffer` storage, describe the position
288    /// attribute with a `Attribute` and upload your data.
289    ///
290    /// For example to draw a convex polygon you can do:
291    ///
292    /// ```text
293    /// CoglVertexP3 triangle[] =
294    /// {
295    ///   { 0,   300, 0 },
296    ///   { 150, 0,   0 },
297    ///   { 300, 300, 0 }
298    /// };
299    /// prim = cogl_primitive_new_p3 (COGL_VERTICES_MODE_TRIANGLE_FAN,
300    ///                               3, triangle);
301    /// cogl_primitive_draw (prim);
302    /// ```
303    ///
304    /// The value passed as `n_vertices` is initially used to determine how
305    /// much can be read from `data` but it will also be used to update the
306    /// `Primitive` `<structfield>`n_vertices`</structfield>` property as if
307    /// `Primitive::set_n_vertices` were called. This property defines
308    /// the number of vertices to read when drawing.
309    ///
310    /// `<note>`The primitive API doesn't support drawing with sliced
311    /// textures (since switching between slices implies changing state and
312    /// so that implies multiple primitives need to be submitted). You
313    /// should pass the `TextureFlags::NoSlicing` flag to all textures that
314    /// might be used while drawing with this API. If your hardware doesn't
315    /// support non-power of two textures (For example you are using GLES
316    /// 1.1) then you will need to make sure your assets are resized to a
317    /// power-of-two size (though they don't have to be square)`</note>`
318    /// ## `context`
319    /// A `Context`
320    /// ## `mode`
321    /// A `VerticesMode` defining how to draw the vertices
322    /// ## `n_vertices`
323    /// The number of vertices to read from `data` and also
324    ///  the number of vertices to read when later drawing.
325    /// ## `data`
326    /// An array of
327    ///  `VertexP3` vertices
328    ///
329    /// # Returns
330    ///
331    /// A newly allocated `Primitive`
332    /// with a reference of 1. This can be freed using `Object::unref`.
333    pub fn new_p3(context: &Context, mode: VerticesMode, data: &[&VertexP3]) -> Primitive {
334        let data: Vec<ffi::CoglVertexP3> = data
335            .iter()
336            .map(|e| unsafe { *e.to_glib_none().0 })
337            .collect();
338        let n_vertices = data.len() as i32;
339        unsafe {
340            from_glib_full(ffi::cogl_primitive_new_p3(
341                context.to_glib_none().0,
342                mode.to_glib(),
343                n_vertices,
344                data.as_ptr(),
345            ))
346        }
347    }
348
349    /// Provides a convenient way to describe a primitive, such as a single
350    /// triangle strip or a triangle fan, that will internally allocate the
351    /// necessary `AttributeBuffer` storage, describe the position
352    /// and color attributes with `Attribute`<!-- -->s and upload
353    /// your data.
354    ///
355    /// For example to draw a convex polygon with a linear gradient you
356    /// can do:
357    ///
358    /// ```text
359    /// CoglVertexP3C4 triangle[] =
360    /// {
361    ///   { 0,   300, 0,  0xff, 0x00, 0x00, 0xff },
362    ///   { 150, 0,   0,  0x00, 0xff, 0x00, 0xff },
363    ///   { 300, 300, 0,  0xff, 0x00, 0x00, 0xff }
364    /// };
365    /// prim = cogl_primitive_new_p3c4 (COGL_VERTICES_MODE_TRIANGLE_FAN,
366    ///                                 3, triangle);
367    /// cogl_primitive_draw (prim);
368    /// ```
369    ///
370    /// The value passed as `n_vertices` is initially used to determine how
371    /// much can be read from `data` but it will also be used to update the
372    /// `Primitive` `<structfield>`n_vertices`</structfield>` property as if
373    /// `Primitive::set_n_vertices` were called. This property defines
374    /// the number of vertices to read when drawing.
375    ///
376    /// `<note>`The primitive API doesn't support drawing with sliced
377    /// textures (since switching between slices implies changing state and
378    /// so that implies multiple primitives need to be submitted). You
379    /// should pass the `TextureFlags::NoSlicing` flag to all textures that
380    /// might be used while drawing with this API. If your hardware doesn't
381    /// support non-power of two textures (For example you are using GLES
382    /// 1.1) then you will need to make sure your assets are resized to a
383    /// power-of-two size (though they don't have to be square)`</note>`
384    /// ## `context`
385    /// A `Context`
386    /// ## `mode`
387    /// A `VerticesMode` defining how to draw the vertices
388    /// ## `n_vertices`
389    /// The number of vertices to read from `data` and also
390    ///  the number of vertices to read when later drawing.
391    /// ## `data`
392    /// An array
393    ///  of `VertexP3C4` vertices
394    ///
395    /// # Returns
396    ///
397    /// A newly allocated `Primitive`
398    /// with a reference of 1. This can be freed using `Object::unref`.
399    pub fn new_p3c4(context: &Context, mode: VerticesMode, data: &[&VertexP3C4]) -> Primitive {
400        let data: Vec<ffi::CoglVertexP3C4> = data
401            .iter()
402            .map(|e| unsafe { *e.to_glib_none().0 })
403            .collect();
404        let n_vertices = data.len() as i32;
405        unsafe {
406            from_glib_full(ffi::cogl_primitive_new_p3c4(
407                context.to_glib_none().0,
408                mode.to_glib(),
409                n_vertices,
410                data.as_ptr(),
411            ))
412        }
413    }
414
415    /// Provides a convenient way to describe a primitive, such as a single
416    /// triangle strip or a triangle fan, that will internally allocate the
417    /// necessary `AttributeBuffer` storage, describe the position and
418    /// texture coordinate attributes with `Attribute`<!-- -->s and
419    /// upload your data.
420    ///
421    /// For example to draw a convex polygon with texture mapping you can
422    /// do:
423    ///
424    /// ```text
425    /// CoglVertexP3T2 triangle[] =
426    /// {
427    ///   { 0,   300, 0,  0.0, 1.0},
428    ///   { 150, 0,   0,  0.5, 0.0},
429    ///   { 300, 300, 0,  1.0, 1.0}
430    /// };
431    /// prim = cogl_primitive_new_p3t2 (COGL_VERTICES_MODE_TRIANGLE_FAN,
432    ///                                 3, triangle);
433    /// cogl_primitive_draw (prim);
434    /// ```
435    ///
436    /// The value passed as `n_vertices` is initially used to determine how
437    /// much can be read from `data` but it will also be used to update the
438    /// `Primitive` `<structfield>`n_vertices`</structfield>` property as if
439    /// `Primitive::set_n_vertices` were called. This property defines
440    /// the number of vertices to read when drawing.
441    ///
442    /// `<note>`The primitive API doesn't support drawing with sliced
443    /// textures (since switching between slices implies changing state and
444    /// so that implies multiple primitives need to be submitted). You
445    /// should pass the `TextureFlags::NoSlicing` flag to all textures that
446    /// might be used while drawing with this API. If your hardware doesn't
447    /// support non-power of two textures (For example you are using GLES
448    /// 1.1) then you will need to make sure your assets are resized to a
449    /// power-of-two size (though they don't have to be square)`</note>`
450    /// ## `context`
451    /// A `Context`
452    /// ## `mode`
453    /// A `VerticesMode` defining how to draw the vertices
454    /// ## `n_vertices`
455    /// The number of vertices to read from `data` and also
456    ///  the number of vertices to read when later drawing.
457    /// ## `data`
458    /// An array
459    ///  of `VertexP3T2` vertices
460    ///
461    /// # Returns
462    ///
463    /// A newly allocated `Primitive`
464    /// with a reference of 1. This can be freed using `Object::unref`.
465    pub fn new_p3t2(context: &Context, mode: VerticesMode, data: &[&VertexP3T2]) -> Primitive {
466        let data: Vec<ffi::CoglVertexP3T2> = data
467            .iter()
468            .map(|e| unsafe { *e.to_glib_none().0 })
469            .collect();
470        let n_vertices = data.len() as i32;
471        unsafe {
472            from_glib_full(ffi::cogl_primitive_new_p3t2(
473                context.to_glib_none().0,
474                mode.to_glib(),
475                n_vertices,
476                data.as_ptr(),
477            ))
478        }
479    }
480
481    /// Provides a convenient way to describe a primitive, such as a single
482    /// triangle strip or a triangle fan, that will internally allocate the
483    /// necessary `AttributeBuffer` storage, describe the position, texture
484    /// coordinate and color attributes with `Attribute`<!-- -->s and
485    /// upload your data.
486    ///
487    /// For example to draw a convex polygon with texture mapping and a
488    /// linear gradient you can do:
489    ///
490    /// ```text
491    /// CoglVertexP3T2C4 triangle[] =
492    /// {
493    ///   { 0,   300, 0,  0.0, 1.0,  0xff, 0x00, 0x00, 0xff},
494    ///   { 150, 0,   0,  0.5, 0.0,  0x00, 0xff, 0x00, 0xff},
495    ///   { 300, 300, 0,  1.0, 1.0,  0xff, 0x00, 0x00, 0xff}
496    /// };
497    /// prim = cogl_primitive_new_p3t2c4 (COGL_VERTICES_MODE_TRIANGLE_FAN,
498    ///                                   3, triangle);
499    /// cogl_primitive_draw (prim);
500    /// ```
501    ///
502    /// The value passed as `n_vertices` is initially used to determine how
503    /// much can be read from `data` but it will also be used to update the
504    /// `Primitive` `<structfield>`n_vertices`</structfield>` property as if
505    /// `Primitive::set_n_vertices` were called. This property defines
506    /// the number of vertices to read when drawing.
507    ///
508    /// `<note>`The primitive API doesn't support drawing with sliced
509    /// textures (since switching between slices implies changing state and
510    /// so that implies multiple primitives need to be submitted). You
511    /// should pass the `TextureFlags::NoSlicing` flag to all textures that
512    /// might be used while drawing with this API. If your hardware doesn't
513    /// support non-power of two textures (For example you are using GLES
514    /// 1.1) then you will need to make sure your assets are resized to a
515    /// power-of-two size (though they don't have to be square)`</note>`
516    /// ## `context`
517    /// A `Context`
518    /// ## `mode`
519    /// A `VerticesMode` defining how to draw the vertices
520    /// ## `n_vertices`
521    /// The number of vertices to read from `data` and also
522    ///  the number of vertices to read when later drawing.
523    /// ## `data`
524    /// An
525    ///  array of `VertexP3T2C4` vertices
526    ///
527    /// # Returns
528    ///
529    /// A newly allocated `Primitive`
530    /// with a reference of 1. This can be freed using `Object::unref`.
531    pub fn new_p3t2c4(context: &Context, mode: VerticesMode, data: &[&VertexP3T2C4]) -> Primitive {
532        let data: Vec<ffi::CoglVertexP3T2C4> = data
533            .iter()
534            .map(|e| unsafe { *e.to_glib_none().0 })
535            .collect();
536        let n_vertices = data.len() as i32;
537        unsafe {
538            from_glib_full(ffi::cogl_primitive_new_p3t2c4(
539                context.to_glib_none().0,
540                mode.to_glib(),
541                n_vertices,
542                data.as_ptr(),
543            ))
544        }
545    }
546
547    // TODO:
548    // pub fn with_attributes(
549    //     mode: VerticesMode,
550    //     n_vertices: i32,
551    //     attributes: &[&Attribute],
552    //     n_attributes: i32,
553    // ) -> Primitive {
554    //
555    //     unsafe {
556    //         from_glib_full(ffi::cogl_primitive_new_with_attributes(
557    //             mode.to_glib(),
558    //             n_vertices,
559    //             attributes.to_glib_none().0,
560    //             n_attributes,
561    //         ))
562    //     }
563    // }
564
565    /// Makes a copy of an existing `Primitive`. Note that the primitive
566    /// is a shallow copy which means it will use the same attributes and
567    /// attribute buffers as the original primitive.
568    ///
569    /// # Returns
570    ///
571    /// the new primitive
572    pub fn copy(&self) -> Option<Primitive> {
573        unsafe { from_glib_full(ffi::cogl_primitive_copy(self.to_glib_none().0)) }
574    }
575
576    /// Draws the given `self` geometry to the specified destination
577    /// `framebuffer` using the graphics processing state described by `pipeline`.
578    ///
579    /// This drawing api doesn't support high-level meta texture types such
580    /// as `Texture2DSliced` so it is the user's responsibility to
581    /// ensure that only low-level textures that can be directly sampled by
582    /// a GPU such as `Texture2D`, `TextureRectangle` or `Texture3D`
583    /// are associated with layers of the given `pipeline`.
584    /// ## `framebuffer`
585    /// A destination `Framebuffer`
586    /// ## `pipeline`
587    /// A `Pipeline` state object
588    pub fn draw<P: IsA<Framebuffer>>(&self, framebuffer: &P, pipeline: &Pipeline) {
589        unsafe {
590            ffi::cogl_primitive_draw(
591                self.to_glib_none().0,
592                framebuffer.as_ref().to_glib_none().0,
593                pipeline.to_glib_none().0,
594            );
595        }
596    }
597
598    /// Iterates all the attributes of the given `Primitive`.
599    /// ## `callback`
600    /// A `CoglPrimitiveAttributeCallback` to be
601    ///  called for each attribute
602    /// ## `user_data`
603    /// Private data that will be passed to the
604    ///  callback
605    pub fn foreach_attribute<P: FnMut(&Primitive, &Attribute) -> i32>(&self, callback: P) {
606        //TODO: should replace i32 to bool in callback
607        let callback_data: P = callback;
608        unsafe extern "C" fn callback_func<P: FnMut(&Primitive, &Attribute) -> i32>(
609            primitive: *mut ffi::CoglPrimitive,
610            attribute: *mut ffi::CoglAttribute,
611            user_data: glib_sys::gpointer,
612        ) -> ffi::CoglBool {
613            let primitive = from_glib_borrow(primitive);
614            let attribute = from_glib_borrow(attribute);
615            let callback: *mut P = user_data as *const _ as usize as *mut P;
616            (*callback)(&primitive, &attribute)
617        }
618        let callback = Some(callback_func::<P> as _);
619        let super_callback0: &P = &callback_data;
620        unsafe {
621            ffi::cogl_primitive_foreach_attribute(
622                self.to_glib_none().0,
623                callback,
624                super_callback0 as *const _ as usize as *mut _,
625            );
626        }
627    }
628
629    pub fn get_first_vertex(&self) -> i32 {
630        unsafe { ffi::cogl_primitive_get_first_vertex(self.to_glib_none().0) }
631    }
632
633    ///
634    /// # Returns
635    ///
636    /// the indices that were set with
637    /// `Primitive::set_indices` or `None` if no indices were set.
638    pub fn get_indices(&self) -> Option<Indices> {
639        unsafe { from_glib_none(ffi::cogl_primitive_get_indices(self.to_glib_none().0)) }
640    }
641
642    pub fn get_mode(&self) -> VerticesMode {
643        unsafe { from_glib(ffi::cogl_primitive_get_mode(self.to_glib_none().0)) }
644    }
645
646    /// Queries the number of vertices to read when drawing the given
647    /// `self`. Usually this value is implicitly set when associating
648    /// vertex data or indices with a `Primitive`.
649    ///
650    /// If `Primitive::set_indices` has been used to associate a
651    /// sequence of `Indices` with the given `self` then the
652    /// number of vertices to read can also be phrased as the number
653    /// of indices to read.
654    ///
655    /// `<note>`To be clear; it doesn't refer to the number of vertices - in
656    /// terms of data - associated with the primitive it's just the number
657    /// of vertices to read and draw.`</note>`
658    ///
659    /// # Returns
660    ///
661    /// The number of vertices to read when drawing.
662    pub fn get_n_vertices(&self) -> i32 {
663        unsafe { ffi::cogl_primitive_get_n_vertices(self.to_glib_none().0) }
664    }
665
666    // TODO:
667    // /// Replaces all the attributes of the given `Primitive` object.
668    // /// ## `attributes`
669    // /// an array of `Attribute` pointers
670    // /// ## `n_attributes`
671    // /// the number of elements in `attributes`
672    // pub fn set_attributes(&self, attributes: &[&Attribute], n_attributes: i32) {
673    //     unsafe {
674    //         ffi::cogl_primitive_set_attributes(
675    //             self.to_glib_none().0,
676    //             attributes.to_glib_none().0,
677    //             n_attributes,
678    //         );
679    //     }
680    // }
681
682    pub fn set_first_vertex(&self, first_vertex: i32) {
683        unsafe {
684            ffi::cogl_primitive_set_first_vertex(self.to_glib_none().0, first_vertex);
685        }
686    }
687
688    /// Associates a sequence of `Indices` with the given `self`.
689    ///
690    /// `Indices` provide a way to virtualize your real vertex data by
691    /// providing a sequence of indices that index into your real vertex
692    /// data. The GPU will walk though the index values to indirectly
693    /// lookup the data for each vertex instead of sequentially walking
694    /// through the data directly. This lets you save memory by indexing
695    /// shared data multiple times instead of duplicating the data.
696    ///
697    /// The value passed as `n_indices` will simply update the
698    /// `Primitive` `<structfield>`n_vertices`</structfield>` property as if
699    /// `Primitive::set_n_vertices` were called. This property defines
700    /// the number of vertices to draw or, put another way, how many
701    /// indices should be read from `indices` when drawing.
702    ///
703    /// `<note>`The `Primitive` `<structfield>`first_vertex`</structfield>` property
704    /// also affects drawing with indices by defining the first entry of the
705    /// indices to start drawing from.`</note>`
706    /// ## `indices`
707    /// A `Indices` array
708    /// ## `n_indices`
709    /// The number of indices to reference when drawing
710    pub fn set_indices(&self, indices: &Indices, n_indices: i32) {
711        unsafe {
712            ffi::cogl_primitive_set_indices(
713                self.to_glib_none().0,
714                indices.to_glib_none().0,
715                n_indices,
716            );
717        }
718    }
719
720    pub fn set_mode(&self, mode: VerticesMode) {
721        unsafe {
722            ffi::cogl_primitive_set_mode(self.to_glib_none().0, mode.to_glib());
723        }
724    }
725
726    /// Specifies how many vertices should be read when drawing the given
727    /// `self`.
728    ///
729    /// Usually this value is set implicitly when associating vertex data
730    /// or indices with a `Primitive`.
731    ///
732    /// `<note>`To be clear; it doesn't refer to the number of vertices - in
733    /// terms of data - associated with the primitive it's just the number
734    /// of vertices to read and draw.`</note>`
735    /// ## `n_vertices`
736    /// The number of vertices to read when drawing.
737    pub fn set_n_vertices(&self, n_vertices: i32) {
738        unsafe {
739            ffi::cogl_primitive_set_n_vertices(self.to_glib_none().0, n_vertices);
740        }
741    }
742
743    //pub fn texture_set_auto_mipmap(primitive_texture: /*Unknown conversion*//*Unimplemented*/PrimitiveTexture, value: Bool) {
744    //    unsafe { TODO: call cogl_sys:cogl_primitive_texture_set_auto_mipmap() }
745    //}
746}
747
748impl fmt::Display for Primitive {
749    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
750        write!(f, "Primitive")
751    }
752}