-/* $Id: s_depth.c,v 1.2 2000/11/05 18:24:40 keithw Exp $ */
+/* $Id: s_depth.c,v 1.9 2001/03/19 02:25:36 keithw Exp $ */
/*
* Mesa 3-D graphics library
- * Version: 3.3
- *
- * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
- *
+ * Version: 3.5
+ *
+ * Copyright (C) 1999-2001 Brian Paul 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
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* 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 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 NONINFRINGEMENT. IN NO EVENT SHALL
GLvoid *
_mesa_zbuffer_address(GLcontext *ctx, GLint x, GLint y)
{
- if (ctx->Visual.DepthBits <= 16)
+ if (ctx->Visual.depthBits <= 16)
return (GLushort *) ctx->DrawBuffer->DepthBuffer + ctx->DrawBuffer->Width * y + x;
else
return (GLuint *) ctx->DrawBuffer->DepthBuffer + ctx->DrawBuffer->Width * y + x;
BZERO(mask, n * sizeof(GLubyte));
break;
default:
- gl_problem(ctx, "Bad depth func in depth_test_span16");
+ _mesa_problem(ctx, "Bad depth func in depth_test_span16");
}
return passed;
BZERO(mask, n * sizeof(GLubyte));
break;
default:
- gl_problem(ctx, "Bad depth func in depth_test_span32");
+ _mesa_problem(ctx, "Bad depth func in depth_test_span32");
}
return passed;
_mesa_depth_test_span( GLcontext *ctx, GLuint n, GLint x, GLint y,
const GLdepth z[], GLubyte mask[] )
{
- if (ctx->Driver.ReadDepthSpan) {
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
+ if (swrast->Driver.ReadDepthSpan) {
/* hardware-based depth buffer */
GLdepth zbuffer[MAX_WIDTH];
GLuint passed;
- (*ctx->Driver.ReadDepthSpan)(ctx, n, x, y, zbuffer);
+ (*swrast->Driver.ReadDepthSpan)(ctx, n, x, y, zbuffer);
passed = depth_test_span32(ctx, n, x, y, zbuffer, z, mask);
- assert(ctx->Driver.WriteDepthSpan);
- (*ctx->Driver.WriteDepthSpan)(ctx, n, x, y, zbuffer, mask);
+ assert(swrast->Driver.WriteDepthSpan);
+ (*swrast->Driver.WriteDepthSpan)(ctx, n, x, y, zbuffer, mask);
return passed;
}
else {
/* software depth buffer */
- if (ctx->Visual.DepthBits <= 16) {
+ if (ctx->Visual.depthBits <= 16) {
GLushort *zptr = (GLushort *) Z_ADDRESS16(ctx, x, y);
GLuint passed = depth_test_span16(ctx, n, x, y, zptr, z, mask);
return passed;
BZERO(mask, n * sizeof(GLubyte));
break;
default:
- gl_problem(ctx, "Bad depth func in software_depth_test_pixels");
+ _mesa_problem(ctx, "Bad depth func in software_depth_test_pixels");
}
}
BZERO(mask, n * sizeof(GLubyte));
break;
default:
- gl_problem(ctx, "Bad depth func in software_depth_test_pixels");
+ _mesa_problem(ctx, "Bad depth func in software_depth_test_pixels");
}
}
BZERO(mask, n * sizeof(GLubyte));
break;
default:
- gl_problem(ctx, "Bad depth func in hardware_depth_test_pixels");
+ _mesa_problem(ctx, "Bad depth func in hardware_depth_test_pixels");
}
}
GLuint n, const GLint x[], const GLint y[],
const GLdepth z[], GLubyte mask[] )
{
- if (ctx->Driver.ReadDepthPixels) {
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
+ if (swrast->Driver.ReadDepthPixels) {
/* read depth values from hardware Z buffer */
GLdepth zbuffer[PB_SIZE];
- (*ctx->Driver.ReadDepthPixels)(ctx, n, x, y, zbuffer);
+ (*swrast->Driver.ReadDepthPixels)(ctx, n, x, y, zbuffer);
hardware_depth_test_pixels( ctx, n, zbuffer, z, mask );
/* update hardware Z buffer with new values */
- assert(ctx->Driver.WriteDepthPixels);
- (*ctx->Driver.WriteDepthPixels)(ctx, n, x, y, zbuffer, mask );
+ assert(swrast->Driver.WriteDepthPixels);
+ (*swrast->Driver.WriteDepthPixels)(ctx, n, x, y, zbuffer, mask );
}
else {
/* software depth testing */
- if (ctx->Visual.DepthBits <= 16)
+ if (ctx->Visual.depthBits <= 16)
software_depth_test_pixels16(ctx, n, x, y, z, mask);
else
software_depth_test_pixels32(ctx, n, x, y, z, mask);
_mesa_read_depth_span( GLcontext *ctx,
GLint n, GLint x, GLint y, GLdepth depth[] )
{
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
+
if (y < 0 || y >= ctx->DrawBuffer->Height ||
x + (GLint) n <= 0 || x >= ctx->DrawBuffer->Width) {
/* span is completely outside framebuffer */
if (ctx->DrawBuffer->DepthBuffer) {
/* read from software depth buffer */
- if (ctx->Visual.DepthBits <= 16) {
+ if (ctx->Visual.depthBits <= 16) {
const GLushort *zptr = Z_ADDRESS16( ctx, x, y );
- GLuint i;
+ GLint i;
for (i = 0; i < n; i++) {
depth[i] = zptr[i];
}
}
else {
const GLuint *zptr = Z_ADDRESS32( ctx, x, y );
- GLuint i;
+ GLint i;
for (i = 0; i < n; i++) {
depth[i] = zptr[i];
}
}
}
- else if (ctx->Driver.ReadDepthSpan) {
+ else if (swrast->Driver.ReadDepthSpan) {
/* read from hardware depth buffer */
- (*ctx->Driver.ReadDepthSpan)( ctx, n, x, y, depth );
+ (*swrast->Driver.ReadDepthSpan)( ctx, n, x, y, depth );
}
else {
/* no depth buffer */
_mesa_read_depth_span_float( GLcontext *ctx,
GLint n, GLint x, GLint y, GLfloat depth[] )
{
- const GLfloat scale = 1.0F / ctx->Visual.DepthMaxF;
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
+ const GLfloat scale = 1.0F / ctx->DepthMaxF;
if (y < 0 || y >= ctx->DrawBuffer->Height ||
x + (GLint) n <= 0 || x >= ctx->DrawBuffer->Width) {
if (ctx->DrawBuffer->DepthBuffer) {
/* read from software depth buffer */
- if (ctx->Visual.DepthBits <= 16) {
+ if (ctx->Visual.depthBits <= 16) {
const GLushort *zptr = Z_ADDRESS16( ctx, x, y );
- GLuint i;
+ GLint i;
for (i = 0; i < n; i++) {
depth[i] = (GLfloat) zptr[i] * scale;
}
}
else {
const GLuint *zptr = Z_ADDRESS32( ctx, x, y );
- GLuint i;
+ GLint i;
for (i = 0; i < n; i++) {
depth[i] = (GLfloat) zptr[i] * scale;
}
}
}
- else if (ctx->Driver.ReadDepthSpan) {
+ else if (swrast->Driver.ReadDepthSpan) {
/* read from hardware depth buffer */
GLdepth d[MAX_WIDTH];
- GLuint i;
+ GLint i;
assert(n <= MAX_WIDTH);
- (*ctx->Driver.ReadDepthSpan)( ctx, n, x, y, d );
+ (*swrast->Driver.ReadDepthSpan)( ctx, n, x, y, d );
for (i = 0; i < n; i++) {
depth[i] = d[i] * scale;
}
}
/* allocate new depth buffer, but don't initialize it */
- if (ctx->Visual.DepthBits <= 16)
+ if (ctx->Visual.depthBits <= 16)
bytesPerValue = sizeof(GLushort);
else
bytesPerValue = sizeof(GLuint);
/* out of memory */
ctx->Depth.Test = GL_FALSE;
ctx->NewState |= _NEW_DEPTH;
- gl_error( ctx, GL_OUT_OF_MEMORY, "Couldn't allocate depth buffer" );
+ _mesa_error( ctx, GL_OUT_OF_MEMORY, "Couldn't allocate depth buffer" );
}
}
}
void
_mesa_clear_depth_buffer( GLcontext *ctx )
{
- if (ctx->Visual.DepthBits == 0
+ if (ctx->Visual.depthBits == 0
|| !ctx->DrawBuffer->DepthBuffer
|| !ctx->Depth.Mask) {
/* no depth buffer, or writing to it is disabled */
if (ctx->Scissor.Enabled) {
/* only clear scissor region */
- if (ctx->Visual.DepthBits <= 16) {
- const GLushort clearValue = (GLushort) (ctx->Depth.Clear * ctx->Visual.DepthMax);
- const GLint rows = ctx->DrawBuffer->Ymax - ctx->DrawBuffer->Ymin;
- const GLint width = ctx->DrawBuffer->Width;
+ if (ctx->Visual.depthBits <= 16) {
+ const GLushort clearValue = (GLushort) (ctx->Depth.Clear * ctx->DepthMax);
+ const GLint rows = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
+ const GLint cols = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
+ const GLint rowStride = ctx->DrawBuffer->Width;
GLushort *dRow = (GLushort *) ctx->DrawBuffer->DepthBuffer
- + ctx->DrawBuffer->Ymin * width + ctx->DrawBuffer->Xmin;
+ + ctx->DrawBuffer->_Ymin * rowStride + ctx->DrawBuffer->_Xmin;
GLint i, j;
for (i = 0; i < rows; i++) {
- for (j = 0; j < width; j++) {
+ for (j = 0; j < cols; j++) {
dRow[j] = clearValue;
}
- dRow += width;
+ dRow += rowStride;
}
}
else {
- const GLuint clearValue = (GLuint) (ctx->Depth.Clear * ctx->Visual.DepthMax);
- const GLint rows = ctx->DrawBuffer->Ymax - ctx->DrawBuffer->Ymin;
- const GLint width = ctx->DrawBuffer->Width;
+ const GLuint clearValue = (GLuint) (ctx->Depth.Clear * ctx->DepthMax);
+ const GLint rows = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
+ const GLint cols = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
+ const GLint rowStride = ctx->DrawBuffer->Width;
GLuint *dRow = (GLuint *) ctx->DrawBuffer->DepthBuffer
- + ctx->DrawBuffer->Ymin * width + ctx->DrawBuffer->Xmin;
+ + ctx->DrawBuffer->_Ymin * rowStride + ctx->DrawBuffer->_Xmin;
GLint i, j;
for (i = 0; i < rows; i++) {
- for (j = 0; j < width; j++) {
+ for (j = 0; j < cols; j++) {
dRow[j] = clearValue;
}
- dRow += width;
+ dRow += rowStride;
}
}
}
else {
/* clear whole buffer */
- if (ctx->Visual.DepthBits <= 16) {
- const GLushort clearValue = (GLushort) (ctx->Depth.Clear * ctx->Visual.DepthMax);
+ if (ctx->Visual.depthBits <= 16) {
+ const GLushort clearValue = (GLushort) (ctx->Depth.Clear * ctx->DepthMax);
if ((clearValue & 0xff) == (clearValue >> 8)) {
if (clearValue == 0) {
BZERO(ctx->DrawBuffer->DepthBuffer,
}
else {
/* >16 bit depth buffer */
- const GLuint clearValue = (GLuint) (ctx->Depth.Clear * ctx->Visual.DepthMax);
+ const GLuint clearValue = (GLuint) (ctx->Depth.Clear * ctx->DepthMax);
if (clearValue == 0) {
BZERO(ctx->DrawBuffer->DepthBuffer,
ctx->DrawBuffer->Width*ctx->DrawBuffer->Height*sizeof(GLuint));