OSDN Git Service

vbo: move/refactor debug code
[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  * Compute min and max elements for glDraw[Range]Elements() calls.
42  */
43 static void get_minmax_index( GLuint count, GLuint type, 
44                               const GLvoid *indices,
45                               GLuint *min_index,
46                               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 bind_array_obj( GLcontext *ctx )
286 {
287    struct vbo_context *vbo = vbo_context(ctx);
288    struct vbo_exec_context *exec = &vbo->exec;
289    struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
290    GLuint i;
291
292    /* TODO: Fix the ArrayObj struct to keep legacy arrays in an array
293     * rather than as individual named arrays.  Then this function can
294     * go away.
295     */
296    exec->array.legacy_array[VERT_ATTRIB_POS] = &arrayObj->Vertex;
297    exec->array.legacy_array[VERT_ATTRIB_WEIGHT] = &arrayObj->Weight;
298    exec->array.legacy_array[VERT_ATTRIB_NORMAL] = &arrayObj->Normal;
299    exec->array.legacy_array[VERT_ATTRIB_COLOR0] = &arrayObj->Color;
300    exec->array.legacy_array[VERT_ATTRIB_COLOR1] = &arrayObj->SecondaryColor;
301    exec->array.legacy_array[VERT_ATTRIB_FOG] = &arrayObj->FogCoord;
302    exec->array.legacy_array[VERT_ATTRIB_COLOR_INDEX] = &arrayObj->Index;
303    if (arrayObj->PointSize.Enabled) {
304       /* this aliases COLOR_INDEX */
305       exec->array.legacy_array[VERT_ATTRIB_POINT_SIZE] = &arrayObj->PointSize;
306    }
307    exec->array.legacy_array[VERT_ATTRIB_EDGEFLAG] = &arrayObj->EdgeFlag;
308
309    for (i = 0; i < Elements(arrayObj->TexCoord); i++)
310       exec->array.legacy_array[VERT_ATTRIB_TEX0 + i] = &arrayObj->TexCoord[i];
311
312    for (i = 0; i < Elements(arrayObj->VertexAttrib); i++) {
313       assert(i < Elements(exec->array.generic_array));
314       exec->array.generic_array[i] = &arrayObj->VertexAttrib[i];
315    }
316    
317    exec->array.array_obj = arrayObj->Name;
318 }
319
320
321 static void recalculate_input_bindings( GLcontext *ctx )
322 {
323    struct vbo_context *vbo = vbo_context(ctx);
324    struct vbo_exec_context *exec = &vbo->exec;
325    const struct gl_client_array **inputs = &exec->array.inputs[0];
326    GLbitfield const_inputs = 0x0;
327    GLuint i;
328
329    exec->array.program_mode = get_program_mode(ctx);
330    exec->array.enabled_flags = ctx->Array.ArrayObj->_Enabled;
331
332    switch (exec->array.program_mode) {
333    case VP_NONE:
334       /* When no vertex program is active (or the vertex program is generated
335        * from fixed-function state).  We put the material values into the
336        * generic slots.  This is the only situation where material values
337        * are available as per-vertex attributes.
338        */
339       for (i = 0; i <= VERT_ATTRIB_TEX7; i++) {
340          if (exec->array.legacy_array[i]->Enabled)
341             inputs[i] = exec->array.legacy_array[i];
342          else {
343             inputs[i] = &vbo->legacy_currval[i];
344             const_inputs |= 1 << i;
345          }
346       }
347
348       for (i = 0; i < MAT_ATTRIB_MAX; i++) {
349          inputs[VERT_ATTRIB_GENERIC0 + i] = &vbo->mat_currval[i];
350          const_inputs |= 1 << (VERT_ATTRIB_GENERIC0 + i);
351       }
352
353       /* Could use just about anything, just to fill in the empty
354        * slots:
355        */
356       for (i = MAT_ATTRIB_MAX; i < VERT_ATTRIB_MAX - VERT_ATTRIB_GENERIC0; i++) {
357          inputs[VERT_ATTRIB_GENERIC0 + i] = &vbo->generic_currval[i];
358          const_inputs |= 1 << (VERT_ATTRIB_GENERIC0 + i);
359       }
360       break;
361
362    case VP_NV:
363       /* NV_vertex_program - attribute arrays alias and override
364        * conventional, legacy arrays.  No materials, and the generic
365        * slots are vacant.
366        */
367       for (i = 0; i <= VERT_ATTRIB_TEX7; i++) {
368          if (exec->array.generic_array[i]->Enabled)
369             inputs[i] = exec->array.generic_array[i];
370          else if (exec->array.legacy_array[i]->Enabled)
371             inputs[i] = exec->array.legacy_array[i];
372          else {
373             inputs[i] = &vbo->legacy_currval[i];
374             const_inputs |= 1 << i;
375          }
376       }
377
378       /* Could use just about anything, just to fill in the empty
379        * slots:
380        */
381       for (i = VERT_ATTRIB_GENERIC0; i < VERT_ATTRIB_MAX; i++) {
382          inputs[i] = &vbo->generic_currval[i - VERT_ATTRIB_GENERIC0];
383          const_inputs |= 1 << i;
384       }
385       break;
386
387    case VP_ARB:
388       /* GL_ARB_vertex_program or GLSL vertex shader - Only the generic[0]
389        * attribute array aliases and overrides the legacy position array.  
390        *
391        * Otherwise, legacy attributes available in the legacy slots,
392        * generic attributes in the generic slots and materials are not
393        * available as per-vertex attributes.
394        */
395       if (exec->array.generic_array[0]->Enabled)
396          inputs[0] = exec->array.generic_array[0];
397       else if (exec->array.legacy_array[0]->Enabled)
398          inputs[0] = exec->array.legacy_array[0];
399       else {
400          inputs[0] = &vbo->legacy_currval[0];
401          const_inputs |= 1 << 0;
402       }
403
404       for (i = 1; i <= VERT_ATTRIB_TEX7; i++) {
405          if (exec->array.legacy_array[i]->Enabled)
406             inputs[i] = exec->array.legacy_array[i];
407          else {
408             inputs[i] = &vbo->legacy_currval[i];
409             const_inputs |= 1 << i;
410          }
411       }
412
413       for (i = 0; i < MAX_VERTEX_GENERIC_ATTRIBS; i++) {
414          if (exec->array.generic_array[i]->Enabled)
415             inputs[VERT_ATTRIB_GENERIC0 + i] = exec->array.generic_array[i];
416          else {
417             inputs[VERT_ATTRIB_GENERIC0 + i] = &vbo->generic_currval[i];
418             const_inputs |= 1 << (VERT_ATTRIB_GENERIC0 + i);
419          }
420
421       }
422       break;
423    }
424
425    _mesa_set_varying_vp_inputs( ctx, ~const_inputs );
426 }
427
428
429 static void bind_arrays( GLcontext *ctx )
430 {
431 #if 0
432    if (ctx->Array.ArrayObj.Name != exec->array.array_obj) {
433       bind_array_obj(ctx);
434       recalculate_input_bindings(ctx);
435    }
436    else if (exec->array.program_mode != get_program_mode(ctx) ||
437             exec->array.enabled_flags != ctx->Array.ArrayObj->_Enabled) {
438       
439       recalculate_input_bindings(ctx);
440    }
441 #else
442    bind_array_obj(ctx);
443    recalculate_input_bindings(ctx);
444 #endif
445 }
446
447
448
449 /***********************************************************************
450  * API functions.
451  */
452
453 static void GLAPIENTRY
454 vbo_exec_DrawArrays(GLenum mode, GLint start, GLsizei count)
455 {
456    GET_CURRENT_CONTEXT(ctx);
457    struct vbo_context *vbo = vbo_context(ctx);
458    struct vbo_exec_context *exec = &vbo->exec;
459    struct _mesa_prim prim[1];
460
461    if (!_mesa_validate_DrawArrays( ctx, mode, start, count ))
462       return;
463
464    FLUSH_CURRENT( ctx, 0 );
465
466    if (ctx->NewState)
467       _mesa_update_state( ctx );
468       
469    if (!vbo_validate_shaders(ctx)) {
470       _mesa_error(ctx, GL_INVALID_OPERATION, "glDrawArrays(bad shader)");
471       return;
472    }
473
474 #if 0
475    check_draw_arrays_data(ctx, start, count);
476 #else
477    (void) check_draw_arrays_data;
478 #endif
479
480
481    bind_arrays( ctx );
482
483    /* Again... because we may have changed the bitmask of per-vertex varying
484     * attributes.  If we regenerate the fixed-function vertex program now
485     * we may be able to prune down the number of vertex attributes which we
486     * need in the shader.
487     */
488    if (ctx->NewState)
489       _mesa_update_state( ctx );
490
491    prim[0].begin = 1;
492    prim[0].end = 1;
493    prim[0].weak = 0;
494    prim[0].pad = 0;
495    prim[0].mode = mode;
496    prim[0].start = start;
497    prim[0].count = count;
498    prim[0].indexed = 0;
499
500    vbo->draw_prims( ctx, exec->array.inputs, prim, 1, NULL,
501                     start, start + count - 1 );
502
503 #if 0
504    print_draw_arrays(ctx, exec, mode, start, count);
505 #else
506    (void) print_draw_arrays;
507 #endif
508 }
509
510
511 static void GLAPIENTRY
512 vbo_exec_DrawRangeElements(GLenum mode,
513                            GLuint start, GLuint end,
514                            GLsizei count, GLenum type, const GLvoid *indices)
515 {
516    GET_CURRENT_CONTEXT(ctx);
517    struct vbo_context *vbo = vbo_context(ctx);
518    struct vbo_exec_context *exec = &vbo->exec;
519    struct _mesa_index_buffer ib;
520    struct _mesa_prim prim[1];
521
522    if (!_mesa_validate_DrawRangeElements( ctx, mode, start, end, count, type, indices ))
523       return;
524
525    if (end >= ctx->Array.ArrayObj->_MaxElement) {
526       /* the max element is out of bounds of one or more enabled arrays */
527       _mesa_warning(ctx, "glDraw[Range]Elements(start %u, end %u, count %d, "
528                     "type 0x%x) index=%u is out of bounds (max=%u)",
529                     start, end, count, type, end,
530                     ctx->Array.ArrayObj->_MaxElement - 1);
531       if (0)
532          _mesa_print_arrays(ctx);
533       return;
534    }
535
536 #if 0
537    check_draw_elements_data(ctx, count, type, indices);
538 #else
539    (void) check_draw_elements_data;
540 #endif
541
542    FLUSH_CURRENT( ctx, 0 );
543
544    if (ctx->NewState)
545       _mesa_update_state( ctx );
546
547    if (!vbo_validate_shaders(ctx)) {
548       _mesa_error(ctx, GL_INVALID_OPERATION, "glDrawRangeElements(bad shader)");
549       return;
550    }
551
552    bind_arrays( ctx );
553
554    if (ctx->NewState)
555       _mesa_update_state( ctx );
556
557    ib.count = count;
558    ib.type = type; 
559    ib.obj = ctx->Array.ElementArrayBufferObj;
560    ib.ptr = indices;
561
562    prim[0].begin = 1;
563    prim[0].end = 1;
564    prim[0].weak = 0;
565    prim[0].pad = 0;
566    prim[0].mode = mode;
567    prim[0].start = 0;
568    prim[0].count = count;
569    prim[0].indexed = 1;
570
571    /* Need to give special consideration to rendering a range of
572     * indices starting somewhere above zero.  Typically the
573     * application is issuing multiple DrawRangeElements() to draw
574     * successive primitives layed out linearly in the vertex arrays.
575     * Unless the vertex arrays are all in a VBO (or locked as with
576     * CVA), the OpenGL semantics imply that we need to re-read or
577     * re-upload the vertex data on each draw call.  
578     *
579     * In the case of hardware tnl, we want to avoid starting the
580     * upload at zero, as it will mean every draw call uploads an
581     * increasing amount of not-used vertex data.  Worse - in the
582     * software tnl module, all those vertices might be transformed and
583     * lit but never rendered.
584     *
585     * If we just upload or transform the vertices in start..end,
586     * however, the indices will be incorrect.
587     *
588     * At this level, we don't know exactly what the requirements of
589     * the backend are going to be, though it will likely boil down to
590     * either:
591     *
592     * 1) Do nothing, everything is in a VBO and is processed once
593     *       only.
594     *
595     * 2) Adjust the indices and vertex arrays so that start becomes
596     *    zero.
597     *
598     * Rather than doing anything here, I'll provide a helper function
599     * for the latter case elsewhere.
600     */
601
602    vbo->draw_prims( ctx, exec->array.inputs, prim, 1, &ib, start, end );
603 }
604
605
606 static void GLAPIENTRY
607 vbo_exec_DrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices)
608 {
609    GET_CURRENT_CONTEXT(ctx);
610    GLuint min_index = 0;
611    GLuint max_index = 0;
612
613    if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices ))
614       return;
615
616    if (!vbo_validate_shaders(ctx)) {
617       _mesa_error(ctx, GL_INVALID_OPERATION, "glDrawElements(bad shader)");
618       return;
619    }
620
621    if (ctx->Array.ElementArrayBufferObj->Name) {
622       const GLvoid *map = ctx->Driver.MapBuffer(ctx,
623                                                  GL_ELEMENT_ARRAY_BUFFER_ARB,
624                                                  GL_READ_ONLY,
625                                                  ctx->Array.ElementArrayBufferObj);
626
627       get_minmax_index(count, type, ADD_POINTERS(map, indices), &min_index, &max_index);
628
629       ctx->Driver.UnmapBuffer(ctx,
630                               GL_ELEMENT_ARRAY_BUFFER_ARB,
631                               ctx->Array.ElementArrayBufferObj);
632    }
633    else {
634       get_minmax_index(count, type, indices, &min_index, &max_index);
635    }
636
637    vbo_exec_DrawRangeElements(mode, min_index, max_index, count, type, indices);
638 }
639
640
641 /***********************************************************************
642  * Initialization
643  */
644
645 void vbo_exec_array_init( struct vbo_exec_context *exec )
646 {
647 #if 1
648    exec->vtxfmt.DrawArrays = vbo_exec_DrawArrays;
649    exec->vtxfmt.DrawElements = vbo_exec_DrawElements;
650    exec->vtxfmt.DrawRangeElements = vbo_exec_DrawRangeElements;
651 #else
652    exec->vtxfmt.DrawArrays = _mesa_noop_DrawArrays;
653    exec->vtxfmt.DrawElements = _mesa_noop_DrawElements;
654    exec->vtxfmt.DrawRangeElements = _mesa_noop_DrawRangeElements;
655 #endif
656 }
657
658
659 void vbo_exec_array_destroy( struct vbo_exec_context *exec )
660 {
661    /* nothing to do */
662 }
663
664
665 /* This API entrypoint is not ordinarily used */
666 void GLAPIENTRY
667 _mesa_DrawArrays(GLenum mode, GLint first, GLsizei count)
668 {
669    vbo_exec_DrawArrays(mode, first, count);
670 }
671
672
673 /* This API entrypoint is not ordinarily used */
674 void GLAPIENTRY
675 _mesa_DrawElements(GLenum mode, GLsizei count, GLenum type,
676                    const GLvoid *indices)
677 {
678    vbo_exec_DrawElements(mode, count, type, indices);
679 }
680
681
682 /* This API entrypoint is not ordinarily used */
683 void GLAPIENTRY
684 _mesa_DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count,
685                         GLenum type, const GLvoid *indices)
686 {
687    vbo_exec_DrawRangeElements(mode, start, end, count, type, indices);
688 }