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.
11 static int width
= 300;
12 static int height
= 300;
14 static struct graw_info info
;
27 static struct vertex vertices
[] =
29 /* left quad: clock-wise, front-facing, red */
31 {-0.8, -0.9, z0
, 1.0 },
36 { -0.2, -0.9, z0
, 1.0 },
41 { 0.2, 0.9, z01
, 1.0 },
46 {-0.9, 0.9, z01
, 1.0 },
50 /* right quad : counter-clock-wise, back-facing, green */
52 { 0.2, -0.9, z1
, 1.0 },
57 { -0.2, 0.8, z1
, 1.0 },
62 { 0.9, 0.8, z1
, 1.0 },
67 { 0.8, -0.9, z1
, 1.0 },
72 #define NUM_VERTS (sizeof(vertices) / sizeof(vertices[0]))
79 struct pipe_vertex_element ve
[2];
80 struct pipe_vertex_buffer vbuf
;
83 memset(ve
, 0, sizeof ve
);
85 ve
[0].src_offset
= Offset(struct vertex
, position
);
86 ve
[0].src_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
87 ve
[1].src_offset
= Offset(struct vertex
, color
);
88 ve
[1].src_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
90 handle
= info
.ctx
->create_vertex_elements_state(info
.ctx
, 2, ve
);
91 info
.ctx
->bind_vertex_elements_state(info
.ctx
, handle
);
93 memset(&vbuf
, 0, sizeof vbuf
);
95 vbuf
.stride
= sizeof(struct vertex
);
96 vbuf
.buffer_offset
= 0;
97 vbuf
.buffer
= pipe_buffer_create_with_data(info
.ctx
,
98 PIPE_BIND_VERTEX_BUFFER
,
103 info
.ctx
->set_vertex_buffers(info
.ctx
, 0, 1, &vbuf
);
108 set_vertex_shader(void)
115 "DCL OUT[0], POSITION\n"
116 "DCL OUT[1], GENERIC[0]\n"
117 " 0: MOV OUT[0], IN[0]\n"
118 " 1: MOV OUT[1], IN[1]\n"
121 handle
= graw_parse_vertex_shader(info
.ctx
, text
);
122 info
.ctx
->bind_vs_state(info
.ctx
, handle
);
127 set_fragment_shader(void)
132 "DCL IN[0], GENERIC, CONSTANT\n"
133 "DCL OUT[0], COLOR\n"
134 "DCL OUT[1], POSITION\n"
136 "IMM FLT32 { 1.0, 0.0, 0.0, 0.0 }\n"
137 "IMM FLT32 { 0.0, 1.0, 0.0, 0.0 }\n"
138 "IMM FLT32 { 0.5, 0.4, 0.0, 0.0 }\n"
139 " 0: MOV OUT[0], IN[0]\n" /* front-facing: red */
140 " 1: IF IN[0].xxxx :3\n"
141 " 2: MOV OUT[1].z, IMM[2].yyyy\n" /* red: Z = 0.4 */
143 " 4: MOV OUT[1].z, IMM[2].xxxx\n" /* blue: Z = 0.5 */
147 handle
= graw_parse_fragment_shader(info
.ctx
, text
);
148 info
.ctx
->bind_fs_state(info
.ctx
, handle
);
156 union pipe_color_union clear_color
;
158 clear_color
.f
[0] = 0.25;
159 clear_color
.f
[1] = 0.25;
160 clear_color
.f
[2] = 0.25;
161 clear_color
.f
[3] = 1.00;
163 info
.ctx
->clear(info
.ctx
,
164 PIPE_CLEAR_COLOR
| PIPE_CLEAR_DEPTHSTENCIL
,
165 &clear_color
, 1.0, 0);
166 util_draw_arrays(info
.ctx
, PIPE_PRIM_QUADS
, 0, NUM_VERTS
);
167 info
.ctx
->flush(info
.ctx
, NULL
);
170 /* At the moment, libgraw leaks out/makes available some of the
171 * symbols from gallium/auxiliary, including these debug helpers.
172 * Will eventually want to bless some of these paths, and lock the
173 * others down so they aren't accessible from test programs.
175 * This currently just happens to work on debug builds - a release
176 * build will probably fail to link here:
178 debug_dump_surface_bmp(info
.ctx
, "result.bmp", surf
);
181 graw_util_flush_front(&info
);
192 graw_util_viewport(&info
, 0, 0, width
, height
, -1.0, 1.0);
200 if (!graw_util_create_window(&info
, width
, height
, 1, TRUE
))
203 graw_util_default_state(&info
, TRUE
);
205 graw_util_viewport(&info
, 0, 0, width
, height
, -1.0, 1.0);
209 set_fragment_shader();
214 main(int argc
, char *argv
[])
218 printf("The red quad should be entirely in front of the blue quad.\n");
220 graw_set_display_func(draw
);
221 /*graw_set_reshape_func(resize);*/