Merge branch 'mesa_7_5_branch'
[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, GLenum format,
163 GLboolean normalized)
164 {
165 assert((type >= GL_BYTE && type <= GL_DOUBLE) ||
166 type == GL_FIXED);
167 assert(size >= 1);
168 assert(size <= 4);
169 assert(format == GL_RGBA || format == GL_BGRA);
170
171 if (format == GL_BGRA) {
172 /* this is an odd-ball case */
173 assert(type == GL_UNSIGNED_BYTE);
174 assert(normalized);
175 return PIPE_FORMAT_B8G8R8A8_UNORM;
176 }
177
178 if (normalized) {
179 switch (type) {
180 case GL_DOUBLE: return double_types[size-1];
181 case GL_FLOAT: return float_types[size-1];
182 case GL_INT: return int_types_norm[size-1];
183 case GL_SHORT: return short_types_norm[size-1];
184 case GL_BYTE: return byte_types_norm[size-1];
185 case GL_UNSIGNED_INT: return uint_types_norm[size-1];
186 case GL_UNSIGNED_SHORT: return ushort_types_norm[size-1];
187 case GL_UNSIGNED_BYTE: return ubyte_types_norm[size-1];
188 case GL_FIXED: return fixed_types[size-1];
189 default: assert(0); return 0;
190 }
191 }
192 else {
193 switch (type) {
194 case GL_DOUBLE: return double_types[size-1];
195 case GL_FLOAT: return float_types[size-1];
196 case GL_INT: return int_types_scale[size-1];
197 case GL_SHORT: return short_types_scale[size-1];
198 case GL_BYTE: return byte_types_scale[size-1];
199 case GL_UNSIGNED_INT: return uint_types_scale[size-1];
200 case GL_UNSIGNED_SHORT: return ushort_types_scale[size-1];
201 case GL_UNSIGNED_BYTE: return ubyte_types_scale[size-1];
202 case GL_FIXED: return fixed_types[size-1];
203 default: assert(0); return 0;
204 }
205 }
206 return 0; /* silence compiler warning */
207 }
208
209
210 /*
211 * If edge flags are needed, setup an bitvector of flags and call
212 * pipe->set_edgeflags().
213 * XXX memleak: need to free the returned pointer at some point
214 */
215 static void *
216 setup_edgeflags(GLcontext *ctx, GLenum primMode, GLint start, GLint count,
217 const struct gl_client_array *array)
218 {
219 struct pipe_context *pipe = ctx->st->pipe;
220
221 if ((primMode == GL_TRIANGLES ||
222 primMode == GL_QUADS ||
223 primMode == GL_POLYGON) &&
224 (ctx->Polygon.FrontMode != GL_FILL ||
225 ctx->Polygon.BackMode != GL_FILL)) {
226 /* need edge flags */
227 GLint i;
228 unsigned *vec;
229 struct st_buffer_object *stobj = st_buffer_object(array->BufferObj);
230 ubyte *map;
231
232 if (!stobj)
233 return NULL;
234
235 vec = (unsigned *) _mesa_calloc(sizeof(unsigned) * ((count + 31) / 32));
236 if (!vec)
237 return NULL;
238
239 map = pipe_buffer_map(pipe->screen, stobj->buffer, PIPE_BUFFER_USAGE_CPU_READ);
240 map = ADD_POINTERS(map, array->Ptr);
241
242 for (i = 0; i < count; i++) {
243 if (*((float *) map))
244 vec[i/32] |= 1 << (i % 32);
245
246 map += array->StrideB;
247 }
248
249 pipe_buffer_unmap(pipe->screen, stobj->buffer);
250
251 pipe->set_edgeflags(pipe, vec);
252
253 return vec;
254 }
255 else {
256 /* edge flags not needed */
257 pipe->set_edgeflags(pipe, NULL);
258 return NULL;
259 }
260 }
261
262
263 /**
264 * Examine the active arrays to determine if we have interleaved
265 * vertex arrays all living in one VBO, or all living in user space.
266 * \param userSpace returns whether the arrays are in user space.
267 */
268 static GLboolean
269 is_interleaved_arrays(const struct st_vertex_program *vp,
270 const struct gl_client_array **arrays,
271 GLboolean *userSpace)
272 {
273 GLuint attr;
274 const struct gl_buffer_object *firstBufObj = NULL;
275 GLint firstStride = -1;
276 GLuint num_client_arrays = 0;
277 const GLubyte *client_addr = NULL;
278
279 for (attr = 0; attr < vp->num_inputs; attr++) {
280 const GLuint mesaAttr = vp->index_to_input[attr];
281 const struct gl_buffer_object *bufObj = arrays[mesaAttr]->BufferObj;
282 const GLsizei stride = arrays[mesaAttr]->StrideB; /* in bytes */
283
284 if (firstStride < 0) {
285 firstStride = stride;
286 }
287 else if (firstStride != stride) {
288 return GL_FALSE;
289 }
290
291 if (!bufObj || !bufObj->Name) {
292 num_client_arrays++;
293 /* Try to detect if the client-space arrays are
294 * "close" to each other.
295 */
296 if (!client_addr) {
297 client_addr = arrays[mesaAttr]->Ptr;
298 }
299 else if (abs(arrays[mesaAttr]->Ptr - client_addr) > firstStride) {
300 /* arrays start too far apart */
301 return GL_FALSE;
302 }
303 }
304 else if (!firstBufObj) {
305 firstBufObj = bufObj;
306 }
307 else if (bufObj != firstBufObj) {
308 return GL_FALSE;
309 }
310 }
311
312 *userSpace = (num_client_arrays == vp->num_inputs);
313 /* printf("user space: %d (%d %d)\n", (int) *userSpace,num_client_arrays,vp->num_inputs); */
314
315 return GL_TRUE;
316 }
317
318
319 /**
320 * Compute the memory range occupied by the arrays.
321 */
322 static void
323 get_arrays_bounds(const struct st_vertex_program *vp,
324 const struct gl_client_array **arrays,
325 GLuint max_index,
326 const GLubyte **low, const GLubyte **high)
327 {
328 const GLubyte *low_addr = NULL;
329 GLuint attr;
330 GLint stride;
331
332 for (attr = 0; attr < vp->num_inputs; attr++) {
333 const GLuint mesaAttr = vp->index_to_input[attr];
334 const GLubyte *start = arrays[mesaAttr]->Ptr;
335 stride = arrays[mesaAttr]->StrideB;
336 if (attr == 0) {
337 low_addr = start;
338 }
339 else {
340 low_addr = MIN2(low_addr, start);
341 }
342 }
343
344 *low = low_addr;
345 *high = low_addr + (max_index + 1) * stride;
346 }
347
348
349 /**
350 * Set up for drawing interleaved arrays that all live in one VBO
351 * or all live in user space.
352 * \param vbuffer returns vertex buffer info
353 * \param velements returns vertex element info
354 */
355 static void
356 setup_interleaved_attribs(GLcontext *ctx,
357 const struct st_vertex_program *vp,
358 const struct gl_client_array **arrays,
359 GLuint max_index,
360 GLboolean userSpace,
361 struct pipe_vertex_buffer *vbuffer,
362 struct pipe_vertex_element velements[])
363 {
364 struct pipe_context *pipe = ctx->st->pipe;
365 GLuint attr;
366 const GLubyte *offset0;
367
368 for (attr = 0; attr < vp->num_inputs; attr++) {
369 const GLuint mesaAttr = vp->index_to_input[attr];
370 struct gl_buffer_object *bufobj = arrays[mesaAttr]->BufferObj;
371 struct st_buffer_object *stobj = st_buffer_object(bufobj);
372 GLsizei stride = arrays[mesaAttr]->StrideB;
373
374 /*printf("stobj %u = %p\n", attr, (void*)stobj);*/
375
376 if (attr == 0) {
377 const GLubyte *low, *high;
378
379 get_arrays_bounds(vp, arrays, max_index, &low, &high);
380 /*printf("buffer range: %p %p %d\n", low, high, high-low);*/
381
382 offset0 = low;
383 if (userSpace) {
384 vbuffer->buffer =
385 pipe_user_buffer_create(pipe->screen, (void *) low, high - low);
386 vbuffer->buffer_offset = 0;
387 }
388 else {
389 vbuffer->buffer = NULL;
390 pipe_buffer_reference(&vbuffer->buffer, stobj->buffer);
391 vbuffer->buffer_offset = pointer_to_offset(low);
392 }
393 vbuffer->stride = stride; /* in bytes */
394 vbuffer->max_index = max_index;
395 }
396
397 velements[attr].src_offset =
398 (unsigned) (arrays[mesaAttr]->Ptr - offset0);
399 velements[attr].vertex_buffer_index = 0;
400 velements[attr].nr_components = arrays[mesaAttr]->Size;
401 velements[attr].src_format =
402 st_pipe_vertex_format(arrays[mesaAttr]->Type,
403 arrays[mesaAttr]->Size,
404 arrays[mesaAttr]->Format,
405 arrays[mesaAttr]->Normalized);
406 assert(velements[attr].src_format);
407 }
408 }
409
410
411 /**
412 * Set up a separate pipe_vertex_buffer and pipe_vertex_element for each
413 * vertex attribute.
414 * \param vbuffer returns vertex buffer info
415 * \param velements returns vertex element info
416 */
417 static void
418 setup_non_interleaved_attribs(GLcontext *ctx,
419 const struct st_vertex_program *vp,
420 const struct gl_client_array **arrays,
421 GLuint max_index,
422 GLboolean *userSpace,
423 struct pipe_vertex_buffer vbuffer[],
424 struct pipe_vertex_element velements[])
425 {
426 struct pipe_context *pipe = ctx->st->pipe;
427 GLuint attr;
428
429 for (attr = 0; attr < vp->num_inputs; attr++) {
430 const GLuint mesaAttr = vp->index_to_input[attr];
431 struct gl_buffer_object *bufobj = arrays[mesaAttr]->BufferObj;
432 GLsizei stride = arrays[mesaAttr]->StrideB;
433
434 *userSpace = GL_FALSE;
435
436 if (bufobj && bufobj->Name) {
437 /* Attribute data is in a VBO.
438 * Recall that for VBOs, the gl_client_array->Ptr field is
439 * really an offset from the start of the VBO, not a pointer.
440 */
441 struct st_buffer_object *stobj = st_buffer_object(bufobj);
442 assert(stobj->buffer);
443 /*printf("stobj %u = %p\n", attr, (void*) stobj);*/
444
445 vbuffer[attr].buffer = NULL;
446 pipe_buffer_reference(&vbuffer[attr].buffer, stobj->buffer);
447 vbuffer[attr].buffer_offset = pointer_to_offset(arrays[mesaAttr]->Ptr);
448 velements[attr].src_offset = 0;
449 }
450 else {
451 /* attribute data is in user-space memory, not a VBO */
452 uint bytes;
453 /*printf("user-space array %d stride %d\n", attr, stride);*/
454
455 *userSpace = GL_TRUE;
456
457 /* wrap user data */
458 if (arrays[mesaAttr]->Ptr) {
459 /* user's vertex array */
460 if (arrays[mesaAttr]->StrideB) {
461 bytes = arrays[mesaAttr]->StrideB * (max_index + 1);
462 }
463 else {
464 bytes = arrays[mesaAttr]->Size
465 * _mesa_sizeof_type(arrays[mesaAttr]->Type);
466 }
467 vbuffer[attr].buffer = pipe_user_buffer_create(pipe->screen,
468 (void *) arrays[mesaAttr]->Ptr, bytes);
469 }
470 else {
471 /* no array, use ctx->Current.Attrib[] value */
472 bytes = sizeof(ctx->Current.Attrib[0]);
473 vbuffer[attr].buffer = pipe_user_buffer_create(pipe->screen,
474 (void *) ctx->Current.Attrib[mesaAttr], bytes);
475 stride = 0;
476 }
477
478 vbuffer[attr].buffer_offset = 0;
479 velements[attr].src_offset = 0;
480 }
481
482 assert(velements[attr].src_offset <= 2048); /* 11-bit field */
483
484 /* common-case setup */
485 vbuffer[attr].stride = stride; /* in bytes */
486 vbuffer[attr].max_index = max_index;
487 velements[attr].vertex_buffer_index = attr;
488 velements[attr].nr_components = arrays[mesaAttr]->Size;
489 velements[attr].src_format
490 = st_pipe_vertex_format(arrays[mesaAttr]->Type,
491 arrays[mesaAttr]->Size,
492 arrays[mesaAttr]->Format,
493 arrays[mesaAttr]->Normalized);
494 assert(velements[attr].src_format);
495 }
496 }
497
498
499
500 /**
501 * Prior to drawing, check that any uniforms referenced by the
502 * current shader have been set. If a uniform has not been set,
503 * issue a warning.
504 */
505 static void
506 check_uniforms(GLcontext *ctx)
507 {
508 const struct gl_shader_program *shProg = ctx->Shader.CurrentProgram;
509 if (shProg && shProg->LinkStatus) {
510 GLuint i;
511 for (i = 0; i < shProg->Uniforms->NumUniforms; i++) {
512 const struct gl_uniform *u = &shProg->Uniforms->Uniforms[i];
513 if (!u->Initialized) {
514 _mesa_warning(ctx,
515 "Using shader with uninitialized uniform: %s",
516 u->Name);
517 }
518 }
519 }
520 }
521
522
523 /**
524 * This function gets plugged into the VBO module and is called when
525 * we have something to render.
526 * Basically, translate the information into the format expected by gallium.
527 */
528 void
529 st_draw_vbo(GLcontext *ctx,
530 const struct gl_client_array **arrays,
531 const struct _mesa_prim *prims,
532 GLuint nr_prims,
533 const struct _mesa_index_buffer *ib,
534 GLuint min_index,
535 GLuint max_index)
536 {
537 struct pipe_context *pipe = ctx->st->pipe;
538 const struct st_vertex_program *vp;
539 const struct pipe_shader_state *vs;
540 struct pipe_vertex_buffer vbuffer[PIPE_MAX_SHADER_INPUTS];
541 GLuint attr;
542 struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS];
543 unsigned num_vbuffers, num_velements;
544 GLboolean userSpace;
545
546 /* sanity check for pointer arithmetic below */
547 assert(sizeof(arrays[0]->Ptr[0]) == 1);
548
549 st_validate_state(ctx->st);
550
551 /* must get these after state validation! */
552 vp = ctx->st->vp;
553 vs = &ctx->st->vp->state;
554
555 #if 0
556 if (MESA_VERBOSE & VERBOSE_GLSL) {
557 check_uniforms(ctx);
558 }
559 #else
560 (void) check_uniforms;
561 #endif
562
563 /*
564 * Setup the vbuffer[] and velements[] arrays.
565 */
566 if (is_interleaved_arrays(vp, arrays, &userSpace)) {
567 /*printf("Draw interleaved\n");*/
568 setup_interleaved_attribs(ctx, vp, arrays, max_index, userSpace,
569 vbuffer, velements);
570 num_vbuffers = 1;
571 num_velements = vp->num_inputs;
572 if (num_velements == 0)
573 num_vbuffers = 0;
574 }
575 else {
576 /*printf("Draw non-interleaved\n");*/
577 setup_non_interleaved_attribs(ctx, vp, arrays, max_index,
578 &userSpace, vbuffer, velements);
579 num_vbuffers = vp->num_inputs;
580 num_velements = vp->num_inputs;
581 }
582
583 #if 0
584 {
585 GLuint i;
586 for (i = 0; i < num_vbuffers; i++) {
587 printf("buffers[%d].stride = %u\n", i, vbuffer[i].stride);
588 printf("buffers[%d].max_index = %u\n", i, vbuffer[i].max_index);
589 printf("buffers[%d].buffer_offset = %u\n", i, vbuffer[i].buffer_offset);
590 printf("buffers[%d].buffer = %p\n", i, (void*) vbuffer[i].buffer);
591 }
592 for (i = 0; i < num_velements; i++) {
593 printf("vlements[%d].vbuffer_index = %u\n", i, velements[i].vertex_buffer_index);
594 printf("vlements[%d].src_offset = %u\n", i, velements[i].src_offset);
595 printf("vlements[%d].nr_comps = %u\n", i, velements[i].nr_components);
596 printf("vlements[%d].format = %s\n", i, pf_name(velements[i].src_format));
597 }
598 }
599 #endif
600
601 pipe->set_vertex_buffers(pipe, num_vbuffers, vbuffer);
602 pipe->set_vertex_elements(pipe, num_velements, velements);
603
604 if (num_vbuffers == 0 || num_velements == 0)
605 return;
606
607 /* do actual drawing */
608 if (ib) {
609 /* indexed primitive */
610 struct gl_buffer_object *bufobj = ib->obj;
611 struct pipe_buffer *indexBuf = NULL;
612 unsigned indexSize, indexOffset, i;
613
614 switch (ib->type) {
615 case GL_UNSIGNED_INT:
616 indexSize = 4;
617 break;
618 case GL_UNSIGNED_SHORT:
619 indexSize = 2;
620 break;
621 case GL_UNSIGNED_BYTE:
622 indexSize = 1;
623 break;
624 default:
625 assert(0);
626 return;
627 }
628
629 /* get/create the index buffer object */
630 if (bufobj && bufobj->Name) {
631 /* elements/indexes are in a real VBO */
632 struct st_buffer_object *stobj = st_buffer_object(bufobj);
633 pipe_buffer_reference(&indexBuf, stobj->buffer);
634 indexOffset = pointer_to_offset(ib->ptr) / indexSize;
635 }
636 else {
637 /* element/indicies are in user space memory */
638 indexBuf = pipe_user_buffer_create(pipe->screen, (void *) ib->ptr,
639 ib->count * indexSize);
640 indexOffset = 0;
641 }
642
643 /* draw */
644 if (nr_prims == 1 && pipe->draw_range_elements != NULL) {
645 i = 0;
646
647 /* XXX: exercise temporary path to pass min/max directly
648 * through to driver & draw module. These interfaces still
649 * need a bit of work...
650 */
651 setup_edgeflags(ctx, prims[i].mode,
652 prims[i].start + indexOffset, prims[i].count,
653 arrays[VERT_ATTRIB_EDGEFLAG]);
654
655 pipe->draw_range_elements(pipe, indexBuf, indexSize,
656 min_index,
657 max_index,
658 prims[i].mode,
659 prims[i].start + indexOffset, prims[i].count);
660 }
661 else {
662 for (i = 0; i < nr_prims; i++) {
663 setup_edgeflags(ctx, prims[i].mode,
664 prims[i].start + indexOffset, prims[i].count,
665 arrays[VERT_ATTRIB_EDGEFLAG]);
666
667 pipe->draw_elements(pipe, indexBuf, indexSize,
668 prims[i].mode,
669 prims[i].start + indexOffset, prims[i].count);
670 }
671 }
672
673 pipe_buffer_reference(&indexBuf, NULL);
674 }
675 else {
676 /* non-indexed */
677 GLuint i;
678 for (i = 0; i < nr_prims; i++) {
679 setup_edgeflags(ctx, prims[i].mode,
680 prims[i].start, prims[i].count,
681 arrays[VERT_ATTRIB_EDGEFLAG]);
682
683 pipe->draw_arrays(pipe, prims[i].mode, prims[i].start, prims[i].count);
684 }
685 }
686
687 /* unreference buffers (frees wrapped user-space buffer objects) */
688 for (attr = 0; attr < num_vbuffers; attr++) {
689 pipe_buffer_reference(&vbuffer[attr].buffer, NULL);
690 assert(!vbuffer[attr].buffer);
691 }
692
693 if (userSpace)
694 {
695 pipe->set_vertex_buffers(pipe, 0, NULL);
696 }
697 }
698
699
700 void st_init_draw( struct st_context *st )
701 {
702 GLcontext *ctx = st->ctx;
703
704 vbo_set_draw_func(ctx, st_draw_vbo);
705 }
706
707
708 void st_destroy_draw( struct st_context *st )
709 {
710 }
711
712