1 /**************************************************************************
3 * Copyright 2008 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 #include "pipe/p_context.h"
30 #include "pipe/p_defines.h"
31 #include "util/u_inlines.h"
32 #include "util/u_draw_quad.h"
36 * Draw a simple vertex buffer / primitive.
37 * Limited to float[4] vertex attribs, tightly packed.
40 util_draw_vertex_buffer(struct pipe_context
*pipe
,
41 struct pipe_buffer
*vbuf
,
47 struct pipe_vertex_buffer vbuffer
;
49 assert(num_attribs
<= PIPE_MAX_ATTRIBS
);
51 /* tell pipe about the vertex buffer */
52 memset(&vbuffer
, 0, sizeof(vbuffer
));
53 vbuffer
.buffer
= vbuf
;
54 vbuffer
.stride
= num_attribs
* 4 * sizeof(float); /* vertex size */
55 vbuffer
.buffer_offset
= offset
;
56 vbuffer
.max_index
= num_verts
- 1;
57 pipe
->set_vertex_buffers(pipe
, 1, &vbuffer
);
59 /* note: vertex elements already set by caller */
62 pipe
->draw_arrays(pipe
, prim_type
, 0, num_verts
);
68 * Draw screen-aligned textured quad.
69 * Note: this function allocs/destroys a vertex buffer and isn't especially
73 util_draw_texquad(struct pipe_context
*pipe
,
74 float x0
, float y0
, float x1
, float y1
, float z
)
76 struct pipe_buffer
*vbuf
;
77 uint numAttribs
= 2, vertexBytes
, i
, j
;
79 vertexBytes
= 4 * (4 * numAttribs
* sizeof(float));
81 /* XXX create one-time */
82 vbuf
= pipe_buffer_create(pipe
->screen
, 32,
83 PIPE_BUFFER_USAGE_VERTEX
, vertexBytes
);
85 float *v
= (float *) pipe_buffer_map(pipe
->screen
, vbuf
,
86 PIPE_BUFFER_USAGE_CPU_WRITE
);
91 for (i
= j
= 0; i
< 4; i
++) {
93 v
[j
+ 3] = 1.0; /* w */
94 v
[j
+ 6] = 0.0; /* r */
95 v
[j
+ 7] = 1.0; /* q */
119 pipe_buffer_unmap(pipe
->screen
, vbuf
);
120 util_draw_vertex_buffer(pipe
, vbuf
, 0, PIPE_PRIM_TRIANGLE_FAN
, 4, 2);
123 pipe_buffer_reference(&vbuf
, NULL
);