api_validate.c revision 08836341788a9f9d638d9dc8328510ccd18ddeb5
1cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul/* $Id: api_validate.c,v 1.4 2001/03/03 20:33:27 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
3458e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell
35cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith WhitwellGLboolean
36cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell_mesa_validate_DrawElements(GLcontext *ctx,
37cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell			    GLenum mode, GLsizei count, GLenum type,
38cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell			    const GLvoid *indices)
39cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell{
40cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx,  GL_FALSE);
41cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
42cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   if (count <= 0) {
43cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      if (count < 0)
4408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul	 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawElements(count)" );
45cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      return GL_FALSE;
46cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   }
47cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
48cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   if (mode < 0 ||
49cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell       mode > GL_POLYGON) {
5008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul      _mesa_error(ctx, GL_INVALID_ENUM, "glDrawArrays(mode)" );
51cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      return GL_FALSE;
52cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   }
53cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
54cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   if (type != GL_UNSIGNED_INT &&
55cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell       type != GL_UNSIGNED_BYTE &&
56cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell       type != GL_UNSIGNED_SHORT)
57cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   {
5808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul      _mesa_error(ctx, GL_INVALID_ENUM, "glDrawElements(type)" );
59cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      return GL_FALSE;
60cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   }
61cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
62cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   if (ctx->NewState)
6308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul      _mesa_update_state( ctx );
64cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
65cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   if (!ctx->Array.Vertex.Enabled)
66cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      return GL_FALSE;
67cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
68cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   return GL_TRUE;
69cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell}
70cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
71cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
72cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith WhitwellGLboolean
73cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell_mesa_validate_DrawRangeElements(GLcontext *ctx, GLenum mode,
74cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell				 GLuint start, GLuint end,
75cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell				 GLsizei count, GLenum type,
76cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell				 const GLvoid *indices)
77cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell{
78cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
79cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
80cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   if (count <= 0) {
81cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      if (count < 0)
8208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul	 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawElements(count)" );
83cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      return GL_FALSE;
84cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   }
85cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
86cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   if (mode < 0 || mode > GL_POLYGON) {
8708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul      _mesa_error(ctx, GL_INVALID_ENUM, "glDrawArrays(mode)" );
88cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      return GL_FALSE;
89cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   }
90cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
91cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   if (end < start) {
9208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul      _mesa_error(ctx, GL_INVALID_VALUE, "glDrawRangeElements(end<start)");
93cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      return GL_FALSE;
94cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   }
95cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
96cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   if (type != GL_UNSIGNED_INT &&
97cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell       type != GL_UNSIGNED_BYTE &&
98cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell       type != GL_UNSIGNED_SHORT)
99cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   {
10008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul      _mesa_error(ctx, GL_INVALID_ENUM, "glDrawElements(type)" );
101cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      return GL_FALSE;
102cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   }
103cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
104cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   if (ctx->NewState)
10508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul      _mesa_update_state( ctx );
106cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
107cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   if (!ctx->Array.Vertex.Enabled)
108cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      return GL_FALSE;
109cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
110cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   return GL_TRUE;
111cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell}
112cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
113cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
114cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
115cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith WhitwellGLboolean
116cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell_mesa_validate_DrawArrays(GLcontext *ctx,
117cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell			  GLenum mode, GLint start, GLsizei count)
118cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell{
119cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
120cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
121cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   if (count<0) {
12208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul      _mesa_error(ctx, GL_INVALID_VALUE, "glDrawArrays(count)" );
123cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      return GL_FALSE;
124cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   }
125cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
126cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   if (mode < 0 || mode > GL_POLYGON) {
12708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul      _mesa_error(ctx, GL_INVALID_ENUM, "glDrawArrays(mode)" );
128cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      return GL_FALSE;
129cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   }
130cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
131cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   if (ctx->NewState)
13208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul      _mesa_update_state( ctx );
133cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
134cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   if (!ctx->Array.Vertex.Enabled)
135cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      return GL_FALSE;
136cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
137cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   return GL_TRUE;
138cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell}
139cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
140