mesa: whitespace fixes, just to be consistent
[mesa.git] / src / mesa / main / api_validate.c
index 4929a9310d48a43243ae9ba8ee17e856ee4118f2..699b414f5021581e687e0fa8c5ca7ca2c7ebedd7 100644 (file)
@@ -27,6 +27,7 @@
 #include "bufferobj.h"
 #include "context.h"
 #include "imports.h"
+#include "mfeatures.h"
 #include "mtypes.h"
 #include "vbo/vbo.h"
 
@@ -64,8 +65,8 @@ _mesa_max_buffer_index(struct gl_context *ctx, GLuint count, GLenum type,
 
    if (_mesa_is_bufferobj(elementBuf)) {
       /* elements are in a user-defined buffer object.  need to map it */
-      map = ctx->Driver.MapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER,
-                                  GL_READ_ONLY, elementBuf);
+      map = ctx->Driver.MapBufferRange(ctx, 0, elementBuf->Size,
+                                      GL_MAP_READ_BIT, elementBuf);
       /* Actual address is the sum of pointers */
       indices = (const GLvoid *) ADD_POINTERS(map, (const GLubyte *) indices);
    }
@@ -88,7 +89,7 @@ _mesa_max_buffer_index(struct gl_context *ctx, GLuint count, GLenum type,
    }
 
    if (map) {
-      ctx->Driver.UnmapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER_ARB, elementBuf);
+      ctx->Driver.UnmapBuffer(ctx, elementBuf);
    }
 
    return max;
@@ -115,17 +116,39 @@ check_valid_to_render(struct gl_context *ctx, const char *function)
       break;
 #endif
 
-#if FEATURE_ES1 || FEATURE_GL
+#if FEATURE_ES1
    case API_OPENGLES:
-   case API_OPENGL:
-      /* For regular OpenGL, only draw if we have vertex positions
-       * (regardless of whether or not we have a vertex program/shader). */
-      if (!ctx->Array.ArrayObj->Vertex.Enabled &&
-         !ctx->Array.ArrayObj->VertexAttrib[0].Enabled)
+      /* For OpenGL ES, only draw if we have vertex positions
+       */
+      if (!ctx->Array.ArrayObj->Vertex.Enabled)
         return GL_FALSE;
       break;
 #endif
 
+#if FEATURE_GL
+   case API_OPENGL:
+      {
+         const struct gl_shader_program *vsProg =
+            ctx->Shader.CurrentVertexProgram;
+         GLboolean haveVertexShader = (vsProg && vsProg->LinkStatus);
+         GLboolean haveVertexProgram = ctx->VertexProgram._Enabled;
+         if (haveVertexShader || haveVertexProgram) {
+            /* Draw regardless of whether or not we have any vertex arrays.
+             * (Ex: could draw a point using a constant vertex pos)
+             */
+            return GL_TRUE;
+         }
+         else {
+            /* Draw if we have vertex positions (GL_VERTEX_ARRAY or generic
+             * array [0]).
+             */
+            return (ctx->Array.ArrayObj->Vertex.Enabled ||
+                    ctx->Array.ArrayObj->VertexAttrib[0].Enabled);
+         }
+      }
+      break;
+#endif
+
    default:
       ASSERT_NO_FEATURE();
    }
@@ -328,7 +351,7 @@ _mesa_validate_DrawArrays(struct gl_context *ctx,
 
 GLboolean
 _mesa_validate_DrawArraysInstanced(struct gl_context *ctx, GLenum mode, GLint first,
-                                   GLsizei count, GLsizei primcount)
+                                   GLsizei count, GLsizei numInstances)
 {
    ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
 
@@ -345,10 +368,10 @@ _mesa_validate_DrawArraysInstanced(struct gl_context *ctx, GLenum mode, GLint fi
       return GL_FALSE;
    }
 
-   if (primcount <= 0) {
-      if (primcount < 0)
+   if (numInstances <= 0) {
+      if (numInstances < 0)
          _mesa_error(ctx, GL_INVALID_VALUE,
-                     "glDrawArraysInstanced(primcount=%d)", primcount);
+                     "glDrawArraysInstanced(numInstances=%d)", numInstances);
       return GL_FALSE;
    }
 
@@ -373,7 +396,8 @@ _mesa_validate_DrawArraysInstanced(struct gl_context *ctx, GLenum mode, GLint fi
 GLboolean
 _mesa_validate_DrawElementsInstanced(struct gl_context *ctx,
                                      GLenum mode, GLsizei count, GLenum type,
-                                     const GLvoid *indices, GLsizei primcount)
+                                     const GLvoid *indices, GLsizei numInstances,
+                                     GLint basevertex)
 {
    ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
 
@@ -398,10 +422,10 @@ _mesa_validate_DrawElementsInstanced(struct gl_context *ctx,
       return GL_FALSE;
    }
 
-   if (primcount <= 0) {
-      if (primcount < 0)
+   if (numInstances <= 0) {
+      if (numInstances < 0)
          _mesa_error(ctx, GL_INVALID_VALUE,
-                     "glDrawElementsInstanced(primcount=%d)", primcount);
+                     "glDrawElementsInstanced(numInstances=%d)", numInstances);
       return GL_FALSE;
    }
 
@@ -424,7 +448,7 @@ _mesa_validate_DrawElementsInstanced(struct gl_context *ctx,
          return GL_FALSE;
    }
 
-   if (!check_index_bounds(ctx, count, type, indices, 0))
+   if (!check_index_bounds(ctx, count, type, indices, basevertex))
       return GL_FALSE;
 
    return GL_TRUE;