我正在使用 openGL ES 在UIView
. 我正在关注这个线程(CADisplayLink OpenGL 渲染会破坏 UIScrollView 行为)以实现 30fps。一切似乎都还好。播放流畅。现在我想我通过 Instruments 运行我的应用程序,但我收到了一些警告:
- 逻辑缓冲区加载 - 摘要 => 缓慢的帧缓冲区加载
- GPU 在纹理上等待 - 摘要 => CPU 在纹理上传上等待 GPU
- 纹理上传非最佳 GPU 利用率 - 摘要 => 中帧纹理上传
在我的回调中,我执行以下操作:
[EAGLContext setCurrentContext:_context];
glClear(GL_COLOR_BUFFER_BIT);
// load the color components into OpenGL
glBindTexture(GL_TEXTURE_2D, _textures[TEXTURE_Y]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, frameWidth, frameHeight, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, (UInt8*)yuvFrame.luma.bytes);
glBindTexture(GL_TEXTURE_2D, _textures[TEXTURE_U]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, frameWidth/2, frameHeight/2, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, (UInt8*)yuvFrame.chromaB.bytes);
glBindTexture(GL_TEXTURE_2D, _textures[TEXTURE_V]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, frameWidth/2, frameHeight/2, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, (UInt8*)yuvFrame.chromaR.bytes);
// draw
glDrawElements(GL_TRIANGLE_STRIP, sizeof(indices)/sizeof(indices[0]), GL_UNSIGNED_SHORT, 0);
[_context presentRenderbuffer:GL_RENDERBUFFER];
在此调用之前,在 的init
方法中UIView
,我生成纹理并设置一些参数,如下所示:
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glGenTextures(NUM_TEXTURES, _textures);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, _textures[TEXTURE_Y]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glUniform1i(_uniformSamplers[SAMPLER_Y], TEXTURE_Y);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, _textures[TEXTURE_U]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glUniform1i(_uniformSamplers[SAMPLER_U], TEXTURE_U);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, _textures[TEXTURE_V]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glUniform1i(_uniformSamplers[SAMPLER_V], TEXTURE_V);
虽然,就像我说的播放效果似乎不错,但我想尝试修复这些警告。我尝试了几件事但没有成功。我能够删除它们的唯一方法是glGenTextures(NUM_TEXTURES, _textures)/glDeleteTextures(NUM_TEXTURES, _textures)
在回调的开始/结束时调用,但我认为这不是正确的方法。
有没有人有什么建议?