2 #include "DepthBuffer.h"
5 DepthBufferInfo depthBuffer;
7 void DepthBuffer_Init()
9 depthBuffer.current = NULL;
10 depthBuffer.top = NULL;
11 depthBuffer.bottom = NULL;
12 depthBuffer.numBuffers = 0;
15 void DepthBuffer_RemoveBottom()
17 DepthBuffer *newBottom = depthBuffer.bottom->higher;
19 if (depthBuffer.bottom == depthBuffer.top)
20 depthBuffer.top = NULL;
22 free( depthBuffer.bottom );
24 depthBuffer.bottom = newBottom;
26 if (depthBuffer.bottom != NULL)
27 depthBuffer.bottom->lower = NULL;
29 depthBuffer.numBuffers--;
32 void DepthBuffer_Remove( DepthBuffer *buffer )
34 if ((buffer == depthBuffer.bottom) &&
35 (buffer == depthBuffer.top))
37 depthBuffer.top = NULL;
38 depthBuffer.bottom = NULL;
40 else if (buffer == depthBuffer.bottom)
42 depthBuffer.bottom = buffer->higher;
44 if (depthBuffer.bottom)
45 depthBuffer.bottom->lower = NULL;
47 else if (buffer == depthBuffer.top)
49 depthBuffer.top = buffer->lower;
52 depthBuffer.top->higher = NULL;
56 buffer->higher->lower = buffer->lower;
57 buffer->lower->higher = buffer->higher;
61 depthBuffer.numBuffers--;
64 void DepthBuffer_RemoveBuffer( u32 address )
66 DepthBuffer *current = depthBuffer.bottom;
67 while (current != NULL)
69 if (current->address == address)
71 DepthBuffer_Remove( current );
74 current = current->higher;
78 DepthBuffer *DepthBuffer_AddTop()
80 DepthBuffer *newtop = (DepthBuffer*)malloc( sizeof( DepthBuffer ) );
82 newtop->lower = depthBuffer.top;
83 newtop->higher = NULL;
86 depthBuffer.top->higher = newtop;
88 if (!depthBuffer.bottom)
89 depthBuffer.bottom = newtop;
91 depthBuffer.top = newtop;
93 depthBuffer.numBuffers++;
98 void DepthBuffer_MoveToTop( DepthBuffer *newtop )
100 if (newtop == depthBuffer.top)
103 if (newtop == depthBuffer.bottom)
105 depthBuffer.bottom = newtop->higher;
106 depthBuffer.bottom->lower = NULL;
110 newtop->higher->lower = newtop->lower;
111 newtop->lower->higher = newtop->higher;
114 newtop->higher = NULL;
115 newtop->lower = depthBuffer.top;
116 depthBuffer.top->higher = newtop;
117 depthBuffer.top = newtop;
120 void DepthBuffer_Destroy()
122 while (depthBuffer.bottom)
123 DepthBuffer_RemoveBottom();
125 depthBuffer.top = NULL;
128 void DepthBuffer_SetBuffer( u32 address )
130 DepthBuffer *current = depthBuffer.top;
132 // Search through saved depth buffers
133 while (current != NULL)
135 if (current->address == address)
137 DepthBuffer_MoveToTop( current );
138 depthBuffer.current = current;
141 current = current->lower;
144 current = DepthBuffer_AddTop();
146 current->address = address;
147 current->cleared = TRUE;
149 depthBuffer.current = current;
152 DepthBuffer *DepthBuffer_FindBuffer( u32 address )
154 DepthBuffer *current = depthBuffer.top;
158 if (current->address == address)
160 current = current->lower;