aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/mimesh/libg3d-0.0.8/include/g3d/types.h
blob: a2403a00707096cf7e4ba6204ed13b2f86454988 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
/* $Id$ */

/*
    libg3d - 3D object loading library

    Copyright (C) 2005-2009  Markus Dahms <mad@automagically.de>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifndef __G3D_TYPES_H__
#define __G3D_TYPES_H__

#include <GL/gl.h>

#include <glib.h>

#ifdef USE_LIBMAGIC
#include <magic.h>
#endif

#ifdef EAPI
# undef EAPI
#endif /* ifdef EAPI */

#ifdef _WIN32
# ifdef EFL_EET_BUILD
#  ifdef DLL_EXPORT
#   define EAPI __declspec(dllexport)
#  else /* ifdef DLL_EXPORT */
#   define EAPI
#  endif /* ! DLL_EXPORT */
# else /* ifdef EFL_EET_BUILD */
#  define EAPI __declspec(dllimport)
# endif /* ! EFL_EET_BUILD */
#else /* ifdef _WIN32 */
# ifdef __GNUC__
#  if __GNUC__ >= 4
#   define EAPI __attribute__ ((visibility("default")))
#  else /* if __GNUC__ >= 4 */
#   define EAPI
#  endif /* if __GNUC__ >= 4 */
# else /* ifdef __GNUC__ */
#  define EAPI
# endif /* ifdef __GNUC__ */
#endif /* ! _WIN32 */


#ifdef __cplusplus
extern "C" {
#endif /* ifdef __cplusplus */

/**
 * SECTION:types
 * @short_description: some defined types for libg3d
 * @include: g3d/g3d.h
 */
/* goffset is defined since glib 2.14 */
#ifndef G_MAXOFFSET
typedef gint64 goffset;
#endif

/* supposed to trick gtk-doc not to ignore these functions - not really... */
#define _G3D_STATIC_INLINE static inline

/*****************************************************************************
 * basic types
 *****************************************************************************/

/**
 * SECTION:types
 * @short_description: Basic types
 * @include: g3d/types.h
 *
 * Some basic type abstractions used in libg3d.
 */

/**
 * G3DFloat:
 *
 * Default floating point type. If used consistently in the library (not the
 * case at the moment) this type can be switched between single and double
 * precision at compile-time.
 */
/**
 * G3D_FLOAT_IS_DOUBLE
 *
 * A flag indicating type of #G3DFloat. It is TRUE if #G3DFloat is double and
 * FALSE if #G3DFloat is single precision.
 */
#if 1
#define G3D_FLOAT_IS_DOUBLE TRUE
#define G3D_SCANF_FLOAT "%lf"
typedef gdouble G3DFloat;
#else
#define G3D_FLOAT_IS_DOUBLE FALSE
#define G3D_SCANF_FLOAT "%f"
typedef gfloat G3DFloat;
#endif
/**
 * G3DSingle:
 *
 * Single-precision floating point number.
 */
typedef gfloat G3DSingle;
/**
 * G3DDouble:
 *
 * Double-precision floating point number.
 */
typedef gdouble G3DDouble;
/**
 * G3DVector
 *
 * Vector element type.
 */
typedef G3DFloat G3DVector;
/**
 * G3DMatrix:
 *
 * Matrix element type.
 */
typedef G3DFloat G3DMatrix;
/**
 * G3DQuat
 *
 * Quaternion element type.
 */
typedef G3DFloat G3DQuat;

/*****************************************************************************
 * G3DImage
 *****************************************************************************/

/**
 * G3D_FLAG_IMG_GREYSCALE:
 *
 * The image just uses the red channel for grey value
 */
#define G3D_FLAG_IMG_GREYSCALE       (1L << 1)

/**
 * G3DTexEnv:
 * @G3D_TEXENV_UNSPECIFIED: unspecified, application decides
 * @G3D_TEXENV_BLEND: use blending
 * @G3D_TEXENV_DECAL: use as decal
 * @G3D_TEXENV_MODULATE: use modulate
 * @G3D_TEXENV_REPLACE: replace color
 *
 * Specify how the texture should interact with other material properties.
 */
typedef enum {
	G3D_TEXENV_UNSPECIFIED = 0,
	G3D_TEXENV_BLEND,
	G3D_TEXENV_DECAL,
	G3D_TEXENV_MODULATE,
	G3D_TEXENV_REPLACE
} G3DTexEnv;

/**
 * G3DImage:
 * @name: name of image
 * @width: width of image in pixels
 * @height: height of image in pixels
 * @depth: depth of image in bits
 * @flags: flags
 * @pixeldata: the binary image data
 * @tex_id: the OpenGL texture id, should be unique model-wide
 * @tex_env: texture environment flags
 * @tex_scale_u: factor scaling texture width, should be 1.0 for most cases
 * @tex_scale_v: factor scaling texture height, should be 1.0 for most cases
 *
 * Object containing a two-dimensional pixel image.
 */
typedef struct {
	gchar *name;
	guint32 width;
	guint32 height;
	guint8 depth;
	guint32 flags;
	guint8 *pixeldata;

	guint32 tex_id;
	G3DTexEnv tex_env;
	G3DFloat tex_scale_u;
	G3DFloat tex_scale_v;
} G3DImage;

/*****************************************************************************
 * G3DMaterial
 *****************************************************************************/

/**
 * G3D_FLAG_MAT_TWOSIDE:
 *
 * Faces using this material should be rendered two-sided as the direction
 * is unknown.
 */
#define G3D_FLAG_MAT_TWOSIDE    (1L << 0)

/**
 * G3DMaterial:
 * @name: name of material
 * @r: red component of color
 * @g: green component of color
 * @b: blue component of color
 * @a: alpha component of color
 * @shininess: shiny color
 * @specular: specular color
 * @flags: flags
 * @tex_image: texture image (optional, may be NULL)
 *
 * A material object.
 */

typedef struct {
	gchar *name;
	G3DFloat r, g, b, a;
	GLfloat shininess;
	GLfloat specular[4];
	guint32 flags;

	G3DImage *tex_image;
} G3DMaterial;

/*****************************************************************************
 * G3DFace
 *****************************************************************************/

/**
 * G3D_FLAG_FAC_NORMALS:
 *
 * The face has custom normals.
 */
#define G3D_FLAG_FAC_NORMALS    (1L << 0)
/**
 * G3D_FLAG_FAC_TEXMAP:
 *
 * The face has a texture map and texture coordinates.
 */
#define G3D_FLAG_FAC_TEXMAP     (1L << 1)

/**
 * G3DFace:
 * @vertex_count: number of vertices
 * @vertex_indices: indices of vertices in #G3DObject
 * @material: material to use for surface
 * @flags: flags
 * @normals: optional normal array (one vector - 3 #G3DVector values - for each
 *   vertex)
 * @tex_image: optional texture image
 * @tex_vertex_count: number of texture vertices, should be 0 or match
 *   vertex_count
 * @tex_vertex_data: array of texture vertices
 *
 * An object representing a surface.
 */
typedef struct {
	guint32 vertex_count;
	guint32 *vertex_indices;

	G3DMaterial *material;

	guint32 flags;

	G3DVector *normals;

	G3DImage *tex_image;
	guint32 tex_vertex_count;
	G3DVector *tex_vertex_data;
} G3DFace;

/*****************************************************************************
 * G3DTransformation
 *****************************************************************************/

/**
 * G3DTransformation:
 * @matrix: the transformation matrix
 * @flags: flags
 *
 * A three-dimensional matrix transformation object.
 */
typedef struct {
	G3DMatrix matrix[16];
	guint32 flags;
} G3DTransformation;


/*****************************************************************************
 * G3DObject
 *****************************************************************************/

/**
 * G3DObject:
 * @name: name of object
 * @materials: list of materials
 * @faces: list of faces
 * @objects: list of sub-objects
 * @transformation: optional transformation
 * @hide: flag to disable object rendering
 * @vertex_count: number of vertices
 * @vertex_data: vertex vector data
 *
 * A three-dimensional object.
 */
typedef struct {
	gchar *name;

	GSList *materials;
	GSList *faces;
	GSList *objects;

	/* transformation, may be NULL */
	G3DTransformation *transformation;

	/* don't render this object */
	gboolean hide;

	/* vertices */
	guint32 vertex_count;
	G3DVector *vertex_data;

	/*< private >*/
	/* FIXME: texture stuff: temporary storage, should be in G3DFace items */
	guint32 tex_vertex_count;
	G3DVector *tex_vertex_data;
	G3DImage *tex_image;

	/*< private >*/
	/* some fields to speed up rendering, should not be used by plugins */
	/* FIXME: remove from API (replace with user_data pointer?) */
	G3DVector *_normals;
	G3DMaterial **_materials;
	guint32  _num_faces;
	guint32 *_indices;
	guint32 *_flags;
	guint32 *_tex_images;
	G3DVector *_tex_coords;
} G3DObject;

/*****************************************************************************
 * G3DContext
 *****************************************************************************/

/**
 * G3DSetBgColorFunc:
 * @r: red component
 * @g: green component
 * @b: blue component
 * @a: alpha component
 * @user_data: opaque data as given to g3d_context_set_set_bgcolor_func()
 *
 * Background color setting callback.
 *
 * Returns: TRUE on success, FALSE else.
 */
typedef gboolean (* G3DSetBgColorFunc)(G3DFloat r, G3DFloat g, G3DFloat b,
	G3DFloat a,	gpointer user_data);

/**
 * G3DUpdateInterfaceFunc:
 * @user_data: opaque data as given to g3d_context_set_update_interface_func()
 *
 * Interface updating callback.
 *
 * Returns: TRUE on success, FALSE else.
 */
typedef gboolean (* G3DUpdateInterfaceFunc)(gpointer user_data);

/**
 * G3DUpdateProgressBarFunc:
 * @percentage: progress of plugin operation
 * @show: #TRUE if the progress bar should be visible, #FALSE else
 * @user_data: opaque data as given to
 * g3d_context_set_update_progress_bar_func()
 *
 * Progress updating callback.
 *
 * Returns: TRUE on success, FALSE else.
 */
typedef gboolean (* G3DUpdateProgressBarFunc)(G3DFloat percentage,
	gboolean show, gpointer user_data);

/*< private >*/
#ifdef USE_LIBMAGIC
#define MAGIC_PTR_TYPE magic_t
#else
#define MAGIC_PTR_TYPE void *
#endif
/*< public >*/

/**
 * G3DContext:
 *
 * Internal stuff for libg3d.
 */
typedef struct {
	/*< private >*/
	GSList *plugins;
	MAGIC_PTR_TYPE magic_cookie;

	GHashTable *exts_import;
	GHashTable *exts_image;

	G3DSetBgColorFunc set_bgcolor_func;
	gpointer set_bgcolor_data;
	G3DUpdateInterfaceFunc update_interface_func;
	gpointer update_interface_data;
	G3DUpdateProgressBarFunc update_progress_bar_func;
	gpointer update_progress_bar_data;

	GHashTable *modelCache;
} G3DContext;

/*****************************************************************************
 * G3DPlugin: real definition in g3d/plugins.h
 *****************************************************************************/

typedef struct _G3DPlugin G3DPlugin;

/*****************************************************************************
 * G3DStream
 *****************************************************************************/

/* declared in stream.h */
typedef struct _G3DStream G3DStream;

/*****************************************************************************
 * G3DModel
 *****************************************************************************/

/**
 * G3DModel:
 * @filename: file name or URI of loaded model, may be set by application
 * @materials: list of materials (#G3DMaterial)
 * @objects: list of objects (#G3DObject)
 *
 * A 3D model.
 */
typedef struct {
	gchar *filename;
	/*< private >*/
	G3DContext *context;

	/*< public >*/
	GSList *materials;
	GSList *objects;

	/*< private >*/
	GHashTable *tex_images;

	/* the plugin used to load the model, may be NULL */
	G3DPlugin *plugin;
	/* The stream used to load the model, may be NULL */
	G3DStream *stream;

	int refCount;
} G3DModel;

#ifdef __cplusplus
}
#endif /* ifdef __cplusplus */

#endif /* __G3D_TYPES_H__ */