多个GL纹理(实时)渲染速度太慢

时间:2015-04-16 14:48:54

标签: opengl-es textures

我要同时绘制2个纹理。 (来自不同的视频,实时获得不同的帧纹理......) 它运作良好,代码如下。

// module 1---------------
{
    CVPixelBufferLockBaseAddress(cameraFrame, 0);
    int bufferHeight = CVPixelBufferGetHeight(cameraFrame);
    int bufferWidth = CVPixelBufferGetWidth(cameraFrame);

    // Create a new texture from the camera frame data, display that using the shaders
    glGenTextures(1, &videoFrameTexture);
    glBindTexture(GL_TEXTURE_2D, videoFrameTexture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    // This is necessary for non-power-of-two textures
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    // Using BGRA extension to pull in video frame data directly
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bufferWidth, bufferHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, CVPixelBufferGetBaseAddress(cameraFrame));
}
{
    CVPixelBufferLockBaseAddress(buf2, 0);
    int bufferHeight = CVPixelBufferGetHeight(buf2);
    int bufferWidth = CVPixelBufferGetWidth(buf2);
    // Create a new texture from the camera frame data, display that using the shaders
    glGenTextures(1, &videoFrameTexture2);
    glBindTexture(GL_TEXTURE_2D, videoFrameTexture2);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    // This is necessary for non-power-of-two textures
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    // Using BGRA extension to pull in video frame data directly
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bufferWidth, bufferHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, CVPixelBufferGetBaseAddress(buf2));
}

[self drawFrame]; // module2---------

{
    glDeleteTextures(1, &videoFrameTexture);
    CVPixelBufferUnlockBaseAddress(cameraFrame, 0);
    glDeleteTextures(1, &videoFrameTexture2);
    CVPixelBufferUnlockBaseAddress(buf2, 0);
}

但它的速度太慢了。主要是module2很慢。 我检查了glTexSubImage2D而不是glTexImage2D,但没有很好的结果。

有没有加速的解决方案?

1 个答案:

答案 0 :(得分:1)

我得到了解决方案,我最初只调用了一次glGenTextures,然后绘制循环。速度加倍了。我将用glTexSubImage2D替换glTexImage2D。我删除了glDeleteTextures!

CVOpenGLESTextureCacheRef,这是加速的关键!几乎是实时!!!