Fix _cogl_texture_unsliced_quad when no texture coordinates are given
authorNeil Roberts <neil@linux.intel.com>
Wed, 28 Jan 2009 11:09:47 +0000 (11:09 +0000)
committerNeil Roberts <neil@linux.intel.com>
Wed, 28 Jan 2009 12:24:10 +0000 (12:24 +0000)
If no texture coordinates are given then texture_unsliced_quad tries
to generate its own coordinates. However it also tries to read the
texture coordinates to check if they are in [0.0,1.0] range so it will
crash before it reaches that.

clutter/cogl/gl/cogl-texture.c
clutter/cogl/gles/cogl-texture.c

index 4aa2cb3..c324154 100644 (file)
@@ -2441,6 +2441,7 @@ _cogl_multitexture_unsliced_quad (float        x_1,
        */
       if ((tex->gl_target == GL_TEXTURE_RECTANGLE_ARB
            || _cogl_texture_span_has_waste (tex, 0, 0))
+          && i < user_tex_coords_len / 4
           && (in_tex_coords[0] < 0 || in_tex_coords[0] > 1.0
               || in_tex_coords[1] < 0 || in_tex_coords[1] > 1.0
               || in_tex_coords[2] < 0 || in_tex_coords[2] > 1.0
@@ -2497,6 +2498,8 @@ _cogl_multitexture_unsliced_quad (float        x_1,
           else
             wrap_mode = GL_REPEAT;
 
+          memcpy (out_tex_coords, in_tex_coords, sizeof (GLfloat) * 4);
+
           _cogl_texture_set_wrap_mode_parameter (tex, wrap_mode);
         }
       else
@@ -2514,13 +2517,13 @@ _cogl_multitexture_unsliced_quad (float        x_1,
       y_span = &g_array_index (tex->slice_y_spans, CoglTexSliceSpan, 0);
 
       out_tex_coords[0] =
-        in_tex_coords[0] * (x_span->size - x_span->waste) / x_span->size;
+        out_tex_coords[0] * (x_span->size - x_span->waste) / x_span->size;
       out_tex_coords[1] =
-        in_tex_coords[1] * (x_span->size - x_span->waste) / x_span->size;
+        out_tex_coords[1] * (x_span->size - x_span->waste) / x_span->size;
       out_tex_coords[2] =
-        in_tex_coords[2] * (y_span->size - y_span->waste) / y_span->size;
+        out_tex_coords[2] * (y_span->size - y_span->waste) / y_span->size;
       out_tex_coords[3] =
-        in_tex_coords[3] * (y_span->size - y_span->waste) / y_span->size;
+        out_tex_coords[3] * (y_span->size - y_span->waste) / y_span->size;
 
       /* Denormalize texture coordinates for rectangle textures */
       if (tex->gl_target == GL_TEXTURE_RECTANGLE_ARB)
index d5218cf..7f7242c 100644 (file)
@@ -2556,6 +2556,7 @@ _cogl_multitexture_unsliced_quad (float        x1,
        * case.
        */
       if (_cogl_texture_span_has_waste (tex, 0, 0)
+          && i < user_tex_coords_len / 4
           && (in_tex_coords[0] < 0 || in_tex_coords[0] > 1.0
               || in_tex_coords[1] < 0 || in_tex_coords[1] > 1.0
               || in_tex_coords[2] < 0 || in_tex_coords[2] > 1.0
@@ -2612,6 +2613,8 @@ _cogl_multitexture_unsliced_quad (float        x1,
           else
             wrap_mode = GL_REPEAT;
 
+          memcpy (out_tex_coords, in_tex_coords, sizeof (GLfloat) * 4);
+
           _cogl_texture_set_wrap_mode_parameter (tex, wrap_mode);
         }
       else
@@ -2629,13 +2632,13 @@ _cogl_multitexture_unsliced_quad (float        x1,
       y_span = &g_array_index (tex->slice_y_spans, CoglTexSliceSpan, 0);
 
       out_tex_coords[0] =
-        in_tex_coords[0] * (x_span->size - x_span->waste) / x_span->size;
+        out_tex_coords[0] * (x_span->size - x_span->waste) / x_span->size;
       out_tex_coords[1] =
-        in_tex_coords[1] * (x_span->size - x_span->waste) / x_span->size;
+        out_tex_coords[1] * (x_span->size - x_span->waste) / x_span->size;
       out_tex_coords[2] =
-        in_tex_coords[2] * (y_span->size - y_span->waste) / y_span->size;
+        out_tex_coords[2] * (y_span->size - y_span->waste) / y_span->size;
       out_tex_coords[3] =
-        in_tex_coords[3] * (y_span->size - y_span->waste) / y_span->size;
+        out_tex_coords[3] * (y_span->size - y_span->waste) / y_span->size;
     }
 
   _cogl_journal_log_quad (x1,