在排查渲染模块的渲染问题时,需要查看纹理数据是否正常,此时需要dump纹理数据来排查问题。
以 Android 平台为例,dump OES texture 和普通 texture 的代码
FILE* file_handler_{nullptr};
file_handler_ = fopen(yuv_file_name.c_str(), "wb");
static void save_texture(int texture_id, bool is_texture_2d, int width, int height, FILE* file_handler) {
GLint old_fbo;
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old_fbo);
GLuint tmp_fbo;
glGenFramebuffers(1, &tmp_fbo);
glBindFramebuffer(GL_FRAMEBUFFER, tmp_fbo);
if (is_texture_2d) {
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
texture_id, 0);
} else {
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_EXTERNAL_OES,
texture_id, 0);
}
std::unique_ptr<uint8_t []> outRgbaBuf(new uint8_t[width*height*4]);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, outRgbaBuf.get());
{
fwrite(outRgbaBuf.get(), 1, width * height * 4, file_handler);
}
glBindFramebuffer(GL_FRAMEBUFFER, old_fbo);
glDeleteFramebuffers(1, &tmp_fbo);
}
参考:https://blog.csdn.net/weixin_43931399/article/details/106638116
网友评论