clang: Fixes of warning and nasty bugs
[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 enum {
49         C3_RAW_TYPE = 0,
50         C3_TRIANGLE_TYPE,
51         C3_TEXTURE_TYPE,
52 };
53
54 typedef union {
55         struct  { uint32_t type : 16, subtype : 16; };
56         uint32_t value;
57 } c3geometry_type_t;
58
59 typedef struct c3geometry_t {
60         c3geometry_type_t       type;   // GL_LINES etc
61         int                                     dirty : 1,
62                                                 texture : 1,    // has a valid material.texture
63                                                 custom : 1;             // has a custom driver
64         str_p                           name;   // optional
65         c3material_t            mat;
66         struct c3object_t * object;
67         const struct c3driver_geometry_t ** driver;
68
69         c3vertex_array_t        vertice;
70         c3tex_array_t           textures;
71         c3colorf_array_t        colorf;
72         c3vertex_array_t        normals;
73
74         // projected version of the vertice
75         c3vertex_array_t        projected;
76         c3bbox_t                        bbox;
77 } c3geometry_t, *c3geometry_p;
78
79 DECLARE_C_ARRAY(c3geometry_p, c3geometry_array, 4);
80
81 c3geometry_p
82 c3geometry_new(
83                 c3geometry_type_t type,
84                 struct c3object_t * o /* = NULL */);
85 c3geometry_p
86 c3geometry_init(
87                 c3geometry_p g,
88                 c3geometry_type_t type,
89                 struct c3object_t * o /* = NULL */);
90 void
91 c3geometry_dispose(
92                 c3geometry_p g);
93
94 void
95 c3geometry_prepare(
96                 c3geometry_p g );
97 void
98 c3geometry_draw(
99                 c3geometry_p g );
100
101 //! allocate (if not there) and return a custom driver for this geometry
102 struct c3driver_geometry_t *
103 c3geometry_get_custom(
104                 c3geometry_p g );
105
106 IMPLEMENT_C_ARRAY(c3geometry_array);
107 IMPLEMENT_C_ARRAY(c3vertex_array);
108 IMPLEMENT_C_ARRAY(c3tex_array);
109 IMPLEMENT_C_ARRAY(c3colorf_array);
110
111 static inline c3geometry_type_t
112 c3geometry_type(int type, int subtype)
113 {
114         c3geometry_type_t r = { .type = type, .subtype = subtype };
115         return r;
116 }
117
118 #endif /* __C3GEOMETRY_H___ */