st/mesa: set vertex arrays state only when necessary
[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 * 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.
33 *
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().
37 *
38 * Authors:
39 * Keith Whitwell <keith@tungstengraphics.com>
40 */
41
42
43 #include "main/imports.h"
44 #include "main/image.h"
45 #include "main/macros.h"
46 #include "main/mfeatures.h"
47 #include "program/prog_uniform.h"
48
49 #include "vbo/vbo.h"
50
51 #include "st_context.h"
52 #include "st_atom.h"
53 #include "st_cb_bufferobjects.h"
54 #include "st_draw.h"
55 #include "st_program.h"
56
57 #include "pipe/p_context.h"
58 #include "pipe/p_defines.h"
59 #include "util/u_inlines.h"
60 #include "util/u_format.h"
61 #include "util/u_prim.h"
62 #include "util/u_draw_quad.h"
63 #include "draw/draw_context.h"
64 #include "cso_cache/cso_context.h"
65
66
67 static GLuint double_types[4] = {
68 PIPE_FORMAT_R64_FLOAT,
69 PIPE_FORMAT_R64G64_FLOAT,
70 PIPE_FORMAT_R64G64B64_FLOAT,
71 PIPE_FORMAT_R64G64B64A64_FLOAT
72 };
73
74 static GLuint float_types[4] = {
75 PIPE_FORMAT_R32_FLOAT,
76 PIPE_FORMAT_R32G32_FLOAT,
77 PIPE_FORMAT_R32G32B32_FLOAT,
78 PIPE_FORMAT_R32G32B32A32_FLOAT
79 };
80
81 static GLuint half_float_types[4] = {
82 PIPE_FORMAT_R16_FLOAT,
83 PIPE_FORMAT_R16G16_FLOAT,
84 PIPE_FORMAT_R16G16B16_FLOAT,
85 PIPE_FORMAT_R16G16B16A16_FLOAT
86 };
87
88 static GLuint uint_types_norm[4] = {
89 PIPE_FORMAT_R32_UNORM,
90 PIPE_FORMAT_R32G32_UNORM,
91 PIPE_FORMAT_R32G32B32_UNORM,
92 PIPE_FORMAT_R32G32B32A32_UNORM
93 };
94
95 static GLuint uint_types_scale[4] = {
96 PIPE_FORMAT_R32_USCALED,
97 PIPE_FORMAT_R32G32_USCALED,
98 PIPE_FORMAT_R32G32B32_USCALED,
99 PIPE_FORMAT_R32G32B32A32_USCALED
100 };
101
102 static GLuint int_types_norm[4] = {
103 PIPE_FORMAT_R32_SNORM,
104 PIPE_FORMAT_R32G32_SNORM,
105 PIPE_FORMAT_R32G32B32_SNORM,
106 PIPE_FORMAT_R32G32B32A32_SNORM
107 };
108
109 static GLuint int_types_scale[4] = {
110 PIPE_FORMAT_R32_SSCALED,
111 PIPE_FORMAT_R32G32_SSCALED,
112 PIPE_FORMAT_R32G32B32_SSCALED,
113 PIPE_FORMAT_R32G32B32A32_SSCALED
114 };
115
116 static GLuint ushort_types_norm[4] = {
117 PIPE_FORMAT_R16_UNORM,
118 PIPE_FORMAT_R16G16_UNORM,
119 PIPE_FORMAT_R16G16B16_UNORM,
120 PIPE_FORMAT_R16G16B16A16_UNORM
121 };
122
123 static GLuint ushort_types_scale[4] = {
124 PIPE_FORMAT_R16_USCALED,
125 PIPE_FORMAT_R16G16_USCALED,
126 PIPE_FORMAT_R16G16B16_USCALED,
127 PIPE_FORMAT_R16G16B16A16_USCALED
128 };
129
130 static GLuint short_types_norm[4] = {
131 PIPE_FORMAT_R16_SNORM,
132 PIPE_FORMAT_R16G16_SNORM,
133 PIPE_FORMAT_R16G16B16_SNORM,
134 PIPE_FORMAT_R16G16B16A16_SNORM
135 };
136
137 static GLuint short_types_scale[4] = {
138 PIPE_FORMAT_R16_SSCALED,
139 PIPE_FORMAT_R16G16_SSCALED,
140 PIPE_FORMAT_R16G16B16_SSCALED,
141 PIPE_FORMAT_R16G16B16A16_SSCALED
142 };
143
144 static GLuint ubyte_types_norm[4] = {
145 PIPE_FORMAT_R8_UNORM,
146 PIPE_FORMAT_R8G8_UNORM,
147 PIPE_FORMAT_R8G8B8_UNORM,
148 PIPE_FORMAT_R8G8B8A8_UNORM
149 };
150
151 static GLuint ubyte_types_scale[4] = {
152 PIPE_FORMAT_R8_USCALED,
153 PIPE_FORMAT_R8G8_USCALED,
154 PIPE_FORMAT_R8G8B8_USCALED,
155 PIPE_FORMAT_R8G8B8A8_USCALED
156 };
157
158 static GLuint byte_types_norm[4] = {
159 PIPE_FORMAT_R8_SNORM,
160 PIPE_FORMAT_R8G8_SNORM,
161 PIPE_FORMAT_R8G8B8_SNORM,
162 PIPE_FORMAT_R8G8B8A8_SNORM
163 };
164
165 static GLuint byte_types_scale[4] = {
166 PIPE_FORMAT_R8_SSCALED,
167 PIPE_FORMAT_R8G8_SSCALED,
168 PIPE_FORMAT_R8G8B8_SSCALED,
169 PIPE_FORMAT_R8G8B8A8_SSCALED
170 };
171
172 static GLuint fixed_types[4] = {
173 PIPE_FORMAT_R32_FIXED,
174 PIPE_FORMAT_R32G32_FIXED,
175 PIPE_FORMAT_R32G32B32_FIXED,
176 PIPE_FORMAT_R32G32B32A32_FIXED
177 };
178
179
180
181 /**
182 * Return a PIPE_FORMAT_x for the given GL datatype and size.
183 */
184 GLuint
185 st_pipe_vertex_format(GLenum type, GLuint size, GLenum format,
186 GLboolean normalized)
187 {
188 assert((type >= GL_BYTE && type <= GL_DOUBLE) ||
189 type == GL_FIXED || type == GL_HALF_FLOAT);
190 assert(size >= 1);
191 assert(size <= 4);
192 assert(format == GL_RGBA || format == GL_BGRA);
193
194 if (format == GL_BGRA) {
195 /* this is an odd-ball case */
196 assert(type == GL_UNSIGNED_BYTE);
197 assert(normalized);
198 return PIPE_FORMAT_B8G8R8A8_UNORM;
199 }
200
201 if (normalized) {
202 switch (type) {
203 case GL_DOUBLE: return double_types[size-1];
204 case GL_FLOAT: return float_types[size-1];
205 case GL_HALF_FLOAT: return half_float_types[size-1];
206 case GL_INT: return int_types_norm[size-1];
207 case GL_SHORT: return short_types_norm[size-1];
208 case GL_BYTE: return byte_types_norm[size-1];
209 case GL_UNSIGNED_INT: return uint_types_norm[size-1];
210 case GL_UNSIGNED_SHORT: return ushort_types_norm[size-1];
211 case GL_UNSIGNED_BYTE: return ubyte_types_norm[size-1];
212 case GL_FIXED: return fixed_types[size-1];
213 default: assert(0); return 0;
214 }
215 }
216 else {
217 switch (type) {
218 case GL_DOUBLE: return double_types[size-1];
219 case GL_FLOAT: return float_types[size-1];
220 case GL_HALF_FLOAT: return half_float_types[size-1];
221 case GL_INT: return int_types_scale[size-1];
222 case GL_SHORT: return short_types_scale[size-1];
223 case GL_BYTE: return byte_types_scale[size-1];
224 case GL_UNSIGNED_INT: return uint_types_scale[size-1];
225 case GL_UNSIGNED_SHORT: return ushort_types_scale[size-1];
226 case GL_UNSIGNED_BYTE: return ubyte_types_scale[size-1];
227 case GL_FIXED: return fixed_types[size-1];
228 default: assert(0); return 0;
229 }
230 }
231 return 0; /* silence compiler warning */
232 }
233
234
235
236
237
238 /**
239 * Examine the active arrays to determine if we have interleaved
240 * vertex arrays all living in one VBO, or all living in user space.
241 * \param userSpace returns whether the arrays are in user space.
242 */
243 static GLboolean
244 is_interleaved_arrays(const struct st_vertex_program *vp,
245 const struct st_vp_variant *vpv,
246 const struct gl_client_array **arrays)
247 {
248 GLuint attr;
249 const struct gl_buffer_object *firstBufObj = NULL;
250 GLint firstStride = -1;
251 const GLubyte *client_addr = NULL;
252
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 */
257
258 if (firstStride < 0) {
259 firstStride = stride;
260 }
261 else if (firstStride != stride) {
262 return GL_FALSE;
263 }
264
265 if (!bufObj || !bufObj->Name) {
266 /* Try to detect if the client-space arrays are
267 * "close" to each other.
268 */
269 if (!client_addr) {
270 client_addr = arrays[mesaAttr]->Ptr;
271 }
272 else if (abs(arrays[mesaAttr]->Ptr - client_addr) > firstStride) {
273 /* arrays start too far apart */
274 return GL_FALSE;
275 }
276 }
277 else if (!firstBufObj) {
278 firstBufObj = bufObj;
279 }
280 else if (bufObj != firstBufObj) {
281 return GL_FALSE;
282 }
283 }
284
285 return GL_TRUE;
286 }
287
288
289 /**
290 * Set up for drawing interleaved arrays that all live in one VBO
291 * or all live in user space.
292 * \param vbuffer returns vertex buffer info
293 * \param velements returns vertex element info
294 */
295 static void
296 setup_interleaved_attribs(struct gl_context *ctx,
297 const struct st_vertex_program *vp,
298 const struct st_vp_variant *vpv,
299 const struct gl_client_array **arrays,
300 struct pipe_vertex_buffer *vbuffer,
301 struct pipe_vertex_element velements[],
302 unsigned max_index)
303 {
304 struct st_context *st = st_context(ctx);
305 struct pipe_context *pipe = st->pipe;
306 GLuint attr;
307 const GLubyte *low_addr = NULL;
308
309 /* Find the lowest address. */
310 for (attr = 0; attr < vpv->num_inputs; attr++) {
311 const GLubyte *start = arrays[vp->index_to_input[attr]]->Ptr;
312
313 low_addr = !low_addr ? start : MIN2(low_addr, start);
314 }
315
316 for (attr = 0; attr < vpv->num_inputs; attr++) {
317 const GLuint mesaAttr = vp->index_to_input[attr];
318 struct gl_buffer_object *bufobj = arrays[mesaAttr]->BufferObj;
319 struct st_buffer_object *stobj = st_buffer_object(bufobj);
320 GLsizei stride = arrays[mesaAttr]->StrideB;
321
322 if (attr == 0) {
323 if (bufobj && bufobj->Name) {
324 vbuffer->buffer = NULL;
325 pipe_resource_reference(&vbuffer->buffer, stobj->buffer);
326 vbuffer->buffer_offset = pointer_to_offset(low_addr);
327 } else {
328 vbuffer->buffer =
329 pipe_user_buffer_create(pipe->screen, (void*)low_addr,
330 stride * (max_index + 1),
331 PIPE_BIND_VERTEX_BUFFER);
332 vbuffer->buffer_offset = 0;
333 }
334 vbuffer->stride = stride; /* in bytes */
335 }
336
337 velements[attr].src_offset =
338 (unsigned) (arrays[mesaAttr]->Ptr - low_addr);
339 velements[attr].instance_divisor = arrays[mesaAttr]->InstanceDivisor;
340 velements[attr].vertex_buffer_index = 0;
341 velements[attr].src_format =
342 st_pipe_vertex_format(arrays[mesaAttr]->Type,
343 arrays[mesaAttr]->Size,
344 arrays[mesaAttr]->Format,
345 arrays[mesaAttr]->Normalized);
346 assert(velements[attr].src_format);
347 }
348 }
349
350
351 /**
352 * Set up a separate pipe_vertex_buffer and pipe_vertex_element for each
353 * vertex attribute.
354 * \param vbuffer returns vertex buffer info
355 * \param velements returns vertex element info
356 */
357 static void
358 setup_non_interleaved_attribs(struct gl_context *ctx,
359 const struct st_vertex_program *vp,
360 const struct st_vp_variant *vpv,
361 const struct gl_client_array **arrays,
362 struct pipe_vertex_buffer vbuffer[],
363 struct pipe_vertex_element velements[],
364 unsigned max_index)
365 {
366 struct st_context *st = st_context(ctx);
367 struct pipe_context *pipe = st->pipe;
368 GLuint attr;
369
370 for (attr = 0; attr < vpv->num_inputs; attr++) {
371 const GLuint mesaAttr = vp->index_to_input[attr];
372 struct gl_buffer_object *bufobj = arrays[mesaAttr]->BufferObj;
373 GLsizei stride = arrays[mesaAttr]->StrideB;
374
375 if (bufobj && bufobj->Name) {
376 /* Attribute data is in a VBO.
377 * Recall that for VBOs, the gl_client_array->Ptr field is
378 * really an offset from the start of the VBO, not a pointer.
379 */
380 struct st_buffer_object *stobj = st_buffer_object(bufobj);
381 assert(stobj->buffer);
382
383 vbuffer[attr].buffer = NULL;
384 pipe_resource_reference(&vbuffer[attr].buffer, stobj->buffer);
385 vbuffer[attr].buffer_offset = pointer_to_offset(arrays[mesaAttr]->Ptr);
386 }
387 else {
388 /* wrap user data */
389 if (arrays[mesaAttr]->Ptr) {
390 vbuffer[attr].buffer =
391 pipe_user_buffer_create(pipe->screen,
392 (void *) arrays[mesaAttr]->Ptr,
393 stride * (max_index + 1),
394 PIPE_BIND_VERTEX_BUFFER);
395 }
396 else {
397 /* no array, use ctx->Current.Attrib[] value */
398 uint bytes = sizeof(ctx->Current.Attrib[0]);
399 vbuffer[attr].buffer =
400 pipe_user_buffer_create(pipe->screen,
401 (void *) ctx->Current.Attrib[mesaAttr],
402 bytes,
403 PIPE_BIND_VERTEX_BUFFER);
404 stride = 0;
405 }
406
407 vbuffer[attr].buffer_offset = 0;
408 }
409
410 /* common-case setup */
411 vbuffer[attr].stride = stride; /* in bytes */
412
413 velements[attr].src_offset = 0;
414 velements[attr].instance_divisor = arrays[mesaAttr]->InstanceDivisor;
415 velements[attr].vertex_buffer_index = attr;
416 velements[attr].src_format
417 = st_pipe_vertex_format(arrays[mesaAttr]->Type,
418 arrays[mesaAttr]->Size,
419 arrays[mesaAttr]->Format,
420 arrays[mesaAttr]->Normalized);
421 assert(velements[attr].src_format);
422 }
423 }
424
425
426 static void
427 setup_index_buffer(struct gl_context *ctx,
428 const struct _mesa_index_buffer *ib,
429 struct pipe_index_buffer *ibuffer)
430 {
431 struct st_context *st = st_context(ctx);
432 struct pipe_context *pipe = st->pipe;
433
434 memset(ibuffer, 0, sizeof(*ibuffer));
435 if (ib) {
436 struct gl_buffer_object *bufobj = ib->obj;
437
438 switch (ib->type) {
439 case GL_UNSIGNED_INT:
440 ibuffer->index_size = 4;
441 break;
442 case GL_UNSIGNED_SHORT:
443 ibuffer->index_size = 2;
444 break;
445 case GL_UNSIGNED_BYTE:
446 ibuffer->index_size = 1;
447 break;
448 default:
449 assert(0);
450 return;
451 }
452
453 /* get/create the index buffer object */
454 if (bufobj && bufobj->Name) {
455 /* elements/indexes are in a real VBO */
456 struct st_buffer_object *stobj = st_buffer_object(bufobj);
457 pipe_resource_reference(&ibuffer->buffer, stobj->buffer);
458 ibuffer->offset = pointer_to_offset(ib->ptr);
459 }
460 else {
461 /* element/indicies are in user space memory */
462 ibuffer->buffer =
463 pipe_user_buffer_create(pipe->screen, (void *) ib->ptr,
464 ib->count * ibuffer->index_size,
465 PIPE_BIND_INDEX_BUFFER);
466 }
467 }
468 }
469
470 /**
471 * Prior to drawing, check that any uniforms referenced by the
472 * current shader have been set. If a uniform has not been set,
473 * issue a warning.
474 */
475 static void
476 check_uniforms(struct gl_context *ctx)
477 {
478 struct gl_shader_program *shProg[3] = {
479 ctx->Shader.CurrentVertexProgram,
480 ctx->Shader.CurrentGeometryProgram,
481 ctx->Shader.CurrentFragmentProgram,
482 };
483 unsigned j;
484
485 for (j = 0; j < 3; j++) {
486 unsigned i;
487
488 if (shProg[j] == NULL || !shProg[j]->LinkStatus)
489 continue;
490
491 for (i = 0; i < shProg[j]->Uniforms->NumUniforms; i++) {
492 const struct gl_uniform *u = &shProg[j]->Uniforms->Uniforms[i];
493 if (!u->Initialized) {
494 _mesa_warning(ctx,
495 "Using shader with uninitialized uniform: %s",
496 u->Name);
497 }
498 }
499 }
500 }
501
502
503 /**
504 * Translate OpenGL primtive type (GL_POINTS, GL_TRIANGLE_STRIP, etc) to
505 * the corresponding Gallium type.
506 */
507 static unsigned
508 translate_prim(const struct gl_context *ctx, unsigned prim)
509 {
510 /* GL prims should match Gallium prims, spot-check a few */
511 assert(GL_POINTS == PIPE_PRIM_POINTS);
512 assert(GL_QUADS == PIPE_PRIM_QUADS);
513 assert(GL_TRIANGLE_STRIP_ADJACENCY == PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY);
514
515 /* Avoid quadstrips if it's easy to do so:
516 * Note: it's imporant to do the correct trimming if we change the prim type!
517 * We do that wherever this function is called.
518 */
519 if (prim == GL_QUAD_STRIP &&
520 ctx->Light.ShadeModel != GL_FLAT &&
521 ctx->Polygon.FrontMode == GL_FILL &&
522 ctx->Polygon.BackMode == GL_FILL)
523 prim = GL_TRIANGLE_STRIP;
524
525 return prim;
526 }
527
528
529 static void
530 st_validate_varrays(struct gl_context *ctx,
531 const struct gl_client_array **arrays,
532 unsigned max_index)
533 {
534 struct st_context *st = st_context(ctx);
535 const struct st_vertex_program *vp;
536 const struct st_vp_variant *vpv;
537 struct pipe_vertex_buffer vbuffer[PIPE_MAX_SHADER_INPUTS];
538 struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS];
539 unsigned num_vbuffers, num_velements;
540 GLuint attr;
541
542 /* must get these after state validation! */
543 vp = st->vp;
544 vpv = st->vp_variant;
545
546 memset(velements, 0, sizeof(struct pipe_vertex_element) * vpv->num_inputs);
547 /*
548 * Setup the vbuffer[] and velements[] arrays.
549 */
550 if (is_interleaved_arrays(vp, vpv, arrays)) {
551 setup_interleaved_attribs(ctx, vp, vpv, arrays, vbuffer, velements,
552 max_index);
553 num_vbuffers = 1;
554 num_velements = vpv->num_inputs;
555 if (num_velements == 0)
556 num_vbuffers = 0;
557 }
558 else {
559 setup_non_interleaved_attribs(ctx, vp, vpv, arrays,
560 vbuffer, velements, max_index);
561 num_vbuffers = vpv->num_inputs;
562 num_velements = vpv->num_inputs;
563 }
564
565 cso_set_vertex_buffers(st->cso_context, num_vbuffers, vbuffer);
566 cso_set_vertex_elements(st->cso_context, num_velements, velements);
567
568 /* unreference buffers (frees wrapped user-space buffer objects)
569 * This is OK, because the pipe driver should reference buffers by itself
570 * in set_vertex_buffers. */
571 for (attr = 0; attr < num_vbuffers; attr++) {
572 pipe_resource_reference(&vbuffer[attr].buffer, NULL);
573 assert(!vbuffer[attr].buffer);
574 }
575 }
576
577
578 /**
579 * This function gets plugged into the VBO module and is called when
580 * we have something to render.
581 * Basically, translate the information into the format expected by gallium.
582 */
583 void
584 st_draw_vbo(struct gl_context *ctx,
585 const struct gl_client_array **arrays,
586 const struct _mesa_prim *prims,
587 GLuint nr_prims,
588 const struct _mesa_index_buffer *ib,
589 GLboolean index_bounds_valid,
590 GLuint min_index,
591 GLuint max_index)
592 {
593 struct st_context *st = st_context(ctx);
594 struct pipe_context *pipe = st->pipe;
595 struct pipe_index_buffer ibuffer;
596 struct pipe_draw_info info;
597 unsigned i;
598 GLboolean new_array =
599 st->dirty.st && (st->dirty.mesa & (_NEW_ARRAY | _NEW_PROGRAM)) != 0;
600
601 /* Mesa core state should have been validated already */
602 assert(ctx->NewState == 0x0);
603
604 if (ib) {
605 /* Gallium probably doesn't want this in some cases. */
606 if (!index_bounds_valid)
607 if (!vbo_all_varyings_in_vbos(arrays))
608 vbo_get_minmax_index(ctx, prims, ib, &min_index, &max_index);
609 } else {
610 /* Get min/max index for non-indexed drawing. */
611 min_index = ~0;
612 max_index = 0;
613
614 for (i = 0; i < nr_prims; i++) {
615 min_index = MIN2(min_index, prims[i].start);
616 max_index = MAX2(max_index, prims[i].start + prims[i].count - 1);
617 }
618 }
619
620 /* Validate state. */
621 if (st->dirty.st) {
622 GLboolean vertDataEdgeFlags;
623
624 /* sanity check for pointer arithmetic below */
625 assert(sizeof(arrays[0]->Ptr[0]) == 1);
626
627 vertDataEdgeFlags = arrays[VERT_ATTRIB_EDGEFLAG]->BufferObj &&
628 arrays[VERT_ATTRIB_EDGEFLAG]->BufferObj->Name;
629 if (vertDataEdgeFlags != st->vertdata_edgeflags) {
630 st->vertdata_edgeflags = vertDataEdgeFlags;
631 st->dirty.st |= ST_NEW_EDGEFLAGS_DATA;
632 }
633
634 st_validate_state(st);
635
636 if (new_array) {
637 st_validate_varrays(ctx, arrays, max_index);
638 }
639
640 #if 0
641 if (MESA_VERBOSE & VERBOSE_GLSL) {
642 check_uniforms(ctx);
643 }
644 #else
645 (void) check_uniforms;
646 #endif
647 }
648
649 setup_index_buffer(ctx, ib, &ibuffer);
650 pipe->set_index_buffer(pipe, &ibuffer);
651
652 util_draw_init_info(&info);
653 if (ib) {
654 info.indexed = TRUE;
655 if (min_index != ~0 && max_index != ~0) {
656 info.min_index = min_index;
657 info.max_index = max_index;
658 }
659 }
660
661 info.primitive_restart = st->ctx->Array.PrimitiveRestart;
662 info.restart_index = st->ctx->Array.RestartIndex;
663
664 /* do actual drawing */
665 for (i = 0; i < nr_prims; i++) {
666 info.mode = translate_prim( ctx, prims[i].mode );
667 info.start = prims[i].start;
668 info.count = prims[i].count;
669 info.instance_count = prims[i].num_instances;
670 info.index_bias = prims[i].basevertex;
671 if (!ib) {
672 info.min_index = info.start;
673 info.max_index = info.start + info.count - 1;
674 }
675
676 if (u_trim_pipe_prim(info.mode, &info.count))
677 pipe->draw_vbo(pipe, &info);
678 }
679
680 pipe_resource_reference(&ibuffer.buffer, NULL);
681 }
682
683
684 void st_init_draw( struct st_context *st )
685 {
686 struct gl_context *ctx = st->ctx;
687
688 vbo_set_draw_func(ctx, st_draw_vbo);
689
690 #if FEATURE_feedback || FEATURE_rastpos
691 st->draw = draw_create(st->pipe); /* for selection/feedback */
692
693 /* Disable draw options that might convert points/lines to tris, etc.
694 * as that would foul-up feedback/selection mode.
695 */
696 draw_wide_line_threshold(st->draw, 1000.0f);
697 draw_wide_point_threshold(st->draw, 1000.0f);
698 draw_enable_line_stipple(st->draw, FALSE);
699 draw_enable_point_sprites(st->draw, FALSE);
700 #endif
701 }
702
703
704 void st_destroy_draw( struct st_context *st )
705 {
706 #if FEATURE_feedback || FEATURE_rastpos
707 draw_destroy(st->draw);
708 #endif
709 }
710
711