api_validate.c revision 6bf0ac0916bf09e049b378d94478035072efed53
1cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell/*
2cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * Mesa 3-D graphics library
3a3c3bc9ece7e7c55c8832dbc8c50ab1c34f5bfe9Brian * Version:  7.1
4cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell *
537ece4df7c654b30b6720044b35a83694d7e5bb3Brian * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
6cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell *
7cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a
8cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * copy of this software and associated documentation files (the "Software"),
9cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * to deal in the Software without restriction, including without limitation
10cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * and/or sell copies of the Software, and to permit persons to whom the
12cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * Software is furnished to do so, subject to the following conditions:
13cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell *
14cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * The above copyright notice and this permission notice shall be included
15cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * in all copies or substantial portions of the Software.
16cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell *
17cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell */
24cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
25cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#include "glheader.h"
268446d1bab15ef82b35b8980a0a56072ace6feb04Brian Paul#include "api_validate.h"
27434ec3ada841915a00ffc23f699401eb3e7b37eeBrian Paul#include "bufferobj.h"
28cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#include "context.h"
293c63452e64df7e10aa073c6c3b9492b1d7dabbb8Brian Paul#include "imports.h"
306bf0ac0916bf09e049b378d94478035072efed53Vinson Lee#include "mfeatures.h"
31cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#include "mtypes.h"
3292d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt#include "vbo/vbo.h"
3358e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell
34bb1fb2a5444c6b7d83ccb47949f60ed9fb4f0f93Brian Paul
35bb1fb2a5444c6b7d83ccb47949f60ed9fb4f0f93Brian Paul/**
36bb1fb2a5444c6b7d83ccb47949f60ed9fb4f0f93Brian Paul * \return  number of bytes in array [count] of type.
37bb1fb2a5444c6b7d83ccb47949f60ed9fb4f0f93Brian Paul */
38bb1fb2a5444c6b7d83ccb47949f60ed9fb4f0f93Brian Paulstatic GLsizei
39bb1fb2a5444c6b7d83ccb47949f60ed9fb4f0f93Brian Paulindex_bytes(GLenum type, GLsizei count)
40bb1fb2a5444c6b7d83ccb47949f60ed9fb4f0f93Brian Paul{
41bb1fb2a5444c6b7d83ccb47949f60ed9fb4f0f93Brian Paul   if (type == GL_UNSIGNED_INT) {
42bb1fb2a5444c6b7d83ccb47949f60ed9fb4f0f93Brian Paul      return count * sizeof(GLuint);
43bb1fb2a5444c6b7d83ccb47949f60ed9fb4f0f93Brian Paul   }
44bb1fb2a5444c6b7d83ccb47949f60ed9fb4f0f93Brian Paul   else if (type == GL_UNSIGNED_BYTE) {
45bb1fb2a5444c6b7d83ccb47949f60ed9fb4f0f93Brian Paul      return count * sizeof(GLubyte);
46bb1fb2a5444c6b7d83ccb47949f60ed9fb4f0f93Brian Paul   }
47bb1fb2a5444c6b7d83ccb47949f60ed9fb4f0f93Brian Paul   else {
48bb1fb2a5444c6b7d83ccb47949f60ed9fb4f0f93Brian Paul      ASSERT(type == GL_UNSIGNED_SHORT);
49bb1fb2a5444c6b7d83ccb47949f60ed9fb4f0f93Brian Paul      return count * sizeof(GLushort);
50bb1fb2a5444c6b7d83ccb47949f60ed9fb4f0f93Brian Paul   }
51bb1fb2a5444c6b7d83ccb47949f60ed9fb4f0f93Brian Paul}
52bb1fb2a5444c6b7d83ccb47949f60ed9fb4f0f93Brian Paul
53bb1fb2a5444c6b7d83ccb47949f60ed9fb4f0f93Brian Paul
54d8c6719f95b1543296ac954f95d13b048ae48634Brian/**
55e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul * Find the max index in the given element/index buffer
56e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul */
57e5d29ebb5e5dd923c9c60972170d072120007aabBrian PaulGLuint
58f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_max_buffer_index(struct gl_context *ctx, GLuint count, GLenum type,
59e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul                       const void *indices,
60e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul                       struct gl_buffer_object *elementBuf)
61e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul{
62e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul   const GLubyte *map = NULL;
63e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul   GLuint max = 0;
64e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul   GLuint i;
65e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul
66e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul   if (_mesa_is_bufferobj(elementBuf)) {
67e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul      /* elements are in a user-defined buffer object.  need to map it */
68e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul      map = ctx->Driver.MapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER,
69e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul                                  GL_READ_ONLY, elementBuf);
70e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul      /* Actual address is the sum of pointers */
71e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul      indices = (const GLvoid *) ADD_POINTERS(map, (const GLubyte *) indices);
72e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul   }
73e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul
74e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul   if (type == GL_UNSIGNED_INT) {
75e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul      for (i = 0; i < count; i++)
76e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul         if (((GLuint *) indices)[i] > max)
77e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul            max = ((GLuint *) indices)[i];
78e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul   }
79e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul   else if (type == GL_UNSIGNED_SHORT) {
80e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul      for (i = 0; i < count; i++)
81e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul         if (((GLushort *) indices)[i] > max)
82e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul            max = ((GLushort *) indices)[i];
83e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul   }
84e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul   else {
85e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul      ASSERT(type == GL_UNSIGNED_BYTE);
86e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul      for (i = 0; i < count; i++)
87e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul         if (((GLubyte *) indices)[i] > max)
88e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul            max = ((GLubyte *) indices)[i];
89e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul   }
90e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul
91e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul   if (map) {
92e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul      ctx->Driver.UnmapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER_ARB, elementBuf);
93e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul   }
94e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul
95e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul   return max;
96e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul}
97e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul
98e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul
99e5d29ebb5e5dd923c9c60972170d072120007aabBrian Paul/**
100b6e5600bd460245afef605dbfbcf6650ff677dcbBrian Paul * Check if OK to draw arrays/elements.
10188af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul */
102263b96e160606975285154c4b8b610fcb8f4c930Alan Hourihanestatic GLboolean
103f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcheck_valid_to_render(struct gl_context *ctx, const char *function)
104263b96e160606975285154c4b8b610fcb8f4c930Alan Hourihane{
105b6e5600bd460245afef605dbfbcf6650ff677dcbBrian Paul   if (!_mesa_valid_to_render(ctx, function)) {
106263b96e160606975285154c4b8b610fcb8f4c930Alan Hourihane      return GL_FALSE;
107263b96e160606975285154c4b8b610fcb8f4c930Alan Hourihane   }
108263b96e160606975285154c4b8b610fcb8f4c930Alan Hourihane
109f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg   switch (ctx->API) {
11097dd2ddbd97ba95e8bc8ab572ec05e8081556e1eBrian Paul#if FEATURE_es2_glsl
111f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg   case API_OPENGLES2:
112f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg      /* For ES2, we can draw if any vertex array is enabled (and we
113f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg       * should always have a vertex program/shader). */
114f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg      if (ctx->Array.ArrayObj->_Enabled == 0x0 || !ctx->VertexProgram._Current)
115f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg	 return GL_FALSE;
116f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg      break;
117f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg#endif
118f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg
119f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg#if FEATURE_ES1 || FEATURE_GL
120f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg   case API_OPENGLES:
121f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg   case API_OPENGL:
122f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg      /* For regular OpenGL, only draw if we have vertex positions
123f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg       * (regardless of whether or not we have a vertex program/shader). */
124f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg      if (!ctx->Array.ArrayObj->Vertex.Enabled &&
125f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg	  !ctx->Array.ArrayObj->VertexAttrib[0].Enabled)
126f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg	 return GL_FALSE;
127f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg      break;
12897dd2ddbd97ba95e8bc8ab572ec05e8081556e1eBrian Paul#endif
129263b96e160606975285154c4b8b610fcb8f4c930Alan Hourihane
130f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg   default:
131f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg      ASSERT_NO_FEATURE();
132f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg   }
133f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg
134263b96e160606975285154c4b8b610fcb8f4c930Alan Hourihane   return GL_TRUE;
135263b96e160606975285154c4b8b610fcb8f4c930Alan Hourihane}
136d8c6719f95b1543296ac954f95d13b048ae48634Brian
137e9968ebfa40b4740601c1596950ebd3f168664b0Brian Paul
138e9968ebfa40b4740601c1596950ebd3f168664b0Brian Paul/**
139e9968ebfa40b4740601c1596950ebd3f168664b0Brian Paul * Do bounds checking on array element indexes.  Check that the vertices
140e9968ebfa40b4740601c1596950ebd3f168664b0Brian Paul * pointed to by the indices don't lie outside buffer object bounds.
141e9968ebfa40b4740601c1596950ebd3f168664b0Brian Paul * \return GL_TRUE if OK, GL_FALSE if any indexed vertex goes is out of bounds
142e9968ebfa40b4740601c1596950ebd3f168664b0Brian Paul */
14392d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholtstatic GLboolean
144f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcheck_index_bounds(struct gl_context *ctx, GLsizei count, GLenum type,
14592d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt		   const GLvoid *indices, GLint basevertex)
14692d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt{
14792d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt   struct _mesa_prim prim;
14892d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt   struct _mesa_index_buffer ib;
14992d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt   GLuint min, max;
15092d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt
15192d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt   /* Only the X Server needs to do this -- otherwise, accessing outside
15292d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt    * array/BO bounds allows application termination.
15392d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt    */
15492d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt   if (!ctx->Const.CheckArrayBounds)
15592d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt      return GL_TRUE;
15692d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt
15792d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt   memset(&prim, 0, sizeof(prim));
15892d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt   prim.count = count;
15992d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt
16092d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt   memset(&ib, 0, sizeof(ib));
16192d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt   ib.type = type;
16292d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt   ib.ptr = indices;
16392d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt   ib.obj = ctx->Array.ElementArrayBufferObj;
16492d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt
16592d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt   vbo_get_minmax_index(ctx, &prim, &ib, &min, &max);
16692d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt
167391b396f3fb300a912e6d9bfbf26f49cc30e52dfMichel Dänzer   if ((int)(min + basevertex) < 0 ||
16892d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt       max + basevertex > ctx->Array.ArrayObj->_MaxElement) {
16992d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt      /* the max element is out of bounds of one or more enabled arrays */
170e9968ebfa40b4740601c1596950ebd3f168664b0Brian Paul      _mesa_warning(ctx, "glDrawElements() index=%u is out of bounds (max=%u)",
171e9968ebfa40b4740601c1596950ebd3f168664b0Brian Paul                    max, ctx->Array.ArrayObj->_MaxElement);
17292d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt      return GL_FALSE;
17392d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt   }
17492d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt
17592d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt   return GL_TRUE;
17692d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt}
17788af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul
178e9968ebfa40b4740601c1596950ebd3f168664b0Brian Paul
17988af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul/**
18088af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul * Error checking for glDrawElements().  Includes parameter checking
18188af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul * and VBO bounds checking.
18288af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul * \return GL_TRUE if OK to render, GL_FALSE if error found
18388af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul */
184cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith WhitwellGLboolean
185f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_validate_DrawElements(struct gl_context *ctx,
18622144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes			    GLenum mode, GLsizei count, GLenum type,
18792d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt			    const GLvoid *indices, GLint basevertex)
188cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell{
189cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
190cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
191cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   if (count <= 0) {
192cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      if (count < 0)
19308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul	 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawElements(count)" );
194cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      return GL_FALSE;
195cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   }
196cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
197df0831f3750918ce3cd9cc1f5610bafc8b87c8e4Zack Rusin   if (mode > GL_TRIANGLE_STRIP_ADJACENCY_ARB) {
198a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul      _mesa_error(ctx, GL_INVALID_ENUM, "glDrawElements(mode)" );
199cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      return GL_FALSE;
200cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   }
201cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
20222144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes   if (type != GL_UNSIGNED_INT &&
20322144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes       type != GL_UNSIGNED_BYTE &&
204cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell       type != GL_UNSIGNED_SHORT)
205cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   {
20608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul      _mesa_error(ctx, GL_INVALID_ENUM, "glDrawElements(type)" );
207cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      return GL_FALSE;
208cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   }
209cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
210a48b0a5ce7fc17eab4daa375fb95768fa2f50825Brian Paul   if (!check_valid_to_render(ctx, "glDrawElements"))
211a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul      return GL_FALSE;
212a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul
21303e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul   /* Vertex buffer object tests */
214434ec3ada841915a00ffc23f699401eb3e7b37eeBrian Paul   if (_mesa_is_bufferobj(ctx->Array.ElementArrayBufferObj)) {
21503e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul      /* use indices in the buffer object */
216d8c6719f95b1543296ac954f95d13b048ae48634Brian      /* make sure count doesn't go outside buffer bounds */
217bb1fb2a5444c6b7d83ccb47949f60ed9fb4f0f93Brian Paul      if (index_bytes(type, count) > ctx->Array.ElementArrayBufferObj->Size) {
21803e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul         _mesa_warning(ctx, "glDrawElements index out of buffer bounds");
21903e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul         return GL_FALSE;
22003e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul      }
22103e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul   }
22237ece4df7c654b30b6720044b35a83694d7e5bb3Brian   else {
22337ece4df7c654b30b6720044b35a83694d7e5bb3Brian      /* not using a VBO */
22437ece4df7c654b30b6720044b35a83694d7e5bb3Brian      if (!indices)
22537ece4df7c654b30b6720044b35a83694d7e5bb3Brian         return GL_FALSE;
22637ece4df7c654b30b6720044b35a83694d7e5bb3Brian   }
22703e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul
22892d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt   if (!check_index_bounds(ctx, count, type, indices, basevertex))
22992d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt      return GL_FALSE;
230cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
231cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   return GL_TRUE;
232cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell}
233cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
23488af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul
23588af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul/**
23688af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul * Error checking for glDrawRangeElements().  Includes parameter checking
23788af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul * and VBO bounds checking.
23888af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul * \return GL_TRUE if OK to render, GL_FALSE if error found
23988af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul */
240cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith WhitwellGLboolean
241f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_validate_DrawRangeElements(struct gl_context *ctx, GLenum mode,
24222144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes				 GLuint start, GLuint end,
24322144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes				 GLsizei count, GLenum type,
24492d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt				 const GLvoid *indices, GLint basevertex)
245cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell{
24622144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
247cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
248cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   if (count <= 0) {
249cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      if (count < 0)
250a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul	 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawRangeElements(count)" );
251cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      return GL_FALSE;
252cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   }
253cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
254df0831f3750918ce3cd9cc1f5610bafc8b87c8e4Zack Rusin   if (mode > GL_TRIANGLE_STRIP_ADJACENCY_ARB) {
255a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul      _mesa_error(ctx, GL_INVALID_ENUM, "glDrawRangeElements(mode)" );
256cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      return GL_FALSE;
257cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   }
258cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
259cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   if (end < start) {
26008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul      _mesa_error(ctx, GL_INVALID_VALUE, "glDrawRangeElements(end<start)");
261cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      return GL_FALSE;
262cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   }
263cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
26422144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes   if (type != GL_UNSIGNED_INT &&
26522144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes       type != GL_UNSIGNED_BYTE &&
26661bac6014aa15e0bec134e290aebac18f9815299Brian Paul       type != GL_UNSIGNED_SHORT) {
267a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul      _mesa_error(ctx, GL_INVALID_ENUM, "glDrawRangeElements(type)" );
268cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      return GL_FALSE;
269cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   }
270cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
271a48b0a5ce7fc17eab4daa375fb95768fa2f50825Brian Paul   if (!check_valid_to_render(ctx, "glDrawRangeElements"))
272a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul      return GL_FALSE;
273a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul
27437ece4df7c654b30b6720044b35a83694d7e5bb3Brian   /* Vertex buffer object tests */
275434ec3ada841915a00ffc23f699401eb3e7b37eeBrian Paul   if (_mesa_is_bufferobj(ctx->Array.ElementArrayBufferObj)) {
276d8c6719f95b1543296ac954f95d13b048ae48634Brian      /* use indices in the buffer object */
277d8c6719f95b1543296ac954f95d13b048ae48634Brian      /* make sure count doesn't go outside buffer bounds */
278bb1fb2a5444c6b7d83ccb47949f60ed9fb4f0f93Brian Paul      if (index_bytes(type, count) > ctx->Array.ElementArrayBufferObj->Size) {
279ef5935bc94a1439eb8f1731732a3eabd0e360407Brian         _mesa_warning(ctx, "glDrawRangeElements index out of buffer bounds");
280d8c6719f95b1543296ac954f95d13b048ae48634Brian         return GL_FALSE;
281d8c6719f95b1543296ac954f95d13b048ae48634Brian      }
28237ece4df7c654b30b6720044b35a83694d7e5bb3Brian   }
28337ece4df7c654b30b6720044b35a83694d7e5bb3Brian   else {
284d8c6719f95b1543296ac954f95d13b048ae48634Brian      /* not using a VBO */
28537ece4df7c654b30b6720044b35a83694d7e5bb3Brian      if (!indices)
28637ece4df7c654b30b6720044b35a83694d7e5bb3Brian         return GL_FALSE;
28737ece4df7c654b30b6720044b35a83694d7e5bb3Brian   }
28837ece4df7c654b30b6720044b35a83694d7e5bb3Brian
28992d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt   if (!check_index_bounds(ctx, count, type, indices, basevertex))
29092d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt      return GL_FALSE;
291a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul
292c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul   return GL_TRUE;
293c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul}
294c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul
295cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
296c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul/**
297c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul * Called from the tnl module to error check the function parameters and
298c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul * verify that we really can draw something.
29988af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul * \return GL_TRUE if OK to render, GL_FALSE if error found
300c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul */
301cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith WhitwellGLboolean
302f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_validate_DrawArrays(struct gl_context *ctx,
303cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell			  GLenum mode, GLint start, GLsizei count)
304cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell{
30522144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
306cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
3075cb203433ab5c4e54a7386a816263a237c716aa2Brian   if (count <= 0) {
3085cb203433ab5c4e54a7386a816263a237c716aa2Brian      if (count < 0)
3095cb203433ab5c4e54a7386a816263a237c716aa2Brian         _mesa_error(ctx, GL_INVALID_VALUE, "glDrawArrays(count)" );
310cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      return GL_FALSE;
311cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   }
312cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
313df0831f3750918ce3cd9cc1f5610bafc8b87c8e4Zack Rusin   if (mode > GL_TRIANGLE_STRIP_ADJACENCY_ARB) {
31408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul      _mesa_error(ctx, GL_INVALID_ENUM, "glDrawArrays(mode)" );
315cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      return GL_FALSE;
316cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   }
317cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
318a48b0a5ce7fc17eab4daa375fb95768fa2f50825Brian Paul   if (!check_valid_to_render(ctx, "glDrawArrays"))
319c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul      return GL_FALSE;
320c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul
321a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul   if (ctx->Const.CheckArrayBounds) {
322a185bcbdec856cc98c26098e4e447a683eed14d1Brian Paul      if (start + count > (GLint) ctx->Array.ArrayObj->_MaxElement)
323c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul         return GL_FALSE;
324a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul   }
325c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul
326c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul   return GL_TRUE;
327cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell}
328cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul
329cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul
330cf3193ad1cd75b847c5d626def701a4bb012d080Brian PaulGLboolean
331f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_validate_DrawArraysInstanced(struct gl_context *ctx, GLenum mode, GLint first,
332cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul                                   GLsizei count, GLsizei primcount)
333cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul{
334cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
335cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul
336cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   if (count <= 0) {
337cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul      if (count < 0)
338cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul         _mesa_error(ctx, GL_INVALID_VALUE,
339cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul                     "glDrawArraysInstanced(count=%d)", count);
340cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul      return GL_FALSE;
341cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   }
342cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul
343df0831f3750918ce3cd9cc1f5610bafc8b87c8e4Zack Rusin   if (mode > GL_TRIANGLE_STRIP_ADJACENCY_ARB) {
344cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul      _mesa_error(ctx, GL_INVALID_ENUM,
345cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul                  "glDrawArraysInstanced(mode=0x%x)", mode);
346cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul      return GL_FALSE;
347cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   }
348cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul
349cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   if (primcount <= 0) {
350cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul      if (primcount < 0)
351cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul         _mesa_error(ctx, GL_INVALID_VALUE,
352cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul                     "glDrawArraysInstanced(primcount=%d)", primcount);
353cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul      return GL_FALSE;
354cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   }
355cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul
356cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   if (!check_valid_to_render(ctx, "glDrawArraysInstanced(invalid to render)"))
357cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul      return GL_FALSE;
358cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul
359cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   if (ctx->CompileFlag) {
360cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul      _mesa_error(ctx, GL_INVALID_OPERATION,
361cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul                  "glDrawArraysInstanced(display list");
362cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul      return GL_FALSE;
363cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   }
364cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul
365cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   if (ctx->Const.CheckArrayBounds) {
366cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul      if (first + count > (GLint) ctx->Array.ArrayObj->_MaxElement)
367cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul         return GL_FALSE;
368cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   }
369cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul
370cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   return GL_TRUE;
371cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul}
372cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul
373cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul
374cf3193ad1cd75b847c5d626def701a4bb012d080Brian PaulGLboolean
375f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_validate_DrawElementsInstanced(struct gl_context *ctx,
376cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul                                     GLenum mode, GLsizei count, GLenum type,
377cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul                                     const GLvoid *indices, GLsizei primcount)
378cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul{
379cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
380cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul
381cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   if (count <= 0) {
382cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul      if (count < 0)
383cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul	 _mesa_error(ctx, GL_INVALID_VALUE,
384cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul                     "glDrawElementsInstanced(count=%d)", count);
385cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul      return GL_FALSE;
386cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   }
387cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul
388df0831f3750918ce3cd9cc1f5610bafc8b87c8e4Zack Rusin   if (mode > GL_TRIANGLE_STRIP_ADJACENCY_ARB) {
389cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul      _mesa_error(ctx, GL_INVALID_ENUM,
390cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul                  "glDrawElementsInstanced(mode = 0x%x)", mode);
391cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul      return GL_FALSE;
392cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   }
393cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul
394cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   if (type != GL_UNSIGNED_INT &&
395cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul       type != GL_UNSIGNED_BYTE &&
396cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul       type != GL_UNSIGNED_SHORT) {
397cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul      _mesa_error(ctx, GL_INVALID_ENUM,
398cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul                  "glDrawElementsInstanced(type=0x%x)", type);
399cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul      return GL_FALSE;
400cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   }
401cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul
402cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   if (primcount <= 0) {
403cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul      if (primcount < 0)
404cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul         _mesa_error(ctx, GL_INVALID_VALUE,
405cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul                     "glDrawElementsInstanced(primcount=%d)", primcount);
406cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul      return GL_FALSE;
407cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   }
408cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul
409cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   if (!check_valid_to_render(ctx, "glDrawElementsInstanced"))
410cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul      return GL_FALSE;
411cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul
412cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   /* Vertex buffer object tests */
413cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   if (_mesa_is_bufferobj(ctx->Array.ElementArrayBufferObj)) {
414cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul      /* use indices in the buffer object */
415cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul      /* make sure count doesn't go outside buffer bounds */
416cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul      if (index_bytes(type, count) > ctx->Array.ElementArrayBufferObj->Size) {
417cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul         _mesa_warning(ctx,
418cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul                       "glDrawElementsInstanced index out of buffer bounds");
419cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul         return GL_FALSE;
420cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul      }
421cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   }
422cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   else {
423cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul      /* not using a VBO */
424cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul      if (!indices)
425cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul         return GL_FALSE;
426cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   }
427cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul
428cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   if (!check_index_bounds(ctx, count, type, indices, 0))
429cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul      return GL_FALSE;
430cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul
431cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul   return GL_TRUE;
432cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul}
433