summaryrefslogtreecommitdiffstats
path: root/progs
diff options
context:
space:
mode:
authorKeith Whitwell <[email protected]>2010-03-28 09:53:58 -0700
committerKeith Whitwell <[email protected]>2010-03-28 10:42:38 -0700
commitdb5c2235d1accc2adcf1746aec2342bfa67237ba (patch)
tree1dcfbcda4288341b53f51c9f88c8ac2fae978f3a /progs
parentf97f46f269666b289f9af977e238ccda9b483c44 (diff)
gallium: new raw gallium interface to support standalone tests
Provides basic window system integration behind a simple interface, allowing tests to be written without dependency on either the driver or window system. With a lot of work, could turn into something like glut for gallium.
Diffstat (limited to 'progs')
-rw-r--r--progs/SConscript1
-rw-r--r--progs/gallium/raw/SConscript17
-rw-r--r--progs/gallium/raw/clear.c85
3 files changed, 103 insertions, 0 deletions
diff --git a/progs/SConscript b/progs/SConscript
index aa6640cf7a6..20be60972d2 100644
--- a/progs/SConscript
+++ b/progs/SConscript
@@ -56,4 +56,5 @@ SConscript([
'wgl/SConscript',
'perf/SConscript',
'gallium/unit/SConscript',
+ 'gallium/raw/SConscript',
])
diff --git a/progs/gallium/raw/SConscript b/progs/gallium/raw/SConscript
new file mode 100644
index 00000000000..073b97951e7
--- /dev/null
+++ b/progs/gallium/raw/SConscript
@@ -0,0 +1,17 @@
+Import('*')
+
+env = env.Clone()
+
+env.Prepend(LIBPATH = [graw.dir])
+env.Prepend(LIBS = [graw.name])
+
+progs = [
+ 'clear'
+]
+
+for prog in progs:
+ env.Program(
+ target = prog,
+ source = prog + '.c',
+ )
+
diff --git a/progs/gallium/raw/clear.c b/progs/gallium/raw/clear.c
new file mode 100644
index 00000000000..e46d135224d
--- /dev/null
+++ b/progs/gallium/raw/clear.c
@@ -0,0 +1,85 @@
+/* Display a cleared blue window. This demo has no dependencies on
+ * any utility code, just the graw interface and gallium.
+ */
+
+#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 <unistd.h> /* for sleep() */
+
+enum pipe_format formats[] = {
+ PIPE_FORMAT_R8G8B8A8_UNORM,
+ PIPE_FORMAT_B8G8R8A8_UNORM,
+ PIPE_FORMAT_NONE
+};
+
+static const int WIDTH = 300;
+static const int HEIGHT = 300;
+
+int main( int argc, char *argv[] )
+{
+ struct pipe_screen *screen;
+ struct pipe_context *pipe;
+ struct pipe_surface *surf;
+ struct pipe_framebuffer_state fb;
+ struct pipe_texture *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++) {
+
+ window = graw_create_window(0,0,300,300, formats[i]);
+ }
+
+ if (window == NULL)
+ exit(2);
+
+ pipe = screen->context_create(screen, NULL);
+ if (pipe == NULL)
+ exit(3);
+
+ templat.target = PIPE_TEXTURE_2D;
+ templat.format = formats[i];
+ templat.width0 = WIDTH;
+ templat.height0 = HEIGHT;
+ templat.depth0 = 1;
+ templat.last_level = 0;
+ templat.nr_samples = 1;
+ templat.tex_usage = (PIPE_TEXTURE_USAGE_RENDER_TARGET |
+ PIPE_TEXTURE_USAGE_DISPLAY_TARGET);
+
+ tex = screen->texture_create(screen,
+ &templat);
+ if (tex == NULL)
+ exit(4);
+
+ surf = screen->get_tex_surface(screen, tex, 0, 0, 0,
+ PIPE_TEXTURE_USAGE_RENDER_TARGET |
+ PIPE_TEXTURE_USAGE_DISPLAY_TARGET);
+ if (surf == NULL)
+ exit(5);
+
+ memset(&fb, 0, sizeof fb);
+ fb.nr_cbufs = 1;
+ fb.width = WIDTH;
+ 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);
+
+ screen->flush_frontbuffer(screen, surf, window);
+
+ sleep(100);
+ return 0;
+}