blob: 230fb30cb23ca06ca33b752ded783f33aef0107b [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 Paul80fa7fd2014-08-08 07:49:33 -060027#include <inttypes.h> /* for PRId64 macro */
28
Brian Paulfbd8f211999-11-11 01:22:25 +000029#include "glheader.h"
Brian Paul148a2842003-09-17 03:40:11 +000030#include "imports.h"
Brian Paul26895aa2004-03-03 15:35:08 +000031#include "bufferobj.h"
jtgafb833d1999-08-19 00:55:39 +000032#include "context.h"
jtgafb833d1999-08-19 00:55:39 +000033#include "enable.h"
34#include "enums.h"
Brian Paul12cf98f2009-06-19 17:58:47 -060035#include "hash.h"
Brian Paul433e5e62010-10-28 21:17:42 -060036#include "image.h"
Brian Pauld3f598a2010-05-25 21:42:13 -060037#include "macros.h"
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000038#include "mtypes.h"
jtgafb833d1999-08-19 00:55:39 +000039#include "varray.h"
Ian Romanickee34e6e2006-06-12 16:26:29 +000040#include "arrayobj.h"
Chia-I Wu2cf44392010-02-24 12:01:14 +080041#include "main/dispatch.h"
jtgafb833d1999-08-19 00:55:39 +000042
Brian Paulc5b1e812003-10-22 22:59:07 +000043
Brian Paul433e5e62010-10-28 21:17:42 -060044/** Used to do error checking for GL_EXT_vertex_array_bgra */
45#define BGRA_OR_4 5
46
47
48/** Used to indicate which GL datatypes are accepted by each of the
49 * glVertex/Color/Attrib/EtcPointer() functions.
50 */
Brian Paula5743fd2014-08-08 07:46:45 -060051#define BOOL_BIT (1 << 0)
52#define BYTE_BIT (1 << 1)
53#define UNSIGNED_BYTE_BIT (1 << 2)
54#define SHORT_BIT (1 << 3)
55#define UNSIGNED_SHORT_BIT (1 << 4)
56#define INT_BIT (1 << 5)
57#define UNSIGNED_INT_BIT (1 << 6)
58#define HALF_BIT (1 << 7)
59#define FLOAT_BIT (1 << 8)
60#define DOUBLE_BIT (1 << 9)
61#define FIXED_ES_BIT (1 << 10)
62#define FIXED_GL_BIT (1 << 11)
63#define UNSIGNED_INT_2_10_10_10_REV_BIT (1 << 12)
64#define INT_2_10_10_10_REV_BIT (1 << 13)
65#define UNSIGNED_INT_10F_11F_11F_REV_BIT (1 << 14)
66#define ALL_TYPE_BITS ((1 << 15) - 1)
Brian Paul433e5e62010-10-28 21:17:42 -060067
68
69/** Convert GL datatype enum into a <type>_BIT value seen above */
70static GLbitfield
71type_to_bit(const struct gl_context *ctx, GLenum type)
72{
73 switch (type) {
74 case GL_BOOL:
75 return BOOL_BIT;
76 case GL_BYTE:
77 return BYTE_BIT;
78 case GL_UNSIGNED_BYTE:
79 return UNSIGNED_BYTE_BIT;
80 case GL_SHORT:
81 return SHORT_BIT;
82 case GL_UNSIGNED_SHORT:
83 return UNSIGNED_SHORT_BIT;
84 case GL_INT:
85 return INT_BIT;
86 case GL_UNSIGNED_INT:
87 return UNSIGNED_INT_BIT;
88 case GL_HALF_FLOAT:
89 if (ctx->Extensions.ARB_half_float_vertex)
90 return HALF_BIT;
91 else
92 return 0x0;
93 case GL_FLOAT:
94 return FLOAT_BIT;
95 case GL_DOUBLE:
96 return DOUBLE_BIT;
97 case GL_FIXED:
Jordan Justen09714c02012-07-19 11:27:16 -070098 return _mesa_is_desktop_gl(ctx) ? FIXED_GL_BIT : FIXED_ES_BIT;
Dave Airlie6cd2d552011-08-13 15:30:38 +010099 case GL_UNSIGNED_INT_2_10_10_10_REV:
100 return UNSIGNED_INT_2_10_10_10_REV_BIT;
101 case GL_INT_2_10_10_10_REV:
102 return INT_2_10_10_10_REV_BIT;
Chris Forbes1f092a92013-11-07 22:02:24 +1300103 case GL_UNSIGNED_INT_10F_11F_11F_REV:
104 return UNSIGNED_INT_10F_11F_11F_REV_BIT;
Brian Paul433e5e62010-10-28 21:17:42 -0600105 default:
106 return 0;
107 }
108}
109
110
Brian Paulc5b1e812003-10-22 22:59:07 +0000111/**
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200112 * Sets the VertexBinding field in the vertex attribute given by attribIndex.
113 */
114static void
115vertex_attrib_binding(struct gl_context *ctx, GLuint attribIndex,
116 GLuint bindingIndex)
117{
Kenneth Graunkeaac14152014-02-01 19:36:59 -0800118 struct gl_vertex_array_object *vao = ctx->Array.VAO;
Kenneth Graunke94e07c12014-02-01 19:31:22 -0800119 struct gl_vertex_attrib_array *array = &vao->VertexAttrib[attribIndex];
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200120
121 if (array->VertexBinding != bindingIndex) {
122 const GLbitfield64 array_bit = VERT_BIT(attribIndex);
123
124 FLUSH_VERTICES(ctx, _NEW_ARRAY);
125
Kenneth Graunke94e07c12014-02-01 19:31:22 -0800126 vao->VertexBinding[array->VertexBinding]._BoundArrays &= ~array_bit;
127 vao->VertexBinding[bindingIndex]._BoundArrays |= array_bit;
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200128
129 array->VertexBinding = bindingIndex;
130
Kenneth Graunke94e07c12014-02-01 19:31:22 -0800131 vao->NewArrays |= array_bit;
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200132 }
133}
134
135
136/**
137 * Binds a buffer object to the vertex buffer binding point given by index,
138 * and sets the Offset and Stride fields.
139 */
140static void
141bind_vertex_buffer(struct gl_context *ctx, GLuint index,
142 struct gl_buffer_object *vbo,
143 GLintptr offset, GLsizei stride)
144{
Kenneth Graunkeaac14152014-02-01 19:36:59 -0800145 struct gl_vertex_array_object *vao = ctx->Array.VAO;
Kenneth Graunke94e07c12014-02-01 19:31:22 -0800146 struct gl_vertex_buffer_binding *binding = &vao->VertexBinding[index];
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200147
148 if (binding->BufferObj != vbo ||
149 binding->Offset != offset ||
150 binding->Stride != stride) {
151
152 FLUSH_VERTICES(ctx, _NEW_ARRAY);
153
154 _mesa_reference_buffer_object(ctx, &binding->BufferObj, vbo);
155
156 binding->Offset = offset;
157 binding->Stride = stride;
158
Kenneth Graunke94e07c12014-02-01 19:31:22 -0800159 vao->NewArrays |= binding->_BoundArrays;
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200160 }
161}
162
163
164/**
165 * Sets the InstanceDivisor field in the vertex buffer binding point
166 * given by bindingIndex.
167 */
168static void
169vertex_binding_divisor(struct gl_context *ctx, GLuint bindingIndex,
170 GLuint divisor)
171{
Kenneth Graunkeaac14152014-02-01 19:36:59 -0800172 struct gl_vertex_array_object *vao = ctx->Array.VAO;
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200173 struct gl_vertex_buffer_binding *binding =
Kenneth Graunke94e07c12014-02-01 19:31:22 -0800174 &vao->VertexBinding[bindingIndex];
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200175
176 if (binding->InstanceDivisor != divisor) {
177 FLUSH_VERTICES(ctx, _NEW_ARRAY);
178 binding->InstanceDivisor = divisor;
Kenneth Graunke94e07c12014-02-01 19:31:22 -0800179 vao->NewArrays |= binding->_BoundArrays;
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200180 }
181}
182
183
184/**
Brian Paul67199142014-07-29 09:17:53 -0600185 * Examine the API profile and extensions to determine which types are legal
186 * for vertex arrays. This is called once from update_array_format().
187 */
188static GLbitfield
189get_legal_types_mask(const struct gl_context *ctx)
190{
Brian Paula5743fd2014-08-08 07:46:45 -0600191 GLbitfield legalTypesMask = ALL_TYPE_BITS;
Brian Paul67199142014-07-29 09:17:53 -0600192
193 if (_mesa_is_gles(ctx)) {
194 legalTypesMask &= ~(FIXED_GL_BIT |
195 DOUBLE_BIT |
196 UNSIGNED_INT_10F_11F_11F_REV_BIT);
197
198 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
199 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
200 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
201 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
202 * quite as trivial as we'd like because it uses a different enum value
203 * for GL_HALF_FLOAT_OES.
204 */
205 if (ctx->Version < 30) {
206 legalTypesMask &= ~(UNSIGNED_INT_BIT |
207 INT_BIT |
208 UNSIGNED_INT_2_10_10_10_REV_BIT |
209 INT_2_10_10_10_REV_BIT |
210 HALF_BIT);
211 }
212 }
213 else {
214 legalTypesMask &= ~FIXED_ES_BIT;
215
216 if (!ctx->Extensions.ARB_ES2_compatibility)
217 legalTypesMask &= ~FIXED_GL_BIT;
218
219 if (!ctx->Extensions.ARB_vertex_type_2_10_10_10_rev)
220 legalTypesMask &= ~(UNSIGNED_INT_2_10_10_10_REV_BIT |
221 INT_2_10_10_10_REV_BIT);
222
223 if (!ctx->Extensions.ARB_vertex_type_10f_11f_11f_rev)
224 legalTypesMask &= ~UNSIGNED_INT_10F_11F_11F_REV_BIT;
225 }
226
227 return legalTypesMask;
228}
229
230
231/**
Fredrik Höglundd5543212013-04-03 21:47:44 +0200232 * Does error checking and updates the format in an attrib array.
Brian Paulf9d88c82006-06-13 17:24:36 +0000233 *
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200234 * Called by update_array() and VertexAttrib*Format().
Fredrik Höglundd5543212013-04-03 21:47:44 +0200235 *
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200236 * \param func Name of calling function used for error reporting
237 * \param attrib The index of the attribute array
238 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
239 * \param sizeMin Min allowable size value
240 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
241 * \param size Components per element (1, 2, 3 or 4)
242 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
243 * \param normalized Whether integer types are converted to floats in [-1, 1]
244 * \param integer Integer-valued values (will not be normalized to [-1, 1])
245 * \param relativeOffset Offset of the first element relative to the binding offset.
Brian Paulc5b1e812003-10-22 22:59:07 +0000246 */
Fredrik Höglundd5543212013-04-03 21:47:44 +0200247static bool
248update_array_format(struct gl_context *ctx,
249 const char *func,
250 GLuint attrib, GLbitfield legalTypesMask,
251 GLint sizeMin, GLint sizeMax,
252 GLint size, GLenum type,
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200253 GLboolean normalized, GLboolean integer,
254 GLuint relativeOffset)
Brian Paulc5b1e812003-10-22 22:59:07 +0000255{
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200256 struct gl_vertex_attrib_array *array;
Brian Paul433e5e62010-10-28 21:17:42 -0600257 GLbitfield typeBit;
Fredrik Höglundd5543212013-04-03 21:47:44 +0200258 GLuint elementSize;
Brian Paul433e5e62010-10-28 21:17:42 -0600259 GLenum format = GL_RGBA;
260
Brian Paul67199142014-07-29 09:17:53 -0600261 if (ctx->Array.LegalTypesMask == 0) {
262 /* One-time initialization. We can't do this in _mesa_init_varrays()
263 * below because extensions are not yet enabled at that point.
Ian Romanickbbceed22012-07-25 14:40:18 -0700264 */
Brian Paul67199142014-07-29 09:17:53 -0600265 ctx->Array.LegalTypesMask = get_legal_types_mask(ctx);
266 }
Ian Romanick946ddec2012-07-25 14:46:54 -0700267
Brian Paul67199142014-07-29 09:17:53 -0600268 legalTypesMask &= ctx->Array.LegalTypesMask;
269
270 if (_mesa_is_gles(ctx) && sizeMax == BGRA_OR_4) {
Ian Romanick946ddec2012-07-25 14:46:54 -0700271 /* BGRA ordering is not supported in ES contexts.
272 */
Brian Paul67199142014-07-29 09:17:53 -0600273 sizeMax = 4;
Dave Airlie6cd2d552011-08-13 15:30:38 +0100274 }
Brian Paul11dd2282010-11-07 18:35:35 -0700275
Brian Paul433e5e62010-10-28 21:17:42 -0600276 typeBit = type_to_bit(ctx, type);
277 if (typeBit == 0x0 || (typeBit & legalTypesMask) == 0x0) {
278 _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)",
279 func, _mesa_lookup_enum_by_nr(type));
Fredrik Höglundd5543212013-04-03 21:47:44 +0200280 return false;
Brian Paul433e5e62010-10-28 21:17:42 -0600281 }
282
283 /* Do size parameter checking.
284 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
285 * must be handled specially.
286 */
287 if (ctx->Extensions.EXT_vertex_array_bgra &&
288 sizeMax == BGRA_OR_4 &&
289 size == GL_BGRA) {
Fredrik Höglund0e7a61a2013-04-12 17:36:06 +0200290 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
291 *
292 * "An INVALID_OPERATION error is generated under any of the following
293 * conditions:
294 * ...
295 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
296 * or UNSIGNED_INT_2_10_10_10_REV;
297 * ...
298 * • size is BGRA and normalized is FALSE;"
299 */
Fredrik Höglundd5543212013-04-03 21:47:44 +0200300 bool bgra_error = false;
Dave Airlie99c1a582011-09-07 10:19:14 +0100301
302 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev) {
303 if (type != GL_UNSIGNED_INT_2_10_10_10_REV &&
304 type != GL_INT_2_10_10_10_REV &&
305 type != GL_UNSIGNED_BYTE)
Fredrik Höglundd5543212013-04-03 21:47:44 +0200306 bgra_error = true;
Dave Airlie99c1a582011-09-07 10:19:14 +0100307 } else if (type != GL_UNSIGNED_BYTE)
Fredrik Höglundd5543212013-04-03 21:47:44 +0200308 bgra_error = true;
Dave Airlie99c1a582011-09-07 10:19:14 +0100309
310 if (bgra_error) {
Fredrik Höglund0e7a61a2013-04-12 17:36:06 +0200311 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=GL_BGRA and type=%s)",
312 func, _mesa_lookup_enum_by_nr(type));
Fredrik Höglundd5543212013-04-03 21:47:44 +0200313 return false;
Brian Paul433e5e62010-10-28 21:17:42 -0600314 }
Fredrik Höglund0e7a61a2013-04-12 17:36:06 +0200315
316 if (!normalized) {
317 _mesa_error(ctx, GL_INVALID_OPERATION,
318 "%s(size=GL_BGRA and normalized=GL_FALSE)", func);
Fredrik Höglundd5543212013-04-03 21:47:44 +0200319 return false;
Fredrik Höglund0e7a61a2013-04-12 17:36:06 +0200320 }
321
Brian Paul433e5e62010-10-28 21:17:42 -0600322 format = GL_BGRA;
323 size = 4;
324 }
325 else if (size < sizeMin || size > sizeMax || size > 4) {
326 _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d)", func, size);
Fredrik Höglundd5543212013-04-03 21:47:44 +0200327 return false;
Brian Paul433e5e62010-10-28 21:17:42 -0600328 }
329
Dave Airlie6cd2d552011-08-13 15:30:38 +0100330 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev &&
331 (type == GL_UNSIGNED_INT_2_10_10_10_REV ||
332 type == GL_INT_2_10_10_10_REV) && size != 4) {
333 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size);
Fredrik Höglundd5543212013-04-03 21:47:44 +0200334 return false;
Dave Airlie6cd2d552011-08-13 15:30:38 +0100335 }
336
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200337 /* The ARB_vertex_attrib_binding_spec says:
338 *
339 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
340 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
341 */
342 if (relativeOffset > ctx->Const.MaxVertexAttribRelativeOffset) {
343 _mesa_error(ctx, GL_INVALID_VALUE,
344 "%s(relativeOffset=%d > "
345 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
346 func, relativeOffset);
Brian Paulfe9284a2013-11-07 15:23:34 -0700347 return false;
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200348 }
349
Chris Forbes1f092a92013-11-07 22:02:24 +1300350 if (ctx->Extensions.ARB_vertex_type_10f_11f_11f_rev &&
351 type == GL_UNSIGNED_INT_10F_11F_11F_REV && size != 3) {
352 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size);
Brian Paulfe9284a2013-11-07 15:23:34 -0700353 return false;
Chris Forbes1f092a92013-11-07 22:02:24 +1300354 }
355
Brian Paul433e5e62010-10-28 21:17:42 -0600356 ASSERT(size <= 4);
357
Fredrik Höglundd5543212013-04-03 21:47:44 +0200358 elementSize = _mesa_bytes_per_vertex_attrib(size, type);
359 assert(elementSize != -1);
360
Kenneth Graunke0dfe50f2014-02-01 19:14:38 -0800361 array = &ctx->Array.VAO->VertexAttrib[attrib];
Fredrik Höglundd5543212013-04-03 21:47:44 +0200362 array->Size = size;
363 array->Type = type;
364 array->Format = format;
365 array->Normalized = normalized;
366 array->Integer = integer;
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200367 array->RelativeOffset = relativeOffset;
Fredrik Höglundd5543212013-04-03 21:47:44 +0200368 array->_ElementSize = elementSize;
369
Kenneth Graunke0dfe50f2014-02-01 19:14:38 -0800370 ctx->Array.VAO->NewArrays |= VERT_BIT(attrib);
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200371 ctx->NewState |= _NEW_ARRAY;
372
Fredrik Höglundd5543212013-04-03 21:47:44 +0200373 return true;
374}
375
376
377/**
378 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
379 * functions.
380 *
381 * \param func name of calling function used for error reporting
382 * \param attrib the attribute array index to update
383 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
384 * \param sizeMin min allowable size value
385 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
386 * \param size components per element (1, 2, 3 or 4)
387 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
388 * \param stride stride between elements, in elements
389 * \param normalized are integer types converted to floats in [-1, 1]?
390 * \param integer integer-valued values (will not be normalized to [-1,1])
391 * \param ptr the address (or offset inside VBO) of the array data
392 */
393static void
394update_array(struct gl_context *ctx,
395 const char *func,
396 GLuint attrib, GLbitfield legalTypesMask,
397 GLint sizeMin, GLint sizeMax,
398 GLint size, GLenum type, GLsizei stride,
399 GLboolean normalized, GLboolean integer,
400 const GLvoid *ptr)
401{
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200402 struct gl_vertex_attrib_array *array;
403 GLsizei effectiveStride;
Fredrik Höglundd5543212013-04-03 21:47:44 +0200404
405 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
406 *
407 * "Client vertex arrays - all vertex array attribute pointers must
408 * refer to buffer objects (section 2.9.2). The default vertex array
409 * object (the name zero) is also deprecated. Calling
410 * VertexAttribPointer when no buffer object or no vertex array object
411 * is bound will generate an INVALID_OPERATION error..."
412 *
413 * The check for VBOs is handled below.
414 */
415 if (ctx->API == API_OPENGL_CORE
Kenneth Graunke0dfe50f2014-02-01 19:14:38 -0800416 && (ctx->Array.VAO == ctx->Array.DefaultVAO)) {
Fredrik Höglundd5543212013-04-03 21:47:44 +0200417 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(no array object bound)",
418 func);
419 return;
420 }
421
Brian Paul433e5e62010-10-28 21:17:42 -0600422 if (stride < 0) {
423 _mesa_error( ctx, GL_INVALID_VALUE, "%s(stride=%d)", func, stride );
424 return;
425 }
Brian Paule2b72492009-06-22 16:56:35 -0600426
Ian Romanick843b8762012-08-17 17:12:39 -0700427 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
428 *
429 * "An INVALID_OPERATION error is generated under any of the following
430 * conditions:
431 *
432 * ...
433 *
434 * * any of the *Pointer commands specifying the location and
435 * organization of vertex array data are called while zero is bound
436 * to the ARRAY_BUFFER buffer object binding point (see section
437 * 2.9.6), and the pointer argument is not NULL."
438 */
Kenneth Graunke0dfe50f2014-02-01 19:14:38 -0800439 if (ptr != NULL && ctx->Array.VAO->ARBsemantics &&
Brian Paulefcf5aa2011-11-29 07:44:20 -0700440 !_mesa_is_bufferobj(ctx->Array.ArrayBufferObj)) {
Brian Paul433e5e62010-10-28 21:17:42 -0600441 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-VBO array)", func);
Brian Paulf549f4c2009-11-12 23:04:26 -0700442 return;
Brian Paule2b72492009-06-22 16:56:35 -0600443 }
444
Brian Paulce193d42013-11-11 15:06:13 -0700445 if (!update_array_format(ctx, func, attrib, legalTypesMask, sizeMin,
446 sizeMax, size, type, normalized, integer, 0)) {
447 return;
448 }
449
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200450 /* Reset the vertex attrib binding */
451 vertex_attrib_binding(ctx, attrib, attrib);
452
453 /* The Stride and Ptr fields are not set by update_array_format() */
Kenneth Graunke0dfe50f2014-02-01 19:14:38 -0800454 array = &ctx->Array.VAO->VertexAttrib[attrib];
Brian Paulc5b1e812003-10-22 22:59:07 +0000455 array->Stride = stride;
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200456 array->Ptr = (const GLvoid *) ptr;
Brian Paul0077c872009-05-06 13:00:35 -0600457
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200458 /* Update the vertex buffer binding */
459 effectiveStride = stride != 0 ? stride : array->_ElementSize;
460 bind_vertex_buffer(ctx, attrib, ctx->Array.ArrayBufferObj,
461 (GLintptr) ptr, effectiveStride);
Brian Paulc5b1e812003-10-22 22:59:07 +0000462}
463
464
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000465void GLAPIENTRY
Brian Paulfbd8f211999-11-11 01:22:25 +0000466_mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
jtgafb833d1999-08-19 00:55:39 +0000467{
Brian Paulfbd8f211999-11-11 01:22:25 +0000468 GET_CURRENT_CONTEXT(ctx);
Ian Romanicke2cf14d2012-07-25 15:19:31 -0700469 GLbitfield legalTypes = (ctx->API == API_OPENGLES)
470 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
471 : (SHORT_BIT | INT_BIT | FLOAT_BIT |
472 DOUBLE_BIT | HALF_BIT |
473 UNSIGNED_INT_2_10_10_10_REV_BIT |
474 INT_2_10_10_10_REV_BIT);
Eric Anholta9754792013-01-16 16:20:38 -0800475
476 FLUSH_VERTICES(ctx, 0);
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000477
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100478 update_array(ctx, "glVertexPointer", VERT_ATTRIB_POS,
Brian Paul433e5e62010-10-28 21:17:42 -0600479 legalTypes, 2, 4,
480 size, type, stride, GL_FALSE, GL_FALSE, ptr);
jtgafb833d1999-08-19 00:55:39 +0000481}
482
483
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000484void GLAPIENTRY
Brian Paulfbd8f211999-11-11 01:22:25 +0000485_mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
jtgafb833d1999-08-19 00:55:39 +0000486{
Brian Paulfbd8f211999-11-11 01:22:25 +0000487 GET_CURRENT_CONTEXT(ctx);
Ian Romanicke5ef0cb2012-07-25 15:10:21 -0700488 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
489 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
490 : (BYTE_BIT | SHORT_BIT | INT_BIT |
491 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
492 UNSIGNED_INT_2_10_10_10_REV_BIT |
493 INT_2_10_10_10_REV_BIT);
Eric Anholta9754792013-01-16 16:20:38 -0800494
495 FLUSH_VERTICES(ctx, 0);
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000496
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100497 update_array(ctx, "glNormalPointer", VERT_ATTRIB_NORMAL,
Brian Paul433e5e62010-10-28 21:17:42 -0600498 legalTypes, 3, 3,
499 3, type, stride, GL_TRUE, GL_FALSE, ptr);
jtgafb833d1999-08-19 00:55:39 +0000500}
501
502
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000503void GLAPIENTRY
Brian Paulfbd8f211999-11-11 01:22:25 +0000504_mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
jtgafb833d1999-08-19 00:55:39 +0000505{
Brian Paulfbd8f211999-11-11 01:22:25 +0000506 GET_CURRENT_CONTEXT(ctx);
Ian Romanick07ccfef2012-07-25 14:53:01 -0700507 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
508 ? (UNSIGNED_BYTE_BIT | HALF_BIT | FLOAT_BIT | FIXED_ES_BIT)
509 : (BYTE_BIT | UNSIGNED_BYTE_BIT |
510 SHORT_BIT | UNSIGNED_SHORT_BIT |
511 INT_BIT | UNSIGNED_INT_BIT |
512 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
513 UNSIGNED_INT_2_10_10_10_REV_BIT |
514 INT_2_10_10_10_REV_BIT);
Ian Romanickfb821852012-07-25 14:58:36 -0700515 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 4 : 3;
Eric Anholta9754792013-01-16 16:20:38 -0800516
517 FLUSH_VERTICES(ctx, 0);
Brian Paulfbd8f211999-11-11 01:22:25 +0000518
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100519 update_array(ctx, "glColorPointer", VERT_ATTRIB_COLOR0,
Ian Romanickfb821852012-07-25 14:58:36 -0700520 legalTypes, sizeMin, BGRA_OR_4,
Brian Paul433e5e62010-10-28 21:17:42 -0600521 size, type, stride, GL_TRUE, 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_FogCoordPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000527{
Brian Paul433e5e62010-10-28 21:17:42 -0600528 const GLbitfield legalTypes = (HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000529 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -0800530
531 FLUSH_VERTICES(ctx, 0);
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000532
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100533 update_array(ctx, "glFogCoordPointer", VERT_ATTRIB_FOG,
Brian Paul433e5e62010-10-28 21:17:42 -0600534 legalTypes, 1, 1,
535 1, type, stride, GL_FALSE, GL_FALSE, ptr);
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000536}
537
538
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000539void GLAPIENTRY
Brian Paulfbd8f211999-11-11 01:22:25 +0000540_mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
jtgafb833d1999-08-19 00:55:39 +0000541{
Brian Paul433e5e62010-10-28 21:17:42 -0600542 const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT | INT_BIT |
543 FLOAT_BIT | DOUBLE_BIT);
Brian Paulfbd8f211999-11-11 01:22:25 +0000544 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -0800545
546 FLUSH_VERTICES(ctx, 0);
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000547
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100548 update_array(ctx, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX,
Brian Paul433e5e62010-10-28 21:17:42 -0600549 legalTypes, 1, 1,
550 1, type, stride, GL_FALSE, GL_FALSE, ptr);
jtgafb833d1999-08-19 00:55:39 +0000551}
552
553
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000554void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800555_mesa_SecondaryColorPointer(GLint size, GLenum type,
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000556 GLsizei stride, const GLvoid *ptr)
557{
Brian Paul433e5e62010-10-28 21:17:42 -0600558 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
559 SHORT_BIT | UNSIGNED_SHORT_BIT |
560 INT_BIT | UNSIGNED_INT_BIT |
Dave Airlie6cd2d552011-08-13 15:30:38 +0100561 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
562 UNSIGNED_INT_2_10_10_10_REV_BIT |
563 INT_2_10_10_10_REV_BIT);
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000564 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -0800565
566 FLUSH_VERTICES(ctx, 0);
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000567
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100568 update_array(ctx, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1,
Brian Paul433e5e62010-10-28 21:17:42 -0600569 legalTypes, 3, BGRA_OR_4,
570 size, type, stride, GL_TRUE, GL_FALSE, ptr);
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000571}
572
573
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000574void GLAPIENTRY
Brian Paul2edd1802002-01-11 17:25:35 +0000575_mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
576 const GLvoid *ptr)
jtgafb833d1999-08-19 00:55:39 +0000577{
Brian Paulfbd8f211999-11-11 01:22:25 +0000578 GET_CURRENT_CONTEXT(ctx);
Ian Romanickc3e9a202012-07-25 15:13:00 -0700579 GLbitfield legalTypes = (ctx->API == API_OPENGLES)
580 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
581 : (SHORT_BIT | INT_BIT |
582 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
583 UNSIGNED_INT_2_10_10_10_REV_BIT |
584 INT_2_10_10_10_REV_BIT);
Ian Romanicka8f475d2012-07-25 15:13:51 -0700585 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 2 : 1;
Brian Paulc5b1e812003-10-22 22:59:07 +0000586 const GLuint unit = ctx->Array.ActiveTexture;
Eric Anholta9754792013-01-16 16:20:38 -0800587
588 FLUSH_VERTICES(ctx, 0);
jtgafb833d1999-08-19 00:55:39 +0000589
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100590 update_array(ctx, "glTexCoordPointer", VERT_ATTRIB_TEX(unit),
Ian Romanicka8f475d2012-07-25 15:13:51 -0700591 legalTypes, sizeMin, 4,
Brian Paul433e5e62010-10-28 21:17:42 -0600592 size, type, stride, GL_FALSE, GL_FALSE,
Brian Pauld1184d22010-10-28 21:17:41 -0600593 ptr);
jtgafb833d1999-08-19 00:55:39 +0000594}
595
596
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000597void GLAPIENTRY
Brian Paulc5b1e812003-10-22 22:59:07 +0000598_mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr)
jtgafb833d1999-08-19 00:55:39 +0000599{
Brian Paulee1f0472010-11-02 08:22:40 -0600600 const GLbitfield legalTypes = UNSIGNED_BYTE_BIT;
Marek Olšák780ce572014-03-03 01:01:05 +0100601 /* this is the same type that glEdgeFlag uses */
602 const GLboolean integer = GL_FALSE;
Brian Paulfbd8f211999-11-11 01:22:25 +0000603 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -0800604
605 FLUSH_VERTICES(ctx, 0);
jtgafb833d1999-08-19 00:55:39 +0000606
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100607 update_array(ctx, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG,
Brian Paul433e5e62010-10-28 21:17:42 -0600608 legalTypes, 1, 1,
Brian Paulee1f0472010-11-02 08:22:40 -0600609 1, GL_UNSIGNED_BYTE, stride, GL_FALSE, integer, ptr);
jtgafb833d1999-08-19 00:55:39 +0000610}
611
612
Brian Paul1cf2c8a2008-06-25 08:45:14 -0600613void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800614_mesa_PointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *ptr)
Brian Paul1cf2c8a2008-06-25 08:45:14 -0600615{
Marek Olšák0f1e59d2011-04-29 14:23:15 +0200616 const GLbitfield legalTypes = (FLOAT_BIT | FIXED_ES_BIT);
Brian Paul1cf2c8a2008-06-25 08:45:14 -0600617 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -0800618
619 FLUSH_VERTICES(ctx, 0);
Brian Paul1cf2c8a2008-06-25 08:45:14 -0600620
Brian Paul11dd2282010-11-07 18:35:35 -0700621 if (ctx->API != API_OPENGLES) {
622 _mesa_error(ctx, GL_INVALID_OPERATION,
623 "glPointSizePointer(ES 1.x only)");
624 return;
625 }
626
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100627 update_array(ctx, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE,
Brian Paul433e5e62010-10-28 21:17:42 -0600628 legalTypes, 1, 1,
629 1, type, stride, GL_FALSE, GL_FALSE, ptr);
Brian Paul1cf2c8a2008-06-25 08:45:14 -0600630}
631
632
Brian Paula554d7c2009-05-21 15:55:33 -0600633/**
Brian Paula554d7c2009-05-21 15:55:33 -0600634 * Set a generic vertex attribute array.
635 * Note that these arrays DO NOT alias the conventional GL vertex arrays
636 * (position, normal, color, fog, texcoord, etc).
637 */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000638void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800639_mesa_VertexAttribPointer(GLuint index, GLint size, GLenum type,
Brian Paul92f97852003-05-01 22:44:02 +0000640 GLboolean normalized,
641 GLsizei stride, const GLvoid *ptr)
642{
Brian Paul433e5e62010-10-28 21:17:42 -0600643 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
644 SHORT_BIT | UNSIGNED_SHORT_BIT |
645 INT_BIT | UNSIGNED_INT_BIT |
646 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
Dave Airlie6cd2d552011-08-13 15:30:38 +0100647 FIXED_ES_BIT | FIXED_GL_BIT |
648 UNSIGNED_INT_2_10_10_10_REV_BIT |
Chris Forbes1f092a92013-11-07 22:02:24 +1300649 INT_2_10_10_10_REV_BIT |
650 UNSIGNED_INT_10F_11F_11F_REV_BIT);
Brian Paul92f97852003-05-01 22:44:02 +0000651 GET_CURRENT_CONTEXT(ctx);
Brian Paul92f97852003-05-01 22:44:02 +0000652
Paul Berry84732a92014-01-08 10:00:28 -0800653 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
Brian Paul92f97852003-05-01 22:44:02 +0000654 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(index)");
655 return;
656 }
657
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100658 update_array(ctx, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index),
Brian Paul433e5e62010-10-28 21:17:42 -0600659 legalTypes, 1, BGRA_OR_4,
660 size, type, stride, normalized, GL_FALSE, ptr);
Brian Paul92f97852003-05-01 22:44:02 +0000661}
Brian Paul92f97852003-05-01 22:44:02 +0000662
663
Brian Paule00d07c2010-05-25 21:12:24 -0600664/**
Brian Pauld1184d22010-10-28 21:17:41 -0600665 * GL_EXT_gpu_shader4 / GL 3.0.
Brian Paule00d07c2010-05-25 21:12:24 -0600666 * Set an integer-valued vertex attribute array.
667 * Note that these arrays DO NOT alias the conventional GL vertex arrays
668 * (position, normal, color, fog, texcoord, etc).
669 */
670void GLAPIENTRY
671_mesa_VertexAttribIPointer(GLuint index, GLint size, GLenum type,
Brian Paule00d07c2010-05-25 21:12:24 -0600672 GLsizei stride, const GLvoid *ptr)
673{
Brian Paul433e5e62010-10-28 21:17:42 -0600674 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
675 SHORT_BIT | UNSIGNED_SHORT_BIT |
676 INT_BIT | UNSIGNED_INT_BIT);
Brian Pauld1184d22010-10-28 21:17:41 -0600677 const GLboolean normalized = GL_FALSE;
678 const GLboolean integer = GL_TRUE;
Brian Pauld1184d22010-10-28 21:17:41 -0600679 GET_CURRENT_CONTEXT(ctx);
Brian Pauld1184d22010-10-28 21:17:41 -0600680
Paul Berry84732a92014-01-08 10:00:28 -0800681 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
Brian Pauld1184d22010-10-28 21:17:41 -0600682 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribIPointer(index)");
683 return;
684 }
685
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100686 update_array(ctx, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index),
Brian Paul433e5e62010-10-28 21:17:42 -0600687 legalTypes, 1, 4,
688 size, type, stride, normalized, integer, ptr);
Brian Paule00d07c2010-05-25 21:12:24 -0600689}
690
691
692
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000693void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800694_mesa_EnableVertexAttribArray(GLuint index)
Brian Pauld3f598a2010-05-25 21:42:13 -0600695{
Kenneth Graunkeaac14152014-02-01 19:36:59 -0800696 struct gl_vertex_array_object *vao;
Brian Pauld3f598a2010-05-25 21:42:13 -0600697 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600698
Paul Berry84732a92014-01-08 10:00:28 -0800699 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
Brian Pauld3f598a2010-05-25 21:42:13 -0600700 _mesa_error(ctx, GL_INVALID_VALUE,
701 "glEnableVertexAttribArrayARB(index)");
702 return;
703 }
704
Kenneth Graunke94e07c12014-02-01 19:31:22 -0800705 vao = ctx->Array.VAO;
Brian Pauld3f598a2010-05-25 21:42:13 -0600706
Kenneth Graunke94e07c12014-02-01 19:31:22 -0800707 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(vao->_VertexAttrib));
Brian Paul45453d82012-02-19 19:50:31 -0700708
Kenneth Graunke94e07c12014-02-01 19:31:22 -0800709 if (!vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) {
Brian Paul45453d82012-02-19 19:50:31 -0700710 /* was disabled, now being enabled */
711 FLUSH_VERTICES(ctx, _NEW_ARRAY);
Kenneth Graunke94e07c12014-02-01 19:31:22 -0800712 vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_TRUE;
713 vao->_Enabled |= VERT_BIT_GENERIC(index);
714 vao->NewArrays |= VERT_BIT_GENERIC(index);
Brian Paul45453d82012-02-19 19:50:31 -0700715 }
Brian Pauld3f598a2010-05-25 21:42:13 -0600716}
717
718
719void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800720_mesa_DisableVertexAttribArray(GLuint index)
Brian Pauld3f598a2010-05-25 21:42:13 -0600721{
Kenneth Graunkeaac14152014-02-01 19:36:59 -0800722 struct gl_vertex_array_object *vao;
Brian Pauld3f598a2010-05-25 21:42:13 -0600723 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600724
Paul Berry84732a92014-01-08 10:00:28 -0800725 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
Brian Pauld3f598a2010-05-25 21:42:13 -0600726 _mesa_error(ctx, GL_INVALID_VALUE,
Brian Paul95368f22011-04-06 14:22:39 -0600727 "glDisableVertexAttribArrayARB(index)");
Brian Pauld3f598a2010-05-25 21:42:13 -0600728 return;
729 }
730
Kenneth Graunke94e07c12014-02-01 19:31:22 -0800731 vao = ctx->Array.VAO;
Brian Pauld3f598a2010-05-25 21:42:13 -0600732
Kenneth Graunke94e07c12014-02-01 19:31:22 -0800733 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(vao->_VertexAttrib));
Brian Paul45453d82012-02-19 19:50:31 -0700734
Kenneth Graunke94e07c12014-02-01 19:31:22 -0800735 if (vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) {
Brian Paul45453d82012-02-19 19:50:31 -0700736 /* was enabled, now being disabled */
737 FLUSH_VERTICES(ctx, _NEW_ARRAY);
Kenneth Graunke94e07c12014-02-01 19:31:22 -0800738 vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_FALSE;
739 vao->_Enabled &= ~VERT_BIT_GENERIC(index);
740 vao->NewArrays |= VERT_BIT_GENERIC(index);
Brian Paul45453d82012-02-19 19:50:31 -0700741 }
Brian Pauld3f598a2010-05-25 21:42:13 -0600742}
743
744
745/**
746 * Return info for a vertex attribute array (no alias with legacy
747 * vertex attributes (pos, normal, color, etc)). This function does
748 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
749 */
750static GLuint
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400751get_vertex_array_attrib(struct gl_context *ctx, GLuint index, GLenum pname,
Brian Pauld3f598a2010-05-25 21:42:13 -0600752 const char *caller)
753{
Kenneth Graunkeaac14152014-02-01 19:36:59 -0800754 const struct gl_vertex_array_object *vao = ctx->Array.VAO;
Fredrik Höglund59b01ca2013-04-09 20:54:25 +0200755 const struct gl_vertex_attrib_array *array;
Brian Pauld3f598a2010-05-25 21:42:13 -0600756
Paul Berry84732a92014-01-08 10:00:28 -0800757 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
Brian Pauld3f598a2010-05-25 21:42:13 -0600758 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", caller, index);
759 return 0;
760 }
761
Kenneth Graunke94e07c12014-02-01 19:31:22 -0800762 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(vao->VertexAttrib));
Brian Pauld3f598a2010-05-25 21:42:13 -0600763
Kenneth Graunke94e07c12014-02-01 19:31:22 -0800764 array = &vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)];
Brian Pauld3f598a2010-05-25 21:42:13 -0600765
766 switch (pname) {
767 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
768 return array->Enabled;
769 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
Anuj Phogatfdd8beb2014-03-12 18:16:21 -0700770 return (array->Format == GL_BGRA) ? GL_BGRA : array->Size;
Brian Pauld3f598a2010-05-25 21:42:13 -0600771 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
772 return array->Stride;
773 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
774 return array->Type;
775 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
776 return array->Normalized;
777 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
Kenneth Graunke94e07c12014-02-01 19:31:22 -0800778 return vao->VertexBinding[array->VertexBinding].BufferObj->Name;
Brian Pauld1184d22010-10-28 21:17:41 -0600779 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
Ian Romanick2c870302012-07-25 16:21:49 -0700780 if ((_mesa_is_desktop_gl(ctx)
781 && (ctx->Version >= 30 || ctx->Extensions.EXT_gpu_shader4))
782 || _mesa_is_gles3(ctx)) {
Brian Pauld1184d22010-10-28 21:17:41 -0600783 return array->Integer;
784 }
Brian Paul1d1eb952011-01-15 10:32:34 -0700785 goto error;
786 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB:
Ian Romanick2c870302012-07-25 16:21:49 -0700787 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_instanced_arrays)
788 || _mesa_is_gles3(ctx)) {
Kenneth Graunke94e07c12014-02-01 19:31:22 -0800789 return vao->VertexBinding[array->VertexBinding].InstanceDivisor;
Brian Paul1d1eb952011-01-15 10:32:34 -0700790 }
791 goto error;
Fredrik Höglundfb370f82013-04-04 22:15:13 +0200792 case GL_VERTEX_ATTRIB_BINDING:
793 if (_mesa_is_desktop_gl(ctx)) {
794 return array->VertexBinding - VERT_ATTRIB_GENERIC0;
795 }
796 goto error;
797 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET:
798 if (_mesa_is_desktop_gl(ctx)) {
799 return array->RelativeOffset;
800 }
801 goto error;
Brian Pauld3f598a2010-05-25 21:42:13 -0600802 default:
Brian Paul1d1eb952011-01-15 10:32:34 -0700803 ; /* fall-through */
Brian Pauld3f598a2010-05-25 21:42:13 -0600804 }
Brian Paul1d1eb952011-01-15 10:32:34 -0700805
806error:
807 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", caller, pname);
808 return 0;
Brian Pauld3f598a2010-05-25 21:42:13 -0600809}
810
811
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800812static const GLfloat *
813get_current_attrib(struct gl_context *ctx, GLuint index, const char *function)
814{
815 if (index == 0) {
Anuj Phogat49c71052014-03-28 17:44:59 -0700816 if (_mesa_attr_zero_aliases_vertex(ctx)) {
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800817 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(index==0)", function);
818 return NULL;
819 }
820 }
Paul Berry84732a92014-01-08 10:00:28 -0800821 else if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800822 _mesa_error(ctx, GL_INVALID_VALUE,
823 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function);
824 return NULL;
825 }
826
Kenneth Graunke0dfe50f2014-02-01 19:14:38 -0800827 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.VAO->_VertexAttrib));
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100828
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800829 FLUSH_CURRENT(ctx, 0);
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100830 return ctx->Current.Attrib[VERT_ATTRIB_GENERIC(index)];
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800831}
832
Brian Pauld3f598a2010-05-25 21:42:13 -0600833void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800834_mesa_GetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
Brian Pauld3f598a2010-05-25 21:42:13 -0600835{
836 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600837
838 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800839 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribfv");
840 if (v != NULL) {
Brian Pauld3f598a2010-05-25 21:42:13 -0600841 COPY_4V(params, v);
842 }
843 }
844 else {
845 params[0] = (GLfloat) get_vertex_array_attrib(ctx, index, pname,
846 "glGetVertexAttribfv");
847 }
848}
849
850
851void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800852_mesa_GetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params)
Brian Pauld3f598a2010-05-25 21:42:13 -0600853{
854 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600855
856 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800857 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribdv");
858 if (v != NULL) {
Brian Pauld3f598a2010-05-25 21:42:13 -0600859 params[0] = (GLdouble) v[0];
860 params[1] = (GLdouble) v[1];
861 params[2] = (GLdouble) v[2];
862 params[3] = (GLdouble) v[3];
863 }
864 }
865 else {
866 params[0] = (GLdouble) get_vertex_array_attrib(ctx, index, pname,
867 "glGetVertexAttribdv");
868 }
869}
870
871
872void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800873_mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params)
Brian Pauld3f598a2010-05-25 21:42:13 -0600874{
875 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600876
877 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800878 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribiv");
879 if (v != NULL) {
Brian Pauld3f598a2010-05-25 21:42:13 -0600880 /* XXX should floats in[0,1] be scaled to full int range? */
881 params[0] = (GLint) v[0];
882 params[1] = (GLint) v[1];
883 params[2] = (GLint) v[2];
884 params[3] = (GLint) v[3];
885 }
886 }
887 else {
888 params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname,
889 "glGetVertexAttribiv");
890 }
891}
892
893
894/** GL 3.0 */
895void GLAPIENTRY
896_mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
897{
898 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600899
900 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
Kenneth Graunkec299f442012-11-07 20:29:40 -0800901 const GLint *v = (const GLint *)
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800902 get_current_attrib(ctx, index, "glGetVertexAttribIiv");
903 if (v != NULL) {
Kenneth Graunkec299f442012-11-07 20:29:40 -0800904 COPY_4V(params, v);
Brian Pauld3f598a2010-05-25 21:42:13 -0600905 }
906 }
907 else {
908 params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname,
909 "glGetVertexAttribIiv");
910 }
911}
912
913
914/** GL 3.0 */
915void GLAPIENTRY
916_mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
917{
918 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600919
920 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
Kenneth Graunkec299f442012-11-07 20:29:40 -0800921 const GLuint *v = (const GLuint *)
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800922 get_current_attrib(ctx, index, "glGetVertexAttribIuiv");
923 if (v != NULL) {
Kenneth Graunkec299f442012-11-07 20:29:40 -0800924 COPY_4V(params, v);
Brian Pauld3f598a2010-05-25 21:42:13 -0600925 }
926 }
927 else {
928 params[0] = get_vertex_array_attrib(ctx, index, pname,
929 "glGetVertexAttribIuiv");
930 }
931}
932
933
934void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800935_mesa_GetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer)
Brian Pauld3f598a2010-05-25 21:42:13 -0600936{
937 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600938
Paul Berry84732a92014-01-08 10:00:28 -0800939 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
Brian Pauld3f598a2010-05-25 21:42:13 -0600940 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
941 return;
942 }
943
944 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
945 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
946 return;
947 }
948
Kenneth Graunke0dfe50f2014-02-01 19:14:38 -0800949 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.VAO->_VertexAttrib));
Brian Pauld3f598a2010-05-25 21:42:13 -0600950
Kenneth Graunke0dfe50f2014-02-01 19:14:38 -0800951 *pointer = (GLvoid *) ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr;
Brian Pauld3f598a2010-05-25 21:42:13 -0600952}
953
954
955void GLAPIENTRY
Brian Paul1f0e2132000-06-12 15:30:51 +0000956_mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
957 GLsizei count, const GLvoid *ptr)
958{
959 (void) count;
960 _mesa_VertexPointer(size, type, stride, ptr);
961}
962
963
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000964void GLAPIENTRY
Brian Paul1f0e2132000-06-12 15:30:51 +0000965_mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
966 const GLvoid *ptr)
967{
968 (void) count;
969 _mesa_NormalPointer(type, stride, ptr);
970}
971
972
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000973void GLAPIENTRY
Brian Paul1f0e2132000-06-12 15:30:51 +0000974_mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
975 const GLvoid *ptr)
976{
977 (void) count;
978 _mesa_ColorPointer(size, type, stride, ptr);
979}
980
981
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000982void GLAPIENTRY
Brian Paul1f0e2132000-06-12 15:30:51 +0000983_mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
984 const GLvoid *ptr)
985{
986 (void) count;
987 _mesa_IndexPointer(type, stride, ptr);
988}
989
990
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000991void GLAPIENTRY
Brian Paul1f0e2132000-06-12 15:30:51 +0000992_mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
993 GLsizei count, const GLvoid *ptr)
994{
995 (void) count;
996 _mesa_TexCoordPointer(size, type, stride, ptr);
997}
998
999
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001000void GLAPIENTRY
Brian Paul1f0e2132000-06-12 15:30:51 +00001001_mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
1002{
1003 (void) count;
1004 _mesa_EdgeFlagPointer(stride, ptr);
1005}
1006
1007
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001008void GLAPIENTRY
Brian Paulfbd8f211999-11-11 01:22:25 +00001009_mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
jtgafb833d1999-08-19 00:55:39 +00001010{
Brian Paulfbd8f211999-11-11 01:22:25 +00001011 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +00001012 GLboolean tflag, cflag, nflag; /* enable/disable flags */
1013 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
Keith Whitwellf4b02d12001-01-05 05:31:42 +00001014 GLenum ctype = 0; /* color type */
1015 GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
Brian Paul4a3110f2003-12-12 18:40:02 +00001016 const GLint toffset = 0; /* always zero */
jtgafb833d1999-08-19 00:55:39 +00001017 GLint defstride; /* default stride */
1018 GLint c, f;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001019
Eric Anholta9754792013-01-16 16:20:38 -08001020 FLUSH_VERTICES(ctx, 0);
Keith Whitwellcab974c2000-12-26 05:09:27 +00001021
jtgafb833d1999-08-19 00:55:39 +00001022 f = sizeof(GLfloat);
Brian Paulc5b1e812003-10-22 22:59:07 +00001023 c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
jtgafb833d1999-08-19 00:55:39 +00001024
Brian Paulc5b1e812003-10-22 22:59:07 +00001025 if (stride < 0) {
Brian Paul08836342001-03-03 20:33:27 +00001026 _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
jtgafb833d1999-08-19 00:55:39 +00001027 return;
1028 }
1029
1030 switch (format) {
1031 case GL_V2F:
1032 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1033 tcomps = 0; ccomps = 0; vcomps = 2;
1034 voffset = 0;
1035 defstride = 2*f;
1036 break;
1037 case GL_V3F:
1038 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1039 tcomps = 0; ccomps = 0; vcomps = 3;
1040 voffset = 0;
1041 defstride = 3*f;
1042 break;
1043 case GL_C4UB_V2F:
1044 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1045 tcomps = 0; ccomps = 4; vcomps = 2;
1046 ctype = GL_UNSIGNED_BYTE;
1047 coffset = 0;
1048 voffset = c;
1049 defstride = c + 2*f;
1050 break;
1051 case GL_C4UB_V3F:
1052 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1053 tcomps = 0; ccomps = 4; vcomps = 3;
1054 ctype = GL_UNSIGNED_BYTE;
1055 coffset = 0;
1056 voffset = c;
1057 defstride = c + 3*f;
1058 break;
1059 case GL_C3F_V3F:
1060 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1061 tcomps = 0; ccomps = 3; vcomps = 3;
1062 ctype = GL_FLOAT;
1063 coffset = 0;
1064 voffset = 3*f;
1065 defstride = 6*f;
1066 break;
1067 case GL_N3F_V3F:
1068 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
1069 tcomps = 0; ccomps = 0; vcomps = 3;
1070 noffset = 0;
1071 voffset = 3*f;
1072 defstride = 6*f;
1073 break;
1074 case GL_C4F_N3F_V3F:
1075 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
1076 tcomps = 0; ccomps = 4; vcomps = 3;
1077 ctype = GL_FLOAT;
1078 coffset = 0;
1079 noffset = 4*f;
1080 voffset = 7*f;
1081 defstride = 10*f;
1082 break;
1083 case GL_T2F_V3F:
1084 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1085 tcomps = 2; ccomps = 0; vcomps = 3;
1086 voffset = 2*f;
1087 defstride = 5*f;
1088 break;
1089 case GL_T4F_V4F:
1090 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1091 tcomps = 4; ccomps = 0; vcomps = 4;
1092 voffset = 4*f;
1093 defstride = 8*f;
1094 break;
1095 case GL_T2F_C4UB_V3F:
1096 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1097 tcomps = 2; ccomps = 4; vcomps = 3;
1098 ctype = GL_UNSIGNED_BYTE;
1099 coffset = 2*f;
1100 voffset = c+2*f;
1101 defstride = c+5*f;
1102 break;
1103 case GL_T2F_C3F_V3F:
1104 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1105 tcomps = 2; ccomps = 3; vcomps = 3;
1106 ctype = GL_FLOAT;
1107 coffset = 2*f;
1108 voffset = 5*f;
1109 defstride = 8*f;
1110 break;
1111 case GL_T2F_N3F_V3F:
1112 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
1113 tcomps = 2; ccomps = 0; vcomps = 3;
1114 noffset = 2*f;
1115 voffset = 5*f;
1116 defstride = 8*f;
1117 break;
1118 case GL_T2F_C4F_N3F_V3F:
1119 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1120 tcomps = 2; ccomps = 4; vcomps = 3;
1121 ctype = GL_FLOAT;
1122 coffset = 2*f;
1123 noffset = 6*f;
1124 voffset = 9*f;
1125 defstride = 12*f;
1126 break;
1127 case GL_T4F_C4F_N3F_V4F:
1128 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1129 tcomps = 4; ccomps = 4; vcomps = 4;
1130 ctype = GL_FLOAT;
1131 coffset = 4*f;
1132 noffset = 8*f;
1133 voffset = 11*f;
1134 defstride = 15*f;
1135 break;
1136 default:
Brian Paul08836342001-03-03 20:33:27 +00001137 _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
jtgafb833d1999-08-19 00:55:39 +00001138 return;
1139 }
1140
1141 if (stride==0) {
1142 stride = defstride;
1143 }
1144
Brian Paulfbd8f211999-11-11 01:22:25 +00001145 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
1146 _mesa_DisableClientState( GL_INDEX_ARRAY );
Brian Paul095c6692006-04-25 00:21:32 +00001147 /* XXX also disable secondary color and generic arrays? */
jtgafb833d1999-08-19 00:55:39 +00001148
1149 /* Texcoords */
jtgafb833d1999-08-19 00:55:39 +00001150 if (tflag) {
Brian Paul4a3110f2003-12-12 18:40:02 +00001151 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
1152 _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
Brian Paulab928e52004-03-10 16:17:35 +00001153 (GLubyte *) pointer + toffset );
jtgafb833d1999-08-19 00:55:39 +00001154 }
1155 else {
Brian Paulab928e52004-03-10 16:17:35 +00001156 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
jtgafb833d1999-08-19 00:55:39 +00001157 }
jtgafb833d1999-08-19 00:55:39 +00001158
1159 /* Color */
1160 if (cflag) {
Brian Paulfbd8f211999-11-11 01:22:25 +00001161 _mesa_EnableClientState( GL_COLOR_ARRAY );
Keith Whitwellcab974c2000-12-26 05:09:27 +00001162 _mesa_ColorPointer( ccomps, ctype, stride,
Brian Paul4a3110f2003-12-12 18:40:02 +00001163 (GLubyte *) pointer + coffset );
jtgafb833d1999-08-19 00:55:39 +00001164 }
1165 else {
Brian Paulfbd8f211999-11-11 01:22:25 +00001166 _mesa_DisableClientState( GL_COLOR_ARRAY );
jtgafb833d1999-08-19 00:55:39 +00001167 }
1168
1169
1170 /* Normals */
1171 if (nflag) {
Brian Paulfbd8f211999-11-11 01:22:25 +00001172 _mesa_EnableClientState( GL_NORMAL_ARRAY );
Brian Paul4a3110f2003-12-12 18:40:02 +00001173 _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset );
jtgafb833d1999-08-19 00:55:39 +00001174 }
1175 else {
Brian Paulfbd8f211999-11-11 01:22:25 +00001176 _mesa_DisableClientState( GL_NORMAL_ARRAY );
jtgafb833d1999-08-19 00:55:39 +00001177 }
1178
Brian Paul4a3110f2003-12-12 18:40:02 +00001179 /* Vertices */
Brian Paulfbd8f211999-11-11 01:22:25 +00001180 _mesa_EnableClientState( GL_VERTEX_ARRAY );
Keith Whitwellcab974c2000-12-26 05:09:27 +00001181 _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
1182 (GLubyte *) pointer + voffset );
jtgafb833d1999-08-19 00:55:39 +00001183}
1184
1185
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001186void GLAPIENTRY
Keith Whitwellad2ac212000-11-24 10:25:05 +00001187_mesa_LockArraysEXT(GLint first, GLsizei count)
1188{
1189 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -08001190
1191 FLUSH_VERTICES(ctx, 0);
Keith Whitwellad2ac212000-11-24 10:25:05 +00001192
1193 if (MESA_VERBOSE & VERBOSE_API)
Brian Paul4753d602002-06-15 02:38:15 +00001194 _mesa_debug(ctx, "glLockArrays %d %d\n", first, count);
Keith Whitwellad2ac212000-11-24 10:25:05 +00001195
Eric Anholt5857e982008-02-02 02:54:13 -08001196 if (first < 0) {
1197 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" );
1198 return;
Gareth Hughes22144ab2001-03-12 00:48:37 +00001199 }
Eric Anholt5857e982008-02-02 02:54:13 -08001200 if (count <= 0) {
1201 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" );
1202 return;
Keith Whitwellad2ac212000-11-24 10:25:05 +00001203 }
Eric Anholt5857e982008-02-02 02:54:13 -08001204 if (ctx->Array.LockCount != 0) {
1205 _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" );
1206 return;
1207 }
1208
1209 ctx->Array.LockFirst = first;
1210 ctx->Array.LockCount = count;
Keith Whitwellad2ac212000-11-24 10:25:05 +00001211
1212 ctx->NewState |= _NEW_ARRAY;
Keith Whitwellad2ac212000-11-24 10:25:05 +00001213}
1214
1215
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001216void GLAPIENTRY
Keith Whitwellad2ac212000-11-24 10:25:05 +00001217_mesa_UnlockArraysEXT( void )
1218{
1219 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -08001220
1221 FLUSH_VERTICES(ctx, 0);
Keith Whitwellad2ac212000-11-24 10:25:05 +00001222
1223 if (MESA_VERBOSE & VERBOSE_API)
Brian Paul4753d602002-06-15 02:38:15 +00001224 _mesa_debug(ctx, "glUnlockArrays\n");
Keith Whitwellad2ac212000-11-24 10:25:05 +00001225
Eric Anholt5857e982008-02-02 02:54:13 -08001226 if (ctx->Array.LockCount == 0) {
1227 _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" );
1228 return;
1229 }
1230
Keith Whitwellad2ac212000-11-24 10:25:05 +00001231 ctx->Array.LockFirst = 0;
1232 ctx->Array.LockCount = 0;
1233 ctx->NewState |= _NEW_ARRAY;
Keith Whitwellad2ac212000-11-24 10:25:05 +00001234}
Brian Paul2525bc72002-06-30 15:47:00 +00001235
1236
Brian Paul2525bc72002-06-30 15:47:00 +00001237/* GL_EXT_multi_draw_arrays */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001238void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -08001239_mesa_MultiDrawArrays( GLenum mode, const GLint *first,
Brian Paul79938322010-09-14 09:37:35 -06001240 const GLsizei *count, GLsizei primcount )
Brian Paul2525bc72002-06-30 15:47:00 +00001241{
1242 GET_CURRENT_CONTEXT(ctx);
1243 GLint i;
1244
Eric Anholta9754792013-01-16 16:20:38 -08001245 FLUSH_VERTICES(ctx, 0);
Brian Paul2525bc72002-06-30 15:47:00 +00001246
1247 for (i = 0; i < primcount; i++) {
1248 if (count[i] > 0) {
Brian Paule3418562014-03-26 17:08:20 -06001249 CALL_DrawArrays(ctx->CurrentDispatch, (mode, first[i], count[i]));
Brian Paul2525bc72002-06-30 15:47:00 +00001250 }
1251 }
1252}
1253
1254
Ian Romanick3baefe62003-08-22 23:28:03 +00001255/* GL_IBM_multimode_draw_arrays */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001256void GLAPIENTRY
Ian Romanick3baefe62003-08-22 23:28:03 +00001257_mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
1258 const GLsizei * count,
1259 GLsizei primcount, GLint modestride )
1260{
1261 GET_CURRENT_CONTEXT(ctx);
1262 GLint i;
1263
Eric Anholta9754792013-01-16 16:20:38 -08001264 FLUSH_VERTICES(ctx, 0);
Ian Romanick3baefe62003-08-22 23:28:03 +00001265
1266 for ( i = 0 ; i < primcount ; i++ ) {
1267 if ( count[i] > 0 ) {
Brian Paul03e29a52003-12-04 03:16:27 +00001268 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
Brian Paule3418562014-03-26 17:08:20 -06001269 CALL_DrawArrays(ctx->CurrentDispatch, ( m, first[i], count[i] ));
Ian Romanick3baefe62003-08-22 23:28:03 +00001270 }
1271 }
1272}
1273
1274
1275/* GL_IBM_multimode_draw_arrays */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001276void GLAPIENTRY
Ian Romanick3baefe62003-08-22 23:28:03 +00001277_mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
1278 GLenum type, const GLvoid * const * indices,
1279 GLsizei primcount, GLint modestride )
1280{
1281 GET_CURRENT_CONTEXT(ctx);
1282 GLint i;
1283
Eric Anholta9754792013-01-16 16:20:38 -08001284 FLUSH_VERTICES(ctx, 0);
Ian Romanick3baefe62003-08-22 23:28:03 +00001285
Brian Pauld2afb392003-09-17 18:15:13 +00001286 /* XXX not sure about ARB_vertex_buffer_object handling here */
1287
Ian Romanick3baefe62003-08-22 23:28:03 +00001288 for ( i = 0 ; i < primcount ; i++ ) {
1289 if ( count[i] > 0 ) {
Brian Paul03e29a52003-12-04 03:16:27 +00001290 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
Brian Paule3418562014-03-26 17:08:20 -06001291 CALL_DrawElements(ctx->CurrentDispatch, ( m, count[i], type,
1292 indices[i] ));
Ian Romanick3baefe62003-08-22 23:28:03 +00001293 }
1294 }
1295}
1296
1297
Brian Paul095c6692006-04-25 00:21:32 +00001298/**
Brian Paul7f26ad82010-10-21 19:03:38 -06001299 * GL_NV_primitive_restart and GL 3.1
Brian Paula40e6f22010-04-20 21:02:09 -06001300 */
1301void GLAPIENTRY
1302_mesa_PrimitiveRestartIndex(GLuint index)
1303{
1304 GET_CURRENT_CONTEXT(ctx);
1305
Eric Anholt9c1b4182012-07-26 14:43:56 -07001306 if (!ctx->Extensions.NV_primitive_restart && ctx->Version < 31) {
Brian Paul7f26ad82010-10-21 19:03:38 -06001307 _mesa_error(ctx, GL_INVALID_OPERATION, "glPrimitiveRestartIndexNV()");
Brian Paula40e6f22010-04-20 21:02:09 -06001308 return;
1309 }
1310
Kenneth Graunkee6efb902013-05-29 08:31:54 -07001311 if (ctx->Array.RestartIndex != index) {
Brian Pauld2003ee2012-02-19 19:50:32 -07001312 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
Kenneth Graunkee6efb902013-05-29 08:31:54 -07001313 ctx->Array.RestartIndex = index;
Brian Pauld2003ee2012-02-19 19:50:32 -07001314 }
Brian Paula40e6f22010-04-20 21:02:09 -06001315}
1316
1317
1318/**
Brian Paul1d1eb952011-01-15 10:32:34 -07001319 * See GL_ARB_instanced_arrays.
1320 * Note that the instance divisor only applies to generic arrays, not
1321 * the legacy vertex arrays.
1322 */
1323void GLAPIENTRY
1324_mesa_VertexAttribDivisor(GLuint index, GLuint divisor)
1325{
1326 GET_CURRENT_CONTEXT(ctx);
Brian Paul1d1eb952011-01-15 10:32:34 -07001327
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001328 const GLuint genericIndex = VERT_ATTRIB_GENERIC(index);
1329
Brian Paul1d1eb952011-01-15 10:32:34 -07001330 if (!ctx->Extensions.ARB_instanced_arrays) {
1331 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()");
1332 return;
1333 }
1334
Paul Berry84732a92014-01-08 10:00:28 -08001335 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
Matt Turnerae1f09b2012-11-13 13:05:03 -08001336 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribDivisor(index = %u)",
Brian Paul1d1eb952011-01-15 10:32:34 -07001337 index);
1338 return;
1339 }
1340
Kenneth Graunke0dfe50f2014-02-01 19:14:38 -08001341 ASSERT(genericIndex < Elements(ctx->Array.VAO->VertexAttrib));
Mathias Fröhlich762c9762011-10-31 22:23:51 +01001342
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001343 /* The ARB_vertex_attrib_binding spec says:
1344 *
1345 * "The command
1346 *
1347 * void VertexAttribDivisor(uint index, uint divisor);
1348 *
1349 * is equivalent to (assuming no errors are generated):
1350 *
1351 * VertexAttribBinding(index, index);
1352 * VertexBindingDivisor(index, divisor);"
1353 */
1354 vertex_attrib_binding(ctx, genericIndex, genericIndex);
1355 vertex_binding_divisor(ctx, genericIndex, divisor);
Brian Paul1d1eb952011-01-15 10:32:34 -07001356}
1357
1358
Kenneth Graunke959d0762013-05-29 08:07:01 -07001359unsigned
1360_mesa_primitive_restart_index(const struct gl_context *ctx, GLenum ib_type)
1361{
1362 /* From the OpenGL 4.3 core specification, page 302:
1363 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1364 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1365 * is used."
1366 */
1367 if (ctx->Array.PrimitiveRestartFixedIndex) {
1368 switch (ib_type) {
1369 case GL_UNSIGNED_BYTE:
1370 return 0xff;
1371 case GL_UNSIGNED_SHORT:
1372 return 0xffff;
1373 case GL_UNSIGNED_INT:
1374 return 0xffffffff;
1375 default:
1376 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1377 }
1378 }
1379
1380 return ctx->Array.RestartIndex;
1381}
1382
Brian Paul1d1eb952011-01-15 10:32:34 -07001383
1384/**
Fredrik Höglundbb2d02c2013-04-09 20:44:58 +02001385 * GL_ARB_vertex_attrib_binding
1386 */
1387void GLAPIENTRY
1388_mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
1389 GLsizei stride)
1390{
Fredrik Höglund193e8b42013-04-11 16:49:44 +02001391 GET_CURRENT_CONTEXT(ctx);
Kenneth Graunkeaac14152014-02-01 19:36:59 -08001392 const struct gl_vertex_array_object *vao = ctx->Array.VAO;
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001393 struct gl_buffer_object *vbo;
1394
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001395 ASSERT_OUTSIDE_BEGIN_END(ctx);
1396
1397 /* The ARB_vertex_attrib_binding spec says:
1398 *
1399 * "An INVALID_OPERATION error is generated if no vertex array object
1400 * is bound."
1401 */
1402 if (ctx->API == API_OPENGL_CORE &&
Kenneth Graunke0dfe50f2014-02-01 19:14:38 -08001403 ctx->Array.VAO == ctx->Array.DefaultVAO) {
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001404 _mesa_error(ctx, GL_INVALID_OPERATION,
1405 "glBindVertexBuffer(No array object bound)");
1406 return;
1407 }
1408
1409 /* The ARB_vertex_attrib_binding spec says:
1410 *
1411 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1412 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1413 */
1414 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
1415 _mesa_error(ctx, GL_INVALID_VALUE,
1416 "glBindVertexBuffer(bindingindex=%u > "
1417 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1418 bindingIndex);
1419 return;
1420 }
1421
1422 /* The ARB_vertex_attrib_binding spec says:
1423 *
1424 * "The error INVALID_VALUE is generated if <stride> or <offset>
1425 * are negative."
1426 */
1427 if (offset < 0) {
1428 _mesa_error(ctx, GL_INVALID_VALUE,
Brian Paul80fa7fd2014-08-08 07:49:33 -06001429 "glBindVertexBuffer(offset=%" PRId64 " < 0)",
1430 (int64_t) offset);
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001431 return;
1432 }
1433
1434 if (stride < 0) {
1435 _mesa_error(ctx, GL_INVALID_VALUE,
1436 "glBindVertexBuffer(stride=%d < 0)", stride);
1437 return;
1438 }
1439
Kenneth Graunke94e07c12014-02-01 19:31:22 -08001440 if (buffer == vao->VertexBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj->Name) {
1441 vbo = vao->VertexBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj;
Fredrik Höglund193e8b42013-04-11 16:49:44 +02001442 } else if (buffer != 0) {
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001443 vbo = _mesa_lookup_bufferobj(ctx, buffer);
1444
1445 /* From the GL_ARB_vertex_attrib_array spec:
1446 *
1447 * "[Core profile only:]
1448 * An INVALID_OPERATION error is generated if buffer is not zero or a
1449 * name returned from a previous call to GenBuffers, or if such a name
1450 * has since been deleted with DeleteBuffers.
1451 *
1452 * Otherwise, we fall back to the same compat profile behavior as other
1453 * object references (automatically gen it).
1454 */
1455 if (!_mesa_handle_bind_buffer_gen(ctx, GL_ARRAY_BUFFER, buffer,
1456 &vbo, "glBindVertexBuffer"))
1457 return;
1458 } else {
1459 /* The ARB_vertex_attrib_binding spec says:
1460 *
1461 * "If <buffer> is zero, any buffer object attached to this
1462 * bindpoint is detached."
1463 */
1464 vbo = ctx->Shared->NullBufferObj;
1465 }
1466
1467 bind_vertex_buffer(ctx, VERT_ATTRIB_GENERIC(bindingIndex),
1468 vbo, offset, stride);
Fredrik Höglundbb2d02c2013-04-09 20:44:58 +02001469}
1470
1471
1472void GLAPIENTRY
Fredrik Höglund6655e702013-11-13 19:02:10 +01001473_mesa_BindVertexBuffers(GLuint first, GLsizei count, const GLuint *buffers,
1474 const GLintptr *offsets, const GLsizei *strides)
1475{
Fredrik Höglund63995b92013-11-15 20:01:07 +01001476 GET_CURRENT_CONTEXT(ctx);
1477 struct gl_vertex_array_object * const vao = ctx->Array.VAO;
1478 GLuint i;
1479
1480 ASSERT_OUTSIDE_BEGIN_END(ctx);
1481
1482 /* The ARB_vertex_attrib_binding spec says:
1483 *
1484 * "An INVALID_OPERATION error is generated if no
1485 * vertex array object is bound."
1486 */
1487 if (ctx->API == API_OPENGL_CORE &&
1488 ctx->Array.VAO == ctx->Array.DefaultVAO) {
1489 _mesa_error(ctx, GL_INVALID_OPERATION,
1490 "glBindVertexBuffers(No array object bound)");
1491 return;
1492 }
1493
1494 /* The ARB_multi_bind spec says:
1495 *
1496 * "An INVALID_OPERATION error is generated if <first> + <count>
1497 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
1498 */
1499 if (first + count > ctx->Const.MaxVertexAttribBindings) {
1500 _mesa_error(ctx, GL_INVALID_OPERATION,
1501 "glBindVertexBuffers(first=%u + count=%d > the value of "
1502 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
1503 first, count, ctx->Const.MaxVertexAttribBindings);
1504 return;
1505 }
1506
1507 if (!buffers) {
1508 /**
1509 * The ARB_multi_bind spec says:
1510 *
1511 * "If <buffers> is NULL, each affected vertex buffer binding point
1512 * from <first> through <first>+<count>-1 will be reset to have no
1513 * bound buffer object. In this case, the offsets and strides
1514 * associated with the binding points are set to default values,
1515 * ignoring <offsets> and <strides>."
1516 */
1517 struct gl_buffer_object *vbo = ctx->Shared->NullBufferObj;
1518
1519 for (i = 0; i < count; i++)
1520 bind_vertex_buffer(ctx, VERT_ATTRIB_GENERIC(first + i), vbo, 0, 16);
1521
1522 return;
1523 }
1524
1525 /* Note that the error semantics for multi-bind commands differ from
1526 * those of other GL commands.
1527 *
1528 * The Issues section in the ARB_multi_bind spec says:
1529 *
1530 * "(11) Typically, OpenGL specifies that if an error is generated by
1531 * a command, that command has no effect. This is somewhat
1532 * unfortunate for multi-bind commands, because it would require
1533 * a first pass to scan the entire list of bound objects for
1534 * errors and then a second pass to actually perform the
1535 * bindings. Should we have different error semantics?
1536 *
1537 * RESOLVED: Yes. In this specification, when the parameters for
1538 * one of the <count> binding points are invalid, that binding
1539 * point is not updated and an error will be generated. However,
1540 * other binding points in the same command will be updated if
1541 * their parameters are valid and no other error occurs."
1542 */
1543
1544 _mesa_begin_bufferobj_lookups(ctx);
1545
1546 for (i = 0; i < count; i++) {
1547 struct gl_buffer_object *vbo;
1548
1549 /* The ARB_multi_bind spec says:
1550 *
1551 * "An INVALID_VALUE error is generated if any value in
1552 * <offsets> or <strides> is negative (per binding)."
1553 */
1554 if (offsets[i] < 0) {
1555 _mesa_error(ctx, GL_INVALID_VALUE,
Brian Paul80fa7fd2014-08-08 07:49:33 -06001556 "glBindVertexBuffer(offsets[%u]=%" PRId64 " < 0)",
1557 i, (int64_t) offsets[i]);
Fredrik Höglund63995b92013-11-15 20:01:07 +01001558 continue;
1559 }
1560
1561 if (strides[i] < 0) {
1562 _mesa_error(ctx, GL_INVALID_VALUE,
Brian Paul80fa7fd2014-08-08 07:49:33 -06001563 "glBindVertexBuffer(strides[%u]=%d < 0)",
1564 i, strides[i]);
Fredrik Höglund63995b92013-11-15 20:01:07 +01001565 continue;
1566 }
1567
1568 if (buffers[i]) {
1569 struct gl_vertex_buffer_binding *binding =
1570 &vao->VertexBinding[VERT_ATTRIB_GENERIC(first + i)];
1571
1572 if (buffers[i] == binding->BufferObj->Name)
1573 vbo = binding->BufferObj;
1574 else
1575 vbo = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, i,
1576 "glBindVertexBuffers");
1577
1578 if (!vbo)
1579 continue;
1580 } else {
1581 vbo = ctx->Shared->NullBufferObj;
1582 }
1583
1584 bind_vertex_buffer(ctx, VERT_ATTRIB_GENERIC(first + i), vbo,
1585 offsets[i], strides[i]);
1586 }
1587
1588 _mesa_end_bufferobj_lookups(ctx);
Fredrik Höglund6655e702013-11-13 19:02:10 +01001589}
1590
1591
1592void GLAPIENTRY
Fredrik Höglundbb2d02c2013-04-09 20:44:58 +02001593_mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type,
1594 GLboolean normalized, GLuint relativeOffset)
1595{
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001596 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
1597 SHORT_BIT | UNSIGNED_SHORT_BIT |
1598 INT_BIT | UNSIGNED_INT_BIT |
1599 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
1600 FIXED_GL_BIT |
1601 UNSIGNED_INT_2_10_10_10_REV_BIT |
Chris Forbes1f092a92013-11-07 22:02:24 +13001602 INT_2_10_10_10_REV_BIT |
1603 UNSIGNED_INT_10F_11F_11F_REV_BIT);
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001604
1605 GET_CURRENT_CONTEXT(ctx);
1606 ASSERT_OUTSIDE_BEGIN_END(ctx);
1607
1608 /* The ARB_vertex_attrib_binding spec says:
1609 *
1610 * "An INVALID_OPERATION error is generated under any of the following
1611 * conditions:
1612 * - if no vertex array object is currently bound (see section 2.10);
1613 * - ..."
1614 */
1615 if (ctx->API == API_OPENGL_CORE &&
Kenneth Graunke0dfe50f2014-02-01 19:14:38 -08001616 ctx->Array.VAO == ctx->Array.DefaultVAO) {
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001617 _mesa_error(ctx, GL_INVALID_OPERATION,
1618 "glVertexAttribFormat(No array object bound)");
1619 return;
1620 }
1621
1622 /* The ARB_vertex_attrib_binding spec says:
1623 *
1624 * "The error INVALID_VALUE is generated if index is greater than or equal
1625 * to the value of MAX_VERTEX_ATTRIBS."
1626 */
Paul Berry84732a92014-01-08 10:00:28 -08001627 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001628 _mesa_error(ctx, GL_INVALID_VALUE,
1629 "glVertexAttribFormat(attribindex=%u > "
1630 "GL_MAX_VERTEX_ATTRIBS)",
1631 attribIndex);
1632 return;
1633 }
1634
1635 FLUSH_VERTICES(ctx, 0);
1636
1637 update_array_format(ctx, "glVertexAttribFormat",
1638 VERT_ATTRIB_GENERIC(attribIndex),
1639 legalTypes, 1, BGRA_OR_4, size, type, normalized,
1640 GL_FALSE, relativeOffset);
Fredrik Höglundbb2d02c2013-04-09 20:44:58 +02001641}
1642
1643
1644void GLAPIENTRY
1645_mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type,
1646 GLuint relativeOffset)
1647{
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001648 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
1649 SHORT_BIT | UNSIGNED_SHORT_BIT |
1650 INT_BIT | UNSIGNED_INT_BIT);
1651
1652 GET_CURRENT_CONTEXT(ctx);
1653 ASSERT_OUTSIDE_BEGIN_END(ctx);
1654
1655 /* The ARB_vertex_attrib_binding spec says:
1656 *
1657 * "An INVALID_OPERATION error is generated under any of the following
1658 * conditions:
1659 * - if no vertex array object is currently bound (see section 2.10);
1660 * - ..."
1661 */
1662 if (ctx->API == API_OPENGL_CORE &&
Kenneth Graunke0dfe50f2014-02-01 19:14:38 -08001663 ctx->Array.VAO == ctx->Array.DefaultVAO) {
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001664 _mesa_error(ctx, GL_INVALID_OPERATION,
1665 "glVertexAttribIFormat(No array object bound)");
1666 return;
1667 }
1668
1669 /* The ARB_vertex_attrib_binding spec says:
1670 *
1671 * "The error INVALID_VALUE is generated if index is greater than
1672 * or equal to the value of MAX_VERTEX_ATTRIBS."
1673 */
Paul Berry84732a92014-01-08 10:00:28 -08001674 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001675 _mesa_error(ctx, GL_INVALID_VALUE,
1676 "glVertexAttribIFormat(attribindex=%u > "
1677 "GL_MAX_VERTEX_ATTRIBS)",
1678 attribIndex);
1679 return;
1680 }
1681
1682 FLUSH_VERTICES(ctx, 0);
1683
1684 update_array_format(ctx, "glVertexAttribIFormat",
1685 VERT_ATTRIB_GENERIC(attribIndex),
1686 legalTypes, 1, 4, size, type, GL_FALSE, GL_TRUE,
1687 relativeOffset);
Fredrik Höglundbb2d02c2013-04-09 20:44:58 +02001688}
1689
1690
1691void GLAPIENTRY
1692_mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type,
1693 GLuint relativeOffset)
1694{
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001695 const GLbitfield legalTypes = DOUBLE_BIT;
1696
1697 GET_CURRENT_CONTEXT(ctx);
1698 ASSERT_OUTSIDE_BEGIN_END(ctx);
1699
1700 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
1701 *
1702 * "An INVALID_OPERATION error is generated under any of the following
1703 * conditions:
1704 * • if no vertex array object is currently bound (see section 10.4);
1705 * • ..."
1706 *
1707 * This language is missing from the extension spec, but we assume
1708 * that this is an oversight.
1709 */
1710 if (ctx->API == API_OPENGL_CORE &&
Kenneth Graunke0dfe50f2014-02-01 19:14:38 -08001711 ctx->Array.VAO == ctx->Array.DefaultVAO) {
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001712 _mesa_error(ctx, GL_INVALID_OPERATION,
1713 "glVertexAttribLFormat(No array object bound)");
1714 return;
1715 }
1716
1717 /* The ARB_vertex_attrib_binding spec says:
1718 *
1719 * "The error INVALID_VALUE is generated if <attribindex> is greater than
1720 * or equal to the value of MAX_VERTEX_ATTRIBS."
1721 */
Paul Berry84732a92014-01-08 10:00:28 -08001722 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001723 _mesa_error(ctx, GL_INVALID_VALUE,
1724 "glVertexAttribLFormat(attribindex=%u > "
1725 "GL_MAX_VERTEX_ATTRIBS)",
1726 attribIndex);
1727 return;
1728 }
1729
1730 FLUSH_VERTICES(ctx, 0);
1731
1732 update_array_format(ctx, "glVertexAttribLFormat",
1733 VERT_ATTRIB_GENERIC(attribIndex),
1734 legalTypes, 1, 4, size, type, GL_FALSE, GL_FALSE,
1735 relativeOffset);
Fredrik Höglundbb2d02c2013-04-09 20:44:58 +02001736}
1737
1738
1739void GLAPIENTRY
1740_mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
1741{
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001742 GET_CURRENT_CONTEXT(ctx);
1743 ASSERT_OUTSIDE_BEGIN_END(ctx);
1744
1745 /* The ARB_vertex_attrib_binding spec says:
1746 *
1747 * "An INVALID_OPERATION error is generated if no vertex array object
1748 * is bound."
1749 */
1750 if (ctx->API == API_OPENGL_CORE &&
Kenneth Graunke0dfe50f2014-02-01 19:14:38 -08001751 ctx->Array.VAO == ctx->Array.DefaultVAO) {
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001752 _mesa_error(ctx, GL_INVALID_OPERATION,
1753 "glVertexAttribBinding(No array object bound)");
1754 return;
1755 }
1756
1757 /* The ARB_vertex_attrib_binding spec says:
1758 *
1759 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
1760 * <bindingindex> must be less than the value of
1761 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
1762 * is generated."
1763 */
Paul Berry84732a92014-01-08 10:00:28 -08001764 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001765 _mesa_error(ctx, GL_INVALID_VALUE,
1766 "glVertexAttribBinding(attribindex=%u >= "
1767 "GL_MAX_VERTEX_ATTRIBS)",
1768 attribIndex);
1769 return;
1770 }
1771
1772 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
1773 _mesa_error(ctx, GL_INVALID_VALUE,
1774 "glVertexAttribBinding(bindingindex=%u >= "
1775 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1776 bindingIndex);
1777 return;
1778 }
1779
1780 ASSERT(VERT_ATTRIB_GENERIC(attribIndex) <
Kenneth Graunke0dfe50f2014-02-01 19:14:38 -08001781 Elements(ctx->Array.VAO->VertexAttrib));
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001782
1783 vertex_attrib_binding(ctx, VERT_ATTRIB_GENERIC(attribIndex),
1784 VERT_ATTRIB_GENERIC(bindingIndex));
Fredrik Höglundbb2d02c2013-04-09 20:44:58 +02001785}
1786
1787
1788void GLAPIENTRY
1789_mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
1790{
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001791 GET_CURRENT_CONTEXT(ctx);
1792 ASSERT_OUTSIDE_BEGIN_END(ctx);
1793
1794 if (!ctx->Extensions.ARB_instanced_arrays) {
1795 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexBindingDivisor()");
1796 return;
1797 }
1798
1799 /* The ARB_vertex_attrib_binding spec says:
1800 *
1801 * "An INVALID_OPERATION error is generated if no vertex array object
1802 * is bound."
1803 */
1804 if (ctx->API == API_OPENGL_CORE &&
Kenneth Graunke0dfe50f2014-02-01 19:14:38 -08001805 ctx->Array.VAO == ctx->Array.DefaultVAO) {
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001806 _mesa_error(ctx, GL_INVALID_OPERATION,
1807 "glVertexBindingDivisor(No array object bound)");
1808 return;
1809 }
1810
1811 /* The ARB_vertex_attrib_binding spec says:
1812 *
1813 * "An INVALID_VALUE error is generated if <bindingindex> is greater
1814 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
1815 */
1816 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
1817 _mesa_error(ctx, GL_INVALID_VALUE,
1818 "glVertexBindingDivisor(bindingindex=%u > "
1819 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1820 bindingIndex);
1821 return;
1822 }
1823
1824 vertex_binding_divisor(ctx, VERT_ATTRIB_GENERIC(bindingIndex), divisor);
Fredrik Höglundbb2d02c2013-04-09 20:44:58 +02001825}
1826
1827
1828/**
Brian Paulb2885402009-08-06 13:53:06 -06001829 * Copy one client vertex array to another.
1830 */
1831void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -04001832_mesa_copy_client_array(struct gl_context *ctx,
Brian Paulb2885402009-08-06 13:53:06 -06001833 struct gl_client_array *dst,
1834 struct gl_client_array *src)
1835{
1836 dst->Size = src->Size;
1837 dst->Type = src->Type;
1838 dst->Format = src->Format;
1839 dst->Stride = src->Stride;
1840 dst->StrideB = src->StrideB;
1841 dst->Ptr = src->Ptr;
1842 dst->Enabled = src->Enabled;
1843 dst->Normalized = src->Normalized;
Brian Pauld1184d22010-10-28 21:17:41 -06001844 dst->Integer = src->Integer;
Brian Paul1d1eb952011-01-15 10:32:34 -07001845 dst->InstanceDivisor = src->InstanceDivisor;
Brian Paulb2885402009-08-06 13:53:06 -06001846 dst->_ElementSize = src->_ElementSize;
1847 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
1848 dst->_MaxElement = src->_MaxElement;
1849}
1850
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001851void
1852_mesa_copy_vertex_attrib_array(struct gl_context *ctx,
1853 struct gl_vertex_attrib_array *dst,
1854 const struct gl_vertex_attrib_array *src)
1855{
1856 dst->Size = src->Size;
1857 dst->Type = src->Type;
1858 dst->Format = src->Format;
1859 dst->VertexBinding = src->VertexBinding;
1860 dst->RelativeOffset = src->RelativeOffset;
1861 dst->Format = src->Format;
1862 dst->Integer = src->Integer;
1863 dst->Normalized = src->Normalized;
1864 dst->Ptr = src->Ptr;
1865 dst->Enabled = src->Enabled;
1866 dst->_ElementSize = src->_ElementSize;
1867}
Brian Paulb2885402009-08-06 13:53:06 -06001868
Fredrik Höglund59b01ca2013-04-09 20:54:25 +02001869void
1870_mesa_copy_vertex_buffer_binding(struct gl_context *ctx,
1871 struct gl_vertex_buffer_binding *dst,
1872 const struct gl_vertex_buffer_binding *src)
1873{
1874 dst->Offset = src->Offset;
1875 dst->Stride = src->Stride;
1876 dst->InstanceDivisor = src->InstanceDivisor;
1877 dst->_BoundArrays = src->_BoundArrays;
1878
1879 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
1880}
Brian Paulb2885402009-08-06 13:53:06 -06001881
1882/**
Brian Paul39d75242009-05-14 16:25:32 -06001883 * Print vertex array's fields.
1884 */
1885static void
1886print_array(const char *name, GLint index, const struct gl_client_array *array)
1887{
1888 if (index >= 0)
Kristian Høgsberg298be2b2010-02-19 12:32:24 -05001889 printf(" %s[%d]: ", name, index);
Brian Paul39d75242009-05-14 16:25:32 -06001890 else
Kristian Høgsberg298be2b2010-02-19 12:32:24 -05001891 printf(" %s: ", name);
Brian Paul4beea122010-07-14 14:36:25 -06001892 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 -05001893 array->Ptr, array->Type, array->Size,
1894 array->_ElementSize, array->StrideB,
Brian Paul4beea122010-07-14 14:36:25 -06001895 array->BufferObj->Name, (unsigned long) array->BufferObj->Size,
Kristian Høgsberg298be2b2010-02-19 12:32:24 -05001896 array->_MaxElement);
Brian Paul39d75242009-05-14 16:25:32 -06001897}
1898
1899
1900/**
1901 * Print current vertex object/array info. For debug.
1902 */
1903void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -04001904_mesa_print_arrays(struct gl_context *ctx)
Brian Paul39d75242009-05-14 16:25:32 -06001905{
Kenneth Graunkeaac14152014-02-01 19:36:59 -08001906 struct gl_vertex_array_object *vao = ctx->Array.VAO;
Brian Paul39d75242009-05-14 16:25:32 -06001907 GLuint i;
1908
Kenneth Graunkede47fd22014-02-01 20:48:51 -08001909 _mesa_update_vao_max_element(ctx, vao);
Brian Paul8fe31342009-05-21 15:36:25 -06001910
Kenneth Graunke94e07c12014-02-01 19:31:22 -08001911 printf("Array Object %u\n", vao->Name);
1912 if (vao->_VertexAttrib[VERT_ATTRIB_POS].Enabled)
1913 print_array("Vertex", -1, &vao->_VertexAttrib[VERT_ATTRIB_POS]);
1914 if (vao->_VertexAttrib[VERT_ATTRIB_NORMAL].Enabled)
1915 print_array("Normal", -1, &vao->_VertexAttrib[VERT_ATTRIB_NORMAL]);
1916 if (vao->_VertexAttrib[VERT_ATTRIB_COLOR0].Enabled)
1917 print_array("Color", -1, &vao->_VertexAttrib[VERT_ATTRIB_COLOR0]);
Mathias Fröhlich762c9762011-10-31 22:23:51 +01001918 for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++)
Kenneth Graunke94e07c12014-02-01 19:31:22 -08001919 if (vao->_VertexAttrib[VERT_ATTRIB_TEX(i)].Enabled)
1920 print_array("TexCoord", i, &vao->_VertexAttrib[VERT_ATTRIB_TEX(i)]);
Mathias Fröhlich762c9762011-10-31 22:23:51 +01001921 for (i = 0; i < VERT_ATTRIB_GENERIC_MAX; i++)
Kenneth Graunke94e07c12014-02-01 19:31:22 -08001922 if (vao->_VertexAttrib[VERT_ATTRIB_GENERIC(i)].Enabled)
1923 print_array("Attrib", i, &vao->_VertexAttrib[VERT_ATTRIB_GENERIC(i)]);
1924 printf(" _MaxElement = %u\n", vao->_MaxElement);
Brian Paul39d75242009-05-14 16:25:32 -06001925}
1926
1927
1928/**
Brian Paul095c6692006-04-25 00:21:32 +00001929 * Initialize vertex array state for given context.
1930 */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001931void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -04001932_mesa_init_varray(struct gl_context *ctx)
Keith Whitwell6dc85572003-07-17 13:43:59 +00001933{
Kenneth Graunke0dfe50f2014-02-01 19:14:38 -08001934 ctx->Array.DefaultVAO = ctx->Driver.NewArrayObject(ctx, 0);
Kenneth Graunkede47fd22014-02-01 20:48:51 -08001935 _mesa_reference_vao(ctx, &ctx->Array.VAO, ctx->Array.DefaultVAO);
Brian Paul095c6692006-04-25 00:21:32 +00001936 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
Brian Paul12cf98f2009-06-19 17:58:47 -06001937
1938 ctx->Array.Objects = _mesa_NewHashTable();
1939}
1940
1941
1942/**
1943 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
1944 */
1945static void
1946delete_arrayobj_cb(GLuint id, void *data, void *userData)
1947{
Kenneth Graunkeaac14152014-02-01 19:36:59 -08001948 struct gl_vertex_array_object *vao = (struct gl_vertex_array_object *) data;
Kristian Høgsbergf9995b32010-10-12 12:26:10 -04001949 struct gl_context *ctx = (struct gl_context *) userData;
Kenneth Graunkede47fd22014-02-01 20:48:51 -08001950 _mesa_delete_vao(ctx, vao);
Brian Paul12cf98f2009-06-19 17:58:47 -06001951}
1952
1953
1954/**
1955 * Free vertex array state for given context.
1956 */
1957void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -04001958_mesa_free_varray_data(struct gl_context *ctx)
Brian Paul12cf98f2009-06-19 17:58:47 -06001959{
1960 _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx);
1961 _mesa_DeleteHashTable(ctx->Array.Objects);
Keith Whitwell6dc85572003-07-17 13:43:59 +00001962}