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