u_draw_quad.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void util_draw_vertex_buffer (struct pipe_context *pipe, struct pipe_buffer *vbuf, uint offset, uint num_attribs, uint num_verts, uint prim_type)
 Draw a simple vertex buffer / primitive.
void util_draw_texquad (struct pipe_context *pipe, float x0, float y0, float x1, float y1, float z)
 Draw screen-aligned textured quad.


Function Documentation

void util_draw_texquad ( struct pipe_context pipe,
float  x0,
float  y0,
float  x1,
float  y1,
float  z 
)

Draw screen-aligned textured quad.

Note: this function allocs/destroys a vertex buffer and isn't especially efficient.

Definition at line 81 of file u_draw_quad.c.

References pipe_buffer_create(), pipe_buffer_map(), pipe_buffer_reference(), pipe_buffer_unmap(), PIPE_BUFFER_USAGE_CPU_WRITE, PIPE_BUFFER_USAGE_VERTEX, PIPE_PRIM_TRIANGLE_FAN, pipe_context::screen, and util_draw_vertex_buffer().

00083 {
00084    struct pipe_buffer *vbuf;
00085    uint numAttribs = 2, vertexBytes, i, j;
00086 
00087    vertexBytes = 4 * (4 * numAttribs * sizeof(float));
00088 
00089    /* XXX create one-time */
00090    vbuf = pipe_buffer_create(pipe->screen, 32,
00091                              PIPE_BUFFER_USAGE_VERTEX, vertexBytes);
00092    if (vbuf) {
00093       float *v = (float *) pipe_buffer_map(pipe->screen, vbuf,
00094                                            PIPE_BUFFER_USAGE_CPU_WRITE);
00095       if (v) {
00096          /*
00097           * Load vertex buffer
00098           */
00099          for (i = j = 0; i < 4; i++) {
00100             v[j + 2] = z;   /* z */
00101             v[j + 3] = 1.0; /* w */
00102             v[j + 6] = 0.0; /* r */
00103             v[j + 7] = 1.0; /* q */
00104             j += 8;
00105          }
00106 
00107          v[0] = x0;
00108          v[1] = y0;
00109          v[4] = 0.0; /*s*/
00110          v[5] = 0.0; /*t*/
00111 
00112          v[8] = x1;
00113          v[9] = y0;
00114          v[12] = 1.0;
00115          v[13] = 0.0;
00116 
00117          v[16] = x1;
00118          v[17] = y1;
00119          v[20] = 1.0;
00120          v[21] = 1.0;
00121 
00122          v[24] = x0;
00123          v[25] = y1;
00124          v[28] = 0.0;
00125          v[29] = 1.0;
00126 
00127          pipe_buffer_unmap(pipe->screen, vbuf);
00128          util_draw_vertex_buffer(pipe, vbuf, 0, PIPE_PRIM_TRIANGLE_FAN, 4, 2);
00129       }
00130 
00131       pipe_buffer_reference(pipe->screen, &vbuf, NULL);
00132    }
00133 }

void util_draw_vertex_buffer ( struct pipe_context pipe,
struct pipe_buffer vbuf,
uint  offset,
uint  prim_type,
uint  num_verts,
uint  num_attribs 
)

Draw a simple vertex buffer / primitive.

Limited to float[4] vertex attribs, tightly packed.

Definition at line 41 of file u_draw_quad.c.

References assert, pipe_vertex_buffer::buffer, pipe_vertex_buffer::buffer_offset, pipe_context::draw_arrays, pipe_vertex_element::nr_components, PIPE_FORMAT_R32G32B32A32_FLOAT, pipe_vertex_buffer::pitch, pipe_context::set_vertex_buffers, pipe_context::set_vertex_elements, pipe_vertex_element::src_format, pipe_vertex_element::src_offset, and pipe_vertex_element::vertex_buffer_index.

00047 {
00048    struct pipe_vertex_buffer vbuffer;
00049    struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS];
00050    uint i;
00051 
00052    assert(num_attribs <= PIPE_MAX_ATTRIBS);
00053 
00054    /* tell pipe about the vertex buffer */
00055    vbuffer.buffer = vbuf;
00056    vbuffer.pitch = num_attribs * 4 * sizeof(float);  /* vertex size */
00057    vbuffer.buffer_offset = offset;
00058    pipe->set_vertex_buffers(pipe, 1, &vbuffer);
00059 
00060    /* tell pipe about the vertex attributes */
00061    for (i = 0; i < num_attribs; i++) {
00062       velements[i].src_offset = i * 4 * sizeof(float);
00063       velements[i].vertex_buffer_index = 0;
00064       velements[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
00065       velements[i].nr_components = 4;
00066    }
00067    pipe->set_vertex_elements(pipe, num_attribs, velements);
00068 
00069    /* draw */
00070    pipe->draw_arrays(pipe, prim_type, 0, num_verts);
00071 }


Generated on Tue Sep 29 06:25:28 2009 for Gallium3D by  doxygen 1.5.4