1 #include <cogl/cogl.h>
2 
3 #include <string.h>
4 
5 #include "test-declarations.h"
6 #include "test-utils.h"
7 
8 #define TEX_WIDTH 8
9 #define TEX_HEIGHT 8
10 
11 static CoglTexture2D *
make_texture(void)12 make_texture (void)
13 {
14   uint8_t tex_data[TEX_WIDTH * TEX_HEIGHT * 2], *p = tex_data;
15   int x, y;
16 
17   for (y = 0; y < TEX_HEIGHT; y++)
18     for (x = 0; x < TEX_WIDTH; x++)
19       {
20         *(p++) = x * 256 / TEX_WIDTH;
21         *(p++) = y * 256 / TEX_HEIGHT;
22       }
23 
24   return cogl_texture_2d_new_from_data (test_ctx,
25                                         TEX_WIDTH, TEX_HEIGHT,
26                                         COGL_PIXEL_FORMAT_RG_88,
27                                         TEX_WIDTH * 2,
28                                         tex_data,
29                                         NULL);
30 }
31 
32 void
test_texture_rg(void)33 test_texture_rg (void)
34 {
35   CoglPipeline *pipeline;
36   CoglTexture2D *tex;
37   int fb_width, fb_height;
38   int x, y;
39 
40   fb_width = cogl_framebuffer_get_width (test_fb);
41   fb_height = cogl_framebuffer_get_height (test_fb);
42 
43   tex = make_texture ();
44 
45   g_assert (cogl_texture_get_components (tex) == COGL_TEXTURE_COMPONENTS_RG);
46 
47   pipeline = cogl_pipeline_new (test_ctx);
48 
49   cogl_pipeline_set_layer_texture (pipeline, 0, tex);
50   cogl_pipeline_set_layer_filters (pipeline,
51                                    0,
52                                    COGL_PIPELINE_FILTER_NEAREST,
53                                    COGL_PIPELINE_FILTER_NEAREST);
54 
55   cogl_framebuffer_draw_rectangle (test_fb,
56                                    pipeline,
57                                    -1.0f, 1.0f,
58                                    1.0f, -1.0f);
59 
60   for (y = 0; y < TEX_HEIGHT; y++)
61     for (x = 0; x < TEX_WIDTH; x++)
62       {
63         test_utils_check_pixel_rgb (test_fb,
64                                     x * fb_width / TEX_WIDTH +
65                                     fb_width / (TEX_WIDTH * 2),
66                                     y * fb_height / TEX_HEIGHT +
67                                     fb_height / (TEX_HEIGHT * 2),
68                                     x * 256 / TEX_WIDTH,
69                                     y * 256 / TEX_HEIGHT,
70                                     0);
71       }
72 
73   cogl_object_unref (pipeline);
74   cogl_object_unref (tex);
75 }
76