fix color modulation for gl surfaces. also fix segvs tat can happen. xrender

engine is behind now though. can't do yuv surfaces (yet)


SVN revision: 27518
This commit is contained in:
Carsten Haitzler 2006-12-19 14:12:40 +00:00
parent 368d44ce5d
commit 9e27a0d98c
6 changed files with 135 additions and 45 deletions

View File

@ -188,7 +188,9 @@ Evas_GL_Texture *evas_gl_common_texture_new(Evas_GL_Context *gc, RGBA_Image *im
void evas_gl_common_texture_update(Evas_GL_Texture *tex, RGBA_Image *im, int smooth);
void evas_gl_common_texture_free(Evas_GL_Texture *tex);
void evas_gl_common_texture_mipmaps_build(Evas_GL_Texture *tex, RGBA_Image *im, int smooth);
Evas_GL_Texture *evas_gl_common_ycbcr601pl_texture_new(Evas_GL_Context *gc, unsigned char **rows, int w, int h, int smooth);
void evas_gl_common_ycbcr601pl_texture_update(Evas_GL_Texture *tex, unsigned char **rows, int w, int h, 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, 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);

View File

@ -67,9 +67,9 @@ evas_gl_common_context_use(Evas_GL_Context *gc)
// 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);
printf("GL EXT supported: GL_ARB_texture_non_power_of_two = %x\n", gc->ext.arb_texture_non_power_of_two);
// 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);
// printf("GL EXT supported: GL_ARB_texture_non_power_of_two = %x\n", gc->ext.arb_texture_non_power_of_two);
// this causes at least nvidia's drivers to go into pathological pain when
// changing textures a lot (doing video). so we wont do anything with this
// for now, but it does work.
@ -78,7 +78,7 @@ evas_gl_common_context_use(Evas_GL_Context *gc)
}
else
{
printf("GL EXT supported: No extensions!!!!!\n");
// printf("GL EXT supported: No extensions!!!!!\n");
}
gc->ext.checked = 1;
}
@ -330,12 +330,14 @@ _evas_gl_common_texture_set(Evas_GL_Context *gc)
}
if (gc->font_texture_rectangle)
{
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_RECTANGLE_NV);
glBindTexture(GL_TEXTURE_RECTANGLE_NV, gc->font_texture);
}
else
{
glActiveTexture(GL_TEXTURE0);
if (gc->ext.nv_texture_rectangle)
glDisable(GL_TEXTURE_RECTANGLE_NV);
glEnable(GL_TEXTURE_2D);
@ -346,6 +348,7 @@ _evas_gl_common_texture_set(Evas_GL_Context *gc)
{
if (gc->texture->rectangle)
{
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_RECTANGLE_NV);
glBindTexture(GL_TEXTURE_RECTANGLE_NV, gc->texture->texture);

View File

@ -246,11 +246,11 @@ evas_gl_common_image_draw(Evas_GL_Context *gc, Evas_GL_Image *im, int sx, int sy
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);
evas_gl_common_ycbcr601pl_texture_update(im->tex, im->cs.data, im->im->image->w, im->im->image->h, smooth);
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);
im->tex = evas_gl_common_ycbcr601pl_texture_new(gc, im->cs.data, im->im->image->w, im->im->image->h, smooth);
if (!im->tex) return;
ow = (dw * im->tex->tw) / sw;
oh = (dh * im->tex->th) / sh;

View File

@ -413,12 +413,11 @@ evas_gl_common_texture_mipmaps_build(Evas_GL_Texture *tex, RGBA_Image *im, int s
}
Evas_GL_Texture *
evas_gl_common_ycbcr601pl_texture_new(Evas_GL_Context *gc, unsigned char **rows, int w, int h)
evas_gl_common_ycbcr601pl_texture_new(Evas_GL_Context *gc, unsigned char **rows, int w, int h, int smooth)
{
Evas_GL_Texture *tex;
int im_w, im_h;
int tw, th;
GLenum pixfmt, texfmt;
int im_w, im_h, tw, th, y;
GLenum texfmt;
GLhandleARB fshad;
if (!gc->ext.arb_texture_non_power_of_two) return NULL;
@ -444,23 +443,17 @@ evas_gl_common_ycbcr601pl_texture_new(Evas_GL_Context *gc, unsigned char **rows,
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"
" 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"
" gl_FragColor = vec4(r * gl_Color.r * gl_Color.a, g * gl_Color.g * gl_Color.a, b * gl_Color.b * gl_Color.a, gl_Color.a);\n"
"}\n";
glShaderSourceARB(fshad, 1, &code, NULL);
}
@ -482,33 +475,69 @@ evas_gl_common_ycbcr601pl_texture_new(Evas_GL_Context *gc, unsigned char **rows,
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);
if (smooth)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}
else
{
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]);
texfmt, GL_UNSIGNED_BYTE, NULL);
for (y = 0; y < tex->h; y++)
glTexSubImage2D(GL_TEXTURE_2D, 0,
0, y, tex->w, tex->h,
texfmt, GL_UNSIGNED_BYTE, rows[y]);
glGenTextures(1, &(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);
if (smooth)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}
else
{
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]);
texfmt, GL_UNSIGNED_BYTE, NULL);
for (y = 0; y < (tex->h / 2); y++)
glTexSubImage2D(GL_TEXTURE_2D, 0,
0, y, tex->w / 2, tex->h / 2,
texfmt, GL_UNSIGNED_BYTE, rows[tex->h + y]);
glGenTextures(1, &(tex->texture3));
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);
if (smooth)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}
else
{
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)]);
texfmt, GL_UNSIGNED_BYTE, NULL);
for (y = 0; y < (tex->h / 2); y++)
glTexSubImage2D(GL_TEXTURE_2D, 0,
0, y, tex->w / 2, tex->h / 2,
texfmt, GL_UNSIGNED_BYTE, rows[tex->h + (tex->h / 2) + y]);
glUseProgramObjectARB(0);
@ -517,39 +546,66 @@ evas_gl_common_ycbcr601pl_texture_new(Evas_GL_Context *gc, unsigned char **rows,
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)
evas_gl_common_ycbcr601pl_texture_update(Evas_GL_Texture *tex, unsigned char **rows, int w, int h, int smooth)
{
int texfmt;
int y;
/* 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]);
if (smooth)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}
else
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
for (y = 0; y < tex->h; y++)
glTexSubImage2D(GL_TEXTURE_2D, 0,
0, y, tex->w, tex->h,
texfmt, GL_UNSIGNED_BYTE, rows[y]);
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]);
if (smooth)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}
else
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
for (y = 0; y < (tex->h / 2); y++)
glTexSubImage2D(GL_TEXTURE_2D, 0,
0, y, tex->w / 2, tex->h / 2,
texfmt, GL_UNSIGNED_BYTE, rows[tex->h + y]);
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 (smooth)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}
else
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
for (y = 0; y < (tex->h / 2); y++)
glTexSubImage2D(GL_TEXTURE_2D, 0,
0, y, tex->w / 2, tex->h / 2,
texfmt, GL_UNSIGNED_BYTE, rows[tex->h + (tex->h / 2) + y]);
if (tex->gc->texture) tex->gc->texture->references--;
tex->gc->texture = tex;

View File

@ -496,6 +496,7 @@ eng_image_alpha_set(void *data, void *image, int has_alpha)
Evas_GL_Image *im;
re = (Render_Engine *)data;
if (!image) return NULL;
eng_window_use(re->win);
im = image;
/* FIXME: can move to gl_common */
@ -546,6 +547,7 @@ eng_image_comment_get(void *data, void *image, char *key)
Evas_GL_Image *im;
re = (Render_Engine *)data;
if (!image) return NULL;
im = image;
return im->im->info.comment;
}
@ -568,6 +570,7 @@ eng_image_colorspace_set(void *data, void *image, int cspace)
Evas_GL_Image *im;
re = (Render_Engine *)data;
if (!image) return;
im = image;
/* FIXME: can move to gl_common */
if (im->cs.space == cspace) return;
@ -651,6 +654,7 @@ eng_image_free(void *data, void *image)
Render_Engine *re;
re = (Render_Engine *)data;
if (!image) return;
eng_window_use(re->win);
evas_gl_common_image_free(image);
}
@ -661,6 +665,12 @@ eng_image_size_get(void *data, void *image, int *w, int *h)
Render_Engine *re;
re = (Render_Engine *)data;
if (!image)
{
*w = 0;
*h = 0;
return;
}
if (w) *w = ((Evas_GL_Image *)image)->im->image->w;
if (h) *h = ((Evas_GL_Image *)image)->im->image->h;
}
@ -672,8 +682,8 @@ eng_image_size_set(void *data, void *image, int w, int h)
Evas_GL_Image *im, *im_old;
re = (Render_Engine *)data;
eng_window_use(re->win);
if (!image) return NULL;
eng_window_use(re->win);
im_old = image;
if ((im_old) && (im_old->im->image->w == w) && (im_old->im->image->h == h))
return image;
@ -703,6 +713,7 @@ eng_image_dirty_region(void *data, void *image, int x, int y, int w, int h)
Render_Engine *re;
re = (Render_Engine *)data;
if (!image) return NULL;
evas_gl_common_image_dirty(image);
return image;
}
@ -714,6 +725,11 @@ eng_image_data_get(void *data, void *image, int to_write, DATA32 **image_data)
Evas_GL_Image *im;
re = (Render_Engine *)data;
if (!image)
{
*image_data = NULL;
return NULL;
}
im = image;
eng_window_use(re->win);
evas_common_load_image_data_from_file(im->im);
@ -759,6 +775,7 @@ eng_image_data_put(void *data, void *image, DATA32 *image_data)
Evas_GL_Image *im, *im2;
re = (Render_Engine *)data;
if (!image) return NULL;
im = image;
eng_window_use(re->win);
switch (im->cs.space)
@ -803,6 +820,7 @@ eng_image_draw(void *data, void *context, void *surface, void *image, int src_x,
Render_Engine *re;
re = (Render_Engine *)data;
if (!image) return;
eng_window_use(re->win);
re->win->gl_context->dc = context;
evas_gl_common_image_draw(re->win->gl_context, image,

View File

@ -361,6 +361,7 @@ eng_image_alpha_set(void *data, void *image, int has_alpha)
{
RGBA_Image *im;
if (!image) return NULL;
im = image;
if (im->cs.space != EVAS_COLORSPACE_ARGB8888)
{
@ -414,6 +415,7 @@ eng_image_comment_get(void *data, void *image, char *key)
{
RGBA_Image *im;
if (!image) return NULL;
im = image;
return im->info.comment;
}
@ -429,6 +431,7 @@ eng_image_colorspace_set(void *data, void *image, int cspace)
{
RGBA_Image *im;
if (!image) return;
im = image;
if (im->cs.space == cspace) return;
switch (cspace)
@ -600,6 +603,7 @@ eng_image_size_set(void *data, void *image, int w, int h)
static void *
eng_image_dirty_region(void *data, void *image, int x, int y, int w, int h)
{
if (!image) return NULL;
evas_common_image_dirty(image);
evas_common_image_colorspace_dirty(image);
return image;
@ -610,6 +614,11 @@ eng_image_data_get(void *data, void *image, int to_write, DATA32 **image_data)
{
RGBA_Image *im;
if (!image)
{
*image_data = NULL;
return NULL;
}
im = image;
evas_common_load_image_data_from_file(im);
switch (im->cs.space)
@ -650,6 +659,7 @@ eng_image_data_put(void *data, void *image, DATA32 *image_data)
{
RGBA_Image *im, *im2;
if (!image) return NULL;
im = image;
switch (im->cs.space)
{
@ -691,6 +701,7 @@ eng_image_draw(void *data, void *context, void *surface, void *image, int src_x,
{
RGBA_Image *im;
if (!image) return;
im = image;
if (im->cs.space == EVAS_COLORSPACE_ARGB8888)
evas_common_load_image_data_from_file(im);