将 GL_TEXTURE_2D 复制到 GL_TEXTURE_2D_ARRAY 纹理的一个切片中

Tho*_*mas 1 opengl

我正在尝试将一个 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();
Run Code Online (Sandbox Code Playgroud)

出现错误时glFramebufferTexture3D: GL_INVALID_VALUE 我认为这是因为

如果纹理不为零或现有纹理对象的名称,则会生成 GL_INVALID_VALUE。

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

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

第三:我需要glFramebufferTexture3D命令还是glFramebufferTexture2DGL_TEXTURE_2D_ARRAYs的命令?

Nic*_*las 5

假设“这是我的代码”实际上包含您的所有代码,它不起作用,因为您在调用glTexImage3D为其分配存储之前没有绑定 2D 数组纹理。

但是,您不必渲染或位图传输来复制纹理数据。您可以通过...复制纹理数据来复制纹理数据。该glCopyImageSubData函数可以在具有不同数组层数的纹理之间复制层。在你的情况下:

glCopyImageSubData(
    texture2D_ID, GL_TEXTURE_2D, 0, 0, 0, 0,
    texture2D_Array_ID, GL_TEXTURE_2D_ARRAY, 0, 0, 0, slicenumber,
    nWidth, nHeight, 1);
Run Code Online (Sandbox Code Playgroud)

这需要 OpenGL 4.3 或更高版本,或者 ARB/NV_copy_image 扩展之一。NVIDIA 扩展实际上已得到相当广泛的实施。

但仍然需要glTexImage3D正确使用。