X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=blobdiff_plain;f=src%2F3dgfx%2F3dgfx.c;h=16024f8065a78d5eb20ac1383d5e50c7281f42dc;hp=e199a64e9a4b8726ab3994d5daf442e481a28118;hb=659ca11730af4e7e5b1b350efa4198a9c42de287;hpb=2e6bc96b25ae3ad5be7f04934be01f63dfd23ce2 diff --git a/src/3dgfx/3dgfx.c b/src/3dgfx/3dgfx.c index e199a64..16024f8 100644 --- a/src/3dgfx/3dgfx.c +++ b/src/3dgfx/3dgfx.c @@ -17,6 +17,8 @@ #include "demo.h" #include "util.h" +#define ENABLE_ZBUFFER + #define STACK_SIZE 8 typedef float g3d_matrix[16]; @@ -90,7 +92,7 @@ static const float idmat[] = { 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; } @@ -101,6 +103,9 @@ int g3d_init(void) void g3d_destroy(void) { +#ifdef ENABLE_ZBUFFER + free(pfill_zbuf); +#endif free(st); } @@ -108,6 +113,9 @@ void g3d_reset(void) { int i; +#ifdef ENABLE_ZBUFFER + free(pfill_zbuf); +#endif memset(st, 0, sizeof *st); st->opt = G3D_CLIP_FRUSTUM; @@ -128,10 +136,22 @@ void g3d_reset(void) 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;