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
);
73 vbuf
.stride
= sizeof(struct vertex
);
74 vbuf
.buffer_offset
= 0;
75 vbuf
.buffer
= info
.screen
->user_buffer_create(info
.screen
,
77 num_verts
*sizeof(struct vertex
),
78 PIPE_BIND_VERTEX_BUFFER
);
80 info
.ctx
->set_vertex_buffers(info
.ctx
, 1, &vbuf
);
83 static void set_vertex_shader( void )
90 "DCL OUT[0], POSITION\n"
91 "DCL OUT[1], GENERIC[0]\n"
92 " 0: MOV OUT[1], IN[1]\n"
93 " 1: MOV OUT[0], IN[0]\n"
96 handle
= graw_parse_vertex_shader(info
.ctx
, text
);
97 info
.ctx
->bind_vs_state(info
.ctx
, handle
);
100 static void set_fragment_shader( void )
105 "DCL IN[0], GENERIC[0], PERSPECTIVE\n"
106 "DCL OUT[0], COLOR\n"
109 " 0: TXP TEMP[0], IN[0], SAMP[0], 2D\n"
110 " 1: MOV OUT[0], TEMP[0]\n"
113 handle
= graw_parse_fragment_shader(info
.ctx
, text
);
114 info
.ctx
->bind_fs_state(info
.ctx
, handle
);
118 static void draw( void )
120 union pipe_color_union clear_color
;
122 clear_color
.f
[0] = 0.5;
123 clear_color
.f
[1] = 0.5;
124 clear_color
.f
[2] = 0.5;
125 clear_color
.f
[3] = 1.0;
127 info
.ctx
->clear(info
.ctx
, PIPE_CLEAR_COLOR
, &clear_color
, 0, 0);
129 info
.ctx
->set_fragment_sampler_views(info
.ctx
, 1, &linear_sv
);
130 set_vertices(vertices1
, 4);
131 util_draw_arrays(info
.ctx
, PIPE_PRIM_QUADS
, 0, 4);
133 info
.ctx
->set_fragment_sampler_views(info
.ctx
, 1, &srgb_sv
);
134 set_vertices(vertices2
, 4);
135 util_draw_arrays(info
.ctx
, PIPE_PRIM_QUADS
, 0, 4);
137 info
.ctx
->flush(info
.ctx
, NULL
);
139 graw_util_flush_front(&info
);
143 static void init_tex( void )
146 ubyte tex2d
[SIZE
][SIZE
][4];
149 for (s
= 0; s
< SIZE
; s
++) {
150 for (t
= 0; t
< SIZE
; t
++) {
152 tex2d
[t
][s
][1] = s
* 255 / SIZE
;
153 tex2d
[t
][s
][2] = t
* 255 / SIZE
;
154 tex2d
[t
][s
][3] = 255;
158 texture
= graw_util_create_tex2d(&info
, SIZE
, SIZE
,
159 PIPE_FORMAT_B8G8R8A8_UNORM
, tex2d
);
163 sampler
= graw_util_create_simple_sampler(&info
,
164 PIPE_TEX_WRAP_REPEAT
,
165 PIPE_TEX_FILTER_NEAREST
);
166 info
.ctx
->bind_fragment_sampler_states(info
.ctx
, 1, &sampler
);
169 /* linear sampler view */
171 struct pipe_sampler_view sv_temp
;
172 memset(&sv_temp
, 0, sizeof sv_temp
);
173 sv_temp
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
174 sv_temp
.texture
= texture
;
175 sv_temp
.swizzle_r
= PIPE_SWIZZLE_RED
;
176 sv_temp
.swizzle_g
= PIPE_SWIZZLE_GREEN
;
177 sv_temp
.swizzle_b
= PIPE_SWIZZLE_BLUE
;
178 sv_temp
.swizzle_a
= PIPE_SWIZZLE_ALPHA
;
179 linear_sv
= info
.ctx
->create_sampler_view(info
.ctx
, texture
, &sv_temp
);
180 if (linear_sv
== NULL
)
184 /* srgb sampler view */
186 struct pipe_sampler_view sv_temp
;
187 memset(&sv_temp
, 0, sizeof sv_temp
);
188 sv_temp
.format
= PIPE_FORMAT_B8G8R8A8_SRGB
;
189 sv_temp
.texture
= texture
;
190 sv_temp
.swizzle_r
= PIPE_SWIZZLE_RED
;
191 sv_temp
.swizzle_g
= PIPE_SWIZZLE_GREEN
;
192 sv_temp
.swizzle_b
= PIPE_SWIZZLE_BLUE
;
193 sv_temp
.swizzle_a
= PIPE_SWIZZLE_ALPHA
;
194 srgb_sv
= info
.ctx
->create_sampler_view(info
.ctx
, texture
, &sv_temp
);
201 static void init( void )
203 if (!graw_util_create_window(&info
, WIDTH
, HEIGHT
, 1, FALSE
))
206 graw_util_default_state(&info
, FALSE
);
208 graw_util_viewport(&info
, 0, 0, WIDTH
, HEIGHT
, 30, 10000);
213 set_fragment_shader();
217 int main( int argc
, char *argv
[] )
221 graw_set_display_func( draw
);