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_array_attributes
*array
= &vao
->VertexAttrib
[attrib
];
56 const struct gl_vertex_buffer_binding
*binding
=
57 &vao
->VertexBinding
[array
->BufferBindingIndex
];
58 struct gl_buffer_object
*bo
= binding
->BufferObj
;
59 const void *data
= array
->Ptr
;
60 if (_mesa_is_bufferobj(bo
)) {
61 if (!bo
->Mappings
[MAP_INTERNAL
].Pointer
) {
63 bo
->Mappings
[MAP_INTERNAL
].Pointer
=
64 ctx
->Driver
.MapBufferRange(ctx
, 0, bo
->Size
,
65 GL_MAP_READ_BIT
, bo
, MAP_INTERNAL
);
67 data
= ADD_POINTERS(_mesa_vertex_attrib_address(array
, binding
),
68 bo
->Mappings
[MAP_INTERNAL
].Pointer
);
70 switch (array
->Type
) {
73 GLfloat
*f
= (GLfloat
*) ((GLubyte
*) data
+ binding
->Stride
* j
);
75 for (k
= 0; k
< array
->Size
; k
++) {
76 if (IS_INF_OR_NAN(f
[k
]) || f
[k
] >= 1.0e20F
|| f
[k
] <= -1.0e10F
) {
77 printf("Bad array data:\n");
78 printf(" Element[%u].%u = %f\n", j
, k
, f
[k
]);
79 printf(" Array %u at %p\n", attrib
, (void *) array
);
80 printf(" Type 0x%x, Size %d, Stride %d\n",
81 array
->Type
, array
->Size
, binding
->Stride
);
82 printf(" Address/offset %p in Buffer Object %u\n",
83 array
->Ptr
, bo
->Name
);
84 f
[k
] = 1.0F
; /* XXX replace the bad value! */
86 /*assert(!IS_INF_OR_NAN(f[k])); */
98 * Unmap the buffer object referenced by given array, if mapped.
101 unmap_array_buffer(struct gl_context
*ctx
, struct gl_vertex_array_object
*vao
,
104 const struct gl_array_attributes
*array
= &vao
->VertexAttrib
[attrib
];
105 if (array
->Enabled
) {
106 const struct gl_vertex_buffer_binding
*binding
=
107 &vao
->VertexBinding
[array
->BufferBindingIndex
];
108 struct gl_buffer_object
*bo
= binding
->BufferObj
;
109 if (_mesa_is_bufferobj(bo
) && _mesa_bufferobj_mapped(bo
, MAP_INTERNAL
)) {
110 ctx
->Driver
.UnmapBuffer(ctx
, bo
, MAP_INTERNAL
);
117 * Examine the array's data for NaNs, etc.
118 * For debug purposes; not normally used.
121 check_draw_elements_data(struct gl_context
*ctx
, GLsizei count
,
122 GLenum elemType
, const void *elements
,
125 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
130 if (_mesa_is_bufferobj(vao
->IndexBufferObj
)) {
131 elemMap
= ctx
->Driver
.MapBufferRange(ctx
, 0,
132 vao
->IndexBufferObj
->Size
,
134 vao
->IndexBufferObj
, MAP_INTERNAL
);
135 elements
= ADD_POINTERS(elements
, elemMap
);
138 for (i
= 0; i
< count
; i
++) {
143 case GL_UNSIGNED_BYTE
:
144 j
= ((const GLubyte
*) elements
)[i
];
146 case GL_UNSIGNED_SHORT
:
147 j
= ((const GLushort
*) elements
)[i
];
149 case GL_UNSIGNED_INT
:
150 j
= ((const GLuint
*) elements
)[i
];
156 /* check element j of each enabled array */
157 for (k
= 0; k
< VERT_ATTRIB_MAX
; k
++) {
158 check_array_data(ctx
, vao
, k
, j
);
162 if (_mesa_is_bufferobj(vao
->IndexBufferObj
)) {
163 ctx
->Driver
.UnmapBuffer(ctx
, vao
->IndexBufferObj
, MAP_INTERNAL
);
166 for (k
= 0; k
< VERT_ATTRIB_MAX
; k
++) {
167 unmap_array_buffer(ctx
, vao
, k
);
173 * Check array data, looking for NaNs, etc.
176 check_draw_arrays_data(struct gl_context
*ctx
, GLint start
, GLsizei count
)
183 * Print info/data for glDrawArrays(), for debugging.
186 print_draw_arrays(struct gl_context
*ctx
,
187 GLenum mode
, GLint start
, GLsizei count
)
189 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
191 printf("vbo_exec_DrawArrays(mode 0x%x, start %d, count %d):\n",
195 for (i
= 0; i
< VERT_ATTRIB_MAX
; ++i
) {
196 const struct gl_array_attributes
*array
= &vao
->VertexAttrib
[i
];
200 const struct gl_vertex_buffer_binding
*binding
=
201 &vao
->VertexBinding
[array
->BufferBindingIndex
];
202 struct gl_buffer_object
*bufObj
= binding
->BufferObj
;
204 printf("attr %s: size %d stride %d enabled %d "
205 "ptr %p Bufobj %u\n",
206 gl_vert_attrib_name((gl_vert_attrib
) i
),
207 array
->Size
, binding
->Stride
, array
->Enabled
,
208 array
->Ptr
, bufObj
->Name
);
210 if (_mesa_is_bufferobj(bufObj
)) {
211 GLubyte
*p
= ctx
->Driver
.MapBufferRange(ctx
, 0, bufObj
->Size
,
212 GL_MAP_READ_BIT
, bufObj
,
214 int offset
= (int) (GLintptr
)
215 _mesa_vertex_attrib_address(array
, binding
);
216 float *f
= (float *) (p
+ offset
);
219 int n
= (count
* binding
->Stride
) / 4;
222 printf(" Data at offset %d:\n", offset
);
223 for (i
= 0; i
< n
; i
++) {
224 printf(" float[%d] = 0x%08x %f\n", i
, k
[i
], f
[i
]);
226 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, MAP_INTERNAL
);
233 * Set the vbo->exec->inputs[] pointers to point to the enabled
234 * vertex arrays. This depends on the current vertex program/shader
235 * being executed because of whether or not generic vertex arrays
236 * alias the conventional vertex arrays.
237 * For arrays that aren't enabled, we set the input[attrib] pointer
238 * to point at a zero-stride current value "array".
241 recalculate_input_bindings(struct gl_context
*ctx
)
243 struct vbo_context
*vbo
= vbo_context(ctx
);
244 struct vbo_exec_context
*exec
= &vbo
->exec
;
245 const struct gl_array_attributes
*array
= ctx
->Array
.VAO
->VertexAttrib
;
246 struct gl_client_array
*vertexAttrib
= ctx
->Array
.VAO
->_VertexAttrib
;
247 const struct gl_client_array
**inputs
= &exec
->array
.inputs
[0];
248 GLbitfield64 const_inputs
= 0x0;
251 switch (get_program_mode(ctx
)) {
253 /* When no vertex program is active (or the vertex program is generated
254 * from fixed-function state). We put the material values into the
255 * generic slots. This is the only situation where material values
256 * are available as per-vertex attributes.
258 for (i
= 0; i
< VERT_ATTRIB_FF_MAX
; i
++) {
259 if (array
[VERT_ATTRIB_FF(i
)].Enabled
)
260 inputs
[i
] = &vertexAttrib
[VERT_ATTRIB_FF(i
)];
262 inputs
[i
] = &vbo
->currval
[VBO_ATTRIB_POS
+ i
];
263 const_inputs
|= VERT_BIT(i
);
267 for (i
= 0; i
< MAT_ATTRIB_MAX
; i
++) {
268 inputs
[VERT_ATTRIB_GENERIC(i
)] =
269 &vbo
->currval
[VBO_ATTRIB_MAT_FRONT_AMBIENT
+ i
];
270 const_inputs
|= VERT_BIT_GENERIC(i
);
273 /* Could use just about anything, just to fill in the empty
276 for (i
= MAT_ATTRIB_MAX
; i
< VERT_ATTRIB_GENERIC_MAX
; i
++) {
277 inputs
[VERT_ATTRIB_GENERIC(i
)] =
278 &vbo
->currval
[VBO_ATTRIB_GENERIC0
+ i
];
279 const_inputs
|= VERT_BIT_GENERIC(i
);
284 /* There are no shaders in OpenGL ES 1.x, so this code path should be
285 * impossible to reach. The meta code is careful to not use shaders in
288 assert(ctx
->API
!= API_OPENGLES
);
290 /* In the compatibility profile of desktop OpenGL, the generic[0]
291 * attribute array aliases and overrides the legacy position array.
292 * Otherwise, legacy attributes available in the legacy slots,
293 * generic attributes in the generic slots and materials are not
294 * available as per-vertex attributes.
296 * In all other APIs, only the generic attributes exist, and none of the
297 * slots are considered "magic."
299 if (ctx
->API
== API_OPENGL_COMPAT
) {
300 if (array
[VERT_ATTRIB_GENERIC0
].Enabled
)
301 inputs
[0] = &vertexAttrib
[VERT_ATTRIB_GENERIC0
];
302 else if (array
[VERT_ATTRIB_POS
].Enabled
)
303 inputs
[0] = &vertexAttrib
[VERT_ATTRIB_POS
];
305 inputs
[0] = &vbo
->currval
[VBO_ATTRIB_POS
];
306 const_inputs
|= VERT_BIT_POS
;
309 for (i
= 1; i
< VERT_ATTRIB_FF_MAX
; i
++) {
310 if (array
[VERT_ATTRIB_FF(i
)].Enabled
)
311 inputs
[i
] = &vertexAttrib
[VERT_ATTRIB_FF(i
)];
313 inputs
[i
] = &vbo
->currval
[VBO_ATTRIB_POS
+ i
];
314 const_inputs
|= VERT_BIT_FF(i
);
318 for (i
= 1; i
< VERT_ATTRIB_GENERIC_MAX
; i
++) {
319 if (array
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
320 inputs
[VERT_ATTRIB_GENERIC(i
)] =
321 &vertexAttrib
[VERT_ATTRIB_GENERIC(i
)];
323 inputs
[VERT_ATTRIB_GENERIC(i
)] =
324 &vbo
->currval
[VBO_ATTRIB_GENERIC0
+ i
];
325 const_inputs
|= VERT_BIT_GENERIC(i
);
329 inputs
[VERT_ATTRIB_GENERIC0
] = inputs
[0];
331 /* Other parts of the code assume that inputs[0] through
332 * inputs[VERT_ATTRIB_FF_MAX] will be non-NULL. However, in OpenGL
333 * ES 2.0+ or OpenGL core profile, none of these arrays should ever
336 for (i
= 0; i
< VERT_ATTRIB_FF_MAX
; i
++) {
337 assert(!array
[VERT_ATTRIB_FF(i
)].Enabled
);
339 inputs
[i
] = &vbo
->currval
[VBO_ATTRIB_POS
+ i
];
340 const_inputs
|= VERT_BIT_FF(i
);
343 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++) {
344 if (array
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
345 inputs
[VERT_ATTRIB_GENERIC(i
)] =
346 &vertexAttrib
[VERT_ATTRIB_GENERIC(i
)];
348 inputs
[VERT_ATTRIB_GENERIC(i
)] =
349 &vbo
->currval
[VBO_ATTRIB_GENERIC0
+ i
];
350 const_inputs
|= VERT_BIT_GENERIC(i
);
358 _mesa_set_varying_vp_inputs(ctx
, VERT_BIT_ALL
& (~const_inputs
));
359 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewArray
;
364 * Examine the enabled vertex arrays to set the exec->array.inputs[] values.
365 * These will point to the arrays to actually use for drawing. Some will
366 * be user-provided arrays, other will be zero-stride const-valued arrays.
367 * Note that this might set the _NEW_VARYING_VP_INPUTS dirty flag so state
368 * validation must be done after this call.
371 vbo_bind_arrays(struct gl_context
*ctx
)
373 struct vbo_context
*vbo
= vbo_context(ctx
);
374 struct vbo_exec_context
*exec
= &vbo
->exec
;
376 vbo_draw_method(vbo
, DRAW_ARRAYS
);
378 if (exec
->array
.recalculate_inputs
) {
379 recalculate_input_bindings(ctx
);
380 exec
->array
.recalculate_inputs
= GL_FALSE
;
382 /* Again... because we may have changed the bitmask of per-vertex varying
383 * attributes. If we regenerate the fixed-function vertex program now
384 * we may be able to prune down the number of vertex attributes which we
385 * need in the shader.
388 /* Setting "validating" to TRUE prevents _mesa_update_state from
389 * invalidating what we just did.
391 exec
->validating
= GL_TRUE
;
392 _mesa_update_state(ctx
);
393 exec
->validating
= GL_FALSE
;
400 * Helper function called by the other DrawArrays() functions below.
401 * This is where we handle primitive restart for drawing non-indexed
402 * arrays. If primitive restart is enabled, it typically means
403 * splitting one DrawArrays() into two.
406 vbo_draw_arrays(struct gl_context
*ctx
, GLenum mode
, GLint start
,
407 GLsizei count
, GLuint numInstances
, GLuint baseInstance
)
409 struct vbo_context
*vbo
= vbo_context(ctx
);
410 struct _mesa_prim prim
[2];
412 vbo_bind_arrays(ctx
);
414 /* init most fields to zero */
415 memset(prim
, 0, sizeof(prim
));
419 prim
[0].num_instances
= numInstances
;
420 prim
[0].base_instance
= baseInstance
;
421 prim
[0].is_indirect
= 0;
423 /* Implement the primitive restart index */
424 if (ctx
->Array
.PrimitiveRestart
&&
425 !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, NULL
, 0, NULL
);
472 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
) {
479 * Execute a glRectf() function.
481 static void GLAPIENTRY
482 vbo_exec_Rectf(GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
)
484 GET_CURRENT_CONTEXT(ctx
);
485 ASSERT_OUTSIDE_BEGIN_END(ctx
);
487 CALL_Begin(GET_DISPATCH(), (GL_QUADS
));
488 CALL_Vertex2f(GET_DISPATCH(), (x1
, y1
));
489 CALL_Vertex2f(GET_DISPATCH(), (x2
, y1
));
490 CALL_Vertex2f(GET_DISPATCH(), (x2
, y2
));
491 CALL_Vertex2f(GET_DISPATCH(), (x1
, y2
));
492 CALL_End(GET_DISPATCH(), ());
496 static void GLAPIENTRY
497 vbo_exec_EvalMesh1(GLenum mode
, GLint i1
, GLint i2
)
499 GET_CURRENT_CONTEXT(ctx
);
509 prim
= GL_LINE_STRIP
;
512 _mesa_error(ctx
, GL_INVALID_ENUM
, "glEvalMesh1(mode)");
516 /* No effect if vertex maps disabled.
518 if (!ctx
->Eval
.Map1Vertex4
&& !ctx
->Eval
.Map1Vertex3
)
521 du
= ctx
->Eval
.MapGrid1du
;
522 u
= ctx
->Eval
.MapGrid1u1
+ i1
* du
;
524 CALL_Begin(GET_DISPATCH(), (prim
));
525 for (i
= i1
; i
<= i2
; i
++, u
+= du
) {
526 CALL_EvalCoord1f(GET_DISPATCH(), (u
));
528 CALL_End(GET_DISPATCH(), ());
532 static void GLAPIENTRY
533 vbo_exec_EvalMesh2(GLenum mode
, GLint i1
, GLint i2
, GLint j1
, GLint j2
)
535 GET_CURRENT_CONTEXT(ctx
);
536 GLfloat u
, du
, v
, dv
, v1
, u1
;
545 _mesa_error(ctx
, GL_INVALID_ENUM
, "glEvalMesh2(mode)");
549 /* No effect if vertex maps disabled.
551 if (!ctx
->Eval
.Map2Vertex4
&& !ctx
->Eval
.Map2Vertex3
)
554 du
= ctx
->Eval
.MapGrid2du
;
555 dv
= ctx
->Eval
.MapGrid2dv
;
556 v1
= ctx
->Eval
.MapGrid2v1
+ j1
* dv
;
557 u1
= ctx
->Eval
.MapGrid2u1
+ i1
* du
;
561 CALL_Begin(GET_DISPATCH(), (GL_POINTS
));
562 for (v
= v1
, j
= j1
; j
<= j2
; j
++, v
+= dv
) {
563 for (u
= u1
, i
= i1
; i
<= i2
; i
++, u
+= du
) {
564 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
567 CALL_End(GET_DISPATCH(), ());
570 for (v
= v1
, j
= j1
; j
<= j2
; j
++, v
+= dv
) {
571 CALL_Begin(GET_DISPATCH(), (GL_LINE_STRIP
));
572 for (u
= u1
, i
= i1
; i
<= i2
; i
++, u
+= du
) {
573 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
575 CALL_End(GET_DISPATCH(), ());
577 for (u
= u1
, i
= i1
; i
<= i2
; i
++, u
+= du
) {
578 CALL_Begin(GET_DISPATCH(), (GL_LINE_STRIP
));
579 for (v
= v1
, j
= j1
; j
<= j2
; j
++, v
+= dv
) {
580 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
582 CALL_End(GET_DISPATCH(), ());
586 for (v
= v1
, j
= j1
; j
< j2
; j
++, v
+= dv
) {
587 CALL_Begin(GET_DISPATCH(), (GL_TRIANGLE_STRIP
));
588 for (u
= u1
, i
= i1
; i
<= i2
; i
++, u
+= du
) {
589 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
590 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
+ dv
));
592 CALL_End(GET_DISPATCH(), ());
600 * Called from glDrawArrays when in immediate mode (not display list mode).
602 static void GLAPIENTRY
603 vbo_exec_DrawArrays(GLenum mode
, GLint start
, GLsizei count
)
605 GET_CURRENT_CONTEXT(ctx
);
607 if (MESA_VERBOSE
& VERBOSE_DRAW
)
608 _mesa_debug(ctx
, "glDrawArrays(%s, %d, %d)\n",
609 _mesa_enum_to_string(mode
), start
, count
);
611 if (!_mesa_validate_DrawArrays(ctx
, mode
, count
))
615 check_draw_arrays_data(ctx
, start
, count
);
617 vbo_draw_arrays(ctx
, mode
, start
, count
, 1, 0);
620 print_draw_arrays(ctx
, mode
, start
, count
);
625 * Called from glDrawArraysInstanced when in immediate mode (not
626 * display list mode).
628 static void GLAPIENTRY
629 vbo_exec_DrawArraysInstanced(GLenum mode
, GLint start
, GLsizei count
,
630 GLsizei numInstances
)
632 GET_CURRENT_CONTEXT(ctx
);
634 if (MESA_VERBOSE
& VERBOSE_DRAW
)
635 _mesa_debug(ctx
, "glDrawArraysInstanced(%s, %d, %d, %d)\n",
636 _mesa_enum_to_string(mode
), start
, count
, numInstances
);
638 if (!_mesa_validate_DrawArraysInstanced(ctx
, mode
, start
, count
,
643 check_draw_arrays_data(ctx
, start
, count
);
645 vbo_draw_arrays(ctx
, mode
, start
, count
, numInstances
, 0);
648 print_draw_arrays(ctx
, mode
, start
, count
);
653 * Called from glDrawArraysInstancedBaseInstance when in immediate mode.
655 static void GLAPIENTRY
656 vbo_exec_DrawArraysInstancedBaseInstance(GLenum mode
, GLint first
,
657 GLsizei count
, GLsizei numInstances
,
660 GET_CURRENT_CONTEXT(ctx
);
662 if (MESA_VERBOSE
& VERBOSE_DRAW
)
664 "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
, MAP_INTERNAL
);
744 * Inner support for both _mesa_DrawElements and _mesa_DrawRangeElements.
745 * Do the rendering for a glDrawElements or glDrawRangeElements call after
746 * we've validated buffer bounds, etc.
749 vbo_validated_drawrangeelements(struct gl_context
*ctx
, GLenum mode
,
750 GLboolean index_bounds_valid
,
751 GLuint start
, GLuint end
,
752 GLsizei count
, GLenum type
,
753 const GLvoid
* indices
,
754 GLint basevertex
, GLuint numInstances
,
757 struct vbo_context
*vbo
= vbo_context(ctx
);
758 struct _mesa_index_buffer ib
;
759 struct _mesa_prim prim
[1];
761 vbo_bind_arrays(ctx
);
765 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
774 prim
[0].count
= count
;
776 prim
[0].is_indirect
= 0;
777 prim
[0].basevertex
= basevertex
;
778 prim
[0].num_instances
= numInstances
;
779 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
, GLuint start
, GLuint end
,
827 GLsizei count
, GLenum type
,
828 const GLvoid
* indices
, GLint basevertex
)
830 static GLuint warnCount
= 0;
831 GLboolean index_bounds_valid
= GL_TRUE
;
833 /* This is only useful to catch invalid values in the "end" parameter
836 GLuint max_element
= 2 * 1000 * 1000 * 1000; /* just a big number */
838 GET_CURRENT_CONTEXT(ctx
);
840 if (MESA_VERBOSE
& VERBOSE_DRAW
)
842 "glDrawRangeElementsBaseVertex(%s, %u, %u, %d, %s, %p, %d)\n",
843 _mesa_enum_to_string(mode
), start
, end
, count
,
844 _mesa_enum_to_string(type
), indices
, basevertex
);
846 if (!_mesa_validate_DrawRangeElements(ctx
, mode
, start
, end
, count
,
850 if ((int) end
+ basevertex
< 0 || start
+ basevertex
>= max_element
) {
851 /* The application requested we draw using a range of indices that's
852 * outside the bounds of the current VBO. This is invalid and appears
853 * to give undefined results. The safest thing to do is to simply
854 * ignore the range, in case the application botched their range tracking
855 * but did provide valid indices. Also issue a warning indicating that
856 * the application is broken.
858 if (warnCount
++ < 10) {
859 _mesa_warning(ctx
, "glDrawRangeElements(start %u, end %u, "
860 "basevertex %d, count %d, type 0x%x, indices=%p):\n"
861 "\trange is outside VBO bounds (max=%u); ignoring.\n"
862 "\tThis should be fixed in the application.",
863 start
, end
, basevertex
, count
, type
, indices
,
866 index_bounds_valid
= GL_FALSE
;
869 /* NOTE: It's important that 'end' is a reasonable value.
870 * in _tnl_draw_prims(), we use end to determine how many vertices
871 * to transform. If it's too large, we can unnecessarily split prims
872 * or we can read/write out of memory in several different places!
875 /* Catch/fix some potential user errors */
876 if (type
== GL_UNSIGNED_BYTE
) {
877 start
= MIN2(start
, 0xff);
878 end
= MIN2(end
, 0xff);
880 else if (type
== GL_UNSIGNED_SHORT
) {
881 start
= MIN2(start
, 0xffff);
882 end
= MIN2(end
, 0xffff);
886 printf("glDraw[Range]Elements{,BaseVertex}"
887 "(start %u, end %u, type 0x%x, count %d) ElemBuf %u, "
889 start
, end
, type
, count
,
890 ctx
->Array
.VAO
->IndexBufferObj
->Name
, basevertex
);
893 if ((int) start
+ basevertex
< 0 || end
+ basevertex
>= max_element
)
894 index_bounds_valid
= GL_FALSE
;
897 check_draw_elements_data(ctx
, count
, type
, indices
, basevertex
);
899 (void) check_draw_elements_data
;
902 vbo_validated_drawrangeelements(ctx
, mode
, index_bounds_valid
, start
, end
,
903 count
, type
, indices
, basevertex
, 1, 0);
908 * Called by glDrawRangeElements() in immediate mode.
910 static void GLAPIENTRY
911 vbo_exec_DrawRangeElements(GLenum mode
, GLuint start
, GLuint end
,
912 GLsizei count
, GLenum type
, const GLvoid
* indices
)
914 if (MESA_VERBOSE
& VERBOSE_DRAW
) {
915 GET_CURRENT_CONTEXT(ctx
);
917 "glDrawRangeElements(%s, %u, %u, %d, %s, %p)\n",
918 _mesa_enum_to_string(mode
), start
, end
, count
,
919 _mesa_enum_to_string(type
), indices
);
922 vbo_exec_DrawRangeElementsBaseVertex(mode
, start
, end
, count
, type
,
928 * Called by glDrawElements() in immediate mode.
930 static void GLAPIENTRY
931 vbo_exec_DrawElements(GLenum mode
, GLsizei count
, GLenum type
,
932 const GLvoid
* indices
)
934 GET_CURRENT_CONTEXT(ctx
);
936 if (MESA_VERBOSE
& VERBOSE_DRAW
)
937 _mesa_debug(ctx
, "glDrawElements(%s, %u, %s, %p)\n",
938 _mesa_enum_to_string(mode
), count
,
939 _mesa_enum_to_string(type
), indices
);
941 if (!_mesa_validate_DrawElements(ctx
, mode
, count
, type
, indices
))
944 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
945 count
, type
, indices
, 0, 1, 0);
950 * Called by glDrawElementsBaseVertex() in immediate mode.
952 static void GLAPIENTRY
953 vbo_exec_DrawElementsBaseVertex(GLenum mode
, GLsizei count
, GLenum type
,
954 const GLvoid
* indices
, GLint basevertex
)
956 GET_CURRENT_CONTEXT(ctx
);
958 if (MESA_VERBOSE
& VERBOSE_DRAW
)
959 _mesa_debug(ctx
, "glDrawElementsBaseVertex(%s, %d, %s, %p, %d)\n",
960 _mesa_enum_to_string(mode
), count
,
961 _mesa_enum_to_string(type
), indices
, basevertex
);
963 if (!_mesa_validate_DrawElements(ctx
, mode
, count
, type
, indices
))
966 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
967 count
, type
, indices
, basevertex
, 1, 0);
972 * Called by glDrawElementsInstanced() in immediate mode.
974 static void GLAPIENTRY
975 vbo_exec_DrawElementsInstanced(GLenum mode
, GLsizei count
, GLenum type
,
976 const GLvoid
* indices
, GLsizei numInstances
)
978 GET_CURRENT_CONTEXT(ctx
);
980 if (MESA_VERBOSE
& VERBOSE_DRAW
)
981 _mesa_debug(ctx
, "glDrawElementsInstanced(%s, %d, %s, %p, %d)\n",
982 _mesa_enum_to_string(mode
), count
,
983 _mesa_enum_to_string(type
), indices
, numInstances
);
985 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
989 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
990 count
, type
, indices
, 0, numInstances
, 0);
995 * Called by glDrawElementsInstancedBaseVertex() in immediate mode.
997 static void GLAPIENTRY
998 vbo_exec_DrawElementsInstancedBaseVertex(GLenum mode
, GLsizei count
,
999 GLenum type
, const GLvoid
* indices
,
1000 GLsizei numInstances
,
1003 GET_CURRENT_CONTEXT(ctx
);
1005 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1007 "glDrawElementsInstancedBaseVertex(%s, %d, %s, %p, %d; %d)\n",
1008 _mesa_enum_to_string(mode
), count
,
1009 _mesa_enum_to_string(type
), indices
,
1010 numInstances
, basevertex
);
1012 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
1016 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1017 count
, type
, indices
,
1018 basevertex
, numInstances
, 0);
1023 * Called by glDrawElementsInstancedBaseInstance() in immediate mode.
1025 static void GLAPIENTRY
1026 vbo_exec_DrawElementsInstancedBaseInstance(GLenum mode
, GLsizei count
,
1028 const GLvoid
*indices
,
1029 GLsizei numInstances
,
1030 GLuint baseInstance
)
1032 GET_CURRENT_CONTEXT(ctx
);
1034 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1036 "glDrawElementsInstancedBaseInstance"
1037 "(%s, %d, %s, %p, %d, %d)\n",
1038 _mesa_enum_to_string(mode
), count
,
1039 _mesa_enum_to_string(type
), indices
,
1040 numInstances
, baseInstance
);
1042 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
1046 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1047 count
, type
, indices
, 0, numInstances
,
1053 * Called by glDrawElementsInstancedBaseVertexBaseInstance() in immediate mode.
1055 static void GLAPIENTRY
1056 vbo_exec_DrawElementsInstancedBaseVertexBaseInstance(GLenum mode
,
1059 const GLvoid
*indices
,
1060 GLsizei numInstances
,
1062 GLuint baseInstance
)
1064 GET_CURRENT_CONTEXT(ctx
);
1066 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1068 "glDrawElementsInstancedBaseVertexBaseInstance"
1069 "(%s, %d, %s, %p, %d, %d, %d)\n",
1070 _mesa_enum_to_string(mode
), count
,
1071 _mesa_enum_to_string(type
), indices
,
1072 numInstances
, basevertex
, baseInstance
);
1074 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
1078 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1079 count
, type
, indices
, basevertex
,
1080 numInstances
, baseInstance
);
1085 * Inner support for both _mesa_MultiDrawElements() and
1086 * _mesa_MultiDrawRangeElements().
1087 * This does the actual rendering after we've checked array indexes, etc.
1090 vbo_validated_multidrawelements(struct gl_context
*ctx
, GLenum mode
,
1091 const GLsizei
*count
, GLenum type
,
1092 const GLvoid
* const *indices
,
1093 GLsizei primcount
, const GLint
*basevertex
)
1095 struct vbo_context
*vbo
= vbo_context(ctx
);
1096 struct _mesa_index_buffer ib
;
1097 struct _mesa_prim
*prim
;
1098 unsigned int index_type_size
= vbo_sizeof_ib_type(type
);
1099 uintptr_t min_index_ptr
, max_index_ptr
;
1100 GLboolean fallback
= GL_FALSE
;
1106 prim
= calloc(primcount
, sizeof(*prim
));
1108 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMultiDrawElements");
1112 vbo_bind_arrays(ctx
);
1114 min_index_ptr
= (uintptr_t) indices
[0];
1116 for (i
= 0; i
< primcount
; i
++) {
1117 min_index_ptr
= MIN2(min_index_ptr
, (uintptr_t) indices
[i
]);
1118 max_index_ptr
= MAX2(max_index_ptr
, (uintptr_t) indices
[i
] +
1119 index_type_size
* count
[i
]);
1122 /* Check if we can handle this thing as a bunch of index offsets from the
1123 * same index pointer. If we can't, then we have to fall back to doing
1124 * a draw_prims per primitive.
1125 * Check that the difference between each prim's indexes is a multiple of
1126 * the index/element size.
1128 if (index_type_size
!= 1) {
1129 for (i
= 0; i
< primcount
; i
++) {
1130 if ((((uintptr_t) indices
[i
] - min_index_ptr
) % index_type_size
) !=
1138 /* Draw primitives individually if one count is zero, so we can easily skip
1141 for (i
= 0; i
< primcount
; i
++) {
1142 if (count
[i
] == 0) {
1148 /* If the index buffer isn't in a VBO, then treating the application's
1149 * subranges of the index buffer as one large index buffer may lead to
1150 * us reading unmapped memory.
1152 if (!_mesa_is_bufferobj(ctx
->Array
.VAO
->IndexBufferObj
))
1156 ib
.count
= (max_index_ptr
- min_index_ptr
) / index_type_size
;
1158 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1159 ib
.ptr
= (void *) min_index_ptr
;
1161 for (i
= 0; i
< primcount
; i
++) {
1162 prim
[i
].begin
= (i
== 0);
1163 prim
[i
].end
= (i
== primcount
- 1);
1166 prim
[i
].mode
= mode
;
1168 ((uintptr_t) indices
[i
] - min_index_ptr
) / index_type_size
;
1169 prim
[i
].count
= count
[i
];
1170 prim
[i
].indexed
= 1;
1171 prim
[i
].num_instances
= 1;
1172 prim
[i
].base_instance
= 0;
1173 prim
[i
].draw_id
= i
;
1174 prim
[i
].is_indirect
= 0;
1175 if (basevertex
!= NULL
)
1176 prim
[i
].basevertex
= basevertex
[i
];
1178 prim
[i
].basevertex
= 0;
1181 vbo
->draw_prims(ctx
, prim
, primcount
, &ib
,
1182 false, ~0, ~0, NULL
, 0, NULL
);
1185 /* render one prim at a time */
1186 for (i
= 0; i
< primcount
; i
++) {
1189 ib
.count
= count
[i
];
1191 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1192 ib
.ptr
= indices
[i
];
1198 prim
[0].mode
= mode
;
1200 prim
[0].count
= count
[i
];
1201 prim
[0].indexed
= 1;
1202 prim
[0].num_instances
= 1;
1203 prim
[0].base_instance
= 0;
1204 prim
[0].draw_id
= i
;
1205 prim
[0].is_indirect
= 0;
1206 if (basevertex
!= NULL
)
1207 prim
[0].basevertex
= basevertex
[i
];
1209 prim
[0].basevertex
= 0;
1211 vbo
->draw_prims(ctx
, prim
, 1, &ib
, false, ~0, ~0, NULL
, 0, NULL
);
1217 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
) {
1223 static void GLAPIENTRY
1224 vbo_exec_MultiDrawElements(GLenum mode
,
1225 const GLsizei
*count
, GLenum type
,
1226 const GLvoid
* const *indices
, GLsizei primcount
)
1228 GET_CURRENT_CONTEXT(ctx
);
1230 if (!_mesa_validate_MultiDrawElements(ctx
, mode
, count
, type
, indices
,
1234 vbo_validated_multidrawelements(ctx
, mode
, count
, type
, indices
, primcount
,
1239 static void GLAPIENTRY
1240 vbo_exec_MultiDrawElementsBaseVertex(GLenum mode
,
1241 const GLsizei
*count
, GLenum type
,
1242 const GLvoid
* const *indices
,
1244 const GLsizei
*basevertex
)
1246 GET_CURRENT_CONTEXT(ctx
);
1248 if (!_mesa_validate_MultiDrawElements(ctx
, mode
, count
, type
, indices
,
1252 vbo_validated_multidrawelements(ctx
, mode
, count
, type
, indices
, primcount
,
1258 vbo_draw_transform_feedback(struct gl_context
*ctx
, GLenum mode
,
1259 struct gl_transform_feedback_object
*obj
,
1260 GLuint stream
, GLuint numInstances
)
1262 struct vbo_context
*vbo
= vbo_context(ctx
);
1263 struct _mesa_prim prim
[2];
1265 if (!_mesa_validate_DrawTransformFeedback(ctx
, mode
, obj
, stream
,
1270 if (ctx
->Driver
.GetTransformFeedbackVertexCount
&&
1271 (ctx
->Const
.AlwaysUseGetTransformFeedbackVertexCount
||
1272 !_mesa_all_varyings_in_vbos(ctx
->Array
.VAO
))) {
1274 ctx
->Driver
.GetTransformFeedbackVertexCount(ctx
, obj
, stream
);
1275 vbo_draw_arrays(ctx
, mode
, 0, n
, numInstances
, 0);
1279 vbo_bind_arrays(ctx
);
1281 /* init most fields to zero */
1282 memset(prim
, 0, sizeof(prim
));
1285 prim
[0].mode
= mode
;
1286 prim
[0].num_instances
= numInstances
;
1287 prim
[0].base_instance
= 0;
1288 prim
[0].is_indirect
= 0;
1290 /* Maybe we should do some primitive splitting for primitive restart
1291 * (like in DrawArrays), but we have no way to know how many vertices
1292 * will be rendered. */
1294 vbo
->draw_prims(ctx
, prim
, 1, NULL
, GL_FALSE
, ~0, ~0, obj
, stream
, NULL
);
1296 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
) {
1303 * Like DrawArrays, but take the count from a transform feedback object.
1304 * \param mode GL_POINTS, GL_LINES, GL_TRIANGLE_STRIP, etc.
1305 * \param name the transform feedback object
1306 * User still has to setup of the vertex attribute info with
1307 * glVertexPointer, glColorPointer, etc.
1308 * Part of GL_ARB_transform_feedback2.
1310 static void GLAPIENTRY
1311 vbo_exec_DrawTransformFeedback(GLenum mode
, GLuint name
)
1313 GET_CURRENT_CONTEXT(ctx
);
1314 struct gl_transform_feedback_object
*obj
=
1315 _mesa_lookup_transform_feedback_object(ctx
, name
);
1317 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1318 _mesa_debug(ctx
, "glDrawTransformFeedback(%s, %d)\n",
1319 _mesa_enum_to_string(mode
), name
);
1321 vbo_draw_transform_feedback(ctx
, mode
, obj
, 0, 1);
1325 static void GLAPIENTRY
1326 vbo_exec_DrawTransformFeedbackStream(GLenum mode
, GLuint name
, GLuint stream
)
1328 GET_CURRENT_CONTEXT(ctx
);
1329 struct gl_transform_feedback_object
*obj
=
1330 _mesa_lookup_transform_feedback_object(ctx
, name
);
1332 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1333 _mesa_debug(ctx
, "glDrawTransformFeedbackStream(%s, %u, %u)\n",
1334 _mesa_enum_to_string(mode
), name
, stream
);
1336 vbo_draw_transform_feedback(ctx
, mode
, obj
, stream
, 1);
1340 static void GLAPIENTRY
1341 vbo_exec_DrawTransformFeedbackInstanced(GLenum mode
, GLuint name
,
1344 GET_CURRENT_CONTEXT(ctx
);
1345 struct gl_transform_feedback_object
*obj
=
1346 _mesa_lookup_transform_feedback_object(ctx
, name
);
1348 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1349 _mesa_debug(ctx
, "glDrawTransformFeedbackInstanced(%s, %d)\n",
1350 _mesa_enum_to_string(mode
), name
);
1352 vbo_draw_transform_feedback(ctx
, mode
, obj
, 0, primcount
);
1356 static void GLAPIENTRY
1357 vbo_exec_DrawTransformFeedbackStreamInstanced(GLenum mode
, GLuint name
,
1361 GET_CURRENT_CONTEXT(ctx
);
1362 struct gl_transform_feedback_object
*obj
=
1363 _mesa_lookup_transform_feedback_object(ctx
, name
);
1365 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1366 _mesa_debug(ctx
, "glDrawTransformFeedbackStreamInstanced"
1367 "(%s, %u, %u, %i)\n",
1368 _mesa_enum_to_string(mode
), name
, stream
, primcount
);
1370 vbo_draw_transform_feedback(ctx
, mode
, obj
, stream
, primcount
);
1375 vbo_validated_drawarraysindirect(struct gl_context
*ctx
,
1376 GLenum mode
, const GLvoid
*indirect
)
1378 struct vbo_context
*vbo
= vbo_context(ctx
);
1380 vbo_bind_arrays(ctx
);
1382 vbo
->draw_indirect_prims(ctx
, mode
,
1383 ctx
->DrawIndirectBuffer
, (GLsizeiptr
) indirect
,
1384 1 /* draw_count */ , 16 /* stride */ ,
1387 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1393 vbo_validated_multidrawarraysindirect(struct gl_context
*ctx
,
1395 const GLvoid
*indirect
,
1396 GLsizei primcount
, GLsizei stride
)
1398 struct vbo_context
*vbo
= vbo_context(ctx
);
1399 GLsizeiptr offset
= (GLsizeiptr
) indirect
;
1404 vbo_bind_arrays(ctx
);
1406 vbo
->draw_indirect_prims(ctx
, mode
, ctx
->DrawIndirectBuffer
, offset
,
1407 primcount
, stride
, NULL
, 0, NULL
);
1409 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1415 vbo_validated_drawelementsindirect(struct gl_context
*ctx
,
1416 GLenum mode
, GLenum type
,
1417 const GLvoid
*indirect
)
1419 struct vbo_context
*vbo
= vbo_context(ctx
);
1420 struct _mesa_index_buffer ib
;
1422 vbo_bind_arrays(ctx
);
1424 ib
.count
= 0; /* unknown */
1426 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1429 vbo
->draw_indirect_prims(ctx
, mode
,
1430 ctx
->DrawIndirectBuffer
, (GLsizeiptr
) indirect
,
1431 1 /* draw_count */ , 20 /* stride */ ,
1434 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1440 vbo_validated_multidrawelementsindirect(struct gl_context
*ctx
,
1441 GLenum mode
, GLenum type
,
1442 const GLvoid
*indirect
,
1443 GLsizei primcount
, GLsizei stride
)
1445 struct vbo_context
*vbo
= vbo_context(ctx
);
1446 struct _mesa_index_buffer ib
;
1447 GLsizeiptr offset
= (GLsizeiptr
) indirect
;
1452 vbo_bind_arrays(ctx
);
1454 /* NOTE: IndexBufferObj is guaranteed to be a VBO. */
1456 ib
.count
= 0; /* unknown */
1458 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1461 vbo
->draw_indirect_prims(ctx
, mode
,
1462 ctx
->DrawIndirectBuffer
, offset
,
1463 primcount
, stride
, NULL
, 0, &ib
);
1465 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1471 * Like [Multi]DrawArrays/Elements, but they take most arguments from
1474 static void GLAPIENTRY
1475 vbo_exec_DrawArraysIndirect(GLenum mode
, const GLvoid
*indirect
)
1477 GET_CURRENT_CONTEXT(ctx
);
1479 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1480 _mesa_debug(ctx
, "glDrawArraysIndirect(%s, %p)\n",
1481 _mesa_enum_to_string(mode
), indirect
);
1483 if (!_mesa_validate_DrawArraysIndirect(ctx
, mode
, indirect
))
1486 vbo_validated_drawarraysindirect(ctx
, mode
, indirect
);
1490 static void GLAPIENTRY
1491 vbo_exec_DrawElementsIndirect(GLenum mode
, GLenum type
, const GLvoid
*indirect
)
1493 GET_CURRENT_CONTEXT(ctx
);
1495 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1496 _mesa_debug(ctx
, "glDrawElementsIndirect(%s, %s, %p)\n",
1497 _mesa_enum_to_string(mode
),
1498 _mesa_enum_to_string(type
), indirect
);
1500 if (!_mesa_validate_DrawElementsIndirect(ctx
, mode
, type
, indirect
))
1503 vbo_validated_drawelementsindirect(ctx
, mode
, type
, indirect
);
1507 static void GLAPIENTRY
1508 vbo_exec_MultiDrawArraysIndirect(GLenum mode
, const GLvoid
*indirect
,
1509 GLsizei primcount
, GLsizei stride
)
1511 GET_CURRENT_CONTEXT(ctx
);
1513 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1514 _mesa_debug(ctx
, "glMultiDrawArraysIndirect(%s, %p, %i, %i)\n",
1515 _mesa_enum_to_string(mode
), indirect
, primcount
, stride
);
1517 /* If <stride> is zero, the array elements are treated as tightly packed. */
1519 stride
= 4 * sizeof(GLuint
); /* sizeof(DrawArraysIndirectCommand) */
1521 if (!_mesa_validate_MultiDrawArraysIndirect(ctx
, mode
, indirect
,
1525 vbo_validated_multidrawarraysindirect(ctx
, mode
, indirect
,
1530 static void GLAPIENTRY
1531 vbo_exec_MultiDrawElementsIndirect(GLenum mode
, GLenum type
,
1532 const GLvoid
*indirect
,
1533 GLsizei primcount
, GLsizei stride
)
1535 GET_CURRENT_CONTEXT(ctx
);
1537 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1538 _mesa_debug(ctx
, "glMultiDrawElementsIndirect(%s, %s, %p, %i, %i)\n",
1539 _mesa_enum_to_string(mode
),
1540 _mesa_enum_to_string(type
), indirect
, primcount
, stride
);
1542 /* If <stride> is zero, the array elements are treated as tightly packed. */
1544 stride
= 5 * sizeof(GLuint
); /* sizeof(DrawElementsIndirectCommand) */
1546 if (!_mesa_validate_MultiDrawElementsIndirect(ctx
, mode
, type
, indirect
,
1550 vbo_validated_multidrawelementsindirect(ctx
, mode
, type
, indirect
,
1556 vbo_validated_multidrawarraysindirectcount(struct gl_context
*ctx
,
1560 GLsizei maxdrawcount
,
1563 struct vbo_context
*vbo
= vbo_context(ctx
);
1564 GLsizeiptr offset
= indirect
;
1566 if (maxdrawcount
== 0)
1569 vbo_bind_arrays(ctx
);
1571 vbo
->draw_indirect_prims(ctx
, mode
,
1572 ctx
->DrawIndirectBuffer
, offset
,
1573 maxdrawcount
, stride
,
1574 ctx
->ParameterBuffer
, drawcount
, NULL
);
1576 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1582 vbo_validated_multidrawelementsindirectcount(struct gl_context
*ctx
,
1583 GLenum mode
, GLenum type
,
1586 GLsizei maxdrawcount
,
1589 struct vbo_context
*vbo
= vbo_context(ctx
);
1590 struct _mesa_index_buffer ib
;
1591 GLsizeiptr offset
= (GLsizeiptr
) indirect
;
1593 if (maxdrawcount
== 0)
1596 vbo_bind_arrays(ctx
);
1598 /* NOTE: IndexBufferObj is guaranteed to be a VBO. */
1600 ib
.count
= 0; /* unknown */
1602 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1605 vbo
->draw_indirect_prims(ctx
, mode
,
1606 ctx
->DrawIndirectBuffer
, offset
,
1607 maxdrawcount
, stride
,
1608 ctx
->ParameterBuffer
, drawcount
, &ib
);
1610 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1615 static void GLAPIENTRY
1616 vbo_exec_MultiDrawArraysIndirectCount(GLenum mode
, GLintptr indirect
,
1618 GLsizei maxdrawcount
, GLsizei stride
)
1620 GET_CURRENT_CONTEXT(ctx
);
1622 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1623 _mesa_debug(ctx
, "glMultiDrawArraysIndirectCountARB"
1624 "(%s, %lx, %lx, %i, %i)\n",
1625 _mesa_enum_to_string(mode
),
1626 (unsigned long) indirect
, (unsigned long) drawcount
,
1627 maxdrawcount
, stride
);
1629 /* If <stride> is zero, the array elements are treated as tightly packed. */
1631 stride
= 4 * sizeof(GLuint
); /* sizeof(DrawArraysIndirectCommand) */
1633 if (!_mesa_validate_MultiDrawArraysIndirectCount(ctx
, mode
,
1634 indirect
, drawcount
,
1635 maxdrawcount
, stride
))
1638 vbo_validated_multidrawarraysindirectcount(ctx
, mode
, indirect
, drawcount
,
1639 maxdrawcount
, stride
);
1643 static void GLAPIENTRY
1644 vbo_exec_MultiDrawElementsIndirectCount(GLenum mode
, GLenum type
,
1645 GLintptr indirect
, GLintptr drawcount
,
1646 GLsizei maxdrawcount
, GLsizei stride
)
1648 GET_CURRENT_CONTEXT(ctx
);
1650 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1651 _mesa_debug(ctx
, "glMultiDrawElementsIndirectCountARB"
1652 "(%s, %s, %lx, %lx, %i, %i)\n",
1653 _mesa_enum_to_string(mode
), _mesa_enum_to_string(type
),
1654 (unsigned long) indirect
, (unsigned long) drawcount
,
1655 maxdrawcount
, stride
);
1657 /* If <stride> is zero, the array elements are treated as tightly packed. */
1659 stride
= 5 * sizeof(GLuint
); /* sizeof(DrawElementsIndirectCommand) */
1661 if (!_mesa_validate_MultiDrawElementsIndirectCount(ctx
, mode
, type
,
1662 indirect
, drawcount
,
1663 maxdrawcount
, stride
))
1666 vbo_validated_multidrawelementsindirectcount(ctx
, mode
, type
, indirect
,
1667 drawcount
, maxdrawcount
,
1673 * Initialize the dispatch table with the VBO functions for drawing.
1676 vbo_initialize_exec_dispatch(const struct gl_context
*ctx
,
1677 struct _glapi_table
*exec
)
1679 SET_DrawArrays(exec
, vbo_exec_DrawArrays
);
1680 SET_DrawElements(exec
, vbo_exec_DrawElements
);
1682 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1683 SET_DrawRangeElements(exec
, vbo_exec_DrawRangeElements
);
1686 SET_MultiDrawElementsEXT(exec
, vbo_exec_MultiDrawElements
);
1688 if (ctx
->API
== API_OPENGL_COMPAT
) {
1689 SET_Rectf(exec
, vbo_exec_Rectf
);
1690 SET_EvalMesh1(exec
, vbo_exec_EvalMesh1
);
1691 SET_EvalMesh2(exec
, vbo_exec_EvalMesh2
);
1694 if (ctx
->API
!= API_OPENGLES
&&
1695 ctx
->Extensions
.ARB_draw_elements_base_vertex
) {
1696 SET_DrawElementsBaseVertex(exec
, vbo_exec_DrawElementsBaseVertex
);
1697 SET_MultiDrawElementsBaseVertex(exec
,
1698 vbo_exec_MultiDrawElementsBaseVertex
);
1700 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1701 SET_DrawRangeElementsBaseVertex(exec
,
1702 vbo_exec_DrawRangeElementsBaseVertex
);
1703 SET_DrawElementsInstancedBaseVertex(exec
,
1704 vbo_exec_DrawElementsInstancedBaseVertex
);
1708 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1709 SET_DrawArraysInstancedBaseInstance(exec
,
1710 vbo_exec_DrawArraysInstancedBaseInstance
);
1711 SET_DrawElementsInstancedBaseInstance(exec
,
1712 vbo_exec_DrawElementsInstancedBaseInstance
);
1713 SET_DrawElementsInstancedBaseVertexBaseInstance(exec
,
1714 vbo_exec_DrawElementsInstancedBaseVertexBaseInstance
);
1717 if (ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) {
1718 SET_DrawArraysIndirect(exec
, vbo_exec_DrawArraysIndirect
);
1719 SET_DrawElementsIndirect(exec
, vbo_exec_DrawElementsIndirect
);
1722 if (ctx
->API
== API_OPENGL_CORE
) {
1723 SET_MultiDrawArraysIndirect(exec
, vbo_exec_MultiDrawArraysIndirect
);
1724 SET_MultiDrawElementsIndirect(exec
, vbo_exec_MultiDrawElementsIndirect
);
1725 SET_MultiDrawArraysIndirectCountARB(exec
,
1726 vbo_exec_MultiDrawArraysIndirectCount
);
1727 SET_MultiDrawElementsIndirectCountARB(exec
,
1728 vbo_exec_MultiDrawElementsIndirectCount
);
1731 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1732 SET_DrawArraysInstancedARB(exec
, vbo_exec_DrawArraysInstanced
);
1733 SET_DrawElementsInstancedARB(exec
, vbo_exec_DrawElementsInstanced
);
1736 if (_mesa_is_desktop_gl(ctx
)) {
1737 SET_DrawTransformFeedback(exec
, vbo_exec_DrawTransformFeedback
);
1738 SET_DrawTransformFeedbackStream(exec
,
1739 vbo_exec_DrawTransformFeedbackStream
);
1740 SET_DrawTransformFeedbackInstanced(exec
,
1741 vbo_exec_DrawTransformFeedbackInstanced
);
1742 SET_DrawTransformFeedbackStreamInstanced(exec
,
1743 vbo_exec_DrawTransformFeedbackStreamInstanced
);
1750 * The following functions are only used for OpenGL ES 1/2 support.
1751 * And some aren't even supported (yet) in ES 1/2.
1756 _mesa_DrawArrays(GLenum mode
, GLint first
, GLsizei count
)
1758 vbo_exec_DrawArrays(mode
, first
, count
);
1763 _mesa_DrawArraysInstanced(GLenum mode
, GLint first
, GLsizei count
,
1766 vbo_exec_DrawArraysInstanced(mode
, first
, count
, primcount
);
1771 _mesa_DrawElements(GLenum mode
, GLsizei count
, GLenum type
,
1772 const GLvoid
*indices
)
1774 vbo_exec_DrawElements(mode
, count
, type
, indices
);
1779 _mesa_DrawElementsBaseVertex(GLenum mode
, GLsizei count
, GLenum type
,
1780 const GLvoid
*indices
, GLint basevertex
)
1782 vbo_exec_DrawElementsBaseVertex(mode
, count
, type
, indices
, basevertex
);
1787 _mesa_DrawRangeElements(GLenum mode
, GLuint start
, GLuint end
, GLsizei count
,
1788 GLenum type
, const GLvoid
* indices
)
1790 vbo_exec_DrawRangeElements(mode
, start
, end
, count
, type
, indices
);
1795 _mesa_DrawRangeElementsBaseVertex(GLenum mode
, GLuint start
, GLuint end
,
1796 GLsizei count
, GLenum type
,
1797 const GLvoid
*indices
, GLint basevertex
)
1799 vbo_exec_DrawRangeElementsBaseVertex(mode
, start
, end
, count
, type
,
1800 indices
, basevertex
);
1805 _mesa_MultiDrawElementsEXT(GLenum mode
, const GLsizei
*count
, GLenum type
,
1806 const GLvoid
** indices
, GLsizei primcount
)
1808 vbo_exec_MultiDrawElements(mode
, count
, type
, indices
, primcount
);
1813 _mesa_MultiDrawElementsBaseVertex(GLenum mode
,
1814 const GLsizei
*count
, GLenum type
,
1815 const GLvoid
**indices
, GLsizei primcount
,
1816 const GLint
*basevertex
)
1818 vbo_exec_MultiDrawElementsBaseVertex(mode
, count
, type
, indices
,
1819 primcount
, basevertex
);
1824 _mesa_DrawTransformFeedback(GLenum mode
, GLuint name
)
1826 vbo_exec_DrawTransformFeedback(mode
, name
);