简体   繁体   English

从QOpenGLFramebuffer创建立方体贴图

[英]Create Cubemap from QOpenGLFramebuffer

I want to implement cubemap convolution for IBL using a Qt widget. 我想使用Qt小部件为IBL实现立方体贴图卷积。

When implementing conversion from an equirectangular map to a cubemap I ran into an error I do not understand: 当实现从等角图到立方图的转换时,我遇到了一个我不明白的错误:

Here is how I create my renderbuffer: 这是我创建渲染缓冲区的方法:

QOpenGLFramebufferObjectFormat format;

format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
format.setInternalTextureFormat(GL_RGBA32F_ARB);

envTarget = new QOpenGLFramebufferObject(QSize(256, 256), format);

Here is how I create my cubemap texture: 这是我创建立方体贴图纹理的方法:

envCubemap = new QOpenGLTexture(QOpenGLTexture::TargetCubeMap);
envCubemap->create();
envCubemap->bind();

envCubemap->setSize(256, 256, 4);
envCubemap->setFormat(QOpenGLTexture::RGBAFormat);
envCubemap->allocateStorage(QOpenGLTexture::RGB, QOpenGLTexture::Float32);
envCubemap->setMinMagFilters(QOpenGLTexture::Nearest, QOpenGLTexture::Linear);

I then proceed to render the different cubemap views to the corresponding parts of the texture: 然后,我继续将不同的立方体贴图视图呈现到纹理的相应部分:

envCubemap->bind(9);

glViewport(0, 0, 256, 256);
envTarget->bind();

for (unsigned int i = 0; i < 6; ++i)
{
    ActiveScene->ActiveCamera->View = captureViews[i];
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 9, 0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    drawBackground();
}

envTarget->release();

The drawBackground() method draws an environment sphere which works fine with my default buffer. drawBackground()方法绘制一个环境球,该球可以与我的默认缓冲区一起正常工作。

The openGL error I get is 1282. This turns to 0 if I comment out the glFramebufferTexture2D line. 我得到的openGL错误是glFramebufferTexture2D如果我注释掉glFramebufferTexture2D行, glFramebufferTexture2D变为0。 1282 corresponds to GL_INVALID_OPERATION or GL_INVALID_VALUE , where both of these have multiple errors attached to them according to the glFramebufferTexture2D documentation. 1282对应于GL_INVALID_OPERATIONGL_INVALID_VALUE ,根据glFramebufferTexture2D文档,这两者都附有多个错误。

What did I get wrong? 我怎么了? I tried iterating over each parameter in order to solve this error but did not come up with a solution. 我尝试遍历每个参数以解决此错误,但未提出解决方案。 As this should be fairly standard stuff I hope to find a solution here :D Help? 因为这应该是相当标准的东西,所以我希望在这里找到解决方案:D帮助?

You need to actually tell the framebuffer, which texture to render to using its ID, and not '9': 您实际上需要告诉帧缓冲区,使用其ID而不是'9'渲染哪个纹理:

glFramebufferTexture2D(
     GL_FRAMEBUFFER,
     GL_COLOR_ATTACHMENT0,
     GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
     envCubemap->textureId(), // <--- The change
     0);

The same goes for envCubemap->bind(9); envCubemap->bind(9); , which can be simply removed. ,只需删除即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM