2012-06-18 17 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