return c;
}
+void
+c3context_dispose(
+ c3context_p c)
+{
+ c3object_dispose(c->root);
+ c3geometry_array_free(&c->projected);
+ free(c);
+}
+
void
c3context_prepare(
c3context_p c)
c3context_prepare(c);
for (int gi = 0; gi < c->projected.count; gi++) {
c3geometry_p g = c->projected.e[gi];
- C3_DRIVER(c, geometry_draw, g);
+ c3geometry_draw(g);
}
}
int w,
int h);
+void
+c3context_dispose(
+ c3context_p c);
+
// Reproject geometry for dirty objects
void
c3context_prepare(
void (*prepare)(
struct c3geometry_t * geometry,
const struct c3driver_geometry_t *d);
+ void (*draw)(
+ struct c3geometry_t * geometry,
+ const struct c3driver_geometry_t *d);
} c3driver_geometry_t, *c3driver_geometry_p;
// C3_DRIVER_INHERITED(g, d, prepare);
}
+static void
+_c3geometry_draw(
+ c3geometry_p g,
+ const struct c3driver_geometry_t *d)
+{
+ if (g->object && g->object->context)
+ C3_DRIVER(g->object->context, geometry_draw, g);
+// C3_DRIVER_INHERITED(g, d, draw);
+}
+
const c3driver_geometry_t c3geometry_driver = {
.dispose = _c3geometry_dispose,
.prepare = _c3geometry_prepare,
+ .draw = _c3geometry_draw,
};
c3geometry_p
return g;
}
+c3driver_geometry_p
+c3geometry_get_custom(
+ c3geometry_p g )
+{
+ if (g->custom)
+ return (c3driver_geometry_p)g->driver[0];
+ int cnt = 0;
+ for (int di = 0; g->driver[di]; di++)
+ cnt++;
+ c3driver_geometry_p * newd = malloc(sizeof(c3driver_geometry_p) * (cnt + 2));
+ memcpy(&newd[1], g->driver, (cnt + 1) * sizeof(c3driver_geometry_p));
+ newd[0] = malloc(sizeof(c3driver_geometry_t));
+ memset(newd[0], 0, sizeof(c3driver_geometry_t));
+ g->custom = 1;
+ g->driver = (typeof(g->driver))newd;
+ return newd[0];
+}
+
void
c3geometry_dispose(
c3geometry_p g)
return;
C3_DRIVER(g, prepare);
}
+
+void
+c3geometry_draw(
+ c3geometry_p g )
+{
+ C3_DRIVER(g, draw);
+}
typedef struct c3geometry_t {
c3geometry_type_t type; // GL_LINES etc
- int dirty : 1, texture : 1;
+ int dirty : 1,
+ texture : 1, // has a valid material.texture
+ custom : 1; // has a custom driver
str_p name; // optional
c3material_t mat;
struct c3object_t * object;
const struct c3driver_geometry_t ** driver;
+
c3vertex_array_t vertice;
c3tex_array_t textures;
c3colorf_array_t colorf;
// projected version of the vertice
c3vertex_array_t projected;
c3bbox_t bbox;
-
- /*
- * optional, geometry dependant custom draw method
- * return nonzero will orevent the default drawing code
- * from being called (c3context one)
- */
- int (*draw)(struct c3geometry_t *);
} c3geometry_t, *c3geometry_p;
DECLARE_C_ARRAY(c3geometry_p, c3geometry_array, 4);
void
c3geometry_prepare(
c3geometry_p g );
+void
+c3geometry_draw(
+ c3geometry_p g );
+
+//! allocate (if not there) and return a custom driver for this geometry
+struct c3driver_geometry_t *
+c3geometry_get_custom(
+ c3geometry_p g );
IMPLEMENT_C_ARRAY(c3geometry_array);
IMPLEMENT_C_ARRAY(c3vertex_array);
switch (key) {
case 'q':
// avr_vcd_stop(&vcd_file);
+ c3context_dispose(c3);
exit(0);
break;
case 'r':
const struct c3driver_context_t *d,
c3geometry_p g)
{
- printf("_c3_geometry_prepare %p %d/%d!\n", g, g->type.type, g->type.subtype);
switch(g->type.type) {
case C3_TEXTURE_TYPE: {
c3texture_p t = (c3texture_p)g;
c3transform_set(head->transform.e[0], &headmove);
if (c3->root->dirty) {
- printf("reproject\n");
+ // printf("reproject\n");
c3context_prepare(c3);
qsort(c3->projected.e, c3->projected.count,
return 1;
}
+void
+gl_dispose()
+{
+ c3context_dispose(c3);
+}
+
int
gl_runloop()
{
glutMainLoop();
+ gl_dispose();
return 0;
}
int
gl_runloop();
+void
+gl_dispose();
+
#endif /* __REPRAP_GL_H___ */