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
,
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_array_attributes
*array
= &vao
->VertexAttrib
[attrib
];
107 if (array
->Enabled
) {
108 const struct gl_vertex_buffer_binding
*binding
=
109 &vao
->VertexBinding
[array
->BufferBindingIndex
];
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(vao
->IndexBufferObj
)) {
132 elemMap
= ctx
->Driver
.MapBufferRange(ctx
, 0,
133 vao
->IndexBufferObj
->Size
,
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
, vao
->IndexBufferObj
, MAP_INTERNAL
);
168 for (k
= 0; k
< VERT_ATTRIB_MAX
; k
++) {
169 unmap_array_buffer(ctx
, vao
, k
);
175 * Check array data, looking for NaNs, etc.
178 check_draw_arrays_data(struct gl_context
*ctx
, GLint start
, GLsizei count
)
185 * Print info/data for glDrawArrays(), for debugging.
188 print_draw_arrays(struct gl_context
*ctx
,
189 GLenum mode
, GLint start
, GLsizei count
)
191 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
193 printf("vbo_exec_DrawArrays(mode 0x%x, start %d, count %d):\n",
197 for (i
= 0; i
< VERT_ATTRIB_MAX
; ++i
) {
198 const struct gl_array_attributes
*array
= &vao
->VertexAttrib
[i
];
202 const struct gl_vertex_buffer_binding
*binding
=
203 &vao
->VertexBinding
[array
->BufferBindingIndex
];
204 struct gl_buffer_object
*bufObj
= binding
->BufferObj
;
206 printf("attr %s: size %d stride %d enabled %d "
207 "ptr %p Bufobj %u\n",
208 gl_vert_attrib_name((gl_vert_attrib
)i
),
209 array
->Size
, binding
->Stride
, array
->Enabled
,
210 array
->Ptr
, bufObj
->Name
);
212 if (_mesa_is_bufferobj(bufObj
)) {
213 GLubyte
*p
= ctx
->Driver
.MapBufferRange(ctx
, 0, bufObj
->Size
,
214 GL_MAP_READ_BIT
, bufObj
,
216 int offset
= (int) (GLintptr
)
217 _mesa_vertex_attrib_address(array
, binding
);
218 float *f
= (float *) (p
+ offset
);
221 int n
= (count
* binding
->Stride
) / 4;
224 printf(" Data at offset %d:\n", offset
);
225 for (i
= 0; i
< n
; i
++) {
226 printf(" float[%d] = 0x%08x %f\n", i
, k
[i
], f
[i
]);
228 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, MAP_INTERNAL
);
235 * Set the vbo->exec->inputs[] pointers to point to the enabled
236 * vertex arrays. This depends on the current vertex program/shader
237 * being executed because of whether or not generic vertex arrays
238 * alias the conventional vertex arrays.
239 * For arrays that aren't enabled, we set the input[attrib] pointer
240 * to point at a zero-stride current value "array".
243 recalculate_input_bindings(struct gl_context
*ctx
)
245 struct vbo_context
*vbo
= vbo_context(ctx
);
246 struct vbo_exec_context
*exec
= &vbo
->exec
;
247 const struct gl_array_attributes
*array
= ctx
->Array
.VAO
->VertexAttrib
;
248 struct gl_client_array
*vertexAttrib
= ctx
->Array
.VAO
->_VertexAttrib
;
249 const struct gl_client_array
**inputs
= &exec
->array
.inputs
[0];
250 GLbitfield64 const_inputs
= 0x0;
253 switch (get_program_mode(ctx
)) {
255 /* When no vertex program is active (or the vertex program is generated
256 * from fixed-function state). We put the material values into the
257 * generic slots. This is the only situation where material values
258 * are available as per-vertex attributes.
260 for (i
= 0; i
< VERT_ATTRIB_FF_MAX
; i
++) {
261 if (array
[VERT_ATTRIB_FF(i
)].Enabled
)
262 inputs
[i
] = &vertexAttrib
[VERT_ATTRIB_FF(i
)];
264 inputs
[i
] = &vbo
->currval
[VBO_ATTRIB_POS
+i
];
265 const_inputs
|= VERT_BIT(i
);
269 for (i
= 0; i
< MAT_ATTRIB_MAX
; i
++) {
270 inputs
[VERT_ATTRIB_GENERIC(i
)] =
271 &vbo
->currval
[VBO_ATTRIB_MAT_FRONT_AMBIENT
+i
];
272 const_inputs
|= VERT_BIT_GENERIC(i
);
275 /* Could use just about anything, just to fill in the empty
278 for (i
= MAT_ATTRIB_MAX
; i
< VERT_ATTRIB_GENERIC_MAX
; i
++) {
279 inputs
[VERT_ATTRIB_GENERIC(i
)] = &vbo
->currval
[VBO_ATTRIB_GENERIC0
+i
];
280 const_inputs
|= VERT_BIT_GENERIC(i
);
285 /* There are no shaders in OpenGL ES 1.x, so this code path should be
286 * impossible to reach. The meta code is careful to not use shaders in
289 assert(ctx
->API
!= API_OPENGLES
);
291 /* In the compatibility profile of desktop OpenGL, the generic[0]
292 * attribute array aliases and overrides the legacy position array.
293 * Otherwise, legacy attributes available in the legacy slots,
294 * generic attributes in the generic slots and materials are not
295 * available as per-vertex attributes.
297 * In all other APIs, only the generic attributes exist, and none of the
298 * slots are considered "magic."
300 if (ctx
->API
== API_OPENGL_COMPAT
) {
301 if (array
[VERT_ATTRIB_GENERIC0
].Enabled
)
302 inputs
[0] = &vertexAttrib
[VERT_ATTRIB_GENERIC0
];
303 else if (array
[VERT_ATTRIB_POS
].Enabled
)
304 inputs
[0] = &vertexAttrib
[VERT_ATTRIB_POS
];
306 inputs
[0] = &vbo
->currval
[VBO_ATTRIB_POS
];
307 const_inputs
|= VERT_BIT_POS
;
310 for (i
= 1; i
< VERT_ATTRIB_FF_MAX
; i
++) {
311 if (array
[VERT_ATTRIB_FF(i
)].Enabled
)
312 inputs
[i
] = &vertexAttrib
[VERT_ATTRIB_FF(i
)];
314 inputs
[i
] = &vbo
->currval
[VBO_ATTRIB_POS
+i
];
315 const_inputs
|= VERT_BIT_FF(i
);
319 for (i
= 1; i
< VERT_ATTRIB_GENERIC_MAX
; i
++) {
320 if (array
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
321 inputs
[VERT_ATTRIB_GENERIC(i
)] =
322 &vertexAttrib
[VERT_ATTRIB_GENERIC(i
)];
324 inputs
[VERT_ATTRIB_GENERIC(i
)] =
325 &vbo
->currval
[VBO_ATTRIB_GENERIC0
+i
];
326 const_inputs
|= VERT_BIT_GENERIC(i
);
330 inputs
[VERT_ATTRIB_GENERIC0
] = inputs
[0];
332 /* Other parts of the code assume that inputs[0] through
333 * inputs[VERT_ATTRIB_FF_MAX] will be non-NULL. However, in OpenGL
334 * ES 2.0+ or OpenGL core profile, none of these arrays should ever
337 for (i
= 0; i
< VERT_ATTRIB_FF_MAX
; i
++) {
338 assert(!array
[VERT_ATTRIB_FF(i
)].Enabled
);
340 inputs
[i
] = &vbo
->currval
[VBO_ATTRIB_POS
+i
];
341 const_inputs
|= VERT_BIT_FF(i
);
344 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++) {
345 if (array
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
346 inputs
[VERT_ATTRIB_GENERIC(i
)] =
347 &vertexAttrib
[VERT_ATTRIB_GENERIC(i
)];
349 inputs
[VERT_ATTRIB_GENERIC(i
)] =
350 &vbo
->currval
[VBO_ATTRIB_GENERIC0
+i
];
351 const_inputs
|= VERT_BIT_GENERIC(i
);
359 _mesa_set_varying_vp_inputs( ctx
, VERT_BIT_ALL
& (~const_inputs
) );
360 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewArray
;
365 * Examine the enabled vertex arrays to set the exec->array.inputs[] values.
366 * These will point to the arrays to actually use for drawing. Some will
367 * be user-provided arrays, other will be zero-stride const-valued arrays.
368 * Note that this might set the _NEW_VARYING_VP_INPUTS dirty flag so state
369 * validation must be done after this call.
372 vbo_bind_arrays(struct gl_context
*ctx
)
374 struct vbo_context
*vbo
= vbo_context(ctx
);
375 struct vbo_exec_context
*exec
= &vbo
->exec
;
377 vbo_draw_method(vbo
, DRAW_ARRAYS
);
379 if (exec
->array
.recalculate_inputs
) {
380 recalculate_input_bindings(ctx
);
381 exec
->array
.recalculate_inputs
= GL_FALSE
;
383 /* Again... because we may have changed the bitmask of per-vertex varying
384 * attributes. If we regenerate the fixed-function vertex program now
385 * we may be able to prune down the number of vertex attributes which we
386 * need in the shader.
389 /* Setting "validating" to TRUE prevents _mesa_update_state from
390 * invalidating what we just did.
392 exec
->validating
= GL_TRUE
;
393 _mesa_update_state(ctx
);
394 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
&& !ctx
->Array
.PrimitiveRestartFixedIndex
&&
425 ctx
->Array
.RestartIndex
< count
) {
426 GLuint primCount
= 0;
428 if (ctx
->Array
.RestartIndex
== start
) {
429 /* special case: RestartIndex at beginning */
431 prim
[0].start
= start
+ 1;
432 prim
[0].count
= count
- 1;
436 else if (ctx
->Array
.RestartIndex
== start
+ count
- 1) {
437 /* special case: RestartIndex at end */
439 prim
[0].start
= start
;
440 prim
[0].count
= count
- 1;
445 /* general case: RestartIndex in middle, split into two prims */
446 prim
[0].start
= start
;
447 prim
[0].count
= ctx
->Array
.RestartIndex
- start
;
450 prim
[1].start
= ctx
->Array
.RestartIndex
+ 1;
451 prim
[1].count
= count
- prim
[1].start
;
457 /* draw one or two prims */
458 vbo
->draw_prims(ctx
, prim
, primCount
, NULL
,
459 GL_TRUE
, start
, start
+ count
- 1, NULL
, 0, NULL
);
463 /* no prim restart */
464 prim
[0].start
= start
;
465 prim
[0].count
= count
;
467 vbo
->draw_prims(ctx
, prim
, 1, NULL
,
468 GL_TRUE
, start
, start
+ count
- 1,
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
&&
519 !ctx
->Eval
.Map1Vertex3
)
522 du
= ctx
->Eval
.MapGrid1du
;
523 u
= ctx
->Eval
.MapGrid1u1
+ i1
* du
;
525 CALL_Begin(GET_DISPATCH(), (prim
));
526 for (i
=i1
;i
<=i2
;i
++,u
+=du
) {
527 CALL_EvalCoord1f(GET_DISPATCH(), (u
));
529 CALL_End(GET_DISPATCH(), ());
533 static void GLAPIENTRY
534 vbo_exec_EvalMesh2(GLenum mode
, GLint i1
, GLint i2
, GLint j1
, GLint j2
)
536 GET_CURRENT_CONTEXT(ctx
);
537 GLfloat u
, du
, v
, dv
, v1
, u1
;
546 _mesa_error( ctx
, GL_INVALID_ENUM
, "glEvalMesh2(mode)" );
550 /* No effect if vertex maps disabled.
552 if (!ctx
->Eval
.Map2Vertex4
&&
553 !ctx
->Eval
.Map2Vertex3
)
556 du
= ctx
->Eval
.MapGrid2du
;
557 dv
= ctx
->Eval
.MapGrid2dv
;
558 v1
= ctx
->Eval
.MapGrid2v1
+ j1
* dv
;
559 u1
= ctx
->Eval
.MapGrid2u1
+ i1
* du
;
563 CALL_Begin(GET_DISPATCH(), (GL_POINTS
));
564 for (v
=v1
,j
=j1
;j
<=j2
;j
++,v
+=dv
) {
565 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
566 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
569 CALL_End(GET_DISPATCH(), ());
572 for (v
=v1
,j
=j1
;j
<=j2
;j
++,v
+=dv
) {
573 CALL_Begin(GET_DISPATCH(), (GL_LINE_STRIP
));
574 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
575 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
577 CALL_End(GET_DISPATCH(), ());
579 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
580 CALL_Begin(GET_DISPATCH(), (GL_LINE_STRIP
));
581 for (v
=v1
,j
=j1
;j
<=j2
;j
++,v
+=dv
) {
582 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
584 CALL_End(GET_DISPATCH(), ());
588 for (v
=v1
,j
=j1
;j
<j2
;j
++,v
+=dv
) {
589 CALL_Begin(GET_DISPATCH(), (GL_TRIANGLE_STRIP
));
590 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
591 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
592 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
+dv
));
594 CALL_End(GET_DISPATCH(), ());
602 * Called from glDrawArrays when in immediate mode (not display list mode).
604 static void GLAPIENTRY
605 vbo_exec_DrawArrays(GLenum mode
, GLint start
, GLsizei count
)
607 GET_CURRENT_CONTEXT(ctx
);
609 if (MESA_VERBOSE
& VERBOSE_DRAW
)
610 _mesa_debug(ctx
, "glDrawArrays(%s, %d, %d)\n",
611 _mesa_enum_to_string(mode
), start
, count
);
613 if (!_mesa_validate_DrawArrays(ctx
, mode
, count
))
617 check_draw_arrays_data(ctx
, start
, count
);
619 vbo_draw_arrays(ctx
, mode
, start
, count
, 1, 0);
622 print_draw_arrays(ctx
, mode
, start
, count
);
627 * Called from glDrawArraysInstanced when in immediate mode (not
628 * display list mode).
630 static void GLAPIENTRY
631 vbo_exec_DrawArraysInstanced(GLenum mode
, GLint start
, GLsizei count
,
632 GLsizei numInstances
)
634 GET_CURRENT_CONTEXT(ctx
);
636 if (MESA_VERBOSE
& VERBOSE_DRAW
)
637 _mesa_debug(ctx
, "glDrawArraysInstanced(%s, %d, %d, %d)\n",
638 _mesa_enum_to_string(mode
), start
, count
, numInstances
);
640 if (!_mesa_validate_DrawArraysInstanced(ctx
, mode
, start
, count
, numInstances
))
644 check_draw_arrays_data(ctx
, start
, count
);
646 vbo_draw_arrays(ctx
, mode
, start
, count
, numInstances
, 0);
649 print_draw_arrays(ctx
, mode
, start
, count
);
654 * Called from glDrawArraysInstancedBaseInstance when in immediate mode.
656 static void GLAPIENTRY
657 vbo_exec_DrawArraysInstancedBaseInstance(GLenum mode
, GLint first
, GLsizei count
,
658 GLsizei numInstances
, GLuint baseInstance
)
660 GET_CURRENT_CONTEXT(ctx
);
662 if (MESA_VERBOSE
& VERBOSE_DRAW
)
663 _mesa_debug(ctx
, "glDrawArraysInstancedBaseInstance(%s, %d, %d, %d, %d)\n",
664 _mesa_enum_to_string(mode
), first
, count
,
665 numInstances
, baseInstance
);
667 if (!_mesa_validate_DrawArraysInstanced(ctx
, mode
, first
, count
,
672 check_draw_arrays_data(ctx
, first
, count
);
674 vbo_draw_arrays(ctx
, mode
, first
, count
, numInstances
, baseInstance
);
677 print_draw_arrays(ctx
, mode
, first
, count
);
683 * Map GL_ELEMENT_ARRAY_BUFFER and print contents.
688 dump_element_buffer(struct gl_context
*ctx
, GLenum type
)
691 ctx
->Driver
.MapBufferRange(ctx
, 0,
692 ctx
->Array
.VAO
->IndexBufferObj
->Size
,
694 ctx
->Array
.VAO
->IndexBufferObj
,
697 case GL_UNSIGNED_BYTE
:
699 const GLubyte
*us
= (const GLubyte
*) map
;
701 for (i
= 0; i
< ctx
->Array
.VAO
->IndexBufferObj
->Size
; i
++) {
702 printf("%02x ", us
[i
]);
709 case GL_UNSIGNED_SHORT
:
711 const GLushort
*us
= (const GLushort
*) map
;
713 for (i
= 0; i
< ctx
->Array
.VAO
->IndexBufferObj
->Size
/ 2; i
++) {
714 printf("%04x ", us
[i
]);
721 case GL_UNSIGNED_INT
:
723 const GLuint
*us
= (const GLuint
*) map
;
725 for (i
= 0; i
< ctx
->Array
.VAO
->IndexBufferObj
->Size
/ 4; i
++) {
726 printf("%08x ", us
[i
]);
737 ctx
->Driver
.UnmapBuffer(ctx
, ctx
->Array
.VAO
->IndexBufferObj
,
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
,
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
),
1615 (unsigned long)indirect
, (unsigned long)drawcount
,
1616 maxdrawcount
, stride
);
1618 /* If <stride> is zero, the array elements are treated as tightly packed. */
1620 stride
= 4 * sizeof(GLuint
); /* sizeof(DrawArraysIndirectCommand) */
1622 if (!_mesa_validate_MultiDrawArraysIndirectCount(ctx
, mode
,
1623 indirect
, drawcount
,
1624 maxdrawcount
, stride
))
1627 vbo_validated_multidrawarraysindirectcount(ctx
, mode
,
1628 indirect
, drawcount
,
1629 maxdrawcount
, stride
);
1632 static void GLAPIENTRY
1633 vbo_exec_MultiDrawElementsIndirectCount(GLenum mode
, GLenum type
,
1636 GLsizei maxdrawcount
, GLsizei stride
)
1638 GET_CURRENT_CONTEXT(ctx
);
1640 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1641 _mesa_debug(ctx
, "glMultiDrawElementsIndirectCountARB"
1642 "(%s, %s, %lx, %lx, %i, %i)\n",
1643 _mesa_enum_to_string(mode
), _mesa_enum_to_string(type
),
1644 (unsigned long)indirect
, (unsigned long)drawcount
,
1645 maxdrawcount
, stride
);
1647 /* If <stride> is zero, the array elements are treated as tightly packed. */
1649 stride
= 5 * sizeof(GLuint
); /* sizeof(DrawElementsIndirectCommand) */
1651 if (!_mesa_validate_MultiDrawElementsIndirectCount(ctx
, mode
, type
,
1652 indirect
, drawcount
,
1653 maxdrawcount
, stride
))
1656 vbo_validated_multidrawelementsindirectcount(ctx
, mode
, type
,
1657 indirect
, drawcount
,
1658 maxdrawcount
, stride
);
1663 * Initialize the dispatch table with the VBO functions for drawing.
1666 vbo_initialize_exec_dispatch(const struct gl_context
*ctx
,
1667 struct _glapi_table
*exec
)
1669 SET_DrawArrays(exec
, vbo_exec_DrawArrays
);
1670 SET_DrawElements(exec
, vbo_exec_DrawElements
);
1672 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1673 SET_DrawRangeElements(exec
, vbo_exec_DrawRangeElements
);
1676 SET_MultiDrawElementsEXT(exec
, vbo_exec_MultiDrawElements
);
1678 if (ctx
->API
== API_OPENGL_COMPAT
) {
1679 SET_Rectf(exec
, vbo_exec_Rectf
);
1680 SET_EvalMesh1(exec
, vbo_exec_EvalMesh1
);
1681 SET_EvalMesh2(exec
, vbo_exec_EvalMesh2
);
1684 if (ctx
->API
!= API_OPENGLES
&&
1685 ctx
->Extensions
.ARB_draw_elements_base_vertex
) {
1686 SET_DrawElementsBaseVertex(exec
, vbo_exec_DrawElementsBaseVertex
);
1687 SET_MultiDrawElementsBaseVertex(exec
, vbo_exec_MultiDrawElementsBaseVertex
);
1689 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1690 SET_DrawRangeElementsBaseVertex(exec
, vbo_exec_DrawRangeElementsBaseVertex
);
1691 SET_DrawElementsInstancedBaseVertex(exec
, vbo_exec_DrawElementsInstancedBaseVertex
);
1695 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1696 SET_DrawArraysInstancedBaseInstance(exec
, vbo_exec_DrawArraysInstancedBaseInstance
);
1697 SET_DrawElementsInstancedBaseInstance(exec
, vbo_exec_DrawElementsInstancedBaseInstance
);
1698 SET_DrawElementsInstancedBaseVertexBaseInstance(exec
, vbo_exec_DrawElementsInstancedBaseVertexBaseInstance
);
1701 if (ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) {
1702 SET_DrawArraysIndirect(exec
, vbo_exec_DrawArraysIndirect
);
1703 SET_DrawElementsIndirect(exec
, vbo_exec_DrawElementsIndirect
);
1706 if (ctx
->API
== API_OPENGL_CORE
) {
1707 SET_MultiDrawArraysIndirect(exec
, vbo_exec_MultiDrawArraysIndirect
);
1708 SET_MultiDrawElementsIndirect(exec
, vbo_exec_MultiDrawElementsIndirect
);
1709 SET_MultiDrawArraysIndirectCountARB(exec
, vbo_exec_MultiDrawArraysIndirectCount
);
1710 SET_MultiDrawElementsIndirectCountARB(exec
, vbo_exec_MultiDrawElementsIndirectCount
);
1713 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1714 SET_DrawArraysInstancedARB(exec
, vbo_exec_DrawArraysInstanced
);
1715 SET_DrawElementsInstancedARB(exec
, vbo_exec_DrawElementsInstanced
);
1718 if (_mesa_is_desktop_gl(ctx
)) {
1719 SET_DrawTransformFeedback(exec
, vbo_exec_DrawTransformFeedback
);
1720 SET_DrawTransformFeedbackStream(exec
, vbo_exec_DrawTransformFeedbackStream
);
1721 SET_DrawTransformFeedbackInstanced(exec
, vbo_exec_DrawTransformFeedbackInstanced
);
1722 SET_DrawTransformFeedbackStreamInstanced(exec
, vbo_exec_DrawTransformFeedbackStreamInstanced
);
1729 * The following functions are only used for OpenGL ES 1/2 support.
1730 * And some aren't even supported (yet) in ES 1/2.
1735 _mesa_DrawArrays(GLenum mode
, GLint first
, GLsizei count
)
1737 vbo_exec_DrawArrays(mode
, first
, count
);
1741 _mesa_DrawArraysInstanced(GLenum mode
, GLint first
, GLsizei count
,
1744 vbo_exec_DrawArraysInstanced(mode
, first
, count
, primcount
);
1748 _mesa_DrawElements(GLenum mode
, GLsizei count
, GLenum type
,
1749 const GLvoid
*indices
)
1751 vbo_exec_DrawElements(mode
, count
, type
, indices
);
1756 _mesa_DrawElementsBaseVertex(GLenum mode
, GLsizei count
, GLenum type
,
1757 const GLvoid
*indices
, GLint basevertex
)
1759 vbo_exec_DrawElementsBaseVertex(mode
, count
, type
, indices
, basevertex
);
1764 _mesa_DrawRangeElements(GLenum mode
, GLuint start
, GLuint end
, GLsizei count
,
1765 GLenum type
, const GLvoid
*indices
)
1767 vbo_exec_DrawRangeElements(mode
, start
, end
, count
, type
, indices
);
1772 _mesa_DrawRangeElementsBaseVertex(GLenum mode
, GLuint start
, GLuint end
,
1773 GLsizei count
, GLenum type
,
1774 const GLvoid
*indices
, GLint basevertex
)
1776 vbo_exec_DrawRangeElementsBaseVertex(mode
, start
, end
, count
, type
,
1777 indices
, basevertex
);
1782 _mesa_MultiDrawElementsEXT(GLenum mode
, const GLsizei
*count
, GLenum type
,
1783 const GLvoid
**indices
, GLsizei primcount
)
1785 vbo_exec_MultiDrawElements(mode
, count
, type
, indices
, primcount
);
1790 _mesa_MultiDrawElementsBaseVertex(GLenum mode
,
1791 const GLsizei
*count
, GLenum type
,
1792 const GLvoid
**indices
, GLsizei primcount
,
1793 const GLint
*basevertex
)
1795 vbo_exec_MultiDrawElementsBaseVertex(mode
, count
, type
, indices
,
1796 primcount
, basevertex
);
1800 _mesa_DrawTransformFeedback(GLenum mode
, GLuint name
)
1802 vbo_exec_DrawTransformFeedback(mode
, name
);