blob: a705b6b9368ced25544b735924197446b5827c17 [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öglundd5543212013-04-03 21:47:44 +0200106 * Does error checking and updates the format in an attrib array.
Brian Paulf9d88c82006-06-13 17:24:36 +0000107 *
Fredrik Höglundd5543212013-04-03 21:47:44 +0200108 * Called by update_array().
109 *
110 * \param func Name of calling function used for error reporting
111 * \param attrib The index of the attribute array
112 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
113 * \param sizeMin Min allowable size value
114 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
115 * \param size Components per element (1, 2, 3 or 4)
116 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
117 * \param normalized Whether integer types are converted to floats in [-1, 1]
118 * \param integer Integer-valued values (will not be normalized to [-1, 1])
Brian Paulc5b1e812003-10-22 22:59:07 +0000119 */
Fredrik Höglundd5543212013-04-03 21:47:44 +0200120static bool
121update_array_format(struct gl_context *ctx,
122 const char *func,
123 GLuint attrib, GLbitfield legalTypesMask,
124 GLint sizeMin, GLint sizeMax,
125 GLint size, GLenum type,
126 GLboolean normalized, GLboolean integer)
Brian Paulc5b1e812003-10-22 22:59:07 +0000127{
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100128 struct gl_client_array *array;
Brian Paul433e5e62010-10-28 21:17:42 -0600129 GLbitfield typeBit;
Fredrik Höglundd5543212013-04-03 21:47:44 +0200130 GLuint elementSize;
Brian Paul433e5e62010-10-28 21:17:42 -0600131 GLenum format = GL_RGBA;
132
Ian Romanickbbceed22012-07-25 14:40:18 -0700133 if (_mesa_is_gles(ctx)) {
Matt Turnerc8901132012-11-28 21:45:19 -0800134 legalTypesMask &= ~(FIXED_GL_BIT | DOUBLE_BIT);
Ian Romanickbbceed22012-07-25 14:40:18 -0700135
136 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
137 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
Matt Turnerc8901132012-11-28 21:45:19 -0800138 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
139 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
140 * quite as trivial as we'd like because it uses a different enum value
141 * for GL_HALF_FLOAT_OES.
Ian Romanickbbceed22012-07-25 14:40:18 -0700142 */
143 if (ctx->Version < 30) {
144 legalTypesMask &= ~(UNSIGNED_INT_BIT
145 | INT_BIT
146 | UNSIGNED_INT_2_10_10_10_REV_BIT
Matt Turnerc8901132012-11-28 21:45:19 -0800147 | INT_2_10_10_10_REV_BIT
148 | HALF_BIT);
Ian Romanickbbceed22012-07-25 14:40:18 -0700149 }
Ian Romanick946ddec2012-07-25 14:46:54 -0700150
151 /* BGRA ordering is not supported in ES contexts.
152 */
153 if (sizeMax == BGRA_OR_4)
154 sizeMax = 4;
Ian Romanickbbceed22012-07-25 14:40:18 -0700155 } else {
Marek Olšák0f1e59d2011-04-29 14:23:15 +0200156 legalTypesMask &= ~FIXED_ES_BIT;
Ian Romanickbbceed22012-07-25 14:40:18 -0700157
158 if (!ctx->Extensions.ARB_ES2_compatibility)
159 legalTypesMask &= ~FIXED_GL_BIT;
160
161 if (!ctx->Extensions.ARB_vertex_type_2_10_10_10_rev)
162 legalTypesMask &= ~(UNSIGNED_INT_2_10_10_10_REV_BIT |
163 INT_2_10_10_10_REV_BIT);
Dave Airlie6cd2d552011-08-13 15:30:38 +0100164 }
Brian Paul11dd2282010-11-07 18:35:35 -0700165
Brian Paul433e5e62010-10-28 21:17:42 -0600166 typeBit = type_to_bit(ctx, type);
167 if (typeBit == 0x0 || (typeBit & legalTypesMask) == 0x0) {
168 _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)",
169 func, _mesa_lookup_enum_by_nr(type));
Fredrik Höglundd5543212013-04-03 21:47:44 +0200170 return false;
Brian Paul433e5e62010-10-28 21:17:42 -0600171 }
172
173 /* Do size parameter checking.
174 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
175 * must be handled specially.
176 */
177 if (ctx->Extensions.EXT_vertex_array_bgra &&
178 sizeMax == BGRA_OR_4 &&
179 size == GL_BGRA) {
Fredrik Höglund0e7a61a2013-04-12 17:36:06 +0200180 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
181 *
182 * "An INVALID_OPERATION error is generated under any of the following
183 * conditions:
184 * ...
185 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
186 * or UNSIGNED_INT_2_10_10_10_REV;
187 * ...
188 * • size is BGRA and normalized is FALSE;"
189 */
Fredrik Höglundd5543212013-04-03 21:47:44 +0200190 bool bgra_error = false;
Dave Airlie99c1a582011-09-07 10:19:14 +0100191
192 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev) {
193 if (type != GL_UNSIGNED_INT_2_10_10_10_REV &&
194 type != GL_INT_2_10_10_10_REV &&
195 type != GL_UNSIGNED_BYTE)
Fredrik Höglundd5543212013-04-03 21:47:44 +0200196 bgra_error = true;
Dave Airlie99c1a582011-09-07 10:19:14 +0100197 } else if (type != GL_UNSIGNED_BYTE)
Fredrik Höglundd5543212013-04-03 21:47:44 +0200198 bgra_error = true;
Dave Airlie99c1a582011-09-07 10:19:14 +0100199
200 if (bgra_error) {
Fredrik Höglund0e7a61a2013-04-12 17:36:06 +0200201 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=GL_BGRA and type=%s)",
202 func, _mesa_lookup_enum_by_nr(type));
Fredrik Höglundd5543212013-04-03 21:47:44 +0200203 return false;
Brian Paul433e5e62010-10-28 21:17:42 -0600204 }
Fredrik Höglund0e7a61a2013-04-12 17:36:06 +0200205
206 if (!normalized) {
207 _mesa_error(ctx, GL_INVALID_OPERATION,
208 "%s(size=GL_BGRA and normalized=GL_FALSE)", func);
Fredrik Höglundd5543212013-04-03 21:47:44 +0200209 return false;
Fredrik Höglund0e7a61a2013-04-12 17:36:06 +0200210 }
211
Brian Paul433e5e62010-10-28 21:17:42 -0600212 format = GL_BGRA;
213 size = 4;
214 }
215 else if (size < sizeMin || size > sizeMax || size > 4) {
216 _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d)", func, size);
Fredrik Höglundd5543212013-04-03 21:47:44 +0200217 return false;
Brian Paul433e5e62010-10-28 21:17:42 -0600218 }
219
Dave Airlie6cd2d552011-08-13 15:30:38 +0100220 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev &&
221 (type == GL_UNSIGNED_INT_2_10_10_10_REV ||
222 type == GL_INT_2_10_10_10_REV) && size != 4) {
223 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size);
Fredrik Höglundd5543212013-04-03 21:47:44 +0200224 return false;
Dave Airlie6cd2d552011-08-13 15:30:38 +0100225 }
226
Brian Paul433e5e62010-10-28 21:17:42 -0600227 ASSERT(size <= 4);
228
Fredrik Höglundd5543212013-04-03 21:47:44 +0200229 elementSize = _mesa_bytes_per_vertex_attrib(size, type);
230 assert(elementSize != -1);
231
Fredrik Höglund12cbe992013-04-03 22:08:47 +0200232 array = &ctx->Array.ArrayObj->_VertexAttrib[attrib];
Fredrik Höglundd5543212013-04-03 21:47:44 +0200233 array->Size = size;
234 array->Type = type;
235 array->Format = format;
236 array->Normalized = normalized;
237 array->Integer = integer;
238 array->_ElementSize = elementSize;
239
240 return true;
241}
242
243
244/**
245 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
246 * functions.
247 *
248 * \param func name of calling function used for error reporting
249 * \param attrib the attribute array index to update
250 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
251 * \param sizeMin min allowable size value
252 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
253 * \param size components per element (1, 2, 3 or 4)
254 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
255 * \param stride stride between elements, in elements
256 * \param normalized are integer types converted to floats in [-1, 1]?
257 * \param integer integer-valued values (will not be normalized to [-1,1])
258 * \param ptr the address (or offset inside VBO) of the array data
259 */
260static void
261update_array(struct gl_context *ctx,
262 const char *func,
263 GLuint attrib, GLbitfield legalTypesMask,
264 GLint sizeMin, GLint sizeMax,
265 GLint size, GLenum type, GLsizei stride,
266 GLboolean normalized, GLboolean integer,
267 const GLvoid *ptr)
268{
269 struct gl_client_array *array;
270
271 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
272 *
273 * "Client vertex arrays - all vertex array attribute pointers must
274 * refer to buffer objects (section 2.9.2). The default vertex array
275 * object (the name zero) is also deprecated. Calling
276 * VertexAttribPointer when no buffer object or no vertex array object
277 * is bound will generate an INVALID_OPERATION error..."
278 *
279 * The check for VBOs is handled below.
280 */
281 if (ctx->API == API_OPENGL_CORE
282 && (ctx->Array.ArrayObj == ctx->Array.DefaultArrayObj)) {
283 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(no array object bound)",
284 func);
285 return;
286 }
287
288 if (!update_array_format(ctx, func, attrib, legalTypesMask, sizeMin, sizeMax,
289 size, type, normalized, integer)) {
290 return;
291 }
292
Brian Paul433e5e62010-10-28 21:17:42 -0600293 if (stride < 0) {
294 _mesa_error( ctx, GL_INVALID_VALUE, "%s(stride=%d)", func, stride );
295 return;
296 }
Brian Paule2b72492009-06-22 16:56:35 -0600297
Ian Romanick843b8762012-08-17 17:12:39 -0700298 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
299 *
300 * "An INVALID_OPERATION error is generated under any of the following
301 * conditions:
302 *
303 * ...
304 *
305 * * any of the *Pointer commands specifying the location and
306 * organization of vertex array data are called while zero is bound
307 * to the ARRAY_BUFFER buffer object binding point (see section
308 * 2.9.6), and the pointer argument is not NULL."
309 */
310 if (ptr != NULL && ctx->Array.ArrayObj->ARBsemantics &&
Brian Paulefcf5aa2011-11-29 07:44:20 -0700311 !_mesa_is_bufferobj(ctx->Array.ArrayBufferObj)) {
Brian Paul433e5e62010-10-28 21:17:42 -0600312 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-VBO array)", func);
Brian Paulf549f4c2009-11-12 23:04:26 -0700313 return;
Brian Paule2b72492009-06-22 16:56:35 -0600314 }
315
Fredrik Höglund12cbe992013-04-03 22:08:47 +0200316 array = &ctx->Array.ArrayObj->_VertexAttrib[attrib];
Brian Paulc5b1e812003-10-22 22:59:07 +0000317 array->Stride = stride;
Fredrik Höglundd5543212013-04-03 21:47:44 +0200318 array->StrideB = stride ? stride : array->_ElementSize;
Brian Paulc5b1e812003-10-22 22:59:07 +0000319 array->Ptr = (const GLubyte *) ptr;
Brian Paul0077c872009-05-06 13:00:35 -0600320
Brian Paul37c74af2008-09-04 14:58:02 -0600321 _mesa_reference_buffer_object(ctx, &array->BufferObj,
322 ctx->Array.ArrayBufferObj);
323
Brian Paulc5b1e812003-10-22 22:59:07 +0000324 ctx->NewState |= _NEW_ARRAY;
Fredrik Höglund6a650fa2013-05-11 19:23:46 +0200325 ctx->Array.ArrayObj->NewArrays |= VERT_BIT(attrib);
Brian Paulc5b1e812003-10-22 22:59:07 +0000326}
327
328
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000329void GLAPIENTRY
Brian Paulfbd8f211999-11-11 01:22:25 +0000330_mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
jtgafb833d1999-08-19 00:55:39 +0000331{
Brian Paulfbd8f211999-11-11 01:22:25 +0000332 GET_CURRENT_CONTEXT(ctx);
Ian Romanicke2cf14d2012-07-25 15:19:31 -0700333 GLbitfield legalTypes = (ctx->API == API_OPENGLES)
334 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
335 : (SHORT_BIT | INT_BIT | FLOAT_BIT |
336 DOUBLE_BIT | HALF_BIT |
337 UNSIGNED_INT_2_10_10_10_REV_BIT |
338 INT_2_10_10_10_REV_BIT);
Eric Anholta9754792013-01-16 16:20:38 -0800339
340 FLUSH_VERTICES(ctx, 0);
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000341
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100342 update_array(ctx, "glVertexPointer", VERT_ATTRIB_POS,
Brian Paul433e5e62010-10-28 21:17:42 -0600343 legalTypes, 2, 4,
344 size, type, stride, GL_FALSE, GL_FALSE, ptr);
jtgafb833d1999-08-19 00:55:39 +0000345}
346
347
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000348void GLAPIENTRY
Brian Paulfbd8f211999-11-11 01:22:25 +0000349_mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
jtgafb833d1999-08-19 00:55:39 +0000350{
Brian Paulfbd8f211999-11-11 01:22:25 +0000351 GET_CURRENT_CONTEXT(ctx);
Ian Romanicke5ef0cb2012-07-25 15:10:21 -0700352 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
353 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
354 : (BYTE_BIT | SHORT_BIT | INT_BIT |
355 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
356 UNSIGNED_INT_2_10_10_10_REV_BIT |
357 INT_2_10_10_10_REV_BIT);
Eric Anholta9754792013-01-16 16:20:38 -0800358
359 FLUSH_VERTICES(ctx, 0);
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000360
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100361 update_array(ctx, "glNormalPointer", VERT_ATTRIB_NORMAL,
Brian Paul433e5e62010-10-28 21:17:42 -0600362 legalTypes, 3, 3,
363 3, type, stride, GL_TRUE, GL_FALSE, ptr);
jtgafb833d1999-08-19 00:55:39 +0000364}
365
366
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000367void GLAPIENTRY
Brian Paulfbd8f211999-11-11 01:22:25 +0000368_mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
jtgafb833d1999-08-19 00:55:39 +0000369{
Brian Paulfbd8f211999-11-11 01:22:25 +0000370 GET_CURRENT_CONTEXT(ctx);
Ian Romanick07ccfef2012-07-25 14:53:01 -0700371 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
372 ? (UNSIGNED_BYTE_BIT | HALF_BIT | FLOAT_BIT | FIXED_ES_BIT)
373 : (BYTE_BIT | UNSIGNED_BYTE_BIT |
374 SHORT_BIT | UNSIGNED_SHORT_BIT |
375 INT_BIT | UNSIGNED_INT_BIT |
376 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
377 UNSIGNED_INT_2_10_10_10_REV_BIT |
378 INT_2_10_10_10_REV_BIT);
Ian Romanickfb821852012-07-25 14:58:36 -0700379 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 4 : 3;
Eric Anholta9754792013-01-16 16:20:38 -0800380
381 FLUSH_VERTICES(ctx, 0);
Brian Paulfbd8f211999-11-11 01:22:25 +0000382
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100383 update_array(ctx, "glColorPointer", VERT_ATTRIB_COLOR0,
Ian Romanickfb821852012-07-25 14:58:36 -0700384 legalTypes, sizeMin, BGRA_OR_4,
Brian Paul433e5e62010-10-28 21:17:42 -0600385 size, type, stride, GL_TRUE, GL_FALSE, ptr);
jtgafb833d1999-08-19 00:55:39 +0000386}
387
388
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000389void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800390_mesa_FogCoordPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000391{
Brian Paul433e5e62010-10-28 21:17:42 -0600392 const GLbitfield legalTypes = (HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000393 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -0800394
395 FLUSH_VERTICES(ctx, 0);
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000396
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100397 update_array(ctx, "glFogCoordPointer", VERT_ATTRIB_FOG,
Brian Paul433e5e62010-10-28 21:17:42 -0600398 legalTypes, 1, 1,
399 1, type, stride, GL_FALSE, GL_FALSE, ptr);
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000400}
401
402
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000403void GLAPIENTRY
Brian Paulfbd8f211999-11-11 01:22:25 +0000404_mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
jtgafb833d1999-08-19 00:55:39 +0000405{
Brian Paul433e5e62010-10-28 21:17:42 -0600406 const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT | INT_BIT |
407 FLOAT_BIT | DOUBLE_BIT);
Brian Paulfbd8f211999-11-11 01:22:25 +0000408 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -0800409
410 FLUSH_VERTICES(ctx, 0);
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000411
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100412 update_array(ctx, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX,
Brian Paul433e5e62010-10-28 21:17:42 -0600413 legalTypes, 1, 1,
414 1, type, stride, GL_FALSE, GL_FALSE, ptr);
jtgafb833d1999-08-19 00:55:39 +0000415}
416
417
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000418void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800419_mesa_SecondaryColorPointer(GLint size, GLenum type,
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000420 GLsizei stride, const GLvoid *ptr)
421{
Brian Paul433e5e62010-10-28 21:17:42 -0600422 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
423 SHORT_BIT | UNSIGNED_SHORT_BIT |
424 INT_BIT | UNSIGNED_INT_BIT |
Dave Airlie6cd2d552011-08-13 15:30:38 +0100425 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
426 UNSIGNED_INT_2_10_10_10_REV_BIT |
427 INT_2_10_10_10_REV_BIT);
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000428 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -0800429
430 FLUSH_VERTICES(ctx, 0);
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000431
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100432 update_array(ctx, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1,
Brian Paul433e5e62010-10-28 21:17:42 -0600433 legalTypes, 3, BGRA_OR_4,
434 size, type, stride, GL_TRUE, GL_FALSE, ptr);
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000435}
436
437
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000438void GLAPIENTRY
Brian Paul2edd1802002-01-11 17:25:35 +0000439_mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
440 const GLvoid *ptr)
jtgafb833d1999-08-19 00:55:39 +0000441{
Brian Paulfbd8f211999-11-11 01:22:25 +0000442 GET_CURRENT_CONTEXT(ctx);
Ian Romanickc3e9a202012-07-25 15:13:00 -0700443 GLbitfield legalTypes = (ctx->API == API_OPENGLES)
444 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
445 : (SHORT_BIT | INT_BIT |
446 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
447 UNSIGNED_INT_2_10_10_10_REV_BIT |
448 INT_2_10_10_10_REV_BIT);
Ian Romanicka8f475d2012-07-25 15:13:51 -0700449 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 2 : 1;
Brian Paulc5b1e812003-10-22 22:59:07 +0000450 const GLuint unit = ctx->Array.ActiveTexture;
Eric Anholta9754792013-01-16 16:20:38 -0800451
452 FLUSH_VERTICES(ctx, 0);
jtgafb833d1999-08-19 00:55:39 +0000453
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100454 update_array(ctx, "glTexCoordPointer", VERT_ATTRIB_TEX(unit),
Ian Romanicka8f475d2012-07-25 15:13:51 -0700455 legalTypes, sizeMin, 4,
Brian Paul433e5e62010-10-28 21:17:42 -0600456 size, type, stride, GL_FALSE, GL_FALSE,
Brian Pauld1184d22010-10-28 21:17:41 -0600457 ptr);
jtgafb833d1999-08-19 00:55:39 +0000458}
459
460
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000461void GLAPIENTRY
Brian Paulc5b1e812003-10-22 22:59:07 +0000462_mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr)
jtgafb833d1999-08-19 00:55:39 +0000463{
Brian Paulee1f0472010-11-02 08:22:40 -0600464 const GLbitfield legalTypes = UNSIGNED_BYTE_BIT;
Brian Pauld1184d22010-10-28 21:17:41 -0600465 /* see table 2.4 edits in GL_EXT_gpu_shader4 spec: */
466 const GLboolean integer = GL_TRUE;
Brian Paulfbd8f211999-11-11 01:22:25 +0000467 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -0800468
469 FLUSH_VERTICES(ctx, 0);
jtgafb833d1999-08-19 00:55:39 +0000470
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100471 update_array(ctx, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG,
Brian Paul433e5e62010-10-28 21:17:42 -0600472 legalTypes, 1, 1,
Brian Paulee1f0472010-11-02 08:22:40 -0600473 1, GL_UNSIGNED_BYTE, stride, GL_FALSE, integer, ptr);
jtgafb833d1999-08-19 00:55:39 +0000474}
475
476
Brian Paul1cf2c8a2008-06-25 08:45:14 -0600477void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800478_mesa_PointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *ptr)
Brian Paul1cf2c8a2008-06-25 08:45:14 -0600479{
Marek Olšák0f1e59d2011-04-29 14:23:15 +0200480 const GLbitfield legalTypes = (FLOAT_BIT | FIXED_ES_BIT);
Brian Paul1cf2c8a2008-06-25 08:45:14 -0600481 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -0800482
483 FLUSH_VERTICES(ctx, 0);
Brian Paul1cf2c8a2008-06-25 08:45:14 -0600484
Brian Paul11dd2282010-11-07 18:35:35 -0700485 if (ctx->API != API_OPENGLES) {
486 _mesa_error(ctx, GL_INVALID_OPERATION,
487 "glPointSizePointer(ES 1.x only)");
488 return;
489 }
490
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100491 update_array(ctx, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE,
Brian Paul433e5e62010-10-28 21:17:42 -0600492 legalTypes, 1, 1,
493 1, type, stride, GL_FALSE, GL_FALSE, ptr);
Brian Paul1cf2c8a2008-06-25 08:45:14 -0600494}
495
496
Brian Paula554d7c2009-05-21 15:55:33 -0600497/**
Brian Paula554d7c2009-05-21 15:55:33 -0600498 * Set a generic vertex attribute array.
499 * Note that these arrays DO NOT alias the conventional GL vertex arrays
500 * (position, normal, color, fog, texcoord, etc).
501 */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000502void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800503_mesa_VertexAttribPointer(GLuint index, GLint size, GLenum type,
Brian Paul92f97852003-05-01 22:44:02 +0000504 GLboolean normalized,
505 GLsizei stride, const GLvoid *ptr)
506{
Brian Paul433e5e62010-10-28 21:17:42 -0600507 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
508 SHORT_BIT | UNSIGNED_SHORT_BIT |
509 INT_BIT | UNSIGNED_INT_BIT |
510 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
Dave Airlie6cd2d552011-08-13 15:30:38 +0100511 FIXED_ES_BIT | FIXED_GL_BIT |
512 UNSIGNED_INT_2_10_10_10_REV_BIT |
513 INT_2_10_10_10_REV_BIT);
Brian Paul92f97852003-05-01 22:44:02 +0000514 GET_CURRENT_CONTEXT(ctx);
Brian Paul92f97852003-05-01 22:44:02 +0000515
Brian Paul05051032005-11-01 04:36:33 +0000516 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
Brian Paul92f97852003-05-01 22:44:02 +0000517 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(index)");
518 return;
519 }
520
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100521 update_array(ctx, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index),
Brian Paul433e5e62010-10-28 21:17:42 -0600522 legalTypes, 1, BGRA_OR_4,
523 size, type, stride, normalized, GL_FALSE, ptr);
Brian Paul92f97852003-05-01 22:44:02 +0000524}
Brian Paul92f97852003-05-01 22:44:02 +0000525
526
Brian Paule00d07c2010-05-25 21:12:24 -0600527/**
Brian Pauld1184d22010-10-28 21:17:41 -0600528 * GL_EXT_gpu_shader4 / GL 3.0.
Brian Paule00d07c2010-05-25 21:12:24 -0600529 * Set an integer-valued vertex attribute array.
530 * Note that these arrays DO NOT alias the conventional GL vertex arrays
531 * (position, normal, color, fog, texcoord, etc).
532 */
533void GLAPIENTRY
534_mesa_VertexAttribIPointer(GLuint index, GLint size, GLenum type,
Brian Paule00d07c2010-05-25 21:12:24 -0600535 GLsizei stride, const GLvoid *ptr)
536{
Brian Paul433e5e62010-10-28 21:17:42 -0600537 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
538 SHORT_BIT | UNSIGNED_SHORT_BIT |
539 INT_BIT | UNSIGNED_INT_BIT);
Brian Pauld1184d22010-10-28 21:17:41 -0600540 const GLboolean normalized = GL_FALSE;
541 const GLboolean integer = GL_TRUE;
Brian Pauld1184d22010-10-28 21:17:41 -0600542 GET_CURRENT_CONTEXT(ctx);
Brian Pauld1184d22010-10-28 21:17:41 -0600543
544 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
545 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribIPointer(index)");
546 return;
547 }
548
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100549 update_array(ctx, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index),
Brian Paul433e5e62010-10-28 21:17:42 -0600550 legalTypes, 1, 4,
551 size, type, stride, normalized, integer, ptr);
Brian Paule00d07c2010-05-25 21:12:24 -0600552}
553
554
555
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000556void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800557_mesa_EnableVertexAttribArray(GLuint index)
Brian Pauld3f598a2010-05-25 21:42:13 -0600558{
Brian Paul45453d82012-02-19 19:50:31 -0700559 struct gl_array_object *arrayObj;
Brian Pauld3f598a2010-05-25 21:42:13 -0600560 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600561
562 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
563 _mesa_error(ctx, GL_INVALID_VALUE,
564 "glEnableVertexAttribArrayARB(index)");
565 return;
566 }
567
Brian Paul45453d82012-02-19 19:50:31 -0700568 arrayObj = ctx->Array.ArrayObj;
Brian Pauld3f598a2010-05-25 21:42:13 -0600569
Fredrik Höglund12cbe992013-04-03 22:08:47 +0200570 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(arrayObj->_VertexAttrib));
Brian Paul45453d82012-02-19 19:50:31 -0700571
Fredrik Höglund12cbe992013-04-03 22:08:47 +0200572 if (!arrayObj->_VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) {
Brian Paul45453d82012-02-19 19:50:31 -0700573 /* was disabled, now being enabled */
574 FLUSH_VERTICES(ctx, _NEW_ARRAY);
Fredrik Höglund12cbe992013-04-03 22:08:47 +0200575 arrayObj->_VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_TRUE;
Brian Paul45453d82012-02-19 19:50:31 -0700576 arrayObj->_Enabled |= VERT_BIT_GENERIC(index);
Fredrik Höglund6a650fa2013-05-11 19:23:46 +0200577 arrayObj->NewArrays |= VERT_BIT_GENERIC(index);
Brian Paul45453d82012-02-19 19:50:31 -0700578 }
Brian Pauld3f598a2010-05-25 21:42:13 -0600579}
580
581
582void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800583_mesa_DisableVertexAttribArray(GLuint index)
Brian Pauld3f598a2010-05-25 21:42:13 -0600584{
Brian Paul45453d82012-02-19 19:50:31 -0700585 struct gl_array_object *arrayObj;
Brian Pauld3f598a2010-05-25 21:42:13 -0600586 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600587
588 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
589 _mesa_error(ctx, GL_INVALID_VALUE,
Brian Paul95368f22011-04-06 14:22:39 -0600590 "glDisableVertexAttribArrayARB(index)");
Brian Pauld3f598a2010-05-25 21:42:13 -0600591 return;
592 }
593
Brian Paul45453d82012-02-19 19:50:31 -0700594 arrayObj = ctx->Array.ArrayObj;
Brian Pauld3f598a2010-05-25 21:42:13 -0600595
Fredrik Höglund12cbe992013-04-03 22:08:47 +0200596 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(arrayObj->_VertexAttrib));
Brian Paul45453d82012-02-19 19:50:31 -0700597
Fredrik Höglund12cbe992013-04-03 22:08:47 +0200598 if (arrayObj->_VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) {
Brian Paul45453d82012-02-19 19:50:31 -0700599 /* was enabled, now being disabled */
600 FLUSH_VERTICES(ctx, _NEW_ARRAY);
Fredrik Höglund12cbe992013-04-03 22:08:47 +0200601 arrayObj->_VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_FALSE;
Brian Paul45453d82012-02-19 19:50:31 -0700602 arrayObj->_Enabled &= ~VERT_BIT_GENERIC(index);
Fredrik Höglund6a650fa2013-05-11 19:23:46 +0200603 arrayObj->NewArrays |= VERT_BIT_GENERIC(index);
Brian Paul45453d82012-02-19 19:50:31 -0700604 }
Brian Pauld3f598a2010-05-25 21:42:13 -0600605}
606
607
608/**
609 * Return info for a vertex attribute array (no alias with legacy
610 * vertex attributes (pos, normal, color, etc)). This function does
611 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
612 */
613static GLuint
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400614get_vertex_array_attrib(struct gl_context *ctx, GLuint index, GLenum pname,
Brian Pauld3f598a2010-05-25 21:42:13 -0600615 const char *caller)
616{
617 const struct gl_client_array *array;
618
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800619 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
Brian Pauld3f598a2010-05-25 21:42:13 -0600620 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", caller, index);
621 return 0;
622 }
623
Fredrik Höglund12cbe992013-04-03 22:08:47 +0200624 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.ArrayObj->_VertexAttrib));
Brian Pauld3f598a2010-05-25 21:42:13 -0600625
Fredrik Höglund12cbe992013-04-03 22:08:47 +0200626 array = &ctx->Array.ArrayObj->_VertexAttrib[VERT_ATTRIB_GENERIC(index)];
Brian Pauld3f598a2010-05-25 21:42:13 -0600627
628 switch (pname) {
629 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
630 return array->Enabled;
631 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
632 return array->Size;
633 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
634 return array->Stride;
635 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
636 return array->Type;
637 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
638 return array->Normalized;
639 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
640 return array->BufferObj->Name;
Brian Pauld1184d22010-10-28 21:17:41 -0600641 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
Ian Romanick2c870302012-07-25 16:21:49 -0700642 if ((_mesa_is_desktop_gl(ctx)
643 && (ctx->Version >= 30 || ctx->Extensions.EXT_gpu_shader4))
644 || _mesa_is_gles3(ctx)) {
Brian Pauld1184d22010-10-28 21:17:41 -0600645 return array->Integer;
646 }
Brian Paul1d1eb952011-01-15 10:32:34 -0700647 goto error;
648 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB:
Ian Romanick2c870302012-07-25 16:21:49 -0700649 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_instanced_arrays)
650 || _mesa_is_gles3(ctx)) {
Brian Paul1d1eb952011-01-15 10:32:34 -0700651 return array->InstanceDivisor;
652 }
653 goto error;
Brian Pauld3f598a2010-05-25 21:42:13 -0600654 default:
Brian Paul1d1eb952011-01-15 10:32:34 -0700655 ; /* fall-through */
Brian Pauld3f598a2010-05-25 21:42:13 -0600656 }
Brian Paul1d1eb952011-01-15 10:32:34 -0700657
658error:
659 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", caller, pname);
660 return 0;
Brian Pauld3f598a2010-05-25 21:42:13 -0600661}
662
663
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800664static const GLfloat *
665get_current_attrib(struct gl_context *ctx, GLuint index, const char *function)
666{
667 if (index == 0) {
Ian Romanick2c870302012-07-25 16:21:49 -0700668 /* In OpenGL 3.1 attribute 0 becomes non-magic, just like in OpenGL ES
669 * 2.0. Note that we cannot just check for API_OPENGL_CORE here because
670 * that will erroneously allow this usage in a 3.0 forward-compatible
671 * context too.
672 */
673 if ((ctx->API != API_OPENGL_CORE || ctx->Version < 31)
674 && ctx->API != API_OPENGLES2) {
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800675 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(index==0)", function);
676 return NULL;
677 }
678 }
679 else if (index >= ctx->Const.VertexProgram.MaxAttribs) {
680 _mesa_error(ctx, GL_INVALID_VALUE,
681 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function);
682 return NULL;
683 }
684
Fredrik Höglund12cbe992013-04-03 22:08:47 +0200685 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.ArrayObj->_VertexAttrib));
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100686
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800687 FLUSH_CURRENT(ctx, 0);
Mathias Fröhlich762c9762011-10-31 22:23:51 +0100688 return ctx->Current.Attrib[VERT_ATTRIB_GENERIC(index)];
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800689}
690
Brian Pauld3f598a2010-05-25 21:42:13 -0600691void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800692_mesa_GetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
Brian Pauld3f598a2010-05-25 21:42:13 -0600693{
694 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600695
696 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800697 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribfv");
698 if (v != NULL) {
Brian Pauld3f598a2010-05-25 21:42:13 -0600699 COPY_4V(params, v);
700 }
701 }
702 else {
703 params[0] = (GLfloat) get_vertex_array_attrib(ctx, index, pname,
704 "glGetVertexAttribfv");
705 }
706}
707
708
709void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800710_mesa_GetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params)
Brian Pauld3f598a2010-05-25 21:42:13 -0600711{
712 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600713
714 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800715 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribdv");
716 if (v != NULL) {
Brian Pauld3f598a2010-05-25 21:42:13 -0600717 params[0] = (GLdouble) v[0];
718 params[1] = (GLdouble) v[1];
719 params[2] = (GLdouble) v[2];
720 params[3] = (GLdouble) v[3];
721 }
722 }
723 else {
724 params[0] = (GLdouble) get_vertex_array_attrib(ctx, index, pname,
725 "glGetVertexAttribdv");
726 }
727}
728
729
730void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800731_mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params)
Brian Pauld3f598a2010-05-25 21:42:13 -0600732{
733 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600734
735 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800736 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribiv");
737 if (v != NULL) {
Brian Pauld3f598a2010-05-25 21:42:13 -0600738 /* XXX should floats in[0,1] be scaled to full int range? */
739 params[0] = (GLint) v[0];
740 params[1] = (GLint) v[1];
741 params[2] = (GLint) v[2];
742 params[3] = (GLint) v[3];
743 }
744 }
745 else {
746 params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname,
747 "glGetVertexAttribiv");
748 }
749}
750
751
752/** GL 3.0 */
753void GLAPIENTRY
754_mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
755{
756 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600757
758 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
Kenneth Graunkec299f442012-11-07 20:29:40 -0800759 const GLint *v = (const GLint *)
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800760 get_current_attrib(ctx, index, "glGetVertexAttribIiv");
761 if (v != NULL) {
Kenneth Graunkec299f442012-11-07 20:29:40 -0800762 COPY_4V(params, v);
Brian Pauld3f598a2010-05-25 21:42:13 -0600763 }
764 }
765 else {
766 params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname,
767 "glGetVertexAttribIiv");
768 }
769}
770
771
772/** GL 3.0 */
773void GLAPIENTRY
774_mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
775{
776 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600777
778 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
Kenneth Graunkec299f442012-11-07 20:29:40 -0800779 const GLuint *v = (const GLuint *)
Ian Romanick5c3f1cd2011-02-03 17:56:44 -0800780 get_current_attrib(ctx, index, "glGetVertexAttribIuiv");
781 if (v != NULL) {
Kenneth Graunkec299f442012-11-07 20:29:40 -0800782 COPY_4V(params, v);
Brian Pauld3f598a2010-05-25 21:42:13 -0600783 }
784 }
785 else {
786 params[0] = get_vertex_array_attrib(ctx, index, pname,
787 "glGetVertexAttribIuiv");
788 }
789}
790
791
792void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -0800793_mesa_GetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer)
Brian Pauld3f598a2010-05-25 21:42:13 -0600794{
795 GET_CURRENT_CONTEXT(ctx);
Brian Pauld3f598a2010-05-25 21:42:13 -0600796
797 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
798 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
799 return;
800 }
801
802 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
803 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
804 return;
805 }
806
Fredrik Höglund12cbe992013-04-03 22:08:47 +0200807 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.ArrayObj->_VertexAttrib));
Brian Pauld3f598a2010-05-25 21:42:13 -0600808
Fredrik Höglund12cbe992013-04-03 22:08:47 +0200809 *pointer = (GLvoid *) ctx->Array.ArrayObj->_VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr;
Brian Pauld3f598a2010-05-25 21:42:13 -0600810}
811
812
813void GLAPIENTRY
Brian Paul1f0e2132000-06-12 15:30:51 +0000814_mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
815 GLsizei count, const GLvoid *ptr)
816{
817 (void) count;
818 _mesa_VertexPointer(size, type, stride, ptr);
819}
820
821
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000822void GLAPIENTRY
Brian Paul1f0e2132000-06-12 15:30:51 +0000823_mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
824 const GLvoid *ptr)
825{
826 (void) count;
827 _mesa_NormalPointer(type, stride, ptr);
828}
829
830
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000831void GLAPIENTRY
Brian Paul1f0e2132000-06-12 15:30:51 +0000832_mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
833 const GLvoid *ptr)
834{
835 (void) count;
836 _mesa_ColorPointer(size, type, stride, ptr);
837}
838
839
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000840void GLAPIENTRY
Brian Paul1f0e2132000-06-12 15:30:51 +0000841_mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
842 const GLvoid *ptr)
843{
844 (void) count;
845 _mesa_IndexPointer(type, stride, ptr);
846}
847
848
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000849void GLAPIENTRY
Brian Paul1f0e2132000-06-12 15:30:51 +0000850_mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
851 GLsizei count, const GLvoid *ptr)
852{
853 (void) count;
854 _mesa_TexCoordPointer(size, type, stride, ptr);
855}
856
857
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000858void GLAPIENTRY
Brian Paul1f0e2132000-06-12 15:30:51 +0000859_mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
860{
861 (void) count;
862 _mesa_EdgeFlagPointer(stride, ptr);
863}
864
865
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000866void GLAPIENTRY
Brian Paulfbd8f211999-11-11 01:22:25 +0000867_mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
jtgafb833d1999-08-19 00:55:39 +0000868{
Brian Paulfbd8f211999-11-11 01:22:25 +0000869 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000870 GLboolean tflag, cflag, nflag; /* enable/disable flags */
871 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
Keith Whitwellf4b02d12001-01-05 05:31:42 +0000872 GLenum ctype = 0; /* color type */
873 GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
Brian Paul4a3110f2003-12-12 18:40:02 +0000874 const GLint toffset = 0; /* always zero */
jtgafb833d1999-08-19 00:55:39 +0000875 GLint defstride; /* default stride */
876 GLint c, f;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000877
Eric Anholta9754792013-01-16 16:20:38 -0800878 FLUSH_VERTICES(ctx, 0);
Keith Whitwellcab974c2000-12-26 05:09:27 +0000879
jtgafb833d1999-08-19 00:55:39 +0000880 f = sizeof(GLfloat);
Brian Paulc5b1e812003-10-22 22:59:07 +0000881 c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
jtgafb833d1999-08-19 00:55:39 +0000882
Brian Paulc5b1e812003-10-22 22:59:07 +0000883 if (stride < 0) {
Brian Paul08836342001-03-03 20:33:27 +0000884 _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
jtgafb833d1999-08-19 00:55:39 +0000885 return;
886 }
887
888 switch (format) {
889 case GL_V2F:
890 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
891 tcomps = 0; ccomps = 0; vcomps = 2;
892 voffset = 0;
893 defstride = 2*f;
894 break;
895 case GL_V3F:
896 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
897 tcomps = 0; ccomps = 0; vcomps = 3;
898 voffset = 0;
899 defstride = 3*f;
900 break;
901 case GL_C4UB_V2F:
902 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
903 tcomps = 0; ccomps = 4; vcomps = 2;
904 ctype = GL_UNSIGNED_BYTE;
905 coffset = 0;
906 voffset = c;
907 defstride = c + 2*f;
908 break;
909 case GL_C4UB_V3F:
910 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
911 tcomps = 0; ccomps = 4; vcomps = 3;
912 ctype = GL_UNSIGNED_BYTE;
913 coffset = 0;
914 voffset = c;
915 defstride = c + 3*f;
916 break;
917 case GL_C3F_V3F:
918 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
919 tcomps = 0; ccomps = 3; vcomps = 3;
920 ctype = GL_FLOAT;
921 coffset = 0;
922 voffset = 3*f;
923 defstride = 6*f;
924 break;
925 case GL_N3F_V3F:
926 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
927 tcomps = 0; ccomps = 0; vcomps = 3;
928 noffset = 0;
929 voffset = 3*f;
930 defstride = 6*f;
931 break;
932 case GL_C4F_N3F_V3F:
933 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
934 tcomps = 0; ccomps = 4; vcomps = 3;
935 ctype = GL_FLOAT;
936 coffset = 0;
937 noffset = 4*f;
938 voffset = 7*f;
939 defstride = 10*f;
940 break;
941 case GL_T2F_V3F:
942 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
943 tcomps = 2; ccomps = 0; vcomps = 3;
944 voffset = 2*f;
945 defstride = 5*f;
946 break;
947 case GL_T4F_V4F:
948 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
949 tcomps = 4; ccomps = 0; vcomps = 4;
950 voffset = 4*f;
951 defstride = 8*f;
952 break;
953 case GL_T2F_C4UB_V3F:
954 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
955 tcomps = 2; ccomps = 4; vcomps = 3;
956 ctype = GL_UNSIGNED_BYTE;
957 coffset = 2*f;
958 voffset = c+2*f;
959 defstride = c+5*f;
960 break;
961 case GL_T2F_C3F_V3F:
962 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
963 tcomps = 2; ccomps = 3; vcomps = 3;
964 ctype = GL_FLOAT;
965 coffset = 2*f;
966 voffset = 5*f;
967 defstride = 8*f;
968 break;
969 case GL_T2F_N3F_V3F:
970 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
971 tcomps = 2; ccomps = 0; vcomps = 3;
972 noffset = 2*f;
973 voffset = 5*f;
974 defstride = 8*f;
975 break;
976 case GL_T2F_C4F_N3F_V3F:
977 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
978 tcomps = 2; ccomps = 4; vcomps = 3;
979 ctype = GL_FLOAT;
980 coffset = 2*f;
981 noffset = 6*f;
982 voffset = 9*f;
983 defstride = 12*f;
984 break;
985 case GL_T4F_C4F_N3F_V4F:
986 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
987 tcomps = 4; ccomps = 4; vcomps = 4;
988 ctype = GL_FLOAT;
989 coffset = 4*f;
990 noffset = 8*f;
991 voffset = 11*f;
992 defstride = 15*f;
993 break;
994 default:
Brian Paul08836342001-03-03 20:33:27 +0000995 _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
jtgafb833d1999-08-19 00:55:39 +0000996 return;
997 }
998
999 if (stride==0) {
1000 stride = defstride;
1001 }
1002
Brian Paulfbd8f211999-11-11 01:22:25 +00001003 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
1004 _mesa_DisableClientState( GL_INDEX_ARRAY );
Brian Paul095c6692006-04-25 00:21:32 +00001005 /* XXX also disable secondary color and generic arrays? */
jtgafb833d1999-08-19 00:55:39 +00001006
1007 /* Texcoords */
jtgafb833d1999-08-19 00:55:39 +00001008 if (tflag) {
Brian Paul4a3110f2003-12-12 18:40:02 +00001009 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
1010 _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
Brian Paulab928e52004-03-10 16:17:35 +00001011 (GLubyte *) pointer + toffset );
jtgafb833d1999-08-19 00:55:39 +00001012 }
1013 else {
Brian Paulab928e52004-03-10 16:17:35 +00001014 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
jtgafb833d1999-08-19 00:55:39 +00001015 }
jtgafb833d1999-08-19 00:55:39 +00001016
1017 /* Color */
1018 if (cflag) {
Brian Paulfbd8f211999-11-11 01:22:25 +00001019 _mesa_EnableClientState( GL_COLOR_ARRAY );
Keith Whitwellcab974c2000-12-26 05:09:27 +00001020 _mesa_ColorPointer( ccomps, ctype, stride,
Brian Paul4a3110f2003-12-12 18:40:02 +00001021 (GLubyte *) pointer + coffset );
jtgafb833d1999-08-19 00:55:39 +00001022 }
1023 else {
Brian Paulfbd8f211999-11-11 01:22:25 +00001024 _mesa_DisableClientState( GL_COLOR_ARRAY );
jtgafb833d1999-08-19 00:55:39 +00001025 }
1026
1027
1028 /* Normals */
1029 if (nflag) {
Brian Paulfbd8f211999-11-11 01:22:25 +00001030 _mesa_EnableClientState( GL_NORMAL_ARRAY );
Brian Paul4a3110f2003-12-12 18:40:02 +00001031 _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset );
jtgafb833d1999-08-19 00:55:39 +00001032 }
1033 else {
Brian Paulfbd8f211999-11-11 01:22:25 +00001034 _mesa_DisableClientState( GL_NORMAL_ARRAY );
jtgafb833d1999-08-19 00:55:39 +00001035 }
1036
Brian Paul4a3110f2003-12-12 18:40:02 +00001037 /* Vertices */
Brian Paulfbd8f211999-11-11 01:22:25 +00001038 _mesa_EnableClientState( GL_VERTEX_ARRAY );
Keith Whitwellcab974c2000-12-26 05:09:27 +00001039 _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
1040 (GLubyte *) pointer + voffset );
jtgafb833d1999-08-19 00:55:39 +00001041}
1042
1043
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001044void GLAPIENTRY
Keith Whitwellad2ac212000-11-24 10:25:05 +00001045_mesa_LockArraysEXT(GLint first, GLsizei count)
1046{
1047 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -08001048
1049 FLUSH_VERTICES(ctx, 0);
Keith Whitwellad2ac212000-11-24 10:25:05 +00001050
1051 if (MESA_VERBOSE & VERBOSE_API)
Brian Paul4753d602002-06-15 02:38:15 +00001052 _mesa_debug(ctx, "glLockArrays %d %d\n", first, count);
Keith Whitwellad2ac212000-11-24 10:25:05 +00001053
Eric Anholt5857e982008-02-02 02:54:13 -08001054 if (first < 0) {
1055 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" );
1056 return;
Gareth Hughes22144ab2001-03-12 00:48:37 +00001057 }
Eric Anholt5857e982008-02-02 02:54:13 -08001058 if (count <= 0) {
1059 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" );
1060 return;
Keith Whitwellad2ac212000-11-24 10:25:05 +00001061 }
Eric Anholt5857e982008-02-02 02:54:13 -08001062 if (ctx->Array.LockCount != 0) {
1063 _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" );
1064 return;
1065 }
1066
1067 ctx->Array.LockFirst = first;
1068 ctx->Array.LockCount = count;
Keith Whitwellad2ac212000-11-24 10:25:05 +00001069
1070 ctx->NewState |= _NEW_ARRAY;
Keith Whitwellad2ac212000-11-24 10:25:05 +00001071}
1072
1073
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001074void GLAPIENTRY
Keith Whitwellad2ac212000-11-24 10:25:05 +00001075_mesa_UnlockArraysEXT( void )
1076{
1077 GET_CURRENT_CONTEXT(ctx);
Eric Anholta9754792013-01-16 16:20:38 -08001078
1079 FLUSH_VERTICES(ctx, 0);
Keith Whitwellad2ac212000-11-24 10:25:05 +00001080
1081 if (MESA_VERBOSE & VERBOSE_API)
Brian Paul4753d602002-06-15 02:38:15 +00001082 _mesa_debug(ctx, "glUnlockArrays\n");
Keith Whitwellad2ac212000-11-24 10:25:05 +00001083
Eric Anholt5857e982008-02-02 02:54:13 -08001084 if (ctx->Array.LockCount == 0) {
1085 _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" );
1086 return;
1087 }
1088
Keith Whitwellad2ac212000-11-24 10:25:05 +00001089 ctx->Array.LockFirst = 0;
1090 ctx->Array.LockCount = 0;
1091 ctx->NewState |= _NEW_ARRAY;
Keith Whitwellad2ac212000-11-24 10:25:05 +00001092}
Brian Paul2525bc72002-06-30 15:47:00 +00001093
1094
Brian Paul2525bc72002-06-30 15:47:00 +00001095/* GL_EXT_multi_draw_arrays */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001096void GLAPIENTRY
Paul Berry1a1db172012-11-06 08:57:59 -08001097_mesa_MultiDrawArrays( GLenum mode, const GLint *first,
Brian Paul79938322010-09-14 09:37:35 -06001098 const GLsizei *count, GLsizei primcount )
Brian Paul2525bc72002-06-30 15:47:00 +00001099{
1100 GET_CURRENT_CONTEXT(ctx);
1101 GLint i;
1102
Eric Anholta9754792013-01-16 16:20:38 -08001103 FLUSH_VERTICES(ctx, 0);
Brian Paul2525bc72002-06-30 15:47:00 +00001104
1105 for (i = 0; i < primcount; i++) {
1106 if (count[i] > 0) {
Ian Romanick9bdfee32005-07-18 12:31:24 +00001107 CALL_DrawArrays(ctx->Exec, (mode, first[i], count[i]));
Brian Paul2525bc72002-06-30 15:47:00 +00001108 }
1109 }
1110}
1111
1112
Ian Romanick3baefe62003-08-22 23:28:03 +00001113/* GL_IBM_multimode_draw_arrays */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001114void GLAPIENTRY
Ian Romanick3baefe62003-08-22 23:28:03 +00001115_mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
1116 const GLsizei * count,
1117 GLsizei primcount, GLint modestride )
1118{
1119 GET_CURRENT_CONTEXT(ctx);
1120 GLint i;
1121
Eric Anholta9754792013-01-16 16:20:38 -08001122 FLUSH_VERTICES(ctx, 0);
Ian Romanick3baefe62003-08-22 23:28:03 +00001123
1124 for ( i = 0 ; i < primcount ; i++ ) {
1125 if ( count[i] > 0 ) {
Brian Paul03e29a52003-12-04 03:16:27 +00001126 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
Ian Romanick9bdfee32005-07-18 12:31:24 +00001127 CALL_DrawArrays(ctx->Exec, ( m, first[i], count[i] ));
Ian Romanick3baefe62003-08-22 23:28:03 +00001128 }
1129 }
1130}
1131
1132
1133/* GL_IBM_multimode_draw_arrays */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001134void GLAPIENTRY
Ian Romanick3baefe62003-08-22 23:28:03 +00001135_mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
1136 GLenum type, const GLvoid * const * indices,
1137 GLsizei primcount, GLint modestride )
1138{
1139 GET_CURRENT_CONTEXT(ctx);
1140 GLint i;
1141
Eric Anholta9754792013-01-16 16:20:38 -08001142 FLUSH_VERTICES(ctx, 0);
Ian Romanick3baefe62003-08-22 23:28:03 +00001143
Brian Pauld2afb392003-09-17 18:15:13 +00001144 /* XXX not sure about ARB_vertex_buffer_object handling here */
1145
Ian Romanick3baefe62003-08-22 23:28:03 +00001146 for ( i = 0 ; i < primcount ; i++ ) {
1147 if ( count[i] > 0 ) {
Brian Paul03e29a52003-12-04 03:16:27 +00001148 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
Ian Romanick9bdfee32005-07-18 12:31:24 +00001149 CALL_DrawElements(ctx->Exec, ( m, count[i], type, indices[i] ));
Ian Romanick3baefe62003-08-22 23:28:03 +00001150 }
1151 }
1152}
1153
1154
Brian Paul095c6692006-04-25 00:21:32 +00001155/**
Brian Paul7f26ad82010-10-21 19:03:38 -06001156 * GL_NV_primitive_restart and GL 3.1
Brian Paula40e6f22010-04-20 21:02:09 -06001157 */
1158void GLAPIENTRY
1159_mesa_PrimitiveRestartIndex(GLuint index)
1160{
1161 GET_CURRENT_CONTEXT(ctx);
1162
Eric Anholt9c1b4182012-07-26 14:43:56 -07001163 if (!ctx->Extensions.NV_primitive_restart && ctx->Version < 31) {
Brian Paul7f26ad82010-10-21 19:03:38 -06001164 _mesa_error(ctx, GL_INVALID_OPERATION, "glPrimitiveRestartIndexNV()");
Brian Paula40e6f22010-04-20 21:02:09 -06001165 return;
1166 }
1167
Kenneth Graunkee6efb902013-05-29 08:31:54 -07001168 if (ctx->Array.RestartIndex != index) {
Brian Pauld2003ee2012-02-19 19:50:32 -07001169 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
Kenneth Graunkee6efb902013-05-29 08:31:54 -07001170 ctx->Array.RestartIndex = index;
Brian Pauld2003ee2012-02-19 19:50:32 -07001171 }
Brian Paula40e6f22010-04-20 21:02:09 -06001172}
1173
1174
1175/**
Brian Paul1d1eb952011-01-15 10:32:34 -07001176 * See GL_ARB_instanced_arrays.
1177 * Note that the instance divisor only applies to generic arrays, not
1178 * the legacy vertex arrays.
1179 */
1180void GLAPIENTRY
1181_mesa_VertexAttribDivisor(GLuint index, GLuint divisor)
1182{
Brian Paul738482e2012-02-27 20:28:09 -07001183 struct gl_client_array *array;
Brian Paul1d1eb952011-01-15 10:32:34 -07001184 GET_CURRENT_CONTEXT(ctx);
Brian Paul1d1eb952011-01-15 10:32:34 -07001185
1186 if (!ctx->Extensions.ARB_instanced_arrays) {
1187 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()");
1188 return;
1189 }
1190
1191 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
Matt Turnerae1f09b2012-11-13 13:05:03 -08001192 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribDivisor(index = %u)",
Brian Paul1d1eb952011-01-15 10:32:34 -07001193 index);
1194 return;
1195 }
1196
Fredrik Höglund12cbe992013-04-03 22:08:47 +02001197 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.ArrayObj->_VertexAttrib));
Mathias Fröhlich762c9762011-10-31 22:23:51 +01001198
Fredrik Höglund12cbe992013-04-03 22:08:47 +02001199 array = &ctx->Array.ArrayObj->_VertexAttrib[VERT_ATTRIB_GENERIC(index)];
Brian Paul738482e2012-02-27 20:28:09 -07001200 if (array->InstanceDivisor != divisor) {
1201 FLUSH_VERTICES(ctx, _NEW_ARRAY);
1202 array->InstanceDivisor = divisor;
Fredrik Höglund6a650fa2013-05-11 19:23:46 +02001203 ctx->Array.ArrayObj->NewArrays |= VERT_BIT(VERT_ATTRIB_GENERIC(index));
Brian Paul738482e2012-02-27 20:28:09 -07001204 }
Brian Paul1d1eb952011-01-15 10:32:34 -07001205}
1206
1207
Kenneth Graunke959d0762013-05-29 08:07:01 -07001208unsigned
1209_mesa_primitive_restart_index(const struct gl_context *ctx, GLenum ib_type)
1210{
1211 /* From the OpenGL 4.3 core specification, page 302:
1212 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1213 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1214 * is used."
1215 */
1216 if (ctx->Array.PrimitiveRestartFixedIndex) {
1217 switch (ib_type) {
1218 case GL_UNSIGNED_BYTE:
1219 return 0xff;
1220 case GL_UNSIGNED_SHORT:
1221 return 0xffff;
1222 case GL_UNSIGNED_INT:
1223 return 0xffffffff;
1224 default:
1225 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1226 }
1227 }
1228
1229 return ctx->Array.RestartIndex;
1230}
1231
Brian Paul1d1eb952011-01-15 10:32:34 -07001232
1233/**
Fredrik Höglundbb2d02c2013-04-09 20:44:58 +02001234 * GL_ARB_vertex_attrib_binding
1235 */
1236void GLAPIENTRY
1237_mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
1238 GLsizei stride)
1239{
1240}
1241
1242
1243void GLAPIENTRY
1244_mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type,
1245 GLboolean normalized, GLuint relativeOffset)
1246{
1247}
1248
1249
1250void GLAPIENTRY
1251_mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type,
1252 GLuint relativeOffset)
1253{
1254}
1255
1256
1257void GLAPIENTRY
1258_mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type,
1259 GLuint relativeOffset)
1260{
1261}
1262
1263
1264void GLAPIENTRY
1265_mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
1266{
1267}
1268
1269
1270void GLAPIENTRY
1271_mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
1272{
1273}
1274
1275
1276/**
Brian Paulb2885402009-08-06 13:53:06 -06001277 * Copy one client vertex array to another.
1278 */
1279void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -04001280_mesa_copy_client_array(struct gl_context *ctx,
Brian Paulb2885402009-08-06 13:53:06 -06001281 struct gl_client_array *dst,
1282 struct gl_client_array *src)
1283{
1284 dst->Size = src->Size;
1285 dst->Type = src->Type;
1286 dst->Format = src->Format;
1287 dst->Stride = src->Stride;
1288 dst->StrideB = src->StrideB;
1289 dst->Ptr = src->Ptr;
1290 dst->Enabled = src->Enabled;
1291 dst->Normalized = src->Normalized;
Brian Pauld1184d22010-10-28 21:17:41 -06001292 dst->Integer = src->Integer;
Brian Paul1d1eb952011-01-15 10:32:34 -07001293 dst->InstanceDivisor = src->InstanceDivisor;
Brian Paulb2885402009-08-06 13:53:06 -06001294 dst->_ElementSize = src->_ElementSize;
1295 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
1296 dst->_MaxElement = src->_MaxElement;
1297}
1298
1299
1300
1301/**
Brian Paul39d75242009-05-14 16:25:32 -06001302 * Print vertex array's fields.
1303 */
1304static void
1305print_array(const char *name, GLint index, const struct gl_client_array *array)
1306{
1307 if (index >= 0)
Kristian Høgsberg298be2b2010-02-19 12:32:24 -05001308 printf(" %s[%d]: ", name, index);
Brian Paul39d75242009-05-14 16:25:32 -06001309 else
Kristian Høgsberg298be2b2010-02-19 12:32:24 -05001310 printf(" %s: ", name);
Brian Paul4beea122010-07-14 14:36:25 -06001311 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 -05001312 array->Ptr, array->Type, array->Size,
1313 array->_ElementSize, array->StrideB,
Brian Paul4beea122010-07-14 14:36:25 -06001314 array->BufferObj->Name, (unsigned long) array->BufferObj->Size,
Kristian Høgsberg298be2b2010-02-19 12:32:24 -05001315 array->_MaxElement);
Brian Paul39d75242009-05-14 16:25:32 -06001316}
1317
1318
1319/**
1320 * Print current vertex object/array info. For debug.
1321 */
1322void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -04001323_mesa_print_arrays(struct gl_context *ctx)
Brian Paul39d75242009-05-14 16:25:32 -06001324{
Brian Paul6a2211f2009-05-21 15:55:50 -06001325 struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
Brian Paul39d75242009-05-14 16:25:32 -06001326 GLuint i;
1327
Brian Paul8fe31342009-05-21 15:36:25 -06001328 _mesa_update_array_object_max_element(ctx, arrayObj);
1329
Kristian Høgsberg298be2b2010-02-19 12:32:24 -05001330 printf("Array Object %u\n", arrayObj->Name);
Fredrik Höglund12cbe992013-04-03 22:08:47 +02001331 if (arrayObj->_VertexAttrib[VERT_ATTRIB_POS].Enabled)
1332 print_array("Vertex", -1, &arrayObj->_VertexAttrib[VERT_ATTRIB_POS]);
1333 if (arrayObj->_VertexAttrib[VERT_ATTRIB_NORMAL].Enabled)
1334 print_array("Normal", -1, &arrayObj->_VertexAttrib[VERT_ATTRIB_NORMAL]);
1335 if (arrayObj->_VertexAttrib[VERT_ATTRIB_COLOR0].Enabled)
1336 print_array("Color", -1, &arrayObj->_VertexAttrib[VERT_ATTRIB_COLOR0]);
Mathias Fröhlich762c9762011-10-31 22:23:51 +01001337 for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++)
Fredrik Höglund12cbe992013-04-03 22:08:47 +02001338 if (arrayObj->_VertexAttrib[VERT_ATTRIB_TEX(i)].Enabled)
1339 print_array("TexCoord", i, &arrayObj->_VertexAttrib[VERT_ATTRIB_TEX(i)]);
Mathias Fröhlich762c9762011-10-31 22:23:51 +01001340 for (i = 0; i < VERT_ATTRIB_GENERIC_MAX; i++)
Fredrik Höglund12cbe992013-04-03 22:08:47 +02001341 if (arrayObj->_VertexAttrib[VERT_ATTRIB_GENERIC(i)].Enabled)
1342 print_array("Attrib", i, &arrayObj->_VertexAttrib[VERT_ATTRIB_GENERIC(i)]);
Kristian Høgsberg298be2b2010-02-19 12:32:24 -05001343 printf(" _MaxElement = %u\n", arrayObj->_MaxElement);
Brian Paul39d75242009-05-14 16:25:32 -06001344}
1345
1346
1347/**
Brian Paul095c6692006-04-25 00:21:32 +00001348 * Initialize vertex array state for given context.
1349 */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001350void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -04001351_mesa_init_varray(struct gl_context *ctx)
Keith Whitwell6dc85572003-07-17 13:43:59 +00001352{
Mathias Fröhlich86f53e62011-11-02 19:54:26 +01001353 ctx->Array.DefaultArrayObj = ctx->Driver.NewArrayObject(ctx, 0);
Brian Paul1030bf02009-05-07 13:52:26 -06001354 _mesa_reference_array_object(ctx, &ctx->Array.ArrayObj,
1355 ctx->Array.DefaultArrayObj);
Brian Paul095c6692006-04-25 00:21:32 +00001356 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
Brian Paul12cf98f2009-06-19 17:58:47 -06001357
1358 ctx->Array.Objects = _mesa_NewHashTable();
1359}
1360
1361
1362/**
1363 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
1364 */
1365static void
1366delete_arrayobj_cb(GLuint id, void *data, void *userData)
1367{
1368 struct gl_array_object *arrayObj = (struct gl_array_object *) data;
Kristian Høgsbergf9995b32010-10-12 12:26:10 -04001369 struct gl_context *ctx = (struct gl_context *) userData;
Brian Paul12cf98f2009-06-19 17:58:47 -06001370 _mesa_delete_array_object(ctx, arrayObj);
1371}
1372
1373
1374/**
1375 * Free vertex array state for given context.
1376 */
1377void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -04001378_mesa_free_varray_data(struct gl_context *ctx)
Brian Paul12cf98f2009-06-19 17:58:47 -06001379{
1380 _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx);
1381 _mesa_DeleteHashTable(ctx->Array.Objects);
Keith Whitwell6dc85572003-07-17 13:43:59 +00001382}