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 **************************************************************************/
29 #include "main/glheader.h"
30 #include "main/context.h"
31 #include "main/state.h"
32 #include "main/api_validate.h"
33 #include "main/dispatch.h"
34 #include "main/varray.h"
35 #include "main/bufferobj.h"
36 #include "main/enums.h"
37 #include "main/macros.h"
38 #include "main/transformfeedback.h"
39 #include "main/sse_minmax.h"
40 #include "x86/common_x86_asm.h"
42 #include "vbo_context.h"
46 * All vertex buffers should be in an unmapped state when we're about
47 * to draw. This debug function checks that.
50 check_buffers_are_unmapped(const struct gl_client_array
**inputs
)
55 for (i
= 0; i
< VERT_ATTRIB_MAX
; i
++) {
57 struct gl_buffer_object
*obj
= inputs
[i
]->BufferObj
;
58 assert(!_mesa_check_disallowed_mapping(obj
));
67 * A debug function that may be called from other parts of Mesa as
68 * needed during debugging.
71 vbo_check_buffers_are_unmapped(struct gl_context
*ctx
)
73 struct vbo_context
*vbo
= vbo_context(ctx
);
74 struct vbo_exec_context
*exec
= &vbo
->exec
;
75 /* check the current vertex arrays */
76 check_buffers_are_unmapped(exec
->array
.inputs
);
77 /* check the current glBegin/glVertex/glEnd-style VBO */
78 assert(!_mesa_check_disallowed_mapping(exec
->vtx
.bufferobj
));
84 * Compute min and max elements by scanning the index buffer for
85 * glDraw[Range]Elements() calls.
86 * If primitive restart is enabled, we need to ignore restart
87 * indexes when computing min/max.
90 vbo_get_minmax_index(struct gl_context
*ctx
,
91 const struct _mesa_prim
*prim
,
92 const struct _mesa_index_buffer
*ib
,
93 GLuint
*min_index
, GLuint
*max_index
,
96 const GLboolean restart
= ctx
->Array
._PrimitiveRestart
;
97 const GLuint restartIndex
= _mesa_primitive_restart_index(ctx
, ib
->type
);
98 const int index_size
= vbo_sizeof_ib_type(ib
->type
);
102 indices
= (char *) ib
->ptr
+ prim
->start
* index_size
;
103 if (_mesa_is_bufferobj(ib
->obj
)) {
104 GLsizeiptr size
= MIN2(count
* index_size
, ib
->obj
->Size
);
105 indices
= ctx
->Driver
.MapBufferRange(ctx
, (GLintptr
) indices
, size
,
106 GL_MAP_READ_BIT
, ib
->obj
,
111 case GL_UNSIGNED_INT
: {
112 const GLuint
*ui_indices
= (const GLuint
*)indices
;
116 for (i
= 0; i
< count
; i
++) {
117 if (ui_indices
[i
] != restartIndex
) {
118 if (ui_indices
[i
] > max_ui
) max_ui
= ui_indices
[i
];
119 if (ui_indices
[i
] < min_ui
) min_ui
= ui_indices
[i
];
124 #if defined(USE_SSE41)
125 if (cpu_has_sse4_1
) {
126 _mesa_uint_array_min_max(ui_indices
, &min_ui
, &max_ui
, count
);
130 for (i
= 0; i
< count
; i
++) {
131 if (ui_indices
[i
] > max_ui
) max_ui
= ui_indices
[i
];
132 if (ui_indices
[i
] < min_ui
) min_ui
= ui_indices
[i
];
139 case GL_UNSIGNED_SHORT
: {
140 const GLushort
*us_indices
= (const GLushort
*)indices
;
144 for (i
= 0; i
< count
; i
++) {
145 if (us_indices
[i
] != restartIndex
) {
146 if (us_indices
[i
] > max_us
) max_us
= us_indices
[i
];
147 if (us_indices
[i
] < min_us
) min_us
= us_indices
[i
];
152 for (i
= 0; i
< count
; i
++) {
153 if (us_indices
[i
] > max_us
) max_us
= us_indices
[i
];
154 if (us_indices
[i
] < min_us
) min_us
= us_indices
[i
];
161 case GL_UNSIGNED_BYTE
: {
162 const GLubyte
*ub_indices
= (const GLubyte
*)indices
;
166 for (i
= 0; i
< count
; i
++) {
167 if (ub_indices
[i
] != restartIndex
) {
168 if (ub_indices
[i
] > max_ub
) max_ub
= ub_indices
[i
];
169 if (ub_indices
[i
] < min_ub
) min_ub
= ub_indices
[i
];
174 for (i
= 0; i
< count
; i
++) {
175 if (ub_indices
[i
] > max_ub
) max_ub
= ub_indices
[i
];
176 if (ub_indices
[i
] < min_ub
) min_ub
= ub_indices
[i
];
188 if (_mesa_is_bufferobj(ib
->obj
)) {
189 ctx
->Driver
.UnmapBuffer(ctx
, ib
->obj
, MAP_INTERNAL
);
194 * Compute min and max elements for nr_prims
197 vbo_get_minmax_indices(struct gl_context
*ctx
,
198 const struct _mesa_prim
*prims
,
199 const struct _mesa_index_buffer
*ib
,
204 GLuint tmp_min
, tmp_max
;
211 for (i
= 0; i
< nr_prims
; i
++) {
212 const struct _mesa_prim
*start_prim
;
214 start_prim
= &prims
[i
];
215 count
= start_prim
->count
;
216 /* Do combination if possible to reduce map/unmap count */
217 while ((i
+ 1 < nr_prims
) &&
218 (prims
[i
].start
+ prims
[i
].count
== prims
[i
+1].start
)) {
219 count
+= prims
[i
+1].count
;
222 vbo_get_minmax_index(ctx
, start_prim
, ib
, &tmp_min
, &tmp_max
, count
);
223 *min_index
= MIN2(*min_index
, tmp_min
);
224 *max_index
= MAX2(*max_index
, tmp_max
);
230 * Check that element 'j' of the array has reasonable data.
232 * For debugging purposes; not normally used.
235 check_array_data(struct gl_context
*ctx
, struct gl_client_array
*array
,
236 GLuint attrib
, GLuint j
)
238 if (array
->Enabled
) {
239 const void *data
= array
->Ptr
;
240 if (_mesa_is_bufferobj(array
->BufferObj
)) {
241 if (!array
->BufferObj
->Mappings
[MAP_INTERNAL
].Pointer
) {
242 /* need to map now */
243 array
->BufferObj
->Mappings
[MAP_INTERNAL
].Pointer
=
244 ctx
->Driver
.MapBufferRange(ctx
, 0, array
->BufferObj
->Size
,
245 GL_MAP_READ_BIT
, array
->BufferObj
,
248 data
= ADD_POINTERS(data
,
249 array
->BufferObj
->Mappings
[MAP_INTERNAL
].Pointer
);
251 switch (array
->Type
) {
254 GLfloat
*f
= (GLfloat
*) ((GLubyte
*) data
+ array
->StrideB
* j
);
256 for (k
= 0; k
< array
->Size
; k
++) {
257 if (IS_INF_OR_NAN(f
[k
]) ||
258 f
[k
] >= 1.0e20
|| f
[k
] <= -1.0e10
) {
259 printf("Bad array data:\n");
260 printf(" Element[%u].%u = %f\n", j
, k
, f
[k
]);
261 printf(" Array %u at %p\n", attrib
, (void* ) array
);
262 printf(" Type 0x%x, Size %d, Stride %d\n",
263 array
->Type
, array
->Size
, array
->Stride
);
264 printf(" Address/offset %p in Buffer Object %u\n",
265 array
->Ptr
, array
->BufferObj
->Name
);
266 f
[k
] = 1.0; /* XXX replace the bad value! */
268 /*assert(!IS_INF_OR_NAN(f[k]));*/
280 * Unmap the buffer object referenced by given array, if mapped.
283 unmap_array_buffer(struct gl_context
*ctx
, struct gl_client_array
*array
)
285 if (array
->Enabled
&&
286 _mesa_is_bufferobj(array
->BufferObj
) &&
287 _mesa_bufferobj_mapped(array
->BufferObj
, MAP_INTERNAL
)) {
288 ctx
->Driver
.UnmapBuffer(ctx
, array
->BufferObj
, MAP_INTERNAL
);
294 * Examine the array's data for NaNs, etc.
295 * For debug purposes; not normally used.
298 check_draw_elements_data(struct gl_context
*ctx
, GLsizei count
, GLenum elemType
,
299 const void *elements
, GLint basevertex
)
301 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
305 if (_mesa_is_bufferobj(ctx
->Array
.VAO
->IndexBufferObj
)) {
306 elemMap
= ctx
->Driver
.MapBufferRange(ctx
, 0,
307 ctx
->Array
.VAO
->IndexBufferObj
->Size
,
309 ctx
->Array
.VAO
->IndexBufferObj
,
311 elements
= ADD_POINTERS(elements
, elemMap
);
314 for (i
= 0; i
< count
; i
++) {
319 case GL_UNSIGNED_BYTE
:
320 j
= ((const GLubyte
*) elements
)[i
];
322 case GL_UNSIGNED_SHORT
:
323 j
= ((const GLushort
*) elements
)[i
];
325 case GL_UNSIGNED_INT
:
326 j
= ((const GLuint
*) elements
)[i
];
332 /* check element j of each enabled array */
333 for (k
= 0; k
< Elements(vao
->_VertexAttrib
); k
++) {
334 check_array_data(ctx
, &vao
->_VertexAttrib
[k
], k
, j
);
338 if (_mesa_is_bufferobj(vao
->IndexBufferObj
)) {
339 ctx
->Driver
.UnmapBuffer(ctx
, ctx
->Array
.VAO
->IndexBufferObj
,
343 for (k
= 0; k
< Elements(vao
->_VertexAttrib
); k
++) {
344 unmap_array_buffer(ctx
, &vao
->_VertexAttrib
[k
]);
350 * Check array data, looking for NaNs, etc.
353 check_draw_arrays_data(struct gl_context
*ctx
, GLint start
, GLsizei count
)
360 * Print info/data for glDrawArrays(), for debugging.
363 print_draw_arrays(struct gl_context
*ctx
,
364 GLenum mode
, GLint start
, GLsizei count
)
366 struct vbo_context
*vbo
= vbo_context(ctx
);
367 struct vbo_exec_context
*exec
= &vbo
->exec
;
368 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
371 printf("vbo_exec_DrawArrays(mode 0x%x, start %d, count %d):\n",
374 for (i
= 0; i
< 32; i
++) {
375 struct gl_buffer_object
*bufObj
= exec
->array
.inputs
[i
]->BufferObj
;
376 GLuint bufName
= bufObj
->Name
;
377 GLint stride
= exec
->array
.inputs
[i
]->Stride
;
378 printf("attr %2d: size %d stride %d enabled %d "
379 "ptr %p Bufobj %u\n",
381 exec
->array
.inputs
[i
]->Size
,
383 /*exec->array.inputs[i]->Enabled,*/
384 vao
->_VertexAttrib
[VERT_ATTRIB_FF(i
)].Enabled
,
385 exec
->array
.inputs
[i
]->Ptr
,
389 GLubyte
*p
= ctx
->Driver
.MapBufferRange(ctx
, 0, bufObj
->Size
,
390 GL_MAP_READ_BIT
, bufObj
,
392 int offset
= (int) (GLintptr
) exec
->array
.inputs
[i
]->Ptr
;
393 float *f
= (float *) (p
+ offset
);
396 int n
= (count
* stride
) / 4;
399 printf(" Data at offset %d:\n", offset
);
400 for (i
= 0; i
< n
; i
++) {
401 printf(" float[%d] = 0x%08x %f\n", i
, k
[i
], f
[i
]);
403 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, MAP_INTERNAL
);
410 * Set the vbo->exec->inputs[] pointers to point to the enabled
411 * vertex arrays. This depends on the current vertex program/shader
412 * being executed because of whether or not generic vertex arrays
413 * alias the conventional vertex arrays.
414 * For arrays that aren't enabled, we set the input[attrib] pointer
415 * to point at a zero-stride current value "array".
418 recalculate_input_bindings(struct gl_context
*ctx
)
420 struct vbo_context
*vbo
= vbo_context(ctx
);
421 struct vbo_exec_context
*exec
= &vbo
->exec
;
422 struct gl_client_array
*vertexAttrib
= ctx
->Array
.VAO
->_VertexAttrib
;
423 const struct gl_client_array
**inputs
= &exec
->array
.inputs
[0];
424 GLbitfield64 const_inputs
= 0x0;
427 switch (get_program_mode(ctx
)) {
429 /* When no vertex program is active (or the vertex program is generated
430 * from fixed-function state). We put the material values into the
431 * generic slots. This is the only situation where material values
432 * are available as per-vertex attributes.
434 for (i
= 0; i
< VERT_ATTRIB_FF_MAX
; i
++) {
435 if (vertexAttrib
[VERT_ATTRIB_FF(i
)].Enabled
)
436 inputs
[i
] = &vertexAttrib
[VERT_ATTRIB_FF(i
)];
438 inputs
[i
] = &vbo
->currval
[VBO_ATTRIB_POS
+i
];
439 const_inputs
|= VERT_BIT(i
);
443 for (i
= 0; i
< MAT_ATTRIB_MAX
; i
++) {
444 inputs
[VERT_ATTRIB_GENERIC(i
)] =
445 &vbo
->currval
[VBO_ATTRIB_MAT_FRONT_AMBIENT
+i
];
446 const_inputs
|= VERT_BIT_GENERIC(i
);
449 /* Could use just about anything, just to fill in the empty
452 for (i
= MAT_ATTRIB_MAX
; i
< VERT_ATTRIB_GENERIC_MAX
; i
++) {
453 inputs
[VERT_ATTRIB_GENERIC(i
)] = &vbo
->currval
[VBO_ATTRIB_GENERIC0
+i
];
454 const_inputs
|= VERT_BIT_GENERIC(i
);
459 /* There are no shaders in OpenGL ES 1.x, so this code path should be
460 * impossible to reach. The meta code is careful to not use shaders in
463 assert(ctx
->API
!= API_OPENGLES
);
465 /* In the compatibility profile of desktop OpenGL, the generic[0]
466 * attribute array aliases and overrides the legacy position array.
467 * Otherwise, legacy attributes available in the legacy slots,
468 * generic attributes in the generic slots and materials are not
469 * available as per-vertex attributes.
471 * In all other APIs, only the generic attributes exist, and none of the
472 * slots are considered "magic."
474 if (ctx
->API
== API_OPENGL_COMPAT
) {
475 if (vertexAttrib
[VERT_ATTRIB_GENERIC0
].Enabled
)
476 inputs
[0] = &vertexAttrib
[VERT_ATTRIB_GENERIC0
];
477 else if (vertexAttrib
[VERT_ATTRIB_POS
].Enabled
)
478 inputs
[0] = &vertexAttrib
[VERT_ATTRIB_POS
];
480 inputs
[0] = &vbo
->currval
[VBO_ATTRIB_POS
];
481 const_inputs
|= VERT_BIT_POS
;
484 for (i
= 1; i
< VERT_ATTRIB_FF_MAX
; i
++) {
485 if (vertexAttrib
[VERT_ATTRIB_FF(i
)].Enabled
)
486 inputs
[i
] = &vertexAttrib
[VERT_ATTRIB_FF(i
)];
488 inputs
[i
] = &vbo
->currval
[VBO_ATTRIB_POS
+i
];
489 const_inputs
|= VERT_BIT_FF(i
);
493 for (i
= 1; i
< VERT_ATTRIB_GENERIC_MAX
; i
++) {
494 if (vertexAttrib
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
495 inputs
[VERT_ATTRIB_GENERIC(i
)] =
496 &vertexAttrib
[VERT_ATTRIB_GENERIC(i
)];
498 inputs
[VERT_ATTRIB_GENERIC(i
)] =
499 &vbo
->currval
[VBO_ATTRIB_GENERIC0
+i
];
500 const_inputs
|= VERT_BIT_GENERIC(i
);
504 inputs
[VERT_ATTRIB_GENERIC0
] = inputs
[0];
506 /* Other parts of the code assume that inputs[0] through
507 * inputs[VERT_ATTRIB_FF_MAX] will be non-NULL. However, in OpenGL
508 * ES 2.0+ or OpenGL core profile, none of these arrays should ever
511 for (i
= 0; i
< VERT_ATTRIB_FF_MAX
; i
++) {
512 assert(!vertexAttrib
[VERT_ATTRIB_FF(i
)].Enabled
);
514 inputs
[i
] = &vbo
->currval
[VBO_ATTRIB_POS
+i
];
515 const_inputs
|= VERT_BIT_FF(i
);
518 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++) {
519 if (vertexAttrib
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
520 inputs
[VERT_ATTRIB_GENERIC(i
)] =
521 &vertexAttrib
[VERT_ATTRIB_GENERIC(i
)];
523 inputs
[VERT_ATTRIB_GENERIC(i
)] =
524 &vbo
->currval
[VBO_ATTRIB_GENERIC0
+i
];
525 const_inputs
|= VERT_BIT_GENERIC(i
);
533 _mesa_set_varying_vp_inputs( ctx
, VERT_BIT_ALL
& (~const_inputs
) );
534 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewArray
;
539 * Examine the enabled vertex arrays to set the exec->array.inputs[] values.
540 * These will point to the arrays to actually use for drawing. Some will
541 * be user-provided arrays, other will be zero-stride const-valued arrays.
542 * Note that this might set the _NEW_VARYING_VP_INPUTS dirty flag so state
543 * validation must be done after this call.
546 vbo_bind_arrays(struct gl_context
*ctx
)
548 struct vbo_context
*vbo
= vbo_context(ctx
);
549 struct vbo_exec_context
*exec
= &vbo
->exec
;
551 vbo_draw_method(vbo
, DRAW_ARRAYS
);
553 if (exec
->array
.recalculate_inputs
) {
554 recalculate_input_bindings(ctx
);
555 exec
->array
.recalculate_inputs
= GL_FALSE
;
557 /* Again... because we may have changed the bitmask of per-vertex varying
558 * attributes. If we regenerate the fixed-function vertex program now
559 * we may be able to prune down the number of vertex attributes which we
560 * need in the shader.
563 /* Setting "validating" to TRUE prevents _mesa_update_state from
564 * invalidating what we just did.
566 exec
->validating
= GL_TRUE
;
567 _mesa_update_state(ctx
);
568 exec
->validating
= GL_FALSE
;
574 * Helper function called by the other DrawArrays() functions below.
575 * This is where we handle primitive restart for drawing non-indexed
576 * arrays. If primitive restart is enabled, it typically means
577 * splitting one DrawArrays() into two.
580 vbo_draw_arrays(struct gl_context
*ctx
, GLenum mode
, GLint start
,
581 GLsizei count
, GLuint numInstances
, GLuint baseInstance
)
583 struct vbo_context
*vbo
= vbo_context(ctx
);
584 struct vbo_exec_context
*exec
= &vbo
->exec
;
585 struct _mesa_prim prim
[2];
587 vbo_bind_arrays(ctx
);
589 /* init most fields to zero */
590 memset(prim
, 0, sizeof(prim
));
594 prim
[0].num_instances
= numInstances
;
595 prim
[0].base_instance
= baseInstance
;
596 prim
[0].is_indirect
= 0;
598 /* Implement the primitive restart index */
599 if (ctx
->Array
.PrimitiveRestart
&& ctx
->Array
.RestartIndex
< count
) {
600 GLuint primCount
= 0;
602 if (ctx
->Array
.RestartIndex
== start
) {
603 /* special case: RestartIndex at beginning */
605 prim
[0].start
= start
+ 1;
606 prim
[0].count
= count
- 1;
610 else if (ctx
->Array
.RestartIndex
== start
+ count
- 1) {
611 /* special case: RestartIndex at end */
613 prim
[0].start
= start
;
614 prim
[0].count
= count
- 1;
619 /* general case: RestartIndex in middle, split into two prims */
620 prim
[0].start
= start
;
621 prim
[0].count
= ctx
->Array
.RestartIndex
- start
;
624 prim
[1].start
= ctx
->Array
.RestartIndex
+ 1;
625 prim
[1].count
= count
- prim
[1].start
;
631 /* draw one or two prims */
632 check_buffers_are_unmapped(exec
->array
.inputs
);
633 vbo
->draw_prims(ctx
, prim
, primCount
, NULL
,
634 GL_TRUE
, start
, start
+ count
- 1, NULL
, NULL
);
638 /* no prim restart */
639 prim
[0].start
= start
;
640 prim
[0].count
= count
;
642 check_buffers_are_unmapped(exec
->array
.inputs
);
643 vbo
->draw_prims(ctx
, prim
, 1, NULL
,
644 GL_TRUE
, start
, start
+ count
- 1,
648 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
) {
655 * Execute a glRectf() function.
657 static void GLAPIENTRY
658 vbo_exec_Rectf(GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
)
660 GET_CURRENT_CONTEXT(ctx
);
661 ASSERT_OUTSIDE_BEGIN_END(ctx
);
663 CALL_Begin(GET_DISPATCH(), (GL_QUADS
));
664 CALL_Vertex2f(GET_DISPATCH(), (x1
, y1
));
665 CALL_Vertex2f(GET_DISPATCH(), (x2
, y1
));
666 CALL_Vertex2f(GET_DISPATCH(), (x2
, y2
));
667 CALL_Vertex2f(GET_DISPATCH(), (x1
, y2
));
668 CALL_End(GET_DISPATCH(), ());
672 static void GLAPIENTRY
673 vbo_exec_EvalMesh1(GLenum mode
, GLint i1
, GLint i2
)
675 GET_CURRENT_CONTEXT(ctx
);
685 prim
= GL_LINE_STRIP
;
688 _mesa_error( ctx
, GL_INVALID_ENUM
, "glEvalMesh1(mode)" );
692 /* No effect if vertex maps disabled.
694 if (!ctx
->Eval
.Map1Vertex4
&&
695 !ctx
->Eval
.Map1Vertex3
)
698 du
= ctx
->Eval
.MapGrid1du
;
699 u
= ctx
->Eval
.MapGrid1u1
+ i1
* du
;
701 CALL_Begin(GET_DISPATCH(), (prim
));
702 for (i
=i1
;i
<=i2
;i
++,u
+=du
) {
703 CALL_EvalCoord1f(GET_DISPATCH(), (u
));
705 CALL_End(GET_DISPATCH(), ());
709 static void GLAPIENTRY
710 vbo_exec_EvalMesh2(GLenum mode
, GLint i1
, GLint i2
, GLint j1
, GLint j2
)
712 GET_CURRENT_CONTEXT(ctx
);
713 GLfloat u
, du
, v
, dv
, v1
, u1
;
722 _mesa_error( ctx
, GL_INVALID_ENUM
, "glEvalMesh2(mode)" );
726 /* No effect if vertex maps disabled.
728 if (!ctx
->Eval
.Map2Vertex4
&&
729 !ctx
->Eval
.Map2Vertex3
)
732 du
= ctx
->Eval
.MapGrid2du
;
733 dv
= ctx
->Eval
.MapGrid2dv
;
734 v1
= ctx
->Eval
.MapGrid2v1
+ j1
* dv
;
735 u1
= ctx
->Eval
.MapGrid2u1
+ i1
* du
;
739 CALL_Begin(GET_DISPATCH(), (GL_POINTS
));
740 for (v
=v1
,j
=j1
;j
<=j2
;j
++,v
+=dv
) {
741 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
742 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
745 CALL_End(GET_DISPATCH(), ());
748 for (v
=v1
,j
=j1
;j
<=j2
;j
++,v
+=dv
) {
749 CALL_Begin(GET_DISPATCH(), (GL_LINE_STRIP
));
750 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
751 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
753 CALL_End(GET_DISPATCH(), ());
755 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
756 CALL_Begin(GET_DISPATCH(), (GL_LINE_STRIP
));
757 for (v
=v1
,j
=j1
;j
<=j2
;j
++,v
+=dv
) {
758 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
760 CALL_End(GET_DISPATCH(), ());
764 for (v
=v1
,j
=j1
;j
<j2
;j
++,v
+=dv
) {
765 CALL_Begin(GET_DISPATCH(), (GL_TRIANGLE_STRIP
));
766 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
767 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
768 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
+dv
));
770 CALL_End(GET_DISPATCH(), ());
778 * Called from glDrawArrays when in immediate mode (not display list mode).
780 static void GLAPIENTRY
781 vbo_exec_DrawArrays(GLenum mode
, GLint start
, GLsizei count
)
783 GET_CURRENT_CONTEXT(ctx
);
785 if (MESA_VERBOSE
& VERBOSE_DRAW
)
786 _mesa_debug(ctx
, "glDrawArrays(%s, %d, %d)\n",
787 _mesa_lookup_enum_by_nr(mode
), start
, count
);
789 if (!_mesa_validate_DrawArrays( ctx
, mode
, start
, count
))
793 check_draw_arrays_data(ctx
, start
, count
);
795 vbo_draw_arrays(ctx
, mode
, start
, count
, 1, 0);
798 print_draw_arrays(ctx
, mode
, start
, count
);
803 * Called from glDrawArraysInstanced when in immediate mode (not
804 * display list mode).
806 static void GLAPIENTRY
807 vbo_exec_DrawArraysInstanced(GLenum mode
, GLint start
, GLsizei count
,
808 GLsizei numInstances
)
810 GET_CURRENT_CONTEXT(ctx
);
812 if (MESA_VERBOSE
& VERBOSE_DRAW
)
813 _mesa_debug(ctx
, "glDrawArraysInstanced(%s, %d, %d, %d)\n",
814 _mesa_lookup_enum_by_nr(mode
), start
, count
, numInstances
);
816 if (!_mesa_validate_DrawArraysInstanced(ctx
, mode
, start
, count
, numInstances
))
820 check_draw_arrays_data(ctx
, start
, count
);
822 vbo_draw_arrays(ctx
, mode
, start
, count
, numInstances
, 0);
825 print_draw_arrays(ctx
, mode
, start
, count
);
830 * Called from glDrawArraysInstancedBaseInstance when in immediate mode.
832 static void GLAPIENTRY
833 vbo_exec_DrawArraysInstancedBaseInstance(GLenum mode
, GLint first
, GLsizei count
,
834 GLsizei numInstances
, GLuint baseInstance
)
836 GET_CURRENT_CONTEXT(ctx
);
838 if (MESA_VERBOSE
& VERBOSE_DRAW
)
839 _mesa_debug(ctx
, "glDrawArraysInstancedBaseInstance(%s, %d, %d, %d, %d)\n",
840 _mesa_lookup_enum_by_nr(mode
), first
, count
,
841 numInstances
, baseInstance
);
843 if (!_mesa_validate_DrawArraysInstanced(ctx
, mode
, first
, count
,
848 check_draw_arrays_data(ctx
, first
, count
);
850 vbo_draw_arrays(ctx
, mode
, first
, count
, numInstances
, baseInstance
);
853 print_draw_arrays(ctx
, mode
, first
, count
);
859 * Map GL_ELEMENT_ARRAY_BUFFER and print contents.
864 dump_element_buffer(struct gl_context
*ctx
, GLenum type
)
867 ctx
->Driver
.MapBufferRange(ctx
, 0,
868 ctx
->Array
.VAO
->IndexBufferObj
->Size
,
870 ctx
->Array
.VAO
->IndexBufferObj
,
873 case GL_UNSIGNED_BYTE
:
875 const GLubyte
*us
= (const GLubyte
*) map
;
877 for (i
= 0; i
< ctx
->Array
.VAO
->IndexBufferObj
->Size
; i
++) {
878 printf("%02x ", us
[i
]);
885 case GL_UNSIGNED_SHORT
:
887 const GLushort
*us
= (const GLushort
*) map
;
889 for (i
= 0; i
< ctx
->Array
.VAO
->IndexBufferObj
->Size
/ 2; i
++) {
890 printf("%04x ", us
[i
]);
897 case GL_UNSIGNED_INT
:
899 const GLuint
*us
= (const GLuint
*) map
;
901 for (i
= 0; i
< ctx
->Array
.VAO
->IndexBufferObj
->Size
/ 4; i
++) {
902 printf("%08x ", us
[i
]);
913 ctx
->Driver
.UnmapBuffer(ctx
, ctx
->Array
.VAO
->IndexBufferObj
,
920 * Inner support for both _mesa_DrawElements and _mesa_DrawRangeElements.
921 * Do the rendering for a glDrawElements or glDrawRangeElements call after
922 * we've validated buffer bounds, etc.
925 vbo_validated_drawrangeelements(struct gl_context
*ctx
, GLenum mode
,
926 GLboolean index_bounds_valid
,
927 GLuint start
, GLuint end
,
928 GLsizei count
, GLenum type
,
929 const GLvoid
*indices
,
930 GLint basevertex
, GLuint numInstances
,
933 struct vbo_context
*vbo
= vbo_context(ctx
);
934 struct vbo_exec_context
*exec
= &vbo
->exec
;
935 struct _mesa_index_buffer ib
;
936 struct _mesa_prim prim
[1];
938 vbo_bind_arrays(ctx
);
942 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
951 prim
[0].count
= count
;
953 prim
[0].is_indirect
= 0;
954 prim
[0].basevertex
= basevertex
;
955 prim
[0].num_instances
= numInstances
;
956 prim
[0].base_instance
= baseInstance
;
958 /* Need to give special consideration to rendering a range of
959 * indices starting somewhere above zero. Typically the
960 * application is issuing multiple DrawRangeElements() to draw
961 * successive primitives layed out linearly in the vertex arrays.
962 * Unless the vertex arrays are all in a VBO (or locked as with
963 * CVA), the OpenGL semantics imply that we need to re-read or
964 * re-upload the vertex data on each draw call.
966 * In the case of hardware tnl, we want to avoid starting the
967 * upload at zero, as it will mean every draw call uploads an
968 * increasing amount of not-used vertex data. Worse - in the
969 * software tnl module, all those vertices might be transformed and
970 * lit but never rendered.
972 * If we just upload or transform the vertices in start..end,
973 * however, the indices will be incorrect.
975 * At this level, we don't know exactly what the requirements of
976 * the backend are going to be, though it will likely boil down to
979 * 1) Do nothing, everything is in a VBO and is processed once
982 * 2) Adjust the indices and vertex arrays so that start becomes
985 * Rather than doing anything here, I'll provide a helper function
986 * for the latter case elsewhere.
989 check_buffers_are_unmapped(exec
->array
.inputs
);
990 vbo
->draw_prims(ctx
, prim
, 1, &ib
,
991 index_bounds_valid
, start
, end
, NULL
, NULL
);
993 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
) {
1000 * Called by glDrawRangeElementsBaseVertex() in immediate mode.
1002 static void GLAPIENTRY
1003 vbo_exec_DrawRangeElementsBaseVertex(GLenum mode
,
1004 GLuint start
, GLuint end
,
1005 GLsizei count
, GLenum type
,
1006 const GLvoid
*indices
,
1009 static GLuint warnCount
= 0;
1010 GLboolean index_bounds_valid
= GL_TRUE
;
1012 /* This is only useful to catch invalid values in the "end" parameter
1015 GLuint max_element
= 2 * 1000 * 1000 * 1000; /* just a big number */
1017 GET_CURRENT_CONTEXT(ctx
);
1019 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1021 "glDrawRangeElementsBaseVertex(%s, %u, %u, %d, %s, %p, %d)\n",
1022 _mesa_lookup_enum_by_nr(mode
), start
, end
, count
,
1023 _mesa_lookup_enum_by_nr(type
), indices
, basevertex
);
1025 if (!_mesa_validate_DrawRangeElements( ctx
, mode
, start
, end
, count
,
1026 type
, indices
, basevertex
))
1029 if ((int) end
+ basevertex
< 0 ||
1030 start
+ basevertex
>= max_element
) {
1031 /* The application requested we draw using a range of indices that's
1032 * outside the bounds of the current VBO. This is invalid and appears
1033 * to give undefined results. The safest thing to do is to simply
1034 * ignore the range, in case the application botched their range tracking
1035 * but did provide valid indices. Also issue a warning indicating that
1036 * the application is broken.
1038 if (warnCount
++ < 10) {
1039 _mesa_warning(ctx
, "glDrawRangeElements(start %u, end %u, "
1040 "basevertex %d, count %d, type 0x%x, indices=%p):\n"
1041 "\trange is outside VBO bounds (max=%u); ignoring.\n"
1042 "\tThis should be fixed in the application.",
1043 start
, end
, basevertex
, count
, type
, indices
,
1046 index_bounds_valid
= GL_FALSE
;
1049 /* NOTE: It's important that 'end' is a reasonable value.
1050 * in _tnl_draw_prims(), we use end to determine how many vertices
1051 * to transform. If it's too large, we can unnecessarily split prims
1052 * or we can read/write out of memory in several different places!
1055 /* Catch/fix some potential user errors */
1056 if (type
== GL_UNSIGNED_BYTE
) {
1057 start
= MIN2(start
, 0xff);
1058 end
= MIN2(end
, 0xff);
1060 else if (type
== GL_UNSIGNED_SHORT
) {
1061 start
= MIN2(start
, 0xffff);
1062 end
= MIN2(end
, 0xffff);
1066 printf("glDraw[Range]Elements{,BaseVertex}"
1067 "(start %u, end %u, type 0x%x, count %d) ElemBuf %u, "
1069 start
, end
, type
, count
,
1070 ctx
->Array
.VAO
->IndexBufferObj
->Name
,
1074 if ((int) start
+ basevertex
< 0 ||
1075 end
+ basevertex
>= max_element
)
1076 index_bounds_valid
= GL_FALSE
;
1079 check_draw_elements_data(ctx
, count
, type
, indices
);
1081 (void) check_draw_elements_data
;
1084 vbo_validated_drawrangeelements(ctx
, mode
, index_bounds_valid
, start
, end
,
1085 count
, type
, indices
, basevertex
, 1, 0);
1090 * Called by glDrawRangeElements() in immediate mode.
1092 static void GLAPIENTRY
1093 vbo_exec_DrawRangeElements(GLenum mode
, GLuint start
, GLuint end
,
1094 GLsizei count
, GLenum type
, const GLvoid
*indices
)
1096 if (MESA_VERBOSE
& VERBOSE_DRAW
) {
1097 GET_CURRENT_CONTEXT(ctx
);
1099 "glDrawRangeElements(%s, %u, %u, %d, %s, %p)\n",
1100 _mesa_lookup_enum_by_nr(mode
), start
, end
, count
,
1101 _mesa_lookup_enum_by_nr(type
), indices
);
1104 vbo_exec_DrawRangeElementsBaseVertex(mode
, start
, end
, count
, type
,
1110 * Called by glDrawElements() in immediate mode.
1112 static void GLAPIENTRY
1113 vbo_exec_DrawElements(GLenum mode
, GLsizei count
, GLenum type
,
1114 const GLvoid
*indices
)
1116 GET_CURRENT_CONTEXT(ctx
);
1118 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1119 _mesa_debug(ctx
, "glDrawElements(%s, %u, %s, %p)\n",
1120 _mesa_lookup_enum_by_nr(mode
), count
,
1121 _mesa_lookup_enum_by_nr(type
), indices
);
1123 if (!_mesa_validate_DrawElements( ctx
, mode
, count
, type
, indices
, 0 ))
1126 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1127 count
, type
, indices
, 0, 1, 0);
1132 * Called by glDrawElementsBaseVertex() in immediate mode.
1134 static void GLAPIENTRY
1135 vbo_exec_DrawElementsBaseVertex(GLenum mode
, GLsizei count
, GLenum type
,
1136 const GLvoid
*indices
, GLint basevertex
)
1138 GET_CURRENT_CONTEXT(ctx
);
1140 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1141 _mesa_debug(ctx
, "glDrawElementsBaseVertex(%s, %d, %s, %p, %d)\n",
1142 _mesa_lookup_enum_by_nr(mode
), count
,
1143 _mesa_lookup_enum_by_nr(type
), indices
, basevertex
);
1145 if (!_mesa_validate_DrawElements( ctx
, mode
, count
, type
, indices
,
1149 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1150 count
, type
, indices
, basevertex
, 1, 0);
1155 * Called by glDrawElementsInstanced() in immediate mode.
1157 static void GLAPIENTRY
1158 vbo_exec_DrawElementsInstanced(GLenum mode
, GLsizei count
, GLenum type
,
1159 const GLvoid
*indices
, GLsizei numInstances
)
1161 GET_CURRENT_CONTEXT(ctx
);
1163 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1164 _mesa_debug(ctx
, "glDrawElementsInstanced(%s, %d, %s, %p, %d)\n",
1165 _mesa_lookup_enum_by_nr(mode
), count
,
1166 _mesa_lookup_enum_by_nr(type
), indices
, numInstances
);
1168 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
1172 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1173 count
, type
, indices
, 0, numInstances
, 0);
1178 * Called by glDrawElementsInstancedBaseVertex() in immediate mode.
1180 static void GLAPIENTRY
1181 vbo_exec_DrawElementsInstancedBaseVertex(GLenum mode
, GLsizei count
, GLenum type
,
1182 const GLvoid
*indices
, GLsizei numInstances
,
1185 GET_CURRENT_CONTEXT(ctx
);
1187 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1188 _mesa_debug(ctx
, "glDrawElementsInstancedBaseVertex(%s, %d, %s, %p, %d; %d)\n",
1189 _mesa_lookup_enum_by_nr(mode
), count
,
1190 _mesa_lookup_enum_by_nr(type
), indices
,
1191 numInstances
, basevertex
);
1193 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
1194 numInstances
, basevertex
))
1197 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1198 count
, type
, indices
, basevertex
, numInstances
, 0);
1203 * Called by glDrawElementsInstancedBaseInstance() in immediate mode.
1205 static void GLAPIENTRY
1206 vbo_exec_DrawElementsInstancedBaseInstance(GLenum mode
, GLsizei count
, GLenum type
,
1207 const GLvoid
*indices
, GLsizei numInstances
,
1208 GLuint baseInstance
)
1210 GET_CURRENT_CONTEXT(ctx
);
1212 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1213 _mesa_debug(ctx
, "glDrawElementsInstancedBaseInstance(%s, %d, %s, %p, %d, %d)\n",
1214 _mesa_lookup_enum_by_nr(mode
), count
,
1215 _mesa_lookup_enum_by_nr(type
), indices
,
1216 numInstances
, baseInstance
);
1218 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
1222 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1223 count
, type
, indices
, 0, numInstances
,
1229 * Called by glDrawElementsInstancedBaseVertexBaseInstance() in immediate mode.
1231 static void GLAPIENTRY
1232 vbo_exec_DrawElementsInstancedBaseVertexBaseInstance(GLenum mode
, GLsizei count
, GLenum type
,
1233 const GLvoid
*indices
, GLsizei numInstances
,
1234 GLint basevertex
, GLuint baseInstance
)
1236 GET_CURRENT_CONTEXT(ctx
);
1238 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1239 _mesa_debug(ctx
, "glDrawElementsInstancedBaseVertexBaseInstance(%s, %d, %s, %p, %d, %d, %d)\n",
1240 _mesa_lookup_enum_by_nr(mode
), count
,
1241 _mesa_lookup_enum_by_nr(type
), indices
,
1242 numInstances
, basevertex
, baseInstance
);
1244 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
1245 numInstances
, basevertex
))
1248 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1249 count
, type
, indices
, basevertex
, numInstances
,
1255 * Inner support for both _mesa_MultiDrawElements() and
1256 * _mesa_MultiDrawRangeElements().
1257 * This does the actual rendering after we've checked array indexes, etc.
1260 vbo_validated_multidrawelements(struct gl_context
*ctx
, GLenum mode
,
1261 const GLsizei
*count
, GLenum type
,
1262 const GLvoid
* const *indices
,
1264 const GLint
*basevertex
)
1266 struct vbo_context
*vbo
= vbo_context(ctx
);
1267 struct vbo_exec_context
*exec
= &vbo
->exec
;
1268 struct _mesa_index_buffer ib
;
1269 struct _mesa_prim
*prim
;
1270 unsigned int index_type_size
= vbo_sizeof_ib_type(type
);
1271 uintptr_t min_index_ptr
, max_index_ptr
;
1272 GLboolean fallback
= GL_FALSE
;
1278 prim
= calloc(primcount
, sizeof(*prim
));
1280 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMultiDrawElements");
1284 vbo_bind_arrays(ctx
);
1286 min_index_ptr
= (uintptr_t)indices
[0];
1288 for (i
= 0; i
< primcount
; i
++) {
1289 min_index_ptr
= MIN2(min_index_ptr
, (uintptr_t)indices
[i
]);
1290 max_index_ptr
= MAX2(max_index_ptr
, (uintptr_t)indices
[i
] +
1291 index_type_size
* count
[i
]);
1294 /* Check if we can handle this thing as a bunch of index offsets from the
1295 * same index pointer. If we can't, then we have to fall back to doing
1296 * a draw_prims per primitive.
1297 * Check that the difference between each prim's indexes is a multiple of
1298 * the index/element size.
1300 if (index_type_size
!= 1) {
1301 for (i
= 0; i
< primcount
; i
++) {
1302 if ((((uintptr_t)indices
[i
] - min_index_ptr
) % index_type_size
) != 0) {
1309 /* Draw primitives individually if one count is zero, so we can easily skip
1312 for (i
= 0; i
< primcount
; i
++) {
1313 if (count
[i
] == 0) {
1319 /* If the index buffer isn't in a VBO, then treating the application's
1320 * subranges of the index buffer as one large index buffer may lead to
1321 * us reading unmapped memory.
1323 if (!_mesa_is_bufferobj(ctx
->Array
.VAO
->IndexBufferObj
))
1327 ib
.count
= (max_index_ptr
- min_index_ptr
) / index_type_size
;
1329 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1330 ib
.ptr
= (void *)min_index_ptr
;
1332 for (i
= 0; i
< primcount
; i
++) {
1333 prim
[i
].begin
= (i
== 0);
1334 prim
[i
].end
= (i
== primcount
- 1);
1337 prim
[i
].mode
= mode
;
1338 prim
[i
].start
= ((uintptr_t)indices
[i
] - min_index_ptr
) / index_type_size
;
1339 prim
[i
].count
= count
[i
];
1340 prim
[i
].indexed
= 1;
1341 prim
[i
].num_instances
= 1;
1342 prim
[i
].base_instance
= 0;
1343 prim
[i
].is_indirect
= 0;
1344 if (basevertex
!= NULL
)
1345 prim
[i
].basevertex
= basevertex
[i
];
1347 prim
[i
].basevertex
= 0;
1350 check_buffers_are_unmapped(exec
->array
.inputs
);
1351 vbo
->draw_prims(ctx
, prim
, primcount
, &ib
,
1352 false, ~0, ~0, NULL
, NULL
);
1354 /* render one prim at a time */
1355 for (i
= 0; i
< primcount
; i
++) {
1358 ib
.count
= count
[i
];
1360 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1361 ib
.ptr
= indices
[i
];
1367 prim
[0].mode
= mode
;
1369 prim
[0].count
= count
[i
];
1370 prim
[0].indexed
= 1;
1371 prim
[0].num_instances
= 1;
1372 prim
[0].base_instance
= 0;
1373 prim
[0].is_indirect
= 0;
1374 if (basevertex
!= NULL
)
1375 prim
[0].basevertex
= basevertex
[i
];
1377 prim
[0].basevertex
= 0;
1379 check_buffers_are_unmapped(exec
->array
.inputs
);
1380 vbo
->draw_prims(ctx
, prim
, 1, &ib
,
1381 false, ~0, ~0, NULL
, NULL
);
1387 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
) {
1393 static void GLAPIENTRY
1394 vbo_exec_MultiDrawElements(GLenum mode
,
1395 const GLsizei
*count
, GLenum type
,
1396 const GLvoid
* const *indices
,
1399 GET_CURRENT_CONTEXT(ctx
);
1401 if (!_mesa_validate_MultiDrawElements(ctx
, mode
, count
, type
, indices
,
1405 vbo_validated_multidrawelements(ctx
, mode
, count
, type
, indices
, primcount
,
1410 static void GLAPIENTRY
1411 vbo_exec_MultiDrawElementsBaseVertex(GLenum mode
,
1412 const GLsizei
*count
, GLenum type
,
1413 const GLvoid
* const *indices
,
1415 const GLsizei
*basevertex
)
1417 GET_CURRENT_CONTEXT(ctx
);
1419 if (!_mesa_validate_MultiDrawElements(ctx
, mode
, count
, type
, indices
,
1420 primcount
, basevertex
))
1423 vbo_validated_multidrawelements(ctx
, mode
, count
, type
, indices
, primcount
,
1428 vbo_draw_transform_feedback(struct gl_context
*ctx
, GLenum mode
,
1429 struct gl_transform_feedback_object
*obj
,
1430 GLuint stream
, GLuint numInstances
)
1432 struct vbo_context
*vbo
= vbo_context(ctx
);
1433 struct vbo_exec_context
*exec
= &vbo
->exec
;
1434 struct _mesa_prim prim
[2];
1436 if (!_mesa_validate_DrawTransformFeedback(ctx
, mode
, obj
, stream
,
1441 if (ctx
->Driver
.GetTransformFeedbackVertexCount
&&
1442 (ctx
->Const
.AlwaysUseGetTransformFeedbackVertexCount
||
1443 !vbo_all_varyings_in_vbos(exec
->array
.inputs
))) {
1444 GLsizei n
= ctx
->Driver
.GetTransformFeedbackVertexCount(ctx
, obj
, stream
);
1445 vbo_draw_arrays(ctx
, mode
, 0, n
, numInstances
, 0);
1449 vbo_bind_arrays(ctx
);
1451 /* init most fields to zero */
1452 memset(prim
, 0, sizeof(prim
));
1455 prim
[0].mode
= mode
;
1456 prim
[0].num_instances
= numInstances
;
1457 prim
[0].base_instance
= 0;
1458 prim
[0].is_indirect
= 0;
1460 /* Maybe we should do some primitive splitting for primitive restart
1461 * (like in DrawArrays), but we have no way to know how many vertices
1462 * will be rendered. */
1464 check_buffers_are_unmapped(exec
->array
.inputs
);
1465 vbo
->draw_prims(ctx
, prim
, 1, NULL
,
1466 GL_TRUE
, 0, 0, obj
, NULL
);
1468 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
) {
1474 * Like DrawArrays, but take the count from a transform feedback object.
1475 * \param mode GL_POINTS, GL_LINES, GL_TRIANGLE_STRIP, etc.
1476 * \param name the transform feedback object
1477 * User still has to setup of the vertex attribute info with
1478 * glVertexPointer, glColorPointer, etc.
1479 * Part of GL_ARB_transform_feedback2.
1481 static void GLAPIENTRY
1482 vbo_exec_DrawTransformFeedback(GLenum mode
, GLuint name
)
1484 GET_CURRENT_CONTEXT(ctx
);
1485 struct gl_transform_feedback_object
*obj
=
1486 _mesa_lookup_transform_feedback_object(ctx
, name
);
1488 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1489 _mesa_debug(ctx
, "glDrawTransformFeedback(%s, %d)\n",
1490 _mesa_lookup_enum_by_nr(mode
), name
);
1492 vbo_draw_transform_feedback(ctx
, mode
, obj
, 0, 1);
1495 static void GLAPIENTRY
1496 vbo_exec_DrawTransformFeedbackStream(GLenum mode
, GLuint name
, GLuint stream
)
1498 GET_CURRENT_CONTEXT(ctx
);
1499 struct gl_transform_feedback_object
*obj
=
1500 _mesa_lookup_transform_feedback_object(ctx
, name
);
1502 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1503 _mesa_debug(ctx
, "glDrawTransformFeedbackStream(%s, %u, %u)\n",
1504 _mesa_lookup_enum_by_nr(mode
), name
, stream
);
1506 vbo_draw_transform_feedback(ctx
, mode
, obj
, stream
, 1);
1509 static void GLAPIENTRY
1510 vbo_exec_DrawTransformFeedbackInstanced(GLenum mode
, GLuint name
,
1513 GET_CURRENT_CONTEXT(ctx
);
1514 struct gl_transform_feedback_object
*obj
=
1515 _mesa_lookup_transform_feedback_object(ctx
, name
);
1517 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1518 _mesa_debug(ctx
, "glDrawTransformFeedbackInstanced(%s, %d)\n",
1519 _mesa_lookup_enum_by_nr(mode
), name
);
1521 vbo_draw_transform_feedback(ctx
, mode
, obj
, 0, primcount
);
1524 static void GLAPIENTRY
1525 vbo_exec_DrawTransformFeedbackStreamInstanced(GLenum mode
, GLuint name
,
1526 GLuint stream
, GLsizei primcount
)
1528 GET_CURRENT_CONTEXT(ctx
);
1529 struct gl_transform_feedback_object
*obj
=
1530 _mesa_lookup_transform_feedback_object(ctx
, name
);
1532 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1533 _mesa_debug(ctx
, "glDrawTransformFeedbackStreamInstanced"
1534 "(%s, %u, %u, %i)\n",
1535 _mesa_lookup_enum_by_nr(mode
), name
, stream
, primcount
);
1537 vbo_draw_transform_feedback(ctx
, mode
, obj
, stream
, primcount
);
1541 vbo_validated_drawarraysindirect(struct gl_context
*ctx
,
1542 GLenum mode
, const GLvoid
*indirect
)
1544 struct vbo_context
*vbo
= vbo_context(ctx
);
1545 struct vbo_exec_context
*exec
= &vbo
->exec
;
1546 struct _mesa_prim prim
[1];
1548 vbo_bind_arrays(ctx
);
1550 memset(prim
, 0, sizeof(prim
));
1553 prim
[0].mode
= mode
;
1554 prim
[0].is_indirect
= 1;
1555 prim
[0].indirect_offset
= (GLsizeiptr
)indirect
;
1557 /* NOTE: We do NOT want to handle primitive restart here, nor perform any
1558 * other checks that require knowledge of the values in the command buffer.
1559 * That would defeat the whole purpose of this function.
1562 check_buffers_are_unmapped(exec
->array
.inputs
);
1563 vbo
->draw_prims(ctx
, prim
, 1,
1564 NULL
, GL_TRUE
, 0, ~0,
1566 ctx
->DrawIndirectBuffer
);
1568 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1573 vbo_validated_multidrawarraysindirect(struct gl_context
*ctx
,
1575 const GLvoid
*indirect
,
1576 GLsizei primcount
, GLsizei stride
)
1578 struct vbo_context
*vbo
= vbo_context(ctx
);
1579 struct vbo_exec_context
*exec
= &vbo
->exec
;
1580 struct _mesa_prim
*prim
;
1582 GLsizeiptr offset
= (GLsizeiptr
)indirect
;
1586 prim
= calloc(primcount
, sizeof(*prim
));
1588 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMultiDrawArraysIndirect");
1592 vbo_bind_arrays(ctx
);
1595 prim
[primcount
- 1].end
= 1;
1596 for (i
= 0; i
< primcount
; ++i
, offset
+= stride
) {
1597 prim
[i
].mode
= mode
;
1598 prim
[i
].indirect_offset
= offset
;
1599 prim
[i
].is_indirect
= 1;
1602 check_buffers_are_unmapped(exec
->array
.inputs
);
1603 vbo
->draw_prims(ctx
, prim
, primcount
,
1604 NULL
, GL_TRUE
, 0, ~0,
1606 ctx
->DrawIndirectBuffer
);
1610 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1615 vbo_validated_drawelementsindirect(struct gl_context
*ctx
,
1616 GLenum mode
, GLenum type
,
1617 const GLvoid
*indirect
)
1619 struct vbo_context
*vbo
= vbo_context(ctx
);
1620 struct vbo_exec_context
*exec
= &vbo
->exec
;
1621 struct _mesa_index_buffer ib
;
1622 struct _mesa_prim prim
[1];
1624 vbo_bind_arrays(ctx
);
1626 ib
.count
= 0; /* unknown */
1628 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1631 memset(prim
, 0, sizeof(prim
));
1634 prim
[0].mode
= mode
;
1635 prim
[0].indexed
= 1;
1636 prim
[0].indirect_offset
= (GLsizeiptr
)indirect
;
1637 prim
[0].is_indirect
= 1;
1639 check_buffers_are_unmapped(exec
->array
.inputs
);
1640 vbo
->draw_prims(ctx
, prim
, 1,
1641 &ib
, GL_TRUE
, 0, ~0,
1643 ctx
->DrawIndirectBuffer
);
1645 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1650 vbo_validated_multidrawelementsindirect(struct gl_context
*ctx
,
1651 GLenum mode
, GLenum type
,
1652 const GLvoid
*indirect
,
1653 GLsizei primcount
, GLsizei stride
)
1655 struct vbo_context
*vbo
= vbo_context(ctx
);
1656 struct vbo_exec_context
*exec
= &vbo
->exec
;
1657 struct _mesa_index_buffer ib
;
1658 struct _mesa_prim
*prim
;
1660 GLsizeiptr offset
= (GLsizeiptr
)indirect
;
1664 prim
= calloc(primcount
, sizeof(*prim
));
1666 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMultiDrawElementsIndirect");
1670 vbo_bind_arrays(ctx
);
1672 /* NOTE: IndexBufferObj is guaranteed to be a VBO. */
1674 ib
.count
= 0; /* unknown */
1676 ib
.obj
= ctx
->Array
.VAO
->IndexBufferObj
;
1680 prim
[primcount
- 1].end
= 1;
1681 for (i
= 0; i
< primcount
; ++i
, offset
+= stride
) {
1682 prim
[i
].mode
= mode
;
1683 prim
[i
].indexed
= 1;
1684 prim
[i
].indirect_offset
= offset
;
1685 prim
[i
].is_indirect
= 1;
1688 check_buffers_are_unmapped(exec
->array
.inputs
);
1689 vbo
->draw_prims(ctx
, prim
, primcount
,
1690 &ib
, GL_TRUE
, 0, ~0,
1692 ctx
->DrawIndirectBuffer
);
1696 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
)
1701 * Like [Multi]DrawArrays/Elements, but they take most arguments from
1704 static void GLAPIENTRY
1705 vbo_exec_DrawArraysIndirect(GLenum mode
, const GLvoid
*indirect
)
1707 GET_CURRENT_CONTEXT(ctx
);
1709 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1710 _mesa_debug(ctx
, "glDrawArraysIndirect(%s, %p)\n",
1711 _mesa_lookup_enum_by_nr(mode
), indirect
);
1713 if (!_mesa_validate_DrawArraysIndirect(ctx
, mode
, indirect
))
1716 vbo_validated_drawarraysindirect(ctx
, mode
, indirect
);
1719 static void GLAPIENTRY
1720 vbo_exec_DrawElementsIndirect(GLenum mode
, GLenum type
,
1721 const GLvoid
*indirect
)
1723 GET_CURRENT_CONTEXT(ctx
);
1725 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1726 _mesa_debug(ctx
, "glDrawElementsIndirect(%s, %s, %p)\n",
1727 _mesa_lookup_enum_by_nr(mode
),
1728 _mesa_lookup_enum_by_nr(type
), indirect
);
1730 if (!_mesa_validate_DrawElementsIndirect(ctx
, mode
, type
, indirect
))
1733 vbo_validated_drawelementsindirect(ctx
, mode
, type
, indirect
);
1736 static void GLAPIENTRY
1737 vbo_exec_MultiDrawArraysIndirect(GLenum mode
,
1738 const GLvoid
*indirect
,
1739 GLsizei primcount
, GLsizei stride
)
1741 GET_CURRENT_CONTEXT(ctx
);
1743 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1744 _mesa_debug(ctx
, "glMultiDrawArraysIndirect(%s, %p, %i, %i)\n",
1745 _mesa_lookup_enum_by_nr(mode
), indirect
, primcount
, stride
);
1747 /* If <stride> is zero, the array elements are treated as tightly packed. */
1749 stride
= 4 * sizeof(GLuint
); /* sizeof(DrawArraysIndirectCommand) */
1751 if (!_mesa_validate_MultiDrawArraysIndirect(ctx
, mode
,
1756 vbo_validated_multidrawarraysindirect(ctx
, mode
,
1761 static void GLAPIENTRY
1762 vbo_exec_MultiDrawElementsIndirect(GLenum mode
, GLenum type
,
1763 const GLvoid
*indirect
,
1764 GLsizei primcount
, GLsizei stride
)
1766 GET_CURRENT_CONTEXT(ctx
);
1768 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1769 _mesa_debug(ctx
, "glMultiDrawElementsIndirect(%s, %s, %p, %i, %i)\n",
1770 _mesa_lookup_enum_by_nr(mode
),
1771 _mesa_lookup_enum_by_nr(type
), indirect
, primcount
, stride
);
1773 /* If <stride> is zero, the array elements are treated as tightly packed. */
1775 stride
= 5 * sizeof(GLuint
); /* sizeof(DrawElementsIndirectCommand) */
1777 if (!_mesa_validate_MultiDrawElementsIndirect(ctx
, mode
, type
,
1782 vbo_validated_multidrawelementsindirect(ctx
, mode
, type
,
1788 * Initialize the dispatch table with the VBO functions for drawing.
1791 vbo_initialize_exec_dispatch(const struct gl_context
*ctx
,
1792 struct _glapi_table
*exec
)
1794 SET_DrawArrays(exec
, vbo_exec_DrawArrays
);
1795 SET_DrawElements(exec
, vbo_exec_DrawElements
);
1797 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1798 SET_DrawRangeElements(exec
, vbo_exec_DrawRangeElements
);
1801 SET_MultiDrawElementsEXT(exec
, vbo_exec_MultiDrawElements
);
1803 if (ctx
->API
== API_OPENGL_COMPAT
) {
1804 SET_Rectf(exec
, vbo_exec_Rectf
);
1805 SET_EvalMesh1(exec
, vbo_exec_EvalMesh1
);
1806 SET_EvalMesh2(exec
, vbo_exec_EvalMesh2
);
1809 if (_mesa_is_desktop_gl(ctx
)) {
1810 SET_DrawElementsBaseVertex(exec
, vbo_exec_DrawElementsBaseVertex
);
1811 SET_DrawRangeElementsBaseVertex(exec
, vbo_exec_DrawRangeElementsBaseVertex
);
1812 SET_MultiDrawElementsBaseVertex(exec
, vbo_exec_MultiDrawElementsBaseVertex
);
1813 SET_DrawArraysInstancedBaseInstance(exec
, vbo_exec_DrawArraysInstancedBaseInstance
);
1814 SET_DrawElementsInstancedBaseInstance(exec
, vbo_exec_DrawElementsInstancedBaseInstance
);
1815 SET_DrawElementsInstancedBaseVertex(exec
, vbo_exec_DrawElementsInstancedBaseVertex
);
1816 SET_DrawElementsInstancedBaseVertexBaseInstance(exec
, vbo_exec_DrawElementsInstancedBaseVertexBaseInstance
);
1819 if (ctx
->API
== API_OPENGL_CORE
) {
1820 SET_DrawArraysIndirect(exec
, vbo_exec_DrawArraysIndirect
);
1821 SET_DrawElementsIndirect(exec
, vbo_exec_DrawElementsIndirect
);
1822 SET_MultiDrawArraysIndirect(exec
, vbo_exec_MultiDrawArraysIndirect
);
1823 SET_MultiDrawElementsIndirect(exec
, vbo_exec_MultiDrawElementsIndirect
);
1826 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1827 SET_DrawArraysInstancedARB(exec
, vbo_exec_DrawArraysInstanced
);
1828 SET_DrawElementsInstancedARB(exec
, vbo_exec_DrawElementsInstanced
);
1831 if (_mesa_is_desktop_gl(ctx
)) {
1832 SET_DrawTransformFeedback(exec
, vbo_exec_DrawTransformFeedback
);
1833 SET_DrawTransformFeedbackStream(exec
, vbo_exec_DrawTransformFeedbackStream
);
1834 SET_DrawTransformFeedbackInstanced(exec
, vbo_exec_DrawTransformFeedbackInstanced
);
1835 SET_DrawTransformFeedbackStreamInstanced(exec
, vbo_exec_DrawTransformFeedbackStreamInstanced
);
1842 * The following functions are only used for OpenGL ES 1/2 support.
1843 * And some aren't even supported (yet) in ES 1/2.
1848 _mesa_DrawArrays(GLenum mode
, GLint first
, GLsizei count
)
1850 vbo_exec_DrawArrays(mode
, first
, count
);
1854 _mesa_DrawArraysInstanced(GLenum mode
, GLint first
, GLsizei count
,
1857 vbo_exec_DrawArraysInstanced(mode
, first
, count
, primcount
);
1861 _mesa_DrawElements(GLenum mode
, GLsizei count
, GLenum type
,
1862 const GLvoid
*indices
)
1864 vbo_exec_DrawElements(mode
, count
, type
, indices
);
1869 _mesa_DrawElementsBaseVertex(GLenum mode
, GLsizei count
, GLenum type
,
1870 const GLvoid
*indices
, GLint basevertex
)
1872 vbo_exec_DrawElementsBaseVertex(mode
, count
, type
, indices
, basevertex
);
1877 _mesa_DrawRangeElements(GLenum mode
, GLuint start
, GLuint end
, GLsizei count
,
1878 GLenum type
, const GLvoid
*indices
)
1880 vbo_exec_DrawRangeElements(mode
, start
, end
, count
, type
, indices
);
1885 _mesa_DrawRangeElementsBaseVertex(GLenum mode
, GLuint start
, GLuint end
,
1886 GLsizei count
, GLenum type
,
1887 const GLvoid
*indices
, GLint basevertex
)
1889 vbo_exec_DrawRangeElementsBaseVertex(mode
, start
, end
, count
, type
,
1890 indices
, basevertex
);
1895 _mesa_MultiDrawElementsEXT(GLenum mode
, const GLsizei
*count
, GLenum type
,
1896 const GLvoid
**indices
, GLsizei primcount
)
1898 vbo_exec_MultiDrawElements(mode
, count
, type
, indices
, primcount
);
1903 _mesa_MultiDrawElementsBaseVertex(GLenum mode
,
1904 const GLsizei
*count
, GLenum type
,
1905 const GLvoid
**indices
, GLsizei primcount
,
1906 const GLint
*basevertex
)
1908 vbo_exec_MultiDrawElementsBaseVertex(mode
, count
, type
, indices
,
1909 primcount
, basevertex
);
1913 _mesa_DrawTransformFeedback(GLenum mode
, GLuint name
)
1915 vbo_exec_DrawTransformFeedback(mode
, name
);