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 | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 106 | * Sets the VertexBinding field in the vertex attribute given by attribIndex. |
| 107 | */ |
| 108 | static void |
| 109 | vertex_attrib_binding(struct gl_context *ctx, GLuint attribIndex, |
| 110 | GLuint bindingIndex) |
| 111 | { |
| 112 | struct gl_array_object *arrayObj = ctx->Array.ArrayObj; |
| 113 | struct gl_vertex_attrib_array *array = &arrayObj->VertexAttrib[attribIndex]; |
| 114 | |
| 115 | if (array->VertexBinding != bindingIndex) { |
| 116 | const GLbitfield64 array_bit = VERT_BIT(attribIndex); |
| 117 | |
| 118 | FLUSH_VERTICES(ctx, _NEW_ARRAY); |
| 119 | |
| 120 | arrayObj->VertexBinding[array->VertexBinding]._BoundArrays &= ~array_bit; |
| 121 | arrayObj->VertexBinding[bindingIndex]._BoundArrays |= array_bit; |
| 122 | |
| 123 | array->VertexBinding = bindingIndex; |
| 124 | |
| 125 | arrayObj->NewArrays |= array_bit; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | |
| 130 | /** |
| 131 | * Binds a buffer object to the vertex buffer binding point given by index, |
| 132 | * and sets the Offset and Stride fields. |
| 133 | */ |
| 134 | static void |
| 135 | bind_vertex_buffer(struct gl_context *ctx, GLuint index, |
| 136 | struct gl_buffer_object *vbo, |
| 137 | GLintptr offset, GLsizei stride) |
| 138 | { |
| 139 | struct gl_array_object *arrayObj = ctx->Array.ArrayObj; |
| 140 | struct gl_vertex_buffer_binding *binding = &arrayObj->VertexBinding[index]; |
| 141 | |
| 142 | if (binding->BufferObj != vbo || |
| 143 | binding->Offset != offset || |
| 144 | binding->Stride != stride) { |
| 145 | |
| 146 | FLUSH_VERTICES(ctx, _NEW_ARRAY); |
| 147 | |
| 148 | _mesa_reference_buffer_object(ctx, &binding->BufferObj, vbo); |
| 149 | |
| 150 | binding->Offset = offset; |
| 151 | binding->Stride = stride; |
| 152 | |
| 153 | arrayObj->NewArrays |= binding->_BoundArrays; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | |
| 158 | /** |
| 159 | * Sets the InstanceDivisor field in the vertex buffer binding point |
| 160 | * given by bindingIndex. |
| 161 | */ |
| 162 | static void |
| 163 | vertex_binding_divisor(struct gl_context *ctx, GLuint bindingIndex, |
| 164 | GLuint divisor) |
| 165 | { |
| 166 | struct gl_array_object *arrayObj = ctx->Array.ArrayObj; |
| 167 | struct gl_vertex_buffer_binding *binding = |
| 168 | &arrayObj->VertexBinding[bindingIndex]; |
| 169 | |
| 170 | if (binding->InstanceDivisor != divisor) { |
| 171 | FLUSH_VERTICES(ctx, _NEW_ARRAY); |
| 172 | binding->InstanceDivisor = divisor; |
| 173 | arrayObj->NewArrays |= binding->_BoundArrays; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | |
| 178 | /** |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 179 | * Does error checking and updates the format in an attrib array. |
Brian Paul | f9d88c8 | 2006-06-13 17:24:36 +0000 | [diff] [blame] | 180 | * |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 181 | * Called by update_array() and VertexAttrib*Format(). |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 182 | * |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 183 | * \param func Name of calling function used for error reporting |
| 184 | * \param attrib The index of the attribute array |
| 185 | * \param legalTypes Bitmask of *_BIT above indicating legal datatypes |
| 186 | * \param sizeMin Min allowable size value |
| 187 | * \param sizeMax Max allowable size value (may also be BGRA_OR_4) |
| 188 | * \param size Components per element (1, 2, 3 or 4) |
| 189 | * \param type Datatype of each component (GL_FLOAT, GL_INT, etc) |
| 190 | * \param normalized Whether integer types are converted to floats in [-1, 1] |
| 191 | * \param integer Integer-valued values (will not be normalized to [-1, 1]) |
| 192 | * \param relativeOffset Offset of the first element relative to the binding offset. |
Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame] | 193 | */ |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 194 | static bool |
| 195 | update_array_format(struct gl_context *ctx, |
| 196 | const char *func, |
| 197 | GLuint attrib, GLbitfield legalTypesMask, |
| 198 | GLint sizeMin, GLint sizeMax, |
| 199 | GLint size, GLenum type, |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 200 | GLboolean normalized, GLboolean integer, |
| 201 | GLuint relativeOffset) |
Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame] | 202 | { |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 203 | struct gl_vertex_attrib_array *array; |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 204 | GLbitfield typeBit; |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 205 | GLuint elementSize; |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 206 | GLenum format = GL_RGBA; |
| 207 | |
Ian Romanick | bbceed2 | 2012-07-25 14:40:18 -0700 | [diff] [blame] | 208 | if (_mesa_is_gles(ctx)) { |
Matt Turner | c890113 | 2012-11-28 21:45:19 -0800 | [diff] [blame] | 209 | legalTypesMask &= ~(FIXED_GL_BIT | DOUBLE_BIT); |
Ian Romanick | bbceed2 | 2012-07-25 14:40:18 -0700 | [diff] [blame] | 210 | |
| 211 | /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until |
| 212 | * 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] | 213 | * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed |
| 214 | * until 3.0 or with the GL_OES_vertex_half float extension, which isn't |
| 215 | * quite as trivial as we'd like because it uses a different enum value |
| 216 | * for GL_HALF_FLOAT_OES. |
Ian Romanick | bbceed2 | 2012-07-25 14:40:18 -0700 | [diff] [blame] | 217 | */ |
| 218 | if (ctx->Version < 30) { |
| 219 | legalTypesMask &= ~(UNSIGNED_INT_BIT |
| 220 | | INT_BIT |
| 221 | | UNSIGNED_INT_2_10_10_10_REV_BIT |
Matt Turner | c890113 | 2012-11-28 21:45:19 -0800 | [diff] [blame] | 222 | | INT_2_10_10_10_REV_BIT |
| 223 | | HALF_BIT); |
Ian Romanick | bbceed2 | 2012-07-25 14:40:18 -0700 | [diff] [blame] | 224 | } |
Ian Romanick | 946ddec | 2012-07-25 14:46:54 -0700 | [diff] [blame] | 225 | |
| 226 | /* BGRA ordering is not supported in ES contexts. |
| 227 | */ |
| 228 | if (sizeMax == BGRA_OR_4) |
| 229 | sizeMax = 4; |
Ian Romanick | bbceed2 | 2012-07-25 14:40:18 -0700 | [diff] [blame] | 230 | } else { |
Marek Olšák | 0f1e59d | 2011-04-29 14:23:15 +0200 | [diff] [blame] | 231 | legalTypesMask &= ~FIXED_ES_BIT; |
Ian Romanick | bbceed2 | 2012-07-25 14:40:18 -0700 | [diff] [blame] | 232 | |
| 233 | if (!ctx->Extensions.ARB_ES2_compatibility) |
| 234 | legalTypesMask &= ~FIXED_GL_BIT; |
| 235 | |
| 236 | if (!ctx->Extensions.ARB_vertex_type_2_10_10_10_rev) |
| 237 | legalTypesMask &= ~(UNSIGNED_INT_2_10_10_10_REV_BIT | |
| 238 | INT_2_10_10_10_REV_BIT); |
Dave Airlie | 6cd2d55 | 2011-08-13 15:30:38 +0100 | [diff] [blame] | 239 | } |
Brian Paul | 11dd228 | 2010-11-07 18:35:35 -0700 | [diff] [blame] | 240 | |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 241 | typeBit = type_to_bit(ctx, type); |
| 242 | if (typeBit == 0x0 || (typeBit & legalTypesMask) == 0x0) { |
| 243 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)", |
| 244 | func, _mesa_lookup_enum_by_nr(type)); |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 245 | return false; |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | /* Do size parameter checking. |
| 249 | * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and |
| 250 | * must be handled specially. |
| 251 | */ |
| 252 | if (ctx->Extensions.EXT_vertex_array_bgra && |
| 253 | sizeMax == BGRA_OR_4 && |
| 254 | size == GL_BGRA) { |
Fredrik Höglund | 0e7a61a | 2013-04-12 17:36:06 +0200 | [diff] [blame] | 255 | /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says: |
| 256 | * |
| 257 | * "An INVALID_OPERATION error is generated under any of the following |
| 258 | * conditions: |
| 259 | * ... |
| 260 | * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV |
| 261 | * or UNSIGNED_INT_2_10_10_10_REV; |
| 262 | * ... |
| 263 | * • size is BGRA and normalized is FALSE;" |
| 264 | */ |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 265 | bool bgra_error = false; |
Dave Airlie | 99c1a58 | 2011-09-07 10:19:14 +0100 | [diff] [blame] | 266 | |
| 267 | if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev) { |
| 268 | if (type != GL_UNSIGNED_INT_2_10_10_10_REV && |
| 269 | type != GL_INT_2_10_10_10_REV && |
| 270 | type != GL_UNSIGNED_BYTE) |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 271 | bgra_error = true; |
Dave Airlie | 99c1a58 | 2011-09-07 10:19:14 +0100 | [diff] [blame] | 272 | } else if (type != GL_UNSIGNED_BYTE) |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 273 | bgra_error = true; |
Dave Airlie | 99c1a58 | 2011-09-07 10:19:14 +0100 | [diff] [blame] | 274 | |
| 275 | if (bgra_error) { |
Fredrik Höglund | 0e7a61a | 2013-04-12 17:36:06 +0200 | [diff] [blame] | 276 | _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=GL_BGRA and type=%s)", |
| 277 | func, _mesa_lookup_enum_by_nr(type)); |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 278 | return false; |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 279 | } |
Fredrik Höglund | 0e7a61a | 2013-04-12 17:36:06 +0200 | [diff] [blame] | 280 | |
| 281 | if (!normalized) { |
| 282 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 283 | "%s(size=GL_BGRA and normalized=GL_FALSE)", func); |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 284 | return false; |
Fredrik Höglund | 0e7a61a | 2013-04-12 17:36:06 +0200 | [diff] [blame] | 285 | } |
| 286 | |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 287 | format = GL_BGRA; |
| 288 | size = 4; |
| 289 | } |
| 290 | else if (size < sizeMin || size > sizeMax || size > 4) { |
| 291 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d)", func, size); |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 292 | return false; |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 293 | } |
| 294 | |
Dave Airlie | 6cd2d55 | 2011-08-13 15:30:38 +0100 | [diff] [blame] | 295 | if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev && |
| 296 | (type == GL_UNSIGNED_INT_2_10_10_10_REV || |
| 297 | type == GL_INT_2_10_10_10_REV) && size != 4) { |
| 298 | _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size); |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 299 | return false; |
Dave Airlie | 6cd2d55 | 2011-08-13 15:30:38 +0100 | [diff] [blame] | 300 | } |
| 301 | |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 302 | /* The ARB_vertex_attrib_binding_spec says: |
| 303 | * |
| 304 | * An INVALID_VALUE error is generated if <relativeoffset> is larger than |
| 305 | * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET. |
| 306 | */ |
| 307 | if (relativeOffset > ctx->Const.MaxVertexAttribRelativeOffset) { |
| 308 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 309 | "%s(relativeOffset=%d > " |
| 310 | "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)", |
| 311 | func, relativeOffset); |
| 312 | return GL_FALSE; |
| 313 | } |
| 314 | |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 315 | ASSERT(size <= 4); |
| 316 | |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 317 | elementSize = _mesa_bytes_per_vertex_attrib(size, type); |
| 318 | assert(elementSize != -1); |
| 319 | |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 320 | array = &ctx->Array.ArrayObj->VertexAttrib[attrib]; |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 321 | array->Size = size; |
| 322 | array->Type = type; |
| 323 | array->Format = format; |
| 324 | array->Normalized = normalized; |
| 325 | array->Integer = integer; |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 326 | array->RelativeOffset = relativeOffset; |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 327 | array->_ElementSize = elementSize; |
| 328 | |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 329 | ctx->Array.ArrayObj->NewArrays |= VERT_BIT(attrib); |
| 330 | ctx->NewState |= _NEW_ARRAY; |
| 331 | |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 332 | return true; |
| 333 | } |
| 334 | |
| 335 | |
| 336 | /** |
| 337 | * Do error checking and update state for glVertex/Color/TexCoord/...Pointer |
| 338 | * functions. |
| 339 | * |
| 340 | * \param func name of calling function used for error reporting |
| 341 | * \param attrib the attribute array index to update |
| 342 | * \param legalTypes bitmask of *_BIT above indicating legal datatypes |
| 343 | * \param sizeMin min allowable size value |
| 344 | * \param sizeMax max allowable size value (may also be BGRA_OR_4) |
| 345 | * \param size components per element (1, 2, 3 or 4) |
| 346 | * \param type datatype of each component (GL_FLOAT, GL_INT, etc) |
| 347 | * \param stride stride between elements, in elements |
| 348 | * \param normalized are integer types converted to floats in [-1, 1]? |
| 349 | * \param integer integer-valued values (will not be normalized to [-1,1]) |
| 350 | * \param ptr the address (or offset inside VBO) of the array data |
| 351 | */ |
| 352 | static void |
| 353 | update_array(struct gl_context *ctx, |
| 354 | const char *func, |
| 355 | GLuint attrib, GLbitfield legalTypesMask, |
| 356 | GLint sizeMin, GLint sizeMax, |
| 357 | GLint size, GLenum type, GLsizei stride, |
| 358 | GLboolean normalized, GLboolean integer, |
| 359 | const GLvoid *ptr) |
| 360 | { |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 361 | struct gl_vertex_attrib_array *array; |
| 362 | GLsizei effectiveStride; |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 363 | |
| 364 | /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says: |
| 365 | * |
| 366 | * "Client vertex arrays - all vertex array attribute pointers must |
| 367 | * refer to buffer objects (section 2.9.2). The default vertex array |
| 368 | * object (the name zero) is also deprecated. Calling |
| 369 | * VertexAttribPointer when no buffer object or no vertex array object |
| 370 | * is bound will generate an INVALID_OPERATION error..." |
| 371 | * |
| 372 | * The check for VBOs is handled below. |
| 373 | */ |
| 374 | if (ctx->API == API_OPENGL_CORE |
| 375 | && (ctx->Array.ArrayObj == ctx->Array.DefaultArrayObj)) { |
| 376 | _mesa_error(ctx, GL_INVALID_OPERATION, "%s(no array object bound)", |
| 377 | func); |
| 378 | return; |
| 379 | } |
| 380 | |
| 381 | if (!update_array_format(ctx, func, attrib, legalTypesMask, sizeMin, sizeMax, |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 382 | size, type, normalized, integer, 0)) { |
Fredrik Höglund | d554321 | 2013-04-03 21:47:44 +0200 | [diff] [blame] | 383 | return; |
| 384 | } |
| 385 | |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 386 | if (stride < 0) { |
| 387 | _mesa_error( ctx, GL_INVALID_VALUE, "%s(stride=%d)", func, stride ); |
| 388 | return; |
| 389 | } |
Brian Paul | e2b7249 | 2009-06-22 16:56:35 -0600 | [diff] [blame] | 390 | |
Ian Romanick | 843b876 | 2012-08-17 17:12:39 -0700 | [diff] [blame] | 391 | /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says: |
| 392 | * |
| 393 | * "An INVALID_OPERATION error is generated under any of the following |
| 394 | * conditions: |
| 395 | * |
| 396 | * ... |
| 397 | * |
| 398 | * * any of the *Pointer commands specifying the location and |
| 399 | * organization of vertex array data are called while zero is bound |
| 400 | * to the ARRAY_BUFFER buffer object binding point (see section |
| 401 | * 2.9.6), and the pointer argument is not NULL." |
| 402 | */ |
| 403 | if (ptr != NULL && ctx->Array.ArrayObj->ARBsemantics && |
Brian Paul | efcf5aa | 2011-11-29 07:44:20 -0700 | [diff] [blame] | 404 | !_mesa_is_bufferobj(ctx->Array.ArrayBufferObj)) { |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 405 | _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-VBO array)", func); |
Brian Paul | f549f4c | 2009-11-12 23:04:26 -0700 | [diff] [blame] | 406 | return; |
Brian Paul | e2b7249 | 2009-06-22 16:56:35 -0600 | [diff] [blame] | 407 | } |
| 408 | |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 409 | /* Reset the vertex attrib binding */ |
| 410 | vertex_attrib_binding(ctx, attrib, attrib); |
| 411 | |
| 412 | /* The Stride and Ptr fields are not set by update_array_format() */ |
| 413 | array = &ctx->Array.ArrayObj->VertexAttrib[attrib]; |
Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame] | 414 | array->Stride = stride; |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 415 | array->Ptr = (const GLvoid *) ptr; |
Brian Paul | 0077c87 | 2009-05-06 13:00:35 -0600 | [diff] [blame] | 416 | |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 417 | /* Update the vertex buffer binding */ |
| 418 | effectiveStride = stride != 0 ? stride : array->_ElementSize; |
| 419 | bind_vertex_buffer(ctx, attrib, ctx->Array.ArrayBufferObj, |
| 420 | (GLintptr) ptr, effectiveStride); |
Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 424 | void GLAPIENTRY |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 425 | _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 426 | { |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 427 | GET_CURRENT_CONTEXT(ctx); |
Ian Romanick | e2cf14d | 2012-07-25 15:19:31 -0700 | [diff] [blame] | 428 | GLbitfield legalTypes = (ctx->API == API_OPENGLES) |
| 429 | ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT) |
| 430 | : (SHORT_BIT | INT_BIT | FLOAT_BIT | |
| 431 | DOUBLE_BIT | HALF_BIT | |
| 432 | UNSIGNED_INT_2_10_10_10_REV_BIT | |
| 433 | INT_2_10_10_10_REV_BIT); |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 434 | |
| 435 | FLUSH_VERTICES(ctx, 0); |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 436 | |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 437 | update_array(ctx, "glVertexPointer", VERT_ATTRIB_POS, |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 438 | legalTypes, 2, 4, |
| 439 | size, type, stride, GL_FALSE, GL_FALSE, ptr); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 443 | void GLAPIENTRY |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 444 | _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 445 | { |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 446 | GET_CURRENT_CONTEXT(ctx); |
Ian Romanick | e5ef0cb | 2012-07-25 15:10:21 -0700 | [diff] [blame] | 447 | const GLbitfield legalTypes = (ctx->API == API_OPENGLES) |
| 448 | ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT) |
| 449 | : (BYTE_BIT | SHORT_BIT | INT_BIT | |
| 450 | HALF_BIT | FLOAT_BIT | DOUBLE_BIT | |
| 451 | UNSIGNED_INT_2_10_10_10_REV_BIT | |
| 452 | INT_2_10_10_10_REV_BIT); |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 453 | |
| 454 | FLUSH_VERTICES(ctx, 0); |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 455 | |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 456 | update_array(ctx, "glNormalPointer", VERT_ATTRIB_NORMAL, |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 457 | legalTypes, 3, 3, |
| 458 | 3, type, stride, GL_TRUE, GL_FALSE, ptr); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 462 | void GLAPIENTRY |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 463 | _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 464 | { |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 465 | GET_CURRENT_CONTEXT(ctx); |
Ian Romanick | 07ccfef | 2012-07-25 14:53:01 -0700 | [diff] [blame] | 466 | const GLbitfield legalTypes = (ctx->API == API_OPENGLES) |
| 467 | ? (UNSIGNED_BYTE_BIT | HALF_BIT | FLOAT_BIT | FIXED_ES_BIT) |
| 468 | : (BYTE_BIT | UNSIGNED_BYTE_BIT | |
| 469 | SHORT_BIT | UNSIGNED_SHORT_BIT | |
| 470 | INT_BIT | UNSIGNED_INT_BIT | |
| 471 | HALF_BIT | FLOAT_BIT | DOUBLE_BIT | |
| 472 | UNSIGNED_INT_2_10_10_10_REV_BIT | |
| 473 | INT_2_10_10_10_REV_BIT); |
Ian Romanick | fb82185 | 2012-07-25 14:58:36 -0700 | [diff] [blame] | 474 | const GLint sizeMin = (ctx->API == API_OPENGLES) ? 4 : 3; |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 475 | |
| 476 | FLUSH_VERTICES(ctx, 0); |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 477 | |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 478 | update_array(ctx, "glColorPointer", VERT_ATTRIB_COLOR0, |
Ian Romanick | fb82185 | 2012-07-25 14:58:36 -0700 | [diff] [blame] | 479 | legalTypes, sizeMin, BGRA_OR_4, |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 480 | size, type, stride, GL_TRUE, GL_FALSE, ptr); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 484 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 485 | _mesa_FogCoordPointer(GLenum type, GLsizei stride, const GLvoid *ptr) |
Keith Whitwell | fe5d67d | 2000-10-27 16:44:40 +0000 | [diff] [blame] | 486 | { |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 487 | const GLbitfield legalTypes = (HALF_BIT | FLOAT_BIT | DOUBLE_BIT); |
Keith Whitwell | fe5d67d | 2000-10-27 16:44:40 +0000 | [diff] [blame] | 488 | GET_CURRENT_CONTEXT(ctx); |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 489 | |
| 490 | FLUSH_VERTICES(ctx, 0); |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 491 | |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 492 | update_array(ctx, "glFogCoordPointer", VERT_ATTRIB_FOG, |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 493 | legalTypes, 1, 1, |
| 494 | 1, type, stride, GL_FALSE, GL_FALSE, ptr); |
Keith Whitwell | fe5d67d | 2000-10-27 16:44:40 +0000 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 498 | void GLAPIENTRY |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 499 | _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 500 | { |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 501 | const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT | INT_BIT | |
| 502 | FLOAT_BIT | DOUBLE_BIT); |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 503 | GET_CURRENT_CONTEXT(ctx); |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 504 | |
| 505 | FLUSH_VERTICES(ctx, 0); |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 506 | |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 507 | update_array(ctx, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX, |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 508 | legalTypes, 1, 1, |
| 509 | 1, type, stride, GL_FALSE, GL_FALSE, ptr); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 513 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 514 | _mesa_SecondaryColorPointer(GLint size, GLenum type, |
Keith Whitwell | fe5d67d | 2000-10-27 16:44:40 +0000 | [diff] [blame] | 515 | GLsizei stride, const GLvoid *ptr) |
| 516 | { |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 517 | const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT | |
| 518 | SHORT_BIT | UNSIGNED_SHORT_BIT | |
| 519 | INT_BIT | UNSIGNED_INT_BIT | |
Dave Airlie | 6cd2d55 | 2011-08-13 15:30:38 +0100 | [diff] [blame] | 520 | HALF_BIT | FLOAT_BIT | DOUBLE_BIT | |
| 521 | UNSIGNED_INT_2_10_10_10_REV_BIT | |
| 522 | INT_2_10_10_10_REV_BIT); |
Keith Whitwell | fe5d67d | 2000-10-27 16:44:40 +0000 | [diff] [blame] | 523 | GET_CURRENT_CONTEXT(ctx); |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 524 | |
| 525 | FLUSH_VERTICES(ctx, 0); |
Keith Whitwell | fe5d67d | 2000-10-27 16:44:40 +0000 | [diff] [blame] | 526 | |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 527 | update_array(ctx, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1, |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 528 | legalTypes, 3, BGRA_OR_4, |
| 529 | size, type, stride, GL_TRUE, GL_FALSE, ptr); |
Keith Whitwell | fe5d67d | 2000-10-27 16:44:40 +0000 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 533 | void GLAPIENTRY |
Brian Paul | 2edd180 | 2002-01-11 17:25:35 +0000 | [diff] [blame] | 534 | _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride, |
| 535 | const GLvoid *ptr) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 536 | { |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 537 | GET_CURRENT_CONTEXT(ctx); |
Ian Romanick | c3e9a20 | 2012-07-25 15:13:00 -0700 | [diff] [blame] | 538 | GLbitfield legalTypes = (ctx->API == API_OPENGLES) |
| 539 | ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT) |
| 540 | : (SHORT_BIT | INT_BIT | |
| 541 | HALF_BIT | FLOAT_BIT | DOUBLE_BIT | |
| 542 | UNSIGNED_INT_2_10_10_10_REV_BIT | |
| 543 | INT_2_10_10_10_REV_BIT); |
Ian Romanick | a8f475d | 2012-07-25 15:13:51 -0700 | [diff] [blame] | 544 | const GLint sizeMin = (ctx->API == API_OPENGLES) ? 2 : 1; |
Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame] | 545 | const GLuint unit = ctx->Array.ActiveTexture; |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 546 | |
| 547 | FLUSH_VERTICES(ctx, 0); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 548 | |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 549 | update_array(ctx, "glTexCoordPointer", VERT_ATTRIB_TEX(unit), |
Ian Romanick | a8f475d | 2012-07-25 15:13:51 -0700 | [diff] [blame] | 550 | legalTypes, sizeMin, 4, |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 551 | size, type, stride, GL_FALSE, GL_FALSE, |
Brian Paul | d1184d2 | 2010-10-28 21:17:41 -0600 | [diff] [blame] | 552 | ptr); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 556 | void GLAPIENTRY |
Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame] | 557 | _mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 558 | { |
Brian Paul | ee1f047 | 2010-11-02 08:22:40 -0600 | [diff] [blame] | 559 | const GLbitfield legalTypes = UNSIGNED_BYTE_BIT; |
Brian Paul | d1184d2 | 2010-10-28 21:17:41 -0600 | [diff] [blame] | 560 | /* see table 2.4 edits in GL_EXT_gpu_shader4 spec: */ |
| 561 | const GLboolean integer = GL_TRUE; |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 562 | GET_CURRENT_CONTEXT(ctx); |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 563 | |
| 564 | FLUSH_VERTICES(ctx, 0); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 565 | |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 566 | update_array(ctx, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG, |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 567 | legalTypes, 1, 1, |
Brian Paul | ee1f047 | 2010-11-02 08:22:40 -0600 | [diff] [blame] | 568 | 1, GL_UNSIGNED_BYTE, stride, GL_FALSE, integer, ptr); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | |
Brian Paul | 1cf2c8a | 2008-06-25 08:45:14 -0600 | [diff] [blame] | 572 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 573 | _mesa_PointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *ptr) |
Brian Paul | 1cf2c8a | 2008-06-25 08:45:14 -0600 | [diff] [blame] | 574 | { |
Marek Olšák | 0f1e59d | 2011-04-29 14:23:15 +0200 | [diff] [blame] | 575 | const GLbitfield legalTypes = (FLOAT_BIT | FIXED_ES_BIT); |
Brian Paul | 1cf2c8a | 2008-06-25 08:45:14 -0600 | [diff] [blame] | 576 | GET_CURRENT_CONTEXT(ctx); |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 577 | |
| 578 | FLUSH_VERTICES(ctx, 0); |
Brian Paul | 1cf2c8a | 2008-06-25 08:45:14 -0600 | [diff] [blame] | 579 | |
Brian Paul | 11dd228 | 2010-11-07 18:35:35 -0700 | [diff] [blame] | 580 | if (ctx->API != API_OPENGLES) { |
| 581 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 582 | "glPointSizePointer(ES 1.x only)"); |
| 583 | return; |
| 584 | } |
| 585 | |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 586 | update_array(ctx, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE, |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 587 | legalTypes, 1, 1, |
| 588 | 1, type, stride, GL_FALSE, GL_FALSE, ptr); |
Brian Paul | 1cf2c8a | 2008-06-25 08:45:14 -0600 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | |
Brian Paul | a554d7c | 2009-05-21 15:55:33 -0600 | [diff] [blame] | 592 | /** |
Brian Paul | a554d7c | 2009-05-21 15:55:33 -0600 | [diff] [blame] | 593 | * Set a generic vertex attribute array. |
| 594 | * Note that these arrays DO NOT alias the conventional GL vertex arrays |
| 595 | * (position, normal, color, fog, texcoord, etc). |
| 596 | */ |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 597 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 598 | _mesa_VertexAttribPointer(GLuint index, GLint size, GLenum type, |
Brian Paul | 92f9785 | 2003-05-01 22:44:02 +0000 | [diff] [blame] | 599 | GLboolean normalized, |
| 600 | GLsizei stride, const GLvoid *ptr) |
| 601 | { |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 602 | const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT | |
| 603 | SHORT_BIT | UNSIGNED_SHORT_BIT | |
| 604 | INT_BIT | UNSIGNED_INT_BIT | |
| 605 | HALF_BIT | FLOAT_BIT | DOUBLE_BIT | |
Dave Airlie | 6cd2d55 | 2011-08-13 15:30:38 +0100 | [diff] [blame] | 606 | FIXED_ES_BIT | FIXED_GL_BIT | |
| 607 | UNSIGNED_INT_2_10_10_10_REV_BIT | |
| 608 | INT_2_10_10_10_REV_BIT); |
Brian Paul | 92f9785 | 2003-05-01 22:44:02 +0000 | [diff] [blame] | 609 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | 92f9785 | 2003-05-01 22:44:02 +0000 | [diff] [blame] | 610 | |
Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 611 | if (index >= ctx->Const.VertexProgram.MaxAttribs) { |
Brian Paul | 92f9785 | 2003-05-01 22:44:02 +0000 | [diff] [blame] | 612 | _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(index)"); |
| 613 | return; |
| 614 | } |
| 615 | |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 616 | update_array(ctx, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index), |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 617 | legalTypes, 1, BGRA_OR_4, |
| 618 | size, type, stride, normalized, GL_FALSE, ptr); |
Brian Paul | 92f9785 | 2003-05-01 22:44:02 +0000 | [diff] [blame] | 619 | } |
Brian Paul | 92f9785 | 2003-05-01 22:44:02 +0000 | [diff] [blame] | 620 | |
| 621 | |
Brian Paul | e00d07c | 2010-05-25 21:12:24 -0600 | [diff] [blame] | 622 | /** |
Brian Paul | d1184d2 | 2010-10-28 21:17:41 -0600 | [diff] [blame] | 623 | * GL_EXT_gpu_shader4 / GL 3.0. |
Brian Paul | e00d07c | 2010-05-25 21:12:24 -0600 | [diff] [blame] | 624 | * Set an integer-valued vertex attribute array. |
| 625 | * Note that these arrays DO NOT alias the conventional GL vertex arrays |
| 626 | * (position, normal, color, fog, texcoord, etc). |
| 627 | */ |
| 628 | void GLAPIENTRY |
| 629 | _mesa_VertexAttribIPointer(GLuint index, GLint size, GLenum type, |
Brian Paul | e00d07c | 2010-05-25 21:12:24 -0600 | [diff] [blame] | 630 | GLsizei stride, const GLvoid *ptr) |
| 631 | { |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 632 | const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT | |
| 633 | SHORT_BIT | UNSIGNED_SHORT_BIT | |
| 634 | INT_BIT | UNSIGNED_INT_BIT); |
Brian Paul | d1184d2 | 2010-10-28 21:17:41 -0600 | [diff] [blame] | 635 | const GLboolean normalized = GL_FALSE; |
| 636 | const GLboolean integer = GL_TRUE; |
Brian Paul | d1184d2 | 2010-10-28 21:17:41 -0600 | [diff] [blame] | 637 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | d1184d2 | 2010-10-28 21:17:41 -0600 | [diff] [blame] | 638 | |
| 639 | if (index >= ctx->Const.VertexProgram.MaxAttribs) { |
| 640 | _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribIPointer(index)"); |
| 641 | return; |
| 642 | } |
| 643 | |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 644 | update_array(ctx, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index), |
Brian Paul | 433e5e6 | 2010-10-28 21:17:42 -0600 | [diff] [blame] | 645 | legalTypes, 1, 4, |
| 646 | size, type, stride, normalized, integer, ptr); |
Brian Paul | e00d07c | 2010-05-25 21:12:24 -0600 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | |
| 650 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 651 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 652 | _mesa_EnableVertexAttribArray(GLuint index) |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 653 | { |
Brian Paul | 45453d8 | 2012-02-19 19:50:31 -0700 | [diff] [blame] | 654 | struct gl_array_object *arrayObj; |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 655 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 656 | |
| 657 | if (index >= ctx->Const.VertexProgram.MaxAttribs) { |
| 658 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 659 | "glEnableVertexAttribArrayARB(index)"); |
| 660 | return; |
| 661 | } |
| 662 | |
Brian Paul | 45453d8 | 2012-02-19 19:50:31 -0700 | [diff] [blame] | 663 | arrayObj = ctx->Array.ArrayObj; |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 664 | |
Fredrik Höglund | 12cbe99 | 2013-04-03 22:08:47 +0200 | [diff] [blame] | 665 | ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(arrayObj->_VertexAttrib)); |
Brian Paul | 45453d8 | 2012-02-19 19:50:31 -0700 | [diff] [blame] | 666 | |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 667 | if (!arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) { |
Brian Paul | 45453d8 | 2012-02-19 19:50:31 -0700 | [diff] [blame] | 668 | /* was disabled, now being enabled */ |
| 669 | FLUSH_VERTICES(ctx, _NEW_ARRAY); |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 670 | arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_TRUE; |
Brian Paul | 45453d8 | 2012-02-19 19:50:31 -0700 | [diff] [blame] | 671 | arrayObj->_Enabled |= VERT_BIT_GENERIC(index); |
Fredrik Höglund | 6a650fa | 2013-05-11 19:23:46 +0200 | [diff] [blame] | 672 | arrayObj->NewArrays |= VERT_BIT_GENERIC(index); |
Brian Paul | 45453d8 | 2012-02-19 19:50:31 -0700 | [diff] [blame] | 673 | } |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | |
| 677 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 678 | _mesa_DisableVertexAttribArray(GLuint index) |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 679 | { |
Brian Paul | 45453d8 | 2012-02-19 19:50:31 -0700 | [diff] [blame] | 680 | struct gl_array_object *arrayObj; |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 681 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 682 | |
| 683 | if (index >= ctx->Const.VertexProgram.MaxAttribs) { |
| 684 | _mesa_error(ctx, GL_INVALID_VALUE, |
Brian Paul | 95368f2 | 2011-04-06 14:22:39 -0600 | [diff] [blame] | 685 | "glDisableVertexAttribArrayARB(index)"); |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 686 | return; |
| 687 | } |
| 688 | |
Brian Paul | 45453d8 | 2012-02-19 19:50:31 -0700 | [diff] [blame] | 689 | arrayObj = ctx->Array.ArrayObj; |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 690 | |
Fredrik Höglund | 12cbe99 | 2013-04-03 22:08:47 +0200 | [diff] [blame] | 691 | ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(arrayObj->_VertexAttrib)); |
Brian Paul | 45453d8 | 2012-02-19 19:50:31 -0700 | [diff] [blame] | 692 | |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 693 | if (arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) { |
Brian Paul | 45453d8 | 2012-02-19 19:50:31 -0700 | [diff] [blame] | 694 | /* was enabled, now being disabled */ |
| 695 | FLUSH_VERTICES(ctx, _NEW_ARRAY); |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 696 | arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_FALSE; |
Brian Paul | 45453d8 | 2012-02-19 19:50:31 -0700 | [diff] [blame] | 697 | arrayObj->_Enabled &= ~VERT_BIT_GENERIC(index); |
Fredrik Höglund | 6a650fa | 2013-05-11 19:23:46 +0200 | [diff] [blame] | 698 | arrayObj->NewArrays |= VERT_BIT_GENERIC(index); |
Brian Paul | 45453d8 | 2012-02-19 19:50:31 -0700 | [diff] [blame] | 699 | } |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | |
| 703 | /** |
| 704 | * Return info for a vertex attribute array (no alias with legacy |
| 705 | * vertex attributes (pos, normal, color, etc)). This function does |
| 706 | * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query. |
| 707 | */ |
| 708 | static GLuint |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 709 | get_vertex_array_attrib(struct gl_context *ctx, GLuint index, GLenum pname, |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 710 | const char *caller) |
| 711 | { |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 712 | const struct gl_array_object *arrayObj = ctx->Array.ArrayObj; |
| 713 | const struct gl_vertex_attrib_array *array; |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 714 | |
Ian Romanick | 5c3f1cd | 2011-02-03 17:56:44 -0800 | [diff] [blame] | 715 | if (index >= ctx->Const.VertexProgram.MaxAttribs) { |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 716 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", caller, index); |
| 717 | return 0; |
| 718 | } |
| 719 | |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 720 | ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(arrayObj->VertexAttrib)); |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 721 | |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 722 | array = &arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)]; |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 723 | |
| 724 | switch (pname) { |
| 725 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB: |
| 726 | return array->Enabled; |
| 727 | case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB: |
| 728 | return array->Size; |
| 729 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB: |
| 730 | return array->Stride; |
| 731 | case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB: |
| 732 | return array->Type; |
| 733 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB: |
| 734 | return array->Normalized; |
| 735 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB: |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 736 | return arrayObj->VertexBinding[array->VertexBinding].BufferObj->Name; |
Brian Paul | d1184d2 | 2010-10-28 21:17:41 -0600 | [diff] [blame] | 737 | case GL_VERTEX_ATTRIB_ARRAY_INTEGER: |
Ian Romanick | 2c87030 | 2012-07-25 16:21:49 -0700 | [diff] [blame] | 738 | if ((_mesa_is_desktop_gl(ctx) |
| 739 | && (ctx->Version >= 30 || ctx->Extensions.EXT_gpu_shader4)) |
| 740 | || _mesa_is_gles3(ctx)) { |
Brian Paul | d1184d2 | 2010-10-28 21:17:41 -0600 | [diff] [blame] | 741 | return array->Integer; |
| 742 | } |
Brian Paul | 1d1eb95 | 2011-01-15 10:32:34 -0700 | [diff] [blame] | 743 | goto error; |
| 744 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB: |
Ian Romanick | 2c87030 | 2012-07-25 16:21:49 -0700 | [diff] [blame] | 745 | if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_instanced_arrays) |
| 746 | || _mesa_is_gles3(ctx)) { |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 747 | return arrayObj->VertexBinding[array->VertexBinding].InstanceDivisor; |
Brian Paul | 1d1eb95 | 2011-01-15 10:32:34 -0700 | [diff] [blame] | 748 | } |
| 749 | goto error; |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 750 | default: |
Brian Paul | 1d1eb95 | 2011-01-15 10:32:34 -0700 | [diff] [blame] | 751 | ; /* fall-through */ |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 752 | } |
Brian Paul | 1d1eb95 | 2011-01-15 10:32:34 -0700 | [diff] [blame] | 753 | |
| 754 | error: |
| 755 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", caller, pname); |
| 756 | return 0; |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | |
Ian Romanick | 5c3f1cd | 2011-02-03 17:56:44 -0800 | [diff] [blame] | 760 | static const GLfloat * |
| 761 | get_current_attrib(struct gl_context *ctx, GLuint index, const char *function) |
| 762 | { |
| 763 | if (index == 0) { |
Ian Romanick | 2c87030 | 2012-07-25 16:21:49 -0700 | [diff] [blame] | 764 | /* In OpenGL 3.1 attribute 0 becomes non-magic, just like in OpenGL ES |
| 765 | * 2.0. Note that we cannot just check for API_OPENGL_CORE here because |
| 766 | * that will erroneously allow this usage in a 3.0 forward-compatible |
| 767 | * context too. |
| 768 | */ |
| 769 | if ((ctx->API != API_OPENGL_CORE || ctx->Version < 31) |
| 770 | && ctx->API != API_OPENGLES2) { |
Ian Romanick | 5c3f1cd | 2011-02-03 17:56:44 -0800 | [diff] [blame] | 771 | _mesa_error(ctx, GL_INVALID_OPERATION, "%s(index==0)", function); |
| 772 | return NULL; |
| 773 | } |
| 774 | } |
| 775 | else if (index >= ctx->Const.VertexProgram.MaxAttribs) { |
| 776 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 777 | "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function); |
| 778 | return NULL; |
| 779 | } |
| 780 | |
Fredrik Höglund | 12cbe99 | 2013-04-03 22:08:47 +0200 | [diff] [blame] | 781 | ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.ArrayObj->_VertexAttrib)); |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 782 | |
Ian Romanick | 5c3f1cd | 2011-02-03 17:56:44 -0800 | [diff] [blame] | 783 | FLUSH_CURRENT(ctx, 0); |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 784 | return ctx->Current.Attrib[VERT_ATTRIB_GENERIC(index)]; |
Ian Romanick | 5c3f1cd | 2011-02-03 17:56:44 -0800 | [diff] [blame] | 785 | } |
| 786 | |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 787 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 788 | _mesa_GetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params) |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 789 | { |
| 790 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 791 | |
| 792 | if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) { |
Ian Romanick | 5c3f1cd | 2011-02-03 17:56:44 -0800 | [diff] [blame] | 793 | const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribfv"); |
| 794 | if (v != NULL) { |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 795 | COPY_4V(params, v); |
| 796 | } |
| 797 | } |
| 798 | else { |
| 799 | params[0] = (GLfloat) get_vertex_array_attrib(ctx, index, pname, |
| 800 | "glGetVertexAttribfv"); |
| 801 | } |
| 802 | } |
| 803 | |
| 804 | |
| 805 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 806 | _mesa_GetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params) |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 807 | { |
| 808 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 809 | |
| 810 | if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) { |
Ian Romanick | 5c3f1cd | 2011-02-03 17:56:44 -0800 | [diff] [blame] | 811 | const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribdv"); |
| 812 | if (v != NULL) { |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 813 | params[0] = (GLdouble) v[0]; |
| 814 | params[1] = (GLdouble) v[1]; |
| 815 | params[2] = (GLdouble) v[2]; |
| 816 | params[3] = (GLdouble) v[3]; |
| 817 | } |
| 818 | } |
| 819 | else { |
| 820 | params[0] = (GLdouble) get_vertex_array_attrib(ctx, index, pname, |
| 821 | "glGetVertexAttribdv"); |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | |
| 826 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 827 | _mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params) |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 828 | { |
| 829 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 830 | |
| 831 | if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) { |
Ian Romanick | 5c3f1cd | 2011-02-03 17:56:44 -0800 | [diff] [blame] | 832 | const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribiv"); |
| 833 | if (v != NULL) { |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 834 | /* XXX should floats in[0,1] be scaled to full int range? */ |
| 835 | params[0] = (GLint) v[0]; |
| 836 | params[1] = (GLint) v[1]; |
| 837 | params[2] = (GLint) v[2]; |
| 838 | params[3] = (GLint) v[3]; |
| 839 | } |
| 840 | } |
| 841 | else { |
| 842 | params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname, |
| 843 | "glGetVertexAttribiv"); |
| 844 | } |
| 845 | } |
| 846 | |
| 847 | |
| 848 | /** GL 3.0 */ |
| 849 | void GLAPIENTRY |
| 850 | _mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params) |
| 851 | { |
| 852 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 853 | |
| 854 | if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) { |
Kenneth Graunke | c299f44 | 2012-11-07 20:29:40 -0800 | [diff] [blame] | 855 | const GLint *v = (const GLint *) |
Ian Romanick | 5c3f1cd | 2011-02-03 17:56:44 -0800 | [diff] [blame] | 856 | get_current_attrib(ctx, index, "glGetVertexAttribIiv"); |
| 857 | if (v != NULL) { |
Kenneth Graunke | c299f44 | 2012-11-07 20:29:40 -0800 | [diff] [blame] | 858 | COPY_4V(params, v); |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 859 | } |
| 860 | } |
| 861 | else { |
| 862 | params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname, |
| 863 | "glGetVertexAttribIiv"); |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | |
| 868 | /** GL 3.0 */ |
| 869 | void GLAPIENTRY |
| 870 | _mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params) |
| 871 | { |
| 872 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 873 | |
| 874 | if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) { |
Kenneth Graunke | c299f44 | 2012-11-07 20:29:40 -0800 | [diff] [blame] | 875 | const GLuint *v = (const GLuint *) |
Ian Romanick | 5c3f1cd | 2011-02-03 17:56:44 -0800 | [diff] [blame] | 876 | get_current_attrib(ctx, index, "glGetVertexAttribIuiv"); |
| 877 | if (v != NULL) { |
Kenneth Graunke | c299f44 | 2012-11-07 20:29:40 -0800 | [diff] [blame] | 878 | COPY_4V(params, v); |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 879 | } |
| 880 | } |
| 881 | else { |
| 882 | params[0] = get_vertex_array_attrib(ctx, index, pname, |
| 883 | "glGetVertexAttribIuiv"); |
| 884 | } |
| 885 | } |
| 886 | |
| 887 | |
| 888 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 889 | _mesa_GetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer) |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 890 | { |
| 891 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 892 | |
| 893 | if (index >= ctx->Const.VertexProgram.MaxAttribs) { |
| 894 | _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)"); |
| 895 | return; |
| 896 | } |
| 897 | |
| 898 | if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) { |
| 899 | _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)"); |
| 900 | return; |
| 901 | } |
| 902 | |
Fredrik Höglund | 12cbe99 | 2013-04-03 22:08:47 +0200 | [diff] [blame] | 903 | ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.ArrayObj->_VertexAttrib)); |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 904 | |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 905 | *pointer = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr; |
Brian Paul | d3f598a | 2010-05-25 21:42:13 -0600 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | |
| 909 | void GLAPIENTRY |
Brian Paul | 1f0e213 | 2000-06-12 15:30:51 +0000 | [diff] [blame] | 910 | _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride, |
| 911 | GLsizei count, const GLvoid *ptr) |
| 912 | { |
| 913 | (void) count; |
| 914 | _mesa_VertexPointer(size, type, stride, ptr); |
| 915 | } |
| 916 | |
| 917 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 918 | void GLAPIENTRY |
Brian Paul | 1f0e213 | 2000-06-12 15:30:51 +0000 | [diff] [blame] | 919 | _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count, |
| 920 | const GLvoid *ptr) |
| 921 | { |
| 922 | (void) count; |
| 923 | _mesa_NormalPointer(type, stride, ptr); |
| 924 | } |
| 925 | |
| 926 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 927 | void GLAPIENTRY |
Brian Paul | 1f0e213 | 2000-06-12 15:30:51 +0000 | [diff] [blame] | 928 | _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count, |
| 929 | const GLvoid *ptr) |
| 930 | { |
| 931 | (void) count; |
| 932 | _mesa_ColorPointer(size, type, stride, ptr); |
| 933 | } |
| 934 | |
| 935 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 936 | void GLAPIENTRY |
Brian Paul | 1f0e213 | 2000-06-12 15:30:51 +0000 | [diff] [blame] | 937 | _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count, |
| 938 | const GLvoid *ptr) |
| 939 | { |
| 940 | (void) count; |
| 941 | _mesa_IndexPointer(type, stride, ptr); |
| 942 | } |
| 943 | |
| 944 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 945 | void GLAPIENTRY |
Brian Paul | 1f0e213 | 2000-06-12 15:30:51 +0000 | [diff] [blame] | 946 | _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride, |
| 947 | GLsizei count, const GLvoid *ptr) |
| 948 | { |
| 949 | (void) count; |
| 950 | _mesa_TexCoordPointer(size, type, stride, ptr); |
| 951 | } |
| 952 | |
| 953 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 954 | void GLAPIENTRY |
Brian Paul | 1f0e213 | 2000-06-12 15:30:51 +0000 | [diff] [blame] | 955 | _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr) |
| 956 | { |
| 957 | (void) count; |
| 958 | _mesa_EdgeFlagPointer(stride, ptr); |
| 959 | } |
| 960 | |
| 961 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 962 | void GLAPIENTRY |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 963 | _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 964 | { |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 965 | GET_CURRENT_CONTEXT(ctx); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 966 | GLboolean tflag, cflag, nflag; /* enable/disable flags */ |
| 967 | GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */ |
Keith Whitwell | f4b02d1 | 2001-01-05 05:31:42 +0000 | [diff] [blame] | 968 | GLenum ctype = 0; /* color type */ |
| 969 | GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */ |
Brian Paul | 4a3110f | 2003-12-12 18:40:02 +0000 | [diff] [blame] | 970 | const GLint toffset = 0; /* always zero */ |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 971 | GLint defstride; /* default stride */ |
| 972 | GLint c, f; |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 973 | |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 974 | FLUSH_VERTICES(ctx, 0); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 975 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 976 | f = sizeof(GLfloat); |
Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame] | 977 | c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 978 | |
Brian Paul | c5b1e81 | 2003-10-22 22:59:07 +0000 | [diff] [blame] | 979 | if (stride < 0) { |
Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 980 | _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 981 | return; |
| 982 | } |
| 983 | |
| 984 | switch (format) { |
| 985 | case GL_V2F: |
| 986 | tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE; |
| 987 | tcomps = 0; ccomps = 0; vcomps = 2; |
| 988 | voffset = 0; |
| 989 | defstride = 2*f; |
| 990 | break; |
| 991 | case GL_V3F: |
| 992 | tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE; |
| 993 | tcomps = 0; ccomps = 0; vcomps = 3; |
| 994 | voffset = 0; |
| 995 | defstride = 3*f; |
| 996 | break; |
| 997 | case GL_C4UB_V2F: |
| 998 | tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE; |
| 999 | tcomps = 0; ccomps = 4; vcomps = 2; |
| 1000 | ctype = GL_UNSIGNED_BYTE; |
| 1001 | coffset = 0; |
| 1002 | voffset = c; |
| 1003 | defstride = c + 2*f; |
| 1004 | break; |
| 1005 | case GL_C4UB_V3F: |
| 1006 | tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE; |
| 1007 | tcomps = 0; ccomps = 4; vcomps = 3; |
| 1008 | ctype = GL_UNSIGNED_BYTE; |
| 1009 | coffset = 0; |
| 1010 | voffset = c; |
| 1011 | defstride = c + 3*f; |
| 1012 | break; |
| 1013 | case GL_C3F_V3F: |
| 1014 | tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE; |
| 1015 | tcomps = 0; ccomps = 3; vcomps = 3; |
| 1016 | ctype = GL_FLOAT; |
| 1017 | coffset = 0; |
| 1018 | voffset = 3*f; |
| 1019 | defstride = 6*f; |
| 1020 | break; |
| 1021 | case GL_N3F_V3F: |
| 1022 | tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE; |
| 1023 | tcomps = 0; ccomps = 0; vcomps = 3; |
| 1024 | noffset = 0; |
| 1025 | voffset = 3*f; |
| 1026 | defstride = 6*f; |
| 1027 | break; |
| 1028 | case GL_C4F_N3F_V3F: |
| 1029 | tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE; |
| 1030 | tcomps = 0; ccomps = 4; vcomps = 3; |
| 1031 | ctype = GL_FLOAT; |
| 1032 | coffset = 0; |
| 1033 | noffset = 4*f; |
| 1034 | voffset = 7*f; |
| 1035 | defstride = 10*f; |
| 1036 | break; |
| 1037 | case GL_T2F_V3F: |
| 1038 | tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE; |
| 1039 | tcomps = 2; ccomps = 0; vcomps = 3; |
| 1040 | voffset = 2*f; |
| 1041 | defstride = 5*f; |
| 1042 | break; |
| 1043 | case GL_T4F_V4F: |
| 1044 | tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE; |
| 1045 | tcomps = 4; ccomps = 0; vcomps = 4; |
| 1046 | voffset = 4*f; |
| 1047 | defstride = 8*f; |
| 1048 | break; |
| 1049 | case GL_T2F_C4UB_V3F: |
| 1050 | tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE; |
| 1051 | tcomps = 2; ccomps = 4; vcomps = 3; |
| 1052 | ctype = GL_UNSIGNED_BYTE; |
| 1053 | coffset = 2*f; |
| 1054 | voffset = c+2*f; |
| 1055 | defstride = c+5*f; |
| 1056 | break; |
| 1057 | case GL_T2F_C3F_V3F: |
| 1058 | tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE; |
| 1059 | tcomps = 2; ccomps = 3; vcomps = 3; |
| 1060 | ctype = GL_FLOAT; |
| 1061 | coffset = 2*f; |
| 1062 | voffset = 5*f; |
| 1063 | defstride = 8*f; |
| 1064 | break; |
| 1065 | case GL_T2F_N3F_V3F: |
| 1066 | tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE; |
| 1067 | tcomps = 2; ccomps = 0; vcomps = 3; |
| 1068 | noffset = 2*f; |
| 1069 | voffset = 5*f; |
| 1070 | defstride = 8*f; |
| 1071 | break; |
| 1072 | case GL_T2F_C4F_N3F_V3F: |
| 1073 | tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE; |
| 1074 | tcomps = 2; ccomps = 4; vcomps = 3; |
| 1075 | ctype = GL_FLOAT; |
| 1076 | coffset = 2*f; |
| 1077 | noffset = 6*f; |
| 1078 | voffset = 9*f; |
| 1079 | defstride = 12*f; |
| 1080 | break; |
| 1081 | case GL_T4F_C4F_N3F_V4F: |
| 1082 | tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE; |
| 1083 | tcomps = 4; ccomps = 4; vcomps = 4; |
| 1084 | ctype = GL_FLOAT; |
| 1085 | coffset = 4*f; |
| 1086 | noffset = 8*f; |
| 1087 | voffset = 11*f; |
| 1088 | defstride = 15*f; |
| 1089 | break; |
| 1090 | default: |
Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 1091 | _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1092 | return; |
| 1093 | } |
| 1094 | |
| 1095 | if (stride==0) { |
| 1096 | stride = defstride; |
| 1097 | } |
| 1098 | |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1099 | _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY ); |
| 1100 | _mesa_DisableClientState( GL_INDEX_ARRAY ); |
Brian Paul | 095c669 | 2006-04-25 00:21:32 +0000 | [diff] [blame] | 1101 | /* XXX also disable secondary color and generic arrays? */ |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1102 | |
| 1103 | /* Texcoords */ |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1104 | if (tflag) { |
Brian Paul | 4a3110f | 2003-12-12 18:40:02 +0000 | [diff] [blame] | 1105 | _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY ); |
| 1106 | _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride, |
Brian Paul | ab928e5 | 2004-03-10 16:17:35 +0000 | [diff] [blame] | 1107 | (GLubyte *) pointer + toffset ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1108 | } |
| 1109 | else { |
Brian Paul | ab928e5 | 2004-03-10 16:17:35 +0000 | [diff] [blame] | 1110 | _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1111 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1112 | |
| 1113 | /* Color */ |
| 1114 | if (cflag) { |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1115 | _mesa_EnableClientState( GL_COLOR_ARRAY ); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1116 | _mesa_ColorPointer( ccomps, ctype, stride, |
Brian Paul | 4a3110f | 2003-12-12 18:40:02 +0000 | [diff] [blame] | 1117 | (GLubyte *) pointer + coffset ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1118 | } |
| 1119 | else { |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1120 | _mesa_DisableClientState( GL_COLOR_ARRAY ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | |
| 1124 | /* Normals */ |
| 1125 | if (nflag) { |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1126 | _mesa_EnableClientState( GL_NORMAL_ARRAY ); |
Brian Paul | 4a3110f | 2003-12-12 18:40:02 +0000 | [diff] [blame] | 1127 | _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1128 | } |
| 1129 | else { |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1130 | _mesa_DisableClientState( GL_NORMAL_ARRAY ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1131 | } |
| 1132 | |
Brian Paul | 4a3110f | 2003-12-12 18:40:02 +0000 | [diff] [blame] | 1133 | /* Vertices */ |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1134 | _mesa_EnableClientState( GL_VERTEX_ARRAY ); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1135 | _mesa_VertexPointer( vcomps, GL_FLOAT, stride, |
| 1136 | (GLubyte *) pointer + voffset ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 1140 | void GLAPIENTRY |
Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 1141 | _mesa_LockArraysEXT(GLint first, GLsizei count) |
| 1142 | { |
| 1143 | GET_CURRENT_CONTEXT(ctx); |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 1144 | |
| 1145 | FLUSH_VERTICES(ctx, 0); |
Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 1146 | |
| 1147 | if (MESA_VERBOSE & VERBOSE_API) |
Brian Paul | 4753d60 | 2002-06-15 02:38:15 +0000 | [diff] [blame] | 1148 | _mesa_debug(ctx, "glLockArrays %d %d\n", first, count); |
Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 1149 | |
Eric Anholt | 5857e98 | 2008-02-02 02:54:13 -0800 | [diff] [blame] | 1150 | if (first < 0) { |
| 1151 | _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" ); |
| 1152 | return; |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 1153 | } |
Eric Anholt | 5857e98 | 2008-02-02 02:54:13 -0800 | [diff] [blame] | 1154 | if (count <= 0) { |
| 1155 | _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" ); |
| 1156 | return; |
Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 1157 | } |
Eric Anholt | 5857e98 | 2008-02-02 02:54:13 -0800 | [diff] [blame] | 1158 | if (ctx->Array.LockCount != 0) { |
| 1159 | _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" ); |
| 1160 | return; |
| 1161 | } |
| 1162 | |
| 1163 | ctx->Array.LockFirst = first; |
| 1164 | ctx->Array.LockCount = count; |
Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 1165 | |
| 1166 | ctx->NewState |= _NEW_ARRAY; |
Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 1170 | void GLAPIENTRY |
Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 1171 | _mesa_UnlockArraysEXT( void ) |
| 1172 | { |
| 1173 | GET_CURRENT_CONTEXT(ctx); |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 1174 | |
| 1175 | FLUSH_VERTICES(ctx, 0); |
Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 1176 | |
| 1177 | if (MESA_VERBOSE & VERBOSE_API) |
Brian Paul | 4753d60 | 2002-06-15 02:38:15 +0000 | [diff] [blame] | 1178 | _mesa_debug(ctx, "glUnlockArrays\n"); |
Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 1179 | |
Eric Anholt | 5857e98 | 2008-02-02 02:54:13 -0800 | [diff] [blame] | 1180 | if (ctx->Array.LockCount == 0) { |
| 1181 | _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" ); |
| 1182 | return; |
| 1183 | } |
| 1184 | |
Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 1185 | ctx->Array.LockFirst = 0; |
| 1186 | ctx->Array.LockCount = 0; |
| 1187 | ctx->NewState |= _NEW_ARRAY; |
Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 1188 | } |
Brian Paul | 2525bc7 | 2002-06-30 15:47:00 +0000 | [diff] [blame] | 1189 | |
| 1190 | |
Brian Paul | 2525bc7 | 2002-06-30 15:47:00 +0000 | [diff] [blame] | 1191 | /* GL_EXT_multi_draw_arrays */ |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 1192 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 1193 | _mesa_MultiDrawArrays( GLenum mode, const GLint *first, |
Brian Paul | 7993832 | 2010-09-14 09:37:35 -0600 | [diff] [blame] | 1194 | const GLsizei *count, GLsizei primcount ) |
Brian Paul | 2525bc7 | 2002-06-30 15:47:00 +0000 | [diff] [blame] | 1195 | { |
| 1196 | GET_CURRENT_CONTEXT(ctx); |
| 1197 | GLint i; |
| 1198 | |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 1199 | FLUSH_VERTICES(ctx, 0); |
Brian Paul | 2525bc7 | 2002-06-30 15:47:00 +0000 | [diff] [blame] | 1200 | |
| 1201 | for (i = 0; i < primcount; i++) { |
| 1202 | if (count[i] > 0) { |
Ian Romanick | 9bdfee3 | 2005-07-18 12:31:24 +0000 | [diff] [blame] | 1203 | CALL_DrawArrays(ctx->Exec, (mode, first[i], count[i])); |
Brian Paul | 2525bc7 | 2002-06-30 15:47:00 +0000 | [diff] [blame] | 1204 | } |
| 1205 | } |
| 1206 | } |
| 1207 | |
| 1208 | |
Ian Romanick | 3baefe6 | 2003-08-22 23:28:03 +0000 | [diff] [blame] | 1209 | /* GL_IBM_multimode_draw_arrays */ |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 1210 | void GLAPIENTRY |
Ian Romanick | 3baefe6 | 2003-08-22 23:28:03 +0000 | [diff] [blame] | 1211 | _mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first, |
| 1212 | const GLsizei * count, |
| 1213 | GLsizei primcount, GLint modestride ) |
| 1214 | { |
| 1215 | GET_CURRENT_CONTEXT(ctx); |
| 1216 | GLint i; |
| 1217 | |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 1218 | FLUSH_VERTICES(ctx, 0); |
Ian Romanick | 3baefe6 | 2003-08-22 23:28:03 +0000 | [diff] [blame] | 1219 | |
| 1220 | for ( i = 0 ; i < primcount ; i++ ) { |
| 1221 | if ( count[i] > 0 ) { |
Brian Paul | 03e29a5 | 2003-12-04 03:16:27 +0000 | [diff] [blame] | 1222 | GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride)); |
Ian Romanick | 9bdfee3 | 2005-07-18 12:31:24 +0000 | [diff] [blame] | 1223 | CALL_DrawArrays(ctx->Exec, ( m, first[i], count[i] )); |
Ian Romanick | 3baefe6 | 2003-08-22 23:28:03 +0000 | [diff] [blame] | 1224 | } |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | |
| 1229 | /* GL_IBM_multimode_draw_arrays */ |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 1230 | void GLAPIENTRY |
Ian Romanick | 3baefe6 | 2003-08-22 23:28:03 +0000 | [diff] [blame] | 1231 | _mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count, |
| 1232 | GLenum type, const GLvoid * const * indices, |
| 1233 | GLsizei primcount, GLint modestride ) |
| 1234 | { |
| 1235 | GET_CURRENT_CONTEXT(ctx); |
| 1236 | GLint i; |
| 1237 | |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 1238 | FLUSH_VERTICES(ctx, 0); |
Ian Romanick | 3baefe6 | 2003-08-22 23:28:03 +0000 | [diff] [blame] | 1239 | |
Brian Paul | d2afb39 | 2003-09-17 18:15:13 +0000 | [diff] [blame] | 1240 | /* XXX not sure about ARB_vertex_buffer_object handling here */ |
| 1241 | |
Ian Romanick | 3baefe6 | 2003-08-22 23:28:03 +0000 | [diff] [blame] | 1242 | for ( i = 0 ; i < primcount ; i++ ) { |
| 1243 | if ( count[i] > 0 ) { |
Brian Paul | 03e29a5 | 2003-12-04 03:16:27 +0000 | [diff] [blame] | 1244 | GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride)); |
Ian Romanick | 9bdfee3 | 2005-07-18 12:31:24 +0000 | [diff] [blame] | 1245 | CALL_DrawElements(ctx->Exec, ( m, count[i], type, indices[i] )); |
Ian Romanick | 3baefe6 | 2003-08-22 23:28:03 +0000 | [diff] [blame] | 1246 | } |
| 1247 | } |
| 1248 | } |
| 1249 | |
| 1250 | |
Brian Paul | 095c669 | 2006-04-25 00:21:32 +0000 | [diff] [blame] | 1251 | /** |
Brian Paul | 7f26ad8 | 2010-10-21 19:03:38 -0600 | [diff] [blame] | 1252 | * GL_NV_primitive_restart and GL 3.1 |
Brian Paul | a40e6f2 | 2010-04-20 21:02:09 -0600 | [diff] [blame] | 1253 | */ |
| 1254 | void GLAPIENTRY |
| 1255 | _mesa_PrimitiveRestartIndex(GLuint index) |
| 1256 | { |
| 1257 | GET_CURRENT_CONTEXT(ctx); |
| 1258 | |
Eric Anholt | 9c1b418 | 2012-07-26 14:43:56 -0700 | [diff] [blame] | 1259 | if (!ctx->Extensions.NV_primitive_restart && ctx->Version < 31) { |
Brian Paul | 7f26ad8 | 2010-10-21 19:03:38 -0600 | [diff] [blame] | 1260 | _mesa_error(ctx, GL_INVALID_OPERATION, "glPrimitiveRestartIndexNV()"); |
Brian Paul | a40e6f2 | 2010-04-20 21:02:09 -0600 | [diff] [blame] | 1261 | return; |
| 1262 | } |
| 1263 | |
Kenneth Graunke | e6efb90 | 2013-05-29 08:31:54 -0700 | [diff] [blame] | 1264 | if (ctx->Array.RestartIndex != index) { |
Brian Paul | d2003ee | 2012-02-19 19:50:32 -0700 | [diff] [blame] | 1265 | FLUSH_VERTICES(ctx, _NEW_TRANSFORM); |
Kenneth Graunke | e6efb90 | 2013-05-29 08:31:54 -0700 | [diff] [blame] | 1266 | ctx->Array.RestartIndex = index; |
Brian Paul | d2003ee | 2012-02-19 19:50:32 -0700 | [diff] [blame] | 1267 | } |
Brian Paul | a40e6f2 | 2010-04-20 21:02:09 -0600 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | |
| 1271 | /** |
Brian Paul | 1d1eb95 | 2011-01-15 10:32:34 -0700 | [diff] [blame] | 1272 | * See GL_ARB_instanced_arrays. |
| 1273 | * Note that the instance divisor only applies to generic arrays, not |
| 1274 | * the legacy vertex arrays. |
| 1275 | */ |
| 1276 | void GLAPIENTRY |
| 1277 | _mesa_VertexAttribDivisor(GLuint index, GLuint divisor) |
| 1278 | { |
| 1279 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | 1d1eb95 | 2011-01-15 10:32:34 -0700 | [diff] [blame] | 1280 | |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 1281 | const GLuint genericIndex = VERT_ATTRIB_GENERIC(index); |
| 1282 | |
Brian Paul | 1d1eb95 | 2011-01-15 10:32:34 -0700 | [diff] [blame] | 1283 | if (!ctx->Extensions.ARB_instanced_arrays) { |
| 1284 | _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()"); |
| 1285 | return; |
| 1286 | } |
| 1287 | |
| 1288 | if (index >= ctx->Const.VertexProgram.MaxAttribs) { |
Matt Turner | ae1f09b | 2012-11-13 13:05:03 -0800 | [diff] [blame] | 1289 | _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribDivisor(index = %u)", |
Brian Paul | 1d1eb95 | 2011-01-15 10:32:34 -0700 | [diff] [blame] | 1290 | index); |
| 1291 | return; |
| 1292 | } |
| 1293 | |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 1294 | ASSERT(genericIndex < Elements(ctx->Array.ArrayObj->VertexAttrib)); |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 1295 | |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 1296 | /* The ARB_vertex_attrib_binding spec says: |
| 1297 | * |
| 1298 | * "The command |
| 1299 | * |
| 1300 | * void VertexAttribDivisor(uint index, uint divisor); |
| 1301 | * |
| 1302 | * is equivalent to (assuming no errors are generated): |
| 1303 | * |
| 1304 | * VertexAttribBinding(index, index); |
| 1305 | * VertexBindingDivisor(index, divisor);" |
| 1306 | */ |
| 1307 | vertex_attrib_binding(ctx, genericIndex, genericIndex); |
| 1308 | vertex_binding_divisor(ctx, genericIndex, divisor); |
Brian Paul | 1d1eb95 | 2011-01-15 10:32:34 -0700 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | |
Kenneth Graunke | 959d076 | 2013-05-29 08:07:01 -0700 | [diff] [blame] | 1312 | unsigned |
| 1313 | _mesa_primitive_restart_index(const struct gl_context *ctx, GLenum ib_type) |
| 1314 | { |
| 1315 | /* From the OpenGL 4.3 core specification, page 302: |
| 1316 | * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are |
| 1317 | * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX |
| 1318 | * is used." |
| 1319 | */ |
| 1320 | if (ctx->Array.PrimitiveRestartFixedIndex) { |
| 1321 | switch (ib_type) { |
| 1322 | case GL_UNSIGNED_BYTE: |
| 1323 | return 0xff; |
| 1324 | case GL_UNSIGNED_SHORT: |
| 1325 | return 0xffff; |
| 1326 | case GL_UNSIGNED_INT: |
| 1327 | return 0xffffffff; |
| 1328 | default: |
| 1329 | assert(!"_mesa_primitive_restart_index: Invalid index buffer type."); |
| 1330 | } |
| 1331 | } |
| 1332 | |
| 1333 | return ctx->Array.RestartIndex; |
| 1334 | } |
| 1335 | |
Brian Paul | 1d1eb95 | 2011-01-15 10:32:34 -0700 | [diff] [blame] | 1336 | |
| 1337 | /** |
Fredrik Höglund | bb2d02c | 2013-04-09 20:44:58 +0200 | [diff] [blame] | 1338 | * GL_ARB_vertex_attrib_binding |
| 1339 | */ |
| 1340 | void GLAPIENTRY |
| 1341 | _mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset, |
| 1342 | GLsizei stride) |
| 1343 | { |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 1344 | struct gl_buffer_object *vbo; |
| 1345 | |
| 1346 | GET_CURRENT_CONTEXT(ctx); |
| 1347 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 1348 | |
| 1349 | /* The ARB_vertex_attrib_binding spec says: |
| 1350 | * |
| 1351 | * "An INVALID_OPERATION error is generated if no vertex array object |
| 1352 | * is bound." |
| 1353 | */ |
| 1354 | if (ctx->API == API_OPENGL_CORE && |
| 1355 | ctx->Array.ArrayObj == ctx->Array.DefaultArrayObj) { |
| 1356 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1357 | "glBindVertexBuffer(No array object bound)"); |
| 1358 | return; |
| 1359 | } |
| 1360 | |
| 1361 | /* The ARB_vertex_attrib_binding spec says: |
| 1362 | * |
| 1363 | * "An INVALID_VALUE error is generated if <bindingindex> is greater than |
| 1364 | * the value of MAX_VERTEX_ATTRIB_BINDINGS." |
| 1365 | */ |
| 1366 | if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) { |
| 1367 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 1368 | "glBindVertexBuffer(bindingindex=%u > " |
| 1369 | "GL_MAX_VERTEX_ATTRIB_BINDINGS)", |
| 1370 | bindingIndex); |
| 1371 | return; |
| 1372 | } |
| 1373 | |
| 1374 | /* The ARB_vertex_attrib_binding spec says: |
| 1375 | * |
| 1376 | * "The error INVALID_VALUE is generated if <stride> or <offset> |
| 1377 | * are negative." |
| 1378 | */ |
| 1379 | if (offset < 0) { |
| 1380 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 1381 | "glBindVertexBuffer(offset=%lld < 0)", (long long)offset); |
| 1382 | return; |
| 1383 | } |
| 1384 | |
| 1385 | if (stride < 0) { |
| 1386 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 1387 | "glBindVertexBuffer(stride=%d < 0)", stride); |
| 1388 | return; |
| 1389 | } |
| 1390 | |
| 1391 | if (buffer != 0) { |
| 1392 | vbo = _mesa_lookup_bufferobj(ctx, buffer); |
| 1393 | |
| 1394 | /* From the GL_ARB_vertex_attrib_array spec: |
| 1395 | * |
| 1396 | * "[Core profile only:] |
| 1397 | * An INVALID_OPERATION error is generated if buffer is not zero or a |
| 1398 | * name returned from a previous call to GenBuffers, or if such a name |
| 1399 | * has since been deleted with DeleteBuffers. |
| 1400 | * |
| 1401 | * Otherwise, we fall back to the same compat profile behavior as other |
| 1402 | * object references (automatically gen it). |
| 1403 | */ |
| 1404 | if (!_mesa_handle_bind_buffer_gen(ctx, GL_ARRAY_BUFFER, buffer, |
| 1405 | &vbo, "glBindVertexBuffer")) |
| 1406 | return; |
| 1407 | } else { |
| 1408 | /* The ARB_vertex_attrib_binding spec says: |
| 1409 | * |
| 1410 | * "If <buffer> is zero, any buffer object attached to this |
| 1411 | * bindpoint is detached." |
| 1412 | */ |
| 1413 | vbo = ctx->Shared->NullBufferObj; |
| 1414 | } |
| 1415 | |
| 1416 | bind_vertex_buffer(ctx, VERT_ATTRIB_GENERIC(bindingIndex), |
| 1417 | vbo, offset, stride); |
Fredrik Höglund | bb2d02c | 2013-04-09 20:44:58 +0200 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | |
| 1421 | void GLAPIENTRY |
| 1422 | _mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type, |
| 1423 | GLboolean normalized, GLuint relativeOffset) |
| 1424 | { |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 1425 | const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT | |
| 1426 | SHORT_BIT | UNSIGNED_SHORT_BIT | |
| 1427 | INT_BIT | UNSIGNED_INT_BIT | |
| 1428 | HALF_BIT | FLOAT_BIT | DOUBLE_BIT | |
| 1429 | FIXED_GL_BIT | |
| 1430 | UNSIGNED_INT_2_10_10_10_REV_BIT | |
| 1431 | INT_2_10_10_10_REV_BIT); |
| 1432 | |
| 1433 | GET_CURRENT_CONTEXT(ctx); |
| 1434 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 1435 | |
| 1436 | /* The ARB_vertex_attrib_binding spec says: |
| 1437 | * |
| 1438 | * "An INVALID_OPERATION error is generated under any of the following |
| 1439 | * conditions: |
| 1440 | * - if no vertex array object is currently bound (see section 2.10); |
| 1441 | * - ..." |
| 1442 | */ |
| 1443 | if (ctx->API == API_OPENGL_CORE && |
| 1444 | ctx->Array.ArrayObj == ctx->Array.DefaultArrayObj) { |
| 1445 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1446 | "glVertexAttribFormat(No array object bound)"); |
| 1447 | return; |
| 1448 | } |
| 1449 | |
| 1450 | /* The ARB_vertex_attrib_binding spec says: |
| 1451 | * |
| 1452 | * "The error INVALID_VALUE is generated if index is greater than or equal |
| 1453 | * to the value of MAX_VERTEX_ATTRIBS." |
| 1454 | */ |
| 1455 | if (attribIndex >= ctx->Const.VertexProgram.MaxAttribs) { |
| 1456 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 1457 | "glVertexAttribFormat(attribindex=%u > " |
| 1458 | "GL_MAX_VERTEX_ATTRIBS)", |
| 1459 | attribIndex); |
| 1460 | return; |
| 1461 | } |
| 1462 | |
| 1463 | FLUSH_VERTICES(ctx, 0); |
| 1464 | |
| 1465 | update_array_format(ctx, "glVertexAttribFormat", |
| 1466 | VERT_ATTRIB_GENERIC(attribIndex), |
| 1467 | legalTypes, 1, BGRA_OR_4, size, type, normalized, |
| 1468 | GL_FALSE, relativeOffset); |
Fredrik Höglund | bb2d02c | 2013-04-09 20:44:58 +0200 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | |
| 1472 | void GLAPIENTRY |
| 1473 | _mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type, |
| 1474 | GLuint relativeOffset) |
| 1475 | { |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 1476 | const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT | |
| 1477 | SHORT_BIT | UNSIGNED_SHORT_BIT | |
| 1478 | INT_BIT | UNSIGNED_INT_BIT); |
| 1479 | |
| 1480 | GET_CURRENT_CONTEXT(ctx); |
| 1481 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 1482 | |
| 1483 | /* The ARB_vertex_attrib_binding spec says: |
| 1484 | * |
| 1485 | * "An INVALID_OPERATION error is generated under any of the following |
| 1486 | * conditions: |
| 1487 | * - if no vertex array object is currently bound (see section 2.10); |
| 1488 | * - ..." |
| 1489 | */ |
| 1490 | if (ctx->API == API_OPENGL_CORE && |
| 1491 | ctx->Array.ArrayObj == ctx->Array.DefaultArrayObj) { |
| 1492 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1493 | "glVertexAttribIFormat(No array object bound)"); |
| 1494 | return; |
| 1495 | } |
| 1496 | |
| 1497 | /* The ARB_vertex_attrib_binding spec says: |
| 1498 | * |
| 1499 | * "The error INVALID_VALUE is generated if index is greater than |
| 1500 | * or equal to the value of MAX_VERTEX_ATTRIBS." |
| 1501 | */ |
| 1502 | if (attribIndex >= ctx->Const.VertexProgram.MaxAttribs) { |
| 1503 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 1504 | "glVertexAttribIFormat(attribindex=%u > " |
| 1505 | "GL_MAX_VERTEX_ATTRIBS)", |
| 1506 | attribIndex); |
| 1507 | return; |
| 1508 | } |
| 1509 | |
| 1510 | FLUSH_VERTICES(ctx, 0); |
| 1511 | |
| 1512 | update_array_format(ctx, "glVertexAttribIFormat", |
| 1513 | VERT_ATTRIB_GENERIC(attribIndex), |
| 1514 | legalTypes, 1, 4, size, type, GL_FALSE, GL_TRUE, |
| 1515 | relativeOffset); |
Fredrik Höglund | bb2d02c | 2013-04-09 20:44:58 +0200 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | |
| 1519 | void GLAPIENTRY |
| 1520 | _mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type, |
| 1521 | GLuint relativeOffset) |
| 1522 | { |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 1523 | const GLbitfield legalTypes = DOUBLE_BIT; |
| 1524 | |
| 1525 | GET_CURRENT_CONTEXT(ctx); |
| 1526 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 1527 | |
| 1528 | /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says: |
| 1529 | * |
| 1530 | * "An INVALID_OPERATION error is generated under any of the following |
| 1531 | * conditions: |
| 1532 | * • if no vertex array object is currently bound (see section 10.4); |
| 1533 | * • ..." |
| 1534 | * |
| 1535 | * This language is missing from the extension spec, but we assume |
| 1536 | * that this is an oversight. |
| 1537 | */ |
| 1538 | if (ctx->API == API_OPENGL_CORE && |
| 1539 | ctx->Array.ArrayObj == ctx->Array.DefaultArrayObj) { |
| 1540 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1541 | "glVertexAttribLFormat(No array object bound)"); |
| 1542 | return; |
| 1543 | } |
| 1544 | |
| 1545 | /* The ARB_vertex_attrib_binding spec says: |
| 1546 | * |
| 1547 | * "The error INVALID_VALUE is generated if <attribindex> is greater than |
| 1548 | * or equal to the value of MAX_VERTEX_ATTRIBS." |
| 1549 | */ |
| 1550 | if (attribIndex >= ctx->Const.VertexProgram.MaxAttribs) { |
| 1551 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 1552 | "glVertexAttribLFormat(attribindex=%u > " |
| 1553 | "GL_MAX_VERTEX_ATTRIBS)", |
| 1554 | attribIndex); |
| 1555 | return; |
| 1556 | } |
| 1557 | |
| 1558 | FLUSH_VERTICES(ctx, 0); |
| 1559 | |
| 1560 | update_array_format(ctx, "glVertexAttribLFormat", |
| 1561 | VERT_ATTRIB_GENERIC(attribIndex), |
| 1562 | legalTypes, 1, 4, size, type, GL_FALSE, GL_FALSE, |
| 1563 | relativeOffset); |
Fredrik Höglund | bb2d02c | 2013-04-09 20:44:58 +0200 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | |
| 1567 | void GLAPIENTRY |
| 1568 | _mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex) |
| 1569 | { |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 1570 | GET_CURRENT_CONTEXT(ctx); |
| 1571 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 1572 | |
| 1573 | /* The ARB_vertex_attrib_binding spec says: |
| 1574 | * |
| 1575 | * "An INVALID_OPERATION error is generated if no vertex array object |
| 1576 | * is bound." |
| 1577 | */ |
| 1578 | if (ctx->API == API_OPENGL_CORE && |
| 1579 | ctx->Array.ArrayObj == ctx->Array.DefaultArrayObj) { |
| 1580 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1581 | "glVertexAttribBinding(No array object bound)"); |
| 1582 | return; |
| 1583 | } |
| 1584 | |
| 1585 | /* The ARB_vertex_attrib_binding spec says: |
| 1586 | * |
| 1587 | * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and |
| 1588 | * <bindingindex> must be less than the value of |
| 1589 | * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE |
| 1590 | * is generated." |
| 1591 | */ |
| 1592 | if (attribIndex >= ctx->Const.VertexProgram.MaxAttribs) { |
| 1593 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 1594 | "glVertexAttribBinding(attribindex=%u >= " |
| 1595 | "GL_MAX_VERTEX_ATTRIBS)", |
| 1596 | attribIndex); |
| 1597 | return; |
| 1598 | } |
| 1599 | |
| 1600 | if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) { |
| 1601 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 1602 | "glVertexAttribBinding(bindingindex=%u >= " |
| 1603 | "GL_MAX_VERTEX_ATTRIB_BINDINGS)", |
| 1604 | bindingIndex); |
| 1605 | return; |
| 1606 | } |
| 1607 | |
| 1608 | ASSERT(VERT_ATTRIB_GENERIC(attribIndex) < |
| 1609 | Elements(ctx->Array.ArrayObj->VertexAttrib)); |
| 1610 | |
| 1611 | vertex_attrib_binding(ctx, VERT_ATTRIB_GENERIC(attribIndex), |
| 1612 | VERT_ATTRIB_GENERIC(bindingIndex)); |
Fredrik Höglund | bb2d02c | 2013-04-09 20:44:58 +0200 | [diff] [blame] | 1613 | } |
| 1614 | |
| 1615 | |
| 1616 | void GLAPIENTRY |
| 1617 | _mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor) |
| 1618 | { |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 1619 | GET_CURRENT_CONTEXT(ctx); |
| 1620 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 1621 | |
| 1622 | if (!ctx->Extensions.ARB_instanced_arrays) { |
| 1623 | _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexBindingDivisor()"); |
| 1624 | return; |
| 1625 | } |
| 1626 | |
| 1627 | /* The ARB_vertex_attrib_binding spec says: |
| 1628 | * |
| 1629 | * "An INVALID_OPERATION error is generated if no vertex array object |
| 1630 | * is bound." |
| 1631 | */ |
| 1632 | if (ctx->API == API_OPENGL_CORE && |
| 1633 | ctx->Array.ArrayObj == ctx->Array.DefaultArrayObj) { |
| 1634 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1635 | "glVertexBindingDivisor(No array object bound)"); |
| 1636 | return; |
| 1637 | } |
| 1638 | |
| 1639 | /* The ARB_vertex_attrib_binding spec says: |
| 1640 | * |
| 1641 | * "An INVALID_VALUE error is generated if <bindingindex> is greater |
| 1642 | * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS." |
| 1643 | */ |
| 1644 | if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) { |
| 1645 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 1646 | "glVertexBindingDivisor(bindingindex=%u > " |
| 1647 | "GL_MAX_VERTEX_ATTRIB_BINDINGS)", |
| 1648 | bindingIndex); |
| 1649 | return; |
| 1650 | } |
| 1651 | |
| 1652 | vertex_binding_divisor(ctx, VERT_ATTRIB_GENERIC(bindingIndex), divisor); |
Fredrik Höglund | bb2d02c | 2013-04-09 20:44:58 +0200 | [diff] [blame] | 1653 | } |
| 1654 | |
| 1655 | |
| 1656 | /** |
Brian Paul | b288540 | 2009-08-06 13:53:06 -0600 | [diff] [blame] | 1657 | * Copy one client vertex array to another. |
| 1658 | */ |
| 1659 | void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 1660 | _mesa_copy_client_array(struct gl_context *ctx, |
Brian Paul | b288540 | 2009-08-06 13:53:06 -0600 | [diff] [blame] | 1661 | struct gl_client_array *dst, |
| 1662 | struct gl_client_array *src) |
| 1663 | { |
| 1664 | dst->Size = src->Size; |
| 1665 | dst->Type = src->Type; |
| 1666 | dst->Format = src->Format; |
| 1667 | dst->Stride = src->Stride; |
| 1668 | dst->StrideB = src->StrideB; |
| 1669 | dst->Ptr = src->Ptr; |
| 1670 | dst->Enabled = src->Enabled; |
| 1671 | dst->Normalized = src->Normalized; |
Brian Paul | d1184d2 | 2010-10-28 21:17:41 -0600 | [diff] [blame] | 1672 | dst->Integer = src->Integer; |
Brian Paul | 1d1eb95 | 2011-01-15 10:32:34 -0700 | [diff] [blame] | 1673 | dst->InstanceDivisor = src->InstanceDivisor; |
Brian Paul | b288540 | 2009-08-06 13:53:06 -0600 | [diff] [blame] | 1674 | dst->_ElementSize = src->_ElementSize; |
| 1675 | _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj); |
| 1676 | dst->_MaxElement = src->_MaxElement; |
| 1677 | } |
| 1678 | |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 1679 | void |
| 1680 | _mesa_copy_vertex_attrib_array(struct gl_context *ctx, |
| 1681 | struct gl_vertex_attrib_array *dst, |
| 1682 | const struct gl_vertex_attrib_array *src) |
| 1683 | { |
| 1684 | dst->Size = src->Size; |
| 1685 | dst->Type = src->Type; |
| 1686 | dst->Format = src->Format; |
| 1687 | dst->VertexBinding = src->VertexBinding; |
| 1688 | dst->RelativeOffset = src->RelativeOffset; |
| 1689 | dst->Format = src->Format; |
| 1690 | dst->Integer = src->Integer; |
| 1691 | dst->Normalized = src->Normalized; |
| 1692 | dst->Ptr = src->Ptr; |
| 1693 | dst->Enabled = src->Enabled; |
| 1694 | dst->_ElementSize = src->_ElementSize; |
| 1695 | } |
Brian Paul | b288540 | 2009-08-06 13:53:06 -0600 | [diff] [blame] | 1696 | |
Fredrik Höglund | 59b01ca | 2013-04-09 20:54:25 +0200 | [diff] [blame^] | 1697 | void |
| 1698 | _mesa_copy_vertex_buffer_binding(struct gl_context *ctx, |
| 1699 | struct gl_vertex_buffer_binding *dst, |
| 1700 | const struct gl_vertex_buffer_binding *src) |
| 1701 | { |
| 1702 | dst->Offset = src->Offset; |
| 1703 | dst->Stride = src->Stride; |
| 1704 | dst->InstanceDivisor = src->InstanceDivisor; |
| 1705 | dst->_BoundArrays = src->_BoundArrays; |
| 1706 | |
| 1707 | _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj); |
| 1708 | } |
Brian Paul | b288540 | 2009-08-06 13:53:06 -0600 | [diff] [blame] | 1709 | |
| 1710 | /** |
Brian Paul | 39d7524 | 2009-05-14 16:25:32 -0600 | [diff] [blame] | 1711 | * Print vertex array's fields. |
| 1712 | */ |
| 1713 | static void |
| 1714 | print_array(const char *name, GLint index, const struct gl_client_array *array) |
| 1715 | { |
| 1716 | if (index >= 0) |
Kristian Høgsberg | 298be2b | 2010-02-19 12:32:24 -0500 | [diff] [blame] | 1717 | printf(" %s[%d]: ", name, index); |
Brian Paul | 39d7524 | 2009-05-14 16:25:32 -0600 | [diff] [blame] | 1718 | else |
Kristian Høgsberg | 298be2b | 2010-02-19 12:32:24 -0500 | [diff] [blame] | 1719 | printf(" %s: ", name); |
Brian Paul | 4beea12 | 2010-07-14 14:36:25 -0600 | [diff] [blame] | 1720 | 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] | 1721 | array->Ptr, array->Type, array->Size, |
| 1722 | array->_ElementSize, array->StrideB, |
Brian Paul | 4beea12 | 2010-07-14 14:36:25 -0600 | [diff] [blame] | 1723 | array->BufferObj->Name, (unsigned long) array->BufferObj->Size, |
Kristian Høgsberg | 298be2b | 2010-02-19 12:32:24 -0500 | [diff] [blame] | 1724 | array->_MaxElement); |
Brian Paul | 39d7524 | 2009-05-14 16:25:32 -0600 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | |
| 1728 | /** |
| 1729 | * Print current vertex object/array info. For debug. |
| 1730 | */ |
| 1731 | void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 1732 | _mesa_print_arrays(struct gl_context *ctx) |
Brian Paul | 39d7524 | 2009-05-14 16:25:32 -0600 | [diff] [blame] | 1733 | { |
Brian Paul | 6a2211f | 2009-05-21 15:55:50 -0600 | [diff] [blame] | 1734 | struct gl_array_object *arrayObj = ctx->Array.ArrayObj; |
Brian Paul | 39d7524 | 2009-05-14 16:25:32 -0600 | [diff] [blame] | 1735 | GLuint i; |
| 1736 | |
Brian Paul | 8fe3134 | 2009-05-21 15:36:25 -0600 | [diff] [blame] | 1737 | _mesa_update_array_object_max_element(ctx, arrayObj); |
| 1738 | |
Kristian Høgsberg | 298be2b | 2010-02-19 12:32:24 -0500 | [diff] [blame] | 1739 | printf("Array Object %u\n", arrayObj->Name); |
Fredrik Höglund | 12cbe99 | 2013-04-03 22:08:47 +0200 | [diff] [blame] | 1740 | if (arrayObj->_VertexAttrib[VERT_ATTRIB_POS].Enabled) |
| 1741 | print_array("Vertex", -1, &arrayObj->_VertexAttrib[VERT_ATTRIB_POS]); |
| 1742 | if (arrayObj->_VertexAttrib[VERT_ATTRIB_NORMAL].Enabled) |
| 1743 | print_array("Normal", -1, &arrayObj->_VertexAttrib[VERT_ATTRIB_NORMAL]); |
| 1744 | if (arrayObj->_VertexAttrib[VERT_ATTRIB_COLOR0].Enabled) |
| 1745 | print_array("Color", -1, &arrayObj->_VertexAttrib[VERT_ATTRIB_COLOR0]); |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 1746 | for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) |
Fredrik Höglund | 12cbe99 | 2013-04-03 22:08:47 +0200 | [diff] [blame] | 1747 | if (arrayObj->_VertexAttrib[VERT_ATTRIB_TEX(i)].Enabled) |
| 1748 | print_array("TexCoord", i, &arrayObj->_VertexAttrib[VERT_ATTRIB_TEX(i)]); |
Mathias Fröhlich | 762c976 | 2011-10-31 22:23:51 +0100 | [diff] [blame] | 1749 | for (i = 0; i < VERT_ATTRIB_GENERIC_MAX; i++) |
Fredrik Höglund | 12cbe99 | 2013-04-03 22:08:47 +0200 | [diff] [blame] | 1750 | if (arrayObj->_VertexAttrib[VERT_ATTRIB_GENERIC(i)].Enabled) |
| 1751 | print_array("Attrib", i, &arrayObj->_VertexAttrib[VERT_ATTRIB_GENERIC(i)]); |
Kristian Høgsberg | 298be2b | 2010-02-19 12:32:24 -0500 | [diff] [blame] | 1752 | printf(" _MaxElement = %u\n", arrayObj->_MaxElement); |
Brian Paul | 39d7524 | 2009-05-14 16:25:32 -0600 | [diff] [blame] | 1753 | } |
| 1754 | |
| 1755 | |
| 1756 | /** |
Brian Paul | 095c669 | 2006-04-25 00:21:32 +0000 | [diff] [blame] | 1757 | * Initialize vertex array state for given context. |
| 1758 | */ |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 1759 | void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 1760 | _mesa_init_varray(struct gl_context *ctx) |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1761 | { |
Mathias Fröhlich | 86f53e6 | 2011-11-02 19:54:26 +0100 | [diff] [blame] | 1762 | ctx->Array.DefaultArrayObj = ctx->Driver.NewArrayObject(ctx, 0); |
Brian Paul | 1030bf0 | 2009-05-07 13:52:26 -0600 | [diff] [blame] | 1763 | _mesa_reference_array_object(ctx, &ctx->Array.ArrayObj, |
| 1764 | ctx->Array.DefaultArrayObj); |
Brian Paul | 095c669 | 2006-04-25 00:21:32 +0000 | [diff] [blame] | 1765 | ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */ |
Brian Paul | 12cf98f | 2009-06-19 17:58:47 -0600 | [diff] [blame] | 1766 | |
| 1767 | ctx->Array.Objects = _mesa_NewHashTable(); |
| 1768 | } |
| 1769 | |
| 1770 | |
| 1771 | /** |
| 1772 | * Callback for deleting an array object. Called by _mesa_HashDeleteAll(). |
| 1773 | */ |
| 1774 | static void |
| 1775 | delete_arrayobj_cb(GLuint id, void *data, void *userData) |
| 1776 | { |
| 1777 | struct gl_array_object *arrayObj = (struct gl_array_object *) data; |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 1778 | struct gl_context *ctx = (struct gl_context *) userData; |
Brian Paul | 12cf98f | 2009-06-19 17:58:47 -0600 | [diff] [blame] | 1779 | _mesa_delete_array_object(ctx, arrayObj); |
| 1780 | } |
| 1781 | |
| 1782 | |
| 1783 | /** |
| 1784 | * Free vertex array state for given context. |
| 1785 | */ |
| 1786 | void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 1787 | _mesa_free_varray_data(struct gl_context *ctx) |
Brian Paul | 12cf98f | 2009-06-19 17:58:47 -0600 | [diff] [blame] | 1788 | { |
| 1789 | _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx); |
| 1790 | _mesa_DeleteHashTable(ctx->Array.Objects); |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1791 | } |