added _swrast_get_row()
authorBrian Paul <brian.paul@tungstengraphics.com>
Fri, 30 Sep 2005 03:00:03 +0000 (03:00 +0000)
committerBrian Paul <brian.paul@tungstengraphics.com>
Fri, 30 Sep 2005 03:00:03 +0000 (03:00 +0000)
src/mesa/swrast/s_span.c
src/mesa/swrast/s_span.h

index a974506..b6d4098 100644 (file)
@@ -1508,3 +1508,36 @@ _swrast_put_row(GLcontext *ctx, struct gl_renderbuffer *rb,
    rb->PutRow(ctx, rb, count, x, y,
               (const GLubyte *) values + skip * valueSize, NULL);
 }
+
+
+/**
+ * Wrapper for gl_renderbuffer::GetRow() which does clipping.
+ */
+void
+_swrast_get_row(GLcontext *ctx, struct gl_renderbuffer *rb,
+                GLuint count, GLint x, GLint y,
+                GLvoid *values, GLuint valueSize)
+{
+   GLint skip = 0;
+
+   if (y < 0 || y >= rb->Height)
+      return; /* above or below */
+
+   if (x + (GLint) count <= 0 || x >= rb->Width)
+      return; /* entirely left or right */
+
+   if (x + count > rb->Width) {
+      /* right clip */
+      GLint clip = x + count - rb->Width;
+      count -= clip;
+   }
+
+   if (x < 0) {
+      /* left clip */
+      skip = -x;
+      x = 0;
+      count -= skip;
+   }
+
+   rb->GetRow(ctx, rb, count, x, y, (GLubyte *) values + skip * valueSize);
+}
index 0c85374..40a57e1 100644 (file)
@@ -77,4 +77,9 @@ _swrast_put_row(GLcontext *ctx, struct gl_renderbuffer *rb,
                 GLuint count, GLint x, GLint y,
                 const GLvoid *values, GLuint valueSize);
 
+extern void
+_swrast_get_row(GLcontext *ctx, struct gl_renderbuffer *rb,
+                GLuint count, GLint x, GLint y,
+                GLvoid *values, GLuint valueSize);
+
 #endif