fixed a bunch of g++ warnings/errors. Compiling with g++ can help find lots of poten...
[mesa.git] / src / mesa / array_cache / ac_import.c
1 /* $Id: ac_import.c,v 1.8 2001/03/07 05:06:12 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2001 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 * Author:
27 * Keith Whitwell <keithw@valinux.com>
28 */
29
30 #include "glheader.h"
31 #include "macros.h"
32 #include "mem.h"
33 #include "mmath.h"
34 #include "mtypes.h"
35
36 #include "math/m_translate.h"
37 #include "array_cache/ac_context.h"
38 #include "math/m_translate.h"
39
40 #define STRIDE_ARRAY( array, offset ) \
41 do { \
42 char *tmp = (char *) (array).Ptr; \
43 tmp += (offset) * (array).StrideB; \
44 (array).Ptr = tmp; \
45 } while (0)
46
47 /* Set the array pointer back to its source when the cached data is
48 * invalidated:
49 */
50
51 static void reset_texcoord( GLcontext *ctx, GLuint unit )
52 {
53 ACcontext *ac = AC_CONTEXT(ctx);
54
55 if (ctx->Array._Enabled & _NEW_ARRAY_TEXCOORD(unit)) {
56 ac->Raw.TexCoord[unit] = ctx->Array.TexCoord[unit];
57 STRIDE_ARRAY(ac->Raw.TexCoord[unit], ac->start);
58 }
59 else {
60 ac->Raw.TexCoord[unit] = ac->Fallback.TexCoord[unit];
61
62 if (ctx->Current.Texcoord[unit][3] != 1.0)
63 ac->Raw.TexCoord[unit].Size = 4;
64 else if (ctx->Current.Texcoord[unit][2] != 0.0)
65 ac->Raw.TexCoord[unit].Size = 3;
66 else
67 ac->Raw.TexCoord[unit].Size = 2;
68 }
69
70 ac->IsCached.TexCoord[unit] = GL_FALSE;
71 ac->NewArrayState &= ~_NEW_ARRAY_TEXCOORD(unit);
72 }
73
74 static void reset_vertex( GLcontext *ctx )
75 {
76 ACcontext *ac = AC_CONTEXT(ctx);
77 ASSERT(ctx->Array.Vertex.Enabled);
78 ac->Raw.Vertex = ctx->Array.Vertex;
79 STRIDE_ARRAY(ac->Raw.Vertex, ac->start);
80 ac->IsCached.Vertex = GL_FALSE;
81 ac->NewArrayState &= ~_NEW_ARRAY_VERTEX;
82 }
83
84
85 static void reset_normal( GLcontext *ctx )
86 {
87 ACcontext *ac = AC_CONTEXT(ctx);
88
89 if (ctx->Array._Enabled & _NEW_ARRAY_NORMAL) {
90 ac->Raw.Normal = ctx->Array.Normal;
91 STRIDE_ARRAY(ac->Raw.Normal, ac->start);
92 }
93 else {
94 ac->Raw.Normal = ac->Fallback.Normal;
95 }
96
97 ac->IsCached.Normal = GL_FALSE;
98 ac->NewArrayState &= ~_NEW_ARRAY_NORMAL;
99 }
100
101
102 static void reset_color( GLcontext *ctx )
103 {
104 ACcontext *ac = AC_CONTEXT(ctx);
105
106
107 if (ctx->Array._Enabled & _NEW_ARRAY_COLOR) {
108 ac->Raw.Color = ctx->Array.Color;
109 STRIDE_ARRAY(ac->Raw.Color, ac->start);
110 }
111 else
112 ac->Raw.Color = ac->Fallback.Color;
113
114 ac->IsCached.Color = GL_FALSE;
115 ac->NewArrayState &= ~_NEW_ARRAY_COLOR;
116 }
117
118
119 static void reset_secondarycolor( GLcontext *ctx )
120 {
121 ACcontext *ac = AC_CONTEXT(ctx);
122
123 if (ctx->Array._Enabled & _NEW_ARRAY_SECONDARYCOLOR) {
124 ac->Raw.SecondaryColor = ctx->Array.SecondaryColor;
125 STRIDE_ARRAY(ac->Raw.SecondaryColor, ac->start);
126 }
127 else
128 ac->Raw.SecondaryColor = ac->Fallback.SecondaryColor;
129
130 ac->IsCached.SecondaryColor = GL_FALSE;
131 ac->NewArrayState &= ~_NEW_ARRAY_SECONDARYCOLOR;
132 }
133
134
135 static void reset_index( GLcontext *ctx )
136 {
137 ACcontext *ac = AC_CONTEXT(ctx);
138
139 if (ctx->Array._Enabled & _NEW_ARRAY_INDEX) {
140 ac->Raw.Index = ctx->Array.Index;
141 STRIDE_ARRAY(ac->Raw.Index, ac->start);
142 }
143 else
144 ac->Raw.Index = ac->Fallback.Index;
145
146 ac->IsCached.Index = GL_FALSE;
147 ac->NewArrayState &= ~_NEW_ARRAY_INDEX;
148 }
149
150 static void reset_fogcoord( GLcontext *ctx )
151 {
152 ACcontext *ac = AC_CONTEXT(ctx);
153
154 if (ctx->Array._Enabled & _NEW_ARRAY_FOGCOORD) {
155 ac->Raw.FogCoord = ctx->Array.FogCoord;
156 STRIDE_ARRAY(ac->Raw.FogCoord, ac->start);
157 }
158 else
159 ac->Raw.FogCoord = ac->Fallback.FogCoord;
160
161 ac->IsCached.FogCoord = GL_FALSE;
162 ac->NewArrayState &= ~_NEW_ARRAY_FOGCOORD;
163 }
164
165 static void reset_edgeflag( GLcontext *ctx )
166 {
167 ACcontext *ac = AC_CONTEXT(ctx);
168
169 if (ctx->Array._Enabled & _NEW_ARRAY_EDGEFLAG) {
170 ac->Raw.EdgeFlag = ctx->Array.EdgeFlag;
171 STRIDE_ARRAY(ac->Raw.EdgeFlag, ac->start);
172 }
173 else
174 ac->Raw.EdgeFlag = ac->Fallback.EdgeFlag;
175
176 ac->IsCached.EdgeFlag = GL_FALSE;
177 ac->NewArrayState &= ~_NEW_ARRAY_EDGEFLAG;
178 }
179
180
181 /* Functions to import array ranges with specified types and strides.
182 */
183 static void import_texcoord( GLcontext *ctx, GLuint unit,
184 GLenum type, GLuint stride )
185 {
186 ACcontext *ac = AC_CONTEXT(ctx);
187 struct gl_client_array *from = &ac->Raw.TexCoord[unit];
188 struct gl_client_array *to = &ac->Cache.TexCoord[unit];
189
190 /* Limited choices at this stage:
191 */
192 ASSERT(type == GL_FLOAT);
193 ASSERT(stride == 4*sizeof(GLfloat) || stride == 0);
194 ASSERT(ac->count - ac->start < ctx->Const.MaxArrayLockSize);
195
196 _math_trans_4f( (GLfloat (*)[4]) to->Ptr,
197 from->Ptr,
198 from->StrideB,
199 from->Type,
200 from->Size,
201 ac->start,
202 ac->count);
203
204 to->Size = from->Size;
205 to->StrideB = 4 * sizeof(GLfloat);
206 to->Type = GL_FLOAT;
207 ac->IsCached.TexCoord[unit] = GL_TRUE;
208 }
209
210 static void import_vertex( GLcontext *ctx,
211 GLenum type, GLuint stride )
212 {
213 ACcontext *ac = AC_CONTEXT(ctx);
214 struct gl_client_array *from = &ac->Raw.Vertex;
215 struct gl_client_array *to = &ac->Cache.Vertex;
216
217 /* Limited choices at this stage:
218 */
219 ASSERT(type == GL_FLOAT);
220 ASSERT(stride == 4*sizeof(GLfloat) || stride == 0);
221
222 _math_trans_4f( (GLfloat (*)[4]) to->Ptr,
223 from->Ptr,
224 from->StrideB,
225 from->Type,
226 from->Size,
227 0,
228 ac->count - ac->start);
229
230 to->Size = from->Size;
231 to->StrideB = 4 * sizeof(GLfloat);
232 to->Type = GL_FLOAT;
233 ac->IsCached.Vertex = GL_TRUE;
234 }
235
236 static void import_normal( GLcontext *ctx,
237 GLenum type, GLuint stride )
238 {
239 ACcontext *ac = AC_CONTEXT(ctx);
240 struct gl_client_array *from = &ac->Raw.Normal;
241 struct gl_client_array *to = &ac->Cache.Normal;
242
243 /* Limited choices at this stage:
244 */
245 ASSERT(type == GL_FLOAT);
246 ASSERT(stride == 3*sizeof(GLfloat) || stride == 0);
247
248 _math_trans_3f( (GLfloat (*)[3]) to->Ptr,
249 from->Ptr,
250 from->StrideB,
251 from->Type,
252 0,
253 ac->count - ac->start);
254
255 to->StrideB = 3 * sizeof(GLfloat);
256 to->Type = GL_FLOAT;
257 ac->IsCached.Normal = GL_TRUE;
258 }
259
260 static void import_color( GLcontext *ctx,
261 GLenum type, GLuint stride )
262 {
263 ACcontext *ac = AC_CONTEXT(ctx);
264 struct gl_client_array *from = &ac->Raw.Color;
265 struct gl_client_array *to = &ac->Cache.Color;
266
267 /* Limited choices at this stage:
268 */
269 /* XXX GLchan: is this right for GLchan? */
270 ASSERT(type == CHAN_TYPE);
271 ASSERT(stride == 4 * sizeof(GLchan) || stride == 0);
272
273 _math_trans_4chan( (GLchan (*)[4]) to->Ptr,
274 from->Ptr,
275 from->StrideB,
276 from->Type,
277 from->Size,
278 0,
279 ac->count - ac->start);
280
281 to->Size = from->Size;
282 to->StrideB = 4 * sizeof(GLchan);
283 to->Type = CHAN_TYPE;
284 ac->IsCached.Color = GL_TRUE;
285 }
286
287 static void import_index( GLcontext *ctx,
288 GLenum type, GLuint stride )
289 {
290 ACcontext *ac = AC_CONTEXT(ctx);
291 struct gl_client_array *from = &ac->Raw.Index;
292 struct gl_client_array *to = &ac->Cache.Index;
293
294 /* Limited choices at this stage:
295 */
296 ASSERT(type == GL_UNSIGNED_INT);
297 ASSERT(stride == sizeof(GLuint) || stride == 0);
298
299 _math_trans_1ui( (GLuint *) to->Ptr,
300 from->Ptr,
301 from->StrideB,
302 from->Type,
303 0,
304 ac->count - ac->start);
305
306 to->StrideB = sizeof(GLuint);
307 to->Type = GL_UNSIGNED_INT;
308 ac->IsCached.Index = GL_TRUE;
309 }
310
311 static void import_secondarycolor( GLcontext *ctx,
312 GLenum type, GLuint stride )
313 {
314 ACcontext *ac = AC_CONTEXT(ctx);
315 struct gl_client_array *from = &ac->Raw.SecondaryColor;
316 struct gl_client_array *to = &ac->Cache.SecondaryColor;
317
318 /* Limited choices at this stage:
319 */
320 ASSERT(type == CHAN_TYPE);
321 ASSERT(stride == 4 * sizeof(GLchan) || stride == 0);
322
323 _math_trans_4chan( (GLchan (*)[4]) to->Ptr,
324 from->Ptr,
325 from->StrideB,
326 from->Type,
327 from->Size,
328 0,
329 ac->count - ac->start);
330
331 to->StrideB = 4 * sizeof(GLchan);
332 to->Type = CHAN_TYPE;
333 ac->IsCached.SecondaryColor = GL_TRUE;
334 }
335
336 static void import_fogcoord( GLcontext *ctx,
337 GLenum type, GLuint stride )
338 {
339 ACcontext *ac = AC_CONTEXT(ctx);
340 struct gl_client_array *from = &ac->Raw.FogCoord;
341 struct gl_client_array *to = &ac->Cache.FogCoord;
342
343 /* Limited choices at this stage:
344 */
345 ASSERT(type == GL_FLOAT);
346 ASSERT(stride == sizeof(GLfloat) || stride == 0);
347
348 _math_trans_1f( (GLfloat *) to->Ptr,
349 from->Ptr,
350 from->StrideB,
351 from->Type,
352 0,
353 ac->count - ac->start);
354
355 to->StrideB = sizeof(GLfloat);
356 to->Type = GL_FLOAT;
357 ac->IsCached.FogCoord = GL_TRUE;
358 }
359
360 static void import_edgeflag( GLcontext *ctx,
361 GLenum type, GLuint stride )
362 {
363 ACcontext *ac = AC_CONTEXT(ctx);
364 struct gl_client_array *from = &ac->Raw.EdgeFlag;
365 struct gl_client_array *to = &ac->Cache.EdgeFlag;
366
367 /* Limited choices at this stage:
368 */
369 ASSERT(type == GL_FLOAT);
370 ASSERT(stride == sizeof(GLfloat) || stride == 0);
371
372 _math_trans_1f( (GLfloat *) to->Ptr,
373 from->Ptr,
374 from->StrideB,
375 from->Type,
376 0,
377 ac->count - ac->start);
378
379 to->StrideB = sizeof(GLfloat);
380 to->Type = GL_FLOAT;
381 ac->IsCached.EdgeFlag = GL_TRUE;
382 }
383
384
385
386 /* Externals to request arrays with specific properties:
387 */
388 struct gl_client_array *_ac_import_texcoord( GLcontext *ctx,
389 GLuint unit,
390 GLenum type,
391 GLuint reqstride,
392 GLuint reqsize,
393 GLboolean reqwriteable,
394 GLboolean *writeable )
395 {
396 ACcontext *ac = AC_CONTEXT(ctx);
397
398 /* Can we keep the existing version?
399 */
400 if (ac->NewArrayState & _NEW_ARRAY_TEXCOORD(unit))
401 reset_texcoord( ctx, unit );
402
403 /* Is the request impossible?
404 */
405 if (reqsize != 0 && ac->Raw.TexCoord[unit].Size > (GLint) reqsize)
406 return 0;
407
408 /* Do we need to pull in a copy of the client data:
409 */
410 if (ac->Raw.TexCoord[unit].Type != type ||
411 (reqstride != 0 && ac->Raw.TexCoord[unit].StrideB != (GLint) reqstride) ||
412 reqwriteable)
413 {
414 if (!ac->IsCached.TexCoord[unit])
415 import_texcoord(ctx, unit, type, reqstride );
416 *writeable = GL_TRUE;
417 return &ac->Cache.TexCoord[unit];
418 }
419 else {
420 *writeable = GL_FALSE;
421 return &ac->Raw.TexCoord[unit];
422 }
423 }
424
425 struct gl_client_array *_ac_import_vertex( GLcontext *ctx,
426 GLenum type,
427 GLuint reqstride,
428 GLuint reqsize,
429 GLboolean reqwriteable,
430 GLboolean *writeable )
431 {
432 ACcontext *ac = AC_CONTEXT(ctx);
433
434 /* Can we keep the existing version?
435 */
436 if (ac->NewArrayState & _NEW_ARRAY_VERTEX)
437 reset_vertex( ctx );
438
439 /* Is the request impossible?
440 */
441 if (reqsize != 0 && ac->Raw.Vertex.Size > (GLint) reqsize)
442 return 0;
443
444 /* Do we need to pull in a copy of the client data:
445 */
446 if (ac->Raw.Vertex.Type != type ||
447 (reqstride != 0 && ac->Raw.Vertex.StrideB != (GLint) reqstride) ||
448 reqwriteable)
449 {
450 if (!ac->IsCached.Vertex)
451 import_vertex(ctx, type, reqstride );
452 *writeable = GL_TRUE;
453 return &ac->Cache.Vertex;
454 }
455 else {
456 *writeable = GL_FALSE;
457 return &ac->Raw.Vertex;
458 }
459 }
460
461 struct gl_client_array *_ac_import_normal( GLcontext *ctx,
462 GLenum type,
463 GLuint reqstride,
464 GLboolean reqwriteable,
465 GLboolean *writeable )
466 {
467 ACcontext *ac = AC_CONTEXT(ctx);
468
469 /* Can we keep the existing version?
470 */
471 if (ac->NewArrayState & _NEW_ARRAY_NORMAL)
472 reset_normal( ctx );
473
474 /* Do we need to pull in a copy of the client data:
475 */
476 if (ac->Raw.Normal.Type != type ||
477 (reqstride != 0 && ac->Raw.Normal.StrideB != (GLint) reqstride) ||
478 reqwriteable)
479 {
480 if (!ac->IsCached.Normal)
481 import_normal(ctx, type, reqstride );
482 *writeable = GL_TRUE;
483 return &ac->Cache.Normal;
484 }
485 else {
486 *writeable = GL_FALSE;
487 return &ac->Raw.Normal;
488 }
489 }
490
491 struct gl_client_array *_ac_import_color( GLcontext *ctx,
492 GLenum type,
493 GLuint reqstride,
494 GLuint reqsize,
495 GLboolean reqwriteable,
496 GLboolean *writeable )
497 {
498 ACcontext *ac = AC_CONTEXT(ctx);
499
500 /* Can we keep the existing version?
501 */
502 if (ac->NewArrayState & _NEW_ARRAY_COLOR)
503 reset_color( ctx );
504
505 /* Is the request impossible?
506 */
507 if (reqsize != 0 && ac->Raw.Color.Size > (GLint) reqsize) {
508 return 0;
509 }
510
511 /* Do we need to pull in a copy of the client data:
512 */
513 if (ac->Raw.Color.Type != type ||
514 (reqstride != 0 && ac->Raw.Color.StrideB != (GLint) reqstride) ||
515 reqwriteable)
516 {
517 if (!ac->IsCached.Color)
518 import_color(ctx, type, reqstride );
519 *writeable = GL_TRUE;
520 return &ac->Cache.Color;
521 }
522 else {
523 *writeable = GL_FALSE;
524 return &ac->Raw.Color;
525 }
526 }
527
528 struct gl_client_array *_ac_import_index( GLcontext *ctx,
529 GLenum type,
530 GLuint reqstride,
531 GLboolean reqwriteable,
532 GLboolean *writeable )
533 {
534 ACcontext *ac = AC_CONTEXT(ctx);
535
536 /* Can we keep the existing version?
537 */
538 if (ac->NewArrayState & _NEW_ARRAY_INDEX)
539 reset_index( ctx );
540
541
542 /* Do we need to pull in a copy of the client data:
543 */
544 if (ac->Raw.Index.Type != type ||
545 (reqstride != 0 && ac->Raw.Index.StrideB != (GLint) reqstride) ||
546 reqwriteable)
547 {
548 if (!ac->IsCached.Index)
549 import_index(ctx, type, reqstride );
550 *writeable = GL_TRUE;
551 return &ac->Cache.Index;
552 }
553 else {
554 *writeable = GL_FALSE;
555 return &ac->Raw.Index;
556 }
557 }
558
559 struct gl_client_array *_ac_import_secondarycolor( GLcontext *ctx,
560 GLenum type,
561 GLuint reqstride,
562 GLuint reqsize,
563 GLboolean reqwriteable,
564 GLboolean *writeable )
565 {
566 ACcontext *ac = AC_CONTEXT(ctx);
567
568 /* Can we keep the existing version?
569 */
570 if (ac->NewArrayState & _NEW_ARRAY_SECONDARYCOLOR)
571 reset_secondarycolor( ctx );
572
573 /* Is the request impossible?
574 */
575 if (reqsize != 0 && ac->Raw.SecondaryColor.Size > (GLint) reqsize)
576 return 0;
577
578 /* Do we need to pull in a copy of the client data:
579 */
580 if (ac->Raw.SecondaryColor.Type != type ||
581 (reqstride != 0 && ac->Raw.SecondaryColor.StrideB != (GLint) reqstride) ||
582 reqwriteable)
583 {
584 if (!ac->IsCached.SecondaryColor)
585 import_secondarycolor(ctx, type, reqstride );
586 *writeable = GL_TRUE;
587 return &ac->Cache.SecondaryColor;
588 }
589 else {
590 *writeable = GL_FALSE;
591 return &ac->Raw.SecondaryColor;
592 }
593 }
594
595 struct gl_client_array *_ac_import_fogcoord( GLcontext *ctx,
596 GLenum type,
597 GLuint reqstride,
598 GLboolean reqwriteable,
599 GLboolean *writeable )
600 {
601 ACcontext *ac = AC_CONTEXT(ctx);
602
603 /* Can we keep the existing version?
604 */
605 if (ac->NewArrayState & _NEW_ARRAY_FOGCOORD)
606 reset_fogcoord( ctx );
607
608 /* Do we need to pull in a copy of the client data:
609 */
610 if (ac->Raw.FogCoord.Type != type ||
611 (reqstride != 0 && ac->Raw.FogCoord.StrideB != (GLint) reqstride) ||
612 reqwriteable)
613 {
614 if (!ac->IsCached.FogCoord)
615 import_fogcoord(ctx, type, reqstride );
616 *writeable = GL_TRUE;
617 return &ac->Cache.FogCoord;
618 }
619 else {
620 *writeable = GL_FALSE;
621 return &ac->Raw.FogCoord;
622 }
623 }
624
625
626
627
628 struct gl_client_array *_ac_import_edgeflag( GLcontext *ctx,
629 GLenum type,
630 GLuint reqstride,
631 GLboolean reqwriteable,
632 GLboolean *writeable )
633 {
634 ACcontext *ac = AC_CONTEXT(ctx);
635
636 /* Can we keep the existing version?
637 */
638 if (ac->NewArrayState & _NEW_ARRAY_EDGEFLAG)
639 reset_edgeflag( ctx );
640
641 /* Do we need to pull in a copy of the client data:
642 */
643 if (ac->Raw.EdgeFlag.Type != type ||
644 (reqstride != 0 && ac->Raw.EdgeFlag.StrideB != (GLint) reqstride) ||
645 reqwriteable)
646 {
647 if (!ac->IsCached.EdgeFlag)
648 import_edgeflag(ctx, type, reqstride );
649 *writeable = GL_TRUE;
650 return &ac->Cache.EdgeFlag;
651 }
652 else {
653 *writeable = GL_FALSE;
654 return &ac->Raw.EdgeFlag;
655 }
656 }
657
658
659
660
661
662 /* Clients must call this function to validate state and set bounds
663 * before importing any data:
664 */
665 void _ac_import_range( GLcontext *ctx, GLuint start, GLuint count )
666 {
667 ACcontext *ac = AC_CONTEXT(ctx);
668
669 /* Discard cached data which has been invalidated by state changes
670 * since last time. **ALREADY DONE**
671 if (ac->NewState)
672 _ac_update_state( ctx );
673 */
674
675 if (!ctx->Array.LockCount) {
676 /* Not locked, discard cached data. Changes to lock
677 * status are caught via. _ac_invalidate_state().
678 */
679 ac->NewArrayState = _NEW_ARRAY_ALL;
680 ac->start = start;
681 ac->count = count;
682 }
683 else {
684 /* Locked, discard data for any disabled arrays. Require that
685 * the whole locked range always be dealt with, otherwise hard to
686 * maintain cached data in the face of clipping.
687 */
688 ac->NewArrayState |= ~ctx->Array._Enabled;
689 ac->start = ctx->Array.LockFirst;
690 ac->count = ctx->Array.LockCount;
691 ASSERT(ac->start == start); /* hmm? */
692 ASSERT(ac->count == count);
693 }
694 }
695
696
697
698 /* Additional convienence function for importing a the element list
699 * for drawelements, drawrangeelements:
700 */
701 CONST void *
702 _ac_import_elements( GLcontext *ctx,
703 GLenum new_type,
704 GLuint count,
705 GLenum old_type,
706 CONST void *indices )
707 {
708 ACcontext *ac = AC_CONTEXT(ctx);
709
710 if (old_type == new_type)
711 return indices;
712
713 if (ac->elt_size < count * sizeof(GLuint)) {
714 if (ac->Elts) FREE(ac->Elts);
715 while (ac->elt_size < count * sizeof(GLuint))
716 ac->elt_size *= 2;
717 ac->Elts = (GLuint *) MALLOC(ac->elt_size);
718 }
719
720 switch (new_type) {
721 case GL_UNSIGNED_BYTE:
722 ASSERT(0);
723 return 0;
724 case GL_UNSIGNED_SHORT:
725 ASSERT(0);
726 return 0;
727 case GL_UNSIGNED_INT: {
728 GLuint *out = (GLuint *)ac->Elts;
729 GLuint i;
730
731 switch (old_type) {
732 case GL_UNSIGNED_BYTE: {
733 CONST GLubyte *in = (CONST GLubyte *)indices;
734 for (i = 0 ; i < count ; i++)
735 out[i] = in[i];
736 break;
737 }
738 case GL_UNSIGNED_SHORT: {
739 CONST GLushort *in = (CONST GLushort *)indices;
740 for (i = 0 ; i < count ; i++)
741 out[i] = in[i];
742 break;
743 }
744 default:
745 ASSERT(0);
746 }
747
748 return (CONST void *)out;
749 }
750 default:
751 ASSERT(0);
752 break;
753 }
754
755 return 0;
756 }
757