将FBO复制到VBO时出错 [英] Error copying FBO to VBO

查看:139
本文介绍了将FBO复制到VBO时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在GPU上进行了一些计算之后,我想将FBO中存储的结果复制到VBO进行渲染.

After doing some computation on the GPU I want to copy the results stored in the FBO to VBOs for rendering.

问题:执行复制时,似乎某些数据已损坏.我已经检查了缓冲区的格式和大小,并检查了FBO中存储的数据是否正确.

The problem: It looks like some of the data is corrupted when I do the copy. I've already checked both buffers' format and size, and also checked that the data stored in the FBO is correct.

请考虑以下代码来初始化FBO:

Consider the following code that initializes the FBO:

unsigned int verticesTextureId = AllocateTexture(GL_TEXTURE_RECTANGLE, mVBOSize, 1, GL_RGBA32F, GL_RGBA);
CHECK_FOR_OPENGL_ERRORS();

unsigned int normalsTextureId = AllocateTexture(GL_TEXTURE_RECTANGLE, mVBOSize, 1, GL_RGBA32F, GL_RGBA);
CHECK_FOR_OPENGL_ERRORS();

SetUpViewport(mVBOSize, 1);

glBindFramebuffer(GL_FRAMEBUFFER, mFBOId);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE, verticesTextureId, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_RECTANGLE, normalsTextureId, 0);

以下代码初始化VBO,并将数据从FBO复制到VBO:

And the following code that initializes the VBOs and copies data from the FBO to the VBOs:

mVerticesBufferId = AllocateVBO();
CHECK_FOR_OPENGL_ERRORS();

glBindBuffer(GL_PIXEL_PACK_BUFFER, mVerticesBufferId);
glBufferData(GL_PIXEL_PACK_BUFFER, mVBOSize * 4 * sizeof(float), 0, GL_STATIC_DRAW);

mNormalsBufferId = AllocateVBO();
CHECK_FOR_OPENGL_ERRORS();

glBindBuffer(GL_PIXEL_PACK_BUFFER, mNormalsBufferId);
glBufferData(GL_PIXEL_PACK_BUFFER, mVBOSize * 4 * sizeof(float), 0, GL_STATIC_DRAW);

glReadBuffer(GL_COLOR_ATTACHMENT0);
glBindBuffer(GL_PIXEL_PACK_BUFFER, mVerticesBufferId);
glReadPixels(0, 0, mVBOSize, 1, GL_RGBA, GL_FLOAT, 0);

glReadBuffer(GL_COLOR_ATTACHMENT1);
glBindBuffer(GL_PIXEL_PACK_BUFFER, mNormalsBufferId);
glReadPixels(0, 0, mVBOSize, 1, GL_RGBA, GL_FLOAT, 0);

在这里,我将VBO绑定为顶点/法线属性并调用绘制:

Here I bind the VBOs as vertex/normal attributes and call the draw:

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);

glBindBuffer(GL_ARRAY_BUFFER, mVerticesBufferId);
glVertexPointer(4, GL_FLOAT, 4 * sizeof(float), 0);

glBindBuffer(GL_ARRAY_BUFFER, mNormalsBufferId);
glNormalPointer(GL_FLOAT, 4 * sizeof(float), 0);

glDrawArrays(GL_POINTS, 0, mVBOSize);

glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);

此呼叫后,大多数点正确显示在屏幕上,但有些却奇怪地出现在位置上.这似乎与信号或钳位无关,因为正确显示了具有负数或大于1个分量的顶点.

After this call, most points appear correctly on screen, but some appear strangely out of place. This seems to be unrelated to signal or clamping because vertices with negative or greater than 1 components are being displayed correctly.

我要附上未正确渲染的 kosh雪花(曲线)的图片.

I'm attaching pictures of a kosh snowflake (a curve) that's not being correctly rendered.

1)渲染为点的顶点:

1) Vertices rendered as points:

2)使用简单的几何着色器将顶点渲染为线条:

2) Vertices rendered as line strips, using a simple geometry shader:

参考图片:

推荐答案

使用gDEBugger,我发现VBO上的数据也是正确的.问题在于,在计算片段着色器后,我的向量(w)的同构分量上存在垃圾,这对转换产生了不良影响.

Using gDEBugger I found that the data on my VBOs were also correct. The problem was that after fragment shader computation, the homogeneous component of my vectors (the w) had garbage on them, which produced unwanted effects on transforms.

这篇关于将FBO复制到VBO时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆