#include "demo.h"
#include "util.h"
+#define ENABLE_ZBUFFER
+
#define STACK_SIZE 8
typedef float g3d_matrix[16];
int g3d_init(void)
{
- if(!(st = malloc(sizeof *st))) {
+ if(!(st = calloc(1, sizeof *st))) {
fprintf(stderr, "failed to allocate G3D context\n");
return -1;
}
void g3d_destroy(void)
{
+#ifdef ENABLE_ZBUFFER
+ free(pfill_zbuf);
+#endif
free(st);
}
{
int i;
+#ifdef ENABLE_ZBUFFER
+ free(pfill_zbuf);
+#endif
memset(st, 0, sizeof *st);
st->opt = G3D_CLIP_FRUSTUM;
void g3d_framebuffer(int width, int height, void *pixels)
{
- static int prev_height;
+ static int max_height;
+
+#ifdef ENABLE_ZBUFFER
+ static int max_npixels;
+ int npixels = width * height;
+
+ if(npixels > max_npixels) {
+ free(pfill_zbuf);
+ pfill_zbuf = malloc(npixels * sizeof *pfill_zbuf);
+ max_npixels = npixels;
+ }
+#endif
- if(height > prev_height) {
+ if(height > max_height) {
polyfill_fbheight(height);
+ max_height = height;
}
st->width = width;