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
| #include <stdlib.h>
#include "framebuffer.h"
#include "OffscreenContext.h"
struct _framebuffer {
OffscreenContext * ctx;
float * depth;
unsigned width, height;
};
void framebuffer_destroy (framebuffer * p)
{
free (p->depth);
teardown_offscreen_context (p->ctx);
free (p);
}
framebuffer * framebuffer_new (unsigned width, unsigned height)
{
framebuffer * p = malloc (sizeof (struct _framebuffer));
p->ctx = create_offscreen_context (width, height);
p->depth = NULL;
p->width = width, p->height = height;
return p;
}
unsigned char * framebuffer_image (framebuffer * p)
{
return get_framebuffer_pixels (p->ctx);
}
float * framebuffer_depth (framebuffer * p)
{
unsigned int * depth = get_framebuffer_depth (p->ctx);
if (!p->depth)
p->depth = (float *) malloc (p->width*p->height*sizeof (float));
float * d = p->depth;
unsigned int * z = depth;
for (unsigned long i = 0; i < p->width*p->height; i++, z++, d++)
*d = *z;
return p->depth;
}
|