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