graw: fix tests to build on msvc again.
[mesa.git] / src / gallium / tests / graw / tri.c
index 4dbd2c062a5f6ac96050811529b80e4e6d32e9fb..11f8bb35cafc2937f2a351e0f71bc813dc24be26 100644 (file)
@@ -2,13 +2,14 @@
  * any utility code, just the graw interface and gallium.
  */
 
+#include <stdio.h>
+
 #include "state_tracker/graw.h"
 #include "pipe/p_screen.h"
 #include "pipe/p_context.h"
 #include "pipe/p_state.h"
 #include "pipe/p_defines.h"
 
-#include "util/u_debug.h"       /* debug_dump_surface_bmp() */
 #include "util/u_memory.h"      /* Offset() */
 #include "util/u_draw_quad.h"
 
@@ -24,6 +25,7 @@ static const int HEIGHT = 300;
 static struct pipe_screen *screen = NULL;
 static struct pipe_context *ctx = NULL;
 static struct pipe_surface *surf = NULL;
+static struct pipe_resource *tex = NULL;
 static void *window = NULL;
 
 struct vertex {
@@ -31,16 +33,19 @@ struct vertex {
    float color[4];
 };
 
-static struct vertex vertices[4] =
+static struct vertex vertices[3] =
 {
-   { { 0.0f, -0.9f, 0.0f, 1.0f },
-     { 1.0f, 0.0f, 0.0f, 1.0f }
+   {
+      { 0.0f, -0.9f, 0.0f, 1.0f },
+      { 1.0f, 0.0f, 0.0f, 1.0f }
    },
-   { { -0.9f, 0.9f, 0.0f, 1.0f },
-     { 0.0f, 1.0f, 0.0f, 1.0f }
+   {
+      { -0.9f, 0.9f, 0.0f, 1.0f },
+      { 0.0f, 1.0f, 0.0f, 1.0f }
    },
-   { { 0.9f, 0.9f, 0.0f, 1.0f },
-     { 0.0f, 0.0f, 1.0f, 1.0f }
+   {
+      { 0.9f, 0.9f, 0.0f, 1.0f },
+      { 0.0f, 0.0f, 1.0f, 1.0f }
    }
 };
 
@@ -88,7 +93,6 @@ static void set_vertices( void )
 
 
    vbuf.stride = sizeof( struct vertex );
-   vbuf.max_index = sizeof(vertices) / vbuf.stride;
    vbuf.buffer_offset = 0;
    vbuf.buffer = screen->user_buffer_create(screen,
                                             vertices,
@@ -132,32 +136,23 @@ static void set_fragment_shader( void )
 
 static void draw( void )
 {
-   float clear_color[4] = {1,0,1,1};
+   union pipe_color_union clear_color = { {1,0,1,1} };
 
-   ctx->clear(ctx, PIPE_CLEAR_COLOR, clear_color, 0, 0);
+   ctx->clear(ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
    util_draw_arrays(ctx, PIPE_PRIM_TRIANGLES, 0, 3);
-   ctx->flush(ctx, PIPE_FLUSH_RENDER_CACHE, NULL);
+   ctx->flush(ctx, NULL);
 
-#if 0
-   /* At the moment, libgraw leaks out/makes available some of the
-    * symbols from gallium/auxiliary, including these debug helpers.
-    * Will eventually want to bless some of these paths, and lock the
-    * others down so they aren't accessible from test programs.
-    *
-    * This currently just happens to work on debug builds - a release
-    * build will probably fail to link here:
-    */
-   debug_dump_surface_bmp(ctx, "result.bmp", surf);
-#endif
+   graw_save_surface_to_file(ctx, surf, NULL);
 
-   screen->flush_frontbuffer(screen, surf, window);
+   screen->flush_frontbuffer(screen, tex, 0, 0, window);
 }
 
 
 static void init( void )
 {
    struct pipe_framebuffer_state fb;
-   struct pipe_resource *tex, templat;
+   struct pipe_resource templat;
+   struct pipe_surface surf_tmpl;
    int i;
 
    /* It's hard to say whether window or screen should be created
@@ -166,24 +161,30 @@ static void init( void )
     * Also, no easy way of querying supported formats if the screen
     * cannot be created first.
     */
-   for (i = 0; 
-        window == NULL && formats[i] != PIPE_FORMAT_NONE;
-        i++) {
-      
-      screen = graw_create_window_and_screen(0,0,300,300,
+   for (i = 0; formats[i] != PIPE_FORMAT_NONE; i++) {
+      screen = graw_create_window_and_screen(0, 0, 300, 300,
                                              formats[i],
                                              &window);
+      if (window && screen)
+         break;
+   }
+   if (!screen || !window) {
+      fprintf(stderr, "Unable to create window\n");
+      exit(1);
    }
    
    ctx = screen->context_create(screen, NULL);
-   if (ctx == NULL)
+   if (ctx == NULL) {
+      fprintf(stderr, "Unable to create context!\n");
       exit(3);
+   }
 
    templat.target = PIPE_TEXTURE_2D;
    templat.format = formats[i];
    templat.width0 = WIDTH;
    templat.height0 = HEIGHT;
    templat.depth0 = 1;
+   templat.array_size = 1;
    templat.last_level = 0;
    templat.nr_samples = 1;
    templat.bind = (PIPE_BIND_RENDER_TARGET |
@@ -191,14 +192,21 @@ static void init( void )
    
    tex = screen->resource_create(screen,
                                  &templat);
-   if (tex == NULL)
+   if (tex == NULL) {
+      fprintf(stderr, "Unable to create screen texture!\n");
       exit(4);
+   }
 
-   surf = screen->get_tex_surface(screen, tex, 0, 0, 0,
-                                  PIPE_BIND_RENDER_TARGET |
-                                  PIPE_BIND_DISPLAY_TARGET);
-   if (surf == NULL)
+   surf_tmpl.format = templat.format;
+   surf_tmpl.usage = PIPE_BIND_RENDER_TARGET;
+   surf_tmpl.u.tex.level = 0;
+   surf_tmpl.u.tex.first_layer = 0;
+   surf_tmpl.u.tex.last_layer = 0;
+   surf = ctx->create_surface(ctx, tex, &surf_tmpl);
+   if (surf == NULL) {
+      fprintf(stderr, "Unable to create tex surface!\n");
       exit(5);
+   }
 
    memset(&fb, 0, sizeof fb);
    fb.nr_cbufs = 1;
@@ -241,9 +249,21 @@ static void init( void )
    set_fragment_shader();
 }
 
+static void args(int argc, char *argv[])
+{
+   int i;
+
+   for (i = 1; i < argc;) {
+      if (graw_parse_args(&i, argc, argv)) {
+         continue;
+      }
+      exit(1);
+   }
+}
 
 int main( int argc, char *argv[] )
 {
+   args(argc, argv);
    init();
 
    graw_set_display_func( draw );