blob: d17d698d3fb755af14896f192c42bfbba987c5ae [file] [log] [blame]
jtgafb833d1999-08-19 00:55:39 +00001/*
2 * Mesa 3-D graphics library
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00003 *
Brian Paul37c74af2008-09-04 14:58:02 -06004 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
Brian Paul39d75242009-05-14 16:25:32 -06005 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00006 *
jtgafb833d1999-08-19 00:55:39 +00007 * 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 Jansen5e3bc0c2000-11-22 07:32:16 +000013 *
jtgafb833d1999-08-19 00:55:39 +000014 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000016 *
jtgafb833d1999-08-19 00:55:39 +000017 * 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 Graunke3d8d5b22013-04-21 13:46:48 -070020 * 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.
jtgafb833d1999-08-19 00:55:39 +000024 */
25
Keith Whitwell6dc85572003-07-17 13:43:59 +000026
Brian Paulfbd8f211999-11-11 01:22:25 +000027#include "glheader.h"
Brian Paul148a2842003-09-17 03:40:11 +000028#include "imports.h"
Brian Paul26895aa2004-03-03 15:35:08 +000029#include "bufferobj.h"
jtgafb833d1999-08-19 00:55:39 +000030#include "context.h"
jtgafb833d1999-08-19 00:55:39 +000031#include "enable.h"
32#include "enums.h"
Brian Paul12cf98f2009-06-19 17:58:47 -060033#include "hash.h"
Brian Paul433e5e62010-10-28 21:17:42 -060034#include "image.h"
Brian Pauld3f598a2010-05-25 21:42:13 -060035#include "macros.h"
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000036#include "mtypes.h"
jtgafb833d1999-08-19 00:55:39 +000037#include "varray.h"
Ian Romanickee34e6e2006-06-12 16:26:29 +000038#include "arrayobj.h"
Chia-I Wu2cf44392010-02-24 12:01:14 +080039#include "main/dispatch.h"
jtgafb833d1999-08-19 00:55:39 +000040
Brian Paulc5b1e812003-10-22 22:59:07 +000041
Brian Paul433e5e62010-10-28 21:17:42 -060042/** Used to do error checking for GL_EXT_vertex_array_bgra */
43#define BGRA_OR_4 5
44
45
46/** Used to indicate which GL datatypes are accepted by each of the
47 * glVertex/Color/Attrib/EtcPointer() functions.
48 */
49#define BOOL_BIT 0x1
50#define BYTE_BIT 0x2
51#define UNSIGNED_BYTE_BIT 0x4
52#define SHORT_BIT 0x8
53#define UNSIGNED_SHORT_BIT 0x10
54#define INT_BIT 0x20
55#define UNSIGNED_INT_BIT 0x40
56#define HALF_BIT 0x80
57#define FLOAT_BIT 0x100
58#define DOUBLE_BIT 0x200
Marek Olšák0f1e59d2011-04-29 14:23:15 +020059#define FIXED_ES_BIT 0x400
60#define FIXED_GL_BIT 0x800
Dave Airlie6cd2d552011-08-13 15:30:38 +010061#define UNSIGNED_INT_2_10_10_10_REV_BIT 0x1000
62#define INT_2_10_10_10_REV_BIT 0x2000
Chris Forbes1f092a92013-11-07 22:02:24 +130063#define UNSIGNED_INT_10F_11F_11F_REV_BIT 0x4000
Brian Paul433e5e62010-10-28 21:17:42 -060064
65
66/** Convert GL datatype enum into a <type>_BIT value seen above */
67static GLbitfield
68type_to_bit(const struct gl_context *ctx, GLenum type)
69{
70 switch (type) {
71 case GL_BOOL:
72 return BOOL_BIT;
73 case GL_BYTE:
74 return BYTE_BIT;
75 case GL_UNSIGNED_BYTE:
76 return UNSIGNED_BYTE_BIT;
77 case GL_SHORT:
78 return SHORT_BIT;
79 case GL_UNSIGNED_SHORT:
80 return UNSIGNED_SHORT_BIT;
81 case GL_INT:
82 return INT_BIT;
83 case GL_UNSIGNED_INT:
84 return UNSIGNED_INT_BIT;
85 case GL_HALF_FLOAT:
86 if (ctx->Extensions.ARB_half_float_vertex)
87 return HALF_BIT;
88 else
89 return 0x0;
90 case GL_FLOAT:
91 return FLOAT_BIT;
92 case GL_DOUBLE:
93 return DOUBLE_BIT;
94 case GL_FIXED:
Jordan Justen09714c02012-07-19 11:27:16 -070095 return _mesa_is_desktop_gl(ctx) ? FIXED_GL_BIT : FIXED_ES_BIT;
Dave Airlie6cd2d552011-08-13 15:30:38 +010096 case GL_UNSIGNED_INT_2_10_10_10_REV:
97 return UNSIGNED_INT_2_10_10_10_REV_BIT;
98 case GL_INT_2_10_10_10_REV:
99 return INT_2_10_10_10_REV_BIT;
Chris Forbes1f092a92013-11-07 22:02:24 +1300100 case GL_UNSIGNED_INT_10F_11F_11F_REV:
101 return UNSIGNED_INT_10F_11F_11F_REV_BIT;
Brian Paul433e5e62010-10-28 21:17:42 -0600102 default:
103 return 0;
104 }
105}
106
107
Brian Paulc5b1e812003-10-22 22:59:07 +0000108/**
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200109 * Sets the VertexBinding field in the vertex attribute given by attribIndex.
110 */
111static void
112vertex_attrib_binding(struct gl_context *ctx, GLuint attribIndex,
113 GLuint bindingIndex)
114{
115 struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
116 struct gl_vertex_attrib_array *array = &arrayObj->VertexAttrib[attribIndex];
117
118 if (array->VertexBinding != bindingIndex) {
119 const GLbitfield64 array_bit = VERT_BIT(attribIndex);
120
121 FLUSH_VERTICES(ctx, _NEW_ARRAY);
122
123 arrayObj->VertexBinding[array->VertexBinding]._BoundArrays &= ~array_bit;
124 arrayObj->VertexBinding[bindingIndex]._BoundArrays |= array_bit;
125
126 array->VertexBinding = bindingIndex;
127
128 arrayObj->NewArrays |= array_bit;
129 }
130}
131
132
133/**
134 * Binds a buffer object to the vertex buffer binding point given by index,
135 * and sets the Offset and Stride fields.
136 */
137static void
138bind_vertex_buffer(struct gl_context *ctx, GLuint index,
139 struct gl_buffer_object *vbo,
140 GLintptr offset, GLsizei stride)
141{
142 struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
143 struct gl_vertex_buffer_binding *binding = &arrayObj->VertexBinding[index];
144
145 if (binding->BufferObj != vbo ||
146 binding->Offset != offset ||
147 binding->Stride != stride) {
148
149 FLUSH_VERTICES(ctx, _NEW_ARRAY);
150
151 _mesa_reference_buffer_object(ctx, &binding->BufferObj, vbo);
152
153 binding->Offset = offset;
154 binding->Stride = stride;
155
156 arrayObj->NewArrays |= binding->_BoundArrays;
157 }
158}
159
160
161/**
162 * Sets the InstanceDivisor field in the vertex buffer binding point
163 * given by bindingIndex.
164 */
165static void
166vertex_binding_divisor(struct gl_context *ctx, GLuint bindingIndex,
167 GLuint divisor)
168{
169 struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
170 struct gl_vertex_buffer_binding *binding =
171 &arrayObj->VertexBinding[bindingIndex];
172
173 if (binding->InstanceDivisor != divisor) {
174 FLUSH_VERTICES(ctx, _NEW_ARRAY);
175 binding->InstanceDivisor = divisor;
176 arrayObj->NewArrays |= binding->_BoundArrays;
177 }
178}
179
180
181/**
Fredrik Höglundd5543212013-04-03 21:47:44 +0200182 * Does error checking and updates the format in an attrib array.
Brian Paulf9d88c82006-06-13 17:24:36 +0000183 *
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200184 * Called by update_array() and VertexAttrib*Format().
Fredrik Höglundd5543212013-04-03 21:47:44 +0200185 *
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200186 * \param func Name of calling function used for error reporting
187 * \param attrib The index of the attribute array
188 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
189 * \param sizeMin Min allowable size value
190 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
191 * \param size Components per element (1, 2, 3 or 4)
192 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
193 * \param normalized Whether integer types are converted to floats in [-1, 1]
194 * \param integer Integer-valued values (will not be normalized to [-1, 1])
195 * \param relativeOffset Offset of the first element relative to the binding offset.
Brian Paulc5b1e812003-10-22 22:59:07 +0000196 */
Fredrik Höglundd5543212013-04-03 21:47:44 +0200197static bool
198update_array_format(struct gl_context *ctx,
199 const char *func,
200 GLuint attrib, GLbitfield legalTypesMask,
201 GLint sizeMin, GLint sizeMax,
202 GLint size, GLenum type,
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200203 GLboolean normalized, GLboolean integer,
204 GLuint relativeOffset)
Brian Paulc5b1e812003-10-22 22:59:07 +0000205{
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200206 struct gl_vertex_attrib_array *array;
Brian Paul433e5e62010-10-28 21:17:42 -0600207 GLbitfield typeBit;
Fredrik Höglundd5543212013-04-03 21:47:44 +0200208 GLuint elementSize;
Brian Paul433e5e62010-10-28 21:17:42 -0600209 GLenum format = GL_RGBA;
210
Ian Romanickbbceed22012-07-25 14:40:18 -0700211 if (_mesa_is_gles(ctx)) {
Chris Forbes1f092a92013-11-07 22:02:24 +1300212 legalTypesMask &= ~(FIXED_GL_BIT | DOUBLE_BIT | UNSIGNED_INT_10F_11F_11F_REV_BIT);
Ian Romanickbbceed22012-07-25 14:40:18 -0700213
214 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
215 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
Matt Turnerc8901132012-11-28 21:45:19 -0800216 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
217 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
218 * quite as trivial as we'd like because it uses a different enum value
219 * for GL_HALF_FLOAT_OES.
Ian Romanickbbceed22012-07-25 14:40:18 -0700220 */
221 if (ctx->Version < 30) {
222 legalTypesMask &= ~(UNSIGNED_INT_BIT
223 | INT_BIT
224 | UNSIGNED_INT_2_10_10_10_REV_BIT
Matt Turnerc8901132012-11-28 21:45:19 -0800225 | INT_2_10_10_10_REV_BIT
226 | HALF_BIT);
Ian Romanickbbceed22012-07-25 14:40:18 -0700227 }
Ian Romanick946ddec2012-07-25 14:46:54 -0700228
229 /* BGRA ordering is not supported in ES contexts.
230 */
231 if (sizeMax == BGRA_OR_4)
232 sizeMax = 4;
Ian Romanickbbceed22012-07-25 14:40:18 -0700233 } else {
Marek Olšák0f1e59d2011-04-29 14:23:15 +0200234 legalTypesMask &= ~FIXED_ES_BIT;
Ian Romanickbbceed22012-07-25 14:40:18 -0700235
236 if (!ctx->Extensions.ARB_ES2_compatibility)
237 legalTypesMask &= ~FIXED_GL_BIT;
238
239 if (!ctx->Extensions.ARB_vertex_type_2_10_10_10_rev)
240 legalTypesMask &= ~(UNSIGNED_INT_2_10_10_10_REV_BIT |
241 INT_2_10_10_10_REV_BIT);
Chris Forbes1f092a92013-11-07 22:02:24 +1300242
243 if (!ctx->Extensions.ARB_vertex_type_10f_11f_11f_rev)
244 legalTypesMask &= ~UNSIGNED_INT_10F_11F_11F_REV_BIT;
Dave Airlie6cd2d552011-08-13 15:30:38 +0100245 }
Brian Paul11dd2282010-11-07 18:35:35 -0700246
Brian Paul433e5e62010-10-28 21:17:42 -0600247 typeBit = type_to_bit(ctx, type);
248 if (typeBit == 0x0 || (typeBit & legalTypesMask) == 0x0) {
249 _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)",
250 func, _mesa_lookup_enum_by_nr(type));
Fredrik Höglundd5543212013-04-03 21:47:44 +0200251 return false;
Brian Paul433e5e62010-10-28 21:17:42 -0600252 }
253
254 /* Do size parameter checking.
255 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
256 * must be handled specially.
257 */
258 if (ctx->Extensions.EXT_vertex_array_bgra &&
259 sizeMax == BGRA_OR_4 &&
260 size == GL_BGRA) {
Fredrik Höglund0e7a61a2013-04-12 17:36:06 +0200261 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
262 *
263 * "An INVALID_OPERATION error is generated under any of the following
264 * conditions:
265 * ...
266 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
267 * or UNSIGNED_INT_2_10_10_10_REV;
268 * ...
269 * • size is BGRA and normalized is FALSE;"
270 */
Fredrik Höglundd5543212013-04-03 21:47:44 +0200271 bool bgra_error = false;
Dave Airlie99c1a582011-09-07 10:19:14 +0100272
273 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev) {
274 if (type != GL_UNSIGNED_INT_2_10_10_10_REV &&
275 type != GL_INT_2_10_10_10_REV &&
276 type != GL_UNSIGNED_BYTE)
Fredrik Höglundd5543212013-04-03 21:47:44 +0200277 bgra_error = true;
Dave Airlie99c1a582011-09-07 10:19:14 +0100278 } else if (type != GL_UNSIGNED_BYTE)
Fredrik Höglundd5543212013-04-03 21:47:44 +0200279 bgra_error = true;
Dave Airlie99c1a582011-09-07 10:19:14 +0100280
281 if (bgra_error) {
Fredrik Höglund0e7a61a2013-04-12 17:36:06 +0200282 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=GL_BGRA and type=%s)",
283 func, _mesa_lookup_enum_by_nr(type));
Fredrik Höglundd5543212013-04-03 21:47:44 +0200284 return false;
Brian Paul433e5e62010-10-28 21:17:42 -0600285 }
Fredrik Höglund0e7a61a2013-04-12 17:36:06 +0200286
287 if (!normalized) {
288 _mesa_error(ctx, GL_INVALID_OPERATION,
289 "%s(size=GL_BGRA and normalized=GL_FALSE)", func);
Fredrik Höglundd5543212013-04-03 21:47:44 +0200290 return false;
Fredrik Höglund0e7a61a2013-04-12 17:36:06 +0200291 }
292
Brian Paul433e5e62010-10-28 21:17:42 -0600293 format = GL_BGRA;
294 size = 4;
295 }
296 else if (size < sizeMin || size > sizeMax || size > 4) {
297 _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d)", func, size);
Fredrik Höglundd5543212013-04-03 21:47:44 +0200298 return false;
Brian Paul433e5e62010-10-28 21:17:42 -0600299 }
300
Dave Airlie6cd2d552011-08-13 15:30:38 +0100301 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev &&
302 (type == GL_UNSIGNED_INT_2_10_10_10_REV ||
303 type == GL_INT_2_10_10_10_REV) && size != 4) {
304 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size);
Fredrik Höglundd5543212013-04-03 21:47:44 +0200305 return false;
Dave Airlie6cd2d552011-08-13 15:30:38 +0100306 }
307
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200308 /* The ARB_vertex_attrib_binding_spec says:
309 *
310 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
311 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
312 */
313 if (relativeOffset > ctx->Const.MaxVertexAttribRelativeOffset) {
314 _mesa_error(ctx, GL_INVALID_VALUE,
315 "%s(relativeOffset=%d > "
316 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
317 func, relativeOffset);
Brian Paulfe9284a2013-11-07 15:23:34 -0700318 return false;
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200319 }
320
Chris Forbes1f092a92013-11-07 22:02:24 +1300321 if (ctx->Extensions.ARB_vertex_type_10f_11f_11f_rev &&
322 type == GL_UNSIGNED_INT_10F_11F_11F_REV && size != 3) {
323 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size);
Brian Paulfe9284a2013-11-07 15:23:34 -0700324 return false;
Chris Forbes1f092a92013-11-07 22:02:24 +1300325 }
326
Brian Paul433e5e62010-10-28 21:17:42 -0600327 ASSERT(size <= 4);
328
Fredrik Höglundd5543212013-04-03 21:47:44 +0200329 elementSize = _mesa_bytes_per_vertex_attrib(size, type);
330 assert(elementSize != -1);
331
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200332 array = &ctx->Array.ArrayObj->VertexAttrib[attrib];
Fredrik Höglundd5543212013-04-03 21:47:44 +0200333 array->Size = size;
334 array->Type = type;
335 array->Format = format;
336 array->Normalized = normalized;
337 array->Integer = integer;
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200338 array->RelativeOffset = relativeOffset;
Fredrik Höglundd5543212013-04-03 21:47:44 +0200339 array->_ElementSize = elementSize;
340
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200341 ctx->Array.ArrayObj->NewArrays |= VERT_BIT(attrib);
342 ctx->NewState |= _NEW_ARRAY;
343
Fredrik Höglundd5543212013-04-03 21:47:44 +0200344 return true;
345}
346
347
348/**
349 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
350 * functions.
351 *
352 * \param func name of calling function used for error reporting
353 * \param attrib the attribute array index to update
354 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
355 * \param sizeMin min allowable size value
356 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
357 * \param size components per element (1, 2, 3 or 4)
358 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
359 * \param stride stride between elements, in elements
360 * \param normalized are integer types converted to floats in [-1, 1]?
361 * \param integer integer-valued values (will not be normalized to [-1,1])
362 * \param ptr the address (or offset inside VBO) of the array data
363 */
364static void
365update_array(struct gl_context *ctx,
366 const char *func,
367 GLuint attrib, GLbitfield legalTypesMask,
368 GLint sizeMin, GLint sizeMax,
369 GLint size, GLenum type, GLsizei stride,
370 GLboolean normalized, GLboolean integer,
371 const GLvoid *ptr)
372{
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200373 struct gl_vertex_attrib_array *array;
374 GLsizei effectiveStride;
Fredrik Höglundd5543212013-04-03 21:47:44 +0200375
376 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
377 *
378 * "Client vertex arrays - all vertex array attribute pointers must
379 * refer to buffer objects (section 2.9.2). The default vertex array
380 * object (the name zero) is also deprecated. Calling
381 * VertexAttribPointer when no buffer object or no vertex array object
382 * is bound will generate an INVALID_OPERATION error..."
383 *
384 * The check for VBOs is handled below.
385 */
386 if (ctx->API == API_OPENGL_CORE
387 && (ctx->Array.ArrayObj == ctx->Array.DefaultArrayObj)) {
388 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(no array object bound)",
389 func);
390 return;
391 }
392
393 if (!update_array_format(ctx, func, attrib, legalTypesMask, sizeMin, sizeMax,
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200394 size, type, normalized, integer, 0)) {
Fredrik Höglundd5543212013-04-03 21:47:44 +0200395 return;
396 }
397
Brian Paul433e5e62010-10-28 21:17:42 -0600398 if (stride < 0) {
399 _mesa_error( ctx, GL_INVALID_VALUE, "%s(stride=%d)", func, stride );
400 return;
401 }
Brian Paule2b72492009-06-22 16:56:35 -0600402
Ian Romanick843b8762012-08-17 17:12:39 -0700403 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
404 *
405 * "An INVALID_OPERATION error is generated under any of the following
406 * conditions:
407 *
408 * ...
409 *
410 * * any of the *Pointer commands specifying the location and
411 * organization of vertex array data are called while zero is bound
412 * to the ARRAY_BUFFER buffer object binding point (see section
413 * 2.9.6), and the pointer argument is not NULL."
414 */
415 if (ptr != NULL && ctx->Array.ArrayObj->ARBsemantics &&
Brian Paulefcf5aa2011-11-29 07:44:20 -0700416 !_mesa_is_bufferobj(ctx->Array.ArrayBufferObj)) {
Brian Paul433e5e62010-10-28 21:17:42 -0600417 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-VBO array)", func);
Brian Paulf549f4c2009-11-12 23:04:26 -0700418 return;
Brian Paule2b72492009-06-22 16:56:35 -0600419 }
420
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200421 /* Reset the vertex attrib binding */
422 vertex_attrib_binding(ctx, attrib, attrib);
423
424 /* The Stride and Ptr fields are not set by update_array_format() */
425 array = &ctx->Array.ArrayObj->VertexAttrib[attrib];
Brian Paulc5b1e812003-10-22 22:59:07 +0000426 array->Stride = stride;
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200427 array->Ptr = (const GLvoid *) ptr;
Brian Paul0077c872009-05-06 13:00:35 -0600428
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200429 /* Update the vertex buffer binding */
430 effectiveStride = stride != 0 ? stride : array->_ElementSize;
431 bind_vertex_buffer(ctx, attrib, ctx->Array.ArrayBufferObj,
432 (GLintptr) ptr, effectiveStride);
Brian Paulc5b1e812003-10-22 22:59:07 +0000433}
434
435
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000436void GLAPIENTRY
Brian Paulfbd8f211999-11-11 01:22:25 +0000437_mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
jtgafb833d1999-08-19 00:55:39 +0000438{
Brian Paulfbd8f211999-11-11 01:22:25 +0000439 GET_CURRENT_CONTEXT(ctx);
Ian Romanicke2cf14d2012-07-25 15:19:31 -0700440 GLbitfield legalTypes = (ctx->API == API_OPENGLES)
441 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
442 : (SHORT_BIT | INT_BIT | FLOAT_BIT |
443 DOUBLE_BIT | HALF_BIT |
444 UNSIGNED_INT_2_10_10_10_REV_BIT |
445 INT_2_10_10_10_REV_BIT);
Eric Anholta9754792013-01-16 16:20:38 -0800446
447 FLUSH_VERTICES(ctx, 0);
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000448
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100449 update_array(ctx, "glVertexPointer", VERT_ATTRIB_POS,
Brian Paul433e5e62010-10-28 21:17:42 -0600450 legalTypes, 2, 4,
451 size, type, stride, GL_FALSE, GL_FALSE, ptr);
jtgafb833d1999-08-19 00:55:39 +0000452}
453
454
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000455void GLAPIENTRY
Brian Paulfbd8f211999-11-11 01:22:25 +0000456_mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
jtgafb833d1999-08-19 00:55:39 +0000457{
Brian Paulfbd8f211999-11-11 01:22:25 +0000458 GET_CURRENT_CONTEXT(ctx);
Ian Romanicke5ef0cb2012-07-25 15:10:21 -0700459 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
460 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
461 : (BYTE_BIT | SHORT_BIT | INT_BIT |
462 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
463 UNSIGNED_INT_2_10_10_10_REV_BIT |
464 INT_2_10_10_10_REV_BIT);
Eric Anholta9754792013-01-16 16:20:38 -0800465
466 FLUSH_VERTICES(ctx, 0);
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000467
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100468 update_array(ctx, "glNormalPointer", VERT_ATTRIB_NORMAL,
Brian Paul433e5e62010-10-28 21:17:42 -0600469 legalTypes, 3, 3,
470 3, type, stride, GL_TRUE, GL_FALSE, ptr);
jtgafb833d1999-08-19 00:55:39 +0000471}
472
473
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000474void GLAPIENTRY
Brian Paulfbd8f211999-11-11 01:22:25 +0000475_mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
jtgafb833d1999-08-19 00:55:39 +0000476{
Brian Paulfbd8f211999-11-11 01:22:25 +0000477 GET_CURRENT_CONTEXT(ctx);
Ian Romanick07ccfef2012-07-25 14:53:01 -0700478 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
479 ? (UNSIGNED_BYTE_BIT | HALF_BIT | FLOAT_BIT | FIXED_ES_BIT)
480 : (BYTE_BIT | UNSIGNED_BYTE_BIT |
481 SHORT_BIT | UNSIGNED_SHORT_BIT |
482 INT_BIT | UNSIGNED_INT_BIT |
483 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
484 UNSIGNED_INT_2_10_10_10_REV_BIT |
485 INT_2_10_10_10_REV_BIT);
Ian Romanickfb821852012-07-25 14:58:36 -0700486 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 4 : 3;
Eric Anholta9754792013-01-16 16:20:38 -0800487
488 FLUSH_VERTICES(ctx, 0);
Brian Paulfbd8f211999-11-11 01:22:25 +0000489
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100490 update_array(ctx, "glColorPointer", VERT_ATTRIB_COLOR0,
Ian Romanickfb821852012-07-25 14:58:36 -0700491 legalTypes, sizeMin, BGRA_OR_4,
Brian Paul433e5e62010-10-28 21:17:42 -0600492 size, type, stride, GL_TRUE, GL_FALSE, ptr);
jtgafb833d1999-08-19 00:55:39 +0000493}
494
495
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000496void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800497_mesa_FogCoordPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000498{
Brian Paul433e5e62010-10-28 21:17:42 -0600499 const GLbitfield legalTypes = (HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000500 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -0800501
502 FLUSH_VERTICES(ctx, 0);
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000503
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100504 update_array(ctx, "glFogCoordPointer", VERT_ATTRIB_FOG,
Brian Paul433e5e62010-10-28 21:17:42 -0600505 legalTypes, 1, 1,
506 1, type, stride, GL_FALSE, GL_FALSE, ptr);
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000507}
508
509
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000510void GLAPIENTRY
Brian Paulfbd8f211999-11-11 01:22:25 +0000511_mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
jtgafb833d1999-08-19 00:55:39 +0000512{
Brian Paul433e5e62010-10-28 21:17:42 -0600513 const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT | INT_BIT |
514 FLOAT_BIT | DOUBLE_BIT);
Brian Paulfbd8f211999-11-11 01:22:25 +0000515 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -0800516
517 FLUSH_VERTICES(ctx, 0);
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000518
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100519 update_array(ctx, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX,
Brian Paul433e5e62010-10-28 21:17:42 -0600520 legalTypes, 1, 1,
521 1, type, stride, GL_FALSE, GL_FALSE, ptr);
jtgafb833d1999-08-19 00:55:39 +0000522}
523
524
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000525void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800526_mesa_SecondaryColorPointer(GLint size, GLenum type,
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000527 GLsizei stride, const GLvoid *ptr)
528{
Brian Paul433e5e62010-10-28 21:17:42 -0600529 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
530 SHORT_BIT | UNSIGNED_SHORT_BIT |
531 INT_BIT | UNSIGNED_INT_BIT |
Dave Airlie6cd2d552011-08-13 15:30:38 +0100532 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
533 UNSIGNED_INT_2_10_10_10_REV_BIT |
534 INT_2_10_10_10_REV_BIT);
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000535 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -0800536
537 FLUSH_VERTICES(ctx, 0);
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000538
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100539 update_array(ctx, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1,
Brian Paul433e5e62010-10-28 21:17:42 -0600540 legalTypes, 3, BGRA_OR_4,
541 size, type, stride, GL_TRUE, GL_FALSE, ptr);
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000542}
543
544
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000545void GLAPIENTRY
Brian Paul2edd1802002-01-11 17:25:35 +0000546_mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
547 const GLvoid *ptr)
jtgafb833d1999-08-19 00:55:39 +0000548{
Brian Paulfbd8f211999-11-11 01:22:25 +0000549 GET_CURRENT_CONTEXT(ctx);
Ian Romanickc3e9a202012-07-25 15:13:00 -0700550 GLbitfield legalTypes = (ctx->API == API_OPENGLES)
551 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
552 : (SHORT_BIT | INT_BIT |
553 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
554 UNSIGNED_INT_2_10_10_10_REV_BIT |
555 INT_2_10_10_10_REV_BIT);
Ian Romanicka8f475d2012-07-25 15:13:51 -0700556 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 2 : 1;
Brian Paulc5b1e812003-10-22 22:59:07 +0000557 const GLuint unit = ctx->Array.ActiveTexture;
Eric Anholta9754792013-01-16 16:20:38 -0800558
559 FLUSH_VERTICES(ctx, 0);
jtgafb833d1999-08-19 00:55:39 +0000560
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100561 update_array(ctx, "glTexCoordPointer", VERT_ATTRIB_TEX(unit),
Ian Romanicka8f475d2012-07-25 15:13:51 -0700562 legalTypes, sizeMin, 4,
Brian Paul433e5e62010-10-28 21:17:42 -0600563 size, type, stride, GL_FALSE, GL_FALSE,
Brian Pauld1184d22010-10-28 21:17:41 -0600564 ptr);
jtgafb833d1999-08-19 00:55:39 +0000565}
566
567
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000568void GLAPIENTRY
Brian Paulc5b1e812003-10-22 22:59:07 +0000569_mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr)
jtgafb833d1999-08-19 00:55:39 +0000570{
Brian Paulee1f0472010-11-02 08:22:40 -0600571 const GLbitfield legalTypes = UNSIGNED_BYTE_BIT;
Brian Pauld1184d22010-10-28 21:17:41 -0600572 /* see table 2.4 edits in GL_EXT_gpu_shader4 spec: */
573 const GLboolean integer = GL_TRUE;
Brian Paulfbd8f211999-11-11 01:22:25 +0000574 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -0800575
576 FLUSH_VERTICES(ctx, 0);
jtgafb833d1999-08-19 00:55:39 +0000577
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100578 update_array(ctx, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG,
Brian Paul433e5e62010-10-28 21:17:42 -0600579 legalTypes, 1, 1,
Brian Paulee1f0472010-11-02 08:22:40 -0600580 1, GL_UNSIGNED_BYTE, stride, GL_FALSE, integer, ptr);
jtgafb833d1999-08-19 00:55:39 +0000581}
582
583
Brian Paul1cf2c8a2008-06-25 08:45:14 -0600584void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800585_mesa_PointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *ptr)
Brian Paul1cf2c8a2008-06-25 08:45:14 -0600586{
Marek Olšák0f1e59d2011-04-29 14:23:15 +0200587 const GLbitfield legalTypes = (FLOAT_BIT | FIXED_ES_BIT);
Brian Paul1cf2c8a2008-06-25 08:45:14 -0600588 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -0800589
590 FLUSH_VERTICES(ctx, 0);
Brian Paul1cf2c8a2008-06-25 08:45:14 -0600591
Brian Paul11dd2282010-11-07 18:35:35 -0700592 if (ctx->API != API_OPENGLES) {
593 _mesa_error(ctx, GL_INVALID_OPERATION,
594 "glPointSizePointer(ES 1.x only)");
595 return;
596 }
597
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100598 update_array(ctx, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE,
Brian Paul433e5e62010-10-28 21:17:42 -0600599 legalTypes, 1, 1,
600 1, type, stride, GL_FALSE, GL_FALSE, ptr);
Brian Paul1cf2c8a2008-06-25 08:45:14 -0600601}
602
603
Brian Paula554d7c2009-05-21 15:55:33 -0600604/**
Brian Paula554d7c2009-05-21 15:55:33 -0600605 * Set a generic vertex attribute array.
606 * Note that these arrays DO NOT alias the conventional GL vertex arrays
607 * (position, normal, color, fog, texcoord, etc).
608 */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000609void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800610_mesa_VertexAttribPointer(GLuint index, GLint size, GLenum type,
Brian Paul92f97852003-05-01 22:44:02 +0000611 GLboolean normalized,
612 GLsizei stride, const GLvoid *ptr)
613{
Brian Paul433e5e62010-10-28 21:17:42 -0600614 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
615 SHORT_BIT | UNSIGNED_SHORT_BIT |
616 INT_BIT | UNSIGNED_INT_BIT |
617 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
Dave Airlie6cd2d552011-08-13 15:30:38 +0100618 FIXED_ES_BIT | FIXED_GL_BIT |
619 UNSIGNED_INT_2_10_10_10_REV_BIT |
Chris Forbes1f092a92013-11-07 22:02:24 +1300620 INT_2_10_10_10_REV_BIT |
621 UNSIGNED_INT_10F_11F_11F_REV_BIT);
Brian Paul92f97852003-05-01 22:44:02 +0000622 GET_CURRENT_CONTEXT(ctx);
Brian Paul92f97852003-05-01 22:44:02 +0000623
Brian Paul05051032005-11-01 04:36:33 +0000624 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
Brian Paul92f97852003-05-01 22:44:02 +0000625 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(index)");
626 return;
627 }
628
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100629 update_array(ctx, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index),
Brian Paul433e5e62010-10-28 21:17:42 -0600630 legalTypes, 1, BGRA_OR_4,
631 size, type, stride, normalized, GL_FALSE, ptr);
Brian Paul92f97852003-05-01 22:44:02 +0000632}
Brian Paul92f97852003-05-01 22:44:02 +0000633
634
Brian Paule00d07c2010-05-25 21:12:24 -0600635/**
Brian Pauld1184d22010-10-28 21:17:41 -0600636 * GL_EXT_gpu_shader4 / GL 3.0.
Brian Paule00d07c2010-05-25 21:12:24 -0600637 * Set an integer-valued vertex attribute array.
638 * Note that these arrays DO NOT alias the conventional GL vertex arrays
639 * (position, normal, color, fog, texcoord, etc).
640 */
641void GLAPIENTRY
642_mesa_VertexAttribIPointer(GLuint index, GLint size, GLenum type,
Brian Paule00d07c2010-05-25 21:12:24 -0600643 GLsizei stride, const GLvoid *ptr)
644{
Brian Paul433e5e62010-10-28 21:17:42 -0600645 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
646 SHORT_BIT | UNSIGNED_SHORT_BIT |
647 INT_BIT | UNSIGNED_INT_BIT);
Brian Pauld1184d22010-10-28 21:17:41 -0600648 const GLboolean normalized = GL_FALSE;
649 const GLboolean integer = GL_TRUE;
Brian Pauld1184d22010-10-28 21:17:41 -0600650 GET_CURRENT_CONTEXT(ctx);
Brian Pauld1184d22010-10-28 21:17:41 -0600651
652 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
653 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribIPointer(index)");
654 return;
655 }
656
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100657 update_array(ctx, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index),
Brian Paul433e5e62010-10-28 21:17:42 -0600658 legalTypes, 1, 4,
659 size, type, stride, normalized, integer, ptr);
Brian Paule00d07c2010-05-25 21:12:24 -0600660}
661
662
663
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000664void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800665_mesa_EnableVertexAttribArray(GLuint index)
Brian Pauld3f598a2010-05-25 21:42:13 -0600666{
Brian Paul45453d82012-02-19 19:50:31 -0700667 struct gl_array_object *arrayObj;
Brian Pauld3f598a2010-05-25 21:42:13 -0600668 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600669
670 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
671 _mesa_error(ctx, GL_INVALID_VALUE,
672 "glEnableVertexAttribArrayARB(index)");
673 return;
674 }
675
Brian Paul45453d82012-02-19 19:50:31 -0700676 arrayObj = ctx->Array.ArrayObj;
Brian Pauld3f598a2010-05-25 21:42:13 -0600677
Fredrik Höglund12cbe992013-04-03 22:08:47 +0200678 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(arrayObj->_VertexAttrib));
Brian Paul45453d82012-02-19 19:50:31 -0700679
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200680 if (!arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) {
Brian Paul45453d82012-02-19 19:50:31 -0700681 /* was disabled, now being enabled */
682 FLUSH_VERTICES(ctx, _NEW_ARRAY);
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200683 arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_TRUE;
Brian Paul45453d82012-02-19 19:50:31 -0700684 arrayObj->_Enabled |= VERT_BIT_GENERIC(index);
Fredrik Höglund6a650fa2013-05-11 19:23:46 +0200685 arrayObj->NewArrays |= VERT_BIT_GENERIC(index);
Brian Paul45453d82012-02-19 19:50:31 -0700686 }
Brian Pauld3f598a2010-05-25 21:42:13 -0600687}
688
689
690void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800691_mesa_DisableVertexAttribArray(GLuint index)
Brian Pauld3f598a2010-05-25 21:42:13 -0600692{
Brian Paul45453d82012-02-19 19:50:31 -0700693 struct gl_array_object *arrayObj;
Brian Pauld3f598a2010-05-25 21:42:13 -0600694 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600695
696 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
697 _mesa_error(ctx, GL_INVALID_VALUE,
Brian Paul95368f22011-04-06 14:22:39 -0600698 "glDisableVertexAttribArrayARB(index)");
Brian Pauld3f598a2010-05-25 21:42:13 -0600699 return;
700 }
701
Brian Paul45453d82012-02-19 19:50:31 -0700702 arrayObj = ctx->Array.ArrayObj;
Brian Pauld3f598a2010-05-25 21:42:13 -0600703
Fredrik Höglund12cbe992013-04-03 22:08:47 +0200704 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(arrayObj->_VertexAttrib));
Brian Paul45453d82012-02-19 19:50:31 -0700705
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200706 if (arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) {
Brian Paul45453d82012-02-19 19:50:31 -0700707 /* was enabled, now being disabled */
708 FLUSH_VERTICES(ctx, _NEW_ARRAY);
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200709 arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_FALSE;
Brian Paul45453d82012-02-19 19:50:31 -0700710 arrayObj->_Enabled &= ~VERT_BIT_GENERIC(index);
Fredrik Höglund6a650fa2013-05-11 19:23:46 +0200711 arrayObj->NewArrays |= VERT_BIT_GENERIC(index);
Brian Paul45453d82012-02-19 19:50:31 -0700712 }
Brian Pauld3f598a2010-05-25 21:42:13 -0600713}
714
715
716/**
717 * Return info for a vertex attribute array (no alias with legacy
718 * vertex attributes (pos, normal, color, etc)). This function does
719 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
720 */
721static GLuint
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400722get_vertex_array_attrib(struct gl_context *ctx, GLuint index, GLenum pname,
Brian Pauld3f598a2010-05-25 21:42:13 -0600723 const char *caller)
724{
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200725 const struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
726 const struct gl_vertex_attrib_array *array;
Brian Pauld3f598a2010-05-25 21:42:13 -0600727
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800728 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
Brian Pauld3f598a2010-05-25 21:42:13 -0600729 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", caller, index);
730 return 0;
731 }
732
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200733 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(arrayObj->VertexAttrib));
Brian Pauld3f598a2010-05-25 21:42:13 -0600734
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200735 array = &arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)];
Brian Pauld3f598a2010-05-25 21:42:13 -0600736
737 switch (pname) {
738 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
739 return array->Enabled;
740 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
741 return array->Size;
742 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
743 return array->Stride;
744 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
745 return array->Type;
746 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
747 return array->Normalized;
748 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200749 return arrayObj->VertexBinding[array->VertexBinding].BufferObj->Name;
Brian Pauld1184d22010-10-28 21:17:41 -0600750 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
Ian Romanick2c870302012-07-25 16:21:49 -0700751 if ((_mesa_is_desktop_gl(ctx)
752 && (ctx->Version >= 30 || ctx->Extensions.EXT_gpu_shader4))
753 || _mesa_is_gles3(ctx)) {
Brian Pauld1184d22010-10-28 21:17:41 -0600754 return array->Integer;
755 }
Brian Paul1d1eb952011-01-15 10:32:34 -0700756 goto error;
757 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB:
Ian Romanick2c870302012-07-25 16:21:49 -0700758 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_instanced_arrays)
759 || _mesa_is_gles3(ctx)) {
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200760 return arrayObj->VertexBinding[array->VertexBinding].InstanceDivisor;
Brian Paul1d1eb952011-01-15 10:32:34 -0700761 }
762 goto error;
Fredrik Höglundfb370f82013-04-04 22:15:13 +0200763 case GL_VERTEX_ATTRIB_BINDING:
764 if (_mesa_is_desktop_gl(ctx)) {
765 return array->VertexBinding - VERT_ATTRIB_GENERIC0;
766 }
767 goto error;
768 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET:
769 if (_mesa_is_desktop_gl(ctx)) {
770 return array->RelativeOffset;
771 }
772 goto error;
Brian Pauld3f598a2010-05-25 21:42:13 -0600773 default:
Brian Paul1d1eb952011-01-15 10:32:34 -0700774 ; /* fall-through */
Brian Pauld3f598a2010-05-25 21:42:13 -0600775 }
Brian Paul1d1eb952011-01-15 10:32:34 -0700776
777error:
778 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", caller, pname);
779 return 0;
Brian Pauld3f598a2010-05-25 21:42:13 -0600780}
781
782
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800783static const GLfloat *
784get_current_attrib(struct gl_context *ctx, GLuint index, const char *function)
785{
786 if (index == 0) {
Ian Romanick2c870302012-07-25 16:21:49 -0700787 /* In OpenGL 3.1 attribute 0 becomes non-magic, just like in OpenGL ES
788 * 2.0. Note that we cannot just check for API_OPENGL_CORE here because
789 * that will erroneously allow this usage in a 3.0 forward-compatible
790 * context too.
791 */
792 if ((ctx->API != API_OPENGL_CORE || ctx->Version < 31)
793 && ctx->API != API_OPENGLES2) {
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800794 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(index==0)", function);
795 return NULL;
796 }
797 }
798 else if (index >= ctx->Const.VertexProgram.MaxAttribs) {
799 _mesa_error(ctx, GL_INVALID_VALUE,
800 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function);
801 return NULL;
802 }
803
Fredrik Höglund12cbe992013-04-03 22:08:47 +0200804 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.ArrayObj->_VertexAttrib));
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100805
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800806 FLUSH_CURRENT(ctx, 0);
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100807 return ctx->Current.Attrib[VERT_ATTRIB_GENERIC(index)];
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800808}
809
Brian Pauld3f598a2010-05-25 21:42:13 -0600810void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800811_mesa_GetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
Brian Pauld3f598a2010-05-25 21:42:13 -0600812{
813 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600814
815 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800816 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribfv");
817 if (v != NULL) {
Brian Pauld3f598a2010-05-25 21:42:13 -0600818 COPY_4V(params, v);
819 }
820 }
821 else {
822 params[0] = (GLfloat) get_vertex_array_attrib(ctx, index, pname,
823 "glGetVertexAttribfv");
824 }
825}
826
827
828void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800829_mesa_GetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params)
Brian Pauld3f598a2010-05-25 21:42:13 -0600830{
831 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600832
833 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800834 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribdv");
835 if (v != NULL) {
Brian Pauld3f598a2010-05-25 21:42:13 -0600836 params[0] = (GLdouble) v[0];
837 params[1] = (GLdouble) v[1];
838 params[2] = (GLdouble) v[2];
839 params[3] = (GLdouble) v[3];
840 }
841 }
842 else {
843 params[0] = (GLdouble) get_vertex_array_attrib(ctx, index, pname,
844 "glGetVertexAttribdv");
845 }
846}
847
848
849void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800850_mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params)
Brian Pauld3f598a2010-05-25 21:42:13 -0600851{
852 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600853
854 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800855 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribiv");
856 if (v != NULL) {
Brian Pauld3f598a2010-05-25 21:42:13 -0600857 /* XXX should floats in[0,1] be scaled to full int range? */
858 params[0] = (GLint) v[0];
859 params[1] = (GLint) v[1];
860 params[2] = (GLint) v[2];
861 params[3] = (GLint) v[3];
862 }
863 }
864 else {
865 params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname,
866 "glGetVertexAttribiv");
867 }
868}
869
870
871/** GL 3.0 */
872void GLAPIENTRY
873_mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
874{
875 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600876
877 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
Kenneth Graunkec299f442012-11-07 20:29:40 -0800878 const GLint *v = (const GLint *)
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800879 get_current_attrib(ctx, index, "glGetVertexAttribIiv");
880 if (v != NULL) {
Kenneth Graunkec299f442012-11-07 20:29:40 -0800881 COPY_4V(params, v);
Brian Pauld3f598a2010-05-25 21:42:13 -0600882 }
883 }
884 else {
885 params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname,
886 "glGetVertexAttribIiv");
887 }
888}
889
890
891/** GL 3.0 */
892void GLAPIENTRY
893_mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
894{
895 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600896
897 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
Kenneth Graunkec299f442012-11-07 20:29:40 -0800898 const GLuint *v = (const GLuint *)
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800899 get_current_attrib(ctx, index, "glGetVertexAttribIuiv");
900 if (v != NULL) {
Kenneth Graunkec299f442012-11-07 20:29:40 -0800901 COPY_4V(params, v);
Brian Pauld3f598a2010-05-25 21:42:13 -0600902 }
903 }
904 else {
905 params[0] = get_vertex_array_attrib(ctx, index, pname,
906 "glGetVertexAttribIuiv");
907 }
908}
909
910
911void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800912_mesa_GetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer)
Brian Pauld3f598a2010-05-25 21:42:13 -0600913{
914 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600915
916 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
917 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
918 return;
919 }
920
921 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
922 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
923 return;
924 }
925
Fredrik Höglund12cbe992013-04-03 22:08:47 +0200926 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.ArrayObj->_VertexAttrib));
Brian Pauld3f598a2010-05-25 21:42:13 -0600927
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200928 *pointer = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr;
Brian Pauld3f598a2010-05-25 21:42:13 -0600929}
930
931
932void GLAPIENTRY
Brian Paul1f0e2132000-06-12 15:30:51 +0000933_mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
934 GLsizei count, const GLvoid *ptr)
935{
936 (void) count;
937 _mesa_VertexPointer(size, type, stride, ptr);
938}
939
940
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000941void GLAPIENTRY
Brian Paul1f0e2132000-06-12 15:30:51 +0000942_mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
943 const GLvoid *ptr)
944{
945 (void) count;
946 _mesa_NormalPointer(type, stride, ptr);
947}
948
949
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000950void GLAPIENTRY
Brian Paul1f0e2132000-06-12 15:30:51 +0000951_mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
952 const GLvoid *ptr)
953{
954 (void) count;
955 _mesa_ColorPointer(size, type, stride, ptr);
956}
957
958
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000959void GLAPIENTRY
Brian Paul1f0e2132000-06-12 15:30:51 +0000960_mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
961 const GLvoid *ptr)
962{
963 (void) count;
964 _mesa_IndexPointer(type, stride, ptr);
965}
966
967
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000968void GLAPIENTRY
Brian Paul1f0e2132000-06-12 15:30:51 +0000969_mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
970 GLsizei count, const GLvoid *ptr)
971{
972 (void) count;
973 _mesa_TexCoordPointer(size, type, stride, ptr);
974}
975
976
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000977void GLAPIENTRY
Brian Paul1f0e2132000-06-12 15:30:51 +0000978_mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
979{
980 (void) count;
981 _mesa_EdgeFlagPointer(stride, ptr);
982}
983
984
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000985void GLAPIENTRY
Brian Paulfbd8f211999-11-11 01:22:25 +0000986_mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
jtgafb833d1999-08-19 00:55:39 +0000987{
Brian Paulfbd8f211999-11-11 01:22:25 +0000988 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000989 GLboolean tflag, cflag, nflag; /* enable/disable flags */
990 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
Keith Whitwellf4b02d12001-01-05 05:31:42 +0000991 GLenum ctype = 0; /* color type */
992 GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
Brian Paul4a3110f2003-12-12 18:40:02 +0000993 const GLint toffset = 0; /* always zero */
jtgafb833d1999-08-19 00:55:39 +0000994 GLint defstride; /* default stride */
995 GLint c, f;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000996
Eric Anholta9754792013-01-16 16:20:38 -0800997 FLUSH_VERTICES(ctx, 0);
Keith Whitwellcab974c2000-12-26 05:09:27 +0000998
jtgafb833d1999-08-19 00:55:39 +0000999 f = sizeof(GLfloat);
Brian Paulc5b1e812003-10-22 22:59:07 +00001000 c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
jtgafb833d1999-08-19 00:55:39 +00001001
Brian Paulc5b1e812003-10-22 22:59:07 +00001002 if (stride < 0) {
Brian Paul08836342001-03-03 20:33:27 +00001003 _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
jtgafb833d1999-08-19 00:55:39 +00001004 return;
1005 }
1006
1007 switch (format) {
1008 case GL_V2F:
1009 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1010 tcomps = 0; ccomps = 0; vcomps = 2;
1011 voffset = 0;
1012 defstride = 2*f;
1013 break;
1014 case GL_V3F:
1015 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1016 tcomps = 0; ccomps = 0; vcomps = 3;
1017 voffset = 0;
1018 defstride = 3*f;
1019 break;
1020 case GL_C4UB_V2F:
1021 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1022 tcomps = 0; ccomps = 4; vcomps = 2;
1023 ctype = GL_UNSIGNED_BYTE;
1024 coffset = 0;
1025 voffset = c;
1026 defstride = c + 2*f;
1027 break;
1028 case GL_C4UB_V3F:
1029 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1030 tcomps = 0; ccomps = 4; vcomps = 3;
1031 ctype = GL_UNSIGNED_BYTE;
1032 coffset = 0;
1033 voffset = c;
1034 defstride = c + 3*f;
1035 break;
1036 case GL_C3F_V3F:
1037 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1038 tcomps = 0; ccomps = 3; vcomps = 3;
1039 ctype = GL_FLOAT;
1040 coffset = 0;
1041 voffset = 3*f;
1042 defstride = 6*f;
1043 break;
1044 case GL_N3F_V3F:
1045 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
1046 tcomps = 0; ccomps = 0; vcomps = 3;
1047 noffset = 0;
1048 voffset = 3*f;
1049 defstride = 6*f;
1050 break;
1051 case GL_C4F_N3F_V3F:
1052 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
1053 tcomps = 0; ccomps = 4; vcomps = 3;
1054 ctype = GL_FLOAT;
1055 coffset = 0;
1056 noffset = 4*f;
1057 voffset = 7*f;
1058 defstride = 10*f;
1059 break;
1060 case GL_T2F_V3F:
1061 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1062 tcomps = 2; ccomps = 0; vcomps = 3;
1063 voffset = 2*f;
1064 defstride = 5*f;
1065 break;
1066 case GL_T4F_V4F:
1067 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1068 tcomps = 4; ccomps = 0; vcomps = 4;
1069 voffset = 4*f;
1070 defstride = 8*f;
1071 break;
1072 case GL_T2F_C4UB_V3F:
1073 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1074 tcomps = 2; ccomps = 4; vcomps = 3;
1075 ctype = GL_UNSIGNED_BYTE;
1076 coffset = 2*f;
1077 voffset = c+2*f;
1078 defstride = c+5*f;
1079 break;
1080 case GL_T2F_C3F_V3F:
1081 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1082 tcomps = 2; ccomps = 3; vcomps = 3;
1083 ctype = GL_FLOAT;
1084 coffset = 2*f;
1085 voffset = 5*f;
1086 defstride = 8*f;
1087 break;
1088 case GL_T2F_N3F_V3F:
1089 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
1090 tcomps = 2; ccomps = 0; vcomps = 3;
1091 noffset = 2*f;
1092 voffset = 5*f;
1093 defstride = 8*f;
1094 break;
1095 case GL_T2F_C4F_N3F_V3F:
1096 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1097 tcomps = 2; ccomps = 4; vcomps = 3;
1098 ctype = GL_FLOAT;
1099 coffset = 2*f;
1100 noffset = 6*f;
1101 voffset = 9*f;
1102 defstride = 12*f;
1103 break;
1104 case GL_T4F_C4F_N3F_V4F:
1105 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1106 tcomps = 4; ccomps = 4; vcomps = 4;
1107 ctype = GL_FLOAT;
1108 coffset = 4*f;
1109 noffset = 8*f;
1110 voffset = 11*f;
1111 defstride = 15*f;
1112 break;
1113 default:
Brian Paul08836342001-03-03 20:33:27 +00001114 _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
jtgafb833d1999-08-19 00:55:39 +00001115 return;
1116 }
1117
1118 if (stride==0) {
1119 stride = defstride;
1120 }
1121
Brian Paulfbd8f211999-11-11 01:22:25 +00001122 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
1123 _mesa_DisableClientState( GL_INDEX_ARRAY );
Brian Paul095c6692006-04-25 00:21:32 +00001124 /* XXX also disable secondary color and generic arrays? */
jtgafb833d1999-08-19 00:55:39 +00001125
1126 /* Texcoords */
jtgafb833d1999-08-19 00:55:39 +00001127 if (tflag) {
Brian Paul4a3110f2003-12-12 18:40:02 +00001128 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
1129 _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
Brian Paulab928e52004-03-10 16:17:35 +00001130 (GLubyte *) pointer + toffset );
jtgafb833d1999-08-19 00:55:39 +00001131 }
1132 else {
Brian Paulab928e52004-03-10 16:17:35 +00001133 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
jtgafb833d1999-08-19 00:55:39 +00001134 }
jtgafb833d1999-08-19 00:55:39 +00001135
1136 /* Color */
1137 if (cflag) {
Brian Paulfbd8f211999-11-11 01:22:25 +00001138 _mesa_EnableClientState( GL_COLOR_ARRAY );
Keith Whitwellcab974c2000-12-26 05:09:27 +00001139 _mesa_ColorPointer( ccomps, ctype, stride,
Brian Paul4a3110f2003-12-12 18:40:02 +00001140 (GLubyte *) pointer + coffset );
jtgafb833d1999-08-19 00:55:39 +00001141 }
1142 else {
Brian Paulfbd8f211999-11-11 01:22:25 +00001143 _mesa_DisableClientState( GL_COLOR_ARRAY );
jtgafb833d1999-08-19 00:55:39 +00001144 }
1145
1146
1147 /* Normals */
1148 if (nflag) {
Brian Paulfbd8f211999-11-11 01:22:25 +00001149 _mesa_EnableClientState( GL_NORMAL_ARRAY );
Brian Paul4a3110f2003-12-12 18:40:02 +00001150 _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset );
jtgafb833d1999-08-19 00:55:39 +00001151 }
1152 else {
Brian Paulfbd8f211999-11-11 01:22:25 +00001153 _mesa_DisableClientState( GL_NORMAL_ARRAY );
jtgafb833d1999-08-19 00:55:39 +00001154 }
1155
Brian Paul4a3110f2003-12-12 18:40:02 +00001156 /* Vertices */
Brian Paulfbd8f211999-11-11 01:22:25 +00001157 _mesa_EnableClientState( GL_VERTEX_ARRAY );
Keith Whitwellcab974c2000-12-26 05:09:27 +00001158 _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
1159 (GLubyte *) pointer + voffset );
jtgafb833d1999-08-19 00:55:39 +00001160}
1161
1162
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001163void GLAPIENTRY
Keith Whitwellad2ac212000-11-24 10:25:05 +00001164_mesa_LockArraysEXT(GLint first, GLsizei count)
1165{
1166 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -08001167
1168 FLUSH_VERTICES(ctx, 0);
Keith Whitwellad2ac212000-11-24 10:25:05 +00001169
1170 if (MESA_VERBOSE & VERBOSE_API)
Brian Paul4753d602002-06-15 02:38:15 +00001171 _mesa_debug(ctx, "glLockArrays %d %d\n", first, count);
Keith Whitwellad2ac212000-11-24 10:25:05 +00001172
Eric Anholt5857e982008-02-02 02:54:13 -08001173 if (first < 0) {
1174 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" );
1175 return;
Gareth Hughes22144ab2001-03-12 00:48:37 +00001176 }
Eric Anholt5857e982008-02-02 02:54:13 -08001177 if (count <= 0) {
1178 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" );
1179 return;
Keith Whitwellad2ac212000-11-24 10:25:05 +00001180 }
Eric Anholt5857e982008-02-02 02:54:13 -08001181 if (ctx->Array.LockCount != 0) {
1182 _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" );
1183 return;
1184 }
1185
1186 ctx->Array.LockFirst = first;
1187 ctx->Array.LockCount = count;
Keith Whitwellad2ac212000-11-24 10:25:05 +00001188
1189 ctx->NewState |= _NEW_ARRAY;
Keith Whitwellad2ac212000-11-24 10:25:05 +00001190}
1191
1192
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001193void GLAPIENTRY
Keith Whitwellad2ac212000-11-24 10:25:05 +00001194_mesa_UnlockArraysEXT( void )
1195{
1196 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -08001197
1198 FLUSH_VERTICES(ctx, 0);
Keith Whitwellad2ac212000-11-24 10:25:05 +00001199
1200 if (MESA_VERBOSE & VERBOSE_API)
Brian Paul4753d602002-06-15 02:38:15 +00001201 _mesa_debug(ctx, "glUnlockArrays\n");
Keith Whitwellad2ac212000-11-24 10:25:05 +00001202
Eric Anholt5857e982008-02-02 02:54:13 -08001203 if (ctx->Array.LockCount == 0) {
1204 _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" );
1205 return;
1206 }
1207
Keith Whitwellad2ac212000-11-24 10:25:05 +00001208 ctx->Array.LockFirst = 0;
1209 ctx->Array.LockCount = 0;
1210 ctx->NewState |= _NEW_ARRAY;
Keith Whitwellad2ac212000-11-24 10:25:05 +00001211}
Brian Paul2525bc72002-06-30 15:47:00 +00001212
1213
Brian Paul2525bc72002-06-30 15:47:00 +00001214/* GL_EXT_multi_draw_arrays */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001215void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -08001216_mesa_MultiDrawArrays( GLenum mode, const GLint *first,
Brian Paul79938322010-09-14 09:37:35 -06001217 const GLsizei *count, GLsizei primcount )
Brian Paul2525bc72002-06-30 15:47:00 +00001218{
1219 GET_CURRENT_CONTEXT(ctx);
1220 GLint i;
1221
Eric Anholta9754792013-01-16 16:20:38 -08001222 FLUSH_VERTICES(ctx, 0);
Brian Paul2525bc72002-06-30 15:47:00 +00001223
1224 for (i = 0; i < primcount; i++) {
1225 if (count[i] > 0) {
Ian Romanick9bdfee32005-07-18 12:31:24 +00001226 CALL_DrawArrays(ctx->Exec, (mode, first[i], count[i]));
Brian Paul2525bc72002-06-30 15:47:00 +00001227 }
1228 }
1229}
1230
1231
Ian Romanick3baefe62003-08-22 23:28:03 +00001232/* GL_IBM_multimode_draw_arrays */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001233void GLAPIENTRY
Ian Romanick3baefe62003-08-22 23:28:03 +00001234_mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
1235 const GLsizei * count,
1236 GLsizei primcount, GLint modestride )
1237{
1238 GET_CURRENT_CONTEXT(ctx);
1239 GLint i;
1240
Eric Anholta9754792013-01-16 16:20:38 -08001241 FLUSH_VERTICES(ctx, 0);
Ian Romanick3baefe62003-08-22 23:28:03 +00001242
1243 for ( i = 0 ; i < primcount ; i++ ) {
1244 if ( count[i] > 0 ) {
Brian Paul03e29a52003-12-04 03:16:27 +00001245 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
Ian Romanick9bdfee32005-07-18 12:31:24 +00001246 CALL_DrawArrays(ctx->Exec, ( m, first[i], count[i] ));
Ian Romanick3baefe62003-08-22 23:28:03 +00001247 }
1248 }
1249}
1250
1251
1252/* GL_IBM_multimode_draw_arrays */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001253void GLAPIENTRY
Ian Romanick3baefe62003-08-22 23:28:03 +00001254_mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
1255 GLenum type, const GLvoid * const * indices,
1256 GLsizei primcount, GLint modestride )
1257{
1258 GET_CURRENT_CONTEXT(ctx);
1259 GLint i;
1260
Eric Anholta9754792013-01-16 16:20:38 -08001261 FLUSH_VERTICES(ctx, 0);
Ian Romanick3baefe62003-08-22 23:28:03 +00001262
Brian Pauld2afb392003-09-17 18:15:13 +00001263 /* XXX not sure about ARB_vertex_buffer_object handling here */
1264
Ian Romanick3baefe62003-08-22 23:28:03 +00001265 for ( i = 0 ; i < primcount ; i++ ) {
1266 if ( count[i] > 0 ) {
Brian Paul03e29a52003-12-04 03:16:27 +00001267 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
Ian Romanick9bdfee32005-07-18 12:31:24 +00001268 CALL_DrawElements(ctx->Exec, ( m, count[i], type, indices[i] ));
Ian Romanick3baefe62003-08-22 23:28:03 +00001269 }
1270 }
1271}
1272
1273
Brian Paul095c6692006-04-25 00:21:32 +00001274/**
Brian Paul7f26ad82010-10-21 19:03:38 -06001275 * GL_NV_primitive_restart and GL 3.1
Brian Paula40e6f22010-04-20 21:02:09 -06001276 */
1277void GLAPIENTRY
1278_mesa_PrimitiveRestartIndex(GLuint index)
1279{
1280 GET_CURRENT_CONTEXT(ctx);
1281
Eric Anholt9c1b4182012-07-26 14:43:56 -07001282 if (!ctx->Extensions.NV_primitive_restart && ctx->Version < 31) {
Brian Paul7f26ad82010-10-21 19:03:38 -06001283 _mesa_error(ctx, GL_INVALID_OPERATION, "glPrimitiveRestartIndexNV()");
Brian Paula40e6f22010-04-20 21:02:09 -06001284 return;
1285 }
1286
Kenneth Graunkee6efb902013-05-29 08:31:54 -07001287 if (ctx->Array.RestartIndex != index) {
Brian Pauld2003ee2012-02-19 19:50:32 -07001288 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
Kenneth Graunkee6efb902013-05-29 08:31:54 -07001289 ctx->Array.RestartIndex = index;
Brian Pauld2003ee2012-02-19 19:50:32 -07001290 }
Brian Paula40e6f22010-04-20 21:02:09 -06001291}
1292
1293
1294/**
Brian Paul1d1eb952011-01-15 10:32:34 -07001295 * See GL_ARB_instanced_arrays.
1296 * Note that the instance divisor only applies to generic arrays, not
1297 * the legacy vertex arrays.
1298 */
1299void GLAPIENTRY
1300_mesa_VertexAttribDivisor(GLuint index, GLuint divisor)
1301{
1302 GET_CURRENT_CONTEXT(ctx);
Brian Paul1d1eb952011-01-15 10:32:34 -07001303
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001304 const GLuint genericIndex = VERT_ATTRIB_GENERIC(index);
1305
Brian Paul1d1eb952011-01-15 10:32:34 -07001306 if (!ctx->Extensions.ARB_instanced_arrays) {
1307 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()");
1308 return;
1309 }
1310
1311 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
Matt Turnerae1f09b2012-11-13 13:05:03 -08001312 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribDivisor(index = %u)",
Brian Paul1d1eb952011-01-15 10:32:34 -07001313 index);
1314 return;
1315 }
1316
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001317 ASSERT(genericIndex < Elements(ctx->Array.ArrayObj->VertexAttrib));
Mathias Fröhlich762c9762011-10-31 22:23:51 +01001318
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001319 /* The ARB_vertex_attrib_binding spec says:
1320 *
1321 * "The command
1322 *
1323 * void VertexAttribDivisor(uint index, uint divisor);
1324 *
1325 * is equivalent to (assuming no errors are generated):
1326 *
1327 * VertexAttribBinding(index, index);
1328 * VertexBindingDivisor(index, divisor);"
1329 */
1330 vertex_attrib_binding(ctx, genericIndex, genericIndex);
1331 vertex_binding_divisor(ctx, genericIndex, divisor);
Brian Paul1d1eb952011-01-15 10:32:34 -07001332}
1333
1334
Kenneth Graunke959d0762013-05-29 08:07:01 -07001335unsigned
1336_mesa_primitive_restart_index(const struct gl_context *ctx, GLenum ib_type)
1337{
1338 /* From the OpenGL 4.3 core specification, page 302:
1339 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1340 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1341 * is used."
1342 */
1343 if (ctx->Array.PrimitiveRestartFixedIndex) {
1344 switch (ib_type) {
1345 case GL_UNSIGNED_BYTE:
1346 return 0xff;
1347 case GL_UNSIGNED_SHORT:
1348 return 0xffff;
1349 case GL_UNSIGNED_INT:
1350 return 0xffffffff;
1351 default:
1352 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1353 }
1354 }
1355
1356 return ctx->Array.RestartIndex;
1357}
1358
Brian Paul1d1eb952011-01-15 10:32:34 -07001359
1360/**
Fredrik Höglundbb2d02c2013-04-09 20:44:58 +02001361 * GL_ARB_vertex_attrib_binding
1362 */
1363void GLAPIENTRY
1364_mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
1365 GLsizei stride)
1366{
Fredrik Höglund193e8b42013-04-11 16:49:44 +02001367 GET_CURRENT_CONTEXT(ctx);
1368 const struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001369 struct gl_buffer_object *vbo;
1370
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001371 ASSERT_OUTSIDE_BEGIN_END(ctx);
1372
1373 /* The ARB_vertex_attrib_binding spec says:
1374 *
1375 * "An INVALID_OPERATION error is generated if no vertex array object
1376 * is bound."
1377 */
1378 if (ctx->API == API_OPENGL_CORE &&
1379 ctx->Array.ArrayObj == ctx->Array.DefaultArrayObj) {
1380 _mesa_error(ctx, GL_INVALID_OPERATION,
1381 "glBindVertexBuffer(No array object bound)");
1382 return;
1383 }
1384
1385 /* The ARB_vertex_attrib_binding spec says:
1386 *
1387 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1388 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1389 */
1390 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
1391 _mesa_error(ctx, GL_INVALID_VALUE,
1392 "glBindVertexBuffer(bindingindex=%u > "
1393 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1394 bindingIndex);
1395 return;
1396 }
1397
1398 /* The ARB_vertex_attrib_binding spec says:
1399 *
1400 * "The error INVALID_VALUE is generated if <stride> or <offset>
1401 * are negative."
1402 */
1403 if (offset < 0) {
1404 _mesa_error(ctx, GL_INVALID_VALUE,
1405 "glBindVertexBuffer(offset=%lld < 0)", (long long)offset);
1406 return;
1407 }
1408
1409 if (stride < 0) {
1410 _mesa_error(ctx, GL_INVALID_VALUE,
1411 "glBindVertexBuffer(stride=%d < 0)", stride);
1412 return;
1413 }
1414
Fredrik Höglund193e8b42013-04-11 16:49:44 +02001415 if (buffer == arrayObj->VertexBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj->Name) {
1416 vbo = arrayObj->VertexBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj;
1417 } else if (buffer != 0) {
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001418 vbo = _mesa_lookup_bufferobj(ctx, buffer);
1419
1420 /* From the GL_ARB_vertex_attrib_array spec:
1421 *
1422 * "[Core profile only:]
1423 * An INVALID_OPERATION error is generated if buffer is not zero or a
1424 * name returned from a previous call to GenBuffers, or if such a name
1425 * has since been deleted with DeleteBuffers.
1426 *
1427 * Otherwise, we fall back to the same compat profile behavior as other
1428 * object references (automatically gen it).
1429 */
1430 if (!_mesa_handle_bind_buffer_gen(ctx, GL_ARRAY_BUFFER, buffer,
1431 &vbo, "glBindVertexBuffer"))
1432 return;
1433 } else {
1434 /* The ARB_vertex_attrib_binding spec says:
1435 *
1436 * "If <buffer> is zero, any buffer object attached to this
1437 * bindpoint is detached."
1438 */
1439 vbo = ctx->Shared->NullBufferObj;
1440 }
1441
1442 bind_vertex_buffer(ctx, VERT_ATTRIB_GENERIC(bindingIndex),
1443 vbo, offset, stride);
Fredrik Höglundbb2d02c2013-04-09 20:44:58 +02001444}
1445
1446
1447void GLAPIENTRY
1448_mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type,
1449 GLboolean normalized, GLuint relativeOffset)
1450{
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001451 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
1452 SHORT_BIT | UNSIGNED_SHORT_BIT |
1453 INT_BIT | UNSIGNED_INT_BIT |
1454 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
1455 FIXED_GL_BIT |
1456 UNSIGNED_INT_2_10_10_10_REV_BIT |
Chris Forbes1f092a92013-11-07 22:02:24 +13001457 INT_2_10_10_10_REV_BIT |
1458 UNSIGNED_INT_10F_11F_11F_REV_BIT);
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001459
1460 GET_CURRENT_CONTEXT(ctx);
1461 ASSERT_OUTSIDE_BEGIN_END(ctx);
1462
1463 /* The ARB_vertex_attrib_binding spec says:
1464 *
1465 * "An INVALID_OPERATION error is generated under any of the following
1466 * conditions:
1467 * - if no vertex array object is currently bound (see section 2.10);
1468 * - ..."
1469 */
1470 if (ctx->API == API_OPENGL_CORE &&
1471 ctx->Array.ArrayObj == ctx->Array.DefaultArrayObj) {
1472 _mesa_error(ctx, GL_INVALID_OPERATION,
1473 "glVertexAttribFormat(No array object bound)");
1474 return;
1475 }
1476
1477 /* The ARB_vertex_attrib_binding spec says:
1478 *
1479 * "The error INVALID_VALUE is generated if index is greater than or equal
1480 * to the value of MAX_VERTEX_ATTRIBS."
1481 */
1482 if (attribIndex >= ctx->Const.VertexProgram.MaxAttribs) {
1483 _mesa_error(ctx, GL_INVALID_VALUE,
1484 "glVertexAttribFormat(attribindex=%u > "
1485 "GL_MAX_VERTEX_ATTRIBS)",
1486 attribIndex);
1487 return;
1488 }
1489
1490 FLUSH_VERTICES(ctx, 0);
1491
1492 update_array_format(ctx, "glVertexAttribFormat",
1493 VERT_ATTRIB_GENERIC(attribIndex),
1494 legalTypes, 1, BGRA_OR_4, size, type, normalized,
1495 GL_FALSE, relativeOffset);
Fredrik Höglundbb2d02c2013-04-09 20:44:58 +02001496}
1497
1498
1499void GLAPIENTRY
1500_mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type,
1501 GLuint relativeOffset)
1502{
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001503 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
1504 SHORT_BIT | UNSIGNED_SHORT_BIT |
1505 INT_BIT | UNSIGNED_INT_BIT);
1506
1507 GET_CURRENT_CONTEXT(ctx);
1508 ASSERT_OUTSIDE_BEGIN_END(ctx);
1509
1510 /* The ARB_vertex_attrib_binding spec says:
1511 *
1512 * "An INVALID_OPERATION error is generated under any of the following
1513 * conditions:
1514 * - if no vertex array object is currently bound (see section 2.10);
1515 * - ..."
1516 */
1517 if (ctx->API == API_OPENGL_CORE &&
1518 ctx->Array.ArrayObj == ctx->Array.DefaultArrayObj) {
1519 _mesa_error(ctx, GL_INVALID_OPERATION,
1520 "glVertexAttribIFormat(No array object bound)");
1521 return;
1522 }
1523
1524 /* The ARB_vertex_attrib_binding spec says:
1525 *
1526 * "The error INVALID_VALUE is generated if index is greater than
1527 * or equal to the value of MAX_VERTEX_ATTRIBS."
1528 */
1529 if (attribIndex >= ctx->Const.VertexProgram.MaxAttribs) {
1530 _mesa_error(ctx, GL_INVALID_VALUE,
1531 "glVertexAttribIFormat(attribindex=%u > "
1532 "GL_MAX_VERTEX_ATTRIBS)",
1533 attribIndex);
1534 return;
1535 }
1536
1537 FLUSH_VERTICES(ctx, 0);
1538
1539 update_array_format(ctx, "glVertexAttribIFormat",
1540 VERT_ATTRIB_GENERIC(attribIndex),
1541 legalTypes, 1, 4, size, type, GL_FALSE, GL_TRUE,
1542 relativeOffset);
Fredrik Höglundbb2d02c2013-04-09 20:44:58 +02001543}
1544
1545
1546void GLAPIENTRY
1547_mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type,
1548 GLuint relativeOffset)
1549{
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001550 const GLbitfield legalTypes = DOUBLE_BIT;
1551
1552 GET_CURRENT_CONTEXT(ctx);
1553 ASSERT_OUTSIDE_BEGIN_END(ctx);
1554
1555 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
1556 *
1557 * "An INVALID_OPERATION error is generated under any of the following
1558 * conditions:
1559 * • if no vertex array object is currently bound (see section 10.4);
1560 * • ..."
1561 *
1562 * This language is missing from the extension spec, but we assume
1563 * that this is an oversight.
1564 */
1565 if (ctx->API == API_OPENGL_CORE &&
1566 ctx->Array.ArrayObj == ctx->Array.DefaultArrayObj) {
1567 _mesa_error(ctx, GL_INVALID_OPERATION,
1568 "glVertexAttribLFormat(No array object bound)");
1569 return;
1570 }
1571
1572 /* The ARB_vertex_attrib_binding spec says:
1573 *
1574 * "The error INVALID_VALUE is generated if <attribindex> is greater than
1575 * or equal to the value of MAX_VERTEX_ATTRIBS."
1576 */
1577 if (attribIndex >= ctx->Const.VertexProgram.MaxAttribs) {
1578 _mesa_error(ctx, GL_INVALID_VALUE,
1579 "glVertexAttribLFormat(attribindex=%u > "
1580 "GL_MAX_VERTEX_ATTRIBS)",
1581 attribIndex);
1582 return;
1583 }
1584
1585 FLUSH_VERTICES(ctx, 0);
1586
1587 update_array_format(ctx, "glVertexAttribLFormat",
1588 VERT_ATTRIB_GENERIC(attribIndex),
1589 legalTypes, 1, 4, size, type, GL_FALSE, GL_FALSE,
1590 relativeOffset);
Fredrik Höglundbb2d02c2013-04-09 20:44:58 +02001591}
1592
1593
1594void GLAPIENTRY
1595_mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
1596{
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001597 GET_CURRENT_CONTEXT(ctx);
1598 ASSERT_OUTSIDE_BEGIN_END(ctx);
1599
1600 /* The ARB_vertex_attrib_binding spec says:
1601 *
1602 * "An INVALID_OPERATION error is generated if no vertex array object
1603 * is bound."
1604 */
1605 if (ctx->API == API_OPENGL_CORE &&
1606 ctx->Array.ArrayObj == ctx->Array.DefaultArrayObj) {
1607 _mesa_error(ctx, GL_INVALID_OPERATION,
1608 "glVertexAttribBinding(No array object bound)");
1609 return;
1610 }
1611
1612 /* The ARB_vertex_attrib_binding spec says:
1613 *
1614 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
1615 * <bindingindex> must be less than the value of
1616 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
1617 * is generated."
1618 */
1619 if (attribIndex >= ctx->Const.VertexProgram.MaxAttribs) {
1620 _mesa_error(ctx, GL_INVALID_VALUE,
1621 "glVertexAttribBinding(attribindex=%u >= "
1622 "GL_MAX_VERTEX_ATTRIBS)",
1623 attribIndex);
1624 return;
1625 }
1626
1627 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
1628 _mesa_error(ctx, GL_INVALID_VALUE,
1629 "glVertexAttribBinding(bindingindex=%u >= "
1630 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1631 bindingIndex);
1632 return;
1633 }
1634
1635 ASSERT(VERT_ATTRIB_GENERIC(attribIndex) <
1636 Elements(ctx->Array.ArrayObj->VertexAttrib));
1637
1638 vertex_attrib_binding(ctx, VERT_ATTRIB_GENERIC(attribIndex),
1639 VERT_ATTRIB_GENERIC(bindingIndex));
Fredrik Höglundbb2d02c2013-04-09 20:44:58 +02001640}
1641
1642
1643void GLAPIENTRY
1644_mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
1645{
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001646 GET_CURRENT_CONTEXT(ctx);
1647 ASSERT_OUTSIDE_BEGIN_END(ctx);
1648
1649 if (!ctx->Extensions.ARB_instanced_arrays) {
1650 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexBindingDivisor()");
1651 return;
1652 }
1653
1654 /* The ARB_vertex_attrib_binding spec says:
1655 *
1656 * "An INVALID_OPERATION error is generated if no vertex array object
1657 * is bound."
1658 */
1659 if (ctx->API == API_OPENGL_CORE &&
1660 ctx->Array.ArrayObj == ctx->Array.DefaultArrayObj) {
1661 _mesa_error(ctx, GL_INVALID_OPERATION,
1662 "glVertexBindingDivisor(No array object bound)");
1663 return;
1664 }
1665
1666 /* The ARB_vertex_attrib_binding spec says:
1667 *
1668 * "An INVALID_VALUE error is generated if <bindingindex> is greater
1669 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
1670 */
1671 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
1672 _mesa_error(ctx, GL_INVALID_VALUE,
1673 "glVertexBindingDivisor(bindingindex=%u > "
1674 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1675 bindingIndex);
1676 return;
1677 }
1678
1679 vertex_binding_divisor(ctx, VERT_ATTRIB_GENERIC(bindingIndex), divisor);
Fredrik Höglundbb2d02c2013-04-09 20:44:58 +02001680}
1681
1682
1683/**
Brian Paulb2885402009-08-06 13:53:06 -06001684 * Copy one client vertex array to another.
1685 */
1686void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -04001687_mesa_copy_client_array(struct gl_context *ctx,
Brian Paulb2885402009-08-06 13:53:06 -06001688 struct gl_client_array *dst,
1689 struct gl_client_array *src)
1690{
1691 dst->Size = src->Size;
1692 dst->Type = src->Type;
1693 dst->Format = src->Format;
1694 dst->Stride = src->Stride;
1695 dst->StrideB = src->StrideB;
1696 dst->Ptr = src->Ptr;
1697 dst->Enabled = src->Enabled;
1698 dst->Normalized = src->Normalized;
Brian Pauld1184d22010-10-28 21:17:41 -06001699 dst->Integer = src->Integer;
Brian Paul1d1eb952011-01-15 10:32:34 -07001700 dst->InstanceDivisor = src->InstanceDivisor;
Brian Paulb2885402009-08-06 13:53:06 -06001701 dst->_ElementSize = src->_ElementSize;
1702 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
1703 dst->_MaxElement = src->_MaxElement;
1704}
1705
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001706void
1707_mesa_copy_vertex_attrib_array(struct gl_context *ctx,
1708 struct gl_vertex_attrib_array *dst,
1709 const struct gl_vertex_attrib_array *src)
1710{
1711 dst->Size = src->Size;
1712 dst->Type = src->Type;
1713 dst->Format = src->Format;
1714 dst->VertexBinding = src->VertexBinding;
1715 dst->RelativeOffset = src->RelativeOffset;
1716 dst->Format = src->Format;
1717 dst->Integer = src->Integer;
1718 dst->Normalized = src->Normalized;
1719 dst->Ptr = src->Ptr;
1720 dst->Enabled = src->Enabled;
1721 dst->_ElementSize = src->_ElementSize;
1722}
Brian Paulb2885402009-08-06 13:53:06 -06001723
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001724void
1725_mesa_copy_vertex_buffer_binding(struct gl_context *ctx,
1726 struct gl_vertex_buffer_binding *dst,
1727 const struct gl_vertex_buffer_binding *src)
1728{
1729 dst->Offset = src->Offset;
1730 dst->Stride = src->Stride;
1731 dst->InstanceDivisor = src->InstanceDivisor;
1732 dst->_BoundArrays = src->_BoundArrays;
1733
1734 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
1735}
Brian Paulb2885402009-08-06 13:53:06 -06001736
1737/**
Brian Paul39d75242009-05-14 16:25:32 -06001738 * Print vertex array's fields.
1739 */
1740static void
1741print_array(const char *name, GLint index, const struct gl_client_array *array)
1742{
1743 if (index >= 0)
Kristian Høgsberg298be2b2010-02-19 12:32:24 -05001744 printf(" %s[%d]: ", name, index);
Brian Paul39d75242009-05-14 16:25:32 -06001745 else
Kristian Høgsberg298be2b2010-02-19 12:32:24 -05001746 printf(" %s: ", name);
Brian Paul4beea122010-07-14 14:36:25 -06001747 printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu), MaxElem=%u\n",
Kristian Høgsberg298be2b2010-02-19 12:32:24 -05001748 array->Ptr, array->Type, array->Size,
1749 array->_ElementSize, array->StrideB,
Brian Paul4beea122010-07-14 14:36:25 -06001750 array->BufferObj->Name, (unsigned long) array->BufferObj->Size,
Kristian Høgsberg298be2b2010-02-19 12:32:24 -05001751 array->_MaxElement);
Brian Paul39d75242009-05-14 16:25:32 -06001752}
1753
1754
1755/**
1756 * Print current vertex object/array info. For debug.
1757 */
1758void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -04001759_mesa_print_arrays(struct gl_context *ctx)
Brian Paul39d75242009-05-14 16:25:32 -06001760{
Brian Paul6a2211f2009-05-21 15:55:50 -06001761 struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
Brian Paul39d75242009-05-14 16:25:32 -06001762 GLuint i;
1763
Brian Paul8fe31342009-05-21 15:36:25 -06001764 _mesa_update_array_object_max_element(ctx, arrayObj);
1765
Kristian Høgsberg298be2b2010-02-19 12:32:24 -05001766 printf("Array Object %u\n", arrayObj->Name);
Fredrik Höglund12cbe992013-04-03 22:08:47 +02001767 if (arrayObj->_VertexAttrib[VERT_ATTRIB_POS].Enabled)
1768 print_array("Vertex", -1, &arrayObj->_VertexAttrib[VERT_ATTRIB_POS]);
1769 if (arrayObj->_VertexAttrib[VERT_ATTRIB_NORMAL].Enabled)
1770 print_array("Normal", -1, &arrayObj->_VertexAttrib[VERT_ATTRIB_NORMAL]);
1771 if (arrayObj->_VertexAttrib[VERT_ATTRIB_COLOR0].Enabled)
1772 print_array("Color", -1, &arrayObj->_VertexAttrib[VERT_ATTRIB_COLOR0]);
Mathias Fröhlich762c9762011-10-31 22:23:51 +01001773 for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++)
Fredrik Höglund12cbe992013-04-03 22:08:47 +02001774 if (arrayObj->_VertexAttrib[VERT_ATTRIB_TEX(i)].Enabled)
1775 print_array("TexCoord", i, &arrayObj->_VertexAttrib[VERT_ATTRIB_TEX(i)]);
Mathias Fröhlich762c9762011-10-31 22:23:51 +01001776 for (i = 0; i < VERT_ATTRIB_GENERIC_MAX; i++)
Fredrik Höglund12cbe992013-04-03 22:08:47 +02001777 if (arrayObj->_VertexAttrib[VERT_ATTRIB_GENERIC(i)].Enabled)
1778 print_array("Attrib", i, &arrayObj->_VertexAttrib[VERT_ATTRIB_GENERIC(i)]);
Kristian Høgsberg298be2b2010-02-19 12:32:24 -05001779 printf(" _MaxElement = %u\n", arrayObj->_MaxElement);
Brian Paul39d75242009-05-14 16:25:32 -06001780}
1781
1782
1783/**
Brian Paul095c6692006-04-25 00:21:32 +00001784 * Initialize vertex array state for given context.
1785 */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001786void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -04001787_mesa_init_varray(struct gl_context *ctx)
Keith Whitwell6dc85572003-07-17 13:43:59 +00001788{
Mathias Fröhlich86f53e62011-11-02 19:54:26 +01001789 ctx->Array.DefaultArrayObj = ctx->Driver.NewArrayObject(ctx, 0);
Brian Paul1030bf02009-05-07 13:52:26 -06001790 _mesa_reference_array_object(ctx, &ctx->Array.ArrayObj,
1791 ctx->Array.DefaultArrayObj);
Brian Paul095c6692006-04-25 00:21:32 +00001792 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
Brian Paul12cf98f2009-06-19 17:58:47 -06001793
1794 ctx->Array.Objects = _mesa_NewHashTable();
1795}
1796
1797
1798/**
1799 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
1800 */
1801static void
1802delete_arrayobj_cb(GLuint id, void *data, void *userData)
1803{
1804 struct gl_array_object *arrayObj = (struct gl_array_object *) data;
Kristian Høgsbergf9995b32010-10-12 12:26:10 -04001805 struct gl_context *ctx = (struct gl_context *) userData;
Brian Paul12cf98f2009-06-19 17:58:47 -06001806 _mesa_delete_array_object(ctx, arrayObj);
1807}
1808
1809
1810/**
1811 * Free vertex array state for given context.
1812 */
1813void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -04001814_mesa_free_varray_data(struct gl_context *ctx)
Brian Paul12cf98f2009-06-19 17:58:47 -06001815{
1816 _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx);
1817 _mesa_DeleteHashTable(ctx->Array.Objects);
Keith Whitwell6dc85572003-07-17 13:43:59 +00001818}