1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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"
40 #include "vbo_context.h"
44 * All vertex buffers should be in an unmapped state when we're about
45 * to draw. This debug function checks that.
48 check_buffers_are_unmapped(const struct gl_client_array
**inputs
)
53 for (i
= 0; i
< VERT_ATTRIB_MAX
; i
++) {
55 struct gl_buffer_object
*obj
= inputs
[i
]->BufferObj
;
56 assert(!_mesa_bufferobj_mapped(obj
));
65 * A debug function that may be called from other parts of Mesa as
66 * needed during debugging.
69 vbo_check_buffers_are_unmapped(struct gl_context
*ctx
)
71 struct vbo_context
*vbo
= vbo_context(ctx
);
72 struct vbo_exec_context
*exec
= &vbo
->exec
;
73 /* check the current vertex arrays */
74 check_buffers_are_unmapped(exec
->array
.inputs
);
75 /* check the current glBegin/glVertex/glEnd-style VBO */
76 assert(!_mesa_bufferobj_mapped(exec
->vtx
.bufferobj
));
82 * Compute min and max elements by scanning the index buffer for
83 * glDraw[Range]Elements() calls.
84 * If primitive restart is enabled, we need to ignore restart
85 * indexes when computing min/max.
88 vbo_get_minmax_index(struct gl_context
*ctx
,
89 const struct _mesa_prim
*prim
,
90 const struct _mesa_index_buffer
*ib
,
91 GLuint
*min_index
, GLuint
*max_index
,
94 const GLboolean restart
= ctx
->Array
._PrimitiveRestart
;
95 const GLuint restartIndex
= ctx
->Array
._RestartIndex
;
96 const int index_size
= vbo_sizeof_ib_type(ib
->type
);
100 indices
= (char *) ib
->ptr
+ prim
->start
* index_size
;
101 if (_mesa_is_bufferobj(ib
->obj
)) {
102 GLsizeiptr size
= MIN2(count
* index_size
, ib
->obj
->Size
);
103 indices
= ctx
->Driver
.MapBufferRange(ctx
, (GLintptr
) indices
, size
,
104 GL_MAP_READ_BIT
, ib
->obj
);
108 case GL_UNSIGNED_INT
: {
109 const GLuint
*ui_indices
= (const GLuint
*)indices
;
113 for (i
= 0; i
< count
; i
++) {
114 if (ui_indices
[i
] != restartIndex
) {
115 if (ui_indices
[i
] > max_ui
) max_ui
= ui_indices
[i
];
116 if (ui_indices
[i
] < min_ui
) min_ui
= ui_indices
[i
];
121 for (i
= 0; i
< count
; i
++) {
122 if (ui_indices
[i
] > max_ui
) max_ui
= ui_indices
[i
];
123 if (ui_indices
[i
] < min_ui
) min_ui
= ui_indices
[i
];
130 case GL_UNSIGNED_SHORT
: {
131 const GLushort
*us_indices
= (const GLushort
*)indices
;
135 for (i
= 0; i
< count
; i
++) {
136 if (us_indices
[i
] != restartIndex
) {
137 if (us_indices
[i
] > max_us
) max_us
= us_indices
[i
];
138 if (us_indices
[i
] < min_us
) min_us
= us_indices
[i
];
143 for (i
= 0; i
< count
; i
++) {
144 if (us_indices
[i
] > max_us
) max_us
= us_indices
[i
];
145 if (us_indices
[i
] < min_us
) min_us
= us_indices
[i
];
152 case GL_UNSIGNED_BYTE
: {
153 const GLubyte
*ub_indices
= (const GLubyte
*)indices
;
157 for (i
= 0; i
< count
; i
++) {
158 if (ub_indices
[i
] != restartIndex
) {
159 if (ub_indices
[i
] > max_ub
) max_ub
= ub_indices
[i
];
160 if (ub_indices
[i
] < min_ub
) min_ub
= ub_indices
[i
];
165 for (i
= 0; i
< count
; i
++) {
166 if (ub_indices
[i
] > max_ub
) max_ub
= ub_indices
[i
];
167 if (ub_indices
[i
] < min_ub
) min_ub
= ub_indices
[i
];
179 if (_mesa_is_bufferobj(ib
->obj
)) {
180 ctx
->Driver
.UnmapBuffer(ctx
, ib
->obj
);
185 * Compute min and max elements for nr_prims
188 vbo_get_minmax_indices(struct gl_context
*ctx
,
189 const struct _mesa_prim
*prims
,
190 const struct _mesa_index_buffer
*ib
,
195 GLuint tmp_min
, tmp_max
;
202 for (i
= 0; i
< nr_prims
; i
++) {
203 const struct _mesa_prim
*start_prim
;
205 start_prim
= &prims
[i
];
206 count
= start_prim
->count
;
207 /* Do combination if possible to reduce map/unmap count */
208 while ((i
+ 1 < nr_prims
) &&
209 (prims
[i
].start
+ prims
[i
].count
== prims
[i
+1].start
)) {
210 count
+= prims
[i
+1].count
;
213 vbo_get_minmax_index(ctx
, start_prim
, ib
, &tmp_min
, &tmp_max
, count
);
214 *min_index
= MIN2(*min_index
, tmp_min
);
215 *max_index
= MAX2(*max_index
, tmp_max
);
221 * Check that element 'j' of the array has reasonable data.
223 * For debugging purposes; not normally used.
226 check_array_data(struct gl_context
*ctx
, struct gl_client_array
*array
,
227 GLuint attrib
, GLuint j
)
229 if (array
->Enabled
) {
230 const void *data
= array
->Ptr
;
231 if (_mesa_is_bufferobj(array
->BufferObj
)) {
232 if (!array
->BufferObj
->Pointer
) {
233 /* need to map now */
234 array
->BufferObj
->Pointer
=
235 ctx
->Driver
.MapBufferRange(ctx
, 0, array
->BufferObj
->Size
,
236 GL_MAP_READ_BIT
, array
->BufferObj
);
238 data
= ADD_POINTERS(data
, array
->BufferObj
->Pointer
);
240 switch (array
->Type
) {
243 GLfloat
*f
= (GLfloat
*) ((GLubyte
*) data
+ array
->StrideB
* j
);
245 for (k
= 0; k
< array
->Size
; k
++) {
246 if (IS_INF_OR_NAN(f
[k
]) ||
247 f
[k
] >= 1.0e20
|| f
[k
] <= -1.0e10
) {
248 printf("Bad array data:\n");
249 printf(" Element[%u].%u = %f\n", j
, k
, f
[k
]);
250 printf(" Array %u at %p\n", attrib
, (void* ) array
);
251 printf(" Type 0x%x, Size %d, Stride %d\n",
252 array
->Type
, array
->Size
, array
->Stride
);
253 printf(" Address/offset %p in Buffer Object %u\n",
254 array
->Ptr
, array
->BufferObj
->Name
);
255 f
[k
] = 1.0; /* XXX replace the bad value! */
257 /*assert(!IS_INF_OR_NAN(f[k]));*/
269 * Unmap the buffer object referenced by given array, if mapped.
272 unmap_array_buffer(struct gl_context
*ctx
, struct gl_client_array
*array
)
274 if (array
->Enabled
&&
275 _mesa_is_bufferobj(array
->BufferObj
) &&
276 _mesa_bufferobj_mapped(array
->BufferObj
)) {
277 ctx
->Driver
.UnmapBuffer(ctx
, array
->BufferObj
);
283 * Examine the array's data for NaNs, etc.
284 * For debug purposes; not normally used.
287 check_draw_elements_data(struct gl_context
*ctx
, GLsizei count
, GLenum elemType
,
288 const void *elements
, GLint basevertex
)
290 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
294 if (_mesa_is_bufferobj(ctx
->Array
.ArrayObj
->ElementArrayBufferObj
)) {
295 elemMap
= ctx
->Driver
.MapBufferRange(ctx
, 0,
296 ctx
->Array
.ArrayObj
->ElementArrayBufferObj
->Size
,
298 ctx
->Array
.ArrayObj
->ElementArrayBufferObj
);
299 elements
= ADD_POINTERS(elements
, elemMap
);
302 for (i
= 0; i
< count
; i
++) {
307 case GL_UNSIGNED_BYTE
:
308 j
= ((const GLubyte
*) elements
)[i
];
310 case GL_UNSIGNED_SHORT
:
311 j
= ((const GLushort
*) elements
)[i
];
313 case GL_UNSIGNED_INT
:
314 j
= ((const GLuint
*) elements
)[i
];
320 /* check element j of each enabled array */
321 for (k
= 0; k
< Elements(arrayObj
->VertexAttrib
); k
++) {
322 check_array_data(ctx
, &arrayObj
->VertexAttrib
[k
], k
, j
);
326 if (_mesa_is_bufferobj(arrayObj
->ElementArrayBufferObj
)) {
327 ctx
->Driver
.UnmapBuffer(ctx
, ctx
->Array
.ArrayObj
->ElementArrayBufferObj
);
330 for (k
= 0; k
< Elements(arrayObj
->VertexAttrib
); k
++) {
331 unmap_array_buffer(ctx
, &arrayObj
->VertexAttrib
[k
]);
337 * Check array data, looking for NaNs, etc.
340 check_draw_arrays_data(struct gl_context
*ctx
, GLint start
, GLsizei count
)
347 * Print info/data for glDrawArrays(), for debugging.
350 print_draw_arrays(struct gl_context
*ctx
,
351 GLenum mode
, GLint start
, GLsizei count
)
353 struct vbo_context
*vbo
= vbo_context(ctx
);
354 struct vbo_exec_context
*exec
= &vbo
->exec
;
355 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
358 printf("vbo_exec_DrawArrays(mode 0x%x, start %d, count %d):\n",
361 for (i
= 0; i
< 32; i
++) {
362 struct gl_buffer_object
*bufObj
= exec
->array
.inputs
[i
]->BufferObj
;
363 GLuint bufName
= bufObj
->Name
;
364 GLint stride
= exec
->array
.inputs
[i
]->Stride
;
365 printf("attr %2d: size %d stride %d enabled %d "
366 "ptr %p Bufobj %u\n",
368 exec
->array
.inputs
[i
]->Size
,
370 /*exec->array.inputs[i]->Enabled,*/
371 arrayObj
->VertexAttrib
[VERT_ATTRIB_FF(i
)].Enabled
,
372 exec
->array
.inputs
[i
]->Ptr
,
376 GLubyte
*p
= ctx
->Driver
.MapBufferRange(ctx
, 0, bufObj
->Size
,
377 GL_MAP_READ_BIT
, bufObj
);
378 int offset
= (int) (GLintptr
) exec
->array
.inputs
[i
]->Ptr
;
379 float *f
= (float *) (p
+ offset
);
382 int n
= (count
* stride
) / 4;
385 printf(" Data at offset %d:\n", offset
);
386 for (i
= 0; i
< n
; i
++) {
387 printf(" float[%d] = 0x%08x %f\n", i
, k
[i
], f
[i
]);
389 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
);
396 * Set the vbo->exec->inputs[] pointers to point to the enabled
397 * vertex arrays. This depends on the current vertex program/shader
398 * being executed because of whether or not generic vertex arrays
399 * alias the conventional vertex arrays.
400 * For arrays that aren't enabled, we set the input[attrib] pointer
401 * to point at a zero-stride current value "array".
404 recalculate_input_bindings(struct gl_context
*ctx
)
406 struct vbo_context
*vbo
= vbo_context(ctx
);
407 struct vbo_exec_context
*exec
= &vbo
->exec
;
408 struct gl_client_array
*vertexAttrib
= ctx
->Array
.ArrayObj
->VertexAttrib
;
409 const struct gl_client_array
**inputs
= &exec
->array
.inputs
[0];
410 GLbitfield64 const_inputs
= 0x0;
413 switch (get_program_mode(ctx
)) {
415 /* When no vertex program is active (or the vertex program is generated
416 * from fixed-function state). We put the material values into the
417 * generic slots. This is the only situation where material values
418 * are available as per-vertex attributes.
420 for (i
= 0; i
< VERT_ATTRIB_FF_MAX
; i
++) {
421 if (vertexAttrib
[VERT_ATTRIB_FF(i
)].Enabled
)
422 inputs
[i
] = &vertexAttrib
[VERT_ATTRIB_FF(i
)];
424 inputs
[i
] = &vbo
->currval
[VBO_ATTRIB_POS
+i
];
425 const_inputs
|= VERT_BIT(i
);
429 for (i
= 0; i
< MAT_ATTRIB_MAX
; i
++) {
430 inputs
[VERT_ATTRIB_GENERIC(i
)] =
431 &vbo
->currval
[VBO_ATTRIB_MAT_FRONT_AMBIENT
+i
];
432 const_inputs
|= VERT_BIT_GENERIC(i
);
435 /* Could use just about anything, just to fill in the empty
438 for (i
= MAT_ATTRIB_MAX
; i
< VERT_ATTRIB_GENERIC_MAX
; i
++) {
439 inputs
[VERT_ATTRIB_GENERIC(i
)] = &vbo
->currval
[VBO_ATTRIB_GENERIC0
+i
];
440 const_inputs
|= VERT_BIT_GENERIC(i
);
445 /* GL_ARB_vertex_program or GLSL vertex shader - Only the generic[0]
446 * attribute array aliases and overrides the legacy position array.
448 * Otherwise, legacy attributes available in the legacy slots,
449 * generic attributes in the generic slots and materials are not
450 * available as per-vertex attributes.
452 if (vertexAttrib
[VERT_ATTRIB_GENERIC0
].Enabled
)
453 inputs
[0] = &vertexAttrib
[VERT_ATTRIB_GENERIC0
];
454 else if (vertexAttrib
[VERT_ATTRIB_POS
].Enabled
)
455 inputs
[0] = &vertexAttrib
[VERT_ATTRIB_POS
];
457 inputs
[0] = &vbo
->currval
[VBO_ATTRIB_POS
];
458 const_inputs
|= VERT_BIT_POS
;
461 for (i
= 1; i
< VERT_ATTRIB_FF_MAX
; i
++) {
462 if (vertexAttrib
[VERT_ATTRIB_FF(i
)].Enabled
)
463 inputs
[i
] = &vertexAttrib
[VERT_ATTRIB_FF(i
)];
465 inputs
[i
] = &vbo
->currval
[VBO_ATTRIB_POS
+i
];
466 const_inputs
|= VERT_BIT_FF(i
);
470 for (i
= 1; i
< VERT_ATTRIB_GENERIC_MAX
; i
++) {
471 if (vertexAttrib
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
472 inputs
[VERT_ATTRIB_GENERIC(i
)] = &vertexAttrib
[VERT_ATTRIB_GENERIC(i
)];
474 inputs
[VERT_ATTRIB_GENERIC(i
)] = &vbo
->currval
[VBO_ATTRIB_GENERIC0
+i
];
475 const_inputs
|= VERT_BIT_GENERIC(i
);
479 inputs
[VERT_ATTRIB_GENERIC0
] = inputs
[0];
483 _mesa_set_varying_vp_inputs( ctx
, VERT_BIT_ALL
& (~const_inputs
) );
484 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewArray
;
489 * Examine the enabled vertex arrays to set the exec->array.inputs[] values.
490 * These will point to the arrays to actually use for drawing. Some will
491 * be user-provided arrays, other will be zero-stride const-valued arrays.
492 * Note that this might set the _NEW_VARYING_VP_INPUTS dirty flag so state
493 * validation must be done after this call.
496 vbo_bind_arrays(struct gl_context
*ctx
)
498 struct vbo_context
*vbo
= vbo_context(ctx
);
499 struct vbo_exec_context
*exec
= &vbo
->exec
;
501 vbo_draw_method(vbo
, DRAW_ARRAYS
);
503 if (exec
->array
.recalculate_inputs
) {
504 recalculate_input_bindings(ctx
);
505 exec
->array
.recalculate_inputs
= GL_FALSE
;
507 /* Again... because we may have changed the bitmask of per-vertex varying
508 * attributes. If we regenerate the fixed-function vertex program now
509 * we may be able to prune down the number of vertex attributes which we
510 * need in the shader.
513 /* Setting "validating" to TRUE prevents _mesa_update_state from
514 * invalidating what we just did.
516 exec
->validating
= GL_TRUE
;
517 _mesa_update_state(ctx
);
518 exec
->validating
= GL_FALSE
;
525 * Handle a draw case that potentially has primitive restart enabled.
527 * If primitive restart is enabled, and PrimitiveRestartInSoftware is
528 * set, then vbo_sw_primitive_restart is used to handle the primitive
529 * restart case in software.
532 vbo_handle_primitive_restart(struct gl_context
*ctx
,
533 const struct _mesa_prim
*prim
,
535 const struct _mesa_index_buffer
*ib
,
536 GLboolean index_bounds_valid
,
540 struct vbo_context
*vbo
= vbo_context(ctx
);
543 ctx
->Const
.PrimitiveRestartInSoftware
&&
544 ctx
->Array
._PrimitiveRestart
) {
545 /* Handle primitive restart in software */
546 vbo_sw_primitive_restart(ctx
, prim
, nr_prims
, ib
);
548 /* Call driver directly for draw_prims */
549 vbo
->draw_prims(ctx
, prim
, nr_prims
, ib
,
550 index_bounds_valid
, min_index
, max_index
, NULL
);
556 * Helper function called by the other DrawArrays() functions below.
557 * This is where we handle primitive restart for drawing non-indexed
558 * arrays. If primitive restart is enabled, it typically means
559 * splitting one DrawArrays() into two.
562 vbo_draw_arrays(struct gl_context
*ctx
, GLenum mode
, GLint start
,
563 GLsizei count
, GLuint numInstances
, GLuint baseInstance
)
565 struct vbo_context
*vbo
= vbo_context(ctx
);
566 struct vbo_exec_context
*exec
= &vbo
->exec
;
567 struct _mesa_prim prim
[2];
569 vbo_bind_arrays(ctx
);
571 /* init most fields to zero */
572 memset(prim
, 0, sizeof(prim
));
576 prim
[0].num_instances
= numInstances
;
577 prim
[0].base_instance
= baseInstance
;
579 /* Implement the primitive restart index */
580 if (ctx
->Array
._PrimitiveRestart
&& ctx
->Array
._RestartIndex
< count
) {
581 GLuint primCount
= 0;
583 if (ctx
->Array
._RestartIndex
== start
) {
584 /* special case: RestartIndex at beginning */
586 prim
[0].start
= start
+ 1;
587 prim
[0].count
= count
- 1;
591 else if (ctx
->Array
._RestartIndex
== start
+ count
- 1) {
592 /* special case: RestartIndex at end */
594 prim
[0].start
= start
;
595 prim
[0].count
= count
- 1;
600 /* general case: RestartIndex in middle, split into two prims */
601 prim
[0].start
= start
;
602 prim
[0].count
= ctx
->Array
._RestartIndex
- start
;
605 prim
[1].start
= ctx
->Array
._RestartIndex
+ 1;
606 prim
[1].count
= count
- prim
[1].start
;
612 /* draw one or two prims */
613 check_buffers_are_unmapped(exec
->array
.inputs
);
614 vbo
->draw_prims(ctx
, prim
, primCount
, NULL
,
615 GL_TRUE
, start
, start
+ count
- 1, NULL
);
619 /* no prim restart */
620 prim
[0].start
= start
;
621 prim
[0].count
= count
;
623 check_buffers_are_unmapped(exec
->array
.inputs
);
624 vbo
->draw_prims(ctx
, prim
, 1, NULL
,
625 GL_TRUE
, start
, start
+ count
- 1,
629 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
) {
636 * Execute a glRectf() function.
638 static void GLAPIENTRY
639 vbo_exec_Rectf(GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
)
641 GET_CURRENT_CONTEXT(ctx
);
642 ASSERT_OUTSIDE_BEGIN_END(ctx
);
644 CALL_Begin(GET_DISPATCH(), (GL_QUADS
));
645 CALL_Vertex2f(GET_DISPATCH(), (x1
, y1
));
646 CALL_Vertex2f(GET_DISPATCH(), (x2
, y1
));
647 CALL_Vertex2f(GET_DISPATCH(), (x2
, y2
));
648 CALL_Vertex2f(GET_DISPATCH(), (x1
, y2
));
649 CALL_End(GET_DISPATCH(), ());
653 static void GLAPIENTRY
654 vbo_exec_EvalMesh1(GLenum mode
, GLint i1
, GLint i2
)
656 GET_CURRENT_CONTEXT(ctx
);
666 prim
= GL_LINE_STRIP
;
669 _mesa_error( ctx
, GL_INVALID_ENUM
, "glEvalMesh1(mode)" );
673 /* No effect if vertex maps disabled.
675 if (!ctx
->Eval
.Map1Vertex4
&&
676 !ctx
->Eval
.Map1Vertex3
)
679 du
= ctx
->Eval
.MapGrid1du
;
680 u
= ctx
->Eval
.MapGrid1u1
+ i1
* du
;
682 CALL_Begin(GET_DISPATCH(), (prim
));
683 for (i
=i1
;i
<=i2
;i
++,u
+=du
) {
684 CALL_EvalCoord1f(GET_DISPATCH(), (u
));
686 CALL_End(GET_DISPATCH(), ());
690 static void GLAPIENTRY
691 vbo_exec_EvalMesh2(GLenum mode
, GLint i1
, GLint i2
, GLint j1
, GLint j2
)
693 GET_CURRENT_CONTEXT(ctx
);
694 GLfloat u
, du
, v
, dv
, v1
, u1
;
703 _mesa_error( ctx
, GL_INVALID_ENUM
, "glEvalMesh2(mode)" );
707 /* No effect if vertex maps disabled.
709 if (!ctx
->Eval
.Map2Vertex4
&&
710 !ctx
->Eval
.Map2Vertex3
)
713 du
= ctx
->Eval
.MapGrid2du
;
714 dv
= ctx
->Eval
.MapGrid2dv
;
715 v1
= ctx
->Eval
.MapGrid2v1
+ j1
* dv
;
716 u1
= ctx
->Eval
.MapGrid2u1
+ i1
* du
;
720 CALL_Begin(GET_DISPATCH(), (GL_POINTS
));
721 for (v
=v1
,j
=j1
;j
<=j2
;j
++,v
+=dv
) {
722 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
723 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
726 CALL_End(GET_DISPATCH(), ());
729 for (v
=v1
,j
=j1
;j
<=j2
;j
++,v
+=dv
) {
730 CALL_Begin(GET_DISPATCH(), (GL_LINE_STRIP
));
731 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
732 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
734 CALL_End(GET_DISPATCH(), ());
736 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
737 CALL_Begin(GET_DISPATCH(), (GL_LINE_STRIP
));
738 for (v
=v1
,j
=j1
;j
<=j2
;j
++,v
+=dv
) {
739 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
741 CALL_End(GET_DISPATCH(), ());
745 for (v
=v1
,j
=j1
;j
<j2
;j
++,v
+=dv
) {
746 CALL_Begin(GET_DISPATCH(), (GL_TRIANGLE_STRIP
));
747 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
748 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
));
749 CALL_EvalCoord2f(GET_DISPATCH(), (u
, v
+dv
));
751 CALL_End(GET_DISPATCH(), ());
759 * Called from glDrawArrays when in immediate mode (not display list mode).
761 static void GLAPIENTRY
762 vbo_exec_DrawArrays(GLenum mode
, GLint start
, GLsizei count
)
764 GET_CURRENT_CONTEXT(ctx
);
766 if (MESA_VERBOSE
& VERBOSE_DRAW
)
767 _mesa_debug(ctx
, "glDrawArrays(%s, %d, %d)\n",
768 _mesa_lookup_enum_by_nr(mode
), start
, count
);
770 if (!_mesa_validate_DrawArrays( ctx
, mode
, start
, count
))
774 check_draw_arrays_data(ctx
, start
, count
);
776 vbo_draw_arrays(ctx
, mode
, start
, count
, 1, 0);
779 print_draw_arrays(ctx
, mode
, start
, count
);
784 * Called from glDrawArraysInstanced when in immediate mode (not
785 * display list mode).
787 static void GLAPIENTRY
788 vbo_exec_DrawArraysInstanced(GLenum mode
, GLint start
, GLsizei count
,
789 GLsizei numInstances
)
791 GET_CURRENT_CONTEXT(ctx
);
793 if (MESA_VERBOSE
& VERBOSE_DRAW
)
794 _mesa_debug(ctx
, "glDrawArraysInstanced(%s, %d, %d, %d)\n",
795 _mesa_lookup_enum_by_nr(mode
), start
, count
, numInstances
);
797 if (!_mesa_validate_DrawArraysInstanced(ctx
, mode
, start
, count
, numInstances
))
801 check_draw_arrays_data(ctx
, start
, count
);
803 vbo_draw_arrays(ctx
, mode
, start
, count
, numInstances
, 0);
806 print_draw_arrays(ctx
, mode
, start
, count
);
811 * Called from glDrawArraysInstancedBaseInstance when in immediate mode.
813 static void GLAPIENTRY
814 vbo_exec_DrawArraysInstancedBaseInstance(GLenum mode
, GLint first
, GLsizei count
,
815 GLsizei numInstances
, GLuint baseInstance
)
817 GET_CURRENT_CONTEXT(ctx
);
819 if (MESA_VERBOSE
& VERBOSE_DRAW
)
820 _mesa_debug(ctx
, "glDrawArraysInstancedBaseInstance(%s, %d, %d, %d, %d)\n",
821 _mesa_lookup_enum_by_nr(mode
), first
, count
,
822 numInstances
, baseInstance
);
824 if (!_mesa_validate_DrawArraysInstanced(ctx
, mode
, first
, count
,
829 check_draw_arrays_data(ctx
, first
, count
);
831 vbo_draw_arrays(ctx
, mode
, first
, count
, numInstances
, baseInstance
);
834 print_draw_arrays(ctx
, mode
, first
, count
);
840 * Map GL_ELEMENT_ARRAY_BUFFER and print contents.
845 dump_element_buffer(struct gl_context
*ctx
, GLenum type
)
848 ctx
->Driver
.MapBufferRange(ctx
, 0,
849 ctx
->Array
.ArrayObj
->ElementArrayBufferObj
->Size
,
851 ctx
->Array
.ArrayObj
->ElementArrayBufferObj
);
853 case GL_UNSIGNED_BYTE
:
855 const GLubyte
*us
= (const GLubyte
*) map
;
857 for (i
= 0; i
< ctx
->Array
.ArrayObj
->ElementArrayBufferObj
->Size
; i
++) {
858 printf("%02x ", us
[i
]);
865 case GL_UNSIGNED_SHORT
:
867 const GLushort
*us
= (const GLushort
*) map
;
869 for (i
= 0; i
< ctx
->Array
.ArrayObj
->ElementArrayBufferObj
->Size
/ 2; i
++) {
870 printf("%04x ", us
[i
]);
877 case GL_UNSIGNED_INT
:
879 const GLuint
*us
= (const GLuint
*) map
;
881 for (i
= 0; i
< ctx
->Array
.ArrayObj
->ElementArrayBufferObj
->Size
/ 4; i
++) {
882 printf("%08x ", us
[i
]);
893 ctx
->Driver
.UnmapBuffer(ctx
, ctx
->Array
.ArrayObj
->ElementArrayBufferObj
);
899 * Inner support for both _mesa_DrawElements and _mesa_DrawRangeElements.
900 * Do the rendering for a glDrawElements or glDrawRangeElements call after
901 * we've validated buffer bounds, etc.
904 vbo_validated_drawrangeelements(struct gl_context
*ctx
, GLenum mode
,
905 GLboolean index_bounds_valid
,
906 GLuint start
, GLuint end
,
907 GLsizei count
, GLenum type
,
908 const GLvoid
*indices
,
909 GLint basevertex
, GLuint numInstances
,
912 struct vbo_context
*vbo
= vbo_context(ctx
);
913 struct vbo_exec_context
*exec
= &vbo
->exec
;
914 struct _mesa_index_buffer ib
;
915 struct _mesa_prim prim
[1];
917 vbo_bind_arrays(ctx
);
921 ib
.obj
= ctx
->Array
.ArrayObj
->ElementArrayBufferObj
;
930 prim
[0].count
= count
;
932 prim
[0].basevertex
= basevertex
;
933 prim
[0].num_instances
= numInstances
;
934 prim
[0].base_instance
= baseInstance
;
936 /* Need to give special consideration to rendering a range of
937 * indices starting somewhere above zero. Typically the
938 * application is issuing multiple DrawRangeElements() to draw
939 * successive primitives layed out linearly in the vertex arrays.
940 * Unless the vertex arrays are all in a VBO (or locked as with
941 * CVA), the OpenGL semantics imply that we need to re-read or
942 * re-upload the vertex data on each draw call.
944 * In the case of hardware tnl, we want to avoid starting the
945 * upload at zero, as it will mean every draw call uploads an
946 * increasing amount of not-used vertex data. Worse - in the
947 * software tnl module, all those vertices might be transformed and
948 * lit but never rendered.
950 * If we just upload or transform the vertices in start..end,
951 * however, the indices will be incorrect.
953 * At this level, we don't know exactly what the requirements of
954 * the backend are going to be, though it will likely boil down to
957 * 1) Do nothing, everything is in a VBO and is processed once
960 * 2) Adjust the indices and vertex arrays so that start becomes
963 * Rather than doing anything here, I'll provide a helper function
964 * for the latter case elsewhere.
967 check_buffers_are_unmapped(exec
->array
.inputs
);
968 vbo_handle_primitive_restart(ctx
, prim
, 1, &ib
,
969 index_bounds_valid
, start
, end
);
971 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
) {
978 * Called by glDrawRangeElementsBaseVertex() in immediate mode.
980 static void GLAPIENTRY
981 vbo_exec_DrawRangeElementsBaseVertex(GLenum mode
,
982 GLuint start
, GLuint end
,
983 GLsizei count
, GLenum type
,
984 const GLvoid
*indices
,
987 static GLuint warnCount
= 0;
988 GLboolean index_bounds_valid
= GL_TRUE
;
989 GET_CURRENT_CONTEXT(ctx
);
991 if (MESA_VERBOSE
& VERBOSE_DRAW
)
993 "glDrawRangeElementsBaseVertex(%s, %u, %u, %d, %s, %p, %d)\n",
994 _mesa_lookup_enum_by_nr(mode
), start
, end
, count
,
995 _mesa_lookup_enum_by_nr(type
), indices
, basevertex
);
997 if (!_mesa_validate_DrawRangeElements( ctx
, mode
, start
, end
, count
,
998 type
, indices
, basevertex
))
1001 if ((int) end
+ basevertex
< 0 ||
1002 start
+ basevertex
>= ctx
->Array
.ArrayObj
->_MaxElement
) {
1003 /* The application requested we draw using a range of indices that's
1004 * outside the bounds of the current VBO. This is invalid and appears
1005 * to give undefined results. The safest thing to do is to simply
1006 * ignore the range, in case the application botched their range tracking
1007 * but did provide valid indices. Also issue a warning indicating that
1008 * the application is broken.
1010 if (warnCount
++ < 10) {
1011 _mesa_warning(ctx
, "glDrawRangeElements(start %u, end %u, "
1012 "basevertex %d, count %d, type 0x%x, indices=%p):\n"
1013 "\trange is outside VBO bounds (max=%u); ignoring.\n"
1014 "\tThis should be fixed in the application.",
1015 start
, end
, basevertex
, count
, type
, indices
,
1016 ctx
->Array
.ArrayObj
->_MaxElement
- 1);
1018 index_bounds_valid
= GL_FALSE
;
1021 /* NOTE: It's important that 'end' is a reasonable value.
1022 * in _tnl_draw_prims(), we use end to determine how many vertices
1023 * to transform. If it's too large, we can unnecessarily split prims
1024 * or we can read/write out of memory in several different places!
1027 /* Catch/fix some potential user errors */
1028 if (type
== GL_UNSIGNED_BYTE
) {
1029 start
= MIN2(start
, 0xff);
1030 end
= MIN2(end
, 0xff);
1032 else if (type
== GL_UNSIGNED_SHORT
) {
1033 start
= MIN2(start
, 0xffff);
1034 end
= MIN2(end
, 0xffff);
1038 printf("glDraw[Range]Elements{,BaseVertex}"
1039 "(start %u, end %u, type 0x%x, count %d) ElemBuf %u, "
1041 start
, end
, type
, count
,
1042 ctx
->Array
.ArrayObj
->ElementArrayBufferObj
->Name
,
1046 if ((int) start
+ basevertex
< 0 ||
1047 end
+ basevertex
>= ctx
->Array
.ArrayObj
->_MaxElement
)
1048 index_bounds_valid
= GL_FALSE
;
1051 check_draw_elements_data(ctx
, count
, type
, indices
);
1053 (void) check_draw_elements_data
;
1056 vbo_validated_drawrangeelements(ctx
, mode
, index_bounds_valid
, start
, end
,
1057 count
, type
, indices
, basevertex
, 1, 0);
1062 * Called by glDrawRangeElements() in immediate mode.
1064 static void GLAPIENTRY
1065 vbo_exec_DrawRangeElements(GLenum mode
, GLuint start
, GLuint end
,
1066 GLsizei count
, GLenum type
, const GLvoid
*indices
)
1068 if (MESA_VERBOSE
& VERBOSE_DRAW
) {
1069 GET_CURRENT_CONTEXT(ctx
);
1071 "glDrawRangeElements(%s, %u, %u, %d, %s, %p)\n",
1072 _mesa_lookup_enum_by_nr(mode
), start
, end
, count
,
1073 _mesa_lookup_enum_by_nr(type
), indices
);
1076 vbo_exec_DrawRangeElementsBaseVertex(mode
, start
, end
, count
, type
,
1082 * Called by glDrawElements() in immediate mode.
1084 static void GLAPIENTRY
1085 vbo_exec_DrawElements(GLenum mode
, GLsizei count
, GLenum type
,
1086 const GLvoid
*indices
)
1088 GET_CURRENT_CONTEXT(ctx
);
1090 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1091 _mesa_debug(ctx
, "glDrawElements(%s, %u, %s, %p)\n",
1092 _mesa_lookup_enum_by_nr(mode
), count
,
1093 _mesa_lookup_enum_by_nr(type
), indices
);
1095 if (!_mesa_validate_DrawElements( ctx
, mode
, count
, type
, indices
, 0 ))
1098 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1099 count
, type
, indices
, 0, 1, 0);
1104 * Called by glDrawElementsBaseVertex() in immediate mode.
1106 static void GLAPIENTRY
1107 vbo_exec_DrawElementsBaseVertex(GLenum mode
, GLsizei count
, GLenum type
,
1108 const GLvoid
*indices
, GLint basevertex
)
1110 GET_CURRENT_CONTEXT(ctx
);
1112 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1113 _mesa_debug(ctx
, "glDrawElementsBaseVertex(%s, %d, %s, %p, %d)\n",
1114 _mesa_lookup_enum_by_nr(mode
), count
,
1115 _mesa_lookup_enum_by_nr(type
), indices
, basevertex
);
1117 if (!_mesa_validate_DrawElements( ctx
, mode
, count
, type
, indices
,
1121 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1122 count
, type
, indices
, basevertex
, 1, 0);
1127 * Called by glDrawElementsInstanced() in immediate mode.
1129 static void GLAPIENTRY
1130 vbo_exec_DrawElementsInstanced(GLenum mode
, GLsizei count
, GLenum type
,
1131 const GLvoid
*indices
, GLsizei numInstances
)
1133 GET_CURRENT_CONTEXT(ctx
);
1135 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1136 _mesa_debug(ctx
, "glDrawElementsInstanced(%s, %d, %s, %p, %d)\n",
1137 _mesa_lookup_enum_by_nr(mode
), count
,
1138 _mesa_lookup_enum_by_nr(type
), indices
, numInstances
);
1140 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
1144 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1145 count
, type
, indices
, 0, numInstances
, 0);
1150 * Called by glDrawElementsInstancedBaseVertex() in immediate mode.
1152 static void GLAPIENTRY
1153 vbo_exec_DrawElementsInstancedBaseVertex(GLenum mode
, GLsizei count
, GLenum type
,
1154 const GLvoid
*indices
, GLsizei numInstances
,
1157 GET_CURRENT_CONTEXT(ctx
);
1159 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1160 _mesa_debug(ctx
, "glDrawElementsInstancedBaseVertex(%s, %d, %s, %p, %d; %d)\n",
1161 _mesa_lookup_enum_by_nr(mode
), count
,
1162 _mesa_lookup_enum_by_nr(type
), indices
,
1163 numInstances
, basevertex
);
1165 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
1166 numInstances
, basevertex
))
1169 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1170 count
, type
, indices
, basevertex
, numInstances
, 0);
1175 * Called by glDrawElementsInstancedBaseInstance() in immediate mode.
1177 static void GLAPIENTRY
1178 vbo_exec_DrawElementsInstancedBaseInstance(GLenum mode
, GLsizei count
, GLenum type
,
1179 const GLvoid
*indices
, GLsizei numInstances
,
1180 GLuint baseInstance
)
1182 GET_CURRENT_CONTEXT(ctx
);
1184 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1185 _mesa_debug(ctx
, "glDrawElementsInstancedBaseInstance(%s, %d, %s, %p, %d, %d)\n",
1186 _mesa_lookup_enum_by_nr(mode
), count
,
1187 _mesa_lookup_enum_by_nr(type
), indices
,
1188 numInstances
, baseInstance
);
1190 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
1194 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1195 count
, type
, indices
, 0, numInstances
,
1201 * Called by glDrawElementsInstancedBaseVertexBaseInstance() in immediate mode.
1203 static void GLAPIENTRY
1204 vbo_exec_DrawElementsInstancedBaseVertexBaseInstance(GLenum mode
, GLsizei count
, GLenum type
,
1205 const GLvoid
*indices
, GLsizei numInstances
,
1206 GLint basevertex
, GLuint baseInstance
)
1208 GET_CURRENT_CONTEXT(ctx
);
1210 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1211 _mesa_debug(ctx
, "glDrawElementsInstancedBaseVertexBaseInstance(%s, %d, %s, %p, %d, %d, %d)\n",
1212 _mesa_lookup_enum_by_nr(mode
), count
,
1213 _mesa_lookup_enum_by_nr(type
), indices
,
1214 numInstances
, basevertex
, baseInstance
);
1216 if (!_mesa_validate_DrawElementsInstanced(ctx
, mode
, count
, type
, indices
,
1217 numInstances
, basevertex
))
1220 vbo_validated_drawrangeelements(ctx
, mode
, GL_FALSE
, ~0, ~0,
1221 count
, type
, indices
, basevertex
, numInstances
,
1227 * Inner support for both _mesa_MultiDrawElements() and
1228 * _mesa_MultiDrawRangeElements().
1229 * This does the actual rendering after we've checked array indexes, etc.
1232 vbo_validated_multidrawelements(struct gl_context
*ctx
, GLenum mode
,
1233 const GLsizei
*count
, GLenum type
,
1234 const GLvoid
* const *indices
,
1236 const GLint
*basevertex
)
1238 struct vbo_context
*vbo
= vbo_context(ctx
);
1239 struct vbo_exec_context
*exec
= &vbo
->exec
;
1240 struct _mesa_index_buffer ib
;
1241 struct _mesa_prim
*prim
;
1242 unsigned int index_type_size
= vbo_sizeof_ib_type(type
);
1243 uintptr_t min_index_ptr
, max_index_ptr
;
1244 GLboolean fallback
= GL_FALSE
;
1250 prim
= calloc(1, primcount
* sizeof(*prim
));
1252 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMultiDrawElements");
1256 vbo_bind_arrays(ctx
);
1258 min_index_ptr
= (uintptr_t)indices
[0];
1260 for (i
= 0; i
< primcount
; i
++) {
1261 min_index_ptr
= MIN2(min_index_ptr
, (uintptr_t)indices
[i
]);
1262 max_index_ptr
= MAX2(max_index_ptr
, (uintptr_t)indices
[i
] +
1263 index_type_size
* count
[i
]);
1266 /* Check if we can handle this thing as a bunch of index offsets from the
1267 * same index pointer. If we can't, then we have to fall back to doing
1268 * a draw_prims per primitive.
1269 * Check that the difference between each prim's indexes is a multiple of
1270 * the index/element size.
1272 if (index_type_size
!= 1) {
1273 for (i
= 0; i
< primcount
; i
++) {
1274 if ((((uintptr_t)indices
[i
] - min_index_ptr
) % index_type_size
) != 0) {
1281 /* If the index buffer isn't in a VBO, then treating the application's
1282 * subranges of the index buffer as one large index buffer may lead to
1283 * us reading unmapped memory.
1285 if (!_mesa_is_bufferobj(ctx
->Array
.ArrayObj
->ElementArrayBufferObj
))
1289 ib
.count
= (max_index_ptr
- min_index_ptr
) / index_type_size
;
1291 ib
.obj
= ctx
->Array
.ArrayObj
->ElementArrayBufferObj
;
1292 ib
.ptr
= (void *)min_index_ptr
;
1294 for (i
= 0; i
< primcount
; i
++) {
1295 prim
[i
].begin
= (i
== 0);
1296 prim
[i
].end
= (i
== primcount
- 1);
1299 prim
[i
].mode
= mode
;
1300 prim
[i
].start
= ((uintptr_t)indices
[i
] - min_index_ptr
) / index_type_size
;
1301 prim
[i
].count
= count
[i
];
1302 prim
[i
].indexed
= 1;
1303 prim
[i
].num_instances
= 1;
1304 prim
[i
].base_instance
= 0;
1305 if (basevertex
!= NULL
)
1306 prim
[i
].basevertex
= basevertex
[i
];
1308 prim
[i
].basevertex
= 0;
1311 check_buffers_are_unmapped(exec
->array
.inputs
);
1312 vbo_handle_primitive_restart(ctx
, prim
, primcount
, &ib
,
1315 /* render one prim at a time */
1316 for (i
= 0; i
< primcount
; i
++) {
1317 ib
.count
= count
[i
];
1319 ib
.obj
= ctx
->Array
.ArrayObj
->ElementArrayBufferObj
;
1320 ib
.ptr
= indices
[i
];
1326 prim
[0].mode
= mode
;
1328 prim
[0].count
= count
[i
];
1329 prim
[0].indexed
= 1;
1330 prim
[0].num_instances
= 1;
1331 prim
[0].base_instance
= 0;
1332 if (basevertex
!= NULL
)
1333 prim
[0].basevertex
= basevertex
[i
];
1335 prim
[0].basevertex
= 0;
1337 check_buffers_are_unmapped(exec
->array
.inputs
);
1338 vbo_handle_primitive_restart(ctx
, prim
, 1, &ib
,
1345 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
) {
1351 static void GLAPIENTRY
1352 vbo_exec_MultiDrawElements(GLenum mode
,
1353 const GLsizei
*count
, GLenum type
,
1354 const GLvoid
**indices
,
1357 GET_CURRENT_CONTEXT(ctx
);
1359 if (!_mesa_validate_MultiDrawElements(ctx
, mode
, count
, type
, indices
,
1363 vbo_validated_multidrawelements(ctx
, mode
, count
, type
, indices
, primcount
,
1368 static void GLAPIENTRY
1369 vbo_exec_MultiDrawElementsBaseVertex(GLenum mode
,
1370 const GLsizei
*count
, GLenum type
,
1371 const GLvoid
* const *indices
,
1373 const GLsizei
*basevertex
)
1375 GET_CURRENT_CONTEXT(ctx
);
1377 if (!_mesa_validate_MultiDrawElements(ctx
, mode
, count
, type
, indices
,
1378 primcount
, basevertex
))
1381 vbo_validated_multidrawelements(ctx
, mode
, count
, type
, indices
, primcount
,
1386 vbo_draw_transform_feedback(struct gl_context
*ctx
, GLenum mode
,
1387 struct gl_transform_feedback_object
*obj
,
1388 GLuint stream
, GLuint numInstances
)
1390 struct vbo_context
*vbo
= vbo_context(ctx
);
1391 struct vbo_exec_context
*exec
= &vbo
->exec
;
1392 struct _mesa_prim prim
[2];
1394 if (!_mesa_validate_DrawTransformFeedback(ctx
, mode
, obj
, stream
,
1399 vbo_bind_arrays(ctx
);
1401 /* init most fields to zero */
1402 memset(prim
, 0, sizeof(prim
));
1405 prim
[0].mode
= mode
;
1406 prim
[0].num_instances
= numInstances
;
1407 prim
[0].base_instance
= 0;
1409 /* Maybe we should do some primitive splitting for primitive restart
1410 * (like in DrawArrays), but we have no way to know how many vertices
1411 * will be rendered. */
1413 check_buffers_are_unmapped(exec
->array
.inputs
);
1414 vbo
->draw_prims(ctx
, prim
, 1, NULL
,
1415 GL_TRUE
, 0, 0, obj
);
1417 if (MESA_DEBUG_FLAGS
& DEBUG_ALWAYS_FLUSH
) {
1423 * Like DrawArrays, but take the count from a transform feedback object.
1424 * \param mode GL_POINTS, GL_LINES, GL_TRIANGLE_STRIP, etc.
1425 * \param name the transform feedback object
1426 * User still has to setup of the vertex attribute info with
1427 * glVertexPointer, glColorPointer, etc.
1428 * Part of GL_ARB_transform_feedback2.
1430 static void GLAPIENTRY
1431 vbo_exec_DrawTransformFeedback(GLenum mode
, GLuint name
)
1433 GET_CURRENT_CONTEXT(ctx
);
1434 struct gl_transform_feedback_object
*obj
=
1435 _mesa_lookup_transform_feedback_object(ctx
, name
);
1437 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1438 _mesa_debug(ctx
, "glDrawTransformFeedback(%s, %d)\n",
1439 _mesa_lookup_enum_by_nr(mode
), name
);
1441 vbo_draw_transform_feedback(ctx
, mode
, obj
, 0, 1);
1444 static void GLAPIENTRY
1445 vbo_exec_DrawTransformFeedbackStream(GLenum mode
, GLuint name
, GLuint stream
)
1447 GET_CURRENT_CONTEXT(ctx
);
1448 struct gl_transform_feedback_object
*obj
=
1449 _mesa_lookup_transform_feedback_object(ctx
, name
);
1451 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1452 _mesa_debug(ctx
, "glDrawTransformFeedbackStream(%s, %u, %u)\n",
1453 _mesa_lookup_enum_by_nr(mode
), name
, stream
);
1455 vbo_draw_transform_feedback(ctx
, mode
, obj
, stream
, 1);
1458 static void GLAPIENTRY
1459 vbo_exec_DrawTransformFeedbackInstanced(GLenum mode
, GLuint name
,
1462 GET_CURRENT_CONTEXT(ctx
);
1463 struct gl_transform_feedback_object
*obj
=
1464 _mesa_lookup_transform_feedback_object(ctx
, name
);
1466 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1467 _mesa_debug(ctx
, "glDrawTransformFeedbackInstanced(%s, %d)\n",
1468 _mesa_lookup_enum_by_nr(mode
), name
);
1470 vbo_draw_transform_feedback(ctx
, mode
, obj
, 0, primcount
);
1473 static void GLAPIENTRY
1474 vbo_exec_DrawTransformFeedbackStreamInstanced(GLenum mode
, GLuint name
,
1475 GLuint stream
, GLsizei primcount
)
1477 GET_CURRENT_CONTEXT(ctx
);
1478 struct gl_transform_feedback_object
*obj
=
1479 _mesa_lookup_transform_feedback_object(ctx
, name
);
1481 if (MESA_VERBOSE
& VERBOSE_DRAW
)
1482 _mesa_debug(ctx
, "glDrawTransformFeedbackStreamInstanced"
1483 "(%s, %u, %u, %i)\n",
1484 _mesa_lookup_enum_by_nr(mode
), name
, stream
, primcount
);
1486 vbo_draw_transform_feedback(ctx
, mode
, obj
, stream
, primcount
);
1491 * Initialize the dispatch table with the VBO functions for drawing.
1494 vbo_initialize_exec_dispatch(const struct gl_context
*ctx
,
1495 struct _glapi_table
*exec
)
1497 SET_DrawArrays(exec
, vbo_exec_DrawArrays
);
1498 SET_DrawElements(exec
, vbo_exec_DrawElements
);
1500 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1501 SET_DrawRangeElements(exec
, vbo_exec_DrawRangeElements
);
1504 SET_MultiDrawElementsEXT(exec
, vbo_exec_MultiDrawElements
);
1506 if (ctx
->API
== API_OPENGL_COMPAT
) {
1507 SET_Rectf(exec
, vbo_exec_Rectf
);
1508 SET_EvalMesh1(exec
, vbo_exec_EvalMesh1
);
1509 SET_EvalMesh2(exec
, vbo_exec_EvalMesh2
);
1512 if (_mesa_is_desktop_gl(ctx
)) {
1513 SET_DrawElementsBaseVertex(exec
, vbo_exec_DrawElementsBaseVertex
);
1514 SET_DrawRangeElementsBaseVertex(exec
, vbo_exec_DrawRangeElementsBaseVertex
);
1515 SET_MultiDrawElementsBaseVertex(exec
, vbo_exec_MultiDrawElementsBaseVertex
);
1516 SET_DrawArraysInstancedBaseInstance(exec
, vbo_exec_DrawArraysInstancedBaseInstance
);
1517 SET_DrawElementsInstancedBaseInstance(exec
, vbo_exec_DrawElementsInstancedBaseInstance
);
1518 SET_DrawElementsInstancedBaseVertex(exec
, vbo_exec_DrawElementsInstancedBaseVertex
);
1519 SET_DrawElementsInstancedBaseVertexBaseInstance(exec
, vbo_exec_DrawElementsInstancedBaseVertexBaseInstance
);
1522 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
1523 SET_DrawArraysInstancedARB(exec
, vbo_exec_DrawArraysInstanced
);
1524 SET_DrawElementsInstancedARB(exec
, vbo_exec_DrawElementsInstanced
);
1527 if (_mesa_is_desktop_gl(ctx
)) {
1528 SET_DrawTransformFeedback(exec
, vbo_exec_DrawTransformFeedback
);
1529 SET_DrawTransformFeedbackStream(exec
, vbo_exec_DrawTransformFeedbackStream
);
1530 SET_DrawTransformFeedbackInstanced(exec
, vbo_exec_DrawTransformFeedbackInstanced
);
1531 SET_DrawTransformFeedbackStreamInstanced(exec
, vbo_exec_DrawTransformFeedbackStreamInstanced
);
1538 * The following functions are only used for OpenGL ES 1/2 support.
1539 * And some aren't even supported (yet) in ES 1/2.
1544 _mesa_DrawArrays(GLenum mode
, GLint first
, GLsizei count
)
1546 vbo_exec_DrawArrays(mode
, first
, count
);
1551 _mesa_DrawElements(GLenum mode
, GLsizei count
, GLenum type
,
1552 const GLvoid
*indices
)
1554 vbo_exec_DrawElements(mode
, count
, type
, indices
);
1559 _mesa_DrawElementsBaseVertex(GLenum mode
, GLsizei count
, GLenum type
,
1560 const GLvoid
*indices
, GLint basevertex
)
1562 vbo_exec_DrawElementsBaseVertex(mode
, count
, type
, indices
, basevertex
);
1567 _mesa_DrawRangeElements(GLenum mode
, GLuint start
, GLuint end
, GLsizei count
,
1568 GLenum type
, const GLvoid
*indices
)
1570 vbo_exec_DrawRangeElements(mode
, start
, end
, count
, type
, indices
);
1575 _mesa_DrawRangeElementsBaseVertex(GLenum mode
, GLuint start
, GLuint end
,
1576 GLsizei count
, GLenum type
,
1577 const GLvoid
*indices
, GLint basevertex
)
1579 vbo_exec_DrawRangeElementsBaseVertex(mode
, start
, end
, count
, type
,
1580 indices
, basevertex
);
1585 _mesa_MultiDrawElementsEXT(GLenum mode
, const GLsizei
*count
, GLenum type
,
1586 const GLvoid
**indices
, GLsizei primcount
)
1588 vbo_exec_MultiDrawElements(mode
, count
, type
, indices
, primcount
);
1593 _mesa_MultiDrawElementsBaseVertex(GLenum mode
,
1594 const GLsizei
*count
, GLenum type
,
1595 const GLvoid
**indices
, GLsizei primcount
,
1596 const GLint
*basevertex
)
1598 vbo_exec_MultiDrawElementsBaseVertex(mode
, count
, type
, indices
,
1599 primcount
, basevertex
);
1603 _mesa_DrawTransformFeedback(GLenum mode
, GLuint name
)
1605 vbo_exec_DrawTransformFeedback(mode
, name
);