1 /* Display a cleared blue window. This demo has no dependencies on
2 * any utility code, just the graw interface and gallium.
6 #include "state_tracker/graw.h"
7 #include "pipe/p_screen.h"
8 #include "pipe/p_context.h"
9 #include "pipe/p_state.h"
10 #include "pipe/p_defines.h"
12 enum pipe_format formats[] = {
13 PIPE_FORMAT_R8G8B8A8_UNORM,
14 PIPE_FORMAT_B8G8R8A8_UNORM,
18 static const int WIDTH = 300;
19 static const int HEIGHT = 300;
21 struct pipe_screen *screen;
22 struct pipe_context *ctx;
23 struct pipe_surface *surf;
24 struct pipe_resource *tex;
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, NULL);
34 graw_save_surface_to_file(ctx, surf, NULL);
36 screen->flush_frontbuffer(screen, tex, 0, 0, window);
39 static void init( void )
41 struct pipe_framebuffer_state fb;
42 struct pipe_resource templat;
43 struct pipe_surface surf_tmpl;
46 /* It's hard to say whether window or screen should be created
47 * first. Different environments would prefer one or the other.
49 * Also, no easy way of querying supported formats if the screen
50 * cannot be created first.
52 for (i = 0; formats[i] != PIPE_FORMAT_NONE; i++) {
53 screen = graw_create_window_and_screen(0, 0, 300, 300,
59 if (!screen || !window) {
60 fprintf(stderr, "Unable to create window\n");
64 ctx = screen->context_create(screen, NULL);
68 templat.target = PIPE_TEXTURE_2D;
69 templat.format = formats[i];
70 templat.width0 = WIDTH;
71 templat.height0 = HEIGHT;
73 templat.array_size = 1;
74 templat.last_level = 0;
75 templat.nr_samples = 1;
76 templat.bind = (PIPE_BIND_RENDER_TARGET |
77 PIPE_BIND_DISPLAY_TARGET);
79 tex = screen->resource_create(screen,
84 surf_tmpl.format = templat.format;
85 surf_tmpl.usage = PIPE_BIND_RENDER_TARGET;
86 surf_tmpl.u.tex.level = 0;
87 surf_tmpl.u.tex.first_layer = 0;
88 surf_tmpl.u.tex.last_layer = 0;
89 surf = ctx->create_surface(ctx, tex, &surf_tmpl);
93 memset(&fb, 0, sizeof fb);
99 ctx->set_framebuffer_state(ctx, &fb);
102 static void args(int argc, char *argv[])
106 for (i = 1; i < argc;) {
107 if (graw_parse_args(&i, argc, argv)) {
114 int main( int argc, char *argv[] )
119 graw_set_display_func( draw );