Evas gl: Fix texture allocation (missing Y offset)
authorJean-Philippe Andre <jp.andre@samsung.com>
Tue, 1 Jul 2014 09:32:18 +0000 (18:32 +0900)
committerJean-Philippe Andre <jp.andre@samsung.com>
Thu, 3 Jul 2014 02:37:48 +0000 (11:37 +0900)
I saw some GL error messages (with the GLERR() macro activated),
that were caused by GL_INVALID_VALUE.

For some (many) textures, tex->y was 0 but since we now use a 2D
atlas (rectangle allocator), the first row of pixels should be
repeated. This caused uploads to Y = tex->y - 1 = -1, which is
invalid.

src/modules/evas/engines/gl_common/evas_gl_texture.c

index 16cb9c4..0bf1c52 100644 (file)
@@ -435,7 +435,7 @@ evas_gl_common_texture_new(Evas_Engine_GL_Context *gc, RGBA_Image *im)
 {
    Evas_GL_Texture *tex;
    GLsizei w, h;
-   int u = 0, v = 0, yoffset = 0;
+   int u = 0, v = 0, xoffset = 1, yoffset = 1;
    int lformat;
 
    lformat = _evas_gl_texture_search_format(im->cache_entry.flags.alpha, gc->shared->info.bgra, im->cache_entry.space);
@@ -444,9 +444,6 @@ evas_gl_common_texture_new(Evas_Engine_GL_Context *gc, RGBA_Image *im)
    tex = evas_gl_common_texture_alloc(gc, im->cache_entry.w, im->cache_entry.h, im->cache_entry.flags.alpha);
    if (!tex) return NULL;
 
-#define TEX_HREP 1
-#define TEX_VREP 1
-
    switch (im->cache_entry.space)
      {
       case EVAS_COLORSPACE_ETC1:
@@ -456,13 +453,14 @@ evas_gl_common_texture_new(Evas_Engine_GL_Context *gc, RGBA_Image *im)
         w = im->cache_entry.w + im->cache_entry.borders.l + im->cache_entry.borders.r;
         h = im->cache_entry.h + im->cache_entry.borders.t + im->cache_entry.borders.b;
         EINA_SAFETY_ON_FALSE_RETURN_VAL(!(w & 0x3) && !(h & 0x3), NULL);
-        yoffset = 1;
+        xoffset = im->cache_entry.borders.l;
+        yoffset = im->cache_entry.borders.t;
         break;
 
      default:
-        /* This need to be adjusted if we do something else than strip allocation */
-        w = im->cache_entry.w + TEX_HREP + 2; /* one pixel stop gap and two pixels for the border */
-        h = im->cache_entry.h + TEX_VREP + 2; /* only one added border for security down */
+        // One pixel gap and two pixels for duplicated borders
+        w = im->cache_entry.w + 3;
+        h = im->cache_entry.h + 3;
         break;
      }
 
@@ -476,7 +474,7 @@ evas_gl_common_texture_new(Evas_Engine_GL_Context *gc, RGBA_Image *im)
         evas_gl_common_texture_light_free(tex);
         return NULL;
      }
-   tex->x = u + 1;
+   tex->x = u + xoffset;
    tex->y = v + yoffset;
 
    tex->pt->references++;