49cff3dae3096d76dc715cf11878ad9ac053463c
2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
25 * Keith Whitwell <keith@tungstengraphics.com>
33 #include "math/m_translate.h"
34 #include "array_cache/ac_context.h"
35 #include "math/m_translate.h"
37 #define STRIDE_ARRAY( array, offset ) \
39 GLubyte *tmp = ADD_POINTERS( (array).BufferObj->Data, (array).Ptr ) \
40 + (offset) * (array).StrideB; \
45 /* Set the array pointer back to its source when the cached data is
49 reset_texcoord( GLcontext
*ctx
, GLuint unit
)
51 ACcontext
*ac
= AC_CONTEXT(ctx
);
53 if (ctx
->Array
.TexCoord
[unit
].Enabled
) {
54 ac
->Raw
.TexCoord
[unit
] = ctx
->Array
.TexCoord
[unit
];
55 STRIDE_ARRAY(ac
->Raw
.TexCoord
[unit
], ac
->start
);
58 ac
->Raw
.TexCoord
[unit
] = ac
->Fallback
.TexCoord
[unit
];
60 if (ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][3] != 1.0)
61 ac
->Raw
.TexCoord
[unit
].Size
= 4;
62 else if (ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][2] != 0.0)
63 ac
->Raw
.TexCoord
[unit
].Size
= 3;
65 ac
->Raw
.TexCoord
[unit
].Size
= 2;
68 ac
->IsCached
.TexCoord
[unit
] = GL_FALSE
;
69 ac
->NewArrayState
&= ~_NEW_ARRAY_TEXCOORD(unit
);
73 reset_vertex( GLcontext
*ctx
)
75 ACcontext
*ac
= AC_CONTEXT(ctx
);
76 ASSERT(ctx
->Array
.Vertex
.Enabled
77 || (ctx
->VertexProgram
._Enabled
&& ctx
->Array
.VertexAttrib
[0].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
;
86 reset_normal( GLcontext
*ctx
)
88 ACcontext
*ac
= AC_CONTEXT(ctx
);
90 if (ctx
->Array
.Normal
.Enabled
) {
91 ac
->Raw
.Normal
= ctx
->Array
.Normal
;
92 STRIDE_ARRAY(ac
->Raw
.Normal
, ac
->start
);
95 ac
->Raw
.Normal
= ac
->Fallback
.Normal
;
98 ac
->IsCached
.Normal
= GL_FALSE
;
99 ac
->NewArrayState
&= ~_NEW_ARRAY_NORMAL
;
104 reset_color( GLcontext
*ctx
)
106 ACcontext
*ac
= AC_CONTEXT(ctx
);
108 if (ctx
->Array
.Color
.Enabled
) {
109 ac
->Raw
.Color
= ctx
->Array
.Color
;
110 STRIDE_ARRAY(ac
->Raw
.Color
, ac
->start
);
113 ac
->Raw
.Color
= ac
->Fallback
.Color
;
115 ac
->IsCached
.Color
= GL_FALSE
;
116 ac
->NewArrayState
&= ~_NEW_ARRAY_COLOR0
;
121 reset_secondarycolor( GLcontext
*ctx
)
123 ACcontext
*ac
= AC_CONTEXT(ctx
);
125 if (ctx
->Array
.SecondaryColor
.Enabled
) {
126 ac
->Raw
.SecondaryColor
= ctx
->Array
.SecondaryColor
;
127 STRIDE_ARRAY(ac
->Raw
.SecondaryColor
, ac
->start
);
130 ac
->Raw
.SecondaryColor
= ac
->Fallback
.SecondaryColor
;
132 ac
->IsCached
.SecondaryColor
= GL_FALSE
;
133 ac
->NewArrayState
&= ~_NEW_ARRAY_COLOR1
;
138 reset_index( GLcontext
*ctx
)
140 ACcontext
*ac
= AC_CONTEXT(ctx
);
142 if (ctx
->Array
.Index
.Enabled
) {
143 ac
->Raw
.Index
= ctx
->Array
.Index
;
144 STRIDE_ARRAY(ac
->Raw
.Index
, ac
->start
);
147 ac
->Raw
.Index
= ac
->Fallback
.Index
;
149 ac
->IsCached
.Index
= GL_FALSE
;
150 ac
->NewArrayState
&= ~_NEW_ARRAY_INDEX
;
155 reset_fogcoord( GLcontext
*ctx
)
157 ACcontext
*ac
= AC_CONTEXT(ctx
);
159 if (ctx
->Array
.FogCoord
.Enabled
) {
160 ac
->Raw
.FogCoord
= ctx
->Array
.FogCoord
;
161 STRIDE_ARRAY(ac
->Raw
.FogCoord
, ac
->start
);
164 ac
->Raw
.FogCoord
= ac
->Fallback
.FogCoord
;
166 ac
->IsCached
.FogCoord
= GL_FALSE
;
167 ac
->NewArrayState
&= ~_NEW_ARRAY_FOGCOORD
;
172 reset_edgeflag( GLcontext
*ctx
)
174 ACcontext
*ac
= AC_CONTEXT(ctx
);
176 if (ctx
->Array
.EdgeFlag
.Enabled
) {
177 ac
->Raw
.EdgeFlag
= ctx
->Array
.EdgeFlag
;
178 STRIDE_ARRAY(ac
->Raw
.EdgeFlag
, ac
->start
);
181 ac
->Raw
.EdgeFlag
= ac
->Fallback
.EdgeFlag
;
183 ac
->IsCached
.EdgeFlag
= GL_FALSE
;
184 ac
->NewArrayState
&= ~_NEW_ARRAY_EDGEFLAG
;
189 reset_attrib( GLcontext
*ctx
, GLuint index
)
191 ACcontext
*ac
= AC_CONTEXT(ctx
);
193 if (ctx
->Array
.VertexAttrib
[index
].Enabled
) {
194 ac
->Raw
.Attrib
[index
] = ctx
->Array
.VertexAttrib
[index
];
195 STRIDE_ARRAY(ac
->Raw
.Attrib
[index
], ac
->start
);
198 ac
->Raw
.Attrib
[index
] = ac
->Fallback
.Attrib
[index
];
200 ac
->IsCached
.Attrib
[index
] = GL_FALSE
;
201 ac
->NewArrayState
&= ~_NEW_ARRAY_ATTRIB(index
);
206 * Generic import function for color data
209 import( const GLcontext
*ctx
,
211 struct gl_client_array
*to
,
212 const struct gl_client_array
*from
)
214 const ACcontext
*ac
= AC_CONTEXT(ctx
);
217 destType
= from
->Type
;
221 _math_trans_4fc( (GLfloat (*)[4]) to
->Ptr
,
227 ac
->count
- ac
->start
);
229 to
->StrideB
= 4 * sizeof(GLfloat
);
233 case GL_UNSIGNED_BYTE
:
234 _math_trans_4ub( (GLubyte (*)[4]) to
->Ptr
,
240 ac
->count
- ac
->start
);
242 to
->StrideB
= 4 * sizeof(GLubyte
);
243 to
->Type
= GL_UNSIGNED_BYTE
;
246 case GL_UNSIGNED_SHORT
:
247 _math_trans_4us( (GLushort (*)[4]) to
->Ptr
,
253 ac
->count
- ac
->start
);
255 to
->StrideB
= 4 * sizeof(GLushort
);
256 to
->Type
= GL_UNSIGNED_SHORT
;
260 _mesa_problem(ctx
, "Unexpected dest format in import()");
268 * Functions to import array ranges with specified types and strides.
269 * For example, if the vertex data is GLshort[2] and we want GLfloat[3]
270 * we'll use an import function to do the data conversion.
274 import_texcoord( GLcontext
*ctx
, GLuint unit
, GLenum type
, GLuint stride
)
276 ACcontext
*ac
= AC_CONTEXT(ctx
);
277 const struct gl_client_array
*from
= &ac
->Raw
.TexCoord
[unit
];
278 struct gl_client_array
*to
= &ac
->Cache
.TexCoord
[unit
];
280 ASSERT(unit
< ctx
->Const
.MaxTextureCoordUnits
);
282 /* Limited choices at this stage:
284 ASSERT(type
== GL_FLOAT
);
285 ASSERT(stride
== 4*sizeof(GLfloat
) || stride
== 0);
286 ASSERT(ac
->count
- ac
->start
< ctx
->Const
.MaxArrayLockSize
);
288 _math_trans_4f( (GLfloat (*)[4]) to
->Ptr
,
294 ac
->count
- ac
->start
);
296 to
->Size
= from
->Size
;
297 to
->StrideB
= 4 * sizeof(GLfloat
);
299 ac
->IsCached
.TexCoord
[unit
] = GL_TRUE
;
303 import_vertex( GLcontext
*ctx
, GLenum type
, GLuint stride
)
305 ACcontext
*ac
= AC_CONTEXT(ctx
);
306 const struct gl_client_array
*from
= &ac
->Raw
.Vertex
;
307 struct gl_client_array
*to
= &ac
->Cache
.Vertex
;
309 /* Limited choices at this stage:
311 ASSERT(type
== GL_FLOAT
);
312 ASSERT(stride
== 4*sizeof(GLfloat
) || stride
== 0);
314 _math_trans_4f( (GLfloat (*)[4]) to
->Ptr
,
320 ac
->count
- ac
->start
);
322 to
->Size
= from
->Size
;
323 to
->StrideB
= 4 * sizeof(GLfloat
);
325 ac
->IsCached
.Vertex
= GL_TRUE
;
329 import_normal( GLcontext
*ctx
, GLenum type
, GLuint stride
)
331 ACcontext
*ac
= AC_CONTEXT(ctx
);
332 const struct gl_client_array
*from
= &ac
->Raw
.Normal
;
333 struct gl_client_array
*to
= &ac
->Cache
.Normal
;
335 /* Limited choices at this stage:
337 ASSERT(type
== GL_FLOAT
);
338 ASSERT(stride
== 3*sizeof(GLfloat
) || stride
== 0);
340 _math_trans_3f( (GLfloat (*)[3]) to
->Ptr
,
345 ac
->count
- ac
->start
);
347 to
->StrideB
= 3 * sizeof(GLfloat
);
349 ac
->IsCached
.Normal
= GL_TRUE
;
353 import_color( GLcontext
*ctx
, GLenum type
, GLuint stride
)
355 ACcontext
*ac
= AC_CONTEXT(ctx
);
356 const struct gl_client_array
*from
= &ac
->Raw
.Color
;
357 struct gl_client_array
*to
= &ac
->Cache
.Color
;
359 import( ctx
, type
, to
, from
);
361 ac
->IsCached
.Color
= GL_TRUE
;
365 import_index( GLcontext
*ctx
, GLenum type
, GLuint stride
)
367 ACcontext
*ac
= AC_CONTEXT(ctx
);
368 const struct gl_client_array
*from
= &ac
->Raw
.Index
;
369 struct gl_client_array
*to
= &ac
->Cache
.Index
;
371 /* Limited choices at this stage:
373 ASSERT(type
== GL_UNSIGNED_INT
);
374 ASSERT(stride
== sizeof(GLuint
) || stride
== 0);
376 _math_trans_1ui( (GLuint
*) to
->Ptr
,
381 ac
->count
- ac
->start
);
383 to
->StrideB
= sizeof(GLuint
);
384 to
->Type
= GL_UNSIGNED_INT
;
385 ac
->IsCached
.Index
= GL_TRUE
;
389 import_secondarycolor( GLcontext
*ctx
, GLenum type
, GLuint stride
)
391 ACcontext
*ac
= AC_CONTEXT(ctx
);
392 const struct gl_client_array
*from
= &ac
->Raw
.SecondaryColor
;
393 struct gl_client_array
*to
= &ac
->Cache
.SecondaryColor
;
395 import( ctx
, type
, to
, from
);
397 ac
->IsCached
.SecondaryColor
= GL_TRUE
;
401 import_fogcoord( GLcontext
*ctx
, GLenum type
, GLuint stride
)
403 ACcontext
*ac
= AC_CONTEXT(ctx
);
404 const struct gl_client_array
*from
= &ac
->Raw
.FogCoord
;
405 struct gl_client_array
*to
= &ac
->Cache
.FogCoord
;
407 /* Limited choices at this stage:
409 ASSERT(type
== GL_FLOAT
);
410 ASSERT(stride
== sizeof(GLfloat
) || stride
== 0);
412 _math_trans_1f( (GLfloat
*) to
->Ptr
,
417 ac
->count
- ac
->start
);
419 to
->StrideB
= sizeof(GLfloat
);
421 ac
->IsCached
.FogCoord
= GL_TRUE
;
425 import_edgeflag( GLcontext
*ctx
, GLenum type
, GLuint stride
)
427 ACcontext
*ac
= AC_CONTEXT(ctx
);
428 const struct gl_client_array
*from
= &ac
->Raw
.EdgeFlag
;
429 struct gl_client_array
*to
= &ac
->Cache
.EdgeFlag
;
431 /* Limited choices at this stage:
433 ASSERT(type
== GL_UNSIGNED_BYTE
);
434 ASSERT(stride
== sizeof(GLubyte
) || stride
== 0);
436 _math_trans_1ub( (GLubyte
*) to
->Ptr
,
441 ac
->count
- ac
->start
);
443 to
->StrideB
= sizeof(GLubyte
);
444 to
->Type
= GL_UNSIGNED_BYTE
;
445 ac
->IsCached
.EdgeFlag
= GL_TRUE
;
449 import_attrib( GLcontext
*ctx
, GLuint index
, GLenum type
, GLuint stride
)
451 ACcontext
*ac
= AC_CONTEXT(ctx
);
452 const struct gl_client_array
*from
= &ac
->Raw
.Attrib
[index
];
453 struct gl_client_array
*to
= &ac
->Cache
.Attrib
[index
];
455 ASSERT(index
< VERT_ATTRIB_MAX
);
457 /* Limited choices at this stage:
459 ASSERT(type
== GL_FLOAT
);
460 ASSERT(stride
== 4*sizeof(GLfloat
) || stride
== 0);
461 ASSERT(ac
->count
- ac
->start
< ctx
->Const
.MaxArrayLockSize
);
463 _math_trans_4f( (GLfloat (*)[4]) to
->Ptr
,
469 ac
->count
- ac
->start
);
471 to
->Size
= from
->Size
;
472 to
->StrideB
= 4 * sizeof(GLfloat
);
474 ac
->IsCached
.Attrib
[index
] = GL_TRUE
;
480 * Externals to request arrays with specific properties:
484 struct gl_client_array
*
485 _ac_import_texcoord( GLcontext
*ctx
,
490 GLboolean reqwriteable
,
491 GLboolean
*writeable
)
493 ACcontext
*ac
= AC_CONTEXT(ctx
);
495 ASSERT(unit
< ctx
->Const
.MaxTextureCoordUnits
);
497 /* Can we keep the existing version?
499 if (ac
->NewArrayState
& _NEW_ARRAY_TEXCOORD(unit
))
500 reset_texcoord( ctx
, unit
);
502 /* Is the request impossible?
504 if (reqsize
!= 0 && ac
->Raw
.TexCoord
[unit
].Size
> (GLint
) reqsize
)
507 /* Do we need to pull in a copy of the client data:
509 if (ac
->Raw
.TexCoord
[unit
].Type
!= type
||
510 (reqstride
!= 0 && ac
->Raw
.TexCoord
[unit
].StrideB
!= (GLint
)reqstride
) ||
513 if (!ac
->IsCached
.TexCoord
[unit
])
514 import_texcoord(ctx
, unit
, type
, reqstride
);
515 *writeable
= GL_TRUE
;
516 return &ac
->Cache
.TexCoord
[unit
];
519 *writeable
= GL_FALSE
;
520 return &ac
->Raw
.TexCoord
[unit
];
524 struct gl_client_array
*
525 _ac_import_vertex( GLcontext
*ctx
,
529 GLboolean reqwriteable
,
530 GLboolean
*writeable
)
532 ACcontext
*ac
= AC_CONTEXT(ctx
);
534 /* Can we keep the existing version?
536 if (ac
->NewArrayState
& _NEW_ARRAY_VERTEX
)
539 /* Is the request impossible?
541 if (reqsize
!= 0 && ac
->Raw
.Vertex
.Size
> (GLint
) reqsize
)
544 /* Do we need to pull in a copy of the client data:
546 if (ac
->Raw
.Vertex
.Type
!= type
||
547 (reqstride
!= 0 && ac
->Raw
.Vertex
.StrideB
!= (GLint
) reqstride
) ||
550 if (!ac
->IsCached
.Vertex
)
551 import_vertex(ctx
, type
, reqstride
);
552 *writeable
= GL_TRUE
;
553 return &ac
->Cache
.Vertex
;
556 *writeable
= GL_FALSE
;
557 return &ac
->Raw
.Vertex
;
561 struct gl_client_array
*
562 _ac_import_normal( GLcontext
*ctx
,
565 GLboolean reqwriteable
,
566 GLboolean
*writeable
)
568 ACcontext
*ac
= AC_CONTEXT(ctx
);
570 /* Can we keep the existing version?
572 if (ac
->NewArrayState
& _NEW_ARRAY_NORMAL
)
575 /* Do we need to pull in a copy of the client data:
577 if (ac
->Raw
.Normal
.Type
!= type
||
578 (reqstride
!= 0 && ac
->Raw
.Normal
.StrideB
!= (GLint
) reqstride
) ||
581 if (!ac
->IsCached
.Normal
)
582 import_normal(ctx
, type
, reqstride
);
583 *writeable
= GL_TRUE
;
584 return &ac
->Cache
.Normal
;
587 *writeable
= GL_FALSE
;
588 return &ac
->Raw
.Normal
;
592 struct gl_client_array
*
593 _ac_import_color( GLcontext
*ctx
,
597 GLboolean reqwriteable
,
598 GLboolean
*writeable
)
600 ACcontext
*ac
= AC_CONTEXT(ctx
);
602 /* Can we keep the existing version?
604 if (ac
->NewArrayState
& _NEW_ARRAY_COLOR0
)
607 /* Is the request impossible?
609 if (reqsize
!= 0 && ac
->Raw
.Color
.Size
> (GLint
) reqsize
) {
613 /* Do we need to pull in a copy of the client data:
615 if ((type
!= 0 && ac
->Raw
.Color
.Type
!= type
) ||
616 (reqstride
!= 0 && ac
->Raw
.Color
.StrideB
!= (GLint
) reqstride
) ||
619 if (!ac
->IsCached
.Color
) {
620 import_color(ctx
, type
, reqstride
);
622 *writeable
= GL_TRUE
;
623 return &ac
->Cache
.Color
;
626 *writeable
= GL_FALSE
;
627 return &ac
->Raw
.Color
;
631 struct gl_client_array
*
632 _ac_import_index( GLcontext
*ctx
,
635 GLboolean reqwriteable
,
636 GLboolean
*writeable
)
638 ACcontext
*ac
= AC_CONTEXT(ctx
);
640 /* Can we keep the existing version?
642 if (ac
->NewArrayState
& _NEW_ARRAY_INDEX
)
646 /* Do we need to pull in a copy of the client data:
648 if (ac
->Raw
.Index
.Type
!= type
||
649 (reqstride
!= 0 && ac
->Raw
.Index
.StrideB
!= (GLint
) reqstride
) ||
652 if (!ac
->IsCached
.Index
)
653 import_index(ctx
, type
, reqstride
);
654 *writeable
= GL_TRUE
;
655 return &ac
->Cache
.Index
;
658 *writeable
= GL_FALSE
;
659 return &ac
->Raw
.Index
;
663 struct gl_client_array
*
664 _ac_import_secondarycolor( GLcontext
*ctx
,
668 GLboolean reqwriteable
,
669 GLboolean
*writeable
)
671 ACcontext
*ac
= AC_CONTEXT(ctx
);
673 /* Can we keep the existing version?
675 if (ac
->NewArrayState
& _NEW_ARRAY_COLOR1
)
676 reset_secondarycolor( ctx
);
678 /* Is the request impossible?
680 if (reqsize
!= 0 && ac
->Raw
.SecondaryColor
.Size
> (GLint
) reqsize
)
683 /* Do we need to pull in a copy of the client data:
685 if ((type
!= 0 && ac
->Raw
.SecondaryColor
.Type
!= type
) ||
686 (reqstride
!= 0 && ac
->Raw
.SecondaryColor
.StrideB
!= (GLint
)reqstride
) ||
689 if (!ac
->IsCached
.SecondaryColor
)
690 import_secondarycolor(ctx
, type
, reqstride
);
691 *writeable
= GL_TRUE
;
692 return &ac
->Cache
.SecondaryColor
;
695 *writeable
= GL_FALSE
;
696 return &ac
->Raw
.SecondaryColor
;
700 struct gl_client_array
*
701 _ac_import_fogcoord( GLcontext
*ctx
,
704 GLboolean reqwriteable
,
705 GLboolean
*writeable
)
707 ACcontext
*ac
= AC_CONTEXT(ctx
);
709 /* Can we keep the existing version?
711 if (ac
->NewArrayState
& _NEW_ARRAY_FOGCOORD
)
712 reset_fogcoord( ctx
);
714 /* Do we need to pull in a copy of the client data:
716 if (ac
->Raw
.FogCoord
.Type
!= type
||
717 (reqstride
!= 0 && ac
->Raw
.FogCoord
.StrideB
!= (GLint
) reqstride
) ||
720 if (!ac
->IsCached
.FogCoord
)
721 import_fogcoord(ctx
, type
, reqstride
);
722 *writeable
= GL_TRUE
;
723 return &ac
->Cache
.FogCoord
;
726 *writeable
= GL_FALSE
;
727 return &ac
->Raw
.FogCoord
;
731 struct gl_client_array
*
732 _ac_import_edgeflag( GLcontext
*ctx
,
735 GLboolean reqwriteable
,
736 GLboolean
*writeable
)
738 ACcontext
*ac
= AC_CONTEXT(ctx
);
740 /* Can we keep the existing version?
742 if (ac
->NewArrayState
& _NEW_ARRAY_EDGEFLAG
)
743 reset_edgeflag( ctx
);
745 /* Do we need to pull in a copy of the client data:
747 if (ac
->Raw
.EdgeFlag
.Type
!= type
||
748 (reqstride
!= 0 && ac
->Raw
.EdgeFlag
.StrideB
!= (GLint
) reqstride
) ||
751 if (!ac
->IsCached
.EdgeFlag
)
752 import_edgeflag(ctx
, type
, reqstride
);
753 *writeable
= GL_TRUE
;
754 return &ac
->Cache
.EdgeFlag
;
757 *writeable
= GL_FALSE
;
758 return &ac
->Raw
.EdgeFlag
;
762 /* GL_NV_vertex_program */
763 struct gl_client_array
*
764 _ac_import_attrib( GLcontext
*ctx
,
769 GLboolean reqwriteable
,
770 GLboolean
*writeable
)
772 ACcontext
*ac
= AC_CONTEXT(ctx
);
774 ASSERT(index
< VERT_ATTRIB_MAX
);
776 /* Can we keep the existing version?
778 if (ac
->NewArrayState
& _NEW_ARRAY_ATTRIB(index
))
779 reset_attrib( ctx
, index
);
781 /* Is the request impossible?
783 if (reqsize
!= 0 && ac
->Raw
.Attrib
[index
].Size
> (GLint
) reqsize
)
786 /* Do we need to pull in a copy of the client data:
788 if (ac
->Raw
.Attrib
[index
].Type
!= type
||
789 (reqstride
!= 0 && ac
->Raw
.Attrib
[index
].StrideB
!= (GLint
)reqstride
) ||
792 if (!ac
->IsCached
.Attrib
[index
])
793 import_attrib(ctx
, index
, type
, reqstride
);
794 *writeable
= GL_TRUE
;
795 return &ac
->Cache
.Attrib
[index
];
798 *writeable
= GL_FALSE
;
799 return &ac
->Raw
.Attrib
[index
];
804 /* Clients must call this function to validate state and set bounds
805 * before importing any data:
808 _ac_import_range( GLcontext
*ctx
, GLuint start
, GLuint count
)
810 ACcontext
*ac
= AC_CONTEXT(ctx
);
812 if (!ctx
->Array
.LockCount
) {
813 /* Not locked, discard cached data. Changes to lock
814 * status are caught via. _ac_invalidate_state().
816 ac
->NewArrayState
= _NEW_ARRAY_ALL
;
821 /* Locked, discard data for any disabled arrays. Require that
822 * the whole locked range always be dealt with, otherwise hard to
823 * maintain cached data in the face of clipping.
825 ac
->NewArrayState
|= ~ctx
->Array
._Enabled
;
826 ac
->start
= ctx
->Array
.LockFirst
;
827 ac
->count
= ctx
->Array
.LockCount
;
828 ASSERT(ac
->start
== start
); /* hmm? */
829 ASSERT(ac
->count
== count
);
835 /* Additional convienence function for importing the element list
836 * for glDrawElements() and glDrawRangeElements().
839 _ac_import_elements( GLcontext
*ctx
,
843 CONST
void *indices
)
845 ACcontext
*ac
= AC_CONTEXT(ctx
);
847 if (old_type
== new_type
)
850 if (ac
->elt_size
< count
* sizeof(GLuint
)) {
851 if (ac
->Elts
) FREE(ac
->Elts
);
852 while (ac
->elt_size
< count
* sizeof(GLuint
))
854 ac
->Elts
= (GLuint
*) MALLOC(ac
->elt_size
);
858 case GL_UNSIGNED_BYTE
:
861 case GL_UNSIGNED_SHORT
:
864 case GL_UNSIGNED_INT
: {
865 GLuint
*out
= (GLuint
*)ac
->Elts
;
869 case GL_UNSIGNED_BYTE
: {
870 CONST GLubyte
*in
= (CONST GLubyte
*)indices
;
871 for (i
= 0 ; i
< count
; i
++)
875 case GL_UNSIGNED_SHORT
: {
876 CONST GLushort
*in
= (CONST GLushort
*)indices
;
877 for (i
= 0 ; i
< count
; i
++)
885 return (CONST
void *)out
;