api_validate.c revision 8446d1bab15ef82b35b8980a0a56072ace6feb04
1cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 28446d1bab15ef82b35b8980a0a56072ace6feb04Brian Paul/* $Id: api_validate.c,v 1.2 2001/01/02 21:40:57 brianp Exp $ */ 3cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 4cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell/* 5cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * Mesa 3-D graphics library 6cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * Version: 3.5 7cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * 8cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. 9cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * 10cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a 11cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * copy of this software and associated documentation files (the "Software"), 12cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * to deal in the Software without restriction, including without limitation 13cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * the rights to use, copy, modify, merge, publish, distribute, sublicense, 14cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * and/or sell copies of the Software, and to permit persons to whom the 15cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * Software is furnished to do so, subject to the following conditions: 16cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * 17cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * The above copyright notice and this permission notice shall be included 18cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * in all copies or substantial portions of the Software. 19cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * 20cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 21cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 23cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 24cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 25cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell */ 27cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 28cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#include "glheader.h" 298446d1bab15ef82b35b8980a0a56072ace6feb04Brian Paul#include "api_validate.h" 30cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#include "context.h" 31cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#include "mtypes.h" 328446d1bab15ef82b35b8980a0a56072ace6feb04Brian Paul#include "state.h" 33cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 34cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith WhitwellGLboolean 35cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell_mesa_validate_DrawElements(GLcontext *ctx, 36cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell GLenum mode, GLsizei count, GLenum type, 37cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell const GLvoid *indices) 38cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell{ 39cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); 40cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 41cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (count <= 0) { 42cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (count < 0) 43cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell gl_error(ctx, GL_INVALID_VALUE, "glDrawElements(count)" ); 44cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 45cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 46cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 47cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (mode < 0 || 48cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell mode > GL_POLYGON) { 49cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell gl_error(ctx, GL_INVALID_ENUM, "glDrawArrays(mode)" ); 50cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 51cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 52cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 53cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (type != GL_UNSIGNED_INT && 54cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell type != GL_UNSIGNED_BYTE && 55cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell type != GL_UNSIGNED_SHORT) 56cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell { 57cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell gl_error(ctx, GL_INVALID_ENUM, "glDrawElements(type)" ); 58cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 59cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 60cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 61cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (ctx->NewState) 62cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell gl_update_state( ctx ); 63cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 64cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (!ctx->Array.Vertex.Enabled) 65cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 66cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 67cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_TRUE; 68cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell} 69cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 70cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 71cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith WhitwellGLboolean 72cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell_mesa_validate_DrawRangeElements(GLcontext *ctx, GLenum mode, 73cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell GLuint start, GLuint end, 74cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell GLsizei count, GLenum type, 75cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell const GLvoid *indices) 76cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell{ 77cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); 78cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 79cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (count <= 0) { 80cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (count < 0) 81cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell gl_error(ctx, GL_INVALID_VALUE, "glDrawElements(count)" ); 82cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 83cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 84cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 85cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (mode < 0 || mode > GL_POLYGON) { 86cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell gl_error(ctx, GL_INVALID_ENUM, "glDrawArrays(mode)" ); 87cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 88cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 89cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 90cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (end < start) { 91cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell gl_error(ctx, GL_INVALID_VALUE, "glDrawRangeElements(end<start)"); 92cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 93cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 94cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 95cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (type != GL_UNSIGNED_INT && 96cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell type != GL_UNSIGNED_BYTE && 97cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell type != GL_UNSIGNED_SHORT) 98cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell { 99cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell gl_error(ctx, GL_INVALID_ENUM, "glDrawElements(type)" ); 100cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 101cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 102cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 103cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (ctx->NewState) 104cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell gl_update_state( ctx ); 105cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 106cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (!ctx->Array.Vertex.Enabled) 107cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 108cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 109cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_TRUE; 110cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell} 111cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 112cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 113cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 114cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith WhitwellGLboolean 115cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell_mesa_validate_DrawArrays(GLcontext *ctx, 116cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell GLenum mode, GLint start, GLsizei count) 117cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell{ 118cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); 119cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 120cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (count<0) { 121cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell gl_error(ctx, GL_INVALID_VALUE, "glDrawArrays(count)" ); 122cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 123cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 124cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 125cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (mode < 0 || mode > GL_POLYGON) { 126cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell gl_error(ctx, GL_INVALID_ENUM, "glDrawArrays(mode)" ); 127cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 128cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 129cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 130cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (ctx->NewState) 131cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell gl_update_state( ctx ); 132cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 133cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (!ctx->Array.Vertex.Enabled) 134cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; 135cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 136cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_TRUE; 137cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell} 138cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 139