blob: b0e02865b1de965e8f6b954dc6b0e71ee6e0d43d [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
Brian Paul433e5e62010-10-28 21:17:42 -060063
64
65/** Convert GL datatype enum into a <type>_BIT value seen above */
66static GLbitfield
67type_to_bit(const struct gl_context *ctx, GLenum type)
68{
69 switch (type) {
70 case GL_BOOL:
71 return BOOL_BIT;
72 case GL_BYTE:
73 return BYTE_BIT;
74 case GL_UNSIGNED_BYTE:
75 return UNSIGNED_BYTE_BIT;
76 case GL_SHORT:
77 return SHORT_BIT;
78 case GL_UNSIGNED_SHORT:
79 return UNSIGNED_SHORT_BIT;
80 case GL_INT:
81 return INT_BIT;
82 case GL_UNSIGNED_INT:
83 return UNSIGNED_INT_BIT;
84 case GL_HALF_FLOAT:
85 if (ctx->Extensions.ARB_half_float_vertex)
86 return HALF_BIT;
87 else
88 return 0x0;
89 case GL_FLOAT:
90 return FLOAT_BIT;
91 case GL_DOUBLE:
92 return DOUBLE_BIT;
93 case GL_FIXED:
Jordan Justen09714c02012-07-19 11:27:16 -070094 return _mesa_is_desktop_gl(ctx) ? FIXED_GL_BIT : FIXED_ES_BIT;
Dave Airlie6cd2d552011-08-13 15:30:38 +010095 case GL_UNSIGNED_INT_2_10_10_10_REV:
96 return UNSIGNED_INT_2_10_10_10_REV_BIT;
97 case GL_INT_2_10_10_10_REV:
98 return INT_2_10_10_10_REV_BIT;
Brian Paul433e5e62010-10-28 21:17:42 -060099 default:
100 return 0;
101 }
102}
103
104
Brian Paulc5b1e812003-10-22 22:59:07 +0000105/**
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200106 * Sets the VertexBinding field in the vertex attribute given by attribIndex.
107 */
108static void
109vertex_attrib_binding(struct gl_context *ctx, GLuint attribIndex,
110 GLuint bindingIndex)
111{
112 struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
113 struct gl_vertex_attrib_array *array = &arrayObj->VertexAttrib[attribIndex];
114
115 if (array->VertexBinding != bindingIndex) {
116 const GLbitfield64 array_bit = VERT_BIT(attribIndex);
117
118 FLUSH_VERTICES(ctx, _NEW_ARRAY);
119
120 arrayObj->VertexBinding[array->VertexBinding]._BoundArrays &= ~array_bit;
121 arrayObj->VertexBinding[bindingIndex]._BoundArrays |= array_bit;
122
123 array->VertexBinding = bindingIndex;
124
125 arrayObj->NewArrays |= array_bit;
126 }
127}
128
129
130/**
131 * Binds a buffer object to the vertex buffer binding point given by index,
132 * and sets the Offset and Stride fields.
133 */
134static void
135bind_vertex_buffer(struct gl_context *ctx, GLuint index,
136 struct gl_buffer_object *vbo,
137 GLintptr offset, GLsizei stride)
138{
139 struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
140 struct gl_vertex_buffer_binding *binding = &arrayObj->VertexBinding[index];
141
142 if (binding->BufferObj != vbo ||
143 binding->Offset != offset ||
144 binding->Stride != stride) {
145
146 FLUSH_VERTICES(ctx, _NEW_ARRAY);
147
148 _mesa_reference_buffer_object(ctx, &binding->BufferObj, vbo);
149
150 binding->Offset = offset;
151 binding->Stride = stride;
152
153 arrayObj->NewArrays |= binding->_BoundArrays;
154 }
155}
156
157
158/**
159 * Sets the InstanceDivisor field in the vertex buffer binding point
160 * given by bindingIndex.
161 */
162static void
163vertex_binding_divisor(struct gl_context *ctx, GLuint bindingIndex,
164 GLuint divisor)
165{
166 struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
167 struct gl_vertex_buffer_binding *binding =
168 &arrayObj->VertexBinding[bindingIndex];
169
170 if (binding->InstanceDivisor != divisor) {
171 FLUSH_VERTICES(ctx, _NEW_ARRAY);
172 binding->InstanceDivisor = divisor;
173 arrayObj->NewArrays |= binding->_BoundArrays;
174 }
175}
176
177
178/**
Fredrik Höglundd5543212013-04-03 21:47:44 +0200179 * Does error checking and updates the format in an attrib array.
Brian Paulf9d88c82006-06-13 17:24:36 +0000180 *
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200181 * Called by update_array() and VertexAttrib*Format().
Fredrik Höglundd5543212013-04-03 21:47:44 +0200182 *
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200183 * \param func Name of calling function used for error reporting
184 * \param attrib The index of the attribute array
185 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
186 * \param sizeMin Min allowable size value
187 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
188 * \param size Components per element (1, 2, 3 or 4)
189 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
190 * \param normalized Whether integer types are converted to floats in [-1, 1]
191 * \param integer Integer-valued values (will not be normalized to [-1, 1])
192 * \param relativeOffset Offset of the first element relative to the binding offset.
Brian Paulc5b1e812003-10-22 22:59:07 +0000193 */
Fredrik Höglundd5543212013-04-03 21:47:44 +0200194static bool
195update_array_format(struct gl_context *ctx,
196 const char *func,
197 GLuint attrib, GLbitfield legalTypesMask,
198 GLint sizeMin, GLint sizeMax,
199 GLint size, GLenum type,
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200200 GLboolean normalized, GLboolean integer,
201 GLuint relativeOffset)
Brian Paulc5b1e812003-10-22 22:59:07 +0000202{
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200203 struct gl_vertex_attrib_array *array;
Brian Paul433e5e62010-10-28 21:17:42 -0600204 GLbitfield typeBit;
Fredrik Höglundd5543212013-04-03 21:47:44 +0200205 GLuint elementSize;
Brian Paul433e5e62010-10-28 21:17:42 -0600206 GLenum format = GL_RGBA;
207
Ian Romanickbbceed22012-07-25 14:40:18 -0700208 if (_mesa_is_gles(ctx)) {
Matt Turnerc8901132012-11-28 21:45:19 -0800209 legalTypesMask &= ~(FIXED_GL_BIT | DOUBLE_BIT);
Ian Romanickbbceed22012-07-25 14:40:18 -0700210
211 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
212 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
Matt Turnerc8901132012-11-28 21:45:19 -0800213 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
214 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
215 * quite as trivial as we'd like because it uses a different enum value
216 * for GL_HALF_FLOAT_OES.
Ian Romanickbbceed22012-07-25 14:40:18 -0700217 */
218 if (ctx->Version < 30) {
219 legalTypesMask &= ~(UNSIGNED_INT_BIT
220 | INT_BIT
221 | UNSIGNED_INT_2_10_10_10_REV_BIT
Matt Turnerc8901132012-11-28 21:45:19 -0800222 | INT_2_10_10_10_REV_BIT
223 | HALF_BIT);
Ian Romanickbbceed22012-07-25 14:40:18 -0700224 }
Ian Romanick946ddec2012-07-25 14:46:54 -0700225
226 /* BGRA ordering is not supported in ES contexts.
227 */
228 if (sizeMax == BGRA_OR_4)
229 sizeMax = 4;
Ian Romanickbbceed22012-07-25 14:40:18 -0700230 } else {
Marek Olšák0f1e59d2011-04-29 14:23:15 +0200231 legalTypesMask &= ~FIXED_ES_BIT;
Ian Romanickbbceed22012-07-25 14:40:18 -0700232
233 if (!ctx->Extensions.ARB_ES2_compatibility)
234 legalTypesMask &= ~FIXED_GL_BIT;
235
236 if (!ctx->Extensions.ARB_vertex_type_2_10_10_10_rev)
237 legalTypesMask &= ~(UNSIGNED_INT_2_10_10_10_REV_BIT |
238 INT_2_10_10_10_REV_BIT);
Dave Airlie6cd2d552011-08-13 15:30:38 +0100239 }
Brian Paul11dd2282010-11-07 18:35:35 -0700240
Brian Paul433e5e62010-10-28 21:17:42 -0600241 typeBit = type_to_bit(ctx, type);
242 if (typeBit == 0x0 || (typeBit & legalTypesMask) == 0x0) {
243 _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)",
244 func, _mesa_lookup_enum_by_nr(type));
Fredrik Höglundd5543212013-04-03 21:47:44 +0200245 return false;
Brian Paul433e5e62010-10-28 21:17:42 -0600246 }
247
248 /* Do size parameter checking.
249 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
250 * must be handled specially.
251 */
252 if (ctx->Extensions.EXT_vertex_array_bgra &&
253 sizeMax == BGRA_OR_4 &&
254 size == GL_BGRA) {
Fredrik Höglund0e7a61a2013-04-12 17:36:06 +0200255 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
256 *
257 * "An INVALID_OPERATION error is generated under any of the following
258 * conditions:
259 * ...
260 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
261 * or UNSIGNED_INT_2_10_10_10_REV;
262 * ...
263 * • size is BGRA and normalized is FALSE;"
264 */
Fredrik Höglundd5543212013-04-03 21:47:44 +0200265 bool bgra_error = false;
Dave Airlie99c1a582011-09-07 10:19:14 +0100266
267 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev) {
268 if (type != GL_UNSIGNED_INT_2_10_10_10_REV &&
269 type != GL_INT_2_10_10_10_REV &&
270 type != GL_UNSIGNED_BYTE)
Fredrik Höglundd5543212013-04-03 21:47:44 +0200271 bgra_error = true;
Dave Airlie99c1a582011-09-07 10:19:14 +0100272 } else if (type != GL_UNSIGNED_BYTE)
Fredrik Höglundd5543212013-04-03 21:47:44 +0200273 bgra_error = true;
Dave Airlie99c1a582011-09-07 10:19:14 +0100274
275 if (bgra_error) {
Fredrik Höglund0e7a61a2013-04-12 17:36:06 +0200276 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=GL_BGRA and type=%s)",
277 func, _mesa_lookup_enum_by_nr(type));
Fredrik Höglundd5543212013-04-03 21:47:44 +0200278 return false;
Brian Paul433e5e62010-10-28 21:17:42 -0600279 }
Fredrik Höglund0e7a61a2013-04-12 17:36:06 +0200280
281 if (!normalized) {
282 _mesa_error(ctx, GL_INVALID_OPERATION,
283 "%s(size=GL_BGRA and normalized=GL_FALSE)", func);
Fredrik Höglundd5543212013-04-03 21:47:44 +0200284 return false;
Fredrik Höglund0e7a61a2013-04-12 17:36:06 +0200285 }
286
Brian Paul433e5e62010-10-28 21:17:42 -0600287 format = GL_BGRA;
288 size = 4;
289 }
290 else if (size < sizeMin || size > sizeMax || size > 4) {
291 _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d)", func, size);
Fredrik Höglundd5543212013-04-03 21:47:44 +0200292 return false;
Brian Paul433e5e62010-10-28 21:17:42 -0600293 }
294
Dave Airlie6cd2d552011-08-13 15:30:38 +0100295 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev &&
296 (type == GL_UNSIGNED_INT_2_10_10_10_REV ||
297 type == GL_INT_2_10_10_10_REV) && size != 4) {
298 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size);
Fredrik Höglundd5543212013-04-03 21:47:44 +0200299 return false;
Dave Airlie6cd2d552011-08-13 15:30:38 +0100300 }
301
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200302 /* The ARB_vertex_attrib_binding_spec says:
303 *
304 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
305 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
306 */
307 if (relativeOffset > ctx->Const.MaxVertexAttribRelativeOffset) {
308 _mesa_error(ctx, GL_INVALID_VALUE,
309 "%s(relativeOffset=%d > "
310 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
311 func, relativeOffset);
312 return GL_FALSE;
313 }
314
Brian Paul433e5e62010-10-28 21:17:42 -0600315 ASSERT(size <= 4);
316
Fredrik Höglundd5543212013-04-03 21:47:44 +0200317 elementSize = _mesa_bytes_per_vertex_attrib(size, type);
318 assert(elementSize != -1);
319
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200320 array = &ctx->Array.ArrayObj->VertexAttrib[attrib];
Fredrik Höglundd5543212013-04-03 21:47:44 +0200321 array->Size = size;
322 array->Type = type;
323 array->Format = format;
324 array->Normalized = normalized;
325 array->Integer = integer;
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200326 array->RelativeOffset = relativeOffset;
Fredrik Höglundd5543212013-04-03 21:47:44 +0200327 array->_ElementSize = elementSize;
328
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200329 ctx->Array.ArrayObj->NewArrays |= VERT_BIT(attrib);
330 ctx->NewState |= _NEW_ARRAY;
331
Fredrik Höglundd5543212013-04-03 21:47:44 +0200332 return true;
333}
334
335
336/**
337 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
338 * functions.
339 *
340 * \param func name of calling function used for error reporting
341 * \param attrib the attribute array index to update
342 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
343 * \param sizeMin min allowable size value
344 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
345 * \param size components per element (1, 2, 3 or 4)
346 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
347 * \param stride stride between elements, in elements
348 * \param normalized are integer types converted to floats in [-1, 1]?
349 * \param integer integer-valued values (will not be normalized to [-1,1])
350 * \param ptr the address (or offset inside VBO) of the array data
351 */
352static void
353update_array(struct gl_context *ctx,
354 const char *func,
355 GLuint attrib, GLbitfield legalTypesMask,
356 GLint sizeMin, GLint sizeMax,
357 GLint size, GLenum type, GLsizei stride,
358 GLboolean normalized, GLboolean integer,
359 const GLvoid *ptr)
360{
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200361 struct gl_vertex_attrib_array *array;
362 GLsizei effectiveStride;
Fredrik Höglundd5543212013-04-03 21:47:44 +0200363
364 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
365 *
366 * "Client vertex arrays - all vertex array attribute pointers must
367 * refer to buffer objects (section 2.9.2). The default vertex array
368 * object (the name zero) is also deprecated. Calling
369 * VertexAttribPointer when no buffer object or no vertex array object
370 * is bound will generate an INVALID_OPERATION error..."
371 *
372 * The check for VBOs is handled below.
373 */
374 if (ctx->API == API_OPENGL_CORE
375 && (ctx->Array.ArrayObj == ctx->Array.DefaultArrayObj)) {
376 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(no array object bound)",
377 func);
378 return;
379 }
380
381 if (!update_array_format(ctx, func, attrib, legalTypesMask, sizeMin, sizeMax,
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200382 size, type, normalized, integer, 0)) {
Fredrik Höglundd5543212013-04-03 21:47:44 +0200383 return;
384 }
385
Brian Paul433e5e62010-10-28 21:17:42 -0600386 if (stride < 0) {
387 _mesa_error( ctx, GL_INVALID_VALUE, "%s(stride=%d)", func, stride );
388 return;
389 }
Brian Paule2b72492009-06-22 16:56:35 -0600390
Ian Romanick843b8762012-08-17 17:12:39 -0700391 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
392 *
393 * "An INVALID_OPERATION error is generated under any of the following
394 * conditions:
395 *
396 * ...
397 *
398 * * any of the *Pointer commands specifying the location and
399 * organization of vertex array data are called while zero is bound
400 * to the ARRAY_BUFFER buffer object binding point (see section
401 * 2.9.6), and the pointer argument is not NULL."
402 */
403 if (ptr != NULL && ctx->Array.ArrayObj->ARBsemantics &&
Brian Paulefcf5aa2011-11-29 07:44:20 -0700404 !_mesa_is_bufferobj(ctx->Array.ArrayBufferObj)) {
Brian Paul433e5e62010-10-28 21:17:42 -0600405 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-VBO array)", func);
Brian Paulf549f4c2009-11-12 23:04:26 -0700406 return;
Brian Paule2b72492009-06-22 16:56:35 -0600407 }
408
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200409 /* Reset the vertex attrib binding */
410 vertex_attrib_binding(ctx, attrib, attrib);
411
412 /* The Stride and Ptr fields are not set by update_array_format() */
413 array = &ctx->Array.ArrayObj->VertexAttrib[attrib];
Brian Paulc5b1e812003-10-22 22:59:07 +0000414 array->Stride = stride;
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200415 array->Ptr = (const GLvoid *) ptr;
Brian Paul0077c872009-05-06 13:00:35 -0600416
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200417 /* Update the vertex buffer binding */
418 effectiveStride = stride != 0 ? stride : array->_ElementSize;
419 bind_vertex_buffer(ctx, attrib, ctx->Array.ArrayBufferObj,
420 (GLintptr) ptr, effectiveStride);
Brian Paulc5b1e812003-10-22 22:59:07 +0000421}
422
423
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000424void GLAPIENTRY
Brian Paulfbd8f211999-11-11 01:22:25 +0000425_mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
jtgafb833d1999-08-19 00:55:39 +0000426{
Brian Paulfbd8f211999-11-11 01:22:25 +0000427 GET_CURRENT_CONTEXT(ctx);
Ian Romanicke2cf14d2012-07-25 15:19:31 -0700428 GLbitfield legalTypes = (ctx->API == API_OPENGLES)
429 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
430 : (SHORT_BIT | INT_BIT | FLOAT_BIT |
431 DOUBLE_BIT | HALF_BIT |
432 UNSIGNED_INT_2_10_10_10_REV_BIT |
433 INT_2_10_10_10_REV_BIT);
Eric Anholta9754792013-01-16 16:20:38 -0800434
435 FLUSH_VERTICES(ctx, 0);
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000436
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100437 update_array(ctx, "glVertexPointer", VERT_ATTRIB_POS,
Brian Paul433e5e62010-10-28 21:17:42 -0600438 legalTypes, 2, 4,
439 size, type, stride, GL_FALSE, GL_FALSE, ptr);
jtgafb833d1999-08-19 00:55:39 +0000440}
441
442
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000443void GLAPIENTRY
Brian Paulfbd8f211999-11-11 01:22:25 +0000444_mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
jtgafb833d1999-08-19 00:55:39 +0000445{
Brian Paulfbd8f211999-11-11 01:22:25 +0000446 GET_CURRENT_CONTEXT(ctx);
Ian Romanicke5ef0cb2012-07-25 15:10:21 -0700447 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
448 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
449 : (BYTE_BIT | SHORT_BIT | INT_BIT |
450 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
451 UNSIGNED_INT_2_10_10_10_REV_BIT |
452 INT_2_10_10_10_REV_BIT);
Eric Anholta9754792013-01-16 16:20:38 -0800453
454 FLUSH_VERTICES(ctx, 0);
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000455
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100456 update_array(ctx, "glNormalPointer", VERT_ATTRIB_NORMAL,
Brian Paul433e5e62010-10-28 21:17:42 -0600457 legalTypes, 3, 3,
458 3, type, stride, GL_TRUE, GL_FALSE, ptr);
jtgafb833d1999-08-19 00:55:39 +0000459}
460
461
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000462void GLAPIENTRY
Brian Paulfbd8f211999-11-11 01:22:25 +0000463_mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
jtgafb833d1999-08-19 00:55:39 +0000464{
Brian Paulfbd8f211999-11-11 01:22:25 +0000465 GET_CURRENT_CONTEXT(ctx);
Ian Romanick07ccfef2012-07-25 14:53:01 -0700466 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
467 ? (UNSIGNED_BYTE_BIT | HALF_BIT | FLOAT_BIT | FIXED_ES_BIT)
468 : (BYTE_BIT | UNSIGNED_BYTE_BIT |
469 SHORT_BIT | UNSIGNED_SHORT_BIT |
470 INT_BIT | UNSIGNED_INT_BIT |
471 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
472 UNSIGNED_INT_2_10_10_10_REV_BIT |
473 INT_2_10_10_10_REV_BIT);
Ian Romanickfb821852012-07-25 14:58:36 -0700474 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 4 : 3;
Eric Anholta9754792013-01-16 16:20:38 -0800475
476 FLUSH_VERTICES(ctx, 0);
Brian Paulfbd8f211999-11-11 01:22:25 +0000477
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100478 update_array(ctx, "glColorPointer", VERT_ATTRIB_COLOR0,
Ian Romanickfb821852012-07-25 14:58:36 -0700479 legalTypes, sizeMin, BGRA_OR_4,
Brian Paul433e5e62010-10-28 21:17:42 -0600480 size, type, stride, GL_TRUE, GL_FALSE, ptr);
jtgafb833d1999-08-19 00:55:39 +0000481}
482
483
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000484void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800485_mesa_FogCoordPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000486{
Brian Paul433e5e62010-10-28 21:17:42 -0600487 const GLbitfield legalTypes = (HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000488 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -0800489
490 FLUSH_VERTICES(ctx, 0);
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000491
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100492 update_array(ctx, "glFogCoordPointer", VERT_ATTRIB_FOG,
Brian Paul433e5e62010-10-28 21:17:42 -0600493 legalTypes, 1, 1,
494 1, type, stride, GL_FALSE, GL_FALSE, ptr);
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000495}
496
497
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000498void GLAPIENTRY
Brian Paulfbd8f211999-11-11 01:22:25 +0000499_mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
jtgafb833d1999-08-19 00:55:39 +0000500{
Brian Paul433e5e62010-10-28 21:17:42 -0600501 const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT | INT_BIT |
502 FLOAT_BIT | DOUBLE_BIT);
Brian Paulfbd8f211999-11-11 01:22:25 +0000503 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -0800504
505 FLUSH_VERTICES(ctx, 0);
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000506
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100507 update_array(ctx, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX,
Brian Paul433e5e62010-10-28 21:17:42 -0600508 legalTypes, 1, 1,
509 1, type, stride, GL_FALSE, GL_FALSE, ptr);
jtgafb833d1999-08-19 00:55:39 +0000510}
511
512
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000513void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800514_mesa_SecondaryColorPointer(GLint size, GLenum type,
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000515 GLsizei stride, const GLvoid *ptr)
516{
Brian Paul433e5e62010-10-28 21:17:42 -0600517 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
518 SHORT_BIT | UNSIGNED_SHORT_BIT |
519 INT_BIT | UNSIGNED_INT_BIT |
Dave Airlie6cd2d552011-08-13 15:30:38 +0100520 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
521 UNSIGNED_INT_2_10_10_10_REV_BIT |
522 INT_2_10_10_10_REV_BIT);
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000523 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -0800524
525 FLUSH_VERTICES(ctx, 0);
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000526
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100527 update_array(ctx, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1,
Brian Paul433e5e62010-10-28 21:17:42 -0600528 legalTypes, 3, BGRA_OR_4,
529 size, type, stride, GL_TRUE, GL_FALSE, ptr);
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000530}
531
532
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000533void GLAPIENTRY
Brian Paul2edd1802002-01-11 17:25:35 +0000534_mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
535 const GLvoid *ptr)
jtgafb833d1999-08-19 00:55:39 +0000536{
Brian Paulfbd8f211999-11-11 01:22:25 +0000537 GET_CURRENT_CONTEXT(ctx);
Ian Romanickc3e9a202012-07-25 15:13:00 -0700538 GLbitfield legalTypes = (ctx->API == API_OPENGLES)
539 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
540 : (SHORT_BIT | INT_BIT |
541 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
542 UNSIGNED_INT_2_10_10_10_REV_BIT |
543 INT_2_10_10_10_REV_BIT);
Ian Romanicka8f475d2012-07-25 15:13:51 -0700544 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 2 : 1;
Brian Paulc5b1e812003-10-22 22:59:07 +0000545 const GLuint unit = ctx->Array.ActiveTexture;
Eric Anholta9754792013-01-16 16:20:38 -0800546
547 FLUSH_VERTICES(ctx, 0);
jtgafb833d1999-08-19 00:55:39 +0000548
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100549 update_array(ctx, "glTexCoordPointer", VERT_ATTRIB_TEX(unit),
Ian Romanicka8f475d2012-07-25 15:13:51 -0700550 legalTypes, sizeMin, 4,
Brian Paul433e5e62010-10-28 21:17:42 -0600551 size, type, stride, GL_FALSE, GL_FALSE,
Brian Pauld1184d22010-10-28 21:17:41 -0600552 ptr);
jtgafb833d1999-08-19 00:55:39 +0000553}
554
555
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000556void GLAPIENTRY
Brian Paulc5b1e812003-10-22 22:59:07 +0000557_mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr)
jtgafb833d1999-08-19 00:55:39 +0000558{
Brian Paulee1f0472010-11-02 08:22:40 -0600559 const GLbitfield legalTypes = UNSIGNED_BYTE_BIT;
Brian Pauld1184d22010-10-28 21:17:41 -0600560 /* see table 2.4 edits in GL_EXT_gpu_shader4 spec: */
561 const GLboolean integer = GL_TRUE;
Brian Paulfbd8f211999-11-11 01:22:25 +0000562 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -0800563
564 FLUSH_VERTICES(ctx, 0);
jtgafb833d1999-08-19 00:55:39 +0000565
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100566 update_array(ctx, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG,
Brian Paul433e5e62010-10-28 21:17:42 -0600567 legalTypes, 1, 1,
Brian Paulee1f0472010-11-02 08:22:40 -0600568 1, GL_UNSIGNED_BYTE, stride, GL_FALSE, integer, ptr);
jtgafb833d1999-08-19 00:55:39 +0000569}
570
571
Brian Paul1cf2c8a2008-06-25 08:45:14 -0600572void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800573_mesa_PointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *ptr)
Brian Paul1cf2c8a2008-06-25 08:45:14 -0600574{
Marek Olšák0f1e59d2011-04-29 14:23:15 +0200575 const GLbitfield legalTypes = (FLOAT_BIT | FIXED_ES_BIT);
Brian Paul1cf2c8a2008-06-25 08:45:14 -0600576 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -0800577
578 FLUSH_VERTICES(ctx, 0);
Brian Paul1cf2c8a2008-06-25 08:45:14 -0600579
Brian Paul11dd2282010-11-07 18:35:35 -0700580 if (ctx->API != API_OPENGLES) {
581 _mesa_error(ctx, GL_INVALID_OPERATION,
582 "glPointSizePointer(ES 1.x only)");
583 return;
584 }
585
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100586 update_array(ctx, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE,
Brian Paul433e5e62010-10-28 21:17:42 -0600587 legalTypes, 1, 1,
588 1, type, stride, GL_FALSE, GL_FALSE, ptr);
Brian Paul1cf2c8a2008-06-25 08:45:14 -0600589}
590
591
Brian Paula554d7c2009-05-21 15:55:33 -0600592/**
Brian Paula554d7c2009-05-21 15:55:33 -0600593 * Set a generic vertex attribute array.
594 * Note that these arrays DO NOT alias the conventional GL vertex arrays
595 * (position, normal, color, fog, texcoord, etc).
596 */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000597void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800598_mesa_VertexAttribPointer(GLuint index, GLint size, GLenum type,
Brian Paul92f97852003-05-01 22:44:02 +0000599 GLboolean normalized,
600 GLsizei stride, const GLvoid *ptr)
601{
Brian Paul433e5e62010-10-28 21:17:42 -0600602 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
603 SHORT_BIT | UNSIGNED_SHORT_BIT |
604 INT_BIT | UNSIGNED_INT_BIT |
605 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
Dave Airlie6cd2d552011-08-13 15:30:38 +0100606 FIXED_ES_BIT | FIXED_GL_BIT |
607 UNSIGNED_INT_2_10_10_10_REV_BIT |
608 INT_2_10_10_10_REV_BIT);
Brian Paul92f97852003-05-01 22:44:02 +0000609 GET_CURRENT_CONTEXT(ctx);
Brian Paul92f97852003-05-01 22:44:02 +0000610
Brian Paul05051032005-11-01 04:36:33 +0000611 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
Brian Paul92f97852003-05-01 22:44:02 +0000612 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(index)");
613 return;
614 }
615
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100616 update_array(ctx, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index),
Brian Paul433e5e62010-10-28 21:17:42 -0600617 legalTypes, 1, BGRA_OR_4,
618 size, type, stride, normalized, GL_FALSE, ptr);
Brian Paul92f97852003-05-01 22:44:02 +0000619}
Brian Paul92f97852003-05-01 22:44:02 +0000620
621
Brian Paule00d07c2010-05-25 21:12:24 -0600622/**
Brian Pauld1184d22010-10-28 21:17:41 -0600623 * GL_EXT_gpu_shader4 / GL 3.0.
Brian Paule00d07c2010-05-25 21:12:24 -0600624 * Set an integer-valued vertex attribute array.
625 * Note that these arrays DO NOT alias the conventional GL vertex arrays
626 * (position, normal, color, fog, texcoord, etc).
627 */
628void GLAPIENTRY
629_mesa_VertexAttribIPointer(GLuint index, GLint size, GLenum type,
Brian Paule00d07c2010-05-25 21:12:24 -0600630 GLsizei stride, const GLvoid *ptr)
631{
Brian Paul433e5e62010-10-28 21:17:42 -0600632 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
633 SHORT_BIT | UNSIGNED_SHORT_BIT |
634 INT_BIT | UNSIGNED_INT_BIT);
Brian Pauld1184d22010-10-28 21:17:41 -0600635 const GLboolean normalized = GL_FALSE;
636 const GLboolean integer = GL_TRUE;
Brian Pauld1184d22010-10-28 21:17:41 -0600637 GET_CURRENT_CONTEXT(ctx);
Brian Pauld1184d22010-10-28 21:17:41 -0600638
639 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
640 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribIPointer(index)");
641 return;
642 }
643
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100644 update_array(ctx, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index),
Brian Paul433e5e62010-10-28 21:17:42 -0600645 legalTypes, 1, 4,
646 size, type, stride, normalized, integer, ptr);
Brian Paule00d07c2010-05-25 21:12:24 -0600647}
648
649
650
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000651void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800652_mesa_EnableVertexAttribArray(GLuint index)
Brian Pauld3f598a2010-05-25 21:42:13 -0600653{
Brian Paul45453d82012-02-19 19:50:31 -0700654 struct gl_array_object *arrayObj;
Brian Pauld3f598a2010-05-25 21:42:13 -0600655 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600656
657 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
658 _mesa_error(ctx, GL_INVALID_VALUE,
659 "glEnableVertexAttribArrayARB(index)");
660 return;
661 }
662
Brian Paul45453d82012-02-19 19:50:31 -0700663 arrayObj = ctx->Array.ArrayObj;
Brian Pauld3f598a2010-05-25 21:42:13 -0600664
Fredrik Höglund12cbe992013-04-03 22:08:47 +0200665 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(arrayObj->_VertexAttrib));
Brian Paul45453d82012-02-19 19:50:31 -0700666
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200667 if (!arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) {
Brian Paul45453d82012-02-19 19:50:31 -0700668 /* was disabled, now being enabled */
669 FLUSH_VERTICES(ctx, _NEW_ARRAY);
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200670 arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_TRUE;
Brian Paul45453d82012-02-19 19:50:31 -0700671 arrayObj->_Enabled |= VERT_BIT_GENERIC(index);
Fredrik Höglund6a650fa2013-05-11 19:23:46 +0200672 arrayObj->NewArrays |= VERT_BIT_GENERIC(index);
Brian Paul45453d82012-02-19 19:50:31 -0700673 }
Brian Pauld3f598a2010-05-25 21:42:13 -0600674}
675
676
677void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800678_mesa_DisableVertexAttribArray(GLuint index)
Brian Pauld3f598a2010-05-25 21:42:13 -0600679{
Brian Paul45453d82012-02-19 19:50:31 -0700680 struct gl_array_object *arrayObj;
Brian Pauld3f598a2010-05-25 21:42:13 -0600681 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600682
683 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
684 _mesa_error(ctx, GL_INVALID_VALUE,
Brian Paul95368f22011-04-06 14:22:39 -0600685 "glDisableVertexAttribArrayARB(index)");
Brian Pauld3f598a2010-05-25 21:42:13 -0600686 return;
687 }
688
Brian Paul45453d82012-02-19 19:50:31 -0700689 arrayObj = ctx->Array.ArrayObj;
Brian Pauld3f598a2010-05-25 21:42:13 -0600690
Fredrik Höglund12cbe992013-04-03 22:08:47 +0200691 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(arrayObj->_VertexAttrib));
Brian Paul45453d82012-02-19 19:50:31 -0700692
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200693 if (arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) {
Brian Paul45453d82012-02-19 19:50:31 -0700694 /* was enabled, now being disabled */
695 FLUSH_VERTICES(ctx, _NEW_ARRAY);
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200696 arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_FALSE;
Brian Paul45453d82012-02-19 19:50:31 -0700697 arrayObj->_Enabled &= ~VERT_BIT_GENERIC(index);
Fredrik Höglund6a650fa2013-05-11 19:23:46 +0200698 arrayObj->NewArrays |= VERT_BIT_GENERIC(index);
Brian Paul45453d82012-02-19 19:50:31 -0700699 }
Brian Pauld3f598a2010-05-25 21:42:13 -0600700}
701
702
703/**
704 * Return info for a vertex attribute array (no alias with legacy
705 * vertex attributes (pos, normal, color, etc)). This function does
706 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
707 */
708static GLuint
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400709get_vertex_array_attrib(struct gl_context *ctx, GLuint index, GLenum pname,
Brian Pauld3f598a2010-05-25 21:42:13 -0600710 const char *caller)
711{
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200712 const struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
713 const struct gl_vertex_attrib_array *array;
Brian Pauld3f598a2010-05-25 21:42:13 -0600714
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800715 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
Brian Pauld3f598a2010-05-25 21:42:13 -0600716 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", caller, index);
717 return 0;
718 }
719
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200720 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(arrayObj->VertexAttrib));
Brian Pauld3f598a2010-05-25 21:42:13 -0600721
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200722 array = &arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)];
Brian Pauld3f598a2010-05-25 21:42:13 -0600723
724 switch (pname) {
725 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
726 return array->Enabled;
727 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
728 return array->Size;
729 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
730 return array->Stride;
731 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
732 return array->Type;
733 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
734 return array->Normalized;
735 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200736 return arrayObj->VertexBinding[array->VertexBinding].BufferObj->Name;
Brian Pauld1184d22010-10-28 21:17:41 -0600737 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
Ian Romanick2c870302012-07-25 16:21:49 -0700738 if ((_mesa_is_desktop_gl(ctx)
739 && (ctx->Version >= 30 || ctx->Extensions.EXT_gpu_shader4))
740 || _mesa_is_gles3(ctx)) {
Brian Pauld1184d22010-10-28 21:17:41 -0600741 return array->Integer;
742 }
Brian Paul1d1eb952011-01-15 10:32:34 -0700743 goto error;
744 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB:
Ian Romanick2c870302012-07-25 16:21:49 -0700745 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_instanced_arrays)
746 || _mesa_is_gles3(ctx)) {
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200747 return arrayObj->VertexBinding[array->VertexBinding].InstanceDivisor;
Brian Paul1d1eb952011-01-15 10:32:34 -0700748 }
749 goto error;
Brian Pauld3f598a2010-05-25 21:42:13 -0600750 default:
Brian Paul1d1eb952011-01-15 10:32:34 -0700751 ; /* fall-through */
Brian Pauld3f598a2010-05-25 21:42:13 -0600752 }
Brian Paul1d1eb952011-01-15 10:32:34 -0700753
754error:
755 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", caller, pname);
756 return 0;
Brian Pauld3f598a2010-05-25 21:42:13 -0600757}
758
759
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800760static const GLfloat *
761get_current_attrib(struct gl_context *ctx, GLuint index, const char *function)
762{
763 if (index == 0) {
Ian Romanick2c870302012-07-25 16:21:49 -0700764 /* In OpenGL 3.1 attribute 0 becomes non-magic, just like in OpenGL ES
765 * 2.0. Note that we cannot just check for API_OPENGL_CORE here because
766 * that will erroneously allow this usage in a 3.0 forward-compatible
767 * context too.
768 */
769 if ((ctx->API != API_OPENGL_CORE || ctx->Version < 31)
770 && ctx->API != API_OPENGLES2) {
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800771 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(index==0)", function);
772 return NULL;
773 }
774 }
775 else if (index >= ctx->Const.VertexProgram.MaxAttribs) {
776 _mesa_error(ctx, GL_INVALID_VALUE,
777 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function);
778 return NULL;
779 }
780
Fredrik Höglund12cbe992013-04-03 22:08:47 +0200781 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.ArrayObj->_VertexAttrib));
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100782
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800783 FLUSH_CURRENT(ctx, 0);
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100784 return ctx->Current.Attrib[VERT_ATTRIB_GENERIC(index)];
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800785}
786
Brian Pauld3f598a2010-05-25 21:42:13 -0600787void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800788_mesa_GetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
Brian Pauld3f598a2010-05-25 21:42:13 -0600789{
790 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600791
792 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800793 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribfv");
794 if (v != NULL) {
Brian Pauld3f598a2010-05-25 21:42:13 -0600795 COPY_4V(params, v);
796 }
797 }
798 else {
799 params[0] = (GLfloat) get_vertex_array_attrib(ctx, index, pname,
800 "glGetVertexAttribfv");
801 }
802}
803
804
805void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800806_mesa_GetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params)
Brian Pauld3f598a2010-05-25 21:42:13 -0600807{
808 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600809
810 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800811 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribdv");
812 if (v != NULL) {
Brian Pauld3f598a2010-05-25 21:42:13 -0600813 params[0] = (GLdouble) v[0];
814 params[1] = (GLdouble) v[1];
815 params[2] = (GLdouble) v[2];
816 params[3] = (GLdouble) v[3];
817 }
818 }
819 else {
820 params[0] = (GLdouble) get_vertex_array_attrib(ctx, index, pname,
821 "glGetVertexAttribdv");
822 }
823}
824
825
826void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800827_mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params)
Brian Pauld3f598a2010-05-25 21:42:13 -0600828{
829 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600830
831 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800832 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribiv");
833 if (v != NULL) {
Brian Pauld3f598a2010-05-25 21:42:13 -0600834 /* XXX should floats in[0,1] be scaled to full int range? */
835 params[0] = (GLint) v[0];
836 params[1] = (GLint) v[1];
837 params[2] = (GLint) v[2];
838 params[3] = (GLint) v[3];
839 }
840 }
841 else {
842 params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname,
843 "glGetVertexAttribiv");
844 }
845}
846
847
848/** GL 3.0 */
849void GLAPIENTRY
850_mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
851{
852 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600853
854 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
Kenneth Graunkec299f442012-11-07 20:29:40 -0800855 const GLint *v = (const GLint *)
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800856 get_current_attrib(ctx, index, "glGetVertexAttribIiv");
857 if (v != NULL) {
Kenneth Graunkec299f442012-11-07 20:29:40 -0800858 COPY_4V(params, v);
Brian Pauld3f598a2010-05-25 21:42:13 -0600859 }
860 }
861 else {
862 params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname,
863 "glGetVertexAttribIiv");
864 }
865}
866
867
868/** GL 3.0 */
869void GLAPIENTRY
870_mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
871{
872 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600873
874 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
Kenneth Graunkec299f442012-11-07 20:29:40 -0800875 const GLuint *v = (const GLuint *)
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800876 get_current_attrib(ctx, index, "glGetVertexAttribIuiv");
877 if (v != NULL) {
Kenneth Graunkec299f442012-11-07 20:29:40 -0800878 COPY_4V(params, v);
Brian Pauld3f598a2010-05-25 21:42:13 -0600879 }
880 }
881 else {
882 params[0] = get_vertex_array_attrib(ctx, index, pname,
883 "glGetVertexAttribIuiv");
884 }
885}
886
887
888void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800889_mesa_GetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer)
Brian Pauld3f598a2010-05-25 21:42:13 -0600890{
891 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600892
893 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
894 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
895 return;
896 }
897
898 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
899 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
900 return;
901 }
902
Fredrik Höglund12cbe992013-04-03 22:08:47 +0200903 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.ArrayObj->_VertexAttrib));
Brian Pauld3f598a2010-05-25 21:42:13 -0600904
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200905 *pointer = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr;
Brian Pauld3f598a2010-05-25 21:42:13 -0600906}
907
908
909void GLAPIENTRY
Brian Paul1f0e2132000-06-12 15:30:51 +0000910_mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
911 GLsizei count, const GLvoid *ptr)
912{
913 (void) count;
914 _mesa_VertexPointer(size, type, stride, ptr);
915}
916
917
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000918void GLAPIENTRY
Brian Paul1f0e2132000-06-12 15:30:51 +0000919_mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
920 const GLvoid *ptr)
921{
922 (void) count;
923 _mesa_NormalPointer(type, stride, ptr);
924}
925
926
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000927void GLAPIENTRY
Brian Paul1f0e2132000-06-12 15:30:51 +0000928_mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
929 const GLvoid *ptr)
930{
931 (void) count;
932 _mesa_ColorPointer(size, type, stride, ptr);
933}
934
935
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000936void GLAPIENTRY
Brian Paul1f0e2132000-06-12 15:30:51 +0000937_mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
938 const GLvoid *ptr)
939{
940 (void) count;
941 _mesa_IndexPointer(type, stride, ptr);
942}
943
944
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000945void GLAPIENTRY
Brian Paul1f0e2132000-06-12 15:30:51 +0000946_mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
947 GLsizei count, const GLvoid *ptr)
948{
949 (void) count;
950 _mesa_TexCoordPointer(size, type, stride, ptr);
951}
952
953
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000954void GLAPIENTRY
Brian Paul1f0e2132000-06-12 15:30:51 +0000955_mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
956{
957 (void) count;
958 _mesa_EdgeFlagPointer(stride, ptr);
959}
960
961
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000962void GLAPIENTRY
Brian Paulfbd8f211999-11-11 01:22:25 +0000963_mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
jtgafb833d1999-08-19 00:55:39 +0000964{
Brian Paulfbd8f211999-11-11 01:22:25 +0000965 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000966 GLboolean tflag, cflag, nflag; /* enable/disable flags */
967 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
Keith Whitwellf4b02d12001-01-05 05:31:42 +0000968 GLenum ctype = 0; /* color type */
969 GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
Brian Paul4a3110f2003-12-12 18:40:02 +0000970 const GLint toffset = 0; /* always zero */
jtgafb833d1999-08-19 00:55:39 +0000971 GLint defstride; /* default stride */
972 GLint c, f;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000973
Eric Anholta9754792013-01-16 16:20:38 -0800974 FLUSH_VERTICES(ctx, 0);
Keith Whitwellcab974c2000-12-26 05:09:27 +0000975
jtgafb833d1999-08-19 00:55:39 +0000976 f = sizeof(GLfloat);
Brian Paulc5b1e812003-10-22 22:59:07 +0000977 c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
jtgafb833d1999-08-19 00:55:39 +0000978
Brian Paulc5b1e812003-10-22 22:59:07 +0000979 if (stride < 0) {
Brian Paul08836342001-03-03 20:33:27 +0000980 _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
jtgafb833d1999-08-19 00:55:39 +0000981 return;
982 }
983
984 switch (format) {
985 case GL_V2F:
986 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
987 tcomps = 0; ccomps = 0; vcomps = 2;
988 voffset = 0;
989 defstride = 2*f;
990 break;
991 case GL_V3F:
992 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
993 tcomps = 0; ccomps = 0; vcomps = 3;
994 voffset = 0;
995 defstride = 3*f;
996 break;
997 case GL_C4UB_V2F:
998 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
999 tcomps = 0; ccomps = 4; vcomps = 2;
1000 ctype = GL_UNSIGNED_BYTE;
1001 coffset = 0;
1002 voffset = c;
1003 defstride = c + 2*f;
1004 break;
1005 case GL_C4UB_V3F:
1006 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1007 tcomps = 0; ccomps = 4; vcomps = 3;
1008 ctype = GL_UNSIGNED_BYTE;
1009 coffset = 0;
1010 voffset = c;
1011 defstride = c + 3*f;
1012 break;
1013 case GL_C3F_V3F:
1014 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1015 tcomps = 0; ccomps = 3; vcomps = 3;
1016 ctype = GL_FLOAT;
1017 coffset = 0;
1018 voffset = 3*f;
1019 defstride = 6*f;
1020 break;
1021 case GL_N3F_V3F:
1022 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
1023 tcomps = 0; ccomps = 0; vcomps = 3;
1024 noffset = 0;
1025 voffset = 3*f;
1026 defstride = 6*f;
1027 break;
1028 case GL_C4F_N3F_V3F:
1029 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
1030 tcomps = 0; ccomps = 4; vcomps = 3;
1031 ctype = GL_FLOAT;
1032 coffset = 0;
1033 noffset = 4*f;
1034 voffset = 7*f;
1035 defstride = 10*f;
1036 break;
1037 case GL_T2F_V3F:
1038 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1039 tcomps = 2; ccomps = 0; vcomps = 3;
1040 voffset = 2*f;
1041 defstride = 5*f;
1042 break;
1043 case GL_T4F_V4F:
1044 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1045 tcomps = 4; ccomps = 0; vcomps = 4;
1046 voffset = 4*f;
1047 defstride = 8*f;
1048 break;
1049 case GL_T2F_C4UB_V3F:
1050 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1051 tcomps = 2; ccomps = 4; vcomps = 3;
1052 ctype = GL_UNSIGNED_BYTE;
1053 coffset = 2*f;
1054 voffset = c+2*f;
1055 defstride = c+5*f;
1056 break;
1057 case GL_T2F_C3F_V3F:
1058 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1059 tcomps = 2; ccomps = 3; vcomps = 3;
1060 ctype = GL_FLOAT;
1061 coffset = 2*f;
1062 voffset = 5*f;
1063 defstride = 8*f;
1064 break;
1065 case GL_T2F_N3F_V3F:
1066 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
1067 tcomps = 2; ccomps = 0; vcomps = 3;
1068 noffset = 2*f;
1069 voffset = 5*f;
1070 defstride = 8*f;
1071 break;
1072 case GL_T2F_C4F_N3F_V3F:
1073 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1074 tcomps = 2; ccomps = 4; vcomps = 3;
1075 ctype = GL_FLOAT;
1076 coffset = 2*f;
1077 noffset = 6*f;
1078 voffset = 9*f;
1079 defstride = 12*f;
1080 break;
1081 case GL_T4F_C4F_N3F_V4F:
1082 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1083 tcomps = 4; ccomps = 4; vcomps = 4;
1084 ctype = GL_FLOAT;
1085 coffset = 4*f;
1086 noffset = 8*f;
1087 voffset = 11*f;
1088 defstride = 15*f;
1089 break;
1090 default:
Brian Paul08836342001-03-03 20:33:27 +00001091 _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
jtgafb833d1999-08-19 00:55:39 +00001092 return;
1093 }
1094
1095 if (stride==0) {
1096 stride = defstride;
1097 }
1098
Brian Paulfbd8f211999-11-11 01:22:25 +00001099 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
1100 _mesa_DisableClientState( GL_INDEX_ARRAY );
Brian Paul095c6692006-04-25 00:21:32 +00001101 /* XXX also disable secondary color and generic arrays? */
jtgafb833d1999-08-19 00:55:39 +00001102
1103 /* Texcoords */
jtgafb833d1999-08-19 00:55:39 +00001104 if (tflag) {
Brian Paul4a3110f2003-12-12 18:40:02 +00001105 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
1106 _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
Brian Paulab928e52004-03-10 16:17:35 +00001107 (GLubyte *) pointer + toffset );
jtgafb833d1999-08-19 00:55:39 +00001108 }
1109 else {
Brian Paulab928e52004-03-10 16:17:35 +00001110 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
jtgafb833d1999-08-19 00:55:39 +00001111 }
jtgafb833d1999-08-19 00:55:39 +00001112
1113 /* Color */
1114 if (cflag) {
Brian Paulfbd8f211999-11-11 01:22:25 +00001115 _mesa_EnableClientState( GL_COLOR_ARRAY );
Keith Whitwellcab974c2000-12-26 05:09:27 +00001116 _mesa_ColorPointer( ccomps, ctype, stride,
Brian Paul4a3110f2003-12-12 18:40:02 +00001117 (GLubyte *) pointer + coffset );
jtgafb833d1999-08-19 00:55:39 +00001118 }
1119 else {
Brian Paulfbd8f211999-11-11 01:22:25 +00001120 _mesa_DisableClientState( GL_COLOR_ARRAY );
jtgafb833d1999-08-19 00:55:39 +00001121 }
1122
1123
1124 /* Normals */
1125 if (nflag) {
Brian Paulfbd8f211999-11-11 01:22:25 +00001126 _mesa_EnableClientState( GL_NORMAL_ARRAY );
Brian Paul4a3110f2003-12-12 18:40:02 +00001127 _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset );
jtgafb833d1999-08-19 00:55:39 +00001128 }
1129 else {
Brian Paulfbd8f211999-11-11 01:22:25 +00001130 _mesa_DisableClientState( GL_NORMAL_ARRAY );
jtgafb833d1999-08-19 00:55:39 +00001131 }
1132
Brian Paul4a3110f2003-12-12 18:40:02 +00001133 /* Vertices */
Brian Paulfbd8f211999-11-11 01:22:25 +00001134 _mesa_EnableClientState( GL_VERTEX_ARRAY );
Keith Whitwellcab974c2000-12-26 05:09:27 +00001135 _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
1136 (GLubyte *) pointer + voffset );
jtgafb833d1999-08-19 00:55:39 +00001137}
1138
1139
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001140void GLAPIENTRY
Keith Whitwellad2ac212000-11-24 10:25:05 +00001141_mesa_LockArraysEXT(GLint first, GLsizei count)
1142{
1143 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -08001144
1145 FLUSH_VERTICES(ctx, 0);
Keith Whitwellad2ac212000-11-24 10:25:05 +00001146
1147 if (MESA_VERBOSE & VERBOSE_API)
Brian Paul4753d602002-06-15 02:38:15 +00001148 _mesa_debug(ctx, "glLockArrays %d %d\n", first, count);
Keith Whitwellad2ac212000-11-24 10:25:05 +00001149
Eric Anholt5857e982008-02-02 02:54:13 -08001150 if (first < 0) {
1151 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" );
1152 return;
Gareth Hughes22144ab2001-03-12 00:48:37 +00001153 }
Eric Anholt5857e982008-02-02 02:54:13 -08001154 if (count <= 0) {
1155 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" );
1156 return;
Keith Whitwellad2ac212000-11-24 10:25:05 +00001157 }
Eric Anholt5857e982008-02-02 02:54:13 -08001158 if (ctx->Array.LockCount != 0) {
1159 _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" );
1160 return;
1161 }
1162
1163 ctx->Array.LockFirst = first;
1164 ctx->Array.LockCount = count;
Keith Whitwellad2ac212000-11-24 10:25:05 +00001165
1166 ctx->NewState |= _NEW_ARRAY;
Keith Whitwellad2ac212000-11-24 10:25:05 +00001167}
1168
1169
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001170void GLAPIENTRY
Keith Whitwellad2ac212000-11-24 10:25:05 +00001171_mesa_UnlockArraysEXT( void )
1172{
1173 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -08001174
1175 FLUSH_VERTICES(ctx, 0);
Keith Whitwellad2ac212000-11-24 10:25:05 +00001176
1177 if (MESA_VERBOSE & VERBOSE_API)
Brian Paul4753d602002-06-15 02:38:15 +00001178 _mesa_debug(ctx, "glUnlockArrays\n");
Keith Whitwellad2ac212000-11-24 10:25:05 +00001179
Eric Anholt5857e982008-02-02 02:54:13 -08001180 if (ctx->Array.LockCount == 0) {
1181 _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" );
1182 return;
1183 }
1184
Keith Whitwellad2ac212000-11-24 10:25:05 +00001185 ctx->Array.LockFirst = 0;
1186 ctx->Array.LockCount = 0;
1187 ctx->NewState |= _NEW_ARRAY;
Keith Whitwellad2ac212000-11-24 10:25:05 +00001188}
Brian Paul2525bc72002-06-30 15:47:00 +00001189
1190
Brian Paul2525bc72002-06-30 15:47:00 +00001191/* GL_EXT_multi_draw_arrays */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001192void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -08001193_mesa_MultiDrawArrays( GLenum mode, const GLint *first,
Brian Paul79938322010-09-14 09:37:35 -06001194 const GLsizei *count, GLsizei primcount )
Brian Paul2525bc72002-06-30 15:47:00 +00001195{
1196 GET_CURRENT_CONTEXT(ctx);
1197 GLint i;
1198
Eric Anholta9754792013-01-16 16:20:38 -08001199 FLUSH_VERTICES(ctx, 0);
Brian Paul2525bc72002-06-30 15:47:00 +00001200
1201 for (i = 0; i < primcount; i++) {
1202 if (count[i] > 0) {
Ian Romanick9bdfee32005-07-18 12:31:24 +00001203 CALL_DrawArrays(ctx->Exec, (mode, first[i], count[i]));
Brian Paul2525bc72002-06-30 15:47:00 +00001204 }
1205 }
1206}
1207
1208
Ian Romanick3baefe62003-08-22 23:28:03 +00001209/* GL_IBM_multimode_draw_arrays */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001210void GLAPIENTRY
Ian Romanick3baefe62003-08-22 23:28:03 +00001211_mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
1212 const GLsizei * count,
1213 GLsizei primcount, GLint modestride )
1214{
1215 GET_CURRENT_CONTEXT(ctx);
1216 GLint i;
1217
Eric Anholta9754792013-01-16 16:20:38 -08001218 FLUSH_VERTICES(ctx, 0);
Ian Romanick3baefe62003-08-22 23:28:03 +00001219
1220 for ( i = 0 ; i < primcount ; i++ ) {
1221 if ( count[i] > 0 ) {
Brian Paul03e29a52003-12-04 03:16:27 +00001222 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
Ian Romanick9bdfee32005-07-18 12:31:24 +00001223 CALL_DrawArrays(ctx->Exec, ( m, first[i], count[i] ));
Ian Romanick3baefe62003-08-22 23:28:03 +00001224 }
1225 }
1226}
1227
1228
1229/* GL_IBM_multimode_draw_arrays */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001230void GLAPIENTRY
Ian Romanick3baefe62003-08-22 23:28:03 +00001231_mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
1232 GLenum type, const GLvoid * const * indices,
1233 GLsizei primcount, GLint modestride )
1234{
1235 GET_CURRENT_CONTEXT(ctx);
1236 GLint i;
1237
Eric Anholta9754792013-01-16 16:20:38 -08001238 FLUSH_VERTICES(ctx, 0);
Ian Romanick3baefe62003-08-22 23:28:03 +00001239
Brian Pauld2afb392003-09-17 18:15:13 +00001240 /* XXX not sure about ARB_vertex_buffer_object handling here */
1241
Ian Romanick3baefe62003-08-22 23:28:03 +00001242 for ( i = 0 ; i < primcount ; i++ ) {
1243 if ( count[i] > 0 ) {
Brian Paul03e29a52003-12-04 03:16:27 +00001244 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
Ian Romanick9bdfee32005-07-18 12:31:24 +00001245 CALL_DrawElements(ctx->Exec, ( m, count[i], type, indices[i] ));
Ian Romanick3baefe62003-08-22 23:28:03 +00001246 }
1247 }
1248}
1249
1250
Brian Paul095c6692006-04-25 00:21:32 +00001251/**
Brian Paul7f26ad82010-10-21 19:03:38 -06001252 * GL_NV_primitive_restart and GL 3.1
Brian Paula40e6f22010-04-20 21:02:09 -06001253 */
1254void GLAPIENTRY
1255_mesa_PrimitiveRestartIndex(GLuint index)
1256{
1257 GET_CURRENT_CONTEXT(ctx);
1258
Eric Anholt9c1b4182012-07-26 14:43:56 -07001259 if (!ctx->Extensions.NV_primitive_restart && ctx->Version < 31) {
Brian Paul7f26ad82010-10-21 19:03:38 -06001260 _mesa_error(ctx, GL_INVALID_OPERATION, "glPrimitiveRestartIndexNV()");
Brian Paula40e6f22010-04-20 21:02:09 -06001261 return;
1262 }
1263
Kenneth Graunkee6efb902013-05-29 08:31:54 -07001264 if (ctx->Array.RestartIndex != index) {
Brian Pauld2003ee2012-02-19 19:50:32 -07001265 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
Kenneth Graunkee6efb902013-05-29 08:31:54 -07001266 ctx->Array.RestartIndex = index;
Brian Pauld2003ee2012-02-19 19:50:32 -07001267 }
Brian Paula40e6f22010-04-20 21:02:09 -06001268}
1269
1270
1271/**
Brian Paul1d1eb952011-01-15 10:32:34 -07001272 * See GL_ARB_instanced_arrays.
1273 * Note that the instance divisor only applies to generic arrays, not
1274 * the legacy vertex arrays.
1275 */
1276void GLAPIENTRY
1277_mesa_VertexAttribDivisor(GLuint index, GLuint divisor)
1278{
1279 GET_CURRENT_CONTEXT(ctx);
Brian Paul1d1eb952011-01-15 10:32:34 -07001280
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001281 const GLuint genericIndex = VERT_ATTRIB_GENERIC(index);
1282
Brian Paul1d1eb952011-01-15 10:32:34 -07001283 if (!ctx->Extensions.ARB_instanced_arrays) {
1284 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()");
1285 return;
1286 }
1287
1288 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
Matt Turnerae1f09b2012-11-13 13:05:03 -08001289 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribDivisor(index = %u)",
Brian Paul1d1eb952011-01-15 10:32:34 -07001290 index);
1291 return;
1292 }
1293
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001294 ASSERT(genericIndex < Elements(ctx->Array.ArrayObj->VertexAttrib));
Mathias Fröhlich762c9762011-10-31 22:23:51 +01001295
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001296 /* The ARB_vertex_attrib_binding spec says:
1297 *
1298 * "The command
1299 *
1300 * void VertexAttribDivisor(uint index, uint divisor);
1301 *
1302 * is equivalent to (assuming no errors are generated):
1303 *
1304 * VertexAttribBinding(index, index);
1305 * VertexBindingDivisor(index, divisor);"
1306 */
1307 vertex_attrib_binding(ctx, genericIndex, genericIndex);
1308 vertex_binding_divisor(ctx, genericIndex, divisor);
Brian Paul1d1eb952011-01-15 10:32:34 -07001309}
1310
1311
Kenneth Graunke959d0762013-05-29 08:07:01 -07001312unsigned
1313_mesa_primitive_restart_index(const struct gl_context *ctx, GLenum ib_type)
1314{
1315 /* From the OpenGL 4.3 core specification, page 302:
1316 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1317 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1318 * is used."
1319 */
1320 if (ctx->Array.PrimitiveRestartFixedIndex) {
1321 switch (ib_type) {
1322 case GL_UNSIGNED_BYTE:
1323 return 0xff;
1324 case GL_UNSIGNED_SHORT:
1325 return 0xffff;
1326 case GL_UNSIGNED_INT:
1327 return 0xffffffff;
1328 default:
1329 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1330 }
1331 }
1332
1333 return ctx->Array.RestartIndex;
1334}
1335
Brian Paul1d1eb952011-01-15 10:32:34 -07001336
1337/**
Fredrik Höglundbb2d02c2013-04-09 20:44:58 +02001338 * GL_ARB_vertex_attrib_binding
1339 */
1340void GLAPIENTRY
1341_mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
1342 GLsizei stride)
1343{
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001344 struct gl_buffer_object *vbo;
1345
1346 GET_CURRENT_CONTEXT(ctx);
1347 ASSERT_OUTSIDE_BEGIN_END(ctx);
1348
1349 /* The ARB_vertex_attrib_binding spec says:
1350 *
1351 * "An INVALID_OPERATION error is generated if no vertex array object
1352 * is bound."
1353 */
1354 if (ctx->API == API_OPENGL_CORE &&
1355 ctx->Array.ArrayObj == ctx->Array.DefaultArrayObj) {
1356 _mesa_error(ctx, GL_INVALID_OPERATION,
1357 "glBindVertexBuffer(No array object bound)");
1358 return;
1359 }
1360
1361 /* The ARB_vertex_attrib_binding spec says:
1362 *
1363 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1364 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1365 */
1366 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
1367 _mesa_error(ctx, GL_INVALID_VALUE,
1368 "glBindVertexBuffer(bindingindex=%u > "
1369 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1370 bindingIndex);
1371 return;
1372 }
1373
1374 /* The ARB_vertex_attrib_binding spec says:
1375 *
1376 * "The error INVALID_VALUE is generated if <stride> or <offset>
1377 * are negative."
1378 */
1379 if (offset < 0) {
1380 _mesa_error(ctx, GL_INVALID_VALUE,
1381 "glBindVertexBuffer(offset=%lld < 0)", (long long)offset);
1382 return;
1383 }
1384
1385 if (stride < 0) {
1386 _mesa_error(ctx, GL_INVALID_VALUE,
1387 "glBindVertexBuffer(stride=%d < 0)", stride);
1388 return;
1389 }
1390
1391 if (buffer != 0) {
1392 vbo = _mesa_lookup_bufferobj(ctx, buffer);
1393
1394 /* From the GL_ARB_vertex_attrib_array spec:
1395 *
1396 * "[Core profile only:]
1397 * An INVALID_OPERATION error is generated if buffer is not zero or a
1398 * name returned from a previous call to GenBuffers, or if such a name
1399 * has since been deleted with DeleteBuffers.
1400 *
1401 * Otherwise, we fall back to the same compat profile behavior as other
1402 * object references (automatically gen it).
1403 */
1404 if (!_mesa_handle_bind_buffer_gen(ctx, GL_ARRAY_BUFFER, buffer,
1405 &vbo, "glBindVertexBuffer"))
1406 return;
1407 } else {
1408 /* The ARB_vertex_attrib_binding spec says:
1409 *
1410 * "If <buffer> is zero, any buffer object attached to this
1411 * bindpoint is detached."
1412 */
1413 vbo = ctx->Shared->NullBufferObj;
1414 }
1415
1416 bind_vertex_buffer(ctx, VERT_ATTRIB_GENERIC(bindingIndex),
1417 vbo, offset, stride);
Fredrik Höglundbb2d02c2013-04-09 20:44:58 +02001418}
1419
1420
1421void GLAPIENTRY
1422_mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type,
1423 GLboolean normalized, GLuint relativeOffset)
1424{
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001425 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
1426 SHORT_BIT | UNSIGNED_SHORT_BIT |
1427 INT_BIT | UNSIGNED_INT_BIT |
1428 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
1429 FIXED_GL_BIT |
1430 UNSIGNED_INT_2_10_10_10_REV_BIT |
1431 INT_2_10_10_10_REV_BIT);
1432
1433 GET_CURRENT_CONTEXT(ctx);
1434 ASSERT_OUTSIDE_BEGIN_END(ctx);
1435
1436 /* The ARB_vertex_attrib_binding spec says:
1437 *
1438 * "An INVALID_OPERATION error is generated under any of the following
1439 * conditions:
1440 * - if no vertex array object is currently bound (see section 2.10);
1441 * - ..."
1442 */
1443 if (ctx->API == API_OPENGL_CORE &&
1444 ctx->Array.ArrayObj == ctx->Array.DefaultArrayObj) {
1445 _mesa_error(ctx, GL_INVALID_OPERATION,
1446 "glVertexAttribFormat(No array object bound)");
1447 return;
1448 }
1449
1450 /* The ARB_vertex_attrib_binding spec says:
1451 *
1452 * "The error INVALID_VALUE is generated if index is greater than or equal
1453 * to the value of MAX_VERTEX_ATTRIBS."
1454 */
1455 if (attribIndex >= ctx->Const.VertexProgram.MaxAttribs) {
1456 _mesa_error(ctx, GL_INVALID_VALUE,
1457 "glVertexAttribFormat(attribindex=%u > "
1458 "GL_MAX_VERTEX_ATTRIBS)",
1459 attribIndex);
1460 return;
1461 }
1462
1463 FLUSH_VERTICES(ctx, 0);
1464
1465 update_array_format(ctx, "glVertexAttribFormat",
1466 VERT_ATTRIB_GENERIC(attribIndex),
1467 legalTypes, 1, BGRA_OR_4, size, type, normalized,
1468 GL_FALSE, relativeOffset);
Fredrik Höglundbb2d02c2013-04-09 20:44:58 +02001469}
1470
1471
1472void GLAPIENTRY
1473_mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type,
1474 GLuint relativeOffset)
1475{
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001476 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
1477 SHORT_BIT | UNSIGNED_SHORT_BIT |
1478 INT_BIT | UNSIGNED_INT_BIT);
1479
1480 GET_CURRENT_CONTEXT(ctx);
1481 ASSERT_OUTSIDE_BEGIN_END(ctx);
1482
1483 /* The ARB_vertex_attrib_binding spec says:
1484 *
1485 * "An INVALID_OPERATION error is generated under any of the following
1486 * conditions:
1487 * - if no vertex array object is currently bound (see section 2.10);
1488 * - ..."
1489 */
1490 if (ctx->API == API_OPENGL_CORE &&
1491 ctx->Array.ArrayObj == ctx->Array.DefaultArrayObj) {
1492 _mesa_error(ctx, GL_INVALID_OPERATION,
1493 "glVertexAttribIFormat(No array object bound)");
1494 return;
1495 }
1496
1497 /* The ARB_vertex_attrib_binding spec says:
1498 *
1499 * "The error INVALID_VALUE is generated if index is greater than
1500 * or equal to the value of MAX_VERTEX_ATTRIBS."
1501 */
1502 if (attribIndex >= ctx->Const.VertexProgram.MaxAttribs) {
1503 _mesa_error(ctx, GL_INVALID_VALUE,
1504 "glVertexAttribIFormat(attribindex=%u > "
1505 "GL_MAX_VERTEX_ATTRIBS)",
1506 attribIndex);
1507 return;
1508 }
1509
1510 FLUSH_VERTICES(ctx, 0);
1511
1512 update_array_format(ctx, "glVertexAttribIFormat",
1513 VERT_ATTRIB_GENERIC(attribIndex),
1514 legalTypes, 1, 4, size, type, GL_FALSE, GL_TRUE,
1515 relativeOffset);
Fredrik Höglundbb2d02c2013-04-09 20:44:58 +02001516}
1517
1518
1519void GLAPIENTRY
1520_mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type,
1521 GLuint relativeOffset)
1522{
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001523 const GLbitfield legalTypes = DOUBLE_BIT;
1524
1525 GET_CURRENT_CONTEXT(ctx);
1526 ASSERT_OUTSIDE_BEGIN_END(ctx);
1527
1528 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
1529 *
1530 * "An INVALID_OPERATION error is generated under any of the following
1531 * conditions:
1532 * • if no vertex array object is currently bound (see section 10.4);
1533 * • ..."
1534 *
1535 * This language is missing from the extension spec, but we assume
1536 * that this is an oversight.
1537 */
1538 if (ctx->API == API_OPENGL_CORE &&
1539 ctx->Array.ArrayObj == ctx->Array.DefaultArrayObj) {
1540 _mesa_error(ctx, GL_INVALID_OPERATION,
1541 "glVertexAttribLFormat(No array object bound)");
1542 return;
1543 }
1544
1545 /* The ARB_vertex_attrib_binding spec says:
1546 *
1547 * "The error INVALID_VALUE is generated if <attribindex> is greater than
1548 * or equal to the value of MAX_VERTEX_ATTRIBS."
1549 */
1550 if (attribIndex >= ctx->Const.VertexProgram.MaxAttribs) {
1551 _mesa_error(ctx, GL_INVALID_VALUE,
1552 "glVertexAttribLFormat(attribindex=%u > "
1553 "GL_MAX_VERTEX_ATTRIBS)",
1554 attribIndex);
1555 return;
1556 }
1557
1558 FLUSH_VERTICES(ctx, 0);
1559
1560 update_array_format(ctx, "glVertexAttribLFormat",
1561 VERT_ATTRIB_GENERIC(attribIndex),
1562 legalTypes, 1, 4, size, type, GL_FALSE, GL_FALSE,
1563 relativeOffset);
Fredrik Höglundbb2d02c2013-04-09 20:44:58 +02001564}
1565
1566
1567void GLAPIENTRY
1568_mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
1569{
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001570 GET_CURRENT_CONTEXT(ctx);
1571 ASSERT_OUTSIDE_BEGIN_END(ctx);
1572
1573 /* The ARB_vertex_attrib_binding spec says:
1574 *
1575 * "An INVALID_OPERATION error is generated if no vertex array object
1576 * is bound."
1577 */
1578 if (ctx->API == API_OPENGL_CORE &&
1579 ctx->Array.ArrayObj == ctx->Array.DefaultArrayObj) {
1580 _mesa_error(ctx, GL_INVALID_OPERATION,
1581 "glVertexAttribBinding(No array object bound)");
1582 return;
1583 }
1584
1585 /* The ARB_vertex_attrib_binding spec says:
1586 *
1587 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
1588 * <bindingindex> must be less than the value of
1589 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
1590 * is generated."
1591 */
1592 if (attribIndex >= ctx->Const.VertexProgram.MaxAttribs) {
1593 _mesa_error(ctx, GL_INVALID_VALUE,
1594 "glVertexAttribBinding(attribindex=%u >= "
1595 "GL_MAX_VERTEX_ATTRIBS)",
1596 attribIndex);
1597 return;
1598 }
1599
1600 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
1601 _mesa_error(ctx, GL_INVALID_VALUE,
1602 "glVertexAttribBinding(bindingindex=%u >= "
1603 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1604 bindingIndex);
1605 return;
1606 }
1607
1608 ASSERT(VERT_ATTRIB_GENERIC(attribIndex) <
1609 Elements(ctx->Array.ArrayObj->VertexAttrib));
1610
1611 vertex_attrib_binding(ctx, VERT_ATTRIB_GENERIC(attribIndex),
1612 VERT_ATTRIB_GENERIC(bindingIndex));
Fredrik Höglundbb2d02c2013-04-09 20:44:58 +02001613}
1614
1615
1616void GLAPIENTRY
1617_mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
1618{
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001619 GET_CURRENT_CONTEXT(ctx);
1620 ASSERT_OUTSIDE_BEGIN_END(ctx);
1621
1622 if (!ctx->Extensions.ARB_instanced_arrays) {
1623 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexBindingDivisor()");
1624 return;
1625 }
1626
1627 /* The ARB_vertex_attrib_binding spec says:
1628 *
1629 * "An INVALID_OPERATION error is generated if no vertex array object
1630 * is bound."
1631 */
1632 if (ctx->API == API_OPENGL_CORE &&
1633 ctx->Array.ArrayObj == ctx->Array.DefaultArrayObj) {
1634 _mesa_error(ctx, GL_INVALID_OPERATION,
1635 "glVertexBindingDivisor(No array object bound)");
1636 return;
1637 }
1638
1639 /* The ARB_vertex_attrib_binding spec says:
1640 *
1641 * "An INVALID_VALUE error is generated if <bindingindex> is greater
1642 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
1643 */
1644 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
1645 _mesa_error(ctx, GL_INVALID_VALUE,
1646 "glVertexBindingDivisor(bindingindex=%u > "
1647 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1648 bindingIndex);
1649 return;
1650 }
1651
1652 vertex_binding_divisor(ctx, VERT_ATTRIB_GENERIC(bindingIndex), divisor);
Fredrik Höglundbb2d02c2013-04-09 20:44:58 +02001653}
1654
1655
1656/**
Brian Paulb2885402009-08-06 13:53:06 -06001657 * Copy one client vertex array to another.
1658 */
1659void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -04001660_mesa_copy_client_array(struct gl_context *ctx,
Brian Paulb2885402009-08-06 13:53:06 -06001661 struct gl_client_array *dst,
1662 struct gl_client_array *src)
1663{
1664 dst->Size = src->Size;
1665 dst->Type = src->Type;
1666 dst->Format = src->Format;
1667 dst->Stride = src->Stride;
1668 dst->StrideB = src->StrideB;
1669 dst->Ptr = src->Ptr;
1670 dst->Enabled = src->Enabled;
1671 dst->Normalized = src->Normalized;
Brian Pauld1184d22010-10-28 21:17:41 -06001672 dst->Integer = src->Integer;
Brian Paul1d1eb952011-01-15 10:32:34 -07001673 dst->InstanceDivisor = src->InstanceDivisor;
Brian Paulb2885402009-08-06 13:53:06 -06001674 dst->_ElementSize = src->_ElementSize;
1675 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
1676 dst->_MaxElement = src->_MaxElement;
1677}
1678
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001679void
1680_mesa_copy_vertex_attrib_array(struct gl_context *ctx,
1681 struct gl_vertex_attrib_array *dst,
1682 const struct gl_vertex_attrib_array *src)
1683{
1684 dst->Size = src->Size;
1685 dst->Type = src->Type;
1686 dst->Format = src->Format;
1687 dst->VertexBinding = src->VertexBinding;
1688 dst->RelativeOffset = src->RelativeOffset;
1689 dst->Format = src->Format;
1690 dst->Integer = src->Integer;
1691 dst->Normalized = src->Normalized;
1692 dst->Ptr = src->Ptr;
1693 dst->Enabled = src->Enabled;
1694 dst->_ElementSize = src->_ElementSize;
1695}
Brian Paulb2885402009-08-06 13:53:06 -06001696
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001697void
1698_mesa_copy_vertex_buffer_binding(struct gl_context *ctx,
1699 struct gl_vertex_buffer_binding *dst,
1700 const struct gl_vertex_buffer_binding *src)
1701{
1702 dst->Offset = src->Offset;
1703 dst->Stride = src->Stride;
1704 dst->InstanceDivisor = src->InstanceDivisor;
1705 dst->_BoundArrays = src->_BoundArrays;
1706
1707 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
1708}
Brian Paulb2885402009-08-06 13:53:06 -06001709
1710/**
Brian Paul39d75242009-05-14 16:25:32 -06001711 * Print vertex array's fields.
1712 */
1713static void
1714print_array(const char *name, GLint index, const struct gl_client_array *array)
1715{
1716 if (index >= 0)
Kristian Høgsberg298be2b2010-02-19 12:32:24 -05001717 printf(" %s[%d]: ", name, index);
Brian Paul39d75242009-05-14 16:25:32 -06001718 else
Kristian Høgsberg298be2b2010-02-19 12:32:24 -05001719 printf(" %s: ", name);
Brian Paul4beea122010-07-14 14:36:25 -06001720 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 -05001721 array->Ptr, array->Type, array->Size,
1722 array->_ElementSize, array->StrideB,
Brian Paul4beea122010-07-14 14:36:25 -06001723 array->BufferObj->Name, (unsigned long) array->BufferObj->Size,
Kristian Høgsberg298be2b2010-02-19 12:32:24 -05001724 array->_MaxElement);
Brian Paul39d75242009-05-14 16:25:32 -06001725}
1726
1727
1728/**
1729 * Print current vertex object/array info. For debug.
1730 */
1731void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -04001732_mesa_print_arrays(struct gl_context *ctx)
Brian Paul39d75242009-05-14 16:25:32 -06001733{
Brian Paul6a2211f2009-05-21 15:55:50 -06001734 struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
Brian Paul39d75242009-05-14 16:25:32 -06001735 GLuint i;
1736
Brian Paul8fe31342009-05-21 15:36:25 -06001737 _mesa_update_array_object_max_element(ctx, arrayObj);
1738
Kristian Høgsberg298be2b2010-02-19 12:32:24 -05001739 printf("Array Object %u\n", arrayObj->Name);
Fredrik Höglund12cbe992013-04-03 22:08:47 +02001740 if (arrayObj->_VertexAttrib[VERT_ATTRIB_POS].Enabled)
1741 print_array("Vertex", -1, &arrayObj->_VertexAttrib[VERT_ATTRIB_POS]);
1742 if (arrayObj->_VertexAttrib[VERT_ATTRIB_NORMAL].Enabled)
1743 print_array("Normal", -1, &arrayObj->_VertexAttrib[VERT_ATTRIB_NORMAL]);
1744 if (arrayObj->_VertexAttrib[VERT_ATTRIB_COLOR0].Enabled)
1745 print_array("Color", -1, &arrayObj->_VertexAttrib[VERT_ATTRIB_COLOR0]);
Mathias Fröhlich762c9762011-10-31 22:23:51 +01001746 for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++)
Fredrik Höglund12cbe992013-04-03 22:08:47 +02001747 if (arrayObj->_VertexAttrib[VERT_ATTRIB_TEX(i)].Enabled)
1748 print_array("TexCoord", i, &arrayObj->_VertexAttrib[VERT_ATTRIB_TEX(i)]);
Mathias Fröhlich762c9762011-10-31 22:23:51 +01001749 for (i = 0; i < VERT_ATTRIB_GENERIC_MAX; i++)
Fredrik Höglund12cbe992013-04-03 22:08:47 +02001750 if (arrayObj->_VertexAttrib[VERT_ATTRIB_GENERIC(i)].Enabled)
1751 print_array("Attrib", i, &arrayObj->_VertexAttrib[VERT_ATTRIB_GENERIC(i)]);
Kristian Høgsberg298be2b2010-02-19 12:32:24 -05001752 printf(" _MaxElement = %u\n", arrayObj->_MaxElement);
Brian Paul39d75242009-05-14 16:25:32 -06001753}
1754
1755
1756/**
Brian Paul095c6692006-04-25 00:21:32 +00001757 * Initialize vertex array state for given context.
1758 */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001759void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -04001760_mesa_init_varray(struct gl_context *ctx)
Keith Whitwell6dc85572003-07-17 13:43:59 +00001761{
Mathias Fröhlich86f53e62011-11-02 19:54:26 +01001762 ctx->Array.DefaultArrayObj = ctx->Driver.NewArrayObject(ctx, 0);
Brian Paul1030bf02009-05-07 13:52:26 -06001763 _mesa_reference_array_object(ctx, &ctx->Array.ArrayObj,
1764 ctx->Array.DefaultArrayObj);
Brian Paul095c6692006-04-25 00:21:32 +00001765 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
Brian Paul12cf98f2009-06-19 17:58:47 -06001766
1767 ctx->Array.Objects = _mesa_NewHashTable();
1768}
1769
1770
1771/**
1772 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
1773 */
1774static void
1775delete_arrayobj_cb(GLuint id, void *data, void *userData)
1776{
1777 struct gl_array_object *arrayObj = (struct gl_array_object *) data;
Kristian Høgsbergf9995b32010-10-12 12:26:10 -04001778 struct gl_context *ctx = (struct gl_context *) userData;
Brian Paul12cf98f2009-06-19 17:58:47 -06001779 _mesa_delete_array_object(ctx, arrayObj);
1780}
1781
1782
1783/**
1784 * Free vertex array state for given context.
1785 */
1786void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -04001787_mesa_free_varray_data(struct gl_context *ctx)
Brian Paul12cf98f2009-06-19 17:58:47 -06001788{
1789 _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx);
1790 _mesa_DeleteHashTable(ctx->Array.Objects);
Keith Whitwell6dc85572003-07-17 13:43:59 +00001791}