Go to the source code of this file.
Functions | |
void | st_init_draw (struct st_context *st) |
void | st_destroy_draw (struct st_context *st) |
void | st_draw_vbo (GLcontext *ctx, const struct gl_client_array **arrays, const struct _mesa_prim *prims, GLuint nr_prims, const struct _mesa_index_buffer *ib, GLuint min_index, GLuint max_index) |
This function gets plugged into the VBO module and is called when we have something to render. | |
void | st_feedback_draw_vbo (GLcontext *ctx, const struct gl_client_array **arrays, const struct _mesa_prim *prims, GLuint nr_prims, const struct _mesa_index_buffer *ib, GLuint min_index, GLuint max_index) |
GLuint | st_pipe_vertex_format (GLenum type, GLuint size, GLboolean normalized) |
Return a PIPE_FORMAT_x for the given GL datatype and size. |
void st_destroy_draw | ( | struct st_context * | st | ) |
void st_draw_vbo | ( | GLcontext * | ctx, | |
const struct gl_client_array ** | arrays, | |||
const struct _mesa_prim * | prims, | |||
GLuint | nr_prims, | |||
const struct _mesa_index_buffer * | ib, | |||
GLuint | min_index, | |||
GLuint | max_index | |||
) |
This function gets plugged into the VBO module and is called when we have something to render.
Basically, translate the information into the format expected by gallium.
Definition at line 518 of file st_draw.c.
References assert, pipe_vertex_buffer::buffer, st_buffer_object::buffer, check_uniforms(), pipe_context::draw_arrays, pipe_context::draw_elements, pipe_context::draw_range_elements, is_interleaved_arrays(), mode, pipe_vertex_element::nr_components, st_vertex_program::num_inputs, pf_name(), pipe_buffer_reference(), pipe_user_buffer_create(), pipe_context::screen, pipe_context::set_vertex_buffers, pipe_context::set_vertex_elements, setup_edgeflags(), setup_interleaved_attribs(), setup_non_interleaved_attribs(), pipe_vertex_element::src_format, pipe_vertex_element::src_offset, st_buffer_object(), st_validate_state(), and pipe_vertex_element::vertex_buffer_index.
00525 { 00526 struct pipe_context *pipe = ctx->st->pipe; 00527 const struct st_vertex_program *vp; 00528 const struct pipe_shader_state *vs; 00529 struct pipe_vertex_buffer vbuffer[PIPE_MAX_SHADER_INPUTS]; 00530 GLuint attr; 00531 struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS]; 00532 unsigned num_vbuffers, num_velements; 00533 GLboolean userSpace; 00534 00535 /* sanity check for pointer arithmetic below */ 00536 assert(sizeof(arrays[0]->Ptr[0]) == 1); 00537 00538 st_validate_state(ctx->st); 00539 00540 /* must get these after state validation! */ 00541 vp = ctx->st->vp; 00542 vs = &ctx->st->vp->state; 00543 00544 if (MESA_VERBOSE & VERBOSE_GLSL) { 00545 check_uniforms(ctx); 00546 } 00547 00548 /* 00549 * Setup the vbuffer[] and velements[] arrays. 00550 */ 00551 if (is_interleaved_arrays(vp, arrays, &userSpace)) { 00552 /*printf("Draw interleaved\n");*/ 00553 setup_interleaved_attribs(ctx, vp, arrays, max_index, userSpace, 00554 vbuffer, velements); 00555 num_vbuffers = 1; 00556 num_velements = vp->num_inputs; 00557 if (num_velements == 0) 00558 num_vbuffers = 0; 00559 } 00560 else { 00561 /*printf("Draw non-interleaved\n");*/ 00562 setup_non_interleaved_attribs(ctx, vp, arrays, max_index, 00563 &userSpace, vbuffer, velements); 00564 num_vbuffers = vp->num_inputs; 00565 num_velements = vp->num_inputs; 00566 } 00567 00568 #if 0 00569 { 00570 GLuint i; 00571 for (i = 0; i < num_vbuffers; i++) { 00572 printf("buffers[%d].pitch = %u\n", i, vbuffer[i].pitch); 00573 printf("buffers[%d].max_index = %u\n", i, vbuffer[i].max_index); 00574 printf("buffers[%d].buffer_offset = %u\n", i, vbuffer[i].buffer_offset); 00575 printf("buffers[%d].buffer = %p\n", i, (void*) vbuffer[i].buffer); 00576 } 00577 for (i = 0; i < num_velements; i++) { 00578 printf("vlements[%d].vbuffer_index = %u\n", i, velements[i].vertex_buffer_index); 00579 printf("vlements[%d].src_offset = %u\n", i, velements[i].src_offset); 00580 printf("vlements[%d].nr_comps = %u\n", i, velements[i].nr_components); 00581 printf("vlements[%d].format = %s\n", i, pf_name(velements[i].src_format)); 00582 } 00583 } 00584 #endif 00585 00586 pipe->set_vertex_buffers(pipe, num_vbuffers, vbuffer); 00587 pipe->set_vertex_elements(pipe, num_velements, velements); 00588 00589 if (num_vbuffers == 0 || num_velements == 0) 00590 return; 00591 00592 /* do actual drawing */ 00593 if (ib) { 00594 /* indexed primitive */ 00595 struct gl_buffer_object *bufobj = ib->obj; 00596 struct pipe_buffer *indexBuf = NULL; 00597 unsigned indexSize, indexOffset, i; 00598 00599 switch (ib->type) { 00600 case GL_UNSIGNED_INT: 00601 indexSize = 4; 00602 break; 00603 case GL_UNSIGNED_SHORT: 00604 indexSize = 2; 00605 break; 00606 case GL_UNSIGNED_BYTE: 00607 indexSize = 1; 00608 break; 00609 default: 00610 assert(0); 00611 return; 00612 } 00613 00614 /* get/create the index buffer object */ 00615 if (bufobj && bufobj->Name) { 00616 /* elements/indexes are in a real VBO */ 00617 struct st_buffer_object *stobj = st_buffer_object(bufobj); 00618 pipe_buffer_reference(pipe->screen, &indexBuf, stobj->buffer); 00619 indexOffset = (unsigned) ib->ptr / indexSize; 00620 } 00621 else { 00622 /* element/indicies are in user space memory */ 00623 indexBuf = pipe_user_buffer_create(pipe->screen, (void *) ib->ptr, 00624 ib->count * indexSize); 00625 indexOffset = 0; 00626 } 00627 00628 /* draw */ 00629 if (nr_prims == 1 && pipe->draw_range_elements != NULL) { 00630 i = 0; 00631 00632 /* XXX: exercise temporary path to pass min/max directly 00633 * through to driver & draw module. These interfaces still 00634 * need a bit of work... 00635 */ 00636 setup_edgeflags(ctx, prims[i].mode, 00637 prims[i].start + indexOffset, prims[i].count, 00638 arrays[VERT_ATTRIB_EDGEFLAG]); 00639 00640 pipe->draw_range_elements(pipe, indexBuf, indexSize, 00641 min_index, 00642 max_index, 00643 prims[i].mode, 00644 prims[i].start + indexOffset, prims[i].count); 00645 } 00646 else { 00647 for (i = 0; i < nr_prims; i++) { 00648 setup_edgeflags(ctx, prims[i].mode, 00649 prims[i].start + indexOffset, prims[i].count, 00650 arrays[VERT_ATTRIB_EDGEFLAG]); 00651 00652 pipe->draw_elements(pipe, indexBuf, indexSize, 00653 prims[i].mode, 00654 prims[i].start + indexOffset, prims[i].count); 00655 } 00656 } 00657 00658 pipe_buffer_reference(pipe->screen, &indexBuf, NULL); 00659 } 00660 else { 00661 /* non-indexed */ 00662 GLuint i; 00663 for (i = 0; i < nr_prims; i++) { 00664 setup_edgeflags(ctx, prims[i].mode, 00665 prims[i].start, prims[i].count, 00666 arrays[VERT_ATTRIB_EDGEFLAG]); 00667 00668 pipe->draw_arrays(pipe, prims[i].mode, prims[i].start, prims[i].count); 00669 } 00670 } 00671 00672 /* unreference buffers (frees wrapped user-space buffer objects) */ 00673 for (attr = 0; attr < num_vbuffers; attr++) { 00674 pipe_buffer_reference(pipe->screen, &vbuffer[attr].buffer, NULL); 00675 assert(!vbuffer[attr].buffer); 00676 } 00677 00678 if (userSpace) 00679 { 00680 pipe->set_vertex_buffers(pipe, 0, NULL); 00681 } 00682 }
void st_feedback_draw_vbo | ( | GLcontext * | ctx, | |
const struct gl_client_array ** | arrays, | |||
const struct _mesa_prim * | prims, | |||
GLuint | nr_prims, | |||
const struct _mesa_index_buffer * | ib, | |||
GLuint | min_index, | |||
GLuint | max_index | |||
) |
void st_init_draw | ( | struct st_context * | st | ) |
Definition at line 685 of file st_draw.c.
References st_context::ctx, and st_draw_vbo().
00686 { 00687 GLcontext *ctx = st->ctx; 00688 00689 vbo_set_draw_func(ctx, st_draw_vbo); 00690 }
GLuint st_pipe_vertex_format | ( | GLenum | type, | |
GLuint | size, | |||
GLboolean | normalized | |||
) |
Return a PIPE_FORMAT_x for the given GL datatype and size.
Definition at line 162 of file st_draw.c.
References assert, byte_types_norm, byte_types_scale, double_types, fixed_types, float_types, int_types_norm, int_types_scale, short_types_norm, short_types_scale, ubyte_types_norm, ubyte_types_scale, uint_types_norm, uint_types_scale, ushort_types_norm, and ushort_types_scale.
00163 { 00164 assert((type >= GL_BYTE && type <= GL_DOUBLE) || 00165 type == GL_FIXED); 00166 assert(size >= 1); 00167 assert(size <= 4); 00168 00169 if (normalized) { 00170 switch (type) { 00171 case GL_DOUBLE: return double_types[size-1]; 00172 case GL_FLOAT: return float_types[size-1]; 00173 case GL_INT: return int_types_norm[size-1]; 00174 case GL_SHORT: return short_types_norm[size-1]; 00175 case GL_BYTE: return byte_types_norm[size-1]; 00176 case GL_UNSIGNED_INT: return uint_types_norm[size-1]; 00177 case GL_UNSIGNED_SHORT: return ushort_types_norm[size-1]; 00178 case GL_UNSIGNED_BYTE: return ubyte_types_norm[size-1]; 00179 case GL_FIXED: return fixed_types[size-1]; 00180 default: assert(0); return 0; 00181 } 00182 } 00183 else { 00184 switch (type) { 00185 case GL_DOUBLE: return double_types[size-1]; 00186 case GL_FLOAT: return float_types[size-1]; 00187 case GL_INT: return int_types_scale[size-1]; 00188 case GL_SHORT: return short_types_scale[size-1]; 00189 case GL_BYTE: return byte_types_scale[size-1]; 00190 case GL_UNSIGNED_INT: return uint_types_scale[size-1]; 00191 case GL_UNSIGNED_SHORT: return ushort_types_scale[size-1]; 00192 case GL_UNSIGNED_BYTE: return ubyte_types_scale[size-1]; 00193 case GL_FIXED: return fixed_types[size-1]; 00194 default: assert(0); return 0; 00195 } 00196 } 00197 return 0; /* silence compiler warning */ 00198 }