blob: 78cff94bd00f5c69db9de9df69bbdb90214f54e9 [file] [log] [blame]
Brian Pauld4757302000-10-20 19:54:49 +00001/* $Id: varray.c,v 1.25 2000/10/20 19:54:49 brianp Exp $ */
jtgafb833d1999-08-19 00:55:39 +00002
3/*
4 * Mesa 3-D graphics library
Brian Paulce938b32000-10-18 15:02:59 +00005 * Version: 3.5
jtgafb833d1999-08-19 00:55:39 +00006 *
Brian Paul4463a242000-01-13 00:25:22 +00007 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
jtgafb833d1999-08-19 00:55:39 +00008 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27#ifdef PC_HEADER
28#include "all.h"
29#else
Brian Paulfbd8f211999-11-11 01:22:25 +000030#include "glheader.h"
jtgafb833d1999-08-19 00:55:39 +000031#include "context.h"
jtgafb833d1999-08-19 00:55:39 +000032#include "cva.h"
33#include "enable.h"
34#include "enums.h"
35#include "dlist.h"
36#include "light.h"
37#include "macros.h"
38#include "mmath.h"
39#include "pipeline.h"
Brian Paulea39f042000-02-02 19:17:57 +000040#include "state.h"
jtgafb833d1999-08-19 00:55:39 +000041#include "texstate.h"
42#include "translate.h"
43#include "types.h"
44#include "varray.h"
45#include "vb.h"
46#include "vbfill.h"
47#include "vbrender.h"
48#include "vbindirect.h"
49#include "vbxform.h"
50#include "xform.h"
Keith Whitwell485f0401999-10-08 09:27:09 +000051#endif
52
jtgafb833d1999-08-19 00:55:39 +000053
Brian Paulfbd8f211999-11-11 01:22:25 +000054
55void
56_mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
jtgafb833d1999-08-19 00:55:39 +000057{
Brian Paulfbd8f211999-11-11 01:22:25 +000058 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +000059
60 if (size<2 || size>4) {
61 gl_error( ctx, GL_INVALID_VALUE, "glVertexPointer(size)" );
62 return;
63 }
64 if (stride<0) {
65 gl_error( ctx, GL_INVALID_VALUE, "glVertexPointer(stride)" );
66 return;
67 }
68
69 if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API))
70 fprintf(stderr, "glVertexPointer( sz %d type %s stride %d )\n", size,
71 gl_lookup_enum_by_nr( type ),
72 stride);
73
74 ctx->Array.Vertex.StrideB = stride;
75 if (!stride) {
76 switch (type) {
77 case GL_SHORT:
78 ctx->Array.Vertex.StrideB = size*sizeof(GLshort);
79 break;
80 case GL_INT:
81 ctx->Array.Vertex.StrideB = size*sizeof(GLint);
82 break;
83 case GL_FLOAT:
84 ctx->Array.Vertex.StrideB = size*sizeof(GLfloat);
85 break;
86 case GL_DOUBLE:
87 ctx->Array.Vertex.StrideB = size*sizeof(GLdouble);
88 break;
89 default:
90 gl_error( ctx, GL_INVALID_ENUM, "glVertexPointer(type)" );
91 return;
92 }
93 }
94 ctx->Array.Vertex.Size = size;
95 ctx->Array.Vertex.Type = type;
96 ctx->Array.Vertex.Stride = stride;
97 ctx->Array.Vertex.Ptr = (void *) ptr;
98 ctx->Array.VertexFunc = gl_trans_4f_tab[size][TYPE_IDX(type)];
99 ctx->Array.VertexEltFunc = gl_trans_elt_4f_tab[size][TYPE_IDX(type)];
100 ctx->Array.NewArrayState |= VERT_OBJ_ANY;
101 ctx->NewState |= NEW_CLIENT_STATE;
102}
103
104
105
106
Brian Paulfbd8f211999-11-11 01:22:25 +0000107void
108_mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
jtgafb833d1999-08-19 00:55:39 +0000109{
Brian Paulfbd8f211999-11-11 01:22:25 +0000110 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000111
112 if (stride<0) {
113 gl_error( ctx, GL_INVALID_VALUE, "glNormalPointer(stride)" );
114 return;
115 }
116
117 if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API))
118 fprintf(stderr, "glNormalPointer( type %s stride %d )\n",
119 gl_lookup_enum_by_nr( type ),
120 stride);
121
122 ctx->Array.Normal.StrideB = stride;
123 if (!stride) {
124 switch (type) {
125 case GL_BYTE:
126 ctx->Array.Normal.StrideB = 3*sizeof(GLbyte);
127 break;
128 case GL_SHORT:
129 ctx->Array.Normal.StrideB = 3*sizeof(GLshort);
130 break;
131 case GL_INT:
132 ctx->Array.Normal.StrideB = 3*sizeof(GLint);
133 break;
134 case GL_FLOAT:
135 ctx->Array.Normal.StrideB = 3*sizeof(GLfloat);
136 break;
137 case GL_DOUBLE:
138 ctx->Array.Normal.StrideB = 3*sizeof(GLdouble);
139 break;
140 default:
141 gl_error( ctx, GL_INVALID_ENUM, "glNormalPointer(type)" );
142 return;
143 }
144 }
145 ctx->Array.Normal.Type = type;
146 ctx->Array.Normal.Stride = stride;
147 ctx->Array.Normal.Ptr = (void *) ptr;
148 ctx->Array.NormalFunc = gl_trans_3f_tab[TYPE_IDX(type)];
149 ctx->Array.NormalEltFunc = gl_trans_elt_3f_tab[TYPE_IDX(type)];
150 ctx->Array.NewArrayState |= VERT_NORM;
151 ctx->NewState |= NEW_CLIENT_STATE;
152}
153
154
155
Brian Paulfbd8f211999-11-11 01:22:25 +0000156void
157_mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
jtgafb833d1999-08-19 00:55:39 +0000158{
Brian Paulfbd8f211999-11-11 01:22:25 +0000159 GET_CURRENT_CONTEXT(ctx);
160
jtgafb833d1999-08-19 00:55:39 +0000161 if (size<3 || size>4) {
162 gl_error( ctx, GL_INVALID_VALUE, "glColorPointer(size)" );
163 return;
164 }
165 if (stride<0) {
166 gl_error( ctx, GL_INVALID_VALUE, "glColorPointer(stride)" );
167 return;
168 }
169
170 if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API))
171 fprintf(stderr, "glColorPointer( sz %d type %s stride %d )\n", size,
172 gl_lookup_enum_by_nr( type ),
173 stride);
174
175 ctx->Array.Color.StrideB = stride;
176 if (!stride) {
177 switch (type) {
178 case GL_BYTE:
179 ctx->Array.Color.StrideB = size*sizeof(GLbyte);
180 break;
181 case GL_UNSIGNED_BYTE:
182 ctx->Array.Color.StrideB = size*sizeof(GLubyte);
183 break;
184 case GL_SHORT:
185 ctx->Array.Color.StrideB = size*sizeof(GLshort);
186 break;
187 case GL_UNSIGNED_SHORT:
188 ctx->Array.Color.StrideB = size*sizeof(GLushort);
189 break;
190 case GL_INT:
191 ctx->Array.Color.StrideB = size*sizeof(GLint);
192 break;
193 case GL_UNSIGNED_INT:
194 ctx->Array.Color.StrideB = size*sizeof(GLuint);
195 break;
196 case GL_FLOAT:
197 ctx->Array.Color.StrideB = size*sizeof(GLfloat);
198 break;
199 case GL_DOUBLE:
200 ctx->Array.Color.StrideB = size*sizeof(GLdouble);
201 break;
202 default:
203 gl_error( ctx, GL_INVALID_ENUM, "glColorPointer(type)" );
204 return;
205 }
206 }
207 ctx->Array.Color.Size = size;
208 ctx->Array.Color.Type = type;
209 ctx->Array.Color.Stride = stride;
210 ctx->Array.Color.Ptr = (void *) ptr;
211 ctx->Array.ColorFunc = gl_trans_4ub_tab[size][TYPE_IDX(type)];
212 ctx->Array.ColorEltFunc = gl_trans_elt_4ub_tab[size][TYPE_IDX(type)];
213 ctx->Array.NewArrayState |= VERT_RGBA;
214 ctx->NewState |= NEW_CLIENT_STATE;
215}
216
217
218
Brian Paulfbd8f211999-11-11 01:22:25 +0000219void
220_mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
jtgafb833d1999-08-19 00:55:39 +0000221{
Brian Paulfbd8f211999-11-11 01:22:25 +0000222 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000223
224 if (stride<0) {
225 gl_error( ctx, GL_INVALID_VALUE, "glIndexPointer(stride)" );
226 return;
227 }
228
229 ctx->Array.Index.StrideB = stride;
230 if (!stride) {
231 switch (type) {
232 case GL_UNSIGNED_BYTE:
233 ctx->Array.Index.StrideB = sizeof(GLubyte);
234 break;
235 case GL_SHORT:
236 ctx->Array.Index.StrideB = sizeof(GLshort);
237 break;
238 case GL_INT:
239 ctx->Array.Index.StrideB = sizeof(GLint);
240 break;
241 case GL_FLOAT:
242 ctx->Array.Index.StrideB = sizeof(GLfloat);
243 break;
244 case GL_DOUBLE:
245 ctx->Array.Index.StrideB = sizeof(GLdouble);
246 break;
247 default:
248 gl_error( ctx, GL_INVALID_ENUM, "glIndexPointer(type)" );
249 return;
250 }
251 }
252 ctx->Array.Index.Type = type;
253 ctx->Array.Index.Stride = stride;
254 ctx->Array.Index.Ptr = (void *) ptr;
255 ctx->Array.IndexFunc = gl_trans_1ui_tab[TYPE_IDX(type)];
256 ctx->Array.IndexEltFunc = gl_trans_elt_1ui_tab[TYPE_IDX(type)];
257 ctx->Array.NewArrayState |= VERT_INDEX;
258 ctx->NewState |= NEW_CLIENT_STATE;
259}
260
261
262
Brian Paulfbd8f211999-11-11 01:22:25 +0000263void
264_mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
jtgafb833d1999-08-19 00:55:39 +0000265{
Brian Paulfbd8f211999-11-11 01:22:25 +0000266 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000267 GLuint texUnit;
268
Brian Paul45224fa1999-09-07 22:31:30 +0000269 texUnit = ctx->Array.ActiveTexture;
jtgafb833d1999-08-19 00:55:39 +0000270
271 if (size<1 || size>4) {
272 gl_error( ctx, GL_INVALID_VALUE, "glTexCoordPointer(size)" );
273 return;
274 }
275 if (stride<0) {
276 gl_error( ctx, GL_INVALID_VALUE, "glTexCoordPointer(stride)" );
277 return;
278 }
279
280 if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API))
281 fprintf(stderr, "glTexCoordPointer( unit %u sz %d type %s stride %d )\n",
282 texUnit,
283 size,
284 gl_lookup_enum_by_nr( type ),
285 stride);
286
287 ctx->Array.TexCoord[texUnit].StrideB = stride;
288 if (!stride) {
289 switch (type) {
290 case GL_SHORT:
291 ctx->Array.TexCoord[texUnit].StrideB = size*sizeof(GLshort);
292 break;
293 case GL_INT:
294 ctx->Array.TexCoord[texUnit].StrideB = size*sizeof(GLint);
295 break;
296 case GL_FLOAT:
297 ctx->Array.TexCoord[texUnit].StrideB = size*sizeof(GLfloat);
298 break;
299 case GL_DOUBLE:
300 ctx->Array.TexCoord[texUnit].StrideB = size*sizeof(GLdouble);
301 break;
302 default:
303 gl_error( ctx, GL_INVALID_ENUM, "glTexCoordPointer(type)" );
304 return;
305 }
306 }
307 ctx->Array.TexCoord[texUnit].Size = size;
308 ctx->Array.TexCoord[texUnit].Type = type;
309 ctx->Array.TexCoord[texUnit].Stride = stride;
310 ctx->Array.TexCoord[texUnit].Ptr = (void *) ptr;
311
312 ctx->Array.TexCoordFunc[texUnit] = gl_trans_4f_tab[size][TYPE_IDX(type)];
313 ctx->Array.TexCoordEltFunc[texUnit] = gl_trans_elt_4f_tab[size][TYPE_IDX(type)];
314 ctx->Array.NewArrayState |= PIPE_TEX(texUnit);
315 ctx->NewState |= NEW_CLIENT_STATE;
316}
317
318
319
320
Brian Paulfbd8f211999-11-11 01:22:25 +0000321void
322_mesa_EdgeFlagPointer(GLsizei stride, const void *vptr)
jtgafb833d1999-08-19 00:55:39 +0000323{
Brian Paulfbd8f211999-11-11 01:22:25 +0000324 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000325 const GLboolean *ptr = (GLboolean *)vptr;
jtgafb833d1999-08-19 00:55:39 +0000326
327 if (stride<0) {
328 gl_error( ctx, GL_INVALID_VALUE, "glEdgeFlagPointer(stride)" );
329 return;
330 }
331 ctx->Array.EdgeFlag.Stride = stride;
332 ctx->Array.EdgeFlag.StrideB = stride ? stride : sizeof(GLboolean);
333 ctx->Array.EdgeFlag.Ptr = (GLboolean *) ptr;
334 if (stride != sizeof(GLboolean)) {
335 ctx->Array.EdgeFlagFunc = gl_trans_1ub_tab[TYPE_IDX(GL_UNSIGNED_BYTE)];
336 } else {
337 ctx->Array.EdgeFlagFunc = 0;
338 }
339 ctx->Array.EdgeFlagEltFunc = gl_trans_elt_1ub_tab[TYPE_IDX(GL_UNSIGNED_BYTE)];
340 ctx->Array.NewArrayState |= VERT_EDGE;
341 ctx->NewState |= NEW_CLIENT_STATE;
342}
343
344
Brian Paul4463a242000-01-13 00:25:22 +0000345#if 0
jtgafb833d1999-08-19 00:55:39 +0000346/* Called only from gl_DrawElements
347 */
Brian Paul4463a242000-01-13 00:25:22 +0000348static void gl_CVAEltPointer( GLcontext *ctx, GLenum type, const GLvoid *ptr )
jtgafb833d1999-08-19 00:55:39 +0000349{
350 switch (type) {
351 case GL_UNSIGNED_BYTE:
352 ctx->CVA.Elt.StrideB = sizeof(GLubyte);
353 break;
354 case GL_UNSIGNED_SHORT:
355 ctx->CVA.Elt.StrideB = sizeof(GLushort);
356 break;
357 case GL_UNSIGNED_INT:
358 ctx->CVA.Elt.StrideB = sizeof(GLuint);
359 break;
360 default:
361 gl_error( ctx, GL_INVALID_ENUM, "glEltPointer(type)" );
362 return;
363 }
364 ctx->CVA.Elt.Type = type;
365 ctx->CVA.Elt.Stride = 0;
366 ctx->CVA.Elt.Ptr = (void *) ptr;
367 ctx->CVA.EltFunc = gl_trans_1ui_tab[TYPE_IDX(type)];
368 ctx->Array.NewArrayState |= VERT_ELT; /* ??? */
369}
Brian Paul4463a242000-01-13 00:25:22 +0000370#endif
jtgafb833d1999-08-19 00:55:39 +0000371
372
Brian Paul1f0e2132000-06-12 15:30:51 +0000373
374void
375_mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
376 GLsizei count, const GLvoid *ptr)
377{
378 (void) count;
379 _mesa_VertexPointer(size, type, stride, ptr);
380}
381
382
383void
384_mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
385 const GLvoid *ptr)
386{
387 (void) count;
388 _mesa_NormalPointer(type, stride, ptr);
389}
390
391
392void
393_mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
394 const GLvoid *ptr)
395{
396 (void) count;
397 _mesa_ColorPointer(size, type, stride, ptr);
398}
399
400
401void
402_mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
403 const GLvoid *ptr)
404{
405 (void) count;
406 _mesa_IndexPointer(type, stride, ptr);
407}
408
409
410void
411_mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
412 GLsizei count, const GLvoid *ptr)
413{
414 (void) count;
415 _mesa_TexCoordPointer(size, type, stride, ptr);
416}
417
418
419void
420_mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
421{
422 (void) count;
423 _mesa_EdgeFlagPointer(stride, ptr);
424}
425
426
427
428
429
jtgafb833d1999-08-19 00:55:39 +0000430/* KW: Batch function to exec all the array elements in the input
431 * buffer prior to transform. Done only the first time a vertex
432 * buffer is executed or compiled.
Keith Whitwelld4714731999-10-19 18:37:02 +0000433 *
434 * KW: Have to do this after each glEnd if cva isn't active. (also
435 * have to do it after each full buffer)
jtgafb833d1999-08-19 00:55:39 +0000436 */
Keith Whitwelld4714731999-10-19 18:37:02 +0000437void gl_exec_array_elements( GLcontext *ctx, struct immediate *IM,
438 GLuint start,
439 GLuint count)
jtgafb833d1999-08-19 00:55:39 +0000440{
441 GLuint *flags = IM->Flag;
442 GLuint *elts = IM->Elt;
jtgafb833d1999-08-19 00:55:39 +0000443 GLuint translate = ctx->Array.Flags;
444 GLuint i;
Keith Whitwelld4714731999-10-19 18:37:02 +0000445
446 if (MESA_VERBOSE&VERBOSE_IMMEDIATE)
447 fprintf(stderr, "exec_array_elements %d .. %d\n", start, count);
jtgafb833d1999-08-19 00:55:39 +0000448
449 if (translate & VERT_OBJ_ANY)
450 (ctx->Array.VertexEltFunc)( IM->Obj,
451 &ctx->Array.Vertex,
Keith Whitwell2be79c11999-08-26 14:50:49 +0000452 flags, elts, (VERT_ELT|VERT_OBJ_ANY),
jtgafb833d1999-08-19 00:55:39 +0000453 start, count);
454
455 if (translate & VERT_NORM)
456 (ctx->Array.NormalEltFunc)( IM->Normal,
457 &ctx->Array.Normal,
458 flags, elts, (VERT_ELT|VERT_NORM),
459 start, count);
460
461 if (translate & VERT_EDGE)
462 (ctx->Array.EdgeFlagEltFunc)( IM->EdgeFlag,
463 &ctx->Array.EdgeFlag,
464 flags, elts, (VERT_ELT|VERT_EDGE),
465 start, count);
466
467 if (translate & VERT_RGBA)
468 (ctx->Array.ColorEltFunc)( IM->Color,
469 &ctx->Array.Color,
470 flags, elts, (VERT_ELT|VERT_RGBA),
471 start, count);
472
473 if (translate & VERT_INDEX)
474 (ctx->Array.IndexEltFunc)( IM->Index,
475 &ctx->Array.Index,
476 flags, elts, (VERT_ELT|VERT_INDEX),
477 start, count);
478
479 if (translate & VERT_TEX0_ANY)
480 (ctx->Array.TexCoordEltFunc[0])( IM->TexCoord[0],
481 &ctx->Array.TexCoord[0],
482 flags, elts, (VERT_ELT|VERT_TEX0_ANY),
483 start, count);
484
485 if (translate & VERT_TEX1_ANY)
486 (ctx->Array.TexCoordEltFunc[1])( IM->TexCoord[1],
487 &ctx->Array.TexCoord[1],
488 flags, elts, (VERT_ELT|VERT_TEX1_ANY),
489 start, count);
490
Brian Paulce938b32000-10-18 15:02:59 +0000491#if MAX_TEXTURE_UNITS > 2
492 if (translate & VERT_TEX2_ANY)
Brian Pauld4757302000-10-20 19:54:49 +0000493 (ctx->Array.TexCoordEltFunc[2])( IM->TexCoord[2],
Brian Paulce938b32000-10-18 15:02:59 +0000494 &ctx->Array.TexCoord[2],
495 flags, elts, (VERT_ELT|VERT_TEX2_ANY),
496 start, count);
497#endif
Brian Pauld4757302000-10-20 19:54:49 +0000498#if MAX_TEXTURE_UNITS > 3
499 if (translate & VERT_TEX3_ANY)
500 (ctx->Array.TexCoordEltFunc[3])( IM->TexCoord[3],
501 &ctx->Array.TexCoord[3],
502 flags, elts, (VERT_ELT|VERT_TEX3_ANY),
503 start, count);
504#endif
Keith Whitwelld4714731999-10-19 18:37:02 +0000505
506 for (i = start ; i < count ; i++)
Keith Whitwell6adfc6b1999-11-09 17:26:15 +0000507 if (flags[i] & VERT_ELT)
jtgafb833d1999-08-19 00:55:39 +0000508 flags[i] |= translate;
Keith Whitwell6adfc6b1999-11-09 17:26:15 +0000509
jtgafb833d1999-08-19 00:55:39 +0000510}
511
512
513
Brian Paulfbd8f211999-11-11 01:22:25 +0000514/* Enough funny business going on in here it might be quicker to use a
515 * function pointer.
516 */
517#define ARRAY_ELT( IM, i ) \
518{ \
519 GLuint count = IM->Count; \
520 IM->Elt[count] = i; \
521 IM->Flag[count] = ((IM->Flag[count] & IM->ArrayAndFlags) | \
522 VERT_ELT); \
523 IM->FlushElt |= IM->ArrayEltFlush; \
524 IM->Count = count += IM->ArrayIncr; \
525 if (count == VB_MAX) \
Brian Paul038573a2000-09-11 18:49:06 +0000526 _mesa_maybe_transform_vb( IM ); \
Brian Paulfbd8f211999-11-11 01:22:25 +0000527}
528
529
530void
531_mesa_ArrayElement( GLint i )
jtgafb833d1999-08-19 00:55:39 +0000532{
Brian Paulfbd8f211999-11-11 01:22:25 +0000533 GET_IMMEDIATE;
534 ARRAY_ELT( IM, i );
535}
536
537
Brian Paul4463a242000-01-13 00:25:22 +0000538static void
539gl_ArrayElement( GLcontext *CC, GLint i )
Brian Paulfbd8f211999-11-11 01:22:25 +0000540{
541 struct immediate *im = CC->input;
542 ARRAY_ELT( im, i );
543}
544
545
546
547void
548_mesa_DrawArrays(GLenum mode, GLint start, GLsizei count)
549{
550 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000551 struct vertex_buffer *VB = ctx->VB;
552 GLint i;
553
554 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glDrawArrays");
555
556 if (count<0) {
557 gl_error( ctx, GL_INVALID_VALUE, "glDrawArrays(count)" );
558 return;
559 }
560
Brian Paulce938b32000-10-18 15:02:59 +0000561 if (!ctx->CompileFlag && ctx->Array.Vertex.Enabled) {
jtgafb833d1999-08-19 00:55:39 +0000562 GLint remaining = count;
563 GLint i;
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000564 struct gl_client_array *Normal;
565 struct gl_client_array *Color;
566 struct gl_client_array *Index;
567 struct gl_client_array *TexCoord[MAX_TEXTURE_UNITS];
568 struct gl_client_array *EdgeFlag;
jtgafb833d1999-08-19 00:55:39 +0000569 struct immediate *IM = VB->IM;
jtgafb833d1999-08-19 00:55:39 +0000570 struct gl_pipeline *elt = &ctx->CVA.elt;
Brian Paul5b37c321999-11-05 06:43:10 +0000571 GLboolean relock;
jtgafb833d1999-08-19 00:55:39 +0000572 GLuint fallback, required;
573
574 if (ctx->NewState)
575 gl_update_state( ctx );
576
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000577 /* Just turn off cva on this path. Could be useful for multipass
578 * rendering to keep it turned on.
jtgafb833d1999-08-19 00:55:39 +0000579 */
580 relock = ctx->CompileCVAFlag;
jtgafb833d1999-08-19 00:55:39 +0000581
Keith Whitwell784657c1999-11-19 00:03:27 +0000582 if (relock) {
583 ctx->CompileCVAFlag = 0;
584 elt->pipeline_valid = 0;
585 }
586
587 if (!elt->pipeline_valid)
jtgafb833d1999-08-19 00:55:39 +0000588 gl_build_immediate_pipeline( ctx );
589
590 required = elt->inputs;
591 fallback = (elt->inputs & ~ctx->Array.Summary);
592
Keith Whitwell784657c1999-11-19 00:03:27 +0000593 /* The translate function doesn't do anything about size. It
594 * just ensures that type and stride come out right.
595 */
596 IM->v.Obj.size = ctx->Array.Vertex.Size;
597
Brian Paulce938b32000-10-18 15:02:59 +0000598 if (required & VERT_RGBA) {
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000599 Color = &ctx->Array.Color;
600 if (fallback & VERT_RGBA) {
601 Color = &ctx->Fallback.Color;
602 ctx->Array.ColorFunc =
603 gl_trans_4ub_tab[4][TYPE_IDX(GL_UNSIGNED_BYTE)];
604 }
jtgafb833d1999-08-19 00:55:39 +0000605 }
606
Brian Paulce938b32000-10-18 15:02:59 +0000607 if (required & VERT_INDEX) {
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000608 Index = &ctx->Array.Index;
609 if (fallback & VERT_INDEX) {
610 Index = &ctx->Fallback.Index;
611 ctx->Array.IndexFunc = gl_trans_1ui_tab[TYPE_IDX(GL_UNSIGNED_INT)];
612 }
jtgafb833d1999-08-19 00:55:39 +0000613 }
614
Brian Paulce938b32000-10-18 15:02:59 +0000615 for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) {
jtgafb833d1999-08-19 00:55:39 +0000616 GLuint flag = VERT_TEX_ANY(i);
617
618 if (required & flag) {
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000619 TexCoord[i] = &ctx->Array.TexCoord[i];
jtgafb833d1999-08-19 00:55:39 +0000620
Brian Paulce938b32000-10-18 15:02:59 +0000621 if (fallback & flag) {
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000622 TexCoord[i] = &ctx->Fallback.TexCoord[i];
623 TexCoord[i]->Size = gl_texcoord_size( ctx->Current.Flag, i );
624
625 ctx->Array.TexCoordFunc[i] =
626 gl_trans_4f_tab[TexCoord[i]->Size][TYPE_IDX(GL_FLOAT)];
jtgafb833d1999-08-19 00:55:39 +0000627 }
jtgafb833d1999-08-19 00:55:39 +0000628 }
629 }
630
Brian Paulce938b32000-10-18 15:02:59 +0000631 if (ctx->Array.Flags != ctx->Array.Flag[0]) {
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000632 for (i = 0 ; i < VB_MAX ; i++)
jtgafb833d1999-08-19 00:55:39 +0000633 ctx->Array.Flag[i] = ctx->Array.Flags;
Brian Paulce938b32000-10-18 15:02:59 +0000634 }
jtgafb833d1999-08-19 00:55:39 +0000635
Brian Paulce938b32000-10-18 15:02:59 +0000636 if (required & VERT_NORM) {
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000637 Normal = &ctx->Array.Normal;
638 if (fallback & VERT_NORM) {
639 Normal = &ctx->Fallback.Normal;
640 ctx->Array.NormalFunc = gl_trans_3f_tab[TYPE_IDX(GL_FLOAT)];
641 }
jtgafb833d1999-08-19 00:55:39 +0000642 }
643
Brian Paulce938b32000-10-18 15:02:59 +0000644 if ( required & VERT_EDGE ) {
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000645 if (mode == GL_TRIANGLES ||
646 mode == GL_QUADS ||
Brian Paulce938b32000-10-18 15:02:59 +0000647 mode == GL_POLYGON) {
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000648 EdgeFlag = &ctx->Array.EdgeFlag;
649 if (fallback & VERT_EDGE) {
650 EdgeFlag = &ctx->Fallback.EdgeFlag;
651 ctx->Array.EdgeFlagFunc =
652 gl_trans_1ub_tab[TYPE_IDX(GL_UNSIGNED_BYTE)];
653 }
654 }
655 else
656 required &= ~VERT_EDGE;
jtgafb833d1999-08-19 00:55:39 +0000657 }
658
659 VB->Primitive = IM->Primitive;
660 VB->NextPrimitive = IM->NextPrimitive;
661 VB->MaterialMask = IM->MaterialMask;
662 VB->Material = IM->Material;
663 VB->BoundsPtr = 0;
664
665 while (remaining > 0) {
666 GLint vbspace = VB_MAX - VB_START;
667 GLuint count, n;
668
jtgafb833d1999-08-19 00:55:39 +0000669 if (vbspace >= remaining) {
670 n = remaining;
671 VB->LastPrimitive = VB_START + n;
Brian Paulce938b32000-10-18 15:02:59 +0000672 }
673 else {
jtgafb833d1999-08-19 00:55:39 +0000674 n = vbspace;
675 VB->LastPrimitive = VB_START;
676 }
677
678 VB->CullMode = 0;
679
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000680 ctx->Array.VertexFunc( IM->Obj + VB_START,
681 &ctx->Array.Vertex, start, n );
Keith Whitwell20f6c101999-11-09 10:12:34 +0000682
683 if (required & VERT_NORM) {
684 ctx->Array.NormalFunc( IM->Normal + VB_START,
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000685 Normal, start, n );
Keith Whitwell20f6c101999-11-09 10:12:34 +0000686 }
687
688 if (required & VERT_EDGE) {
689 ctx->Array.EdgeFlagFunc( IM->EdgeFlag + VB_START,
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000690 EdgeFlag, start, n );
Keith Whitwell20f6c101999-11-09 10:12:34 +0000691 }
692
693 if (required & VERT_RGBA) {
694 ctx->Array.ColorFunc( IM->Color + VB_START,
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000695 Color, start, n );
Keith Whitwell20f6c101999-11-09 10:12:34 +0000696 }
697
698 if (required & VERT_INDEX) {
699 ctx->Array.IndexFunc( IM->Index + VB_START,
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000700 Index, start, n );
Keith Whitwell20f6c101999-11-09 10:12:34 +0000701 }
702
703 if (required & VERT_TEX0_ANY) {
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000704 IM->v.TexCoord[0].size = TexCoord[0]->Size;
Keith Whitwell20f6c101999-11-09 10:12:34 +0000705 ctx->Array.TexCoordFunc[0]( IM->TexCoord[0] + VB_START,
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000706 TexCoord[0], start, n );
Keith Whitwell20f6c101999-11-09 10:12:34 +0000707 }
708
709 if (required & VERT_TEX1_ANY) {
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000710 IM->v.TexCoord[1].size = TexCoord[1]->Size;
Keith Whitwell20f6c101999-11-09 10:12:34 +0000711 ctx->Array.TexCoordFunc[1]( IM->TexCoord[1] + VB_START,
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000712 TexCoord[1], start, n );
jtgafb833d1999-08-19 00:55:39 +0000713 }
Brian Paulce938b32000-10-18 15:02:59 +0000714#if MAX_TEXTURE_UNITS > 2
715 if (required & VERT_TEX2_ANY) {
716 IM->v.TexCoord[2].size = TexCoord[2]->Size;
717 ctx->Array.TexCoordFunc[2]( IM->TexCoord[2] + VB_START,
718 TexCoord[2], start, n );
719 }
720#endif
Brian Pauld4757302000-10-20 19:54:49 +0000721#if MAX_TEXTURE_UNITS > 3
722 if (required & VERT_TEX3_ANY) {
723 IM->v.TexCoord[3].size = TexCoord[3]->Size;
724 ctx->Array.TexCoordFunc[3]( IM->TexCoord[3] + VB_START,
725 TexCoord[3], start, n );
726 }
727#endif
jtgafb833d1999-08-19 00:55:39 +0000728
Keith Whitwell20f6c101999-11-09 10:12:34 +0000729 VB->ObjPtr = &IM->v.Obj;
730 VB->NormalPtr = &IM->v.Normal;
731 VB->ColorPtr = &IM->v.Color;
732 VB->Color[0] = VB->Color[1] = VB->ColorPtr;
733 VB->IndexPtr = &IM->v.Index;
734 VB->EdgeFlagPtr = &IM->v.EdgeFlag;
Brian Paulce938b32000-10-18 15:02:59 +0000735 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
736 VB->TexCoordPtr[i] = &IM->v.TexCoord[i];
737 }
jtgafb833d1999-08-19 00:55:39 +0000738
739 VB->Flag = ctx->Array.Flag;
jtgafb833d1999-08-19 00:55:39 +0000740 VB->OrFlag = ctx->Array.Flags;
741
Keith Whitwell20f6c101999-11-09 10:12:34 +0000742 VB->Start = IM->Start = VB_START;
743 count = VB->Count = IM->Count = VB_START + n;
jtgafb833d1999-08-19 00:55:39 +0000744
Keith Whitwell20f6c101999-11-09 10:12:34 +0000745#define RESET_VEC(v, t, s, c) (v.start = t v.data[s], v.count = c)
jtgafb833d1999-08-19 00:55:39 +0000746
Keith Whitwell20f6c101999-11-09 10:12:34 +0000747 RESET_VEC(IM->v.Obj, (GLfloat *), VB_START, count);
748 RESET_VEC(IM->v.Normal, (GLfloat *), VB_START, count);
Brian Paulce938b32000-10-18 15:02:59 +0000749 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
750 RESET_VEC(IM->v.TexCoord[i], (GLfloat *), VB_START, count);
751 }
Keith Whitwell20f6c101999-11-09 10:12:34 +0000752 RESET_VEC(IM->v.Index, &, VB_START, count);
753 RESET_VEC(IM->v.Elt, &, VB_START, count);
754 RESET_VEC(IM->v.EdgeFlag, &, VB_START, count);
755 RESET_VEC(IM->v.Color, (GLubyte *), VB_START, count);
756 RESET_VEC(VB->Clip, (GLfloat *), VB_START, count);
757 RESET_VEC(VB->Eye, (GLfloat *), VB_START, count);
758 RESET_VEC(VB->Win, (GLfloat *), VB_START, count);
759 RESET_VEC(VB->BColor, (GLubyte *), VB_START, count);
760 RESET_VEC(VB->BIndex, &, VB_START, count);
jtgafb833d1999-08-19 00:55:39 +0000761
762 VB->NextPrimitive[VB->CopyStart] = VB->Count;
763 VB->Primitive[VB->CopyStart] = mode;
Keith Whitwelle828bc82000-02-25 03:55:39 +0000764 ctx->Array.Flag[count] |= VERT_END_VB;
jtgafb833d1999-08-19 00:55:39 +0000765
766 /* Transform and render.
767 */
768 gl_run_pipeline( VB );
769 gl_reset_vb( VB );
770
771 ctx->Array.Flag[count] = ctx->Array.Flags;
772 ctx->Array.Flag[VB_START] = ctx->Array.Flags;
jtgafb833d1999-08-19 00:55:39 +0000773
774 start += n;
775 remaining -= n;
776 }
777
Keith Whitwell784657c1999-11-19 00:03:27 +0000778 gl_reset_input( ctx );
779
780 if (relock) {
781 ctx->CompileCVAFlag = relock;
782 elt->pipeline_valid = 0;
783 }
jtgafb833d1999-08-19 00:55:39 +0000784 }
785 else if (ctx->Array.Vertex.Enabled)
786 {
787 /* The GL_COMPILE and GL_COMPILE_AND_EXECUTE cases. These
788 * could be handled by the above code, but it gets a little
Keith Whitwell20f6c101999-11-09 10:12:34 +0000789 * complex. The generated list is still of good quality
790 * this way.
jtgafb833d1999-08-19 00:55:39 +0000791 */
jtgafb833d1999-08-19 00:55:39 +0000792 gl_Begin( ctx, mode );
793 for (i=0;i<count;i++) {
794 gl_ArrayElement( ctx, start+i );
795 }
796 gl_End( ctx );
797 }
798 else
799 {
800 /* The degenerate case where vertices are not enabled - only
801 * need to process the very final array element, as all of the
802 * preceding ones would be overwritten anyway.
803 */
804 gl_Begin( ctx, mode );
805 gl_ArrayElement( ctx, start+count );
806 gl_End( ctx );
807 }
808}
809
810
811
812/* KW: Exactly fakes the effects of calling glArrayElement multiple times.
jtgafb833d1999-08-19 00:55:39 +0000813 */
Keith Whitwell30990a61999-11-04 19:42:28 +0000814#if 1
jtgafb833d1999-08-19 00:55:39 +0000815#define DRAW_ELT(FUNC, TYPE) \
816static void FUNC( GLcontext *ctx, GLenum mode, \
817 TYPE *indices, GLuint count ) \
818{ \
819 GLuint i,j; \
820 \
Keith Whitwell30990a61999-11-04 19:42:28 +0000821 gl_Begin( ctx, mode ); \
jtgafb833d1999-08-19 00:55:39 +0000822 \
823 for (j = 0 ; j < count ; ) { \
jtgafb833d1999-08-19 00:55:39 +0000824 struct immediate *IM = ctx->input; \
Keith Whitwell30990a61999-11-04 19:42:28 +0000825 GLuint start = IM->Start; \
826 GLuint nr = MIN2( VB_MAX, count - j + start ); \
827 GLuint sf = IM->Flag[start]; \
Keith Whitwelld4714731999-10-19 18:37:02 +0000828 IM->FlushElt |= IM->ArrayEltFlush; \
jtgafb833d1999-08-19 00:55:39 +0000829 \
Keith Whitwell30990a61999-11-04 19:42:28 +0000830 for (i = start ; i < nr ; i++) { \
jtgafb833d1999-08-19 00:55:39 +0000831 IM->Elt[i] = (GLuint) *indices++; \
Keith Whitwell2be79c11999-08-26 14:50:49 +0000832 IM->Flag[i] = VERT_ELT; \
jtgafb833d1999-08-19 00:55:39 +0000833 } \
834 \
Keith Whitwell30990a61999-11-04 19:42:28 +0000835 if (j == 0) IM->Flag[start] |= sf; \
jtgafb833d1999-08-19 00:55:39 +0000836 \
837 IM->Count = nr; \
Keith Whitwell30990a61999-11-04 19:42:28 +0000838 j += nr - start; \
jtgafb833d1999-08-19 00:55:39 +0000839 \
Brian Paul038573a2000-09-11 18:49:06 +0000840 if (j == count) \
841 gl_End( ctx ); \
842 _mesa_maybe_transform_vb( IM ); \
jtgafb833d1999-08-19 00:55:39 +0000843 } \
844}
Keith Whitwell30990a61999-11-04 19:42:28 +0000845#else
846#define DRAW_ELT(FUNC, TYPE) \
847static void FUNC( GLcontext *ctx, GLenum mode, \
848 TYPE *indices, GLuint count ) \
849{ \
850 int i; \
851 glBegin(mode); \
852 for (i = 0 ; i < count ; i++) \
853 glArrayElement( indices[i] ); \
854 glEnd(); \
855}
856#endif
857
jtgafb833d1999-08-19 00:55:39 +0000858
859DRAW_ELT( draw_elt_ubyte, GLubyte )
860DRAW_ELT( draw_elt_ushort, GLushort )
861DRAW_ELT( draw_elt_uint, GLuint )
862
863
864static GLuint natural_stride[0x10] =
865{
866 sizeof(GLbyte), /* 0 */
867 sizeof(GLubyte), /* 1 */
868 sizeof(GLshort), /* 2 */
869 sizeof(GLushort), /* 3 */
870 sizeof(GLint), /* 4 */
871 sizeof(GLuint), /* 5 */
872 sizeof(GLfloat), /* 6 */
873 2 * sizeof(GLbyte), /* 7 */
874 3 * sizeof(GLbyte), /* 8 */
875 4 * sizeof(GLbyte), /* 9 */
876 sizeof(GLdouble), /* a */
877 0, /* b */
878 0, /* c */
879 0, /* d */
880 0, /* e */
881 0 /* f */
882};
883
Brian Paulfbd8f211999-11-11 01:22:25 +0000884
885void
886_mesa_DrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices)
jtgafb833d1999-08-19 00:55:39 +0000887{
Brian Paulfbd8f211999-11-11 01:22:25 +0000888 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000889 struct gl_cva *cva;
890
jtgafb833d1999-08-19 00:55:39 +0000891 cva = &ctx->CVA;
892 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glDrawElements");
893
Keith Whitwelld4714731999-10-19 18:37:02 +0000894 if (count <= 0) {
895 if (count < 0)
896 gl_error( ctx, GL_INVALID_VALUE, "glDrawElements(count)" );
jtgafb833d1999-08-19 00:55:39 +0000897 return;
898 }
899
Keith Whitwelle828bc82000-02-25 03:55:39 +0000900 if (mode < 0 || mode > GL_POLYGON) {
jtgafb833d1999-08-19 00:55:39 +0000901 gl_error( ctx, GL_INVALID_ENUM, "glDrawArrays(mode)" );
902 return;
903 }
904
905 if (type != GL_UNSIGNED_INT && type != GL_UNSIGNED_BYTE && type != GL_UNSIGNED_SHORT)
906 {
907 gl_error( ctx, GL_INVALID_ENUM, "glDrawElements(type)" );
908 return;
909 }
910
911 if (ctx->NewState)
912 gl_update_state(ctx);
913
914 if (ctx->CompileCVAFlag)
915 {
916#if defined(MESA_CVA_PROF)
917 force_init_prof();
918#endif
919
920 /* Treat VERT_ELT like a special client array.
921 */
922 ctx->Array.NewArrayState |= VERT_ELT;
923 ctx->Array.Summary |= VERT_ELT;
924 ctx->Array.Flags |= VERT_ELT;
925
926 cva->elt_mode = mode;
927 cva->elt_count = count;
928 cva->Elt.Type = type;
929 cva->Elt.Ptr = (void *) indices;
930 cva->Elt.StrideB = natural_stride[TYPE_IDX(type)];
931 cva->EltFunc = gl_trans_1ui_tab[TYPE_IDX(type)];
932
933 if (!cva->pre.pipeline_valid)
934 gl_build_precalc_pipeline( ctx );
935 else if (MESA_VERBOSE & VERBOSE_PIPELINE)
936 fprintf(stderr, ": dont rebuild\n");
937
938 gl_cva_force_precalc( ctx );
939
940 /* Did we 'precalculate' the render op?
941 */
942 if (ctx->CVA.pre.ops & PIPE_OP_RENDER) {
943 ctx->Array.NewArrayState |= VERT_ELT;
944 ctx->Array.Summary &= ~VERT_ELT;
945 ctx->Array.Flags &= ~VERT_ELT;
946 return;
947 }
948
949 if ( (MESA_VERBOSE&VERBOSE_VARRAY) )
950 printf("using immediate\n");
951 }
952
953
954 /* Otherwise, have to use the immediate path to render.
955 */
956 switch (type) {
957 case GL_UNSIGNED_BYTE:
958 {
959 GLubyte *ub_indices = (GLubyte *) indices;
960 if (ctx->Array.Summary & VERT_OBJ_ANY) {
961 draw_elt_ubyte( ctx, mode, ub_indices, count );
962 } else {
963 gl_ArrayElement( ctx, (GLuint) ub_indices[count-1] );
964 }
965 }
966 break;
967 case GL_UNSIGNED_SHORT:
968 {
969 GLushort *us_indices = (GLushort *) indices;
970 if (ctx->Array.Summary & VERT_OBJ_ANY) {
971 draw_elt_ushort( ctx, mode, us_indices, count );
972 } else {
973 gl_ArrayElement( ctx, (GLuint) us_indices[count-1] );
974 }
975 }
976 break;
977 case GL_UNSIGNED_INT:
978 {
979 GLuint *ui_indices = (GLuint *) indices;
980 if (ctx->Array.Summary & VERT_OBJ_ANY) {
981 draw_elt_uint( ctx, mode, ui_indices, count );
982 } else {
983 gl_ArrayElement( ctx, ui_indices[count-1] );
984 }
985 }
986 break;
987 default:
988 gl_error( ctx, GL_INVALID_ENUM, "glDrawElements(type)" );
989 break;
990 }
991
992 if (ctx->CompileCVAFlag) {
993 ctx->Array.NewArrayState |= VERT_ELT;
994 ctx->Array.Summary &= ~VERT_ELT;
995 }
996}
997
998
999
Brian Paulfbd8f211999-11-11 01:22:25 +00001000void
1001_mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
jtgafb833d1999-08-19 00:55:39 +00001002{
Brian Paulfbd8f211999-11-11 01:22:25 +00001003 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +00001004 GLboolean tflag, cflag, nflag; /* enable/disable flags */
1005 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
1006
1007 GLenum ctype; /* color type */
1008 GLint coffset, noffset, voffset;/* color, normal, vertex offsets */
1009 GLint defstride; /* default stride */
1010 GLint c, f;
1011 GLint coordUnitSave;
1012
jtgafb833d1999-08-19 00:55:39 +00001013 f = sizeof(GLfloat);
1014 c = f * ((4*sizeof(GLubyte) + (f-1)) / f);
1015
1016 if (stride<0) {
1017 gl_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
1018 return;
1019 }
1020
1021 switch (format) {
1022 case GL_V2F:
1023 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1024 tcomps = 0; ccomps = 0; vcomps = 2;
1025 voffset = 0;
1026 defstride = 2*f;
1027 break;
1028 case GL_V3F:
1029 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1030 tcomps = 0; ccomps = 0; vcomps = 3;
1031 voffset = 0;
1032 defstride = 3*f;
1033 break;
1034 case GL_C4UB_V2F:
1035 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1036 tcomps = 0; ccomps = 4; vcomps = 2;
1037 ctype = GL_UNSIGNED_BYTE;
1038 coffset = 0;
1039 voffset = c;
1040 defstride = c + 2*f;
1041 break;
1042 case GL_C4UB_V3F:
1043 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1044 tcomps = 0; ccomps = 4; vcomps = 3;
1045 ctype = GL_UNSIGNED_BYTE;
1046 coffset = 0;
1047 voffset = c;
1048 defstride = c + 3*f;
1049 break;
1050 case GL_C3F_V3F:
1051 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1052 tcomps = 0; ccomps = 3; vcomps = 3;
1053 ctype = GL_FLOAT;
1054 coffset = 0;
1055 voffset = 3*f;
1056 defstride = 6*f;
1057 break;
1058 case GL_N3F_V3F:
1059 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
1060 tcomps = 0; ccomps = 0; vcomps = 3;
1061 noffset = 0;
1062 voffset = 3*f;
1063 defstride = 6*f;
1064 break;
1065 case GL_C4F_N3F_V3F:
1066 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
1067 tcomps = 0; ccomps = 4; vcomps = 3;
1068 ctype = GL_FLOAT;
1069 coffset = 0;
1070 noffset = 4*f;
1071 voffset = 7*f;
1072 defstride = 10*f;
1073 break;
1074 case GL_T2F_V3F:
1075 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1076 tcomps = 2; ccomps = 0; vcomps = 3;
1077 voffset = 2*f;
1078 defstride = 5*f;
1079 break;
1080 case GL_T4F_V4F:
1081 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1082 tcomps = 4; ccomps = 0; vcomps = 4;
1083 voffset = 4*f;
1084 defstride = 8*f;
1085 break;
1086 case GL_T2F_C4UB_V3F:
1087 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1088 tcomps = 2; ccomps = 4; vcomps = 3;
1089 ctype = GL_UNSIGNED_BYTE;
1090 coffset = 2*f;
1091 voffset = c+2*f;
1092 defstride = c+5*f;
1093 break;
1094 case GL_T2F_C3F_V3F:
1095 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1096 tcomps = 2; ccomps = 3; vcomps = 3;
1097 ctype = GL_FLOAT;
1098 coffset = 2*f;
1099 voffset = 5*f;
1100 defstride = 8*f;
1101 break;
1102 case GL_T2F_N3F_V3F:
1103 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
1104 tcomps = 2; ccomps = 0; vcomps = 3;
1105 noffset = 2*f;
1106 voffset = 5*f;
1107 defstride = 8*f;
1108 break;
1109 case GL_T2F_C4F_N3F_V3F:
1110 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1111 tcomps = 2; ccomps = 4; vcomps = 3;
1112 ctype = GL_FLOAT;
1113 coffset = 2*f;
1114 noffset = 6*f;
1115 voffset = 9*f;
1116 defstride = 12*f;
1117 break;
1118 case GL_T4F_C4F_N3F_V4F:
1119 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1120 tcomps = 4; ccomps = 4; vcomps = 4;
1121 ctype = GL_FLOAT;
1122 coffset = 4*f;
1123 noffset = 8*f;
1124 voffset = 11*f;
1125 defstride = 15*f;
1126 break;
1127 default:
1128 gl_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
1129 return;
1130 }
1131
1132 if (stride==0) {
1133 stride = defstride;
1134 }
1135
Brian Paulfbd8f211999-11-11 01:22:25 +00001136 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
1137 _mesa_DisableClientState( GL_INDEX_ARRAY );
jtgafb833d1999-08-19 00:55:39 +00001138
1139 /* Texcoords */
Brian Paul45224fa1999-09-07 22:31:30 +00001140 coordUnitSave = ctx->Array.ActiveTexture;
jtgafb833d1999-08-19 00:55:39 +00001141 if (tflag) {
1142 GLint i;
1143 GLint factor = ctx->Array.TexCoordInterleaveFactor;
1144 for (i = 0; i < factor; i++) {
Brian Paulfbd8f211999-11-11 01:22:25 +00001145 _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + i) );
1146 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
1147 glTexCoordPointer( tcomps, GL_FLOAT, stride,
jtgafb833d1999-08-19 00:55:39 +00001148 (GLubyte *) pointer + i * coffset );
1149 }
1150 for (i = factor; i < ctx->Const.MaxTextureUnits; i++) {
Brian Paulfbd8f211999-11-11 01:22:25 +00001151 _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + i) );
1152 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
jtgafb833d1999-08-19 00:55:39 +00001153 }
1154 }
1155 else {
1156 GLint i;
1157 for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
Brian Paulfbd8f211999-11-11 01:22:25 +00001158 _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + i) );
1159 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
jtgafb833d1999-08-19 00:55:39 +00001160 }
1161 }
1162 /* Restore texture coordinate unit index */
Brian Paulfbd8f211999-11-11 01:22:25 +00001163 _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + coordUnitSave) );
jtgafb833d1999-08-19 00:55:39 +00001164
1165
1166 /* Color */
1167 if (cflag) {
Brian Paulfbd8f211999-11-11 01:22:25 +00001168 _mesa_EnableClientState( GL_COLOR_ARRAY );
1169 glColorPointer( ccomps, ctype, stride,
jtgafb833d1999-08-19 00:55:39 +00001170 (GLubyte*) pointer + coffset );
1171 }
1172 else {
Brian Paulfbd8f211999-11-11 01:22:25 +00001173 _mesa_DisableClientState( GL_COLOR_ARRAY );
jtgafb833d1999-08-19 00:55:39 +00001174 }
1175
1176
1177 /* Normals */
1178 if (nflag) {
Brian Paulfbd8f211999-11-11 01:22:25 +00001179 _mesa_EnableClientState( GL_NORMAL_ARRAY );
1180 glNormalPointer( GL_FLOAT, stride,
jtgafb833d1999-08-19 00:55:39 +00001181 (GLubyte*) pointer + noffset );
1182 }
1183 else {
Brian Paulfbd8f211999-11-11 01:22:25 +00001184 _mesa_DisableClientState( GL_NORMAL_ARRAY );
jtgafb833d1999-08-19 00:55:39 +00001185 }
1186
Brian Paulfbd8f211999-11-11 01:22:25 +00001187 _mesa_EnableClientState( GL_VERTEX_ARRAY );
1188 glVertexPointer( vcomps, GL_FLOAT, stride,
jtgafb833d1999-08-19 00:55:39 +00001189 (GLubyte *) pointer + voffset );
1190}
1191
1192
1193
Brian Paulfbd8f211999-11-11 01:22:25 +00001194void
1195_mesa_DrawRangeElements(GLenum mode, GLuint start,
1196 GLuint end, GLsizei count,
1197 GLenum type, const GLvoid *indices)
jtgafb833d1999-08-19 00:55:39 +00001198{
Brian Paulfbd8f211999-11-11 01:22:25 +00001199 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +00001200
1201 if (end < start) {
1202 gl_error(ctx, GL_INVALID_VALUE, "glDrawRangeElements( end < start )");
1203 return;
1204 }
1205
Brian Pauldf37c6b2000-02-05 02:05:14 +00001206#if 0
1207 /*
1208 * XXX something in locked arrays is broken! If start = 0,
1209 * end = 1 and count = 2 we'll take the LockArrays path and
1210 * get incorrect results. See Scott McMillan's bug of 3 Jan 2000.
1211 * For now, don't use locked arrays.
1212 */
Brian Paul5b37c321999-11-05 06:43:10 +00001213 if (!ctx->Array.LockCount && 2*count > (GLint) 3*(end-start)) {
Brian Paulfbd8f211999-11-11 01:22:25 +00001214 glLockArraysEXT( start, end );
1215 glDrawElements( mode, count, type, indices );
1216 glUnlockArraysEXT();
jtgafb833d1999-08-19 00:55:39 +00001217 } else {
Brian Paulfbd8f211999-11-11 01:22:25 +00001218 glDrawElements( mode, count, type, indices );
jtgafb833d1999-08-19 00:55:39 +00001219 }
Brian Pauldf37c6b2000-02-05 02:05:14 +00001220#else
1221 glDrawElements( mode, count, type, indices );
1222#endif
jtgafb833d1999-08-19 00:55:39 +00001223}
1224
1225
1226
1227void gl_update_client_state( GLcontext *ctx )
1228{
Brian Paulce938b32000-10-18 15:02:59 +00001229 static const GLuint sz_flags[5] = {
1230 0,
1231 0,
1232 VERT_OBJ_2,
1233 VERT_OBJ_23,
1234 VERT_OBJ_234
1235 };
1236 static const GLuint tc_flags[5] = {
1237 0,
1238 VERT_TEX0_1,
1239 VERT_TEX0_12,
1240 VERT_TEX0_123,
1241 VERT_TEX0_1234
1242 };
1243 GLint i;
jtgafb833d1999-08-19 00:55:39 +00001244
1245 ctx->Array.Flags = 0;
1246 ctx->Array.Summary = 0;
1247 ctx->input->ArrayIncr = 0;
1248
1249 if (ctx->Array.Normal.Enabled) ctx->Array.Flags |= VERT_NORM;
1250 if (ctx->Array.Color.Enabled) ctx->Array.Flags |= VERT_RGBA;
1251 if (ctx->Array.Index.Enabled) ctx->Array.Flags |= VERT_INDEX;
1252 if (ctx->Array.EdgeFlag.Enabled) ctx->Array.Flags |= VERT_EDGE;
1253 if (ctx->Array.Vertex.Enabled) {
1254 ctx->Array.Flags |= sz_flags[ctx->Array.Vertex.Size];
1255 ctx->input->ArrayIncr = 1;
1256 }
Brian Paulce938b32000-10-18 15:02:59 +00001257 for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
1258 if (ctx->Array.TexCoord[i].Enabled) {
1259 ctx->Array.Flags |= (tc_flags[ctx->Array.TexCoord[i].Size] << (i * NR_TEXSIZE_BITS));
1260 }
jtgafb833d1999-08-19 00:55:39 +00001261 }
1262
1263 /* Not really important any more:
1264 */
1265 ctx->Array.Summary = ctx->Array.Flags & VERT_DATA;
jtgafb833d1999-08-19 00:55:39 +00001266 ctx->input->ArrayAndFlags = ~ctx->Array.Flags;
1267 ctx->input->ArrayEltFlush = !(ctx->CompileCVAFlag);
1268}
1269