source: trunk/src/opengl/mesa/varray.c@ 3993

Last change on this file since 3993 was 3598, checked in by jeroen, 25 years ago

* empty log message *

File size: 35.7 KB
Line 
1/* $Id: varray.c,v 1.3 2000-05-23 20:40:59 jeroen Exp $ */
2
3/*
4 * Mesa 3-D graphics library
5 * Version: 3.1
6 *
7 * Copyright (C) 1999 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27#ifdef PC_HEADER
28#include "all.h"
29#else
30#include "glheader.h"
31#include "types.h"
32#include "context.h"
33#include "cva.h"
34#include "enable.h"
35#include "enums.h"
36#include "dlist.h"
37#include "light.h"
38#include "macros.h"
39#include "mmath.h"
40#include "pipeline.h"
41#include "texstate.h"
42#include "translate.h"
43#include "varray.h"
44#include "vb.h"
45#include "vbfill.h"
46#include "vbrender.h"
47#include "vbindirect.h"
48#include "vbxform.h"
49#include "xform.h"
50#include "state.h"
51#endif
52
53void
54_mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr )
55{
56 GET_CURRENT_CONTEXT(ctx);
57
58 if (size<2 || size>4) {
59 gl_error( ctx, GL_INVALID_VALUE, "glVertexPointer(size)" );
60 return;
61 }
62 if (stride<0) {
63 gl_error( ctx, GL_INVALID_VALUE, "glVertexPointer(stride)" );
64 return;
65 }
66
67 if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API))
68 fprintf(stderr, "glVertexPointer( sz %d type %s stride %d )\n", size,
69 gl_lookup_enum_by_nr( type ),
70 stride);
71
72 ctx->Array.Vertex.StrideB = stride;
73 if (!stride) {
74 switch (type) {
75 case GL_SHORT:
76 ctx->Array.Vertex.StrideB = size*sizeof(GLshort);
77 break;
78 case GL_INT:
79 ctx->Array.Vertex.StrideB = size*sizeof(GLint);
80 break;
81 case GL_FLOAT:
82 ctx->Array.Vertex.StrideB = size*sizeof(GLfloat);
83 break;
84 case GL_DOUBLE:
85 ctx->Array.Vertex.StrideB = size*sizeof(GLdouble);
86 break;
87 default:
88 gl_error( ctx, GL_INVALID_ENUM, "glVertexPointer(type)" );
89 return;
90 }
91 }
92 ctx->Array.Vertex.Size = size;
93 ctx->Array.Vertex.Type = type;
94 ctx->Array.Vertex.Stride = stride;
95 ctx->Array.Vertex.Ptr = (void *) ptr;
96 ctx->Array.VertexFunc = gl_trans_4f_tab[size][TYPE_IDX(type)];
97 ctx->Array.VertexEltFunc = gl_trans_elt_4f_tab[size][TYPE_IDX(type)];
98 ctx->Array.NewArrayState |= VERT_OBJ_ANY;
99 ctx->NewState |= NEW_CLIENT_STATE;
100}
101
102
103
104
105void
106_mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
107{
108 GET_CURRENT_CONTEXT(ctx);
109
110 if (stride<0) {
111 gl_error( ctx, GL_INVALID_VALUE, "glNormalPointer(stride)" );
112 return;
113 }
114
115 if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API))
116 fprintf(stderr, "glNormalPointer( type %s stride %d )\n",
117 gl_lookup_enum_by_nr( type ),
118 stride);
119
120 ctx->Array.Normal.StrideB = stride;
121 if (!stride) {
122 switch (type) {
123 case GL_BYTE:
124 ctx->Array.Normal.StrideB = 3*sizeof(GLbyte);
125 break;
126 case GL_SHORT:
127 ctx->Array.Normal.StrideB = 3*sizeof(GLshort);
128 break;
129 case GL_INT:
130 ctx->Array.Normal.StrideB = 3*sizeof(GLint);
131 break;
132 case GL_FLOAT:
133 ctx->Array.Normal.StrideB = 3*sizeof(GLfloat);
134 break;
135 case GL_DOUBLE:
136 ctx->Array.Normal.StrideB = 3*sizeof(GLdouble);
137 break;
138 default:
139 gl_error( ctx, GL_INVALID_ENUM, "glNormalPointer(type)" );
140 return;
141 }
142 }
143 ctx->Array.Normal.Type = type;
144 ctx->Array.Normal.Stride = stride;
145 ctx->Array.Normal.Ptr = (void *) ptr;
146 ctx->Array.NormalFunc = gl_trans_3f_tab[TYPE_IDX(type)];
147 ctx->Array.NormalEltFunc = gl_trans_elt_3f_tab[TYPE_IDX(type)];
148 ctx->Array.NewArrayState |= VERT_NORM;
149 ctx->NewState |= NEW_CLIENT_STATE;
150}
151
152
153
154void
155_mesa_ColorPointer(GLint size, GLenum type, GLsizei stride,const GLvoid *ptr )
156{
157 GET_CURRENT_CONTEXT(ctx);
158
159 if (size<3 || size>4) {
160 gl_error( ctx, GL_INVALID_VALUE, "glColorPointer(size)" );
161 return;
162 }
163 if (stride<0) {
164 gl_error( ctx, GL_INVALID_VALUE, "glColorPointer(stride)" );
165 return;
166 }
167
168 if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API))
169 fprintf(stderr, "glColorPointer( sz %d type %s stride %d )\n", size,
170 gl_lookup_enum_by_nr( type ),
171 stride);
172
173 ctx->Array.Color.StrideB = stride;
174 if (!stride) {
175 switch (type) {
176 case GL_BYTE:
177 ctx->Array.Color.StrideB = size*sizeof(GLbyte);
178 break;
179 case GL_UNSIGNED_BYTE:
180 ctx->Array.Color.StrideB = size*sizeof(GLubyte);
181 break;
182 case GL_SHORT:
183 ctx->Array.Color.StrideB = size*sizeof(GLshort);
184 break;
185 case GL_UNSIGNED_SHORT:
186 ctx->Array.Color.StrideB = size*sizeof(GLushort);
187 break;
188 case GL_INT:
189 ctx->Array.Color.StrideB = size*sizeof(GLint);
190 break;
191 case GL_UNSIGNED_INT:
192 ctx->Array.Color.StrideB = size*sizeof(GLuint);
193 break;
194 case GL_FLOAT:
195 ctx->Array.Color.StrideB = size*sizeof(GLfloat);
196 break;
197 case GL_DOUBLE:
198 ctx->Array.Color.StrideB = size*sizeof(GLdouble);
199 break;
200 default:
201 gl_error( ctx, GL_INVALID_ENUM, "glColorPointer(type)" );
202 return;
203 }
204 }
205 ctx->Array.Color.Size = size;
206 ctx->Array.Color.Type = type;
207 ctx->Array.Color.Stride = stride;
208 ctx->Array.Color.Ptr = (void *) ptr;
209 ctx->Array.ColorFunc = gl_trans_4ub_tab[size][TYPE_IDX(type)];
210 ctx->Array.ColorEltFunc = gl_trans_elt_4ub_tab[size][TYPE_IDX(type)];
211 ctx->Array.NewArrayState |= VERT_RGBA;
212 ctx->NewState |= NEW_CLIENT_STATE;
213}
214
215
216
217void
218_mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
219{
220 GET_CURRENT_CONTEXT(ctx);
221
222 if (stride<0) {
223 gl_error( ctx, GL_INVALID_VALUE, "glIndexPointer(stride)" );
224 return;
225 }
226
227 ctx->Array.Index.StrideB = stride;
228 if (!stride) {
229 switch (type) {
230 case GL_UNSIGNED_BYTE:
231 ctx->Array.Index.StrideB = sizeof(GLubyte);
232 break;
233 case GL_SHORT:
234 ctx->Array.Index.StrideB = sizeof(GLshort);
235 break;
236 case GL_INT:
237 ctx->Array.Index.StrideB = sizeof(GLint);
238 break;
239 case GL_FLOAT:
240 ctx->Array.Index.StrideB = sizeof(GLfloat);
241 break;
242 case GL_DOUBLE:
243 ctx->Array.Index.StrideB = sizeof(GLdouble);
244 break;
245 default:
246 gl_error( ctx, GL_INVALID_ENUM, "glIndexPointer(type)" );
247 return;
248 }
249 }
250 ctx->Array.Index.Type = type;
251 ctx->Array.Index.Stride = stride;
252 ctx->Array.Index.Ptr = (void *) ptr;
253 ctx->Array.IndexFunc = gl_trans_1ui_tab[TYPE_IDX(type)];
254 ctx->Array.IndexEltFunc = gl_trans_elt_1ui_tab[TYPE_IDX(type)];
255 ctx->Array.NewArrayState |= VERT_INDEX;
256 ctx->NewState |= NEW_CLIENT_STATE;
257}
258
259
260
261void
262_mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr )
263{
264 GET_CURRENT_CONTEXT(ctx);
265 GLuint texUnit;
266
267 texUnit = ctx->Array.ActiveTexture;
268
269 if (size<1 || size>4) {
270 gl_error( ctx, GL_INVALID_VALUE, "glTexCoordPointer(size)" );
271 return;
272 }
273 if (stride<0) {
274 gl_error( ctx, GL_INVALID_VALUE, "glTexCoordPointer(stride)" );
275 return;
276 }
277
278 if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API))
279 fprintf(stderr, "glTexCoordPointer( unit %u sz %d type %s stride %d )\n",
280 texUnit,
281 size,
282 gl_lookup_enum_by_nr( type ),
283 stride);
284
285 ctx->Array.TexCoord[texUnit].StrideB = stride;
286 if (!stride) {
287 switch (type) {
288 case GL_SHORT:
289 ctx->Array.TexCoord[texUnit].StrideB = size*sizeof(GLshort);
290 break;
291 case GL_INT:
292 ctx->Array.TexCoord[texUnit].StrideB = size*sizeof(GLint);
293 break;
294 case GL_FLOAT:
295 ctx->Array.TexCoord[texUnit].StrideB = size*sizeof(GLfloat);
296 break;
297 case GL_DOUBLE:
298 ctx->Array.TexCoord[texUnit].StrideB = size*sizeof(GLdouble);
299 break;
300 default:
301 gl_error( ctx, GL_INVALID_ENUM, "glTexCoordPointer(type)" );
302 return;
303 }
304 }
305 ctx->Array.TexCoord[texUnit].Size = size;
306 ctx->Array.TexCoord[texUnit].Type = type;
307 ctx->Array.TexCoord[texUnit].Stride = stride;
308 ctx->Array.TexCoord[texUnit].Ptr = (void *) ptr;
309
310 ctx->Array.TexCoordFunc[texUnit] = gl_trans_4f_tab[size][TYPE_IDX(type)];
311 ctx->Array.TexCoordEltFunc[texUnit] = gl_trans_elt_4f_tab[size][TYPE_IDX(type)];
312 ctx->Array.NewArrayState |= PIPE_TEX(texUnit);
313 ctx->NewState |= NEW_CLIENT_STATE;
314}
315
316
317
318
319void
320_mesa_EdgeFlagPointer(GLsizei stride, const void *vptr )
321{
322 GET_CURRENT_CONTEXT(ctx);
323 const GLboolean *ptr = (GLboolean *)vptr;
324
325 if (stride<0) {
326 gl_error( ctx, GL_INVALID_VALUE, "glEdgeFlagPointer(stride)" );
327 return;
328 }
329 ctx->Array.EdgeFlag.Stride = stride;
330 ctx->Array.EdgeFlag.StrideB = stride ? stride : sizeof(GLboolean);
331 ctx->Array.EdgeFlag.Ptr = (GLboolean *) ptr;
332 if (stride != sizeof(GLboolean)) {
333 ctx->Array.EdgeFlagFunc = gl_trans_1ub_tab[TYPE_IDX(GL_UNSIGNED_BYTE)];
334 } else {
335 ctx->Array.EdgeFlagFunc = 0;
336 }
337 ctx->Array.EdgeFlagEltFunc = gl_trans_elt_1ub_tab[TYPE_IDX(GL_UNSIGNED_BYTE)];
338 ctx->Array.NewArrayState |= VERT_EDGE;
339 ctx->NewState |= NEW_CLIENT_STATE;
340}
341
342#if 0
343/* Called only from gl_DrawElements
344 */
345static void gl_CVAEltPointer( GLcontext *ctx, GLenum type, const GLvoid *ptr )
346{
347 switch (type) {
348 case GL_UNSIGNED_BYTE:
349 ctx->CVA.Elt.StrideB = sizeof(GLubyte);
350 break;
351 case GL_UNSIGNED_SHORT:
352 ctx->CVA.Elt.StrideB = sizeof(GLushort);
353 break;
354 case GL_UNSIGNED_INT:
355 ctx->CVA.Elt.StrideB = sizeof(GLuint);
356 break;
357 default:
358 gl_error( ctx, GL_INVALID_ENUM, "glEltPointer(type)" );
359 return;
360 }
361 ctx->CVA.Elt.Type = type;
362 ctx->CVA.Elt.Stride = 0;
363 ctx->CVA.Elt.Ptr = (void *) ptr;
364 ctx->CVA.EltFunc = gl_trans_1ui_tab[TYPE_IDX(type)];
365 ctx->Array.NewArrayState |= VERT_ELT; /* ???*/
366}
367#endif
368
369
370/* KW: Batch function to exec all the array elements in the input
371 * buffer prior to transform. Done only the first time a vertex
372 * buffer is executed or compiled.
373 *
374 * KW: Have to do this after each glEnd if cva isn't active. (also
375 * have to do it after each full buffer)
376 */
377void gl_exec_array_elements( GLcontext *ctx, struct immediate *IM,
378 GLuint start,
379 GLuint count)
380{
381 GLuint *flags = IM->Flag;
382 GLuint *elts = IM->Elt;
383 GLuint translate = ctx->Array.Flags;
384 GLuint i;
385
386 if (MESA_VERBOSE&VERBOSE_IMMEDIATE)
387 fprintf(stderr, "exec_array_elements %d .. %d\n", start, count);
388
389 if (translate & VERT_OBJ_ANY)
390 (ctx->Array.VertexEltFunc)( IM->Obj,
391 &ctx->Array.Vertex,
392 flags, elts, (VERT_ELT|VERT_OBJ_ANY),
393 start, count);
394
395 if (translate & VERT_NORM)
396 (ctx->Array.NormalEltFunc)( IM->Normal,
397 &ctx->Array.Normal,
398 flags, elts, (VERT_ELT|VERT_NORM),
399 start, count);
400
401 if (translate & VERT_EDGE)
402 (ctx->Array.EdgeFlagEltFunc)( IM->EdgeFlag,
403 &ctx->Array.EdgeFlag,
404 flags, elts, (VERT_ELT|VERT_EDGE),
405 start, count);
406
407 if (translate & VERT_RGBA)
408 (ctx->Array.ColorEltFunc)( IM->Color,
409 &ctx->Array.Color,
410 flags, elts, (VERT_ELT|VERT_RGBA),
411 start, count);
412
413 if (translate & VERT_INDEX)
414 (ctx->Array.IndexEltFunc)( IM->Index,
415 &ctx->Array.Index,
416 flags, elts, (VERT_ELT|VERT_INDEX),
417 start, count);
418
419 if (translate & VERT_TEX0_ANY)
420 (ctx->Array.TexCoordEltFunc[0])( IM->TexCoord[0],
421 &ctx->Array.TexCoord[0],
422 flags, elts, (VERT_ELT|VERT_TEX0_ANY),
423 start, count);
424
425 if (translate & VERT_TEX1_ANY)
426 (ctx->Array.TexCoordEltFunc[1])( IM->TexCoord[1],
427 &ctx->Array.TexCoord[1],
428 flags, elts, (VERT_ELT|VERT_TEX1_ANY),
429 start, count);
430
431
432 for (i = start ; i < count ; i++)
433 if (flags[i] & VERT_ELT)
434 flags[i] |= translate;
435
436}
437
438
439
440/* Enough funny business going on in here it might be quicker to use a
441 * function pointer.
442 */
443#define ARRAY_ELT( IM, i ) \
444{ \
445 GLuint count = IM->Count; \
446 IM->Elt[count] = i; \
447 IM->Flag[count] = ((IM->Flag[count] & IM->ArrayAndFlags) | \
448 VERT_ELT); \
449 IM->FlushElt |= IM->ArrayEltFlush; \
450 IM->Count = count += IM->ArrayIncr; \
451 if (count == VB_MAX) \
452 IM->maybe_transform_vb( IM ); \
453}
454
455
456void
457_mesa_ArrayElement( GLint i )
458{
459 GET_IMMEDIATE;
460 ARRAY_ELT( IM, i );
461}
462
463
464static void
465gl_ArrayElement( GLcontext *CC, GLint i )
466{
467 struct immediate *im = CC->input;
468 ARRAY_ELT( im, i );
469}
470
471
472
473void
474_mesa_DrawArrays(GLenum mode, GLint start, GLsizei count)
475{
476 GET_CURRENT_CONTEXT(ctx);
477 struct vertex_buffer *VB = ctx->VB;
478 GLint i;
479
480 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glDrawArrays");
481
482 if (count<0) {
483 gl_error( ctx, GL_INVALID_VALUE, "glDrawArrays(count)" );
484 return;
485 }
486
487 if (!ctx->CompileFlag && ctx->Array.Vertex.Enabled)
488 {
489 GLint remaining = count;
490 GLint i;
491 struct gl_client_array *Normal;
492 struct gl_client_array *Color;
493 struct gl_client_array *Index;
494 struct gl_client_array *TexCoord[MAX_TEXTURE_UNITS];
495 struct gl_client_array *EdgeFlag;
496 struct immediate *IM = VB->IM;
497 struct gl_pipeline *elt = &ctx->CVA.elt;
498 GLboolean relock;
499 GLuint fallback, required;
500
501 if (ctx->NewState)
502 gl_update_state( ctx );
503
504 /* Just turn off cva on this path. Could be useful for multipass
505 * rendering to keep it turned on.
506 */
507 relock = ctx->CompileCVAFlag;
508
509 if (relock) {
510 ctx->CompileCVAFlag = 0;
511 elt->pipeline_valid = 0;
512 }
513
514 if (!elt->pipeline_valid)
515 gl_build_immediate_pipeline( ctx );
516
517 required = elt->inputs;
518 fallback = (elt->inputs & ~ctx->Array.Summary);
519
520 /* The translate function doesn't do anything about size. It
521 * just ensures that type and stride come out right.
522 */
523 IM->v.Obj.size = ctx->Array.Vertex.Size;
524
525 if (required & VERT_RGBA)
526 {
527 Color = &ctx->Array.Color;
528 if (fallback & VERT_RGBA) {
529 Color = &ctx->Fallback.Color;
530 ctx->Array.ColorFunc =
531 gl_trans_4ub_tab[4][TYPE_IDX(GL_UNSIGNED_BYTE)];
532 }
533 }
534
535 if (required & VERT_INDEX)
536 {
537 Index = &ctx->Array.Index;
538 if (fallback & VERT_INDEX) {
539 Index = &ctx->Fallback.Index;
540 ctx->Array.IndexFunc = gl_trans_1ui_tab[TYPE_IDX(GL_UNSIGNED_INT)];
541 }
542 }
543
544 for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++)
545 {
546 GLuint flag = VERT_TEX_ANY(i);
547
548 if (required & flag) {
549 TexCoord[i] = &ctx->Array.TexCoord[i];
550
551 if (fallback & flag)
552 {
553 TexCoord[i] = &ctx->Fallback.TexCoord[i];
554 TexCoord[i]->Size = gl_texcoord_size( ctx->Current.Flag, i );
555
556 ctx->Array.TexCoordFunc[i] =
557 gl_trans_4f_tab[TexCoord[i]->Size][TYPE_IDX(GL_FLOAT)];
558 }
559 }
560 }
561
562 if (ctx->Array.Flags != ctx->Array.Flag[0])
563 for (i = 0 ; i < VB_MAX ; i++)
564 ctx->Array.Flag[i] = ctx->Array.Flags;
565
566
567 if (required & VERT_NORM)
568 {
569 Normal = &ctx->Array.Normal;
570 if (fallback & VERT_NORM) {
571 Normal = &ctx->Fallback.Normal;
572 ctx->Array.NormalFunc = gl_trans_3f_tab[TYPE_IDX(GL_FLOAT)];
573 }
574 }
575
576 if ( required & VERT_EDGE )
577 {
578 if (mode == GL_TRIANGLES ||
579 mode == GL_QUADS ||
580 mode == GL_POLYGON)
581 {
582 EdgeFlag = &ctx->Array.EdgeFlag;
583 if (fallback & VERT_EDGE) {
584 EdgeFlag = &ctx->Fallback.EdgeFlag;
585 ctx->Array.EdgeFlagFunc =
586 gl_trans_1ub_tab[TYPE_IDX(GL_UNSIGNED_BYTE)];
587 }
588 }
589 else
590 required &= ~VERT_EDGE;
591 }
592
593 VB->Primitive = IM->Primitive;
594 VB->NextPrimitive = IM->NextPrimitive;
595 VB->MaterialMask = IM->MaterialMask;
596 VB->Material = IM->Material;
597 VB->BoundsPtr = 0;
598
599 while (remaining > 0) {
600 GLint vbspace = VB_MAX - VB_START;
601 GLuint count, n;
602
603 if (vbspace >= remaining) {
604 n = remaining;
605 VB->LastPrimitive = VB_START + n;
606 } else {
607 n = vbspace;
608 VB->LastPrimitive = VB_START;
609 }
610
611 VB->CullMode = 0;
612
613 ctx->Array.VertexFunc( IM->Obj + VB_START,
614 &ctx->Array.Vertex, start, n );
615
616 if (required & VERT_NORM) {
617 ctx->Array.NormalFunc( IM->Normal + VB_START,
618 Normal, start, n );
619 }
620
621 if (required & VERT_EDGE) {
622 ctx->Array.EdgeFlagFunc( IM->EdgeFlag + VB_START,
623 EdgeFlag, start, n );
624 }
625
626 if (required & VERT_RGBA) {
627 ctx->Array.ColorFunc( IM->Color + VB_START,
628 Color, start, n );
629 }
630
631 if (required & VERT_INDEX) {
632 ctx->Array.IndexFunc( IM->Index + VB_START,
633 Index, start, n );
634 }
635
636 if (required & VERT_TEX0_ANY) {
637 IM->v.TexCoord[0].size = TexCoord[0]->Size;
638 ctx->Array.TexCoordFunc[0]( IM->TexCoord[0] + VB_START,
639 TexCoord[0], start, n );
640 }
641
642 if (required & VERT_TEX1_ANY) {
643 IM->v.TexCoord[1].size = TexCoord[1]->Size;
644 ctx->Array.TexCoordFunc[1]( IM->TexCoord[1] + VB_START,
645 TexCoord[1], start, n );
646 }
647
648 VB->ObjPtr = &IM->v.Obj;
649 VB->NormalPtr = &IM->v.Normal;
650 VB->ColorPtr = &IM->v.Color;
651 VB->Color[0] = VB->Color[1] = VB->ColorPtr;
652 VB->IndexPtr = &IM->v.Index;
653 VB->EdgeFlagPtr = &IM->v.EdgeFlag;
654 VB->TexCoordPtr[0] = &IM->v.TexCoord[0];
655 VB->TexCoordPtr[1] = &IM->v.TexCoord[1];
656
657 VB->Flag = ctx->Array.Flag;
658 VB->OrFlag = ctx->Array.Flags;
659
660 VB->Start = IM->Start = VB_START;
661 count = VB->Count = IM->Count = VB_START + n;
662
663#define RESET_VEC(v, t, s, c) (v.start = t v.data[s], v.count = c)
664
665 RESET_VEC(IM->v.Obj, (GLfloat *), VB_START, count);
666 RESET_VEC(IM->v.Normal, (GLfloat *), VB_START, count);
667 RESET_VEC(IM->v.TexCoord[0], (GLfloat *), VB_START, count);
668 RESET_VEC(IM->v.TexCoord[1], (GLfloat *), VB_START, count);
669 RESET_VEC(IM->v.Index, &, VB_START, count);
670 RESET_VEC(IM->v.Elt, &, VB_START, count);
671 RESET_VEC(IM->v.EdgeFlag, &, VB_START, count);
672 RESET_VEC(IM->v.Color, (GLubyte *), VB_START, count);
673 RESET_VEC(VB->Clip, (GLfloat *), VB_START, count);
674 RESET_VEC(VB->Eye, (GLfloat *), VB_START, count);
675 RESET_VEC(VB->Win, (GLfloat *), VB_START, count);
676 RESET_VEC(VB->BColor, (GLubyte *), VB_START, count);
677 RESET_VEC(VB->BIndex, &, VB_START, count);
678
679 VB->NextPrimitive[VB->CopyStart] = VB->Count;
680 VB->Primitive[VB->CopyStart] = mode;
681 ctx->Array.Flag[count] |= VERT_END_VB;
682
683 /* Transform and render.
684 */
685 gl_run_pipeline( VB );
686 gl_reset_vb( VB );
687
688 ctx->Array.Flag[count] = ctx->Array.Flags;
689 ctx->Array.Flag[VB_START] = ctx->Array.Flags;
690
691 start += n;
692 remaining -= n;
693 }
694
695 gl_reset_input( ctx );
696
697 if (relock) {
698 ctx->CompileCVAFlag = relock;
699 elt->pipeline_valid = 0;
700 }
701 }
702 else if (ctx->Array.Vertex.Enabled)
703 {
704 /* The GL_COMPILE and GL_COMPILE_AND_EXECUTE cases. These
705 * could be handled by the above code, but it gets a little
706 * complex. The generated list is still of good quality
707 * this way.
708 */
709 gl_Begin( ctx, mode );
710 for (i=0;i<count;i++) {
711 gl_ArrayElement( ctx, start+i );
712 }
713 gl_End( ctx );
714 }
715 else
716 {
717 /* The degenerate case where vertices are not enabled - only
718 * need to process the very final array element, as all of the
719 * preceding ones would be overwritten anyway.
720 */
721 gl_Begin( ctx, mode );
722 gl_ArrayElement( ctx, start+count );
723 gl_End( ctx );
724 }
725}
726
727
728
729/* KW: Exactly fakes the effects of calling glArrayElement multiple times.
730 * Compilation is handled via. the IM->maybe_transform_vb() callback.
731 */
732#if 1
733#define DRAW_ELT(FUNC, TYPE) \
734static void FUNC( GLcontext *ctx, GLenum mode, \
735 TYPE *indices, GLuint count ) \
736{ \
737 GLuint i,j; \
738 \
739 gl_Begin( ctx, mode ); \
740 \
741 for (j = 0 ; j < count ; ) { \
742 struct immediate *IM = ctx->input; \
743 GLuint start = IM->Start; \
744 GLuint nr = MIN2( VB_MAX, count - j + start ); \
745 GLuint sf = IM->Flag[start]; \
746 IM->FlushElt |= IM->ArrayEltFlush; \
747 \
748 for (i = start ; i < nr ; i++) { \
749 IM->Elt[i] = (GLuint) *indices++; \
750 IM->Flag[i] = VERT_ELT; \
751 } \
752 \
753 if (j == 0) IM->Flag[start] |= sf; \
754 \
755 IM->Count = nr; \
756 j += nr - start; \
757 \
758 if (j == count) gl_End( ctx ); \
759 IM->maybe_transform_vb( IM ); \
760 } \
761}
762#else
763#define DRAW_ELT(FUNC, TYPE) \
764static void FUNC( GLcontext *ctx, GLenum mode, \
765 TYPE *indices, GLuint count ) \
766{ \
767 int i; \
768 glBegin(mode); \
769 for (i = 0 ; i < count ; i++) \
770 glArrayElement( indices[i] ); \
771 glEnd(); \
772}
773#endif
774
775
776DRAW_ELT( draw_elt_ubyte, GLubyte )
777DRAW_ELT( draw_elt_ushort, GLushort )
778DRAW_ELT( draw_elt_uint, GLuint )
779
780
781static GLuint natural_stride[0x10] =
782{
783 sizeof(GLbyte), /* 0 */
784 sizeof(GLubyte), /* 1 */
785 sizeof(GLshort), /* 2 */
786 sizeof(GLushort), /* 3 */
787 sizeof(GLint), /* 4 */
788 sizeof(GLuint), /* 5 */
789 sizeof(GLfloat), /* 6 */
790 2 * sizeof(GLbyte), /* 7 */
791 3 * sizeof(GLbyte), /* 8 */
792 4 * sizeof(GLbyte), /* 9 */
793 sizeof(GLdouble), /* a */
794 0, /* b */
795 0, /* c */
796 0, /* d */
797 0, /* e */
798 0 /* f */
799};
800
801
802void
803_mesa_DrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices )
804{
805 GET_CURRENT_CONTEXT(ctx);
806 struct gl_cva *cva;
807
808 cva = &ctx->CVA;
809 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glDrawElements");
810
811 if (count <= 0) {
812 if (count < 0)
813 gl_error( ctx, GL_INVALID_VALUE, "glDrawElements(count)" );
814 return;
815 }
816
817 if (mode < 0 || mode > GL_POLYGON) {
818 gl_error( ctx, GL_INVALID_ENUM, "glDrawArrays(mode)" );
819 return;
820 }
821
822 if (type != GL_UNSIGNED_INT && type != GL_UNSIGNED_BYTE && type != GL_UNSIGNED_SHORT)
823 {
824 gl_error( ctx, GL_INVALID_ENUM, "glDrawElements(type)" );
825 return;
826 }
827
828 if (ctx->NewState)
829 gl_update_state(ctx);
830
831 if (ctx->CompileCVAFlag)
832 {
833#if defined(MESA_CVA_PROF)
834 force_init_prof();
835#endif
836
837 /* Treat VERT_ELT like a special client array.
838 */
839 ctx->Array.NewArrayState |= VERT_ELT;
840 ctx->Array.Summary |= VERT_ELT;
841 ctx->Array.Flags |= VERT_ELT;
842
843 cva->elt_mode = mode;
844 cva->elt_count = count;
845 cva->Elt.Type = type;
846 cva->Elt.Ptr = (void *) indices;
847 cva->Elt.StrideB = natural_stride[TYPE_IDX(type)];
848 cva->EltFunc = gl_trans_1ui_tab[TYPE_IDX(type)];
849
850 if (!cva->pre.pipeline_valid)
851 gl_build_precalc_pipeline( ctx );
852 else if (MESA_VERBOSE & VERBOSE_PIPELINE)
853 fprintf(stderr, ": dont rebuild\n");
854
855 gl_cva_force_precalc( ctx );
856
857 /* Did we 'precalculate' the render op?
858 */
859 if (ctx->CVA.pre.ops & PIPE_OP_RENDER) {
860 ctx->Array.NewArrayState |= VERT_ELT;
861 ctx->Array.Summary &= ~VERT_ELT;
862 ctx->Array.Flags &= ~VERT_ELT;
863 return;
864 }
865
866 if ( (MESA_VERBOSE&VERBOSE_VARRAY) )
867 printf("using immediate\n");
868 }
869
870
871 /* Otherwise, have to use the immediate path to render.
872 */
873 switch (type) {
874 case GL_UNSIGNED_BYTE:
875 {
876 GLubyte *ub_indices = (GLubyte *) indices;
877 if (ctx->Array.Summary & VERT_OBJ_ANY) {
878 draw_elt_ubyte( ctx, mode, ub_indices, count );
879 } else {
880 gl_ArrayElement( ctx, (GLuint) ub_indices[count-1] );
881 }
882 }
883 break;
884 case GL_UNSIGNED_SHORT:
885 {
886 GLushort *us_indices = (GLushort *) indices;
887 if (ctx->Array.Summary & VERT_OBJ_ANY) {
888 draw_elt_ushort( ctx, mode, us_indices, count );
889 } else {
890 gl_ArrayElement( ctx, (GLuint) us_indices[count-1] );
891 }
892 }
893 break;
894 case GL_UNSIGNED_INT:
895 {
896 GLuint *ui_indices = (GLuint *) indices;
897 if (ctx->Array.Summary & VERT_OBJ_ANY) {
898 draw_elt_uint( ctx, mode, ui_indices, count );
899 } else {
900 gl_ArrayElement( ctx, ui_indices[count-1] );
901 }
902 }
903 break;
904 default:
905 gl_error( ctx, GL_INVALID_ENUM, "glDrawElements(type)" );
906 break;
907 }
908
909 if (ctx->CompileCVAFlag) {
910 ctx->Array.NewArrayState |= VERT_ELT;
911 ctx->Array.Summary &= ~VERT_ELT;
912 }
913}
914
915
916
917void
918_mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer )
919{
920 GET_CURRENT_CONTEXT(ctx);
921 GLboolean tflag, cflag, nflag; /* enable/disable flags */
922 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
923
924 GLenum ctype; /* color type */
925 GLint coffset, noffset, voffset;/* color, normal, vertex offsets */
926 GLint defstride; /* default stride */
927 GLint c, f;
928 GLint coordUnitSave;
929
930 f = sizeof(GLfloat);
931 c = f * ((4*sizeof(GLubyte) + (f-1)) / f);
932
933 if (stride<0) {
934 gl_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
935 return;
936 }
937
938 switch (format) {
939 case GL_V2F:
940 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
941 tcomps = 0; ccomps = 0; vcomps = 2;
942 voffset = 0;
943 defstride = 2*f;
944 break;
945 case GL_V3F:
946 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
947 tcomps = 0; ccomps = 0; vcomps = 3;
948 voffset = 0;
949 defstride = 3*f;
950 break;
951 case GL_C4UB_V2F:
952 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
953 tcomps = 0; ccomps = 4; vcomps = 2;
954 ctype = GL_UNSIGNED_BYTE;
955 coffset = 0;
956 voffset = c;
957 defstride = c + 2*f;
958 break;
959 case GL_C4UB_V3F:
960 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
961 tcomps = 0; ccomps = 4; vcomps = 3;
962 ctype = GL_UNSIGNED_BYTE;
963 coffset = 0;
964 voffset = c;
965 defstride = c + 3*f;
966 break;
967 case GL_C3F_V3F:
968 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
969 tcomps = 0; ccomps = 3; vcomps = 3;
970 ctype = GL_FLOAT;
971 coffset = 0;
972 voffset = 3*f;
973 defstride = 6*f;
974 break;
975 case GL_N3F_V3F:
976 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
977 tcomps = 0; ccomps = 0; vcomps = 3;
978 noffset = 0;
979 voffset = 3*f;
980 defstride = 6*f;
981 break;
982 case GL_C4F_N3F_V3F:
983 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
984 tcomps = 0; ccomps = 4; vcomps = 3;
985 ctype = GL_FLOAT;
986 coffset = 0;
987 noffset = 4*f;
988 voffset = 7*f;
989 defstride = 10*f;
990 break;
991 case GL_T2F_V3F:
992 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
993 tcomps = 2; ccomps = 0; vcomps = 3;
994 voffset = 2*f;
995 defstride = 5*f;
996 break;
997 case GL_T4F_V4F:
998 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
999 tcomps = 4; ccomps = 0; vcomps = 4;
1000 voffset = 4*f;
1001 defstride = 8*f;
1002 break;
1003 case GL_T2F_C4UB_V3F:
1004 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1005 tcomps = 2; ccomps = 4; vcomps = 3;
1006 ctype = GL_UNSIGNED_BYTE;
1007 coffset = 2*f;
1008 voffset = c+2*f;
1009 defstride = c+5*f;
1010 break;
1011 case GL_T2F_C3F_V3F:
1012 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1013 tcomps = 2; ccomps = 3; vcomps = 3;
1014 ctype = GL_FLOAT;
1015 coffset = 2*f;
1016 voffset = 5*f;
1017 defstride = 8*f;
1018 break;
1019 case GL_T2F_N3F_V3F:
1020 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
1021 tcomps = 2; ccomps = 0; vcomps = 3;
1022 noffset = 2*f;
1023 voffset = 5*f;
1024 defstride = 8*f;
1025 break;
1026 case GL_T2F_C4F_N3F_V3F:
1027 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1028 tcomps = 2; ccomps = 4; vcomps = 3;
1029 ctype = GL_FLOAT;
1030 coffset = 2*f;
1031 noffset = 6*f;
1032 voffset = 9*f;
1033 defstride = 12*f;
1034 break;
1035 case GL_T4F_C4F_N3F_V4F:
1036 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1037 tcomps = 4; ccomps = 4; vcomps = 4;
1038 ctype = GL_FLOAT;
1039 coffset = 4*f;
1040 noffset = 8*f;
1041 voffset = 11*f;
1042 defstride = 15*f;
1043 break;
1044 default:
1045 gl_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
1046 return;
1047 }
1048
1049 if (stride==0) {
1050 stride = defstride;
1051 }
1052
1053 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
1054 _mesa_DisableClientState( GL_INDEX_ARRAY );
1055
1056 /* Texcoords */
1057 coordUnitSave = ctx->Array.ActiveTexture;
1058 if (tflag) {
1059 GLint i;
1060 GLint factor = ctx->Array.TexCoordInterleaveFactor;
1061 for (i = 0; i < factor; i++) {
1062 _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + i) );
1063 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
1064 glTexCoordPointer( tcomps, GL_FLOAT, stride,
1065 (GLubyte *) pointer + i * coffset );
1066 }
1067 for (i = factor; i < ctx->Const.MaxTextureUnits; i++) {
1068 _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + i) );
1069 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
1070 }
1071 }
1072 else {
1073 GLint i;
1074 for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
1075 _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + i) );
1076 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
1077 }
1078 }
1079 /* Restore texture coordinate unit index */
1080 _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + coordUnitSave) );
1081
1082
1083 /* Color */
1084 if (cflag) {
1085 _mesa_EnableClientState( GL_COLOR_ARRAY );
1086 glColorPointer( ccomps, ctype, stride,
1087 (GLubyte*) pointer + coffset );
1088 }
1089 else {
1090 _mesa_DisableClientState( GL_COLOR_ARRAY );
1091 }
1092
1093
1094 /* Normals */
1095 if (nflag) {
1096 _mesa_EnableClientState( GL_NORMAL_ARRAY );
1097 glNormalPointer( GL_FLOAT, stride,
1098 (GLubyte*) pointer + noffset );
1099 }
1100 else {
1101 _mesa_DisableClientState( GL_NORMAL_ARRAY );
1102 }
1103
1104 _mesa_EnableClientState( GL_VERTEX_ARRAY );
1105 glVertexPointer( vcomps, GL_FLOAT, stride,
1106 (GLubyte *) pointer + voffset );
1107}
1108
1109
1110
1111void
1112_mesa_DrawRangeElements(GLenum mode, GLuint start,
1113 GLuint end, GLsizei count,
1114 GLenum type, const GLvoid *indices)
1115{
1116 GET_CURRENT_CONTEXT(ctx);
1117
1118 if (end < start) {
1119 gl_error(ctx, GL_INVALID_VALUE, "glDrawRangeElements( end < start )");
1120 return;
1121 }
1122
1123#if 0
1124 /*
1125 * XXX something in locked arrays is broken! If start = 0,
1126 * end = 1 and count = 2 we'll take the LockArrays path and
1127 * get incorrect results. See Scott McMillan's bug of 3 Jan 2000.
1128 * For now, don't use locked arrays.
1129 */
1130 if (!ctx->Array.LockCount && 2*count > (GLint) 3*(end-start)) {
1131 glLockArraysEXT( start, end );
1132 glDrawElements( mode, count, type, indices );
1133 glUnlockArraysEXT();
1134 } else {
1135 glDrawElements( mode, count, type, indices );
1136 }
1137#else
1138 glDrawElements( mode, count, type, indices );
1139#endif
1140}
1141
1142
1143
1144void gl_update_client_state( GLcontext *ctx )
1145{
1146 static GLuint sz_flags[5] = { 0,
1147 0,
1148 VERT_OBJ_2,
1149 VERT_OBJ_23,
1150 VERT_OBJ_234 };
1151
1152 static GLuint tc_flags[5] = { 0,
1153 VERT_TEX0_1,
1154 VERT_TEX0_12,
1155 VERT_TEX0_123,
1156 VERT_TEX0_1234 };
1157
1158 ctx->Array.Flags = 0;
1159 ctx->Array.Summary = 0;
1160 ctx->input->ArrayIncr = 0;
1161
1162 if (ctx->Array.Normal.Enabled) ctx->Array.Flags |= VERT_NORM;
1163 if (ctx->Array.Color.Enabled) ctx->Array.Flags |= VERT_RGBA;
1164 if (ctx->Array.Index.Enabled) ctx->Array.Flags |= VERT_INDEX;
1165 if (ctx->Array.EdgeFlag.Enabled) ctx->Array.Flags |= VERT_EDGE;
1166 if (ctx->Array.Vertex.Enabled) {
1167 ctx->Array.Flags |= sz_flags[ctx->Array.Vertex.Size];
1168 ctx->input->ArrayIncr = 1;
1169 }
1170 if (ctx->Array.TexCoord[0].Enabled) {
1171 ctx->Array.Flags |= tc_flags[ctx->Array.TexCoord[0].Size];
1172 }
1173 if (ctx->Array.TexCoord[1].Enabled) {
1174 ctx->Array.Flags |= (tc_flags[ctx->Array.TexCoord[1].Size] << NR_TEXSIZE_BITS);
1175 }
1176
1177 /* Not really important any more:
1178 */
1179 ctx->Array.Summary = ctx->Array.Flags & VERT_DATA;
1180 ctx->input->ArrayAndFlags = ~ctx->Array.Flags;
1181 ctx->input->ArrayEltFlush = !(ctx->CompileCVAFlag);
1182}
1183
Note: See TracBrowser for help on using the repository browser.