4 Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
6 This file is part of simavr.
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.
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.
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/>.
23 * c3geometry is a structure containing one set of vertices and various
24 * bits related to it. Ultimately it contains a pre-cached projected
25 * version of the vertices that the drawing code can use directly.
26 * c3geometry is aways attached to a c3object as a parent.
29 #ifndef __C3GEOMETRY_H___
30 #define __C3GEOMETRY_H___
32 #include "c3/c3algebra.h"
35 typedef c3vec3 c3vertex;
36 typedef c3vec4 c3colorf;
41 DECLARE_C_ARRAY(c3vertex, c3vertex_array, 16);
42 DECLARE_C_ARRAY(c3tex, c3tex_array, 16);
43 DECLARE_C_ARRAY(c3colorf, c3colorf_array, 16);
45 //! Geometry material. TODO: Beef up. Add vertex/fragment programs..
46 typedef struct c3material_t {
51 //! Bounding box. TODO: Move to a separate file?
52 typedef struct c3bbox_t {
56 //! Generic geometry type
65 * The type is used as non-opengl description of what the geometry
66 * contains, like "texture", and the subtype can be used to store the
67 * real format of the vertices. like GL_LINES etc
70 struct { uint32_t type : 16, subtype : 16; };
75 * Geometry object. Describes a set of vertices, texture coordinates,
76 * normals, colors and material
77 * The projection is not set here, a geometry is always attached to a
78 * c3object that has the projection
80 typedef struct c3geometry_t {
81 c3geometry_type_t type; // C3_TRIANGLE_TYPE, GL_LINES etc
83 texture : 1, // has a valid material.texture
84 custom : 1; // has a custom driver
85 str_p name; // optional
87 struct c3object_t * object;
88 const struct c3driver_geometry_t ** driver;
90 c3vertex_array_t vertice;
91 c3tex_array_t textures;
92 c3colorf_array_t colorf;
93 c3vertex_array_t normals;
95 // projected version of the vertice
96 c3vertex_array_t projected;
98 } c3geometry_t, *c3geometry_p;
100 DECLARE_C_ARRAY(c3geometry_p, c3geometry_array, 4);
102 //! Allocates a new geometry, init it, and attached it to parent 'o' (optional)
105 c3geometry_type_t type,
106 struct c3object_t * o /* = NULL */);
107 //! Init an existing new geometry, and attached it to parent 'o' (optional)
111 c3geometry_type_t type,
112 struct c3object_t * o /* = NULL */);
113 //! Disposes (via the driver interface) the geometry
118 //! Prepares a geometry.
120 * The prepare phase is called only when the container object is 'dirty'
121 * for example if it's projection has changed.
122 * The prepare call is responsible for reprojecting the geometry and that
129 //! Draw the geometry
131 * Called when drawing the context. Typicaly this calls the geometry
132 * driver, which in turn will call the 'context' draw method, and the
133 * application to draw this particular geometry
140 //! allocate (if not there) and return a custom driver for this geometry
142 * Geometries come with a default, read only driver stack.. It is a constant
143 * global to save memory for each of the 'generic' object.
144 * This call will duplicate that stack and allocate (if not there) a read/write
145 * empty driver that the application can use to put their own, per object,
146 * callback. For example you can add your own prepare() or draw() function
147 * and have it called first
149 struct c3driver_geometry_t *
150 c3geometry_get_custom(
153 IMPLEMENT_C_ARRAY(c3geometry_array);
154 IMPLEMENT_C_ARRAY(c3vertex_array);
155 IMPLEMENT_C_ARRAY(c3tex_array);
156 IMPLEMENT_C_ARRAY(c3colorf_array);
158 static inline c3geometry_type_t
159 c3geometry_type(int type, int subtype)
161 c3geometry_type_t r = { .type = type, .subtype = subtype };
165 #endif /* __C3GEOMETRY_H___ */