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