blob: 62e5019dc92cc663584627377291000663ea018b [file] [log] [blame]
Brian Paulce938b32000-10-18 15:02:59 +00001/* $Id: varray.c,v 1.24 2000/10/18 15:02:59 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)
493 (ctx->Array.TexCoordEltFunc[1])( IM->TexCoord[2],
494 &ctx->Array.TexCoord[2],
495 flags, elts, (VERT_ELT|VERT_TEX2_ANY),
496 start, count);
497#endif
Keith Whitwelld4714731999-10-19 18:37:02 +0000498
499 for (i = start ; i < count ; i++)
Keith Whitwell6adfc6b1999-11-09 17:26:15 +0000500 if (flags[i] & VERT_ELT)
jtgafb833d1999-08-19 00:55:39 +0000501 flags[i] |= translate;
Keith Whitwell6adfc6b1999-11-09 17:26:15 +0000502
jtgafb833d1999-08-19 00:55:39 +0000503}
504
505
506
Brian Paulfbd8f211999-11-11 01:22:25 +0000507/* Enough funny business going on in here it might be quicker to use a
508 * function pointer.
509 */
510#define ARRAY_ELT( IM, i ) \
511{ \
512 GLuint count = IM->Count; \
513 IM->Elt[count] = i; \
514 IM->Flag[count] = ((IM->Flag[count] & IM->ArrayAndFlags) | \
515 VERT_ELT); \
516 IM->FlushElt |= IM->ArrayEltFlush; \
517 IM->Count = count += IM->ArrayIncr; \
518 if (count == VB_MAX) \
Brian Paul038573a2000-09-11 18:49:06 +0000519 _mesa_maybe_transform_vb( IM ); \
Brian Paulfbd8f211999-11-11 01:22:25 +0000520}
521
522
523void
524_mesa_ArrayElement( GLint i )
jtgafb833d1999-08-19 00:55:39 +0000525{
Brian Paulfbd8f211999-11-11 01:22:25 +0000526 GET_IMMEDIATE;
527 ARRAY_ELT( IM, i );
528}
529
530
Brian Paul4463a242000-01-13 00:25:22 +0000531static void
532gl_ArrayElement( GLcontext *CC, GLint i )
Brian Paulfbd8f211999-11-11 01:22:25 +0000533{
534 struct immediate *im = CC->input;
535 ARRAY_ELT( im, i );
536}
537
538
539
540void
541_mesa_DrawArrays(GLenum mode, GLint start, GLsizei count)
542{
543 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000544 struct vertex_buffer *VB = ctx->VB;
545 GLint i;
546
547 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glDrawArrays");
548
549 if (count<0) {
550 gl_error( ctx, GL_INVALID_VALUE, "glDrawArrays(count)" );
551 return;
552 }
553
Brian Paulce938b32000-10-18 15:02:59 +0000554 if (!ctx->CompileFlag && ctx->Array.Vertex.Enabled) {
jtgafb833d1999-08-19 00:55:39 +0000555 GLint remaining = count;
556 GLint i;
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000557 struct gl_client_array *Normal;
558 struct gl_client_array *Color;
559 struct gl_client_array *Index;
560 struct gl_client_array *TexCoord[MAX_TEXTURE_UNITS];
561 struct gl_client_array *EdgeFlag;
jtgafb833d1999-08-19 00:55:39 +0000562 struct immediate *IM = VB->IM;
jtgafb833d1999-08-19 00:55:39 +0000563 struct gl_pipeline *elt = &ctx->CVA.elt;
Brian Paul5b37c321999-11-05 06:43:10 +0000564 GLboolean relock;
jtgafb833d1999-08-19 00:55:39 +0000565 GLuint fallback, required;
566
567 if (ctx->NewState)
568 gl_update_state( ctx );
569
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000570 /* Just turn off cva on this path. Could be useful for multipass
571 * rendering to keep it turned on.
jtgafb833d1999-08-19 00:55:39 +0000572 */
573 relock = ctx->CompileCVAFlag;
jtgafb833d1999-08-19 00:55:39 +0000574
Keith Whitwell784657c1999-11-19 00:03:27 +0000575 if (relock) {
576 ctx->CompileCVAFlag = 0;
577 elt->pipeline_valid = 0;
578 }
579
580 if (!elt->pipeline_valid)
jtgafb833d1999-08-19 00:55:39 +0000581 gl_build_immediate_pipeline( ctx );
582
583 required = elt->inputs;
584 fallback = (elt->inputs & ~ctx->Array.Summary);
585
Keith Whitwell784657c1999-11-19 00:03:27 +0000586 /* The translate function doesn't do anything about size. It
587 * just ensures that type and stride come out right.
588 */
589 IM->v.Obj.size = ctx->Array.Vertex.Size;
590
Brian Paulce938b32000-10-18 15:02:59 +0000591 if (required & VERT_RGBA) {
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000592 Color = &ctx->Array.Color;
593 if (fallback & VERT_RGBA) {
594 Color = &ctx->Fallback.Color;
595 ctx->Array.ColorFunc =
596 gl_trans_4ub_tab[4][TYPE_IDX(GL_UNSIGNED_BYTE)];
597 }
jtgafb833d1999-08-19 00:55:39 +0000598 }
599
Brian Paulce938b32000-10-18 15:02:59 +0000600 if (required & VERT_INDEX) {
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000601 Index = &ctx->Array.Index;
602 if (fallback & VERT_INDEX) {
603 Index = &ctx->Fallback.Index;
604 ctx->Array.IndexFunc = gl_trans_1ui_tab[TYPE_IDX(GL_UNSIGNED_INT)];
605 }
jtgafb833d1999-08-19 00:55:39 +0000606 }
607
Brian Paulce938b32000-10-18 15:02:59 +0000608 for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) {
jtgafb833d1999-08-19 00:55:39 +0000609 GLuint flag = VERT_TEX_ANY(i);
610
611 if (required & flag) {
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000612 TexCoord[i] = &ctx->Array.TexCoord[i];
jtgafb833d1999-08-19 00:55:39 +0000613
Brian Paulce938b32000-10-18 15:02:59 +0000614 if (fallback & flag) {
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000615 TexCoord[i] = &ctx->Fallback.TexCoord[i];
616 TexCoord[i]->Size = gl_texcoord_size( ctx->Current.Flag, i );
617
618 ctx->Array.TexCoordFunc[i] =
619 gl_trans_4f_tab[TexCoord[i]->Size][TYPE_IDX(GL_FLOAT)];
jtgafb833d1999-08-19 00:55:39 +0000620 }
jtgafb833d1999-08-19 00:55:39 +0000621 }
622 }
623
Brian Paulce938b32000-10-18 15:02:59 +0000624 if (ctx->Array.Flags != ctx->Array.Flag[0]) {
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000625 for (i = 0 ; i < VB_MAX ; i++)
jtgafb833d1999-08-19 00:55:39 +0000626 ctx->Array.Flag[i] = ctx->Array.Flags;
Brian Paulce938b32000-10-18 15:02:59 +0000627 }
jtgafb833d1999-08-19 00:55:39 +0000628
Brian Paulce938b32000-10-18 15:02:59 +0000629 if (required & VERT_NORM) {
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000630 Normal = &ctx->Array.Normal;
631 if (fallback & VERT_NORM) {
632 Normal = &ctx->Fallback.Normal;
633 ctx->Array.NormalFunc = gl_trans_3f_tab[TYPE_IDX(GL_FLOAT)];
634 }
jtgafb833d1999-08-19 00:55:39 +0000635 }
636
Brian Paulce938b32000-10-18 15:02:59 +0000637 if ( required & VERT_EDGE ) {
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000638 if (mode == GL_TRIANGLES ||
639 mode == GL_QUADS ||
Brian Paulce938b32000-10-18 15:02:59 +0000640 mode == GL_POLYGON) {
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000641 EdgeFlag = &ctx->Array.EdgeFlag;
642 if (fallback & VERT_EDGE) {
643 EdgeFlag = &ctx->Fallback.EdgeFlag;
644 ctx->Array.EdgeFlagFunc =
645 gl_trans_1ub_tab[TYPE_IDX(GL_UNSIGNED_BYTE)];
646 }
647 }
648 else
649 required &= ~VERT_EDGE;
jtgafb833d1999-08-19 00:55:39 +0000650 }
651
652 VB->Primitive = IM->Primitive;
653 VB->NextPrimitive = IM->NextPrimitive;
654 VB->MaterialMask = IM->MaterialMask;
655 VB->Material = IM->Material;
656 VB->BoundsPtr = 0;
657
658 while (remaining > 0) {
659 GLint vbspace = VB_MAX - VB_START;
660 GLuint count, n;
661
jtgafb833d1999-08-19 00:55:39 +0000662 if (vbspace >= remaining) {
663 n = remaining;
664 VB->LastPrimitive = VB_START + n;
Brian Paulce938b32000-10-18 15:02:59 +0000665 }
666 else {
jtgafb833d1999-08-19 00:55:39 +0000667 n = vbspace;
668 VB->LastPrimitive = VB_START;
669 }
670
671 VB->CullMode = 0;
672
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000673 ctx->Array.VertexFunc( IM->Obj + VB_START,
674 &ctx->Array.Vertex, start, n );
Keith Whitwell20f6c101999-11-09 10:12:34 +0000675
676 if (required & VERT_NORM) {
677 ctx->Array.NormalFunc( IM->Normal + VB_START,
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000678 Normal, start, n );
Keith Whitwell20f6c101999-11-09 10:12:34 +0000679 }
680
681 if (required & VERT_EDGE) {
682 ctx->Array.EdgeFlagFunc( IM->EdgeFlag + VB_START,
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000683 EdgeFlag, start, n );
Keith Whitwell20f6c101999-11-09 10:12:34 +0000684 }
685
686 if (required & VERT_RGBA) {
687 ctx->Array.ColorFunc( IM->Color + VB_START,
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000688 Color, start, n );
Keith Whitwell20f6c101999-11-09 10:12:34 +0000689 }
690
691 if (required & VERT_INDEX) {
692 ctx->Array.IndexFunc( IM->Index + VB_START,
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000693 Index, start, n );
Keith Whitwell20f6c101999-11-09 10:12:34 +0000694 }
695
696 if (required & VERT_TEX0_ANY) {
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000697 IM->v.TexCoord[0].size = TexCoord[0]->Size;
Keith Whitwell20f6c101999-11-09 10:12:34 +0000698 ctx->Array.TexCoordFunc[0]( IM->TexCoord[0] + VB_START,
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000699 TexCoord[0], start, n );
Keith Whitwell20f6c101999-11-09 10:12:34 +0000700 }
701
702 if (required & VERT_TEX1_ANY) {
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000703 IM->v.TexCoord[1].size = TexCoord[1]->Size;
Keith Whitwell20f6c101999-11-09 10:12:34 +0000704 ctx->Array.TexCoordFunc[1]( IM->TexCoord[1] + VB_START,
Keith Whitwell6a9f16e1999-11-09 17:00:25 +0000705 TexCoord[1], start, n );
jtgafb833d1999-08-19 00:55:39 +0000706 }
Brian Paulce938b32000-10-18 15:02:59 +0000707#if MAX_TEXTURE_UNITS > 2
708 if (required & VERT_TEX2_ANY) {
709 IM->v.TexCoord[2].size = TexCoord[2]->Size;
710 ctx->Array.TexCoordFunc[2]( IM->TexCoord[2] + VB_START,
711 TexCoord[2], start, n );
712 }
713#endif
jtgafb833d1999-08-19 00:55:39 +0000714
Keith Whitwell20f6c101999-11-09 10:12:34 +0000715 VB->ObjPtr = &IM->v.Obj;
716 VB->NormalPtr = &IM->v.Normal;
717 VB->ColorPtr = &IM->v.Color;
718 VB->Color[0] = VB->Color[1] = VB->ColorPtr;
719 VB->IndexPtr = &IM->v.Index;
720 VB->EdgeFlagPtr = &IM->v.EdgeFlag;
Brian Paulce938b32000-10-18 15:02:59 +0000721 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
722 VB->TexCoordPtr[i] = &IM->v.TexCoord[i];
723 }
jtgafb833d1999-08-19 00:55:39 +0000724
725 VB->Flag = ctx->Array.Flag;
jtgafb833d1999-08-19 00:55:39 +0000726 VB->OrFlag = ctx->Array.Flags;
727
Keith Whitwell20f6c101999-11-09 10:12:34 +0000728 VB->Start = IM->Start = VB_START;
729 count = VB->Count = IM->Count = VB_START + n;
jtgafb833d1999-08-19 00:55:39 +0000730
Keith Whitwell20f6c101999-11-09 10:12:34 +0000731#define RESET_VEC(v, t, s, c) (v.start = t v.data[s], v.count = c)
jtgafb833d1999-08-19 00:55:39 +0000732
Keith Whitwell20f6c101999-11-09 10:12:34 +0000733 RESET_VEC(IM->v.Obj, (GLfloat *), VB_START, count);
734 RESET_VEC(IM->v.Normal, (GLfloat *), VB_START, count);
Brian Paulce938b32000-10-18 15:02:59 +0000735 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
736 RESET_VEC(IM->v.TexCoord[i], (GLfloat *), VB_START, count);
737 }
Keith Whitwell20f6c101999-11-09 10:12:34 +0000738 RESET_VEC(IM->v.Index, &, VB_START, count);
739 RESET_VEC(IM->v.Elt, &, VB_START, count);
740 RESET_VEC(IM->v.EdgeFlag, &, VB_START, count);
741 RESET_VEC(IM->v.Color, (GLubyte *), VB_START, count);
742 RESET_VEC(VB->Clip, (GLfloat *), VB_START, count);
743 RESET_VEC(VB->Eye, (GLfloat *), VB_START, count);
744 RESET_VEC(VB->Win, (GLfloat *), VB_START, count);
745 RESET_VEC(VB->BColor, (GLubyte *), VB_START, count);
746 RESET_VEC(VB->BIndex, &, VB_START, count);
jtgafb833d1999-08-19 00:55:39 +0000747
748 VB->NextPrimitive[VB->CopyStart] = VB->Count;
749 VB->Primitive[VB->CopyStart] = mode;
Keith Whitwelle828bc82000-02-25 03:55:39 +0000750 ctx->Array.Flag[count] |= VERT_END_VB;
jtgafb833d1999-08-19 00:55:39 +0000751
752 /* Transform and render.
753 */
754 gl_run_pipeline( VB );
755 gl_reset_vb( VB );
756
757 ctx->Array.Flag[count] = ctx->Array.Flags;
758 ctx->Array.Flag[VB_START] = ctx->Array.Flags;
jtgafb833d1999-08-19 00:55:39 +0000759
760 start += n;
761 remaining -= n;
762 }
763
Keith Whitwell784657c1999-11-19 00:03:27 +0000764 gl_reset_input( ctx );
765
766 if (relock) {
767 ctx->CompileCVAFlag = relock;
768 elt->pipeline_valid = 0;
769 }
jtgafb833d1999-08-19 00:55:39 +0000770 }
771 else if (ctx->Array.Vertex.Enabled)
772 {
773 /* The GL_COMPILE and GL_COMPILE_AND_EXECUTE cases. These
774 * could be handled by the above code, but it gets a little
Keith Whitwell20f6c101999-11-09 10:12:34 +0000775 * complex. The generated list is still of good quality
776 * this way.
jtgafb833d1999-08-19 00:55:39 +0000777 */
jtgafb833d1999-08-19 00:55:39 +0000778 gl_Begin( ctx, mode );
779 for (i=0;i<count;i++) {
780 gl_ArrayElement( ctx, start+i );
781 }
782 gl_End( ctx );
783 }
784 else
785 {
786 /* The degenerate case where vertices are not enabled - only
787 * need to process the very final array element, as all of the
788 * preceding ones would be overwritten anyway.
789 */
790 gl_Begin( ctx, mode );
791 gl_ArrayElement( ctx, start+count );
792 gl_End( ctx );
793 }
794}
795
796
797
798/* KW: Exactly fakes the effects of calling glArrayElement multiple times.
jtgafb833d1999-08-19 00:55:39 +0000799 */
Keith Whitwell30990a61999-11-04 19:42:28 +0000800#if 1
jtgafb833d1999-08-19 00:55:39 +0000801#define DRAW_ELT(FUNC, TYPE) \
802static void FUNC( GLcontext *ctx, GLenum mode, \
803 TYPE *indices, GLuint count ) \
804{ \
805 GLuint i,j; \
806 \
Keith Whitwell30990a61999-11-04 19:42:28 +0000807 gl_Begin( ctx, mode ); \
jtgafb833d1999-08-19 00:55:39 +0000808 \
809 for (j = 0 ; j < count ; ) { \
jtgafb833d1999-08-19 00:55:39 +0000810 struct immediate *IM = ctx->input; \
Keith Whitwell30990a61999-11-04 19:42:28 +0000811 GLuint start = IM->Start; \
812 GLuint nr = MIN2( VB_MAX, count - j + start ); \
813 GLuint sf = IM->Flag[start]; \
Keith Whitwelld4714731999-10-19 18:37:02 +0000814 IM->FlushElt |= IM->ArrayEltFlush; \
jtgafb833d1999-08-19 00:55:39 +0000815 \
Keith Whitwell30990a61999-11-04 19:42:28 +0000816 for (i = start ; i < nr ; i++) { \
jtgafb833d1999-08-19 00:55:39 +0000817 IM->Elt[i] = (GLuint) *indices++; \
Keith Whitwell2be79c11999-08-26 14:50:49 +0000818 IM->Flag[i] = VERT_ELT; \
jtgafb833d1999-08-19 00:55:39 +0000819 } \
820 \
Keith Whitwell30990a61999-11-04 19:42:28 +0000821 if (j == 0) IM->Flag[start] |= sf; \
jtgafb833d1999-08-19 00:55:39 +0000822 \
823 IM->Count = nr; \
Keith Whitwell30990a61999-11-04 19:42:28 +0000824 j += nr - start; \
jtgafb833d1999-08-19 00:55:39 +0000825 \
Brian Paul038573a2000-09-11 18:49:06 +0000826 if (j == count) \
827 gl_End( ctx ); \
828 _mesa_maybe_transform_vb( IM ); \
jtgafb833d1999-08-19 00:55:39 +0000829 } \
830}
Keith Whitwell30990a61999-11-04 19:42:28 +0000831#else
832#define DRAW_ELT(FUNC, TYPE) \
833static void FUNC( GLcontext *ctx, GLenum mode, \
834 TYPE *indices, GLuint count ) \
835{ \
836 int i; \
837 glBegin(mode); \
838 for (i = 0 ; i < count ; i++) \
839 glArrayElement( indices[i] ); \
840 glEnd(); \
841}
842#endif
843
jtgafb833d1999-08-19 00:55:39 +0000844
845DRAW_ELT( draw_elt_ubyte, GLubyte )
846DRAW_ELT( draw_elt_ushort, GLushort )
847DRAW_ELT( draw_elt_uint, GLuint )
848
849
850static GLuint natural_stride[0x10] =
851{
852 sizeof(GLbyte), /* 0 */
853 sizeof(GLubyte), /* 1 */
854 sizeof(GLshort), /* 2 */
855 sizeof(GLushort), /* 3 */
856 sizeof(GLint), /* 4 */
857 sizeof(GLuint), /* 5 */
858 sizeof(GLfloat), /* 6 */
859 2 * sizeof(GLbyte), /* 7 */
860 3 * sizeof(GLbyte), /* 8 */
861 4 * sizeof(GLbyte), /* 9 */
862 sizeof(GLdouble), /* a */
863 0, /* b */
864 0, /* c */
865 0, /* d */
866 0, /* e */
867 0 /* f */
868};
869
Brian Paulfbd8f211999-11-11 01:22:25 +0000870
871void
872_mesa_DrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices)
jtgafb833d1999-08-19 00:55:39 +0000873{
Brian Paulfbd8f211999-11-11 01:22:25 +0000874 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000875 struct gl_cva *cva;
876
jtgafb833d1999-08-19 00:55:39 +0000877 cva = &ctx->CVA;
878 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glDrawElements");
879
Keith Whitwelld4714731999-10-19 18:37:02 +0000880 if (count <= 0) {
881 if (count < 0)
882 gl_error( ctx, GL_INVALID_VALUE, "glDrawElements(count)" );
jtgafb833d1999-08-19 00:55:39 +0000883 return;
884 }
885
Keith Whitwelle828bc82000-02-25 03:55:39 +0000886 if (mode < 0 || mode > GL_POLYGON) {
jtgafb833d1999-08-19 00:55:39 +0000887 gl_error( ctx, GL_INVALID_ENUM, "glDrawArrays(mode)" );
888 return;
889 }
890
891 if (type != GL_UNSIGNED_INT && type != GL_UNSIGNED_BYTE && type != GL_UNSIGNED_SHORT)
892 {
893 gl_error( ctx, GL_INVALID_ENUM, "glDrawElements(type)" );
894 return;
895 }
896
897 if (ctx->NewState)
898 gl_update_state(ctx);
899
900 if (ctx->CompileCVAFlag)
901 {
902#if defined(MESA_CVA_PROF)
903 force_init_prof();
904#endif
905
906 /* Treat VERT_ELT like a special client array.
907 */
908 ctx->Array.NewArrayState |= VERT_ELT;
909 ctx->Array.Summary |= VERT_ELT;
910 ctx->Array.Flags |= VERT_ELT;
911
912 cva->elt_mode = mode;
913 cva->elt_count = count;
914 cva->Elt.Type = type;
915 cva->Elt.Ptr = (void *) indices;
916 cva->Elt.StrideB = natural_stride[TYPE_IDX(type)];
917 cva->EltFunc = gl_trans_1ui_tab[TYPE_IDX(type)];
918
919 if (!cva->pre.pipeline_valid)
920 gl_build_precalc_pipeline( ctx );
921 else if (MESA_VERBOSE & VERBOSE_PIPELINE)
922 fprintf(stderr, ": dont rebuild\n");
923
924 gl_cva_force_precalc( ctx );
925
926 /* Did we 'precalculate' the render op?
927 */
928 if (ctx->CVA.pre.ops & PIPE_OP_RENDER) {
929 ctx->Array.NewArrayState |= VERT_ELT;
930 ctx->Array.Summary &= ~VERT_ELT;
931 ctx->Array.Flags &= ~VERT_ELT;
932 return;
933 }
934
935 if ( (MESA_VERBOSE&VERBOSE_VARRAY) )
936 printf("using immediate\n");
937 }
938
939
940 /* Otherwise, have to use the immediate path to render.
941 */
942 switch (type) {
943 case GL_UNSIGNED_BYTE:
944 {
945 GLubyte *ub_indices = (GLubyte *) indices;
946 if (ctx->Array.Summary & VERT_OBJ_ANY) {
947 draw_elt_ubyte( ctx, mode, ub_indices, count );
948 } else {
949 gl_ArrayElement( ctx, (GLuint) ub_indices[count-1] );
950 }
951 }
952 break;
953 case GL_UNSIGNED_SHORT:
954 {
955 GLushort *us_indices = (GLushort *) indices;
956 if (ctx->Array.Summary & VERT_OBJ_ANY) {
957 draw_elt_ushort( ctx, mode, us_indices, count );
958 } else {
959 gl_ArrayElement( ctx, (GLuint) us_indices[count-1] );
960 }
961 }
962 break;
963 case GL_UNSIGNED_INT:
964 {
965 GLuint *ui_indices = (GLuint *) indices;
966 if (ctx->Array.Summary & VERT_OBJ_ANY) {
967 draw_elt_uint( ctx, mode, ui_indices, count );
968 } else {
969 gl_ArrayElement( ctx, ui_indices[count-1] );
970 }
971 }
972 break;
973 default:
974 gl_error( ctx, GL_INVALID_ENUM, "glDrawElements(type)" );
975 break;
976 }
977
978 if (ctx->CompileCVAFlag) {
979 ctx->Array.NewArrayState |= VERT_ELT;
980 ctx->Array.Summary &= ~VERT_ELT;
981 }
982}
983
984
985
Brian Paulfbd8f211999-11-11 01:22:25 +0000986void
987_mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
jtgafb833d1999-08-19 00:55:39 +0000988{
Brian Paulfbd8f211999-11-11 01:22:25 +0000989 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000990 GLboolean tflag, cflag, nflag; /* enable/disable flags */
991 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
992
993 GLenum ctype; /* color type */
994 GLint coffset, noffset, voffset;/* color, normal, vertex offsets */
995 GLint defstride; /* default stride */
996 GLint c, f;
997 GLint coordUnitSave;
998
jtgafb833d1999-08-19 00:55:39 +0000999 f = sizeof(GLfloat);
1000 c = f * ((4*sizeof(GLubyte) + (f-1)) / f);
1001
1002 if (stride<0) {
1003 gl_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
1004 return;
1005 }
1006
1007 switch (format) {
1008 case GL_V2F:
1009 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1010 tcomps = 0; ccomps = 0; vcomps = 2;
1011 voffset = 0;
1012 defstride = 2*f;
1013 break;
1014 case GL_V3F:
1015 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1016 tcomps = 0; ccomps = 0; vcomps = 3;
1017 voffset = 0;
1018 defstride = 3*f;
1019 break;
1020 case GL_C4UB_V2F:
1021 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1022 tcomps = 0; ccomps = 4; vcomps = 2;
1023 ctype = GL_UNSIGNED_BYTE;
1024 coffset = 0;
1025 voffset = c;
1026 defstride = c + 2*f;
1027 break;
1028 case GL_C4UB_V3F:
1029 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1030 tcomps = 0; ccomps = 4; vcomps = 3;
1031 ctype = GL_UNSIGNED_BYTE;
1032 coffset = 0;
1033 voffset = c;
1034 defstride = c + 3*f;
1035 break;
1036 case GL_C3F_V3F:
1037 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1038 tcomps = 0; ccomps = 3; vcomps = 3;
1039 ctype = GL_FLOAT;
1040 coffset = 0;
1041 voffset = 3*f;
1042 defstride = 6*f;
1043 break;
1044 case GL_N3F_V3F:
1045 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
1046 tcomps = 0; ccomps = 0; vcomps = 3;
1047 noffset = 0;
1048 voffset = 3*f;
1049 defstride = 6*f;
1050 break;
1051 case GL_C4F_N3F_V3F:
1052 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
1053 tcomps = 0; ccomps = 4; vcomps = 3;
1054 ctype = GL_FLOAT;
1055 coffset = 0;
1056 noffset = 4*f;
1057 voffset = 7*f;
1058 defstride = 10*f;
1059 break;
1060 case GL_T2F_V3F:
1061 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1062 tcomps = 2; ccomps = 0; vcomps = 3;
1063 voffset = 2*f;
1064 defstride = 5*f;
1065 break;
1066 case GL_T4F_V4F:
1067 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1068 tcomps = 4; ccomps = 0; vcomps = 4;
1069 voffset = 4*f;
1070 defstride = 8*f;
1071 break;
1072 case GL_T2F_C4UB_V3F:
1073 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1074 tcomps = 2; ccomps = 4; vcomps = 3;
1075 ctype = GL_UNSIGNED_BYTE;
1076 coffset = 2*f;
1077 voffset = c+2*f;
1078 defstride = c+5*f;
1079 break;
1080 case GL_T2F_C3F_V3F:
1081 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1082 tcomps = 2; ccomps = 3; vcomps = 3;
1083 ctype = GL_FLOAT;
1084 coffset = 2*f;
1085 voffset = 5*f;
1086 defstride = 8*f;
1087 break;
1088 case GL_T2F_N3F_V3F:
1089 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
1090 tcomps = 2; ccomps = 0; vcomps = 3;
1091 noffset = 2*f;
1092 voffset = 5*f;
1093 defstride = 8*f;
1094 break;
1095 case GL_T2F_C4F_N3F_V3F:
1096 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1097 tcomps = 2; ccomps = 4; vcomps = 3;
1098 ctype = GL_FLOAT;
1099 coffset = 2*f;
1100 noffset = 6*f;
1101 voffset = 9*f;
1102 defstride = 12*f;
1103 break;
1104 case GL_T4F_C4F_N3F_V4F:
1105 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1106 tcomps = 4; ccomps = 4; vcomps = 4;
1107 ctype = GL_FLOAT;
1108 coffset = 4*f;
1109 noffset = 8*f;
1110 voffset = 11*f;
1111 defstride = 15*f;
1112 break;
1113 default:
1114 gl_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
1115 return;
1116 }
1117
1118 if (stride==0) {
1119 stride = defstride;
1120 }
1121
Brian Paulfbd8f211999-11-11 01:22:25 +00001122 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
1123 _mesa_DisableClientState( GL_INDEX_ARRAY );
jtgafb833d1999-08-19 00:55:39 +00001124
1125 /* Texcoords */
Brian Paul45224fa1999-09-07 22:31:30 +00001126 coordUnitSave = ctx->Array.ActiveTexture;
jtgafb833d1999-08-19 00:55:39 +00001127 if (tflag) {
1128 GLint i;
1129 GLint factor = ctx->Array.TexCoordInterleaveFactor;
1130 for (i = 0; i < factor; i++) {
Brian Paulfbd8f211999-11-11 01:22:25 +00001131 _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + i) );
1132 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
1133 glTexCoordPointer( tcomps, GL_FLOAT, stride,
jtgafb833d1999-08-19 00:55:39 +00001134 (GLubyte *) pointer + i * coffset );
1135 }
1136 for (i = factor; i < ctx->Const.MaxTextureUnits; i++) {
Brian Paulfbd8f211999-11-11 01:22:25 +00001137 _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + i) );
1138 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
jtgafb833d1999-08-19 00:55:39 +00001139 }
1140 }
1141 else {
1142 GLint i;
1143 for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
Brian Paulfbd8f211999-11-11 01:22:25 +00001144 _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + i) );
1145 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
jtgafb833d1999-08-19 00:55:39 +00001146 }
1147 }
1148 /* Restore texture coordinate unit index */
Brian Paulfbd8f211999-11-11 01:22:25 +00001149 _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + coordUnitSave) );
jtgafb833d1999-08-19 00:55:39 +00001150
1151
1152 /* Color */
1153 if (cflag) {
Brian Paulfbd8f211999-11-11 01:22:25 +00001154 _mesa_EnableClientState( GL_COLOR_ARRAY );
1155 glColorPointer( ccomps, ctype, stride,
jtgafb833d1999-08-19 00:55:39 +00001156 (GLubyte*) pointer + coffset );
1157 }
1158 else {
Brian Paulfbd8f211999-11-11 01:22:25 +00001159 _mesa_DisableClientState( GL_COLOR_ARRAY );
jtgafb833d1999-08-19 00:55:39 +00001160 }
1161
1162
1163 /* Normals */
1164 if (nflag) {
Brian Paulfbd8f211999-11-11 01:22:25 +00001165 _mesa_EnableClientState( GL_NORMAL_ARRAY );
1166 glNormalPointer( GL_FLOAT, stride,
jtgafb833d1999-08-19 00:55:39 +00001167 (GLubyte*) pointer + noffset );
1168 }
1169 else {
Brian Paulfbd8f211999-11-11 01:22:25 +00001170 _mesa_DisableClientState( GL_NORMAL_ARRAY );
jtgafb833d1999-08-19 00:55:39 +00001171 }
1172
Brian Paulfbd8f211999-11-11 01:22:25 +00001173 _mesa_EnableClientState( GL_VERTEX_ARRAY );
1174 glVertexPointer( vcomps, GL_FLOAT, stride,
jtgafb833d1999-08-19 00:55:39 +00001175 (GLubyte *) pointer + voffset );
1176}
1177
1178
1179
Brian Paulfbd8f211999-11-11 01:22:25 +00001180void
1181_mesa_DrawRangeElements(GLenum mode, GLuint start,
1182 GLuint end, GLsizei count,
1183 GLenum type, const GLvoid *indices)
jtgafb833d1999-08-19 00:55:39 +00001184{
Brian Paulfbd8f211999-11-11 01:22:25 +00001185 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +00001186
1187 if (end < start) {
1188 gl_error(ctx, GL_INVALID_VALUE, "glDrawRangeElements( end < start )");
1189 return;
1190 }
1191
Brian Pauldf37c6b2000-02-05 02:05:14 +00001192#if 0
1193 /*
1194 * XXX something in locked arrays is broken! If start = 0,
1195 * end = 1 and count = 2 we'll take the LockArrays path and
1196 * get incorrect results. See Scott McMillan's bug of 3 Jan 2000.
1197 * For now, don't use locked arrays.
1198 */
Brian Paul5b37c321999-11-05 06:43:10 +00001199 if (!ctx->Array.LockCount && 2*count > (GLint) 3*(end-start)) {
Brian Paulfbd8f211999-11-11 01:22:25 +00001200 glLockArraysEXT( start, end );
1201 glDrawElements( mode, count, type, indices );
1202 glUnlockArraysEXT();
jtgafb833d1999-08-19 00:55:39 +00001203 } else {
Brian Paulfbd8f211999-11-11 01:22:25 +00001204 glDrawElements( mode, count, type, indices );
jtgafb833d1999-08-19 00:55:39 +00001205 }
Brian Pauldf37c6b2000-02-05 02:05:14 +00001206#else
1207 glDrawElements( mode, count, type, indices );
1208#endif
jtgafb833d1999-08-19 00:55:39 +00001209}
1210
1211
1212
1213void gl_update_client_state( GLcontext *ctx )
1214{
Brian Paulce938b32000-10-18 15:02:59 +00001215 static const GLuint sz_flags[5] = {
1216 0,
1217 0,
1218 VERT_OBJ_2,
1219 VERT_OBJ_23,
1220 VERT_OBJ_234
1221 };
1222 static const GLuint tc_flags[5] = {
1223 0,
1224 VERT_TEX0_1,
1225 VERT_TEX0_12,
1226 VERT_TEX0_123,
1227 VERT_TEX0_1234
1228 };
1229 GLint i;
jtgafb833d1999-08-19 00:55:39 +00001230
1231 ctx->Array.Flags = 0;
1232 ctx->Array.Summary = 0;
1233 ctx->input->ArrayIncr = 0;
1234
1235 if (ctx->Array.Normal.Enabled) ctx->Array.Flags |= VERT_NORM;
1236 if (ctx->Array.Color.Enabled) ctx->Array.Flags |= VERT_RGBA;
1237 if (ctx->Array.Index.Enabled) ctx->Array.Flags |= VERT_INDEX;
1238 if (ctx->Array.EdgeFlag.Enabled) ctx->Array.Flags |= VERT_EDGE;
1239 if (ctx->Array.Vertex.Enabled) {
1240 ctx->Array.Flags |= sz_flags[ctx->Array.Vertex.Size];
1241 ctx->input->ArrayIncr = 1;
1242 }
Brian Paulce938b32000-10-18 15:02:59 +00001243 for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
1244 if (ctx->Array.TexCoord[i].Enabled) {
1245 ctx->Array.Flags |= (tc_flags[ctx->Array.TexCoord[i].Size] << (i * NR_TEXSIZE_BITS));
1246 }
jtgafb833d1999-08-19 00:55:39 +00001247 }
1248
1249 /* Not really important any more:
1250 */
1251 ctx->Array.Summary = ctx->Array.Flags & VERT_DATA;
jtgafb833d1999-08-19 00:55:39 +00001252 ctx->input->ArrayAndFlags = ~ctx->Array.Flags;
1253 ctx->input->ArrayEltFlush = !(ctx->CompileCVAFlag);
1254}
1255