reprap: c3 update
[simavr] / examples / board_reprap / src / c3 / c3geometry.h
1 /*
2         c3geometry.h
3
4         Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
5
6         This file is part of simavr.
7
8         simavr is free software: you can redistribute it and/or modify
9         it under the terms of the GNU General Public License as published by
10         the Free Software Foundation, either version 3 of the License, or
11         (at your option) any later version.
12
13         simavr is distributed in the hope that it will be useful,
14         but WITHOUT ANY WARRANTY; without even the implied warranty of
15         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16         GNU General Public License for more details.
17
18         You should have received a copy of the GNU General Public License
19         along with simavr.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22
23 #ifndef __C3GEOMETRY_H___
24 #define __C3GEOMETRY_H___
25
26 #include "c3/c3algebra.h"
27 #include "c_utils.h"
28
29 typedef c3vec3 c3vertex;
30 typedef c3vec4 c3colorf;
31 typedef c3vec2 c3tex;
32
33 struct c3object_t;
34
35 DECLARE_C_ARRAY(c3vertex, c3vertex_array, 16);
36 DECLARE_C_ARRAY(c3tex, c3tex_array, 16);
37 DECLARE_C_ARRAY(c3colorf, c3colorf_array, 16);
38
39 typedef struct c3material_t {
40         c3colorf        color;
41         uint32_t        texture;
42 } c3material_t;
43
44 typedef struct c3bbox_t {
45         c3vec3  min, max;
46 } c3bbox_t;
47
48 #define C3_RAW_TYPE     (0)
49
50 typedef union {
51         struct  { uint32_t type : 16, subtype : 16; };
52         uint32_t value;
53 } c3geometry_type_t;
54
55 typedef struct c3geometry_t {
56         c3geometry_type_t       type;   // GL_LINES etc
57         int                                     dirty : 1,
58                                                 texture : 1,    // has a valid material.texture
59                                                 custom : 1;             // has a custom driver
60         str_p                           name;   // optional
61         c3material_t            mat;
62         struct c3object_t * object;
63         const struct c3driver_geometry_t ** driver;
64
65         c3vertex_array_t        vertice;
66         c3tex_array_t           textures;
67         c3colorf_array_t        colorf;
68
69         // projected version of the vertice
70         c3vertex_array_t        projected;
71         c3bbox_t                        bbox;
72 } c3geometry_t, *c3geometry_p;
73
74 DECLARE_C_ARRAY(c3geometry_p, c3geometry_array, 4);
75
76 c3geometry_p
77 c3geometry_new(
78                 c3geometry_type_t type,
79                 struct c3object_t * o /* = NULL */);
80 c3geometry_p
81 c3geometry_init(
82                 c3geometry_p g,
83                 c3geometry_type_t type,
84                 struct c3object_t * o /* = NULL */);
85 void
86 c3geometry_dispose(
87                 c3geometry_p g);
88
89 void
90 c3geometry_prepare(
91                 c3geometry_p g );
92 void
93 c3geometry_draw(
94                 c3geometry_p g );
95
96 //! allocate (if not there) and return a custom driver for this geometry
97 struct c3driver_geometry_t *
98 c3geometry_get_custom(
99                 c3geometry_p g );
100
101 IMPLEMENT_C_ARRAY(c3geometry_array);
102 IMPLEMENT_C_ARRAY(c3vertex_array);
103 IMPLEMENT_C_ARRAY(c3tex_array);
104 IMPLEMENT_C_ARRAY(c3colorf_array);
105
106 static inline c3geometry_type_t
107 c3geometry_type(int type, int subtype)
108 {
109         c3geometry_type_t r = { .type = type, . subtype = subtype };
110         return r;
111 }
112
113 #endif /* __C3GEOMETRY_H___ */