Moved _mesa_VertexAttribPointerNV into varray.c.
[mesa.git] / src / mesa / main / varray.c
1 /* $Id: varray.c,v 1.41 2002/01/11 17:25:35 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 4.1
6 *
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27 #ifdef PC_HEADER
28 #include "all.h"
29 #else
30 #include "glheader.h"
31 #include "context.h"
32 #include "enable.h"
33 #include "enums.h"
34 #include "dlist.h"
35 #include "light.h"
36 #include "macros.h"
37 #include "mmath.h"
38 #include "state.h"
39 #include "texstate.h"
40 #include "mtypes.h"
41 #include "varray.h"
42 #include "math/m_translate.h"
43 #endif
44
45
46
47 void
48 _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
49 {
50 GET_CURRENT_CONTEXT(ctx);
51 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
52
53 if (size < 2 || size > 4) {
54 _mesa_error( ctx, GL_INVALID_VALUE, "glVertexPointer(size)" );
55 return;
56 }
57 if (stride < 0) {
58 _mesa_error( ctx, GL_INVALID_VALUE, "glVertexPointer(stride)" );
59 return;
60 }
61
62 if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API))
63 fprintf(stderr, "glVertexPointer( sz %d type %s stride %d )\n", size,
64 _mesa_lookup_enum_by_nr( type ),
65 stride);
66
67 /* always need to check that <type> is legal */
68 switch (type) {
69 case GL_SHORT:
70 ctx->Array.Vertex.StrideB = size * sizeof(GLshort);
71 break;
72 case GL_INT:
73 ctx->Array.Vertex.StrideB = size * sizeof(GLint);
74 break;
75 case GL_FLOAT:
76 ctx->Array.Vertex.StrideB = size * sizeof(GLfloat);
77 break;
78 case GL_DOUBLE:
79 ctx->Array.Vertex.StrideB = size * sizeof(GLdouble);
80 break;
81 default:
82 _mesa_error( ctx, GL_INVALID_ENUM, "glVertexPointer(type)" );
83 return;
84 }
85
86 if (stride)
87 ctx->Array.Vertex.StrideB = stride;
88
89 ctx->Array.Vertex.Size = size;
90 ctx->Array.Vertex.Type = type;
91 ctx->Array.Vertex.Stride = stride;
92 ctx->Array.Vertex.Ptr = (void *) ptr;
93 ctx->NewState |= _NEW_ARRAY;
94 ctx->Array.NewState |= _NEW_ARRAY_VERTEX;
95
96 if (ctx->Driver.VertexPointer)
97 ctx->Driver.VertexPointer( ctx, size, type, stride, ptr );
98 }
99
100
101
102
103 void
104 _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
105 {
106 GET_CURRENT_CONTEXT(ctx);
107 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
108
109 if (stride < 0) {
110 _mesa_error( ctx, GL_INVALID_VALUE, "glNormalPointer(stride)" );
111 return;
112 }
113
114 if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API))
115 fprintf(stderr, "glNormalPointer( type %s stride %d )\n",
116 _mesa_lookup_enum_by_nr( type ),
117 stride);
118
119 switch (type) {
120 case GL_BYTE:
121 ctx->Array.Normal.StrideB = 3 * sizeof(GLbyte);
122 break;
123 case GL_SHORT:
124 ctx->Array.Normal.StrideB = 3 * sizeof(GLshort);
125 break;
126 case GL_INT:
127 ctx->Array.Normal.StrideB = 3 * sizeof(GLint);
128 break;
129 case GL_FLOAT:
130 ctx->Array.Normal.StrideB = 3 * sizeof(GLfloat);
131 break;
132 case GL_DOUBLE:
133 ctx->Array.Normal.StrideB = 3 * sizeof(GLdouble);
134 break;
135 default:
136 _mesa_error( ctx, GL_INVALID_ENUM, "glNormalPointer(type)" );
137 return;
138 }
139 if (stride)
140 ctx->Array.Normal.StrideB = stride;
141
142 ctx->Array.Normal.Size = 3;
143 ctx->Array.Normal.Type = type;
144 ctx->Array.Normal.Stride = stride;
145 ctx->Array.Normal.Ptr = (void *) ptr;
146 ctx->NewState |= _NEW_ARRAY;
147 ctx->Array.NewState |= _NEW_ARRAY_VERTEX;
148
149 if (ctx->Driver.NormalPointer)
150 ctx->Driver.NormalPointer( ctx, type, stride, ptr );
151 }
152
153
154
155 void
156 _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
157 {
158 GET_CURRENT_CONTEXT(ctx);
159 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
160
161 if (size < 3 || size > 4) {
162 _mesa_error( ctx, GL_INVALID_VALUE, "glColorPointer(size)" );
163 return;
164 }
165 if (stride<0) {
166 _mesa_error( ctx, GL_INVALID_VALUE, "glColorPointer(stride)" );
167 return;
168 }
169
170 if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API))
171 fprintf(stderr, "glColorPointer( sz %d type %s stride %d )\n", size,
172 _mesa_lookup_enum_by_nr( type ),
173 stride);
174
175 switch (type) {
176 case GL_BYTE:
177 ctx->Array.Color.StrideB = size * sizeof(GLbyte);
178 break;
179 case GL_UNSIGNED_BYTE:
180 ctx->Array.Color.StrideB = size * sizeof(GLubyte);
181 break;
182 case GL_SHORT:
183 ctx->Array.Color.StrideB = size * sizeof(GLshort);
184 break;
185 case GL_UNSIGNED_SHORT:
186 ctx->Array.Color.StrideB = size * sizeof(GLushort);
187 break;
188 case GL_INT:
189 ctx->Array.Color.StrideB = size * sizeof(GLint);
190 break;
191 case GL_UNSIGNED_INT:
192 ctx->Array.Color.StrideB = size * sizeof(GLuint);
193 break;
194 case GL_FLOAT:
195 ctx->Array.Color.StrideB = size * sizeof(GLfloat);
196 break;
197 case GL_DOUBLE:
198 ctx->Array.Color.StrideB = size * sizeof(GLdouble);
199 break;
200 default:
201 _mesa_error( ctx, GL_INVALID_ENUM, "glColorPointer(type)" );
202 return;
203 }
204
205 if (stride)
206 ctx->Array.Color.StrideB = stride;
207
208 ctx->Array.Color.Size = size;
209 ctx->Array.Color.Type = type;
210 ctx->Array.Color.Stride = stride;
211 ctx->Array.Color.Ptr = (void *) ptr;
212 ctx->NewState |= _NEW_ARRAY;
213 ctx->Array.NewState |= _NEW_ARRAY_VERTEX;
214
215 if (ctx->Driver.ColorPointer)
216 ctx->Driver.ColorPointer( ctx, size, type, stride, ptr );
217 }
218
219
220
221 void
222 _mesa_FogCoordPointerEXT(GLenum type, GLsizei stride, const GLvoid *ptr)
223 {
224 GET_CURRENT_CONTEXT(ctx);
225 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
226
227 if (stride < 0) {
228 _mesa_error( ctx, GL_INVALID_VALUE, "glFogCoordPointer(stride)" );
229 return;
230 }
231
232 switch (type) {
233 case GL_FLOAT:
234 ctx->Array.FogCoord.StrideB = sizeof(GLfloat);
235 break;
236 case GL_DOUBLE:
237 ctx->Array.FogCoord.StrideB = sizeof(GLdouble);
238 break;
239 default:
240 _mesa_error( ctx, GL_INVALID_ENUM, "glFogCoordPointer(type)" );
241 return;
242 }
243
244 if (stride)
245 ctx->Array.FogCoord.StrideB = stride;
246
247 ctx->Array.FogCoord.Size = 1;
248 ctx->Array.FogCoord.Type = type;
249 ctx->Array.FogCoord.Stride = stride;
250 ctx->Array.FogCoord.Ptr = (void *) ptr;
251 ctx->NewState |= _NEW_ARRAY;
252 ctx->Array.NewState |= _NEW_ARRAY_VERTEX;
253
254 if (ctx->Driver.FogCoordPointer)
255 ctx->Driver.FogCoordPointer( ctx, type, stride, ptr );
256 }
257
258
259 void
260 _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
261 {
262 GET_CURRENT_CONTEXT(ctx);
263 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
264
265 if (stride < 0) {
266 _mesa_error( ctx, GL_INVALID_VALUE, "glIndexPointer(stride)" );
267 return;
268 }
269
270 switch (type) {
271 case GL_UNSIGNED_BYTE:
272 ctx->Array.Index.StrideB = sizeof(GLubyte);
273 break;
274 case GL_SHORT:
275 ctx->Array.Index.StrideB = sizeof(GLshort);
276 break;
277 case GL_INT:
278 ctx->Array.Index.StrideB = sizeof(GLint);
279 break;
280 case GL_FLOAT:
281 ctx->Array.Index.StrideB = sizeof(GLfloat);
282 break;
283 case GL_DOUBLE:
284 ctx->Array.Index.StrideB = sizeof(GLdouble);
285 break;
286 default:
287 _mesa_error( ctx, GL_INVALID_ENUM, "glIndexPointer(type)" );
288 return;
289 }
290
291 if (stride)
292 ctx->Array.Index.StrideB = stride;
293
294 ctx->Array.Index.Size = 1;
295 ctx->Array.Index.Type = type;
296 ctx->Array.Index.Stride = stride;
297 ctx->Array.Index.Ptr = (void *) ptr;
298 ctx->NewState |= _NEW_ARRAY;
299 ctx->Array.NewState |= _NEW_ARRAY_VERTEX;
300
301 if (ctx->Driver.IndexPointer)
302 ctx->Driver.IndexPointer( ctx, type, stride, ptr );
303 }
304
305
306 void
307 _mesa_SecondaryColorPointerEXT(GLint size, GLenum type,
308 GLsizei stride, const GLvoid *ptr)
309 {
310 GET_CURRENT_CONTEXT(ctx);
311 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
312
313 if (size != 3 && size != 4) {
314 _mesa_error( ctx, GL_INVALID_VALUE, "glSecondaryColorPointer(size)" );
315 return;
316 }
317 if (stride < 0) {
318 _mesa_error( ctx, GL_INVALID_VALUE, "glSecondaryColorPointer(stride)" );
319 return;
320 }
321
322 if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API))
323 fprintf(stderr,
324 "glSecondaryColorPointer( sz %d type %s stride %d )\n", size,
325 _mesa_lookup_enum_by_nr( type ),
326 stride);
327
328 switch (type) {
329 case GL_BYTE:
330 ctx->Array.SecondaryColor.StrideB = size * sizeof(GLbyte);
331 break;
332 case GL_UNSIGNED_BYTE:
333 ctx->Array.SecondaryColor.StrideB = size * sizeof(GLubyte);
334 break;
335 case GL_SHORT:
336 ctx->Array.SecondaryColor.StrideB = size * sizeof(GLshort);
337 break;
338 case GL_UNSIGNED_SHORT:
339 ctx->Array.SecondaryColor.StrideB = size * sizeof(GLushort);
340 break;
341 case GL_INT:
342 ctx->Array.SecondaryColor.StrideB = size * sizeof(GLint);
343 break;
344 case GL_UNSIGNED_INT:
345 ctx->Array.SecondaryColor.StrideB = size * sizeof(GLuint);
346 break;
347 case GL_FLOAT:
348 ctx->Array.SecondaryColor.StrideB = size * sizeof(GLfloat);
349 break;
350 case GL_DOUBLE:
351 ctx->Array.SecondaryColor.StrideB = size * sizeof(GLdouble);
352 break;
353 default:
354 _mesa_error( ctx, GL_INVALID_ENUM, "glSecondaryColorPointer(type)" );
355 return;
356 }
357
358 if (stride)
359 ctx->Array.SecondaryColor.StrideB = stride;
360
361 ctx->Array.SecondaryColor.Size = 3; /* hardwire */
362 ctx->Array.SecondaryColor.Type = type;
363 ctx->Array.SecondaryColor.Stride = stride;
364 ctx->Array.SecondaryColor.Ptr = (void *) ptr;
365 ctx->NewState |= _NEW_ARRAY;
366 ctx->Array.NewState |= _NEW_ARRAY_VERTEX;
367
368 if (ctx->Driver.SecondaryColorPointer)
369 ctx->Driver.SecondaryColorPointer( ctx, size, type, stride, ptr );
370 }
371
372
373
374 void
375 _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
376 const GLvoid *ptr)
377 {
378 GET_CURRENT_CONTEXT(ctx);
379 GLuint texUnit = ctx->Array.ActiveTexture;
380 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
381
382 if (size < 1 || size > 4) {
383 _mesa_error( ctx, GL_INVALID_VALUE, "glTexCoordPointer(size)" );
384 return;
385 }
386 if (stride < 0) {
387 _mesa_error( ctx, GL_INVALID_VALUE, "glTexCoordPointer(stride)" );
388 return;
389 }
390
391 if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API))
392 fprintf(stderr, "glTexCoordPointer( unit %u sz %d type %s stride %d )\n",
393 texUnit,
394 size,
395 _mesa_lookup_enum_by_nr( type ),
396 stride);
397
398 /* always need to check that <type> is legal */
399 switch (type) {
400 case GL_SHORT:
401 ctx->Array.TexCoord[texUnit].StrideB = size * sizeof(GLshort);
402 break;
403 case GL_INT:
404 ctx->Array.TexCoord[texUnit].StrideB = size * sizeof(GLint);
405 break;
406 case GL_FLOAT:
407 ctx->Array.TexCoord[texUnit].StrideB = size * sizeof(GLfloat);
408 break;
409 case GL_DOUBLE:
410 ctx->Array.TexCoord[texUnit].StrideB = size * sizeof(GLdouble);
411 break;
412 default:
413 _mesa_error( ctx, GL_INVALID_ENUM, "glTexCoordPointer(type)" );
414 return;
415 }
416
417 if (stride)
418 ctx->Array.TexCoord[texUnit].StrideB = stride;
419
420 ctx->Array.TexCoord[texUnit].Size = size;
421 ctx->Array.TexCoord[texUnit].Type = type;
422 ctx->Array.TexCoord[texUnit].Stride = stride;
423 ctx->Array.TexCoord[texUnit].Ptr = (void *) ptr;
424 ctx->NewState |= _NEW_ARRAY;
425 ctx->Array.NewState |= _NEW_ARRAY_VERTEX;
426
427 if (ctx->Driver.TexCoordPointer)
428 ctx->Driver.TexCoordPointer( ctx, size, type, stride, ptr );
429 }
430
431
432 void
433 _mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *vptr)
434 {
435 GET_CURRENT_CONTEXT(ctx);
436 const GLboolean *ptr = (GLboolean *)vptr;
437 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
438
439 if (stride<0) {
440 _mesa_error( ctx, GL_INVALID_VALUE, "glEdgeFlagPointer(stride)" );
441 return;
442 }
443 ctx->Array.EdgeFlag.Stride = stride;
444 ctx->Array.EdgeFlag.StrideB = stride ? stride : sizeof(GLboolean);
445 ctx->Array.EdgeFlag.Ptr = (GLboolean *) ptr;
446 ctx->NewState |= _NEW_ARRAY;
447 ctx->Array.NewState |= _NEW_ARRAY_VERTEX;
448
449 if (ctx->Driver.EdgeFlagPointer)
450 ctx->Driver.EdgeFlagPointer( ctx, stride, ptr );
451 }
452
453
454 void _mesa_VertexAttribPointerNV(GLuint index, GLint size, GLenum type,
455 GLsizei stride, const GLvoid *pointer)
456 {
457 GET_CURRENT_CONTEXT(ctx);
458 ASSERT_OUTSIDE_BEGIN_END(ctx);
459
460 if (index >= VP_NUM_PROG_REGS) {
461 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(index)");
462 return;
463 }
464
465 if (size < 1 || size > 4) {
466 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(size)");
467 return;
468 }
469
470 if (stride < 0) {
471 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(stride)");
472 return;
473 }
474
475 if (type == GL_UNSIGNED_BYTE && size != 4) {
476 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(size!=4)");
477 return;
478 }
479
480 /* check for valid 'type' and compute StrideB right away */
481 switch (type) {
482 case GL_UNSIGNED_BYTE:
483 ctx->Array.Normal.StrideB = size * sizeof(GLubyte);
484 break;
485 case GL_SHORT:
486 ctx->Array.Normal.StrideB = size * sizeof(GLshort);
487 break;
488 case GL_FLOAT:
489 ctx->Array.Normal.StrideB = size * sizeof(GLfloat);
490 break;
491 case GL_DOUBLE:
492 ctx->Array.Normal.StrideB = size * sizeof(GLdouble);
493 break;
494 default:
495 _mesa_error( ctx, GL_INVALID_ENUM, "glVertexAttribPointerNV(type)" );
496 return;
497 }
498
499 if (stride)
500 ctx->Array.VertexAttrib[index].StrideB = stride;
501
502 ctx->Array.VertexAttrib[index].Stride = stride;
503 ctx->Array.VertexAttrib[index].Size = size;
504 ctx->Array.VertexAttrib[index].Type = type;
505
506 /* XXX need new flags here??? */
507 ctx->NewState |= _NEW_ARRAY;
508 ctx->Array.NewState |= _NEW_ARRAY_VERTEX;
509
510 /* XXX
511 if (ctx->Driver.VertexAttribdPointer)
512 ctx->Driver.VertexAttribPointer( ctx, index, size, type, stride, ptr );
513 */
514 }
515
516
517 void
518 _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
519 GLsizei count, const GLvoid *ptr)
520 {
521 (void) count;
522 _mesa_VertexPointer(size, type, stride, ptr);
523 }
524
525
526 void
527 _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
528 const GLvoid *ptr)
529 {
530 (void) count;
531 _mesa_NormalPointer(type, stride, ptr);
532 }
533
534
535 void
536 _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
537 const GLvoid *ptr)
538 {
539 (void) count;
540 _mesa_ColorPointer(size, type, stride, ptr);
541 }
542
543
544 void
545 _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
546 const GLvoid *ptr)
547 {
548 (void) count;
549 _mesa_IndexPointer(type, stride, ptr);
550 }
551
552
553 void
554 _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
555 GLsizei count, const GLvoid *ptr)
556 {
557 (void) count;
558 _mesa_TexCoordPointer(size, type, stride, ptr);
559 }
560
561
562 void
563 _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
564 {
565 (void) count;
566 _mesa_EdgeFlagPointer(stride, ptr);
567 }
568
569
570
571
572 void
573 _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
574 {
575 GET_CURRENT_CONTEXT(ctx);
576 GLboolean tflag, cflag, nflag; /* enable/disable flags */
577 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
578
579 GLenum ctype = 0; /* color type */
580 GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
581 GLint defstride; /* default stride */
582 GLint c, f;
583 GLint coordUnitSave;
584
585 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
586
587 f = sizeof(GLfloat);
588 c = f * ((4*sizeof(GLubyte) + (f-1)) / f);
589
590 if (stride<0) {
591 _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
592 return;
593 }
594
595 switch (format) {
596 case GL_V2F:
597 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
598 tcomps = 0; ccomps = 0; vcomps = 2;
599 voffset = 0;
600 defstride = 2*f;
601 break;
602 case GL_V3F:
603 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
604 tcomps = 0; ccomps = 0; vcomps = 3;
605 voffset = 0;
606 defstride = 3*f;
607 break;
608 case GL_C4UB_V2F:
609 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
610 tcomps = 0; ccomps = 4; vcomps = 2;
611 ctype = GL_UNSIGNED_BYTE;
612 coffset = 0;
613 voffset = c;
614 defstride = c + 2*f;
615 break;
616 case GL_C4UB_V3F:
617 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
618 tcomps = 0; ccomps = 4; vcomps = 3;
619 ctype = GL_UNSIGNED_BYTE;
620 coffset = 0;
621 voffset = c;
622 defstride = c + 3*f;
623 break;
624 case GL_C3F_V3F:
625 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
626 tcomps = 0; ccomps = 3; vcomps = 3;
627 ctype = GL_FLOAT;
628 coffset = 0;
629 voffset = 3*f;
630 defstride = 6*f;
631 break;
632 case GL_N3F_V3F:
633 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
634 tcomps = 0; ccomps = 0; vcomps = 3;
635 noffset = 0;
636 voffset = 3*f;
637 defstride = 6*f;
638 break;
639 case GL_C4F_N3F_V3F:
640 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
641 tcomps = 0; ccomps = 4; vcomps = 3;
642 ctype = GL_FLOAT;
643 coffset = 0;
644 noffset = 4*f;
645 voffset = 7*f;
646 defstride = 10*f;
647 break;
648 case GL_T2F_V3F:
649 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
650 tcomps = 2; ccomps = 0; vcomps = 3;
651 voffset = 2*f;
652 defstride = 5*f;
653 break;
654 case GL_T4F_V4F:
655 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
656 tcomps = 4; ccomps = 0; vcomps = 4;
657 voffset = 4*f;
658 defstride = 8*f;
659 break;
660 case GL_T2F_C4UB_V3F:
661 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
662 tcomps = 2; ccomps = 4; vcomps = 3;
663 ctype = GL_UNSIGNED_BYTE;
664 coffset = 2*f;
665 voffset = c+2*f;
666 defstride = c+5*f;
667 break;
668 case GL_T2F_C3F_V3F:
669 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
670 tcomps = 2; ccomps = 3; vcomps = 3;
671 ctype = GL_FLOAT;
672 coffset = 2*f;
673 voffset = 5*f;
674 defstride = 8*f;
675 break;
676 case GL_T2F_N3F_V3F:
677 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
678 tcomps = 2; ccomps = 0; vcomps = 3;
679 noffset = 2*f;
680 voffset = 5*f;
681 defstride = 8*f;
682 break;
683 case GL_T2F_C4F_N3F_V3F:
684 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
685 tcomps = 2; ccomps = 4; vcomps = 3;
686 ctype = GL_FLOAT;
687 coffset = 2*f;
688 noffset = 6*f;
689 voffset = 9*f;
690 defstride = 12*f;
691 break;
692 case GL_T4F_C4F_N3F_V4F:
693 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
694 tcomps = 4; ccomps = 4; vcomps = 4;
695 ctype = GL_FLOAT;
696 coffset = 4*f;
697 noffset = 8*f;
698 voffset = 11*f;
699 defstride = 15*f;
700 break;
701 default:
702 _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
703 return;
704 }
705
706 if (stride==0) {
707 stride = defstride;
708 }
709
710 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
711 _mesa_DisableClientState( GL_INDEX_ARRAY );
712
713 /* Texcoords */
714 coordUnitSave = ctx->Array.ActiveTexture;
715 if (tflag) {
716 GLint i;
717 GLint factor = ctx->Array.TexCoordInterleaveFactor;
718 for (i = 0; i < factor; i++) {
719 _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + i) );
720 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
721 _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
722 (GLubyte *) pointer + i * coffset );
723 }
724 for (i = factor; i < (GLint) ctx->Const.MaxTextureUnits; i++) {
725 _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + i) );
726 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
727 }
728 }
729 else {
730 GLint i;
731 for (i = 0; i < (GLint) ctx->Const.MaxTextureUnits; i++) {
732 _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + i) );
733 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
734 }
735 }
736 /* Restore texture coordinate unit index */
737 _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + coordUnitSave) );
738
739
740 /* Color */
741 if (cflag) {
742 _mesa_EnableClientState( GL_COLOR_ARRAY );
743 _mesa_ColorPointer( ccomps, ctype, stride,
744 (GLubyte*) pointer + coffset );
745 }
746 else {
747 _mesa_DisableClientState( GL_COLOR_ARRAY );
748 }
749
750
751 /* Normals */
752 if (nflag) {
753 _mesa_EnableClientState( GL_NORMAL_ARRAY );
754 _mesa_NormalPointer( GL_FLOAT, stride,
755 (GLubyte*) pointer + noffset );
756 }
757 else {
758 _mesa_DisableClientState( GL_NORMAL_ARRAY );
759 }
760
761 _mesa_EnableClientState( GL_VERTEX_ARRAY );
762 _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
763 (GLubyte *) pointer + voffset );
764 }
765
766
767
768 void
769 _mesa_LockArraysEXT(GLint first, GLsizei count)
770 {
771 GET_CURRENT_CONTEXT(ctx);
772 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
773
774 if (MESA_VERBOSE & VERBOSE_API)
775 fprintf(stderr, "glLockArrays %d %d\n", first, count);
776
777 if (first == 0 && count > 0 &&
778 count <= (GLint) ctx->Const.MaxArrayLockSize) {
779 ctx->Array.LockFirst = first;
780 ctx->Array.LockCount = count;
781 }
782 else {
783 ctx->Array.LockFirst = 0;
784 ctx->Array.LockCount = 0;
785 }
786
787 ctx->NewState |= _NEW_ARRAY;
788 ctx->Array.NewState |= _NEW_ARRAY_ALL;
789
790 if (ctx->Driver.LockArraysEXT)
791 ctx->Driver.LockArraysEXT( ctx, first, count );
792 }
793
794
795 void
796 _mesa_UnlockArraysEXT( void )
797 {
798 GET_CURRENT_CONTEXT(ctx);
799 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
800
801 if (MESA_VERBOSE & VERBOSE_API)
802 fprintf(stderr, "glUnlockArrays\n");
803
804 ctx->Array.LockFirst = 0;
805 ctx->Array.LockCount = 0;
806 ctx->NewState |= _NEW_ARRAY;
807 ctx->Array.NewState |= _NEW_ARRAY_ALL;
808
809 if (ctx->Driver.UnlockArraysEXT)
810 ctx->Driver.UnlockArraysEXT( ctx );
811 }