GL_COLOR_ATTACHMENT是做什么的? [英] What does GL_COLOR_ATTACHMENT do?

查看:2229
本文介绍了GL_COLOR_ATTACHMENT是做什么的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在学习framebuffers,我只是不明白Color附件的功能。

第二个参数的要点是什么? $ c> glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,textureColorBuffer,0); 

当我将其更改为COLOR_ATTACHMENT1时,为什么没有绘制到我的帧缓冲区?



如何通过将纹理设置为Color attachment 1来绘制帧缓冲区?
为什么会使用多种颜色附件有用?
是否与glActiveTexture(GL_TEXTUREi)概念一次绘制多个纹理相似?



我只是想了解更多的开放式gl。谢谢。

解决方案

是的,framebuffer可以有多个颜色附件,第二个参数是 glFramebufferTexture2D )控制你正在设置哪一个。可以查询支持的最大颜色附件数量:

  GLint maxAtt = 0; 
glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS,& maxAtt);

所有实现支持的最小数量为8。



要选择要渲染的缓冲区,可以使用 glDrawBuffer() glDrawBuffers()。这两个调用之间唯一的区别是第一个允许你指定一个缓冲区,而第二个允许多个缓冲区。



在你尝试的例子中,你可以通过以下任一方式呈现给 GL_COLOR_ATTACHMENT1

  glDrawBuffer(GL_COLOR_ATTACHMENT1); 

或:

  GLenum bufs [1] = {GL_COLOR_ATTACHMENT1}; 
glDrawBuffers(1,bufs);

默认值是 GL_COLOR_ATTACHMENT0 ,这解释了为什么您已成功呈现到附件0而无需使用此调用。绘制缓冲区列表是FBO状态的一部分。



为了产生多个颜色缓冲区的输出,您可以在片段着色器中定义多个输出。
$ b

多种颜色缓冲区(通常称为缩写MRT =多个渲染目标)的一个流行用法是延迟着色,其中用于着色计算的内插顶点属性存储在多个缓冲区中在最初的渲染过程中。然后使用第一遍中生成的缓冲区的属性值,仅对第二遍中的可见像素执行实际阴影计算。请参阅 http://ogldev.atspace.co.uk/www/tutorial35/ tutorial35.html ,以获得更完整的解释。


I'm learning about framebuffers right now and I just don't understand what the Color attachment does. I understand framebuffers.

What is the point of the second parameter in:

glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureColorBuffer, 0);

Why doesn't anything draw to my frame buffer when I change it to COLOR_ATTACHMENT1?

How could I draw to the frame buffer by setting the texture to Color attachment 1? Why would using multiple color attachments be useful? Is it similar to the glActiveTexture(GL_TEXTUREi) concept of drawing multiple textures at once?

I'm just trying to understand more open gl. Thanks.

解决方案

Yes, a framebuffer can have multiple color attachments, and the second parameter to glFramebufferTexture2D() controls which of them you're setting. The maximum number of supported color attachments can be queried with:

GLint maxAtt = 0;
glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxAtt);

The minimum number supported by all implementations is 8.

To select which buffer(s) you want to render to, you use glDrawBuffer() or glDrawBuffers(). The only difference between these two calls is that the first one allows you to specify only one buffer, while the second one supports multiple buffers.

In the example you tried, you can render to GL_COLOR_ATTACHMENT1 by using either:

glDrawBuffer(GL_COLOR_ATTACHMENT1);

or:

GLenum bufs[1] = {GL_COLOR_ATTACHMENT1};
glDrawBuffers(1, bufs);

The default is GL_COLOR_ATTACHMENT0, which explains why you had success rendering to attachment 0 without ever using this call. The list of draw buffers is part of the FBO state.

To produce output for multiple color buffers, you define multiple outputs in the fragment shader.

One popular use for multiple color buffers (often referred to by the acronym MRT = Multiple Render Targets) is deferred shading, where the interpolated vertex attributes used for the shading calculation are stored in a number of buffers in the initial rendering pass. The actual shading calculation is then performed only for the visible pixels in a second pass, using the attribute values from the buffers produced in the first pass. See for example http://ogldev.atspace.co.uk/www/tutorial35/tutorial35.html for a more complete explanation of how this works.

这篇关于GL_COLOR_ATTACHMENT是做什么的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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