r600c: eg: 256 float4 constants may need more than 256 bytes
[mesa.git] / src / mesa / main / polygon.c
index 564250b881cf10c3cdae0481fdeea63d265fbe9d..30e4a606bb79ea78819b02f50ea3b860f2f788fb 100644 (file)
@@ -34,7 +34,6 @@
 #include "context.h"
 #include "image.h"
 #include "enums.h"
-#include "macros.h"
 #include "polygon.h"
 #include "mtypes.h"
 
@@ -193,32 +192,16 @@ _mesa_PolygonMode( GLenum face, GLenum mode )
 void
 _mesa_polygon_stipple(GLcontext *ctx, const GLubyte *pattern)
 {
-   if (ctx->Unpack.BufferObj->Name) {
-      /* Get/unpack the stipple pattern from a PBO */
-      GLubyte *buf;
-      if (!_mesa_validate_pbo_access(2, &ctx->Unpack, 32, 32, 1,
-                                     GL_COLOR_INDEX, GL_BITMAP, pattern)) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "glPolygonStipple(bad PBO access)");
-         return;
-      }
-      buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
-                                              GL_READ_ONLY_ARB,
-                                              ctx->Unpack.BufferObj);
-      if (!buf) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "glPolygonStipple(PBO mapped)");
-         return;
-      }
-      buf = ADD_POINTERS(buf, pattern);
-      _mesa_unpack_polygon_stipple(buf, ctx->PolygonStipple, &ctx->Unpack);
-      ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
-                              ctx->Unpack.BufferObj);
-   }
-   else {
-      /* Get/unpack the stipple pattern from user memory */
-      _mesa_unpack_polygon_stipple(pattern, ctx->PolygonStipple, &ctx->Unpack);
-   }
+   pattern = _mesa_map_validate_pbo_source(ctx, 2,
+                                           &ctx->Unpack, 32, 32, 1,
+                                           GL_COLOR_INDEX, GL_BITMAP, pattern,
+                                           "glPolygonStipple");
+   if (!pattern)
+      return;
+
+   _mesa_unpack_polygon_stipple(pattern, ctx->PolygonStipple, &ctx->Unpack);
+
+   _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
 }
 
 
@@ -255,35 +238,16 @@ _mesa_GetPolygonStipple( GLubyte *dest )
    if (MESA_VERBOSE&VERBOSE_API)
       _mesa_debug(ctx, "glGetPolygonStipple\n");
 
-   /* XXX someday we may put this code into a separate function and call
-    * it with ctx->Driver.GetPolygonStipple().
-    */
-   if (ctx->Pack.BufferObj->Name) {
-      /* Put/pack the stipple pattern into a PBO */
-      GLubyte *buf;
-      if (!_mesa_validate_pbo_access(2, &ctx->Pack, 32, 32, 1,
-                                     GL_COLOR_INDEX, GL_BITMAP, dest)) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "glGetPolygonStipple(bad PBO access)");
-         return;
-      }
-      buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
-                                              GL_WRITE_ONLY_ARB,
-                                              ctx->Pack.BufferObj);
-      if (!buf) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "glGetPolygonStipple(PBO mapped)");
-         return;
-      }
-      buf = ADD_POINTERS(buf, dest);
-      _mesa_pack_polygon_stipple(ctx->PolygonStipple, buf, &ctx->Pack);
-      ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
-                              ctx->Pack.BufferObj);
-   }
-   else {
-      /* Put/pack the stipple pattern into user memory */
-      _mesa_pack_polygon_stipple(ctx->PolygonStipple, dest, &ctx->Pack);
-   }
+   dest = _mesa_map_validate_pbo_dest(ctx, 2,
+                                      &ctx->Pack, 32, 32, 1,
+                                      GL_COLOR_INDEX, GL_BITMAP, dest,
+                                      "glGetPolygonStipple");
+   if (!dest)
+      return;
+
+   _mesa_pack_polygon_stipple(ctx->PolygonStipple, dest, &ctx->Pack);
+
+   _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
 }
 
 
@@ -351,7 +315,7 @@ void _mesa_init_polygon( GLcontext * ctx )
 
 
    /* Polygon Stipple group */
-   MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
+   memset( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
 }
 
 /*@}*/