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
;
782 /* Need to give special consideration to rendering a range of
783 * indices starting somewhere above zero. Typically the
784 * application is issuing multiple DrawRangeElements() to draw
785 * successive primitives layed out linearly in the vertex arrays.
786 * Unless the vertex arrays are all in a VBO (or locked as with
787 * CVA), the OpenGL semantics imply that we need to re-read or
788 * re-upload the vertex data on each draw call.
790 * In the case of hardware tnl, we want to avoid starting the
791 * upload at zero, as it will mean every draw call uploads an
792 * increasing amount of not-used vertex data. Worse - in the
793 * software tnl module, all those vertices might be transformed and
794 * lit but never rendered.
796 * If we just upload or transform the vertices in start..end,
797 * however, the indices will be incorrect.
799 * At this level, we don't know exactly what the requirements of
800 * the backend are going to be, though it will likely boil down to
803 * 1) Do nothing, everything is in a VBO and is processed once
806 * 2) Adjust the indices and vertex arrays so that start becomes
809 * Rather than doing anything here, I'll provide a helper function
810 * for the latter case elsewhere.
813 vbo
->draw_prims(ctx
, prim
, 1, &ib
,
814 index_bounds_valid
, start
, end
, NULL
, 0, NULL
);
816 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
) {
823 * Called by glDrawRangeElementsBaseVertex() in immediate mode.
825 static void GLAPIENTRY
826 vbo_exec_DrawRangeElementsBaseVertex(GLenum mode
,
827 GLuint start
, GLuint end
,
828 GLsizei count
, GLenum type
,
829 const GLvoid
*indices
,
832 static GLuint warnCount
= 0;
833 GLboolean index_bounds_valid
= GL_TRUE
;
835 /* This is only useful to catch invalid values in the "end" parameter
838 GLuint max_element
= 2 * 1000 * 1000 * 1000; /* just a big number */
840 GET_CURRENT_CONTEXT(ctx
);
842 if (MESA_VERBOSE
& VERBOSE_DRAW
)
844 "glDrawRangeElementsBaseVertex(%s, %u, %u, %d, %s, %p, %d)\n",
845 _mesa_enum_to_string(mode
), start
, end
, count
,
846 _mesa_enum_to_string(type
), indices
, basevertex
);
848 if (!_mesa_validate_DrawRangeElements(ctx
, mode
, start
, end
, count
,
852 if ((int) end
+ basevertex
< 0 ||
853 start
+ basevertex
>= max_element
) {
854 /* The application requested we draw using a range of indices that's
855 * outside the bounds of the current VBO. This is invalid and appears
856 * to give undefined results. The safest thing to do is to simply
857 * ignore the range, in case the application botched their range tracking
858 * but did provide valid indices. Also issue a warning indicating that
859 * the application is broken.
861 if (warnCount
++ < 10) {
862 _mesa_warning(ctx
, "glDrawRangeElements(start %u, end %u, "
863 "basevertex %d, count %d, type 0x%x, indices=%p):\n"
864 "\trange is outside VBO bounds (max=%u); ignoring.\n"
865 "\tThis should be fixed in the application.",
866 start
, end
, basevertex
, count
, type
, indices
,
869 index_bounds_valid
= GL_FALSE
;
872 /* NOTE: It's important that 'end' is a reasonable value.
873 * in _tnl_draw_prims(), we use end to determine how many vertices
874 * to transform. If it's too large, we can unnecessarily split prims
875 * or we can read/write out of memory in several different places!
878 /* Catch/fix some potential user errors */
879 if (type
== GL_UNSIGNED_BYTE
) {
880 start
= MIN2(start
, 0xff);
881 end
= MIN2(end
, 0xff);
883 else if (type
== GL_UNSIGNED_SHORT
) {
884 start
= MIN2(start
, 0xffff);
885 end
= MIN2(end
, 0xffff);
889 printf("glDraw[Range]Elements{,BaseVertex}"
890 "(start %u, end %u, type 0x%x, count %d) ElemBuf %u, "
892 start
, end
, type
, count
,
893 ctx
->Array
.VAO
->IndexBufferObj
->Name
,
897 if ((int) start
+ basevertex
< 0 ||
898 end
+ basevertex
>= max_element
)
899 index_bounds_valid
= GL_FALSE
;
902 check_draw_elements_data(ctx
, count
, type
, indices
, basevertex
);
904 (void) check_draw_elements_data
;
907 vbo_validated_drawrangeelements(ctx
, mode
, index_bounds_valid
, start
, end
,
908 count
, type
, indices
, basevertex
, 1, 0);
913 * Called by glDrawRangeElements() in immediate mode.
915 static void GLAPIENTRY
916 vbo_exec_DrawRangeElements(GLenum mode
, GLuint start
, GLuint end
,
917 GLsizei count
, GLenum type
, const GLvoid
*indices
)
919 if (MESA_VERBOSE
& VERBOSE_DRAW
) {
920 GET_CURRENT_CONTEXT(ctx
);
922 "glDrawRangeElements(%s, %u, %u, %d, %s, %p)\n",
923 _mesa_enum_to_string(mode
), start
, end
, count
,
924 _mesa_enum_to_string(type
), indices
);
927 vbo_exec_DrawRangeElementsBaseVertex(mode
, start
, end
, count
, type
,
933 * Called by glDrawElements() in immediate mode.
935 static void GLAPIENTRY
936 vbo_exec_DrawElements(GLenum mode
, GLsizei count
, GLenum type
,
937 const GLvoid
*indices
)
939 GET_CURRENT_CONTEXT(ctx
);
941 if (MESA_VERBOSE
& VERBOSE_DRAW
)
942 _mesa_debug(ctx
, "glDrawElements(%s, %u, %s, %p)\n",
943 _mesa_enum_to_string(mode
), count
,
944 _mesa_enum_to_string(type
), indices
);
946 if (!_mesa_validate_DrawElements(ctx
, mode
, count
, type
, indices
))
949 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
950 count
, type
, indices
, 0, 1, 0);
955 * Called by glDrawElementsBaseVertex() in immediate mode.
957 static void GLAPIENTRY
958 vbo_exec_DrawElementsBaseVertex(GLenum mode
, GLsizei count
, GLenum type
,
959 const GLvoid
*indices
, GLint basevertex
)
961 GET_CURRENT_CONTEXT(ctx
);
963 if (MESA_VERBOSE
& VERBOSE_DRAW
)
964 _mesa_debug(ctx
, "glDrawElementsBaseVertex(%s, %d, %s, %p, %d)\n",
965 _mesa_enum_to_string(mode
), count
,
966 _mesa_enum_to_string(type
), indices
, basevertex
);
968 if (!_mesa_validate_DrawElements(ctx
, mode
, count
, type
, indices
))
971 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
972 count
, type
, indices
, basevertex
, 1, 0);
977 * Called by glDrawElementsInstanced() in immediate mode.
979 static void GLAPIENTRY
980 vbo_exec_DrawElementsInstanced(GLenum mode
, GLsizei count
, GLenum type
,
981 const GLvoid
*indices
, GLsizei numInstances
)
983 GET_CURRENT_CONTEXT(ctx
);
985 if (MESA_VERBOSE
& VERBOSE_DRAW
)
986 _mesa_debug(ctx
, "glDrawElementsInstanced(%s, %d, %s, %p, %d)\n",
987 _mesa_enum_to_string(mode
), count
,
988 _mesa_enum_to_string(type
), indices
, numInstances
);
990 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
994 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
995 count
, type
, indices
, 0, numInstances
, 0);
1000 * Called by glDrawElementsInstancedBaseVertex() in immediate mode.
1002 static void GLAPIENTRY
1003 vbo_exec_DrawElementsInstancedBaseVertex(GLenum mode
, GLsizei count
, GLenum type
,
1004 const GLvoid
*indices
, GLsizei numInstances
,
1007 GET_CURRENT_CONTEXT(ctx
);
1009 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1010 _mesa_debug(ctx
, "glDrawElementsInstancedBaseVertex(%s, %d, %s, %p, %d; %d)\n",
1011 _mesa_enum_to_string(mode
), count
,
1012 _mesa_enum_to_string(type
), indices
,
1013 numInstances
, basevertex
);
1015 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
1019 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1020 count
, type
, indices
, basevertex
, numInstances
, 0);
1025 * Called by glDrawElementsInstancedBaseInstance() in immediate mode.
1027 static void GLAPIENTRY
1028 vbo_exec_DrawElementsInstancedBaseInstance(GLenum mode
, GLsizei count
, GLenum type
,
1029 const GLvoid
*indices
, GLsizei numInstances
,
1030 GLuint baseInstance
)
1032 GET_CURRENT_CONTEXT(ctx
);
1034 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1035 _mesa_debug(ctx
, "glDrawElementsInstancedBaseInstance(%s, %d, %s, %p, %d, %d)\n",
1036 _mesa_enum_to_string(mode
), count
,
1037 _mesa_enum_to_string(type
), indices
,
1038 numInstances
, baseInstance
);
1040 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
1044 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1045 count
, type
, indices
, 0, numInstances
,
1051 * Called by glDrawElementsInstancedBaseVertexBaseInstance() in immediate mode.
1053 static void GLAPIENTRY
1054 vbo_exec_DrawElementsInstancedBaseVertexBaseInstance(GLenum mode
, GLsizei count
, GLenum type
,
1055 const GLvoid
*indices
, GLsizei numInstances
,
1056 GLint basevertex
, GLuint baseInstance
)
1058 GET_CURRENT_CONTEXT(ctx
);
1060 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1061 _mesa_debug(ctx
, "glDrawElementsInstancedBaseVertexBaseInstance(%s, %d, %s, %p, %d, %d, %d)\n",
1062 _mesa_enum_to_string(mode
), count
,
1063 _mesa_enum_to_string(type
), indices
,
1064 numInstances
, basevertex
, baseInstance
);
1066 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
1070 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1071 count
, type
, indices
, basevertex
, numInstances
,
1077 * Inner support for both _mesa_MultiDrawElements() and
1078 * _mesa_MultiDrawRangeElements().
1079 * This does the actual rendering after we've checked array indexes, etc.
1082 vbo_validated_multidrawelements(struct gl_context
*ctx
, GLenum mode
,
1083 const GLsizei
*count
, GLenum type
,
1084 const GLvoid
* const *indices
,
1086 const GLint
*basevertex
)
1088 struct vbo_context
*vbo
= vbo_context(ctx
);
1089 struct _mesa_index_buffer ib
;
1090 struct _mesa_prim
*prim
;
1091 unsigned int index_type_size
= vbo_sizeof_ib_type(type
);
1092 uintptr_t min_index_ptr
, max_index_ptr
;
1093 GLboolean fallback
= GL_FALSE
;
1099 prim
= calloc(primcount
, sizeof(*prim
));
1101 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMultiDrawElements");
1105 vbo_bind_arrays(ctx
);
1107 min_index_ptr
= (uintptr_t)indices
[0];
1109 for (i
= 0; i
< primcount
; i
++) {
1110 min_index_ptr
= MIN2(min_index_ptr
, (uintptr_t)indices
[i
]);
1111 max_index_ptr
= MAX2(max_index_ptr
, (uintptr_t)indices
[i
] +
1112 index_type_size
* count
[i
]);
1115 /* Check if we can handle this thing as a bunch of index offsets from the
1116 * same index pointer. If we can't, then we have to fall back to doing
1117 * a draw_prims per primitive.
1118 * Check that the difference between each prim's indexes is a multiple of
1119 * the index/element size.
1121 if (index_type_size
!= 1) {
1122 for (i
= 0; i
< primcount
; i
++) {
1123 if ((((uintptr_t)indices
[i
] - min_index_ptr
) % index_type_size
) != 0) {
1130 /* Draw primitives individually if one count is zero, so we can easily skip
1133 for (i
= 0; i
< primcount
; i
++) {
1134 if (count
[i
] == 0) {
1140 /* If the index buffer isn't in a VBO, then treating the application's
1141 * subranges of the index buffer as one large index buffer may lead to
1142 * us reading unmapped memory.
1144 if (!_mesa_is_bufferobj(ctx
->Array
.VAO
->IndexBufferObj
))
1148 ib
.count
= (max_index_ptr
- min_index_ptr
) / index_type_size
;
1150 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1151 ib
.ptr
= (void *)min_index_ptr
;
1153 for (i
= 0; i
< primcount
; i
++) {
1154 prim
[i
].begin
= (i
== 0);
1155 prim
[i
].end
= (i
== primcount
- 1);
1158 prim
[i
].mode
= mode
;
1159 prim
[i
].start
= ((uintptr_t)indices
[i
] - min_index_ptr
) / index_type_size
;
1160 prim
[i
].count
= count
[i
];
1161 prim
[i
].indexed
= 1;
1162 prim
[i
].num_instances
= 1;
1163 prim
[i
].base_instance
= 0;
1164 prim
[i
].draw_id
= i
;
1165 prim
[i
].is_indirect
= 0;
1166 if (basevertex
!= NULL
)
1167 prim
[i
].basevertex
= basevertex
[i
];
1169 prim
[i
].basevertex
= 0;
1172 vbo
->draw_prims(ctx
, prim
, primcount
, &ib
,
1173 false, ~0, ~0, NULL
, 0, NULL
);
1175 /* render one prim at a time */
1176 for (i
= 0; i
< primcount
; i
++) {
1179 ib
.count
= count
[i
];
1181 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1182 ib
.ptr
= indices
[i
];
1188 prim
[0].mode
= mode
;
1190 prim
[0].count
= count
[i
];
1191 prim
[0].indexed
= 1;
1192 prim
[0].num_instances
= 1;
1193 prim
[0].base_instance
= 0;
1194 prim
[0].draw_id
= i
;
1195 prim
[0].is_indirect
= 0;
1196 if (basevertex
!= NULL
)
1197 prim
[0].basevertex
= basevertex
[i
];
1199 prim
[0].basevertex
= 0;
1201 vbo
->draw_prims(ctx
, prim
, 1, &ib
,
1202 false, ~0, ~0, NULL
, 0, NULL
);
1208 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
) {
1214 static void GLAPIENTRY
1215 vbo_exec_MultiDrawElements(GLenum mode
,
1216 const GLsizei
*count
, GLenum type
,
1217 const GLvoid
* const *indices
,
1220 GET_CURRENT_CONTEXT(ctx
);
1222 if (!_mesa_validate_MultiDrawElements(ctx
, mode
, count
, type
, indices
,
1226 vbo_validated_multidrawelements(ctx
, mode
, count
, type
, indices
, primcount
,
1231 static void GLAPIENTRY
1232 vbo_exec_MultiDrawElementsBaseVertex(GLenum mode
,
1233 const GLsizei
*count
, GLenum type
,
1234 const GLvoid
* const *indices
,
1236 const GLsizei
*basevertex
)
1238 GET_CURRENT_CONTEXT(ctx
);
1240 if (!_mesa_validate_MultiDrawElements(ctx
, mode
, count
, type
, indices
,
1244 vbo_validated_multidrawelements(ctx
, mode
, count
, type
, indices
, primcount
,
1249 vbo_draw_transform_feedback(struct gl_context
*ctx
, GLenum mode
,
1250 struct gl_transform_feedback_object
*obj
,
1251 GLuint stream
, GLuint numInstances
)
1253 struct vbo_context
*vbo
= vbo_context(ctx
);
1254 struct _mesa_prim prim
[2];
1256 if (!_mesa_validate_DrawTransformFeedback(ctx
, mode
, obj
, stream
,
1261 if (ctx
->Driver
.GetTransformFeedbackVertexCount
&&
1262 (ctx
->Const
.AlwaysUseGetTransformFeedbackVertexCount
||
1263 !_mesa_all_varyings_in_vbos(ctx
->Array
.VAO
))) {
1264 GLsizei n
= ctx
->Driver
.GetTransformFeedbackVertexCount(ctx
, obj
, stream
);
1265 vbo_draw_arrays(ctx
, mode
, 0, n
, numInstances
, 0);
1269 vbo_bind_arrays(ctx
);
1271 /* init most fields to zero */
1272 memset(prim
, 0, sizeof(prim
));
1275 prim
[0].mode
= mode
;
1276 prim
[0].num_instances
= numInstances
;
1277 prim
[0].base_instance
= 0;
1278 prim
[0].is_indirect
= 0;
1280 /* Maybe we should do some primitive splitting for primitive restart
1281 * (like in DrawArrays), but we have no way to know how many vertices
1282 * will be rendered. */
1284 vbo
->draw_prims(ctx
, prim
, 1, NULL
,
1285 GL_FALSE
, ~0, ~0, obj
, stream
, NULL
);
1287 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
) {
1293 * Like DrawArrays, but take the count from a transform feedback object.
1294 * \param mode GL_POINTS, GL_LINES, GL_TRIANGLE_STRIP, etc.
1295 * \param name the transform feedback object
1296 * User still has to setup of the vertex attribute info with
1297 * glVertexPointer, glColorPointer, etc.
1298 * Part of GL_ARB_transform_feedback2.
1300 static void GLAPIENTRY
1301 vbo_exec_DrawTransformFeedback(GLenum mode
, GLuint name
)
1303 GET_CURRENT_CONTEXT(ctx
);
1304 struct gl_transform_feedback_object
*obj
=
1305 _mesa_lookup_transform_feedback_object(ctx
, name
);
1307 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1308 _mesa_debug(ctx
, "glDrawTransformFeedback(%s, %d)\n",
1309 _mesa_enum_to_string(mode
), name
);
1311 vbo_draw_transform_feedback(ctx
, mode
, obj
, 0, 1);
1314 static void GLAPIENTRY
1315 vbo_exec_DrawTransformFeedbackStream(GLenum mode
, GLuint name
, GLuint stream
)
1317 GET_CURRENT_CONTEXT(ctx
);
1318 struct gl_transform_feedback_object
*obj
=
1319 _mesa_lookup_transform_feedback_object(ctx
, name
);
1321 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1322 _mesa_debug(ctx
, "glDrawTransformFeedbackStream(%s, %u, %u)\n",
1323 _mesa_enum_to_string(mode
), name
, stream
);
1325 vbo_draw_transform_feedback(ctx
, mode
, obj
, stream
, 1);
1328 static void GLAPIENTRY
1329 vbo_exec_DrawTransformFeedbackInstanced(GLenum mode
, GLuint name
,
1332 GET_CURRENT_CONTEXT(ctx
);
1333 struct gl_transform_feedback_object
*obj
=
1334 _mesa_lookup_transform_feedback_object(ctx
, name
);
1336 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1337 _mesa_debug(ctx
, "glDrawTransformFeedbackInstanced(%s, %d)\n",
1338 _mesa_enum_to_string(mode
), name
);
1340 vbo_draw_transform_feedback(ctx
, mode
, obj
, 0, primcount
);
1343 static void GLAPIENTRY
1344 vbo_exec_DrawTransformFeedbackStreamInstanced(GLenum mode
, GLuint name
,
1345 GLuint stream
, GLsizei primcount
)
1347 GET_CURRENT_CONTEXT(ctx
);
1348 struct gl_transform_feedback_object
*obj
=
1349 _mesa_lookup_transform_feedback_object(ctx
, name
);
1351 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1352 _mesa_debug(ctx
, "glDrawTransformFeedbackStreamInstanced"
1353 "(%s, %u, %u, %i)\n",
1354 _mesa_enum_to_string(mode
), name
, stream
, primcount
);
1356 vbo_draw_transform_feedback(ctx
, mode
, obj
, stream
, primcount
);
1360 vbo_validated_drawarraysindirect(struct gl_context
*ctx
,
1361 GLenum mode
, const GLvoid
*indirect
)
1363 struct vbo_context
*vbo
= vbo_context(ctx
);
1365 vbo_bind_arrays(ctx
);
1367 vbo
->draw_indirect_prims(ctx
, mode
,
1368 ctx
->DrawIndirectBuffer
, (GLsizeiptr
)indirect
,
1369 1 /* draw_count */, 16 /* stride */,
1372 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1377 vbo_validated_multidrawarraysindirect(struct gl_context
*ctx
,
1379 const GLvoid
*indirect
,
1380 GLsizei primcount
, GLsizei stride
)
1382 struct vbo_context
*vbo
= vbo_context(ctx
);
1383 GLsizeiptr offset
= (GLsizeiptr
)indirect
;
1388 vbo_bind_arrays(ctx
);
1390 vbo
->draw_indirect_prims(ctx
, mode
,
1391 ctx
->DrawIndirectBuffer
, offset
,
1395 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1400 vbo_validated_drawelementsindirect(struct gl_context
*ctx
,
1401 GLenum mode
, GLenum type
,
1402 const GLvoid
*indirect
)
1404 struct vbo_context
*vbo
= vbo_context(ctx
);
1405 struct _mesa_index_buffer ib
;
1407 vbo_bind_arrays(ctx
);
1409 ib
.count
= 0; /* unknown */
1411 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1414 vbo
->draw_indirect_prims(ctx
, mode
,
1415 ctx
->DrawIndirectBuffer
, (GLsizeiptr
)indirect
,
1416 1 /* draw_count */, 20 /* stride */,
1420 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1425 vbo_validated_multidrawelementsindirect(struct gl_context
*ctx
,
1426 GLenum mode
, GLenum type
,
1427 const GLvoid
*indirect
,
1428 GLsizei primcount
, GLsizei stride
)
1430 struct vbo_context
*vbo
= vbo_context(ctx
);
1431 struct _mesa_index_buffer ib
;
1432 GLsizeiptr offset
= (GLsizeiptr
)indirect
;
1437 vbo_bind_arrays(ctx
);
1439 /* NOTE: IndexBufferObj is guaranteed to be a VBO. */
1441 ib
.count
= 0; /* unknown */
1443 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1446 vbo
->draw_indirect_prims(ctx
, mode
,
1447 ctx
->DrawIndirectBuffer
, offset
,
1452 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1457 * Like [Multi]DrawArrays/Elements, but they take most arguments from
1460 static void GLAPIENTRY
1461 vbo_exec_DrawArraysIndirect(GLenum mode
, const GLvoid
*indirect
)
1463 GET_CURRENT_CONTEXT(ctx
);
1465 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1466 _mesa_debug(ctx
, "glDrawArraysIndirect(%s, %p)\n",
1467 _mesa_enum_to_string(mode
), indirect
);
1469 if (!_mesa_validate_DrawArraysIndirect(ctx
, mode
, indirect
))
1472 vbo_validated_drawarraysindirect(ctx
, mode
, indirect
);
1475 static void GLAPIENTRY
1476 vbo_exec_DrawElementsIndirect(GLenum mode
, GLenum type
,
1477 const GLvoid
*indirect
)
1479 GET_CURRENT_CONTEXT(ctx
);
1481 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1482 _mesa_debug(ctx
, "glDrawElementsIndirect(%s, %s, %p)\n",
1483 _mesa_enum_to_string(mode
),
1484 _mesa_enum_to_string(type
), indirect
);
1486 if (!_mesa_validate_DrawElementsIndirect(ctx
, mode
, type
, indirect
))
1489 vbo_validated_drawelementsindirect(ctx
, mode
, type
, indirect
);
1492 static void GLAPIENTRY
1493 vbo_exec_MultiDrawArraysIndirect(GLenum mode
,
1494 const GLvoid
*indirect
,
1495 GLsizei primcount
, GLsizei stride
)
1497 GET_CURRENT_CONTEXT(ctx
);
1499 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1500 _mesa_debug(ctx
, "glMultiDrawArraysIndirect(%s, %p, %i, %i)\n",
1501 _mesa_enum_to_string(mode
), indirect
, primcount
, stride
);
1503 /* If <stride> is zero, the array elements are treated as tightly packed. */
1505 stride
= 4 * sizeof(GLuint
); /* sizeof(DrawArraysIndirectCommand) */
1507 if (!_mesa_validate_MultiDrawArraysIndirect(ctx
, mode
,
1512 vbo_validated_multidrawarraysindirect(ctx
, mode
,
1517 static void GLAPIENTRY
1518 vbo_exec_MultiDrawElementsIndirect(GLenum mode
, GLenum type
,
1519 const GLvoid
*indirect
,
1520 GLsizei primcount
, GLsizei stride
)
1522 GET_CURRENT_CONTEXT(ctx
);
1524 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1525 _mesa_debug(ctx
, "glMultiDrawElementsIndirect(%s, %s, %p, %i, %i)\n",
1526 _mesa_enum_to_string(mode
),
1527 _mesa_enum_to_string(type
), indirect
, primcount
, stride
);
1529 /* If <stride> is zero, the array elements are treated as tightly packed. */
1531 stride
= 5 * sizeof(GLuint
); /* sizeof(DrawElementsIndirectCommand) */
1533 if (!_mesa_validate_MultiDrawElementsIndirect(ctx
, mode
, type
,
1538 vbo_validated_multidrawelementsindirect(ctx
, mode
, type
,
1544 vbo_validated_multidrawarraysindirectcount(struct gl_context
*ctx
,
1548 GLsizei maxdrawcount
,
1551 struct vbo_context
*vbo
= vbo_context(ctx
);
1552 GLsizeiptr offset
= indirect
;
1554 if (maxdrawcount
== 0)
1557 vbo_bind_arrays(ctx
);
1559 vbo
->draw_indirect_prims(ctx
, mode
,
1560 ctx
->DrawIndirectBuffer
, offset
,
1561 maxdrawcount
, stride
,
1562 ctx
->ParameterBuffer
, drawcount
,
1565 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1570 vbo_validated_multidrawelementsindirectcount(struct gl_context
*ctx
,
1571 GLenum mode
, GLenum type
,
1574 GLsizei maxdrawcount
,
1577 struct vbo_context
*vbo
= vbo_context(ctx
);
1578 struct _mesa_index_buffer ib
;
1579 GLsizeiptr offset
= (GLsizeiptr
)indirect
;
1581 if (maxdrawcount
== 0)
1584 vbo_bind_arrays(ctx
);
1586 /* NOTE: IndexBufferObj is guaranteed to be a VBO. */
1588 ib
.count
= 0; /* unknown */
1590 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1593 vbo
->draw_indirect_prims(ctx
, mode
,
1594 ctx
->DrawIndirectBuffer
, offset
,
1595 maxdrawcount
, stride
,
1596 ctx
->ParameterBuffer
, drawcount
,
1599 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1603 static void GLAPIENTRY
1604 vbo_exec_MultiDrawArraysIndirectCount(GLenum mode
,
1607 GLsizei maxdrawcount
, GLsizei stride
)
1609 GET_CURRENT_CONTEXT(ctx
);
1611 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1612 _mesa_debug(ctx
, "glMultiDrawArraysIndirectCountARB"
1613 "(%s, %lx, %lx, %i, %i)\n",
1614 _mesa_enum_to_string(mode
), indirect
,
1615 drawcount
, maxdrawcount
, stride
);
1617 /* If <stride> is zero, the array elements are treated as tightly packed. */
1619 stride
= 4 * sizeof(GLuint
); /* sizeof(DrawArraysIndirectCommand) */
1621 if (!_mesa_validate_MultiDrawArraysIndirectCount(ctx
, mode
,
1622 indirect
, drawcount
,
1623 maxdrawcount
, stride
))
1626 vbo_validated_multidrawarraysindirectcount(ctx
, mode
,
1627 indirect
, drawcount
,
1628 maxdrawcount
, stride
);
1631 static void GLAPIENTRY
1632 vbo_exec_MultiDrawElementsIndirectCount(GLenum mode
, GLenum type
,
1635 GLsizei maxdrawcount
, GLsizei stride
)
1637 GET_CURRENT_CONTEXT(ctx
);
1639 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1640 _mesa_debug(ctx
, "glMultiDrawElementsIndirectCountARB"
1641 "(%s, %s, %lx, %lx, %i, %i)\n",
1642 _mesa_enum_to_string(mode
),
1643 _mesa_enum_to_string(type
), indirect
,
1644 drawcount
, maxdrawcount
, stride
);
1646 /* If <stride> is zero, the array elements are treated as tightly packed. */
1648 stride
= 5 * sizeof(GLuint
); /* sizeof(DrawElementsIndirectCommand) */
1650 if (!_mesa_validate_MultiDrawElementsIndirectCount(ctx
, mode
, type
,
1651 indirect
, drawcount
,
1652 maxdrawcount
, stride
))
1655 vbo_validated_multidrawelementsindirectcount(ctx
, mode
, type
,
1656 indirect
, drawcount
,
1657 maxdrawcount
, stride
);
1662 * Initialize the dispatch table with the VBO functions for drawing.
1665 vbo_initialize_exec_dispatch(const struct gl_context
*ctx
,
1666 struct _glapi_table
*exec
)
1668 SET_DrawArrays(exec
, vbo_exec_DrawArrays
);
1669 SET_DrawElements(exec
, vbo_exec_DrawElements
);
1671 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1672 SET_DrawRangeElements(exec
, vbo_exec_DrawRangeElements
);
1675 SET_MultiDrawElementsEXT(exec
, vbo_exec_MultiDrawElements
);
1677 if (ctx
->API
== API_OPENGL_COMPAT
) {
1678 SET_Rectf(exec
, vbo_exec_Rectf
);
1679 SET_EvalMesh1(exec
, vbo_exec_EvalMesh1
);
1680 SET_EvalMesh2(exec
, vbo_exec_EvalMesh2
);
1683 if (ctx
->API
!= API_OPENGLES
&&
1684 ctx
->Extensions
.ARB_draw_elements_base_vertex
) {
1685 SET_DrawElementsBaseVertex(exec
, vbo_exec_DrawElementsBaseVertex
);
1686 SET_MultiDrawElementsBaseVertex(exec
, vbo_exec_MultiDrawElementsBaseVertex
);
1688 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1689 SET_DrawRangeElementsBaseVertex(exec
, vbo_exec_DrawRangeElementsBaseVertex
);
1690 SET_DrawElementsInstancedBaseVertex(exec
, vbo_exec_DrawElementsInstancedBaseVertex
);
1694 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1695 SET_DrawArraysInstancedBaseInstance(exec
, vbo_exec_DrawArraysInstancedBaseInstance
);
1696 SET_DrawElementsInstancedBaseInstance(exec
, vbo_exec_DrawElementsInstancedBaseInstance
);
1697 SET_DrawElementsInstancedBaseVertexBaseInstance(exec
, vbo_exec_DrawElementsInstancedBaseVertexBaseInstance
);
1700 if (ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) {
1701 SET_DrawArraysIndirect(exec
, vbo_exec_DrawArraysIndirect
);
1702 SET_DrawElementsIndirect(exec
, vbo_exec_DrawElementsIndirect
);
1705 if (ctx
->API
== API_OPENGL_CORE
) {
1706 SET_MultiDrawArraysIndirect(exec
, vbo_exec_MultiDrawArraysIndirect
);
1707 SET_MultiDrawElementsIndirect(exec
, vbo_exec_MultiDrawElementsIndirect
);
1708 SET_MultiDrawArraysIndirectCountARB(exec
, vbo_exec_MultiDrawArraysIndirectCount
);
1709 SET_MultiDrawElementsIndirectCountARB(exec
, vbo_exec_MultiDrawElementsIndirectCount
);
1712 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1713 SET_DrawArraysInstancedARB(exec
, vbo_exec_DrawArraysInstanced
);
1714 SET_DrawElementsInstancedARB(exec
, vbo_exec_DrawElementsInstanced
);
1717 if (_mesa_is_desktop_gl(ctx
)) {
1718 SET_DrawTransformFeedback(exec
, vbo_exec_DrawTransformFeedback
);
1719 SET_DrawTransformFeedbackStream(exec
, vbo_exec_DrawTransformFeedbackStream
);
1720 SET_DrawTransformFeedbackInstanced(exec
, vbo_exec_DrawTransformFeedbackInstanced
);
1721 SET_DrawTransformFeedbackStreamInstanced(exec
, vbo_exec_DrawTransformFeedbackStreamInstanced
);
1728 * The following functions are only used for OpenGL ES 1/2 support.
1729 * And some aren't even supported (yet) in ES 1/2.
1734 _mesa_DrawArrays(GLenum mode
, GLint first
, GLsizei count
)
1736 vbo_exec_DrawArrays(mode
, first
, count
);
1740 _mesa_DrawArraysInstanced(GLenum mode
, GLint first
, GLsizei count
,
1743 vbo_exec_DrawArraysInstanced(mode
, first
, count
, primcount
);
1747 _mesa_DrawElements(GLenum mode
, GLsizei count
, GLenum type
,
1748 const GLvoid
*indices
)
1750 vbo_exec_DrawElements(mode
, count
, type
, indices
);
1755 _mesa_DrawElementsBaseVertex(GLenum mode
, GLsizei count
, GLenum type
,
1756 const GLvoid
*indices
, GLint basevertex
)
1758 vbo_exec_DrawElementsBaseVertex(mode
, count
, type
, indices
, basevertex
);
1763 _mesa_DrawRangeElements(GLenum mode
, GLuint start
, GLuint end
, GLsizei count
,
1764 GLenum type
, const GLvoid
*indices
)
1766 vbo_exec_DrawRangeElements(mode
, start
, end
, count
, type
, indices
);
1771 _mesa_DrawRangeElementsBaseVertex(GLenum mode
, GLuint start
, GLuint end
,
1772 GLsizei count
, GLenum type
,
1773 const GLvoid
*indices
, GLint basevertex
)
1775 vbo_exec_DrawRangeElementsBaseVertex(mode
, start
, end
, count
, type
,
1776 indices
, basevertex
);
1781 _mesa_MultiDrawElementsEXT(GLenum mode
, const GLsizei
*count
, GLenum type
,
1782 const GLvoid
**indices
, GLsizei primcount
)
1784 vbo_exec_MultiDrawElements(mode
, count
, type
, indices
, primcount
);
1789 _mesa_MultiDrawElementsBaseVertex(GLenum mode
,
1790 const GLsizei
*count
, GLenum type
,
1791 const GLvoid
**indices
, GLsizei primcount
,
1792 const GLint
*basevertex
)
1794 vbo_exec_MultiDrawElementsBaseVertex(mode
, count
, type
, indices
,
1795 primcount
, basevertex
);
1799 _mesa_DrawTransformFeedback(GLenum mode
, GLuint name
)
1801 vbo_exec_DrawTransformFeedback(mode
, name
);