[cogl/cogl-1.14: 154/174] texture-2d-slice: Fix the foreach_sub_texture_in_region implementation



commit a2aa04f2193571af17f11f93b906ed2d84f2593e
Author: Neil Roberts <neil linux intel com>
Date:   Mon Dec 10 15:47:45 2012 +0000

    texture-2d-slice: Fix the foreach_sub_texture_in_region implementation
    
    There were a few problems with the sub texture iterating code of
    sliced textures which were causing some conformance tests to fail when
    NPOT textures are disabled:
    
    â The spans are stored in un-normalized coordinates and the
      coordinates passed to the foreach function are normalized. The
      function was trying to un-normalize them before passing them to the
      span iterator code but it was using the wrong factor which was
      causing it to actually doubley normalize them.
    
    â The shim function to renormalize the coordinates before passing them
      to the callback was renormalizing the sub-texture coordinates
      instead of the virtual coordinates. The sub-texture coordinates are
      already in the right scale for whatever is the underlying texture so
      we don't need to touch them. Instead we need to normalize the
      virtual coordinates because these are coming from the un-normalized
      coordinates that we passed to the span iterating code.
    
    â The normalize factors passed to the span iterating were always 1.
      The code uses this normalizing factor to round the incoming
      coordinates to the nearest multiple of a full texture. It divides
      the coordinates by the factor rather than multiplying so it looks
      like we should be passing the virtual texture size here.
    
    Reviewed-by: Robert Bragg <robert linux intel com>
    
    (cherry picked from commit c9773566b0ec0a17b34c440090529de8cff9609e)

 cogl/cogl-texture-2d-sliced.c     |   28 +++++++++++++++++-----------
 tests/conform/test-conform-main.c |    4 ++--
 2 files changed, 19 insertions(+), 13 deletions(-)
---
diff --git a/cogl/cogl-texture-2d-sliced.c b/cogl/cogl-texture-2d-sliced.c
index ef9d72d..b7f16f9 100644
--- a/cogl/cogl-texture-2d-sliced.c
+++ b/cogl/cogl-texture-2d-sliced.c
@@ -75,15 +75,18 @@ re_normalize_sub_texture_coords_cb (CoglTexture *sub_texture,
                                     void *user_data)
 {
   ForeachData *data = user_data;
+  /* The coordinates passed to the span iterating code were
+   * un-normalized so we need to renormalize them before passing them
+   * on */
   float re_normalized_coords[4] =
     {
-      sub_texture_coords[0] * data->x_normalize_factor,
-      sub_texture_coords[1] * data->y_normalize_factor,
-      sub_texture_coords[2] * data->x_normalize_factor,
-      sub_texture_coords[3] * data->y_normalize_factor
+      meta_coords[0] * data->x_normalize_factor,
+      meta_coords[1] * data->y_normalize_factor,
+      meta_coords[2] * data->x_normalize_factor,
+      meta_coords[3] * data->y_normalize_factor
     };
 
-  data->callback (sub_texture, re_normalized_coords, meta_coords,
+  data->callback (sub_texture, sub_texture_coords, re_normalized_coords,
                   data->user_data);
 }
 
@@ -115,19 +118,22 @@ _cogl_texture_2d_sliced_foreach_sub_texture_in_region (
   data.x_normalize_factor = 1.0f / tex->width;
   data.y_normalize_factor = 1.0f / tex->height;
 
-  un_normalized_coords[0] = virtual_tx_1 * data.x_normalize_factor;
-  un_normalized_coords[1] = virtual_ty_1 * data.y_normalize_factor;
-  un_normalized_coords[2] = virtual_tx_2 * data.x_normalize_factor;
-  un_normalized_coords[3] = virtual_ty_2 * data.y_normalize_factor;
+  un_normalized_coords[0] = virtual_tx_1 * tex->width;
+  un_normalized_coords[1] = virtual_ty_1 * tex->height;
+  un_normalized_coords[2] = virtual_tx_2 * tex->width;
+  un_normalized_coords[3] = virtual_ty_2 * tex->height;
 
+  /* Note that the normalize factors passed here are the reciprocal of
+   * the factors calculated above because the span iterating code
+   * normalizes by dividing by the factor instead of multiplying */
   _cogl_texture_spans_foreach_in_region (x_spans,
                                          tex_2ds->slice_x_spans->len,
                                          y_spans,
                                          tex_2ds->slice_y_spans->len,
                                          textures,
                                          un_normalized_coords,
-                                         1, /* x_normalize_factor */
-                                         1, /* y_normalize_factor */
+                                         tex->width,
+                                         tex->height,
                                          COGL_PIPELINE_WRAP_MODE_REPEAT,
                                          COGL_PIPELINE_WRAP_MODE_REPEAT,
                                          re_normalize_sub_texture_coords_cb,
diff --git a/tests/conform/test-conform-main.c b/tests/conform/test-conform-main.c
index fc566c1..38b53a1 100644
--- a/tests/conform/test-conform-main.c
+++ b/tests/conform/test-conform-main.c
@@ -64,7 +64,7 @@ main (int argc, char **argv)
 
   ADD_TEST (test_sparse_pipeline, 0, 0);
 
-  ADD_TEST (test_npot_texture, 0, TEST_REQUIREMENT_NPOT);
+  ADD_TEST (test_npot_texture, 0, 0);
   UNPORTED_TEST (test_multitexture);
   UNPORTED_TEST (test_texture_mipmaps);
   ADD_TEST (test_sub_texture, 0, 0);
@@ -75,7 +75,7 @@ main (int argc, char **argv)
   ADD_TEST (test_texture_3d, TEST_REQUIREMENT_TEXTURE_3D, 0);
   ADD_TEST (test_wrap_modes, 0, 0);
   UNPORTED_TEST (test_texture_pixmap_x11);
-  ADD_TEST (test_texture_get_set_data, 0, TEST_REQUIREMENT_NPOT);
+  ADD_TEST (test_texture_get_set_data, 0, 0);
   ADD_TEST (test_atlas_migration, 0, 0);
   ADD_TEST (test_read_texture_formats, 0, 0);
   ADD_TEST (test_write_texture_formats, 0, 0);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]