1 /**************************************************************************
3 * Copyright 2003 VMware, Inc.
4 * Copyright 2009 VMware, Inc.
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:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
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.
27 **************************************************************************/
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"
42 #include "vbo_context.h"
46 * Check that element 'j' of the array has reasonable data.
48 * For debugging purposes; not normally used.
51 check_array_data(struct gl_context
*ctx
, struct gl_vertex_array_object
*vao
,
52 GLuint attrib
, GLuint j
)
54 const struct gl_vertex_attrib_array
*array
= &vao
->VertexAttrib
[attrib
];
56 const struct gl_vertex_buffer_binding
*binding
=
57 &vao
->VertexBinding
[array
->VertexBinding
];
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
) {
63 bo
->Mappings
[MAP_INTERNAL
].Pointer
=
64 ctx
->Driver
.MapBufferRange(ctx
, 0, bo
->Size
,
68 data
= ADD_POINTERS(_mesa_vertex_attrib_address(array
, binding
),
69 bo
->Mappings
[MAP_INTERNAL
].Pointer
);
71 switch (array
->Type
) {
74 GLfloat
*f
= (GLfloat
*) ((GLubyte
*) data
+ binding
->Stride
* j
);
76 for (k
= 0; k
< array
->Size
; k
++) {
77 if (IS_INF_OR_NAN(f
[k
]) ||
78 f
[k
] >= 1.0e20F
|| f
[k
] <= -1.0e10F
) {
79 printf("Bad array data:\n");
80 printf(" Element[%u].%u = %f\n", j
, k
, f
[k
]);
81 printf(" Array %u at %p\n", attrib
, (void* ) array
);
82 printf(" Type 0x%x, Size %d, Stride %d\n",
83 array
->Type
, array
->Size
, binding
->Stride
);
84 printf(" Address/offset %p in Buffer Object %u\n",
85 array
->Ptr
, bo
->Name
);
86 f
[k
] = 1.0F
; /* XXX replace the bad value! */
88 /*assert(!IS_INF_OR_NAN(f[k]));*/
100 * Unmap the buffer object referenced by given array, if mapped.
103 unmap_array_buffer(struct gl_context
*ctx
, struct gl_vertex_array_object
*vao
,
106 const struct gl_vertex_attrib_array
*array
= &vao
->VertexAttrib
[attrib
];
107 if (array
->Enabled
) {
108 const struct gl_vertex_buffer_binding
*binding
=
109 &vao
->VertexBinding
[array
->VertexBinding
];
110 struct gl_buffer_object
*bo
= binding
->BufferObj
;
111 if (_mesa_is_bufferobj(bo
) && _mesa_bufferobj_mapped(bo
, MAP_INTERNAL
)) {
112 ctx
->Driver
.UnmapBuffer(ctx
, bo
, MAP_INTERNAL
);
119 * Examine the array's data for NaNs, etc.
120 * For debug purposes; not normally used.
123 check_draw_elements_data(struct gl_context
*ctx
, GLsizei count
, GLenum elemType
,
124 const void *elements
, GLint basevertex
)
126 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
131 if (_mesa_is_bufferobj(ctx
->Array
.VAO
->IndexBufferObj
)) {
132 elemMap
= ctx
->Driver
.MapBufferRange(ctx
, 0,
133 ctx
->Array
.VAO
->IndexBufferObj
->Size
,
135 ctx
->Array
.VAO
->IndexBufferObj
,
137 elements
= ADD_POINTERS(elements
, elemMap
);
140 for (i
= 0; i
< count
; i
++) {
145 case GL_UNSIGNED_BYTE
:
146 j
= ((const GLubyte
*) elements
)[i
];
148 case GL_UNSIGNED_SHORT
:
149 j
= ((const GLushort
*) elements
)[i
];
151 case GL_UNSIGNED_INT
:
152 j
= ((const GLuint
*) elements
)[i
];
158 /* check element j of each enabled array */
159 for (k
= 0; k
< VERT_ATTRIB_MAX
; k
++) {
160 check_array_data(ctx
, vao
, k
, j
);
164 if (_mesa_is_bufferobj(vao
->IndexBufferObj
)) {
165 ctx
->Driver
.UnmapBuffer(ctx
, ctx
->Array
.VAO
->IndexBufferObj
,
169 for (k
= 0; k
< VERT_ATTRIB_MAX
; k
++) {
170 unmap_array_buffer(ctx
, vao
, k
);
176 * Check array data, looking for NaNs, etc.
179 check_draw_arrays_data(struct gl_context
*ctx
, GLint start
, GLsizei count
)
186 * Print info/data for glDrawArrays(), for debugging.
189 print_draw_arrays(struct gl_context
*ctx
,
190 GLenum mode
, GLint start
, GLsizei count
)
192 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
194 printf("vbo_exec_DrawArrays(mode 0x%x, start %d, count %d):\n",
198 for (i
= 0; i
< VERT_ATTRIB_MAX
; ++i
) {
199 const struct gl_vertex_attrib_array
*array
= &vao
->VertexAttrib
[i
];
203 const struct gl_vertex_buffer_binding
*binding
=
204 &vao
->VertexBinding
[array
->VertexBinding
];
205 struct gl_buffer_object
*bufObj
= binding
->BufferObj
;
207 printf("attr %s: size %d stride %d enabled %d "
208 "ptr %p Bufobj %u\n",
209 gl_vert_attrib_name((gl_vert_attrib
)i
),
210 array
->Size
, binding
->Stride
, array
->Enabled
,
211 array
->Ptr
, bufObj
->Name
);
213 if (_mesa_is_bufferobj(bufObj
)) {
214 GLubyte
*p
= ctx
->Driver
.MapBufferRange(ctx
, 0, bufObj
->Size
,
215 GL_MAP_READ_BIT
, bufObj
,
217 int offset
= (int) (GLintptr
)
218 _mesa_vertex_attrib_address(array
, binding
);
219 float *f
= (float *) (p
+ offset
);
222 int n
= (count
* binding
->Stride
) / 4;
225 printf(" Data at offset %d:\n", offset
);
226 for (i
= 0; i
< n
; i
++) {
227 printf(" float[%d] = 0x%08x %f\n", i
, k
[i
], f
[i
]);
229 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, MAP_INTERNAL
);
236 * Set the vbo->exec->inputs[] pointers to point to the enabled
237 * vertex arrays. This depends on the current vertex program/shader
238 * being executed because of whether or not generic vertex arrays
239 * alias the conventional vertex arrays.
240 * For arrays that aren't enabled, we set the input[attrib] pointer
241 * to point at a zero-stride current value "array".
244 recalculate_input_bindings(struct gl_context
*ctx
)
246 struct vbo_context
*vbo
= vbo_context(ctx
);
247 struct vbo_exec_context
*exec
= &vbo
->exec
;
248 const struct gl_vertex_attrib_array
*array
= ctx
->Array
.VAO
->VertexAttrib
;
249 struct gl_client_array
*vertexAttrib
= ctx
->Array
.VAO
->_VertexAttrib
;
250 const struct gl_client_array
**inputs
= &exec
->array
.inputs
[0];
251 GLbitfield64 const_inputs
= 0x0;
254 switch (get_program_mode(ctx
)) {
256 /* When no vertex program is active (or the vertex program is generated
257 * from fixed-function state). We put the material values into the
258 * generic slots. This is the only situation where material values
259 * are available as per-vertex attributes.
261 for (i
= 0; i
< VERT_ATTRIB_FF_MAX
; i
++) {
262 if (array
[VERT_ATTRIB_FF(i
)].Enabled
)
263 inputs
[i
] = &vertexAttrib
[VERT_ATTRIB_FF(i
)];
265 inputs
[i
] = &vbo
->currval
[VBO_ATTRIB_POS
+i
];
266 const_inputs
|= VERT_BIT(i
);
270 for (i
= 0; i
< MAT_ATTRIB_MAX
; i
++) {
271 inputs
[VERT_ATTRIB_GENERIC(i
)] =
272 &vbo
->currval
[VBO_ATTRIB_MAT_FRONT_AMBIENT
+i
];
273 const_inputs
|= VERT_BIT_GENERIC(i
);
276 /* Could use just about anything, just to fill in the empty
279 for (i
= MAT_ATTRIB_MAX
; i
< VERT_ATTRIB_GENERIC_MAX
; i
++) {
280 inputs
[VERT_ATTRIB_GENERIC(i
)] = &vbo
->currval
[VBO_ATTRIB_GENERIC0
+i
];
281 const_inputs
|= VERT_BIT_GENERIC(i
);
286 /* There are no shaders in OpenGL ES 1.x, so this code path should be
287 * impossible to reach. The meta code is careful to not use shaders in
290 assert(ctx
->API
!= API_OPENGLES
);
292 /* In the compatibility profile of desktop OpenGL, the generic[0]
293 * attribute array aliases and overrides the legacy position array.
294 * Otherwise, legacy attributes available in the legacy slots,
295 * generic attributes in the generic slots and materials are not
296 * available as per-vertex attributes.
298 * In all other APIs, only the generic attributes exist, and none of the
299 * slots are considered "magic."
301 if (ctx
->API
== API_OPENGL_COMPAT
) {
302 if (array
[VERT_ATTRIB_GENERIC0
].Enabled
)
303 inputs
[0] = &vertexAttrib
[VERT_ATTRIB_GENERIC0
];
304 else if (array
[VERT_ATTRIB_POS
].Enabled
)
305 inputs
[0] = &vertexAttrib
[VERT_ATTRIB_POS
];
307 inputs
[0] = &vbo
->currval
[VBO_ATTRIB_POS
];
308 const_inputs
|= VERT_BIT_POS
;
311 for (i
= 1; i
< VERT_ATTRIB_FF_MAX
; i
++) {
312 if (array
[VERT_ATTRIB_FF(i
)].Enabled
)
313 inputs
[i
] = &vertexAttrib
[VERT_ATTRIB_FF(i
)];
315 inputs
[i
] = &vbo
->currval
[VBO_ATTRIB_POS
+i
];
316 const_inputs
|= VERT_BIT_FF(i
);
320 for (i
= 1; i
< VERT_ATTRIB_GENERIC_MAX
; i
++) {
321 if (array
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
322 inputs
[VERT_ATTRIB_GENERIC(i
)] =
323 &vertexAttrib
[VERT_ATTRIB_GENERIC(i
)];
325 inputs
[VERT_ATTRIB_GENERIC(i
)] =
326 &vbo
->currval
[VBO_ATTRIB_GENERIC0
+i
];
327 const_inputs
|= VERT_BIT_GENERIC(i
);
331 inputs
[VERT_ATTRIB_GENERIC0
] = inputs
[0];
333 /* Other parts of the code assume that inputs[0] through
334 * inputs[VERT_ATTRIB_FF_MAX] will be non-NULL. However, in OpenGL
335 * ES 2.0+ or OpenGL core profile, none of these arrays should ever
338 for (i
= 0; i
< VERT_ATTRIB_FF_MAX
; i
++) {
339 assert(!array
[VERT_ATTRIB_FF(i
)].Enabled
);
341 inputs
[i
] = &vbo
->currval
[VBO_ATTRIB_POS
+i
];
342 const_inputs
|= VERT_BIT_FF(i
);
345 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++) {
346 if (array
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
347 inputs
[VERT_ATTRIB_GENERIC(i
)] =
348 &vertexAttrib
[VERT_ATTRIB_GENERIC(i
)];
350 inputs
[VERT_ATTRIB_GENERIC(i
)] =
351 &vbo
->currval
[VBO_ATTRIB_GENERIC0
+i
];
352 const_inputs
|= VERT_BIT_GENERIC(i
);
360 _mesa_set_varying_vp_inputs( ctx
, VERT_BIT_ALL
& (~const_inputs
) );
361 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewArray
;
366 * Examine the enabled vertex arrays to set the exec->array.inputs[] values.
367 * These will point to the arrays to actually use for drawing. Some will
368 * be user-provided arrays, other will be zero-stride const-valued arrays.
369 * Note that this might set the _NEW_VARYING_VP_INPUTS dirty flag so state
370 * validation must be done after this call.
373 vbo_bind_arrays(struct gl_context
*ctx
)
375 struct vbo_context
*vbo
= vbo_context(ctx
);
376 struct vbo_exec_context
*exec
= &vbo
->exec
;
378 vbo_draw_method(vbo
, DRAW_ARRAYS
);
380 if (exec
->array
.recalculate_inputs
) {
381 recalculate_input_bindings(ctx
);
382 exec
->array
.recalculate_inputs
= GL_FALSE
;
384 /* Again... because we may have changed the bitmask of per-vertex varying
385 * attributes. If we regenerate the fixed-function vertex program now
386 * we may be able to prune down the number of vertex attributes which we
387 * need in the shader.
390 /* Setting "validating" to TRUE prevents _mesa_update_state from
391 * invalidating what we just did.
393 exec
->validating
= GL_TRUE
;
394 _mesa_update_state(ctx
);
395 exec
->validating
= GL_FALSE
;
403 * Helper function called by the other DrawArrays() functions below.
404 * This is where we handle primitive restart for drawing non-indexed
405 * arrays. If primitive restart is enabled, it typically means
406 * splitting one DrawArrays() into two.
409 vbo_draw_arrays(struct gl_context
*ctx
, GLenum mode
, GLint start
,
410 GLsizei count
, GLuint numInstances
, GLuint baseInstance
)
412 struct vbo_context
*vbo
= vbo_context(ctx
);
413 struct _mesa_prim prim
[2];
415 if (!vbo_bind_arrays(ctx
))
418 /* init most fields to zero */
419 memset(prim
, 0, sizeof(prim
));
423 prim
[0].num_instances
= numInstances
;
424 prim
[0].base_instance
= baseInstance
;
425 prim
[0].is_indirect
= 0;
427 /* Implement the primitive restart index */
428 if (ctx
->Array
.PrimitiveRestart
&& !ctx
->Array
.PrimitiveRestartFixedIndex
&&
429 ctx
->Array
.RestartIndex
< count
) {
430 GLuint primCount
= 0;
432 if (ctx
->Array
.RestartIndex
== start
) {
433 /* special case: RestartIndex at beginning */
435 prim
[0].start
= start
+ 1;
436 prim
[0].count
= count
- 1;
440 else if (ctx
->Array
.RestartIndex
== start
+ count
- 1) {
441 /* special case: RestartIndex at end */
443 prim
[0].start
= start
;
444 prim
[0].count
= count
- 1;
449 /* general case: RestartIndex in middle, split into two prims */
450 prim
[0].start
= start
;
451 prim
[0].count
= ctx
->Array
.RestartIndex
- start
;
454 prim
[1].start
= ctx
->Array
.RestartIndex
+ 1;
455 prim
[1].count
= count
- prim
[1].start
;
461 /* draw one or two prims */
462 vbo
->draw_prims(ctx
, prim
, primCount
, NULL
,
463 GL_TRUE
, start
, start
+ count
- 1, NULL
, 0, NULL
);
467 /* no prim restart */
468 prim
[0].start
= start
;
469 prim
[0].count
= count
;
471 vbo
->draw_prims(ctx
, prim
, 1, NULL
,
472 GL_TRUE
, start
, start
+ count
- 1,
476 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
) {
483 * Execute a glRectf() function.
485 static void GLAPIENTRY
486 vbo_exec_Rectf(GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
)
488 GET_CURRENT_CONTEXT(ctx
);
489 ASSERT_OUTSIDE_BEGIN_END(ctx
);
491 CALL_Begin(GET_DISPATCH(), (GL_QUADS
));
492 CALL_Vertex2f(GET_DISPATCH(), (x1
, y1
));
493 CALL_Vertex2f(GET_DISPATCH(), (x2
, y1
));
494 CALL_Vertex2f(GET_DISPATCH(), (x2
, y2
));
495 CALL_Vertex2f(GET_DISPATCH(), (x1
, y2
));
496 CALL_End(GET_DISPATCH(), ());
500 static void GLAPIENTRY
501 vbo_exec_EvalMesh1(GLenum mode
, GLint i1
, GLint i2
)
503 GET_CURRENT_CONTEXT(ctx
);
513 prim
= GL_LINE_STRIP
;
516 _mesa_error( ctx
, GL_INVALID_ENUM
, "glEvalMesh1(mode)" );
520 /* No effect if vertex maps disabled.
522 if (!ctx
->Eval
.Map1Vertex4
&&
523 !ctx
->Eval
.Map1Vertex3
)
526 du
= ctx
->Eval
.MapGrid1du
;
527 u
= ctx
->Eval
.MapGrid1u1
+ i1
* du
;
529 CALL_Begin(GET_DISPATCH(), (prim
));
530 for (i
=i1
;i
<=i2
;i
++,u
+=du
) {
531 CALL_EvalCoord1f(GET_DISPATCH(), (u
));
533 CALL_End(GET_DISPATCH(), ());
537 static void GLAPIENTRY
538 vbo_exec_EvalMesh2(GLenum mode
, GLint i1
, GLint i2
, GLint j1
, GLint j2
)
540 GET_CURRENT_CONTEXT(ctx
);
541 GLfloat u
, du
, v
, dv
, v1
, u1
;
550 _mesa_error( ctx
, GL_INVALID_ENUM
, "glEvalMesh2(mode)" );
554 /* No effect if vertex maps disabled.
556 if (!ctx
->Eval
.Map2Vertex4
&&
557 !ctx
->Eval
.Map2Vertex3
)
560 du
= ctx
->Eval
.MapGrid2du
;
561 dv
= ctx
->Eval
.MapGrid2dv
;
562 v1
= ctx
->Eval
.MapGrid2v1
+ j1
* dv
;
563 u1
= ctx
->Eval
.MapGrid2u1
+ i1
* du
;
567 CALL_Begin(GET_DISPATCH(), (GL_POINTS
));
568 for (v
=v1
,j
=j1
;j
<=j2
;j
++,v
+=dv
) {
569 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
570 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
573 CALL_End(GET_DISPATCH(), ());
576 for (v
=v1
,j
=j1
;j
<=j2
;j
++,v
+=dv
) {
577 CALL_Begin(GET_DISPATCH(), (GL_LINE_STRIP
));
578 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
579 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
581 CALL_End(GET_DISPATCH(), ());
583 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
584 CALL_Begin(GET_DISPATCH(), (GL_LINE_STRIP
));
585 for (v
=v1
,j
=j1
;j
<=j2
;j
++,v
+=dv
) {
586 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
588 CALL_End(GET_DISPATCH(), ());
592 for (v
=v1
,j
=j1
;j
<j2
;j
++,v
+=dv
) {
593 CALL_Begin(GET_DISPATCH(), (GL_TRIANGLE_STRIP
));
594 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
595 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
596 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
+dv
));
598 CALL_End(GET_DISPATCH(), ());
606 * Called from glDrawArrays when in immediate mode (not display list mode).
608 static void GLAPIENTRY
609 vbo_exec_DrawArrays(GLenum mode
, GLint start
, GLsizei count
)
611 GET_CURRENT_CONTEXT(ctx
);
613 if (MESA_VERBOSE
& VERBOSE_DRAW
)
614 _mesa_debug(ctx
, "glDrawArrays(%s, %d, %d)\n",
615 _mesa_enum_to_string(mode
), start
, count
);
617 if (!_mesa_validate_DrawArrays(ctx
, mode
, count
))
621 check_draw_arrays_data(ctx
, start
, count
);
623 vbo_draw_arrays(ctx
, mode
, start
, count
, 1, 0);
626 print_draw_arrays(ctx
, mode
, start
, count
);
631 * Called from glDrawArraysInstanced when in immediate mode (not
632 * display list mode).
634 static void GLAPIENTRY
635 vbo_exec_DrawArraysInstanced(GLenum mode
, GLint start
, GLsizei count
,
636 GLsizei numInstances
)
638 GET_CURRENT_CONTEXT(ctx
);
640 if (MESA_VERBOSE
& VERBOSE_DRAW
)
641 _mesa_debug(ctx
, "glDrawArraysInstanced(%s, %d, %d, %d)\n",
642 _mesa_enum_to_string(mode
), start
, count
, numInstances
);
644 if (!_mesa_validate_DrawArraysInstanced(ctx
, mode
, start
, count
, numInstances
))
648 check_draw_arrays_data(ctx
, start
, count
);
650 vbo_draw_arrays(ctx
, mode
, start
, count
, numInstances
, 0);
653 print_draw_arrays(ctx
, mode
, start
, count
);
658 * Called from glDrawArraysInstancedBaseInstance when in immediate mode.
660 static void GLAPIENTRY
661 vbo_exec_DrawArraysInstancedBaseInstance(GLenum mode
, GLint first
, GLsizei count
,
662 GLsizei numInstances
, GLuint baseInstance
)
664 GET_CURRENT_CONTEXT(ctx
);
666 if (MESA_VERBOSE
& VERBOSE_DRAW
)
667 _mesa_debug(ctx
, "glDrawArraysInstancedBaseInstance(%s, %d, %d, %d, %d)\n",
668 _mesa_enum_to_string(mode
), first
, count
,
669 numInstances
, baseInstance
);
671 if (!_mesa_validate_DrawArraysInstanced(ctx
, mode
, first
, count
,
676 check_draw_arrays_data(ctx
, first
, count
);
678 vbo_draw_arrays(ctx
, mode
, first
, count
, numInstances
, baseInstance
);
681 print_draw_arrays(ctx
, mode
, first
, count
);
687 * Map GL_ELEMENT_ARRAY_BUFFER and print contents.
692 dump_element_buffer(struct gl_context
*ctx
, GLenum type
)
695 ctx
->Driver
.MapBufferRange(ctx
, 0,
696 ctx
->Array
.VAO
->IndexBufferObj
->Size
,
698 ctx
->Array
.VAO
->IndexBufferObj
,
701 case GL_UNSIGNED_BYTE
:
703 const GLubyte
*us
= (const GLubyte
*) map
;
705 for (i
= 0; i
< ctx
->Array
.VAO
->IndexBufferObj
->Size
; i
++) {
706 printf("%02x ", us
[i
]);
713 case GL_UNSIGNED_SHORT
:
715 const GLushort
*us
= (const GLushort
*) map
;
717 for (i
= 0; i
< ctx
->Array
.VAO
->IndexBufferObj
->Size
/ 2; i
++) {
718 printf("%04x ", us
[i
]);
725 case GL_UNSIGNED_INT
:
727 const GLuint
*us
= (const GLuint
*) map
;
729 for (i
= 0; i
< ctx
->Array
.VAO
->IndexBufferObj
->Size
/ 4; i
++) {
730 printf("%08x ", us
[i
]);
741 ctx
->Driver
.UnmapBuffer(ctx
, ctx
->Array
.VAO
->IndexBufferObj
,
748 * Inner support for both _mesa_DrawElements and _mesa_DrawRangeElements.
749 * Do the rendering for a glDrawElements or glDrawRangeElements call after
750 * we've validated buffer bounds, etc.
753 vbo_validated_drawrangeelements(struct gl_context
*ctx
, GLenum mode
,
754 GLboolean index_bounds_valid
,
755 GLuint start
, GLuint end
,
756 GLsizei count
, GLenum type
,
757 const GLvoid
*indices
,
758 GLint basevertex
, GLuint numInstances
,
761 struct vbo_context
*vbo
= vbo_context(ctx
);
762 struct _mesa_index_buffer ib
;
763 struct _mesa_prim prim
[1];
765 if (!vbo_bind_arrays(ctx
))
770 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
779 prim
[0].count
= count
;
781 prim
[0].is_indirect
= 0;
782 prim
[0].basevertex
= basevertex
;
783 prim
[0].num_instances
= numInstances
;
784 prim
[0].base_instance
= baseInstance
;
786 /* Need to give special consideration to rendering a range of
787 * indices starting somewhere above zero. Typically the
788 * application is issuing multiple DrawRangeElements() to draw
789 * successive primitives layed out linearly in the vertex arrays.
790 * Unless the vertex arrays are all in a VBO (or locked as with
791 * CVA), the OpenGL semantics imply that we need to re-read or
792 * re-upload the vertex data on each draw call.
794 * In the case of hardware tnl, we want to avoid starting the
795 * upload at zero, as it will mean every draw call uploads an
796 * increasing amount of not-used vertex data. Worse - in the
797 * software tnl module, all those vertices might be transformed and
798 * lit but never rendered.
800 * If we just upload or transform the vertices in start..end,
801 * however, the indices will be incorrect.
803 * At this level, we don't know exactly what the requirements of
804 * the backend are going to be, though it will likely boil down to
807 * 1) Do nothing, everything is in a VBO and is processed once
810 * 2) Adjust the indices and vertex arrays so that start becomes
813 * Rather than doing anything here, I'll provide a helper function
814 * for the latter case elsewhere.
817 vbo
->draw_prims(ctx
, prim
, 1, &ib
,
818 index_bounds_valid
, start
, end
, NULL
, 0, NULL
);
820 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
) {
827 * Called by glDrawRangeElementsBaseVertex() in immediate mode.
829 static void GLAPIENTRY
830 vbo_exec_DrawRangeElementsBaseVertex(GLenum mode
,
831 GLuint start
, GLuint end
,
832 GLsizei count
, GLenum type
,
833 const GLvoid
*indices
,
836 static GLuint warnCount
= 0;
837 GLboolean index_bounds_valid
= GL_TRUE
;
839 /* This is only useful to catch invalid values in the "end" parameter
842 GLuint max_element
= 2 * 1000 * 1000 * 1000; /* just a big number */
844 GET_CURRENT_CONTEXT(ctx
);
846 if (MESA_VERBOSE
& VERBOSE_DRAW
)
848 "glDrawRangeElementsBaseVertex(%s, %u, %u, %d, %s, %p, %d)\n",
849 _mesa_enum_to_string(mode
), start
, end
, count
,
850 _mesa_enum_to_string(type
), indices
, basevertex
);
852 if (!_mesa_validate_DrawRangeElements(ctx
, mode
, start
, end
, count
,
856 if ((int) end
+ basevertex
< 0 ||
857 start
+ basevertex
>= max_element
) {
858 /* The application requested we draw using a range of indices that's
859 * outside the bounds of the current VBO. This is invalid and appears
860 * to give undefined results. The safest thing to do is to simply
861 * ignore the range, in case the application botched their range tracking
862 * but did provide valid indices. Also issue a warning indicating that
863 * the application is broken.
865 if (warnCount
++ < 10) {
866 _mesa_warning(ctx
, "glDrawRangeElements(start %u, end %u, "
867 "basevertex %d, count %d, type 0x%x, indices=%p):\n"
868 "\trange is outside VBO bounds (max=%u); ignoring.\n"
869 "\tThis should be fixed in the application.",
870 start
, end
, basevertex
, count
, type
, indices
,
873 index_bounds_valid
= GL_FALSE
;
876 /* NOTE: It's important that 'end' is a reasonable value.
877 * in _tnl_draw_prims(), we use end to determine how many vertices
878 * to transform. If it's too large, we can unnecessarily split prims
879 * or we can read/write out of memory in several different places!
882 /* Catch/fix some potential user errors */
883 if (type
== GL_UNSIGNED_BYTE
) {
884 start
= MIN2(start
, 0xff);
885 end
= MIN2(end
, 0xff);
887 else if (type
== GL_UNSIGNED_SHORT
) {
888 start
= MIN2(start
, 0xffff);
889 end
= MIN2(end
, 0xffff);
893 printf("glDraw[Range]Elements{,BaseVertex}"
894 "(start %u, end %u, type 0x%x, count %d) ElemBuf %u, "
896 start
, end
, type
, count
,
897 ctx
->Array
.VAO
->IndexBufferObj
->Name
,
901 if ((int) start
+ basevertex
< 0 ||
902 end
+ basevertex
>= max_element
)
903 index_bounds_valid
= GL_FALSE
;
906 check_draw_elements_data(ctx
, count
, type
, indices
);
908 (void) check_draw_elements_data
;
911 vbo_validated_drawrangeelements(ctx
, mode
, index_bounds_valid
, start
, end
,
912 count
, type
, indices
, basevertex
, 1, 0);
917 * Called by glDrawRangeElements() in immediate mode.
919 static void GLAPIENTRY
920 vbo_exec_DrawRangeElements(GLenum mode
, GLuint start
, GLuint end
,
921 GLsizei count
, GLenum type
, const GLvoid
*indices
)
923 if (MESA_VERBOSE
& VERBOSE_DRAW
) {
924 GET_CURRENT_CONTEXT(ctx
);
926 "glDrawRangeElements(%s, %u, %u, %d, %s, %p)\n",
927 _mesa_enum_to_string(mode
), start
, end
, count
,
928 _mesa_enum_to_string(type
), indices
);
931 vbo_exec_DrawRangeElementsBaseVertex(mode
, start
, end
, count
, type
,
937 * Called by glDrawElements() in immediate mode.
939 static void GLAPIENTRY
940 vbo_exec_DrawElements(GLenum mode
, GLsizei count
, GLenum type
,
941 const GLvoid
*indices
)
943 GET_CURRENT_CONTEXT(ctx
);
945 if (MESA_VERBOSE
& VERBOSE_DRAW
)
946 _mesa_debug(ctx
, "glDrawElements(%s, %u, %s, %p)\n",
947 _mesa_enum_to_string(mode
), count
,
948 _mesa_enum_to_string(type
), indices
);
950 if (!_mesa_validate_DrawElements(ctx
, mode
, count
, type
, indices
))
953 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
954 count
, type
, indices
, 0, 1, 0);
959 * Called by glDrawElementsBaseVertex() in immediate mode.
961 static void GLAPIENTRY
962 vbo_exec_DrawElementsBaseVertex(GLenum mode
, GLsizei count
, GLenum type
,
963 const GLvoid
*indices
, GLint basevertex
)
965 GET_CURRENT_CONTEXT(ctx
);
967 if (MESA_VERBOSE
& VERBOSE_DRAW
)
968 _mesa_debug(ctx
, "glDrawElementsBaseVertex(%s, %d, %s, %p, %d)\n",
969 _mesa_enum_to_string(mode
), count
,
970 _mesa_enum_to_string(type
), indices
, basevertex
);
972 if (!_mesa_validate_DrawElements(ctx
, mode
, count
, type
, indices
))
975 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
976 count
, type
, indices
, basevertex
, 1, 0);
981 * Called by glDrawElementsInstanced() in immediate mode.
983 static void GLAPIENTRY
984 vbo_exec_DrawElementsInstanced(GLenum mode
, GLsizei count
, GLenum type
,
985 const GLvoid
*indices
, GLsizei numInstances
)
987 GET_CURRENT_CONTEXT(ctx
);
989 if (MESA_VERBOSE
& VERBOSE_DRAW
)
990 _mesa_debug(ctx
, "glDrawElementsInstanced(%s, %d, %s, %p, %d)\n",
991 _mesa_enum_to_string(mode
), count
,
992 _mesa_enum_to_string(type
), indices
, numInstances
);
994 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
998 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
999 count
, type
, indices
, 0, numInstances
, 0);
1004 * Called by glDrawElementsInstancedBaseVertex() in immediate mode.
1006 static void GLAPIENTRY
1007 vbo_exec_DrawElementsInstancedBaseVertex(GLenum mode
, GLsizei count
, GLenum type
,
1008 const GLvoid
*indices
, GLsizei numInstances
,
1011 GET_CURRENT_CONTEXT(ctx
);
1013 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1014 _mesa_debug(ctx
, "glDrawElementsInstancedBaseVertex(%s, %d, %s, %p, %d; %d)\n",
1015 _mesa_enum_to_string(mode
), count
,
1016 _mesa_enum_to_string(type
), indices
,
1017 numInstances
, basevertex
);
1019 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
1023 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1024 count
, type
, indices
, basevertex
, numInstances
, 0);
1029 * Called by glDrawElementsInstancedBaseInstance() in immediate mode.
1031 static void GLAPIENTRY
1032 vbo_exec_DrawElementsInstancedBaseInstance(GLenum mode
, GLsizei count
, GLenum type
,
1033 const GLvoid
*indices
, GLsizei numInstances
,
1034 GLuint baseInstance
)
1036 GET_CURRENT_CONTEXT(ctx
);
1038 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1039 _mesa_debug(ctx
, "glDrawElementsInstancedBaseInstance(%s, %d, %s, %p, %d, %d)\n",
1040 _mesa_enum_to_string(mode
), count
,
1041 _mesa_enum_to_string(type
), indices
,
1042 numInstances
, baseInstance
);
1044 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
1048 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1049 count
, type
, indices
, 0, numInstances
,
1055 * Called by glDrawElementsInstancedBaseVertexBaseInstance() in immediate mode.
1057 static void GLAPIENTRY
1058 vbo_exec_DrawElementsInstancedBaseVertexBaseInstance(GLenum mode
, GLsizei count
, GLenum type
,
1059 const GLvoid
*indices
, GLsizei numInstances
,
1060 GLint basevertex
, GLuint baseInstance
)
1062 GET_CURRENT_CONTEXT(ctx
);
1064 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1065 _mesa_debug(ctx
, "glDrawElementsInstancedBaseVertexBaseInstance(%s, %d, %s, %p, %d, %d, %d)\n",
1066 _mesa_enum_to_string(mode
), count
,
1067 _mesa_enum_to_string(type
), indices
,
1068 numInstances
, basevertex
, baseInstance
);
1070 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
1074 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1075 count
, type
, indices
, basevertex
, numInstances
,
1081 * Inner support for both _mesa_MultiDrawElements() and
1082 * _mesa_MultiDrawRangeElements().
1083 * This does the actual rendering after we've checked array indexes, etc.
1086 vbo_validated_multidrawelements(struct gl_context
*ctx
, GLenum mode
,
1087 const GLsizei
*count
, GLenum type
,
1088 const GLvoid
* const *indices
,
1090 const GLint
*basevertex
)
1092 struct vbo_context
*vbo
= vbo_context(ctx
);
1093 struct _mesa_index_buffer ib
;
1094 struct _mesa_prim
*prim
;
1095 unsigned int index_type_size
= vbo_sizeof_ib_type(type
);
1096 uintptr_t min_index_ptr
, max_index_ptr
;
1097 GLboolean fallback
= GL_FALSE
;
1103 prim
= calloc(primcount
, sizeof(*prim
));
1105 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMultiDrawElements");
1109 if (!vbo_bind_arrays(ctx
)) {
1114 min_index_ptr
= (uintptr_t)indices
[0];
1116 for (i
= 0; i
< primcount
; i
++) {
1117 min_index_ptr
= MIN2(min_index_ptr
, (uintptr_t)indices
[i
]);
1118 max_index_ptr
= MAX2(max_index_ptr
, (uintptr_t)indices
[i
] +
1119 index_type_size
* count
[i
]);
1122 /* Check if we can handle this thing as a bunch of index offsets from the
1123 * same index pointer. If we can't, then we have to fall back to doing
1124 * a draw_prims per primitive.
1125 * Check that the difference between each prim's indexes is a multiple of
1126 * the index/element size.
1128 if (index_type_size
!= 1) {
1129 for (i
= 0; i
< primcount
; i
++) {
1130 if ((((uintptr_t)indices
[i
] - min_index_ptr
) % index_type_size
) != 0) {
1137 /* Draw primitives individually if one count is zero, so we can easily skip
1140 for (i
= 0; i
< primcount
; i
++) {
1141 if (count
[i
] == 0) {
1147 /* If the index buffer isn't in a VBO, then treating the application's
1148 * subranges of the index buffer as one large index buffer may lead to
1149 * us reading unmapped memory.
1151 if (!_mesa_is_bufferobj(ctx
->Array
.VAO
->IndexBufferObj
))
1155 ib
.count
= (max_index_ptr
- min_index_ptr
) / index_type_size
;
1157 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1158 ib
.ptr
= (void *)min_index_ptr
;
1160 for (i
= 0; i
< primcount
; i
++) {
1161 prim
[i
].begin
= (i
== 0);
1162 prim
[i
].end
= (i
== primcount
- 1);
1165 prim
[i
].mode
= mode
;
1166 prim
[i
].start
= ((uintptr_t)indices
[i
] - min_index_ptr
) / index_type_size
;
1167 prim
[i
].count
= count
[i
];
1168 prim
[i
].indexed
= 1;
1169 prim
[i
].num_instances
= 1;
1170 prim
[i
].base_instance
= 0;
1171 prim
[i
].draw_id
= i
;
1172 prim
[i
].is_indirect
= 0;
1173 if (basevertex
!= NULL
)
1174 prim
[i
].basevertex
= basevertex
[i
];
1176 prim
[i
].basevertex
= 0;
1179 vbo
->draw_prims(ctx
, prim
, primcount
, &ib
,
1180 false, ~0, ~0, NULL
, 0, NULL
);
1182 /* render one prim at a time */
1183 for (i
= 0; i
< primcount
; i
++) {
1186 ib
.count
= count
[i
];
1188 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1189 ib
.ptr
= indices
[i
];
1195 prim
[0].mode
= mode
;
1197 prim
[0].count
= count
[i
];
1198 prim
[0].indexed
= 1;
1199 prim
[0].num_instances
= 1;
1200 prim
[0].base_instance
= 0;
1201 prim
[0].draw_id
= i
;
1202 prim
[0].is_indirect
= 0;
1203 if (basevertex
!= NULL
)
1204 prim
[0].basevertex
= basevertex
[i
];
1206 prim
[0].basevertex
= 0;
1208 vbo
->draw_prims(ctx
, prim
, 1, &ib
,
1209 false, ~0, ~0, NULL
, 0, NULL
);
1215 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
) {
1221 static void GLAPIENTRY
1222 vbo_exec_MultiDrawElements(GLenum mode
,
1223 const GLsizei
*count
, GLenum type
,
1224 const GLvoid
* const *indices
,
1227 GET_CURRENT_CONTEXT(ctx
);
1229 if (!_mesa_validate_MultiDrawElements(ctx
, mode
, count
, type
, indices
,
1233 vbo_validated_multidrawelements(ctx
, mode
, count
, type
, indices
, primcount
,
1238 static void GLAPIENTRY
1239 vbo_exec_MultiDrawElementsBaseVertex(GLenum mode
,
1240 const GLsizei
*count
, GLenum type
,
1241 const GLvoid
* const *indices
,
1243 const GLsizei
*basevertex
)
1245 GET_CURRENT_CONTEXT(ctx
);
1247 if (!_mesa_validate_MultiDrawElements(ctx
, mode
, count
, type
, indices
,
1251 vbo_validated_multidrawelements(ctx
, mode
, count
, type
, indices
, primcount
,
1256 vbo_draw_transform_feedback(struct gl_context
*ctx
, GLenum mode
,
1257 struct gl_transform_feedback_object
*obj
,
1258 GLuint stream
, GLuint numInstances
)
1260 struct vbo_context
*vbo
= vbo_context(ctx
);
1261 struct _mesa_prim prim
[2];
1263 if (!_mesa_validate_DrawTransformFeedback(ctx
, mode
, obj
, stream
,
1268 if (ctx
->Driver
.GetTransformFeedbackVertexCount
&&
1269 (ctx
->Const
.AlwaysUseGetTransformFeedbackVertexCount
||
1270 !_mesa_all_varyings_in_vbos(ctx
->Array
.VAO
))) {
1271 GLsizei n
= ctx
->Driver
.GetTransformFeedbackVertexCount(ctx
, obj
, stream
);
1272 vbo_draw_arrays(ctx
, mode
, 0, n
, numInstances
, 0);
1276 if (!vbo_bind_arrays(ctx
))
1279 /* init most fields to zero */
1280 memset(prim
, 0, sizeof(prim
));
1283 prim
[0].mode
= mode
;
1284 prim
[0].num_instances
= numInstances
;
1285 prim
[0].base_instance
= 0;
1286 prim
[0].is_indirect
= 0;
1288 /* Maybe we should do some primitive splitting for primitive restart
1289 * (like in DrawArrays), but we have no way to know how many vertices
1290 * will be rendered. */
1292 vbo
->draw_prims(ctx
, prim
, 1, NULL
,
1293 GL_FALSE
, ~0, ~0, obj
, stream
, NULL
);
1295 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
) {
1301 * Like DrawArrays, but take the count from a transform feedback object.
1302 * \param mode GL_POINTS, GL_LINES, GL_TRIANGLE_STRIP, etc.
1303 * \param name the transform feedback object
1304 * User still has to setup of the vertex attribute info with
1305 * glVertexPointer, glColorPointer, etc.
1306 * Part of GL_ARB_transform_feedback2.
1308 static void GLAPIENTRY
1309 vbo_exec_DrawTransformFeedback(GLenum mode
, GLuint name
)
1311 GET_CURRENT_CONTEXT(ctx
);
1312 struct gl_transform_feedback_object
*obj
=
1313 _mesa_lookup_transform_feedback_object(ctx
, name
);
1315 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1316 _mesa_debug(ctx
, "glDrawTransformFeedback(%s, %d)\n",
1317 _mesa_enum_to_string(mode
), name
);
1319 vbo_draw_transform_feedback(ctx
, mode
, obj
, 0, 1);
1322 static void GLAPIENTRY
1323 vbo_exec_DrawTransformFeedbackStream(GLenum mode
, GLuint name
, GLuint stream
)
1325 GET_CURRENT_CONTEXT(ctx
);
1326 struct gl_transform_feedback_object
*obj
=
1327 _mesa_lookup_transform_feedback_object(ctx
, name
);
1329 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1330 _mesa_debug(ctx
, "glDrawTransformFeedbackStream(%s, %u, %u)\n",
1331 _mesa_enum_to_string(mode
), name
, stream
);
1333 vbo_draw_transform_feedback(ctx
, mode
, obj
, stream
, 1);
1336 static void GLAPIENTRY
1337 vbo_exec_DrawTransformFeedbackInstanced(GLenum mode
, GLuint name
,
1340 GET_CURRENT_CONTEXT(ctx
);
1341 struct gl_transform_feedback_object
*obj
=
1342 _mesa_lookup_transform_feedback_object(ctx
, name
);
1344 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1345 _mesa_debug(ctx
, "glDrawTransformFeedbackInstanced(%s, %d)\n",
1346 _mesa_enum_to_string(mode
), name
);
1348 vbo_draw_transform_feedback(ctx
, mode
, obj
, 0, primcount
);
1351 static void GLAPIENTRY
1352 vbo_exec_DrawTransformFeedbackStreamInstanced(GLenum mode
, GLuint name
,
1353 GLuint stream
, GLsizei primcount
)
1355 GET_CURRENT_CONTEXT(ctx
);
1356 struct gl_transform_feedback_object
*obj
=
1357 _mesa_lookup_transform_feedback_object(ctx
, name
);
1359 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1360 _mesa_debug(ctx
, "glDrawTransformFeedbackStreamInstanced"
1361 "(%s, %u, %u, %i)\n",
1362 _mesa_enum_to_string(mode
), name
, stream
, primcount
);
1364 vbo_draw_transform_feedback(ctx
, mode
, obj
, stream
, primcount
);
1368 vbo_validated_drawarraysindirect(struct gl_context
*ctx
,
1369 GLenum mode
, const GLvoid
*indirect
)
1371 struct vbo_context
*vbo
= vbo_context(ctx
);
1373 if (!vbo_bind_arrays(ctx
))
1376 vbo
->draw_indirect_prims(ctx
, mode
,
1377 ctx
->DrawIndirectBuffer
, (GLsizeiptr
)indirect
,
1378 1 /* draw_count */, 16 /* stride */,
1381 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1386 vbo_validated_multidrawarraysindirect(struct gl_context
*ctx
,
1388 const GLvoid
*indirect
,
1389 GLsizei primcount
, GLsizei stride
)
1391 struct vbo_context
*vbo
= vbo_context(ctx
);
1392 GLsizeiptr offset
= (GLsizeiptr
)indirect
;
1397 if (!vbo_bind_arrays(ctx
))
1400 vbo
->draw_indirect_prims(ctx
, mode
,
1401 ctx
->DrawIndirectBuffer
, offset
,
1405 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1410 vbo_validated_drawelementsindirect(struct gl_context
*ctx
,
1411 GLenum mode
, GLenum type
,
1412 const GLvoid
*indirect
)
1414 struct vbo_context
*vbo
= vbo_context(ctx
);
1415 struct _mesa_index_buffer ib
;
1417 if (!vbo_bind_arrays(ctx
))
1420 ib
.count
= 0; /* unknown */
1422 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1425 vbo
->draw_indirect_prims(ctx
, mode
,
1426 ctx
->DrawIndirectBuffer
, (GLsizeiptr
)indirect
,
1427 1 /* draw_count */, 20 /* stride */,
1431 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1436 vbo_validated_multidrawelementsindirect(struct gl_context
*ctx
,
1437 GLenum mode
, GLenum type
,
1438 const GLvoid
*indirect
,
1439 GLsizei primcount
, GLsizei stride
)
1441 struct vbo_context
*vbo
= vbo_context(ctx
);
1442 struct _mesa_index_buffer ib
;
1443 GLsizeiptr offset
= (GLsizeiptr
)indirect
;
1448 if (!vbo_bind_arrays(ctx
))
1451 /* NOTE: IndexBufferObj is guaranteed to be a VBO. */
1453 ib
.count
= 0; /* unknown */
1455 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1458 vbo
->draw_indirect_prims(ctx
, mode
,
1459 ctx
->DrawIndirectBuffer
, offset
,
1464 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1469 * Like [Multi]DrawArrays/Elements, but they take most arguments from
1472 static void GLAPIENTRY
1473 vbo_exec_DrawArraysIndirect(GLenum mode
, const GLvoid
*indirect
)
1475 GET_CURRENT_CONTEXT(ctx
);
1477 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1478 _mesa_debug(ctx
, "glDrawArraysIndirect(%s, %p)\n",
1479 _mesa_enum_to_string(mode
), indirect
);
1481 if (!_mesa_validate_DrawArraysIndirect(ctx
, mode
, indirect
))
1484 vbo_validated_drawarraysindirect(ctx
, mode
, indirect
);
1487 static void GLAPIENTRY
1488 vbo_exec_DrawElementsIndirect(GLenum mode
, GLenum type
,
1489 const GLvoid
*indirect
)
1491 GET_CURRENT_CONTEXT(ctx
);
1493 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1494 _mesa_debug(ctx
, "glDrawElementsIndirect(%s, %s, %p)\n",
1495 _mesa_enum_to_string(mode
),
1496 _mesa_enum_to_string(type
), indirect
);
1498 if (!_mesa_validate_DrawElementsIndirect(ctx
, mode
, type
, indirect
))
1501 vbo_validated_drawelementsindirect(ctx
, mode
, type
, indirect
);
1504 static void GLAPIENTRY
1505 vbo_exec_MultiDrawArraysIndirect(GLenum mode
,
1506 const GLvoid
*indirect
,
1507 GLsizei primcount
, GLsizei stride
)
1509 GET_CURRENT_CONTEXT(ctx
);
1511 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1512 _mesa_debug(ctx
, "glMultiDrawArraysIndirect(%s, %p, %i, %i)\n",
1513 _mesa_enum_to_string(mode
), indirect
, primcount
, stride
);
1515 /* If <stride> is zero, the array elements are treated as tightly packed. */
1517 stride
= 4 * sizeof(GLuint
); /* sizeof(DrawArraysIndirectCommand) */
1519 if (!_mesa_validate_MultiDrawArraysIndirect(ctx
, mode
,
1524 vbo_validated_multidrawarraysindirect(ctx
, mode
,
1529 static void GLAPIENTRY
1530 vbo_exec_MultiDrawElementsIndirect(GLenum mode
, GLenum type
,
1531 const GLvoid
*indirect
,
1532 GLsizei primcount
, GLsizei stride
)
1534 GET_CURRENT_CONTEXT(ctx
);
1536 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1537 _mesa_debug(ctx
, "glMultiDrawElementsIndirect(%s, %s, %p, %i, %i)\n",
1538 _mesa_enum_to_string(mode
),
1539 _mesa_enum_to_string(type
), indirect
, primcount
, stride
);
1541 /* If <stride> is zero, the array elements are treated as tightly packed. */
1543 stride
= 5 * sizeof(GLuint
); /* sizeof(DrawElementsIndirectCommand) */
1545 if (!_mesa_validate_MultiDrawElementsIndirect(ctx
, mode
, type
,
1550 vbo_validated_multidrawelementsindirect(ctx
, mode
, type
,
1556 vbo_validated_multidrawarraysindirectcount(struct gl_context
*ctx
,
1560 GLsizei maxdrawcount
,
1563 struct vbo_context
*vbo
= vbo_context(ctx
);
1564 GLsizeiptr offset
= indirect
;
1566 if (maxdrawcount
== 0)
1569 if (!vbo_bind_arrays(ctx
))
1572 vbo
->draw_indirect_prims(ctx
, mode
,
1573 ctx
->DrawIndirectBuffer
, offset
,
1574 maxdrawcount
, stride
,
1575 ctx
->ParameterBuffer
, drawcount
,
1578 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1583 vbo_validated_multidrawelementsindirectcount(struct gl_context
*ctx
,
1584 GLenum mode
, GLenum type
,
1587 GLsizei maxdrawcount
,
1590 struct vbo_context
*vbo
= vbo_context(ctx
);
1591 struct _mesa_index_buffer ib
;
1592 GLsizeiptr offset
= (GLsizeiptr
)indirect
;
1594 if (maxdrawcount
== 0)
1597 if (!vbo_bind_arrays(ctx
))
1600 /* NOTE: IndexBufferObj is guaranteed to be a VBO. */
1602 ib
.count
= 0; /* unknown */
1604 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1607 vbo
->draw_indirect_prims(ctx
, mode
,
1608 ctx
->DrawIndirectBuffer
, offset
,
1609 maxdrawcount
, stride
,
1610 ctx
->ParameterBuffer
, drawcount
,
1613 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1617 static void GLAPIENTRY
1618 vbo_exec_MultiDrawArraysIndirectCount(GLenum mode
,
1621 GLsizei maxdrawcount
, GLsizei stride
)
1623 GET_CURRENT_CONTEXT(ctx
);
1625 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1626 _mesa_debug(ctx
, "glMultiDrawArraysIndirectCountARB"
1627 "(%s, %lx, %lx, %i, %i)\n",
1628 _mesa_enum_to_string(mode
), indirect
,
1629 drawcount
, maxdrawcount
, stride
);
1631 /* If <stride> is zero, the array elements are treated as tightly packed. */
1633 stride
= 4 * sizeof(GLuint
); /* sizeof(DrawArraysIndirectCommand) */
1635 if (!_mesa_validate_MultiDrawArraysIndirectCount(ctx
, mode
,
1636 indirect
, drawcount
,
1637 maxdrawcount
, stride
))
1640 vbo_validated_multidrawarraysindirectcount(ctx
, mode
,
1641 indirect
, drawcount
,
1642 maxdrawcount
, stride
);
1645 static void GLAPIENTRY
1646 vbo_exec_MultiDrawElementsIndirectCount(GLenum mode
, GLenum type
,
1649 GLsizei maxdrawcount
, GLsizei stride
)
1651 GET_CURRENT_CONTEXT(ctx
);
1653 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1654 _mesa_debug(ctx
, "glMultiDrawElementsIndirectCountARB"
1655 "(%s, %s, %lx, %lx, %i, %i)\n",
1656 _mesa_enum_to_string(mode
),
1657 _mesa_enum_to_string(type
), indirect
,
1658 drawcount
, maxdrawcount
, stride
);
1660 /* If <stride> is zero, the array elements are treated as tightly packed. */
1662 stride
= 5 * sizeof(GLuint
); /* sizeof(DrawElementsIndirectCommand) */
1664 if (!_mesa_validate_MultiDrawElementsIndirectCount(ctx
, mode
, type
,
1665 indirect
, drawcount
,
1666 maxdrawcount
, stride
))
1669 vbo_validated_multidrawelementsindirectcount(ctx
, mode
, type
,
1670 indirect
, drawcount
,
1671 maxdrawcount
, stride
);
1676 * Initialize the dispatch table with the VBO functions for drawing.
1679 vbo_initialize_exec_dispatch(const struct gl_context
*ctx
,
1680 struct _glapi_table
*exec
)
1682 SET_DrawArrays(exec
, vbo_exec_DrawArrays
);
1683 SET_DrawElements(exec
, vbo_exec_DrawElements
);
1685 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1686 SET_DrawRangeElements(exec
, vbo_exec_DrawRangeElements
);
1689 SET_MultiDrawElementsEXT(exec
, vbo_exec_MultiDrawElements
);
1691 if (ctx
->API
== API_OPENGL_COMPAT
) {
1692 SET_Rectf(exec
, vbo_exec_Rectf
);
1693 SET_EvalMesh1(exec
, vbo_exec_EvalMesh1
);
1694 SET_EvalMesh2(exec
, vbo_exec_EvalMesh2
);
1697 if (ctx
->API
!= API_OPENGLES
&&
1698 ctx
->Extensions
.ARB_draw_elements_base_vertex
) {
1699 SET_DrawElementsBaseVertex(exec
, vbo_exec_DrawElementsBaseVertex
);
1700 SET_MultiDrawElementsBaseVertex(exec
, vbo_exec_MultiDrawElementsBaseVertex
);
1702 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1703 SET_DrawRangeElementsBaseVertex(exec
, vbo_exec_DrawRangeElementsBaseVertex
);
1704 SET_DrawElementsInstancedBaseVertex(exec
, vbo_exec_DrawElementsInstancedBaseVertex
);
1708 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1709 SET_DrawArraysInstancedBaseInstance(exec
, vbo_exec_DrawArraysInstancedBaseInstance
);
1710 SET_DrawElementsInstancedBaseInstance(exec
, vbo_exec_DrawElementsInstancedBaseInstance
);
1711 SET_DrawElementsInstancedBaseVertexBaseInstance(exec
, vbo_exec_DrawElementsInstancedBaseVertexBaseInstance
);
1714 if (ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) {
1715 SET_DrawArraysIndirect(exec
, vbo_exec_DrawArraysIndirect
);
1716 SET_DrawElementsIndirect(exec
, vbo_exec_DrawElementsIndirect
);
1719 if (ctx
->API
== API_OPENGL_CORE
) {
1720 SET_MultiDrawArraysIndirect(exec
, vbo_exec_MultiDrawArraysIndirect
);
1721 SET_MultiDrawElementsIndirect(exec
, vbo_exec_MultiDrawElementsIndirect
);
1722 SET_MultiDrawArraysIndirectCountARB(exec
, vbo_exec_MultiDrawArraysIndirectCount
);
1723 SET_MultiDrawElementsIndirectCountARB(exec
, vbo_exec_MultiDrawElementsIndirectCount
);
1726 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1727 SET_DrawArraysInstancedARB(exec
, vbo_exec_DrawArraysInstanced
);
1728 SET_DrawElementsInstancedARB(exec
, vbo_exec_DrawElementsInstanced
);
1731 if (_mesa_is_desktop_gl(ctx
)) {
1732 SET_DrawTransformFeedback(exec
, vbo_exec_DrawTransformFeedback
);
1733 SET_DrawTransformFeedbackStream(exec
, vbo_exec_DrawTransformFeedbackStream
);
1734 SET_DrawTransformFeedbackInstanced(exec
, vbo_exec_DrawTransformFeedbackInstanced
);
1735 SET_DrawTransformFeedbackStreamInstanced(exec
, vbo_exec_DrawTransformFeedbackStreamInstanced
);
1742 * The following functions are only used for OpenGL ES 1/2 support.
1743 * And some aren't even supported (yet) in ES 1/2.
1748 _mesa_DrawArrays(GLenum mode
, GLint first
, GLsizei count
)
1750 vbo_exec_DrawArrays(mode
, first
, count
);
1754 _mesa_DrawArraysInstanced(GLenum mode
, GLint first
, GLsizei count
,
1757 vbo_exec_DrawArraysInstanced(mode
, first
, count
, primcount
);
1761 _mesa_DrawElements(GLenum mode
, GLsizei count
, GLenum type
,
1762 const GLvoid
*indices
)
1764 vbo_exec_DrawElements(mode
, count
, type
, indices
);
1769 _mesa_DrawElementsBaseVertex(GLenum mode
, GLsizei count
, GLenum type
,
1770 const GLvoid
*indices
, GLint basevertex
)
1772 vbo_exec_DrawElementsBaseVertex(mode
, count
, type
, indices
, basevertex
);
1777 _mesa_DrawRangeElements(GLenum mode
, GLuint start
, GLuint end
, GLsizei count
,
1778 GLenum type
, const GLvoid
*indices
)
1780 vbo_exec_DrawRangeElements(mode
, start
, end
, count
, type
, indices
);
1785 _mesa_DrawRangeElementsBaseVertex(GLenum mode
, GLuint start
, GLuint end
,
1786 GLsizei count
, GLenum type
,
1787 const GLvoid
*indices
, GLint basevertex
)
1789 vbo_exec_DrawRangeElementsBaseVertex(mode
, start
, end
, count
, type
,
1790 indices
, basevertex
);
1795 _mesa_MultiDrawElementsEXT(GLenum mode
, const GLsizei
*count
, GLenum type
,
1796 const GLvoid
**indices
, GLsizei primcount
)
1798 vbo_exec_MultiDrawElements(mode
, count
, type
, indices
, primcount
);
1803 _mesa_MultiDrawElementsBaseVertex(GLenum mode
,
1804 const GLsizei
*count
, GLenum type
,
1805 const GLvoid
**indices
, GLsizei primcount
,
1806 const GLint
*basevertex
)
1808 vbo_exec_MultiDrawElementsBaseVertex(mode
, count
, type
, indices
,
1809 primcount
, basevertex
);
1813 _mesa_DrawTransformFeedback(GLenum mode
, GLuint name
)
1815 vbo_exec_DrawTransformFeedback(mode
, name
);