1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 * This file implements the st_draw_vbo() function which is called from
30 * Mesa's VBO module. All point/line/triangle rendering is done through
31 * this function whether the user called glBegin/End, glDrawArrays,
32 * glDrawElements, glEvalMesh, or glCalList, etc.
34 * We basically convert the VBO's vertex attribute/array information into
35 * Gallium vertex state, bind the vertex buffer objects and call
36 * pipe->draw_elements(), pipe->draw_range_elements() or pipe->draw_arrays().
39 * Keith Whitwell <keith@tungstengraphics.com>
43 #include "main/imports.h"
44 #include "main/image.h"
45 #include "main/macros.h"
46 #include "shader/prog_uniform.h"
50 #include "st_context.h"
52 #include "st_cb_bufferobjects.h"
54 #include "st_program.h"
56 #include "pipe/p_context.h"
57 #include "pipe/p_defines.h"
58 #include "util/u_inlines.h"
59 #include "util/u_format.h"
60 #include "cso_cache/cso_context.h"
63 static GLuint double_types
[4] = {
64 PIPE_FORMAT_R64_FLOAT
,
65 PIPE_FORMAT_R64G64_FLOAT
,
66 PIPE_FORMAT_R64G64B64_FLOAT
,
67 PIPE_FORMAT_R64G64B64A64_FLOAT
70 static GLuint float_types
[4] = {
71 PIPE_FORMAT_R32_FLOAT
,
72 PIPE_FORMAT_R32G32_FLOAT
,
73 PIPE_FORMAT_R32G32B32_FLOAT
,
74 PIPE_FORMAT_R32G32B32A32_FLOAT
77 static GLuint half_float_types
[4] = {
78 PIPE_FORMAT_R16_FLOAT
,
79 PIPE_FORMAT_R16G16_FLOAT
,
80 PIPE_FORMAT_R16G16B16_FLOAT
,
81 PIPE_FORMAT_R16G16B16A16_FLOAT
84 static GLuint uint_types_norm
[4] = {
85 PIPE_FORMAT_R32_UNORM
,
86 PIPE_FORMAT_R32G32_UNORM
,
87 PIPE_FORMAT_R32G32B32_UNORM
,
88 PIPE_FORMAT_R32G32B32A32_UNORM
91 static GLuint uint_types_scale
[4] = {
92 PIPE_FORMAT_R32_USCALED
,
93 PIPE_FORMAT_R32G32_USCALED
,
94 PIPE_FORMAT_R32G32B32_USCALED
,
95 PIPE_FORMAT_R32G32B32A32_USCALED
98 static GLuint int_types_norm
[4] = {
99 PIPE_FORMAT_R32_SNORM
,
100 PIPE_FORMAT_R32G32_SNORM
,
101 PIPE_FORMAT_R32G32B32_SNORM
,
102 PIPE_FORMAT_R32G32B32A32_SNORM
105 static GLuint int_types_scale
[4] = {
106 PIPE_FORMAT_R32_SSCALED
,
107 PIPE_FORMAT_R32G32_SSCALED
,
108 PIPE_FORMAT_R32G32B32_SSCALED
,
109 PIPE_FORMAT_R32G32B32A32_SSCALED
112 static GLuint ushort_types_norm
[4] = {
113 PIPE_FORMAT_R16_UNORM
,
114 PIPE_FORMAT_R16G16_UNORM
,
115 PIPE_FORMAT_R16G16B16_UNORM
,
116 PIPE_FORMAT_R16G16B16A16_UNORM
119 static GLuint ushort_types_scale
[4] = {
120 PIPE_FORMAT_R16_USCALED
,
121 PIPE_FORMAT_R16G16_USCALED
,
122 PIPE_FORMAT_R16G16B16_USCALED
,
123 PIPE_FORMAT_R16G16B16A16_USCALED
126 static GLuint short_types_norm
[4] = {
127 PIPE_FORMAT_R16_SNORM
,
128 PIPE_FORMAT_R16G16_SNORM
,
129 PIPE_FORMAT_R16G16B16_SNORM
,
130 PIPE_FORMAT_R16G16B16A16_SNORM
133 static GLuint short_types_scale
[4] = {
134 PIPE_FORMAT_R16_SSCALED
,
135 PIPE_FORMAT_R16G16_SSCALED
,
136 PIPE_FORMAT_R16G16B16_SSCALED
,
137 PIPE_FORMAT_R16G16B16A16_SSCALED
140 static GLuint ubyte_types_norm
[4] = {
141 PIPE_FORMAT_R8_UNORM
,
142 PIPE_FORMAT_R8G8_UNORM
,
143 PIPE_FORMAT_R8G8B8_UNORM
,
144 PIPE_FORMAT_R8G8B8A8_UNORM
147 static GLuint ubyte_types_scale
[4] = {
148 PIPE_FORMAT_R8_USCALED
,
149 PIPE_FORMAT_R8G8_USCALED
,
150 PIPE_FORMAT_R8G8B8_USCALED
,
151 PIPE_FORMAT_R8G8B8A8_USCALED
154 static GLuint byte_types_norm
[4] = {
155 PIPE_FORMAT_R8_SNORM
,
156 PIPE_FORMAT_R8G8_SNORM
,
157 PIPE_FORMAT_R8G8B8_SNORM
,
158 PIPE_FORMAT_R8G8B8A8_SNORM
161 static GLuint byte_types_scale
[4] = {
162 PIPE_FORMAT_R8_SSCALED
,
163 PIPE_FORMAT_R8G8_SSCALED
,
164 PIPE_FORMAT_R8G8B8_SSCALED
,
165 PIPE_FORMAT_R8G8B8A8_SSCALED
168 static GLuint fixed_types
[4] = {
169 PIPE_FORMAT_R32_FIXED
,
170 PIPE_FORMAT_R32G32_FIXED
,
171 PIPE_FORMAT_R32G32B32_FIXED
,
172 PIPE_FORMAT_R32G32B32A32_FIXED
178 * Return a PIPE_FORMAT_x for the given GL datatype and size.
181 st_pipe_vertex_format(GLenum type
, GLuint size
, GLenum format
,
182 GLboolean normalized
)
184 assert((type
>= GL_BYTE
&& type
<= GL_DOUBLE
) ||
185 type
== GL_FIXED
|| type
== GL_HALF_FLOAT
);
188 assert(format
== GL_RGBA
|| format
== GL_BGRA
);
190 if (format
== GL_BGRA
) {
191 /* this is an odd-ball case */
192 assert(type
== GL_UNSIGNED_BYTE
);
194 return PIPE_FORMAT_B8G8R8A8_UNORM
;
199 case GL_DOUBLE
: return double_types
[size
-1];
200 case GL_FLOAT
: return float_types
[size
-1];
201 case GL_HALF_FLOAT
: return half_float_types
[size
-1];
202 case GL_INT
: return int_types_norm
[size
-1];
203 case GL_SHORT
: return short_types_norm
[size
-1];
204 case GL_BYTE
: return byte_types_norm
[size
-1];
205 case GL_UNSIGNED_INT
: return uint_types_norm
[size
-1];
206 case GL_UNSIGNED_SHORT
: return ushort_types_norm
[size
-1];
207 case GL_UNSIGNED_BYTE
: return ubyte_types_norm
[size
-1];
208 case GL_FIXED
: return fixed_types
[size
-1];
209 default: assert(0); return 0;
214 case GL_DOUBLE
: return double_types
[size
-1];
215 case GL_FLOAT
: return float_types
[size
-1];
216 case GL_HALF_FLOAT
: return half_float_types
[size
-1];
217 case GL_INT
: return int_types_scale
[size
-1];
218 case GL_SHORT
: return short_types_scale
[size
-1];
219 case GL_BYTE
: return byte_types_scale
[size
-1];
220 case GL_UNSIGNED_INT
: return uint_types_scale
[size
-1];
221 case GL_UNSIGNED_SHORT
: return ushort_types_scale
[size
-1];
222 case GL_UNSIGNED_BYTE
: return ubyte_types_scale
[size
-1];
223 case GL_FIXED
: return fixed_types
[size
-1];
224 default: assert(0); return 0;
227 return 0; /* silence compiler warning */
235 * Examine the active arrays to determine if we have interleaved
236 * vertex arrays all living in one VBO, or all living in user space.
237 * \param userSpace returns whether the arrays are in user space.
240 is_interleaved_arrays(const struct st_vertex_program
*vp
,
241 const struct st_vp_varient
*vpv
,
242 const struct gl_client_array
**arrays
,
243 GLboolean
*userSpace
)
246 const struct gl_buffer_object
*firstBufObj
= NULL
;
247 GLint firstStride
= -1;
248 GLuint num_client_arrays
= 0;
249 const GLubyte
*client_addr
= NULL
;
251 for (attr
= 0; attr
< vpv
->num_inputs
; attr
++) {
252 const GLuint mesaAttr
= vp
->index_to_input
[attr
];
253 const struct gl_buffer_object
*bufObj
= arrays
[mesaAttr
]->BufferObj
;
254 const GLsizei stride
= arrays
[mesaAttr
]->StrideB
; /* in bytes */
256 if (firstStride
< 0) {
257 firstStride
= stride
;
259 else if (firstStride
!= stride
) {
263 if (!bufObj
|| !bufObj
->Name
) {
265 /* Try to detect if the client-space arrays are
266 * "close" to each other.
269 client_addr
= arrays
[mesaAttr
]->Ptr
;
271 else if (abs(arrays
[mesaAttr
]->Ptr
- client_addr
) > firstStride
) {
272 /* arrays start too far apart */
276 else if (!firstBufObj
) {
277 firstBufObj
= bufObj
;
279 else if (bufObj
!= firstBufObj
) {
284 *userSpace
= (num_client_arrays
== vpv
->num_inputs
);
285 /* debug_printf("user space: %s (%d arrays, %d inputs)\n",
286 (int)*userSpace ? "Yes" : "No", num_client_arrays, vp->num_inputs); */
293 * Compute the memory range occupied by the arrays.
296 get_arrays_bounds(const struct st_vertex_program
*vp
,
297 const struct st_vp_varient
*vpv
,
298 const struct gl_client_array
**arrays
,
300 const GLubyte
**low
, const GLubyte
**high
)
302 const GLubyte
*low_addr
= NULL
;
303 const GLubyte
*high_addr
= NULL
;
306 /* debug_printf("get_arrays_bounds: Handling %u attrs\n", vpv->num_inputs); */
308 for (attr
= 0; attr
< vpv
->num_inputs
; attr
++) {
309 const GLuint mesaAttr
= vp
->index_to_input
[attr
];
310 const GLint stride
= arrays
[mesaAttr
]->StrideB
;
311 const GLubyte
*start
= arrays
[mesaAttr
]->Ptr
;
312 const unsigned sz
= (arrays
[mesaAttr
]->Size
*
313 _mesa_sizeof_type(arrays
[mesaAttr
]->Type
));
314 const GLubyte
*end
= start
+ (max_index
* stride
) + sz
;
316 /* debug_printf("attr %u: stride %d size %u start %p end %p\n",
317 attr, stride, sz, start, end); */
324 low_addr
= MIN2(low_addr
, start
);
325 high_addr
= MAX2(high_addr
, end
);
335 * Set up for drawing interleaved arrays that all live in one VBO
336 * or all live in user space.
337 * \param vbuffer returns vertex buffer info
338 * \param velements returns vertex element info
341 setup_interleaved_attribs(GLcontext
*ctx
,
342 const struct st_vertex_program
*vp
,
343 const struct st_vp_varient
*vpv
,
344 const struct gl_client_array
**arrays
,
347 struct pipe_vertex_buffer
*vbuffer
,
348 struct pipe_vertex_element velements
[])
350 struct st_context
*st
= st_context(ctx
);
351 struct pipe_context
*pipe
= st
->pipe
;
353 const GLubyte
*offset0
= NULL
;
355 for (attr
= 0; attr
< vpv
->num_inputs
; attr
++) {
356 const GLuint mesaAttr
= vp
->index_to_input
[attr
];
357 struct gl_buffer_object
*bufobj
= arrays
[mesaAttr
]->BufferObj
;
358 struct st_buffer_object
*stobj
= st_buffer_object(bufobj
);
359 GLsizei stride
= arrays
[mesaAttr
]->StrideB
;
361 /*printf("stobj %u = %p\n", attr, (void*)stobj);*/
364 const GLubyte
*low
, *high
;
366 get_arrays_bounds(vp
, vpv
, arrays
, max_index
, &low
, &high
);
367 /* debug_printf("buffer range: %p %p range %d max index %u\n",
368 low, high, high - low, max_index); */
373 pipe_user_buffer_create(pipe
->screen
, (void *) low
, high
- low
,
374 PIPE_BIND_VERTEX_BUFFER
);
375 vbuffer
->buffer_offset
= 0;
378 vbuffer
->buffer
= NULL
;
379 pipe_resource_reference(&vbuffer
->buffer
, stobj
->buffer
);
380 vbuffer
->buffer_offset
= pointer_to_offset(low
);
382 vbuffer
->stride
= stride
; /* in bytes */
383 vbuffer
->max_index
= max_index
;
386 velements
[attr
].src_offset
=
387 (unsigned) (arrays
[mesaAttr
]->Ptr
- offset0
);
388 velements
[attr
].instance_divisor
= 0;
389 velements
[attr
].vertex_buffer_index
= 0;
390 velements
[attr
].src_format
=
391 st_pipe_vertex_format(arrays
[mesaAttr
]->Type
,
392 arrays
[mesaAttr
]->Size
,
393 arrays
[mesaAttr
]->Format
,
394 arrays
[mesaAttr
]->Normalized
);
395 assert(velements
[attr
].src_format
);
401 * Set up a separate pipe_vertex_buffer and pipe_vertex_element for each
403 * \param vbuffer returns vertex buffer info
404 * \param velements returns vertex element info
407 setup_non_interleaved_attribs(GLcontext
*ctx
,
408 const struct st_vertex_program
*vp
,
409 const struct st_vp_varient
*vpv
,
410 const struct gl_client_array
**arrays
,
412 GLboolean
*userSpace
,
413 struct pipe_vertex_buffer vbuffer
[],
414 struct pipe_vertex_element velements
[])
416 struct st_context
*st
= st_context(ctx
);
417 struct pipe_context
*pipe
= st
->pipe
;
420 for (attr
= 0; attr
< vpv
->num_inputs
; attr
++) {
421 const GLuint mesaAttr
= vp
->index_to_input
[attr
];
422 struct gl_buffer_object
*bufobj
= arrays
[mesaAttr
]->BufferObj
;
423 GLsizei stride
= arrays
[mesaAttr
]->StrideB
;
425 *userSpace
= GL_FALSE
;
427 if (bufobj
&& bufobj
->Name
) {
428 /* Attribute data is in a VBO.
429 * Recall that for VBOs, the gl_client_array->Ptr field is
430 * really an offset from the start of the VBO, not a pointer.
432 struct st_buffer_object
*stobj
= st_buffer_object(bufobj
);
433 assert(stobj
->buffer
);
434 /*printf("stobj %u = %p\n", attr, (void*) stobj);*/
436 vbuffer
[attr
].buffer
= NULL
;
437 pipe_resource_reference(&vbuffer
[attr
].buffer
, stobj
->buffer
);
438 vbuffer
[attr
].buffer_offset
= pointer_to_offset(arrays
[mesaAttr
]->Ptr
);
439 velements
[attr
].src_offset
= 0;
442 /* attribute data is in user-space memory, not a VBO */
444 /*printf("user-space array %d stride %d\n", attr, stride);*/
446 *userSpace
= GL_TRUE
;
449 if (arrays
[mesaAttr
]->Ptr
) {
450 /* user's vertex array */
451 if (arrays
[mesaAttr
]->StrideB
) {
452 bytes
= arrays
[mesaAttr
]->StrideB
* (max_index
+ 1);
455 bytes
= arrays
[mesaAttr
]->Size
456 * _mesa_sizeof_type(arrays
[mesaAttr
]->Type
);
458 vbuffer
[attr
].buffer
=
459 pipe_user_buffer_create(pipe
->screen
,
460 (void *) arrays
[mesaAttr
]->Ptr
, bytes
,
461 PIPE_BIND_VERTEX_BUFFER
);
464 /* no array, use ctx->Current.Attrib[] value */
465 bytes
= sizeof(ctx
->Current
.Attrib
[0]);
466 vbuffer
[attr
].buffer
=
467 pipe_user_buffer_create(pipe
->screen
,
468 (void *) ctx
->Current
.Attrib
[mesaAttr
],
470 PIPE_BIND_VERTEX_BUFFER
);
474 vbuffer
[attr
].buffer_offset
= 0;
475 velements
[attr
].src_offset
= 0;
478 assert(velements
[attr
].src_offset
<= 2048); /* 11-bit field */
480 /* common-case setup */
481 vbuffer
[attr
].stride
= stride
; /* in bytes */
482 vbuffer
[attr
].max_index
= max_index
;
483 velements
[attr
].instance_divisor
= 0;
484 velements
[attr
].vertex_buffer_index
= attr
;
485 velements
[attr
].src_format
486 = st_pipe_vertex_format(arrays
[mesaAttr
]->Type
,
487 arrays
[mesaAttr
]->Size
,
488 arrays
[mesaAttr
]->Format
,
489 arrays
[mesaAttr
]->Normalized
);
490 assert(velements
[attr
].src_format
);
497 * Prior to drawing, check that any uniforms referenced by the
498 * current shader have been set. If a uniform has not been set,
502 check_uniforms(GLcontext
*ctx
)
504 const struct gl_shader_program
*shProg
= ctx
->Shader
.CurrentProgram
;
505 if (shProg
&& shProg
->LinkStatus
) {
507 for (i
= 0; i
< shProg
->Uniforms
->NumUniforms
; i
++) {
508 const struct gl_uniform
*u
= &shProg
->Uniforms
->Uniforms
[i
];
509 if (!u
->Initialized
) {
511 "Using shader with uninitialized uniform: %s",
519 static unsigned translate_prim( GLcontext
*ctx
,
522 /* Avoid quadstrips if it's easy to do so:
524 if (prim
== GL_QUAD_STRIP
&&
525 ctx
->Light
.ShadeModel
!= GL_FLAT
&&
526 ctx
->Polygon
.FrontMode
== GL_FILL
&&
527 ctx
->Polygon
.BackMode
== GL_FILL
)
528 prim
= GL_TRIANGLE_STRIP
;
534 * This function gets plugged into the VBO module and is called when
535 * we have something to render.
536 * Basically, translate the information into the format expected by gallium.
539 st_draw_vbo(GLcontext
*ctx
,
540 const struct gl_client_array
**arrays
,
541 const struct _mesa_prim
*prims
,
543 const struct _mesa_index_buffer
*ib
,
544 GLboolean index_bounds_valid
,
548 struct st_context
*st
= st_context(ctx
);
549 struct pipe_context
*pipe
= st
->pipe
;
550 const struct st_vertex_program
*vp
;
551 const struct st_vp_varient
*vpv
;
552 struct pipe_vertex_buffer vbuffer
[PIPE_MAX_SHADER_INPUTS
];
554 struct pipe_vertex_element velements
[PIPE_MAX_ATTRIBS
];
555 unsigned num_vbuffers
, num_velements
;
556 GLboolean userSpace
= GL_FALSE
;
557 GLboolean vertDataEdgeFlags
;
559 /* Mesa core state should have been validated already */
560 assert(ctx
->NewState
== 0x0);
562 /* Gallium probably doesn't want this in some cases. */
563 if (!index_bounds_valid
)
564 if (!vbo_all_varyings_in_vbos(arrays
))
565 vbo_get_minmax_index(ctx
, prims
, ib
, &min_index
, &max_index
);
567 /* sanity check for pointer arithmetic below */
568 assert(sizeof(arrays
[0]->Ptr
[0]) == 1);
570 vertDataEdgeFlags
= arrays
[VERT_ATTRIB_EDGEFLAG
]->BufferObj
&&
571 arrays
[VERT_ATTRIB_EDGEFLAG
]->BufferObj
->Name
;
572 if (vertDataEdgeFlags
!= st
->vertdata_edgeflags
) {
573 st
->vertdata_edgeflags
= vertDataEdgeFlags
;
574 st
->dirty
.st
|= ST_NEW_EDGEFLAGS_DATA
;
577 st_validate_state(st
);
579 /* must get these after state validation! */
581 vpv
= st
->vp_varient
;
584 if (MESA_VERBOSE
& VERBOSE_GLSL
) {
588 (void) check_uniforms
;
591 memset(velements
, 0, sizeof(struct pipe_vertex_element
) * vpv
->num_inputs
);
593 * Setup the vbuffer[] and velements[] arrays.
595 if (is_interleaved_arrays(vp
, vpv
, arrays
, &userSpace
)) {
596 /*printf("Draw interleaved\n");*/
597 setup_interleaved_attribs(ctx
, vp
, vpv
, arrays
, max_index
, userSpace
,
600 num_velements
= vpv
->num_inputs
;
601 if (num_velements
== 0)
605 /*printf("Draw non-interleaved\n");*/
606 setup_non_interleaved_attribs(ctx
, vp
, vpv
, arrays
, max_index
,
607 &userSpace
, vbuffer
, velements
);
608 num_vbuffers
= vpv
->num_inputs
;
609 num_velements
= vpv
->num_inputs
;
615 for (i
= 0; i
< num_vbuffers
; i
++) {
616 printf("buffers[%d].stride = %u\n", i
, vbuffer
[i
].stride
);
617 printf("buffers[%d].max_index = %u\n", i
, vbuffer
[i
].max_index
);
618 printf("buffers[%d].buffer_offset = %u\n", i
, vbuffer
[i
].buffer_offset
);
619 printf("buffers[%d].buffer = %p\n", i
, (void*) vbuffer
[i
].buffer
);
621 for (i
= 0; i
< num_velements
; i
++) {
622 printf("vlements[%d].vbuffer_index = %u\n", i
, velements
[i
].vertex_buffer_index
);
623 printf("vlements[%d].src_offset = %u\n", i
, velements
[i
].src_offset
);
624 printf("vlements[%d].format = %s\n", i
, util_format_name(velements
[i
].src_format
));
629 pipe
->set_vertex_buffers(pipe
, num_vbuffers
, vbuffer
);
630 cso_set_vertex_elements(st
->cso_context
, num_velements
, velements
);
632 if (num_vbuffers
== 0 || num_velements
== 0)
635 /* do actual drawing */
637 /* indexed primitive */
638 struct gl_buffer_object
*bufobj
= ib
->obj
;
639 struct pipe_resource
*indexBuf
= NULL
;
640 unsigned indexSize
, indexOffset
, i
;
644 case GL_UNSIGNED_INT
:
647 case GL_UNSIGNED_SHORT
:
650 case GL_UNSIGNED_BYTE
:
658 /* get/create the index buffer object */
659 if (bufobj
&& bufobj
->Name
) {
660 /* elements/indexes are in a real VBO */
661 struct st_buffer_object
*stobj
= st_buffer_object(bufobj
);
662 pipe_resource_reference(&indexBuf
, stobj
->buffer
);
663 indexOffset
= pointer_to_offset(ib
->ptr
) / indexSize
;
666 /* element/indicies are in user space memory */
667 indexBuf
= pipe_user_buffer_create(pipe
->screen
, (void *) ib
->ptr
,
668 ib
->count
* indexSize
,
669 PIPE_BIND_INDEX_BUFFER
);
674 if (pipe
->draw_range_elements
&& min_index
!= ~0 && max_index
!= ~0) {
675 /* XXX: exercise temporary path to pass min/max directly
676 * through to driver & draw module. These interfaces still
677 * need a bit of work...
679 for (i
= 0; i
< nr_prims
; i
++) {
680 prim
= translate_prim( ctx
, prims
[i
].mode
);
682 pipe
->draw_range_elements(pipe
, indexBuf
, indexSize
, 0,
683 min_index
, max_index
, prim
,
684 prims
[i
].start
+ indexOffset
, prims
[i
].count
);
688 for (i
= 0; i
< nr_prims
; i
++) {
689 prim
= translate_prim( ctx
, prims
[i
].mode
);
691 if (prims
[i
].num_instances
== 1) {
692 pipe
->draw_elements(pipe
, indexBuf
, indexSize
, 0, prim
,
693 prims
[i
].start
+ indexOffset
,
697 pipe
->draw_elements_instanced(pipe
, indexBuf
, indexSize
, 0, prim
,
698 prims
[i
].start
+ indexOffset
,
700 0, prims
[i
].num_instances
);
705 pipe_resource_reference(&indexBuf
, NULL
);
712 for (i
= 0; i
< nr_prims
; i
++) {
713 prim
= translate_prim( ctx
, prims
[i
].mode
);
715 if (prims
[i
].num_instances
== 1) {
716 pipe
->draw_arrays(pipe
, prim
, prims
[i
].start
, prims
[i
].count
);
719 pipe
->draw_arrays_instanced(pipe
, prim
, prims
[i
].start
,
721 0, prims
[i
].num_instances
);
726 /* unreference buffers (frees wrapped user-space buffer objects) */
727 for (attr
= 0; attr
< num_vbuffers
; attr
++) {
728 pipe_resource_reference(&vbuffer
[attr
].buffer
, NULL
);
729 assert(!vbuffer
[attr
].buffer
);
734 pipe
->set_vertex_buffers(pipe
, 0, NULL
);
739 void st_init_draw( struct st_context
*st
)
741 GLcontext
*ctx
= st
->ctx
;
743 vbo_set_draw_func(ctx
, st_draw_vbo
);
747 void st_destroy_draw( struct st_context
*st
)