我在OpenTK(一个C#包装的OpenGL 4)制作的2D游戏,一切都很好,除了多边形和东西跳跃,而不是口吃平滑移动的锯齿状边缘 - 所以我试图在多重采样中添加抗锯齿纹理。的OpenGL 4多重采样与FBO - FBO不完整
我的设置有几台摄像机,它们将所有场景对象渲染到FrameBufferObject纹理上(我希望这是MSAA),然后将它们全部绘制到屏幕上(不需要多重采样),一个在另一个之上。
没有多重采样,它工作得很好,但现在我想改变我的所有的Texture2D调用Texture2DMultisample等,但现在我得到FBO未完成的错误和它绘制错误。我相信我也需要改变我的着色器,但我想先解决这个问题。
下面的代码引用了几类,比如我做了纹理,但我不认为应该影响到这一点,我不想扰乱后 - 如果需要会给MROE细节。
我成立了FBO每个摄像头:
private void SetUpFBOTex()
{
_frameBufferTexture = new Texture(GL.GenTexture(), Window.W, Window.H);
GL.BindTexture(TextureTarget.Texture2DMultisample, _frameBufferTexture.ID);
GL.TexImage2DMultisample(TextureTargetMultisample.Texture2DMultisample, 0, PixelInternalFormat.Rgba8, Window.W, Window.H, true);
_frameBufferID = GL.GenFramebuffer();
}
,并得出:
public void Render(Matrix4 matrix)
{
GL.Enable(EnableCap.Multisample);
//Bind FBO to be the draw destination and clear it
GL.BindFramebuffer(FramebufferTarget.Framebuffer, _frameBufferID);
GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2DMultisample, _frameBufferTexture.ID, 0);
GL.ClearColor(new Color4(0,0,0,0));
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
//draw stuff here
foreach (Layer l in Layers)
l.Render(Matrix);
GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
//Bind the FBO to be drawn
_frameBufferTexture.Bind();
//Translate to camera window position
Matrix4 fbomatrix = matrix * Matrix4.CreateTranslation(_window.x, _window.y, 0) * FBOMatrix;
//Bind shader
shader.Bind(ref fbomatrix, DrawType);
//Some OpenGL setup nonsense, binding vertices and index buffer and telling OpenGL where in the vertex struct things are, pointers &c
GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBuffer);
GL.EnableVertexAttribArray(shader.LocationPosition);
GL.VertexAttribPointer(shader.LocationPosition, 2, VertexAttribPointerType.Float, false, Stride, 0);
if (shader.LocationTexture != -1)
{
GL.EnableVertexAttribArray(shader.LocationTexture);
GL.VertexAttribPointer(shader.LocationTexture, 2, VertexAttribPointerType.Float, false, Stride, 8);
}
GL.EnableVertexAttribArray(shader.LocationColour);
GL.VertexAttribPointer(shader.LocationColour, 4, VertexAttribPointerType.UnsignedByte, true, Stride, 16);
GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexBuffer);
//Draw the damn quad
GL.DrawArrays(DrawType, 0, Vertices.Length);
//Cleanup
GL.DisableVertexAttribArray(shader.LocationPosition);
if (shader.LocationTexture != -1)
GL.DisableVertexAttribArray(shader.LocationTexture);
GL.DisableVertexAttribArray(shader.LocationColour);
}
请问FBO有深度附件?我没有看到它被附加在发布的代码中,但是您清除深度缓冲区的事实表明存在一个。 –
我不相信它,我不知道我知道一个是什么.. –
我真的不明白你希望通过什么建立一个多重采样纹理0样品来完成?这可能是因为它不完整。 –