Hi all

Some time ago I did wanted to learn a bit about more of the gallium
interface so I wrote two very small programs that does pretty much the
same things as the programs in progs/trivial with the same name does.
I'm not sure if this is something that we want in mesa but I thought I
share them with the ML should anybody find them remotely interesting.

I cleaned up the patch a bit and added some comments. Looking at the
source you can see that the programs only interact with
gallium/auxiliaries and softpipe. So the programs saves the result as
result.bmp.

To test the programs just goto progs/gallium and run make, after
compilation just run "./tri && gnome-open result.bmp" and should see a
triangle in your favorite image viewer (provided you have gnome based
desktop).

Have fun.

Cheers Jakob.
From ea21ea2bd56b85314bc716ec75845437372b960b Mon Sep 17 00:00:00 2001
From: Jakob Bornecrantz <wallbra...@gmail.com>
Date: Mon, 22 Feb 2010 02:20:24 +0000
Subject: [PATCH] progs/gallium: Add very small gallium test programs

---
 progs/gallium/.gitignore |    3 +
 progs/gallium/Makefile   |   41 ++++++
 progs/gallium/quad-tex.c |  315 ++++++++++++++++++++++++++++++++++++++++++++++
 progs/gallium/tri.c      |  257 +++++++++++++++++++++++++++++++++++++
 4 files changed, 616 insertions(+), 0 deletions(-)
 create mode 100644 progs/gallium/.gitignore
 create mode 100644 progs/gallium/Makefile
 create mode 100644 progs/gallium/quad-tex.c
 create mode 100644 progs/gallium/tri.c

diff --git a/progs/gallium/.gitignore b/progs/gallium/.gitignore
new file mode 100644
index 0000000..af6cded
--- /dev/null
+++ b/progs/gallium/.gitignore
@@ -0,0 +1,3 @@
+tri
+quad-tex
+result.bmp
diff --git a/progs/gallium/Makefile b/progs/gallium/Makefile
new file mode 100644
index 0000000..a92c05c
--- /dev/null
+++ b/progs/gallium/Makefile
@@ -0,0 +1,41 @@
+# progs/alone/Makefile
+
+TOP = ../..
+include $(TOP)/configs/current
+
+INCLUDES = \
+	-I. \
+	-I$(TOP)/src/gallium/include \
+	-I$(TOP)/src/gallium/auxiliary \
+	-I$(TOP)/src/gallium/drivers \
+	$(PROG_INCLUDES)
+
+LINKS = \
+	$(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \
+	$(TOP)/src/gallium/drivers/trace/libtrace.a \
+	$(GALLIUM_AUXILIARIES) \
+	$(PROG_LINKS)
+
+SOURCES = \
+	tri.c \
+	quad-tex.c
+
+OBJECTS = $(SOURCES:.c=.o)
+
+PROGS = $(OBJECTS:.o=)
+
+##### TARGETS #####
+
+default: $(PROGS)
+
+clean:
+	-rm -f $(PROGS)
+	-rm -f *.o
+
+##### RULES #####
+
+$(OBJECTS): %.o: %.c
+	$(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $(PROG_DEFINES) $< -o $@
+
+$(PROGS): %: %.o
+	$(CC) $(LDFLAGS) $< $(LINKS) -lm -lpthread -o $@
diff --git a/progs/gallium/quad-tex.c b/progs/gallium/quad-tex.c
new file mode 100644
index 0000000..8d9f557
--- /dev/null
+++ b/progs/gallium/quad-tex.c
@@ -0,0 +1,315 @@
+/**************************************************************************
+ *
+ * Copyright © 2010 Jakob Bornecrantz
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+#define USE_TRACE 0
+#define WIDTH 300
+#define HEIGHT 300
+#define NEAR 30
+#define FAR 1000
+#define FLIP 0
+
+/* pipe_*_state structs */
+#include "pipe/p_state.h"
+/* pipe_context */
+#include "pipe/p_context.h"
+/* pipe_screen */
+#include "pipe/p_screen.h"
+/* PIPE_* */
+#include "pipe/p_defines.h"
+/* TGSI_SEMANTIC_{POSITION|GENERIC} */
+#include "pipe/p_shader_tokens.h"
+/* pipe_buffer_* helpers */
+#include "util/u_inlines.h"
+
+/* constant state object helper */
+#include "cso_cache/cso_context.h"
+
+/* debug_dump_surface_bmp */
+#include "util/u_debug.h"
+/* util_draw_vertex_buffer helper */
+#include "util/u_draw_quad.h"
+/* FREE & CALLOC_STRUCT */
+#include "util/u_memory.h"
+/* util_make_[fragment|vertex]_passthrough_shader */
+#include "util/u_simple_shaders.h"
+
+/* software rasterizer */
+#include "softpipe/sp_winsys.h"
+
+/* traceing support see src/gallium/drivers/trace/README for more info. */
+#if USE_TRACE
+#include "trace/tr_screen.h"
+#include "trace/tr_context.h"
+#endif
+
+struct program
+{
+	struct pipe_screen *screen;
+	struct pipe_context *pipe;
+	struct cso_context *cso;
+
+	struct pipe_blend_state blend;
+	struct pipe_depth_stencil_alpha_state depthstencil;
+	struct pipe_rasterizer_state rasterizer;
+	struct pipe_sampler_state sampler;
+	struct pipe_viewport_state viewport;
+	struct pipe_framebuffer_state framebuffer;
+
+	void *vs;
+	void *fs;
+
+	float clear_color[4];
+
+	struct pipe_buffer *vbuf;
+	struct pipe_texture *target;
+	struct pipe_texture *tex;
+};
+
+static void init_prog(struct program *p)
+{
+	/* create the software rasterizer */
+	p->screen = softpipe_create_screen_malloc();
+	p->pipe = p->screen->context_create(p->screen, NULL);
+#if USE_TRACE
+	p->screen = trace_screen_create(p->screen);
+	p->pipe = trace_context_create(p->screen, p->pipe);
+#endif
+	p->cso = cso_create_context(p->pipe);
+
+	/* set clear color */
+	p->clear_color[0] = 0.3;
+	p->clear_color[1] = 0.1;
+	p->clear_color[2] = 0.3;
+	p->clear_color[3] = 1.0;
+
+	/* vertex buffer */
+	{
+		float vertices[4][2][4] = {
+			{
+				{ 0.9f, 0.9f, 0.0f, 1.0f },
+				{ 1.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 },
+				{ 1.0f,  0.0f, 1.0f, 1.0f }
+			}
+		};
+
+		p->vbuf = pipe_buffer_create(p->screen, 16, PIPE_BUFFER_USAGE_VERTEX, sizeof(vertices));
+		pipe_buffer_write(p->screen, p->vbuf, 0, sizeof(vertices), vertices);
+	}
+
+	/* render target texture */
+	{
+		struct pipe_texture tmplt;
+		memset(&tmplt, 0, sizeof(tmplt));
+		tmplt.target = PIPE_TEXTURE_2D;
+		tmplt.format = PIPE_FORMAT_A8R8G8B8_UNORM; /* AFAIK all drivers support this */
+		tmplt.width0 = WIDTH;
+		tmplt.height0 = HEIGHT;
+		tmplt.depth0 = 1;
+		tmplt.last_level = 0;
+		tmplt.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
+
+		p->target = p->screen->texture_create(p->screen, &tmplt);
+	}
+
+	/* source texture */
+	{
+		uint32_t *ptr;
+		struct pipe_transfer *t;
+		struct pipe_texture tmplt;
+		memset(&tmplt, 0, sizeof(tmplt));
+		tmplt.target = PIPE_TEXTURE_2D;
+		tmplt.format = PIPE_FORMAT_A8R8G8B8_UNORM; /* AFAIK all drivers support this */
+		tmplt.width0 = 2;
+		tmplt.height0 = 2;
+		tmplt.depth0 = 1;
+		tmplt.last_level = 0;
+		tmplt.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
+
+		p->tex = p->screen->texture_create(p->screen, &tmplt);
+
+		t = p->screen->get_tex_transfer(p->screen, p->tex,
+		                                0, 0, 0, /* face, level, zslice */
+		                                PIPE_TRANSFER_WRITE,
+		                                0, 0, 2, 2); /* x, y, width, height */
+
+		ptr = p->screen->transfer_map(p->screen, t);
+		ptr[0] = 0xffff0000;
+		ptr[1] = 0xff0000ff;
+		ptr[2] = 0xff00ff00;
+		ptr[3] = 0xffffff00;
+		p->screen->transfer_unmap(p->screen, t);
+
+		p->screen->tex_transfer_destroy(t);
+	}
+
+	/* disabled blending/masking */
+	memset(&p->blend, 0, sizeof(p->blend));
+	p->blend.rt[0].colormask = PIPE_MASK_RGBA;
+
+	/* no-op depth/stencil/alpha */
+	memset(&p->depthstencil, 0, sizeof(p->depthstencil));
+
+	/* rasterizer */
+	memset(&p->rasterizer, 0, sizeof(p->rasterizer));
+	p->rasterizer.front_winding = PIPE_WINDING_CW;
+	p->rasterizer.cull_mode = PIPE_WINDING_NONE;
+	p->rasterizer.gl_rasterization_rules = 1;
+
+	/* sampler */
+	memset(&p->sampler, 0, sizeof(p->sampler));
+	p->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
+	p->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
+	p->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
+	p->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
+	p->sampler.min_img_filter = PIPE_TEX_MIPFILTER_LINEAR;
+	p->sampler.mag_img_filter = PIPE_TEX_MIPFILTER_LINEAR;
+	p->sampler.normalized_coords = 1;
+
+	/* drawing destination */
+	memset(&p->framebuffer, 0, sizeof(p->framebuffer));
+	p->framebuffer.width = WIDTH;
+	p->framebuffer.height = HEIGHT;
+	p->framebuffer.nr_cbufs = 1;
+	p->framebuffer.cbufs[0] = p->screen->get_tex_surface(p->screen, p->target, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE);
+
+	/* viewport, depth isn't really needed */
+	{
+		float x = 0;
+		float y = 0;
+		float z = FAR;
+		float half_width = (float)WIDTH / 2.0f;
+		float half_height = (float)HEIGHT / 2.0f;
+		float half_depth = ((float)FAR - (float)NEAR) / 2.0f;
+		float scale, bias;
+
+		if (FLIP) {
+			scale = -1.0f;
+			bias = (float)HEIGHT;
+		} else {
+			scale = 1.0f;
+			bias = 0.0f;
+		}
+
+		p->viewport.scale[0] = half_width;
+		p->viewport.scale[1] = half_height * scale;
+		p->viewport.scale[2] = half_depth;
+		p->viewport.scale[3] = 1.0f;
+
+		p->viewport.translate[0] = half_width + x;
+		p->viewport.translate[1] = (half_height + y) * scale + bias;
+		p->viewport.translate[2] = half_depth + z;
+		p->viewport.translate[3] = 0.0f;
+	}
+
+	/* vertex shader */
+	{
+		const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, TGSI_SEMANTIC_GENERIC };
+		const uint semantic_indexes[] = { 0, 0 };
+		p->vs = util_make_vertex_passthrough_shader(p->pipe, 2, semantic_names, semantic_indexes);
+	}
+
+	/* fragment shader */
+	p->fs = util_make_fragment_tex_shader(p->pipe, TGSI_TEXTURE_2D);
+}
+
+static void close_prog(struct program *p)
+{
+	/* unset all state */
+	cso_release_all(p->cso);
+
+	/* unset bound textures as well */
+	cso_set_sampler_textures(p->cso, 0, NULL);
+
+	p->pipe->delete_vs_state(p->pipe, p->vs);
+	p->pipe->delete_fs_state(p->pipe, p->fs);
+
+	pipe_surface_reference(&p->framebuffer.cbufs[0], NULL);
+	pipe_texture_reference(&p->target, NULL);
+	pipe_texture_reference(&p->tex, NULL);
+	pipe_buffer_reference(&p->vbuf, NULL);
+
+	cso_destroy_context(p->cso);
+	p->pipe->destroy(p->pipe);
+	p->screen->destroy(p->screen);
+
+	FREE(p);
+}
+
+static void draw(struct program *p)
+{
+	/* set misc state we care about */
+	cso_set_blend(p->cso, &p->blend);
+	cso_set_depth_stencil_alpha(p->cso, &p->depthstencil);
+	cso_set_rasterizer(p->cso, &p->rasterizer);
+	cso_set_viewport(p->cso, &p->viewport);
+
+	/* sampler */
+	cso_single_sampler(p->cso, 0, &p->sampler);
+	cso_single_sampler_done(p->cso);
+
+	/* texture */
+	cso_set_sampler_textures(p->cso, 1, &p->tex);
+
+	/* shaders */
+	cso_set_fragment_shader_handle(p->cso, p->fs);
+	cso_set_vertex_shader_handle(p->cso, p->vs);
+
+	cso_set_framebuffer(p->cso, &p->framebuffer);
+
+	p->pipe->clear(p->pipe, PIPE_CLEAR_COLOR, p->clear_color, 0, 0);
+
+	util_draw_vertex_buffer(p->pipe,
+	                        p->vbuf, 0,
+	                        PIPE_PRIM_QUADS,
+	                        4,  /* verts */
+	                        2); /* attribs/vert */
+
+	p->pipe->flush(p->pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
+
+	debug_dump_surface_bmp("result.bmp", p->framebuffer.cbufs[0]);
+}
+
+int main(int argc, char** argv)
+{
+	struct program *p = CALLOC_STRUCT(program);
+
+	init_prog(p);
+	draw(p);
+	close_prog(p);
+
+	return 0;
+}
diff --git a/progs/gallium/tri.c b/progs/gallium/tri.c
new file mode 100644
index 0000000..0f1599a
--- /dev/null
+++ b/progs/gallium/tri.c
@@ -0,0 +1,257 @@
+/**************************************************************************
+ *
+ * Copyright © 2010 Jakob Bornecrantz
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+#define USE_TRACE 0
+#define WIDTH 300
+#define HEIGHT 300
+#define NEAR 30
+#define FAR 1000
+#define FLIP 0
+
+/* pipe_*_state structs */
+#include "pipe/p_state.h"
+/* pipe_context */
+#include "pipe/p_context.h"
+/* pipe_screen */
+#include "pipe/p_screen.h"
+/* PIPE_* */
+#include "pipe/p_defines.h"
+/* TGSI_SEMANTIC_{POSITION|GENERIC} */
+#include "pipe/p_shader_tokens.h"
+/* pipe_buffer_* helpers */
+#include "util/u_inlines.h"
+
+/* constant state object helper */
+#include "cso_cache/cso_context.h"
+
+/* debug_dump_surface_bmp */
+#include "util/u_debug.h"
+/* util_draw_vertex_buffer helper */
+#include "util/u_draw_quad.h"
+/* FREE & CALLOC_STRUCT */
+#include "util/u_memory.h"
+/* util_make_[fragment|vertex]_passthrough_shader */
+#include "util/u_simple_shaders.h"
+
+/* software rasterizer */
+#include "softpipe/sp_winsys.h"
+
+/* traceing support see src/gallium/drivers/trace/README for more info. */
+#if USE_TRACE
+#include "trace/tr_screen.h"
+#include "trace/tr_context.h"
+#endif
+
+struct program
+{
+	struct pipe_screen *screen;
+	struct pipe_context *pipe;
+	struct cso_context *cso;
+
+	struct pipe_blend_state blend;
+	struct pipe_depth_stencil_alpha_state depthstencil;
+	struct pipe_rasterizer_state rasterizer;
+	struct pipe_viewport_state viewport;
+	struct pipe_framebuffer_state framebuffer;
+
+	void *vs;
+	void *fs;
+
+	float clear_color[4];
+
+	struct pipe_buffer *vbuf;
+	struct pipe_texture *target;
+};
+
+static void init_prog(struct program *p)
+{
+	/* create the software rasterizer */
+	p->screen = softpipe_create_screen_malloc();
+	p->pipe = p->screen->context_create(p->screen, NULL);
+#if USE_TRACE
+	p->screen = trace_screen_create(p->screen);
+	p->pipe = trace_context_create(p->screen, p->pipe);
+#endif
+	p->cso = cso_create_context(p->pipe);
+
+	/* set clear color */
+	p->clear_color[0] = 0.3;
+	p->clear_color[1] = 0.1;
+	p->clear_color[2] = 0.3;
+	p->clear_color[3] = 1.0;
+
+	/* vertex buffer */
+	{
+		float vertices[4][2][4] = {
+			{
+				{ 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, 0.0f, 1.0f, 1.0f }
+			}
+		};
+
+		p->vbuf = pipe_buffer_create(p->screen, 16, PIPE_BUFFER_USAGE_VERTEX, sizeof(vertices));
+		pipe_buffer_write(p->screen, p->vbuf, 0, sizeof(vertices), vertices);
+	}
+
+	/* render target texture */
+	{
+		struct pipe_texture tmplt;
+		memset(&tmplt, 0, sizeof(tmplt));
+		tmplt.target = PIPE_TEXTURE_2D;
+		tmplt.format = PIPE_FORMAT_A8R8G8B8_UNORM; /* AFAIK all drivers support this */
+		tmplt.width0 = WIDTH;
+		tmplt.height0 = HEIGHT;
+		tmplt.depth0 = 1;
+		tmplt.last_level = 0;
+		tmplt.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
+
+		p->target = p->screen->texture_create(p->screen, &tmplt);
+	}
+
+	/* disabled blending/masking */
+	memset(&p->blend, 0, sizeof(p->blend));
+	p->blend.rt[0].colormask = PIPE_MASK_RGBA;
+
+	/* no-op depth/stencil/alpha */
+	memset(&p->depthstencil, 0, sizeof(p->depthstencil));
+
+	/* rasterizer */
+	memset(&p->rasterizer, 0, sizeof(p->rasterizer));
+	p->rasterizer.front_winding = PIPE_WINDING_CW;
+	p->rasterizer.cull_mode = PIPE_WINDING_NONE;
+	p->rasterizer.gl_rasterization_rules = 1;
+
+	/* drawing destination */
+	memset(&p->framebuffer, 0, sizeof(p->framebuffer));
+	p->framebuffer.width = WIDTH;
+	p->framebuffer.height = HEIGHT;
+	p->framebuffer.nr_cbufs = 1;
+	p->framebuffer.cbufs[0] = p->screen->get_tex_surface(p->screen, p->target, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE);
+
+	/* viewport, depth isn't really needed */
+	{
+		float x = 0;
+		float y = 0;
+		float z = FAR;
+		float half_width = (float)WIDTH / 2.0f;
+		float half_height = (float)HEIGHT / 2.0f;
+		float half_depth = ((float)FAR - (float)NEAR) / 2.0f;
+		float scale, bias;
+
+		if (FLIP) {
+			scale = -1.0f;
+			bias = (float)HEIGHT;
+		} else {
+			scale = 1.0f;
+			bias = 0.0f;
+		}
+
+		p->viewport.scale[0] = half_width;
+		p->viewport.scale[1] = half_height * scale;
+		p->viewport.scale[2] = half_depth;
+		p->viewport.scale[3] = 1.0f;
+
+		p->viewport.translate[0] = half_width + x;
+		p->viewport.translate[1] = (half_height + y) * scale + bias;
+		p->viewport.translate[2] = half_depth + z;
+		p->viewport.translate[3] = 0.0f;
+	}
+
+	/* vertex shader */
+	{
+		const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, TGSI_SEMANTIC_COLOR };
+		const uint semantic_indexes[] = { 0, 0 };
+		p->vs = util_make_vertex_passthrough_shader(p->pipe, 2, semantic_names, semantic_indexes);
+	}
+
+	/* fragment shader */
+	p->fs = util_make_fragment_passthrough_shader(p->pipe);
+}
+
+static void close_prog(struct program *p)
+{
+	/* unset all state */
+	cso_release_all(p->cso);
+
+	p->pipe->delete_vs_state(p->pipe, p->vs);
+	p->pipe->delete_fs_state(p->pipe, p->fs);
+
+	pipe_surface_reference(&p->framebuffer.cbufs[0], NULL);
+	pipe_texture_reference(&p->target, NULL);
+	pipe_buffer_reference(&p->vbuf, NULL);
+
+	cso_destroy_context(p->cso);
+	p->pipe->destroy(p->pipe);
+	p->screen->destroy(p->screen);
+
+	FREE(p);
+}
+
+static void draw(struct program *p)
+{
+	/* set misc state we care about */
+	cso_set_blend(p->cso, &p->blend);
+	cso_set_depth_stencil_alpha(p->cso, &p->depthstencil);
+	cso_set_rasterizer(p->cso, &p->rasterizer);
+	cso_set_viewport(p->cso, &p->viewport);
+
+	/* shaders */
+	cso_set_fragment_shader_handle(p->cso, p->fs);
+	cso_set_vertex_shader_handle(p->cso, p->vs);
+
+	cso_set_framebuffer(p->cso, &p->framebuffer);
+
+	p->pipe->clear(p->pipe, PIPE_CLEAR_COLOR, p->clear_color, 0, 0);
+
+	util_draw_vertex_buffer(p->pipe,
+	                        p->vbuf, 0,
+	                        PIPE_PRIM_TRIANGLES,
+	                        3,  /* verts */
+	                        2); /* attribs/vert */
+
+	p->pipe->flush(p->pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
+
+	debug_dump_surface_bmp("result.bmp", p->framebuffer.cbufs[0]);
+}
+
+int main(int argc, char** argv)
+{
+	struct program *p = CALLOC_STRUCT(program);
+
+	init_prog(p);
+	draw(p);
+	close_prog(p);
+
+	return 0;
+}
-- 
1.6.0.4

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Mesa3d-dev mailing list
Mesa3d-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to