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