blob: 33e3ea140fae4c68c7f1bf7f5d68fc780eba07f7 [file] [log] [blame]
Brian Paul3c634522002-10-24 23:57:19 +00001/* $Id: api_validate.c,v 1.7 2002/10/24 23:57:19 brianp Exp $ */
Keith Whitwellcab974c2000-12-26 05:09:27 +00002
3/*
4 * Mesa 3-D graphics library
Brian Paul61bac602002-04-21 21:04:46 +00005 * Version: 4.1
Keith Whitwellcab974c2000-12-26 05:09:27 +00006 *
Brian Paul61bac602002-04-21 21:04:46 +00007 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
Keith Whitwellcab974c2000-12-26 05:09:27 +00008 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27#include "glheader.h"
Brian Paul8446d1b2001-01-02 21:40:57 +000028#include "api_validate.h"
Keith Whitwellcab974c2000-12-26 05:09:27 +000029#include "context.h"
Brian Paul3c634522002-10-24 23:57:19 +000030#include "imports.h"
Keith Whitwellcab974c2000-12-26 05:09:27 +000031#include "mtypes.h"
Brian Paul8446d1b2001-01-02 21:40:57 +000032#include "state.h"
Keith Whitwellcab974c2000-12-26 05:09:27 +000033
Keith Whitwell58e99172001-01-05 02:26:48 +000034
Keith Whitwellcab974c2000-12-26 05:09:27 +000035GLboolean
36_mesa_validate_DrawElements(GLcontext *ctx,
Gareth Hughes22144ab2001-03-12 00:48:37 +000037 GLenum mode, GLsizei count, GLenum type,
Keith Whitwellcab974c2000-12-26 05:09:27 +000038 const GLvoid *indices)
39{
Gareth Hughes22144ab2001-03-12 00:48:37 +000040 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
Keith Whitwellcab974c2000-12-26 05:09:27 +000041
42 if (count <= 0) {
43 if (count < 0)
Brian Paul08836342001-03-03 20:33:27 +000044 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawElements(count)" );
Keith Whitwellcab974c2000-12-26 05:09:27 +000045 return GL_FALSE;
46 }
47
Gareth Hughes22144ab2001-03-12 00:48:37 +000048 if (mode < 0 ||
Keith Whitwellcab974c2000-12-26 05:09:27 +000049 mode > GL_POLYGON) {
Brian Paul08836342001-03-03 20:33:27 +000050 _mesa_error(ctx, GL_INVALID_ENUM, "glDrawArrays(mode)" );
Keith Whitwellcab974c2000-12-26 05:09:27 +000051 return GL_FALSE;
52 }
53
Gareth Hughes22144ab2001-03-12 00:48:37 +000054 if (type != GL_UNSIGNED_INT &&
55 type != GL_UNSIGNED_BYTE &&
Keith Whitwellcab974c2000-12-26 05:09:27 +000056 type != GL_UNSIGNED_SHORT)
57 {
Brian Paul08836342001-03-03 20:33:27 +000058 _mesa_error(ctx, GL_INVALID_ENUM, "glDrawElements(type)" );
Keith Whitwellcab974c2000-12-26 05:09:27 +000059 return GL_FALSE;
60 }
61
62 if (ctx->NewState)
Brian Paul08836342001-03-03 20:33:27 +000063 _mesa_update_state( ctx );
Keith Whitwellcab974c2000-12-26 05:09:27 +000064
Brian Paul61bac602002-04-21 21:04:46 +000065 if (ctx->Array.Vertex.Enabled
66 || (ctx->VertexProgram.Enabled && ctx->Array.VertexAttrib[0].Enabled))
67 return GL_TRUE;
68 else
Keith Whitwellcab974c2000-12-26 05:09:27 +000069 return GL_FALSE;
70
71 return GL_TRUE;
72}
73
74
75GLboolean
Gareth Hughes22144ab2001-03-12 00:48:37 +000076_mesa_validate_DrawRangeElements(GLcontext *ctx, GLenum mode,
77 GLuint start, GLuint end,
78 GLsizei count, GLenum type,
Keith Whitwellcab974c2000-12-26 05:09:27 +000079 const GLvoid *indices)
80{
Gareth Hughes22144ab2001-03-12 00:48:37 +000081 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
Keith Whitwellcab974c2000-12-26 05:09:27 +000082
83 if (count <= 0) {
84 if (count < 0)
Brian Paul08836342001-03-03 20:33:27 +000085 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawElements(count)" );
Keith Whitwellcab974c2000-12-26 05:09:27 +000086 return GL_FALSE;
87 }
88
89 if (mode < 0 || mode > GL_POLYGON) {
Brian Paul08836342001-03-03 20:33:27 +000090 _mesa_error(ctx, GL_INVALID_ENUM, "glDrawArrays(mode)" );
Keith Whitwellcab974c2000-12-26 05:09:27 +000091 return GL_FALSE;
92 }
93
94 if (end < start) {
Brian Paul08836342001-03-03 20:33:27 +000095 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawRangeElements(end<start)");
Keith Whitwellcab974c2000-12-26 05:09:27 +000096 return GL_FALSE;
97 }
98
Gareth Hughes22144ab2001-03-12 00:48:37 +000099 if (type != GL_UNSIGNED_INT &&
100 type != GL_UNSIGNED_BYTE &&
Brian Paul61bac602002-04-21 21:04:46 +0000101 type != GL_UNSIGNED_SHORT) {
Brian Paul08836342001-03-03 20:33:27 +0000102 _mesa_error(ctx, GL_INVALID_ENUM, "glDrawElements(type)" );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000103 return GL_FALSE;
104 }
105
106 if (ctx->NewState)
Brian Paul08836342001-03-03 20:33:27 +0000107 _mesa_update_state( ctx );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000108
Brian Paul61bac602002-04-21 21:04:46 +0000109 if (ctx->Array.Vertex.Enabled
110 || (ctx->VertexProgram.Enabled && ctx->Array.VertexAttrib[0].Enabled))
111 return GL_TRUE;
112 else
Keith Whitwellcab974c2000-12-26 05:09:27 +0000113 return GL_FALSE;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000114}
115
116
117
118GLboolean
Gareth Hughes22144ab2001-03-12 00:48:37 +0000119_mesa_validate_DrawArrays(GLcontext *ctx,
Keith Whitwellcab974c2000-12-26 05:09:27 +0000120 GLenum mode, GLint start, GLsizei count)
121{
Gareth Hughes22144ab2001-03-12 00:48:37 +0000122 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
Keith Whitwellcab974c2000-12-26 05:09:27 +0000123
124 if (count<0) {
Brian Paul08836342001-03-03 20:33:27 +0000125 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawArrays(count)" );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000126 return GL_FALSE;
127 }
128
129 if (mode < 0 || mode > GL_POLYGON) {
Brian Paul08836342001-03-03 20:33:27 +0000130 _mesa_error(ctx, GL_INVALID_ENUM, "glDrawArrays(mode)" );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000131 return GL_FALSE;
132 }
133
134 if (ctx->NewState)
Brian Paul08836342001-03-03 20:33:27 +0000135 _mesa_update_state( ctx );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000136
Brian Paul61bac602002-04-21 21:04:46 +0000137 if (ctx->Array.Vertex.Enabled
138 || (ctx->VertexProgram.Enabled && ctx->Array.VertexAttrib[0].Enabled))
139 return GL_TRUE;
140 else
Keith Whitwellcab974c2000-12-26 05:09:27 +0000141 return GL_FALSE;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000142}