mesa: replace _mesa_problem() with assert() in hash table
[mesa.git] / src / mesa / main / scissor.c
index 2b568e4926b18d7fad6258e4cc594fb7a80bf9c5..631ea4d32055accc70d40fb8b30fa48c9e9893bc 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "main/glheader.h"
 #include "main/context.h"
+#include "main/enums.h"
 #include "main/mtypes.h"
 #include "main/scissor.h"
 
@@ -213,7 +214,53 @@ _mesa_ScissorIndexedv(GLuint index, const GLint *v)
 void GLAPIENTRY
 _mesa_WindowRectanglesEXT(GLenum mode, GLsizei count, const GLint *box)
 {
+   int i;
+   struct gl_scissor_rect newval[MAX_WINDOW_RECTANGLES];
+   GET_CURRENT_CONTEXT(ctx);
+
+   if (MESA_VERBOSE & VERBOSE_API)
+      _mesa_debug(ctx, "glWindowRectanglesEXT(%s, %d, %p)\n",
+                  _mesa_enum_to_string(mode), count, box);
+
+   if (mode != GL_INCLUSIVE_EXT && mode != GL_EXCLUSIVE_EXT) {
+      _mesa_error(ctx, GL_INVALID_ENUM,
+                  "glWindowRectanglesEXT(invalid mode 0x%x)", mode);
+      return;
+   }
+
+   if (count < 0) {
+      _mesa_error(ctx, GL_INVALID_VALUE, "glWindowRectanglesEXT(count < 0)");
+      return;
+   }
+
+   if (count > ctx->Const.MaxWindowRectangles) {
+      _mesa_error(ctx, GL_INVALID_VALUE,
+                  "glWindowRectanglesEXT(count >= MaxWindowRectangles (%d)",
+                  ctx->Const.MaxWindowRectangles);
+      return;
+   }
+
+   for (i = 0; i < count; i++) {
+      if (box[2] < 0 || box[3] < 0) {
+         _mesa_error(ctx, GL_INVALID_VALUE,
+                     "glWindowRectanglesEXT(box %d: w < 0 || h < 0)", i);
+         return;
+      }
+      newval[i].X = box[0];
+      newval[i].Y = box[1];
+      newval[i].Width = box[2];
+      newval[i].Height = box[3];
+      box += 4;
+   }
+
+   FLUSH_VERTICES(ctx, _NEW_SCISSOR);
+   memcpy(ctx->Scissor.WindowRects, newval,
+          sizeof(struct gl_scissor_rect) * count);
+   ctx->Scissor.NumWindowRects = count;
+   ctx->Scissor.WindowRectMode = mode;
 
+   if (ctx->Driver.Scissor)
+      ctx->Driver.Scissor(ctx);
 }
 
 
@@ -228,6 +275,7 @@ _mesa_init_scissor(struct gl_context *ctx)
 
    /* Scissor group */
    ctx->Scissor.EnableFlags = 0;
+   ctx->Scissor.WindowRectMode = GL_EXCLUSIVE_EXT;
 
    /* Note: ctx->Const.MaxViewports may not have been set by the driver yet,
     * so just initialize all of them.