Merge remote branch 'origin/7.8'
[mesa.git] / progs / gallium / raw / clear.c
1 /* Display a cleared blue window. This demo has no dependencies on
2 * any utility code, just the graw interface and gallium.
3 */
4
5 #include "state_tracker/graw.h"
6 #include "pipe/p_screen.h"
7 #include "pipe/p_context.h"
8 #include "pipe/p_state.h"
9 #include "pipe/p_defines.h"
10 #include <unistd.h> /* for sleep() */
11
12 #include "util/u_debug.h" /* debug_dump_surface_bmp() */
13
14 enum pipe_format formats[] = {
15 PIPE_FORMAT_R8G8B8A8_UNORM,
16 PIPE_FORMAT_B8G8R8A8_UNORM,
17 PIPE_FORMAT_NONE
18 };
19
20 static const int WIDTH = 300;
21 static const int HEIGHT = 300;
22
23 int main( int argc, char *argv[] )
24 {
25 struct pipe_screen *screen;
26 struct pipe_context *pipe;
27 struct pipe_surface *surf;
28 struct pipe_framebuffer_state fb;
29 struct pipe_texture *tex, templat;
30 void *window = NULL;
31 float clear_color[4] = {1,0,1,1};
32 int i;
33
34 screen = graw_init();
35 if (screen == NULL)
36 exit(1);
37
38 for (i = 0;
39 window == NULL && formats[i] != PIPE_FORMAT_NONE;
40 i++) {
41
42 window = graw_create_window(0,0,300,300, formats[i]);
43 }
44
45 if (window == NULL)
46 exit(2);
47
48 pipe = screen->context_create(screen, NULL);
49 if (pipe == NULL)
50 exit(3);
51
52 templat.target = PIPE_TEXTURE_2D;
53 templat.format = formats[i];
54 templat.width0 = WIDTH;
55 templat.height0 = HEIGHT;
56 templat.depth0 = 1;
57 templat.last_level = 0;
58 templat.nr_samples = 1;
59 templat.tex_usage = (PIPE_TEXTURE_USAGE_RENDER_TARGET |
60 PIPE_TEXTURE_USAGE_DISPLAY_TARGET);
61
62 tex = screen->texture_create(screen,
63 &templat);
64 if (tex == NULL)
65 exit(4);
66
67 surf = screen->get_tex_surface(screen, tex, 0, 0, 0,
68 PIPE_TEXTURE_USAGE_RENDER_TARGET |
69 PIPE_TEXTURE_USAGE_DISPLAY_TARGET);
70 if (surf == NULL)
71 exit(5);
72
73 memset(&fb, 0, sizeof fb);
74 fb.nr_cbufs = 1;
75 fb.width = WIDTH;
76 fb.height = HEIGHT;
77 fb.cbufs[0] = surf;
78
79 pipe->set_framebuffer_state(pipe, &fb);
80 pipe->clear(pipe, PIPE_CLEAR_COLOR, clear_color, 0, 0);
81 pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
82
83 /* At the moment, libgraw includes/makes available all the symbols
84 * from gallium/auxiliary, including these debug helpers. Will
85 * eventually want to bless some of these paths, and lock the
86 * others down so they aren't accessible from test programs.
87 */
88 if (0)
89 debug_dump_surface_bmp(pipe, "result.bmp", surf);
90
91 screen->flush_frontbuffer(screen, surf, window);
92
93 sleep(100);
94 return 0;
95 }