mesa: reference counting for gl_array_object
[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 GET_CURRENT_CONTEXT(ctx);
538 ASSERT_OUTSIDE_BEGIN_END(ctx);
539
540 if (index >= MAX_VERTEX_PROGRAM_ATTRIBS) {
541 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(index)");
542 return;
543 }
544
545 if (size < 1 || size > 4) {
546 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(size)");
547 return;
548 }
549
550 if (stride < 0) {
551 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(stride)");
552 return;
553 }
554
555 if (type == GL_UNSIGNED_BYTE && size != 4) {
556 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(size!=4)");
557 return;
558 }
559
560 /* check for valid 'type' and compute StrideB right away */
561 switch (type) {
562 case GL_UNSIGNED_BYTE:
563 normalized = GL_TRUE;
564 elementSize = size * sizeof(GLubyte);
565 break;
566 case GL_SHORT:
567 elementSize = size * sizeof(GLshort);
568 break;
569 case GL_FLOAT:
570 elementSize = size * sizeof(GLfloat);
571 break;
572 case GL_DOUBLE:
573 elementSize = size * sizeof(GLdouble);
574 break;
575 default:
576 _mesa_error( ctx, GL_INVALID_ENUM, "glVertexAttribPointerNV(type)" );
577 return;
578 }
579
580 update_array(ctx, &ctx->Array.ArrayObj->VertexAttrib[index],
581 _NEW_ARRAY_ATTRIB(index),
582 elementSize, size, type, GL_RGBA, stride, normalized, ptr);
583
584 if (ctx->Driver.VertexAttribPointer)
585 ctx->Driver.VertexAttribPointer( ctx, index, size, type, stride, ptr );
586 }
587 #endif
588
589
590 #if FEATURE_ARB_vertex_program
591 void GLAPIENTRY
592 _mesa_VertexAttribPointerARB(GLuint index, GLint size, GLenum type,
593 GLboolean normalized,
594 GLsizei stride, const GLvoid *ptr)
595 {
596 GLsizei elementSize;
597 GLenum format;
598 GET_CURRENT_CONTEXT(ctx);
599 ASSERT_OUTSIDE_BEGIN_END(ctx);
600
601 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
602 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(index)");
603 return;
604 }
605
606 if (size < 1 || size > 4) {
607 if (!ctx->Extensions.EXT_vertex_array_bgra || size != GL_BGRA) {
608 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(size)");
609 return;
610 }
611 }
612
613 if (stride < 0) {
614 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(stride)");
615 return;
616 }
617
618 if (size == GL_BGRA) {
619 if (type != GL_UNSIGNED_BYTE) {
620 _mesa_error(ctx, GL_INVALID_VALUE,
621 "glVertexAttribPointerARB(GL_BGRA/type)");
622 return;
623 }
624 format = GL_BGRA;
625 size = 4;
626 normalized = GL_TRUE;
627 }
628 else {
629 format = GL_RGBA;
630 }
631
632 /* check for valid 'type' and compute StrideB right away */
633 /* NOTE: more types are supported here than in the NV extension */
634 switch (type) {
635 case GL_BYTE:
636 elementSize = size * sizeof(GLbyte);
637 break;
638 case GL_UNSIGNED_BYTE:
639 elementSize = size * sizeof(GLubyte);
640 break;
641 case GL_SHORT:
642 elementSize = size * sizeof(GLshort);
643 break;
644 case GL_UNSIGNED_SHORT:
645 elementSize = size * sizeof(GLushort);
646 break;
647 case GL_INT:
648 elementSize = size * sizeof(GLint);
649 break;
650 case GL_UNSIGNED_INT:
651 elementSize = size * sizeof(GLuint);
652 break;
653 case GL_FLOAT:
654 elementSize = size * sizeof(GLfloat);
655 break;
656 case GL_DOUBLE:
657 elementSize = size * sizeof(GLdouble);
658 break;
659 #if FEATURE_fixedpt
660 case GL_FIXED:
661 elementSize = size * sizeof(GLfixed);
662 break;
663 #endif
664 default:
665 _mesa_error( ctx, GL_INVALID_ENUM, "glVertexAttribPointerARB(type)" );
666 return;
667 }
668
669 update_array(ctx, &ctx->Array.ArrayObj->VertexAttrib[index],
670 _NEW_ARRAY_ATTRIB(index),
671 elementSize, size, type, GL_RGBA, stride, normalized, ptr);
672
673 if (ctx->Driver.VertexAttribPointer)
674 ctx->Driver.VertexAttribPointer(ctx, index, size, type, stride, ptr);
675 }
676 #endif
677
678
679 void GLAPIENTRY
680 _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
681 GLsizei count, const GLvoid *ptr)
682 {
683 (void) count;
684 _mesa_VertexPointer(size, type, stride, ptr);
685 }
686
687
688 void GLAPIENTRY
689 _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
690 const GLvoid *ptr)
691 {
692 (void) count;
693 _mesa_NormalPointer(type, stride, ptr);
694 }
695
696
697 void GLAPIENTRY
698 _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
699 const GLvoid *ptr)
700 {
701 (void) count;
702 _mesa_ColorPointer(size, type, stride, ptr);
703 }
704
705
706 void GLAPIENTRY
707 _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
708 const GLvoid *ptr)
709 {
710 (void) count;
711 _mesa_IndexPointer(type, stride, ptr);
712 }
713
714
715 void GLAPIENTRY
716 _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
717 GLsizei count, const GLvoid *ptr)
718 {
719 (void) count;
720 _mesa_TexCoordPointer(size, type, stride, ptr);
721 }
722
723
724 void GLAPIENTRY
725 _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
726 {
727 (void) count;
728 _mesa_EdgeFlagPointer(stride, ptr);
729 }
730
731
732 void GLAPIENTRY
733 _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
734 {
735 GET_CURRENT_CONTEXT(ctx);
736 GLboolean tflag, cflag, nflag; /* enable/disable flags */
737 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
738 GLenum ctype = 0; /* color type */
739 GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
740 const GLint toffset = 0; /* always zero */
741 GLint defstride; /* default stride */
742 GLint c, f;
743
744 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
745
746 f = sizeof(GLfloat);
747 c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
748
749 if (stride < 0) {
750 _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
751 return;
752 }
753
754 switch (format) {
755 case GL_V2F:
756 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
757 tcomps = 0; ccomps = 0; vcomps = 2;
758 voffset = 0;
759 defstride = 2*f;
760 break;
761 case GL_V3F:
762 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
763 tcomps = 0; ccomps = 0; vcomps = 3;
764 voffset = 0;
765 defstride = 3*f;
766 break;
767 case GL_C4UB_V2F:
768 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
769 tcomps = 0; ccomps = 4; vcomps = 2;
770 ctype = GL_UNSIGNED_BYTE;
771 coffset = 0;
772 voffset = c;
773 defstride = c + 2*f;
774 break;
775 case GL_C4UB_V3F:
776 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
777 tcomps = 0; ccomps = 4; vcomps = 3;
778 ctype = GL_UNSIGNED_BYTE;
779 coffset = 0;
780 voffset = c;
781 defstride = c + 3*f;
782 break;
783 case GL_C3F_V3F:
784 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
785 tcomps = 0; ccomps = 3; vcomps = 3;
786 ctype = GL_FLOAT;
787 coffset = 0;
788 voffset = 3*f;
789 defstride = 6*f;
790 break;
791 case GL_N3F_V3F:
792 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
793 tcomps = 0; ccomps = 0; vcomps = 3;
794 noffset = 0;
795 voffset = 3*f;
796 defstride = 6*f;
797 break;
798 case GL_C4F_N3F_V3F:
799 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
800 tcomps = 0; ccomps = 4; vcomps = 3;
801 ctype = GL_FLOAT;
802 coffset = 0;
803 noffset = 4*f;
804 voffset = 7*f;
805 defstride = 10*f;
806 break;
807 case GL_T2F_V3F:
808 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
809 tcomps = 2; ccomps = 0; vcomps = 3;
810 voffset = 2*f;
811 defstride = 5*f;
812 break;
813 case GL_T4F_V4F:
814 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
815 tcomps = 4; ccomps = 0; vcomps = 4;
816 voffset = 4*f;
817 defstride = 8*f;
818 break;
819 case GL_T2F_C4UB_V3F:
820 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
821 tcomps = 2; ccomps = 4; vcomps = 3;
822 ctype = GL_UNSIGNED_BYTE;
823 coffset = 2*f;
824 voffset = c+2*f;
825 defstride = c+5*f;
826 break;
827 case GL_T2F_C3F_V3F:
828 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
829 tcomps = 2; ccomps = 3; vcomps = 3;
830 ctype = GL_FLOAT;
831 coffset = 2*f;
832 voffset = 5*f;
833 defstride = 8*f;
834 break;
835 case GL_T2F_N3F_V3F:
836 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
837 tcomps = 2; ccomps = 0; vcomps = 3;
838 noffset = 2*f;
839 voffset = 5*f;
840 defstride = 8*f;
841 break;
842 case GL_T2F_C4F_N3F_V3F:
843 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
844 tcomps = 2; ccomps = 4; vcomps = 3;
845 ctype = GL_FLOAT;
846 coffset = 2*f;
847 noffset = 6*f;
848 voffset = 9*f;
849 defstride = 12*f;
850 break;
851 case GL_T4F_C4F_N3F_V4F:
852 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
853 tcomps = 4; ccomps = 4; vcomps = 4;
854 ctype = GL_FLOAT;
855 coffset = 4*f;
856 noffset = 8*f;
857 voffset = 11*f;
858 defstride = 15*f;
859 break;
860 default:
861 _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
862 return;
863 }
864
865 if (stride==0) {
866 stride = defstride;
867 }
868
869 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
870 _mesa_DisableClientState( GL_INDEX_ARRAY );
871 /* XXX also disable secondary color and generic arrays? */
872
873 /* Texcoords */
874 if (tflag) {
875 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
876 _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
877 (GLubyte *) pointer + toffset );
878 }
879 else {
880 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
881 }
882
883 /* Color */
884 if (cflag) {
885 _mesa_EnableClientState( GL_COLOR_ARRAY );
886 _mesa_ColorPointer( ccomps, ctype, stride,
887 (GLubyte *) pointer + coffset );
888 }
889 else {
890 _mesa_DisableClientState( GL_COLOR_ARRAY );
891 }
892
893
894 /* Normals */
895 if (nflag) {
896 _mesa_EnableClientState( GL_NORMAL_ARRAY );
897 _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset );
898 }
899 else {
900 _mesa_DisableClientState( GL_NORMAL_ARRAY );
901 }
902
903 /* Vertices */
904 _mesa_EnableClientState( GL_VERTEX_ARRAY );
905 _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
906 (GLubyte *) pointer + voffset );
907 }
908
909
910 void GLAPIENTRY
911 _mesa_LockArraysEXT(GLint first, GLsizei count)
912 {
913 GET_CURRENT_CONTEXT(ctx);
914 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
915
916 if (MESA_VERBOSE & VERBOSE_API)
917 _mesa_debug(ctx, "glLockArrays %d %d\n", first, count);
918
919 if (first < 0) {
920 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" );
921 return;
922 }
923 if (count <= 0) {
924 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" );
925 return;
926 }
927 if (ctx->Array.LockCount != 0) {
928 _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" );
929 return;
930 }
931
932 ctx->Array.LockFirst = first;
933 ctx->Array.LockCount = count;
934
935 ctx->NewState |= _NEW_ARRAY;
936 ctx->Array.NewState |= _NEW_ARRAY_ALL;
937
938 if (ctx->Driver.LockArraysEXT)
939 ctx->Driver.LockArraysEXT( ctx, first, count );
940 }
941
942
943 void GLAPIENTRY
944 _mesa_UnlockArraysEXT( void )
945 {
946 GET_CURRENT_CONTEXT(ctx);
947 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
948
949 if (MESA_VERBOSE & VERBOSE_API)
950 _mesa_debug(ctx, "glUnlockArrays\n");
951
952 if (ctx->Array.LockCount == 0) {
953 _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" );
954 return;
955 }
956
957 ctx->Array.LockFirst = 0;
958 ctx->Array.LockCount = 0;
959 ctx->NewState |= _NEW_ARRAY;
960 ctx->Array.NewState |= _NEW_ARRAY_ALL;
961
962 if (ctx->Driver.UnlockArraysEXT)
963 ctx->Driver.UnlockArraysEXT( ctx );
964 }
965
966
967 /* GL_EXT_multi_draw_arrays */
968 /* Somebody forgot to spec the first and count parameters as const! <sigh> */
969 void GLAPIENTRY
970 _mesa_MultiDrawArraysEXT( GLenum mode, GLint *first,
971 GLsizei *count, GLsizei primcount )
972 {
973 GET_CURRENT_CONTEXT(ctx);
974 GLint i;
975
976 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
977
978 for (i = 0; i < primcount; i++) {
979 if (count[i] > 0) {
980 CALL_DrawArrays(ctx->Exec, (mode, first[i], count[i]));
981 }
982 }
983 }
984
985
986 /* GL_EXT_multi_draw_arrays */
987 void GLAPIENTRY
988 _mesa_MultiDrawElementsEXT( GLenum mode, const GLsizei *count, GLenum type,
989 const GLvoid **indices, GLsizei primcount )
990 {
991 GET_CURRENT_CONTEXT(ctx);
992 GLint i;
993
994 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
995
996 for (i = 0; i < primcount; i++) {
997 if (count[i] > 0) {
998 CALL_DrawElements(ctx->Exec, (mode, count[i], type, indices[i]));
999 }
1000 }
1001 }
1002
1003
1004 /* GL_IBM_multimode_draw_arrays */
1005 void GLAPIENTRY
1006 _mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
1007 const GLsizei * count,
1008 GLsizei primcount, GLint modestride )
1009 {
1010 GET_CURRENT_CONTEXT(ctx);
1011 GLint i;
1012
1013 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
1014
1015 for ( i = 0 ; i < primcount ; i++ ) {
1016 if ( count[i] > 0 ) {
1017 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
1018 CALL_DrawArrays(ctx->Exec, ( m, first[i], count[i] ));
1019 }
1020 }
1021 }
1022
1023
1024 /* GL_IBM_multimode_draw_arrays */
1025 void GLAPIENTRY
1026 _mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
1027 GLenum type, const GLvoid * const * indices,
1028 GLsizei primcount, GLint modestride )
1029 {
1030 GET_CURRENT_CONTEXT(ctx);
1031 GLint i;
1032
1033 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
1034
1035 /* XXX not sure about ARB_vertex_buffer_object handling here */
1036
1037 for ( i = 0 ; i < primcount ; i++ ) {
1038 if ( count[i] > 0 ) {
1039 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
1040 CALL_DrawElements(ctx->Exec, ( m, count[i], type, indices[i] ));
1041 }
1042 }
1043 }
1044
1045
1046 /**
1047 * Initialize vertex array state for given context.
1048 */
1049 void
1050 _mesa_init_varray(GLcontext *ctx)
1051 {
1052 ctx->Array.DefaultArrayObj = _mesa_new_array_object(ctx, 0);
1053 _mesa_reference_array_object(ctx, &ctx->Array.ArrayObj,
1054 ctx->Array.DefaultArrayObj);
1055 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1056 }