summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2014-07-01 18:52:00 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2014-07-03 11:37:48 +0900
commit644de1f93feebe2d829dd04c28ca4d1e3cbf9131 (patch)
treefaadfb7833c7c867dc3fb7284c63f618850c862f
parentb0f353cc389e24f79686fc1ba1bc3370c6fdc8f7 (diff)
Evas gl: Remove hack around CompressedTexImage2D
A compressed texture should be created with glCompressedTexImage2D only, and not with glTexImage2D (This returns GL_INVALID_VALUE).
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_common.h1
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_texture.c80
2 files changed, 53 insertions, 28 deletions
diff --git a/src/modules/evas/engines/gl_common/evas_gl_common.h b/src/modules/evas/engines/gl_common/evas_gl_common.h
index da30a8eddc..4e9fe6386e 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_common.h
+++ b/src/modules/evas/engines/gl_common/evas_gl_common.h
@@ -572,7 +572,6 @@ struct _Evas_GL_Texture_Pool
572 Eina_Bool render : 1; 572 Eina_Bool render : 1;
573 Eina_Bool native : 1; 573 Eina_Bool native : 1;
574 Eina_Bool dynamic : 1; 574 Eina_Bool dynamic : 1;
575 Eina_Bool comptex_ready : 1;
576}; 575};
577 576
578struct _Evas_GL_Texture_Alloca 577struct _Evas_GL_Texture_Alloca
diff --git a/src/modules/evas/engines/gl_common/evas_gl_texture.c b/src/modules/evas/engines/gl_common/evas_gl_texture.c
index 0bf1c5217c..c76fcfe9c6 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_texture.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_texture.c
@@ -224,16 +224,57 @@ _tex_format_index(GLuint format)
224 return 0; 224 return 0;
225} 225}
226 226
227static inline int
228_evas_gl_texture_size_get(int w, int h, int intfmt, Eina_Bool *comp)
229{
230 if (comp) *comp = EINA_FALSE;
231 switch (intfmt)
232 {
233 case GL_RGBA:
234 case GL_BGRA:
235 case GL_RGB:
236 return w * h * 4;
237 case GL_ALPHA:
238 return w * h * 1;
239 case GL_ALPHA4:
240 return w * h / 2; // TODO: Check this
241 case GL_LUMINANCE:
242 return w * h * 1;
243 case GL_LUMINANCE_ALPHA:
244 return w * h * 2;
245 case GL_ETC1_RGB8_OES:
246 case GL_COMPRESSED_RGB8_ETC2:
247 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
248 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
249 if (comp) *comp = EINA_TRUE;
250 return ((w + 3) >> 2) * ((h + 3) >> 2) * 8;
251 case GL_COMPRESSED_RGBA8_ETC2_EAC:
252 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
253 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
254 if (comp) *comp = EINA_TRUE;
255 return ((w + 3) >> 2) * ((h + 3) >> 2) * 16;
256 default:
257 return 0;
258 }
259}
260
227static Eina_Bool 261static Eina_Bool
228_tex_2d(Evas_Engine_GL_Context *gc, int intfmt, int w, int h, int fmt, int type) 262_tex_2d(Evas_Engine_GL_Context *gc, int intfmt, int w, int h, int fmt, int type)
229{ 263{
264 Eina_Bool comp;
265 int sz;
266
230 if ((w > gc->shared->info.max_texture_size) || 267 if ((w > gc->shared->info.max_texture_size) ||
231 (h > gc->shared->info.max_texture_size)) 268 (h > gc->shared->info.max_texture_size))
232 { 269 {
233 ERR("Fail tex too big %ix%i", w, h); 270 ERR("Fail tex too big %ix%i", w, h);
234 return EINA_FALSE; 271 return EINA_FALSE;
235 } 272 }
236 glTexImage2D(GL_TEXTURE_2D, 0, intfmt, w, h, 0, fmt, type, NULL); 273 sz = _evas_gl_texture_size_get(w, h, intfmt, &comp);
274 if (!comp)
275 glTexImage2D(GL_TEXTURE_2D, 0, intfmt, w, h, 0, fmt, type, NULL);
276 else
277 glCompressedTexImage2D(GL_TEXTURE_2D, 0, intfmt, w, h, 0, sz, NULL);
237 GLERR(__FUNCTION__, __FILE__, __LINE__, ""); 278 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
238#ifdef GL_TEXTURE_INTERNAL_FORMAT 279#ifdef GL_TEXTURE_INTERNAL_FORMAT
239# ifdef GL_GLES 280# ifdef GL_GLES
@@ -1072,7 +1113,7 @@ evas_gl_common_texture_upload(Evas_GL_Texture *tex, RGBA_Image *im, unsigned int
1072void 1113void
1073evas_gl_common_texture_update(Evas_GL_Texture *tex, RGBA_Image *im) 1114evas_gl_common_texture_update(Evas_GL_Texture *tex, RGBA_Image *im)
1074{ 1115{
1075 unsigned int bytes_count; 1116 unsigned int bytes_count, bsize = 8;
1076 1117
1077 if (tex->alpha != im->cache_entry.flags.alpha) 1118 if (tex->alpha != im->cache_entry.flags.alpha)
1078 { 1119 {
@@ -1099,9 +1140,11 @@ evas_gl_common_texture_update(Evas_GL_Texture *tex, RGBA_Image *im)
1099 case EVAS_COLORSPACE_ARGB8888: bytes_count = 4; break; 1140 case EVAS_COLORSPACE_ARGB8888: bytes_count = 4; break;
1100 case EVAS_COLORSPACE_GRY8: bytes_count = 1; break; 1141 case EVAS_COLORSPACE_GRY8: bytes_count = 1; break;
1101 case EVAS_COLORSPACE_AGRY88: bytes_count = 2; break; 1142 case EVAS_COLORSPACE_AGRY88: bytes_count = 2; break;
1143 case EVAS_COLORSPACE_RGBA8_ETC2_EAC:
1144 bsize = 16;
1145 // fallthrough
1102 case EVAS_COLORSPACE_ETC1: 1146 case EVAS_COLORSPACE_ETC1:
1103 case EVAS_COLORSPACE_RGB8_ETC2: 1147 case EVAS_COLORSPACE_RGB8_ETC2:
1104 case EVAS_COLORSPACE_RGBA8_ETC2_EAC:
1105 { 1148 {
1106 /* 1149 /*
1107 ETC1/2 can't be scaled down on the fly and interpolated, like it is 1150 ETC1/2 can't be scaled down on the fly and interpolated, like it is
@@ -1112,10 +1155,6 @@ evas_gl_common_texture_update(Evas_GL_Texture *tex, RGBA_Image *im)
1112 */ 1155 */
1113 GLsizei width, height; 1156 GLsizei width, height;
1114 GLint x, y; 1157 GLint x, y;
1115 int etc_block_size = 8;
1116
1117 if (im->cache_entry.space == EVAS_COLORSPACE_RGBA8_ETC2_EAC)
1118 etc_block_size = 16;
1119 1158
1120 x = tex->x - im->cache_entry.borders.l; 1159 x = tex->x - im->cache_entry.borders.l;
1121 y = tex->y - im->cache_entry.borders.t; 1160 y = tex->y - im->cache_entry.borders.t;
@@ -1130,32 +1169,19 @@ evas_gl_common_texture_update(Evas_GL_Texture *tex, RGBA_Image *im)
1130 (im->cache_entry.space != EVAS_COLORSPACE_ETC1)) 1169 (im->cache_entry.space != EVAS_COLORSPACE_ETC1))
1131 && (tex->pt->w != width || tex->pt->h != height)) 1170 && (tex->pt->w != width || tex->pt->h != height))
1132 { 1171 {
1133 int glerr; 1172 int err;
1134 glerr = glGetError(); 1173 err = glGetError();
1135
1136 if (!tex->pt->comptex_ready)
1137 {
1138 GLsizei tw, th;
1139 tw = ((tex->pt->w >> 2) + (tex->pt->w & 0x3 ? 1 : 0)) << 2;
1140 th = ((tex->pt->h >> 2) + (tex->pt->h & 0x3 ? 1 : 0)) << 2;
1141 glCompressedTexImage2D(GL_TEXTURE_2D, 0, tex->pt->format,
1142 tw, th, 0,
1143 ((tw * th) >> 4) * etc_block_size,
1144 NULL);
1145 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1146 tex->pt->comptex_ready = EINA_TRUE;
1147 }
1148 1174
1149 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 1175 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0,
1150 x, y, width, height, 1176 x, y, width, height,
1151 tex->pt->format, 1177 tex->pt->format,
1152 ((width * height) >> 4) * etc_block_size, 1178 ((width * height) >> 4) * bsize,
1153 im->image.data); 1179 im->image.data);
1154 1180
1155 glerr = glGetError(); 1181 err = glGetError();
1156 if (glerr != GL_NO_ERROR) 1182 if (err != GL_NO_ERROR)
1157 { 1183 {
1158 ERR("glCompressedTexSubImage2D failed with ETC1/2: %d", glerr); 1184 glerr(err, __FILE__, __FUNCTION__, __LINE__, "glCompressedTexSubImage2D");
1159 1185
1160 // FIXME: Changing settings on the fly. 1186 // FIXME: Changing settings on the fly.
1161 // The first texture will be black. 1187 // The first texture will be black.
@@ -1168,7 +1194,7 @@ evas_gl_common_texture_update(Evas_GL_Texture *tex, RGBA_Image *im)
1168 { 1194 {
1169 glCompressedTexImage2D(GL_TEXTURE_2D, 0, tex->pt->format, 1195 glCompressedTexImage2D(GL_TEXTURE_2D, 0, tex->pt->format,
1170 width, height, 0, 1196 width, height, 0,
1171 ((width * height) >> 4) * etc_block_size, 1197 ((width * height) >> 4) * bsize,
1172 im->image.data); 1198 im->image.data);
1173 GLERR(__FUNCTION__, __FILE__, __LINE__, ""); 1199 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1174 } 1200 }