OSDN Git Service

Merge branch 'mesa_7_5_branch'
[android-x86/external-mesa.git] / src / mesa / vbo / vbo_exec_array.c
1 /**************************************************************************
2  * 
3  * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4  * Copyright 2009 VMware, Inc.
5  * All Rights Reserved.
6  * 
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sub license, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  * 
15  * The above copyright notice and this permission notice (including the
16  * next paragraph) shall be included in all copies or substantial portions
17  * 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
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  * 
27  **************************************************************************/
28
29 #include "main/glheader.h"
30 #include "main/context.h"
31 #include "main/state.h"
32 #include "main/api_validate.h"
33 #include "main/api_noop.h"
34 #include "main/varray.h"
35 #include "main/bufferobj.h"
36 #include "glapi/dispatch.h"
37
38 #include "vbo_context.h"
39
40
41 /**
42  * Compute min and max elements for glDraw[Range]Elements() calls.
43  */
44 static void
45 get_minmax_index(GLuint count, GLuint type, const GLvoid *indices,
46                  GLuint *min_index, GLuint *max_index)
47 {
48    GLuint i;
49
50    switch(type) {
51    case GL_UNSIGNED_INT: {
52       const GLuint *ui_indices = (const GLuint *)indices;
53       GLuint max_ui = ui_indices[count-1];
54       GLuint min_ui = ui_indices[0];
55       for (i = 0; i < count; i++) {
56          if (ui_indices[i] > max_ui) max_ui = ui_indices[i];
57          if (ui_indices[i] < min_ui) min_ui = ui_indices[i];
58       }
59       *min_index = min_ui;
60       *max_index = max_ui;
61       break;
62    }
63    case GL_UNSIGNED_SHORT: {
64       const GLushort *us_indices = (const GLushort *)indices;
65       GLuint max_us = us_indices[count-1];
66       GLuint min_us = us_indices[0];
67       for (i = 0; i < count; i++) {
68          if (us_indices[i] > max_us) max_us = us_indices[i];
69          if (us_indices[i] < min_us) min_us = us_indices[i];
70       }
71       *min_index = min_us;
72       *max_index = max_us;
73       break;
74    }
75    case GL_UNSIGNED_BYTE: {
76       const GLubyte *ub_indices = (const GLubyte *)indices;
77       GLuint max_ub = ub_indices[count-1];
78       GLuint min_ub = ub_indices[0];
79       for (i = 0; i < count; i++) {
80          if (ub_indices[i] > max_ub) max_ub = ub_indices[i];
81          if (ub_indices[i] < min_ub) min_ub = ub_indices[i];
82       }
83       *min_index = min_ub;
84       *max_index = max_ub;
85       break;
86    }
87    default:
88       assert(0);
89       break;
90    }
91 }
92
93
94 /**
95  * Check that element 'j' of the array has reasonable data.
96  * Map VBO if needed.
97  */
98 static void
99 check_array_data(GLcontext *ctx, struct gl_client_array *array,
100                  GLuint attrib, GLuint j)
101 {
102    if (array->Enabled) {
103       const void *data = array->Ptr;
104       if (array->BufferObj->Name) {
105          if (!array->BufferObj->Pointer) {
106             /* need to map now */
107             array->BufferObj->Pointer = ctx->Driver.MapBuffer(ctx,
108                                                               GL_ARRAY_BUFFER_ARB,
109                                                               GL_READ_ONLY,
110                                                               array->BufferObj);
111          }
112          data = ADD_POINTERS(data, array->BufferObj->Pointer);
113       }
114       switch (array->Type) {
115       case GL_FLOAT:
116          {
117             GLfloat *f = (GLfloat *) ((GLubyte *) data + array->StrideB * j);
118             GLuint k;
119             for (k = 0; k < array->Size; k++) {
120                if (IS_INF_OR_NAN(f[k]) ||
121                    f[k] >= 1.0e20 || f[k] <= -1.0e10) {
122                   _mesa_printf("Bad array data:\n");
123                   _mesa_printf("  Element[%u].%u = %f\n", j, k, f[k]);
124                   _mesa_printf("  Array %u at %p\n", attrib, (void* ) array);
125                   _mesa_printf("  Type 0x%x, Size %d, Stride %d\n",
126                                array->Type, array->Size, array->Stride);
127                   _mesa_printf("  Address/offset %p in Buffer Object %u\n",
128                                array->Ptr, array->BufferObj->Name);
129                   f[k] = 1.0; /* XXX replace the bad value! */
130                }
131                //assert(!IS_INF_OR_NAN(f[k]));
132             }
133          }
134          break;
135       default:
136          ;
137       }
138    }
139 }
140
141
142 /**
143  * Unmap the buffer object referenced by given array, if mapped.
144  */
145 static void
146 unmap_array_buffer(GLcontext *ctx, struct gl_client_array *array)
147 {
148    if (array->Enabled &&
149        array->BufferObj->Name &&
150        array->BufferObj->Pointer) {
151       ctx->Driver.UnmapBuffer(ctx,
152                               GL_ARRAY_BUFFER_ARB,
153                               array->BufferObj);
154    }
155 }
156
157
158 /**
159  * Examine the array's data for NaNs, etc.
160  */
161 static void
162 check_draw_elements_data(GLcontext *ctx, GLsizei count, GLenum elemType,
163                          const void *elements)
164 {
165    struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
166    const void *elemMap;
167    GLint i, k;
168
169    if (ctx->Array.ElementArrayBufferObj->Name) {
170       elemMap = ctx->Driver.MapBuffer(ctx,
171                                       GL_ELEMENT_ARRAY_BUFFER_ARB,
172                                       GL_READ_ONLY,
173                                       ctx->Array.ElementArrayBufferObj);
174       elements = ADD_POINTERS(elements, elemMap);
175    }
176
177    for (i = 0; i < count; i++) {
178       GLuint j;
179
180       /* j = element[i] */
181       switch (elemType) {
182       case GL_UNSIGNED_BYTE:
183          j = ((const GLubyte *) elements)[i];
184          break;
185       case GL_UNSIGNED_SHORT:
186          j = ((const GLushort *) elements)[i];
187          break;
188       case GL_UNSIGNED_INT:
189          j = ((const GLuint *) elements)[i];
190          break;
191       default:
192          assert(0);
193       }
194
195       /* check element j of each enabled array */
196       check_array_data(ctx, &arrayObj->Vertex, VERT_ATTRIB_POS, j);
197       check_array_data(ctx, &arrayObj->Normal, VERT_ATTRIB_NORMAL, j);
198       check_array_data(ctx, &arrayObj->Color, VERT_ATTRIB_COLOR0, j);
199       check_array_data(ctx, &arrayObj->SecondaryColor, VERT_ATTRIB_COLOR1, j);
200       for (k = 0; k < Elements(arrayObj->TexCoord); k++) {
201          check_array_data(ctx, &arrayObj->TexCoord[k], VERT_ATTRIB_TEX0 + k, j);
202       }
203       for (k = 0; k < Elements(arrayObj->VertexAttrib); k++) {
204          check_array_data(ctx, &arrayObj->VertexAttrib[k], VERT_ATTRIB_GENERIC0 + k, j);
205       }
206    }
207
208    if (ctx->Array.ElementArrayBufferObj->Name) {
209       ctx->Driver.UnmapBuffer(ctx,
210                               GL_ELEMENT_ARRAY_BUFFER_ARB,
211                               ctx->Array.ElementArrayBufferObj);
212    }
213
214    unmap_array_buffer(ctx, &arrayObj->Vertex);
215    unmap_array_buffer(ctx, &arrayObj->Normal);
216    unmap_array_buffer(ctx, &arrayObj->Color);
217    for (k = 0; k < Elements(arrayObj->TexCoord); k++) {
218       unmap_array_buffer(ctx, &arrayObj->TexCoord[k]);
219    }
220    for (k = 0; k < Elements(arrayObj->VertexAttrib); k++) {
221       unmap_array_buffer(ctx, &arrayObj->VertexAttrib[k]);
222    }
223 }
224
225
226 /**
227  * Check array data, looking for NaNs, etc.
228  */
229 static void
230 check_draw_arrays_data(GLcontext *ctx, GLint start, GLsizei count)
231 {
232    /* TO DO */
233 }
234
235
236 /**
237  * Print info/data for glDrawArrays().
238  */
239 static void
240 print_draw_arrays(GLcontext *ctx, struct vbo_exec_context *exec,
241                   GLenum mode, GLint start, GLsizei count)
242 {
243    int i;
244
245    _mesa_printf("vbo_exec_DrawArrays(mode 0x%x, start %d, count %d):\n",
246                 mode, start, count);
247
248    for (i = 0; i < 32; i++) {
249       GLuint bufName = exec->array.inputs[i]->BufferObj->Name;
250       GLint stride = exec->array.inputs[i]->Stride;
251       _mesa_printf("attr %2d: size %d stride %d  enabled %d  "
252                    "ptr %p  Bufobj %u\n",
253                    i,
254                    exec->array.inputs[i]->Size,
255                    stride,
256                    /*exec->array.inputs[i]->Enabled,*/
257                    exec->array.legacy_array[i]->Enabled,
258                    exec->array.inputs[i]->Ptr,
259                    bufName);
260
261       if (bufName) {
262          struct gl_buffer_object *buf = _mesa_lookup_bufferobj(ctx, bufName);
263          GLubyte *p = ctx->Driver.MapBuffer(ctx, GL_ARRAY_BUFFER_ARB,
264                                             GL_READ_ONLY_ARB, buf);
265          int offset = (int) (GLintptr) exec->array.inputs[i]->Ptr;
266          float *f = (float *) (p + offset);
267          int *k = (int *) f;
268          int i;
269          int n = (count * stride) / 4;
270          if (n > 32)
271             n = 32;
272          _mesa_printf("  Data at offset %d:\n", offset);
273          for (i = 0; i < n; i++) {
274             _mesa_printf("    float[%d] = 0x%08x %f\n", i, k[i], f[i]);
275          }
276          ctx->Driver.UnmapBuffer(ctx, GL_ARRAY_BUFFER_ARB, buf);
277       }
278    }
279 }
280
281
282 /**
283  * Just translate the arrayobj into a sane layout.
284  */
285 static void
286 bind_array_obj(GLcontext *ctx)
287 {
288    struct vbo_context *vbo = vbo_context(ctx);
289    struct vbo_exec_context *exec = &vbo->exec;
290    struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
291    GLuint i;
292
293    /* TODO: Fix the ArrayObj struct to keep legacy arrays in an array
294     * rather than as individual named arrays.  Then this function can
295     * go away.
296     */
297    exec->array.legacy_array[VERT_ATTRIB_POS] = &arrayObj->Vertex;
298    exec->array.legacy_array[VERT_ATTRIB_WEIGHT] = &arrayObj->Weight;
299    exec->array.legacy_array[VERT_ATTRIB_NORMAL] = &arrayObj->Normal;
300    exec->array.legacy_array[VERT_ATTRIB_COLOR0] = &arrayObj->Color;
301    exec->array.legacy_array[VERT_ATTRIB_COLOR1] = &arrayObj->SecondaryColor;
302    exec->array.legacy_array[VERT_ATTRIB_FOG] = &arrayObj->FogCoord;
303    exec->array.legacy_array[VERT_ATTRIB_COLOR_INDEX] = &arrayObj->Index;
304    if (arrayObj->PointSize.Enabled) {
305       /* this aliases COLOR_INDEX */
306       exec->array.legacy_array[VERT_ATTRIB_POINT_SIZE] = &arrayObj->PointSize;
307    }
308    exec->array.legacy_array[VERT_ATTRIB_EDGEFLAG] = &arrayObj->EdgeFlag;
309
310    for (i = 0; i < Elements(arrayObj->TexCoord); i++)
311       exec->array.legacy_array[VERT_ATTRIB_TEX0 + i] = &arrayObj->TexCoord[i];
312
313    for (i = 0; i < Elements(arrayObj->VertexAttrib); i++) {
314       assert(i < Elements(exec->array.generic_array));
315       exec->array.generic_array[i] = &arrayObj->VertexAttrib[i];
316    }
317    
318    exec->array.array_obj = arrayObj->Name;
319 }
320
321
322 static void
323 recalculate_input_bindings(GLcontext *ctx)
324 {
325    struct vbo_context *vbo = vbo_context(ctx);
326    struct vbo_exec_context *exec = &vbo->exec;
327    const struct gl_client_array **inputs = &exec->array.inputs[0];
328    GLbitfield const_inputs = 0x0;
329    GLuint i;
330
331    exec->array.program_mode = get_program_mode(ctx);
332    exec->array.enabled_flags = ctx->Array.ArrayObj->_Enabled;
333
334    switch (exec->array.program_mode) {
335    case VP_NONE:
336       /* When no vertex program is active (or the vertex program is generated
337        * from fixed-function state).  We put the material values into the
338        * generic slots.  This is the only situation where material values
339        * are available as per-vertex attributes.
340        */
341       for (i = 0; i <= VERT_ATTRIB_TEX7; i++) {
342          if (exec->array.legacy_array[i]->Enabled)
343             inputs[i] = exec->array.legacy_array[i];
344          else {
345             inputs[i] = &vbo->legacy_currval[i];
346             const_inputs |= 1 << i;
347          }
348       }
349
350       for (i = 0; i < MAT_ATTRIB_MAX; i++) {
351          inputs[VERT_ATTRIB_GENERIC0 + i] = &vbo->mat_currval[i];
352          const_inputs |= 1 << (VERT_ATTRIB_GENERIC0 + i);
353       }
354
355       /* Could use just about anything, just to fill in the empty
356        * slots:
357        */
358       for (i = MAT_ATTRIB_MAX; i < VERT_ATTRIB_MAX - VERT_ATTRIB_GENERIC0; i++) {
359          inputs[VERT_ATTRIB_GENERIC0 + i] = &vbo->generic_currval[i];
360          const_inputs |= 1 << (VERT_ATTRIB_GENERIC0 + i);
361       }
362       break;
363
364    case VP_NV:
365       /* NV_vertex_program - attribute arrays alias and override
366        * conventional, legacy arrays.  No materials, and the generic
367        * slots are vacant.
368        */
369       for (i = 0; i <= VERT_ATTRIB_TEX7; i++) {
370          if (exec->array.generic_array[i]->Enabled)
371             inputs[i] = exec->array.generic_array[i];
372          else if (exec->array.legacy_array[i]->Enabled)
373             inputs[i] = exec->array.legacy_array[i];
374          else {
375             inputs[i] = &vbo->legacy_currval[i];
376             const_inputs |= 1 << i;
377          }
378       }
379
380       /* Could use just about anything, just to fill in the empty
381        * slots:
382        */
383       for (i = VERT_ATTRIB_GENERIC0; i < VERT_ATTRIB_MAX; i++) {
384          inputs[i] = &vbo->generic_currval[i - VERT_ATTRIB_GENERIC0];
385          const_inputs |= 1 << i;
386       }
387       break;
388
389    case VP_ARB:
390       /* GL_ARB_vertex_program or GLSL vertex shader - Only the generic[0]
391        * attribute array aliases and overrides the legacy position array.  
392        *
393        * Otherwise, legacy attributes available in the legacy slots,
394        * generic attributes in the generic slots and materials are not
395        * available as per-vertex attributes.
396        */
397       if (exec->array.generic_array[0]->Enabled)
398          inputs[0] = exec->array.generic_array[0];
399       else if (exec->array.legacy_array[0]->Enabled)
400          inputs[0] = exec->array.legacy_array[0];
401       else {
402          inputs[0] = &vbo->legacy_currval[0];
403          const_inputs |= 1 << 0;
404       }
405
406       for (i = 1; i <= VERT_ATTRIB_TEX7; i++) {
407          if (exec->array.legacy_array[i]->Enabled)
408             inputs[i] = exec->array.legacy_array[i];
409          else {
410             inputs[i] = &vbo->legacy_currval[i];
411             const_inputs |= 1 << i;
412          }
413       }
414
415       for (i = 0; i < MAX_VERTEX_GENERIC_ATTRIBS; i++) {
416          if (exec->array.generic_array[i]->Enabled)
417             inputs[VERT_ATTRIB_GENERIC0 + i] = exec->array.generic_array[i];
418          else {
419             inputs[VERT_ATTRIB_GENERIC0 + i] = &vbo->generic_currval[i];
420             const_inputs |= 1 << (VERT_ATTRIB_GENERIC0 + i);
421          }
422
423       }
424       break;
425    }
426
427    _mesa_set_varying_vp_inputs( ctx, ~const_inputs );
428 }
429
430
431 static void
432 bind_arrays(GLcontext *ctx)
433 {
434 #if 0
435    if (ctx->Array.ArrayObj.Name != exec->array.array_obj) {
436       bind_array_obj(ctx);
437       recalculate_input_bindings(ctx);
438    }
439    else if (exec->array.program_mode != get_program_mode(ctx) ||
440             exec->array.enabled_flags != ctx->Array.ArrayObj->_Enabled) {
441       
442       recalculate_input_bindings(ctx);
443    }
444 #else
445    bind_array_obj(ctx);
446    recalculate_input_bindings(ctx);
447 #endif
448 }
449
450
451
452 /***********************************************************************
453  * API functions.
454  */
455
456 static void GLAPIENTRY
457 vbo_exec_DrawArrays(GLenum mode, GLint start, GLsizei count)
458 {
459    GET_CURRENT_CONTEXT(ctx);
460    struct vbo_context *vbo = vbo_context(ctx);
461    struct vbo_exec_context *exec = &vbo->exec;
462    struct _mesa_prim prim[1];
463
464    if (!_mesa_validate_DrawArrays( ctx, mode, start, count ))
465       return;
466
467    FLUSH_CURRENT( ctx, 0 );
468
469    if (ctx->NewState)
470       _mesa_update_state( ctx );
471       
472    if (!vbo_validate_shaders(ctx)) {
473       _mesa_error(ctx, GL_INVALID_OPERATION, "glDrawArrays(bad shader)");
474       return;
475    }
476
477 #if 0
478    check_draw_arrays_data(ctx, start, count);
479 #else
480    (void) check_draw_arrays_data;
481 #endif
482
483    bind_arrays( ctx );
484
485    /* Again... because we may have changed the bitmask of per-vertex varying
486     * attributes.  If we regenerate the fixed-function vertex program now
487     * we may be able to prune down the number of vertex attributes which we
488     * need in the shader.
489     */
490    if (ctx->NewState)
491       _mesa_update_state( ctx );
492
493    prim[0].begin = 1;
494    prim[0].end = 1;
495    prim[0].weak = 0;
496    prim[0].pad = 0;
497    prim[0].mode = mode;
498    prim[0].start = start;
499    prim[0].count = count;
500    prim[0].indexed = 0;
501
502    vbo->draw_prims( ctx, exec->array.inputs, prim, 1, NULL,
503                     start, start + count - 1 );
504
505 #if 0
506    print_draw_arrays(ctx, exec, mode, start, count);
507 #else
508    (void) print_draw_arrays;
509 #endif
510 }
511
512
513 static void GLAPIENTRY
514 vbo_exec_DrawRangeElements(GLenum mode,
515                            GLuint start, GLuint end,
516                            GLsizei count, GLenum type, const GLvoid *indices)
517 {
518    GET_CURRENT_CONTEXT(ctx);
519    struct vbo_context *vbo = vbo_context(ctx);
520    struct vbo_exec_context *exec = &vbo->exec;
521    struct _mesa_index_buffer ib;
522    struct _mesa_prim prim[1];
523
524    if (!_mesa_validate_DrawRangeElements( ctx, mode, start, end, count,
525                                           type, indices ))
526       return;
527
528    if (end >= ctx->Array.ArrayObj->_MaxElement) {
529       /* the max element is out of bounds of one or more enabled arrays */
530       _mesa_warning(ctx, "glDraw[Range]Elements(start %u, end %u, count %d, "
531                     "type 0x%x) index=%u is out of bounds (max=%u)",
532                     start, end, count, type, end,
533                     ctx->Array.ArrayObj->_MaxElement - 1);
534       if (0)
535          _mesa_print_arrays(ctx);
536       return;
537    }
538
539 #if 0
540    check_draw_elements_data(ctx, count, type, indices);
541 #else
542    (void) check_draw_elements_data;
543 #endif
544
545    FLUSH_CURRENT( ctx, 0 );
546
547    if (ctx->NewState)
548       _mesa_update_state( ctx );
549
550    if (!vbo_validate_shaders(ctx)) {
551       _mesa_error(ctx, GL_INVALID_OPERATION, "glDrawRangeElements(bad shader)");
552       return;
553    }
554
555    bind_arrays( ctx );
556
557    if (ctx->NewState)
558       _mesa_update_state( ctx );
559
560    ib.count = count;
561    ib.type = type; 
562    ib.obj = ctx->Array.ElementArrayBufferObj;
563    ib.ptr = indices;
564
565    prim[0].begin = 1;
566    prim[0].end = 1;
567    prim[0].weak = 0;
568    prim[0].pad = 0;
569    prim[0].mode = mode;
570    prim[0].start = 0;
571    prim[0].count = count;
572    prim[0].indexed = 1;
573
574    /* Need to give special consideration to rendering a range of
575     * indices starting somewhere above zero.  Typically the
576     * application is issuing multiple DrawRangeElements() to draw
577     * successive primitives layed out linearly in the vertex arrays.
578     * Unless the vertex arrays are all in a VBO (or locked as with
579     * CVA), the OpenGL semantics imply that we need to re-read or
580     * re-upload the vertex data on each draw call.  
581     *
582     * In the case of hardware tnl, we want to avoid starting the
583     * upload at zero, as it will mean every draw call uploads an
584     * increasing amount of not-used vertex data.  Worse - in the
585     * software tnl module, all those vertices might be transformed and
586     * lit but never rendered.
587     *
588     * If we just upload or transform the vertices in start..end,
589     * however, the indices will be incorrect.
590     *
591     * At this level, we don't know exactly what the requirements of
592     * the backend are going to be, though it will likely boil down to
593     * either:
594     *
595     * 1) Do nothing, everything is in a VBO and is processed once
596     *       only.
597     *
598     * 2) Adjust the indices and vertex arrays so that start becomes
599     *    zero.
600     *
601     * Rather than doing anything here, I'll provide a helper function
602     * for the latter case elsewhere.
603     */
604
605    vbo->draw_prims( ctx, exec->array.inputs, prim, 1, &ib, start, end );
606 }
607
608
609 static void GLAPIENTRY
610 vbo_exec_DrawElements(GLenum mode, GLsizei count, GLenum type,
611                       const GLvoid *indices)
612 {
613    GET_CURRENT_CONTEXT(ctx);
614    GLuint min_index = 0;
615    GLuint max_index = 0;
616
617    if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices ))
618       return;
619
620    if (!vbo_validate_shaders(ctx)) {
621       _mesa_error(ctx, GL_INVALID_OPERATION, "glDrawElements(bad shader)");
622       return;
623    }
624
625    if (ctx->Array.ElementArrayBufferObj->Name) {
626       const GLvoid *map = ctx->Driver.MapBuffer(ctx,
627                                                 GL_ELEMENT_ARRAY_BUFFER_ARB,
628                                                 GL_READ_ONLY,
629                                                 ctx->Array.ElementArrayBufferObj);
630
631       get_minmax_index(count, type, ADD_POINTERS(map, indices),
632                        &min_index, &max_index);
633
634       ctx->Driver.UnmapBuffer(ctx,
635                               GL_ELEMENT_ARRAY_BUFFER_ARB,
636                               ctx->Array.ElementArrayBufferObj);
637    }
638    else {
639       get_minmax_index(count, type, indices, &min_index, &max_index);
640    }
641
642    vbo_exec_DrawRangeElements(mode, min_index, max_index, count, type, indices);
643 }
644
645
646 /***********************************************************************
647  * Initialization
648  */
649
650 void
651 vbo_exec_array_init( struct vbo_exec_context *exec )
652 {
653 #if 1
654    exec->vtxfmt.DrawArrays = vbo_exec_DrawArrays;
655    exec->vtxfmt.DrawElements = vbo_exec_DrawElements;
656    exec->vtxfmt.DrawRangeElements = vbo_exec_DrawRangeElements;
657 #else
658    exec->vtxfmt.DrawArrays = _mesa_noop_DrawArrays;
659    exec->vtxfmt.DrawElements = _mesa_noop_DrawElements;
660    exec->vtxfmt.DrawRangeElements = _mesa_noop_DrawRangeElements;
661 #endif
662 }
663
664
665 void
666 vbo_exec_array_destroy( struct vbo_exec_context *exec )
667 {
668    /* nothing to do */
669 }
670
671
672 /* This API entrypoint is not ordinarily used */
673 void GLAPIENTRY
674 _mesa_DrawArrays(GLenum mode, GLint first, GLsizei count)
675 {
676    vbo_exec_DrawArrays(mode, first, count);
677 }
678
679
680 /* This API entrypoint is not ordinarily used */
681 void GLAPIENTRY
682 _mesa_DrawElements(GLenum mode, GLsizei count, GLenum type,
683                    const GLvoid *indices)
684 {
685    vbo_exec_DrawElements(mode, count, type, indices);
686 }
687
688
689 /* This API entrypoint is not ordinarily used */
690 void GLAPIENTRY
691 _mesa_DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count,
692                         GLenum type, const GLvoid *indices)
693 {
694    vbo_exec_DrawRangeElements(mode, start, end, count, type, indices);
695 }