00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "pipe/p_context.h"
00030 #include "pipe/p_defines.h"
00031 #include "pipe/p_inlines.h"
00032 #include "pipe/p_winsys.h"
00033 #include "util/u_draw_quad.h"
00034
00035
00040 void
00041 util_draw_vertex_buffer(struct pipe_context *pipe,
00042 struct pipe_buffer *vbuf,
00043 uint offset,
00044 uint prim_type,
00045 uint num_verts,
00046 uint num_attribs)
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
00055 vbuffer.buffer = vbuf;
00056 vbuffer.pitch = num_attribs * 4 * sizeof(float);
00057 vbuffer.buffer_offset = offset;
00058 pipe->set_vertex_buffers(pipe, 1, &vbuffer);
00059
00060
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
00070 pipe->draw_arrays(pipe, prim_type, 0, num_verts);
00071 }
00072
00073
00074
00080 void
00081 util_draw_texquad(struct pipe_context *pipe,
00082 float x0, float y0, float x1, float y1, float z)
00083 {
00084 struct pipe_buffer *vbuf;
00085 uint numAttribs = 2, vertexBytes, i, j;
00086
00087 vertexBytes = 4 * (4 * numAttribs * sizeof(float));
00088
00089
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
00098
00099 for (i = j = 0; i < 4; i++) {
00100 v[j + 2] = z;
00101 v[j + 3] = 1.0;
00102 v[j + 6] = 0.0;
00103 v[j + 7] = 1.0;
00104 j += 8;
00105 }
00106
00107 v[0] = x0;
00108 v[1] = y0;
00109 v[4] = 0.0;
00110 v[5] = 0.0;
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 }