summaryrefslogtreecommitdiff
path: root/src/mesa/swrast/s_depth.c
diff options
context:
space:
mode:
authorJosé Fonseca <jfonseca@vmware.com>2010-01-08 15:42:57 +0000
committerJosé Fonseca <jfonseca@vmware.com>2010-01-08 15:42:57 +0000
commit080c40ab32b2abd6d8381b4a0cc143d36a1652b2 (patch)
treee173767ebc5a82d81b9fc086449d915e29348976 /src/mesa/swrast/s_depth.c
parent9cdf6f025b2ed55cfb13dd09f870f01d0c7947d3 (diff)
parenta1de400e8de06a80ab140bb0fa950e990607572d (diff)
Merge remote branch 'origin/master' into lp-binning
Conflicts: src/gallium/auxiliary/util/u_surface.c src/gallium/drivers/llvmpipe/Makefile src/gallium/drivers/llvmpipe/SConscript src/gallium/drivers/llvmpipe/lp_bld_arit.c src/gallium/drivers/llvmpipe/lp_bld_flow.c src/gallium/drivers/llvmpipe/lp_bld_interp.c src/gallium/drivers/llvmpipe/lp_clear.c src/gallium/drivers/llvmpipe/lp_context.c src/gallium/drivers/llvmpipe/lp_context.h src/gallium/drivers/llvmpipe/lp_draw_arrays.c src/gallium/drivers/llvmpipe/lp_jit.c src/gallium/drivers/llvmpipe/lp_jit.h src/gallium/drivers/llvmpipe/lp_prim_vbuf.c src/gallium/drivers/llvmpipe/lp_setup.c src/gallium/drivers/llvmpipe/lp_setup_point.c src/gallium/drivers/llvmpipe/lp_state.h src/gallium/drivers/llvmpipe/lp_state_blend.c src/gallium/drivers/llvmpipe/lp_state_derived.c src/gallium/drivers/llvmpipe/lp_state_fs.c src/gallium/drivers/llvmpipe/lp_state_sampler.c src/gallium/drivers/llvmpipe/lp_state_surface.c src/gallium/drivers/llvmpipe/lp_tex_cache.c src/gallium/drivers/llvmpipe/lp_tex_cache.h src/gallium/drivers/llvmpipe/lp_tex_sample.h src/gallium/drivers/llvmpipe/lp_tile_cache.c
Diffstat (limited to 'src/mesa/swrast/s_depth.c')
-rw-r--r--src/mesa/swrast/s_depth.c41
1 files changed, 28 insertions, 13 deletions
diff --git a/src/mesa/swrast/s_depth.c b/src/mesa/swrast/s_depth.c
index 17e00dda4f..c37a54eb3e 100644
--- a/src/mesa/swrast/s_depth.c
+++ b/src/mesa/swrast/s_depth.c
@@ -25,6 +25,7 @@
#include "main/glheader.h"
#include "main/context.h"
+#include "main/formats.h"
#include "main/macros.h"
#include "main/imports.h"
#include "main/fbobject.h"
@@ -505,22 +506,32 @@ _swrast_depth_clamp_span( GLcontext *ctx, SWspan *span )
struct gl_renderbuffer *rb = fb->_DepthBuffer;
const GLuint count = span->end;
GLuint *zValues = span->array->z;
- GLuint near, far;
+ GLuint min, max;
+ GLfloat min_f, max_f;
int i;
+ if (ctx->Viewport.Near < ctx->Viewport.Far) {
+ min_f = ctx->Viewport.Near;
+ max_f = ctx->Viewport.Far;
+ } else {
+ min_f = ctx->Viewport.Far;
+ max_f = ctx->Viewport.Near;
+ }
+
if (rb->DataType == GL_UNSIGNED_SHORT) {
- near = FLOAT_TO_UINT(ctx->Viewport.Near);
- far = FLOAT_TO_UINT(ctx->Viewport.Far);
+ CLAMPED_FLOAT_TO_USHORT(min, min_f);
+ CLAMPED_FLOAT_TO_USHORT(max, max_f);
} else {
assert(rb->DataType == GL_UNSIGNED_INT);
- CLAMPED_FLOAT_TO_USHORT(near, ctx->Viewport.Near);
- CLAMPED_FLOAT_TO_USHORT(far, ctx->Viewport.Far);
+ min = FLOAT_TO_UINT(min_f);
+ max = FLOAT_TO_UINT(max_f);
}
+
for (i = 0; i < count; i++) {
- if (zValues[i] < near)
- zValues[i] = near;
- if (zValues[i] > far)
- zValues[i] = far;
+ if (zValues[i] < min)
+ zValues[i] = min;
+ if (zValues[i] > max)
+ zValues[i] = max;
}
}
@@ -1299,12 +1310,16 @@ void
_swrast_read_depth_span_uint( GLcontext *ctx, struct gl_renderbuffer *rb,
GLint n, GLint x, GLint y, GLuint depth[] )
{
+ GLuint depthBits;
+
if (!rb) {
/* really only doing this to prevent FP exceptions later */
_mesa_bzero(depth, n * sizeof(GLuint));
return;
}
+ depthBits = _mesa_get_format_bits(rb->Format, GL_DEPTH_BITS);
+
ASSERT(rb->_BaseFormat == GL_DEPTH_COMPONENT);
if (y < 0 || y >= (GLint) rb->Height ||
@@ -1336,8 +1351,8 @@ _swrast_read_depth_span_uint( GLcontext *ctx, struct gl_renderbuffer *rb,
if (rb->DataType == GL_UNSIGNED_INT) {
rb->GetRow(ctx, rb, n, x, y, depth);
- if (rb->DepthBits < 32) {
- GLuint shift = 32 - rb->DepthBits;
+ if (depthBits < 32) {
+ GLuint shift = 32 - depthBits;
GLint i;
for (i = 0; i < n; i++) {
GLuint z = depth[i];
@@ -1349,14 +1364,14 @@ _swrast_read_depth_span_uint( GLcontext *ctx, struct gl_renderbuffer *rb,
GLushort temp[MAX_WIDTH];
GLint i;
rb->GetRow(ctx, rb, n, x, y, temp);
- if (rb->DepthBits == 16) {
+ if (depthBits == 16) {
for (i = 0; i < n; i++) {
GLuint z = temp[i];
depth[i] = (z << 16) | z;
}
}
else {
- GLuint shift = 16 - rb->DepthBits;
+ GLuint shift = 16 - depthBits;
for (i = 0; i < n; i++) {
GLuint z = temp[i];
depth[i] = (z << (shift + 16)) | (z << shift); /* XXX lsb bits? */