Merge commit 'origin/gallium-0.1' into gallium-0.2
[mesa.git] / src / mesa / state_tracker / st_draw.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 /*
29 * Authors:
30 * Keith Whitwell <keith@tungstengraphics.com>
31 */
32
33 #include "main/imports.h"
34 #include "main/image.h"
35 #include "main/macros.h"
36 #include "shader/prog_uniform.h"
37
38 #include "vbo/vbo.h"
39
40 #include "st_context.h"
41 #include "st_atom.h"
42 #include "st_cb_bufferobjects.h"
43 #include "st_draw.h"
44 #include "st_program.h"
45
46 #include "pipe/p_context.h"
47 #include "pipe/p_defines.h"
48 #include "pipe/p_inlines.h"
49
50
51 static GLuint double_types[4] = {
52 PIPE_FORMAT_R64_FLOAT,
53 PIPE_FORMAT_R64G64_FLOAT,
54 PIPE_FORMAT_R64G64B64_FLOAT,
55 PIPE_FORMAT_R64G64B64A64_FLOAT
56 };
57
58 static GLuint float_types[4] = {
59 PIPE_FORMAT_R32_FLOAT,
60 PIPE_FORMAT_R32G32_FLOAT,
61 PIPE_FORMAT_R32G32B32_FLOAT,
62 PIPE_FORMAT_R32G32B32A32_FLOAT
63 };
64
65 static GLuint uint_types_norm[4] = {
66 PIPE_FORMAT_R32_UNORM,
67 PIPE_FORMAT_R32G32_UNORM,
68 PIPE_FORMAT_R32G32B32_UNORM,
69 PIPE_FORMAT_R32G32B32A32_UNORM
70 };
71
72 static GLuint uint_types_scale[4] = {
73 PIPE_FORMAT_R32_USCALED,
74 PIPE_FORMAT_R32G32_USCALED,
75 PIPE_FORMAT_R32G32B32_USCALED,
76 PIPE_FORMAT_R32G32B32A32_USCALED
77 };
78
79 static GLuint int_types_norm[4] = {
80 PIPE_FORMAT_R32_SNORM,
81 PIPE_FORMAT_R32G32_SNORM,
82 PIPE_FORMAT_R32G32B32_SNORM,
83 PIPE_FORMAT_R32G32B32A32_SNORM
84 };
85
86 static GLuint int_types_scale[4] = {
87 PIPE_FORMAT_R32_SSCALED,
88 PIPE_FORMAT_R32G32_SSCALED,
89 PIPE_FORMAT_R32G32B32_SSCALED,
90 PIPE_FORMAT_R32G32B32A32_SSCALED
91 };
92
93 static GLuint ushort_types_norm[4] = {
94 PIPE_FORMAT_R16_UNORM,
95 PIPE_FORMAT_R16G16_UNORM,
96 PIPE_FORMAT_R16G16B16_UNORM,
97 PIPE_FORMAT_R16G16B16A16_UNORM
98 };
99
100 static GLuint ushort_types_scale[4] = {
101 PIPE_FORMAT_R16_USCALED,
102 PIPE_FORMAT_R16G16_USCALED,
103 PIPE_FORMAT_R16G16B16_USCALED,
104 PIPE_FORMAT_R16G16B16A16_USCALED
105 };
106
107 static GLuint short_types_norm[4] = {
108 PIPE_FORMAT_R16_SNORM,
109 PIPE_FORMAT_R16G16_SNORM,
110 PIPE_FORMAT_R16G16B16_SNORM,
111 PIPE_FORMAT_R16G16B16A16_SNORM
112 };
113
114 static GLuint short_types_scale[4] = {
115 PIPE_FORMAT_R16_SSCALED,
116 PIPE_FORMAT_R16G16_SSCALED,
117 PIPE_FORMAT_R16G16B16_SSCALED,
118 PIPE_FORMAT_R16G16B16A16_SSCALED
119 };
120
121 static GLuint ubyte_types_norm[4] = {
122 PIPE_FORMAT_R8_UNORM,
123 PIPE_FORMAT_R8G8_UNORM,
124 PIPE_FORMAT_R8G8B8_UNORM,
125 PIPE_FORMAT_R8G8B8A8_UNORM
126 };
127
128 static GLuint ubyte_types_scale[4] = {
129 PIPE_FORMAT_R8_USCALED,
130 PIPE_FORMAT_R8G8_USCALED,
131 PIPE_FORMAT_R8G8B8_USCALED,
132 PIPE_FORMAT_R8G8B8A8_USCALED
133 };
134
135 static GLuint byte_types_norm[4] = {
136 PIPE_FORMAT_R8_SNORM,
137 PIPE_FORMAT_R8G8_SNORM,
138 PIPE_FORMAT_R8G8B8_SNORM,
139 PIPE_FORMAT_R8G8B8A8_SNORM
140 };
141
142 static GLuint byte_types_scale[4] = {
143 PIPE_FORMAT_R8_SSCALED,
144 PIPE_FORMAT_R8G8_SSCALED,
145 PIPE_FORMAT_R8G8B8_SSCALED,
146 PIPE_FORMAT_R8G8B8A8_SSCALED
147 };
148
149 static GLuint fixed_types[4] = {
150 PIPE_FORMAT_R32_FIXED,
151 PIPE_FORMAT_R32G32_FIXED,
152 PIPE_FORMAT_R32G32B32_FIXED,
153 PIPE_FORMAT_R32G32B32A32_FIXED
154 };
155
156
157
158 /**
159 * Return a PIPE_FORMAT_x for the given GL datatype and size.
160 */
161 GLuint
162 st_pipe_vertex_format(GLenum type, GLuint size, GLboolean normalized)
163 {
164 assert((type >= GL_BYTE && type <= GL_DOUBLE) ||
165 type == GL_FIXED);
166 assert(size >= 1);
167 assert(size <= 4);
168
169 if (normalized) {
170 switch (type) {
171 case GL_DOUBLE: return double_types[size-1];
172 case GL_FLOAT: return float_types[size-1];
173 case GL_INT: return int_types_norm[size-1];
174 case GL_SHORT: return short_types_norm[size-1];
175 case GL_BYTE: return byte_types_norm[size-1];
176 case GL_UNSIGNED_INT: return uint_types_norm[size-1];
177 case GL_UNSIGNED_SHORT: return ushort_types_norm[size-1];
178 case GL_UNSIGNED_BYTE: return ubyte_types_norm[size-1];
179 case GL_FIXED: return fixed_types[size-1];
180 default: assert(0); return 0;
181 }
182 }
183 else {
184 switch (type) {
185 case GL_DOUBLE: return double_types[size-1];
186 case GL_FLOAT: return float_types[size-1];
187 case GL_INT: return int_types_scale[size-1];
188 case GL_SHORT: return short_types_scale[size-1];
189 case GL_BYTE: return byte_types_scale[size-1];
190 case GL_UNSIGNED_INT: return uint_types_scale[size-1];
191 case GL_UNSIGNED_SHORT: return ushort_types_scale[size-1];
192 case GL_UNSIGNED_BYTE: return ubyte_types_scale[size-1];
193 case GL_FIXED: return fixed_types[size-1];
194 default: assert(0); return 0;
195 }
196 }
197 return 0; /* silence compiler warning */
198 }
199
200
201 /*
202 * If edge flags are needed, setup an bitvector of flags and call
203 * pipe->set_edgeflags().
204 * XXX memleak: need to free the returned pointer at some point
205 */
206 static void *
207 setup_edgeflags(GLcontext *ctx, GLenum primMode, GLint start, GLint count,
208 const struct gl_client_array *array)
209 {
210 struct pipe_context *pipe = ctx->st->pipe;
211
212 if ((primMode == GL_TRIANGLES ||
213 primMode == GL_QUADS ||
214 primMode == GL_POLYGON) &&
215 (ctx->Polygon.FrontMode != GL_FILL ||
216 ctx->Polygon.BackMode != GL_FILL)) {
217 /* need edge flags */
218 GLint i;
219 unsigned *vec;
220 struct st_buffer_object *stobj = st_buffer_object(array->BufferObj);
221 ubyte *map;
222
223 if (!stobj)
224 return NULL;
225
226 vec = (unsigned *) calloc(sizeof(unsigned), (count + 31) / 32);
227 if (!vec)
228 return NULL;
229
230 map = pipe_buffer_map(pipe->screen, stobj->buffer, PIPE_BUFFER_USAGE_CPU_READ);
231 map = ADD_POINTERS(map, array->Ptr);
232
233 for (i = 0; i < count; i++) {
234 if (*((float *) map))
235 vec[i/32] |= 1 << (i % 32);
236
237 map += array->StrideB;
238 }
239
240 pipe_buffer_unmap(pipe->screen, stobj->buffer);
241
242 pipe->set_edgeflags(pipe, vec);
243
244 return vec;
245 }
246 else {
247 /* edge flags not needed */
248 pipe->set_edgeflags(pipe, NULL);
249 return NULL;
250 }
251 }
252
253
254 /**
255 * Examine the active arrays to determine if we have interleaved
256 * vertex arrays all living in one VBO, or all living in user space.
257 * \param userSpace returns whether the arrays are in user space.
258 */
259 static GLboolean
260 is_interleaved_arrays(const struct st_vertex_program *vp,
261 const struct gl_client_array **arrays,
262 GLboolean *userSpace)
263 {
264 GLuint attr;
265 const struct gl_buffer_object *firstBufObj = NULL;
266 GLint firstStride = -1;
267 GLuint num_client_arrays = 0;
268 const GLubyte *client_addr = NULL;
269
270 for (attr = 0; attr < vp->num_inputs; attr++) {
271 const GLuint mesaAttr = vp->index_to_input[attr];
272 const struct gl_buffer_object *bufObj = arrays[mesaAttr]->BufferObj;
273 const GLsizei stride = arrays[mesaAttr]->StrideB; /* in bytes */
274
275 if (firstStride < 0) {
276 firstStride = stride;
277 }
278 else if (firstStride != stride) {
279 return GL_FALSE;
280 }
281
282 if (!bufObj || !bufObj->Name) {
283 num_client_arrays++;
284 /* Try to detect if the client-space arrays are
285 * "close" to each other.
286 */
287 if (!client_addr) {
288 client_addr = arrays[mesaAttr]->Ptr;
289 }
290 else if (abs(arrays[mesaAttr]->Ptr - client_addr) > firstStride) {
291 /* arrays start too far apart */
292 return GL_FALSE;
293 }
294 }
295 else if (!firstBufObj) {
296 firstBufObj = bufObj;
297 }
298 else if (bufObj != firstBufObj) {
299 return GL_FALSE;
300 }
301 }
302
303 *userSpace = (num_client_arrays == vp->num_inputs);
304 /* printf("user space: %d (%d %d)\n", (int) *userSpace,num_client_arrays,vp->num_inputs); */
305
306 return GL_TRUE;
307 }
308
309
310 /**
311 * Compute the memory range occupied by the arrays.
312 */
313 static void
314 get_arrays_bounds(const struct st_vertex_program *vp,
315 const struct gl_client_array **arrays,
316 GLuint max_index,
317 const GLubyte **low, const GLubyte **high)
318 {
319 const GLubyte *low_addr = NULL;
320 GLuint attr;
321 GLint stride;
322
323 for (attr = 0; attr < vp->num_inputs; attr++) {
324 const GLuint mesaAttr = vp->index_to_input[attr];
325 const GLubyte *start = arrays[mesaAttr]->Ptr;
326 stride = arrays[mesaAttr]->StrideB;
327 if (attr == 0) {
328 low_addr = start;
329 }
330 else {
331 low_addr = MIN2(low_addr, start);
332 }
333 }
334
335 *low = low_addr;
336 *high = low_addr + (max_index + 1) * stride;
337 }
338
339
340 /**
341 * Set up for drawing interleaved arrays that all live in one VBO
342 * or all live in user space.
343 * \param vbuffer returns vertex buffer info
344 * \param velements returns vertex element info
345 */
346 static void
347 setup_interleaved_attribs(GLcontext *ctx,
348 const struct st_vertex_program *vp,
349 const struct gl_client_array **arrays,
350 GLuint max_index,
351 GLboolean userSpace,
352 struct pipe_vertex_buffer *vbuffer,
353 struct pipe_vertex_element velements[])
354 {
355 struct pipe_context *pipe = ctx->st->pipe;
356 GLuint attr;
357 const GLubyte *offset0;
358
359 for (attr = 0; attr < vp->num_inputs; attr++) {
360 const GLuint mesaAttr = vp->index_to_input[attr];
361 struct gl_buffer_object *bufobj = arrays[mesaAttr]->BufferObj;
362 struct st_buffer_object *stobj = st_buffer_object(bufobj);
363 GLsizei stride = arrays[mesaAttr]->StrideB;
364
365 /*printf("stobj %u = %p\n", attr, (void*)stobj);*/
366
367 if (attr == 0) {
368 const GLubyte *low, *high;
369
370 get_arrays_bounds(vp, arrays, max_index, &low, &high);
371 /*printf("buffer range: %p %p %d\n", low, high, high-low);*/
372
373 offset0 = low;
374 if (userSpace) {
375 vbuffer->buffer =
376 pipe_user_buffer_create(pipe->screen, (void *) low, high - low);
377 vbuffer->buffer_offset = 0;
378 }
379 else {
380 vbuffer->buffer = NULL;
381 pipe_buffer_reference(pipe->screen, &vbuffer->buffer, stobj->buffer);
382 vbuffer->buffer_offset = (unsigned) arrays[mesaAttr]->Ptr;
383 }
384 vbuffer->pitch = stride; /* in bytes */
385 vbuffer->max_index = max_index;
386 }
387
388 velements[attr].src_offset =
389 (unsigned) (arrays[mesaAttr]->Ptr - offset0);
390 velements[attr].vertex_buffer_index = 0;
391 velements[attr].nr_components = arrays[mesaAttr]->Size;
392 velements[attr].src_format =
393 st_pipe_vertex_format(arrays[mesaAttr]->Type,
394 arrays[mesaAttr]->Size,
395 arrays[mesaAttr]->Normalized);
396 assert(velements[attr].src_format);
397 }
398 }
399
400
401 /**
402 * Set up a separate pipe_vertex_buffer and pipe_vertex_element for each
403 * vertex attribute.
404 * \param vbuffer returns vertex buffer info
405 * \param velements returns vertex element info
406 */
407 static void
408 setup_non_interleaved_attribs(GLcontext *ctx,
409 const struct st_vertex_program *vp,
410 const struct gl_client_array **arrays,
411 GLuint max_index,
412 GLboolean *userSpace,
413 struct pipe_vertex_buffer vbuffer[],
414 struct pipe_vertex_element velements[])
415 {
416 struct pipe_context *pipe = ctx->st->pipe;
417 GLuint attr;
418
419 for (attr = 0; attr < vp->num_inputs; attr++) {
420 const GLuint mesaAttr = vp->index_to_input[attr];
421 struct gl_buffer_object *bufobj = arrays[mesaAttr]->BufferObj;
422 GLsizei stride = arrays[mesaAttr]->StrideB;
423
424 *userSpace = GL_FALSE;
425
426 if (bufobj && bufobj->Name) {
427 /* Attribute data is in a VBO.
428 * Recall that for VBOs, the gl_client_array->Ptr field is
429 * really an offset from the start of the VBO, not a pointer.
430 */
431 struct st_buffer_object *stobj = st_buffer_object(bufobj);
432 assert(stobj->buffer);
433 /*printf("stobj %u = %p\n", attr, (void*) stobj);*/
434
435 vbuffer[attr].buffer = NULL;
436 pipe_buffer_reference(pipe->screen, &vbuffer[attr].buffer, stobj->buffer);
437 vbuffer[attr].buffer_offset = (unsigned) arrays[mesaAttr]->Ptr;
438 velements[attr].src_offset = 0;
439 }
440 else {
441 /* attribute data is in user-space memory, not a VBO */
442 uint bytes;
443 /*printf("user-space array %d stride %d\n", attr, stride);*/
444
445 *userSpace = GL_TRUE;
446
447 /* wrap user data */
448 if (arrays[mesaAttr]->Ptr) {
449 /* user's vertex array */
450 if (arrays[mesaAttr]->StrideB) {
451 bytes = arrays[mesaAttr]->StrideB * (max_index + 1);
452 }
453 else {
454 bytes = arrays[mesaAttr]->Size
455 * _mesa_sizeof_type(arrays[mesaAttr]->Type);
456 }
457 vbuffer[attr].buffer = pipe_user_buffer_create(pipe->screen,
458 (void *) arrays[mesaAttr]->Ptr, bytes);
459 }
460 else {
461 /* no array, use ctx->Current.Attrib[] value */
462 bytes = sizeof(ctx->Current.Attrib[0]);
463 vbuffer[attr].buffer = pipe_user_buffer_create(pipe->screen,
464 (void *) ctx->Current.Attrib[mesaAttr], bytes);
465 stride = 0;
466 }
467
468 vbuffer[attr].buffer_offset = 0;
469 velements[attr].src_offset = 0;
470 }
471
472 assert(velements[attr].src_offset <= 2048); /* 11-bit field */
473
474 /* common-case setup */
475 vbuffer[attr].pitch = stride; /* in bytes */
476 vbuffer[attr].max_index = max_index;
477 velements[attr].vertex_buffer_index = attr;
478 velements[attr].nr_components = arrays[mesaAttr]->Size;
479 velements[attr].src_format
480 = st_pipe_vertex_format(arrays[mesaAttr]->Type,
481 arrays[mesaAttr]->Size,
482 arrays[mesaAttr]->Normalized);
483 assert(velements[attr].src_format);
484 }
485 }
486
487
488
489 /**
490 * Prior to drawing, check that any uniforms referenced by the
491 * current shader have been set. If a uniform has not been set,
492 * issue a warning.
493 */
494 static void
495 check_uniforms(GLcontext *ctx)
496 {
497 const struct gl_shader_program *shProg = ctx->Shader.CurrentProgram;
498 if (shProg && shProg->LinkStatus) {
499 GLuint i;
500 for (i = 0; i < shProg->Uniforms->NumUniforms; i++) {
501 const struct gl_uniform *u = &shProg->Uniforms->Uniforms[i];
502 if (!u->Initialized) {
503 _mesa_warning(ctx,
504 "Using shader with uninitialized uniform: %s",
505 u->Name);
506 }
507 }
508 }
509 }
510
511
512 /**
513 * This function gets plugged into the VBO module and is called when
514 * we have something to render.
515 * Basically, translate the information into the format expected by gallium.
516 */
517 void
518 st_draw_vbo(GLcontext *ctx,
519 const struct gl_client_array **arrays,
520 const struct _mesa_prim *prims,
521 GLuint nr_prims,
522 const struct _mesa_index_buffer *ib,
523 GLuint min_index,
524 GLuint max_index)
525 {
526 struct pipe_context *pipe = ctx->st->pipe;
527 const struct st_vertex_program *vp;
528 const struct pipe_shader_state *vs;
529 struct pipe_vertex_buffer vbuffer[PIPE_MAX_SHADER_INPUTS];
530 GLuint attr;
531 struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS];
532 unsigned num_vbuffers, num_velements;
533 GLboolean userSpace;
534
535 /* sanity check for pointer arithmetic below */
536 assert(sizeof(arrays[0]->Ptr[0]) == 1);
537
538 st_validate_state(ctx->st);
539
540 /* must get these after state validation! */
541 vp = ctx->st->vp;
542 vs = &ctx->st->vp->state;
543
544 if (MESA_VERBOSE & VERBOSE_GLSL) {
545 check_uniforms(ctx);
546 }
547
548 /*
549 * Setup the vbuffer[] and velements[] arrays.
550 */
551 if (is_interleaved_arrays(vp, arrays, &userSpace)) {
552 /*printf("Draw interleaved\n");*/
553 setup_interleaved_attribs(ctx, vp, arrays, max_index, userSpace,
554 vbuffer, velements);
555 num_vbuffers = 1;
556 num_velements = vp->num_inputs;
557 if (num_velements == 0)
558 num_vbuffers = 0;
559 }
560 else {
561 /*printf("Draw non-interleaved\n");*/
562 setup_non_interleaved_attribs(ctx, vp, arrays, max_index,
563 &userSpace, vbuffer, velements);
564 num_vbuffers = vp->num_inputs;
565 num_velements = vp->num_inputs;
566 }
567
568 #if 0
569 {
570 GLuint i;
571 for (i = 0; i < num_vbuffers; i++) {
572 printf("buffers[%d].pitch = %u\n", i, vbuffer[i].pitch);
573 printf("buffers[%d].max_index = %u\n", i, vbuffer[i].max_index);
574 printf("buffers[%d].buffer_offset = %u\n", i, vbuffer[i].buffer_offset);
575 printf("buffers[%d].buffer = %p\n", i, (void*) vbuffer[i].buffer);
576 }
577 for (i = 0; i < num_velements; i++) {
578 printf("vlements[%d].vbuffer_index = %u\n", i, velements[i].vertex_buffer_index);
579 printf("vlements[%d].src_offset = %u\n", i, velements[i].src_offset);
580 printf("vlements[%d].nr_comps = %u\n", i, velements[i].nr_components);
581 printf("vlements[%d].format = %s\n", i, pf_name(velements[i].src_format));
582 }
583 }
584 #endif
585
586 pipe->set_vertex_buffers(pipe, num_vbuffers, vbuffer);
587 pipe->set_vertex_elements(pipe, num_velements, velements);
588
589 if (num_vbuffers == 0 || num_velements == 0)
590 return;
591
592 /* do actual drawing */
593 if (ib) {
594 /* indexed primitive */
595 struct gl_buffer_object *bufobj = ib->obj;
596 struct pipe_buffer *indexBuf = NULL;
597 unsigned indexSize, indexOffset, i;
598
599 switch (ib->type) {
600 case GL_UNSIGNED_INT:
601 indexSize = 4;
602 break;
603 case GL_UNSIGNED_SHORT:
604 indexSize = 2;
605 break;
606 case GL_UNSIGNED_BYTE:
607 indexSize = 1;
608 break;
609 default:
610 assert(0);
611 return;
612 }
613
614 /* get/create the index buffer object */
615 if (bufobj && bufobj->Name) {
616 /* elements/indexes are in a real VBO */
617 struct st_buffer_object *stobj = st_buffer_object(bufobj);
618 pipe_buffer_reference(pipe->screen, &indexBuf, stobj->buffer);
619 indexOffset = (unsigned) ib->ptr / indexSize;
620 }
621 else {
622 /* element/indicies are in user space memory */
623 indexBuf = pipe_user_buffer_create(pipe->screen, (void *) ib->ptr,
624 ib->count * indexSize);
625 indexOffset = 0;
626 }
627
628 /* draw */
629 if (nr_prims == 1 && pipe->draw_range_elements != NULL) {
630 i = 0;
631
632 /* XXX: exercise temporary path to pass min/max directly
633 * through to driver & draw module. These interfaces still
634 * need a bit of work...
635 */
636 setup_edgeflags(ctx, prims[i].mode,
637 prims[i].start + indexOffset, prims[i].count,
638 arrays[VERT_ATTRIB_EDGEFLAG]);
639
640 pipe->draw_range_elements(pipe, indexBuf, indexSize,
641 min_index,
642 max_index,
643 prims[i].mode,
644 prims[i].start + indexOffset, prims[i].count);
645 }
646 else {
647 for (i = 0; i < nr_prims; i++) {
648 setup_edgeflags(ctx, prims[i].mode,
649 prims[i].start + indexOffset, prims[i].count,
650 arrays[VERT_ATTRIB_EDGEFLAG]);
651
652 pipe->draw_elements(pipe, indexBuf, indexSize,
653 prims[i].mode,
654 prims[i].start + indexOffset, prims[i].count);
655 }
656 }
657
658 pipe_buffer_reference(pipe->screen, &indexBuf, NULL);
659 }
660 else {
661 /* non-indexed */
662 GLuint i;
663 for (i = 0; i < nr_prims; i++) {
664 setup_edgeflags(ctx, prims[i].mode,
665 prims[i].start, prims[i].count,
666 arrays[VERT_ATTRIB_EDGEFLAG]);
667
668 pipe->draw_arrays(pipe, prims[i].mode, prims[i].start, prims[i].count);
669 }
670 }
671
672 /* unreference buffers (frees wrapped user-space buffer objects) */
673 for (attr = 0; attr < num_vbuffers; attr++) {
674 pipe_buffer_reference(pipe->screen, &vbuffer[attr].buffer, NULL);
675 assert(!vbuffer[attr].buffer);
676 }
677
678 if (userSpace)
679 {
680 pipe->set_vertex_buffers(pipe, 0, NULL);
681 }
682 }
683
684
685 void st_init_draw( struct st_context *st )
686 {
687 GLcontext *ctx = st->ctx;
688
689 vbo_set_draw_func(ctx, st_draw_vbo);
690 }
691
692
693 void st_destroy_draw( struct st_context *st )
694 {
695 }
696
697