mesa: add KHR_no_error support to glMultiDraw*Indirect*()
[mesa.git] / src / mesa / vbo / vbo_exec_array.c
1 /**************************************************************************
2 *
3 * Copyright 2003 VMware, Inc.
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 VMWARE 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 <stdio.h>
30 #include "main/arrayobj.h"
31 #include "main/glheader.h"
32 #include "main/context.h"
33 #include "main/state.h"
34 #include "main/api_validate.h"
35 #include "main/dispatch.h"
36 #include "main/varray.h"
37 #include "main/bufferobj.h"
38 #include "main/enums.h"
39 #include "main/macros.h"
40 #include "main/transformfeedback.h"
41
42 #include "vbo_context.h"
43
44
45 /**
46 * Check that element 'j' of the array has reasonable data.
47 * Map VBO if needed.
48 * For debugging purposes; not normally used.
49 */
50 static void
51 check_array_data(struct gl_context *ctx, struct gl_vertex_array_object *vao,
52 GLuint attrib, GLuint j)
53 {
54 const struct gl_array_attributes *array = &vao->VertexAttrib[attrib];
55 if (array->Enabled) {
56 const struct gl_vertex_buffer_binding *binding =
57 &vao->BufferBinding[array->BufferBindingIndex];
58 struct gl_buffer_object *bo = binding->BufferObj;
59 const void *data = array->Ptr;
60 if (_mesa_is_bufferobj(bo)) {
61 if (!bo->Mappings[MAP_INTERNAL].Pointer) {
62 /* need to map now */
63 bo->Mappings[MAP_INTERNAL].Pointer =
64 ctx->Driver.MapBufferRange(ctx, 0, bo->Size,
65 GL_MAP_READ_BIT, bo, MAP_INTERNAL);
66 }
67 data = ADD_POINTERS(_mesa_vertex_attrib_address(array, binding),
68 bo->Mappings[MAP_INTERNAL].Pointer);
69 }
70 switch (array->Type) {
71 case GL_FLOAT:
72 {
73 GLfloat *f = (GLfloat *) ((GLubyte *) data + binding->Stride * j);
74 GLint k;
75 for (k = 0; k < array->Size; k++) {
76 if (IS_INF_OR_NAN(f[k]) || f[k] >= 1.0e20F || f[k] <= -1.0e10F) {
77 printf("Bad array data:\n");
78 printf(" Element[%u].%u = %f\n", j, k, f[k]);
79 printf(" Array %u at %p\n", attrib, (void *) array);
80 printf(" Type 0x%x, Size %d, Stride %d\n",
81 array->Type, array->Size, binding->Stride);
82 printf(" Address/offset %p in Buffer Object %u\n",
83 array->Ptr, bo->Name);
84 f[k] = 1.0F; /* XXX replace the bad value! */
85 }
86 /*assert(!IS_INF_OR_NAN(f[k])); */
87 }
88 }
89 break;
90 default:
91 ;
92 }
93 }
94 }
95
96
97 /**
98 * Unmap the buffer object referenced by given array, if mapped.
99 */
100 static void
101 unmap_array_buffer(struct gl_context *ctx, struct gl_vertex_array_object *vao,
102 GLuint attrib)
103 {
104 const struct gl_array_attributes *array = &vao->VertexAttrib[attrib];
105 if (array->Enabled) {
106 const struct gl_vertex_buffer_binding *binding =
107 &vao->BufferBinding[array->BufferBindingIndex];
108 struct gl_buffer_object *bo = binding->BufferObj;
109 if (_mesa_is_bufferobj(bo) && _mesa_bufferobj_mapped(bo, MAP_INTERNAL)) {
110 ctx->Driver.UnmapBuffer(ctx, bo, MAP_INTERNAL);
111 }
112 }
113 }
114
115
116 /**
117 * Examine the array's data for NaNs, etc.
118 * For debug purposes; not normally used.
119 */
120 static void
121 check_draw_elements_data(struct gl_context *ctx, GLsizei count,
122 GLenum elemType, const void *elements,
123 GLint basevertex)
124 {
125 struct gl_vertex_array_object *vao = ctx->Array.VAO;
126 const void *elemMap;
127 GLint i;
128 GLuint k;
129
130 if (_mesa_is_bufferobj(vao->IndexBufferObj)) {
131 elemMap = ctx->Driver.MapBufferRange(ctx, 0,
132 vao->IndexBufferObj->Size,
133 GL_MAP_READ_BIT,
134 vao->IndexBufferObj, MAP_INTERNAL);
135 elements = ADD_POINTERS(elements, elemMap);
136 }
137
138 for (i = 0; i < count; i++) {
139 GLuint j;
140
141 /* j = element[i] */
142 switch (elemType) {
143 case GL_UNSIGNED_BYTE:
144 j = ((const GLubyte *) elements)[i];
145 break;
146 case GL_UNSIGNED_SHORT:
147 j = ((const GLushort *) elements)[i];
148 break;
149 case GL_UNSIGNED_INT:
150 j = ((const GLuint *) elements)[i];
151 break;
152 default:
153 assert(0);
154 }
155
156 /* check element j of each enabled array */
157 for (k = 0; k < VERT_ATTRIB_MAX; k++) {
158 check_array_data(ctx, vao, k, j);
159 }
160 }
161
162 if (_mesa_is_bufferobj(vao->IndexBufferObj)) {
163 ctx->Driver.UnmapBuffer(ctx, vao->IndexBufferObj, MAP_INTERNAL);
164 }
165
166 for (k = 0; k < VERT_ATTRIB_MAX; k++) {
167 unmap_array_buffer(ctx, vao, k);
168 }
169 }
170
171
172 /**
173 * Check array data, looking for NaNs, etc.
174 */
175 static void
176 check_draw_arrays_data(struct gl_context *ctx, GLint start, GLsizei count)
177 {
178 /* TO DO */
179 }
180
181
182 /**
183 * Check if we should skip the draw call even after validation was successful.
184 */
185 static bool
186 skip_validated_draw(struct gl_context *ctx)
187 {
188 switch (ctx->API) {
189 case API_OPENGLES2:
190 /* For ES2, we can draw if we have a vertex program/shader). */
191 return ctx->VertexProgram._Current == NULL;
192
193 case API_OPENGLES:
194 /* For OpenGL ES, only draw if we have vertex positions
195 */
196 if (ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POS].Enabled)
197 return false;
198 break;
199
200 case API_OPENGL_CORE:
201 /* Section 7.3 (Program Objects) of the OpenGL 4.5 Core Profile spec
202 * says:
203 *
204 * "If there is no active program for the vertex or fragment shader
205 * stages, the results of vertex and/or fragment processing will be
206 * undefined. However, this is not an error."
207 *
208 * The fragment shader is not tested here because other state (e.g.,
209 * GL_RASTERIZER_DISCARD) affects whether or not we actually care.
210 */
211 return ctx->VertexProgram._Current == NULL;
212
213 case API_OPENGL_COMPAT:
214 if (ctx->VertexProgram._Current != NULL) {
215 /* Draw regardless of whether or not we have any vertex arrays.
216 * (Ex: could draw a point using a constant vertex pos)
217 */
218 return false;
219 } else {
220 /* Draw if we have vertex positions (GL_VERTEX_ARRAY or generic
221 * array [0]).
222 */
223 return (!ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POS].Enabled &&
224 !ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_GENERIC0].Enabled);
225 }
226 break;
227
228 default:
229 unreachable("Invalid API value in check_valid_to_render()");
230 }
231
232 return false;
233 }
234
235
236 /**
237 * Print info/data for glDrawArrays(), for debugging.
238 */
239 static void
240 print_draw_arrays(struct gl_context *ctx,
241 GLenum mode, GLint start, GLsizei count)
242 {
243 const struct gl_vertex_array_object *vao = ctx->Array.VAO;
244
245 printf("vbo_exec_DrawArrays(mode 0x%x, start %d, count %d):\n",
246 mode, start, count);
247
248 unsigned i;
249 for (i = 0; i < VERT_ATTRIB_MAX; ++i) {
250 const struct gl_array_attributes *array = &vao->VertexAttrib[i];
251 if (!array->Enabled)
252 continue;
253
254 const struct gl_vertex_buffer_binding *binding =
255 &vao->BufferBinding[array->BufferBindingIndex];
256 struct gl_buffer_object *bufObj = binding->BufferObj;
257
258 printf("attr %s: size %d stride %d enabled %d "
259 "ptr %p Bufobj %u\n",
260 gl_vert_attrib_name((gl_vert_attrib) i),
261 array->Size, binding->Stride, array->Enabled,
262 array->Ptr, bufObj->Name);
263
264 if (_mesa_is_bufferobj(bufObj)) {
265 GLubyte *p = ctx->Driver.MapBufferRange(ctx, 0, bufObj->Size,
266 GL_MAP_READ_BIT, bufObj,
267 MAP_INTERNAL);
268 int offset = (int) (GLintptr)
269 _mesa_vertex_attrib_address(array, binding);
270 float *f = (float *) (p + offset);
271 int *k = (int *) f;
272 int i;
273 int n = (count * binding->Stride) / 4;
274 if (n > 32)
275 n = 32;
276 printf(" Data at offset %d:\n", offset);
277 for (i = 0; i < n; i++) {
278 printf(" float[%d] = 0x%08x %f\n", i, k[i], f[i]);
279 }
280 ctx->Driver.UnmapBuffer(ctx, bufObj, MAP_INTERNAL);
281 }
282 }
283 }
284
285
286 /**
287 * Set the vbo->exec->inputs[] pointers to point to the enabled
288 * vertex arrays. This depends on the current vertex program/shader
289 * being executed because of whether or not generic vertex arrays
290 * alias the conventional vertex arrays.
291 * For arrays that aren't enabled, we set the input[attrib] pointer
292 * to point at a zero-stride current value "array".
293 */
294 static void
295 recalculate_input_bindings(struct gl_context *ctx)
296 {
297 struct vbo_context *vbo = vbo_context(ctx);
298 struct vbo_exec_context *exec = &vbo->exec;
299 const struct gl_array_attributes *array = ctx->Array.VAO->VertexAttrib;
300 struct gl_vertex_array *vertexAttrib = ctx->Array.VAO->_VertexAttrib;
301 const struct gl_vertex_array **inputs = &exec->array.inputs[0];
302 GLbitfield64 const_inputs = 0x0;
303 GLuint i;
304
305 switch (get_program_mode(ctx)) {
306 case VP_NONE:
307 /* When no vertex program is active (or the vertex program is generated
308 * from fixed-function state). We put the material values into the
309 * generic slots. This is the only situation where material values
310 * are available as per-vertex attributes.
311 */
312 for (i = 0; i < VERT_ATTRIB_FF_MAX; i++) {
313 if (array[VERT_ATTRIB_FF(i)].Enabled)
314 inputs[i] = &vertexAttrib[VERT_ATTRIB_FF(i)];
315 else {
316 inputs[i] = &vbo->currval[VBO_ATTRIB_POS + i];
317 const_inputs |= VERT_BIT(i);
318 }
319 }
320
321 for (i = 0; i < MAT_ATTRIB_MAX; i++) {
322 inputs[VERT_ATTRIB_GENERIC(i)] =
323 &vbo->currval[VBO_ATTRIB_MAT_FRONT_AMBIENT + i];
324 const_inputs |= VERT_BIT_GENERIC(i);
325 }
326
327 /* Could use just about anything, just to fill in the empty
328 * slots:
329 */
330 for (i = MAT_ATTRIB_MAX; i < VERT_ATTRIB_GENERIC_MAX; i++) {
331 inputs[VERT_ATTRIB_GENERIC(i)] =
332 &vbo->currval[VBO_ATTRIB_GENERIC0 + i];
333 const_inputs |= VERT_BIT_GENERIC(i);
334 }
335 break;
336
337 case VP_ARB:
338 /* There are no shaders in OpenGL ES 1.x, so this code path should be
339 * impossible to reach. The meta code is careful to not use shaders in
340 * ES1.
341 */
342 assert(ctx->API != API_OPENGLES);
343
344 /* In the compatibility profile of desktop OpenGL, the generic[0]
345 * attribute array aliases and overrides the legacy position array.
346 * Otherwise, legacy attributes available in the legacy slots,
347 * generic attributes in the generic slots and materials are not
348 * available as per-vertex attributes.
349 *
350 * In all other APIs, only the generic attributes exist, and none of the
351 * slots are considered "magic."
352 */
353 if (ctx->API == API_OPENGL_COMPAT) {
354 if (array[VERT_ATTRIB_GENERIC0].Enabled)
355 inputs[0] = &vertexAttrib[VERT_ATTRIB_GENERIC0];
356 else if (array[VERT_ATTRIB_POS].Enabled)
357 inputs[0] = &vertexAttrib[VERT_ATTRIB_POS];
358 else {
359 inputs[0] = &vbo->currval[VBO_ATTRIB_POS];
360 const_inputs |= VERT_BIT_POS;
361 }
362
363 for (i = 1; i < VERT_ATTRIB_FF_MAX; i++) {
364 if (array[VERT_ATTRIB_FF(i)].Enabled)
365 inputs[i] = &vertexAttrib[VERT_ATTRIB_FF(i)];
366 else {
367 inputs[i] = &vbo->currval[VBO_ATTRIB_POS + i];
368 const_inputs |= VERT_BIT_FF(i);
369 }
370 }
371
372 for (i = 1; i < VERT_ATTRIB_GENERIC_MAX; i++) {
373 if (array[VERT_ATTRIB_GENERIC(i)].Enabled)
374 inputs[VERT_ATTRIB_GENERIC(i)] =
375 &vertexAttrib[VERT_ATTRIB_GENERIC(i)];
376 else {
377 inputs[VERT_ATTRIB_GENERIC(i)] =
378 &vbo->currval[VBO_ATTRIB_GENERIC0 + i];
379 const_inputs |= VERT_BIT_GENERIC(i);
380 }
381 }
382
383 inputs[VERT_ATTRIB_GENERIC0] = inputs[0];
384 } else {
385 /* Other parts of the code assume that inputs[0] through
386 * inputs[VERT_ATTRIB_FF_MAX] will be non-NULL. However, in OpenGL
387 * ES 2.0+ or OpenGL core profile, none of these arrays should ever
388 * be enabled.
389 */
390 for (i = 0; i < VERT_ATTRIB_FF_MAX; i++) {
391 assert(!array[VERT_ATTRIB_FF(i)].Enabled);
392
393 inputs[i] = &vbo->currval[VBO_ATTRIB_POS + i];
394 const_inputs |= VERT_BIT_FF(i);
395 }
396
397 for (i = 0; i < VERT_ATTRIB_GENERIC_MAX; i++) {
398 if (array[VERT_ATTRIB_GENERIC(i)].Enabled)
399 inputs[VERT_ATTRIB_GENERIC(i)] =
400 &vertexAttrib[VERT_ATTRIB_GENERIC(i)];
401 else {
402 inputs[VERT_ATTRIB_GENERIC(i)] =
403 &vbo->currval[VBO_ATTRIB_GENERIC0 + i];
404 const_inputs |= VERT_BIT_GENERIC(i);
405 }
406 }
407 }
408
409 break;
410 }
411
412 _mesa_set_varying_vp_inputs(ctx, VERT_BIT_ALL & (~const_inputs));
413 ctx->NewDriverState |= ctx->DriverFlags.NewArray;
414 }
415
416
417 /**
418 * Examine the enabled vertex arrays to set the exec->array.inputs[] values.
419 * These will point to the arrays to actually use for drawing. Some will
420 * be user-provided arrays, other will be zero-stride const-valued arrays.
421 * Note that this might set the _NEW_VARYING_VP_INPUTS dirty flag so state
422 * validation must be done after this call.
423 */
424 void
425 vbo_bind_arrays(struct gl_context *ctx)
426 {
427 struct vbo_context *vbo = vbo_context(ctx);
428 struct vbo_exec_context *exec = &vbo->exec;
429
430 vbo_draw_method(vbo, DRAW_ARRAYS);
431
432 if (exec->array.recalculate_inputs) {
433 recalculate_input_bindings(ctx);
434 exec->array.recalculate_inputs = GL_FALSE;
435
436 /* Again... because we may have changed the bitmask of per-vertex varying
437 * attributes. If we regenerate the fixed-function vertex program now
438 * we may be able to prune down the number of vertex attributes which we
439 * need in the shader.
440 */
441 if (ctx->NewState) {
442 /* Setting "validating" to TRUE prevents _mesa_update_state from
443 * invalidating what we just did.
444 */
445 exec->validating = GL_TRUE;
446 _mesa_update_state(ctx);
447 exec->validating = GL_FALSE;
448 }
449 }
450 }
451
452
453 /**
454 * Helper function called by the other DrawArrays() functions below.
455 * This is where we handle primitive restart for drawing non-indexed
456 * arrays. If primitive restart is enabled, it typically means
457 * splitting one DrawArrays() into two.
458 */
459 static void
460 vbo_draw_arrays(struct gl_context *ctx, GLenum mode, GLint start,
461 GLsizei count, GLuint numInstances, GLuint baseInstance,
462 GLuint drawID)
463 {
464 struct vbo_context *vbo = vbo_context(ctx);
465 struct _mesa_prim prim;
466
467 if (skip_validated_draw(ctx))
468 return;
469
470 vbo_bind_arrays(ctx);
471
472 /* OpenGL 4.5 says that primitive restart is ignored with non-indexed
473 * draws.
474 */
475 memset(&prim, 0, sizeof(prim));
476 prim.begin = 1;
477 prim.end = 1;
478 prim.mode = mode;
479 prim.num_instances = numInstances;
480 prim.base_instance = baseInstance;
481 prim.draw_id = drawID;
482 prim.is_indirect = 0;
483 prim.start = start;
484 prim.count = count;
485
486 vbo->draw_prims(ctx, &prim, 1, NULL,
487 GL_TRUE, start, start + count - 1, NULL, 0, NULL);
488
489 if (MESA_DEBUG_FLAGS & DEBUG_ALWAYS_FLUSH) {
490 _mesa_flush(ctx);
491 }
492 }
493
494
495 /**
496 * Execute a glRectf() function.
497 */
498 static void GLAPIENTRY
499 vbo_exec_Rectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
500 {
501 GET_CURRENT_CONTEXT(ctx);
502 ASSERT_OUTSIDE_BEGIN_END(ctx);
503
504 CALL_Begin(GET_DISPATCH(), (GL_QUADS));
505 CALL_Vertex2f(GET_DISPATCH(), (x1, y1));
506 CALL_Vertex2f(GET_DISPATCH(), (x2, y1));
507 CALL_Vertex2f(GET_DISPATCH(), (x2, y2));
508 CALL_Vertex2f(GET_DISPATCH(), (x1, y2));
509 CALL_End(GET_DISPATCH(), ());
510 }
511
512
513 static void GLAPIENTRY
514 vbo_exec_EvalMesh1(GLenum mode, GLint i1, GLint i2)
515 {
516 GET_CURRENT_CONTEXT(ctx);
517 GLint i;
518 GLfloat u, du;
519 GLenum prim;
520
521 switch (mode) {
522 case GL_POINT:
523 prim = GL_POINTS;
524 break;
525 case GL_LINE:
526 prim = GL_LINE_STRIP;
527 break;
528 default:
529 _mesa_error(ctx, GL_INVALID_ENUM, "glEvalMesh1(mode)");
530 return;
531 }
532
533 /* No effect if vertex maps disabled.
534 */
535 if (!ctx->Eval.Map1Vertex4 && !ctx->Eval.Map1Vertex3)
536 return;
537
538 du = ctx->Eval.MapGrid1du;
539 u = ctx->Eval.MapGrid1u1 + i1 * du;
540
541 CALL_Begin(GET_DISPATCH(), (prim));
542 for (i = i1; i <= i2; i++, u += du) {
543 CALL_EvalCoord1f(GET_DISPATCH(), (u));
544 }
545 CALL_End(GET_DISPATCH(), ());
546 }
547
548
549 static void GLAPIENTRY
550 vbo_exec_EvalMesh2(GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2)
551 {
552 GET_CURRENT_CONTEXT(ctx);
553 GLfloat u, du, v, dv, v1, u1;
554 GLint i, j;
555
556 switch (mode) {
557 case GL_POINT:
558 case GL_LINE:
559 case GL_FILL:
560 break;
561 default:
562 _mesa_error(ctx, GL_INVALID_ENUM, "glEvalMesh2(mode)");
563 return;
564 }
565
566 /* No effect if vertex maps disabled.
567 */
568 if (!ctx->Eval.Map2Vertex4 && !ctx->Eval.Map2Vertex3)
569 return;
570
571 du = ctx->Eval.MapGrid2du;
572 dv = ctx->Eval.MapGrid2dv;
573 v1 = ctx->Eval.MapGrid2v1 + j1 * dv;
574 u1 = ctx->Eval.MapGrid2u1 + i1 * du;
575
576 switch (mode) {
577 case GL_POINT:
578 CALL_Begin(GET_DISPATCH(), (GL_POINTS));
579 for (v = v1, j = j1; j <= j2; j++, v += dv) {
580 for (u = u1, i = i1; i <= i2; i++, u += du) {
581 CALL_EvalCoord2f(GET_DISPATCH(), (u, v));
582 }
583 }
584 CALL_End(GET_DISPATCH(), ());
585 break;
586 case GL_LINE:
587 for (v = v1, j = j1; j <= j2; j++, v += dv) {
588 CALL_Begin(GET_DISPATCH(), (GL_LINE_STRIP));
589 for (u = u1, i = i1; i <= i2; i++, u += du) {
590 CALL_EvalCoord2f(GET_DISPATCH(), (u, v));
591 }
592 CALL_End(GET_DISPATCH(), ());
593 }
594 for (u = u1, i = i1; i <= i2; i++, u += du) {
595 CALL_Begin(GET_DISPATCH(), (GL_LINE_STRIP));
596 for (v = v1, j = j1; j <= j2; j++, v += dv) {
597 CALL_EvalCoord2f(GET_DISPATCH(), (u, v));
598 }
599 CALL_End(GET_DISPATCH(), ());
600 }
601 break;
602 case GL_FILL:
603 for (v = v1, j = j1; j < j2; j++, v += dv) {
604 CALL_Begin(GET_DISPATCH(), (GL_TRIANGLE_STRIP));
605 for (u = u1, i = i1; i <= i2; i++, u += du) {
606 CALL_EvalCoord2f(GET_DISPATCH(), (u, v));
607 CALL_EvalCoord2f(GET_DISPATCH(), (u, v + dv));
608 }
609 CALL_End(GET_DISPATCH(), ());
610 }
611 break;
612 }
613 }
614
615
616 /**
617 * Called from glDrawArrays when in immediate mode (not display list mode).
618 */
619 static void GLAPIENTRY
620 vbo_exec_DrawArrays(GLenum mode, GLint start, GLsizei count)
621 {
622 GET_CURRENT_CONTEXT(ctx);
623
624 if (MESA_VERBOSE & VERBOSE_DRAW)
625 _mesa_debug(ctx, "glDrawArrays(%s, %d, %d)\n",
626 _mesa_enum_to_string(mode), start, count);
627
628 if (_mesa_is_no_error_enabled(ctx)) {
629 FLUSH_CURRENT(ctx, 0);
630
631 if (ctx->NewState)
632 _mesa_update_state(ctx);
633 } else {
634 if (!_mesa_validate_DrawArrays(ctx, mode, count))
635 return;
636 }
637
638 if (0)
639 check_draw_arrays_data(ctx, start, count);
640
641 vbo_draw_arrays(ctx, mode, start, count, 1, 0, 0);
642
643 if (0)
644 print_draw_arrays(ctx, mode, start, count);
645 }
646
647
648 /**
649 * Called from glDrawArraysInstanced when in immediate mode (not
650 * display list mode).
651 */
652 static void GLAPIENTRY
653 vbo_exec_DrawArraysInstanced(GLenum mode, GLint start, GLsizei count,
654 GLsizei numInstances)
655 {
656 GET_CURRENT_CONTEXT(ctx);
657
658 if (MESA_VERBOSE & VERBOSE_DRAW)
659 _mesa_debug(ctx, "glDrawArraysInstanced(%s, %d, %d, %d)\n",
660 _mesa_enum_to_string(mode), start, count, numInstances);
661
662
663 if (_mesa_is_no_error_enabled(ctx)) {
664 FLUSH_CURRENT(ctx, 0);
665
666 if (ctx->NewState)
667 _mesa_update_state(ctx);
668 } else {
669 if (!_mesa_validate_DrawArraysInstanced(ctx, mode, start, count,
670 numInstances))
671 return;
672 }
673
674 if (0)
675 check_draw_arrays_data(ctx, start, count);
676
677 vbo_draw_arrays(ctx, mode, start, count, numInstances, 0, 0);
678
679 if (0)
680 print_draw_arrays(ctx, mode, start, count);
681 }
682
683
684 /**
685 * Called from glDrawArraysInstancedBaseInstance when in immediate mode.
686 */
687 static void GLAPIENTRY
688 vbo_exec_DrawArraysInstancedBaseInstance(GLenum mode, GLint first,
689 GLsizei count, GLsizei numInstances,
690 GLuint baseInstance)
691 {
692 GET_CURRENT_CONTEXT(ctx);
693
694 if (MESA_VERBOSE & VERBOSE_DRAW)
695 _mesa_debug(ctx,
696 "glDrawArraysInstancedBaseInstance(%s, %d, %d, %d, %d)\n",
697 _mesa_enum_to_string(mode), first, count,
698 numInstances, baseInstance);
699
700 if (_mesa_is_no_error_enabled(ctx)) {
701 FLUSH_CURRENT(ctx, 0);
702
703 if (ctx->NewState)
704 _mesa_update_state(ctx);
705 } else {
706 if (!_mesa_validate_DrawArraysInstanced(ctx, mode, first, count,
707 numInstances))
708 return;
709 }
710
711 if (0)
712 check_draw_arrays_data(ctx, first, count);
713
714 vbo_draw_arrays(ctx, mode, first, count, numInstances, baseInstance, 0);
715
716 if (0)
717 print_draw_arrays(ctx, mode, first, count);
718 }
719
720
721 /**
722 * Called from glMultiDrawArrays when in immediate mode.
723 */
724 static void GLAPIENTRY
725 vbo_exec_MultiDrawArrays(GLenum mode, const GLint *first,
726 const GLsizei *count, GLsizei primcount)
727 {
728 GET_CURRENT_CONTEXT(ctx);
729 GLint i;
730
731 if (MESA_VERBOSE & VERBOSE_DRAW)
732 _mesa_debug(ctx,
733 "glMultiDrawArrays(%s, %p, %p, %d)\n",
734 _mesa_enum_to_string(mode), first, count, primcount);
735
736 if (!_mesa_validate_MultiDrawArrays(ctx, mode, count, primcount))
737 return;
738
739 for (i = 0; i < primcount; i++) {
740 if (count[i] > 0) {
741 if (0)
742 check_draw_arrays_data(ctx, first[i], count[i]);
743
744 /* The GL_ARB_shader_draw_parameters spec adds the following after the
745 * pseudo-code describing glMultiDrawArrays:
746 *
747 * "The index of the draw (<i> in the above pseudo-code) may be
748 * read by a vertex shader as <gl_DrawIDARB>, as described in
749 * Section 11.1.3.9."
750 */
751 vbo_draw_arrays(ctx, mode, first[i], count[i], 1, 0, i);
752
753 if (0)
754 print_draw_arrays(ctx, mode, first[i], count[i]);
755 }
756 }
757 }
758
759
760
761 /**
762 * Map GL_ELEMENT_ARRAY_BUFFER and print contents.
763 * For debugging.
764 */
765 #if 0
766 static void
767 dump_element_buffer(struct gl_context *ctx, GLenum type)
768 {
769 const GLvoid *map =
770 ctx->Driver.MapBufferRange(ctx, 0,
771 ctx->Array.VAO->IndexBufferObj->Size,
772 GL_MAP_READ_BIT,
773 ctx->Array.VAO->IndexBufferObj,
774 MAP_INTERNAL);
775 switch (type) {
776 case GL_UNSIGNED_BYTE:
777 {
778 const GLubyte *us = (const GLubyte *) map;
779 GLint i;
780 for (i = 0; i < ctx->Array.VAO->IndexBufferObj->Size; i++) {
781 printf("%02x ", us[i]);
782 if (i % 32 == 31)
783 printf("\n");
784 }
785 printf("\n");
786 }
787 break;
788 case GL_UNSIGNED_SHORT:
789 {
790 const GLushort *us = (const GLushort *) map;
791 GLint i;
792 for (i = 0; i < ctx->Array.VAO->IndexBufferObj->Size / 2; i++) {
793 printf("%04x ", us[i]);
794 if (i % 16 == 15)
795 printf("\n");
796 }
797 printf("\n");
798 }
799 break;
800 case GL_UNSIGNED_INT:
801 {
802 const GLuint *us = (const GLuint *) map;
803 GLint i;
804 for (i = 0; i < ctx->Array.VAO->IndexBufferObj->Size / 4; i++) {
805 printf("%08x ", us[i]);
806 if (i % 8 == 7)
807 printf("\n");
808 }
809 printf("\n");
810 }
811 break;
812 default:
813 ;
814 }
815
816 ctx->Driver.UnmapBuffer(ctx, ctx->Array.VAO->IndexBufferObj, MAP_INTERNAL);
817 }
818 #endif
819
820
821 static bool
822 skip_draw_elements(struct gl_context *ctx, GLsizei count,
823 const GLvoid *indices)
824 {
825 if (count == 0)
826 return true;
827
828 /* Not using a VBO for indices, so avoid NULL pointer derefs later.
829 */
830 if (!_mesa_is_bufferobj(ctx->Array.VAO->IndexBufferObj) && indices == NULL)
831 return true;
832
833 if (skip_validated_draw(ctx))
834 return true;
835
836 return false;
837 }
838
839
840 /**
841 * Inner support for both _mesa_DrawElements and _mesa_DrawRangeElements.
842 * Do the rendering for a glDrawElements or glDrawRangeElements call after
843 * we've validated buffer bounds, etc.
844 */
845 static void
846 vbo_validated_drawrangeelements(struct gl_context *ctx, GLenum mode,
847 GLboolean index_bounds_valid,
848 GLuint start, GLuint end,
849 GLsizei count, GLenum type,
850 const GLvoid * indices,
851 GLint basevertex, GLuint numInstances,
852 GLuint baseInstance)
853 {
854 struct vbo_context *vbo = vbo_context(ctx);
855 struct _mesa_index_buffer ib;
856 struct _mesa_prim prim;
857
858 if (!index_bounds_valid) {
859 assert(start == 0u);
860 assert(end == ~0u);
861 }
862
863 if (skip_draw_elements(ctx, count, indices))
864 return;
865
866 vbo_bind_arrays(ctx);
867
868 ib.count = count;
869 ib.index_size = vbo_sizeof_ib_type(type);
870 ib.obj = ctx->Array.VAO->IndexBufferObj;
871 ib.ptr = indices;
872
873 prim.begin = 1;
874 prim.end = 1;
875 prim.weak = 0;
876 prim.pad = 0;
877 prim.mode = mode;
878 prim.start = 0;
879 prim.count = count;
880 prim.indexed = 1;
881 prim.is_indirect = 0;
882 prim.basevertex = basevertex;
883 prim.num_instances = numInstances;
884 prim.base_instance = baseInstance;
885 prim.draw_id = 0;
886
887 /* Need to give special consideration to rendering a range of
888 * indices starting somewhere above zero. Typically the
889 * application is issuing multiple DrawRangeElements() to draw
890 * successive primitives layed out linearly in the vertex arrays.
891 * Unless the vertex arrays are all in a VBO (or locked as with
892 * CVA), the OpenGL semantics imply that we need to re-read or
893 * re-upload the vertex data on each draw call.
894 *
895 * In the case of hardware tnl, we want to avoid starting the
896 * upload at zero, as it will mean every draw call uploads an
897 * increasing amount of not-used vertex data. Worse - in the
898 * software tnl module, all those vertices might be transformed and
899 * lit but never rendered.
900 *
901 * If we just upload or transform the vertices in start..end,
902 * however, the indices will be incorrect.
903 *
904 * At this level, we don't know exactly what the requirements of
905 * the backend are going to be, though it will likely boil down to
906 * either:
907 *
908 * 1) Do nothing, everything is in a VBO and is processed once
909 * only.
910 *
911 * 2) Adjust the indices and vertex arrays so that start becomes
912 * zero.
913 *
914 * Rather than doing anything here, I'll provide a helper function
915 * for the latter case elsewhere.
916 */
917
918 vbo->draw_prims(ctx, &prim, 1, &ib,
919 index_bounds_valid, start, end, NULL, 0, NULL);
920
921 if (MESA_DEBUG_FLAGS & DEBUG_ALWAYS_FLUSH) {
922 _mesa_flush(ctx);
923 }
924 }
925
926
927 /**
928 * Called by glDrawRangeElementsBaseVertex() in immediate mode.
929 */
930 static void GLAPIENTRY
931 vbo_exec_DrawRangeElementsBaseVertex(GLenum mode, GLuint start, GLuint end,
932 GLsizei count, GLenum type,
933 const GLvoid * indices, GLint basevertex)
934 {
935 static GLuint warnCount = 0;
936 GLboolean index_bounds_valid = GL_TRUE;
937
938 /* This is only useful to catch invalid values in the "end" parameter
939 * like ~0.
940 */
941 GLuint max_element = 2 * 1000 * 1000 * 1000; /* just a big number */
942
943 GET_CURRENT_CONTEXT(ctx);
944
945 if (MESA_VERBOSE & VERBOSE_DRAW)
946 _mesa_debug(ctx,
947 "glDrawRangeElementsBaseVertex(%s, %u, %u, %d, %s, %p, %d)\n",
948 _mesa_enum_to_string(mode), start, end, count,
949 _mesa_enum_to_string(type), indices, basevertex);
950
951 if (_mesa_is_no_error_enabled(ctx)) {
952 FLUSH_CURRENT(ctx, 0);
953
954 if (ctx->NewState)
955 _mesa_update_state(ctx);
956 } else {
957 if (!_mesa_validate_DrawRangeElements(ctx, mode, start, end, count,
958 type, indices))
959 return;
960 }
961
962 if ((int) end + basevertex < 0 || start + basevertex >= max_element) {
963 /* The application requested we draw using a range of indices that's
964 * outside the bounds of the current VBO. This is invalid and appears
965 * to give undefined results. The safest thing to do is to simply
966 * ignore the range, in case the application botched their range tracking
967 * but did provide valid indices. Also issue a warning indicating that
968 * the application is broken.
969 */
970 if (warnCount++ < 10) {
971 _mesa_warning(ctx, "glDrawRangeElements(start %u, end %u, "
972 "basevertex %d, count %d, type 0x%x, indices=%p):\n"
973 "\trange is outside VBO bounds (max=%u); ignoring.\n"
974 "\tThis should be fixed in the application.",
975 start, end, basevertex, count, type, indices,
976 max_element - 1);
977 }
978 index_bounds_valid = GL_FALSE;
979 }
980
981 /* NOTE: It's important that 'end' is a reasonable value.
982 * in _tnl_draw_prims(), we use end to determine how many vertices
983 * to transform. If it's too large, we can unnecessarily split prims
984 * or we can read/write out of memory in several different places!
985 */
986
987 /* Catch/fix some potential user errors */
988 if (type == GL_UNSIGNED_BYTE) {
989 start = MIN2(start, 0xff);
990 end = MIN2(end, 0xff);
991 }
992 else if (type == GL_UNSIGNED_SHORT) {
993 start = MIN2(start, 0xffff);
994 end = MIN2(end, 0xffff);
995 }
996
997 if (0) {
998 printf("glDraw[Range]Elements{,BaseVertex}"
999 "(start %u, end %u, type 0x%x, count %d) ElemBuf %u, "
1000 "base %d\n",
1001 start, end, type, count,
1002 ctx->Array.VAO->IndexBufferObj->Name, basevertex);
1003 }
1004
1005 if ((int) start + basevertex < 0 || end + basevertex >= max_element)
1006 index_bounds_valid = GL_FALSE;
1007
1008 #if 0
1009 check_draw_elements_data(ctx, count, type, indices, basevertex);
1010 #else
1011 (void) check_draw_elements_data;
1012 #endif
1013
1014 if (!index_bounds_valid) {
1015 start = 0;
1016 end = ~0;
1017 }
1018
1019 vbo_validated_drawrangeelements(ctx, mode, index_bounds_valid, start, end,
1020 count, type, indices, basevertex, 1, 0);
1021 }
1022
1023
1024 /**
1025 * Called by glDrawRangeElements() in immediate mode.
1026 */
1027 static void GLAPIENTRY
1028 vbo_exec_DrawRangeElements(GLenum mode, GLuint start, GLuint end,
1029 GLsizei count, GLenum type, const GLvoid * indices)
1030 {
1031 if (MESA_VERBOSE & VERBOSE_DRAW) {
1032 GET_CURRENT_CONTEXT(ctx);
1033 _mesa_debug(ctx,
1034 "glDrawRangeElements(%s, %u, %u, %d, %s, %p)\n",
1035 _mesa_enum_to_string(mode), start, end, count,
1036 _mesa_enum_to_string(type), indices);
1037 }
1038
1039 vbo_exec_DrawRangeElementsBaseVertex(mode, start, end, count, type,
1040 indices, 0);
1041 }
1042
1043
1044 /**
1045 * Called by glDrawElements() in immediate mode.
1046 */
1047 static void GLAPIENTRY
1048 vbo_exec_DrawElements(GLenum mode, GLsizei count, GLenum type,
1049 const GLvoid * indices)
1050 {
1051 GET_CURRENT_CONTEXT(ctx);
1052
1053 if (MESA_VERBOSE & VERBOSE_DRAW)
1054 _mesa_debug(ctx, "glDrawElements(%s, %u, %s, %p)\n",
1055 _mesa_enum_to_string(mode), count,
1056 _mesa_enum_to_string(type), indices);
1057
1058 if (_mesa_is_no_error_enabled(ctx)) {
1059 FLUSH_CURRENT(ctx, 0);
1060
1061 if (ctx->NewState)
1062 _mesa_update_state(ctx);
1063 } else {
1064 if (!_mesa_validate_DrawElements(ctx, mode, count, type, indices))
1065 return;
1066 }
1067
1068 vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, 0, ~0,
1069 count, type, indices, 0, 1, 0);
1070 }
1071
1072
1073 /**
1074 * Called by glDrawElementsBaseVertex() in immediate mode.
1075 */
1076 static void GLAPIENTRY
1077 vbo_exec_DrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type,
1078 const GLvoid * indices, GLint basevertex)
1079 {
1080 GET_CURRENT_CONTEXT(ctx);
1081
1082 if (MESA_VERBOSE & VERBOSE_DRAW)
1083 _mesa_debug(ctx, "glDrawElements(%s, %u, %s, %p)\n",
1084 _mesa_enum_to_string(mode), count,
1085 _mesa_enum_to_string(type), indices);
1086
1087 if (_mesa_is_no_error_enabled(ctx)) {
1088 FLUSH_CURRENT(ctx, 0);
1089
1090 if (ctx->NewState)
1091 _mesa_update_state(ctx);
1092 } else {
1093 if (!_mesa_validate_DrawElements(ctx, mode, count, type, indices))
1094 return;
1095 }
1096
1097 vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, 0, ~0,
1098 count, type, indices, basevertex, 1, 0);
1099 }
1100
1101
1102 /**
1103 * Called by glDrawElementsInstanced() in immediate mode.
1104 */
1105 static void GLAPIENTRY
1106 vbo_exec_DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type,
1107 const GLvoid * indices, GLsizei numInstances)
1108 {
1109 GET_CURRENT_CONTEXT(ctx);
1110
1111 if (MESA_VERBOSE & VERBOSE_DRAW)
1112 _mesa_debug(ctx, "glDrawElements(%s, %u, %s, %p)\n",
1113 _mesa_enum_to_string(mode), count,
1114 _mesa_enum_to_string(type), indices);
1115
1116 if (_mesa_is_no_error_enabled(ctx)) {
1117 FLUSH_CURRENT(ctx, 0);
1118
1119 if (ctx->NewState)
1120 _mesa_update_state(ctx);
1121 } else {
1122 if (!_mesa_validate_DrawElementsInstanced(ctx, mode, count, type,
1123 indices, numInstances))
1124 return;
1125 }
1126
1127 vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, 0, ~0,
1128 count, type, indices, 0, numInstances, 0);
1129 }
1130
1131
1132 /**
1133 * Called by glDrawElementsInstancedBaseVertex() in immediate mode.
1134 */
1135 static void GLAPIENTRY
1136 vbo_exec_DrawElementsInstancedBaseVertex(GLenum mode, GLsizei count,
1137 GLenum type, const GLvoid * indices,
1138 GLsizei numInstances,
1139 GLint basevertex)
1140 {
1141 GET_CURRENT_CONTEXT(ctx);
1142
1143 if (MESA_VERBOSE & VERBOSE_DRAW)
1144 _mesa_debug(ctx,
1145 "glDrawElementsInstancedBaseVertex"
1146 "(%s, %d, %s, %p, %d; %d)\n",
1147 _mesa_enum_to_string(mode), count,
1148 _mesa_enum_to_string(type), indices,
1149 numInstances, basevertex);
1150
1151 if (_mesa_is_no_error_enabled(ctx)) {
1152 FLUSH_CURRENT(ctx, 0);
1153
1154 if (ctx->NewState)
1155 _mesa_update_state(ctx);
1156 } else {
1157 if (!_mesa_validate_DrawElementsInstanced(ctx, mode, count, type,
1158 indices, numInstances))
1159 return;
1160 }
1161
1162 vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, 0, ~0,
1163 count, type, indices,
1164 basevertex, numInstances, 0);
1165 }
1166
1167
1168 /**
1169 * Called by glDrawElementsInstancedBaseInstance() in immediate mode.
1170 */
1171 static void GLAPIENTRY
1172 vbo_exec_DrawElementsInstancedBaseInstance(GLenum mode, GLsizei count,
1173 GLenum type,
1174 const GLvoid *indices,
1175 GLsizei numInstances,
1176 GLuint baseInstance)
1177 {
1178 GET_CURRENT_CONTEXT(ctx);
1179
1180 if (MESA_VERBOSE & VERBOSE_DRAW)
1181 _mesa_debug(ctx,
1182 "glDrawElementsInstancedBaseInstance"
1183 "(%s, %d, %s, %p, %d, %d)\n",
1184 _mesa_enum_to_string(mode), count,
1185 _mesa_enum_to_string(type), indices,
1186 numInstances, baseInstance);
1187
1188 if (_mesa_is_no_error_enabled(ctx)) {
1189 FLUSH_CURRENT(ctx, 0);
1190
1191 if (ctx->NewState)
1192 _mesa_update_state(ctx);
1193 } else {
1194 if (!_mesa_validate_DrawElementsInstanced(ctx, mode, count, type,
1195 indices, numInstances))
1196 return;
1197 }
1198
1199 vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, 0, ~0,
1200 count, type, indices, 0, numInstances,
1201 baseInstance);
1202 }
1203
1204
1205 /**
1206 * Called by glDrawElementsInstancedBaseVertexBaseInstance() in immediate mode.
1207 */
1208 static void GLAPIENTRY
1209 vbo_exec_DrawElementsInstancedBaseVertexBaseInstance(GLenum mode,
1210 GLsizei count,
1211 GLenum type,
1212 const GLvoid *indices,
1213 GLsizei numInstances,
1214 GLint basevertex,
1215 GLuint baseInstance)
1216 {
1217 GET_CURRENT_CONTEXT(ctx);
1218
1219 if (MESA_VERBOSE & VERBOSE_DRAW)
1220 _mesa_debug(ctx,
1221 "glDrawElementsInstancedBaseVertexBaseInstance"
1222 "(%s, %d, %s, %p, %d, %d, %d)\n",
1223 _mesa_enum_to_string(mode), count,
1224 _mesa_enum_to_string(type), indices,
1225 numInstances, basevertex, baseInstance);
1226
1227 if (_mesa_is_no_error_enabled(ctx)) {
1228 FLUSH_CURRENT(ctx, 0);
1229
1230 if (ctx->NewState)
1231 _mesa_update_state(ctx);
1232 } else {
1233 if (!_mesa_validate_DrawElementsInstanced(ctx, mode, count, type,
1234 indices, numInstances))
1235 return;
1236 }
1237
1238 vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, 0, ~0,
1239 count, type, indices, basevertex,
1240 numInstances, baseInstance);
1241 }
1242
1243
1244 /**
1245 * Inner support for both _mesa_MultiDrawElements() and
1246 * _mesa_MultiDrawRangeElements().
1247 * This does the actual rendering after we've checked array indexes, etc.
1248 */
1249 static void
1250 vbo_validated_multidrawelements(struct gl_context *ctx, GLenum mode,
1251 const GLsizei *count, GLenum type,
1252 const GLvoid * const *indices,
1253 GLsizei primcount, const GLint *basevertex)
1254 {
1255 struct vbo_context *vbo = vbo_context(ctx);
1256 struct _mesa_index_buffer ib;
1257 struct _mesa_prim *prim;
1258 unsigned int index_type_size = vbo_sizeof_ib_type(type);
1259 uintptr_t min_index_ptr, max_index_ptr;
1260 GLboolean fallback = GL_FALSE;
1261 int i;
1262
1263 if (primcount == 0)
1264 return;
1265
1266 prim = calloc(primcount, sizeof(*prim));
1267 if (prim == NULL) {
1268 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glMultiDrawElements");
1269 return;
1270 }
1271
1272 vbo_bind_arrays(ctx);
1273
1274 min_index_ptr = (uintptr_t) indices[0];
1275 max_index_ptr = 0;
1276 for (i = 0; i < primcount; i++) {
1277 min_index_ptr = MIN2(min_index_ptr, (uintptr_t) indices[i]);
1278 max_index_ptr = MAX2(max_index_ptr, (uintptr_t) indices[i] +
1279 index_type_size * count[i]);
1280 }
1281
1282 /* Check if we can handle this thing as a bunch of index offsets from the
1283 * same index pointer. If we can't, then we have to fall back to doing
1284 * a draw_prims per primitive.
1285 * Check that the difference between each prim's indexes is a multiple of
1286 * the index/element size.
1287 */
1288 if (index_type_size != 1) {
1289 for (i = 0; i < primcount; i++) {
1290 if ((((uintptr_t) indices[i] - min_index_ptr) % index_type_size) !=
1291 0) {
1292 fallback = GL_TRUE;
1293 break;
1294 }
1295 }
1296 }
1297
1298 /* Draw primitives individually if one count is zero, so we can easily skip
1299 * that primitive.
1300 */
1301 for (i = 0; i < primcount; i++) {
1302 if (count[i] == 0) {
1303 fallback = GL_TRUE;
1304 break;
1305 }
1306 }
1307
1308 /* If the index buffer isn't in a VBO, then treating the application's
1309 * subranges of the index buffer as one large index buffer may lead to
1310 * us reading unmapped memory.
1311 */
1312 if (!_mesa_is_bufferobj(ctx->Array.VAO->IndexBufferObj))
1313 fallback = GL_TRUE;
1314
1315 if (!fallback) {
1316 ib.count = (max_index_ptr - min_index_ptr) / index_type_size;
1317 ib.index_size = vbo_sizeof_ib_type(type);
1318 ib.obj = ctx->Array.VAO->IndexBufferObj;
1319 ib.ptr = (void *) min_index_ptr;
1320
1321 for (i = 0; i < primcount; i++) {
1322 prim[i].begin = (i == 0);
1323 prim[i].end = (i == primcount - 1);
1324 prim[i].weak = 0;
1325 prim[i].pad = 0;
1326 prim[i].mode = mode;
1327 prim[i].start =
1328 ((uintptr_t) indices[i] - min_index_ptr) / index_type_size;
1329 prim[i].count = count[i];
1330 prim[i].indexed = 1;
1331 prim[i].num_instances = 1;
1332 prim[i].base_instance = 0;
1333 prim[i].draw_id = i;
1334 prim[i].is_indirect = 0;
1335 if (basevertex != NULL)
1336 prim[i].basevertex = basevertex[i];
1337 else
1338 prim[i].basevertex = 0;
1339 }
1340
1341 vbo->draw_prims(ctx, prim, primcount, &ib,
1342 false, 0, ~0, NULL, 0, NULL);
1343 }
1344 else {
1345 /* render one prim at a time */
1346 for (i = 0; i < primcount; i++) {
1347 if (count[i] == 0)
1348 continue;
1349 ib.count = count[i];
1350 ib.index_size = vbo_sizeof_ib_type(type);
1351 ib.obj = ctx->Array.VAO->IndexBufferObj;
1352 ib.ptr = indices[i];
1353
1354 prim[0].begin = 1;
1355 prim[0].end = 1;
1356 prim[0].weak = 0;
1357 prim[0].pad = 0;
1358 prim[0].mode = mode;
1359 prim[0].start = 0;
1360 prim[0].count = count[i];
1361 prim[0].indexed = 1;
1362 prim[0].num_instances = 1;
1363 prim[0].base_instance = 0;
1364 prim[0].draw_id = i;
1365 prim[0].is_indirect = 0;
1366 if (basevertex != NULL)
1367 prim[0].basevertex = basevertex[i];
1368 else
1369 prim[0].basevertex = 0;
1370
1371 vbo->draw_prims(ctx, prim, 1, &ib, false, 0, ~0, NULL, 0, NULL);
1372 }
1373 }
1374
1375 free(prim);
1376
1377 if (MESA_DEBUG_FLAGS & DEBUG_ALWAYS_FLUSH) {
1378 _mesa_flush(ctx);
1379 }
1380 }
1381
1382
1383 static void GLAPIENTRY
1384 vbo_exec_MultiDrawElements(GLenum mode,
1385 const GLsizei *count, GLenum type,
1386 const GLvoid * const *indices, GLsizei primcount)
1387 {
1388 GET_CURRENT_CONTEXT(ctx);
1389
1390 if (!_mesa_validate_MultiDrawElements(ctx, mode, count, type, indices,
1391 primcount))
1392 return;
1393
1394 if (skip_validated_draw(ctx))
1395 return;
1396
1397 vbo_validated_multidrawelements(ctx, mode, count, type, indices, primcount,
1398 NULL);
1399 }
1400
1401
1402 static void GLAPIENTRY
1403 vbo_exec_MultiDrawElementsBaseVertex(GLenum mode,
1404 const GLsizei *count, GLenum type,
1405 const GLvoid * const *indices,
1406 GLsizei primcount,
1407 const GLsizei *basevertex)
1408 {
1409 GET_CURRENT_CONTEXT(ctx);
1410
1411 if (_mesa_is_no_error_enabled(ctx)) {
1412 FLUSH_CURRENT(ctx, 0);
1413
1414 if (ctx->NewState)
1415 _mesa_update_state(ctx);
1416 } else {
1417 if (!_mesa_validate_MultiDrawElements(ctx, mode, count, type, indices,
1418 primcount))
1419 return;
1420 }
1421
1422 if (skip_validated_draw(ctx))
1423 return;
1424
1425 vbo_validated_multidrawelements(ctx, mode, count, type, indices, primcount,
1426 basevertex);
1427 }
1428
1429
1430 static void
1431 vbo_draw_transform_feedback(struct gl_context *ctx, GLenum mode,
1432 struct gl_transform_feedback_object *obj,
1433 GLuint stream, GLuint numInstances)
1434 {
1435 struct vbo_context *vbo = vbo_context(ctx);
1436 struct _mesa_prim prim;
1437
1438 if (!_mesa_validate_DrawTransformFeedback(ctx, mode, obj, stream,
1439 numInstances)) {
1440 return;
1441 }
1442
1443 if (ctx->Driver.GetTransformFeedbackVertexCount &&
1444 (ctx->Const.AlwaysUseGetTransformFeedbackVertexCount ||
1445 !_mesa_all_varyings_in_vbos(ctx->Array.VAO))) {
1446 GLsizei n =
1447 ctx->Driver.GetTransformFeedbackVertexCount(ctx, obj, stream);
1448 vbo_draw_arrays(ctx, mode, 0, n, numInstances, 0, 0);
1449 return;
1450 }
1451
1452 if (skip_validated_draw(ctx))
1453 return;
1454
1455 vbo_bind_arrays(ctx);
1456
1457 /* init most fields to zero */
1458 memset(&prim, 0, sizeof(prim));
1459 prim.begin = 1;
1460 prim.end = 1;
1461 prim.mode = mode;
1462 prim.num_instances = numInstances;
1463 prim.base_instance = 0;
1464 prim.is_indirect = 0;
1465
1466 /* Maybe we should do some primitive splitting for primitive restart
1467 * (like in DrawArrays), but we have no way to know how many vertices
1468 * will be rendered. */
1469
1470 vbo->draw_prims(ctx, &prim, 1, NULL, GL_FALSE, 0, ~0, obj, stream, NULL);
1471
1472 if (MESA_DEBUG_FLAGS & DEBUG_ALWAYS_FLUSH) {
1473 _mesa_flush(ctx);
1474 }
1475 }
1476
1477
1478 /**
1479 * Like DrawArrays, but take the count from a transform feedback object.
1480 * \param mode GL_POINTS, GL_LINES, GL_TRIANGLE_STRIP, etc.
1481 * \param name the transform feedback object
1482 * User still has to setup of the vertex attribute info with
1483 * glVertexPointer, glColorPointer, etc.
1484 * Part of GL_ARB_transform_feedback2.
1485 */
1486 static void GLAPIENTRY
1487 vbo_exec_DrawTransformFeedback(GLenum mode, GLuint name)
1488 {
1489 GET_CURRENT_CONTEXT(ctx);
1490 struct gl_transform_feedback_object *obj =
1491 _mesa_lookup_transform_feedback_object(ctx, name);
1492
1493 if (MESA_VERBOSE & VERBOSE_DRAW)
1494 _mesa_debug(ctx, "glDrawTransformFeedback(%s, %d)\n",
1495 _mesa_enum_to_string(mode), name);
1496
1497 vbo_draw_transform_feedback(ctx, mode, obj, 0, 1);
1498 }
1499
1500
1501 static void GLAPIENTRY
1502 vbo_exec_DrawTransformFeedbackStream(GLenum mode, GLuint name, GLuint stream)
1503 {
1504 GET_CURRENT_CONTEXT(ctx);
1505 struct gl_transform_feedback_object *obj =
1506 _mesa_lookup_transform_feedback_object(ctx, name);
1507
1508 if (MESA_VERBOSE & VERBOSE_DRAW)
1509 _mesa_debug(ctx, "glDrawTransformFeedbackStream(%s, %u, %u)\n",
1510 _mesa_enum_to_string(mode), name, stream);
1511
1512 vbo_draw_transform_feedback(ctx, mode, obj, stream, 1);
1513 }
1514
1515
1516 static void GLAPIENTRY
1517 vbo_exec_DrawTransformFeedbackInstanced(GLenum mode, GLuint name,
1518 GLsizei primcount)
1519 {
1520 GET_CURRENT_CONTEXT(ctx);
1521 struct gl_transform_feedback_object *obj =
1522 _mesa_lookup_transform_feedback_object(ctx, name);
1523
1524 if (MESA_VERBOSE & VERBOSE_DRAW)
1525 _mesa_debug(ctx, "glDrawTransformFeedbackInstanced(%s, %d)\n",
1526 _mesa_enum_to_string(mode), name);
1527
1528 vbo_draw_transform_feedback(ctx, mode, obj, 0, primcount);
1529 }
1530
1531
1532 static void GLAPIENTRY
1533 vbo_exec_DrawTransformFeedbackStreamInstanced(GLenum mode, GLuint name,
1534 GLuint stream,
1535 GLsizei primcount)
1536 {
1537 GET_CURRENT_CONTEXT(ctx);
1538 struct gl_transform_feedback_object *obj =
1539 _mesa_lookup_transform_feedback_object(ctx, name);
1540
1541 if (MESA_VERBOSE & VERBOSE_DRAW)
1542 _mesa_debug(ctx, "glDrawTransformFeedbackStreamInstanced"
1543 "(%s, %u, %u, %i)\n",
1544 _mesa_enum_to_string(mode), name, stream, primcount);
1545
1546 vbo_draw_transform_feedback(ctx, mode, obj, stream, primcount);
1547 }
1548
1549
1550 static void
1551 vbo_validated_drawarraysindirect(struct gl_context *ctx,
1552 GLenum mode, const GLvoid *indirect)
1553 {
1554 struct vbo_context *vbo = vbo_context(ctx);
1555
1556 vbo_bind_arrays(ctx);
1557
1558 vbo->draw_indirect_prims(ctx, mode,
1559 ctx->DrawIndirectBuffer, (GLsizeiptr) indirect,
1560 1 /* draw_count */ , 16 /* stride */ ,
1561 NULL, 0, NULL);
1562
1563 if (MESA_DEBUG_FLAGS & DEBUG_ALWAYS_FLUSH)
1564 _mesa_flush(ctx);
1565 }
1566
1567
1568 static void
1569 vbo_validated_multidrawarraysindirect(struct gl_context *ctx,
1570 GLenum mode,
1571 const GLvoid *indirect,
1572 GLsizei primcount, GLsizei stride)
1573 {
1574 struct vbo_context *vbo = vbo_context(ctx);
1575 GLsizeiptr offset = (GLsizeiptr) indirect;
1576
1577 if (primcount == 0)
1578 return;
1579
1580 vbo_bind_arrays(ctx);
1581
1582 vbo->draw_indirect_prims(ctx, mode, ctx->DrawIndirectBuffer, offset,
1583 primcount, stride, NULL, 0, NULL);
1584
1585 if (MESA_DEBUG_FLAGS & DEBUG_ALWAYS_FLUSH)
1586 _mesa_flush(ctx);
1587 }
1588
1589
1590 static void
1591 vbo_validated_drawelementsindirect(struct gl_context *ctx,
1592 GLenum mode, GLenum type,
1593 const GLvoid *indirect)
1594 {
1595 struct vbo_context *vbo = vbo_context(ctx);
1596 struct _mesa_index_buffer ib;
1597
1598 vbo_bind_arrays(ctx);
1599
1600 ib.count = 0; /* unknown */
1601 ib.index_size = vbo_sizeof_ib_type(type);
1602 ib.obj = ctx->Array.VAO->IndexBufferObj;
1603 ib.ptr = NULL;
1604
1605 vbo->draw_indirect_prims(ctx, mode,
1606 ctx->DrawIndirectBuffer, (GLsizeiptr) indirect,
1607 1 /* draw_count */ , 20 /* stride */ ,
1608 NULL, 0, &ib);
1609
1610 if (MESA_DEBUG_FLAGS & DEBUG_ALWAYS_FLUSH)
1611 _mesa_flush(ctx);
1612 }
1613
1614
1615 static void
1616 vbo_validated_multidrawelementsindirect(struct gl_context *ctx,
1617 GLenum mode, GLenum type,
1618 const GLvoid *indirect,
1619 GLsizei primcount, GLsizei stride)
1620 {
1621 struct vbo_context *vbo = vbo_context(ctx);
1622 struct _mesa_index_buffer ib;
1623 GLsizeiptr offset = (GLsizeiptr) indirect;
1624
1625 if (primcount == 0)
1626 return;
1627
1628 vbo_bind_arrays(ctx);
1629
1630 /* NOTE: IndexBufferObj is guaranteed to be a VBO. */
1631
1632 ib.count = 0; /* unknown */
1633 ib.index_size = vbo_sizeof_ib_type(type);
1634 ib.obj = ctx->Array.VAO->IndexBufferObj;
1635 ib.ptr = NULL;
1636
1637 vbo->draw_indirect_prims(ctx, mode,
1638 ctx->DrawIndirectBuffer, offset,
1639 primcount, stride, NULL, 0, &ib);
1640
1641 if (MESA_DEBUG_FLAGS & DEBUG_ALWAYS_FLUSH)
1642 _mesa_flush(ctx);
1643 }
1644
1645
1646 /**
1647 * Like [Multi]DrawArrays/Elements, but they take most arguments from
1648 * a buffer object.
1649 */
1650 static void GLAPIENTRY
1651 vbo_exec_DrawArraysIndirect(GLenum mode, const GLvoid *indirect)
1652 {
1653 GET_CURRENT_CONTEXT(ctx);
1654
1655 if (MESA_VERBOSE & VERBOSE_DRAW)
1656 _mesa_debug(ctx, "glDrawArraysIndirect(%s, %p)\n",
1657 _mesa_enum_to_string(mode), indirect);
1658
1659 if (_mesa_is_no_error_enabled(ctx)) {
1660 FLUSH_CURRENT(ctx, 0);
1661
1662 if (ctx->NewState)
1663 _mesa_update_state(ctx);
1664 } else {
1665 if (!_mesa_validate_DrawArraysIndirect(ctx, mode, indirect))
1666 return;
1667 }
1668
1669 if (skip_validated_draw(ctx))
1670 return;
1671
1672 vbo_validated_drawarraysindirect(ctx, mode, indirect);
1673 }
1674
1675
1676 static void GLAPIENTRY
1677 vbo_exec_DrawElementsIndirect(GLenum mode, GLenum type, const GLvoid *indirect)
1678 {
1679 GET_CURRENT_CONTEXT(ctx);
1680
1681 if (MESA_VERBOSE & VERBOSE_DRAW)
1682 _mesa_debug(ctx, "glDrawElementsIndirect(%s, %s, %p)\n",
1683 _mesa_enum_to_string(mode),
1684 _mesa_enum_to_string(type), indirect);
1685
1686 if (_mesa_is_no_error_enabled(ctx)) {
1687 FLUSH_CURRENT(ctx, 0);
1688
1689 if (ctx->NewState)
1690 _mesa_update_state(ctx);
1691 } else {
1692 if (!_mesa_validate_DrawElementsIndirect(ctx, mode, type, indirect))
1693 return;
1694 }
1695
1696 if (skip_validated_draw(ctx))
1697 return;
1698
1699 vbo_validated_drawelementsindirect(ctx, mode, type, indirect);
1700 }
1701
1702
1703 static void GLAPIENTRY
1704 vbo_exec_MultiDrawArraysIndirect(GLenum mode, const GLvoid *indirect,
1705 GLsizei primcount, GLsizei stride)
1706 {
1707 GET_CURRENT_CONTEXT(ctx);
1708
1709 if (MESA_VERBOSE & VERBOSE_DRAW)
1710 _mesa_debug(ctx, "glMultiDrawArraysIndirect(%s, %p, %i, %i)\n",
1711 _mesa_enum_to_string(mode), indirect, primcount, stride);
1712
1713 /* If <stride> is zero, the array elements are treated as tightly packed. */
1714 if (stride == 0)
1715 stride = 4 * sizeof(GLuint); /* sizeof(DrawArraysIndirectCommand) */
1716
1717 if (_mesa_is_no_error_enabled(ctx)) {
1718 FLUSH_CURRENT(ctx, 0);
1719
1720 if (ctx->NewState)
1721 _mesa_update_state(ctx);
1722 } else {
1723 if (!_mesa_validate_MultiDrawArraysIndirect(ctx, mode, indirect,
1724 primcount, stride))
1725 return;
1726 }
1727
1728 if (skip_validated_draw(ctx))
1729 return;
1730
1731 vbo_validated_multidrawarraysindirect(ctx, mode, indirect,
1732 primcount, stride);
1733 }
1734
1735
1736 static void GLAPIENTRY
1737 vbo_exec_MultiDrawElementsIndirect(GLenum mode, GLenum type,
1738 const GLvoid *indirect,
1739 GLsizei primcount, GLsizei stride)
1740 {
1741 GET_CURRENT_CONTEXT(ctx);
1742
1743 if (MESA_VERBOSE & VERBOSE_DRAW)
1744 _mesa_debug(ctx, "glMultiDrawElementsIndirect(%s, %s, %p, %i, %i)\n",
1745 _mesa_enum_to_string(mode),
1746 _mesa_enum_to_string(type), indirect, primcount, stride);
1747
1748 /* If <stride> is zero, the array elements are treated as tightly packed. */
1749 if (stride == 0)
1750 stride = 5 * sizeof(GLuint); /* sizeof(DrawElementsIndirectCommand) */
1751
1752 if (_mesa_is_no_error_enabled(ctx)) {
1753 FLUSH_CURRENT(ctx, 0);
1754
1755 if (ctx->NewState)
1756 _mesa_update_state(ctx);
1757 } else {
1758 if (!_mesa_validate_MultiDrawElementsIndirect(ctx, mode, type, indirect,
1759 primcount, stride))
1760 return;
1761 }
1762
1763 if (skip_validated_draw(ctx))
1764 return;
1765
1766 vbo_validated_multidrawelementsindirect(ctx, mode, type, indirect,
1767 primcount, stride);
1768 }
1769
1770
1771 static void
1772 vbo_validated_multidrawarraysindirectcount(struct gl_context *ctx,
1773 GLenum mode,
1774 GLintptr indirect,
1775 GLintptr drawcount,
1776 GLsizei maxdrawcount,
1777 GLsizei stride)
1778 {
1779 struct vbo_context *vbo = vbo_context(ctx);
1780 GLsizeiptr offset = indirect;
1781
1782 if (maxdrawcount == 0)
1783 return;
1784
1785 vbo_bind_arrays(ctx);
1786
1787 vbo->draw_indirect_prims(ctx, mode,
1788 ctx->DrawIndirectBuffer, offset,
1789 maxdrawcount, stride,
1790 ctx->ParameterBuffer, drawcount, NULL);
1791
1792 if (MESA_DEBUG_FLAGS & DEBUG_ALWAYS_FLUSH)
1793 _mesa_flush(ctx);
1794 }
1795
1796
1797 static void
1798 vbo_validated_multidrawelementsindirectcount(struct gl_context *ctx,
1799 GLenum mode, GLenum type,
1800 GLintptr indirect,
1801 GLintptr drawcount,
1802 GLsizei maxdrawcount,
1803 GLsizei stride)
1804 {
1805 struct vbo_context *vbo = vbo_context(ctx);
1806 struct _mesa_index_buffer ib;
1807 GLsizeiptr offset = (GLsizeiptr) indirect;
1808
1809 if (maxdrawcount == 0)
1810 return;
1811
1812 vbo_bind_arrays(ctx);
1813
1814 /* NOTE: IndexBufferObj is guaranteed to be a VBO. */
1815
1816 ib.count = 0; /* unknown */
1817 ib.index_size = vbo_sizeof_ib_type(type);
1818 ib.obj = ctx->Array.VAO->IndexBufferObj;
1819 ib.ptr = NULL;
1820
1821 vbo->draw_indirect_prims(ctx, mode,
1822 ctx->DrawIndirectBuffer, offset,
1823 maxdrawcount, stride,
1824 ctx->ParameterBuffer, drawcount, &ib);
1825
1826 if (MESA_DEBUG_FLAGS & DEBUG_ALWAYS_FLUSH)
1827 _mesa_flush(ctx);
1828 }
1829
1830
1831 static void GLAPIENTRY
1832 vbo_exec_MultiDrawArraysIndirectCount(GLenum mode, GLintptr indirect,
1833 GLintptr drawcount,
1834 GLsizei maxdrawcount, GLsizei stride)
1835 {
1836 GET_CURRENT_CONTEXT(ctx);
1837
1838 if (MESA_VERBOSE & VERBOSE_DRAW)
1839 _mesa_debug(ctx, "glMultiDrawArraysIndirectCountARB"
1840 "(%s, %lx, %lx, %i, %i)\n",
1841 _mesa_enum_to_string(mode),
1842 (unsigned long) indirect, (unsigned long) drawcount,
1843 maxdrawcount, stride);
1844
1845 /* If <stride> is zero, the array elements are treated as tightly packed. */
1846 if (stride == 0)
1847 stride = 4 * sizeof(GLuint); /* sizeof(DrawArraysIndirectCommand) */
1848
1849 if (_mesa_is_no_error_enabled(ctx)) {
1850 FLUSH_CURRENT(ctx, 0);
1851
1852 if (ctx->NewState)
1853 _mesa_update_state(ctx);
1854 } else {
1855 if (!_mesa_validate_MultiDrawArraysIndirectCount(ctx, mode,
1856 indirect, drawcount,
1857 maxdrawcount, stride))
1858 return;
1859 }
1860
1861 if (skip_validated_draw(ctx))
1862 return;
1863
1864 vbo_validated_multidrawarraysindirectcount(ctx, mode, indirect, drawcount,
1865 maxdrawcount, stride);
1866 }
1867
1868
1869 static void GLAPIENTRY
1870 vbo_exec_MultiDrawElementsIndirectCount(GLenum mode, GLenum type,
1871 GLintptr indirect, GLintptr drawcount,
1872 GLsizei maxdrawcount, GLsizei stride)
1873 {
1874 GET_CURRENT_CONTEXT(ctx);
1875
1876 if (MESA_VERBOSE & VERBOSE_DRAW)
1877 _mesa_debug(ctx, "glMultiDrawElementsIndirectCountARB"
1878 "(%s, %s, %lx, %lx, %i, %i)\n",
1879 _mesa_enum_to_string(mode), _mesa_enum_to_string(type),
1880 (unsigned long) indirect, (unsigned long) drawcount,
1881 maxdrawcount, stride);
1882
1883 /* If <stride> is zero, the array elements are treated as tightly packed. */
1884 if (stride == 0)
1885 stride = 5 * sizeof(GLuint); /* sizeof(DrawElementsIndirectCommand) */
1886
1887 if (_mesa_is_no_error_enabled(ctx)) {
1888 FLUSH_CURRENT(ctx, 0);
1889
1890 if (ctx->NewState)
1891 _mesa_update_state(ctx);
1892 } else {
1893 if (!_mesa_validate_MultiDrawElementsIndirectCount(ctx, mode, type,
1894 indirect, drawcount,
1895 maxdrawcount, stride))
1896 return;
1897 }
1898
1899 if (skip_validated_draw(ctx))
1900 return;
1901
1902 vbo_validated_multidrawelementsindirectcount(ctx, mode, type, indirect,
1903 drawcount, maxdrawcount,
1904 stride);
1905 }
1906
1907
1908 /**
1909 * Initialize the dispatch table with the VBO functions for drawing.
1910 */
1911 void
1912 vbo_initialize_exec_dispatch(const struct gl_context *ctx,
1913 struct _glapi_table *exec)
1914 {
1915 SET_DrawArrays(exec, vbo_exec_DrawArrays);
1916 SET_DrawElements(exec, vbo_exec_DrawElements);
1917
1918 if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles3(ctx)) {
1919 SET_DrawRangeElements(exec, vbo_exec_DrawRangeElements);
1920 }
1921
1922 SET_MultiDrawArrays(exec, vbo_exec_MultiDrawArrays);
1923 SET_MultiDrawElementsEXT(exec, vbo_exec_MultiDrawElements);
1924
1925 if (ctx->API == API_OPENGL_COMPAT) {
1926 SET_Rectf(exec, vbo_exec_Rectf);
1927 SET_EvalMesh1(exec, vbo_exec_EvalMesh1);
1928 SET_EvalMesh2(exec, vbo_exec_EvalMesh2);
1929 }
1930
1931 if (ctx->API != API_OPENGLES &&
1932 ctx->Extensions.ARB_draw_elements_base_vertex) {
1933 SET_DrawElementsBaseVertex(exec, vbo_exec_DrawElementsBaseVertex);
1934 SET_MultiDrawElementsBaseVertex(exec,
1935 vbo_exec_MultiDrawElementsBaseVertex);
1936
1937 if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles3(ctx)) {
1938 SET_DrawRangeElementsBaseVertex(exec,
1939 vbo_exec_DrawRangeElementsBaseVertex);
1940 SET_DrawElementsInstancedBaseVertex(exec,
1941 vbo_exec_DrawElementsInstancedBaseVertex);
1942 }
1943 }
1944
1945 if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles3(ctx)) {
1946 SET_DrawArraysInstancedBaseInstance(exec,
1947 vbo_exec_DrawArraysInstancedBaseInstance);
1948 SET_DrawElementsInstancedBaseInstance(exec,
1949 vbo_exec_DrawElementsInstancedBaseInstance);
1950 SET_DrawElementsInstancedBaseVertexBaseInstance(exec,
1951 vbo_exec_DrawElementsInstancedBaseVertexBaseInstance);
1952 }
1953
1954 if (ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) {
1955 SET_DrawArraysIndirect(exec, vbo_exec_DrawArraysIndirect);
1956 SET_DrawElementsIndirect(exec, vbo_exec_DrawElementsIndirect);
1957 }
1958
1959 if (ctx->API == API_OPENGL_CORE) {
1960 SET_MultiDrawArraysIndirect(exec, vbo_exec_MultiDrawArraysIndirect);
1961 SET_MultiDrawElementsIndirect(exec, vbo_exec_MultiDrawElementsIndirect);
1962 SET_MultiDrawArraysIndirectCountARB(exec,
1963 vbo_exec_MultiDrawArraysIndirectCount);
1964 SET_MultiDrawElementsIndirectCountARB(exec,
1965 vbo_exec_MultiDrawElementsIndirectCount);
1966 }
1967
1968 if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles3(ctx)) {
1969 SET_DrawArraysInstancedARB(exec, vbo_exec_DrawArraysInstanced);
1970 SET_DrawElementsInstancedARB(exec, vbo_exec_DrawElementsInstanced);
1971 }
1972
1973 if (_mesa_is_desktop_gl(ctx)) {
1974 SET_DrawTransformFeedback(exec, vbo_exec_DrawTransformFeedback);
1975 SET_DrawTransformFeedbackStream(exec,
1976 vbo_exec_DrawTransformFeedbackStream);
1977 SET_DrawTransformFeedbackInstanced(exec,
1978 vbo_exec_DrawTransformFeedbackInstanced);
1979 SET_DrawTransformFeedbackStreamInstanced(exec,
1980 vbo_exec_DrawTransformFeedbackStreamInstanced);
1981 }
1982 }
1983
1984
1985
1986 /**
1987 * The following functions are only used for OpenGL ES 1/2 support.
1988 * And some aren't even supported (yet) in ES 1/2.
1989 */
1990
1991
1992 void GLAPIENTRY
1993 _mesa_DrawArrays(GLenum mode, GLint first, GLsizei count)
1994 {
1995 vbo_exec_DrawArrays(mode, first, count);
1996 }
1997
1998
1999 void GLAPIENTRY
2000 _mesa_DrawArraysInstanced(GLenum mode, GLint first, GLsizei count,
2001 GLsizei primcount)
2002 {
2003 vbo_exec_DrawArraysInstanced(mode, first, count, primcount);
2004 }
2005
2006
2007 void GLAPIENTRY
2008 _mesa_DrawElements(GLenum mode, GLsizei count, GLenum type,
2009 const GLvoid *indices)
2010 {
2011 vbo_exec_DrawElements(mode, count, type, indices);
2012 }
2013
2014
2015 void GLAPIENTRY
2016 _mesa_DrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type,
2017 const GLvoid *indices, GLint basevertex)
2018 {
2019 vbo_exec_DrawElementsBaseVertex(mode, count, type, indices, basevertex);
2020 }
2021
2022
2023 void GLAPIENTRY
2024 _mesa_DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count,
2025 GLenum type, const GLvoid * indices)
2026 {
2027 vbo_exec_DrawRangeElements(mode, start, end, count, type, indices);
2028 }
2029
2030
2031 void GLAPIENTRY
2032 _mesa_DrawRangeElementsBaseVertex(GLenum mode, GLuint start, GLuint end,
2033 GLsizei count, GLenum type,
2034 const GLvoid *indices, GLint basevertex)
2035 {
2036 vbo_exec_DrawRangeElementsBaseVertex(mode, start, end, count, type,
2037 indices, basevertex);
2038 }
2039
2040
2041 void GLAPIENTRY
2042 _mesa_MultiDrawElementsEXT(GLenum mode, const GLsizei *count, GLenum type,
2043 const GLvoid ** indices, GLsizei primcount)
2044 {
2045 vbo_exec_MultiDrawElements(mode, count, type, indices, primcount);
2046 }
2047
2048
2049 void GLAPIENTRY
2050 _mesa_MultiDrawElementsBaseVertex(GLenum mode,
2051 const GLsizei *count, GLenum type,
2052 const GLvoid **indices, GLsizei primcount,
2053 const GLint *basevertex)
2054 {
2055 vbo_exec_MultiDrawElementsBaseVertex(mode, count, type, indices,
2056 primcount, basevertex);
2057 }
2058
2059
2060 void GLAPIENTRY
2061 _mesa_DrawTransformFeedback(GLenum mode, GLuint name)
2062 {
2063 vbo_exec_DrawTransformFeedback(mode, name);
2064 }