| Ian Romanick | 9ac51f5 | 2003-06-05 00:50:18 +0000 | [diff] [blame] | 1 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Mesa 3-D graphics library |
| Brian Paul | 464bc3b | 2003-04-21 15:04:30 +0000 | [diff] [blame] | 4 | * Version: 5.1 |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 5 | * |
| Brian Paul | 464bc3b | 2003-04-21 15:04:30 +0000 | [diff] [blame] | 6 | * Copyright (C) 1999-2003 Brian Paul All Rights Reserved. |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 7 | * |
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 9 | * copy of this software and associated documentation files (the "Software"), |
| 10 | * to deal in the Software without restriction, including without limitation |
| 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 12 | * and/or sell copies of the Software, and to permit persons to whom the |
| 13 | * Software is furnished to do so, subject to the following conditions: |
| 14 | * |
| 15 | * The above copyright notice and this permission notice shall be included |
| 16 | * in all copies or substantial portions of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 19 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 21 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 22 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 24 | */ |
| 25 | |
| 26 | #include "glheader.h" |
| Brian Paul | 8446d1b | 2001-01-02 21:40:57 +0000 | [diff] [blame] | 27 | #include "api_validate.h" |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 28 | #include "context.h" |
| Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame^] | 29 | #include "image.h" /* for _mesa_sizeof_type() */ |
| Brian Paul | 3c63452 | 2002-10-24 23:57:19 +0000 | [diff] [blame] | 30 | #include "imports.h" |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 31 | #include "mtypes.h" |
| Brian Paul | 8446d1b | 2001-01-02 21:40:57 +0000 | [diff] [blame] | 32 | #include "state.h" |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 33 | |
| Keith Whitwell | 58e9917 | 2001-01-05 02:26:48 +0000 | [diff] [blame] | 34 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 35 | GLboolean |
| 36 | _mesa_validate_DrawElements(GLcontext *ctx, |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 37 | GLenum mode, GLsizei count, GLenum type, |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 38 | const GLvoid *indices) |
| 39 | { |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 40 | ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 41 | |
| 42 | if (count <= 0) { |
| 43 | if (count < 0) |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 44 | _mesa_error(ctx, GL_INVALID_VALUE, "glDrawElements(count)" ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 45 | return GL_FALSE; |
| 46 | } |
| 47 | |
| Brian Paul | 464bc3b | 2003-04-21 15:04:30 +0000 | [diff] [blame] | 48 | if (mode > GL_POLYGON) { |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 49 | _mesa_error(ctx, GL_INVALID_ENUM, "glDrawArrays(mode)" ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 50 | return GL_FALSE; |
| 51 | } |
| 52 | |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 53 | if (type != GL_UNSIGNED_INT && |
| 54 | type != GL_UNSIGNED_BYTE && |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 55 | type != GL_UNSIGNED_SHORT) |
| 56 | { |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 57 | _mesa_error(ctx, GL_INVALID_ENUM, "glDrawElements(type)" ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 58 | return GL_FALSE; |
| 59 | } |
| 60 | |
| 61 | if (ctx->NewState) |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 62 | _mesa_update_state( ctx ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 63 | |
| Brian Paul | 61bac60 | 2002-04-21 21:04:46 +0000 | [diff] [blame] | 64 | if (ctx->Array.Vertex.Enabled |
| 65 | || (ctx->VertexProgram.Enabled && ctx->Array.VertexAttrib[0].Enabled)) |
| 66 | return GL_TRUE; |
| 67 | else |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 68 | return GL_FALSE; |
| 69 | |
| 70 | return GL_TRUE; |
| 71 | } |
| 72 | |
| 73 | |
| 74 | GLboolean |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 75 | _mesa_validate_DrawRangeElements(GLcontext *ctx, GLenum mode, |
| 76 | GLuint start, GLuint end, |
| 77 | GLsizei count, GLenum type, |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 78 | const GLvoid *indices) |
| 79 | { |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 80 | ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 81 | |
| 82 | if (count <= 0) { |
| 83 | if (count < 0) |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 84 | _mesa_error(ctx, GL_INVALID_VALUE, "glDrawElements(count)" ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 85 | return GL_FALSE; |
| 86 | } |
| 87 | |
| Brian Paul | 464bc3b | 2003-04-21 15:04:30 +0000 | [diff] [blame] | 88 | if (mode > GL_POLYGON) { |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 89 | _mesa_error(ctx, GL_INVALID_ENUM, "glDrawArrays(mode)" ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 90 | return GL_FALSE; |
| 91 | } |
| 92 | |
| 93 | if (end < start) { |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 94 | _mesa_error(ctx, GL_INVALID_VALUE, "glDrawRangeElements(end<start)"); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 95 | return GL_FALSE; |
| 96 | } |
| 97 | |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 98 | if (type != GL_UNSIGNED_INT && |
| 99 | type != GL_UNSIGNED_BYTE && |
| Brian Paul | 61bac60 | 2002-04-21 21:04:46 +0000 | [diff] [blame] | 100 | type != GL_UNSIGNED_SHORT) { |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 101 | _mesa_error(ctx, GL_INVALID_ENUM, "glDrawElements(type)" ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 102 | return GL_FALSE; |
| 103 | } |
| 104 | |
| 105 | if (ctx->NewState) |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 106 | _mesa_update_state( ctx ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 107 | |
| Brian Paul | 61bac60 | 2002-04-21 21:04:46 +0000 | [diff] [blame] | 108 | if (ctx->Array.Vertex.Enabled |
| 109 | || (ctx->VertexProgram.Enabled && ctx->Array.VertexAttrib[0].Enabled)) |
| 110 | return GL_TRUE; |
| 111 | else |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 112 | return GL_FALSE; |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | |
| Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame^] | 116 | /** |
| 117 | * Helper routine for validating vertex array data to be sure the given |
| 118 | * element lies within the legal range (i.e. vertex buffer object). |
| 119 | */ |
| 120 | static INLINE GLboolean |
| 121 | validate(GLcontext *ctx, GLint attribArray, |
| 122 | const struct gl_client_array *array, GLint element) |
| 123 | { |
| 124 | if (ctx->VertexProgram.Enabled |
| 125 | && attribArray >= 0 |
| 126 | && ctx->Array.VertexAttrib[attribArray].Enabled) { |
| 127 | if (element >= ctx->Array.VertexAttrib[attribArray]._MaxElement) |
| 128 | return GL_FALSE; |
| 129 | } |
| 130 | else if (array && array->Enabled) { |
| 131 | if (element >= array->_MaxElement) |
| 132 | return GL_FALSE; |
| 133 | } |
| 134 | return GL_TRUE; |
| 135 | } |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 136 | |
| Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame^] | 137 | |
| 138 | /** |
| 139 | * Called from the tnl module to error check the function parameters and |
| 140 | * verify that we really can draw something. |
| 141 | */ |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 142 | GLboolean |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 143 | _mesa_validate_DrawArrays(GLcontext *ctx, |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 144 | GLenum mode, GLint start, GLsizei count) |
| 145 | { |
| Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame^] | 146 | GLint i; |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 147 | ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 148 | |
| Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame^] | 149 | if (count < 0) { |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 150 | _mesa_error(ctx, GL_INVALID_VALUE, "glDrawArrays(count)" ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 151 | return GL_FALSE; |
| 152 | } |
| 153 | |
| Brian Paul | 464bc3b | 2003-04-21 15:04:30 +0000 | [diff] [blame] | 154 | if (mode > GL_POLYGON) { |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 155 | _mesa_error(ctx, GL_INVALID_ENUM, "glDrawArrays(mode)" ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 156 | return GL_FALSE; |
| 157 | } |
| 158 | |
| 159 | if (ctx->NewState) |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 160 | _mesa_update_state( ctx ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 161 | |
| Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame^] | 162 | /* Either the conventional vertex position array, or the 0th |
| 163 | * generic vertex attribute array is required to be enabled. |
| 164 | */ |
| 165 | if (ctx->VertexProgram.Enabled |
| 166 | && ctx->Array.VertexAttrib[VERT_ATTRIB_POS].Enabled) { |
| 167 | if (start + count >= ctx->Array.VertexAttrib[VERT_ATTRIB_POS]._MaxElement) |
| 168 | return GL_FALSE; |
| 169 | } |
| 170 | else if (ctx->Array.Vertex.Enabled) { |
| 171 | if (start + count >= ctx->Array.Vertex._MaxElement) |
| 172 | return GL_FALSE; |
| 173 | } |
| 174 | else { |
| 175 | /* no vertex position array! */ |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 176 | return GL_FALSE; |
| Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame^] | 177 | } |
| 178 | |
| 179 | /* |
| 180 | * OK, now check all the other enabled arrays to be sure the elements |
| 181 | * are in bounds. |
| 182 | */ |
| 183 | if (!validate(ctx, VERT_ATTRIB_WEIGHT, NULL, start + count)) |
| 184 | return GL_FALSE; |
| 185 | |
| 186 | if (!validate(ctx, VERT_ATTRIB_NORMAL, &ctx->Array.Normal, start + count)) |
| 187 | return GL_FALSE; |
| 188 | |
| 189 | if (!validate(ctx, VERT_ATTRIB_COLOR0, &ctx->Array.Color, start + count)) |
| 190 | return GL_FALSE; |
| 191 | |
| 192 | if (!validate(ctx, VERT_ATTRIB_COLOR1, &ctx->Array.SecondaryColor, start + count)) |
| 193 | return GL_FALSE; |
| 194 | |
| 195 | if (!validate(ctx, VERT_ATTRIB_FOG, &ctx->Array.FogCoord, start + count)) |
| 196 | return GL_FALSE; |
| 197 | |
| 198 | if (!validate(ctx, VERT_ATTRIB_SIX, NULL, start + count)) |
| 199 | return GL_FALSE; |
| 200 | |
| 201 | if (!validate(ctx, VERT_ATTRIB_SEVEN, &ctx->Array.FogCoord, start + count)) |
| 202 | return GL_FALSE; |
| 203 | |
| 204 | for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) |
| 205 | if (!validate(ctx, VERT_ATTRIB_TEX0 + i, &ctx->Array.TexCoord[i], start + count)) |
| 206 | return GL_FALSE; |
| 207 | |
| 208 | if (!validate(ctx, -1, &ctx->Array.Index, start + count)) |
| 209 | return GL_FALSE; |
| 210 | |
| 211 | if (!validate(ctx, -1, &ctx->Array.EdgeFlag, start + count)) |
| 212 | return GL_FALSE; |
| 213 | |
| 214 | return GL_TRUE; |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 215 | } |