如何将OpenGL外部纹理(gl_texture_external_oes)复制到framebuffer

发布于 2025-02-10 18:49:56 字数 1620 浏览 0 评论 0原文

我需要将纹理复制到Framebuffer,然后使用GlreadPixels读取它,然后将输出保存到缓冲区中。主要目标是将范围的输入帧转储到文件中。我当前的代码给我GLX506错误。

int[] frame = new int[1];
int[] mainFrame = new int[1];
glGetIntegerv(GLES32.GL_FRAMEBUFFER_BINDING, mainFrame,0);

GLES32.glGenFramebuffers(1,frame,0);
GlUtil.checkGlError("glGenFramebufferOES");

GLES11Ext.glBindFramebufferOES(GLES11Ext.GL_FRAMEBUFFER_OES, frame[0]);
GlUtil.checkGlError("glBindFramebufferOES");

GLES11Ext.glFramebufferTexture2DOES(GLES11Ext.GL_FRAMEBUFFER_OES,GLES11Ext.GL_COLOR_ATTACHMENT0_OES, GLES32.GL_TEXTURE_2D, texture,0);
GlUtil.checkGlError("glFramebufferTexture2DOES");

GLES11Ext.glBindFramebufferOES(GLES11Ext.GL_FRAMEBUFFER_OES, frame[0]);
GlUtil.checkGlError("glBindFramebufferOES");

GLES32.glViewport(0, 0, width, height);
GlUtil.checkGlError("glViewport");


ByteBuffer buffer = ByteBuffer.allocateDirect(width * height * 4);

GLES32.glReadPixels(0, 0, width, height, GLES32.GL_RGBA,GLES32.GL_UNSIGNED_BYTE, buffer);
GlUtil.checkGlError("glReadPixels");

File file = new File("/sdcard/Movies/frames/input_"+mediaTime+".rgba");
try {
  FileOutputStream fos = new FileOutputStream(file.toString());
  FileChannel fch = fos.getChannel();
  fch.write(buffer);
  fch.close();
  fos.close();
} catch (FileNotFoundException e) {
  e.printStackTrace();
} catch (IOException e) {
  e.printStackTrace();
}
Log.d(TAG, "Saved input frame : Dimensions : " + width + "x" + height + " Frame saved as '" + file + "'");

GLES11Ext.glBindFramebufferOES(GLES11Ext.GL_FRAMEBUFFER_OES, mainFrame[0]);
GLES32.glViewport(0, 0, mWindowSurface.getWidth(), mWindowSurface.getHeight());

I need to copy the texture to a framebuffer and then read it using GlReadPixels and save the output to a buffer. The main goal is to dump the input frames of exoplayer into a file. My current code gives me glx506 error.

int[] frame = new int[1];
int[] mainFrame = new int[1];
glGetIntegerv(GLES32.GL_FRAMEBUFFER_BINDING, mainFrame,0);

GLES32.glGenFramebuffers(1,frame,0);
GlUtil.checkGlError("glGenFramebufferOES");

GLES11Ext.glBindFramebufferOES(GLES11Ext.GL_FRAMEBUFFER_OES, frame[0]);
GlUtil.checkGlError("glBindFramebufferOES");

GLES11Ext.glFramebufferTexture2DOES(GLES11Ext.GL_FRAMEBUFFER_OES,GLES11Ext.GL_COLOR_ATTACHMENT0_OES, GLES32.GL_TEXTURE_2D, texture,0);
GlUtil.checkGlError("glFramebufferTexture2DOES");

GLES11Ext.glBindFramebufferOES(GLES11Ext.GL_FRAMEBUFFER_OES, frame[0]);
GlUtil.checkGlError("glBindFramebufferOES");

GLES32.glViewport(0, 0, width, height);
GlUtil.checkGlError("glViewport");


ByteBuffer buffer = ByteBuffer.allocateDirect(width * height * 4);

GLES32.glReadPixels(0, 0, width, height, GLES32.GL_RGBA,GLES32.GL_UNSIGNED_BYTE, buffer);
GlUtil.checkGlError("glReadPixels");

File file = new File("/sdcard/Movies/frames/input_"+mediaTime+".rgba");
try {
  FileOutputStream fos = new FileOutputStream(file.toString());
  FileChannel fch = fos.getChannel();
  fch.write(buffer);
  fch.close();
  fos.close();
} catch (FileNotFoundException e) {
  e.printStackTrace();
} catch (IOException e) {
  e.printStackTrace();
}
Log.d(TAG, "Saved input frame : Dimensions : " + width + "x" + height + " Frame saved as '" + file + "'");

GLES11Ext.glBindFramebufferOES(GLES11Ext.GL_FRAMEBUFFER_OES, mainFrame[0]);
GLES32.glViewport(0, 0, mWindowSurface.getWidth(), mWindowSurface.getHeight());

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文