8f6621ee45fec9722fea211837ac1cf424b47ed2
[mesa.git] / src / mesa / main / varray.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.2
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 #include "glheader.h"
27 #include "imports.h"
28 #include "bufferobj.h"
29 #include "context.h"
30 #include "enable.h"
31 #include "enums.h"
32 #include "mtypes.h"
33 #include "varray.h"
34 #include "arrayobj.h"
35 #include "glapi/dispatch.h"
36
37
38 /**
39 * Update the fields of a vertex array object.
40 * We need to do a few special things for arrays that live in
41 * vertex buffer objects.
42 *
43 * \param array the array to update
44 * \param dirtyBit which bit to set in ctx->Array.NewState for this array
45 * \param elementSize size of each array element, in bytes
46 * \param size components per element (1, 2, 3 or 4)
47 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
48 * \param stride stride between elements, in elements
49 * \param normalized are integer types converted to floats in [-1, 1]?
50 * \param ptr the address (or offset inside VBO) of the array data
51 */
52 static void
53 update_array(GLcontext *ctx, struct gl_client_array *array,
54 GLbitfield dirtyBit, GLsizei elementSize,
55 GLint size, GLenum type, 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 #if FEATURE_ARB_vertex_buffer_object
67 _mesa_reference_buffer_object(ctx, &array->BufferObj,
68 ctx->Array.ArrayBufferObj);
69
70 /* Compute the index of the last array element that's inside the buffer.
71 * Later in glDrawArrays we'll check if start + count > _MaxElement to
72 * be sure we won't go out of bounds.
73 */
74 if (ctx->Array.ArrayBufferObj->Name)
75 array->_MaxElement = ((GLsizeiptrARB) ctx->Array.ArrayBufferObj->Size
76 - (GLsizeiptrARB) array->Ptr + array->StrideB
77 - elementSize) / array->StrideB;
78 else
79 #endif
80 array->_MaxElement = 2 * 1000 * 1000 * 1000; /* just a big number */
81
82 ctx->NewState |= _NEW_ARRAY;
83 ctx->Array.NewState |= dirtyBit;
84 }
85
86
87 void GLAPIENTRY
88 _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
89 {
90 GLsizei elementSize;
91 GET_CURRENT_CONTEXT(ctx);
92 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
93
94 if (size < 2 || size > 4) {
95 _mesa_error( ctx, GL_INVALID_VALUE, "glVertexPointer(size)" );
96 return;
97 }
98 if (stride < 0) {
99 _mesa_error( ctx, GL_INVALID_VALUE, "glVertexPointer(stride)" );
100 return;
101 }
102
103 if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API))
104 _mesa_debug(ctx, "glVertexPointer( sz %d type %s stride %d )\n", size,
105 _mesa_lookup_enum_by_nr( type ), stride);
106
107 /* always need to check that <type> is legal */
108 switch (type) {
109 case GL_SHORT:
110 elementSize = size * sizeof(GLshort);
111 break;
112 case GL_INT:
113 elementSize = size * sizeof(GLint);
114 break;
115 case GL_FLOAT:
116 elementSize = size * sizeof(GLfloat);
117 break;
118 case GL_DOUBLE:
119 elementSize = size * sizeof(GLdouble);
120 break;
121 #if FEATURE_fixedpt
122 case GL_FIXED:
123 elementSize = size * sizeof(GLfixed);
124 break;
125 #endif
126 #if FEATURE_vertex_array_byte
127 case GL_BYTE:
128 elementSize = size * sizeof(GLbyte);
129 break;
130 #endif
131 default:
132 _mesa_error( ctx, GL_INVALID_ENUM, "glVertexPointer(type)" );
133 return;
134 }
135
136 update_array(ctx, &ctx->Array.ArrayObj->Vertex, _NEW_ARRAY_VERTEX,
137 elementSize, size, type, GL_RGBA, stride, GL_FALSE, ptr);
138
139 if (ctx->Driver.VertexPointer)
140 ctx->Driver.VertexPointer( ctx, size, type, stride, ptr );
141 }
142
143
144 void GLAPIENTRY
145 _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
146 {
147 GLsizei elementSize;
148 GET_CURRENT_CONTEXT(ctx);
149 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
150
151 if (stride < 0) {
152 _mesa_error( ctx, GL_INVALID_VALUE, "glNormalPointer(stride)" );
153 return;
154 }
155
156 if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API))
157 _mesa_debug(ctx, "glNormalPointer( type %s stride %d )\n",
158 _mesa_lookup_enum_by_nr( type ), stride);
159
160 switch (type) {
161 case GL_BYTE:
162 elementSize = 3 * sizeof(GLbyte);
163 break;
164 case GL_SHORT:
165 elementSize = 3 * sizeof(GLshort);
166 break;
167 case GL_INT:
168 elementSize = 3 * sizeof(GLint);
169 break;
170 case GL_FLOAT:
171 elementSize = 3 * sizeof(GLfloat);
172 break;
173 case GL_DOUBLE:
174 elementSize = 3 * sizeof(GLdouble);
175 break;
176 #if FEATURE_fixedpt
177 case GL_FIXED:
178 elementSize = 3 * sizeof(GLfixed);
179 break;
180 #endif
181 default:
182 _mesa_error( ctx, GL_INVALID_ENUM, "glNormalPointer(type)" );
183 return;
184 }
185
186 update_array(ctx, &ctx->Array.ArrayObj->Normal, _NEW_ARRAY_NORMAL,
187 elementSize, 3, type, GL_RGBA, stride, GL_TRUE, ptr);
188
189 if (ctx->Driver.NormalPointer)
190 ctx->Driver.NormalPointer( ctx, type, stride, ptr );
191 }
192
193
194 void GLAPIENTRY
195 _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
196 {
197 GLsizei elementSize;
198 GLenum format;
199 GET_CURRENT_CONTEXT(ctx);
200 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
201
202 if (size < 3 || size > 4) {
203 if (!ctx->Extensions.EXT_vertex_array_bgra || size != GL_BGRA) {
204 _mesa_error(ctx, GL_INVALID_VALUE, "glColorPointer(size)");
205 return;
206 }
207 }
208 if (stride < 0) {
209 _mesa_error( ctx, GL_INVALID_VALUE, "glColorPointer(stride)" );
210 return;
211 }
212
213 if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API))
214 _mesa_debug(ctx, "glColorPointer( sz %d type %s stride %d )\n", size,
215 _mesa_lookup_enum_by_nr( type ), stride);
216
217 if (size == GL_BGRA) {
218 if (type != GL_UNSIGNED_BYTE) {
219 _mesa_error(ctx, GL_INVALID_VALUE, "glColorPointer(GL_BGRA/GLubyte)");
220 return;
221 }
222 format = GL_BGRA;
223 size = 4;
224 }
225 else {
226 format = GL_RGBA;
227 }
228
229 switch (type) {
230 case GL_BYTE:
231 elementSize = size * sizeof(GLbyte);
232 break;
233 case GL_UNSIGNED_BYTE:
234 elementSize = size * sizeof(GLubyte);
235 break;
236 case GL_SHORT:
237 elementSize = size * sizeof(GLshort);
238 break;
239 case GL_UNSIGNED_SHORT:
240 elementSize = size * sizeof(GLushort);
241 break;
242 case GL_INT:
243 elementSize = size * sizeof(GLint);
244 break;
245 case GL_UNSIGNED_INT:
246 elementSize = size * sizeof(GLuint);
247 break;
248 case GL_FLOAT:
249 elementSize = size * sizeof(GLfloat);
250 break;
251 case GL_DOUBLE:
252 elementSize = size * sizeof(GLdouble);
253 break;
254 #if FEATURE_fixedpt
255 case GL_FIXED:
256 elementSize = size * sizeof(GLfixed);
257 break;
258 #endif
259 default:
260 _mesa_error( ctx, GL_INVALID_ENUM, "glColorPointer(type)" );
261 return;
262 }
263
264 update_array(ctx, &ctx->Array.ArrayObj->Color, _NEW_ARRAY_COLOR0,
265 elementSize, size, type, format, stride, GL_TRUE, ptr);
266
267 if (ctx->Driver.ColorPointer)
268 ctx->Driver.ColorPointer( ctx, size, type, stride, ptr );
269 }
270
271
272 void GLAPIENTRY
273 _mesa_FogCoordPointerEXT(GLenum type, GLsizei stride, const GLvoid *ptr)
274 {
275 GLint elementSize;
276 GET_CURRENT_CONTEXT(ctx);
277 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
278
279 if (stride < 0) {
280 _mesa_error( ctx, GL_INVALID_VALUE, "glFogCoordPointer(stride)" );
281 return;
282 }
283
284 switch (type) {
285 case GL_FLOAT:
286 elementSize = sizeof(GLfloat);
287 break;
288 case GL_DOUBLE:
289 elementSize = sizeof(GLdouble);
290 break;
291 default:
292 _mesa_error( ctx, GL_INVALID_ENUM, "glFogCoordPointer(type)" );
293 return;
294 }
295
296 update_array(ctx, &ctx->Array.ArrayObj->FogCoord, _NEW_ARRAY_FOGCOORD,
297 elementSize, 1, type, GL_RGBA, stride, GL_FALSE, ptr);
298
299 if (ctx->Driver.FogCoordPointer)
300 ctx->Driver.FogCoordPointer( ctx, type, stride, ptr );
301 }
302
303
304 void GLAPIENTRY
305 _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
306 {
307 GLsizei elementSize;
308 GET_CURRENT_CONTEXT(ctx);
309 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
310
311 if (stride < 0) {
312 _mesa_error( ctx, GL_INVALID_VALUE, "glIndexPointer(stride)" );
313 return;
314 }
315
316 switch (type) {
317 case GL_UNSIGNED_BYTE:
318 elementSize = sizeof(GLubyte);
319 break;
320 case GL_SHORT:
321 elementSize = sizeof(GLshort);
322 break;
323 case GL_INT:
324 elementSize = sizeof(GLint);
325 break;
326 case GL_FLOAT:
327 elementSize = sizeof(GLfloat);
328 break;
329 case GL_DOUBLE:
330 elementSize = sizeof(GLdouble);
331 break;
332 default:
333 _mesa_error( ctx, GL_INVALID_ENUM, "glIndexPointer(type)" );
334 return;
335 }
336
337 update_array(ctx, &ctx->Array.ArrayObj->Index, _NEW_ARRAY_INDEX,
338 elementSize, 1, type, GL_RGBA, stride, GL_FALSE, ptr);
339
340 if (ctx->Driver.IndexPointer)
341 ctx->Driver.IndexPointer( ctx, type, stride, ptr );
342 }
343
344
345 void GLAPIENTRY
346 _mesa_SecondaryColorPointerEXT(GLint size, GLenum type,
347 GLsizei stride, const GLvoid *ptr)
348 {
349 GLsizei elementSize;
350 GLenum format;
351 GET_CURRENT_CONTEXT(ctx);
352 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
353
354 if (size != 3 && size != 4) {
355 if (!ctx->Extensions.EXT_vertex_array_bgra || size != GL_BGRA) {
356 _mesa_error(ctx, GL_INVALID_VALUE, "glSecondaryColorPointer(size)");
357 return;
358 }
359 }
360 if (stride < 0) {
361 _mesa_error( ctx, GL_INVALID_VALUE, "glSecondaryColorPointer(stride)" );
362 return;
363 }
364
365 if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API))
366 _mesa_debug(ctx, "glSecondaryColorPointer( sz %d type %s stride %d )\n",
367 size, _mesa_lookup_enum_by_nr( type ), stride);
368
369 if (size == GL_BGRA) {
370 if (type != GL_UNSIGNED_BYTE) {
371 _mesa_error(ctx, GL_INVALID_VALUE, "glColorPointer(GL_BGRA/GLubyte)");
372 return;
373 }
374 format = GL_BGRA;
375 size = 4;
376 }
377 else {
378 format = GL_RGBA;
379 }
380
381 switch (type) {
382 case GL_BYTE:
383 elementSize = size * sizeof(GLbyte);
384 break;
385 case GL_UNSIGNED_BYTE:
386 elementSize = size * sizeof(GLubyte);
387 break;
388 case GL_SHORT:
389 elementSize = size * sizeof(GLshort);
390 break;
391 case GL_UNSIGNED_SHORT:
392 elementSize = size * sizeof(GLushort);
393 break;
394 case GL_INT:
395 elementSize = size * sizeof(GLint);
396 break;
397 case GL_UNSIGNED_INT:
398 elementSize = size * sizeof(GLuint);
399 break;
400 case GL_FLOAT:
401 elementSize = size * sizeof(GLfloat);
402 break;
403 case GL_DOUBLE:
404 elementSize = size * sizeof(GLdouble);
405 break;
406 default:
407 _mesa_error( ctx, GL_INVALID_ENUM, "glSecondaryColorPointer(type)" );
408 return;
409 }
410
411 update_array(ctx, &ctx->Array.ArrayObj->SecondaryColor, _NEW_ARRAY_COLOR1,
412 elementSize, size, type, format, stride, GL_TRUE, ptr);
413
414 if (ctx->Driver.SecondaryColorPointer)
415 ctx->Driver.SecondaryColorPointer( ctx, size, type, stride, ptr );
416 }
417
418
419 void GLAPIENTRY
420 _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
421 const GLvoid *ptr)
422 {
423 GLint elementSize;
424 GET_CURRENT_CONTEXT(ctx);
425 const GLuint unit = ctx->Array.ActiveTexture;
426 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
427
428 if (size < 1 || size > 4) {
429 _mesa_error( ctx, GL_INVALID_VALUE, "glTexCoordPointer(size)" );
430 return;
431 }
432 if (stride < 0) {
433 _mesa_error( ctx, GL_INVALID_VALUE, "glTexCoordPointer(stride)" );
434 return;
435 }
436
437 if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API))
438 _mesa_debug(ctx, "glTexCoordPointer(unit %u sz %d type %s stride %d)\n",
439 unit, size, _mesa_lookup_enum_by_nr( type ), stride);
440
441 /* always need to check that <type> is legal */
442 switch (type) {
443 case GL_SHORT:
444 elementSize = size * sizeof(GLshort);
445 break;
446 case GL_INT:
447 elementSize = size * sizeof(GLint);
448 break;
449 case GL_FLOAT:
450 elementSize = size * sizeof(GLfloat);
451 break;
452 case GL_DOUBLE:
453 elementSize = size * sizeof(GLdouble);
454 break;
455 #if FEATURE_fixedpt
456 case GL_FIXED:
457 elementSize = size * sizeof(GLfixed);
458 break;
459 #endif
460 #if FEATURE_vertex_array_byte
461 case GL_BYTE:
462 elementSize = size * sizeof(GLbyte);
463 break;
464 #endif
465 default:
466 _mesa_error( ctx, GL_INVALID_ENUM, "glTexCoordPointer(type)" );
467 return;
468 }
469
470 update_array(ctx, &ctx->Array.ArrayObj->TexCoord[unit],
471 _NEW_ARRAY_TEXCOORD(unit),
472 elementSize, size, type, GL_RGBA, stride, GL_FALSE, ptr);
473
474 if (ctx->Driver.TexCoordPointer)
475 ctx->Driver.TexCoordPointer( ctx, size, type, stride, ptr );
476 }
477
478
479 void GLAPIENTRY
480 _mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr)
481 {
482 GET_CURRENT_CONTEXT(ctx);
483 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
484
485 if (stride < 0) {
486 _mesa_error( ctx, GL_INVALID_VALUE, "glEdgeFlagPointer(stride)" );
487 return;
488 }
489
490 update_array(ctx, &ctx->Array.ArrayObj->EdgeFlag, _NEW_ARRAY_EDGEFLAG,
491 sizeof(GLboolean), 1, GL_UNSIGNED_BYTE, GL_RGBA,
492 stride, GL_FALSE, ptr);
493
494 if (ctx->Driver.EdgeFlagPointer)
495 ctx->Driver.EdgeFlagPointer( ctx, stride, ptr );
496 }
497
498
499 void GLAPIENTRY
500 _mesa_PointSizePointer(GLenum type, GLsizei stride, const GLvoid *ptr)
501 {
502 GLsizei elementSize;
503 GET_CURRENT_CONTEXT(ctx);
504 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
505
506 if (stride < 0) {
507 _mesa_error( ctx, GL_INVALID_VALUE, "glPointSizePointer(stride)" );
508 return;
509 }
510
511 switch (type) {
512 case GL_FLOAT:
513 elementSize = sizeof(GLfloat);
514 break;
515 #if FEATURE_fixedpt
516 case GL_FIXED:
517 elementSize = sizeof(GLfixed);
518 break;
519 #endif
520 default:
521 _mesa_error( ctx, GL_INVALID_ENUM, "glPointSizePointer(type)" );
522 return;
523 }
524
525 update_array(ctx, &ctx->Array.ArrayObj->PointSize, _NEW_ARRAY_POINT_SIZE,
526 elementSize, 1, type, GL_RGBA, stride, GL_FALSE, ptr);
527 }
528
529
530 #if FEATURE_NV_vertex_program
531 void GLAPIENTRY
532 _mesa_VertexAttribPointerNV(GLuint index, GLint size, GLenum type,
533 GLsizei stride, const GLvoid *ptr)
534 {
535 GLboolean normalized = GL_FALSE;
536 GLsizei elementSize;
537 GLenum format;
538 GET_CURRENT_CONTEXT(ctx);
539 ASSERT_OUTSIDE_BEGIN_END(ctx);
540
541 if (index >= MAX_NV_VERTEX_PROGRAM_INPUTS) {
542 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(index)");
543 return;
544 }
545
546 if (size < 1 || size > 4) {
547 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(size)");
548 return;
549 }
550
551 if (stride < 0) {
552 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(stride)");
553 return;
554 }
555
556 if (type == GL_UNSIGNED_BYTE && size != 4) {
557 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(size!=4)");
558 return;
559 }
560
561 if (size == GL_BGRA) {
562 if (type != GL_UNSIGNED_BYTE) {
563 _mesa_error(ctx, GL_INVALID_VALUE,
564 "glVertexAttribPointerNV(GL_BGRA/type)");
565 return;
566 }
567
568 format = GL_BGRA;
569 size = 4;
570 normalized = GL_TRUE;
571 }
572 else {
573 format = GL_RGBA;
574 }
575
576 /* check for valid 'type' and compute StrideB right away */
577 switch (type) {
578 case GL_UNSIGNED_BYTE:
579 normalized = GL_TRUE;
580 elementSize = size * sizeof(GLubyte);
581 break;
582 case GL_SHORT:
583 elementSize = size * sizeof(GLshort);
584 break;
585 case GL_FLOAT:
586 elementSize = size * sizeof(GLfloat);
587 break;
588 case GL_DOUBLE:
589 elementSize = size * sizeof(GLdouble);
590 break;
591 default:
592 _mesa_error( ctx, GL_INVALID_ENUM, "glVertexAttribPointerNV(type)" );
593 return;
594 }
595
596 update_array(ctx, &ctx->Array.ArrayObj->VertexAttrib[index],
597 _NEW_ARRAY_ATTRIB(index),
598 elementSize, size, type, format, stride, normalized, ptr);
599
600 if (ctx->Driver.VertexAttribPointer)
601 ctx->Driver.VertexAttribPointer( ctx, index, size, type, stride, ptr );
602 }
603 #endif
604
605
606 #if FEATURE_ARB_vertex_program
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 * Initialize vertex array state for given context.
1069 */
1070 void
1071 _mesa_init_varray(GLcontext *ctx)
1072 {
1073 ctx->Array.DefaultArrayObj = _mesa_new_array_object(ctx, 0);
1074 _mesa_reference_array_object(ctx, &ctx->Array.ArrayObj,
1075 ctx->Array.DefaultArrayObj);
1076 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1077 }