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