graw: new tri-instanced.c program to test instanced drawing
[mesa.git] / src / gallium / tests / graw / 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
11 #include "util/u_debug.h" /* debug_dump_surface_bmp() */
12
13 enum pipe_format formats[] = {
14 PIPE_FORMAT_R8G8B8A8_UNORM,
15 PIPE_FORMAT_B8G8R8A8_UNORM,
16 PIPE_FORMAT_NONE
17 };
18
19 static const int WIDTH = 300;
20 static const int HEIGHT = 300;
21
22 struct pipe_screen *screen;
23 struct pipe_context *ctx;
24 struct pipe_surface *surf;
25 static void *window = NULL;
26
27 static void draw( void )
28 {
29 float clear_color[4] = {1,0,1,1};
30
31 ctx->clear(ctx, PIPE_CLEAR_COLOR, clear_color, 0, 0);
32 ctx->flush(ctx, PIPE_FLUSH_RENDER_CACHE, NULL);
33
34 #if 0
35 /* At the moment, libgraw leaks out/makes available some of the
36 * symbols from gallium/auxiliary, including these debug helpers.
37 * Will eventually want to bless some of these paths, and lock the
38 * others down so they aren't accessible from test programs.
39 *
40 * This currently just happens to work on debug builds - a release
41 * build will probably fail to link here:
42 */
43 debug_dump_surface_bmp(ctx, "result.bmp", surf);
44 #endif
45
46 screen->flush_frontbuffer(screen, surf, window);
47 }
48
49 static void init( void )
50 {
51 struct pipe_framebuffer_state fb;
52 struct pipe_resource *tex, templat;
53 int i;
54
55 /* It's hard to say whether window or screen should be created
56 * first. Different environments would prefer one or the other.
57 *
58 * Also, no easy way of querying supported formats if the screen
59 * cannot be created first.
60 */
61 for (i = 0;
62 window == NULL && formats[i] != PIPE_FORMAT_NONE;
63 i++) {
64
65 screen = graw_create_window_and_screen(0,0,300,300,
66 formats[i],
67 &window);
68 }
69 if (window == NULL)
70 exit(2);
71
72 ctx = screen->context_create(screen, NULL);
73 if (ctx == NULL)
74 exit(3);
75
76 templat.target = PIPE_TEXTURE_2D;
77 templat.format = formats[i];
78 templat.width0 = WIDTH;
79 templat.height0 = HEIGHT;
80 templat.depth0 = 1;
81 templat.last_level = 0;
82 templat.nr_samples = 1;
83 templat.bind = (PIPE_BIND_RENDER_TARGET |
84 PIPE_BIND_DISPLAY_TARGET);
85
86 tex = screen->resource_create(screen,
87 &templat);
88 if (tex == NULL)
89 exit(4);
90
91 surf = screen->get_tex_surface(screen, tex, 0, 0, 0,
92 PIPE_BIND_RENDER_TARGET |
93 PIPE_BIND_DISPLAY_TARGET);
94 if (surf == NULL)
95 exit(5);
96
97 memset(&fb, 0, sizeof fb);
98 fb.nr_cbufs = 1;
99 fb.width = WIDTH;
100 fb.height = HEIGHT;
101 fb.cbufs[0] = surf;
102
103 ctx->set_framebuffer_state(ctx, &fb);
104 }
105
106
107
108 int main( int argc, char *argv[] )
109 {
110 init();
111
112 graw_set_display_func( draw );
113 graw_main_loop();
114 return 0;
115 }