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, texture : 1;
58         str_p                           name;   // optional
59         c3material_t            mat;
60         struct c3object_t * object;
61         const struct c3driver_geometry_t ** driver;
62         c3vertex_array_t        vertice;
63         c3tex_array_t           textures;
64         c3colorf_array_t        colorf;
65
66         // projected version of the vertice
67         c3vertex_array_t        projected;
68         c3bbox_t                        bbox;
69
70         /*
71          * optional, geometry dependant custom draw method
72          * return nonzero will orevent the default drawing code
73          * from being called (c3context one)
74          */
75         int     (*draw)(struct c3geometry_t *);
76 } c3geometry_t, *c3geometry_p;
77
78 DECLARE_C_ARRAY(c3geometry_p, c3geometry_array, 4);
79
80 c3geometry_p
81 c3geometry_new(
82                 c3geometry_type_t type,
83                 struct c3object_t * o /* = NULL */);
84 c3geometry_p
85 c3geometry_init(
86                 c3geometry_p g,
87                 c3geometry_type_t type,
88                 struct c3object_t * o /* = NULL */);
89 void
90 c3geometry_dispose(
91                 c3geometry_p g);
92
93 void
94 c3geometry_prepare(
95                 c3geometry_p g );
96
97 IMPLEMENT_C_ARRAY(c3geometry_array);
98 IMPLEMENT_C_ARRAY(c3vertex_array);
99 IMPLEMENT_C_ARRAY(c3tex_array);
100 IMPLEMENT_C_ARRAY(c3colorf_array);
101
102 static inline c3geometry_type_t
103 c3geometry_type(int type, int subtype)
104 {
105         c3geometry_type_t r = { .type = type, . subtype = subtype };
106         return r;
107 }
108
109 #endif /* __C3GEOMETRY_H___ */