1 /* Test the TGSI_SEMANTIC_FACE fragment shader input.
8 #include "util/macros.h"
11 static int width
= 300;
12 static int height
= 300;
14 static struct graw_info info
;
25 static struct vertex vertices
[] =
27 /* left quad: clock-wise, front-facing, red */
29 {-0.8, -0.9, z0
, 1.0 },
34 { -0.2, -0.9, z0
, 1.0 },
39 { 0.2, 0.9, z01
, 1.0 },
44 {-0.9, 0.9, z01
, 1.0 },
48 /* right quad : counter-clock-wise, back-facing, green */
50 { 0.2, -0.9, z1
, 1.0 },
55 { -0.2, 0.8, z1
, 1.0 },
60 { 0.9, 0.8, z1
, 1.0 },
65 { 0.8, -0.9, z1
, 1.0 },
70 #define NUM_VERTS ARRAY_SIZE(vertices)
77 struct pipe_vertex_element ve
[2];
78 struct pipe_vertex_buffer vbuf
;
81 memset(ve
, 0, sizeof ve
);
83 ve
[0].src_offset
= Offset(struct vertex
, position
);
84 ve
[0].src_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
85 ve
[1].src_offset
= Offset(struct vertex
, color
);
86 ve
[1].src_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
88 handle
= info
.ctx
->create_vertex_elements_state(info
.ctx
, 2, ve
);
89 info
.ctx
->bind_vertex_elements_state(info
.ctx
, handle
);
91 memset(&vbuf
, 0, sizeof vbuf
);
93 vbuf
.stride
= sizeof(struct vertex
);
94 vbuf
.buffer_offset
= 0;
95 vbuf
.buffer
.resource
= pipe_buffer_create_with_data(info
.ctx
,
96 PIPE_BIND_VERTEX_BUFFER
,
101 info
.ctx
->set_vertex_buffers(info
.ctx
, 0, 1, &vbuf
);
106 set_vertex_shader(void)
113 "DCL OUT[0], POSITION\n"
114 "DCL OUT[1], GENERIC[0]\n"
115 " 0: MOV OUT[0], IN[0]\n"
116 " 1: MOV OUT[1], IN[1]\n"
119 handle
= graw_parse_vertex_shader(info
.ctx
, text
);
120 info
.ctx
->bind_vs_state(info
.ctx
, handle
);
125 set_fragment_shader(void)
130 "DCL IN[0], FACE, CONSTANT\n"
131 "DCL IN[1], GENERIC, CONSTANT\n"
132 "DCL OUT[0], COLOR\n"
134 "IMM FLT32 { 1.0, 0.0, 0.0, 0.0 }\n"
135 "IMM FLT32 { 0.0, 1.0, 0.0, 0.0 }\n"
136 "IMM FLT32 { 0.5, 0.6, 0.0, 0.0 }\n"
137 " 0: SGT TEMP[0].x, IN[0].xxxx, IMM[1].xxxx\n" /* TMP[0].x = IN[0].x > 0.0 */
138 " 1: IF TEMP[0].xxxx :4\n"
139 " 2: MOV OUT[0], IMM[0]\n" /* front-facing: red */
141 " 4: MOV OUT[0], IMM[1]\n" /* back-facing: green */
145 handle
= graw_parse_fragment_shader(info
.ctx
, text
);
146 info
.ctx
->bind_fs_state(info
.ctx
, handle
);
153 union pipe_color_union clear_color
;
155 clear_color
.f
[0] = 0.25;
156 clear_color
.f
[1] = 0.25;
157 clear_color
.f
[2] = 0.25;
158 clear_color
.f
[3] = 1.00;
160 info
.ctx
->clear(info
.ctx
,
161 PIPE_CLEAR_COLOR
| PIPE_CLEAR_DEPTHSTENCIL
,
163 &clear_color
, 1.0, 0);
164 util_draw_arrays(info
.ctx
, PIPE_PRIM_QUADS
, 0, NUM_VERTS
);
165 info
.ctx
->flush(info
.ctx
, NULL
, 0);
167 graw_util_flush_front(&info
);
178 set_viewport(0, 0, width
, height
, 30, 1000);
186 if (!graw_util_create_window(&info
, width
, height
, 1, TRUE
))
189 graw_util_default_state(&info
, TRUE
);
191 graw_util_viewport(&info
, 0, 0, width
, height
, -1.0, 1.0);
195 set_fragment_shader();
200 main(int argc
, char *argv
[])
204 printf("Left quad: clock-wise, front-facing, red\n");
205 printf("Right quad: counter clock-wise, back-facing, green\n");
207 graw_set_display_func(draw
);
208 /*graw_set_reshape_func(resize);*/