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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
/* $XFree86$ */
/**************************************************************************
Copyright 1999, 2000 ATI Technologies Inc. and Precision Insight, Inc.,
Cedar Park, Texas.
All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
on the rights to use, copy, modify, merge, publish, distribute, sub
license, and/or sell copies of the Software, and to permit persons to whom
the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
ATI, PRECISION INSIGHT AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
**************************************************************************/
/*
* Authors:
* Kevin E. Martin <kevin@precisioninsight.com>
*
*/
#include "r128_init.h"
#include "r128_mesa.h"
#include "r128_xmesa.h"
#include "r128_context.h"
#include "r128_lock.h"
#include "r128_state.h"
#include "r128_reg.h"
#include "r128_cce.h"
#include "r128_depth.h"
/* FIXME: only handles 16bpp depth buffer for now */
#define DEPTH_DECLS \
r128ContextPtr r128ctx = R128_CONTEXT(ctx); \
r128ScreenPtr r128scrn = r128ctx->r128Screen; \
int xoff = (r128ctx->driDrawable->x + \
r128scrn->depthX); \
int yoff = (r128ctx->driDrawable->y + \
r128scrn->depthY); \
int height = r128ctx->driDrawable->h; \
unsigned char *zbase = (r128scrn->fb + \
xoff * (r128scrn->bpp/8) + \
yoff * r128scrn->fbStride); \
volatile GLdepth *zptr; \
int i
#define DEPTH_ADDR(base, _x, _y) \
(GLdepth*)(zbase + _x * (r128scrn->bpp/8) + \
(height - _y) * r128scrn->fbStride)
#define DEPTH_TEST_SPAN(_op_) \
if (ctx->Depth.Mask) { /* Update Z buffer */ \
for (i = 0; i < n; i++, zptr++, m++) { \
if (*m) { \
if (z[i] _op_ *zptr) { /* pass */ \
*zptr = z[i]; \
passed++; \
} else { /* fail */ \
*m = 0; \
} \
} \
} \
} else { /* Don't update Z buffer */ \
for (i = 0; i < n; i++, zptr++, m++) { \
if (*m) { \
if (z[i] _op_ *zptr) { /* pass */ \
passed++; \
} else { /* fail */ \
*m = 0; \
} \
} \
} \
}
#define DEPTH_TEST_PIXELS(_op_) \
if (ctx->Depth.Mask) { /* Update Z buffer */ \
for (i = 0; i < n; i++) { \
if (mask[i]) { \
zptr = DEPTH_ADDR(zbase, x[i], y[i]); \
if (z[i] _op_ *zptr) *zptr = z[i]; \
else mask[i] = 0; \
} \
} \
} else { /* Don't update Z buffer */ \
for (i = 0; i < n; i++, zptr++, m++) { \
if (mask[i]) { \
zptr = DEPTH_ADDR(zbase, x[i], y[i]); \
if (z[i] _op_ *zptr) ; \
else mask[i] = 0; \
} \
} \
}
static void r128DDAllocDepthBuffer(GLcontext *ctx)
{
}
static GLuint r128DDDepthTestSpan(GLcontext *ctx,
GLuint n, GLint x, GLint y,
const GLdepth z[],
GLubyte mask[])
{
DEPTH_DECLS;
GLubyte *m = mask;
int passed = 0;
zptr = DEPTH_ADDR(zbase, x, y);
LOCK_HARDWARE(r128ctx);
R128WaitForIdle(r128scrn);
switch (ctx->Depth.Func) {
case GL_LESS: DEPTH_TEST_SPAN(<) break;
case GL_LEQUAL: DEPTH_TEST_SPAN(<=) break;
case GL_GEQUAL: DEPTH_TEST_SPAN(>=) break;
case GL_GREATER: DEPTH_TEST_SPAN(>) break;
case GL_NOTEQUAL: DEPTH_TEST_SPAN(!=) break;
case GL_EQUAL: DEPTH_TEST_SPAN(==) break;
case GL_ALWAYS:
if (ctx->Depth.Mask) { /* Update Z buffer */
for (i = 0; i < n; i++, zptr++, m++) {
if (*m) {
*zptr = z[i];
passed++;
}
}
} else { /* Don't update Z buffer or mask */
passed = n;
}
break;
case GL_NEVER:
for (i = 0; i < n; i++) mask[i] = 0;
break;
default:
break;
}
UNLOCK_HARDWARE(r128ctx);
return passed;
}
static void r128DDDepthTestPixels(GLcontext *ctx,
GLuint n,
const GLint x[],
const GLint y[],
const GLdepth z[],
GLubyte mask[])
{
DEPTH_DECLS;
GLubyte *m = mask;
LOCK_HARDWARE(r128ctx);
R128WaitForIdle(r128scrn);
switch (ctx->Depth.Func) {
case GL_LESS: DEPTH_TEST_PIXELS(<); break;
case GL_LEQUAL: DEPTH_TEST_PIXELS(<=); break;
case GL_GEQUAL: DEPTH_TEST_PIXELS(>=); break;
case GL_GREATER: DEPTH_TEST_PIXELS(>); break;
case GL_NOTEQUAL: DEPTH_TEST_PIXELS(!=); break;
case GL_EQUAL: DEPTH_TEST_PIXELS(==); break;
case GL_ALWAYS:
if (ctx->Depth.Mask) { /* Update Z buffer */
for (i = 0; i < n; i++) {
if (mask[i]) {
zptr = DEPTH_ADDR(zbase, x[i], y[i]);
*zptr = z[i];
}
}
} else { /* Don't update Z buffer or mask */
}
break;
case GL_NEVER:
for (i = 0; i < n; i++) mask[i] = 0;
break;
default:
break;
}
UNLOCK_HARDWARE(r128ctx);
}
static void r128DDReadDepthSpanFloat(GLcontext *ctx,
GLuint n,
GLint x, GLint y, GLfloat depth[])
{
DEPTH_DECLS;
GLfloat scale = 1.0f / DEPTH_SCALE;
zptr = DEPTH_ADDR(zbase, x, y);
LOCK_HARDWARE(r128ctx);
R128WaitForIdle(r128scrn);
if (ctx->Buffer->Depth) {
for (i = 0; i < n; i++) depth[i] = (GLfloat)zptr[i] * scale;
} else {
for (i = 0; i < n; i++) depth[i] = 0.0f;
}
UNLOCK_HARDWARE(r128ctx);
}
static void r128DDReadDepthSpanInt(GLcontext *ctx,
GLuint n,
GLint x, GLint y, GLdepth depth[])
{
DEPTH_DECLS;
zptr = DEPTH_ADDR(zbase, x, y);
LOCK_HARDWARE(r128ctx);
R128WaitForIdle(r128scrn);
if (ctx->Buffer->Depth) {
MEMCPY(depth, zptr, n*sizeof(*depth));
} else {
for (i = 0; i < n; i++) depth[i] = 0;
}
UNLOCK_HARDWARE(r128ctx);
}
void r128DDInitDepthFuncs(GLcontext *ctx)
{
ctx->Driver.AllocDepthBuffer = r128DDAllocDepthBuffer;
ctx->Driver.DepthTestSpan = r128DDDepthTestSpan;
ctx->Driver.DepthTestPixels = r128DDDepthTestPixels;
ctx->Driver.ReadDepthSpanFloat = r128DDReadDepthSpanFloat;
ctx->Driver.ReadDepthSpanInt = r128DDReadDepthSpanInt;
}
|