* [GL-engine] Do software YUV-conversion if GLSL is not supported. I

can't test it on a GLSL card, so I hope it didn't break anything. If
something is broken, feel free to revert! (but it would probably just be
related to the way it detects GLSL support at l.78 of evas_gl_context.c)


SVN revision: 33242
This commit is contained in:
moom 2007-12-25 11:12:39 +00:00 committed by moom
parent 50dc3d6aab
commit 8a05a8d250
3 changed files with 66 additions and 36 deletions

View File

@ -67,6 +67,7 @@ struct _Evas_GL_Context
int sgis_generate_mipmap : 1;
int nv_texture_rectangle : 1;
int arb_texture_non_power_of_two : 1;
int arb_program : 1;
} ext;
GLenum read_buf;

View File

@ -40,40 +40,6 @@ evas_gl_common_context_new(void)
gc->change.buf = 1;
gc->change.other = 1;
gc->yuv422p.prog = glCreateProgramObjectARB();
// on an nv 6600gt this is fast - but on a 5500fx its DEAD SLOW!!!!!
// if (!gc->ext.arb_texture_non_power_of_two) return NULL;
/* BEGIN LEAK */
gc->yuv422p.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"
" 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 * 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(gc->yuv422p.fshad, 1, &code, NULL);
}
glCompileShaderARB(gc->yuv422p.fshad);
glAttachObjectARB(gc->yuv422p.prog, gc->yuv422p.fshad);
/* END LEAK - something in the above leaks... beats me what. */
glLinkProgramARB(gc->yuv422p.prog);
glUseProgramObjectARB(gc->yuv422p.prog);
glUniform1iARB(glGetUniformLocationARB(gc->yuv422p.prog, "ytex"), 0);
glUniform1iARB(glGetUniformLocationARB(gc->yuv422p.prog, "utex"), 1);
glUniform1iARB(glGetUniformLocationARB(gc->yuv422p.prog, "vtex"), 2);
glUseProgramObjectARB(0);
return gc;
}
@ -110,6 +76,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;
if (strstr(ext, "GL_ARB_shader_objects") && strstr(ext, "GL_ARB_vertex_shader")
&& strstr(ext, "GL_ARB_fragment_shader") && strstr(ext, "GL_ARB_shading_language"))
gc->ext.arb_program = 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);
@ -123,7 +92,45 @@ evas_gl_common_context_use(Evas_GL_Context *gc)
{
// printf("GL EXT supported: No extensions!!!!!\n");
}
gc->ext.checked = 1;
if (gc->ext.arb_program)
{
gc->yuv422p.prog = glCreateProgramObjectARB();
// on an nv 6600gt this is fast - but on a 5500fx its DEAD SLOW!!!!!
// if (!gc->ext.arb_texture_non_power_of_two) return NULL;
/* BEGIN LEAK */
gc->yuv422p.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"
" 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 * 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(gc->yuv422p.fshad, 1, &code, NULL);
}
glCompileShaderARB(gc->yuv422p.fshad);
glAttachObjectARB(gc->yuv422p.prog, gc->yuv422p.fshad);
/* END LEAK - something in the above leaks... beats me what. */
glLinkProgramARB(gc->yuv422p.prog);
glUseProgramObjectARB(gc->yuv422p.prog);
glUniform1iARB(glGetUniformLocationARB(gc->yuv422p.prog, "ytex"), 0);
glUniform1iARB(glGetUniformLocationARB(gc->yuv422p.prog, "utex"), 1);
glUniform1iARB(glGetUniformLocationARB(gc->yuv422p.prog, "vtex"), 2);
glUseProgramObjectARB(0);
}
gc->ext.checked = 1;
}
_evas_gl_common_context = gc;
_evas_gl_common_viewport_set(gc);

View File

@ -224,6 +224,7 @@ evas_gl_common_image_draw(Evas_GL_Context *gc, Evas_GL_Image *im, int sx, int sy
int r, g, b, a;
double tx1, ty1, tx2, ty2;
int ow, oh;
int space;
if (sw < 1) sw = 1;
if (sh < 1) sh = 1;
@ -239,8 +240,29 @@ evas_gl_common_image_draw(Evas_GL_Context *gc, Evas_GL_Image *im, int sx, int sy
{
r = g = b = a = 255;
}
if (!gc->ext.arb_program && (im->cs.space == EVAS_COLORSPACE_YCBCR422P601_PL
|| im->cs.space == EVAS_COLORSPACE_YCBCR422P709_PL))
{
if ((im->cs.data) && (*((unsigned char **)im->cs.data)))
{
if (im->dirty || !im->im->image->data)
{
free(im->im->image->data);
im->im->image->data = malloc(im->im->image->w * im->im->image->h * sizeof(DATA32));
if (im->im->image->data)
evas_common_convert_yuv_420p_601_rgba(im->cs.data,
(void *)im->im->image->data,
im->im->image->w, im->im->image->h);
}
}
space = EVAS_COLORSPACE_ARGB8888;
}
else
space = im->cs.space;
/* leak in this switch */
switch (im->cs.space)
switch (space)
{
case EVAS_COLORSPACE_ARGB8888:
evas_cache_image_load_data(im->im);