graw: move towards glut-like interface, add tri.c
authorKeith Whitwell <keithw@vmware.com>
Fri, 14 May 2010 11:07:38 +0000 (12:07 +0100)
committerKeith Whitwell <keithw@vmware.com>
Fri, 14 May 2010 11:19:57 +0000 (12:19 +0100)
src/gallium/include/state_tracker/graw.h
src/gallium/targets/graw-xlib/graw_xlib.c
src/gallium/tests/graw/SConscript
src/gallium/tests/graw/clear.c

index 385e4d7718eadedcf0237b9081ce2849fdbc8c62..87e7d97543ab9cac94dc18ad3cbfd2dc7ad22f3a 100644 (file)
@@ -17,6 +17,7 @@
 #include "pipe/p_format.h"
 
 struct pipe_screen;
+struct pipe_context;
 
 PUBLIC struct pipe_screen *graw_init( void );
 
@@ -32,5 +33,13 @@ PUBLIC void *graw_create_window( int x,
                                  enum pipe_format format );
 
 PUBLIC void graw_destroy_window( void *handle );
+PUBLIC void graw_set_display_func( void (*func)( void ) );
+PUBLIC void graw_main_loop( void );
+
+PUBLIC void *graw_parse_vertex_shader( struct pipe_context *pipe,
+                                       const char *text );
+
+PUBLIC void *graw_parse_fragment_shader( struct pipe_context *pipe,
+                                         const char *text );
 
 #endif
index 21715c26fdc88af3c9f2cf60649b1f9008f9d35b..d0e3e4bdd6b4b87ca783c493bb27c4079d23b4ae 100644 (file)
@@ -1,6 +1,8 @@
 #include "pipe/p_compiler.h"
+#include "pipe/p_context.h"
 #include "util/u_debug.h"
 #include "util/u_memory.h"
+#include "tgsi/tgsi_text.h"
 #include "target-helpers/wrap_screen.h"
 #include "state_tracker/xlib_sw_winsys.h"
 
@@ -27,6 +29,7 @@
 
 static struct {
    Display *display;
+   void (*draw)(void);
 } graw;
 
 
@@ -179,3 +182,49 @@ graw_destroy_window( void *xlib_drawable )
 {
 }
 
+void 
+graw_set_display_func( void (*draw)( void ) )
+{
+   graw.draw = draw;
+}
+
+void
+graw_main_loop( void )
+{
+   int i;
+   for (i = 0; i < 10; i++) {
+      graw.draw();
+      sleep(1);
+   }
+}
+
+
+
+/* Helper functions.  These are the same for all graw implementations.
+ */
+void *graw_parse_vertex_shader(struct pipe_context *pipe,
+                               const char *text)
+{
+   struct tgsi_token tokens[1024];
+   struct pipe_shader_state state;
+
+   if (!tgsi_text_translate(text, tokens, Elements(tokens)))
+      return NULL;
+
+   state.tokens = tokens;
+   return pipe->create_vs_state(pipe, &state);
+}
+
+void *graw_parse_fragment_shader(struct pipe_context *pipe,
+                                 const char *text)
+{
+   struct tgsi_token tokens[1024];
+   struct pipe_shader_state state;
+
+   if (!tgsi_text_translate(text, tokens, Elements(tokens)))
+      return NULL;
+
+   state.tokens = tokens;
+   return pipe->create_fs_state(pipe, &state);
+}
+
index 8a92ac2c499dba96168da0070dd2f34404d75f71..1dc8dca381dbea094ece70d2e23663c651a8d635 100644 (file)
@@ -12,7 +12,8 @@ env.Prepend(LIBPATH = [graw.dir])
 env.Prepend(LIBS = ['graw'])
 
 progs = [
-    'clear'
+    'clear',
+    'tri'
 ]
 
 for prog in progs:
index 84dd7807337629872bd7848923418d7712397139..adcbb08308fd2b215c307efa182a96d8f2e3f09d 100644 (file)
@@ -20,21 +20,39 @@ enum pipe_format formats[] = {
 static const int WIDTH = 300;
 static const int HEIGHT = 300;
 
-int main( int argc, char *argv[] )
+struct pipe_screen *screen;
+struct pipe_context *ctx;
+struct pipe_surface *surf;
+static void *window = NULL;
+
+static void draw( void )
+{
+   float clear_color[4] = {1,0,1,1};
+
+   ctx->clear(ctx, PIPE_CLEAR_COLOR, clear_color, 0, 0);
+   ctx->flush(ctx, PIPE_FLUSH_RENDER_CACHE, 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
+
+   screen->flush_frontbuffer(screen, surf, window);
+}
+
+static void init( void )
 {
-   struct pipe_screen *screen;
-   struct pipe_context *pipe;
-   struct pipe_surface *surf;
    struct pipe_framebuffer_state fb;
    struct pipe_resource *tex, templat;
-   void *window = NULL;
-   float clear_color[4] = {1,0,1,1};
    int i;
 
-   screen = graw_init();
-   if (screen == NULL)
-      exit(1);
-
    for (i = 0; 
         window == NULL && formats[i] != PIPE_FORMAT_NONE;
         i++) {
@@ -45,8 +63,8 @@ int main( int argc, char *argv[] )
    if (window == NULL)
       exit(2);
    
-   pipe = screen->context_create(screen, NULL);
-   if (pipe == NULL)
+   ctx = screen->context_create(screen, NULL);
+   if (ctx == NULL)
       exit(3);
 
    templat.target = PIPE_TEXTURE_2D;
@@ -57,10 +75,10 @@ int main( int argc, char *argv[] )
    templat.last_level = 0;
    templat.nr_samples = 1;
    templat.bind = (PIPE_BIND_RENDER_TARGET |
-                        PIPE_BIND_DISPLAY_TARGET);
+                   PIPE_BIND_DISPLAY_TARGET);
    
    tex = screen->resource_create(screen,
-                                &templat);
+                                 &templat);
    if (tex == NULL)
       exit(4);
 
@@ -76,21 +94,20 @@ int main( int argc, char *argv[] )
    fb.height = HEIGHT;
    fb.cbufs[0] = surf;
 
-   pipe->set_framebuffer_state(pipe, &fb);
-   pipe->clear(pipe, PIPE_CLEAR_COLOR, clear_color, 0, 0);
-   pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
+   ctx->set_framebuffer_state(ctx, &fb);
+}
 
-   /* At the moment, libgraw includes/makes available all 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.
-    */
-   if (0)
-      debug_dump_surface_bmp(pipe, "result.bmp", surf);
 
-   screen->flush_frontbuffer(screen, surf, window);
+int main( int argc, char *argv[] )
+{
+   screen = graw_init();
+   if (screen == NULL)
+      exit(1);
+
+   init();
 
-   os_time_sleep(100*1000*100);
 
+   graw_set_display_func( draw );
+   graw_main_loop();
    return 0;
 }