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 * All vertex buffers should be in an unmapped state when we're about
50 check_input_buffers_are_unmapped(const struct gl_vertex_array_object
*vao
)
52 /* Walk the enabled arrays that have a vbo attached */
53 GLbitfield64 mask
= vao
->_Enabled
& vao
->VertexAttribBufferMask
;
56 int i
= ffsll(mask
) - 1;
57 const struct gl_vertex_attrib_array
*attrib_array
=
58 &vao
->VertexAttrib
[i
];
59 const struct gl_vertex_buffer_binding
*buffer_binding
=
60 &vao
->VertexBinding
[attrib_array
->VertexBinding
];
62 /* Only enabled arrays shall appear in the _Enabled bitmask */
63 assert(attrib_array
->Enabled
);
64 /* We have already masked with vao->VertexAttribBufferMask */
65 assert(_mesa_is_bufferobj(buffer_binding
->BufferObj
));
67 /* Bail out once we find the first disallowed mapping */
68 if (_mesa_check_disallowed_mapping(buffer_binding
->BufferObj
))
71 /* We have handled everything that is bound to this buffer_binding. */
72 mask
&= ~buffer_binding
->_BoundArrays
;
80 * Check that element 'j' of the array has reasonable data.
82 * For debugging purposes; not normally used.
85 check_array_data(struct gl_context
*ctx
, struct gl_vertex_array_object
*vao
,
86 GLuint attrib
, GLuint j
)
88 const struct gl_vertex_attrib_array
*array
= &vao
->VertexAttrib
[attrib
];
90 const struct gl_vertex_buffer_binding
*binding
=
91 &vao
->VertexBinding
[array
->VertexBinding
];
92 struct gl_buffer_object
*bo
= binding
->BufferObj
;
93 const void *data
= array
->Ptr
;
94 if (_mesa_is_bufferobj(bo
)) {
95 if (!bo
->Mappings
[MAP_INTERNAL
].Pointer
) {
97 bo
->Mappings
[MAP_INTERNAL
].Pointer
=
98 ctx
->Driver
.MapBufferRange(ctx
, 0, bo
->Size
,
102 data
= ADD_POINTERS(_mesa_vertex_attrib_address(array
, binding
),
103 bo
->Mappings
[MAP_INTERNAL
].Pointer
);
105 switch (array
->Type
) {
108 GLfloat
*f
= (GLfloat
*) ((GLubyte
*) data
+ binding
->Stride
* j
);
110 for (k
= 0; k
< array
->Size
; k
++) {
111 if (IS_INF_OR_NAN(f
[k
]) ||
112 f
[k
] >= 1.0e20F
|| f
[k
] <= -1.0e10F
) {
113 printf("Bad array data:\n");
114 printf(" Element[%u].%u = %f\n", j
, k
, f
[k
]);
115 printf(" Array %u at %p\n", attrib
, (void* ) array
);
116 printf(" Type 0x%x, Size %d, Stride %d\n",
117 array
->Type
, array
->Size
, binding
->Stride
);
118 printf(" Address/offset %p in Buffer Object %u\n",
119 array
->Ptr
, bo
->Name
);
120 f
[k
] = 1.0F
; /* XXX replace the bad value! */
122 /*assert(!IS_INF_OR_NAN(f[k]));*/
134 * Unmap the buffer object referenced by given array, if mapped.
137 unmap_array_buffer(struct gl_context
*ctx
, struct gl_vertex_array_object
*vao
,
140 const struct gl_vertex_attrib_array
*array
= &vao
->VertexAttrib
[attrib
];
141 if (array
->Enabled
) {
142 const struct gl_vertex_buffer_binding
*binding
=
143 &vao
->VertexBinding
[array
->VertexBinding
];
144 struct gl_buffer_object
*bo
= binding
->BufferObj
;
145 if (_mesa_is_bufferobj(bo
) && _mesa_bufferobj_mapped(bo
, MAP_INTERNAL
)) {
146 ctx
->Driver
.UnmapBuffer(ctx
, bo
, MAP_INTERNAL
);
153 * Examine the array's data for NaNs, etc.
154 * For debug purposes; not normally used.
157 check_draw_elements_data(struct gl_context
*ctx
, GLsizei count
, GLenum elemType
,
158 const void *elements
, GLint basevertex
)
160 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
165 if (_mesa_is_bufferobj(ctx
->Array
.VAO
->IndexBufferObj
)) {
166 elemMap
= ctx
->Driver
.MapBufferRange(ctx
, 0,
167 ctx
->Array
.VAO
->IndexBufferObj
->Size
,
169 ctx
->Array
.VAO
->IndexBufferObj
,
171 elements
= ADD_POINTERS(elements
, elemMap
);
174 for (i
= 0; i
< count
; i
++) {
179 case GL_UNSIGNED_BYTE
:
180 j
= ((const GLubyte
*) elements
)[i
];
182 case GL_UNSIGNED_SHORT
:
183 j
= ((const GLushort
*) elements
)[i
];
185 case GL_UNSIGNED_INT
:
186 j
= ((const GLuint
*) elements
)[i
];
192 /* check element j of each enabled array */
193 for (k
= 0; k
< VERT_ATTRIB_MAX
; k
++) {
194 check_array_data(ctx
, vao
, k
, j
);
198 if (_mesa_is_bufferobj(vao
->IndexBufferObj
)) {
199 ctx
->Driver
.UnmapBuffer(ctx
, ctx
->Array
.VAO
->IndexBufferObj
,
203 for (k
= 0; k
< VERT_ATTRIB_MAX
; k
++) {
204 unmap_array_buffer(ctx
, vao
, k
);
210 * Check array data, looking for NaNs, etc.
213 check_draw_arrays_data(struct gl_context
*ctx
, GLint start
, GLsizei count
)
220 * Print info/data for glDrawArrays(), for debugging.
223 print_draw_arrays(struct gl_context
*ctx
,
224 GLenum mode
, GLint start
, GLsizei count
)
226 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
228 printf("vbo_exec_DrawArrays(mode 0x%x, start %d, count %d):\n",
232 for (i
= 0; i
< VERT_ATTRIB_MAX
; ++i
) {
233 const struct gl_vertex_attrib_array
*array
= &vao
->VertexAttrib
[i
];
237 const struct gl_vertex_buffer_binding
*binding
=
238 &vao
->VertexBinding
[array
->VertexBinding
];
239 struct gl_buffer_object
*bufObj
= binding
->BufferObj
;
241 printf("attr %s: size %d stride %d enabled %d "
242 "ptr %p Bufobj %u\n",
243 gl_vert_attrib_name((gl_vert_attrib
)i
),
244 array
->Size
, binding
->Stride
, array
->Enabled
,
245 array
->Ptr
, bufObj
->Name
);
247 if (_mesa_is_bufferobj(bufObj
)) {
248 GLubyte
*p
= ctx
->Driver
.MapBufferRange(ctx
, 0, bufObj
->Size
,
249 GL_MAP_READ_BIT
, bufObj
,
251 int offset
= (int) (GLintptr
)
252 _mesa_vertex_attrib_address(array
, binding
);
253 float *f
= (float *) (p
+ offset
);
256 int n
= (count
* binding
->Stride
) / 4;
259 printf(" Data at offset %d:\n", offset
);
260 for (i
= 0; i
< n
; i
++) {
261 printf(" float[%d] = 0x%08x %f\n", i
, k
[i
], f
[i
]);
263 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, MAP_INTERNAL
);
270 * Set the vbo->exec->inputs[] pointers to point to the enabled
271 * vertex arrays. This depends on the current vertex program/shader
272 * being executed because of whether or not generic vertex arrays
273 * alias the conventional vertex arrays.
274 * For arrays that aren't enabled, we set the input[attrib] pointer
275 * to point at a zero-stride current value "array".
278 recalculate_input_bindings(struct gl_context
*ctx
)
280 struct vbo_context
*vbo
= vbo_context(ctx
);
281 struct vbo_exec_context
*exec
= &vbo
->exec
;
282 const struct gl_vertex_attrib_array
*array
= ctx
->Array
.VAO
->VertexAttrib
;
283 struct gl_client_array
*vertexAttrib
= ctx
->Array
.VAO
->_VertexAttrib
;
284 const struct gl_client_array
**inputs
= &exec
->array
.inputs
[0];
285 GLbitfield64 const_inputs
= 0x0;
288 switch (get_program_mode(ctx
)) {
290 /* When no vertex program is active (or the vertex program is generated
291 * from fixed-function state). We put the material values into the
292 * generic slots. This is the only situation where material values
293 * are available as per-vertex attributes.
295 for (i
= 0; i
< VERT_ATTRIB_FF_MAX
; i
++) {
296 if (array
[VERT_ATTRIB_FF(i
)].Enabled
)
297 inputs
[i
] = &vertexAttrib
[VERT_ATTRIB_FF(i
)];
299 inputs
[i
] = &vbo
->currval
[VBO_ATTRIB_POS
+i
];
300 const_inputs
|= VERT_BIT(i
);
304 for (i
= 0; i
< MAT_ATTRIB_MAX
; i
++) {
305 inputs
[VERT_ATTRIB_GENERIC(i
)] =
306 &vbo
->currval
[VBO_ATTRIB_MAT_FRONT_AMBIENT
+i
];
307 const_inputs
|= VERT_BIT_GENERIC(i
);
310 /* Could use just about anything, just to fill in the empty
313 for (i
= MAT_ATTRIB_MAX
; i
< VERT_ATTRIB_GENERIC_MAX
; i
++) {
314 inputs
[VERT_ATTRIB_GENERIC(i
)] = &vbo
->currval
[VBO_ATTRIB_GENERIC0
+i
];
315 const_inputs
|= VERT_BIT_GENERIC(i
);
320 /* There are no shaders in OpenGL ES 1.x, so this code path should be
321 * impossible to reach. The meta code is careful to not use shaders in
324 assert(ctx
->API
!= API_OPENGLES
);
326 /* In the compatibility profile of desktop OpenGL, the generic[0]
327 * attribute array aliases and overrides the legacy position array.
328 * Otherwise, legacy attributes available in the legacy slots,
329 * generic attributes in the generic slots and materials are not
330 * available as per-vertex attributes.
332 * In all other APIs, only the generic attributes exist, and none of the
333 * slots are considered "magic."
335 if (ctx
->API
== API_OPENGL_COMPAT
) {
336 if (array
[VERT_ATTRIB_GENERIC0
].Enabled
)
337 inputs
[0] = &vertexAttrib
[VERT_ATTRIB_GENERIC0
];
338 else if (array
[VERT_ATTRIB_POS
].Enabled
)
339 inputs
[0] = &vertexAttrib
[VERT_ATTRIB_POS
];
341 inputs
[0] = &vbo
->currval
[VBO_ATTRIB_POS
];
342 const_inputs
|= VERT_BIT_POS
;
345 for (i
= 1; i
< VERT_ATTRIB_FF_MAX
; i
++) {
346 if (array
[VERT_ATTRIB_FF(i
)].Enabled
)
347 inputs
[i
] = &vertexAttrib
[VERT_ATTRIB_FF(i
)];
349 inputs
[i
] = &vbo
->currval
[VBO_ATTRIB_POS
+i
];
350 const_inputs
|= VERT_BIT_FF(i
);
354 for (i
= 1; i
< VERT_ATTRIB_GENERIC_MAX
; i
++) {
355 if (array
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
356 inputs
[VERT_ATTRIB_GENERIC(i
)] =
357 &vertexAttrib
[VERT_ATTRIB_GENERIC(i
)];
359 inputs
[VERT_ATTRIB_GENERIC(i
)] =
360 &vbo
->currval
[VBO_ATTRIB_GENERIC0
+i
];
361 const_inputs
|= VERT_BIT_GENERIC(i
);
365 inputs
[VERT_ATTRIB_GENERIC0
] = inputs
[0];
367 /* Other parts of the code assume that inputs[0] through
368 * inputs[VERT_ATTRIB_FF_MAX] will be non-NULL. However, in OpenGL
369 * ES 2.0+ or OpenGL core profile, none of these arrays should ever
372 for (i
= 0; i
< VERT_ATTRIB_FF_MAX
; i
++) {
373 assert(!array
[VERT_ATTRIB_FF(i
)].Enabled
);
375 inputs
[i
] = &vbo
->currval
[VBO_ATTRIB_POS
+i
];
376 const_inputs
|= VERT_BIT_FF(i
);
379 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++) {
380 if (array
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
381 inputs
[VERT_ATTRIB_GENERIC(i
)] =
382 &vertexAttrib
[VERT_ATTRIB_GENERIC(i
)];
384 inputs
[VERT_ATTRIB_GENERIC(i
)] =
385 &vbo
->currval
[VBO_ATTRIB_GENERIC0
+i
];
386 const_inputs
|= VERT_BIT_GENERIC(i
);
394 _mesa_set_varying_vp_inputs( ctx
, VERT_BIT_ALL
& (~const_inputs
) );
395 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewArray
;
400 * Examine the enabled vertex arrays to set the exec->array.inputs[] values.
401 * These will point to the arrays to actually use for drawing. Some will
402 * be user-provided arrays, other will be zero-stride const-valued arrays.
403 * Note that this might set the _NEW_VARYING_VP_INPUTS dirty flag so state
404 * validation must be done after this call.
407 vbo_bind_arrays(struct gl_context
*ctx
)
409 struct vbo_context
*vbo
= vbo_context(ctx
);
410 struct vbo_exec_context
*exec
= &vbo
->exec
;
412 vbo_draw_method(vbo
, DRAW_ARRAYS
);
414 if (exec
->array
.recalculate_inputs
) {
415 recalculate_input_bindings(ctx
);
416 exec
->array
.recalculate_inputs
= GL_FALSE
;
418 /* Again... because we may have changed the bitmask of per-vertex varying
419 * attributes. If we regenerate the fixed-function vertex program now
420 * we may be able to prune down the number of vertex attributes which we
421 * need in the shader.
424 /* Setting "validating" to TRUE prevents _mesa_update_state from
425 * invalidating what we just did.
427 exec
->validating
= GL_TRUE
;
428 _mesa_update_state(ctx
);
429 exec
->validating
= GL_FALSE
;
433 if (!check_input_buffers_are_unmapped(ctx
->Array
.VAO
)) {
434 _mesa_error(ctx
, GL_INVALID_OPERATION
,
435 "draw call (vertex buffers are mapped)");
443 * Helper function called by the other DrawArrays() functions below.
444 * This is where we handle primitive restart for drawing non-indexed
445 * arrays. If primitive restart is enabled, it typically means
446 * splitting one DrawArrays() into two.
449 vbo_draw_arrays(struct gl_context
*ctx
, GLenum mode
, GLint start
,
450 GLsizei count
, GLuint numInstances
, GLuint baseInstance
)
452 struct vbo_context
*vbo
= vbo_context(ctx
);
453 struct _mesa_prim prim
[2];
455 if (!vbo_bind_arrays(ctx
))
458 /* init most fields to zero */
459 memset(prim
, 0, sizeof(prim
));
463 prim
[0].num_instances
= numInstances
;
464 prim
[0].base_instance
= baseInstance
;
465 prim
[0].is_indirect
= 0;
467 /* Implement the primitive restart index */
468 if (ctx
->Array
.PrimitiveRestart
&& !ctx
->Array
.PrimitiveRestartFixedIndex
&&
469 ctx
->Array
.RestartIndex
< count
) {
470 GLuint primCount
= 0;
472 if (ctx
->Array
.RestartIndex
== start
) {
473 /* special case: RestartIndex at beginning */
475 prim
[0].start
= start
+ 1;
476 prim
[0].count
= count
- 1;
480 else if (ctx
->Array
.RestartIndex
== start
+ count
- 1) {
481 /* special case: RestartIndex at end */
483 prim
[0].start
= start
;
484 prim
[0].count
= count
- 1;
489 /* general case: RestartIndex in middle, split into two prims */
490 prim
[0].start
= start
;
491 prim
[0].count
= ctx
->Array
.RestartIndex
- start
;
494 prim
[1].start
= ctx
->Array
.RestartIndex
+ 1;
495 prim
[1].count
= count
- prim
[1].start
;
501 /* draw one or two prims */
502 vbo
->draw_prims(ctx
, prim
, primCount
, NULL
,
503 GL_TRUE
, start
, start
+ count
- 1, NULL
, 0, NULL
);
507 /* no prim restart */
508 prim
[0].start
= start
;
509 prim
[0].count
= count
;
511 vbo
->draw_prims(ctx
, prim
, 1, NULL
,
512 GL_TRUE
, start
, start
+ count
- 1,
516 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
) {
523 * Execute a glRectf() function.
525 static void GLAPIENTRY
526 vbo_exec_Rectf(GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
)
528 GET_CURRENT_CONTEXT(ctx
);
529 ASSERT_OUTSIDE_BEGIN_END(ctx
);
531 CALL_Begin(GET_DISPATCH(), (GL_QUADS
));
532 CALL_Vertex2f(GET_DISPATCH(), (x1
, y1
));
533 CALL_Vertex2f(GET_DISPATCH(), (x2
, y1
));
534 CALL_Vertex2f(GET_DISPATCH(), (x2
, y2
));
535 CALL_Vertex2f(GET_DISPATCH(), (x1
, y2
));
536 CALL_End(GET_DISPATCH(), ());
540 static void GLAPIENTRY
541 vbo_exec_EvalMesh1(GLenum mode
, GLint i1
, GLint i2
)
543 GET_CURRENT_CONTEXT(ctx
);
553 prim
= GL_LINE_STRIP
;
556 _mesa_error( ctx
, GL_INVALID_ENUM
, "glEvalMesh1(mode)" );
560 /* No effect if vertex maps disabled.
562 if (!ctx
->Eval
.Map1Vertex4
&&
563 !ctx
->Eval
.Map1Vertex3
)
566 du
= ctx
->Eval
.MapGrid1du
;
567 u
= ctx
->Eval
.MapGrid1u1
+ i1
* du
;
569 CALL_Begin(GET_DISPATCH(), (prim
));
570 for (i
=i1
;i
<=i2
;i
++,u
+=du
) {
571 CALL_EvalCoord1f(GET_DISPATCH(), (u
));
573 CALL_End(GET_DISPATCH(), ());
577 static void GLAPIENTRY
578 vbo_exec_EvalMesh2(GLenum mode
, GLint i1
, GLint i2
, GLint j1
, GLint j2
)
580 GET_CURRENT_CONTEXT(ctx
);
581 GLfloat u
, du
, v
, dv
, v1
, u1
;
590 _mesa_error( ctx
, GL_INVALID_ENUM
, "glEvalMesh2(mode)" );
594 /* No effect if vertex maps disabled.
596 if (!ctx
->Eval
.Map2Vertex4
&&
597 !ctx
->Eval
.Map2Vertex3
)
600 du
= ctx
->Eval
.MapGrid2du
;
601 dv
= ctx
->Eval
.MapGrid2dv
;
602 v1
= ctx
->Eval
.MapGrid2v1
+ j1
* dv
;
603 u1
= ctx
->Eval
.MapGrid2u1
+ i1
* du
;
607 CALL_Begin(GET_DISPATCH(), (GL_POINTS
));
608 for (v
=v1
,j
=j1
;j
<=j2
;j
++,v
+=dv
) {
609 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
610 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
613 CALL_End(GET_DISPATCH(), ());
616 for (v
=v1
,j
=j1
;j
<=j2
;j
++,v
+=dv
) {
617 CALL_Begin(GET_DISPATCH(), (GL_LINE_STRIP
));
618 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
619 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
621 CALL_End(GET_DISPATCH(), ());
623 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
624 CALL_Begin(GET_DISPATCH(), (GL_LINE_STRIP
));
625 for (v
=v1
,j
=j1
;j
<=j2
;j
++,v
+=dv
) {
626 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
628 CALL_End(GET_DISPATCH(), ());
632 for (v
=v1
,j
=j1
;j
<j2
;j
++,v
+=dv
) {
633 CALL_Begin(GET_DISPATCH(), (GL_TRIANGLE_STRIP
));
634 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
635 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
636 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
+dv
));
638 CALL_End(GET_DISPATCH(), ());
646 * Called from glDrawArrays when in immediate mode (not display list mode).
648 static void GLAPIENTRY
649 vbo_exec_DrawArrays(GLenum mode
, GLint start
, GLsizei count
)
651 GET_CURRENT_CONTEXT(ctx
);
653 if (MESA_VERBOSE
& VERBOSE_DRAW
)
654 _mesa_debug(ctx
, "glDrawArrays(%s, %d, %d)\n",
655 _mesa_enum_to_string(mode
), start
, count
);
657 if (!_mesa_validate_DrawArrays(ctx
, mode
, count
))
661 check_draw_arrays_data(ctx
, start
, count
);
663 vbo_draw_arrays(ctx
, mode
, start
, count
, 1, 0);
666 print_draw_arrays(ctx
, mode
, start
, count
);
671 * Called from glDrawArraysInstanced when in immediate mode (not
672 * display list mode).
674 static void GLAPIENTRY
675 vbo_exec_DrawArraysInstanced(GLenum mode
, GLint start
, GLsizei count
,
676 GLsizei numInstances
)
678 GET_CURRENT_CONTEXT(ctx
);
680 if (MESA_VERBOSE
& VERBOSE_DRAW
)
681 _mesa_debug(ctx
, "glDrawArraysInstanced(%s, %d, %d, %d)\n",
682 _mesa_enum_to_string(mode
), start
, count
, numInstances
);
684 if (!_mesa_validate_DrawArraysInstanced(ctx
, mode
, start
, count
, numInstances
))
688 check_draw_arrays_data(ctx
, start
, count
);
690 vbo_draw_arrays(ctx
, mode
, start
, count
, numInstances
, 0);
693 print_draw_arrays(ctx
, mode
, start
, count
);
698 * Called from glDrawArraysInstancedBaseInstance when in immediate mode.
700 static void GLAPIENTRY
701 vbo_exec_DrawArraysInstancedBaseInstance(GLenum mode
, GLint first
, GLsizei count
,
702 GLsizei numInstances
, GLuint baseInstance
)
704 GET_CURRENT_CONTEXT(ctx
);
706 if (MESA_VERBOSE
& VERBOSE_DRAW
)
707 _mesa_debug(ctx
, "glDrawArraysInstancedBaseInstance(%s, %d, %d, %d, %d)\n",
708 _mesa_enum_to_string(mode
), first
, count
,
709 numInstances
, baseInstance
);
711 if (!_mesa_validate_DrawArraysInstanced(ctx
, mode
, first
, count
,
716 check_draw_arrays_data(ctx
, first
, count
);
718 vbo_draw_arrays(ctx
, mode
, first
, count
, numInstances
, baseInstance
);
721 print_draw_arrays(ctx
, mode
, first
, count
);
727 * Map GL_ELEMENT_ARRAY_BUFFER and print contents.
732 dump_element_buffer(struct gl_context
*ctx
, GLenum type
)
735 ctx
->Driver
.MapBufferRange(ctx
, 0,
736 ctx
->Array
.VAO
->IndexBufferObj
->Size
,
738 ctx
->Array
.VAO
->IndexBufferObj
,
741 case GL_UNSIGNED_BYTE
:
743 const GLubyte
*us
= (const GLubyte
*) map
;
745 for (i
= 0; i
< ctx
->Array
.VAO
->IndexBufferObj
->Size
; i
++) {
746 printf("%02x ", us
[i
]);
753 case GL_UNSIGNED_SHORT
:
755 const GLushort
*us
= (const GLushort
*) map
;
757 for (i
= 0; i
< ctx
->Array
.VAO
->IndexBufferObj
->Size
/ 2; i
++) {
758 printf("%04x ", us
[i
]);
765 case GL_UNSIGNED_INT
:
767 const GLuint
*us
= (const GLuint
*) map
;
769 for (i
= 0; i
< ctx
->Array
.VAO
->IndexBufferObj
->Size
/ 4; i
++) {
770 printf("%08x ", us
[i
]);
781 ctx
->Driver
.UnmapBuffer(ctx
, ctx
->Array
.VAO
->IndexBufferObj
,
788 * Inner support for both _mesa_DrawElements and _mesa_DrawRangeElements.
789 * Do the rendering for a glDrawElements or glDrawRangeElements call after
790 * we've validated buffer bounds, etc.
793 vbo_validated_drawrangeelements(struct gl_context
*ctx
, GLenum mode
,
794 GLboolean index_bounds_valid
,
795 GLuint start
, GLuint end
,
796 GLsizei count
, GLenum type
,
797 const GLvoid
*indices
,
798 GLint basevertex
, GLuint numInstances
,
801 struct vbo_context
*vbo
= vbo_context(ctx
);
802 struct _mesa_index_buffer ib
;
803 struct _mesa_prim prim
[1];
805 if (!vbo_bind_arrays(ctx
))
810 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
819 prim
[0].count
= count
;
821 prim
[0].is_indirect
= 0;
822 prim
[0].basevertex
= basevertex
;
823 prim
[0].num_instances
= numInstances
;
824 prim
[0].base_instance
= baseInstance
;
826 /* Need to give special consideration to rendering a range of
827 * indices starting somewhere above zero. Typically the
828 * application is issuing multiple DrawRangeElements() to draw
829 * successive primitives layed out linearly in the vertex arrays.
830 * Unless the vertex arrays are all in a VBO (or locked as with
831 * CVA), the OpenGL semantics imply that we need to re-read or
832 * re-upload the vertex data on each draw call.
834 * In the case of hardware tnl, we want to avoid starting the
835 * upload at zero, as it will mean every draw call uploads an
836 * increasing amount of not-used vertex data. Worse - in the
837 * software tnl module, all those vertices might be transformed and
838 * lit but never rendered.
840 * If we just upload or transform the vertices in start..end,
841 * however, the indices will be incorrect.
843 * At this level, we don't know exactly what the requirements of
844 * the backend are going to be, though it will likely boil down to
847 * 1) Do nothing, everything is in a VBO and is processed once
850 * 2) Adjust the indices and vertex arrays so that start becomes
853 * Rather than doing anything here, I'll provide a helper function
854 * for the latter case elsewhere.
857 vbo
->draw_prims(ctx
, prim
, 1, &ib
,
858 index_bounds_valid
, start
, end
, NULL
, 0, NULL
);
860 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
) {
867 * Called by glDrawRangeElementsBaseVertex() in immediate mode.
869 static void GLAPIENTRY
870 vbo_exec_DrawRangeElementsBaseVertex(GLenum mode
,
871 GLuint start
, GLuint end
,
872 GLsizei count
, GLenum type
,
873 const GLvoid
*indices
,
876 static GLuint warnCount
= 0;
877 GLboolean index_bounds_valid
= GL_TRUE
;
879 /* This is only useful to catch invalid values in the "end" parameter
882 GLuint max_element
= 2 * 1000 * 1000 * 1000; /* just a big number */
884 GET_CURRENT_CONTEXT(ctx
);
886 if (MESA_VERBOSE
& VERBOSE_DRAW
)
888 "glDrawRangeElementsBaseVertex(%s, %u, %u, %d, %s, %p, %d)\n",
889 _mesa_enum_to_string(mode
), start
, end
, count
,
890 _mesa_enum_to_string(type
), indices
, basevertex
);
892 if (!_mesa_validate_DrawRangeElements(ctx
, mode
, start
, end
, count
,
896 if ((int) end
+ basevertex
< 0 ||
897 start
+ basevertex
>= max_element
) {
898 /* The application requested we draw using a range of indices that's
899 * outside the bounds of the current VBO. This is invalid and appears
900 * to give undefined results. The safest thing to do is to simply
901 * ignore the range, in case the application botched their range tracking
902 * but did provide valid indices. Also issue a warning indicating that
903 * the application is broken.
905 if (warnCount
++ < 10) {
906 _mesa_warning(ctx
, "glDrawRangeElements(start %u, end %u, "
907 "basevertex %d, count %d, type 0x%x, indices=%p):\n"
908 "\trange is outside VBO bounds (max=%u); ignoring.\n"
909 "\tThis should be fixed in the application.",
910 start
, end
, basevertex
, count
, type
, indices
,
913 index_bounds_valid
= GL_FALSE
;
916 /* NOTE: It's important that 'end' is a reasonable value.
917 * in _tnl_draw_prims(), we use end to determine how many vertices
918 * to transform. If it's too large, we can unnecessarily split prims
919 * or we can read/write out of memory in several different places!
922 /* Catch/fix some potential user errors */
923 if (type
== GL_UNSIGNED_BYTE
) {
924 start
= MIN2(start
, 0xff);
925 end
= MIN2(end
, 0xff);
927 else if (type
== GL_UNSIGNED_SHORT
) {
928 start
= MIN2(start
, 0xffff);
929 end
= MIN2(end
, 0xffff);
933 printf("glDraw[Range]Elements{,BaseVertex}"
934 "(start %u, end %u, type 0x%x, count %d) ElemBuf %u, "
936 start
, end
, type
, count
,
937 ctx
->Array
.VAO
->IndexBufferObj
->Name
,
941 if ((int) start
+ basevertex
< 0 ||
942 end
+ basevertex
>= max_element
)
943 index_bounds_valid
= GL_FALSE
;
946 check_draw_elements_data(ctx
, count
, type
, indices
);
948 (void) check_draw_elements_data
;
951 vbo_validated_drawrangeelements(ctx
, mode
, index_bounds_valid
, start
, end
,
952 count
, type
, indices
, basevertex
, 1, 0);
957 * Called by glDrawRangeElements() in immediate mode.
959 static void GLAPIENTRY
960 vbo_exec_DrawRangeElements(GLenum mode
, GLuint start
, GLuint end
,
961 GLsizei count
, GLenum type
, const GLvoid
*indices
)
963 if (MESA_VERBOSE
& VERBOSE_DRAW
) {
964 GET_CURRENT_CONTEXT(ctx
);
966 "glDrawRangeElements(%s, %u, %u, %d, %s, %p)\n",
967 _mesa_enum_to_string(mode
), start
, end
, count
,
968 _mesa_enum_to_string(type
), indices
);
971 vbo_exec_DrawRangeElementsBaseVertex(mode
, start
, end
, count
, type
,
977 * Called by glDrawElements() in immediate mode.
979 static void GLAPIENTRY
980 vbo_exec_DrawElements(GLenum mode
, GLsizei count
, GLenum type
,
981 const GLvoid
*indices
)
983 GET_CURRENT_CONTEXT(ctx
);
985 if (MESA_VERBOSE
& VERBOSE_DRAW
)
986 _mesa_debug(ctx
, "glDrawElements(%s, %u, %s, %p)\n",
987 _mesa_enum_to_string(mode
), count
,
988 _mesa_enum_to_string(type
), indices
);
990 if (!_mesa_validate_DrawElements(ctx
, mode
, count
, type
, indices
))
993 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
994 count
, type
, indices
, 0, 1, 0);
999 * Called by glDrawElementsBaseVertex() in immediate mode.
1001 static void GLAPIENTRY
1002 vbo_exec_DrawElementsBaseVertex(GLenum mode
, GLsizei count
, GLenum type
,
1003 const GLvoid
*indices
, GLint basevertex
)
1005 GET_CURRENT_CONTEXT(ctx
);
1007 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1008 _mesa_debug(ctx
, "glDrawElementsBaseVertex(%s, %d, %s, %p, %d)\n",
1009 _mesa_enum_to_string(mode
), count
,
1010 _mesa_enum_to_string(type
), indices
, basevertex
);
1012 if (!_mesa_validate_DrawElements(ctx
, mode
, count
, type
, indices
))
1015 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1016 count
, type
, indices
, basevertex
, 1, 0);
1021 * Called by glDrawElementsInstanced() in immediate mode.
1023 static void GLAPIENTRY
1024 vbo_exec_DrawElementsInstanced(GLenum mode
, GLsizei count
, GLenum type
,
1025 const GLvoid
*indices
, GLsizei numInstances
)
1027 GET_CURRENT_CONTEXT(ctx
);
1029 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1030 _mesa_debug(ctx
, "glDrawElementsInstanced(%s, %d, %s, %p, %d)\n",
1031 _mesa_enum_to_string(mode
), count
,
1032 _mesa_enum_to_string(type
), indices
, numInstances
);
1034 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
1038 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1039 count
, type
, indices
, 0, numInstances
, 0);
1044 * Called by glDrawElementsInstancedBaseVertex() in immediate mode.
1046 static void GLAPIENTRY
1047 vbo_exec_DrawElementsInstancedBaseVertex(GLenum mode
, GLsizei count
, GLenum type
,
1048 const GLvoid
*indices
, GLsizei numInstances
,
1051 GET_CURRENT_CONTEXT(ctx
);
1053 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1054 _mesa_debug(ctx
, "glDrawElementsInstancedBaseVertex(%s, %d, %s, %p, %d; %d)\n",
1055 _mesa_enum_to_string(mode
), count
,
1056 _mesa_enum_to_string(type
), indices
,
1057 numInstances
, basevertex
);
1059 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
1063 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1064 count
, type
, indices
, basevertex
, numInstances
, 0);
1069 * Called by glDrawElementsInstancedBaseInstance() in immediate mode.
1071 static void GLAPIENTRY
1072 vbo_exec_DrawElementsInstancedBaseInstance(GLenum mode
, GLsizei count
, GLenum type
,
1073 const GLvoid
*indices
, GLsizei numInstances
,
1074 GLuint baseInstance
)
1076 GET_CURRENT_CONTEXT(ctx
);
1078 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1079 _mesa_debug(ctx
, "glDrawElementsInstancedBaseInstance(%s, %d, %s, %p, %d, %d)\n",
1080 _mesa_enum_to_string(mode
), count
,
1081 _mesa_enum_to_string(type
), indices
,
1082 numInstances
, baseInstance
);
1084 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
1088 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1089 count
, type
, indices
, 0, numInstances
,
1095 * Called by glDrawElementsInstancedBaseVertexBaseInstance() in immediate mode.
1097 static void GLAPIENTRY
1098 vbo_exec_DrawElementsInstancedBaseVertexBaseInstance(GLenum mode
, GLsizei count
, GLenum type
,
1099 const GLvoid
*indices
, GLsizei numInstances
,
1100 GLint basevertex
, GLuint baseInstance
)
1102 GET_CURRENT_CONTEXT(ctx
);
1104 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1105 _mesa_debug(ctx
, "glDrawElementsInstancedBaseVertexBaseInstance(%s, %d, %s, %p, %d, %d, %d)\n",
1106 _mesa_enum_to_string(mode
), count
,
1107 _mesa_enum_to_string(type
), indices
,
1108 numInstances
, basevertex
, baseInstance
);
1110 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
1114 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1115 count
, type
, indices
, basevertex
, numInstances
,
1121 * Inner support for both _mesa_MultiDrawElements() and
1122 * _mesa_MultiDrawRangeElements().
1123 * This does the actual rendering after we've checked array indexes, etc.
1126 vbo_validated_multidrawelements(struct gl_context
*ctx
, GLenum mode
,
1127 const GLsizei
*count
, GLenum type
,
1128 const GLvoid
* const *indices
,
1130 const GLint
*basevertex
)
1132 struct vbo_context
*vbo
= vbo_context(ctx
);
1133 struct _mesa_index_buffer ib
;
1134 struct _mesa_prim
*prim
;
1135 unsigned int index_type_size
= vbo_sizeof_ib_type(type
);
1136 uintptr_t min_index_ptr
, max_index_ptr
;
1137 GLboolean fallback
= GL_FALSE
;
1143 prim
= calloc(primcount
, sizeof(*prim
));
1145 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMultiDrawElements");
1149 if (!vbo_bind_arrays(ctx
)) {
1154 min_index_ptr
= (uintptr_t)indices
[0];
1156 for (i
= 0; i
< primcount
; i
++) {
1157 min_index_ptr
= MIN2(min_index_ptr
, (uintptr_t)indices
[i
]);
1158 max_index_ptr
= MAX2(max_index_ptr
, (uintptr_t)indices
[i
] +
1159 index_type_size
* count
[i
]);
1162 /* Check if we can handle this thing as a bunch of index offsets from the
1163 * same index pointer. If we can't, then we have to fall back to doing
1164 * a draw_prims per primitive.
1165 * Check that the difference between each prim's indexes is a multiple of
1166 * the index/element size.
1168 if (index_type_size
!= 1) {
1169 for (i
= 0; i
< primcount
; i
++) {
1170 if ((((uintptr_t)indices
[i
] - min_index_ptr
) % index_type_size
) != 0) {
1177 /* Draw primitives individually if one count is zero, so we can easily skip
1180 for (i
= 0; i
< primcount
; i
++) {
1181 if (count
[i
] == 0) {
1187 /* If the index buffer isn't in a VBO, then treating the application's
1188 * subranges of the index buffer as one large index buffer may lead to
1189 * us reading unmapped memory.
1191 if (!_mesa_is_bufferobj(ctx
->Array
.VAO
->IndexBufferObj
))
1195 ib
.count
= (max_index_ptr
- min_index_ptr
) / index_type_size
;
1197 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1198 ib
.ptr
= (void *)min_index_ptr
;
1200 for (i
= 0; i
< primcount
; i
++) {
1201 prim
[i
].begin
= (i
== 0);
1202 prim
[i
].end
= (i
== primcount
- 1);
1205 prim
[i
].mode
= mode
;
1206 prim
[i
].start
= ((uintptr_t)indices
[i
] - min_index_ptr
) / index_type_size
;
1207 prim
[i
].count
= count
[i
];
1208 prim
[i
].indexed
= 1;
1209 prim
[i
].num_instances
= 1;
1210 prim
[i
].base_instance
= 0;
1211 prim
[i
].draw_id
= i
;
1212 prim
[i
].is_indirect
= 0;
1213 if (basevertex
!= NULL
)
1214 prim
[i
].basevertex
= basevertex
[i
];
1216 prim
[i
].basevertex
= 0;
1219 vbo
->draw_prims(ctx
, prim
, primcount
, &ib
,
1220 false, ~0, ~0, NULL
, 0, NULL
);
1222 /* render one prim at a time */
1223 for (i
= 0; i
< primcount
; i
++) {
1226 ib
.count
= count
[i
];
1228 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1229 ib
.ptr
= indices
[i
];
1235 prim
[0].mode
= mode
;
1237 prim
[0].count
= count
[i
];
1238 prim
[0].indexed
= 1;
1239 prim
[0].num_instances
= 1;
1240 prim
[0].base_instance
= 0;
1241 prim
[0].draw_id
= i
;
1242 prim
[0].is_indirect
= 0;
1243 if (basevertex
!= NULL
)
1244 prim
[0].basevertex
= basevertex
[i
];
1246 prim
[0].basevertex
= 0;
1248 vbo
->draw_prims(ctx
, prim
, 1, &ib
,
1249 false, ~0, ~0, NULL
, 0, NULL
);
1255 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
) {
1261 static void GLAPIENTRY
1262 vbo_exec_MultiDrawElements(GLenum mode
,
1263 const GLsizei
*count
, GLenum type
,
1264 const GLvoid
* const *indices
,
1267 GET_CURRENT_CONTEXT(ctx
);
1269 if (!_mesa_validate_MultiDrawElements(ctx
, mode
, count
, type
, indices
,
1273 vbo_validated_multidrawelements(ctx
, mode
, count
, type
, indices
, primcount
,
1278 static void GLAPIENTRY
1279 vbo_exec_MultiDrawElementsBaseVertex(GLenum mode
,
1280 const GLsizei
*count
, GLenum type
,
1281 const GLvoid
* const *indices
,
1283 const GLsizei
*basevertex
)
1285 GET_CURRENT_CONTEXT(ctx
);
1287 if (!_mesa_validate_MultiDrawElements(ctx
, mode
, count
, type
, indices
,
1291 vbo_validated_multidrawelements(ctx
, mode
, count
, type
, indices
, primcount
,
1296 vbo_draw_transform_feedback(struct gl_context
*ctx
, GLenum mode
,
1297 struct gl_transform_feedback_object
*obj
,
1298 GLuint stream
, GLuint numInstances
)
1300 struct vbo_context
*vbo
= vbo_context(ctx
);
1301 struct _mesa_prim prim
[2];
1303 if (!_mesa_validate_DrawTransformFeedback(ctx
, mode
, obj
, stream
,
1308 if (ctx
->Driver
.GetTransformFeedbackVertexCount
&&
1309 (ctx
->Const
.AlwaysUseGetTransformFeedbackVertexCount
||
1310 !_mesa_all_varyings_in_vbos(ctx
->Array
.VAO
))) {
1311 GLsizei n
= ctx
->Driver
.GetTransformFeedbackVertexCount(ctx
, obj
, stream
);
1312 vbo_draw_arrays(ctx
, mode
, 0, n
, numInstances
, 0);
1316 if (!vbo_bind_arrays(ctx
))
1319 /* init most fields to zero */
1320 memset(prim
, 0, sizeof(prim
));
1323 prim
[0].mode
= mode
;
1324 prim
[0].num_instances
= numInstances
;
1325 prim
[0].base_instance
= 0;
1326 prim
[0].is_indirect
= 0;
1328 /* Maybe we should do some primitive splitting for primitive restart
1329 * (like in DrawArrays), but we have no way to know how many vertices
1330 * will be rendered. */
1332 vbo
->draw_prims(ctx
, prim
, 1, NULL
,
1333 GL_FALSE
, ~0, ~0, obj
, stream
, NULL
);
1335 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
) {
1341 * Like DrawArrays, but take the count from a transform feedback object.
1342 * \param mode GL_POINTS, GL_LINES, GL_TRIANGLE_STRIP, etc.
1343 * \param name the transform feedback object
1344 * User still has to setup of the vertex attribute info with
1345 * glVertexPointer, glColorPointer, etc.
1346 * Part of GL_ARB_transform_feedback2.
1348 static void GLAPIENTRY
1349 vbo_exec_DrawTransformFeedback(GLenum mode
, GLuint name
)
1351 GET_CURRENT_CONTEXT(ctx
);
1352 struct gl_transform_feedback_object
*obj
=
1353 _mesa_lookup_transform_feedback_object(ctx
, name
);
1355 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1356 _mesa_debug(ctx
, "glDrawTransformFeedback(%s, %d)\n",
1357 _mesa_enum_to_string(mode
), name
);
1359 vbo_draw_transform_feedback(ctx
, mode
, obj
, 0, 1);
1362 static void GLAPIENTRY
1363 vbo_exec_DrawTransformFeedbackStream(GLenum mode
, GLuint name
, GLuint stream
)
1365 GET_CURRENT_CONTEXT(ctx
);
1366 struct gl_transform_feedback_object
*obj
=
1367 _mesa_lookup_transform_feedback_object(ctx
, name
);
1369 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1370 _mesa_debug(ctx
, "glDrawTransformFeedbackStream(%s, %u, %u)\n",
1371 _mesa_enum_to_string(mode
), name
, stream
);
1373 vbo_draw_transform_feedback(ctx
, mode
, obj
, stream
, 1);
1376 static void GLAPIENTRY
1377 vbo_exec_DrawTransformFeedbackInstanced(GLenum mode
, GLuint name
,
1380 GET_CURRENT_CONTEXT(ctx
);
1381 struct gl_transform_feedback_object
*obj
=
1382 _mesa_lookup_transform_feedback_object(ctx
, name
);
1384 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1385 _mesa_debug(ctx
, "glDrawTransformFeedbackInstanced(%s, %d)\n",
1386 _mesa_enum_to_string(mode
), name
);
1388 vbo_draw_transform_feedback(ctx
, mode
, obj
, 0, primcount
);
1391 static void GLAPIENTRY
1392 vbo_exec_DrawTransformFeedbackStreamInstanced(GLenum mode
, GLuint name
,
1393 GLuint stream
, GLsizei primcount
)
1395 GET_CURRENT_CONTEXT(ctx
);
1396 struct gl_transform_feedback_object
*obj
=
1397 _mesa_lookup_transform_feedback_object(ctx
, name
);
1399 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1400 _mesa_debug(ctx
, "glDrawTransformFeedbackStreamInstanced"
1401 "(%s, %u, %u, %i)\n",
1402 _mesa_enum_to_string(mode
), name
, stream
, primcount
);
1404 vbo_draw_transform_feedback(ctx
, mode
, obj
, stream
, primcount
);
1408 vbo_validated_drawarraysindirect(struct gl_context
*ctx
,
1409 GLenum mode
, const GLvoid
*indirect
)
1411 struct vbo_context
*vbo
= vbo_context(ctx
);
1413 if (!vbo_bind_arrays(ctx
))
1416 vbo
->draw_indirect_prims(ctx
, mode
,
1417 ctx
->DrawIndirectBuffer
, (GLsizeiptr
)indirect
,
1418 1 /* draw_count */, 16 /* stride */,
1421 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1426 vbo_validated_multidrawarraysindirect(struct gl_context
*ctx
,
1428 const GLvoid
*indirect
,
1429 GLsizei primcount
, GLsizei stride
)
1431 struct vbo_context
*vbo
= vbo_context(ctx
);
1432 GLsizeiptr offset
= (GLsizeiptr
)indirect
;
1437 if (!vbo_bind_arrays(ctx
))
1440 vbo
->draw_indirect_prims(ctx
, mode
,
1441 ctx
->DrawIndirectBuffer
, offset
,
1445 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1450 vbo_validated_drawelementsindirect(struct gl_context
*ctx
,
1451 GLenum mode
, GLenum type
,
1452 const GLvoid
*indirect
)
1454 struct vbo_context
*vbo
= vbo_context(ctx
);
1455 struct _mesa_index_buffer ib
;
1457 if (!vbo_bind_arrays(ctx
))
1460 ib
.count
= 0; /* unknown */
1462 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1465 vbo
->draw_indirect_prims(ctx
, mode
,
1466 ctx
->DrawIndirectBuffer
, (GLsizeiptr
)indirect
,
1467 1 /* draw_count */, 20 /* stride */,
1471 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1476 vbo_validated_multidrawelementsindirect(struct gl_context
*ctx
,
1477 GLenum mode
, GLenum type
,
1478 const GLvoid
*indirect
,
1479 GLsizei primcount
, GLsizei stride
)
1481 struct vbo_context
*vbo
= vbo_context(ctx
);
1482 struct _mesa_index_buffer ib
;
1483 GLsizeiptr offset
= (GLsizeiptr
)indirect
;
1488 if (!vbo_bind_arrays(ctx
))
1491 /* NOTE: IndexBufferObj is guaranteed to be a VBO. */
1493 ib
.count
= 0; /* unknown */
1495 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1498 vbo
->draw_indirect_prims(ctx
, mode
,
1499 ctx
->DrawIndirectBuffer
, offset
,
1504 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1509 * Like [Multi]DrawArrays/Elements, but they take most arguments from
1512 static void GLAPIENTRY
1513 vbo_exec_DrawArraysIndirect(GLenum mode
, const GLvoid
*indirect
)
1515 GET_CURRENT_CONTEXT(ctx
);
1517 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1518 _mesa_debug(ctx
, "glDrawArraysIndirect(%s, %p)\n",
1519 _mesa_enum_to_string(mode
), indirect
);
1521 if (!_mesa_validate_DrawArraysIndirect(ctx
, mode
, indirect
))
1524 vbo_validated_drawarraysindirect(ctx
, mode
, indirect
);
1527 static void GLAPIENTRY
1528 vbo_exec_DrawElementsIndirect(GLenum mode
, GLenum type
,
1529 const GLvoid
*indirect
)
1531 GET_CURRENT_CONTEXT(ctx
);
1533 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1534 _mesa_debug(ctx
, "glDrawElementsIndirect(%s, %s, %p)\n",
1535 _mesa_enum_to_string(mode
),
1536 _mesa_enum_to_string(type
), indirect
);
1538 if (!_mesa_validate_DrawElementsIndirect(ctx
, mode
, type
, indirect
))
1541 vbo_validated_drawelementsindirect(ctx
, mode
, type
, indirect
);
1544 static void GLAPIENTRY
1545 vbo_exec_MultiDrawArraysIndirect(GLenum mode
,
1546 const GLvoid
*indirect
,
1547 GLsizei primcount
, GLsizei stride
)
1549 GET_CURRENT_CONTEXT(ctx
);
1551 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1552 _mesa_debug(ctx
, "glMultiDrawArraysIndirect(%s, %p, %i, %i)\n",
1553 _mesa_enum_to_string(mode
), indirect
, primcount
, stride
);
1555 /* If <stride> is zero, the array elements are treated as tightly packed. */
1557 stride
= 4 * sizeof(GLuint
); /* sizeof(DrawArraysIndirectCommand) */
1559 if (!_mesa_validate_MultiDrawArraysIndirect(ctx
, mode
,
1564 vbo_validated_multidrawarraysindirect(ctx
, mode
,
1569 static void GLAPIENTRY
1570 vbo_exec_MultiDrawElementsIndirect(GLenum mode
, GLenum type
,
1571 const GLvoid
*indirect
,
1572 GLsizei primcount
, GLsizei stride
)
1574 GET_CURRENT_CONTEXT(ctx
);
1576 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1577 _mesa_debug(ctx
, "glMultiDrawElementsIndirect(%s, %s, %p, %i, %i)\n",
1578 _mesa_enum_to_string(mode
),
1579 _mesa_enum_to_string(type
), indirect
, primcount
, stride
);
1581 /* If <stride> is zero, the array elements are treated as tightly packed. */
1583 stride
= 5 * sizeof(GLuint
); /* sizeof(DrawElementsIndirectCommand) */
1585 if (!_mesa_validate_MultiDrawElementsIndirect(ctx
, mode
, type
,
1590 vbo_validated_multidrawelementsindirect(ctx
, mode
, type
,
1596 vbo_validated_multidrawarraysindirectcount(struct gl_context
*ctx
,
1600 GLsizei maxdrawcount
,
1603 struct vbo_context
*vbo
= vbo_context(ctx
);
1604 GLsizeiptr offset
= indirect
;
1606 if (maxdrawcount
== 0)
1609 if (!vbo_bind_arrays(ctx
))
1612 vbo
->draw_indirect_prims(ctx
, mode
,
1613 ctx
->DrawIndirectBuffer
, offset
,
1614 maxdrawcount
, stride
,
1615 ctx
->ParameterBuffer
, drawcount
,
1618 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1623 vbo_validated_multidrawelementsindirectcount(struct gl_context
*ctx
,
1624 GLenum mode
, GLenum type
,
1627 GLsizei maxdrawcount
,
1630 struct vbo_context
*vbo
= vbo_context(ctx
);
1631 struct _mesa_index_buffer ib
;
1632 GLsizeiptr offset
= (GLsizeiptr
)indirect
;
1634 if (maxdrawcount
== 0)
1637 if (!vbo_bind_arrays(ctx
))
1640 /* NOTE: IndexBufferObj is guaranteed to be a VBO. */
1642 ib
.count
= 0; /* unknown */
1644 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1647 vbo
->draw_indirect_prims(ctx
, mode
,
1648 ctx
->DrawIndirectBuffer
, offset
,
1649 maxdrawcount
, stride
,
1650 ctx
->ParameterBuffer
, drawcount
,
1653 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1657 static void GLAPIENTRY
1658 vbo_exec_MultiDrawArraysIndirectCount(GLenum mode
,
1661 GLsizei maxdrawcount
, GLsizei stride
)
1663 GET_CURRENT_CONTEXT(ctx
);
1665 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1666 _mesa_debug(ctx
, "glMultiDrawArraysIndirectCountARB"
1667 "(%s, %lx, %lx, %i, %i)\n",
1668 _mesa_enum_to_string(mode
), indirect
,
1669 drawcount
, maxdrawcount
, stride
);
1671 /* If <stride> is zero, the array elements are treated as tightly packed. */
1673 stride
= 4 * sizeof(GLuint
); /* sizeof(DrawArraysIndirectCommand) */
1675 if (!_mesa_validate_MultiDrawArraysIndirectCount(ctx
, mode
,
1676 indirect
, drawcount
,
1677 maxdrawcount
, stride
))
1680 vbo_validated_multidrawarraysindirectcount(ctx
, mode
,
1681 indirect
, drawcount
,
1682 maxdrawcount
, stride
);
1685 static void GLAPIENTRY
1686 vbo_exec_MultiDrawElementsIndirectCount(GLenum mode
, GLenum type
,
1689 GLsizei maxdrawcount
, GLsizei stride
)
1691 GET_CURRENT_CONTEXT(ctx
);
1693 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1694 _mesa_debug(ctx
, "glMultiDrawElementsIndirectCountARB"
1695 "(%s, %s, %lx, %lx, %i, %i)\n",
1696 _mesa_enum_to_string(mode
),
1697 _mesa_enum_to_string(type
), indirect
,
1698 drawcount
, maxdrawcount
, stride
);
1700 /* If <stride> is zero, the array elements are treated as tightly packed. */
1702 stride
= 5 * sizeof(GLuint
); /* sizeof(DrawElementsIndirectCommand) */
1704 if (!_mesa_validate_MultiDrawElementsIndirectCount(ctx
, mode
, type
,
1705 indirect
, drawcount
,
1706 maxdrawcount
, stride
))
1709 vbo_validated_multidrawelementsindirectcount(ctx
, mode
, type
,
1710 indirect
, drawcount
,
1711 maxdrawcount
, stride
);
1716 * Initialize the dispatch table with the VBO functions for drawing.
1719 vbo_initialize_exec_dispatch(const struct gl_context
*ctx
,
1720 struct _glapi_table
*exec
)
1722 SET_DrawArrays(exec
, vbo_exec_DrawArrays
);
1723 SET_DrawElements(exec
, vbo_exec_DrawElements
);
1725 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1726 SET_DrawRangeElements(exec
, vbo_exec_DrawRangeElements
);
1729 SET_MultiDrawElementsEXT(exec
, vbo_exec_MultiDrawElements
);
1731 if (ctx
->API
== API_OPENGL_COMPAT
) {
1732 SET_Rectf(exec
, vbo_exec_Rectf
);
1733 SET_EvalMesh1(exec
, vbo_exec_EvalMesh1
);
1734 SET_EvalMesh2(exec
, vbo_exec_EvalMesh2
);
1737 if (ctx
->API
!= API_OPENGLES
&&
1738 ctx
->Extensions
.ARB_draw_elements_base_vertex
) {
1739 SET_DrawElementsBaseVertex(exec
, vbo_exec_DrawElementsBaseVertex
);
1740 SET_MultiDrawElementsBaseVertex(exec
, vbo_exec_MultiDrawElementsBaseVertex
);
1742 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1743 SET_DrawRangeElementsBaseVertex(exec
, vbo_exec_DrawRangeElementsBaseVertex
);
1744 SET_DrawElementsInstancedBaseVertex(exec
, vbo_exec_DrawElementsInstancedBaseVertex
);
1748 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1749 SET_DrawArraysInstancedBaseInstance(exec
, vbo_exec_DrawArraysInstancedBaseInstance
);
1750 SET_DrawElementsInstancedBaseInstance(exec
, vbo_exec_DrawElementsInstancedBaseInstance
);
1751 SET_DrawElementsInstancedBaseVertexBaseInstance(exec
, vbo_exec_DrawElementsInstancedBaseVertexBaseInstance
);
1754 if (ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) {
1755 SET_DrawArraysIndirect(exec
, vbo_exec_DrawArraysIndirect
);
1756 SET_DrawElementsIndirect(exec
, vbo_exec_DrawElementsIndirect
);
1759 if (ctx
->API
== API_OPENGL_CORE
) {
1760 SET_MultiDrawArraysIndirect(exec
, vbo_exec_MultiDrawArraysIndirect
);
1761 SET_MultiDrawElementsIndirect(exec
, vbo_exec_MultiDrawElementsIndirect
);
1762 SET_MultiDrawArraysIndirectCountARB(exec
, vbo_exec_MultiDrawArraysIndirectCount
);
1763 SET_MultiDrawElementsIndirectCountARB(exec
, vbo_exec_MultiDrawElementsIndirectCount
);
1766 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1767 SET_DrawArraysInstancedARB(exec
, vbo_exec_DrawArraysInstanced
);
1768 SET_DrawElementsInstancedARB(exec
, vbo_exec_DrawElementsInstanced
);
1771 if (_mesa_is_desktop_gl(ctx
)) {
1772 SET_DrawTransformFeedback(exec
, vbo_exec_DrawTransformFeedback
);
1773 SET_DrawTransformFeedbackStream(exec
, vbo_exec_DrawTransformFeedbackStream
);
1774 SET_DrawTransformFeedbackInstanced(exec
, vbo_exec_DrawTransformFeedbackInstanced
);
1775 SET_DrawTransformFeedbackStreamInstanced(exec
, vbo_exec_DrawTransformFeedbackStreamInstanced
);
1782 * The following functions are only used for OpenGL ES 1/2 support.
1783 * And some aren't even supported (yet) in ES 1/2.
1788 _mesa_DrawArrays(GLenum mode
, GLint first
, GLsizei count
)
1790 vbo_exec_DrawArrays(mode
, first
, count
);
1794 _mesa_DrawArraysInstanced(GLenum mode
, GLint first
, GLsizei count
,
1797 vbo_exec_DrawArraysInstanced(mode
, first
, count
, primcount
);
1801 _mesa_DrawElements(GLenum mode
, GLsizei count
, GLenum type
,
1802 const GLvoid
*indices
)
1804 vbo_exec_DrawElements(mode
, count
, type
, indices
);
1809 _mesa_DrawElementsBaseVertex(GLenum mode
, GLsizei count
, GLenum type
,
1810 const GLvoid
*indices
, GLint basevertex
)
1812 vbo_exec_DrawElementsBaseVertex(mode
, count
, type
, indices
, basevertex
);
1817 _mesa_DrawRangeElements(GLenum mode
, GLuint start
, GLuint end
, GLsizei count
,
1818 GLenum type
, const GLvoid
*indices
)
1820 vbo_exec_DrawRangeElements(mode
, start
, end
, count
, type
, indices
);
1825 _mesa_DrawRangeElementsBaseVertex(GLenum mode
, GLuint start
, GLuint end
,
1826 GLsizei count
, GLenum type
,
1827 const GLvoid
*indices
, GLint basevertex
)
1829 vbo_exec_DrawRangeElementsBaseVertex(mode
, start
, end
, count
, type
,
1830 indices
, basevertex
);
1835 _mesa_MultiDrawElementsEXT(GLenum mode
, const GLsizei
*count
, GLenum type
,
1836 const GLvoid
**indices
, GLsizei primcount
)
1838 vbo_exec_MultiDrawElements(mode
, count
, type
, indices
, primcount
);
1843 _mesa_MultiDrawElementsBaseVertex(GLenum mode
,
1844 const GLsizei
*count
, GLenum type
,
1845 const GLvoid
**indices
, GLsizei primcount
,
1846 const GLint
*basevertex
)
1848 vbo_exec_MultiDrawElementsBaseVertex(mode
, count
, type
, indices
,
1849 primcount
, basevertex
);
1853 _mesa_DrawTransformFeedback(GLenum mode
, GLuint name
)
1855 vbo_exec_DrawTransformFeedback(mode
, name
);