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