Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  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 <stdio.h>
  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"
  11.  
  12. enum pipe_format formats[] = {
  13.    PIPE_FORMAT_RGBA8888_UNORM,
  14.    PIPE_FORMAT_BGRA8888_UNORM,
  15.    PIPE_FORMAT_NONE
  16. };
  17.  
  18. static const int WIDTH = 300;
  19. static const int HEIGHT = 300;
  20.  
  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;
  26.  
  27. static void draw( void )
  28. {
  29.    union pipe_color_union clear_color = { {1, 0, 1, 1} };
  30.  
  31.    ctx->clear(ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
  32.    ctx->flush(ctx, NULL, 0);
  33.  
  34.    graw_save_surface_to_file(ctx, surf, NULL);
  35.  
  36.    screen->flush_frontbuffer(screen, tex, 0, 0, window);
  37. }
  38.  
  39. static void init( void )
  40. {
  41.    struct pipe_framebuffer_state fb;
  42.    struct pipe_resource templat;
  43.    struct pipe_surface surf_tmpl;
  44.    int i;
  45.  
  46.    /* It's hard to say whether window or screen should be created
  47.     * first.  Different environments would prefer one or the other.
  48.     *
  49.     * Also, no easy way of querying supported formats if the screen
  50.     * cannot be created first.
  51.     */
  52.    for (i = 0; formats[i] != PIPE_FORMAT_NONE; i++) {
  53.       screen = graw_create_window_and_screen(0, 0, 300, 300,
  54.                                              formats[i],
  55.                                              &window);
  56.       if (window && screen)
  57.          break;
  58.    }
  59.    if (!screen || !window) {
  60.       fprintf(stderr, "Unable to create window\n");
  61.       exit(1);
  62.    }
  63.    
  64.    ctx = screen->context_create(screen, NULL);
  65.    if (ctx == NULL)
  66.       exit(3);
  67.  
  68.    templat.target = PIPE_TEXTURE_2D;
  69.    templat.format = formats[i];
  70.    templat.width0 = WIDTH;
  71.    templat.height0 = HEIGHT;
  72.    templat.depth0 = 1;
  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);
  78.    
  79.    tex = screen->resource_create(screen,
  80.                                  &templat);
  81.    if (tex == NULL)
  82.       exit(4);
  83.  
  84.    surf_tmpl.format = templat.format;
  85.    surf_tmpl.u.tex.level = 0;
  86.    surf_tmpl.u.tex.first_layer = 0;
  87.    surf_tmpl.u.tex.last_layer = 0;
  88.    surf = ctx->create_surface(ctx, tex, &surf_tmpl);
  89.    if (surf == NULL)
  90.       exit(5);
  91.  
  92.    memset(&fb, 0, sizeof fb);
  93.    fb.nr_cbufs = 1;
  94.    fb.width = WIDTH;
  95.    fb.height = HEIGHT;
  96.    fb.cbufs[0] = surf;
  97.  
  98.    ctx->set_framebuffer_state(ctx, &fb);
  99. }
  100.  
  101. static void args(int argc, char *argv[])
  102. {
  103.    int i;
  104.  
  105.    for (i = 1; i < argc;) {
  106.       if (graw_parse_args(&i, argc, argv)) {
  107.          continue;
  108.       }
  109.       exit(1);
  110.    }
  111. }
  112.  
  113. int main( int argc, char *argv[] )
  114. {
  115.    args(argc, argv);
  116.    init();
  117.  
  118.    graw_set_display_func( draw );
  119.    graw_main_loop();
  120.    return 0;
  121. }
  122.