1 /* Display a cleared blue window. This demo has no dependencies on
2 * any utility code, just the graw interface and gallium.
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"
11 #include "util/u_debug.h" /* debug_dump_surface_bmp() */
13 enum pipe_format formats
[] = {
14 PIPE_FORMAT_R8G8B8A8_UNORM
,
15 PIPE_FORMAT_B8G8R8A8_UNORM
,
19 static const int WIDTH
= 300;
20 static const int HEIGHT
= 300;
22 struct pipe_screen
*screen
;
23 struct pipe_context
*ctx
;
24 struct pipe_surface
*surf
;
25 static void *window
= NULL
;
27 static void draw( void )
29 float clear_color
[4] = {1,0,1,1};
31 ctx
->clear(ctx
, PIPE_CLEAR_COLOR
, clear_color
, 0, 0);
32 ctx
->flush(ctx
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
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.
40 * This currently just happens to work on debug builds - a release
41 * build will probably fail to link here:
43 debug_dump_surface_bmp(ctx
, "result.bmp", surf
);
46 screen
->flush_frontbuffer(screen
, surf
, window
);
49 static void init( void )
51 struct pipe_framebuffer_state fb
;
52 struct pipe_resource
*tex
, templat
;
55 /* It's hard to say whether window or screen should be created
56 * first. Different environments would prefer one or the other.
58 * Also, no easy way of querying supported formats if the screen
59 * cannot be created first.
62 window
== NULL
&& formats
[i
] != PIPE_FORMAT_NONE
;
65 screen
= graw_create_window_and_screen(0,0,300,300,
72 ctx
= screen
->context_create(screen
, NULL
);
76 templat
.target
= PIPE_TEXTURE_2D
;
77 templat
.format
= formats
[i
];
78 templat
.width0
= WIDTH
;
79 templat
.height0
= HEIGHT
;
81 templat
.last_level
= 0;
82 templat
.nr_samples
= 1;
83 templat
.bind
= (PIPE_BIND_RENDER_TARGET
|
84 PIPE_BIND_DISPLAY_TARGET
);
86 tex
= screen
->resource_create(screen
,
91 surf
= screen
->get_tex_surface(screen
, tex
, 0, 0, 0,
92 PIPE_BIND_RENDER_TARGET
|
93 PIPE_BIND_DISPLAY_TARGET
);
97 memset(&fb
, 0, sizeof fb
);
103 ctx
->set_framebuffer_state(ctx
, &fb
);
108 int main( int argc
, char *argv
[] )
112 graw_set_display_func( draw
);