CVOpenGLESTextureCache vs glTexSubImage2D en iOS
Mi aplicación OpenGL usa OpenGL para representar una textura en pantalla completa y actualiza parte de ella a intervalos regulares. Hasta ahora, he estado usando glTexImage2D para impulsar mi textura inicial y luego actualizo las regiones sucias con glTexSubImage2D. Para hacer eso, estoy usando un búfer único. Esto funciona bien
He visto que podría haber otra manera de lograr lo mismo usando CVOpenGLESTextureCache. Las texturas contenidas en el caché de texturas hacen referencia a CVPixelBuffer. Me gustaría saber si puedo mutar estas texturas en caché. Intenté recrear una CVOpenGLESTexture para cada actualización, pero esto disminuye mi velocidad de fotogramas dramáticamente (no es sorprendente, ya que no estoy especificando la región sucia en ningún lugar). Tal vez entendí mal el caso de uso para este caché de texturas.
¿Puede alguien proporcionar alguna orientación?
ACTUALIZACIÓN: Aquí está el código que estoy usando. La primera actualización funciona bien. Las actualizaciones subsiguientes no (no pasa nada). Entre cada actualización modifico el mapa de bits en bruto.
if (firstUpdate) {
CVReturn err = CVOpenGLESTextureCacheCreate(kCFAllocatorDefault, NULL, ctx, NULL, &texCache);
CVPixelBufferRef pixelBuffer;
CVPixelBufferCreateWithBytes(NULL, width_, height_, kCVPixelFormatType_32BGRA, bitmap, width_*4, NULL, 0, NULL, &pixelBuffer);
CVPixelBufferLockBaseAddress(pixelBuffer, 0);
CVOpenGLESTextureRef texture = NULL;
CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault, texCache, pixelBuffer, NULL, GL_TEXTURE_2D, GL_RGBA, width_, height_, GL_BGRA, GL_UNSIGNED_BYTE, 0, &texture);
texture_[0] = CVOpenGLESTextureGetName(texture);
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
}
CVOpenGLESTextureCacheFlush(texCache, 0);
if (firstUpdate) {
glBindTexture(GL_TEXTURE_2D, texture_[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
if (firstUpdate) {
static const float textureVertices[] = {
-1.0, -1.0,
1.0, -1.0,
-1.0, 1.0,
1.0, 1.0
};
static const float textureCoords[] = {
0.0, 0.0,
1.0, 0.0,
0.0, 1.0,
1.0, 1.0
};
glVertexPointer(2, GL_FLOAT, 0, &textureVertices[0]);
glTexCoordPointer(2, GL_FLOAT, 0, textureCoords);
}
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
firstUpdate = false;