blob: 3a0ce52b960c28c4125dfd113ae7e4b4ba793e74 [file] [log] [blame]
Gareth Hughes22144ab2001-03-12 00:48:37 +00001/* $Id: api_validate.c,v 1.5 2001/03/12 00:48:37 gareth Exp $ */
Keith Whitwellcab974c2000-12-26 05:09:27 +00002
3/*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
Gareth Hughes22144ab2001-03-12 00:48:37 +00007 * Copyright (C) 1999-2001 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"
30#include "mtypes.h"
Brian Paul8446d1b2001-01-02 21:40:57 +000031#include "state.h"
Keith Whitwellcab974c2000-12-26 05:09:27 +000032
Keith Whitwell58e99172001-01-05 02:26:48 +000033
Keith Whitwellcab974c2000-12-26 05:09:27 +000034GLboolean
35_mesa_validate_DrawElements(GLcontext *ctx,
Gareth Hughes22144ab2001-03-12 00:48:37 +000036 GLenum mode, GLsizei count, GLenum type,
Keith Whitwellcab974c2000-12-26 05:09:27 +000037 const GLvoid *indices)
38{
Gareth Hughes22144ab2001-03-12 00:48:37 +000039 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
Keith Whitwellcab974c2000-12-26 05:09:27 +000040
41 if (count <= 0) {
42 if (count < 0)
Brian Paul08836342001-03-03 20:33:27 +000043 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawElements(count)" );
Keith Whitwellcab974c2000-12-26 05:09:27 +000044 return GL_FALSE;
45 }
46
Gareth Hughes22144ab2001-03-12 00:48:37 +000047 if (mode < 0 ||
Keith Whitwellcab974c2000-12-26 05:09:27 +000048 mode > GL_POLYGON) {
Brian Paul08836342001-03-03 20:33:27 +000049 _mesa_error(ctx, GL_INVALID_ENUM, "glDrawArrays(mode)" );
Keith Whitwellcab974c2000-12-26 05:09:27 +000050 return GL_FALSE;
51 }
52
Gareth Hughes22144ab2001-03-12 00:48:37 +000053 if (type != GL_UNSIGNED_INT &&
54 type != GL_UNSIGNED_BYTE &&
Keith Whitwellcab974c2000-12-26 05:09:27 +000055 type != GL_UNSIGNED_SHORT)
56 {
Brian Paul08836342001-03-03 20:33:27 +000057 _mesa_error(ctx, GL_INVALID_ENUM, "glDrawElements(type)" );
Keith Whitwellcab974c2000-12-26 05:09:27 +000058 return GL_FALSE;
59 }
60
61 if (ctx->NewState)
Brian Paul08836342001-03-03 20:33:27 +000062 _mesa_update_state( ctx );
Keith Whitwellcab974c2000-12-26 05:09:27 +000063
64 if (!ctx->Array.Vertex.Enabled)
65 return GL_FALSE;
66
67 return GL_TRUE;
68}
69
70
71GLboolean
Gareth Hughes22144ab2001-03-12 00:48:37 +000072_mesa_validate_DrawRangeElements(GLcontext *ctx, GLenum mode,
73 GLuint start, GLuint end,
74 GLsizei count, GLenum type,
Keith Whitwellcab974c2000-12-26 05:09:27 +000075 const GLvoid *indices)
76{
Gareth Hughes22144ab2001-03-12 00:48:37 +000077 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
Keith Whitwellcab974c2000-12-26 05:09:27 +000078
79 if (count <= 0) {
80 if (count < 0)
Brian Paul08836342001-03-03 20:33:27 +000081 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawElements(count)" );
Keith Whitwellcab974c2000-12-26 05:09:27 +000082 return GL_FALSE;
83 }
84
85 if (mode < 0 || mode > GL_POLYGON) {
Brian Paul08836342001-03-03 20:33:27 +000086 _mesa_error(ctx, GL_INVALID_ENUM, "glDrawArrays(mode)" );
Keith Whitwellcab974c2000-12-26 05:09:27 +000087 return GL_FALSE;
88 }
89
90 if (end < start) {
Brian Paul08836342001-03-03 20:33:27 +000091 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawRangeElements(end<start)");
Keith Whitwellcab974c2000-12-26 05:09:27 +000092 return GL_FALSE;
93 }
94
Gareth Hughes22144ab2001-03-12 00:48:37 +000095 if (type != GL_UNSIGNED_INT &&
96 type != GL_UNSIGNED_BYTE &&
Keith Whitwellcab974c2000-12-26 05:09:27 +000097 type != GL_UNSIGNED_SHORT)
98 {
Brian Paul08836342001-03-03 20:33:27 +000099 _mesa_error(ctx, GL_INVALID_ENUM, "glDrawElements(type)" );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000100 return GL_FALSE;
101 }
102
103 if (ctx->NewState)
Brian Paul08836342001-03-03 20:33:27 +0000104 _mesa_update_state( ctx );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000105
106 if (!ctx->Array.Vertex.Enabled)
107 return GL_FALSE;
108
109 return GL_TRUE;
110}
111
112
113
114GLboolean
Gareth Hughes22144ab2001-03-12 00:48:37 +0000115_mesa_validate_DrawArrays(GLcontext *ctx,
Keith Whitwellcab974c2000-12-26 05:09:27 +0000116 GLenum mode, GLint start, GLsizei count)
117{
Gareth Hughes22144ab2001-03-12 00:48:37 +0000118 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
Keith Whitwellcab974c2000-12-26 05:09:27 +0000119
120 if (count<0) {
Brian Paul08836342001-03-03 20:33:27 +0000121 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawArrays(count)" );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000122 return GL_FALSE;
123 }
124
125 if (mode < 0 || mode > GL_POLYGON) {
Brian Paul08836342001-03-03 20:33:27 +0000126 _mesa_error(ctx, GL_INVALID_ENUM, "glDrawArrays(mode)" );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000127 return GL_FALSE;
128 }
129
130 if (ctx->NewState)
Brian Paul08836342001-03-03 20:33:27 +0000131 _mesa_update_state( ctx );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000132
Gareth Hughes22144ab2001-03-12 00:48:37 +0000133 if (!ctx->Array.Vertex.Enabled)
Keith Whitwellcab974c2000-12-26 05:09:27 +0000134 return GL_FALSE;
135
136 return GL_TRUE;
137}