jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Mesa 3-D graphics library |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 3 | * |
Brian Paul | 37c74af | 2008-09-04 14:58:02 -0600 | [diff] [blame] | 4 | * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. |
Brian Paul | 39d7524 | 2009-05-14 16:25:32 -0600 | [diff] [blame] | 5 | * Copyright (C) 2009 VMware, Inc. All Rights Reserved. |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 6 | * |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 7 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | * copy of this software and associated documentation files (the "Software"), |
| 9 | * to deal in the Software without restriction, including without limitation |
| 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | * and/or sell copies of the Software, and to permit persons to whom the |
| 12 | * Software is furnished to do so, subject to the following conditions: |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 13 | * |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 14 | * The above copyright notice and this permission notice shall be included |
| 15 | * in all copies or substantial portions of the Software. |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 16 | * |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
Kenneth Graunke | 3d8d5b2 | 2013-04-21 13:46:48 -0700 | [diff] [blame] | 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 21 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 22 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 23 | * OTHER DEALINGS IN THE SOFTWARE. |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 24 | */ |
| 25 | |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 26 | |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 27 | #include "glheader.h" |
Brian Paul | 148a284 | 2003-09-17 03:40:11 +0000 | [diff] [blame] | 28 | #include "imports.h" |
Brian Paul | 26895aa | 2004-03-03 15:35:08 +0000 | [diff] [blame] | 29 | #include "bufferobj.h" |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 30 | #include "context.h" |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 31 | #include "enable.h" |
| 32 | #include "enums.h" |
Brian Paul | 12cf98f | 2009-06-19 17:58:47 -0600 | [diff] [blame] | 33 | #include "hash.h" |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 34 | #include "image.h" |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 35 | #include "macros.h" |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 36 | #include "mtypes.h" |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 37 | #include "varray.h" |
Ian Romanick | ee34e6e | 2006-06-12 16:26:29 +0000 | [diff] [blame] | 38 | #include "arrayobj.h" |
Chia-I Wu | 2cf4439 | 2010-02-24 12:01:14 +0800 | [diff] [blame] | 39 | #include "main/dispatch.h" |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 40 | |
Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame] | 41 | |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 42 | /** Used to do error checking for GL_EXT_vertex_array_bgra */ |
| 43 | #define BGRA_OR_4 5 |
| 44 | |
| 45 | |
| 46 | /** Used to indicate which GL datatypes are accepted by each of the |
| 47 | * glVertex/Color/Attrib/EtcPointer() functions. |
| 48 | */ |
| 49 | #define BOOL_BIT 0x1 |
| 50 | #define BYTE_BIT 0x2 |
| 51 | #define UNSIGNED_BYTE_BIT 0x4 |
| 52 | #define SHORT_BIT 0x8 |
| 53 | #define UNSIGNED_SHORT_BIT 0x10 |
| 54 | #define INT_BIT 0x20 |
| 55 | #define UNSIGNED_INT_BIT 0x40 |
| 56 | #define HALF_BIT 0x80 |
| 57 | #define FLOAT_BIT 0x100 |
| 58 | #define DOUBLE_BIT 0x200 |
Marek Olšák | 0f1e59d | 2011-04-29 14:23:15 +0200 | [diff] [blame] | 59 | #define FIXED_ES_BIT 0x400 |
| 60 | #define FIXED_GL_BIT 0x800 |
Dave Airlie | 6cd2d55 | 2011-08-13 15:30:38 +0100 | [diff] [blame] | 61 | #define UNSIGNED_INT_2_10_10_10_REV_BIT 0x1000 |
| 62 | #define INT_2_10_10_10_REV_BIT 0x2000 |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 63 | |
| 64 | |
| 65 | /** Convert GL datatype enum into a <type>_BIT value seen above */ |
| 66 | static GLbitfield |
| 67 | type_to_bit(const struct gl_context *ctx, GLenum type) |
| 68 | { |
| 69 | switch (type) { |
| 70 | case GL_BOOL: |
| 71 | return BOOL_BIT; |
| 72 | case GL_BYTE: |
| 73 | return BYTE_BIT; |
| 74 | case GL_UNSIGNED_BYTE: |
| 75 | return UNSIGNED_BYTE_BIT; |
| 76 | case GL_SHORT: |
| 77 | return SHORT_BIT; |
| 78 | case GL_UNSIGNED_SHORT: |
| 79 | return UNSIGNED_SHORT_BIT; |
| 80 | case GL_INT: |
| 81 | return INT_BIT; |
| 82 | case GL_UNSIGNED_INT: |
| 83 | return UNSIGNED_INT_BIT; |
| 84 | case GL_HALF_FLOAT: |
| 85 | if (ctx->Extensions.ARB_half_float_vertex) |
| 86 | return HALF_BIT; |
| 87 | else |
| 88 | return 0x0; |
| 89 | case GL_FLOAT: |
| 90 | return FLOAT_BIT; |
| 91 | case GL_DOUBLE: |
| 92 | return DOUBLE_BIT; |
| 93 | case GL_FIXED: |
Jordan Justen | 09714c0 | 2012-07-19 11:27:16 -0700 | [diff] [blame] | 94 | return _mesa_is_desktop_gl(ctx) ? FIXED_GL_BIT : FIXED_ES_BIT; |
Dave Airlie | 6cd2d55 | 2011-08-13 15:30:38 +0100 | [diff] [blame] | 95 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 96 | return UNSIGNED_INT_2_10_10_10_REV_BIT; |
| 97 | case GL_INT_2_10_10_10_REV: |
| 98 | return INT_2_10_10_10_REV_BIT; |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 99 | default: |
| 100 | return 0; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | |
Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame] | 105 | /** |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 106 | * Does error checking and updates the format in an attrib array. |
Brian Paul | f9d88c8 | 2006-06-13 17:24:36 +0000 | [diff] [blame] | 107 | * |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 108 | * Called by update_array(). |
| 109 | * |
| 110 | * \param func Name of calling function used for error reporting |
| 111 | * \param attrib The index of the attribute array |
| 112 | * \param legalTypes Bitmask of *_BIT above indicating legal datatypes |
| 113 | * \param sizeMin Min allowable size value |
| 114 | * \param sizeMax Max allowable size value (may also be BGRA_OR_4) |
| 115 | * \param size Components per element (1, 2, 3 or 4) |
| 116 | * \param type Datatype of each component (GL_FLOAT, GL_INT, etc) |
| 117 | * \param normalized Whether integer types are converted to floats in [-1, 1] |
| 118 | * \param integer Integer-valued values (will not be normalized to [-1, 1]) |
Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame] | 119 | */ |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 120 | static bool |
| 121 | update_array_format(struct gl_context *ctx, |
| 122 | const char *func, |
| 123 | GLuint attrib, GLbitfield legalTypesMask, |
| 124 | GLint sizeMin, GLint sizeMax, |
| 125 | GLint size, GLenum type, |
| 126 | GLboolean normalized, GLboolean integer) |
Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame] | 127 | { |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 128 | struct gl_client_array *array; |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 129 | GLbitfield typeBit; |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 130 | GLuint elementSize; |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 131 | GLenum format = GL_RGBA; |
| 132 | |
Ian Romanick | bbceed2 | 2012-07-25 14:40:18 -0700 | [diff] [blame] | 133 | if (_mesa_is_gles(ctx)) { |
Matt Turner | c890113 | 2012-11-28 21:45:19 -0800 | [diff] [blame] | 134 | legalTypesMask &= ~(FIXED_GL_BIT | DOUBLE_BIT); |
Ian Romanick | bbceed2 | 2012-07-25 14:40:18 -0700 | [diff] [blame] | 135 | |
| 136 | /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until |
| 137 | * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or |
Matt Turner | c890113 | 2012-11-28 21:45:19 -0800 | [diff] [blame] | 138 | * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed |
| 139 | * until 3.0 or with the GL_OES_vertex_half float extension, which isn't |
| 140 | * quite as trivial as we'd like because it uses a different enum value |
| 141 | * for GL_HALF_FLOAT_OES. |
Ian Romanick | bbceed2 | 2012-07-25 14:40:18 -0700 | [diff] [blame] | 142 | */ |
| 143 | if (ctx->Version < 30) { |
| 144 | legalTypesMask &= ~(UNSIGNED_INT_BIT |
| 145 | | INT_BIT |
| 146 | | UNSIGNED_INT_2_10_10_10_REV_BIT |
Matt Turner | c890113 | 2012-11-28 21:45:19 -0800 | [diff] [blame] | 147 | | INT_2_10_10_10_REV_BIT |
| 148 | | HALF_BIT); |
Ian Romanick | bbceed2 | 2012-07-25 14:40:18 -0700 | [diff] [blame] | 149 | } |
Ian Romanick | 946ddec | 2012-07-25 14:46:54 -0700 | [diff] [blame] | 150 | |
| 151 | /* BGRA ordering is not supported in ES contexts. |
| 152 | */ |
| 153 | if (sizeMax == BGRA_OR_4) |
| 154 | sizeMax = 4; |
Ian Romanick | bbceed2 | 2012-07-25 14:40:18 -0700 | [diff] [blame] | 155 | } else { |
Marek Olšák | 0f1e59d | 2011-04-29 14:23:15 +0200 | [diff] [blame] | 156 | legalTypesMask &= ~FIXED_ES_BIT; |
Ian Romanick | bbceed2 | 2012-07-25 14:40:18 -0700 | [diff] [blame] | 157 | |
| 158 | if (!ctx->Extensions.ARB_ES2_compatibility) |
| 159 | legalTypesMask &= ~FIXED_GL_BIT; |
| 160 | |
| 161 | if (!ctx->Extensions.ARB_vertex_type_2_10_10_10_rev) |
| 162 | legalTypesMask &= ~(UNSIGNED_INT_2_10_10_10_REV_BIT | |
| 163 | INT_2_10_10_10_REV_BIT); |
Dave Airlie | 6cd2d55 | 2011-08-13 15:30:38 +0100 | [diff] [blame] | 164 | } |
Brian Paul | 11dd228 | 2010-11-07 18:35:35 -0700 | [diff] [blame] | 165 | |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 166 | typeBit = type_to_bit(ctx, type); |
| 167 | if (typeBit == 0x0 || (typeBit & legalTypesMask) == 0x0) { |
| 168 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)", |
| 169 | func, _mesa_lookup_enum_by_nr(type)); |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 170 | return false; |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | /* Do size parameter checking. |
| 174 | * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and |
| 175 | * must be handled specially. |
| 176 | */ |
| 177 | if (ctx->Extensions.EXT_vertex_array_bgra && |
| 178 | sizeMax == BGRA_OR_4 && |
| 179 | size == GL_BGRA) { |
Fredrik Höglund | 0e7a61a | 2013-04-12 17:36:06 +0200 | [diff] [blame] | 180 | /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says: |
| 181 | * |
| 182 | * "An INVALID_OPERATION error is generated under any of the following |
| 183 | * conditions: |
| 184 | * ... |
| 185 | * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV |
| 186 | * or UNSIGNED_INT_2_10_10_10_REV; |
| 187 | * ... |
| 188 | * • size is BGRA and normalized is FALSE;" |
| 189 | */ |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 190 | bool bgra_error = false; |
Dave Airlie | 99c1a58 | 2011-09-07 10:19:14 +0100 | [diff] [blame] | 191 | |
| 192 | if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev) { |
| 193 | if (type != GL_UNSIGNED_INT_2_10_10_10_REV && |
| 194 | type != GL_INT_2_10_10_10_REV && |
| 195 | type != GL_UNSIGNED_BYTE) |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 196 | bgra_error = true; |
Dave Airlie | 99c1a58 | 2011-09-07 10:19:14 +0100 | [diff] [blame] | 197 | } else if (type != GL_UNSIGNED_BYTE) |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 198 | bgra_error = true; |
Dave Airlie | 99c1a58 | 2011-09-07 10:19:14 +0100 | [diff] [blame] | 199 | |
| 200 | if (bgra_error) { |
Fredrik Höglund | 0e7a61a | 2013-04-12 17:36:06 +0200 | [diff] [blame] | 201 | _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=GL_BGRA and type=%s)", |
| 202 | func, _mesa_lookup_enum_by_nr(type)); |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 203 | return false; |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 204 | } |
Fredrik Höglund | 0e7a61a | 2013-04-12 17:36:06 +0200 | [diff] [blame] | 205 | |
| 206 | if (!normalized) { |
| 207 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 208 | "%s(size=GL_BGRA and normalized=GL_FALSE)", func); |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 209 | return false; |
Fredrik Höglund | 0e7a61a | 2013-04-12 17:36:06 +0200 | [diff] [blame] | 210 | } |
| 211 | |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 212 | format = GL_BGRA; |
| 213 | size = 4; |
| 214 | } |
| 215 | else if (size < sizeMin || size > sizeMax || size > 4) { |
| 216 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d)", func, size); |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 217 | return false; |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 218 | } |
| 219 | |
Dave Airlie | 6cd2d55 | 2011-08-13 15:30:38 +0100 | [diff] [blame] | 220 | if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev && |
| 221 | (type == GL_UNSIGNED_INT_2_10_10_10_REV || |
| 222 | type == GL_INT_2_10_10_10_REV) && size != 4) { |
| 223 | _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size); |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 224 | return false; |
Dave Airlie | 6cd2d55 | 2011-08-13 15:30:38 +0100 | [diff] [blame] | 225 | } |
| 226 | |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 227 | ASSERT(size <= 4); |
| 228 | |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 229 | elementSize = _mesa_bytes_per_vertex_attrib(size, type); |
| 230 | assert(elementSize != -1); |
| 231 | |
Fredrik Höglund | 12cbe99 | 2013-04-03 22:08:47 +0200 | [diff] [blame] | 232 | array = &ctx->Array.ArrayObj->_VertexAttrib[attrib]; |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 233 | array->Size = size; |
| 234 | array->Type = type; |
| 235 | array->Format = format; |
| 236 | array->Normalized = normalized; |
| 237 | array->Integer = integer; |
| 238 | array->_ElementSize = elementSize; |
| 239 | |
| 240 | return true; |
| 241 | } |
| 242 | |
| 243 | |
| 244 | /** |
| 245 | * Do error checking and update state for glVertex/Color/TexCoord/...Pointer |
| 246 | * functions. |
| 247 | * |
| 248 | * \param func name of calling function used for error reporting |
| 249 | * \param attrib the attribute array index to update |
| 250 | * \param legalTypes bitmask of *_BIT above indicating legal datatypes |
| 251 | * \param sizeMin min allowable size value |
| 252 | * \param sizeMax max allowable size value (may also be BGRA_OR_4) |
| 253 | * \param size components per element (1, 2, 3 or 4) |
| 254 | * \param type datatype of each component (GL_FLOAT, GL_INT, etc) |
| 255 | * \param stride stride between elements, in elements |
| 256 | * \param normalized are integer types converted to floats in [-1, 1]? |
| 257 | * \param integer integer-valued values (will not be normalized to [-1,1]) |
| 258 | * \param ptr the address (or offset inside VBO) of the array data |
| 259 | */ |
| 260 | static void |
| 261 | update_array(struct gl_context *ctx, |
| 262 | const char *func, |
| 263 | GLuint attrib, GLbitfield legalTypesMask, |
| 264 | GLint sizeMin, GLint sizeMax, |
| 265 | GLint size, GLenum type, GLsizei stride, |
| 266 | GLboolean normalized, GLboolean integer, |
| 267 | const GLvoid *ptr) |
| 268 | { |
| 269 | struct gl_client_array *array; |
| 270 | |
| 271 | /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says: |
| 272 | * |
| 273 | * "Client vertex arrays - all vertex array attribute pointers must |
| 274 | * refer to buffer objects (section 2.9.2). The default vertex array |
| 275 | * object (the name zero) is also deprecated. Calling |
| 276 | * VertexAttribPointer when no buffer object or no vertex array object |
| 277 | * is bound will generate an INVALID_OPERATION error..." |
| 278 | * |
| 279 | * The check for VBOs is handled below. |
| 280 | */ |
| 281 | if (ctx->API == API_OPENGL_CORE |
| 282 | && (ctx->Array.ArrayObj == ctx->Array.DefaultArrayObj)) { |
| 283 | _mesa_error(ctx, GL_INVALID_OPERATION, "%s(no array object bound)", |
| 284 | func); |
| 285 | return; |
| 286 | } |
| 287 | |
| 288 | if (!update_array_format(ctx, func, attrib, legalTypesMask, sizeMin, sizeMax, |
| 289 | size, type, normalized, integer)) { |
| 290 | return; |
| 291 | } |
| 292 | |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 293 | if (stride < 0) { |
| 294 | _mesa_error( ctx, GL_INVALID_VALUE, "%s(stride=%d)", func, stride ); |
| 295 | return; |
| 296 | } |
Brian Paul | e2b7249 | 2009-06-22 16:56:35 -0600 | [diff] [blame] | 297 | |
Ian Romanick | 843b876 | 2012-08-17 17:12:39 -0700 | [diff] [blame] | 298 | /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says: |
| 299 | * |
| 300 | * "An INVALID_OPERATION error is generated under any of the following |
| 301 | * conditions: |
| 302 | * |
| 303 | * ... |
| 304 | * |
| 305 | * * any of the *Pointer commands specifying the location and |
| 306 | * organization of vertex array data are called while zero is bound |
| 307 | * to the ARRAY_BUFFER buffer object binding point (see section |
| 308 | * 2.9.6), and the pointer argument is not NULL." |
| 309 | */ |
| 310 | if (ptr != NULL && ctx->Array.ArrayObj->ARBsemantics && |
Brian Paul | efcf5aa | 2011-11-29 07:44:20 -0700 | [diff] [blame] | 311 | !_mesa_is_bufferobj(ctx->Array.ArrayBufferObj)) { |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 312 | _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-VBO array)", func); |
Brian Paul | f549f4c | 2009-11-12 23:04:26 -0700 | [diff] [blame] | 313 | return; |
Brian Paul | e2b7249 | 2009-06-22 16:56:35 -0600 | [diff] [blame] | 314 | } |
| 315 | |
Fredrik Höglund | 12cbe99 | 2013-04-03 22:08:47 +0200 | [diff] [blame] | 316 | array = &ctx->Array.ArrayObj->_VertexAttrib[attrib]; |
Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame] | 317 | array->Stride = stride; |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 318 | array->StrideB = stride ? stride : array->_ElementSize; |
Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame] | 319 | array->Ptr = (const GLubyte *) ptr; |
Brian Paul | 0077c87 | 2009-05-06 13:00:35 -0600 | [diff] [blame] | 320 | |
Brian Paul | 37c74af | 2008-09-04 14:58:02 -0600 | [diff] [blame] | 321 | _mesa_reference_buffer_object(ctx, &array->BufferObj, |
| 322 | ctx->Array.ArrayBufferObj); |
| 323 | |
Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame] | 324 | ctx->NewState |= _NEW_ARRAY; |
Fredrik Höglund | 6a650fa | 2013-05-11 19:23:46 +0200 | [diff] [blame] | 325 | ctx->Array.ArrayObj->NewArrays |= VERT_BIT(attrib); |
Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 329 | void GLAPIENTRY |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 330 | _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 331 | { |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 332 | GET_CURRENT_CONTEXT(ctx); |
Ian Romanick | e2cf14d | 2012-07-25 15:19:31 -0700 | [diff] [blame] | 333 | GLbitfield legalTypes = (ctx->API == API_OPENGLES) |
| 334 | ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT) |
| 335 | : (SHORT_BIT | INT_BIT | FLOAT_BIT | |
| 336 | DOUBLE_BIT | HALF_BIT | |
| 337 | UNSIGNED_INT_2_10_10_10_REV_BIT | |
| 338 | INT_2_10_10_10_REV_BIT); |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 339 | |
| 340 | FLUSH_VERTICES(ctx, 0); |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 341 | |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 342 | update_array(ctx, "glVertexPointer", VERT_ATTRIB_POS, |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 343 | legalTypes, 2, 4, |
| 344 | size, type, stride, GL_FALSE, GL_FALSE, ptr); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 348 | void GLAPIENTRY |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 349 | _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 350 | { |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 351 | GET_CURRENT_CONTEXT(ctx); |
Ian Romanick | e5ef0cb | 2012-07-25 15:10:21 -0700 | [diff] [blame] | 352 | const GLbitfield legalTypes = (ctx->API == API_OPENGLES) |
| 353 | ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT) |
| 354 | : (BYTE_BIT | SHORT_BIT | INT_BIT | |
| 355 | HALF_BIT | FLOAT_BIT | DOUBLE_BIT | |
| 356 | UNSIGNED_INT_2_10_10_10_REV_BIT | |
| 357 | INT_2_10_10_10_REV_BIT); |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 358 | |
| 359 | FLUSH_VERTICES(ctx, 0); |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 360 | |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 361 | update_array(ctx, "glNormalPointer", VERT_ATTRIB_NORMAL, |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 362 | legalTypes, 3, 3, |
| 363 | 3, type, stride, GL_TRUE, GL_FALSE, ptr); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 367 | void GLAPIENTRY |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 368 | _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 369 | { |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 370 | GET_CURRENT_CONTEXT(ctx); |
Ian Romanick | 07ccfef | 2012-07-25 14:53:01 -0700 | [diff] [blame] | 371 | const GLbitfield legalTypes = (ctx->API == API_OPENGLES) |
| 372 | ? (UNSIGNED_BYTE_BIT | HALF_BIT | FLOAT_BIT | FIXED_ES_BIT) |
| 373 | : (BYTE_BIT | UNSIGNED_BYTE_BIT | |
| 374 | SHORT_BIT | UNSIGNED_SHORT_BIT | |
| 375 | INT_BIT | UNSIGNED_INT_BIT | |
| 376 | HALF_BIT | FLOAT_BIT | DOUBLE_BIT | |
| 377 | UNSIGNED_INT_2_10_10_10_REV_BIT | |
| 378 | INT_2_10_10_10_REV_BIT); |
Ian Romanick | fb82185 | 2012-07-25 14:58:36 -0700 | [diff] [blame] | 379 | const GLint sizeMin = (ctx->API == API_OPENGLES) ? 4 : 3; |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 380 | |
| 381 | FLUSH_VERTICES(ctx, 0); |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 382 | |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 383 | update_array(ctx, "glColorPointer", VERT_ATTRIB_COLOR0, |
Ian Romanick | fb82185 | 2012-07-25 14:58:36 -0700 | [diff] [blame] | 384 | legalTypes, sizeMin, BGRA_OR_4, |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 385 | size, type, stride, GL_TRUE, GL_FALSE, ptr); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 389 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 390 | _mesa_FogCoordPointer(GLenum type, GLsizei stride, const GLvoid *ptr) |
Keith Whitwell | fe5d67d | 2000-10-27 16:44:40 +0000 | [diff] [blame] | 391 | { |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 392 | const GLbitfield legalTypes = (HALF_BIT | FLOAT_BIT | DOUBLE_BIT); |
Keith Whitwell | fe5d67d | 2000-10-27 16:44:40 +0000 | [diff] [blame] | 393 | GET_CURRENT_CONTEXT(ctx); |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 394 | |
| 395 | FLUSH_VERTICES(ctx, 0); |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 396 | |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 397 | update_array(ctx, "glFogCoordPointer", VERT_ATTRIB_FOG, |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 398 | legalTypes, 1, 1, |
| 399 | 1, type, stride, GL_FALSE, GL_FALSE, ptr); |
Keith Whitwell | fe5d67d | 2000-10-27 16:44:40 +0000 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 403 | void GLAPIENTRY |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 404 | _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 405 | { |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 406 | const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT | INT_BIT | |
| 407 | FLOAT_BIT | DOUBLE_BIT); |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 408 | GET_CURRENT_CONTEXT(ctx); |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 409 | |
| 410 | FLUSH_VERTICES(ctx, 0); |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 411 | |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 412 | update_array(ctx, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX, |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 413 | legalTypes, 1, 1, |
| 414 | 1, type, stride, GL_FALSE, GL_FALSE, ptr); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 418 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 419 | _mesa_SecondaryColorPointer(GLint size, GLenum type, |
Keith Whitwell | fe5d67d | 2000-10-27 16:44:40 +0000 | [diff] [blame] | 420 | GLsizei stride, const GLvoid *ptr) |
| 421 | { |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 422 | const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT | |
| 423 | SHORT_BIT | UNSIGNED_SHORT_BIT | |
| 424 | INT_BIT | UNSIGNED_INT_BIT | |
Dave Airlie | 6cd2d55 | 2011-08-13 15:30:38 +0100 | [diff] [blame] | 425 | HALF_BIT | FLOAT_BIT | DOUBLE_BIT | |
| 426 | UNSIGNED_INT_2_10_10_10_REV_BIT | |
| 427 | INT_2_10_10_10_REV_BIT); |
Keith Whitwell | fe5d67d | 2000-10-27 16:44:40 +0000 | [diff] [blame] | 428 | GET_CURRENT_CONTEXT(ctx); |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 429 | |
| 430 | FLUSH_VERTICES(ctx, 0); |
Keith Whitwell | fe5d67d | 2000-10-27 16:44:40 +0000 | [diff] [blame] | 431 | |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 432 | update_array(ctx, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1, |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 433 | legalTypes, 3, BGRA_OR_4, |
| 434 | size, type, stride, GL_TRUE, GL_FALSE, ptr); |
Keith Whitwell | fe5d67d | 2000-10-27 16:44:40 +0000 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 438 | void GLAPIENTRY |
Brian Paul | 2edd180 | 2002-01-11 17:25:35 +0000 | [diff] [blame] | 439 | _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride, |
| 440 | const GLvoid *ptr) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 441 | { |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 442 | GET_CURRENT_CONTEXT(ctx); |
Ian Romanick | c3e9a20 | 2012-07-25 15:13:00 -0700 | [diff] [blame] | 443 | GLbitfield legalTypes = (ctx->API == API_OPENGLES) |
| 444 | ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT) |
| 445 | : (SHORT_BIT | INT_BIT | |
| 446 | HALF_BIT | FLOAT_BIT | DOUBLE_BIT | |
| 447 | UNSIGNED_INT_2_10_10_10_REV_BIT | |
| 448 | INT_2_10_10_10_REV_BIT); |
Ian Romanick | a8f475d | 2012-07-25 15:13:51 -0700 | [diff] [blame] | 449 | const GLint sizeMin = (ctx->API == API_OPENGLES) ? 2 : 1; |
Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame] | 450 | const GLuint unit = ctx->Array.ActiveTexture; |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 451 | |
| 452 | FLUSH_VERTICES(ctx, 0); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 453 | |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 454 | update_array(ctx, "glTexCoordPointer", VERT_ATTRIB_TEX(unit), |
Ian Romanick | a8f475d | 2012-07-25 15:13:51 -0700 | [diff] [blame] | 455 | legalTypes, sizeMin, 4, |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 456 | size, type, stride, GL_FALSE, GL_FALSE, |
Brian Paul | d1184d2 | 2010-10-28 21:17:41 -0600 | [diff] [blame] | 457 | ptr); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 461 | void GLAPIENTRY |
Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame] | 462 | _mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 463 | { |
Brian Paul | ee1f047 | 2010-11-02 08:22:40 -0600 | [diff] [blame] | 464 | const GLbitfield legalTypes = UNSIGNED_BYTE_BIT; |
Brian Paul | d1184d2 | 2010-10-28 21:17:41 -0600 | [diff] [blame] | 465 | /* see table 2.4 edits in GL_EXT_gpu_shader4 spec: */ |
| 466 | const GLboolean integer = GL_TRUE; |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 467 | GET_CURRENT_CONTEXT(ctx); |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 468 | |
| 469 | FLUSH_VERTICES(ctx, 0); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 470 | |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 471 | update_array(ctx, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG, |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 472 | legalTypes, 1, 1, |
Brian Paul | ee1f047 | 2010-11-02 08:22:40 -0600 | [diff] [blame] | 473 | 1, GL_UNSIGNED_BYTE, stride, GL_FALSE, integer, ptr); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | |
Brian Paul | 1cf2c8a | 2008-06-25 08:45:14 -0600 | [diff] [blame] | 477 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 478 | _mesa_PointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *ptr) |
Brian Paul | 1cf2c8a | 2008-06-25 08:45:14 -0600 | [diff] [blame] | 479 | { |
Marek Olšák | 0f1e59d | 2011-04-29 14:23:15 +0200 | [diff] [blame] | 480 | const GLbitfield legalTypes = (FLOAT_BIT | FIXED_ES_BIT); |
Brian Paul | 1cf2c8a | 2008-06-25 08:45:14 -0600 | [diff] [blame] | 481 | GET_CURRENT_CONTEXT(ctx); |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 482 | |
| 483 | FLUSH_VERTICES(ctx, 0); |
Brian Paul | 1cf2c8a | 2008-06-25 08:45:14 -0600 | [diff] [blame] | 484 | |
Brian Paul | 11dd228 | 2010-11-07 18:35:35 -0700 | [diff] [blame] | 485 | if (ctx->API != API_OPENGLES) { |
| 486 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 487 | "glPointSizePointer(ES 1.x only)"); |
| 488 | return; |
| 489 | } |
| 490 | |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 491 | update_array(ctx, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE, |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 492 | legalTypes, 1, 1, |
| 493 | 1, type, stride, GL_FALSE, GL_FALSE, ptr); |
Brian Paul | 1cf2c8a | 2008-06-25 08:45:14 -0600 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | |
Brian Paul | a554d7c | 2009-05-21 15:55:33 -0600 | [diff] [blame] | 497 | /** |
Brian Paul | a554d7c | 2009-05-21 15:55:33 -0600 | [diff] [blame] | 498 | * Set a generic vertex attribute array. |
| 499 | * Note that these arrays DO NOT alias the conventional GL vertex arrays |
| 500 | * (position, normal, color, fog, texcoord, etc). |
| 501 | */ |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 502 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 503 | _mesa_VertexAttribPointer(GLuint index, GLint size, GLenum type, |
Brian Paul | 92f9785 | 2003-05-01 22:44:02 +0000 | [diff] [blame] | 504 | GLboolean normalized, |
| 505 | GLsizei stride, const GLvoid *ptr) |
| 506 | { |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 507 | const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT | |
| 508 | SHORT_BIT | UNSIGNED_SHORT_BIT | |
| 509 | INT_BIT | UNSIGNED_INT_BIT | |
| 510 | HALF_BIT | FLOAT_BIT | DOUBLE_BIT | |
Dave Airlie | 6cd2d55 | 2011-08-13 15:30:38 +0100 | [diff] [blame] | 511 | FIXED_ES_BIT | FIXED_GL_BIT | |
| 512 | UNSIGNED_INT_2_10_10_10_REV_BIT | |
| 513 | INT_2_10_10_10_REV_BIT); |
Brian Paul | 92f9785 | 2003-05-01 22:44:02 +0000 | [diff] [blame] | 514 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | 92f9785 | 2003-05-01 22:44:02 +0000 | [diff] [blame] | 515 | |
Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 516 | if (index >= ctx->Const.VertexProgram.MaxAttribs) { |
Brian Paul | 92f9785 | 2003-05-01 22:44:02 +0000 | [diff] [blame] | 517 | _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(index)"); |
| 518 | return; |
| 519 | } |
| 520 | |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 521 | update_array(ctx, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index), |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 522 | legalTypes, 1, BGRA_OR_4, |
| 523 | size, type, stride, normalized, GL_FALSE, ptr); |
Brian Paul | 92f9785 | 2003-05-01 22:44:02 +0000 | [diff] [blame] | 524 | } |
Brian Paul | 92f9785 | 2003-05-01 22:44:02 +0000 | [diff] [blame] | 525 | |
| 526 | |
Brian Paul | e00d07c | 2010-05-25 21:12:24 -0600 | [diff] [blame] | 527 | /** |
Brian Paul | d1184d2 | 2010-10-28 21:17:41 -0600 | [diff] [blame] | 528 | * GL_EXT_gpu_shader4 / GL 3.0. |
Brian Paul | e00d07c | 2010-05-25 21:12:24 -0600 | [diff] [blame] | 529 | * Set an integer-valued vertex attribute array. |
| 530 | * Note that these arrays DO NOT alias the conventional GL vertex arrays |
| 531 | * (position, normal, color, fog, texcoord, etc). |
| 532 | */ |
| 533 | void GLAPIENTRY |
| 534 | _mesa_VertexAttribIPointer(GLuint index, GLint size, GLenum type, |
Brian Paul | e00d07c | 2010-05-25 21:12:24 -0600 | [diff] [blame] | 535 | GLsizei stride, const GLvoid *ptr) |
| 536 | { |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 537 | const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT | |
| 538 | SHORT_BIT | UNSIGNED_SHORT_BIT | |
| 539 | INT_BIT | UNSIGNED_INT_BIT); |
Brian Paul | d1184d2 | 2010-10-28 21:17:41 -0600 | [diff] [blame] | 540 | const GLboolean normalized = GL_FALSE; |
| 541 | const GLboolean integer = GL_TRUE; |
Brian Paul | d1184d2 | 2010-10-28 21:17:41 -0600 | [diff] [blame] | 542 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | d1184d2 | 2010-10-28 21:17:41 -0600 | [diff] [blame] | 543 | |
| 544 | if (index >= ctx->Const.VertexProgram.MaxAttribs) { |
| 545 | _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribIPointer(index)"); |
| 546 | return; |
| 547 | } |
| 548 | |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 549 | update_array(ctx, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index), |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 550 | legalTypes, 1, 4, |
| 551 | size, type, stride, normalized, integer, ptr); |
Brian Paul | e00d07c | 2010-05-25 21:12:24 -0600 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | |
| 555 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 556 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 557 | _mesa_EnableVertexAttribArray(GLuint index) |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 558 | { |
Brian Paul | 45453d8 | 2012-02-19 19:50:31 -0700 | [diff] [blame] | 559 | struct gl_array_object *arrayObj; |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 560 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 561 | |
| 562 | if (index >= ctx->Const.VertexProgram.MaxAttribs) { |
| 563 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 564 | "glEnableVertexAttribArrayARB(index)"); |
| 565 | return; |
| 566 | } |
| 567 | |
Brian Paul | 45453d8 | 2012-02-19 19:50:31 -0700 | [diff] [blame] | 568 | arrayObj = ctx->Array.ArrayObj; |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 569 | |
Fredrik Höglund | 12cbe99 | 2013-04-03 22:08:47 +0200 | [diff] [blame] | 570 | ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(arrayObj->_VertexAttrib)); |
Brian Paul | 45453d8 | 2012-02-19 19:50:31 -0700 | [diff] [blame] | 571 | |
Fredrik Höglund | 12cbe99 | 2013-04-03 22:08:47 +0200 | [diff] [blame] | 572 | if (!arrayObj->_VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) { |
Brian Paul | 45453d8 | 2012-02-19 19:50:31 -0700 | [diff] [blame] | 573 | /* was disabled, now being enabled */ |
| 574 | FLUSH_VERTICES(ctx, _NEW_ARRAY); |
Fredrik Höglund | 12cbe99 | 2013-04-03 22:08:47 +0200 | [diff] [blame] | 575 | arrayObj->_VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_TRUE; |
Brian Paul | 45453d8 | 2012-02-19 19:50:31 -0700 | [diff] [blame] | 576 | arrayObj->_Enabled |= VERT_BIT_GENERIC(index); |
Fredrik Höglund | 6a650fa | 2013-05-11 19:23:46 +0200 | [diff] [blame] | 577 | arrayObj->NewArrays |= VERT_BIT_GENERIC(index); |
Brian Paul | 45453d8 | 2012-02-19 19:50:31 -0700 | [diff] [blame] | 578 | } |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | |
| 582 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 583 | _mesa_DisableVertexAttribArray(GLuint index) |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 584 | { |
Brian Paul | 45453d8 | 2012-02-19 19:50:31 -0700 | [diff] [blame] | 585 | struct gl_array_object *arrayObj; |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 586 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 587 | |
| 588 | if (index >= ctx->Const.VertexProgram.MaxAttribs) { |
| 589 | _mesa_error(ctx, GL_INVALID_VALUE, |
Brian Paul | 95368f2 | 2011-04-06 14:22:39 -0600 | [diff] [blame] | 590 | "glDisableVertexAttribArrayARB(index)"); |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 591 | return; |
| 592 | } |
| 593 | |
Brian Paul | 45453d8 | 2012-02-19 19:50:31 -0700 | [diff] [blame] | 594 | arrayObj = ctx->Array.ArrayObj; |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 595 | |
Fredrik Höglund | 12cbe99 | 2013-04-03 22:08:47 +0200 | [diff] [blame] | 596 | ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(arrayObj->_VertexAttrib)); |
Brian Paul | 45453d8 | 2012-02-19 19:50:31 -0700 | [diff] [blame] | 597 | |
Fredrik Höglund | 12cbe99 | 2013-04-03 22:08:47 +0200 | [diff] [blame] | 598 | if (arrayObj->_VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) { |
Brian Paul | 45453d8 | 2012-02-19 19:50:31 -0700 | [diff] [blame] | 599 | /* was enabled, now being disabled */ |
| 600 | FLUSH_VERTICES(ctx, _NEW_ARRAY); |
Fredrik Höglund | 12cbe99 | 2013-04-03 22:08:47 +0200 | [diff] [blame] | 601 | arrayObj->_VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_FALSE; |
Brian Paul | 45453d8 | 2012-02-19 19:50:31 -0700 | [diff] [blame] | 602 | arrayObj->_Enabled &= ~VERT_BIT_GENERIC(index); |
Fredrik Höglund | 6a650fa | 2013-05-11 19:23:46 +0200 | [diff] [blame] | 603 | arrayObj->NewArrays |= VERT_BIT_GENERIC(index); |
Brian Paul | 45453d8 | 2012-02-19 19:50:31 -0700 | [diff] [blame] | 604 | } |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | |
| 608 | /** |
| 609 | * Return info for a vertex attribute array (no alias with legacy |
| 610 | * vertex attributes (pos, normal, color, etc)). This function does |
| 611 | * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query. |
| 612 | */ |
| 613 | static GLuint |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 614 | get_vertex_array_attrib(struct gl_context *ctx, GLuint index, GLenum pname, |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 615 | const char *caller) |
| 616 | { |
| 617 | const struct gl_client_array *array; |
| 618 | |
Ian Romanick | 5c3f1cd | 2011-02-03 17:56:44 -0800 | [diff] [blame] | 619 | if (index >= ctx->Const.VertexProgram.MaxAttribs) { |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 620 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", caller, index); |
| 621 | return 0; |
| 622 | } |
| 623 | |
Fredrik Höglund | 12cbe99 | 2013-04-03 22:08:47 +0200 | [diff] [blame] | 624 | ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.ArrayObj->_VertexAttrib)); |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 625 | |
Fredrik Höglund | 12cbe99 | 2013-04-03 22:08:47 +0200 | [diff] [blame] | 626 | array = &ctx->Array.ArrayObj->_VertexAttrib[VERT_ATTRIB_GENERIC(index)]; |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 627 | |
| 628 | switch (pname) { |
| 629 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB: |
| 630 | return array->Enabled; |
| 631 | case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB: |
| 632 | return array->Size; |
| 633 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB: |
| 634 | return array->Stride; |
| 635 | case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB: |
| 636 | return array->Type; |
| 637 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB: |
| 638 | return array->Normalized; |
| 639 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB: |
| 640 | return array->BufferObj->Name; |
Brian Paul | d1184d2 | 2010-10-28 21:17:41 -0600 | [diff] [blame] | 641 | case GL_VERTEX_ATTRIB_ARRAY_INTEGER: |
Ian Romanick | 2c87030 | 2012-07-25 16:21:49 -0700 | [diff] [blame] | 642 | if ((_mesa_is_desktop_gl(ctx) |
| 643 | && (ctx->Version >= 30 || ctx->Extensions.EXT_gpu_shader4)) |
| 644 | || _mesa_is_gles3(ctx)) { |
Brian Paul | d1184d2 | 2010-10-28 21:17:41 -0600 | [diff] [blame] | 645 | return array->Integer; |
| 646 | } |
Brian Paul | 1d1eb95 | 2011-01-15 10:32:34 -0700 | [diff] [blame] | 647 | goto error; |
| 648 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB: |
Ian Romanick | 2c87030 | 2012-07-25 16:21:49 -0700 | [diff] [blame] | 649 | if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_instanced_arrays) |
| 650 | || _mesa_is_gles3(ctx)) { |
Brian Paul | 1d1eb95 | 2011-01-15 10:32:34 -0700 | [diff] [blame] | 651 | return array->InstanceDivisor; |
| 652 | } |
| 653 | goto error; |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 654 | default: |
Brian Paul | 1d1eb95 | 2011-01-15 10:32:34 -0700 | [diff] [blame] | 655 | ; /* fall-through */ |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 656 | } |
Brian Paul | 1d1eb95 | 2011-01-15 10:32:34 -0700 | [diff] [blame] | 657 | |
| 658 | error: |
| 659 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", caller, pname); |
| 660 | return 0; |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | |
Ian Romanick | 5c3f1cd | 2011-02-03 17:56:44 -0800 | [diff] [blame] | 664 | static const GLfloat * |
| 665 | get_current_attrib(struct gl_context *ctx, GLuint index, const char *function) |
| 666 | { |
| 667 | if (index == 0) { |
Ian Romanick | 2c87030 | 2012-07-25 16:21:49 -0700 | [diff] [blame] | 668 | /* In OpenGL 3.1 attribute 0 becomes non-magic, just like in OpenGL ES |
| 669 | * 2.0. Note that we cannot just check for API_OPENGL_CORE here because |
| 670 | * that will erroneously allow this usage in a 3.0 forward-compatible |
| 671 | * context too. |
| 672 | */ |
| 673 | if ((ctx->API != API_OPENGL_CORE || ctx->Version < 31) |
| 674 | && ctx->API != API_OPENGLES2) { |
Ian Romanick | 5c3f1cd | 2011-02-03 17:56:44 -0800 | [diff] [blame] | 675 | _mesa_error(ctx, GL_INVALID_OPERATION, "%s(index==0)", function); |
| 676 | return NULL; |
| 677 | } |
| 678 | } |
| 679 | else if (index >= ctx->Const.VertexProgram.MaxAttribs) { |
| 680 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 681 | "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function); |
| 682 | return NULL; |
| 683 | } |
| 684 | |
Fredrik Höglund | 12cbe99 | 2013-04-03 22:08:47 +0200 | [diff] [blame] | 685 | ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.ArrayObj->_VertexAttrib)); |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 686 | |
Ian Romanick | 5c3f1cd | 2011-02-03 17:56:44 -0800 | [diff] [blame] | 687 | FLUSH_CURRENT(ctx, 0); |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 688 | return ctx->Current.Attrib[VERT_ATTRIB_GENERIC(index)]; |
Ian Romanick | 5c3f1cd | 2011-02-03 17:56:44 -0800 | [diff] [blame] | 689 | } |
| 690 | |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 691 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 692 | _mesa_GetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params) |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 693 | { |
| 694 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 695 | |
| 696 | if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) { |
Ian Romanick | 5c3f1cd | 2011-02-03 17:56:44 -0800 | [diff] [blame] | 697 | const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribfv"); |
| 698 | if (v != NULL) { |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 699 | COPY_4V(params, v); |
| 700 | } |
| 701 | } |
| 702 | else { |
| 703 | params[0] = (GLfloat) get_vertex_array_attrib(ctx, index, pname, |
| 704 | "glGetVertexAttribfv"); |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | |
| 709 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 710 | _mesa_GetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params) |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 711 | { |
| 712 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 713 | |
| 714 | if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) { |
Ian Romanick | 5c3f1cd | 2011-02-03 17:56:44 -0800 | [diff] [blame] | 715 | const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribdv"); |
| 716 | if (v != NULL) { |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 717 | params[0] = (GLdouble) v[0]; |
| 718 | params[1] = (GLdouble) v[1]; |
| 719 | params[2] = (GLdouble) v[2]; |
| 720 | params[3] = (GLdouble) v[3]; |
| 721 | } |
| 722 | } |
| 723 | else { |
| 724 | params[0] = (GLdouble) get_vertex_array_attrib(ctx, index, pname, |
| 725 | "glGetVertexAttribdv"); |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | |
| 730 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 731 | _mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params) |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 732 | { |
| 733 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 734 | |
| 735 | if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) { |
Ian Romanick | 5c3f1cd | 2011-02-03 17:56:44 -0800 | [diff] [blame] | 736 | const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribiv"); |
| 737 | if (v != NULL) { |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 738 | /* XXX should floats in[0,1] be scaled to full int range? */ |
| 739 | params[0] = (GLint) v[0]; |
| 740 | params[1] = (GLint) v[1]; |
| 741 | params[2] = (GLint) v[2]; |
| 742 | params[3] = (GLint) v[3]; |
| 743 | } |
| 744 | } |
| 745 | else { |
| 746 | params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname, |
| 747 | "glGetVertexAttribiv"); |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | |
| 752 | /** GL 3.0 */ |
| 753 | void GLAPIENTRY |
| 754 | _mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params) |
| 755 | { |
| 756 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 757 | |
| 758 | if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) { |
Kenneth Graunke | c299f44 | 2012-11-07 20:29:40 -0800 | [diff] [blame] | 759 | const GLint *v = (const GLint *) |
Ian Romanick | 5c3f1cd | 2011-02-03 17:56:44 -0800 | [diff] [blame] | 760 | get_current_attrib(ctx, index, "glGetVertexAttribIiv"); |
| 761 | if (v != NULL) { |
Kenneth Graunke | c299f44 | 2012-11-07 20:29:40 -0800 | [diff] [blame] | 762 | COPY_4V(params, v); |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 763 | } |
| 764 | } |
| 765 | else { |
| 766 | params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname, |
| 767 | "glGetVertexAttribIiv"); |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | |
| 772 | /** GL 3.0 */ |
| 773 | void GLAPIENTRY |
| 774 | _mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params) |
| 775 | { |
| 776 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 777 | |
| 778 | if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) { |
Kenneth Graunke | c299f44 | 2012-11-07 20:29:40 -0800 | [diff] [blame] | 779 | const GLuint *v = (const GLuint *) |
Ian Romanick | 5c3f1cd | 2011-02-03 17:56:44 -0800 | [diff] [blame] | 780 | get_current_attrib(ctx, index, "glGetVertexAttribIuiv"); |
| 781 | if (v != NULL) { |
Kenneth Graunke | c299f44 | 2012-11-07 20:29:40 -0800 | [diff] [blame] | 782 | COPY_4V(params, v); |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 783 | } |
| 784 | } |
| 785 | else { |
| 786 | params[0] = get_vertex_array_attrib(ctx, index, pname, |
| 787 | "glGetVertexAttribIuiv"); |
| 788 | } |
| 789 | } |
| 790 | |
| 791 | |
| 792 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 793 | _mesa_GetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer) |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 794 | { |
| 795 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 796 | |
| 797 | if (index >= ctx->Const.VertexProgram.MaxAttribs) { |
| 798 | _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)"); |
| 799 | return; |
| 800 | } |
| 801 | |
| 802 | if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) { |
| 803 | _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)"); |
| 804 | return; |
| 805 | } |
| 806 | |
Fredrik Höglund | 12cbe99 | 2013-04-03 22:08:47 +0200 | [diff] [blame] | 807 | ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.ArrayObj->_VertexAttrib)); |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 808 | |
Fredrik Höglund | 12cbe99 | 2013-04-03 22:08:47 +0200 | [diff] [blame] | 809 | *pointer = (GLvoid *) ctx->Array.ArrayObj->_VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr; |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | |
| 813 | void GLAPIENTRY |
Brian Paul | 1f0e213 | 2000-06-12 15:30:51 +0000 | [diff] [blame] | 814 | _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride, |
| 815 | GLsizei count, const GLvoid *ptr) |
| 816 | { |
| 817 | (void) count; |
| 818 | _mesa_VertexPointer(size, type, stride, ptr); |
| 819 | } |
| 820 | |
| 821 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 822 | void GLAPIENTRY |
Brian Paul | 1f0e213 | 2000-06-12 15:30:51 +0000 | [diff] [blame] | 823 | _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count, |
| 824 | const GLvoid *ptr) |
| 825 | { |
| 826 | (void) count; |
| 827 | _mesa_NormalPointer(type, stride, ptr); |
| 828 | } |
| 829 | |
| 830 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 831 | void GLAPIENTRY |
Brian Paul | 1f0e213 | 2000-06-12 15:30:51 +0000 | [diff] [blame] | 832 | _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count, |
| 833 | const GLvoid *ptr) |
| 834 | { |
| 835 | (void) count; |
| 836 | _mesa_ColorPointer(size, type, stride, ptr); |
| 837 | } |
| 838 | |
| 839 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 840 | void GLAPIENTRY |
Brian Paul | 1f0e213 | 2000-06-12 15:30:51 +0000 | [diff] [blame] | 841 | _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count, |
| 842 | const GLvoid *ptr) |
| 843 | { |
| 844 | (void) count; |
| 845 | _mesa_IndexPointer(type, stride, ptr); |
| 846 | } |
| 847 | |
| 848 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 849 | void GLAPIENTRY |
Brian Paul | 1f0e213 | 2000-06-12 15:30:51 +0000 | [diff] [blame] | 850 | _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride, |
| 851 | GLsizei count, const GLvoid *ptr) |
| 852 | { |
| 853 | (void) count; |
| 854 | _mesa_TexCoordPointer(size, type, stride, ptr); |
| 855 | } |
| 856 | |
| 857 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 858 | void GLAPIENTRY |
Brian Paul | 1f0e213 | 2000-06-12 15:30:51 +0000 | [diff] [blame] | 859 | _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr) |
| 860 | { |
| 861 | (void) count; |
| 862 | _mesa_EdgeFlagPointer(stride, ptr); |
| 863 | } |
| 864 | |
| 865 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 866 | void GLAPIENTRY |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 867 | _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 868 | { |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 869 | GET_CURRENT_CONTEXT(ctx); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 870 | GLboolean tflag, cflag, nflag; /* enable/disable flags */ |
| 871 | GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */ |
Keith Whitwell | f4b02d1 | 2001-01-05 05:31:42 +0000 | [diff] [blame] | 872 | GLenum ctype = 0; /* color type */ |
| 873 | GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */ |
Brian Paul | 4a3110f | 2003-12-12 18:40:02 +0000 | [diff] [blame] | 874 | const GLint toffset = 0; /* always zero */ |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 875 | GLint defstride; /* default stride */ |
| 876 | GLint c, f; |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 877 | |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 878 | FLUSH_VERTICES(ctx, 0); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 879 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 880 | f = sizeof(GLfloat); |
Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame] | 881 | c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 882 | |
Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame] | 883 | if (stride < 0) { |
Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 884 | _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 885 | return; |
| 886 | } |
| 887 | |
| 888 | switch (format) { |
| 889 | case GL_V2F: |
| 890 | tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE; |
| 891 | tcomps = 0; ccomps = 0; vcomps = 2; |
| 892 | voffset = 0; |
| 893 | defstride = 2*f; |
| 894 | break; |
| 895 | case GL_V3F: |
| 896 | tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE; |
| 897 | tcomps = 0; ccomps = 0; vcomps = 3; |
| 898 | voffset = 0; |
| 899 | defstride = 3*f; |
| 900 | break; |
| 901 | case GL_C4UB_V2F: |
| 902 | tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE; |
| 903 | tcomps = 0; ccomps = 4; vcomps = 2; |
| 904 | ctype = GL_UNSIGNED_BYTE; |
| 905 | coffset = 0; |
| 906 | voffset = c; |
| 907 | defstride = c + 2*f; |
| 908 | break; |
| 909 | case GL_C4UB_V3F: |
| 910 | tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE; |
| 911 | tcomps = 0; ccomps = 4; vcomps = 3; |
| 912 | ctype = GL_UNSIGNED_BYTE; |
| 913 | coffset = 0; |
| 914 | voffset = c; |
| 915 | defstride = c + 3*f; |
| 916 | break; |
| 917 | case GL_C3F_V3F: |
| 918 | tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE; |
| 919 | tcomps = 0; ccomps = 3; vcomps = 3; |
| 920 | ctype = GL_FLOAT; |
| 921 | coffset = 0; |
| 922 | voffset = 3*f; |
| 923 | defstride = 6*f; |
| 924 | break; |
| 925 | case GL_N3F_V3F: |
| 926 | tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE; |
| 927 | tcomps = 0; ccomps = 0; vcomps = 3; |
| 928 | noffset = 0; |
| 929 | voffset = 3*f; |
| 930 | defstride = 6*f; |
| 931 | break; |
| 932 | case GL_C4F_N3F_V3F: |
| 933 | tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE; |
| 934 | tcomps = 0; ccomps = 4; vcomps = 3; |
| 935 | ctype = GL_FLOAT; |
| 936 | coffset = 0; |
| 937 | noffset = 4*f; |
| 938 | voffset = 7*f; |
| 939 | defstride = 10*f; |
| 940 | break; |
| 941 | case GL_T2F_V3F: |
| 942 | tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE; |
| 943 | tcomps = 2; ccomps = 0; vcomps = 3; |
| 944 | voffset = 2*f; |
| 945 | defstride = 5*f; |
| 946 | break; |
| 947 | case GL_T4F_V4F: |
| 948 | tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE; |
| 949 | tcomps = 4; ccomps = 0; vcomps = 4; |
| 950 | voffset = 4*f; |
| 951 | defstride = 8*f; |
| 952 | break; |
| 953 | case GL_T2F_C4UB_V3F: |
| 954 | tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE; |
| 955 | tcomps = 2; ccomps = 4; vcomps = 3; |
| 956 | ctype = GL_UNSIGNED_BYTE; |
| 957 | coffset = 2*f; |
| 958 | voffset = c+2*f; |
| 959 | defstride = c+5*f; |
| 960 | break; |
| 961 | case GL_T2F_C3F_V3F: |
| 962 | tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE; |
| 963 | tcomps = 2; ccomps = 3; vcomps = 3; |
| 964 | ctype = GL_FLOAT; |
| 965 | coffset = 2*f; |
| 966 | voffset = 5*f; |
| 967 | defstride = 8*f; |
| 968 | break; |
| 969 | case GL_T2F_N3F_V3F: |
| 970 | tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE; |
| 971 | tcomps = 2; ccomps = 0; vcomps = 3; |
| 972 | noffset = 2*f; |
| 973 | voffset = 5*f; |
| 974 | defstride = 8*f; |
| 975 | break; |
| 976 | case GL_T2F_C4F_N3F_V3F: |
| 977 | tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE; |
| 978 | tcomps = 2; ccomps = 4; vcomps = 3; |
| 979 | ctype = GL_FLOAT; |
| 980 | coffset = 2*f; |
| 981 | noffset = 6*f; |
| 982 | voffset = 9*f; |
| 983 | defstride = 12*f; |
| 984 | break; |
| 985 | case GL_T4F_C4F_N3F_V4F: |
| 986 | tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE; |
| 987 | tcomps = 4; ccomps = 4; vcomps = 4; |
| 988 | ctype = GL_FLOAT; |
| 989 | coffset = 4*f; |
| 990 | noffset = 8*f; |
| 991 | voffset = 11*f; |
| 992 | defstride = 15*f; |
| 993 | break; |
| 994 | default: |
Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 995 | _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 996 | return; |
| 997 | } |
| 998 | |
| 999 | if (stride==0) { |
| 1000 | stride = defstride; |
| 1001 | } |
| 1002 | |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1003 | _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY ); |
| 1004 | _mesa_DisableClientState( GL_INDEX_ARRAY ); |
Brian Paul | 095c669 | 2006-04-25 00:21:32 +0000 | [diff] [blame] | 1005 | /* XXX also disable secondary color and generic arrays? */ |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1006 | |
| 1007 | /* Texcoords */ |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1008 | if (tflag) { |
Brian Paul | 4a3110f | 2003-12-12 18:40:02 +0000 | [diff] [blame] | 1009 | _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY ); |
| 1010 | _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride, |
Brian Paul | ab928e5 | 2004-03-10 16:17:35 +0000 | [diff] [blame] | 1011 | (GLubyte *) pointer + toffset ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1012 | } |
| 1013 | else { |
Brian Paul | ab928e5 | 2004-03-10 16:17:35 +0000 | [diff] [blame] | 1014 | _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1015 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1016 | |
| 1017 | /* Color */ |
| 1018 | if (cflag) { |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1019 | _mesa_EnableClientState( GL_COLOR_ARRAY ); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1020 | _mesa_ColorPointer( ccomps, ctype, stride, |
Brian Paul | 4a3110f | 2003-12-12 18:40:02 +0000 | [diff] [blame] | 1021 | (GLubyte *) pointer + coffset ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1022 | } |
| 1023 | else { |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1024 | _mesa_DisableClientState( GL_COLOR_ARRAY ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | |
| 1028 | /* Normals */ |
| 1029 | if (nflag) { |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1030 | _mesa_EnableClientState( GL_NORMAL_ARRAY ); |
Brian Paul | 4a3110f | 2003-12-12 18:40:02 +0000 | [diff] [blame] | 1031 | _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1032 | } |
| 1033 | else { |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1034 | _mesa_DisableClientState( GL_NORMAL_ARRAY ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
Brian Paul | 4a3110f | 2003-12-12 18:40:02 +0000 | [diff] [blame] | 1037 | /* Vertices */ |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1038 | _mesa_EnableClientState( GL_VERTEX_ARRAY ); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1039 | _mesa_VertexPointer( vcomps, GL_FLOAT, stride, |
| 1040 | (GLubyte *) pointer + voffset ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 1044 | void GLAPIENTRY |
Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 1045 | _mesa_LockArraysEXT(GLint first, GLsizei count) |
| 1046 | { |
| 1047 | GET_CURRENT_CONTEXT(ctx); |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 1048 | |
| 1049 | FLUSH_VERTICES(ctx, 0); |
Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 1050 | |
| 1051 | if (MESA_VERBOSE & VERBOSE_API) |
Brian Paul | 4753d60 | 2002-06-15 02:38:15 +0000 | [diff] [blame] | 1052 | _mesa_debug(ctx, "glLockArrays %d %d\n", first, count); |
Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 1053 | |
Eric Anholt | 5857e98 | 2008-02-02 02:54:13 -0800 | [diff] [blame] | 1054 | if (first < 0) { |
| 1055 | _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" ); |
| 1056 | return; |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 1057 | } |
Eric Anholt | 5857e98 | 2008-02-02 02:54:13 -0800 | [diff] [blame] | 1058 | if (count <= 0) { |
| 1059 | _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" ); |
| 1060 | return; |
Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 1061 | } |
Eric Anholt | 5857e98 | 2008-02-02 02:54:13 -0800 | [diff] [blame] | 1062 | if (ctx->Array.LockCount != 0) { |
| 1063 | _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" ); |
| 1064 | return; |
| 1065 | } |
| 1066 | |
| 1067 | ctx->Array.LockFirst = first; |
| 1068 | ctx->Array.LockCount = count; |
Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 1069 | |
| 1070 | ctx->NewState |= _NEW_ARRAY; |
Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 1074 | void GLAPIENTRY |
Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 1075 | _mesa_UnlockArraysEXT( void ) |
| 1076 | { |
| 1077 | GET_CURRENT_CONTEXT(ctx); |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 1078 | |
| 1079 | FLUSH_VERTICES(ctx, 0); |
Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 1080 | |
| 1081 | if (MESA_VERBOSE & VERBOSE_API) |
Brian Paul | 4753d60 | 2002-06-15 02:38:15 +0000 | [diff] [blame] | 1082 | _mesa_debug(ctx, "glUnlockArrays\n"); |
Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 1083 | |
Eric Anholt | 5857e98 | 2008-02-02 02:54:13 -0800 | [diff] [blame] | 1084 | if (ctx->Array.LockCount == 0) { |
| 1085 | _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" ); |
| 1086 | return; |
| 1087 | } |
| 1088 | |
Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 1089 | ctx->Array.LockFirst = 0; |
| 1090 | ctx->Array.LockCount = 0; |
| 1091 | ctx->NewState |= _NEW_ARRAY; |
Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 1092 | } |
Brian Paul | 2525bc7 | 2002-06-30 15:47:00 +0000 | [diff] [blame] | 1093 | |
| 1094 | |
Brian Paul | 2525bc7 | 2002-06-30 15:47:00 +0000 | [diff] [blame] | 1095 | /* GL_EXT_multi_draw_arrays */ |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 1096 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 1097 | _mesa_MultiDrawArrays( GLenum mode, const GLint *first, |
Brian Paul | 7993832 | 2010-09-14 09:37:35 -0600 | [diff] [blame] | 1098 | const GLsizei *count, GLsizei primcount ) |
Brian Paul | 2525bc7 | 2002-06-30 15:47:00 +0000 | [diff] [blame] | 1099 | { |
| 1100 | GET_CURRENT_CONTEXT(ctx); |
| 1101 | GLint i; |
| 1102 | |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 1103 | FLUSH_VERTICES(ctx, 0); |
Brian Paul | 2525bc7 | 2002-06-30 15:47:00 +0000 | [diff] [blame] | 1104 | |
| 1105 | for (i = 0; i < primcount; i++) { |
| 1106 | if (count[i] > 0) { |
Ian Romanick | 9bdfee3 | 2005-07-18 12:31:24 +0000 | [diff] [blame] | 1107 | CALL_DrawArrays(ctx->Exec, (mode, first[i], count[i])); |
Brian Paul | 2525bc7 | 2002-06-30 15:47:00 +0000 | [diff] [blame] | 1108 | } |
| 1109 | } |
| 1110 | } |
| 1111 | |
| 1112 | |
Ian Romanick | 3baefe6 | 2003-08-22 23:28:03 +0000 | [diff] [blame] | 1113 | /* GL_IBM_multimode_draw_arrays */ |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 1114 | void GLAPIENTRY |
Ian Romanick | 3baefe6 | 2003-08-22 23:28:03 +0000 | [diff] [blame] | 1115 | _mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first, |
| 1116 | const GLsizei * count, |
| 1117 | GLsizei primcount, GLint modestride ) |
| 1118 | { |
| 1119 | GET_CURRENT_CONTEXT(ctx); |
| 1120 | GLint i; |
| 1121 | |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 1122 | FLUSH_VERTICES(ctx, 0); |
Ian Romanick | 3baefe6 | 2003-08-22 23:28:03 +0000 | [diff] [blame] | 1123 | |
| 1124 | for ( i = 0 ; i < primcount ; i++ ) { |
| 1125 | if ( count[i] > 0 ) { |
Brian Paul | 03e29a5 | 2003-12-04 03:16:27 +0000 | [diff] [blame] | 1126 | GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride)); |
Ian Romanick | 9bdfee3 | 2005-07-18 12:31:24 +0000 | [diff] [blame] | 1127 | CALL_DrawArrays(ctx->Exec, ( m, first[i], count[i] )); |
Ian Romanick | 3baefe6 | 2003-08-22 23:28:03 +0000 | [diff] [blame] | 1128 | } |
| 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | |
| 1133 | /* GL_IBM_multimode_draw_arrays */ |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 1134 | void GLAPIENTRY |
Ian Romanick | 3baefe6 | 2003-08-22 23:28:03 +0000 | [diff] [blame] | 1135 | _mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count, |
| 1136 | GLenum type, const GLvoid * const * indices, |
| 1137 | GLsizei primcount, GLint modestride ) |
| 1138 | { |
| 1139 | GET_CURRENT_CONTEXT(ctx); |
| 1140 | GLint i; |
| 1141 | |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 1142 | FLUSH_VERTICES(ctx, 0); |
Ian Romanick | 3baefe6 | 2003-08-22 23:28:03 +0000 | [diff] [blame] | 1143 | |
Brian Paul | d2afb39 | 2003-09-17 18:15:13 +0000 | [diff] [blame] | 1144 | /* XXX not sure about ARB_vertex_buffer_object handling here */ |
| 1145 | |
Ian Romanick | 3baefe6 | 2003-08-22 23:28:03 +0000 | [diff] [blame] | 1146 | for ( i = 0 ; i < primcount ; i++ ) { |
| 1147 | if ( count[i] > 0 ) { |
Brian Paul | 03e29a5 | 2003-12-04 03:16:27 +0000 | [diff] [blame] | 1148 | GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride)); |
Ian Romanick | 9bdfee3 | 2005-07-18 12:31:24 +0000 | [diff] [blame] | 1149 | CALL_DrawElements(ctx->Exec, ( m, count[i], type, indices[i] )); |
Ian Romanick | 3baefe6 | 2003-08-22 23:28:03 +0000 | [diff] [blame] | 1150 | } |
| 1151 | } |
| 1152 | } |
| 1153 | |
| 1154 | |
Brian Paul | 095c669 | 2006-04-25 00:21:32 +0000 | [diff] [blame] | 1155 | /** |
Brian Paul | 7f26ad8 | 2010-10-21 19:03:38 -0600 | [diff] [blame] | 1156 | * GL_NV_primitive_restart and GL 3.1 |
Brian Paul | a40e6f2 | 2010-04-20 21:02:09 -0600 | [diff] [blame] | 1157 | */ |
| 1158 | void GLAPIENTRY |
| 1159 | _mesa_PrimitiveRestartIndex(GLuint index) |
| 1160 | { |
| 1161 | GET_CURRENT_CONTEXT(ctx); |
| 1162 | |
Eric Anholt | 9c1b418 | 2012-07-26 14:43:56 -0700 | [diff] [blame] | 1163 | if (!ctx->Extensions.NV_primitive_restart && ctx->Version < 31) { |
Brian Paul | 7f26ad8 | 2010-10-21 19:03:38 -0600 | [diff] [blame] | 1164 | _mesa_error(ctx, GL_INVALID_OPERATION, "glPrimitiveRestartIndexNV()"); |
Brian Paul | a40e6f2 | 2010-04-20 21:02:09 -0600 | [diff] [blame] | 1165 | return; |
| 1166 | } |
| 1167 | |
Kenneth Graunke | e6efb90 | 2013-05-29 08:31:54 -0700 | [diff] [blame] | 1168 | if (ctx->Array.RestartIndex != index) { |
Brian Paul | d2003ee | 2012-02-19 19:50:32 -0700 | [diff] [blame] | 1169 | FLUSH_VERTICES(ctx, _NEW_TRANSFORM); |
Kenneth Graunke | e6efb90 | 2013-05-29 08:31:54 -0700 | [diff] [blame] | 1170 | ctx->Array.RestartIndex = index; |
Brian Paul | d2003ee | 2012-02-19 19:50:32 -0700 | [diff] [blame] | 1171 | } |
Brian Paul | a40e6f2 | 2010-04-20 21:02:09 -0600 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | |
| 1175 | /** |
Brian Paul | 1d1eb95 | 2011-01-15 10:32:34 -0700 | [diff] [blame] | 1176 | * See GL_ARB_instanced_arrays. |
| 1177 | * Note that the instance divisor only applies to generic arrays, not |
| 1178 | * the legacy vertex arrays. |
| 1179 | */ |
| 1180 | void GLAPIENTRY |
| 1181 | _mesa_VertexAttribDivisor(GLuint index, GLuint divisor) |
| 1182 | { |
Brian Paul | 738482e | 2012-02-27 20:28:09 -0700 | [diff] [blame] | 1183 | struct gl_client_array *array; |
Brian Paul | 1d1eb95 | 2011-01-15 10:32:34 -0700 | [diff] [blame] | 1184 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | 1d1eb95 | 2011-01-15 10:32:34 -0700 | [diff] [blame] | 1185 | |
| 1186 | if (!ctx->Extensions.ARB_instanced_arrays) { |
| 1187 | _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()"); |
| 1188 | return; |
| 1189 | } |
| 1190 | |
| 1191 | if (index >= ctx->Const.VertexProgram.MaxAttribs) { |
Matt Turner | ae1f09b | 2012-11-13 13:05:03 -0800 | [diff] [blame] | 1192 | _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribDivisor(index = %u)", |
Brian Paul | 1d1eb95 | 2011-01-15 10:32:34 -0700 | [diff] [blame] | 1193 | index); |
| 1194 | return; |
| 1195 | } |
| 1196 | |
Fredrik Höglund | 12cbe99 | 2013-04-03 22:08:47 +0200 | [diff] [blame] | 1197 | ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.ArrayObj->_VertexAttrib)); |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 1198 | |
Fredrik Höglund | 12cbe99 | 2013-04-03 22:08:47 +0200 | [diff] [blame] | 1199 | array = &ctx->Array.ArrayObj->_VertexAttrib[VERT_ATTRIB_GENERIC(index)]; |
Brian Paul | 738482e | 2012-02-27 20:28:09 -0700 | [diff] [blame] | 1200 | if (array->InstanceDivisor != divisor) { |
| 1201 | FLUSH_VERTICES(ctx, _NEW_ARRAY); |
| 1202 | array->InstanceDivisor = divisor; |
Fredrik Höglund | 6a650fa | 2013-05-11 19:23:46 +0200 | [diff] [blame] | 1203 | ctx->Array.ArrayObj->NewArrays |= VERT_BIT(VERT_ATTRIB_GENERIC(index)); |
Brian Paul | 738482e | 2012-02-27 20:28:09 -0700 | [diff] [blame] | 1204 | } |
Brian Paul | 1d1eb95 | 2011-01-15 10:32:34 -0700 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | |
Kenneth Graunke | 959d076 | 2013-05-29 08:07:01 -0700 | [diff] [blame] | 1208 | unsigned |
| 1209 | _mesa_primitive_restart_index(const struct gl_context *ctx, GLenum ib_type) |
| 1210 | { |
| 1211 | /* From the OpenGL 4.3 core specification, page 302: |
| 1212 | * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are |
| 1213 | * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX |
| 1214 | * is used." |
| 1215 | */ |
| 1216 | if (ctx->Array.PrimitiveRestartFixedIndex) { |
| 1217 | switch (ib_type) { |
| 1218 | case GL_UNSIGNED_BYTE: |
| 1219 | return 0xff; |
| 1220 | case GL_UNSIGNED_SHORT: |
| 1221 | return 0xffff; |
| 1222 | case GL_UNSIGNED_INT: |
| 1223 | return 0xffffffff; |
| 1224 | default: |
| 1225 | assert(!"_mesa_primitive_restart_index: Invalid index buffer type."); |
| 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | return ctx->Array.RestartIndex; |
| 1230 | } |
| 1231 | |
Brian Paul | 1d1eb95 | 2011-01-15 10:32:34 -0700 | [diff] [blame] | 1232 | |
| 1233 | /** |
Fredrik Höglund | bb2d02c | 2013-04-09 20:44:58 +0200 | [diff] [blame^] | 1234 | * GL_ARB_vertex_attrib_binding |
| 1235 | */ |
| 1236 | void GLAPIENTRY |
| 1237 | _mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset, |
| 1238 | GLsizei stride) |
| 1239 | { |
| 1240 | } |
| 1241 | |
| 1242 | |
| 1243 | void GLAPIENTRY |
| 1244 | _mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type, |
| 1245 | GLboolean normalized, GLuint relativeOffset) |
| 1246 | { |
| 1247 | } |
| 1248 | |
| 1249 | |
| 1250 | void GLAPIENTRY |
| 1251 | _mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type, |
| 1252 | GLuint relativeOffset) |
| 1253 | { |
| 1254 | } |
| 1255 | |
| 1256 | |
| 1257 | void GLAPIENTRY |
| 1258 | _mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type, |
| 1259 | GLuint relativeOffset) |
| 1260 | { |
| 1261 | } |
| 1262 | |
| 1263 | |
| 1264 | void GLAPIENTRY |
| 1265 | _mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex) |
| 1266 | { |
| 1267 | } |
| 1268 | |
| 1269 | |
| 1270 | void GLAPIENTRY |
| 1271 | _mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor) |
| 1272 | { |
| 1273 | } |
| 1274 | |
| 1275 | |
| 1276 | /** |
Brian Paul | b288540 | 2009-08-06 13:53:06 -0600 | [diff] [blame] | 1277 | * Copy one client vertex array to another. |
| 1278 | */ |
| 1279 | void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 1280 | _mesa_copy_client_array(struct gl_context *ctx, |
Brian Paul | b288540 | 2009-08-06 13:53:06 -0600 | [diff] [blame] | 1281 | struct gl_client_array *dst, |
| 1282 | struct gl_client_array *src) |
| 1283 | { |
| 1284 | dst->Size = src->Size; |
| 1285 | dst->Type = src->Type; |
| 1286 | dst->Format = src->Format; |
| 1287 | dst->Stride = src->Stride; |
| 1288 | dst->StrideB = src->StrideB; |
| 1289 | dst->Ptr = src->Ptr; |
| 1290 | dst->Enabled = src->Enabled; |
| 1291 | dst->Normalized = src->Normalized; |
Brian Paul | d1184d2 | 2010-10-28 21:17:41 -0600 | [diff] [blame] | 1292 | dst->Integer = src->Integer; |
Brian Paul | 1d1eb95 | 2011-01-15 10:32:34 -0700 | [diff] [blame] | 1293 | dst->InstanceDivisor = src->InstanceDivisor; |
Brian Paul | b288540 | 2009-08-06 13:53:06 -0600 | [diff] [blame] | 1294 | dst->_ElementSize = src->_ElementSize; |
| 1295 | _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj); |
| 1296 | dst->_MaxElement = src->_MaxElement; |
| 1297 | } |
| 1298 | |
| 1299 | |
| 1300 | |
| 1301 | /** |
Brian Paul | 39d7524 | 2009-05-14 16:25:32 -0600 | [diff] [blame] | 1302 | * Print vertex array's fields. |
| 1303 | */ |
| 1304 | static void |
| 1305 | print_array(const char *name, GLint index, const struct gl_client_array *array) |
| 1306 | { |
| 1307 | if (index >= 0) |
Kristian Høgsberg | 298be2b | 2010-02-19 12:32:24 -0500 | [diff] [blame] | 1308 | printf(" %s[%d]: ", name, index); |
Brian Paul | 39d7524 | 2009-05-14 16:25:32 -0600 | [diff] [blame] | 1309 | else |
Kristian Høgsberg | 298be2b | 2010-02-19 12:32:24 -0500 | [diff] [blame] | 1310 | printf(" %s: ", name); |
Brian Paul | 4beea12 | 2010-07-14 14:36:25 -0600 | [diff] [blame] | 1311 | printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu), MaxElem=%u\n", |
Kristian Høgsberg | 298be2b | 2010-02-19 12:32:24 -0500 | [diff] [blame] | 1312 | array->Ptr, array->Type, array->Size, |
| 1313 | array->_ElementSize, array->StrideB, |
Brian Paul | 4beea12 | 2010-07-14 14:36:25 -0600 | [diff] [blame] | 1314 | array->BufferObj->Name, (unsigned long) array->BufferObj->Size, |
Kristian Høgsberg | 298be2b | 2010-02-19 12:32:24 -0500 | [diff] [blame] | 1315 | array->_MaxElement); |
Brian Paul | 39d7524 | 2009-05-14 16:25:32 -0600 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | |
| 1319 | /** |
| 1320 | * Print current vertex object/array info. For debug. |
| 1321 | */ |
| 1322 | void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 1323 | _mesa_print_arrays(struct gl_context *ctx) |
Brian Paul | 39d7524 | 2009-05-14 16:25:32 -0600 | [diff] [blame] | 1324 | { |
Brian Paul | 6a2211f | 2009-05-21 15:55:50 -0600 | [diff] [blame] | 1325 | struct gl_array_object *arrayObj = ctx->Array.ArrayObj; |
Brian Paul | 39d7524 | 2009-05-14 16:25:32 -0600 | [diff] [blame] | 1326 | GLuint i; |
| 1327 | |
Brian Paul | 8fe3134 | 2009-05-21 15:36:25 -0600 | [diff] [blame] | 1328 | _mesa_update_array_object_max_element(ctx, arrayObj); |
| 1329 | |
Kristian Høgsberg | 298be2b | 2010-02-19 12:32:24 -0500 | [diff] [blame] | 1330 | printf("Array Object %u\n", arrayObj->Name); |
Fredrik Höglund | 12cbe99 | 2013-04-03 22:08:47 +0200 | [diff] [blame] | 1331 | if (arrayObj->_VertexAttrib[VERT_ATTRIB_POS].Enabled) |
| 1332 | print_array("Vertex", -1, &arrayObj->_VertexAttrib[VERT_ATTRIB_POS]); |
| 1333 | if (arrayObj->_VertexAttrib[VERT_ATTRIB_NORMAL].Enabled) |
| 1334 | print_array("Normal", -1, &arrayObj->_VertexAttrib[VERT_ATTRIB_NORMAL]); |
| 1335 | if (arrayObj->_VertexAttrib[VERT_ATTRIB_COLOR0].Enabled) |
| 1336 | print_array("Color", -1, &arrayObj->_VertexAttrib[VERT_ATTRIB_COLOR0]); |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 1337 | for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) |
Fredrik Höglund | 12cbe99 | 2013-04-03 22:08:47 +0200 | [diff] [blame] | 1338 | if (arrayObj->_VertexAttrib[VERT_ATTRIB_TEX(i)].Enabled) |
| 1339 | print_array("TexCoord", i, &arrayObj->_VertexAttrib[VERT_ATTRIB_TEX(i)]); |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 1340 | for (i = 0; i < VERT_ATTRIB_GENERIC_MAX; i++) |
Fredrik Höglund | 12cbe99 | 2013-04-03 22:08:47 +0200 | [diff] [blame] | 1341 | if (arrayObj->_VertexAttrib[VERT_ATTRIB_GENERIC(i)].Enabled) |
| 1342 | print_array("Attrib", i, &arrayObj->_VertexAttrib[VERT_ATTRIB_GENERIC(i)]); |
Kristian Høgsberg | 298be2b | 2010-02-19 12:32:24 -0500 | [diff] [blame] | 1343 | printf(" _MaxElement = %u\n", arrayObj->_MaxElement); |
Brian Paul | 39d7524 | 2009-05-14 16:25:32 -0600 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | |
| 1347 | /** |
Brian Paul | 095c669 | 2006-04-25 00:21:32 +0000 | [diff] [blame] | 1348 | * Initialize vertex array state for given context. |
| 1349 | */ |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 1350 | void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 1351 | _mesa_init_varray(struct gl_context *ctx) |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1352 | { |
Mathias Fröhlich | 86f53e6 | 2011-11-02 19:54:26 +0100 | [diff] [blame] | 1353 | ctx->Array.DefaultArrayObj = ctx->Driver.NewArrayObject(ctx, 0); |
Brian Paul | 1030bf0 | 2009-05-07 13:52:26 -0600 | [diff] [blame] | 1354 | _mesa_reference_array_object(ctx, &ctx->Array.ArrayObj, |
| 1355 | ctx->Array.DefaultArrayObj); |
Brian Paul | 095c669 | 2006-04-25 00:21:32 +0000 | [diff] [blame] | 1356 | ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */ |
Brian Paul | 12cf98f | 2009-06-19 17:58:47 -0600 | [diff] [blame] | 1357 | |
| 1358 | ctx->Array.Objects = _mesa_NewHashTable(); |
| 1359 | } |
| 1360 | |
| 1361 | |
| 1362 | /** |
| 1363 | * Callback for deleting an array object. Called by _mesa_HashDeleteAll(). |
| 1364 | */ |
| 1365 | static void |
| 1366 | delete_arrayobj_cb(GLuint id, void *data, void *userData) |
| 1367 | { |
| 1368 | struct gl_array_object *arrayObj = (struct gl_array_object *) data; |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 1369 | struct gl_context *ctx = (struct gl_context *) userData; |
Brian Paul | 12cf98f | 2009-06-19 17:58:47 -0600 | [diff] [blame] | 1370 | _mesa_delete_array_object(ctx, arrayObj); |
| 1371 | } |
| 1372 | |
| 1373 | |
| 1374 | /** |
| 1375 | * Free vertex array state for given context. |
| 1376 | */ |
| 1377 | void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 1378 | _mesa_free_varray_data(struct gl_context *ctx) |
Brian Paul | 12cf98f | 2009-06-19 17:58:47 -0600 | [diff] [blame] | 1379 | { |
| 1380 | _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx); |
| 1381 | _mesa_DeleteHashTable(ctx->Array.Objects); |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1382 | } |