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 "program/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 "util/u_prim.h"
61 #include "draw/draw_context.h"
62 #include "cso_cache/cso_context.h"
65 static GLuint double_types
[4] = {
66 PIPE_FORMAT_R64_FLOAT
,
67 PIPE_FORMAT_R64G64_FLOAT
,
68 PIPE_FORMAT_R64G64B64_FLOAT
,
69 PIPE_FORMAT_R64G64B64A64_FLOAT
72 static GLuint float_types
[4] = {
73 PIPE_FORMAT_R32_FLOAT
,
74 PIPE_FORMAT_R32G32_FLOAT
,
75 PIPE_FORMAT_R32G32B32_FLOAT
,
76 PIPE_FORMAT_R32G32B32A32_FLOAT
79 static GLuint half_float_types
[4] = {
80 PIPE_FORMAT_R16_FLOAT
,
81 PIPE_FORMAT_R16G16_FLOAT
,
82 PIPE_FORMAT_R16G16B16_FLOAT
,
83 PIPE_FORMAT_R16G16B16A16_FLOAT
86 static GLuint uint_types_norm
[4] = {
87 PIPE_FORMAT_R32_UNORM
,
88 PIPE_FORMAT_R32G32_UNORM
,
89 PIPE_FORMAT_R32G32B32_UNORM
,
90 PIPE_FORMAT_R32G32B32A32_UNORM
93 static GLuint uint_types_scale
[4] = {
94 PIPE_FORMAT_R32_USCALED
,
95 PIPE_FORMAT_R32G32_USCALED
,
96 PIPE_FORMAT_R32G32B32_USCALED
,
97 PIPE_FORMAT_R32G32B32A32_USCALED
100 static GLuint int_types_norm
[4] = {
101 PIPE_FORMAT_R32_SNORM
,
102 PIPE_FORMAT_R32G32_SNORM
,
103 PIPE_FORMAT_R32G32B32_SNORM
,
104 PIPE_FORMAT_R32G32B32A32_SNORM
107 static GLuint int_types_scale
[4] = {
108 PIPE_FORMAT_R32_SSCALED
,
109 PIPE_FORMAT_R32G32_SSCALED
,
110 PIPE_FORMAT_R32G32B32_SSCALED
,
111 PIPE_FORMAT_R32G32B32A32_SSCALED
114 static GLuint ushort_types_norm
[4] = {
115 PIPE_FORMAT_R16_UNORM
,
116 PIPE_FORMAT_R16G16_UNORM
,
117 PIPE_FORMAT_R16G16B16_UNORM
,
118 PIPE_FORMAT_R16G16B16A16_UNORM
121 static GLuint ushort_types_scale
[4] = {
122 PIPE_FORMAT_R16_USCALED
,
123 PIPE_FORMAT_R16G16_USCALED
,
124 PIPE_FORMAT_R16G16B16_USCALED
,
125 PIPE_FORMAT_R16G16B16A16_USCALED
128 static GLuint short_types_norm
[4] = {
129 PIPE_FORMAT_R16_SNORM
,
130 PIPE_FORMAT_R16G16_SNORM
,
131 PIPE_FORMAT_R16G16B16_SNORM
,
132 PIPE_FORMAT_R16G16B16A16_SNORM
135 static GLuint short_types_scale
[4] = {
136 PIPE_FORMAT_R16_SSCALED
,
137 PIPE_FORMAT_R16G16_SSCALED
,
138 PIPE_FORMAT_R16G16B16_SSCALED
,
139 PIPE_FORMAT_R16G16B16A16_SSCALED
142 static GLuint ubyte_types_norm
[4] = {
143 PIPE_FORMAT_R8_UNORM
,
144 PIPE_FORMAT_R8G8_UNORM
,
145 PIPE_FORMAT_R8G8B8_UNORM
,
146 PIPE_FORMAT_R8G8B8A8_UNORM
149 static GLuint ubyte_types_scale
[4] = {
150 PIPE_FORMAT_R8_USCALED
,
151 PIPE_FORMAT_R8G8_USCALED
,
152 PIPE_FORMAT_R8G8B8_USCALED
,
153 PIPE_FORMAT_R8G8B8A8_USCALED
156 static GLuint byte_types_norm
[4] = {
157 PIPE_FORMAT_R8_SNORM
,
158 PIPE_FORMAT_R8G8_SNORM
,
159 PIPE_FORMAT_R8G8B8_SNORM
,
160 PIPE_FORMAT_R8G8B8A8_SNORM
163 static GLuint byte_types_scale
[4] = {
164 PIPE_FORMAT_R8_SSCALED
,
165 PIPE_FORMAT_R8G8_SSCALED
,
166 PIPE_FORMAT_R8G8B8_SSCALED
,
167 PIPE_FORMAT_R8G8B8A8_SSCALED
170 static GLuint fixed_types
[4] = {
171 PIPE_FORMAT_R32_FIXED
,
172 PIPE_FORMAT_R32G32_FIXED
,
173 PIPE_FORMAT_R32G32B32_FIXED
,
174 PIPE_FORMAT_R32G32B32A32_FIXED
180 * Return a PIPE_FORMAT_x for the given GL datatype and size.
183 st_pipe_vertex_format(GLenum type
, GLuint size
, GLenum format
,
184 GLboolean normalized
)
186 assert((type
>= GL_BYTE
&& type
<= GL_DOUBLE
) ||
187 type
== GL_FIXED
|| type
== GL_HALF_FLOAT
);
190 assert(format
== GL_RGBA
|| format
== GL_BGRA
);
192 if (format
== GL_BGRA
) {
193 /* this is an odd-ball case */
194 assert(type
== GL_UNSIGNED_BYTE
);
196 return PIPE_FORMAT_B8G8R8A8_UNORM
;
201 case GL_DOUBLE
: return double_types
[size
-1];
202 case GL_FLOAT
: return float_types
[size
-1];
203 case GL_HALF_FLOAT
: return half_float_types
[size
-1];
204 case GL_INT
: return int_types_norm
[size
-1];
205 case GL_SHORT
: return short_types_norm
[size
-1];
206 case GL_BYTE
: return byte_types_norm
[size
-1];
207 case GL_UNSIGNED_INT
: return uint_types_norm
[size
-1];
208 case GL_UNSIGNED_SHORT
: return ushort_types_norm
[size
-1];
209 case GL_UNSIGNED_BYTE
: return ubyte_types_norm
[size
-1];
210 case GL_FIXED
: return fixed_types
[size
-1];
211 default: assert(0); return 0;
216 case GL_DOUBLE
: return double_types
[size
-1];
217 case GL_FLOAT
: return float_types
[size
-1];
218 case GL_HALF_FLOAT
: return half_float_types
[size
-1];
219 case GL_INT
: return int_types_scale
[size
-1];
220 case GL_SHORT
: return short_types_scale
[size
-1];
221 case GL_BYTE
: return byte_types_scale
[size
-1];
222 case GL_UNSIGNED_INT
: return uint_types_scale
[size
-1];
223 case GL_UNSIGNED_SHORT
: return ushort_types_scale
[size
-1];
224 case GL_UNSIGNED_BYTE
: return ubyte_types_scale
[size
-1];
225 case GL_FIXED
: return fixed_types
[size
-1];
226 default: assert(0); return 0;
229 return 0; /* silence compiler warning */
237 * Examine the active arrays to determine if we have interleaved
238 * vertex arrays all living in one VBO, or all living in user space.
239 * \param userSpace returns whether the arrays are in user space.
242 is_interleaved_arrays(const struct st_vertex_program
*vp
,
243 const struct st_vp_varient
*vpv
,
244 const struct gl_client_array
**arrays
,
245 GLboolean
*userSpace
)
248 const struct gl_buffer_object
*firstBufObj
= NULL
;
249 GLint firstStride
= -1;
250 GLuint num_client_arrays
= 0;
251 const GLubyte
*client_addr
= NULL
;
253 for (attr
= 0; attr
< vpv
->num_inputs
; attr
++) {
254 const GLuint mesaAttr
= vp
->index_to_input
[attr
];
255 const struct gl_buffer_object
*bufObj
= arrays
[mesaAttr
]->BufferObj
;
256 const GLsizei stride
= arrays
[mesaAttr
]->StrideB
; /* in bytes */
258 if (firstStride
< 0) {
259 firstStride
= stride
;
261 else if (firstStride
!= stride
) {
265 if (!bufObj
|| !bufObj
->Name
) {
267 /* Try to detect if the client-space arrays are
268 * "close" to each other.
271 client_addr
= arrays
[mesaAttr
]->Ptr
;
273 else if (abs(arrays
[mesaAttr
]->Ptr
- client_addr
) > firstStride
) {
274 /* arrays start too far apart */
278 else if (!firstBufObj
) {
279 firstBufObj
= bufObj
;
281 else if (bufObj
!= firstBufObj
) {
286 *userSpace
= (num_client_arrays
== vpv
->num_inputs
);
287 /* debug_printf("user space: %s (%d arrays, %d inputs)\n",
288 (int)*userSpace ? "Yes" : "No", num_client_arrays, vp->num_inputs); */
295 * Compute the memory range occupied by the arrays.
298 get_arrays_bounds(const struct st_vertex_program
*vp
,
299 const struct st_vp_varient
*vpv
,
300 const struct gl_client_array
**arrays
,
302 const GLubyte
**low
, const GLubyte
**high
)
304 const GLubyte
*low_addr
= NULL
;
305 const GLubyte
*high_addr
= NULL
;
308 /* debug_printf("get_arrays_bounds: Handling %u attrs\n", vpv->num_inputs); */
310 for (attr
= 0; attr
< vpv
->num_inputs
; attr
++) {
311 const GLuint mesaAttr
= vp
->index_to_input
[attr
];
312 const GLint stride
= arrays
[mesaAttr
]->StrideB
;
313 const GLubyte
*start
= arrays
[mesaAttr
]->Ptr
;
314 const unsigned sz
= (arrays
[mesaAttr
]->Size
*
315 _mesa_sizeof_type(arrays
[mesaAttr
]->Type
));
316 const GLubyte
*end
= start
+ (max_index
* stride
) + sz
;
318 /* debug_printf("attr %u: stride %d size %u start %p end %p\n",
319 attr, stride, sz, start, end); */
326 low_addr
= MIN2(low_addr
, start
);
327 high_addr
= MAX2(high_addr
, end
);
337 * Set up for drawing interleaved arrays that all live in one VBO
338 * or all live in user space.
339 * \param vbuffer returns vertex buffer info
340 * \param velements returns vertex element info
343 setup_interleaved_attribs(GLcontext
*ctx
,
344 const struct st_vertex_program
*vp
,
345 const struct st_vp_varient
*vpv
,
346 const struct gl_client_array
**arrays
,
349 struct pipe_vertex_buffer
*vbuffer
,
350 struct pipe_vertex_element velements
[])
352 struct st_context
*st
= st_context(ctx
);
353 struct pipe_context
*pipe
= st
->pipe
;
355 const GLubyte
*offset0
= NULL
;
357 for (attr
= 0; attr
< vpv
->num_inputs
; attr
++) {
358 const GLuint mesaAttr
= vp
->index_to_input
[attr
];
359 struct gl_buffer_object
*bufobj
= arrays
[mesaAttr
]->BufferObj
;
360 struct st_buffer_object
*stobj
= st_buffer_object(bufobj
);
361 GLsizei stride
= arrays
[mesaAttr
]->StrideB
;
363 /*printf("stobj %u = %p\n", attr, (void*)stobj);*/
366 const GLubyte
*low
, *high
;
368 get_arrays_bounds(vp
, vpv
, arrays
, max_index
, &low
, &high
);
369 /* debug_printf("buffer range: %p %p range %d max index %u\n",
370 low, high, high - low, max_index); */
375 pipe_user_buffer_create(pipe
->screen
, (void *) low
, high
- low
,
376 PIPE_BIND_VERTEX_BUFFER
);
377 vbuffer
->buffer_offset
= 0;
380 vbuffer
->buffer
= NULL
;
381 pipe_resource_reference(&vbuffer
->buffer
, stobj
->buffer
);
382 vbuffer
->buffer_offset
= pointer_to_offset(low
);
384 vbuffer
->stride
= stride
; /* in bytes */
385 vbuffer
->max_index
= max_index
;
388 velements
[attr
].src_offset
=
389 (unsigned) (arrays
[mesaAttr
]->Ptr
- offset0
);
390 velements
[attr
].instance_divisor
= 0;
391 velements
[attr
].vertex_buffer_index
= 0;
392 velements
[attr
].src_format
=
393 st_pipe_vertex_format(arrays
[mesaAttr
]->Type
,
394 arrays
[mesaAttr
]->Size
,
395 arrays
[mesaAttr
]->Format
,
396 arrays
[mesaAttr
]->Normalized
);
397 assert(velements
[attr
].src_format
);
403 * Set up a separate pipe_vertex_buffer and pipe_vertex_element for each
405 * \param vbuffer returns vertex buffer info
406 * \param velements returns vertex element info
409 setup_non_interleaved_attribs(GLcontext
*ctx
,
410 const struct st_vertex_program
*vp
,
411 const struct st_vp_varient
*vpv
,
412 const struct gl_client_array
**arrays
,
414 GLboolean
*userSpace
,
415 struct pipe_vertex_buffer vbuffer
[],
416 struct pipe_vertex_element velements
[])
418 struct st_context
*st
= st_context(ctx
);
419 struct pipe_context
*pipe
= st
->pipe
;
422 for (attr
= 0; attr
< vpv
->num_inputs
; attr
++) {
423 const GLuint mesaAttr
= vp
->index_to_input
[attr
];
424 struct gl_buffer_object
*bufobj
= arrays
[mesaAttr
]->BufferObj
;
425 GLsizei stride
= arrays
[mesaAttr
]->StrideB
;
427 *userSpace
= GL_FALSE
;
429 if (bufobj
&& bufobj
->Name
) {
430 /* Attribute data is in a VBO.
431 * Recall that for VBOs, the gl_client_array->Ptr field is
432 * really an offset from the start of the VBO, not a pointer.
434 struct st_buffer_object
*stobj
= st_buffer_object(bufobj
);
435 assert(stobj
->buffer
);
436 /*printf("stobj %u = %p\n", attr, (void*) stobj);*/
438 vbuffer
[attr
].buffer
= NULL
;
439 pipe_resource_reference(&vbuffer
[attr
].buffer
, stobj
->buffer
);
440 vbuffer
[attr
].buffer_offset
= pointer_to_offset(arrays
[mesaAttr
]->Ptr
);
441 velements
[attr
].src_offset
= 0;
444 /* attribute data is in user-space memory, not a VBO */
446 /*printf("user-space array %d stride %d\n", attr, stride);*/
448 *userSpace
= GL_TRUE
;
451 if (arrays
[mesaAttr
]->Ptr
) {
452 /* user's vertex array */
453 if (arrays
[mesaAttr
]->StrideB
) {
454 bytes
= arrays
[mesaAttr
]->StrideB
* (max_index
+ 1);
457 bytes
= arrays
[mesaAttr
]->Size
458 * _mesa_sizeof_type(arrays
[mesaAttr
]->Type
);
460 vbuffer
[attr
].buffer
=
461 pipe_user_buffer_create(pipe
->screen
,
462 (void *) arrays
[mesaAttr
]->Ptr
, bytes
,
463 PIPE_BIND_VERTEX_BUFFER
);
466 /* no array, use ctx->Current.Attrib[] value */
467 bytes
= sizeof(ctx
->Current
.Attrib
[0]);
468 vbuffer
[attr
].buffer
=
469 pipe_user_buffer_create(pipe
->screen
,
470 (void *) ctx
->Current
.Attrib
[mesaAttr
],
472 PIPE_BIND_VERTEX_BUFFER
);
476 vbuffer
[attr
].buffer_offset
= 0;
477 velements
[attr
].src_offset
= 0;
480 assert(velements
[attr
].src_offset
<= 2048); /* 11-bit field */
482 /* common-case setup */
483 vbuffer
[attr
].stride
= stride
; /* in bytes */
484 vbuffer
[attr
].max_index
= max_index
;
485 velements
[attr
].instance_divisor
= 0;
486 velements
[attr
].vertex_buffer_index
= attr
;
487 velements
[attr
].src_format
488 = st_pipe_vertex_format(arrays
[mesaAttr
]->Type
,
489 arrays
[mesaAttr
]->Size
,
490 arrays
[mesaAttr
]->Format
,
491 arrays
[mesaAttr
]->Normalized
);
492 assert(velements
[attr
].src_format
);
499 * Prior to drawing, check that any uniforms referenced by the
500 * current shader have been set. If a uniform has not been set,
504 check_uniforms(GLcontext
*ctx
)
506 const struct gl_shader_program
*shProg
= ctx
->Shader
.CurrentProgram
;
507 if (shProg
&& shProg
->LinkStatus
) {
509 for (i
= 0; i
< shProg
->Uniforms
->NumUniforms
; i
++) {
510 const struct gl_uniform
*u
= &shProg
->Uniforms
->Uniforms
[i
];
511 if (!u
->Initialized
) {
513 "Using shader with uninitialized uniform: %s",
522 * Translate OpenGL primtive type (GL_POINTS, GL_TRIANGLE_STRIP, etc) to
523 * the corresponding Gallium type.
526 translate_prim(const GLcontext
*ctx
, unsigned prim
)
528 /* GL prims should match Gallium prims, spot-check a few */
529 assert(GL_POINTS
== PIPE_PRIM_POINTS
);
530 assert(GL_QUADS
== PIPE_PRIM_QUADS
);
531 assert(GL_TRIANGLE_STRIP_ADJACENCY
== PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY
);
533 /* Avoid quadstrips if it's easy to do so:
534 * Note: it's imporant to do the correct trimming if we change the prim type!
535 * We do that wherever this function is called.
537 if (prim
== GL_QUAD_STRIP
&&
538 ctx
->Light
.ShadeModel
!= GL_FLAT
&&
539 ctx
->Polygon
.FrontMode
== GL_FILL
&&
540 ctx
->Polygon
.BackMode
== GL_FILL
)
541 prim
= GL_TRIANGLE_STRIP
;
549 * This function gets plugged into the VBO module and is called when
550 * we have something to render.
551 * Basically, translate the information into the format expected by gallium.
554 st_draw_vbo(GLcontext
*ctx
,
555 const struct gl_client_array
**arrays
,
556 const struct _mesa_prim
*prims
,
558 const struct _mesa_index_buffer
*ib
,
559 GLboolean index_bounds_valid
,
563 struct st_context
*st
= st_context(ctx
);
564 struct pipe_context
*pipe
= st
->pipe
;
565 const struct st_vertex_program
*vp
;
566 const struct st_vp_varient
*vpv
;
567 struct pipe_vertex_buffer vbuffer
[PIPE_MAX_SHADER_INPUTS
];
569 struct pipe_vertex_element velements
[PIPE_MAX_ATTRIBS
];
570 unsigned num_vbuffers
, num_velements
;
571 GLboolean userSpace
= GL_FALSE
;
572 GLboolean vertDataEdgeFlags
;
574 /* Mesa core state should have been validated already */
575 assert(ctx
->NewState
== 0x0);
577 /* Gallium probably doesn't want this in some cases. */
578 if (!index_bounds_valid
)
579 if (!vbo_all_varyings_in_vbos(arrays
))
580 vbo_get_minmax_index(ctx
, prims
, ib
, &min_index
, &max_index
);
582 /* sanity check for pointer arithmetic below */
583 assert(sizeof(arrays
[0]->Ptr
[0]) == 1);
585 vertDataEdgeFlags
= arrays
[VERT_ATTRIB_EDGEFLAG
]->BufferObj
&&
586 arrays
[VERT_ATTRIB_EDGEFLAG
]->BufferObj
->Name
;
587 if (vertDataEdgeFlags
!= st
->vertdata_edgeflags
) {
588 st
->vertdata_edgeflags
= vertDataEdgeFlags
;
589 st
->dirty
.st
|= ST_NEW_EDGEFLAGS_DATA
;
592 st_validate_state(st
);
594 /* must get these after state validation! */
596 vpv
= st
->vp_varient
;
599 if (MESA_VERBOSE
& VERBOSE_GLSL
) {
603 (void) check_uniforms
;
606 memset(velements
, 0, sizeof(struct pipe_vertex_element
) * vpv
->num_inputs
);
608 * Setup the vbuffer[] and velements[] arrays.
610 if (is_interleaved_arrays(vp
, vpv
, arrays
, &userSpace
)) {
611 /*printf("Draw interleaved\n");*/
612 setup_interleaved_attribs(ctx
, vp
, vpv
, arrays
, max_index
, userSpace
,
615 num_velements
= vpv
->num_inputs
;
616 if (num_velements
== 0)
620 /*printf("Draw non-interleaved\n");*/
621 setup_non_interleaved_attribs(ctx
, vp
, vpv
, arrays
, max_index
,
622 &userSpace
, vbuffer
, velements
);
623 num_vbuffers
= vpv
->num_inputs
;
624 num_velements
= vpv
->num_inputs
;
630 for (i
= 0; i
< num_vbuffers
; i
++) {
631 printf("buffers[%d].stride = %u\n", i
, vbuffer
[i
].stride
);
632 printf("buffers[%d].max_index = %u\n", i
, vbuffer
[i
].max_index
);
633 printf("buffers[%d].buffer_offset = %u\n", i
, vbuffer
[i
].buffer_offset
);
634 printf("buffers[%d].buffer = %p\n", i
, (void*) vbuffer
[i
].buffer
);
636 for (i
= 0; i
< num_velements
; i
++) {
637 printf("vlements[%d].vbuffer_index = %u\n", i
, velements
[i
].vertex_buffer_index
);
638 printf("vlements[%d].src_offset = %u\n", i
, velements
[i
].src_offset
);
639 printf("vlements[%d].format = %s\n", i
, util_format_name(velements
[i
].src_format
));
644 pipe
->set_vertex_buffers(pipe
, num_vbuffers
, vbuffer
);
645 cso_set_vertex_elements(st
->cso_context
, num_velements
, velements
);
647 if (num_vbuffers
== 0 || num_velements
== 0)
650 /* do actual drawing */
652 /* indexed primitive */
653 struct gl_buffer_object
*bufobj
= ib
->obj
;
654 struct pipe_resource
*indexBuf
= NULL
;
655 unsigned indexSize
, indexOffset
, i
;
658 case GL_UNSIGNED_INT
:
661 case GL_UNSIGNED_SHORT
:
664 case GL_UNSIGNED_BYTE
:
672 /* get/create the index buffer object */
673 if (bufobj
&& bufobj
->Name
) {
674 /* elements/indexes are in a real VBO */
675 struct st_buffer_object
*stobj
= st_buffer_object(bufobj
);
676 pipe_resource_reference(&indexBuf
, stobj
->buffer
);
677 indexOffset
= pointer_to_offset(ib
->ptr
) / indexSize
;
680 /* element/indicies are in user space memory */
681 indexBuf
= pipe_user_buffer_create(pipe
->screen
, (void *) ib
->ptr
,
682 ib
->count
* indexSize
,
683 PIPE_BIND_INDEX_BUFFER
);
688 if (pipe
->draw_range_elements
&& min_index
!= ~0 && max_index
!= ~0) {
689 /* XXX: exercise temporary path to pass min/max directly
690 * through to driver & draw module. These interfaces still
691 * need a bit of work...
693 for (i
= 0; i
< nr_prims
; i
++) {
694 unsigned vcount
= prims
[i
].count
;
695 unsigned prim
= translate_prim(ctx
, prims
[i
].mode
);
697 if (u_trim_pipe_prim(prims
[i
].mode
, &vcount
)) {
698 pipe
->draw_range_elements(pipe
, indexBuf
, indexSize
, 0,
699 min_index
, max_index
, prim
,
700 prims
[i
].start
+ indexOffset
, vcount
);
705 for (i
= 0; i
< nr_prims
; i
++) {
706 unsigned vcount
= prims
[i
].count
;
707 unsigned prim
= translate_prim(ctx
, prims
[i
].mode
);
709 if (u_trim_pipe_prim(prims
[i
].mode
, &vcount
)) {
710 if (prims
[i
].num_instances
== 1) {
711 pipe
->draw_elements(pipe
, indexBuf
,
715 prims
[i
].start
+ indexOffset
,
719 pipe
->draw_elements_instanced(pipe
, indexBuf
,
723 prims
[i
].start
+ indexOffset
,
725 0, /* startInstance */
726 prims
[i
].num_instances
);
732 pipe_resource_reference(&indexBuf
, NULL
);
738 for (i
= 0; i
< nr_prims
; i
++) {
739 unsigned vcount
= prims
[i
].count
;
740 unsigned prim
= translate_prim(ctx
, prims
[i
].mode
);
742 if (u_trim_pipe_prim(prims
[i
].mode
, &vcount
)) {
743 if (prims
[i
].num_instances
== 1) {
744 pipe
->draw_arrays(pipe
, prim
, prims
[i
].start
, vcount
);
747 pipe
->draw_arrays_instanced(pipe
, prim
,
750 0, /* startInstance */
751 prims
[i
].num_instances
);
757 /* unreference buffers (frees wrapped user-space buffer objects) */
758 for (attr
= 0; attr
< num_vbuffers
; attr
++) {
759 pipe_resource_reference(&vbuffer
[attr
].buffer
, NULL
);
760 assert(!vbuffer
[attr
].buffer
);
765 pipe
->set_vertex_buffers(pipe
, 0, NULL
);
770 void st_init_draw( struct st_context
*st
)
772 GLcontext
*ctx
= st
->ctx
;
774 vbo_set_draw_func(ctx
, st_draw_vbo
);
776 #if FEATURE_feedback || FEATURE_rastpos
777 st
->draw
= draw_create(st
->pipe
); /* for selection/feedback */
779 /* Disable draw options that might convert points/lines to tris, etc.
780 * as that would foul-up feedback/selection mode.
782 draw_wide_line_threshold(st
->draw
, 1000.0f
);
783 draw_wide_point_threshold(st
->draw
, 1000.0f
);
784 draw_enable_line_stipple(st
->draw
, FALSE
);
785 draw_enable_point_sprites(st
->draw
, FALSE
);
790 void st_destroy_draw( struct st_context
*st
)
792 #if FEATURE_feedback || FEATURE_rastpos
793 draw_destroy(st
->draw
);