api_validate.c revision 56f0c00f125ee75caeadc1c9e8cab8a488635e5e
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) { 9256f0c00f125ee75caeadc1c9e8cab8a488635e5eIan Romanick ctx->Driver.UnmapBuffer(ctx, 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 11943bdabd47d98975b56a759954fb5f37d2942c101Brian Paul#if FEATURE_ES1 120f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg case API_OPENGLES: 12143bdabd47d98975b56a759954fb5f37d2942c101Brian Paul /* For OpenGL ES, only draw if we have vertex positions 12243bdabd47d98975b56a759954fb5f37d2942c101Brian Paul */ 12343bdabd47d98975b56a759954fb5f37d2942c101Brian Paul if (!ctx->Array.ArrayObj->Vertex.Enabled) 124f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg return GL_FALSE; 125f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg break; 12697dd2ddbd97ba95e8bc8ab572ec05e8081556e1eBrian Paul#endif 127263b96e160606975285154c4b8b610fcb8f4c930Alan Hourihane 12843bdabd47d98975b56a759954fb5f37d2942c101Brian Paul#if FEATURE_GL 12943bdabd47d98975b56a759954fb5f37d2942c101Brian Paul case API_OPENGL: 13043bdabd47d98975b56a759954fb5f37d2942c101Brian Paul { 13143bdabd47d98975b56a759954fb5f37d2942c101Brian Paul const struct gl_shader_program *vsProg = 13243bdabd47d98975b56a759954fb5f37d2942c101Brian Paul ctx->Shader.CurrentVertexProgram; 13343bdabd47d98975b56a759954fb5f37d2942c101Brian Paul GLboolean haveVertexShader = (vsProg && vsProg->LinkStatus); 13443bdabd47d98975b56a759954fb5f37d2942c101Brian Paul GLboolean haveVertexProgram = ctx->VertexProgram._Enabled; 13543bdabd47d98975b56a759954fb5f37d2942c101Brian Paul if (haveVertexShader || haveVertexProgram) { 13643bdabd47d98975b56a759954fb5f37d2942c101Brian Paul /* Draw regardless of whether or not we have any vertex arrays. 13743bdabd47d98975b56a759954fb5f37d2942c101Brian Paul * (Ex: could draw a point using a constant vertex pos) 13843bdabd47d98975b56a759954fb5f37d2942c101Brian Paul */ 13943bdabd47d98975b56a759954fb5f37d2942c101Brian Paul return GL_TRUE; 14043bdabd47d98975b56a759954fb5f37d2942c101Brian Paul } 14143bdabd47d98975b56a759954fb5f37d2942c101Brian Paul else { 14243bdabd47d98975b56a759954fb5f37d2942c101Brian Paul /* Draw if we have vertex positions (GL_VERTEX_ARRAY or generic 14343bdabd47d98975b56a759954fb5f37d2942c101Brian Paul * array [0]). 14443bdabd47d98975b56a759954fb5f37d2942c101Brian Paul */ 14543bdabd47d98975b56a759954fb5f37d2942c101Brian Paul return (ctx->Array.ArrayObj->Vertex.Enabled || 14643bdabd47d98975b56a759954fb5f37d2942c101Brian Paul ctx->Array.ArrayObj->VertexAttrib[0].Enabled); 14743bdabd47d98975b56a759954fb5f37d2942c101Brian Paul } 14843bdabd47d98975b56a759954fb5f37d2942c101Brian Paul } 14943bdabd47d98975b56a759954fb5f37d2942c101Brian Paul break; 15043bdabd47d98975b56a759954fb5f37d2942c101Brian Paul#endif 15143bdabd47d98975b56a759954fb5f37d2942c101Brian Paul 152f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg default: 153f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg ASSERT_NO_FEATURE(); 154f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg } 155f67b020a942911f80b7b774c6d64701d1981c608Kristian Høgsberg 156263b96e160606975285154c4b8b610fcb8f4c930Alan Hourihane return GL_TRUE; 157263b96e160606975285154c4b8b610fcb8f4c930Alan Hourihane} 158d8c6719f95b1543296ac954f95d13b048ae48634Brian 159e9968ebfa40b4740601c1596950ebd3f168664b0Brian Paul 160e9968ebfa40b4740601c1596950ebd3f168664b0Brian Paul/** 161e9968ebfa40b4740601c1596950ebd3f168664b0Brian Paul * Do bounds checking on array element indexes. Check that the vertices 162e9968ebfa40b4740601c1596950ebd3f168664b0Brian Paul * pointed to by the indices don't lie outside buffer object bounds. 163e9968ebfa40b4740601c1596950ebd3f168664b0Brian Paul * \return GL_TRUE if OK, GL_FALSE if any indexed vertex goes is out of bounds 164e9968ebfa40b4740601c1596950ebd3f168664b0Brian Paul */ 16592d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholtstatic GLboolean 166f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcheck_index_bounds(struct gl_context *ctx, GLsizei count, GLenum type, 16792d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt const GLvoid *indices, GLint basevertex) 16892d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt{ 16992d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt struct _mesa_prim prim; 17092d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt struct _mesa_index_buffer ib; 17192d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt GLuint min, max; 17292d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt 17392d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt /* Only the X Server needs to do this -- otherwise, accessing outside 17492d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt * array/BO bounds allows application termination. 17592d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt */ 17692d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt if (!ctx->Const.CheckArrayBounds) 17792d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt return GL_TRUE; 17892d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt 17992d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt memset(&prim, 0, sizeof(prim)); 18092d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt prim.count = count; 18192d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt 18292d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt memset(&ib, 0, sizeof(ib)); 18392d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt ib.type = type; 18492d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt ib.ptr = indices; 18592d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt ib.obj = ctx->Array.ElementArrayBufferObj; 18692d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt 18792d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt vbo_get_minmax_index(ctx, &prim, &ib, &min, &max); 18892d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt 189391b396f3fb300a912e6d9bfbf26f49cc30e52dfMichel Dänzer if ((int)(min + basevertex) < 0 || 19092d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt max + basevertex > ctx->Array.ArrayObj->_MaxElement) { 19192d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt /* the max element is out of bounds of one or more enabled arrays */ 192e9968ebfa40b4740601c1596950ebd3f168664b0Brian Paul _mesa_warning(ctx, "glDrawElements() index=%u is out of bounds (max=%u)", 193e9968ebfa40b4740601c1596950ebd3f168664b0Brian Paul max, ctx->Array.ArrayObj->_MaxElement); 19492d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt return GL_FALSE; 19592d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt } 19692d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt 19792d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt return GL_TRUE; 19892d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt} 19988af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul 200e9968ebfa40b4740601c1596950ebd3f168664b0Brian Paul 20188af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul/** 20288af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul * Error checking for glDrawElements(). Includes parameter checking 20388af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul * and VBO bounds checking. 20488af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul * \return GL_TRUE if OK to render, GL_FALSE if error found 20588af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul */ 206cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith WhitwellGLboolean 207f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_validate_DrawElements(struct gl_context *ctx, 20822144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes GLenum mode, GLsizei count, GLenum type, 20992d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt const GLvoid *indices, GLint basevertex) 210cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell{ 211cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); 212cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 213cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (count <= 0) { 214cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (count < 0) 21508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glDrawElements(count)" ); 216cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 217cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 218cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 219df0831f3750918ce3cd9cc1f5610bafc8b87c8e4Zack Rusin if (mode > GL_TRIANGLE_STRIP_ADJACENCY_ARB) { 220a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glDrawElements(mode)" ); 221cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 222cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 223cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 22422144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes if (type != GL_UNSIGNED_INT && 22522144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes type != GL_UNSIGNED_BYTE && 226cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell type != GL_UNSIGNED_SHORT) 227cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell { 22808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glDrawElements(type)" ); 229cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 230cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 231cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 232a48b0a5ce7fc17eab4daa375fb95768fa2f50825Brian Paul if (!check_valid_to_render(ctx, "glDrawElements")) 233a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul return GL_FALSE; 234a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul 23503e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul /* Vertex buffer object tests */ 236434ec3ada841915a00ffc23f699401eb3e7b37eeBrian Paul if (_mesa_is_bufferobj(ctx->Array.ElementArrayBufferObj)) { 23703e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul /* use indices in the buffer object */ 238d8c6719f95b1543296ac954f95d13b048ae48634Brian /* make sure count doesn't go outside buffer bounds */ 239bb1fb2a5444c6b7d83ccb47949f60ed9fb4f0f93Brian Paul if (index_bytes(type, count) > ctx->Array.ElementArrayBufferObj->Size) { 24003e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul _mesa_warning(ctx, "glDrawElements index out of buffer bounds"); 24103e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul return GL_FALSE; 24203e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul } 24303e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul } 24437ece4df7c654b30b6720044b35a83694d7e5bb3Brian else { 24537ece4df7c654b30b6720044b35a83694d7e5bb3Brian /* not using a VBO */ 24637ece4df7c654b30b6720044b35a83694d7e5bb3Brian if (!indices) 24737ece4df7c654b30b6720044b35a83694d7e5bb3Brian return GL_FALSE; 24837ece4df7c654b30b6720044b35a83694d7e5bb3Brian } 24903e29a5f77c13b7b888bd8443cb2752850e47d6aBrian Paul 25092d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt if (!check_index_bounds(ctx, count, type, indices, basevertex)) 25192d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt return GL_FALSE; 252cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 253cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_TRUE; 254cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell} 255cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 25688af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul 25788af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul/** 25888af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul * Error checking for glDrawRangeElements(). Includes parameter checking 25988af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul * and VBO bounds checking. 26088af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul * \return GL_TRUE if OK to render, GL_FALSE if error found 26188af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul */ 262cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith WhitwellGLboolean 263f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_validate_DrawRangeElements(struct gl_context *ctx, GLenum mode, 26422144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes GLuint start, GLuint end, 26522144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes GLsizei count, GLenum type, 26692d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt const GLvoid *indices, GLint basevertex) 267cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell{ 26822144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); 269cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 270cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (count <= 0) { 271cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (count < 0) 272a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glDrawRangeElements(count)" ); 273cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 274cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 275cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 276df0831f3750918ce3cd9cc1f5610bafc8b87c8e4Zack Rusin if (mode > GL_TRIANGLE_STRIP_ADJACENCY_ARB) { 277a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glDrawRangeElements(mode)" ); 278cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 279cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 280cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 281cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (end < start) { 28208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glDrawRangeElements(end<start)"); 283cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 284cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 285cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 28622144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes if (type != GL_UNSIGNED_INT && 28722144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes type != GL_UNSIGNED_BYTE && 28861bac6014aa15e0bec134e290aebac18f9815299Brian Paul type != GL_UNSIGNED_SHORT) { 289a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glDrawRangeElements(type)" ); 290cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 291cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 292cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 293a48b0a5ce7fc17eab4daa375fb95768fa2f50825Brian Paul if (!check_valid_to_render(ctx, "glDrawRangeElements")) 294a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul return GL_FALSE; 295a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul 29637ece4df7c654b30b6720044b35a83694d7e5bb3Brian /* Vertex buffer object tests */ 297434ec3ada841915a00ffc23f699401eb3e7b37eeBrian Paul if (_mesa_is_bufferobj(ctx->Array.ElementArrayBufferObj)) { 298d8c6719f95b1543296ac954f95d13b048ae48634Brian /* use indices in the buffer object */ 299d8c6719f95b1543296ac954f95d13b048ae48634Brian /* make sure count doesn't go outside buffer bounds */ 300bb1fb2a5444c6b7d83ccb47949f60ed9fb4f0f93Brian Paul if (index_bytes(type, count) > ctx->Array.ElementArrayBufferObj->Size) { 301ef5935bc94a1439eb8f1731732a3eabd0e360407Brian _mesa_warning(ctx, "glDrawRangeElements index out of buffer bounds"); 302d8c6719f95b1543296ac954f95d13b048ae48634Brian return GL_FALSE; 303d8c6719f95b1543296ac954f95d13b048ae48634Brian } 30437ece4df7c654b30b6720044b35a83694d7e5bb3Brian } 30537ece4df7c654b30b6720044b35a83694d7e5bb3Brian else { 306d8c6719f95b1543296ac954f95d13b048ae48634Brian /* not using a VBO */ 30737ece4df7c654b30b6720044b35a83694d7e5bb3Brian if (!indices) 30837ece4df7c654b30b6720044b35a83694d7e5bb3Brian return GL_FALSE; 30937ece4df7c654b30b6720044b35a83694d7e5bb3Brian } 31037ece4df7c654b30b6720044b35a83694d7e5bb3Brian 31192d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt if (!check_index_bounds(ctx, count, type, indices, basevertex)) 31292d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt return GL_FALSE; 313a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul 314c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul return GL_TRUE; 315c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul} 316c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul 317cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 318c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul/** 319c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul * Called from the tnl module to error check the function parameters and 320c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul * verify that we really can draw something. 32188af3f8783452dcf50a9e2e82076f52b2044f643Brian Paul * \return GL_TRUE if OK to render, GL_FALSE if error found 322c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul */ 323cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith WhitwellGLboolean 324f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_validate_DrawArrays(struct gl_context *ctx, 325cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell GLenum mode, GLint start, GLsizei count) 326cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell{ 32722144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); 328cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 3295cb203433ab5c4e54a7386a816263a237c716aa2Brian if (count <= 0) { 3305cb203433ab5c4e54a7386a816263a237c716aa2Brian if (count < 0) 3315cb203433ab5c4e54a7386a816263a237c716aa2Brian _mesa_error(ctx, GL_INVALID_VALUE, "glDrawArrays(count)" ); 332cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 333cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 334cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 335df0831f3750918ce3cd9cc1f5610bafc8b87c8e4Zack Rusin if (mode > GL_TRIANGLE_STRIP_ADJACENCY_ARB) { 33608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glDrawArrays(mode)" ); 337cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 338cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 339cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 340a48b0a5ce7fc17eab4daa375fb95768fa2f50825Brian Paul if (!check_valid_to_render(ctx, "glDrawArrays")) 341c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul return GL_FALSE; 342c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul 343a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul if (ctx->Const.CheckArrayBounds) { 344a185bcbdec856cc98c26098e4e447a683eed14d1Brian Paul if (start + count > (GLint) ctx->Array.ArrayObj->_MaxElement) 345c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul return GL_FALSE; 346a2b9bad251b058f6255fa037b842c5465c0609a2Brian Paul } 347c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul 348c5b1e81de48de5d8830bf5d92ff767ad1985e46eBrian Paul return GL_TRUE; 349cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell} 350cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul 351cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul 352cf3193ad1cd75b847c5d626def701a4bb012d080Brian PaulGLboolean 353f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_validate_DrawArraysInstanced(struct gl_context *ctx, GLenum mode, GLint first, 35472f2551017e03f888d63fa9040120740c6d40620Brian Paul GLsizei count, GLsizei numInstances) 355cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul{ 356cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); 357cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul 358cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul if (count <= 0) { 359cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul if (count < 0) 360cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 361cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul "glDrawArraysInstanced(count=%d)", count); 362cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul return GL_FALSE; 363cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul } 364cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul 365df0831f3750918ce3cd9cc1f5610bafc8b87c8e4Zack Rusin if (mode > GL_TRIANGLE_STRIP_ADJACENCY_ARB) { 366cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 367cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul "glDrawArraysInstanced(mode=0x%x)", mode); 368cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul return GL_FALSE; 369cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul } 370cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul 37172f2551017e03f888d63fa9040120740c6d40620Brian Paul if (numInstances <= 0) { 37272f2551017e03f888d63fa9040120740c6d40620Brian Paul if (numInstances < 0) 373cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 37472f2551017e03f888d63fa9040120740c6d40620Brian Paul "glDrawArraysInstanced(numInstances=%d)", numInstances); 375cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul return GL_FALSE; 376cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul } 377cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul 378cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul if (!check_valid_to_render(ctx, "glDrawArraysInstanced(invalid to render)")) 379cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul return GL_FALSE; 380cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul 381cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul if (ctx->CompileFlag) { 382cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 383cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul "glDrawArraysInstanced(display list"); 384cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul return GL_FALSE; 385cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul } 386cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul 387cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul if (ctx->Const.CheckArrayBounds) { 388cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul if (first + count > (GLint) ctx->Array.ArrayObj->_MaxElement) 389cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul return GL_FALSE; 390cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul } 391cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul 392cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul return GL_TRUE; 393cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul} 394cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul 395cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul 396cf3193ad1cd75b847c5d626def701a4bb012d080Brian PaulGLboolean 397f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_validate_DrawElementsInstanced(struct gl_context *ctx, 398cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul GLenum mode, GLsizei count, GLenum type, 39909201cc7a0c4c50871bb8aa5d00ac70aa4e9e670Pierre-Eric Pelloux-Prayer const GLvoid *indices, GLsizei numInstances, 40009201cc7a0c4c50871bb8aa5d00ac70aa4e9e670Pierre-Eric Pelloux-Prayer GLint basevertex) 401cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul{ 402cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); 403cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul 404cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul if (count <= 0) { 405cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul if (count < 0) 406cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 407cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul "glDrawElementsInstanced(count=%d)", count); 408cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul return GL_FALSE; 409cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul } 410cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul 411df0831f3750918ce3cd9cc1f5610bafc8b87c8e4Zack Rusin if (mode > GL_TRIANGLE_STRIP_ADJACENCY_ARB) { 412cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 413cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul "glDrawElementsInstanced(mode = 0x%x)", mode); 414cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul return GL_FALSE; 415cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul } 416cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul 417cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul if (type != GL_UNSIGNED_INT && 418cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul type != GL_UNSIGNED_BYTE && 419cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul type != GL_UNSIGNED_SHORT) { 420cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 421cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul "glDrawElementsInstanced(type=0x%x)", type); 422cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul return GL_FALSE; 423cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul } 424cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul 42572f2551017e03f888d63fa9040120740c6d40620Brian Paul if (numInstances <= 0) { 42672f2551017e03f888d63fa9040120740c6d40620Brian Paul if (numInstances < 0) 427cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 42872f2551017e03f888d63fa9040120740c6d40620Brian Paul "glDrawElementsInstanced(numInstances=%d)", numInstances); 429cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul return GL_FALSE; 430cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul } 431cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul 432cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul if (!check_valid_to_render(ctx, "glDrawElementsInstanced")) 433cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul return GL_FALSE; 434cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul 435cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul /* Vertex buffer object tests */ 436cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul if (_mesa_is_bufferobj(ctx->Array.ElementArrayBufferObj)) { 437cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul /* use indices in the buffer object */ 438cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul /* make sure count doesn't go outside buffer bounds */ 439cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul if (index_bytes(type, count) > ctx->Array.ElementArrayBufferObj->Size) { 440cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul _mesa_warning(ctx, 441cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul "glDrawElementsInstanced index out of buffer bounds"); 442cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul return GL_FALSE; 443cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul } 444cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul } 445cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul else { 446cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul /* not using a VBO */ 447cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul if (!indices) 448cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul return GL_FALSE; 449cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul } 450cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul 45109201cc7a0c4c50871bb8aa5d00ac70aa4e9e670Pierre-Eric Pelloux-Prayer if (!check_index_bounds(ctx, count, type, indices, basevertex)) 452cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul return GL_FALSE; 453cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul 454cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul return GL_TRUE; 455cf3193ad1cd75b847c5d626def701a4bb012d080Brian Paul} 456