Mesa (master): graw: move towards glut-like interface, add tri.c

Keith Whitwell keithw at kemper.freedesktop.org
Wed May 19 13:04:33 UTC 2010


Module: Mesa
Branch: master
Commit: 7375d7a5c9d5c32fd6bdde0cc8cab8fe41415964
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=7375d7a5c9d5c32fd6bdde0cc8cab8fe41415964

Author: Keith Whitwell <keithw at vmware.com>
Date:   Fri May 14 12:07:38 2010 +0100

graw: move towards glut-like interface, add tri.c

---

 src/gallium/include/state_tracker/graw.h  |    9 ++++
 src/gallium/targets/graw-xlib/graw_xlib.c |   49 ++++++++++++++++++++
 src/gallium/tests/graw/SConscript         |    3 +-
 src/gallium/tests/graw/clear.c            |   69 ++++++++++++++++++-----------
 4 files changed, 103 insertions(+), 27 deletions(-)

diff --git a/src/gallium/include/state_tracker/graw.h b/src/gallium/include/state_tracker/graw.h
index 385e4d7..87e7d97 100644
--- a/src/gallium/include/state_tracker/graw.h
+++ b/src/gallium/include/state_tracker/graw.h
@@ -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
diff --git a/src/gallium/targets/graw-xlib/graw_xlib.c b/src/gallium/targets/graw-xlib/graw_xlib.c
index 21715c2..d0e3e4b 100644
--- a/src/gallium/targets/graw-xlib/graw_xlib.c
+++ b/src/gallium/targets/graw-xlib/graw_xlib.c
@@ -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);
+}
+
diff --git a/src/gallium/tests/graw/SConscript b/src/gallium/tests/graw/SConscript
index 8a92ac2..1dc8dca 100644
--- a/src/gallium/tests/graw/SConscript
+++ b/src/gallium/tests/graw/SConscript
@@ -12,7 +12,8 @@ env.Prepend(LIBPATH = [graw.dir])
 env.Prepend(LIBS = ['graw'])
 
 progs = [
-    'clear'
+    'clear',
+    'tri'
 ]
 
 for prog in progs:
diff --git a/src/gallium/tests/graw/clear.c b/src/gallium/tests/graw/clear.c
index 84dd780..adcbb08 100644
--- a/src/gallium/tests/graw/clear.c
+++ b/src/gallium/tests/graw/clear.c
@@ -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;
 }




More information about the mesa-commit mailing list