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