Enlightenment CVS committal Author : raster Project : e17 Module : libs/evas
Dir : e17/libs/evas/src/modules/engines/gl_common Modified Files: evas_gl_common.h evas_gl_context.c evas_gl_image.c evas_gl_texture.c Log Message: not complete yet - actually i need help with the fragment shader. in evas_gl_texture.c i have a frag shader, and it tries to use a set of 3 textures that act as the yuv planes, BUT the u and v textures (Utex and Vtex) are simply getting values from the Ytex - regardless of what i try. grrr. what's up with that? =================================================================== RCS file: /cvs/e/e17/libs/evas/src/modules/engines/gl_common/evas_gl_common.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -3 -r1.6 -r1.7 --- evas_gl_common.h 6 Dec 2006 14:58:00 -0000 1.6 +++ evas_gl_common.h 17 Dec 2006 15:48:51 -0000 1.7 @@ -95,7 +95,8 @@ int tw, th; int uw, uh; - GLuint texture; + GLuint texture, texture2, texture3; + GLhandleARB prog; unsigned char smooth : 1; unsigned char changed : 1; @@ -115,6 +116,11 @@ RGBA_Image_Loadopts load_opts; int putcount; int references; + struct { + int space; + void *data; + unsigned char no_free : 1; + } cs; unsigned char dirty : 1; unsigned char cached : 1; }; @@ -183,9 +189,9 @@ void evas_gl_common_texture_mipmaps_build(Evas_GL_Texture *tex, RGBA_Image *im, int smooth); Evas_GL_Image *evas_gl_common_image_load(Evas_GL_Context *gc, char *file, char *key, Evas_Image_Load_Opts *lo); -Evas_GL_Image *evas_gl_common_image_new_from_data(Evas_GL_Context *gc, int w, int h, int *data); -Evas_GL_Image *evas_gl_common_image_new_from_copied_data(Evas_GL_Context *gc, int w, int h, int *data); -Evas_GL_Image *evas_gl_common_image_new(Evas_GL_Context *gc, int w, int h); +Evas_GL_Image *evas_gl_common_image_new_from_data(Evas_GL_Context *gc, int w, int h, int *data, int alpha, int cspace); +Evas_GL_Image *evas_gl_common_image_new_from_copied_data(Evas_GL_Context *gc, int w, int h, int *data, int alpha, int cspace); +Evas_GL_Image *evas_gl_common_image_new(Evas_GL_Context *gc, int w, int h, int alpha, int cspace); void evas_gl_common_image_free(Evas_GL_Image *im); void evas_gl_common_image_dirty(Evas_GL_Image *im); =================================================================== RCS file: /cvs/e/e17/libs/evas/src/modules/engines/gl_common/evas_gl_context.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- evas_gl_context.c 6 Dec 2006 14:58:00 -0000 1.3 +++ evas_gl_context.c 17 Dec 2006 15:48:51 -0000 1.4 @@ -63,9 +63,9 @@ ext = glGetString(GL_EXTENSIONS); if (ext) { - if (strstr(ext, "GL_SGIS_generate_mipmap")) gc->ext.sgis_generate_mipmap = 1; - if (strstr(ext, "GL_NV_texture_rectangle")) gc->ext.nv_texture_rectangle = 1; - if (strstr(ext, "GL_EXT_texture_rectangle")) gc->ext.nv_texture_rectangle = 1; +// if (strstr(ext, "GL_SGIS_generate_mipmap")) gc->ext.sgis_generate_mipmap = 1; +// if (strstr(ext, "GL_NV_texture_rectangle")) gc->ext.nv_texture_rectangle = 1; +// if (strstr(ext, "GL_EXT_texture_rectangle")) gc->ext.nv_texture_rectangle = 1; if (strstr(ext, "GL_ARB_texture_non_power_of_two")) gc->ext.arb_texture_non_power_of_two = 1; printf("GL EXT supported: GL_SGIS_generate_mipmap = %x\n", gc->ext.sgis_generate_mipmap); printf("GL EXT supported: GL_NV_texture_rectangle = %x\n", gc->ext.nv_texture_rectangle); @@ -74,7 +74,7 @@ // changing textures a lot (doing video). so we wont do anything with this // for now, but it does work. // gc->ext.arb_texture_non_power_of_two = 0; printf("DISABLE GL_ARB_texture_non_power_of_two\n"); - gc->ext.nv_texture_rectangle = 0; printf("DISABLE GL_NV_texture_rectangle\n"); +// gc->ext.nv_texture_rectangle = 0; printf("DISABLE GL_NV_texture_rectangle\n"); } else { @@ -317,6 +317,7 @@ if (!gc->change.texture) return; if (gc->font_texture > 0) { + glUseProgramObjectARB(0); if (gc->font_texture_rectangle) { glEnable(GL_TEXTURE_2D); @@ -342,8 +343,38 @@ else { if (gc->ext.nv_texture_rectangle) glDisable(GL_TEXTURE_RECTANGLE_NV); - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, gc->texture->texture); + if ((gc->texture->prog) && + (gc->texture->texture2) && (gc->texture->texture3)) + { + int i; + + glActiveTexture(GL_TEXTURE1); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, gc->texture->texture2); + + glActiveTexture(GL_TEXTURE2); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, gc->texture->texture3); + + glActiveTexture(GL_TEXTURE0); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, gc->texture->texture); + + glUseProgramObjectARB(gc->texture->prog); + } + else + { + glUseProgramObjectARB(0); + + glActiveTexture(GL_TEXTURE1); + glDisable(GL_TEXTURE_2D); + glActiveTexture(GL_TEXTURE2); + glDisable(GL_TEXTURE_2D); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, gc->texture->texture); + glEnable(GL_TEXTURE_2D); + } } if (gc->texture->rectangle) { @@ -375,9 +406,9 @@ { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - if (gc->texture->have_mipmaps) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - else +// if (gc->texture->have_mipmaps) +// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); +// else glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } else =================================================================== RCS file: /cvs/e/e17/libs/evas/src/modules/engines/gl_common/evas_gl_image.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- evas_gl_image.c 30 Sep 2006 10:18:34 -0000 1.3 +++ evas_gl_image.c 17 Dec 2006 15:48:51 -0000 1.4 @@ -35,13 +35,14 @@ im->gc = gc; im->references = 1; im->cached = 1; + im->cs.space = EVAS_COLORSPACE_ARGB8888; if (lo) im->load_opts = *lo; gc->images = evas_list_prepend(gc->images, im); return im; } Evas_GL_Image * -evas_gl_common_image_new_from_data(Evas_GL_Context *gc, int w, int h, int *data) +evas_gl_common_image_new_from_data(Evas_GL_Context *gc, int w, int h, int *data, int alpha, int cspace) { Evas_GL_Image *im; Evas_List *l; @@ -75,20 +76,40 @@ free(im); return NULL; } + im->gc = gc; im->im->image->w = w; im->im->image->h = h; - im->im->image->data = data; - im->im->image->no_free = 1; - im->gc = gc; -/* - im->cached = 1; - gc->images = evas_list_prepend(gc->images, im); - */ + im->cs.space = cspace; + if (alpha) + im->im->flags |= RGBA_IMAGE_HAS_ALPHA; + else + im->im->flags &= ~RGBA_IMAGE_HAS_ALPHA; + switch (cspace) + { + case EVAS_COLORSPACE_ARGB8888: + im->im->image->data = data; + im->im->image->no_free = 1; + break; + case EVAS_COLORSPACE_YCBCR422P601_PL: + case EVAS_COLORSPACE_YCBCR422P709_PL: + if (im->tex) evas_gl_common_texture_free(im->tex); + im->tex = NULL; + im->cs.data = data; + im->cs.no_free = 1; + break; + default: + abort(); + break; + } + /* + im->cached = 1; + gc->images = evas_list_prepend(gc->images, im); + */ return im; } Evas_GL_Image * -evas_gl_common_image_new_from_copied_data(Evas_GL_Context *gc, int w, int h, int *data) +evas_gl_common_image_new_from_copied_data(Evas_GL_Context *gc, int w, int h, int *data, int alpha, int cspace) { Evas_GL_Image *im; @@ -101,14 +122,37 @@ free(im); return NULL; } - if (data) - memcpy(im->im->image->data, data, w * h * sizeof(DATA32)); im->gc = gc; + im->cs.space = cspace; + if (alpha) + im->im->flags |= RGBA_IMAGE_HAS_ALPHA; + else + im->im->flags &= ~RGBA_IMAGE_HAS_ALPHA; + switch (cspace) + { + case EVAS_COLORSPACE_ARGB8888: + if (data) + memcpy(im->im->image->data, data, w * h * sizeof(DATA32)); + break; + case EVAS_COLORSPACE_YCBCR422P601_PL: + case EVAS_COLORSPACE_YCBCR422P709_PL: + evas_common_image_surface_dealloc(im->im->image); + im->im->image->data = NULL; + if (im->tex) evas_gl_common_texture_free(im->tex); + im->tex = NULL; + im->cs.data = calloc(1, im->im->image->h * sizeof(unsigned char *) * 2); + if ((data) && (im->cs.data)) + memcpy(im->cs.data, data, im->im->image->h * sizeof(unsigned char *) * 2); + break; + default: + abort(); + break; + } return im; } Evas_GL_Image * -evas_gl_common_image_new(Evas_GL_Context *gc, int w, int h) +evas_gl_common_image_new(Evas_GL_Context *gc, int w, int h, int alpha, int cspace) { Evas_GL_Image *im; @@ -130,8 +174,11 @@ im->references--; if (im->references > 0) return; - if (im->cached) - im->gc->images = evas_list_remove(im->gc->images, im); + if (im->cs.data) + { + if (!im->cs.no_free) free(im->cs.data); + } + if (im->cached) im->gc->images = evas_list_remove(im->gc->images, im); if (im->im) evas_common_image_unref(im->im); if (im->tex) evas_gl_common_texture_free(im->tex); free(im); @@ -167,35 +214,61 @@ r = g = b = a = 255; } evas_common_load_image_data_from_file(im->im); - if ((im->tex) && (im->dirty)) - { - evas_gl_common_texture_update(im->tex, im->im, im->tex->smooth); - im->dirty = 0; - } - if (!im->tex) - im->tex = evas_gl_common_texture_new(gc, im->im, smooth); - ow = (dw * im->tex->tw) / sw; - oh = (dh * im->tex->th) / sh; - evas_gl_common_context_texture_set(gc, im->tex, smooth, ow, oh); - if ((!im->tex->have_mipmaps) && (smooth) && - ((im->tex->uw < im->tex->tw) || (im->tex->uh < im->tex->th)) && - (!gc->ext.sgis_generate_mipmap)) - evas_gl_common_texture_mipmaps_build(im->tex, im->im, smooth); - - if (im->tex->rectangle) - { - tx1 = sx; - ty1 = sy; - tx2 = sx + sw; - ty2 = sy + sh; - } - else + switch (im->cs.space) { + case EVAS_COLORSPACE_ARGB8888: + if ((im->tex) && (im->dirty)) + { + evas_gl_common_texture_update(im->tex, im->im, im->tex->smooth); + im->dirty = 0; + } + if (!im->tex) + im->tex = evas_gl_common_texture_new(gc, im->im, smooth); + ow = (dw * im->tex->tw) / sw; + oh = (dh * im->tex->th) / sh; + if (im->tex->rectangle) + { + tx1 = sx; + ty1 = sy; + tx2 = sx + sw; + ty2 = sy + sh; + } + else + { + tx1 = (double)(sx ) / (double)(im->tex->w); + ty1 = (double)(sy ) / (double)(im->tex->h); + tx2 = (double)(sx + sw) / (double)(im->tex->w); + ty2 = (double)(sy + sh) / (double)(im->tex->h); + } + evas_gl_common_context_texture_set(gc, im->tex, smooth, ow, oh); + break; + case EVAS_COLORSPACE_YCBCR422P601_PL: + case EVAS_COLORSPACE_YCBCR422P709_PL: + if ((im->tex) && (im->dirty)) + { + evas_gl_common_ycbcr601pl_texture_update(im->tex, im->cs.data, im->im->image->w, im->im->image->h); + im->dirty = 0; + } + if ((!im->tex) && (im->cs.data) && (*((unsigned char **)im->cs.data))) + im->tex = evas_gl_common_ycbcr601pl_texture_new(gc, im->cs.data, im->im->image->w, im->im->image->h); + if (!im->tex) return; + ow = (dw * im->tex->tw) / sw; + oh = (dh * im->tex->th) / sh; tx1 = (double)(sx ) / (double)(im->tex->w); ty1 = (double)(sy ) / (double)(im->tex->h); tx2 = (double)(sx + sw) / (double)(im->tex->w); ty2 = (double)(sy + sh) / (double)(im->tex->h); - } + evas_gl_common_context_texture_set(gc, im->tex, smooth, ow, oh); + break; + default: + abort(); + break; + } +// if ((!im->tex->have_mipmaps) && (smooth) && +// ((im->tex->uw < im->tex->tw) || (im->tex->uh < im->tex->th)) && +// (!gc->ext.sgis_generate_mipmap)) +// evas_gl_common_texture_mipmaps_build(im->tex, im->im, smooth); + evas_gl_common_context_color_set(gc, r, g, b, a); if ((a < 255) || (im->im->flags & RGBA_IMAGE_HAS_ALPHA)) evas_gl_common_context_blend_set(gc, 1); =================================================================== RCS file: /cvs/e/e17/libs/evas/src/modules/engines/gl_common/evas_gl_texture.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- evas_gl_texture.c 14 Jan 2006 12:13:37 -0000 1.1 +++ evas_gl_texture.c 17 Dec 2006 15:48:51 -0000 1.2 @@ -83,7 +83,7 @@ gc->change.texture = 1; tex->references++; -// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 8); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); @@ -101,6 +101,7 @@ glTexImage2D(GL_TEXTURE_2D, 0, texfmt, tw, th, 0, pixfmt, NATIVE_PIX_UNIT, NULL); +/* { int ttw, tth; int l; @@ -120,6 +121,7 @@ pixfmt, NATIVE_PIX_UNIT, NULL); } } + */ if (gc->ext.sgis_generate_mipmap) { glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); @@ -292,6 +294,10 @@ tex->gc->change.texture = 1; } glDeleteTextures(1, &tex->texture); + if (tex->texture2) glDeleteTextures(1, &tex->texture2); + if (tex->texture3) glDeleteTextures(1, &tex->texture3); + if (tex->prog) + glDeleteObjectARB(tex->prog); free(tex); } @@ -404,4 +410,149 @@ #ifdef BUILD_MMX if (mmx) evas_common_cpu_end_opt(); #endif +} + +Evas_GL_Texture * +evas_gl_common_ycbcr601pl_texture_new(Evas_GL_Context *gc, unsigned char **rows, int w, int h) +{ + Evas_GL_Texture *tex; + int im_w, im_h; + int tw, th; + GLenum pixfmt, texfmt; + GLhandleARB fshad; + + if (!gc->ext.arb_texture_non_power_of_two) return NULL; + + tex = calloc(1, sizeof(Evas_GL_Texture)); + if (!tex) return NULL; + + tw = w; + th = h; + tex->gc = gc; + tex->w = tw; + tex->h = th; + tex->tw = w; + tex->th = h; + tex->references = 0; + tex->smooth = 0; + tex->changed = 1; + + tex->prog = glCreateProgramObjectARB(); + fshad = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); + + { + const char *code = + "uniform sampler2D Ytex, Utex, Vtex;\n" + "void main(void) {\n" + + " float r, g, b, y, u, v;\n" + + " y = texture2D(Ytex, gl_TexCoord[0].st).r;\n" + " u = texture2D(Utex, gl_TexCoord[0].st).r;\n" + " v = texture2D(Vtex, gl_TexCoord[0].st).r;\n" + +#if 0 // enable this to direct-test y u and v values + " gl_FragColor = vec4(y, u, v, 1.0);\n" +#else + " y = (y - 0.0625) * 1.164;\n" + " u = u - 0.5;\n" + " v = v - 0.5;\n" + + " r = y + (1.402 * v);\n" + " g = y - (0.34414 * u) - (0.71414 * v);\n" + " b = y + (1.772 * u);\n" + + " gl_FragColor = vec4(r, g, b, 1.0);\n" +#endif + "}\n"; + glShaderSourceARB(fshad, 1, &code, NULL); + } + + glCompileShaderARB(fshad); + glAttachObjectARB(tex->prog, fshad); + glLinkProgramARB(tex->prog); + + glEnable(GL_TEXTURE_2D); + texfmt = GL_LUMINANCE; + + glGenTextures(1, &(tex->texture)); + glUniform1iARB(glGetUniformLocationARB(tex->prog, "Ytex", tex->texture)); + glBindTexture(GL_TEXTURE_2D, tex->texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexImage2D(GL_TEXTURE_2D, 0, + texfmt, tw, th, 0, + texfmt, GL_UNSIGNED_BYTE, rows[0]); + + glGenTextures(1, &(tex->texture2)); + glUniform1iARB(glGetUniformLocationARB(tex->prog, "Utex", tex->texture2)); + glBindTexture(GL_TEXTURE_2D, tex->texture2); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexImage2D(GL_TEXTURE_2D, 0, + texfmt, tw / 2, th / 2, 0, + texfmt, GL_UNSIGNED_BYTE, rows[th]); + + glGenTextures(1, &(tex->texture3)); + glUniform1iARB(glGetUniformLocationARB(tex->prog, "Vtex", 2)); + glBindTexture(GL_TEXTURE_2D, tex->texture3); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexImage2D(GL_TEXTURE_2D, 0, + texfmt, tw / 2, th / 2, 0, + texfmt, GL_UNSIGNED_BYTE, rows[th + (th / 2)]); + + if (gc->texture) gc->texture->references--; + gc->texture = tex; + gc->change.texture = 1; + tex->references++; + + /* FIXME: should use subimage */ +/* + glTexSubImage2D(GL_TEXTURE_2D, 0, + 0, 0, im_w, im_h, + pixfmt, NATIVE_PIX_UNIT, + im_data); + */ + return tex; +} + +void +evas_gl_common_ycbcr601pl_texture_update(Evas_GL_Texture *tex, unsigned char **rows, int w, int h) +{ + int texfmt; + + return; + /* FIXME: should use subimage */ + glEnable(GL_TEXTURE_2D); + texfmt = GL_LUMINANCE; + + glBindTexture(GL_TEXTURE_2D, tex->texture); + glTexImage2D(GL_TEXTURE_2D, 0, + texfmt, tex->w, tex->h, 0, + texfmt, GL_UNSIGNED_BYTE, rows[0]); + + glBindTexture(GL_TEXTURE_2D, tex->texture2); + glTexImage2D(GL_TEXTURE_2D, 0, + texfmt, tex->w / 2, tex->h / 2, 0, + texfmt, GL_UNSIGNED_BYTE, rows[tex->h]); + + glBindTexture(GL_TEXTURE_2D, tex->texture3); + glTexImage2D(GL_TEXTURE_2D, 0, + texfmt, tex->w / 2, tex->h / 2, 0, + texfmt, GL_UNSIGNED_BYTE, rows[tex->h + (tex->h / 2)]); + + if (tex->gc->texture) tex->gc->texture->references--; + tex->gc->texture = tex; + tex->gc->change.texture = 1; + tex->references++; } ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs