aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/swrast/s_depth.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2010-03-07 13:28:57 +0000
committermarha <marha@users.sourceforge.net>2010-03-07 13:28:57 +0000
commit14b1cb8d5a27ec9716d3f790fce95f0469e35605 (patch)
tree6c94dc9f37b19b995bec603141442b1b93e8c9d2 /mesalib/src/mesa/swrast/s_depth.c
parent93c85587c691f9b91e7c2d8bda50f453e0f6674d (diff)
downloadvcxsrv-14b1cb8d5a27ec9716d3f790fce95f0469e35605.tar.gz
vcxsrv-14b1cb8d5a27ec9716d3f790fce95f0469e35605.tar.bz2
vcxsrv-14b1cb8d5a27ec9716d3f790fce95f0469e35605.zip
Updated to Mesa 7.7
Diffstat (limited to 'mesalib/src/mesa/swrast/s_depth.c')
-rw-r--r--mesalib/src/mesa/swrast/s_depth.c50
1 files changed, 46 insertions, 4 deletions
diff --git a/mesalib/src/mesa/swrast/s_depth.c b/mesalib/src/mesa/swrast/s_depth.c
index 7086cae0c..c37a54eb3 100644
--- a/mesalib/src/mesa/swrast/s_depth.c
+++ b/mesalib/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"
@@ -497,6 +498,43 @@ depth_test_span32( GLcontext *ctx, GLuint n,
return passed;
}
+/* Apply ARB_depth_clamp to span of fragments. */
+void
+_swrast_depth_clamp_span( GLcontext *ctx, SWspan *span )
+{
+ struct gl_framebuffer *fb = ctx->DrawBuffer;
+ struct gl_renderbuffer *rb = fb->_DepthBuffer;
+ const GLuint count = span->end;
+ GLuint *zValues = span->array->z;
+ 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) {
+ CLAMPED_FLOAT_TO_USHORT(min, min_f);
+ CLAMPED_FLOAT_TO_USHORT(max, max_f);
+ } else {
+ assert(rb->DataType == GL_UNSIGNED_INT);
+ min = FLOAT_TO_UINT(min_f);
+ max = FLOAT_TO_UINT(max_f);
+ }
+
+ for (i = 0; i < count; i++) {
+ if (zValues[i] < min)
+ zValues[i] = min;
+ if (zValues[i] > max)
+ zValues[i] = max;
+ }
+}
+
/*
@@ -1272,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 ||
@@ -1309,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];
@@ -1322,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? */