Add Z-buffer, fixes issue with pyramidal studs
[render.git] / obj.h
1 /* Copyright (c) 2005 Robert Kooima                                           */
2 /*                                                                            */
3 /* Permission is hereby granted, free of charge, to any person obtaining a    */
4 /* copy of this software and associated documentation files (the "Software"), */
5 /* to deal in the Software without restriction, including without limitation  */
6 /* the rights to use, copy, modify, merge, publish, distribute, sublicense,   */
7 /* and/or sell copies of the Software, and to permit persons to whom the      */
8 /* Software is furnished to do so, subject to the following conditions:       */
9 /*                                                                            */
10 /* The above copyright notice and this permission notice shall be included in */
11 /* all copies or substantial portions of the Software.                        */
12 /*                                                                            */
13 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
14 /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   */
15 /* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    */
16 /* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
17 /* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING    */
18 /* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER        */
19 /* DEALINGS IN THE SOFTWARE.                                                  */
20
21 #ifndef UTIL3D_OBJ_H
22 #define UTIL3D_OBJ_H
23
24 /*============================================================================*/
25
26 #define OBJ_INDEX_IS_INT
27
28 #ifdef OBJ_INDEX_IS_INT
29 typedef unsigned int obj_index_t;
30 #else
31 typedef unsigned short obj_index_t;
32 #endif
33
34 /*============================================================================*/
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 /*============================================================================*/
41
42 enum {
43         OBJ_KD,
44         OBJ_KA,
45         OBJ_KE,
46         OBJ_KS,
47         OBJ_NS,
48         OBJ_KN,
49         OBJ_PROP_COUNT
50 };
51
52 struct obj_prop
53 {
54     char        *str;
55     int          opt;
56 #ifdef CONF_NO_GL
57     struct array *map;
58 #else
59     unsigned int map;
60 #endif
61
62     float c[4];
63     float o[3];
64     float s[3];
65 };
66
67 struct obj_mtrl
68 {
69     char *name;
70
71     struct obj_prop kv[OBJ_PROP_COUNT];
72 };
73
74 struct obj_vert
75 {
76     float u[3];
77     float n[3];
78     float t[2];
79     float v[3];
80 };
81
82 struct obj_poly
83 {
84     obj_index_t vi[3];
85 };
86
87 struct obj_line
88 {
89     obj_index_t vi[2];
90 };
91
92 struct obj_surf
93 {
94     int mi;
95
96     int pc;
97     int pm;
98     int lc;
99     int lm;
100
101     unsigned int pibo;
102     unsigned int libo;
103
104     struct obj_poly *pv;
105     struct obj_line *lv;
106 };
107
108 struct obj
109 {
110     unsigned int vao;
111     unsigned int vbo;
112
113     int mc;
114     int mm;
115     int vc;
116     int vm;
117     int sc;
118     int sm;
119
120     int uloc;
121     int nloc;
122     int tloc;
123     int vloc;
124
125     int cloc[OBJ_PROP_COUNT];
126     int oloc[OBJ_PROP_COUNT];
127     int Mloc[OBJ_PROP_COUNT];
128
129     struct obj_mtrl *mv;
130     struct obj_vert *vv;
131     struct obj_surf *sv;
132 };
133
134 /*----------------------------------------------------------------------------*/
135
136 struct obj *obj_create(const char *);
137 void obj_render(struct obj *);
138 void obj_delete(struct obj *);
139
140 /*----------------------------------------------------------------------------*/
141
142 int  obj_add_mtrl(struct obj *);
143 int  obj_add_vert(struct obj *);
144 int  obj_add_poly(struct obj *, int);
145 int  obj_add_line(struct obj *, int);
146 int  obj_add_surf(struct obj *);
147
148 int  obj_num_mtrl(const struct obj *);
149 int  obj_num_vert(const struct obj *);
150 int  obj_num_poly(const struct obj *, int);
151 int  obj_num_line(const struct obj *, int);
152 int  obj_num_surf(const struct obj *);
153
154 void obj_del_mtrl(struct obj *, int);
155 void obj_del_vert(struct obj *, int);
156 void obj_del_poly(struct obj *, int, int);
157 void obj_del_line(struct obj *, int, int);
158 void obj_del_surf(struct obj *, int);
159
160 /*----------------------------------------------------------------------------*/
161
162 void obj_set_mtrl_name(struct obj *, int,      const char *);
163 void obj_set_mtrl_map (struct obj *, int, int, const char *);
164 void obj_set_mtrl_opt (struct obj *, int, int, unsigned int);
165 void obj_set_mtrl_c   (struct obj *, int, int, const float *);
166 void obj_set_mtrl_o   (struct obj *, int, int, const float *);
167 void obj_set_mtrl_s   (struct obj *, int, int, const float *);
168
169 void obj_set_vert_v(struct obj *, int, const float *);
170 void obj_set_vert_t(struct obj *, int, const float *);
171 void obj_set_vert_n(struct obj *, int, const float *);
172 void obj_set_vert_u(struct obj *, int, const float *);
173
174 void obj_set_poly(struct obj *, int, int, const int *);
175 void obj_set_line(struct obj *, int, int, const int *);
176 void obj_set_surf(struct obj *, int, int);
177
178 void obj_set_vert_loc(struct obj *, int, int, int, int);
179 void obj_set_prop_loc(struct obj *, int, int, int, int);
180
181 /*----------------------------------------------------------------------------*/
182
183 const char  *obj_get_mtrl_name(const struct obj *, int);
184 #ifdef CONF_NO_GL
185 struct array *obj_get_mtrl_map (const struct obj *, int, int);
186 #else
187 unsigned int obj_get_mtrl_map (const struct obj *, int, int);
188 #endif
189 unsigned int obj_get_mtrl_opt (const struct obj *, int, int);
190 void         obj_get_mtrl_c   (const struct obj *, int, int, float *);
191 void         obj_get_mtrl_o   (const struct obj *, int, int, float *);
192 void         obj_get_mtrl_s   (const struct obj *, int, int, float *);
193
194 void obj_get_vert_v(const struct obj *, int, float *);
195 void obj_get_vert_t(const struct obj *, int, float *);
196 void obj_get_vert_n(const struct obj *, int, float *);
197
198 void obj_get_poly(const struct obj *, int, int, int *);
199 void obj_get_line(const struct obj *, int, int, int *);
200 int  obj_get_surf(const struct obj *, int);
201
202 /*----------------------------------------------------------------------------*/
203
204 void  obj_render_mtrl(const struct obj *, int);
205 void  obj_render_surf(const struct obj *, int);
206 void  obj_render_file(const struct obj *);
207
208 /*----------------------------------------------------------------------------*/
209
210 #ifdef CONF_NO_GL
211 struct array *obj_load_image(const char *);
212 #else
213 unsigned int obj_load_image(const char *);
214 #endif
215
216 void  obj_mini(struct obj *);
217 void  obj_norm(struct obj *);
218 void  obj_proc(struct obj *);
219 void  obj_uniq(struct obj *, float, float, int);
220 void  obj_sort(struct obj *, int);
221 float obj_acmr(struct obj *, int);
222
223 void  obj_bound(const struct obj *, float *);
224 void  obj_write(const struct obj *, const char *, const char *, int);
225
226 /*======================================================================+=====*/
227
228 #ifdef __cplusplus
229 }
230 #endif
231 #endif