remove ^M chars, disable shading language extensions
[mesa.git] / src / mesa / main / api_validate.c
index f6193aec556d43f06299425ccd864058b2330f86..d1c8f42e7472c53d1910cc274cd876825237e506 100644 (file)
@@ -1,7 +1,6 @@
-
 /*
  * Mesa 3-D graphics library
- * Version:  5.1
+ * Version:  6.1
  *
  * Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
  *
@@ -62,9 +61,46 @@ _mesa_validate_DrawElements(GLcontext *ctx,
 
    /* Always need vertex positions */
    if (!ctx->Array.Vertex.Enabled
-       && !(ctx->VertexProgram.Enabled && ctx->Array.VertexAttrib[0].Enabled))
+       && !(ctx->VertexProgram._Enabled && ctx->Array.VertexAttrib[0].Enabled))
       return GL_FALSE;
 
+   /* Vertex buffer object tests */
+   if (ctx->Array.ElementArrayBufferObj->Name) {
+      GLuint indexBytes;
+
+      /* use indices in the buffer object */
+      if (!ctx->Array.ElementArrayBufferObj->Data) {
+         _mesa_warning(ctx, "DrawElements with empty vertex elements buffer!");
+         return GL_FALSE;
+      }
+
+      /* make sure count doesn't go outside buffer bounds */
+      if (type == GL_UNSIGNED_INT) {
+         indexBytes = count * sizeof(GLuint);
+      }
+      else if (type == GL_UNSIGNED_BYTE) {
+         indexBytes = count * sizeof(GLubyte);
+      }
+      else {
+         ASSERT(type == GL_UNSIGNED_SHORT);
+         indexBytes = count * sizeof(GLushort);
+      }
+
+      if ((GLubyte *) indices + indexBytes >
+          ctx->Array.ElementArrayBufferObj->Data +
+          ctx->Array.ElementArrayBufferObj->Size) {
+         _mesa_warning(ctx, "glDrawElements index out of buffer bounds");
+         return GL_FALSE;
+      }
+
+      /* Actual address is the sum of pointers.  Indices may be used below. */
+      if (ctx->Const.CheckArrayBounds) {
+         indices = (const GLvoid *)
+            ADD_POINTERS(ctx->Array.ElementArrayBufferObj->Data,
+                         (const GLubyte *) indices);
+      }
+   }
+
    if (ctx->Const.CheckArrayBounds) {
       /* find max array index */
       GLuint max = 0;
@@ -131,7 +167,7 @@ _mesa_validate_DrawRangeElements(GLcontext *ctx, GLenum mode,
 
    /* Always need vertex positions */
    if (!ctx->Array.Vertex.Enabled
-       && !(ctx->VertexProgram.Enabled && ctx->Array.VertexAttrib[0].Enabled))
+       && !(ctx->VertexProgram._Enabled && ctx->Array.VertexAttrib[0].Enabled))
       return GL_FALSE;
 
    if (ctx->Const.CheckArrayBounds) {
@@ -190,12 +226,11 @@ _mesa_validate_DrawArrays(GLcontext *ctx,
       _mesa_update_state(ctx);
 
    /* Always need vertex positions */
-   if (!ctx->Array.Vertex.Enabled
-       && !(ctx->VertexProgram.Enabled && ctx->Array.VertexAttrib[0].Enabled))
+   if (!ctx->Array.Vertex.Enabled && !ctx->Array.VertexAttrib[0].Enabled)
       return GL_FALSE;
 
    if (ctx->Const.CheckArrayBounds) {
-      if (start + count > ctx->Array._MaxElement)
+      if (start + count > (GLint) ctx->Array._MaxElement)
          return GL_FALSE;
    }