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
;
401 * Helper function called by the other DrawArrays() functions below.
402 * This is where we handle primitive restart for drawing non-indexed
403 * arrays. If primitive restart is enabled, it typically means
404 * splitting one DrawArrays() into two.
407 vbo_draw_arrays(struct gl_context
*ctx
, GLenum mode
, GLint start
,
408 GLsizei count
, GLuint numInstances
, GLuint baseInstance
)
410 struct vbo_context
*vbo
= vbo_context(ctx
);
411 struct _mesa_prim prim
[2];
413 vbo_bind_arrays(ctx
);
415 /* init most fields to zero */
416 memset(prim
, 0, sizeof(prim
));
420 prim
[0].num_instances
= numInstances
;
421 prim
[0].base_instance
= baseInstance
;
422 prim
[0].is_indirect
= 0;
424 /* Implement the primitive restart index */
425 if (ctx
->Array
.PrimitiveRestart
&& !ctx
->Array
.PrimitiveRestartFixedIndex
&&
426 ctx
->Array
.RestartIndex
< count
) {
427 GLuint primCount
= 0;
429 if (ctx
->Array
.RestartIndex
== start
) {
430 /* special case: RestartIndex at beginning */
432 prim
[0].start
= start
+ 1;
433 prim
[0].count
= count
- 1;
437 else if (ctx
->Array
.RestartIndex
== start
+ count
- 1) {
438 /* special case: RestartIndex at end */
440 prim
[0].start
= start
;
441 prim
[0].count
= count
- 1;
446 /* general case: RestartIndex in middle, split into two prims */
447 prim
[0].start
= start
;
448 prim
[0].count
= ctx
->Array
.RestartIndex
- start
;
451 prim
[1].start
= ctx
->Array
.RestartIndex
+ 1;
452 prim
[1].count
= count
- prim
[1].start
;
458 /* draw one or two prims */
459 vbo
->draw_prims(ctx
, prim
, primCount
, NULL
,
460 GL_TRUE
, start
, start
+ count
- 1, NULL
, 0, NULL
);
464 /* no prim restart */
465 prim
[0].start
= start
;
466 prim
[0].count
= count
;
468 vbo
->draw_prims(ctx
, prim
, 1, NULL
,
469 GL_TRUE
, start
, start
+ count
- 1,
473 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
) {
480 * Execute a glRectf() function.
482 static void GLAPIENTRY
483 vbo_exec_Rectf(GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
)
485 GET_CURRENT_CONTEXT(ctx
);
486 ASSERT_OUTSIDE_BEGIN_END(ctx
);
488 CALL_Begin(GET_DISPATCH(), (GL_QUADS
));
489 CALL_Vertex2f(GET_DISPATCH(), (x1
, y1
));
490 CALL_Vertex2f(GET_DISPATCH(), (x2
, y1
));
491 CALL_Vertex2f(GET_DISPATCH(), (x2
, y2
));
492 CALL_Vertex2f(GET_DISPATCH(), (x1
, y2
));
493 CALL_End(GET_DISPATCH(), ());
497 static void GLAPIENTRY
498 vbo_exec_EvalMesh1(GLenum mode
, GLint i1
, GLint i2
)
500 GET_CURRENT_CONTEXT(ctx
);
510 prim
= GL_LINE_STRIP
;
513 _mesa_error( ctx
, GL_INVALID_ENUM
, "glEvalMesh1(mode)" );
517 /* No effect if vertex maps disabled.
519 if (!ctx
->Eval
.Map1Vertex4
&&
520 !ctx
->Eval
.Map1Vertex3
)
523 du
= ctx
->Eval
.MapGrid1du
;
524 u
= ctx
->Eval
.MapGrid1u1
+ i1
* du
;
526 CALL_Begin(GET_DISPATCH(), (prim
));
527 for (i
=i1
;i
<=i2
;i
++,u
+=du
) {
528 CALL_EvalCoord1f(GET_DISPATCH(), (u
));
530 CALL_End(GET_DISPATCH(), ());
534 static void GLAPIENTRY
535 vbo_exec_EvalMesh2(GLenum mode
, GLint i1
, GLint i2
, GLint j1
, GLint j2
)
537 GET_CURRENT_CONTEXT(ctx
);
538 GLfloat u
, du
, v
, dv
, v1
, u1
;
547 _mesa_error( ctx
, GL_INVALID_ENUM
, "glEvalMesh2(mode)" );
551 /* No effect if vertex maps disabled.
553 if (!ctx
->Eval
.Map2Vertex4
&&
554 !ctx
->Eval
.Map2Vertex3
)
557 du
= ctx
->Eval
.MapGrid2du
;
558 dv
= ctx
->Eval
.MapGrid2dv
;
559 v1
= ctx
->Eval
.MapGrid2v1
+ j1
* dv
;
560 u1
= ctx
->Eval
.MapGrid2u1
+ i1
* du
;
564 CALL_Begin(GET_DISPATCH(), (GL_POINTS
));
565 for (v
=v1
,j
=j1
;j
<=j2
;j
++,v
+=dv
) {
566 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
567 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
570 CALL_End(GET_DISPATCH(), ());
573 for (v
=v1
,j
=j1
;j
<=j2
;j
++,v
+=dv
) {
574 CALL_Begin(GET_DISPATCH(), (GL_LINE_STRIP
));
575 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
576 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
578 CALL_End(GET_DISPATCH(), ());
580 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
581 CALL_Begin(GET_DISPATCH(), (GL_LINE_STRIP
));
582 for (v
=v1
,j
=j1
;j
<=j2
;j
++,v
+=dv
) {
583 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
585 CALL_End(GET_DISPATCH(), ());
589 for (v
=v1
,j
=j1
;j
<j2
;j
++,v
+=dv
) {
590 CALL_Begin(GET_DISPATCH(), (GL_TRIANGLE_STRIP
));
591 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
592 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
593 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
+dv
));
595 CALL_End(GET_DISPATCH(), ());
603 * Called from glDrawArrays when in immediate mode (not display list mode).
605 static void GLAPIENTRY
606 vbo_exec_DrawArrays(GLenum mode
, GLint start
, GLsizei count
)
608 GET_CURRENT_CONTEXT(ctx
);
610 if (MESA_VERBOSE
& VERBOSE_DRAW
)
611 _mesa_debug(ctx
, "glDrawArrays(%s, %d, %d)\n",
612 _mesa_enum_to_string(mode
), start
, count
);
614 if (!_mesa_validate_DrawArrays(ctx
, mode
, count
))
618 check_draw_arrays_data(ctx
, start
, count
);
620 vbo_draw_arrays(ctx
, mode
, start
, count
, 1, 0);
623 print_draw_arrays(ctx
, mode
, start
, count
);
628 * Called from glDrawArraysInstanced when in immediate mode (not
629 * display list mode).
631 static void GLAPIENTRY
632 vbo_exec_DrawArraysInstanced(GLenum mode
, GLint start
, GLsizei count
,
633 GLsizei numInstances
)
635 GET_CURRENT_CONTEXT(ctx
);
637 if (MESA_VERBOSE
& VERBOSE_DRAW
)
638 _mesa_debug(ctx
, "glDrawArraysInstanced(%s, %d, %d, %d)\n",
639 _mesa_enum_to_string(mode
), start
, count
, numInstances
);
641 if (!_mesa_validate_DrawArraysInstanced(ctx
, mode
, start
, count
, numInstances
))
645 check_draw_arrays_data(ctx
, start
, count
);
647 vbo_draw_arrays(ctx
, mode
, start
, count
, numInstances
, 0);
650 print_draw_arrays(ctx
, mode
, start
, count
);
655 * Called from glDrawArraysInstancedBaseInstance when in immediate mode.
657 static void GLAPIENTRY
658 vbo_exec_DrawArraysInstancedBaseInstance(GLenum mode
, GLint first
, GLsizei count
,
659 GLsizei numInstances
, GLuint baseInstance
)
661 GET_CURRENT_CONTEXT(ctx
);
663 if (MESA_VERBOSE
& VERBOSE_DRAW
)
664 _mesa_debug(ctx
, "glDrawArraysInstancedBaseInstance(%s, %d, %d, %d, %d)\n",
665 _mesa_enum_to_string(mode
), first
, count
,
666 numInstances
, baseInstance
);
668 if (!_mesa_validate_DrawArraysInstanced(ctx
, mode
, first
, count
,
673 check_draw_arrays_data(ctx
, first
, count
);
675 vbo_draw_arrays(ctx
, mode
, first
, count
, numInstances
, baseInstance
);
678 print_draw_arrays(ctx
, mode
, first
, count
);
684 * Map GL_ELEMENT_ARRAY_BUFFER and print contents.
689 dump_element_buffer(struct gl_context
*ctx
, GLenum type
)
692 ctx
->Driver
.MapBufferRange(ctx
, 0,
693 ctx
->Array
.VAO
->IndexBufferObj
->Size
,
695 ctx
->Array
.VAO
->IndexBufferObj
,
698 case GL_UNSIGNED_BYTE
:
700 const GLubyte
*us
= (const GLubyte
*) map
;
702 for (i
= 0; i
< ctx
->Array
.VAO
->IndexBufferObj
->Size
; i
++) {
703 printf("%02x ", us
[i
]);
710 case GL_UNSIGNED_SHORT
:
712 const GLushort
*us
= (const GLushort
*) map
;
714 for (i
= 0; i
< ctx
->Array
.VAO
->IndexBufferObj
->Size
/ 2; i
++) {
715 printf("%04x ", us
[i
]);
722 case GL_UNSIGNED_INT
:
724 const GLuint
*us
= (const GLuint
*) map
;
726 for (i
= 0; i
< ctx
->Array
.VAO
->IndexBufferObj
->Size
/ 4; i
++) {
727 printf("%08x ", us
[i
]);
738 ctx
->Driver
.UnmapBuffer(ctx
, ctx
->Array
.VAO
->IndexBufferObj
,
745 * Inner support for both _mesa_DrawElements and _mesa_DrawRangeElements.
746 * Do the rendering for a glDrawElements or glDrawRangeElements call after
747 * we've validated buffer bounds, etc.
750 vbo_validated_drawrangeelements(struct gl_context
*ctx
, GLenum mode
,
751 GLboolean index_bounds_valid
,
752 GLuint start
, GLuint end
,
753 GLsizei count
, GLenum type
,
754 const GLvoid
*indices
,
755 GLint basevertex
, GLuint numInstances
,
758 struct vbo_context
*vbo
= vbo_context(ctx
);
759 struct _mesa_index_buffer ib
;
760 struct _mesa_prim prim
[1];
762 vbo_bind_arrays(ctx
);
766 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
775 prim
[0].count
= count
;
777 prim
[0].is_indirect
= 0;
778 prim
[0].basevertex
= basevertex
;
779 prim
[0].num_instances
= numInstances
;
780 prim
[0].base_instance
= baseInstance
;
783 /* Need to give special consideration to rendering a range of
784 * indices starting somewhere above zero. Typically the
785 * application is issuing multiple DrawRangeElements() to draw
786 * successive primitives layed out linearly in the vertex arrays.
787 * Unless the vertex arrays are all in a VBO (or locked as with
788 * CVA), the OpenGL semantics imply that we need to re-read or
789 * re-upload the vertex data on each draw call.
791 * In the case of hardware tnl, we want to avoid starting the
792 * upload at zero, as it will mean every draw call uploads an
793 * increasing amount of not-used vertex data. Worse - in the
794 * software tnl module, all those vertices might be transformed and
795 * lit but never rendered.
797 * If we just upload or transform the vertices in start..end,
798 * however, the indices will be incorrect.
800 * At this level, we don't know exactly what the requirements of
801 * the backend are going to be, though it will likely boil down to
804 * 1) Do nothing, everything is in a VBO and is processed once
807 * 2) Adjust the indices and vertex arrays so that start becomes
810 * Rather than doing anything here, I'll provide a helper function
811 * for the latter case elsewhere.
814 vbo
->draw_prims(ctx
, prim
, 1, &ib
,
815 index_bounds_valid
, start
, end
, NULL
, 0, NULL
);
817 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
) {
824 * Called by glDrawRangeElementsBaseVertex() in immediate mode.
826 static void GLAPIENTRY
827 vbo_exec_DrawRangeElementsBaseVertex(GLenum mode
,
828 GLuint start
, GLuint end
,
829 GLsizei count
, GLenum type
,
830 const GLvoid
*indices
,
833 static GLuint warnCount
= 0;
834 GLboolean index_bounds_valid
= GL_TRUE
;
836 /* This is only useful to catch invalid values in the "end" parameter
839 GLuint max_element
= 2 * 1000 * 1000 * 1000; /* just a big number */
841 GET_CURRENT_CONTEXT(ctx
);
843 if (MESA_VERBOSE
& VERBOSE_DRAW
)
845 "glDrawRangeElementsBaseVertex(%s, %u, %u, %d, %s, %p, %d)\n",
846 _mesa_enum_to_string(mode
), start
, end
, count
,
847 _mesa_enum_to_string(type
), indices
, basevertex
);
849 if (!_mesa_validate_DrawRangeElements(ctx
, mode
, start
, end
, count
,
853 if ((int) end
+ basevertex
< 0 ||
854 start
+ basevertex
>= max_element
) {
855 /* The application requested we draw using a range of indices that's
856 * outside the bounds of the current VBO. This is invalid and appears
857 * to give undefined results. The safest thing to do is to simply
858 * ignore the range, in case the application botched their range tracking
859 * but did provide valid indices. Also issue a warning indicating that
860 * the application is broken.
862 if (warnCount
++ < 10) {
863 _mesa_warning(ctx
, "glDrawRangeElements(start %u, end %u, "
864 "basevertex %d, count %d, type 0x%x, indices=%p):\n"
865 "\trange is outside VBO bounds (max=%u); ignoring.\n"
866 "\tThis should be fixed in the application.",
867 start
, end
, basevertex
, count
, type
, indices
,
870 index_bounds_valid
= GL_FALSE
;
873 /* NOTE: It's important that 'end' is a reasonable value.
874 * in _tnl_draw_prims(), we use end to determine how many vertices
875 * to transform. If it's too large, we can unnecessarily split prims
876 * or we can read/write out of memory in several different places!
879 /* Catch/fix some potential user errors */
880 if (type
== GL_UNSIGNED_BYTE
) {
881 start
= MIN2(start
, 0xff);
882 end
= MIN2(end
, 0xff);
884 else if (type
== GL_UNSIGNED_SHORT
) {
885 start
= MIN2(start
, 0xffff);
886 end
= MIN2(end
, 0xffff);
890 printf("glDraw[Range]Elements{,BaseVertex}"
891 "(start %u, end %u, type 0x%x, count %d) ElemBuf %u, "
893 start
, end
, type
, count
,
894 ctx
->Array
.VAO
->IndexBufferObj
->Name
,
898 if ((int) start
+ basevertex
< 0 ||
899 end
+ basevertex
>= max_element
)
900 index_bounds_valid
= GL_FALSE
;
903 check_draw_elements_data(ctx
, count
, type
, indices
, basevertex
);
905 (void) check_draw_elements_data
;
908 vbo_validated_drawrangeelements(ctx
, mode
, index_bounds_valid
, start
, end
,
909 count
, type
, indices
, basevertex
, 1, 0);
914 * Called by glDrawRangeElements() in immediate mode.
916 static void GLAPIENTRY
917 vbo_exec_DrawRangeElements(GLenum mode
, GLuint start
, GLuint end
,
918 GLsizei count
, GLenum type
, const GLvoid
*indices
)
920 if (MESA_VERBOSE
& VERBOSE_DRAW
) {
921 GET_CURRENT_CONTEXT(ctx
);
923 "glDrawRangeElements(%s, %u, %u, %d, %s, %p)\n",
924 _mesa_enum_to_string(mode
), start
, end
, count
,
925 _mesa_enum_to_string(type
), indices
);
928 vbo_exec_DrawRangeElementsBaseVertex(mode
, start
, end
, count
, type
,
934 * Called by glDrawElements() in immediate mode.
936 static void GLAPIENTRY
937 vbo_exec_DrawElements(GLenum mode
, GLsizei count
, GLenum type
,
938 const GLvoid
*indices
)
940 GET_CURRENT_CONTEXT(ctx
);
942 if (MESA_VERBOSE
& VERBOSE_DRAW
)
943 _mesa_debug(ctx
, "glDrawElements(%s, %u, %s, %p)\n",
944 _mesa_enum_to_string(mode
), count
,
945 _mesa_enum_to_string(type
), indices
);
947 if (!_mesa_validate_DrawElements(ctx
, mode
, count
, type
, indices
))
950 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
951 count
, type
, indices
, 0, 1, 0);
956 * Called by glDrawElementsBaseVertex() in immediate mode.
958 static void GLAPIENTRY
959 vbo_exec_DrawElementsBaseVertex(GLenum mode
, GLsizei count
, GLenum type
,
960 const GLvoid
*indices
, GLint basevertex
)
962 GET_CURRENT_CONTEXT(ctx
);
964 if (MESA_VERBOSE
& VERBOSE_DRAW
)
965 _mesa_debug(ctx
, "glDrawElementsBaseVertex(%s, %d, %s, %p, %d)\n",
966 _mesa_enum_to_string(mode
), count
,
967 _mesa_enum_to_string(type
), indices
, basevertex
);
969 if (!_mesa_validate_DrawElements(ctx
, mode
, count
, type
, indices
))
972 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
973 count
, type
, indices
, basevertex
, 1, 0);
978 * Called by glDrawElementsInstanced() in immediate mode.
980 static void GLAPIENTRY
981 vbo_exec_DrawElementsInstanced(GLenum mode
, GLsizei count
, GLenum type
,
982 const GLvoid
*indices
, GLsizei numInstances
)
984 GET_CURRENT_CONTEXT(ctx
);
986 if (MESA_VERBOSE
& VERBOSE_DRAW
)
987 _mesa_debug(ctx
, "glDrawElementsInstanced(%s, %d, %s, %p, %d)\n",
988 _mesa_enum_to_string(mode
), count
,
989 _mesa_enum_to_string(type
), indices
, numInstances
);
991 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
995 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
996 count
, type
, indices
, 0, numInstances
, 0);
1001 * Called by glDrawElementsInstancedBaseVertex() in immediate mode.
1003 static void GLAPIENTRY
1004 vbo_exec_DrawElementsInstancedBaseVertex(GLenum mode
, GLsizei count
, GLenum type
,
1005 const GLvoid
*indices
, GLsizei numInstances
,
1008 GET_CURRENT_CONTEXT(ctx
);
1010 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1011 _mesa_debug(ctx
, "glDrawElementsInstancedBaseVertex(%s, %d, %s, %p, %d; %d)\n",
1012 _mesa_enum_to_string(mode
), count
,
1013 _mesa_enum_to_string(type
), indices
,
1014 numInstances
, basevertex
);
1016 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
1020 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1021 count
, type
, indices
, basevertex
, numInstances
, 0);
1026 * Called by glDrawElementsInstancedBaseInstance() in immediate mode.
1028 static void GLAPIENTRY
1029 vbo_exec_DrawElementsInstancedBaseInstance(GLenum mode
, GLsizei count
, GLenum type
,
1030 const GLvoid
*indices
, GLsizei numInstances
,
1031 GLuint baseInstance
)
1033 GET_CURRENT_CONTEXT(ctx
);
1035 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1036 _mesa_debug(ctx
, "glDrawElementsInstancedBaseInstance(%s, %d, %s, %p, %d, %d)\n",
1037 _mesa_enum_to_string(mode
), count
,
1038 _mesa_enum_to_string(type
), indices
,
1039 numInstances
, baseInstance
);
1041 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
1045 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1046 count
, type
, indices
, 0, numInstances
,
1052 * Called by glDrawElementsInstancedBaseVertexBaseInstance() in immediate mode.
1054 static void GLAPIENTRY
1055 vbo_exec_DrawElementsInstancedBaseVertexBaseInstance(GLenum mode
, GLsizei count
, GLenum type
,
1056 const GLvoid
*indices
, GLsizei numInstances
,
1057 GLint basevertex
, GLuint baseInstance
)
1059 GET_CURRENT_CONTEXT(ctx
);
1061 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1062 _mesa_debug(ctx
, "glDrawElementsInstancedBaseVertexBaseInstance(%s, %d, %s, %p, %d, %d, %d)\n",
1063 _mesa_enum_to_string(mode
), count
,
1064 _mesa_enum_to_string(type
), indices
,
1065 numInstances
, basevertex
, baseInstance
);
1067 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
1071 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1072 count
, type
, indices
, basevertex
, numInstances
,
1078 * Inner support for both _mesa_MultiDrawElements() and
1079 * _mesa_MultiDrawRangeElements().
1080 * This does the actual rendering after we've checked array indexes, etc.
1083 vbo_validated_multidrawelements(struct gl_context
*ctx
, GLenum mode
,
1084 const GLsizei
*count
, GLenum type
,
1085 const GLvoid
* const *indices
,
1087 const GLint
*basevertex
)
1089 struct vbo_context
*vbo
= vbo_context(ctx
);
1090 struct _mesa_index_buffer ib
;
1091 struct _mesa_prim
*prim
;
1092 unsigned int index_type_size
= vbo_sizeof_ib_type(type
);
1093 uintptr_t min_index_ptr
, max_index_ptr
;
1094 GLboolean fallback
= GL_FALSE
;
1100 prim
= calloc(primcount
, sizeof(*prim
));
1102 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMultiDrawElements");
1106 vbo_bind_arrays(ctx
);
1108 min_index_ptr
= (uintptr_t)indices
[0];
1110 for (i
= 0; i
< primcount
; i
++) {
1111 min_index_ptr
= MIN2(min_index_ptr
, (uintptr_t)indices
[i
]);
1112 max_index_ptr
= MAX2(max_index_ptr
, (uintptr_t)indices
[i
] +
1113 index_type_size
* count
[i
]);
1116 /* Check if we can handle this thing as a bunch of index offsets from the
1117 * same index pointer. If we can't, then we have to fall back to doing
1118 * a draw_prims per primitive.
1119 * Check that the difference between each prim's indexes is a multiple of
1120 * the index/element size.
1122 if (index_type_size
!= 1) {
1123 for (i
= 0; i
< primcount
; i
++) {
1124 if ((((uintptr_t)indices
[i
] - min_index_ptr
) % index_type_size
) != 0) {
1131 /* Draw primitives individually if one count is zero, so we can easily skip
1134 for (i
= 0; i
< primcount
; i
++) {
1135 if (count
[i
] == 0) {
1141 /* If the index buffer isn't in a VBO, then treating the application's
1142 * subranges of the index buffer as one large index buffer may lead to
1143 * us reading unmapped memory.
1145 if (!_mesa_is_bufferobj(ctx
->Array
.VAO
->IndexBufferObj
))
1149 ib
.count
= (max_index_ptr
- min_index_ptr
) / index_type_size
;
1151 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1152 ib
.ptr
= (void *)min_index_ptr
;
1154 for (i
= 0; i
< primcount
; i
++) {
1155 prim
[i
].begin
= (i
== 0);
1156 prim
[i
].end
= (i
== primcount
- 1);
1159 prim
[i
].mode
= mode
;
1160 prim
[i
].start
= ((uintptr_t)indices
[i
] - min_index_ptr
) / index_type_size
;
1161 prim
[i
].count
= count
[i
];
1162 prim
[i
].indexed
= 1;
1163 prim
[i
].num_instances
= 1;
1164 prim
[i
].base_instance
= 0;
1165 prim
[i
].draw_id
= i
;
1166 prim
[i
].is_indirect
= 0;
1167 if (basevertex
!= NULL
)
1168 prim
[i
].basevertex
= basevertex
[i
];
1170 prim
[i
].basevertex
= 0;
1173 vbo
->draw_prims(ctx
, prim
, primcount
, &ib
,
1174 false, ~0, ~0, NULL
, 0, NULL
);
1176 /* render one prim at a time */
1177 for (i
= 0; i
< primcount
; i
++) {
1180 ib
.count
= count
[i
];
1182 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1183 ib
.ptr
= indices
[i
];
1189 prim
[0].mode
= mode
;
1191 prim
[0].count
= count
[i
];
1192 prim
[0].indexed
= 1;
1193 prim
[0].num_instances
= 1;
1194 prim
[0].base_instance
= 0;
1195 prim
[0].draw_id
= i
;
1196 prim
[0].is_indirect
= 0;
1197 if (basevertex
!= NULL
)
1198 prim
[0].basevertex
= basevertex
[i
];
1200 prim
[0].basevertex
= 0;
1202 vbo
->draw_prims(ctx
, prim
, 1, &ib
,
1203 false, ~0, ~0, NULL
, 0, NULL
);
1209 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
) {
1215 static void GLAPIENTRY
1216 vbo_exec_MultiDrawElements(GLenum mode
,
1217 const GLsizei
*count
, GLenum type
,
1218 const GLvoid
* const *indices
,
1221 GET_CURRENT_CONTEXT(ctx
);
1223 if (!_mesa_validate_MultiDrawElements(ctx
, mode
, count
, type
, indices
,
1227 vbo_validated_multidrawelements(ctx
, mode
, count
, type
, indices
, primcount
,
1232 static void GLAPIENTRY
1233 vbo_exec_MultiDrawElementsBaseVertex(GLenum mode
,
1234 const GLsizei
*count
, GLenum type
,
1235 const GLvoid
* const *indices
,
1237 const GLsizei
*basevertex
)
1239 GET_CURRENT_CONTEXT(ctx
);
1241 if (!_mesa_validate_MultiDrawElements(ctx
, mode
, count
, type
, indices
,
1245 vbo_validated_multidrawelements(ctx
, mode
, count
, type
, indices
, primcount
,
1250 vbo_draw_transform_feedback(struct gl_context
*ctx
, GLenum mode
,
1251 struct gl_transform_feedback_object
*obj
,
1252 GLuint stream
, GLuint numInstances
)
1254 struct vbo_context
*vbo
= vbo_context(ctx
);
1255 struct _mesa_prim prim
[2];
1257 if (!_mesa_validate_DrawTransformFeedback(ctx
, mode
, obj
, stream
,
1262 if (ctx
->Driver
.GetTransformFeedbackVertexCount
&&
1263 (ctx
->Const
.AlwaysUseGetTransformFeedbackVertexCount
||
1264 !_mesa_all_varyings_in_vbos(ctx
->Array
.VAO
))) {
1265 GLsizei n
= ctx
->Driver
.GetTransformFeedbackVertexCount(ctx
, obj
, stream
);
1266 vbo_draw_arrays(ctx
, mode
, 0, n
, numInstances
, 0);
1270 vbo_bind_arrays(ctx
);
1272 /* init most fields to zero */
1273 memset(prim
, 0, sizeof(prim
));
1276 prim
[0].mode
= mode
;
1277 prim
[0].num_instances
= numInstances
;
1278 prim
[0].base_instance
= 0;
1279 prim
[0].is_indirect
= 0;
1281 /* Maybe we should do some primitive splitting for primitive restart
1282 * (like in DrawArrays), but we have no way to know how many vertices
1283 * will be rendered. */
1285 vbo
->draw_prims(ctx
, prim
, 1, NULL
,
1286 GL_FALSE
, ~0, ~0, obj
, stream
, NULL
);
1288 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
) {
1294 * Like DrawArrays, but take the count from a transform feedback object.
1295 * \param mode GL_POINTS, GL_LINES, GL_TRIANGLE_STRIP, etc.
1296 * \param name the transform feedback object
1297 * User still has to setup of the vertex attribute info with
1298 * glVertexPointer, glColorPointer, etc.
1299 * Part of GL_ARB_transform_feedback2.
1301 static void GLAPIENTRY
1302 vbo_exec_DrawTransformFeedback(GLenum mode
, GLuint name
)
1304 GET_CURRENT_CONTEXT(ctx
);
1305 struct gl_transform_feedback_object
*obj
=
1306 _mesa_lookup_transform_feedback_object(ctx
, name
);
1308 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1309 _mesa_debug(ctx
, "glDrawTransformFeedback(%s, %d)\n",
1310 _mesa_enum_to_string(mode
), name
);
1312 vbo_draw_transform_feedback(ctx
, mode
, obj
, 0, 1);
1315 static void GLAPIENTRY
1316 vbo_exec_DrawTransformFeedbackStream(GLenum mode
, GLuint name
, GLuint stream
)
1318 GET_CURRENT_CONTEXT(ctx
);
1319 struct gl_transform_feedback_object
*obj
=
1320 _mesa_lookup_transform_feedback_object(ctx
, name
);
1322 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1323 _mesa_debug(ctx
, "glDrawTransformFeedbackStream(%s, %u, %u)\n",
1324 _mesa_enum_to_string(mode
), name
, stream
);
1326 vbo_draw_transform_feedback(ctx
, mode
, obj
, stream
, 1);
1329 static void GLAPIENTRY
1330 vbo_exec_DrawTransformFeedbackInstanced(GLenum mode
, GLuint name
,
1333 GET_CURRENT_CONTEXT(ctx
);
1334 struct gl_transform_feedback_object
*obj
=
1335 _mesa_lookup_transform_feedback_object(ctx
, name
);
1337 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1338 _mesa_debug(ctx
, "glDrawTransformFeedbackInstanced(%s, %d)\n",
1339 _mesa_enum_to_string(mode
), name
);
1341 vbo_draw_transform_feedback(ctx
, mode
, obj
, 0, primcount
);
1344 static void GLAPIENTRY
1345 vbo_exec_DrawTransformFeedbackStreamInstanced(GLenum mode
, GLuint name
,
1346 GLuint stream
, GLsizei primcount
)
1348 GET_CURRENT_CONTEXT(ctx
);
1349 struct gl_transform_feedback_object
*obj
=
1350 _mesa_lookup_transform_feedback_object(ctx
, name
);
1352 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1353 _mesa_debug(ctx
, "glDrawTransformFeedbackStreamInstanced"
1354 "(%s, %u, %u, %i)\n",
1355 _mesa_enum_to_string(mode
), name
, stream
, primcount
);
1357 vbo_draw_transform_feedback(ctx
, mode
, obj
, stream
, primcount
);
1361 vbo_validated_drawarraysindirect(struct gl_context
*ctx
,
1362 GLenum mode
, const GLvoid
*indirect
)
1364 struct vbo_context
*vbo
= vbo_context(ctx
);
1366 vbo_bind_arrays(ctx
);
1368 vbo
->draw_indirect_prims(ctx
, mode
,
1369 ctx
->DrawIndirectBuffer
, (GLsizeiptr
)indirect
,
1370 1 /* draw_count */, 16 /* stride */,
1373 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1378 vbo_validated_multidrawarraysindirect(struct gl_context
*ctx
,
1380 const GLvoid
*indirect
,
1381 GLsizei primcount
, GLsizei stride
)
1383 struct vbo_context
*vbo
= vbo_context(ctx
);
1384 GLsizeiptr offset
= (GLsizeiptr
)indirect
;
1389 vbo_bind_arrays(ctx
);
1391 vbo
->draw_indirect_prims(ctx
, mode
,
1392 ctx
->DrawIndirectBuffer
, offset
,
1396 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1401 vbo_validated_drawelementsindirect(struct gl_context
*ctx
,
1402 GLenum mode
, GLenum type
,
1403 const GLvoid
*indirect
)
1405 struct vbo_context
*vbo
= vbo_context(ctx
);
1406 struct _mesa_index_buffer ib
;
1408 vbo_bind_arrays(ctx
);
1410 ib
.count
= 0; /* unknown */
1412 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1415 vbo
->draw_indirect_prims(ctx
, mode
,
1416 ctx
->DrawIndirectBuffer
, (GLsizeiptr
)indirect
,
1417 1 /* draw_count */, 20 /* stride */,
1421 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1426 vbo_validated_multidrawelementsindirect(struct gl_context
*ctx
,
1427 GLenum mode
, GLenum type
,
1428 const GLvoid
*indirect
,
1429 GLsizei primcount
, GLsizei stride
)
1431 struct vbo_context
*vbo
= vbo_context(ctx
);
1432 struct _mesa_index_buffer ib
;
1433 GLsizeiptr offset
= (GLsizeiptr
)indirect
;
1438 vbo_bind_arrays(ctx
);
1440 /* NOTE: IndexBufferObj is guaranteed to be a VBO. */
1442 ib
.count
= 0; /* unknown */
1444 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1447 vbo
->draw_indirect_prims(ctx
, mode
,
1448 ctx
->DrawIndirectBuffer
, offset
,
1453 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1458 * Like [Multi]DrawArrays/Elements, but they take most arguments from
1461 static void GLAPIENTRY
1462 vbo_exec_DrawArraysIndirect(GLenum mode
, const GLvoid
*indirect
)
1464 GET_CURRENT_CONTEXT(ctx
);
1466 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1467 _mesa_debug(ctx
, "glDrawArraysIndirect(%s, %p)\n",
1468 _mesa_enum_to_string(mode
), indirect
);
1470 if (!_mesa_validate_DrawArraysIndirect(ctx
, mode
, indirect
))
1473 vbo_validated_drawarraysindirect(ctx
, mode
, indirect
);
1476 static void GLAPIENTRY
1477 vbo_exec_DrawElementsIndirect(GLenum mode
, GLenum type
,
1478 const GLvoid
*indirect
)
1480 GET_CURRENT_CONTEXT(ctx
);
1482 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1483 _mesa_debug(ctx
, "glDrawElementsIndirect(%s, %s, %p)\n",
1484 _mesa_enum_to_string(mode
),
1485 _mesa_enum_to_string(type
), indirect
);
1487 if (!_mesa_validate_DrawElementsIndirect(ctx
, mode
, type
, indirect
))
1490 vbo_validated_drawelementsindirect(ctx
, mode
, type
, indirect
);
1493 static void GLAPIENTRY
1494 vbo_exec_MultiDrawArraysIndirect(GLenum mode
,
1495 const GLvoid
*indirect
,
1496 GLsizei primcount
, GLsizei stride
)
1498 GET_CURRENT_CONTEXT(ctx
);
1500 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1501 _mesa_debug(ctx
, "glMultiDrawArraysIndirect(%s, %p, %i, %i)\n",
1502 _mesa_enum_to_string(mode
), indirect
, primcount
, stride
);
1504 /* If <stride> is zero, the array elements are treated as tightly packed. */
1506 stride
= 4 * sizeof(GLuint
); /* sizeof(DrawArraysIndirectCommand) */
1508 if (!_mesa_validate_MultiDrawArraysIndirect(ctx
, mode
,
1513 vbo_validated_multidrawarraysindirect(ctx
, mode
,
1518 static void GLAPIENTRY
1519 vbo_exec_MultiDrawElementsIndirect(GLenum mode
, GLenum type
,
1520 const GLvoid
*indirect
,
1521 GLsizei primcount
, GLsizei stride
)
1523 GET_CURRENT_CONTEXT(ctx
);
1525 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1526 _mesa_debug(ctx
, "glMultiDrawElementsIndirect(%s, %s, %p, %i, %i)\n",
1527 _mesa_enum_to_string(mode
),
1528 _mesa_enum_to_string(type
), indirect
, primcount
, stride
);
1530 /* If <stride> is zero, the array elements are treated as tightly packed. */
1532 stride
= 5 * sizeof(GLuint
); /* sizeof(DrawElementsIndirectCommand) */
1534 if (!_mesa_validate_MultiDrawElementsIndirect(ctx
, mode
, type
,
1539 vbo_validated_multidrawelementsindirect(ctx
, mode
, type
,
1545 vbo_validated_multidrawarraysindirectcount(struct gl_context
*ctx
,
1549 GLsizei maxdrawcount
,
1552 struct vbo_context
*vbo
= vbo_context(ctx
);
1553 GLsizeiptr offset
= indirect
;
1555 if (maxdrawcount
== 0)
1558 vbo_bind_arrays(ctx
);
1560 vbo
->draw_indirect_prims(ctx
, mode
,
1561 ctx
->DrawIndirectBuffer
, offset
,
1562 maxdrawcount
, stride
,
1563 ctx
->ParameterBuffer
, drawcount
,
1566 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1571 vbo_validated_multidrawelementsindirectcount(struct gl_context
*ctx
,
1572 GLenum mode
, GLenum type
,
1575 GLsizei maxdrawcount
,
1578 struct vbo_context
*vbo
= vbo_context(ctx
);
1579 struct _mesa_index_buffer ib
;
1580 GLsizeiptr offset
= (GLsizeiptr
)indirect
;
1582 if (maxdrawcount
== 0)
1585 vbo_bind_arrays(ctx
);
1587 /* NOTE: IndexBufferObj is guaranteed to be a VBO. */
1589 ib
.count
= 0; /* unknown */
1591 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1594 vbo
->draw_indirect_prims(ctx
, mode
,
1595 ctx
->DrawIndirectBuffer
, offset
,
1596 maxdrawcount
, stride
,
1597 ctx
->ParameterBuffer
, drawcount
,
1600 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1604 static void GLAPIENTRY
1605 vbo_exec_MultiDrawArraysIndirectCount(GLenum mode
,
1608 GLsizei maxdrawcount
, GLsizei stride
)
1610 GET_CURRENT_CONTEXT(ctx
);
1612 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1613 _mesa_debug(ctx
, "glMultiDrawArraysIndirectCountARB"
1614 "(%s, %lx, %lx, %i, %i)\n",
1615 _mesa_enum_to_string(mode
),
1616 (unsigned long)indirect
, (unsigned long)drawcount
,
1617 maxdrawcount
, stride
);
1619 /* If <stride> is zero, the array elements are treated as tightly packed. */
1621 stride
= 4 * sizeof(GLuint
); /* sizeof(DrawArraysIndirectCommand) */
1623 if (!_mesa_validate_MultiDrawArraysIndirectCount(ctx
, mode
,
1624 indirect
, drawcount
,
1625 maxdrawcount
, stride
))
1628 vbo_validated_multidrawarraysindirectcount(ctx
, mode
,
1629 indirect
, drawcount
,
1630 maxdrawcount
, stride
);
1633 static void GLAPIENTRY
1634 vbo_exec_MultiDrawElementsIndirectCount(GLenum mode
, GLenum type
,
1637 GLsizei maxdrawcount
, GLsizei stride
)
1639 GET_CURRENT_CONTEXT(ctx
);
1641 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1642 _mesa_debug(ctx
, "glMultiDrawElementsIndirectCountARB"
1643 "(%s, %s, %lx, %lx, %i, %i)\n",
1644 _mesa_enum_to_string(mode
), _mesa_enum_to_string(type
),
1645 (unsigned long)indirect
, (unsigned long)drawcount
,
1646 maxdrawcount
, stride
);
1648 /* If <stride> is zero, the array elements are treated as tightly packed. */
1650 stride
= 5 * sizeof(GLuint
); /* sizeof(DrawElementsIndirectCommand) */
1652 if (!_mesa_validate_MultiDrawElementsIndirectCount(ctx
, mode
, type
,
1653 indirect
, drawcount
,
1654 maxdrawcount
, stride
))
1657 vbo_validated_multidrawelementsindirectcount(ctx
, mode
, type
,
1658 indirect
, drawcount
,
1659 maxdrawcount
, stride
);
1664 * Initialize the dispatch table with the VBO functions for drawing.
1667 vbo_initialize_exec_dispatch(const struct gl_context
*ctx
,
1668 struct _glapi_table
*exec
)
1670 SET_DrawArrays(exec
, vbo_exec_DrawArrays
);
1671 SET_DrawElements(exec
, vbo_exec_DrawElements
);
1673 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1674 SET_DrawRangeElements(exec
, vbo_exec_DrawRangeElements
);
1677 SET_MultiDrawElementsEXT(exec
, vbo_exec_MultiDrawElements
);
1679 if (ctx
->API
== API_OPENGL_COMPAT
) {
1680 SET_Rectf(exec
, vbo_exec_Rectf
);
1681 SET_EvalMesh1(exec
, vbo_exec_EvalMesh1
);
1682 SET_EvalMesh2(exec
, vbo_exec_EvalMesh2
);
1685 if (ctx
->API
!= API_OPENGLES
&&
1686 ctx
->Extensions
.ARB_draw_elements_base_vertex
) {
1687 SET_DrawElementsBaseVertex(exec
, vbo_exec_DrawElementsBaseVertex
);
1688 SET_MultiDrawElementsBaseVertex(exec
, vbo_exec_MultiDrawElementsBaseVertex
);
1690 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1691 SET_DrawRangeElementsBaseVertex(exec
, vbo_exec_DrawRangeElementsBaseVertex
);
1692 SET_DrawElementsInstancedBaseVertex(exec
, vbo_exec_DrawElementsInstancedBaseVertex
);
1696 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1697 SET_DrawArraysInstancedBaseInstance(exec
, vbo_exec_DrawArraysInstancedBaseInstance
);
1698 SET_DrawElementsInstancedBaseInstance(exec
, vbo_exec_DrawElementsInstancedBaseInstance
);
1699 SET_DrawElementsInstancedBaseVertexBaseInstance(exec
, vbo_exec_DrawElementsInstancedBaseVertexBaseInstance
);
1702 if (ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) {
1703 SET_DrawArraysIndirect(exec
, vbo_exec_DrawArraysIndirect
);
1704 SET_DrawElementsIndirect(exec
, vbo_exec_DrawElementsIndirect
);
1707 if (ctx
->API
== API_OPENGL_CORE
) {
1708 SET_MultiDrawArraysIndirect(exec
, vbo_exec_MultiDrawArraysIndirect
);
1709 SET_MultiDrawElementsIndirect(exec
, vbo_exec_MultiDrawElementsIndirect
);
1710 SET_MultiDrawArraysIndirectCountARB(exec
, vbo_exec_MultiDrawArraysIndirectCount
);
1711 SET_MultiDrawElementsIndirectCountARB(exec
, vbo_exec_MultiDrawElementsIndirectCount
);
1714 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1715 SET_DrawArraysInstancedARB(exec
, vbo_exec_DrawArraysInstanced
);
1716 SET_DrawElementsInstancedARB(exec
, vbo_exec_DrawElementsInstanced
);
1719 if (_mesa_is_desktop_gl(ctx
)) {
1720 SET_DrawTransformFeedback(exec
, vbo_exec_DrawTransformFeedback
);
1721 SET_DrawTransformFeedbackStream(exec
, vbo_exec_DrawTransformFeedbackStream
);
1722 SET_DrawTransformFeedbackInstanced(exec
, vbo_exec_DrawTransformFeedbackInstanced
);
1723 SET_DrawTransformFeedbackStreamInstanced(exec
, vbo_exec_DrawTransformFeedbackStreamInstanced
);
1730 * The following functions are only used for OpenGL ES 1/2 support.
1731 * And some aren't even supported (yet) in ES 1/2.
1736 _mesa_DrawArrays(GLenum mode
, GLint first
, GLsizei count
)
1738 vbo_exec_DrawArrays(mode
, first
, count
);
1742 _mesa_DrawArraysInstanced(GLenum mode
, GLint first
, GLsizei count
,
1745 vbo_exec_DrawArraysInstanced(mode
, first
, count
, primcount
);
1749 _mesa_DrawElements(GLenum mode
, GLsizei count
, GLenum type
,
1750 const GLvoid
*indices
)
1752 vbo_exec_DrawElements(mode
, count
, type
, indices
);
1757 _mesa_DrawElementsBaseVertex(GLenum mode
, GLsizei count
, GLenum type
,
1758 const GLvoid
*indices
, GLint basevertex
)
1760 vbo_exec_DrawElementsBaseVertex(mode
, count
, type
, indices
, basevertex
);
1765 _mesa_DrawRangeElements(GLenum mode
, GLuint start
, GLuint end
, GLsizei count
,
1766 GLenum type
, const GLvoid
*indices
)
1768 vbo_exec_DrawRangeElements(mode
, start
, end
, count
, type
, indices
);
1773 _mesa_DrawRangeElementsBaseVertex(GLenum mode
, GLuint start
, GLuint end
,
1774 GLsizei count
, GLenum type
,
1775 const GLvoid
*indices
, GLint basevertex
)
1777 vbo_exec_DrawRangeElementsBaseVertex(mode
, start
, end
, count
, type
,
1778 indices
, basevertex
);
1783 _mesa_MultiDrawElementsEXT(GLenum mode
, const GLsizei
*count
, GLenum type
,
1784 const GLvoid
**indices
, GLsizei primcount
)
1786 vbo_exec_MultiDrawElements(mode
, count
, type
, indices
, primcount
);
1791 _mesa_MultiDrawElementsBaseVertex(GLenum mode
,
1792 const GLsizei
*count
, GLenum type
,
1793 const GLvoid
**indices
, GLsizei primcount
,
1794 const GLint
*basevertex
)
1796 vbo_exec_MultiDrawElementsBaseVertex(mode
, count
, type
, indices
,
1797 primcount
, basevertex
);
1801 _mesa_DrawTransformFeedback(GLenum mode
, GLuint name
)
1803 vbo_exec_DrawTransformFeedback(mode
, name
);