2012-06-18 39 views
2

我目前正在研究一种通过Android上的OpenGL ES 1.0显示视频帧(如位图)的系统。我的问题是,我没有能够得到超过10 fps。在Android上的OpenGL中绘制视频帧

在做了一些测试后,我确定最大的瓶颈之一是需要位图的宽度和高度都是2的幂。一个640x480的视频必须放大到1024x1024,例。没有缩放,我已经能够获得大约40-50fps,但纹理看起来是白色的,这对我没有好处。

我知道,使用非电两个纹理的OpenGL ES 2.0的支持,但我有着色器/别的新在2.0

没有经验有没有什么办法可以解决这个问题?其他视频播放与我拥有的相比如何获得如此出色的性能?我已经包含了一些代码以供参考。

private Bitmap makePowerOfTwo(Bitmap bitmap) 
{ 
    // If one of the bitmap's resolutions is not a power of two 
    if(!isPowerOfTwo(bitmap.getWidth()) || !isPowerOfTwo(bitmap.getHeight())) 
    { 
     int newWidth = nextPowerOfTwo(bitmap.getWidth()); 
     int newHeight = nextPowerOfTwo(bitmap.getHeight()); 

     // Generate a new bitmap which has the needed padding 
     return Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, true); 
    } 
    else 
    { 
     return bitmap; 
    } 
} 

private static boolean isPowerOfTwo(int num) 
{ 
    // Check if a bitwise and of the number and itself minus one is zero 
    return (num & (num - 1)) == 0; 
} 

private static int nextPowerOfTwo(int num) 
{ 
    if(num <= 0) 
    { 
     return 0; 
    } 

    int nextPowerOfTwo = 1; 

    while(nextPowerOfTwo < num) 
    { 
     nextPowerOfTwo <<= 1; // Bitwise shift left one bit 
    } 

    return nextPowerOfTwo; 
} 

回答

5

仅仅因为纹理必须是2的幂,并不意味着你的数据必须是2的幂。

你可以自由初始化过程中创建一个1024×1024(或1024×512)纹理glTexImage,与您的位图数据的低640×480与glTexSubImage填写,然后显示纹理的640×480低一些智能texcoords (0,0) to (640/1024, 480/1024)。纹理的其余部分将只包含从未见过的空白空间。

+2

我想添加一些特别针对glTexSubimage的参考,因为OP在每一帧都可能使用glTexImage()(即使您更新整个图像时也会产生其他负面性能影响)。 – fluffy

+0

好点,我澄清了这个帖子。 – Tim

+0

有什么缺点是要调用glTexImage()每一帧,而不是glTexSubimage()?谢谢您的帮助! – Samusaaron3