1 /* Test sRGB texturing.
7 static const int WIDTH
= 600;
8 static const int HEIGHT
= 300;
10 static struct graw_info info
;
12 static struct pipe_resource
*texture
;
13 static struct pipe_sampler_view
*linear_sv
, *srgb_sv
;
21 static struct vertex vertices1
[] =
23 { { -0.1, -0.9, 0.0, 1.0 },
26 { { -0.1, 0.9, 0.0, 1.0 },
29 { {-0.9, 0.9, 0.0, 1.0 },
32 { {-0.9, -0.9, 0.0, 1.0 },
37 static struct vertex vertices2
[] =
39 { { 0.9, -0.9, 0.0, 1.0 },
42 { { 0.9, 0.9, 0.0, 1.0 },
45 { { 0.1, 0.9, 0.0, 1.0 },
48 { { 0.1, -0.9, 0.0, 1.0 },
56 set_vertices(struct vertex
*verts
, unsigned num_verts
)
58 struct pipe_vertex_element ve
[2];
59 struct pipe_vertex_buffer vbuf
;
62 memset(ve
, 0, sizeof ve
);
64 ve
[0].src_offset
= Offset(struct vertex
, position
);
65 ve
[0].src_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
66 ve
[1].src_offset
= Offset(struct vertex
, color
);
67 ve
[1].src_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
69 handle
= info
.ctx
->create_vertex_elements_state(info
.ctx
, 2, ve
);
70 info
.ctx
->bind_vertex_elements_state(info
.ctx
, handle
);
72 memset(&vbuf
, 0, sizeof vbuf
);
74 vbuf
.stride
= sizeof(struct vertex
);
75 vbuf
.buffer_offset
= 0;
76 vbuf
.buffer
= pipe_buffer_create_with_data(info
.ctx
,
77 PIPE_BIND_VERTEX_BUFFER
,
79 num_verts
* sizeof(struct vertex
),
82 info
.ctx
->set_vertex_buffers(info
.ctx
, 0, 1, &vbuf
);
85 static void set_vertex_shader( void )
92 "DCL OUT[0], POSITION\n"
93 "DCL OUT[1], GENERIC[0]\n"
94 " 0: MOV OUT[1], IN[1]\n"
95 " 1: MOV OUT[0], IN[0]\n"
98 handle
= graw_parse_vertex_shader(info
.ctx
, text
);
99 info
.ctx
->bind_vs_state(info
.ctx
, handle
);
102 static void set_fragment_shader( void )
107 "DCL IN[0], GENERIC[0], PERSPECTIVE\n"
108 "DCL OUT[0], COLOR\n"
111 "DCL SVIEW[0], 2D, FLOAT\n"
112 " 0: TXP TEMP[0], IN[0], SAMP[0], 2D\n"
113 " 1: MOV OUT[0], TEMP[0]\n"
116 handle
= graw_parse_fragment_shader(info
.ctx
, text
);
117 info
.ctx
->bind_fs_state(info
.ctx
, handle
);
121 static void draw( void )
123 union pipe_color_union clear_color
;
125 clear_color
.f
[0] = 0.5;
126 clear_color
.f
[1] = 0.5;
127 clear_color
.f
[2] = 0.5;
128 clear_color
.f
[3] = 1.0;
130 info
.ctx
->clear(info
.ctx
, PIPE_CLEAR_COLOR
, &clear_color
, 0, 0);
132 info
.ctx
->set_sampler_views(info
.ctx
, PIPE_SHADER_FRAGMENT
, 0, 1, &linear_sv
);
133 set_vertices(vertices1
, 4);
134 util_draw_arrays(info
.ctx
, PIPE_PRIM_QUADS
, 0, 4);
136 info
.ctx
->set_sampler_views(info
.ctx
, PIPE_SHADER_FRAGMENT
, 0, 1, &srgb_sv
);
137 set_vertices(vertices2
, 4);
138 util_draw_arrays(info
.ctx
, PIPE_PRIM_QUADS
, 0, 4);
140 info
.ctx
->flush(info
.ctx
, NULL
, 0);
142 graw_util_flush_front(&info
);
146 static void init_tex( void )
149 ubyte tex2d
[SIZE
][SIZE
][4];
152 for (s
= 0; s
< SIZE
; s
++) {
153 for (t
= 0; t
< SIZE
; t
++) {
155 tex2d
[t
][s
][1] = s
* 255 / SIZE
;
156 tex2d
[t
][s
][2] = t
* 255 / SIZE
;
157 tex2d
[t
][s
][3] = 255;
161 texture
= graw_util_create_tex2d(&info
, SIZE
, SIZE
,
162 PIPE_FORMAT_B8G8R8A8_UNORM
, tex2d
);
166 sampler
= graw_util_create_simple_sampler(&info
,
167 PIPE_TEX_WRAP_REPEAT
,
168 PIPE_TEX_FILTER_NEAREST
);
169 info
.ctx
->bind_sampler_states(info
.ctx
, PIPE_SHADER_FRAGMENT
,
173 /* linear sampler view */
175 struct pipe_sampler_view sv_temp
;
176 memset(&sv_temp
, 0, sizeof sv_temp
);
177 sv_temp
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
178 sv_temp
.texture
= texture
;
179 sv_temp
.swizzle_r
= PIPE_SWIZZLE_X
;
180 sv_temp
.swizzle_g
= PIPE_SWIZZLE_Y
;
181 sv_temp
.swizzle_b
= PIPE_SWIZZLE_Z
;
182 sv_temp
.swizzle_a
= PIPE_SWIZZLE_W
;
183 linear_sv
= info
.ctx
->create_sampler_view(info
.ctx
, texture
, &sv_temp
);
184 if (linear_sv
== NULL
)
188 /* srgb sampler view */
190 struct pipe_sampler_view sv_temp
;
191 memset(&sv_temp
, 0, sizeof sv_temp
);
192 sv_temp
.format
= PIPE_FORMAT_B8G8R8A8_SRGB
;
193 sv_temp
.texture
= texture
;
194 sv_temp
.swizzle_r
= PIPE_SWIZZLE_X
;
195 sv_temp
.swizzle_g
= PIPE_SWIZZLE_Y
;
196 sv_temp
.swizzle_b
= PIPE_SWIZZLE_Z
;
197 sv_temp
.swizzle_a
= PIPE_SWIZZLE_W
;
198 srgb_sv
= info
.ctx
->create_sampler_view(info
.ctx
, texture
, &sv_temp
);
205 static void init( void )
207 if (!graw_util_create_window(&info
, WIDTH
, HEIGHT
, 1, FALSE
))
210 graw_util_default_state(&info
, FALSE
);
212 graw_util_viewport(&info
, 0, 0, WIDTH
, HEIGHT
, 30, 10000);
217 set_fragment_shader();
221 int main( int argc
, char *argv
[] )
225 graw_set_display_func( draw
);