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 "main/mfeatures.h"
47 #include "program/prog_uniform.h"
51 #include "st_context.h"
53 #include "st_cb_bufferobjects.h"
55 #include "st_program.h"
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"
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
182 * Return a PIPE_FORMAT_x for the given GL datatype and size.
185 st_pipe_vertex_format(GLenum type
, GLuint size
, GLenum format
,
186 GLboolean normalized
)
188 assert((type
>= GL_BYTE
&& type
<= GL_DOUBLE
) ||
189 type
== GL_FIXED
|| type
== GL_HALF_FLOAT
);
192 assert(format
== GL_RGBA
|| format
== GL_BGRA
);
194 if (format
== GL_BGRA
) {
195 /* this is an odd-ball case */
196 assert(type
== GL_UNSIGNED_BYTE
);
198 return PIPE_FORMAT_B8G8R8A8_UNORM
;
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;
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;
231 return 0; /* silence compiler warning */
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.
244 is_interleaved_arrays(const struct st_vertex_program
*vp
,
245 const struct st_vp_variant
*vpv
,
246 const struct gl_client_array
**arrays
)
249 const struct gl_buffer_object
*firstBufObj
= NULL
;
250 GLint firstStride
= -1;
251 const GLubyte
*client_addr
= NULL
;
252 GLboolean user_memory
;
254 for (attr
= 0; attr
< vpv
->num_inputs
; attr
++) {
255 const GLuint mesaAttr
= vp
->index_to_input
[attr
];
256 const struct gl_buffer_object
*bufObj
= arrays
[mesaAttr
]->BufferObj
;
257 const GLsizei stride
= arrays
[mesaAttr
]->StrideB
; /* in bytes */
259 if (firstStride
< 0) {
260 firstStride
= stride
;
261 user_memory
= !bufObj
|| !bufObj
->Name
;
263 else if (firstStride
!= stride
) {
267 if (!bufObj
|| !bufObj
->Name
) {
268 /* Try to detect if the client-space arrays are
269 * "close" to each other.
275 client_addr
= arrays
[mesaAttr
]->Ptr
;
277 else if (abs(arrays
[mesaAttr
]->Ptr
- client_addr
) > firstStride
) {
278 /* arrays start too far apart */
282 else if (!firstBufObj
) {
286 firstBufObj
= bufObj
;
288 else if (bufObj
!= firstBufObj
) {
298 * Set up for drawing interleaved arrays that all live in one VBO
299 * or all live in user space.
300 * \param vbuffer returns vertex buffer info
301 * \param velements returns vertex element info
304 setup_interleaved_attribs(struct gl_context
*ctx
,
305 const struct st_vertex_program
*vp
,
306 const struct st_vp_variant
*vpv
,
307 const struct gl_client_array
**arrays
,
308 struct pipe_vertex_buffer
*vbuffer
,
309 struct pipe_vertex_element velements
[],
311 unsigned num_instances
)
313 struct st_context
*st
= st_context(ctx
);
314 struct pipe_context
*pipe
= st
->pipe
;
316 const GLubyte
*low_addr
= NULL
;
318 /* Find the lowest address. */
319 if(vpv
->num_inputs
) {
320 low_addr
= arrays
[vp
->index_to_input
[0]]->Ptr
;
322 for (attr
= 1; attr
< vpv
->num_inputs
; attr
++) {
323 const GLubyte
*start
= arrays
[vp
->index_to_input
[attr
]]->Ptr
;
324 low_addr
= MIN2(low_addr
, start
);
328 for (attr
= 0; attr
< vpv
->num_inputs
; attr
++) {
329 const GLuint mesaAttr
= vp
->index_to_input
[attr
];
330 struct gl_buffer_object
*bufobj
= arrays
[mesaAttr
]->BufferObj
;
331 struct st_buffer_object
*stobj
= st_buffer_object(bufobj
);
332 GLsizei stride
= arrays
[mesaAttr
]->StrideB
;
335 if (bufobj
&& bufobj
->Name
) {
336 vbuffer
->buffer
= NULL
;
337 pipe_resource_reference(&vbuffer
->buffer
, stobj
->buffer
);
338 vbuffer
->buffer_offset
= pointer_to_offset(low_addr
);
340 uint divisor
= arrays
[mesaAttr
]->InstanceDivisor
;
341 uint length
= (divisor
? num_instances
/ divisor
: max_index
) + 1;
343 pipe_user_buffer_create(pipe
->screen
, (void*)low_addr
,
345 PIPE_BIND_VERTEX_BUFFER
);
346 vbuffer
->buffer_offset
= 0;
348 /* Track user vertex buffers. */
349 pipe_resource_reference(&st
->user_vb
[0], vbuffer
->buffer
);
350 st
->user_vb_stride
[0] = stride
;
351 st
->num_user_vbs
= 1;
353 vbuffer
->stride
= stride
; /* in bytes */
356 velements
[attr
].src_offset
=
357 (unsigned) (arrays
[mesaAttr
]->Ptr
- low_addr
);
358 velements
[attr
].instance_divisor
= arrays
[mesaAttr
]->InstanceDivisor
;
359 velements
[attr
].vertex_buffer_index
= 0;
360 velements
[attr
].src_format
=
361 st_pipe_vertex_format(arrays
[mesaAttr
]->Type
,
362 arrays
[mesaAttr
]->Size
,
363 arrays
[mesaAttr
]->Format
,
364 arrays
[mesaAttr
]->Normalized
);
365 assert(velements
[attr
].src_format
);
371 * Set up a separate pipe_vertex_buffer and pipe_vertex_element for each
373 * \param vbuffer returns vertex buffer info
374 * \param velements returns vertex element info
377 setup_non_interleaved_attribs(struct gl_context
*ctx
,
378 const struct st_vertex_program
*vp
,
379 const struct st_vp_variant
*vpv
,
380 const struct gl_client_array
**arrays
,
381 struct pipe_vertex_buffer vbuffer
[],
382 struct pipe_vertex_element velements
[],
384 unsigned num_instances
)
386 struct st_context
*st
= st_context(ctx
);
387 struct pipe_context
*pipe
= st
->pipe
;
390 for (attr
= 0; attr
< vpv
->num_inputs
; attr
++) {
391 const GLuint mesaAttr
= vp
->index_to_input
[attr
];
392 struct gl_buffer_object
*bufobj
= arrays
[mesaAttr
]->BufferObj
;
393 GLsizei stride
= arrays
[mesaAttr
]->StrideB
;
395 if (bufobj
&& bufobj
->Name
) {
396 /* Attribute data is in a VBO.
397 * Recall that for VBOs, the gl_client_array->Ptr field is
398 * really an offset from the start of the VBO, not a pointer.
400 struct st_buffer_object
*stobj
= st_buffer_object(bufobj
);
401 assert(stobj
->buffer
);
403 vbuffer
[attr
].buffer
= NULL
;
404 pipe_resource_reference(&vbuffer
[attr
].buffer
, stobj
->buffer
);
405 vbuffer
[attr
].buffer_offset
= pointer_to_offset(arrays
[mesaAttr
]->Ptr
);
409 if (arrays
[mesaAttr
]->Ptr
) {
410 uint divisor
= arrays
[mesaAttr
]->InstanceDivisor
;
411 uint length
= (divisor
? num_instances
/ divisor
: max_index
) + 1;
412 vbuffer
[attr
].buffer
=
413 pipe_user_buffer_create(pipe
->screen
,
414 (void *) arrays
[mesaAttr
]->Ptr
,
416 PIPE_BIND_VERTEX_BUFFER
);
419 /* no array, use ctx->Current.Attrib[] value */
420 uint bytes
= sizeof(ctx
->Current
.Attrib
[0]);
421 vbuffer
[attr
].buffer
=
422 pipe_user_buffer_create(pipe
->screen
,
423 (void *) ctx
->Current
.Attrib
[mesaAttr
],
425 PIPE_BIND_VERTEX_BUFFER
);
429 vbuffer
[attr
].buffer_offset
= 0;
431 /* Track user vertex buffers. */
432 pipe_resource_reference(&st
->user_vb
[attr
], vbuffer
[attr
].buffer
);
433 st
->user_vb_stride
[attr
] = stride
;
434 st
->num_user_vbs
= MAX2(st
->num_user_vbs
, attr
+1);
437 /* common-case setup */
438 vbuffer
[attr
].stride
= stride
; /* in bytes */
440 velements
[attr
].src_offset
= 0;
441 velements
[attr
].instance_divisor
= arrays
[mesaAttr
]->InstanceDivisor
;
442 velements
[attr
].vertex_buffer_index
= attr
;
443 velements
[attr
].src_format
444 = st_pipe_vertex_format(arrays
[mesaAttr
]->Type
,
445 arrays
[mesaAttr
]->Size
,
446 arrays
[mesaAttr
]->Format
,
447 arrays
[mesaAttr
]->Normalized
);
448 assert(velements
[attr
].src_format
);
454 setup_index_buffer(struct gl_context
*ctx
,
455 const struct _mesa_index_buffer
*ib
,
456 struct pipe_index_buffer
*ibuffer
)
458 struct st_context
*st
= st_context(ctx
);
459 struct pipe_context
*pipe
= st
->pipe
;
461 memset(ibuffer
, 0, sizeof(*ibuffer
));
463 struct gl_buffer_object
*bufobj
= ib
->obj
;
466 case GL_UNSIGNED_INT
:
467 ibuffer
->index_size
= 4;
469 case GL_UNSIGNED_SHORT
:
470 ibuffer
->index_size
= 2;
472 case GL_UNSIGNED_BYTE
:
473 ibuffer
->index_size
= 1;
480 /* get/create the index buffer object */
481 if (bufobj
&& bufobj
->Name
) {
482 /* elements/indexes are in a real VBO */
483 struct st_buffer_object
*stobj
= st_buffer_object(bufobj
);
484 pipe_resource_reference(&ibuffer
->buffer
, stobj
->buffer
);
485 ibuffer
->offset
= pointer_to_offset(ib
->ptr
);
488 /* element/indicies are in user space memory */
490 pipe_user_buffer_create(pipe
->screen
, (void *) ib
->ptr
,
491 ib
->count
* ibuffer
->index_size
,
492 PIPE_BIND_INDEX_BUFFER
);
498 * Prior to drawing, check that any uniforms referenced by the
499 * current shader have been set. If a uniform has not been set,
503 check_uniforms(struct gl_context
*ctx
)
505 struct gl_shader_program
*shProg
[3] = {
506 ctx
->Shader
.CurrentVertexProgram
,
507 ctx
->Shader
.CurrentGeometryProgram
,
508 ctx
->Shader
.CurrentFragmentProgram
,
512 for (j
= 0; j
< 3; j
++) {
515 if (shProg
[j
] == NULL
|| !shProg
[j
]->LinkStatus
)
518 for (i
= 0; i
< shProg
[j
]->Uniforms
->NumUniforms
; i
++) {
519 const struct gl_uniform
*u
= &shProg
[j
]->Uniforms
->Uniforms
[i
];
520 if (!u
->Initialized
) {
522 "Using shader with uninitialized uniform: %s",
531 * Translate OpenGL primtive type (GL_POINTS, GL_TRIANGLE_STRIP, etc) to
532 * the corresponding Gallium type.
535 translate_prim(const struct gl_context
*ctx
, unsigned prim
)
537 /* GL prims should match Gallium prims, spot-check a few */
538 assert(GL_POINTS
== PIPE_PRIM_POINTS
);
539 assert(GL_QUADS
== PIPE_PRIM_QUADS
);
540 assert(GL_TRIANGLE_STRIP_ADJACENCY
== PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY
);
542 /* Avoid quadstrips if it's easy to do so:
543 * Note: it's imporant to do the correct trimming if we change the prim type!
544 * We do that wherever this function is called.
546 if (prim
== GL_QUAD_STRIP
&&
547 ctx
->Light
.ShadeModel
!= GL_FLAT
&&
548 ctx
->Polygon
.FrontMode
== GL_FILL
&&
549 ctx
->Polygon
.BackMode
== GL_FILL
)
550 prim
= GL_TRIANGLE_STRIP
;
557 st_validate_varrays(struct gl_context
*ctx
,
558 const struct gl_client_array
**arrays
,
560 unsigned num_instances
)
562 struct st_context
*st
= st_context(ctx
);
563 const struct st_vertex_program
*vp
;
564 const struct st_vp_variant
*vpv
;
565 struct pipe_vertex_buffer vbuffer
[PIPE_MAX_SHADER_INPUTS
];
566 struct pipe_vertex_element velements
[PIPE_MAX_ATTRIBS
];
567 unsigned num_vbuffers
, num_velements
;
571 /* must get these after state validation! */
573 vpv
= st
->vp_variant
;
575 memset(velements
, 0, sizeof(struct pipe_vertex_element
) * vpv
->num_inputs
);
577 /* Unreference any user vertex buffers. */
578 for (i
= 0; i
< st
->num_user_vbs
; i
++) {
579 pipe_resource_reference(&st
->user_vb
[i
], NULL
);
581 st
->num_user_vbs
= 0;
584 * Setup the vbuffer[] and velements[] arrays.
586 if (is_interleaved_arrays(vp
, vpv
, arrays
)) {
587 setup_interleaved_attribs(ctx
, vp
, vpv
, arrays
, vbuffer
, velements
,
588 max_index
, num_instances
);
591 num_velements
= vpv
->num_inputs
;
592 if (num_velements
== 0)
596 setup_non_interleaved_attribs(ctx
, vp
, vpv
, arrays
,
597 vbuffer
, velements
, max_index
, num_instances
);
598 num_vbuffers
= vpv
->num_inputs
;
599 num_velements
= vpv
->num_inputs
;
602 cso_set_vertex_buffers(st
->cso_context
, num_vbuffers
, vbuffer
);
603 cso_set_vertex_elements(st
->cso_context
, num_velements
, velements
);
605 /* unreference buffers (frees wrapped user-space buffer objects)
606 * This is OK, because the pipe driver should reference buffers by itself
607 * in set_vertex_buffers. */
608 for (attr
= 0; attr
< num_vbuffers
; attr
++) {
609 pipe_resource_reference(&vbuffer
[attr
].buffer
, NULL
);
610 assert(!vbuffer
[attr
].buffer
);
616 * This function gets plugged into the VBO module and is called when
617 * we have something to render.
618 * Basically, translate the information into the format expected by gallium.
621 st_draw_vbo(struct gl_context
*ctx
,
622 const struct gl_client_array
**arrays
,
623 const struct _mesa_prim
*prims
,
625 const struct _mesa_index_buffer
*ib
,
626 GLboolean index_bounds_valid
,
630 struct st_context
*st
= st_context(ctx
);
631 struct pipe_context
*pipe
= st
->pipe
;
632 struct pipe_index_buffer ibuffer
;
633 struct pipe_draw_info info
;
634 unsigned i
, num_instances
= 1;
635 GLboolean new_array
=
636 st
->dirty
.st
&& (st
->dirty
.mesa
& (_NEW_ARRAY
| _NEW_PROGRAM
)) != 0;
638 /* Mesa core state should have been validated already */
639 assert(ctx
->NewState
== 0x0);
642 /* Gallium probably doesn't want this in some cases. */
643 if (!index_bounds_valid
)
644 if (!vbo_all_varyings_in_vbos(arrays
))
645 vbo_get_minmax_index(ctx
, prims
, ib
, &min_index
, &max_index
);
647 for (i
= 0; i
< nr_prims
; i
++) {
648 num_instances
= MAX2(num_instances
, prims
[i
].num_instances
);
651 /* Get min/max index for non-indexed drawing. */
655 for (i
= 0; i
< nr_prims
; i
++) {
656 min_index
= MIN2(min_index
, prims
[i
].start
);
657 max_index
= MAX2(max_index
, prims
[i
].start
+ prims
[i
].count
- 1);
658 num_instances
= MAX2(num_instances
, prims
[i
].num_instances
);
662 /* Validate state. */
664 GLboolean vertDataEdgeFlags
;
666 /* sanity check for pointer arithmetic below */
667 assert(sizeof(arrays
[0]->Ptr
[0]) == 1);
669 vertDataEdgeFlags
= arrays
[VERT_ATTRIB_EDGEFLAG
]->BufferObj
&&
670 arrays
[VERT_ATTRIB_EDGEFLAG
]->BufferObj
->Name
;
671 if (vertDataEdgeFlags
!= st
->vertdata_edgeflags
) {
672 st
->vertdata_edgeflags
= vertDataEdgeFlags
;
673 st
->dirty
.st
|= ST_NEW_EDGEFLAGS_DATA
;
676 st_validate_state(st
);
679 st_validate_varrays(ctx
, arrays
, max_index
, num_instances
);
683 if (MESA_VERBOSE
& VERBOSE_GLSL
) {
687 (void) check_uniforms
;
691 /* Notify the driver that the content of user buffers may have been
693 if (!new_array
&& st
->num_user_vbs
) {
694 for (i
= 0; i
< st
->num_user_vbs
; i
++) {
695 if (st
->user_vb
[i
]) {
696 unsigned stride
= st
->user_vb_stride
[i
];
699 pipe
->redefine_user_buffer(pipe
, st
->user_vb
[i
],
701 (max_index
+ 1 - min_index
) * stride
);
704 pipe
->redefine_user_buffer(pipe
, st
->user_vb
[i
],
705 0, st
->user_vb
[i
]->width0
);
711 setup_index_buffer(ctx
, ib
, &ibuffer
);
712 pipe
->set_index_buffer(pipe
, &ibuffer
);
714 util_draw_init_info(&info
);
717 if (min_index
!= ~0 && max_index
!= ~0) {
718 info
.min_index
= min_index
;
719 info
.max_index
= max_index
;
723 info
.primitive_restart
= st
->ctx
->Array
.PrimitiveRestart
;
724 info
.restart_index
= st
->ctx
->Array
.RestartIndex
;
726 /* do actual drawing */
727 for (i
= 0; i
< nr_prims
; i
++) {
728 info
.mode
= translate_prim( ctx
, prims
[i
].mode
);
729 info
.start
= prims
[i
].start
;
730 info
.count
= prims
[i
].count
;
731 info
.instance_count
= prims
[i
].num_instances
;
732 info
.index_bias
= prims
[i
].basevertex
;
734 info
.min_index
= info
.start
;
735 info
.max_index
= info
.start
+ info
.count
- 1;
738 if (u_trim_pipe_prim(info
.mode
, &info
.count
))
739 pipe
->draw_vbo(pipe
, &info
);
742 pipe_resource_reference(&ibuffer
.buffer
, NULL
);
746 void st_init_draw( struct st_context
*st
)
748 struct gl_context
*ctx
= st
->ctx
;
750 vbo_set_draw_func(ctx
, st_draw_vbo
);
752 #if FEATURE_feedback || FEATURE_rastpos
753 st
->draw
= draw_create(st
->pipe
); /* for selection/feedback */
755 /* Disable draw options that might convert points/lines to tris, etc.
756 * as that would foul-up feedback/selection mode.
758 draw_wide_line_threshold(st
->draw
, 1000.0f
);
759 draw_wide_point_threshold(st
->draw
, 1000.0f
);
760 draw_enable_line_stipple(st
->draw
, FALSE
);
761 draw_enable_point_sprites(st
->draw
, FALSE
);
766 void st_destroy_draw( struct st_context
*st
)
768 #if FEATURE_feedback || FEATURE_rastpos
769 draw_destroy(st
->draw
);