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() */
12 #include "os/os_time.h" /* os_time_sleep() */
14 enum pipe_format formats
[] = {
15 PIPE_FORMAT_R8G8B8A8_UNORM
,
16 PIPE_FORMAT_B8G8R8A8_UNORM
,
20 static const int WIDTH
= 300;
21 static const int HEIGHT
= 300;
23 struct pipe_screen
*screen
;
24 struct pipe_context
*ctx
;
25 struct pipe_surface
*surf
;
26 static void *window
= NULL
;
28 static void draw( void )
30 float clear_color
[4] = {1,0,1,1};
32 ctx
->clear(ctx
, PIPE_CLEAR_COLOR
, clear_color
, 0, 0);
33 ctx
->flush(ctx
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
36 /* At the moment, libgraw leaks out/makes available some of the
37 * symbols from gallium/auxiliary, including these debug helpers.
38 * Will eventually want to bless some of these paths, and lock the
39 * others down so they aren't accessible from test programs.
41 * This currently just happens to work on debug builds - a release
42 * build will probably fail to link here:
44 debug_dump_surface_bmp(ctx
, "result.bmp", surf
);
47 screen
->flush_frontbuffer(screen
, surf
, window
);
50 static void init( void )
52 struct pipe_framebuffer_state fb
;
53 struct pipe_resource
*tex
, templat
;
56 /* It's hard to say whether window or screen should be created
57 * first. Different environments would prefer one or the other.
59 * Also, no easy way of querying supported formats if the screen
60 * cannot be created first.
63 window
== NULL
&& formats
[i
] != PIPE_FORMAT_NONE
;
66 screen
= graw_create_window_and_screen(0,0,300,300,
73 ctx
= screen
->context_create(screen
, NULL
);
77 templat
.target
= PIPE_TEXTURE_2D
;
78 templat
.format
= formats
[i
];
79 templat
.width0
= WIDTH
;
80 templat
.height0
= HEIGHT
;
82 templat
.last_level
= 0;
83 templat
.nr_samples
= 1;
84 templat
.bind
= (PIPE_BIND_RENDER_TARGET
|
85 PIPE_BIND_DISPLAY_TARGET
);
87 tex
= screen
->resource_create(screen
,
92 surf
= screen
->get_tex_surface(screen
, tex
, 0, 0, 0,
93 PIPE_BIND_RENDER_TARGET
|
94 PIPE_BIND_DISPLAY_TARGET
);
98 memset(&fb
, 0, sizeof fb
);
104 ctx
->set_framebuffer_state(ctx
, &fb
);
109 int main( int argc
, char *argv
[] )
113 graw_set_display_func( draw
);