3
#include "test-utils.h"
5
/* Keep track of the number of textures that we've created and are
7
static int destroyed_texture_count = 0;
12
free_texture_cb (void *user_data)
14
destroyed_texture_count++;
20
static const guint8 data[] =
21
{ 0xff, 0xff, 0xff, 0xff };
22
static CoglUserDataKey texture_data_key;
23
CoglTexture2D *tex_2d;
25
tex_2d = cogl_texture_2d_new_from_data (test_ctx,
26
1, 1, /* width / height */
27
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
32
/* Set some user data on the texture so we can track when it has
34
cogl_object_set_user_data (COGL_OBJECT (tex_2d),
43
test_pipeline_cache_unrefs_texture (void)
45
CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);
46
CoglPipeline *simple_pipeline;
49
/* Create a pipeline with three texture layers. That way we can be
50
* pretty sure the pipeline will cause a unique shader to be
51
* generated in the cache */
52
for (i = 0; i < N_TEXTURES; i++)
54
CoglTexture *tex = create_texture ();
55
cogl_pipeline_set_layer_texture (pipeline, i, tex);
56
cogl_object_unref (tex);
59
/* Draw something with the pipeline to ensure it gets into the
61
cogl_framebuffer_draw_rectangle (test_fb,
64
cogl_framebuffer_finish (test_fb);
66
/* Draw something else so that it is no longer the current flushed
67
* pipeline, and the units have a different texture bound */
68
simple_pipeline = cogl_pipeline_new (test_ctx);
69
for (i = 0; i < N_TEXTURES; i++)
71
CoglColor combine_constant;
72
cogl_color_init_from_4ub (&combine_constant, i, 0, 0, 255);
73
cogl_pipeline_set_layer_combine_constant (simple_pipeline,
77
cogl_framebuffer_draw_rectangle (test_fb, simple_pipeline, 0, 0, 10, 10);
78
cogl_framebuffer_finish (test_fb);
79
cogl_object_unref (simple_pipeline);
81
g_assert_cmpint (destroyed_texture_count, ==, 0);
83
/* Destroy the pipeline. This should immediately cause the textures
85
cogl_object_unref (pipeline);
87
g_assert_cmpint (destroyed_texture_count, ==, N_TEXTURES);
89
if (cogl_test_verbose ())