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