1 /* Test the writing Z in fragment shader.
2 * The red quad should be entirely in front of the blue quad even
3 * though the overlap and intersect in Z.
10 #include "util/macros.h"
13 static int width
= 300;
14 static int height
= 300;
16 static struct graw_info info
;
29 static struct vertex vertices
[] =
31 /* left quad: clock-wise, front-facing, red */
33 {-0.8, -0.9, z0
, 1.0 },
38 { -0.2, -0.9, z0
, 1.0 },
43 { 0.2, 0.9, z01
, 1.0 },
48 {-0.9, 0.9, z01
, 1.0 },
52 /* right quad : counter-clock-wise, back-facing, green */
54 { 0.2, -0.9, z1
, 1.0 },
59 { -0.2, 0.8, z1
, 1.0 },
64 { 0.9, 0.8, z1
, 1.0 },
69 { 0.8, -0.9, z1
, 1.0 },
74 #define NUM_VERTS ARRAY_SIZE(vertices)
81 struct pipe_vertex_element ve
[2];
82 struct pipe_vertex_buffer vbuf
;
85 memset(ve
, 0, sizeof ve
);
87 ve
[0].src_offset
= Offset(struct vertex
, position
);
88 ve
[0].src_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
89 ve
[1].src_offset
= Offset(struct vertex
, color
);
90 ve
[1].src_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
92 handle
= info
.ctx
->create_vertex_elements_state(info
.ctx
, 2, ve
);
93 info
.ctx
->bind_vertex_elements_state(info
.ctx
, handle
);
95 memset(&vbuf
, 0, sizeof vbuf
);
97 vbuf
.stride
= sizeof(struct vertex
);
98 vbuf
.buffer_offset
= 0;
99 vbuf
.buffer
.resource
= pipe_buffer_create_with_data(info
.ctx
,
100 PIPE_BIND_VERTEX_BUFFER
,
105 info
.ctx
->set_vertex_buffers(info
.ctx
, 0, 1, &vbuf
);
110 set_vertex_shader(void)
117 "DCL OUT[0], POSITION\n"
118 "DCL OUT[1], GENERIC[0]\n"
119 " 0: MOV OUT[0], IN[0]\n"
120 " 1: MOV OUT[1], IN[1]\n"
123 handle
= graw_parse_vertex_shader(info
.ctx
, text
);
124 info
.ctx
->bind_vs_state(info
.ctx
, handle
);
129 set_fragment_shader(void)
134 "DCL IN[0], GENERIC, CONSTANT\n"
135 "DCL OUT[0], COLOR\n"
136 "DCL OUT[1], POSITION\n"
138 "IMM FLT32 { 1.0, 0.0, 0.0, 0.0 }\n"
139 "IMM FLT32 { 0.0, 1.0, 0.0, 0.0 }\n"
140 "IMM FLT32 { 0.5, 0.4, 0.0, 0.0 }\n"
141 " 0: MOV OUT[0], IN[0]\n" /* front-facing: red */
142 " 1: IF IN[0].xxxx :3\n"
143 " 2: MOV OUT[1].z, IMM[2].yyyy\n" /* red: Z = 0.4 */
145 " 4: MOV OUT[1].z, IMM[2].xxxx\n" /* blue: Z = 0.5 */
149 handle
= graw_parse_fragment_shader(info
.ctx
, text
);
150 info
.ctx
->bind_fs_state(info
.ctx
, handle
);
158 union pipe_color_union clear_color
;
160 clear_color
.f
[0] = 0.25;
161 clear_color
.f
[1] = 0.25;
162 clear_color
.f
[2] = 0.25;
163 clear_color
.f
[3] = 1.00;
165 info
.ctx
->clear(info
.ctx
,
166 PIPE_CLEAR_COLOR
| PIPE_CLEAR_DEPTHSTENCIL
,
168 &clear_color
, 1.0, 0);
169 util_draw_arrays(info
.ctx
, PIPE_PRIM_QUADS
, 0, NUM_VERTS
);
170 info
.ctx
->flush(info
.ctx
, NULL
, 0);
173 /* At the moment, libgraw leaks out/makes available some of the
174 * symbols from gallium/auxiliary, including these debug helpers.
175 * Will eventually want to bless some of these paths, and lock the
176 * others down so they aren't accessible from test programs.
178 * This currently just happens to work on debug builds - a release
179 * build will probably fail to link here:
181 debug_dump_surface_bmp(info
.ctx
, "result.bmp", surf
);
184 graw_util_flush_front(&info
);
195 graw_util_viewport(&info
, 0, 0, width
, height
, -1.0, 1.0);
203 if (!graw_util_create_window(&info
, width
, height
, 1, TRUE
))
206 graw_util_default_state(&info
, TRUE
);
208 graw_util_viewport(&info
, 0, 0, width
, height
, -1.0, 1.0);
212 set_fragment_shader();
217 main(int argc
, char *argv
[])
221 printf("The red quad should be entirely in front of the blue quad.\n");
223 graw_set_display_func(draw
);
224 /*graw_set_reshape_func(resize);*/