Merge branch 'master' of git://anongit.freedesktop.org/mesa/mesa
[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/varray.h"
34 #include "main/bufferobj.h"
35 #include "main/enums.h"
36 #include "main/macros.h"
37
38 #include "vbo_context.h"
39
40
41 /**
42 * All vertex buffers should be in an unmapped state when we're about
43 * to draw. This debug function checks that.
44 */
45 static void
46 check_buffers_are_unmapped(const struct gl_client_array **inputs)
47 {
48 #ifdef DEBUG
49 GLuint i;
50
51 for (i = 0; i < VERT_ATTRIB_MAX; i++) {
52 if (inputs[i]) {
53 struct gl_buffer_object *obj = inputs[i]->BufferObj;
54 assert(!_mesa_bufferobj_mapped(obj));
55 (void) obj;
56 }
57 }
58 #endif
59 }
60
61
62 /**
63 * A debug function that may be called from other parts of Mesa as
64 * needed during debugging.
65 */
66 void
67 vbo_check_buffers_are_unmapped(struct gl_context *ctx)
68 {
69 struct vbo_context *vbo = vbo_context(ctx);
70 struct vbo_exec_context *exec = &vbo->exec;
71 /* check the current vertex arrays */
72 check_buffers_are_unmapped(exec->array.inputs);
73 /* check the current glBegin/glVertex/glEnd-style VBO */
74 assert(!_mesa_bufferobj_mapped(exec->vtx.bufferobj));
75 }
76
77
78
79 /**
80 * Compute min and max elements by scanning the index buffer for
81 * glDraw[Range]Elements() calls.
82 * If primitive restart is enabled, we need to ignore restart
83 * indexes when computing min/max.
84 */
85 void
86 vbo_get_minmax_index(struct gl_context *ctx,
87 const struct _mesa_prim *prim,
88 const struct _mesa_index_buffer *ib,
89 GLuint *min_index, GLuint *max_index)
90 {
91 const GLboolean restart = ctx->Array.PrimitiveRestart;
92 const GLuint restartIndex = ctx->Array.RestartIndex;
93 const GLuint count = prim->count;
94 const void *indices;
95 GLuint i;
96
97 if (_mesa_is_bufferobj(ib->obj)) {
98 unsigned map_size;
99
100 switch (ib->type) {
101 case GL_UNSIGNED_INT:
102 map_size = count * sizeof(GLuint);
103 break;
104 case GL_UNSIGNED_SHORT:
105 map_size = count * sizeof(GLushort);
106 break;
107 case GL_UNSIGNED_BYTE:
108 map_size = count * sizeof(GLubyte);
109 break;
110 default:
111 assert(0);
112 map_size = 0;
113 }
114
115 indices = ctx->Driver.MapBufferRange(ctx, (GLsizeiptr) ib->ptr, map_size,
116 GL_MAP_READ_BIT, ib->obj);
117 } else {
118 indices = ib->ptr;
119 }
120
121 switch (ib->type) {
122 case GL_UNSIGNED_INT: {
123 const GLuint *ui_indices = (const GLuint *)indices;
124 GLuint max_ui = 0;
125 GLuint min_ui = ~0U;
126 if (restart) {
127 for (i = 0; i < count; i++) {
128 if (ui_indices[i] != restartIndex) {
129 if (ui_indices[i] > max_ui) max_ui = ui_indices[i];
130 if (ui_indices[i] < min_ui) min_ui = ui_indices[i];
131 }
132 }
133 }
134 else {
135 for (i = 0; i < count; i++) {
136 if (ui_indices[i] > max_ui) max_ui = ui_indices[i];
137 if (ui_indices[i] < min_ui) min_ui = ui_indices[i];
138 }
139 }
140 *min_index = min_ui;
141 *max_index = max_ui;
142 break;
143 }
144 case GL_UNSIGNED_SHORT: {
145 const GLushort *us_indices = (const GLushort *)indices;
146 GLuint max_us = 0;
147 GLuint min_us = ~0U;
148 if (restart) {
149 for (i = 0; i < count; i++) {
150 if (us_indices[i] != restartIndex) {
151 if (us_indices[i] > max_us) max_us = us_indices[i];
152 if (us_indices[i] < min_us) min_us = us_indices[i];
153 }
154 }
155 }
156 else {
157 for (i = 0; i < count; i++) {
158 if (us_indices[i] > max_us) max_us = us_indices[i];
159 if (us_indices[i] < min_us) min_us = us_indices[i];
160 }
161 }
162 *min_index = min_us;
163 *max_index = max_us;
164 break;
165 }
166 case GL_UNSIGNED_BYTE: {
167 const GLubyte *ub_indices = (const GLubyte *)indices;
168 GLuint max_ub = 0;
169 GLuint min_ub = ~0U;
170 if (restart) {
171 for (i = 0; i < count; i++) {
172 if (ub_indices[i] != restartIndex) {
173 if (ub_indices[i] > max_ub) max_ub = ub_indices[i];
174 if (ub_indices[i] < min_ub) min_ub = ub_indices[i];
175 }
176 }
177 }
178 else {
179 for (i = 0; i < count; i++) {
180 if (ub_indices[i] > max_ub) max_ub = ub_indices[i];
181 if (ub_indices[i] < min_ub) min_ub = ub_indices[i];
182 }
183 }
184 *min_index = min_ub;
185 *max_index = max_ub;
186 break;
187 }
188 default:
189 assert(0);
190 break;
191 }
192
193 if (_mesa_is_bufferobj(ib->obj)) {
194 ctx->Driver.UnmapBuffer(ctx, ib->obj);
195 }
196 }
197
198
199 /**
200 * Check that element 'j' of the array has reasonable data.
201 * Map VBO if needed.
202 * For debugging purposes; not normally used.
203 */
204 static void
205 check_array_data(struct gl_context *ctx, struct gl_client_array *array,
206 GLuint attrib, GLuint j)
207 {
208 if (array->Enabled) {
209 const void *data = array->Ptr;
210 if (_mesa_is_bufferobj(array->BufferObj)) {
211 if (!array->BufferObj->Pointer) {
212 /* need to map now */
213 array->BufferObj->Pointer =
214 ctx->Driver.MapBufferRange(ctx, 0, array->BufferObj->Size,
215 GL_MAP_READ_BIT, array->BufferObj);
216 }
217 data = ADD_POINTERS(data, array->BufferObj->Pointer);
218 }
219 switch (array->Type) {
220 case GL_FLOAT:
221 {
222 GLfloat *f = (GLfloat *) ((GLubyte *) data + array->StrideB * j);
223 GLint k;
224 for (k = 0; k < array->Size; k++) {
225 if (IS_INF_OR_NAN(f[k]) ||
226 f[k] >= 1.0e20 || f[k] <= -1.0e10) {
227 printf("Bad array data:\n");
228 printf(" Element[%u].%u = %f\n", j, k, f[k]);
229 printf(" Array %u at %p\n", attrib, (void* ) array);
230 printf(" Type 0x%x, Size %d, Stride %d\n",
231 array->Type, array->Size, array->Stride);
232 printf(" Address/offset %p in Buffer Object %u\n",
233 array->Ptr, array->BufferObj->Name);
234 f[k] = 1.0; /* XXX replace the bad value! */
235 }
236 /*assert(!IS_INF_OR_NAN(f[k]));*/
237 }
238 }
239 break;
240 default:
241 ;
242 }
243 }
244 }
245
246
247 /**
248 * Unmap the buffer object referenced by given array, if mapped.
249 */
250 static void
251 unmap_array_buffer(struct gl_context *ctx, struct gl_client_array *array)
252 {
253 if (array->Enabled &&
254 _mesa_is_bufferobj(array->BufferObj) &&
255 _mesa_bufferobj_mapped(array->BufferObj)) {
256 ctx->Driver.UnmapBuffer(ctx, array->BufferObj);
257 }
258 }
259
260
261 /**
262 * Examine the array's data for NaNs, etc.
263 * For debug purposes; not normally used.
264 */
265 static void
266 check_draw_elements_data(struct gl_context *ctx, GLsizei count, GLenum elemType,
267 const void *elements, GLint basevertex)
268 {
269 struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
270 const void *elemMap;
271 GLint i, k;
272
273 if (_mesa_is_bufferobj(ctx->Array.ElementArrayBufferObj)) {
274 elemMap = ctx->Driver.MapBufferRange(ctx, 0,
275 ctx->Array.ElementArrayBufferObj->Size,
276 GL_MAP_READ_BIT,
277 ctx->Array.ElementArrayBufferObj);
278 elements = ADD_POINTERS(elements, elemMap);
279 }
280
281 for (i = 0; i < count; i++) {
282 GLuint j;
283
284 /* j = element[i] */
285 switch (elemType) {
286 case GL_UNSIGNED_BYTE:
287 j = ((const GLubyte *) elements)[i];
288 break;
289 case GL_UNSIGNED_SHORT:
290 j = ((const GLushort *) elements)[i];
291 break;
292 case GL_UNSIGNED_INT:
293 j = ((const GLuint *) elements)[i];
294 break;
295 default:
296 assert(0);
297 }
298
299 /* check element j of each enabled array */
300 check_array_data(ctx, &arrayObj->Vertex, VERT_ATTRIB_POS, j);
301 check_array_data(ctx, &arrayObj->Normal, VERT_ATTRIB_NORMAL, j);
302 check_array_data(ctx, &arrayObj->Color, VERT_ATTRIB_COLOR0, j);
303 check_array_data(ctx, &arrayObj->SecondaryColor, VERT_ATTRIB_COLOR1, j);
304 for (k = 0; k < Elements(arrayObj->TexCoord); k++) {
305 check_array_data(ctx, &arrayObj->TexCoord[k], VERT_ATTRIB_TEX0 + k, j);
306 }
307 for (k = 0; k < Elements(arrayObj->VertexAttrib); k++) {
308 check_array_data(ctx, &arrayObj->VertexAttrib[k],
309 VERT_ATTRIB_GENERIC0 + k, j);
310 }
311 }
312
313 if (_mesa_is_bufferobj(ctx->Array.ElementArrayBufferObj)) {
314 ctx->Driver.UnmapBuffer(ctx, ctx->Array.ElementArrayBufferObj);
315 }
316
317 unmap_array_buffer(ctx, &arrayObj->Vertex);
318 unmap_array_buffer(ctx, &arrayObj->Normal);
319 unmap_array_buffer(ctx, &arrayObj->Color);
320 for (k = 0; k < Elements(arrayObj->TexCoord); k++) {
321 unmap_array_buffer(ctx, &arrayObj->TexCoord[k]);
322 }
323 for (k = 0; k < Elements(arrayObj->VertexAttrib); k++) {
324 unmap_array_buffer(ctx, &arrayObj->VertexAttrib[k]);
325 }
326 }
327
328
329 /**
330 * Check array data, looking for NaNs, etc.
331 */
332 static void
333 check_draw_arrays_data(struct gl_context *ctx, GLint start, GLsizei count)
334 {
335 /* TO DO */
336 }
337
338
339 /**
340 * Print info/data for glDrawArrays(), for debugging.
341 */
342 static void
343 print_draw_arrays(struct gl_context *ctx,
344 GLenum mode, GLint start, GLsizei count)
345 {
346 struct vbo_context *vbo = vbo_context(ctx);
347 struct vbo_exec_context *exec = &vbo->exec;
348 int i;
349
350 printf("vbo_exec_DrawArrays(mode 0x%x, start %d, count %d):\n",
351 mode, start, count);
352
353 for (i = 0; i < 32; i++) {
354 struct gl_buffer_object *bufObj = exec->array.inputs[i]->BufferObj;
355 GLuint bufName = bufObj->Name;
356 GLint stride = exec->array.inputs[i]->Stride;
357 printf("attr %2d: size %d stride %d enabled %d "
358 "ptr %p Bufobj %u\n",
359 i,
360 exec->array.inputs[i]->Size,
361 stride,
362 /*exec->array.inputs[i]->Enabled,*/
363 exec->array.legacy_array[i]->Enabled,
364 exec->array.inputs[i]->Ptr,
365 bufName);
366
367 if (bufName) {
368 GLubyte *p = ctx->Driver.MapBufferRange(ctx, 0, bufObj->Size,
369 GL_MAP_READ_BIT, bufObj);
370 int offset = (int) (GLintptr) exec->array.inputs[i]->Ptr;
371 float *f = (float *) (p + offset);
372 int *k = (int *) f;
373 int i;
374 int n = (count * stride) / 4;
375 if (n > 32)
376 n = 32;
377 printf(" Data at offset %d:\n", offset);
378 for (i = 0; i < n; i++) {
379 printf(" float[%d] = 0x%08x %f\n", i, k[i], f[i]);
380 }
381 ctx->Driver.UnmapBuffer(ctx, bufObj);
382 }
383 }
384 }
385
386
387 /**
388 * Bind the VBO executor to the current vertex array object prior
389 * to drawing.
390 *
391 * Just translate the arrayobj into a sane layout.
392 */
393 static void
394 bind_array_obj(struct gl_context *ctx)
395 {
396 struct vbo_context *vbo = vbo_context(ctx);
397 struct vbo_exec_context *exec = &vbo->exec;
398 struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
399 GLuint i;
400
401 /* TODO: Fix the ArrayObj struct to keep legacy arrays in an array
402 * rather than as individual named arrays. Then this function can
403 * go away.
404 */
405 exec->array.legacy_array[VERT_ATTRIB_POS] = &arrayObj->Vertex;
406 exec->array.legacy_array[VERT_ATTRIB_WEIGHT] = &arrayObj->Weight;
407 exec->array.legacy_array[VERT_ATTRIB_NORMAL] = &arrayObj->Normal;
408 exec->array.legacy_array[VERT_ATTRIB_COLOR0] = &arrayObj->Color;
409 exec->array.legacy_array[VERT_ATTRIB_COLOR1] = &arrayObj->SecondaryColor;
410 exec->array.legacy_array[VERT_ATTRIB_FOG] = &arrayObj->FogCoord;
411 exec->array.legacy_array[VERT_ATTRIB_COLOR_INDEX] = &arrayObj->Index;
412 if (arrayObj->PointSize.Enabled) {
413 /* this aliases COLOR_INDEX */
414 exec->array.legacy_array[VERT_ATTRIB_POINT_SIZE] = &arrayObj->PointSize;
415 }
416 exec->array.legacy_array[VERT_ATTRIB_EDGEFLAG] = &arrayObj->EdgeFlag;
417
418 for (i = 0; i < Elements(arrayObj->TexCoord); i++)
419 exec->array.legacy_array[VERT_ATTRIB_TEX0 + i] = &arrayObj->TexCoord[i];
420
421 for (i = 0; i < Elements(arrayObj->VertexAttrib); i++) {
422 assert(i < Elements(exec->array.generic_array));
423 exec->array.generic_array[i] = &arrayObj->VertexAttrib[i];
424 }
425
426 exec->array.array_obj = arrayObj->Name;
427 }
428
429
430 /**
431 * Set the vbo->exec->inputs[] pointers to point to the enabled
432 * vertex arrays. This depends on the current vertex program/shader
433 * being executed because of whether or not generic vertex arrays
434 * alias the conventional vertex arrays.
435 * For arrays that aren't enabled, we set the input[attrib] pointer
436 * to point at a zero-stride current value "array".
437 */
438 static void
439 recalculate_input_bindings(struct gl_context *ctx)
440 {
441 struct vbo_context *vbo = vbo_context(ctx);
442 struct vbo_exec_context *exec = &vbo->exec;
443 const struct gl_client_array **inputs = &exec->array.inputs[0];
444 GLbitfield const_inputs = 0x0;
445 GLuint i;
446
447 exec->array.program_mode = get_program_mode(ctx);
448 exec->array.enabled_flags = ctx->Array.ArrayObj->_Enabled;
449
450 switch (exec->array.program_mode) {
451 case VP_NONE:
452 /* When no vertex program is active (or the vertex program is generated
453 * from fixed-function state). We put the material values into the
454 * generic slots. This is the only situation where material values
455 * are available as per-vertex attributes.
456 */
457 for (i = 0; i <= VERT_ATTRIB_TEX7; i++) {
458 if (exec->array.legacy_array[i]->Enabled)
459 inputs[i] = exec->array.legacy_array[i];
460 else {
461 inputs[i] = &vbo->legacy_currval[i];
462 const_inputs |= 1 << i;
463 }
464 }
465
466 for (i = 0; i < MAT_ATTRIB_MAX; i++) {
467 inputs[VERT_ATTRIB_GENERIC0 + i] = &vbo->mat_currval[i];
468 const_inputs |= 1 << (VERT_ATTRIB_GENERIC0 + i);
469 }
470
471 /* Could use just about anything, just to fill in the empty
472 * slots:
473 */
474 for (i = MAT_ATTRIB_MAX; i < VERT_ATTRIB_MAX - VERT_ATTRIB_GENERIC0; i++) {
475 inputs[VERT_ATTRIB_GENERIC0 + i] = &vbo->generic_currval[i];
476 const_inputs |= 1 << (VERT_ATTRIB_GENERIC0 + i);
477 }
478
479 /* There is no need to make _NEW_ARRAY dirty here for the TnL program,
480 * because it already takes care of invalidating the state necessary
481 * to revalidate vertex arrays. Not marking the state as dirty also
482 * improves performance (quite significantly in some apps).
483 */
484 if (!ctx->VertexProgram._MaintainTnlProgram)
485 ctx->NewState |= _NEW_ARRAY;
486 break;
487
488 case VP_NV:
489 /* NV_vertex_program - attribute arrays alias and override
490 * conventional, legacy arrays. No materials, and the generic
491 * slots are vacant.
492 */
493 for (i = 0; i <= VERT_ATTRIB_TEX7; i++) {
494 if (exec->array.generic_array[i]->Enabled)
495 inputs[i] = exec->array.generic_array[i];
496 else if (exec->array.legacy_array[i]->Enabled)
497 inputs[i] = exec->array.legacy_array[i];
498 else {
499 inputs[i] = &vbo->legacy_currval[i];
500 const_inputs |= 1 << i;
501 }
502 }
503
504 /* Could use just about anything, just to fill in the empty
505 * slots:
506 */
507 for (i = VERT_ATTRIB_GENERIC0; i < VERT_ATTRIB_MAX; i++) {
508 inputs[i] = &vbo->generic_currval[i - VERT_ATTRIB_GENERIC0];
509 const_inputs |= 1 << i;
510 }
511
512 ctx->NewState |= _NEW_ARRAY;
513 break;
514
515 case VP_ARB:
516 /* GL_ARB_vertex_program or GLSL vertex shader - Only the generic[0]
517 * attribute array aliases and overrides the legacy position array.
518 *
519 * Otherwise, legacy attributes available in the legacy slots,
520 * generic attributes in the generic slots and materials are not
521 * available as per-vertex attributes.
522 */
523 if (exec->array.generic_array[0]->Enabled)
524 inputs[0] = exec->array.generic_array[0];
525 else if (exec->array.legacy_array[0]->Enabled)
526 inputs[0] = exec->array.legacy_array[0];
527 else {
528 inputs[0] = &vbo->legacy_currval[0];
529 const_inputs |= 1 << 0;
530 }
531
532 for (i = 1; i <= VERT_ATTRIB_TEX7; i++) {
533 if (exec->array.legacy_array[i]->Enabled)
534 inputs[i] = exec->array.legacy_array[i];
535 else {
536 inputs[i] = &vbo->legacy_currval[i];
537 const_inputs |= 1 << i;
538 }
539 }
540
541 for (i = 0; i < MAX_VERTEX_GENERIC_ATTRIBS; i++) {
542 if (exec->array.generic_array[i]->Enabled)
543 inputs[VERT_ATTRIB_GENERIC0 + i] = exec->array.generic_array[i];
544 else {
545 inputs[VERT_ATTRIB_GENERIC0 + i] = &vbo->generic_currval[i];
546 const_inputs |= 1 << (VERT_ATTRIB_GENERIC0 + i);
547 }
548 }
549
550 ctx->NewState |= _NEW_ARRAY;
551 break;
552 }
553
554 _mesa_set_varying_vp_inputs( ctx, ~const_inputs );
555 }
556
557
558 /**
559 * Examine the enabled vertex arrays to set the exec->array.inputs[] values.
560 * These will point to the arrays to actually use for drawing. Some will
561 * be user-provided arrays, other will be zero-stride const-valued arrays.
562 * Note that this might set the _NEW_ARRAY dirty flag so state validation
563 * must be done after this call.
564 */
565 static void
566 bind_arrays(struct gl_context *ctx)
567 {
568 if (!ctx->Array.RebindArrays) {
569 return;
570 }
571
572 bind_array_obj(ctx);
573 recalculate_input_bindings(ctx);
574 ctx->Array.RebindArrays = GL_FALSE;
575 }
576
577
578 /**
579 * Helper function called by the other DrawArrays() functions below.
580 * This is where we handle primitive restart for drawing non-indexed
581 * arrays. If primitive restart is enabled, it typically means
582 * splitting one DrawArrays() into two.
583 */
584 static void
585 vbo_draw_arrays(struct gl_context *ctx, GLenum mode, GLint start,
586 GLsizei count, GLuint numInstances)
587 {
588 struct vbo_context *vbo = vbo_context(ctx);
589 struct vbo_exec_context *exec = &vbo->exec;
590 struct _mesa_prim prim[2];
591
592 bind_arrays(ctx);
593
594 /* Again... because we may have changed the bitmask of per-vertex varying
595 * attributes. If we regenerate the fixed-function vertex program now
596 * we may be able to prune down the number of vertex attributes which we
597 * need in the shader.
598 */
599 if (ctx->NewState)
600 _mesa_update_state(ctx);
601
602 /* init most fields to zero */
603 memset(prim, 0, sizeof(prim));
604 prim[0].begin = 1;
605 prim[0].end = 1;
606 prim[0].mode = mode;
607 prim[0].num_instances = numInstances;
608
609 /* Implement the primitive restart index */
610 if (ctx->Array.PrimitiveRestart && ctx->Array.RestartIndex < count) {
611 GLuint primCount = 0;
612
613 if (ctx->Array.RestartIndex == start) {
614 /* special case: RestartIndex at beginning */
615 if (count > 1) {
616 prim[0].start = start + 1;
617 prim[0].count = count - 1;
618 primCount = 1;
619 }
620 }
621 else if (ctx->Array.RestartIndex == start + count - 1) {
622 /* special case: RestartIndex at end */
623 if (count > 1) {
624 prim[0].start = start;
625 prim[0].count = count - 1;
626 primCount = 1;
627 }
628 }
629 else {
630 /* general case: RestartIndex in middle, split into two prims */
631 prim[0].start = start;
632 prim[0].count = ctx->Array.RestartIndex - start;
633
634 prim[1] = prim[0];
635 prim[1].start = ctx->Array.RestartIndex + 1;
636 prim[1].count = count - prim[1].start;
637
638 primCount = 2;
639 }
640
641 if (primCount > 0) {
642 /* draw one or two prims */
643 check_buffers_are_unmapped(exec->array.inputs);
644 vbo->draw_prims(ctx, exec->array.inputs, prim, primCount, NULL,
645 GL_TRUE, start, start + count - 1);
646 }
647 }
648 else {
649 /* no prim restart */
650 prim[0].start = start;
651 prim[0].count = count;
652
653 check_buffers_are_unmapped(exec->array.inputs);
654 vbo->draw_prims(ctx, exec->array.inputs, prim, 1, NULL,
655 GL_TRUE, start, start + count - 1);
656 }
657 }
658
659
660
661 /**
662 * Called from glDrawArrays when in immediate mode (not display list mode).
663 */
664 static void GLAPIENTRY
665 vbo_exec_DrawArrays(GLenum mode, GLint start, GLsizei count)
666 {
667 GET_CURRENT_CONTEXT(ctx);
668
669 if (MESA_VERBOSE & VERBOSE_DRAW)
670 _mesa_debug(ctx, "glDrawArrays(%s, %d, %d)\n",
671 _mesa_lookup_enum_by_nr(mode), start, count);
672
673 if (!_mesa_validate_DrawArrays( ctx, mode, start, count ))
674 return;
675
676 FLUSH_CURRENT( ctx, 0 );
677
678 if (!_mesa_valid_to_render(ctx, "glDrawArrays")) {
679 return;
680 }
681
682 if (0)
683 check_draw_arrays_data(ctx, start, count);
684
685 vbo_draw_arrays(ctx, mode, start, count, 1);
686
687 if (0)
688 print_draw_arrays(ctx, mode, start, count);
689 }
690
691
692 /**
693 * Called from glDrawArraysInstanced when in immediate mode (not
694 * display list mode).
695 */
696 static void GLAPIENTRY
697 vbo_exec_DrawArraysInstanced(GLenum mode, GLint start, GLsizei count,
698 GLsizei numInstances)
699 {
700 GET_CURRENT_CONTEXT(ctx);
701
702 if (MESA_VERBOSE & VERBOSE_DRAW)
703 _mesa_debug(ctx, "glDrawArraysInstanced(%s, %d, %d, %d)\n",
704 _mesa_lookup_enum_by_nr(mode), start, count, numInstances);
705
706 if (!_mesa_validate_DrawArraysInstanced(ctx, mode, start, count, numInstances))
707 return;
708
709 FLUSH_CURRENT( ctx, 0 );
710
711 if (!_mesa_valid_to_render(ctx, "glDrawArraysInstanced")) {
712 return;
713 }
714
715 if (0)
716 check_draw_arrays_data(ctx, start, count);
717
718 vbo_draw_arrays(ctx, mode, start, count, numInstances);
719
720 if (0)
721 print_draw_arrays(ctx, mode, start, count);
722 }
723
724
725 /**
726 * Map GL_ELEMENT_ARRAY_BUFFER and print contents.
727 * For debugging.
728 */
729 static void
730 dump_element_buffer(struct gl_context *ctx, GLenum type)
731 {
732 const GLvoid *map =
733 ctx->Driver.MapBufferRange(ctx, 0,
734 ctx->Array.ElementArrayBufferObj->Size,
735 GL_MAP_READ_BIT,
736 ctx->Array.ElementArrayBufferObj);
737 switch (type) {
738 case GL_UNSIGNED_BYTE:
739 {
740 const GLubyte *us = (const GLubyte *) map;
741 GLint i;
742 for (i = 0; i < ctx->Array.ElementArrayBufferObj->Size; i++) {
743 printf("%02x ", us[i]);
744 if (i % 32 == 31)
745 printf("\n");
746 }
747 printf("\n");
748 }
749 break;
750 case GL_UNSIGNED_SHORT:
751 {
752 const GLushort *us = (const GLushort *) map;
753 GLint i;
754 for (i = 0; i < ctx->Array.ElementArrayBufferObj->Size / 2; i++) {
755 printf("%04x ", us[i]);
756 if (i % 16 == 15)
757 printf("\n");
758 }
759 printf("\n");
760 }
761 break;
762 case GL_UNSIGNED_INT:
763 {
764 const GLuint *us = (const GLuint *) map;
765 GLint i;
766 for (i = 0; i < ctx->Array.ElementArrayBufferObj->Size / 4; i++) {
767 printf("%08x ", us[i]);
768 if (i % 8 == 7)
769 printf("\n");
770 }
771 printf("\n");
772 }
773 break;
774 default:
775 ;
776 }
777
778 ctx->Driver.UnmapBuffer(ctx, ctx->Array.ElementArrayBufferObj);
779 }
780
781
782 /**
783 * Inner support for both _mesa_DrawElements and _mesa_DrawRangeElements.
784 * Do the rendering for a glDrawElements or glDrawRangeElements call after
785 * we've validated buffer bounds, etc.
786 */
787 static void
788 vbo_validated_drawrangeelements(struct gl_context *ctx, GLenum mode,
789 GLboolean index_bounds_valid,
790 GLuint start, GLuint end,
791 GLsizei count, GLenum type,
792 const GLvoid *indices,
793 GLint basevertex, GLint numInstances)
794 {
795 struct vbo_context *vbo = vbo_context(ctx);
796 struct vbo_exec_context *exec = &vbo->exec;
797 struct _mesa_index_buffer ib;
798 struct _mesa_prim prim[1];
799
800 FLUSH_CURRENT( ctx, 0 );
801
802 if (!_mesa_valid_to_render(ctx, "glDraw[Range]Elements")) {
803 return;
804 }
805
806 bind_arrays( ctx );
807
808 /* check for dirty state again */
809 if (ctx->NewState)
810 _mesa_update_state( ctx );
811
812 ib.count = count;
813 ib.type = type;
814 ib.obj = ctx->Array.ElementArrayBufferObj;
815 ib.ptr = indices;
816
817 prim[0].begin = 1;
818 prim[0].end = 1;
819 prim[0].weak = 0;
820 prim[0].pad = 0;
821 prim[0].mode = mode;
822 prim[0].start = 0;
823 prim[0].count = count;
824 prim[0].indexed = 1;
825 prim[0].basevertex = basevertex;
826 prim[0].num_instances = numInstances;
827
828 /* Need to give special consideration to rendering a range of
829 * indices starting somewhere above zero. Typically the
830 * application is issuing multiple DrawRangeElements() to draw
831 * successive primitives layed out linearly in the vertex arrays.
832 * Unless the vertex arrays are all in a VBO (or locked as with
833 * CVA), the OpenGL semantics imply that we need to re-read or
834 * re-upload the vertex data on each draw call.
835 *
836 * In the case of hardware tnl, we want to avoid starting the
837 * upload at zero, as it will mean every draw call uploads an
838 * increasing amount of not-used vertex data. Worse - in the
839 * software tnl module, all those vertices might be transformed and
840 * lit but never rendered.
841 *
842 * If we just upload or transform the vertices in start..end,
843 * however, the indices will be incorrect.
844 *
845 * At this level, we don't know exactly what the requirements of
846 * the backend are going to be, though it will likely boil down to
847 * either:
848 *
849 * 1) Do nothing, everything is in a VBO and is processed once
850 * only.
851 *
852 * 2) Adjust the indices and vertex arrays so that start becomes
853 * zero.
854 *
855 * Rather than doing anything here, I'll provide a helper function
856 * for the latter case elsewhere.
857 */
858
859 check_buffers_are_unmapped(exec->array.inputs);
860 vbo->draw_prims( ctx, exec->array.inputs, prim, 1, &ib,
861 index_bounds_valid, start, end );
862 }
863
864
865 /**
866 * Called by glDrawRangeElementsBaseVertex() in immediate mode.
867 */
868 static void GLAPIENTRY
869 vbo_exec_DrawRangeElementsBaseVertex(GLenum mode,
870 GLuint start, GLuint end,
871 GLsizei count, GLenum type,
872 const GLvoid *indices,
873 GLint basevertex)
874 {
875 static GLuint warnCount = 0;
876 GET_CURRENT_CONTEXT(ctx);
877
878 if (MESA_VERBOSE & VERBOSE_DRAW)
879 _mesa_debug(ctx,
880 "glDrawRangeElementsBaseVertex(%s, %u, %u, %d, %s, %p, %d)\n",
881 _mesa_lookup_enum_by_nr(mode), start, end, count,
882 _mesa_lookup_enum_by_nr(type), indices, basevertex);
883
884 if (!_mesa_validate_DrawRangeElements( ctx, mode, start, end, count,
885 type, indices, basevertex ))
886 return;
887
888 /* NOTE: It's important that 'end' is a reasonable value.
889 * in _tnl_draw_prims(), we use end to determine how many vertices
890 * to transform. If it's too large, we can unnecessarily split prims
891 * or we can read/write out of memory in several different places!
892 */
893
894 /* Catch/fix some potential user errors */
895 if (type == GL_UNSIGNED_BYTE) {
896 start = MIN2(start, 0xff);
897 end = MIN2(end, 0xff);
898 }
899 else if (type == GL_UNSIGNED_SHORT) {
900 start = MIN2(start, 0xffff);
901 end = MIN2(end, 0xffff);
902 }
903
904 if (end >= ctx->Array.ArrayObj->_MaxElement) {
905 /* the max element is out of bounds of one or more enabled arrays */
906 warnCount++;
907
908 if (warnCount < 10) {
909 _mesa_warning(ctx, "glDraw[Range]Elements(start %u, end %u, count %d, "
910 "type 0x%x, indices=%p)\n"
911 "\tend is out of bounds (max=%u) "
912 "Element Buffer %u (size %d)\n"
913 "\tThis should probably be fixed in the application.",
914 start, end, count, type, indices,
915 ctx->Array.ArrayObj->_MaxElement - 1,
916 ctx->Array.ElementArrayBufferObj->Name,
917 (int) ctx->Array.ElementArrayBufferObj->Size);
918 }
919
920 if (0)
921 dump_element_buffer(ctx, type);
922
923 if (0)
924 _mesa_print_arrays(ctx);
925
926 /* 'end' was out of bounds, but now let's check the actual array
927 * indexes to see if any of them are out of bounds.
928 */
929 if (0) {
930 GLuint max = _mesa_max_buffer_index(ctx, count, type, indices,
931 ctx->Array.ElementArrayBufferObj);
932 if (max >= ctx->Array.ArrayObj->_MaxElement) {
933 if (warnCount < 10) {
934 _mesa_warning(ctx, "glDraw[Range]Elements(start %u, end %u, "
935 "count %d, type 0x%x, indices=%p)\n"
936 "\tindex=%u is out of bounds (max=%u) "
937 "Element Buffer %u (size %d)\n"
938 "\tSkipping the glDrawRangeElements() call",
939 start, end, count, type, indices, max,
940 ctx->Array.ArrayObj->_MaxElement - 1,
941 ctx->Array.ElementArrayBufferObj->Name,
942 (int) ctx->Array.ElementArrayBufferObj->Size);
943 }
944 }
945 /* XXX we could also find the min index and compare to 'start'
946 * to see if start is correct. But it's more likely to get the
947 * upper bound wrong.
948 */
949 }
950
951 /* Set 'end' to the max possible legal value */
952 assert(ctx->Array.ArrayObj->_MaxElement >= 1);
953 end = ctx->Array.ArrayObj->_MaxElement - 1;
954
955 if (end < start) {
956 return;
957 }
958 }
959
960 if (0) {
961 printf("glDraw[Range]Elements{,BaseVertex}"
962 "(start %u, end %u, type 0x%x, count %d) ElemBuf %u, "
963 "base %d\n",
964 start, end, type, count,
965 ctx->Array.ElementArrayBufferObj->Name,
966 basevertex);
967 }
968
969 #if 0
970 check_draw_elements_data(ctx, count, type, indices);
971 #else
972 (void) check_draw_elements_data;
973 #endif
974
975 vbo_validated_drawrangeelements(ctx, mode, GL_TRUE, start, end,
976 count, type, indices, basevertex, 1);
977 }
978
979
980 /**
981 * Called by glDrawRangeElements() in immediate mode.
982 */
983 static void GLAPIENTRY
984 vbo_exec_DrawRangeElements(GLenum mode, GLuint start, GLuint end,
985 GLsizei count, GLenum type, const GLvoid *indices)
986 {
987 if (MESA_VERBOSE & VERBOSE_DRAW) {
988 GET_CURRENT_CONTEXT(ctx);
989 _mesa_debug(ctx,
990 "glDrawRangeElements(%s, %u, %u, %d, %s, %p)\n",
991 _mesa_lookup_enum_by_nr(mode), start, end, count,
992 _mesa_lookup_enum_by_nr(type), indices);
993 }
994
995 vbo_exec_DrawRangeElementsBaseVertex(mode, start, end, count, type,
996 indices, 0);
997 }
998
999
1000 /**
1001 * Called by glDrawElements() in immediate mode.
1002 */
1003 static void GLAPIENTRY
1004 vbo_exec_DrawElements(GLenum mode, GLsizei count, GLenum type,
1005 const GLvoid *indices)
1006 {
1007 GET_CURRENT_CONTEXT(ctx);
1008
1009 if (MESA_VERBOSE & VERBOSE_DRAW)
1010 _mesa_debug(ctx, "glDrawElements(%s, %u, %s, %p)\n",
1011 _mesa_lookup_enum_by_nr(mode), count,
1012 _mesa_lookup_enum_by_nr(type), indices);
1013
1014 if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices, 0 ))
1015 return;
1016
1017 vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, ~0, ~0,
1018 count, type, indices, 0, 1);
1019 }
1020
1021
1022 /**
1023 * Called by glDrawElementsBaseVertex() in immediate mode.
1024 */
1025 static void GLAPIENTRY
1026 vbo_exec_DrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type,
1027 const GLvoid *indices, GLint basevertex)
1028 {
1029 GET_CURRENT_CONTEXT(ctx);
1030
1031 if (MESA_VERBOSE & VERBOSE_DRAW)
1032 _mesa_debug(ctx, "glDrawElementsBaseVertex(%s, %d, %s, %p, %d)\n",
1033 _mesa_lookup_enum_by_nr(mode), count,
1034 _mesa_lookup_enum_by_nr(type), indices, basevertex);
1035
1036 if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices,
1037 basevertex ))
1038 return;
1039
1040 vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, ~0, ~0,
1041 count, type, indices, basevertex, 1);
1042 }
1043
1044
1045 /**
1046 * Called by glDrawElementsInstanced() in immediate mode.
1047 */
1048 static void GLAPIENTRY
1049 vbo_exec_DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type,
1050 const GLvoid *indices, GLsizei numInstances)
1051 {
1052 GET_CURRENT_CONTEXT(ctx);
1053
1054 if (MESA_VERBOSE & VERBOSE_DRAW)
1055 _mesa_debug(ctx, "glDrawElementsInstanced(%s, %d, %s, %p, %d)\n",
1056 _mesa_lookup_enum_by_nr(mode), count,
1057 _mesa_lookup_enum_by_nr(type), indices, numInstances);
1058
1059 if (!_mesa_validate_DrawElementsInstanced(ctx, mode, count, type, indices,
1060 numInstances, 0))
1061 return;
1062
1063 vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, ~0, ~0,
1064 count, type, indices, 0, numInstances);
1065 }
1066
1067 /**
1068 * Called by glDrawElementsInstancedBaseVertex() in immediate mode.
1069 */
1070 static void GLAPIENTRY
1071 vbo_exec_DrawElementsInstancedBaseVertex(GLenum mode, GLsizei count, GLenum type,
1072 const GLvoid *indices, GLsizei numInstances,
1073 GLint basevertex)
1074 {
1075 GET_CURRENT_CONTEXT(ctx);
1076
1077 if (MESA_VERBOSE & VERBOSE_DRAW)
1078 _mesa_debug(ctx, "glDrawElementsInstancedBaseVertex(%s, %d, %s, %p, %d; %d)\n",
1079 _mesa_lookup_enum_by_nr(mode), count,
1080 _mesa_lookup_enum_by_nr(type), indices,
1081 numInstances, basevertex);
1082
1083 if (!_mesa_validate_DrawElementsInstanced(ctx, mode, count, type, indices,
1084 numInstances, basevertex))
1085 return;
1086
1087 vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, ~0, ~0,
1088 count, type, indices, basevertex, numInstances);
1089 }
1090
1091
1092 /**
1093 * Inner support for both _mesa_MultiDrawElements() and
1094 * _mesa_MultiDrawRangeElements().
1095 * This does the actual rendering after we've checked array indexes, etc.
1096 */
1097 static void
1098 vbo_validated_multidrawelements(struct gl_context *ctx, GLenum mode,
1099 const GLsizei *count, GLenum type,
1100 const GLvoid **indices, GLsizei primcount,
1101 const GLint *basevertex)
1102 {
1103 struct vbo_context *vbo = vbo_context(ctx);
1104 struct vbo_exec_context *exec = &vbo->exec;
1105 struct _mesa_index_buffer ib;
1106 struct _mesa_prim *prim;
1107 unsigned int index_type_size = 0;
1108 uintptr_t min_index_ptr, max_index_ptr;
1109 GLboolean fallback = GL_FALSE;
1110 int i;
1111
1112 if (primcount == 0)
1113 return;
1114
1115 FLUSH_CURRENT( ctx, 0 );
1116
1117 if (!_mesa_valid_to_render(ctx, "glMultiDrawElements")) {
1118 return;
1119 }
1120
1121 prim = calloc(1, primcount * sizeof(*prim));
1122 if (prim == NULL) {
1123 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glMultiDrawElements");
1124 return;
1125 }
1126
1127 /* Decide if we can do this all as one set of primitives sharing the
1128 * same index buffer, or if we have to reset the index pointer per
1129 * primitive.
1130 */
1131 bind_arrays( ctx );
1132
1133 /* check for dirty state again */
1134 if (ctx->NewState)
1135 _mesa_update_state( ctx );
1136
1137 switch (type) {
1138 case GL_UNSIGNED_INT:
1139 index_type_size = 4;
1140 break;
1141 case GL_UNSIGNED_SHORT:
1142 index_type_size = 2;
1143 break;
1144 case GL_UNSIGNED_BYTE:
1145 index_type_size = 1;
1146 break;
1147 default:
1148 assert(0);
1149 }
1150
1151 min_index_ptr = (uintptr_t)indices[0];
1152 max_index_ptr = 0;
1153 for (i = 0; i < primcount; i++) {
1154 min_index_ptr = MIN2(min_index_ptr, (uintptr_t)indices[i]);
1155 max_index_ptr = MAX2(max_index_ptr, (uintptr_t)indices[i] +
1156 index_type_size * count[i]);
1157 }
1158
1159 /* Check if we can handle this thing as a bunch of index offsets from the
1160 * same index pointer. If we can't, then we have to fall back to doing
1161 * a draw_prims per primitive.
1162 * Check that the difference between each prim's indexes is a multiple of
1163 * the index/element size.
1164 */
1165 if (index_type_size != 1) {
1166 for (i = 0; i < primcount; i++) {
1167 if ((((uintptr_t)indices[i] - min_index_ptr) % index_type_size) != 0) {
1168 fallback = GL_TRUE;
1169 break;
1170 }
1171 }
1172 }
1173
1174 /* If the index buffer isn't in a VBO, then treating the application's
1175 * subranges of the index buffer as one large index buffer may lead to
1176 * us reading unmapped memory.
1177 */
1178 if (!_mesa_is_bufferobj(ctx->Array.ElementArrayBufferObj))
1179 fallback = GL_TRUE;
1180
1181 if (!fallback) {
1182 ib.count = (max_index_ptr - min_index_ptr) / index_type_size;
1183 ib.type = type;
1184 ib.obj = ctx->Array.ElementArrayBufferObj;
1185 ib.ptr = (void *)min_index_ptr;
1186
1187 for (i = 0; i < primcount; i++) {
1188 prim[i].begin = (i == 0);
1189 prim[i].end = (i == primcount - 1);
1190 prim[i].weak = 0;
1191 prim[i].pad = 0;
1192 prim[i].mode = mode;
1193 prim[i].start = ((uintptr_t)indices[i] - min_index_ptr) / index_type_size;
1194 prim[i].count = count[i];
1195 prim[i].indexed = 1;
1196 prim[i].num_instances = 1;
1197 if (basevertex != NULL)
1198 prim[i].basevertex = basevertex[i];
1199 else
1200 prim[i].basevertex = 0;
1201 }
1202
1203 check_buffers_are_unmapped(exec->array.inputs);
1204 vbo->draw_prims(ctx, exec->array.inputs, prim, primcount, &ib,
1205 GL_FALSE, ~0, ~0);
1206 } else {
1207 /* render one prim at a time */
1208 for (i = 0; i < primcount; i++) {
1209 ib.count = count[i];
1210 ib.type = type;
1211 ib.obj = ctx->Array.ElementArrayBufferObj;
1212 ib.ptr = indices[i];
1213
1214 prim[0].begin = 1;
1215 prim[0].end = 1;
1216 prim[0].weak = 0;
1217 prim[0].pad = 0;
1218 prim[0].mode = mode;
1219 prim[0].start = 0;
1220 prim[0].count = count[i];
1221 prim[0].indexed = 1;
1222 prim[0].num_instances = 1;
1223 if (basevertex != NULL)
1224 prim[0].basevertex = basevertex[i];
1225 else
1226 prim[0].basevertex = 0;
1227
1228 check_buffers_are_unmapped(exec->array.inputs);
1229 vbo->draw_prims(ctx, exec->array.inputs, prim, 1, &ib,
1230 GL_FALSE, ~0, ~0);
1231 }
1232 }
1233
1234 free(prim);
1235 }
1236
1237
1238 static void GLAPIENTRY
1239 vbo_exec_MultiDrawElements(GLenum mode,
1240 const GLsizei *count, GLenum type,
1241 const GLvoid **indices,
1242 GLsizei primcount)
1243 {
1244 GET_CURRENT_CONTEXT(ctx);
1245 GLint i;
1246
1247 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
1248
1249 for (i = 0; i < primcount; i++) {
1250 if (!_mesa_validate_DrawElements(ctx, mode, count[i], type, indices[i],
1251 0))
1252 return;
1253 }
1254
1255 vbo_validated_multidrawelements(ctx, mode, count, type, indices, primcount,
1256 NULL);
1257 }
1258
1259
1260 static void GLAPIENTRY
1261 vbo_exec_MultiDrawElementsBaseVertex(GLenum mode,
1262 const GLsizei *count, GLenum type,
1263 const GLvoid **indices,
1264 GLsizei primcount,
1265 const GLsizei *basevertex)
1266 {
1267 GET_CURRENT_CONTEXT(ctx);
1268 GLint i;
1269
1270 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
1271
1272 for (i = 0; i < primcount; i++) {
1273 if (!_mesa_validate_DrawElements(ctx, mode, count[i], type, indices[i],
1274 basevertex[i]))
1275 return;
1276 }
1277
1278 vbo_validated_multidrawelements(ctx, mode, count, type, indices, primcount,
1279 basevertex);
1280 }
1281
1282
1283 /**
1284 * Plug in the immediate-mode vertex array drawing commands into the
1285 * givven vbo_exec_context object.
1286 */
1287 void
1288 vbo_exec_array_init( struct vbo_exec_context *exec )
1289 {
1290 exec->vtxfmt.DrawArrays = vbo_exec_DrawArrays;
1291 exec->vtxfmt.DrawElements = vbo_exec_DrawElements;
1292 exec->vtxfmt.DrawRangeElements = vbo_exec_DrawRangeElements;
1293 exec->vtxfmt.MultiDrawElementsEXT = vbo_exec_MultiDrawElements;
1294 exec->vtxfmt.DrawElementsBaseVertex = vbo_exec_DrawElementsBaseVertex;
1295 exec->vtxfmt.DrawRangeElementsBaseVertex = vbo_exec_DrawRangeElementsBaseVertex;
1296 exec->vtxfmt.MultiDrawElementsBaseVertex = vbo_exec_MultiDrawElementsBaseVertex;
1297 exec->vtxfmt.DrawArraysInstanced = vbo_exec_DrawArraysInstanced;
1298 exec->vtxfmt.DrawElementsInstanced = vbo_exec_DrawElementsInstanced;
1299 exec->vtxfmt.DrawElementsInstancedBaseVertex = vbo_exec_DrawElementsInstancedBaseVertex;
1300 }
1301
1302
1303 void
1304 vbo_exec_array_destroy( struct vbo_exec_context *exec )
1305 {
1306 /* nothing to do */
1307 }
1308
1309
1310
1311 /**
1312 * The following functions are only used for OpenGL ES 1/2 support.
1313 * And some aren't even supported (yet) in ES 1/2.
1314 */
1315
1316
1317 void GLAPIENTRY
1318 _mesa_DrawArrays(GLenum mode, GLint first, GLsizei count)
1319 {
1320 vbo_exec_DrawArrays(mode, first, count);
1321 }
1322
1323
1324 void GLAPIENTRY
1325 _mesa_DrawElements(GLenum mode, GLsizei count, GLenum type,
1326 const GLvoid *indices)
1327 {
1328 vbo_exec_DrawElements(mode, count, type, indices);
1329 }
1330
1331
1332 void GLAPIENTRY
1333 _mesa_DrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type,
1334 const GLvoid *indices, GLint basevertex)
1335 {
1336 vbo_exec_DrawElementsBaseVertex(mode, count, type, indices, basevertex);
1337 }
1338
1339
1340 void GLAPIENTRY
1341 _mesa_DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count,
1342 GLenum type, const GLvoid *indices)
1343 {
1344 vbo_exec_DrawRangeElements(mode, start, end, count, type, indices);
1345 }
1346
1347
1348 void GLAPIENTRY
1349 _mesa_DrawRangeElementsBaseVertex(GLenum mode, GLuint start, GLuint end,
1350 GLsizei count, GLenum type,
1351 const GLvoid *indices, GLint basevertex)
1352 {
1353 vbo_exec_DrawRangeElementsBaseVertex(mode, start, end, count, type,
1354 indices, basevertex);
1355 }
1356
1357
1358 void GLAPIENTRY
1359 _mesa_MultiDrawElementsEXT(GLenum mode, const GLsizei *count, GLenum type,
1360 const GLvoid **indices, GLsizei primcount)
1361 {
1362 vbo_exec_MultiDrawElements(mode, count, type, indices, primcount);
1363 }
1364
1365
1366 void GLAPIENTRY
1367 _mesa_MultiDrawElementsBaseVertex(GLenum mode,
1368 const GLsizei *count, GLenum type,
1369 const GLvoid **indices, GLsizei primcount,
1370 const GLint *basevertex)
1371 {
1372 vbo_exec_MultiDrawElementsBaseVertex(mode, count, type, indices,
1373 primcount, basevertex);
1374 }