api_validate.c revision a3c3bc9ece7e7c55c8832dbc8c50ab1c34f5bfe9
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" 27cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#include "context.h" 283c63452e64df7e10aa073c6c3b9492b1d7dabbb8Brian Paul#include "imports.h" 29cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#include "mtypes.h" 308446d1bab15ef82b35b8980a0a56072ace6feb04Brian Paul#include "state.h" 31cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 3258e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell 33cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith WhitwellGLboolean 34cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell_mesa_validate_DrawElements(GLcontext *ctx, 3522144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes GLenum mode, GLsizei count, GLenum type, 36cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell const GLvoid *indices) 37cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell{ 3822144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); 39cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 40cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (count <= 0) { 41cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (count < 0) 4208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glDrawElements(count)" ); 43cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 44cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 45cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 46464bc3b6747108dd32e4a9fcfe6549a9d4a52a95Brian Paul if (mode > GL_POLYGON) { 47a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glDrawElements(mode)" ); 48cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 49cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 50cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 5122144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes if (type != GL_UNSIGNED_INT && 5222144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes type != GL_UNSIGNED_BYTE && 53cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell type != GL_UNSIGNED_SHORT) 54cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell { 5508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glDrawElements(type)" ); 56cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 57cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 58cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 59cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (ctx->NewState) 60a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul _mesa_update_state(ctx); 61a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul 62a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul /* Always need vertex positions */ 63ee34e6ef716bb630440299ac1efbc2055ef09ffdIan Romanick if (!ctx->Array.ArrayObj->Vertex.Enabled 64ee34e6ef716bb630440299ac1efbc2055ef09ffdIan Romanick && !(ctx->VertexProgram._Enabled && ctx->Array.ArrayObj->VertexAttrib[0].Enabled)) 65a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul return GL_FALSE; 66a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul 6703e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul /* Vertex buffer object tests */ 6803e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul if (ctx->Array.ElementArrayBufferObj->Name) { 6903e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul GLuint indexBytes; 7003e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul 7103e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul /* use indices in the buffer object */ 72a3c3bc9ece7e7c55c8832dbc8c50ab1c34f5bfe9Brian if (!ctx->Array.ElementArrayBufferObj->Size) { 73a3c3bc9ece7e7c55c8832dbc8c50ab1c34f5bfe9Brian _mesa_warning(ctx, 74a3c3bc9ece7e7c55c8832dbc8c50ab1c34f5bfe9Brian "glDrawElements called with empty array elements buffer"); 7503e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul return GL_FALSE; 7603e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul } 7703e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul 7803e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul /* make sure count doesn't go outside buffer bounds */ 7903e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul if (type == GL_UNSIGNED_INT) { 8003e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul indexBytes = count * sizeof(GLuint); 8103e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul } 8203e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul else if (type == GL_UNSIGNED_BYTE) { 8303e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul indexBytes = count * sizeof(GLubyte); 8403e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul } 8503e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul else { 8603e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul ASSERT(type == GL_UNSIGNED_SHORT); 8703e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul indexBytes = count * sizeof(GLushort); 8803e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul } 8903e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul 90a3c3bc9ece7e7c55c8832dbc8c50ab1c34f5bfe9Brian if (indexBytes > ctx->Array.ElementArrayBufferObj->Size) { 9103e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul _mesa_warning(ctx, "glDrawElements index out of buffer bounds"); 9203e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul return GL_FALSE; 9303e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul } 9403e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul } 9537ece4df7c654b30b6720044b35a83694d7e5bb3Brian else { 9637ece4df7c654b30b6720044b35a83694d7e5bb3Brian /* not using a VBO */ 9737ece4df7c654b30b6720044b35a83694d7e5bb3Brian if (!indices) 9837ece4df7c654b30b6720044b35a83694d7e5bb3Brian return GL_FALSE; 9937ece4df7c654b30b6720044b35a83694d7e5bb3Brian } 10003e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul 101a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul if (ctx->Const.CheckArrayBounds) { 102a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul /* find max array index */ 103a3c3bc9ece7e7c55c8832dbc8c50ab1c34f5bfe9Brian const GLubyte *map; 104a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul GLuint max = 0; 105a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul GLint i; 106a3c3bc9ece7e7c55c8832dbc8c50ab1c34f5bfe9Brian 107a3c3bc9ece7e7c55c8832dbc8c50ab1c34f5bfe9Brian map = ctx->Driver.MapBuffer(ctx, 108a3c3bc9ece7e7c55c8832dbc8c50ab1c34f5bfe9Brian GL_ELEMENT_ARRAY_BUFFER_ARB, 109a3c3bc9ece7e7c55c8832dbc8c50ab1c34f5bfe9Brian GL_READ_ONLY, 110a3c3bc9ece7e7c55c8832dbc8c50ab1c34f5bfe9Brian ctx->Array.ElementArrayBufferObj); 111a3c3bc9ece7e7c55c8832dbc8c50ab1c34f5bfe9Brian 112a3c3bc9ece7e7c55c8832dbc8c50ab1c34f5bfe9Brian /* Actual address is the sum of pointers */ 113a3c3bc9ece7e7c55c8832dbc8c50ab1c34f5bfe9Brian indices = (const GLvoid *) ADD_POINTERS(map, (const GLubyte *) indices); 114a3c3bc9ece7e7c55c8832dbc8c50ab1c34f5bfe9Brian 115a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul if (type == GL_UNSIGNED_INT) { 116a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul for (i = 0; i < count; i++) 117a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul if (((GLuint *) indices)[i] > max) 118a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul max = ((GLuint *) indices)[i]; 119a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul } 120a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul else if (type == GL_UNSIGNED_SHORT) { 121a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul for (i = 0; i < count; i++) 122a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul if (((GLushort *) indices)[i] > max) 123a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul max = ((GLushort *) indices)[i]; 124a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul } 125a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul else { 126a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul ASSERT(type == GL_UNSIGNED_BYTE); 127a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul for (i = 0; i < count; i++) 128a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul if (((GLubyte *) indices)[i] > max) 129a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul max = ((GLubyte *) indices)[i]; 130a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul } 1312394d20dafdfa308d494fc739c63c6a4e91c8185Xiang, Haihao 132a3c3bc9ece7e7c55c8832dbc8c50ab1c34f5bfe9Brian ctx->Driver.UnmapBuffer(ctx, 133a3c3bc9ece7e7c55c8832dbc8c50ab1c34f5bfe9Brian GL_ELEMENT_ARRAY_BUFFER_ARB, 134a3c3bc9ece7e7c55c8832dbc8c50ab1c34f5bfe9Brian ctx->Array.ElementArrayBufferObj); 135a3c3bc9ece7e7c55c8832dbc8c50ab1c34f5bfe9Brian 136a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul if (max >= ctx->Array._MaxElement) { 137a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul /* the max element is out of bounds of one or more enabled arrays */ 138a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul return GL_FALSE; 139a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul } 140a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul } 141cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 142cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_TRUE; 143cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell} 144cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 145cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 146cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith WhitwellGLboolean 14722144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes_mesa_validate_DrawRangeElements(GLcontext *ctx, GLenum mode, 14822144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes GLuint start, GLuint end, 14922144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes GLsizei count, GLenum type, 150cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell const GLvoid *indices) 151cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell{ 15222144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); 153cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 154cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (count <= 0) { 155cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (count < 0) 156a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glDrawRangeElements(count)" ); 157cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 158cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 159cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 160464bc3b6747108dd32e4a9fcfe6549a9d4a52a95Brian Paul if (mode > GL_POLYGON) { 161a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glDrawRangeElements(mode)" ); 162cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 163cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 164cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 165cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (end < start) { 16608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glDrawRangeElements(end<start)"); 167cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 168cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 169cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 17022144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes if (type != GL_UNSIGNED_INT && 17122144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes type != GL_UNSIGNED_BYTE && 17261bac6014aa15e0bec134e290aebac18f9815299Brian Paul type != GL_UNSIGNED_SHORT) { 173a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glDrawRangeElements(type)" ); 174cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 175cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 176cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 177cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (ctx->NewState) 178a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul _mesa_update_state(ctx); 179a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul 180a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul /* Always need vertex positions */ 181ee34e6ef716bb630440299ac1efbc2055ef09ffdIan Romanick if (!ctx->Array.ArrayObj->Vertex.Enabled 182ee34e6ef716bb630440299ac1efbc2055ef09ffdIan Romanick && !(ctx->VertexProgram._Enabled && ctx->Array.ArrayObj->VertexAttrib[0].Enabled)) 183a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul return GL_FALSE; 184a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul 18537ece4df7c654b30b6720044b35a83694d7e5bb3Brian /* Vertex buffer object tests */ 18637ece4df7c654b30b6720044b35a83694d7e5bb3Brian if (ctx->Array.ElementArrayBufferObj->Name) { 18737ece4df7c654b30b6720044b35a83694d7e5bb3Brian /* XXX re-use code from above? */ 18837ece4df7c654b30b6720044b35a83694d7e5bb3Brian } 18937ece4df7c654b30b6720044b35a83694d7e5bb3Brian else { 19037ece4df7c654b30b6720044b35a83694d7e5bb3Brian /* not using VBO */ 19137ece4df7c654b30b6720044b35a83694d7e5bb3Brian if (!indices) 19237ece4df7c654b30b6720044b35a83694d7e5bb3Brian return GL_FALSE; 19337ece4df7c654b30b6720044b35a83694d7e5bb3Brian } 19437ece4df7c654b30b6720044b35a83694d7e5bb3Brian 195a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul if (ctx->Const.CheckArrayBounds) { 196a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul /* Find max array index. 197a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul * We don't trust the user's start and end values. 198a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul */ 199a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul GLuint max = 0; 200a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul GLint i; 201a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul if (type == GL_UNSIGNED_INT) { 202a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul for (i = 0; i < count; i++) 203a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul if (((GLuint *) indices)[i] > max) 204a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul max = ((GLuint *) indices)[i]; 205a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul } 206a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul else if (type == GL_UNSIGNED_SHORT) { 207a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul for (i = 0; i < count; i++) 208a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul if (((GLushort *) indices)[i] > max) 209a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul max = ((GLushort *) indices)[i]; 210a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul } 211a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul else { 212a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul ASSERT(type == GL_UNSIGNED_BYTE); 213a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul for (i = 0; i < count; i++) 214a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul if (((GLubyte *) indices)[i] > max) 215a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul max = ((GLubyte *) indices)[i]; 216a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul } 217a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul if (max >= ctx->Array._MaxElement) { 218a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul /* the max element is out of bounds of one or more enabled arrays */ 219c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul return GL_FALSE; 220a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul } 221c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul } 222a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul 223c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul return GL_TRUE; 224c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul} 225c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul 226cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 227c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul/** 228c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul * Called from the tnl module to error check the function parameters and 229c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul * verify that we really can draw something. 230c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul */ 231cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith WhitwellGLboolean 23222144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes_mesa_validate_DrawArrays(GLcontext *ctx, 233cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell GLenum mode, GLint start, GLsizei count) 234cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell{ 23522144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); 236cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 237c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul if (count < 0) { 23808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glDrawArrays(count)" ); 239cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 240cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 241cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 242464bc3b6747108dd32e4a9fcfe6549a9d4a52a95Brian Paul if (mode > GL_POLYGON) { 24308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glDrawArrays(mode)" ); 244cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 245cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 246cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 247cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (ctx->NewState) 248a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul _mesa_update_state(ctx); 249c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul 250a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul /* Always need vertex positions */ 251ee34e6ef716bb630440299ac1efbc2055ef09ffdIan Romanick if (!ctx->Array.ArrayObj->Vertex.Enabled && !ctx->Array.ArrayObj->VertexAttrib[0].Enabled) 252c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul return GL_FALSE; 253c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul 254a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul if (ctx->Const.CheckArrayBounds) { 2552c9f50dd4acc65ddfeb8e3fde98137711167e579Brian Paul if (start + count > (GLint) ctx->Array._MaxElement) 256c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul return GL_FALSE; 257a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul } 258c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul 259c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul return GL_TRUE; 260cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell} 261