-1
我要在同一時間繪製2個紋理。 (來自不同的視頻,實時獲得不同的幀紋理...) 它運行良好,代碼如下。多個GL紋理(實時)渲染速度太慢
// 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,但沒有好的結果。
有什麼解決方案加快速度?
你是否真的在每一幀都做了這個紋理對象的創建/銷燬? –
我知道它不好,所以請讓我知道解決方案。爲什麼人們在沒有正確答案的情況下倒退? – sky1224