【问题标题】:copy GL_TEXTURE_2D into one slice of a GL_TEXTURE_2D_ARRAY Texture将 GL_TEXTURE_2D 复制到 GL_TEXTURE_2D_ARRAY 纹理的一个切片中
【发布时间】:2018-03-02 00:36:13
【问题描述】:

我正在尝试将一个 GL_TEXTURE_2D 复制到 GL_TEXTURE_2D_ARRAY 纹理的选定切片中。

我尝试将通常的 Texture_2D 绑定到一个帧缓冲区,并且仅将 Texture_2D_Array 的一部分绑定到另一个帧缓冲区(两者具有相同的大小(宽度、高度、GL_RGB、GL_UNSIGNED_BYTE))。 后来我想glBlitFramebuffer 会将该纹理复制到这一切片中……但我想我误解了glFramebufferTexture3D 命令。

顺便说一句:GL_TEXTURE_2D 已正确加载,我也将其打印出来(有效)

这是我的代码:

//Create 2 FBOs for copying textures
glGenFramebuffers(1, &nFrameBufferRead); //FBO for texture2D
glGenFramebuffers(1, &nFrameBufferWrite); //FBO for one slice of the texture2d_array
CBasics::GetOpenGLError(); 

//generate the GL_TEXTURE_2D_ARRAY with given values (glgentextures is already called for this texture)
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, nWidth, nHeight, countSlices, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
CBasics::GetOpenGLError();  

//Bind the Texture2D to the readFramebuffer
glBindFramebuffer(GL_READ_FRAMEBUFFER, nFrameBufferRead);
glFramebufferTexture(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture2D_ID, 0);
CBasics::GetOpenGLError();

//try to bind the Texture2D_Array to the drawFramebuffer
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, nFrameBufferWrite);
CBasics::GetOpenGLError(); //till here everything works (no glerror)
glFramebufferTexture3D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_ARRAY, texture2D_Array_ID, 0, slicenumber); // here the error appears 
CBasics::GetOpenGLError();

//because of the error one step earlier here will be the next error... 
glBlitFramebuffer(0, 0, nWidth, nHeight, 0, 0, nWidth, nHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
CBasics::GetOpenGLError();

glFramebufferTexture3D 出现错误:GL_INVALID_VALUE 我想是因为

如果纹理不为零或不为 现有的纹理对象。

1st:这种方式可以正确地将纹理复制到数组切片中吗?或者有更好的方法吗?

第二个:是否可以只绑定 GL_TEXTURE_2D_ARRAY 的一个切片?

3rd:对于 GL_TEXTURE_2D_ARRAY,我需要 glFramebufferTexture3D 命令还是 glFramebufferTexture2D 命令?

【问题讨论】:

  • 您实际上是在尝试复制数据,还是要渲染到该数组层?因为这是两个非常不同的操作。
  • @NicolBolas 我正在尝试复制数据...在 TEXTURE_2D_ARRAY 内的这个方法之后,一个切片应该是 TEXTURE_2D

标签: opengl


【解决方案1】:

假设“Here's my code”确实包含了您的所有代码,它不起作用,因为您在调用 glTexImage3D 为其分配存储空间之前没有绑定 2D 数组纹理。

但是,您不必渲染或 blit 即可复制纹理数据。您可以通过...复制纹理数据...copying texture dataglCopyImageSubData 函数可以在具有不同阵列层数的纹理之间复制层。在你的情况下:

glCopyImageSubData(
    texture2D_ID, GL_TEXTURE_2D, 0, 0, 0, 0,
    texture2D_Array_ID, GL_TEXTURE_2D_ARRAY, 0, 0, 0, slicenumber,
    nWidth, nHeight, 1);

这需要 OpenGL 4.3 或更高版本,或 ARB/NV_copy_image 扩展之一。 NVIDIA 扩展实际上已被广泛实施。

但是你还是需要正确使用glTexImage3D

【讨论】:

  • 感谢您的快速回答! glCopyImageSubData 有效!里面只有一个错误:最后一个参数必须是'1'而不是'0'。非常感谢!
猜你喜欢
  • 2016-09-13
  • 1970-01-01
  • 1970-01-01
  • 2016-10-02
  • 2011-03-16
  • 1970-01-01
  • 2016-11-16
  • 2013-07-19
  • 1970-01-01
相关资源
最近更新 更多