67dd093f2a6ae500b9bc6f896fdb412b50fba019
[mesa.git] / src / mesa / main / varray.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.2
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 #include "glheader.h"
27 #include "imports.h"
28 #include "bufferobj.h"
29 #include "context.h"
30 #include "enable.h"
31 #include "enums.h"
32 #include "mtypes.h"
33 #include "varray.h"
34 #include "arrayobj.h"
35 #include "glapi/dispatch.h"
36
37
38 /**
39 * Update the fields of a vertex array object.
40 * We need to do a few special things for arrays that live in
41 * vertex buffer objects.
42 *
43 * \param array the array to update
44 * \param dirtyBit which bit to set in ctx->Array.NewState for this array
45 * \param elementSize size of each array element, in bytes
46 * \param size components per element (1, 2, 3 or 4)
47 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
48 * \param stride stride between elements, in elements
49 * \param normalized are integer types converted to floats in [-1, 1]?
50 * \param ptr the address (or offset inside VBO) of the array data
51 */
52 static void
53 update_array(GLcontext *ctx, struct gl_client_array *array,
54 GLbitfield dirtyBit, GLsizei elementSize,
55 GLint size, GLenum type,
56 GLsizei stride, GLboolean normalized, const GLvoid *ptr)
57 {
58 array->Size = size;
59 array->Type = type;
60 array->Stride = stride;
61 array->StrideB = stride ? stride : elementSize;
62 array->Normalized = normalized;
63 array->Ptr = (const GLubyte *) ptr;
64 #if FEATURE_ARB_vertex_buffer_object
65 _mesa_reference_buffer_object(ctx, &array->BufferObj,
66 ctx->Array.ArrayBufferObj);
67
68 /* Compute the index of the last array element that's inside the buffer.
69 * Later in glDrawArrays we'll check if start + count > _MaxElement to
70 * be sure we won't go out of bounds.
71 */
72 if (ctx->Array.ArrayBufferObj->Name)
73 array->_MaxElement = ((GLsizeiptrARB) ctx->Array.ArrayBufferObj->Size
74 - (GLsizeiptrARB) array->Ptr + array->StrideB
75 - elementSize) / array->StrideB;
76 else
77 #endif
78 array->_MaxElement = 2 * 1000 * 1000 * 1000; /* just a big number */
79
80 ctx->NewState |= _NEW_ARRAY;
81 ctx->Array.NewState |= dirtyBit;
82 }
83
84
85 void GLAPIENTRY
86 _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
87 {
88 GLsizei elementSize;
89 GET_CURRENT_CONTEXT(ctx);
90 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
91
92 if (size < 2 || size > 4) {
93 _mesa_error( ctx, GL_INVALID_VALUE, "glVertexPointer(size)" );
94 return;
95 }
96 if (stride < 0) {
97 _mesa_error( ctx, GL_INVALID_VALUE, "glVertexPointer(stride)" );
98 return;
99 }
100
101 if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API))
102 _mesa_debug(ctx, "glVertexPointer( sz %d type %s stride %d )\n", size,
103 _mesa_lookup_enum_by_nr( type ), stride);
104
105 /* always need to check that <type> is legal */
106 switch (type) {
107 case GL_SHORT:
108 elementSize = size * sizeof(GLshort);
109 break;
110 case GL_INT:
111 elementSize = size * sizeof(GLint);
112 break;
113 case GL_FLOAT:
114 elementSize = size * sizeof(GLfloat);
115 break;
116 case GL_DOUBLE:
117 elementSize = size * sizeof(GLdouble);
118 break;
119 default:
120 _mesa_error( ctx, GL_INVALID_ENUM, "glVertexPointer(type)" );
121 return;
122 }
123
124 update_array(ctx, &ctx->Array.ArrayObj->Vertex, _NEW_ARRAY_VERTEX,
125 elementSize, size, type, stride, GL_FALSE, ptr);
126
127 if (ctx->Driver.VertexPointer)
128 ctx->Driver.VertexPointer( ctx, size, type, stride, ptr );
129 }
130
131
132 void GLAPIENTRY
133 _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
134 {
135 GLsizei elementSize;
136 GET_CURRENT_CONTEXT(ctx);
137 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
138
139 if (stride < 0) {
140 _mesa_error( ctx, GL_INVALID_VALUE, "glNormalPointer(stride)" );
141 return;
142 }
143
144 if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API))
145 _mesa_debug(ctx, "glNormalPointer( type %s stride %d )\n",
146 _mesa_lookup_enum_by_nr( type ), stride);
147
148 switch (type) {
149 case GL_BYTE:
150 elementSize = 3 * sizeof(GLbyte);
151 break;
152 case GL_SHORT:
153 elementSize = 3 * sizeof(GLshort);
154 break;
155 case GL_INT:
156 elementSize = 3 * sizeof(GLint);
157 break;
158 case GL_FLOAT:
159 elementSize = 3 * sizeof(GLfloat);
160 break;
161 case GL_DOUBLE:
162 elementSize = 3 * sizeof(GLdouble);
163 break;
164 default:
165 _mesa_error( ctx, GL_INVALID_ENUM, "glNormalPointer(type)" );
166 return;
167 }
168
169 update_array(ctx, &ctx->Array.ArrayObj->Normal, _NEW_ARRAY_NORMAL,
170 elementSize, 3, type, stride, GL_TRUE, ptr);
171
172 if (ctx->Driver.NormalPointer)
173 ctx->Driver.NormalPointer( ctx, type, stride, ptr );
174 }
175
176
177 void GLAPIENTRY
178 _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
179 {
180 GLsizei elementSize;
181 GET_CURRENT_CONTEXT(ctx);
182 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
183
184 if (size < 3 || size > 4) {
185 _mesa_error( ctx, GL_INVALID_VALUE, "glColorPointer(size)" );
186 return;
187 }
188 if (stride < 0) {
189 _mesa_error( ctx, GL_INVALID_VALUE, "glColorPointer(stride)" );
190 return;
191 }
192
193 if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API))
194 _mesa_debug(ctx, "glColorPointer( sz %d type %s stride %d )\n", size,
195 _mesa_lookup_enum_by_nr( type ), stride);
196
197 switch (type) {
198 case GL_BYTE:
199 elementSize = size * sizeof(GLbyte);
200 break;
201 case GL_UNSIGNED_BYTE:
202 elementSize = size * sizeof(GLubyte);
203 break;
204 case GL_SHORT:
205 elementSize = size * sizeof(GLshort);
206 break;
207 case GL_UNSIGNED_SHORT:
208 elementSize = size * sizeof(GLushort);
209 break;
210 case GL_INT:
211 elementSize = size * sizeof(GLint);
212 break;
213 case GL_UNSIGNED_INT:
214 elementSize = size * sizeof(GLuint);
215 break;
216 case GL_FLOAT:
217 elementSize = size * sizeof(GLfloat);
218 break;
219 case GL_DOUBLE:
220 elementSize = size * sizeof(GLdouble);
221 break;
222 default:
223 _mesa_error( ctx, GL_INVALID_ENUM, "glColorPointer(type)" );
224 return;
225 }
226
227 update_array(ctx, &ctx->Array.ArrayObj->Color, _NEW_ARRAY_COLOR0,
228 elementSize, size, type, stride, GL_TRUE, ptr);
229
230 if (ctx->Driver.ColorPointer)
231 ctx->Driver.ColorPointer( ctx, size, type, stride, ptr );
232 }
233
234
235 void GLAPIENTRY
236 _mesa_FogCoordPointerEXT(GLenum type, GLsizei stride, const GLvoid *ptr)
237 {
238 GLint elementSize;
239 GET_CURRENT_CONTEXT(ctx);
240 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
241
242 if (stride < 0) {
243 _mesa_error( ctx, GL_INVALID_VALUE, "glFogCoordPointer(stride)" );
244 return;
245 }
246
247 switch (type) {
248 case GL_FLOAT:
249 elementSize = sizeof(GLfloat);
250 break;
251 case GL_DOUBLE:
252 elementSize = sizeof(GLdouble);
253 break;
254 default:
255 _mesa_error( ctx, GL_INVALID_ENUM, "glFogCoordPointer(type)" );
256 return;
257 }
258
259 update_array(ctx, &ctx->Array.ArrayObj->FogCoord, _NEW_ARRAY_FOGCOORD,
260 elementSize, 1, type, stride, GL_FALSE, ptr);
261
262 if (ctx->Driver.FogCoordPointer)
263 ctx->Driver.FogCoordPointer( ctx, type, stride, ptr );
264 }
265
266
267 void GLAPIENTRY
268 _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
269 {
270 GLsizei elementSize;
271 GET_CURRENT_CONTEXT(ctx);
272 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
273
274 if (stride < 0) {
275 _mesa_error( ctx, GL_INVALID_VALUE, "glIndexPointer(stride)" );
276 return;
277 }
278
279 switch (type) {
280 case GL_UNSIGNED_BYTE:
281 elementSize = sizeof(GLubyte);
282 break;
283 case GL_SHORT:
284 elementSize = sizeof(GLshort);
285 break;
286 case GL_INT:
287 elementSize = sizeof(GLint);
288 break;
289 case GL_FLOAT:
290 elementSize = sizeof(GLfloat);
291 break;
292 case GL_DOUBLE:
293 elementSize = sizeof(GLdouble);
294 break;
295 default:
296 _mesa_error( ctx, GL_INVALID_ENUM, "glIndexPointer(type)" );
297 return;
298 }
299
300 update_array(ctx, &ctx->Array.ArrayObj->Index, _NEW_ARRAY_INDEX,
301 elementSize, 1, type, stride, GL_FALSE, ptr);
302
303 if (ctx->Driver.IndexPointer)
304 ctx->Driver.IndexPointer( ctx, type, stride, ptr );
305 }
306
307
308 void GLAPIENTRY
309 _mesa_SecondaryColorPointerEXT(GLint size, GLenum type,
310 GLsizei stride, const GLvoid *ptr)
311 {
312 GLsizei elementSize;
313 GET_CURRENT_CONTEXT(ctx);
314 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
315
316 if (size != 3 && size != 4) {
317 _mesa_error( ctx, GL_INVALID_VALUE, "glSecondaryColorPointer(size)" );
318 return;
319 }
320 if (stride < 0) {
321 _mesa_error( ctx, GL_INVALID_VALUE, "glSecondaryColorPointer(stride)" );
322 return;
323 }
324
325 if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API))
326 _mesa_debug(ctx, "glSecondaryColorPointer( sz %d type %s stride %d )\n",
327 size, _mesa_lookup_enum_by_nr( type ), stride);
328
329 switch (type) {
330 case GL_BYTE:
331 elementSize = size * sizeof(GLbyte);
332 break;
333 case GL_UNSIGNED_BYTE:
334 elementSize = size * sizeof(GLubyte);
335 break;
336 case GL_SHORT:
337 elementSize = size * sizeof(GLshort);
338 break;
339 case GL_UNSIGNED_SHORT:
340 elementSize = size * sizeof(GLushort);
341 break;
342 case GL_INT:
343 elementSize = size * sizeof(GLint);
344 break;
345 case GL_UNSIGNED_INT:
346 elementSize = size * sizeof(GLuint);
347 break;
348 case GL_FLOAT:
349 elementSize = size * sizeof(GLfloat);
350 break;
351 case GL_DOUBLE:
352 elementSize = size * sizeof(GLdouble);
353 break;
354 default:
355 _mesa_error( ctx, GL_INVALID_ENUM, "glSecondaryColorPointer(type)" );
356 return;
357 }
358
359 update_array(ctx, &ctx->Array.ArrayObj->SecondaryColor, _NEW_ARRAY_COLOR1,
360 elementSize, size, type, stride, GL_TRUE, ptr);
361
362 if (ctx->Driver.SecondaryColorPointer)
363 ctx->Driver.SecondaryColorPointer( ctx, size, type, stride, ptr );
364 }
365
366
367 void GLAPIENTRY
368 _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
369 const GLvoid *ptr)
370 {
371 GLint elementSize;
372 GET_CURRENT_CONTEXT(ctx);
373 const GLuint unit = ctx->Array.ActiveTexture;
374 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
375
376 if (size < 1 || size > 4) {
377 _mesa_error( ctx, GL_INVALID_VALUE, "glTexCoordPointer(size)" );
378 return;
379 }
380 if (stride < 0) {
381 _mesa_error( ctx, GL_INVALID_VALUE, "glTexCoordPointer(stride)" );
382 return;
383 }
384
385 if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API))
386 _mesa_debug(ctx, "glTexCoordPointer(unit %u sz %d type %s stride %d)\n",
387 unit, size, _mesa_lookup_enum_by_nr( type ), stride);
388
389 /* always need to check that <type> is legal */
390 switch (type) {
391 case GL_SHORT:
392 elementSize = size * sizeof(GLshort);
393 break;
394 case GL_INT:
395 elementSize = size * sizeof(GLint);
396 break;
397 case GL_FLOAT:
398 elementSize = size * sizeof(GLfloat);
399 break;
400 case GL_DOUBLE:
401 elementSize = size * sizeof(GLdouble);
402 break;
403 default:
404 _mesa_error( ctx, GL_INVALID_ENUM, "glTexCoordPointer(type)" );
405 return;
406 }
407
408 update_array(ctx, &ctx->Array.ArrayObj->TexCoord[unit],
409 _NEW_ARRAY_TEXCOORD(unit),
410 elementSize, size, type, stride, GL_FALSE, ptr);
411
412 if (ctx->Driver.TexCoordPointer)
413 ctx->Driver.TexCoordPointer( ctx, size, type, stride, ptr );
414 }
415
416
417 void GLAPIENTRY
418 _mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr)
419 {
420 GET_CURRENT_CONTEXT(ctx);
421 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
422
423 if (stride < 0) {
424 _mesa_error( ctx, GL_INVALID_VALUE, "glEdgeFlagPointer(stride)" );
425 return;
426 }
427
428 update_array(ctx, &ctx->Array.ArrayObj->EdgeFlag, _NEW_ARRAY_EDGEFLAG,
429 sizeof(GLboolean), 1, GL_UNSIGNED_BYTE, stride, GL_FALSE, ptr);
430
431 if (ctx->Driver.EdgeFlagPointer)
432 ctx->Driver.EdgeFlagPointer( ctx, stride, ptr );
433 }
434
435
436 #if FEATURE_NV_vertex_program
437 void GLAPIENTRY
438 _mesa_VertexAttribPointerNV(GLuint index, GLint size, GLenum type,
439 GLsizei stride, const GLvoid *ptr)
440 {
441 GLboolean normalized = GL_FALSE;
442 GLsizei elementSize;
443 GET_CURRENT_CONTEXT(ctx);
444 ASSERT_OUTSIDE_BEGIN_END(ctx);
445
446 if (index >= MAX_VERTEX_PROGRAM_ATTRIBS) {
447 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(index)");
448 return;
449 }
450
451 if (size < 1 || size > 4) {
452 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(size)");
453 return;
454 }
455
456 if (stride < 0) {
457 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(stride)");
458 return;
459 }
460
461 if (type == GL_UNSIGNED_BYTE && size != 4) {
462 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(size!=4)");
463 return;
464 }
465
466 /* check for valid 'type' and compute StrideB right away */
467 switch (type) {
468 case GL_UNSIGNED_BYTE:
469 normalized = GL_TRUE;
470 elementSize = size * sizeof(GLubyte);
471 break;
472 case GL_SHORT:
473 elementSize = size * sizeof(GLshort);
474 break;
475 case GL_FLOAT:
476 elementSize = size * sizeof(GLfloat);
477 break;
478 case GL_DOUBLE:
479 elementSize = size * sizeof(GLdouble);
480 break;
481 default:
482 _mesa_error( ctx, GL_INVALID_ENUM, "glVertexAttribPointerNV(type)" );
483 return;
484 }
485
486 update_array(ctx, &ctx->Array.ArrayObj->VertexAttrib[index],
487 _NEW_ARRAY_ATTRIB(index),
488 elementSize, size, type, stride, normalized, ptr);
489
490 if (ctx->Driver.VertexAttribPointer)
491 ctx->Driver.VertexAttribPointer( ctx, index, size, type, stride, ptr );
492 }
493 #endif
494
495
496 #if FEATURE_ARB_vertex_program
497 void GLAPIENTRY
498 _mesa_VertexAttribPointerARB(GLuint index, GLint size, GLenum type,
499 GLboolean normalized,
500 GLsizei stride, const GLvoid *ptr)
501 {
502 GLsizei elementSize;
503 GET_CURRENT_CONTEXT(ctx);
504 ASSERT_OUTSIDE_BEGIN_END(ctx);
505
506 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
507 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(index)");
508 return;
509 }
510
511 if (size < 1 || size > 4) {
512 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(size)");
513 return;
514 }
515
516 if (stride < 0) {
517 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(stride)");
518 return;
519 }
520
521 /* check for valid 'type' and compute StrideB right away */
522 /* NOTE: more types are supported here than in the NV extension */
523 switch (type) {
524 case GL_BYTE:
525 elementSize = size * sizeof(GLbyte);
526 break;
527 case GL_UNSIGNED_BYTE:
528 elementSize = size * sizeof(GLubyte);
529 break;
530 case GL_SHORT:
531 elementSize = size * sizeof(GLshort);
532 break;
533 case GL_UNSIGNED_SHORT:
534 elementSize = size * sizeof(GLushort);
535 break;
536 case GL_INT:
537 elementSize = size * sizeof(GLint);
538 break;
539 case GL_UNSIGNED_INT:
540 elementSize = size * sizeof(GLuint);
541 break;
542 case GL_FLOAT:
543 elementSize = size * sizeof(GLfloat);
544 break;
545 case GL_DOUBLE:
546 elementSize = size * sizeof(GLdouble);
547 break;
548 default:
549 _mesa_error( ctx, GL_INVALID_ENUM, "glVertexAttribPointerARB(type)" );
550 return;
551 }
552
553 update_array(ctx, &ctx->Array.ArrayObj->VertexAttrib[index],
554 _NEW_ARRAY_ATTRIB(index),
555 elementSize, size, type, stride, normalized, ptr);
556
557 if (ctx->Driver.VertexAttribPointer)
558 ctx->Driver.VertexAttribPointer(ctx, index, size, type, stride, ptr);
559 }
560 #endif
561
562
563 void GLAPIENTRY
564 _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
565 GLsizei count, const GLvoid *ptr)
566 {
567 (void) count;
568 _mesa_VertexPointer(size, type, stride, ptr);
569 }
570
571
572 void GLAPIENTRY
573 _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
574 const GLvoid *ptr)
575 {
576 (void) count;
577 _mesa_NormalPointer(type, stride, ptr);
578 }
579
580
581 void GLAPIENTRY
582 _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
583 const GLvoid *ptr)
584 {
585 (void) count;
586 _mesa_ColorPointer(size, type, stride, ptr);
587 }
588
589
590 void GLAPIENTRY
591 _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
592 const GLvoid *ptr)
593 {
594 (void) count;
595 _mesa_IndexPointer(type, stride, ptr);
596 }
597
598
599 void GLAPIENTRY
600 _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
601 GLsizei count, const GLvoid *ptr)
602 {
603 (void) count;
604 _mesa_TexCoordPointer(size, type, stride, ptr);
605 }
606
607
608 void GLAPIENTRY
609 _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
610 {
611 (void) count;
612 _mesa_EdgeFlagPointer(stride, ptr);
613 }
614
615
616 void GLAPIENTRY
617 _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
618 {
619 GET_CURRENT_CONTEXT(ctx);
620 GLboolean tflag, cflag, nflag; /* enable/disable flags */
621 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
622 GLenum ctype = 0; /* color type */
623 GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
624 const GLint toffset = 0; /* always zero */
625 GLint defstride; /* default stride */
626 GLint c, f;
627
628 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
629
630 f = sizeof(GLfloat);
631 c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
632
633 if (stride < 0) {
634 _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
635 return;
636 }
637
638 switch (format) {
639 case GL_V2F:
640 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
641 tcomps = 0; ccomps = 0; vcomps = 2;
642 voffset = 0;
643 defstride = 2*f;
644 break;
645 case GL_V3F:
646 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
647 tcomps = 0; ccomps = 0; vcomps = 3;
648 voffset = 0;
649 defstride = 3*f;
650 break;
651 case GL_C4UB_V2F:
652 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
653 tcomps = 0; ccomps = 4; vcomps = 2;
654 ctype = GL_UNSIGNED_BYTE;
655 coffset = 0;
656 voffset = c;
657 defstride = c + 2*f;
658 break;
659 case GL_C4UB_V3F:
660 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
661 tcomps = 0; ccomps = 4; vcomps = 3;
662 ctype = GL_UNSIGNED_BYTE;
663 coffset = 0;
664 voffset = c;
665 defstride = c + 3*f;
666 break;
667 case GL_C3F_V3F:
668 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
669 tcomps = 0; ccomps = 3; vcomps = 3;
670 ctype = GL_FLOAT;
671 coffset = 0;
672 voffset = 3*f;
673 defstride = 6*f;
674 break;
675 case GL_N3F_V3F:
676 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
677 tcomps = 0; ccomps = 0; vcomps = 3;
678 noffset = 0;
679 voffset = 3*f;
680 defstride = 6*f;
681 break;
682 case GL_C4F_N3F_V3F:
683 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
684 tcomps = 0; ccomps = 4; vcomps = 3;
685 ctype = GL_FLOAT;
686 coffset = 0;
687 noffset = 4*f;
688 voffset = 7*f;
689 defstride = 10*f;
690 break;
691 case GL_T2F_V3F:
692 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
693 tcomps = 2; ccomps = 0; vcomps = 3;
694 voffset = 2*f;
695 defstride = 5*f;
696 break;
697 case GL_T4F_V4F:
698 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
699 tcomps = 4; ccomps = 0; vcomps = 4;
700 voffset = 4*f;
701 defstride = 8*f;
702 break;
703 case GL_T2F_C4UB_V3F:
704 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
705 tcomps = 2; ccomps = 4; vcomps = 3;
706 ctype = GL_UNSIGNED_BYTE;
707 coffset = 2*f;
708 voffset = c+2*f;
709 defstride = c+5*f;
710 break;
711 case GL_T2F_C3F_V3F:
712 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
713 tcomps = 2; ccomps = 3; vcomps = 3;
714 ctype = GL_FLOAT;
715 coffset = 2*f;
716 voffset = 5*f;
717 defstride = 8*f;
718 break;
719 case GL_T2F_N3F_V3F:
720 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
721 tcomps = 2; ccomps = 0; vcomps = 3;
722 noffset = 2*f;
723 voffset = 5*f;
724 defstride = 8*f;
725 break;
726 case GL_T2F_C4F_N3F_V3F:
727 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
728 tcomps = 2; ccomps = 4; vcomps = 3;
729 ctype = GL_FLOAT;
730 coffset = 2*f;
731 noffset = 6*f;
732 voffset = 9*f;
733 defstride = 12*f;
734 break;
735 case GL_T4F_C4F_N3F_V4F:
736 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
737 tcomps = 4; ccomps = 4; vcomps = 4;
738 ctype = GL_FLOAT;
739 coffset = 4*f;
740 noffset = 8*f;
741 voffset = 11*f;
742 defstride = 15*f;
743 break;
744 default:
745 _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
746 return;
747 }
748
749 if (stride==0) {
750 stride = defstride;
751 }
752
753 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
754 _mesa_DisableClientState( GL_INDEX_ARRAY );
755 /* XXX also disable secondary color and generic arrays? */
756
757 /* Texcoords */
758 if (tflag) {
759 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
760 _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
761 (GLubyte *) pointer + toffset );
762 }
763 else {
764 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
765 }
766
767 /* Color */
768 if (cflag) {
769 _mesa_EnableClientState( GL_COLOR_ARRAY );
770 _mesa_ColorPointer( ccomps, ctype, stride,
771 (GLubyte *) pointer + coffset );
772 }
773 else {
774 _mesa_DisableClientState( GL_COLOR_ARRAY );
775 }
776
777
778 /* Normals */
779 if (nflag) {
780 _mesa_EnableClientState( GL_NORMAL_ARRAY );
781 _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset );
782 }
783 else {
784 _mesa_DisableClientState( GL_NORMAL_ARRAY );
785 }
786
787 /* Vertices */
788 _mesa_EnableClientState( GL_VERTEX_ARRAY );
789 _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
790 (GLubyte *) pointer + voffset );
791 }
792
793
794 void GLAPIENTRY
795 _mesa_LockArraysEXT(GLint first, GLsizei count)
796 {
797 GET_CURRENT_CONTEXT(ctx);
798 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
799
800 if (MESA_VERBOSE & VERBOSE_API)
801 _mesa_debug(ctx, "glLockArrays %d %d\n", first, count);
802
803 if (first < 0) {
804 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" );
805 return;
806 }
807 if (count <= 0) {
808 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" );
809 return;
810 }
811 if (ctx->Array.LockCount != 0) {
812 _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" );
813 return;
814 }
815
816 ctx->Array.LockFirst = first;
817 ctx->Array.LockCount = count;
818
819 ctx->NewState |= _NEW_ARRAY;
820 ctx->Array.NewState |= _NEW_ARRAY_ALL;
821
822 if (ctx->Driver.LockArraysEXT)
823 ctx->Driver.LockArraysEXT( ctx, first, count );
824 }
825
826
827 void GLAPIENTRY
828 _mesa_UnlockArraysEXT( void )
829 {
830 GET_CURRENT_CONTEXT(ctx);
831 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
832
833 if (MESA_VERBOSE & VERBOSE_API)
834 _mesa_debug(ctx, "glUnlockArrays\n");
835
836 if (ctx->Array.LockCount == 0) {
837 _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" );
838 return;
839 }
840
841 ctx->Array.LockFirst = 0;
842 ctx->Array.LockCount = 0;
843 ctx->NewState |= _NEW_ARRAY;
844 ctx->Array.NewState |= _NEW_ARRAY_ALL;
845
846 if (ctx->Driver.UnlockArraysEXT)
847 ctx->Driver.UnlockArraysEXT( ctx );
848 }
849
850
851 /* GL_EXT_multi_draw_arrays */
852 /* Somebody forgot to spec the first and count parameters as const! <sigh> */
853 void GLAPIENTRY
854 _mesa_MultiDrawArraysEXT( GLenum mode, GLint *first,
855 GLsizei *count, GLsizei primcount )
856 {
857 GET_CURRENT_CONTEXT(ctx);
858 GLint i;
859
860 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
861
862 for (i = 0; i < primcount; i++) {
863 if (count[i] > 0) {
864 CALL_DrawArrays(ctx->Exec, (mode, first[i], count[i]));
865 }
866 }
867 }
868
869
870 /* GL_EXT_multi_draw_arrays */
871 void GLAPIENTRY
872 _mesa_MultiDrawElementsEXT( GLenum mode, const GLsizei *count, GLenum type,
873 const GLvoid **indices, GLsizei primcount )
874 {
875 GET_CURRENT_CONTEXT(ctx);
876 GLint i;
877
878 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
879
880 for (i = 0; i < primcount; i++) {
881 if (count[i] > 0) {
882 CALL_DrawElements(ctx->Exec, (mode, count[i], type, indices[i]));
883 }
884 }
885 }
886
887
888 /* GL_IBM_multimode_draw_arrays */
889 void GLAPIENTRY
890 _mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
891 const GLsizei * count,
892 GLsizei primcount, GLint modestride )
893 {
894 GET_CURRENT_CONTEXT(ctx);
895 GLint i;
896
897 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
898
899 for ( i = 0 ; i < primcount ; i++ ) {
900 if ( count[i] > 0 ) {
901 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
902 CALL_DrawArrays(ctx->Exec, ( m, first[i], count[i] ));
903 }
904 }
905 }
906
907
908 /* GL_IBM_multimode_draw_arrays */
909 void GLAPIENTRY
910 _mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
911 GLenum type, const GLvoid * const * indices,
912 GLsizei primcount, GLint modestride )
913 {
914 GET_CURRENT_CONTEXT(ctx);
915 GLint i;
916
917 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
918
919 /* XXX not sure about ARB_vertex_buffer_object handling here */
920
921 for ( i = 0 ; i < primcount ; i++ ) {
922 if ( count[i] > 0 ) {
923 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
924 CALL_DrawElements(ctx->Exec, ( m, count[i], type, indices[i] ));
925 }
926 }
927 }
928
929
930 /**
931 * Initialize vertex array state for given context.
932 */
933 void
934 _mesa_init_varray(GLcontext *ctx)
935 {
936 ctx->Array.DefaultArrayObj = _mesa_new_array_object(ctx, 0);
937 ctx->Array.ArrayObj = ctx->Array.DefaultArrayObj;
938
939 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
940 }