[cogl/wip/rib/master-next: 26/35] examples: Adds repeat-mode test
- From: Robert Bragg <rbragg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cogl/wip/rib/master-next: 26/35] examples: Adds repeat-mode test
- Date: Fri, 14 Oct 2011 10:39:48 +0000 (UTC)
commit e93ea00ac4ba2608575160714d8612f8173fd7ba
Author: Robert Bragg <robert linux intel com>
Date: Wed Oct 12 18:14:40 2011 +0100
examples: Adds repeat-mode test
examples/Makefile.am | 4 +-
examples/cogl-repeat-modes.c | 157 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 160 insertions(+), 1 deletions(-)
---
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 12bb383..00919d0 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -18,7 +18,7 @@ common_ldadd = \
$(COGL_DEP_LIBS) \
$(top_builddir)/cogl/libcogl.la
-programs = cogl-hello cogl-msaa
+programs = cogl-hello cogl-msaa cogl-repeat-modes
examples_datadir = $(pkgdatadir)/examples-data
examples_data_DATA =
@@ -26,6 +26,8 @@ cogl_hello_SOURCES = cogl-hello.c
cogl_hello_LDADD = $(common_ldadd)
cogl_msaa_SOURCES = cogl-msaa.c
cogl_msaa_LDADD = $(common_ldadd)
+cogl_repeat_modes_SOURCES = cogl-repeat-modes.c
+cogl_repeat_modes_LDADD = $(common_ldadd)
if BUILD_COGL_PANGO
programs += cogl-crate
diff --git a/examples/cogl-repeat-modes.c b/examples/cogl-repeat-modes.c
new file mode 100644
index 0000000..e122a73
--- /dev/null
+++ b/examples/cogl-repeat-modes.c
@@ -0,0 +1,157 @@
+#include <cogl/cogl.h>
+#include <glib.h>
+#include <stdio.h>
+
+CoglColor black;
+
+typedef struct _TestState
+{
+ CoglTexture2D *tex_2d;
+} TestState;
+
+
+guint8 *
+gen_grid_texture (int size)
+{
+ guint8 *data = g_malloc (size * size * 4);
+ int half_size = size / 2;
+ int x, y;
+
+ g_assert (data);
+
+ for (y = 0; y < size; y++)
+ for (x = 0; x < size; x++)
+ {
+ guint8 *p = &data[size * 4 * y + x * 4];
+ if (x < half_size)
+ {
+ p[0] = 0xff;
+ p[1] = 0;
+ }
+ else
+ {
+ p[0] = 0;
+ p[1] = 0xff;
+ }
+ if (y < half_size)
+ p[2] = 0xff;
+ else
+ p[2] = 0;
+ p[3] = 0xff;
+ }
+
+ return data;
+}
+
+typedef struct _ForeachData
+{
+ float zoom;
+ float s0, t0;
+} ForeachData;
+
+static void
+texture_2d_cb (CoglTexture *sub_texture,
+ const float *sub_texture_coords,
+ const float *meta_coords,
+ void *user_data)
+{
+ ForeachData *data = user_data;
+ cogl_set_source_texture (sub_texture);
+ cogl_rectangle_with_texture_coords ((meta_coords[0] - data->s0) * data->zoom,
+ (meta_coords[1] - data->t0) * data->zoom,
+ (meta_coords[2] - data->s0) * data->zoom,
+ (meta_coords[3] - data->t0) * data->zoom,
+ sub_texture_coords[0],
+ sub_texture_coords[1],
+ sub_texture_coords[2],
+ sub_texture_coords[3]);
+}
+
+static void
+paint (TestState *state)
+{
+ ForeachData data;
+
+ data.zoom = 100;
+ data.s0 = -2;
+ data.t0 = -2;
+#if 1
+ cogl_meta_texture_foreach_in_region (COGL_META_TEXTURE (state->tex_2d),
+ -2, -2,
+ 1, 1,
+ COGL_PIPELINE_WRAP_MODE_MIRRORED_REPEAT,
+ //COGL_PIPELINE_WRAP_MODE_REPEAT,
+ //COGL_PIPELINE_WRAP_MODE_MIRRORED_REPEAT,
+ COGL_PIPELINE_WRAP_MODE_REPEAT,
+ texture_2d_cb,
+ &data);
+#else
+ CoglPipeline *pipeline = cogl_pipeline_new ();
+ cogl_pipeline_set_layer_texture (pipeline, 0, COGL_TEXTURE (state->tex_2d));
+ cogl_pipeline_set_layer_wrap_mode_s (pipeline, 0,
+ //COGL_PIPELINE_WRAP_MODE_MIRRORED_REPEAT);
+ //COGL_PIPELINE_WRAP_MODE_REPEAT);
+ COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE);
+ cogl_pipeline_set_layer_wrap_mode_t (pipeline, 0,
+ //COGL_PIPELINE_WRAP_MODE_MIRRORED_REPEAT);
+ //COGL_PIPELINE_WRAP_MODE_REPEAT);
+ COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE);
+
+ cogl_set_source (pipeline);
+ cogl_rectangle_with_texture_coords (0, 0, 200, 200, -0.25, -0.25, 0, 0);
+ cogl_object_unref (pipeline);
+#endif
+}
+
+int
+main (int argc, char **argv)
+{
+ CoglContext *ctx;
+ CoglOnscreen *onscreen;
+ CoglFramebuffer *fb;
+ guint8 *data;
+ GError *error = NULL;
+ TestState state;
+
+ ctx = cogl_context_new (NULL, &error);
+ if (!ctx) {
+ fprintf (stderr, "Failed to create context: %s\n", error->message);
+ return 1;
+ }
+
+ onscreen = cogl_onscreen_new (ctx, 640, 480);
+ /* Eventually there will be an implicit allocate on first use so this
+ * will become optional... */
+ fb = COGL_FRAMEBUFFER (onscreen);
+ if (!cogl_framebuffer_allocate (fb, &error)) {
+ fprintf (stderr, "Failed to allocate framebuffer: %s\n", error->message);
+ return 1;
+ }
+
+ cogl_onscreen_show (onscreen);
+
+ data = gen_grid_texture (200);
+ state.tex_2d = cogl_texture_2d_new_from_data (ctx,
+ 200, 200,
+ COGL_PIXEL_FORMAT_BGRA_8888,
+ COGL_PIXEL_FORMAT_BGRA_8888,
+ 0,
+ data,
+ &error);
+ g_assert_no_error (error);
+ g_free (data);
+
+ cogl_push_framebuffer (fb);
+
+ cogl_ortho (0, 640, /* left, right */
+ 480, 0, /* bottom, top */
+ -1, 100 /* z near, far */);
+
+ for (;;) {
+ cogl_clear (&black, COGL_BUFFER_BIT_COLOR);
+ paint (&state);
+ cogl_framebuffer_swap_buffers (fb);
+ }
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]