#include "main/macros.h"
#include "main/imports.h"
+#include "s_context.h"
#include "s_depth.h"
#include "s_span.h"
/**
* Get array of 32-bit z values from the depth buffer. With clipping.
+ * Note: the returned values are always in the range [0, 2^32-1].
*/
static void
get_z32_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
GLuint count, const GLint x[], const GLint y[],
GLuint zbuffer[])
{
+ struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
const GLint w = rb->Width, h = rb->Height;
- const GLubyte *map = (const GLubyte *) rb->Data;
+ const GLubyte *map = _swrast_pixel_address(rb, 0, 0);
GLuint i;
if (rb->Format == MESA_FORMAT_Z32) {
- const GLint rowStride = rb->RowStride * 4;
+ const GLint rowStride = srb->RowStride;
for (i = 0; i < count; i++) {
if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
zbuffer[i] = *((GLuint *) (map + y[i] * rowStride + x[i] * 4));
}
else {
const GLint bpp = _mesa_get_format_bytes(rb->Format);
- const GLint rowStride = rb->RowStride * bpp;
+ const GLint rowStride = srb->RowStride;
for (i = 0; i < count; i++) {
if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
const GLubyte *src = map + y[i] * rowStride+ x[i] * bpp;
}
}
+
+/**
+ * Put an array of 32-bit z values into the depth buffer.
+ * Note: the z values are always in the range [0, 2^32-1].
+ */
static void
put_z32_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
GLuint count, const GLint x[], const GLint y[],
const GLuint zvalues[], const GLubyte mask[])
{
+ struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
const GLint w = rb->Width, h = rb->Height;
- GLubyte *map = (GLubyte *) rb->Data;
+ GLubyte *map = _swrast_pixel_address(rb, 0, 0);
GLuint i;
if (rb->Format == MESA_FORMAT_Z32) {
- const GLuint rowStride = rb->RowStride * 4;
+ const GLint rowStride = srb->RowStride;
for (i = 0; i < count; i++) {
if (mask[i] && x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
GLuint *dst = (GLuint *) (map + y[i] * rowStride + x[i] * 4);
else {
gl_pack_uint_z_func packZ = _mesa_get_pack_uint_z_func(rb->Format);
const GLint bpp = _mesa_get_format_bytes(rb->Format);
- const GLint rowStride = rb->RowStride * bpp;
+ const GLint rowStride = srb->RowStride;
for (i = 0; i < count; i++) {
if (mask[i] && x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
void *dst = map + y[i] * rowStride + x[i] * bpp;
}
-/**
- * Return the address of a Z value in a renderbuffer.
- */
-static INLINE void *
-get_z_address(struct gl_renderbuffer *rb, GLint x, GLint y)
-{
- const GLint bpp = _mesa_get_format_bytes(rb->Format);
- const GLint rowStride = rb->RowStride * bpp;
- return (GLubyte *) rb->Data + y * rowStride + x * bpp;
-}
-
-
/**
* Apply depth (Z) buffer testing to the span.
* \return approx number of pixels that passed (only zero is reliable)
struct gl_framebuffer *fb = ctx->DrawBuffer;
struct gl_renderbuffer *rb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
const GLint bpp = _mesa_get_format_bytes(rb->Format);
- void *zStart = get_z_address(rb, span->x, span->y);
+ void *zStart;
const GLuint count = span->end;
const GLuint *fragZ = span->array->z;
GLubyte *mask = span->array->mask;
void *zBufferVals;
GLuint *zBufferTemp = NULL;
GLuint passed;
+ GLuint zBits = _mesa_get_format_bits(rb->Format, GL_DEPTH_BITS);
GLboolean ztest16 = GL_FALSE;
- GLboolean ztest24 = _mesa_get_format_bits(rb->Format, GL_DEPTH_BITS) == 24;
+
+ if (span->arrayMask & SPAN_XY)
+ zStart = NULL;
+ else
+ zStart = _swrast_pixel_address(rb, span->x, span->y);
if (rb->Format == MESA_FORMAT_Z16 && !(span->arrayMask & SPAN_XY)) {
/* directly read/write row of 16-bit Z values */
}
else {
/* copy Z buffer values into temp buffer (32-bit Z values) */
- zBufferTemp = (GLuint *) malloc(count * sizeof(GLuint));
+ zBufferTemp = malloc(count * sizeof(GLuint));
if (!zBufferTemp)
return 0;
_mesa_unpack_uint_z_row(rb->Format, count, zStart, zBufferTemp);
}
- if (ztest24) {
+ if (zBits == 24) {
GLuint i;
/* Convert depth buffer values from 32 to 24 bits to match the
* fragment Z values generated by rasterization.
zBufferTemp[i] >>= 8;
}
}
+ else if (zBits == 16) {
+ GLuint i;
+ /* Convert depth buffer values from 32 to 16 bits */
+ for (i = 0; i < count; i++) {
+ zBufferTemp[i] >>= 16;
+ }
+ }
+ else {
+ assert(zBits == 32);
+ }
zBufferVals = zBufferTemp;
}
if (zBufferTemp) {
/* need to write temp Z values back into the buffer */
- if (ztest24) {
+ /* Convert depth buffer values back to 32-bit values. The least
+ * significant bits don't matter since they'll get dropped when
+ * they're packed back into the depth buffer.
+ */
+ if (zBits == 24) {
GLuint i;
- /* Convert depth buffer values back to 32-bit values. The least
- * significant bits don't matter since they'll get dropped when
- * they're packed back into the depth buffer.
- */
for (i = 0; i < count; i++) {
zBufferTemp[i] = (zBufferTemp[i] << 8);
}
}
+ else if (zBits == 16) {
+ GLuint i;
+ for (i = 0; i < count; i++) {
+ zBufferTemp[i] = zBufferTemp[i] << 16;
+ }
+ }
if (span->arrayMask & SPAN_XY) {
/* random locations */
{
struct gl_framebuffer *fb = ctx->DrawBuffer;
struct gl_renderbuffer *rb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
- const GLint bpp = _mesa_get_format_bytes(rb->Format);
- const GLint rowStride = rb->RowStride * bpp;
- GLubyte *zStart = (GLubyte*) rb->Data + span->y * rowStride + span->x * bpp;
+ GLubyte *zStart;
GLuint zMin = (GLuint) (ctx->Depth.BoundsMin * fb->_DepthMaxF + 0.5F);
GLuint zMax = (GLuint) (ctx->Depth.BoundsMax * fb->_DepthMaxF + 0.5F);
GLubyte *mask = span->array->mask;
const GLuint count = span->end;
GLuint i;
GLboolean anyPass = GL_FALSE;
- GLuint zBufferTemp[MAX_WIDTH];
+ GLuint *zBufferTemp;
const GLuint *zBufferVals;
+ zBufferTemp = malloc(count * sizeof(GLuint));
+ if (!zBufferTemp) {
+ /* don't generate a stream of OUT_OF_MEMORY errors here */
+ return GL_FALSE;
+ }
+
+ if (span->arrayMask & SPAN_XY)
+ zStart = NULL;
+ else
+ zStart = _swrast_pixel_address(rb, span->x, span->y);
+
if (rb->Format == MESA_FORMAT_Z32 && !(span->arrayMask & SPAN_XY)) {
/* directly access 32-bit values in the depth buffer */
zBufferVals = (const GLuint *) zStart;
}
}
+ free(zBufferTemp);
+
return anyPass;
}
return;
}
- _mesa_unpack_float_z_row(rb->Format, n, get_z_address(rb, x, y), depth);
+ _mesa_unpack_float_z_row(rb->Format, n, _swrast_pixel_address(rb, x, y),
+ depth);
}
{
struct gl_renderbuffer *rb =
ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
- GLuint clearValue;
GLint x, y, width, height;
GLubyte *map;
GLint rowStride, i, j;
return;
}
- /* compute integer clearing value */
- if (ctx->Depth.Clear == 1.0) {
- clearValue = ctx->DrawBuffer->_DepthMax;
- }
- else {
- clearValue = (GLuint) (ctx->Depth.Clear * ctx->DrawBuffer->_DepthMaxF);
- }
-
/* compute region to clear */
x = ctx->DrawBuffer->_Xmin;
y = ctx->DrawBuffer->_Ymin;