#include "mtypes.h"
#include "swrast/swrast.h"
#include "ffb_dd.h"
#include "ffb_span.h"
#include "ffb_context.h"
#include "ffb_depth.h"
#include "ffb_lock.h"
#include "swrast/swrast.h"
#undef DEPTH_TRACE
static void
FFBWriteDepthSpan(GLcontext *ctx, GLuint n, GLint x, GLint y,
const GLdepth depth[], const GLubyte mask[])
{
#ifdef DEPTH_TRACE
fprintf(stderr, "FFBWriteDepthSpan: n(%d) x(%d) y(%d)\n",
(int) n, x, y);
#endif
if (ctx->Depth.Mask) {
ffbContextPtr fmesa = FFB_CONTEXT(ctx);
__DRIdrawablePrivate *dPriv = fmesa->driDrawable;
GLuint *zptr;
GLuint i;
if (!fmesa->hw_locked)
LOCK_HARDWARE(fmesa);
FFBFifo(fmesa, 2);
fmesa->regs->fbc = (FFB_FBC_WB_C | FFB_FBC_ZE_ON |
FFB_FBC_YE_OFF | FFB_FBC_RGBE_OFF);
fmesa->regs->ppc = FFB_PPC_ZS_VAR;
FFBWait(fmesa, fmesa->regs);
y = (dPriv->h - y);
zptr = (GLuint *)
((char *)fmesa->sfb32 +
((dPriv->x + x) << 2) +
((dPriv->y + y) << 13));
for (i = 0; i < n; i++) {
if (mask[i]) {
*zptr = Z_FROM_MESA(depth[i]);
}
zptr++;
}
FFBFifo(fmesa, 2);
fmesa->regs->fbc = fmesa->fbc;
fmesa->regs->ppc = fmesa->ppc;
fmesa->ffbScreen->rp_active = 1;
if (!fmesa->hw_locked)
UNLOCK_HARDWARE(fmesa);
}
}
static void
FFBWriteDepthPixels(GLcontext *ctx, GLuint n, const GLint x[], const GLint y[],
const GLdepth depth[], const GLubyte mask[])
{
#ifdef DEPTH_TRACE
fprintf(stderr, "FFBWriteDepthPixels: n(%d)\n", (int) n);
#endif
if (ctx->Depth.Mask) {
ffbContextPtr fmesa = FFB_CONTEXT(ctx);
__DRIdrawablePrivate *dPriv = fmesa->driDrawable;
char *zbase;
GLuint i;
if (!fmesa->hw_locked)
LOCK_HARDWARE(fmesa);
FFBFifo(fmesa, 2);
fmesa->regs->fbc = (FFB_FBC_WB_C | FFB_FBC_ZE_ON |
FFB_FBC_YE_OFF | FFB_FBC_RGBE_OFF);
fmesa->regs->ppc = FFB_PPC_ZS_VAR;
fmesa->ffbScreen->rp_active = 1;
FFBWait(fmesa, fmesa->regs);
zbase = ((char *)fmesa->sfb32 +
(dPriv->x << 2) + (dPriv->y << 13));
for (i = 0; i < n; i++) {
GLint y1 = (dPriv->h - y[i]);
GLint x1 = x[i];
GLuint *zptr;
zptr = (GLuint *)
(zbase + (x1 << 2) + (y1 << 13));
if (mask[i])
*zptr = Z_FROM_MESA(depth[i]);
}
FFBFifo(fmesa, 2);
fmesa->regs->fbc = fmesa->fbc;
fmesa->regs->ppc = fmesa->ppc;
fmesa->ffbScreen->rp_active = 1;
if (!fmesa->hw_locked)
UNLOCK_HARDWARE(fmesa);
}
}
static void
FFBReadDepthSpan(GLcontext *ctx, GLuint n, GLint x, GLint y, GLdepth depth[])
{
ffbContextPtr fmesa = FFB_CONTEXT(ctx);
__DRIdrawablePrivate *dPriv = fmesa->driDrawable;
GLuint *zptr;
GLuint i;
#ifdef DEPTH_TRACE
fprintf(stderr, "FFBReadDepthSpan: n(%d) x(%d) y(%d)\n",
(int) n, x, y);
#endif
if (!fmesa->hw_locked)
LOCK_HARDWARE(fmesa);
FFBFifo(fmesa, 1);
fmesa->regs->fbc = FFB_FBC_RB_C;
fmesa->ffbScreen->rp_active = 1;
FFBWait(fmesa, fmesa->regs);
y = (dPriv->h - y);
zptr = (GLuint *)
((char *)fmesa->sfb32 +
((dPriv->x + x) << 2) +
((dPriv->y + y) << 13));
for (i = 0; i < n; i++) {
depth[i] = Z_TO_MESA(*zptr);
zptr++;
}
FFBFifo(fmesa, 1);
fmesa->regs->fbc = fmesa->fbc;
fmesa->ffbScreen->rp_active = 1;
if (!fmesa->hw_locked)
UNLOCK_HARDWARE(fmesa);
}
static void
FFBReadDepthPixels(GLcontext *ctx, GLuint n, const GLint x[], const GLint y[],
GLdepth depth[])
{
ffbContextPtr fmesa = FFB_CONTEXT(ctx);
__DRIdrawablePrivate *dPriv = fmesa->driDrawable;
char *zbase;
GLuint i;
#ifdef DEPTH_TRACE
fprintf(stderr, "FFBReadDepthPixels: n(%d)\n", (int) n);
#endif
if (!fmesa->hw_locked)
LOCK_HARDWARE(fmesa);
FFBFifo(fmesa, 1);
fmesa->regs->fbc = FFB_FBC_RB_C;
fmesa->ffbScreen->rp_active = 1;
FFBWait(fmesa, fmesa->regs);
zbase = ((char *)fmesa->sfb32 +
(dPriv->x << 2) + (dPriv->y << 13));
for (i = 0; i < n; i++) {
GLint y1 = (dPriv->h - y[i]);
GLint x1 = x[i];
GLuint *zptr;
zptr = (GLuint *)
(zbase + (x1 << 2) + (y1 << 13));
depth[i] = Z_TO_MESA(*zptr);
}
FFBFifo(fmesa, 1);
fmesa->regs->fbc = fmesa->fbc;
fmesa->ffbScreen->rp_active = 1;
if (!fmesa->hw_locked)
UNLOCK_HARDWARE(fmesa);
}
void ffbDDInitDepthFuncs(GLcontext *ctx)
{
struct swrast_device_driver *swdd =
_swrast_GetDeviceDriverReference(ctx);
swdd->WriteDepthSpan = FFBWriteDepthSpan;
swdd->ReadDepthSpan = FFBReadDepthSpan;
swdd->WriteDepthPixels = FFBWriteDepthPixels;
swdd->ReadDepthPixels = FFBReadDepthPixels;
}