Home > Back-end >  In OpenGL, can in the default frame buffer technology the MRT?
In OpenGL, can in the default frame buffer technology the MRT?

Time:04-03

RT.

According to the little red book description: in a fragment shader written to multiple buffer technology called in at the same time the MRT rendering. this is usually a performance optimization, list can be avoided since many times to deal with the same set of vertices and a waste of time, and does not require many times on the same figure yuan rasterizer .

When I was on the Internet to find relevant implementation, found that everyone in the application of the MRT technology, can apply for a FBO.

Now I want to be in the default FBO application of technology of the MRT.

 
//apply texture buffer, corresponding to the attachment point for GL_COLOR_ATTACHMENT1. (GL_COLOR_ATTACHMENT0 reserved for screen display with)
GlEnable (GL_TEXTURE_2D);
GlGenTextures (1, & amp; M_pickingColorTexture);
GlBindTexture (GL_TEXTURE_2D m_pickingColorTexture);
GlTexImage2D (GL_TEXTURE_2D, 0, GL_RGB32F, w, h, 0, GL_RGB, GL_FLOAT, nullptr);
GlFramebufferTexture2D (GL_FRAMEBUFFER GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D m_pickingColorTexture, 0).
GlDisable (GL_TEXTURE_2D);

//drawing code. Set at the same time writing GL_COLOR_ATTACHMENT0 and GL_COLOR_ATTACHMENT1
GLenum buffers []={GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1};
GlDrawBuffers (2, buffers);
GlDrawElements (... );

//fragment shader
.
Layout (location=0) out vec4 frag_color0;
Layout (location=1) out vec4 frag_color1;

Void main () {
Frag_color0=vec4 (1.0);
Frag_color1=vec4 (0.5);
}

//query results
GlReadBuffer (GL_COLOR_ATTACHMENT1);

GlPixelStorei (GL_UNPACK_ALIGNMENT, 1);
GlReadPixels (x, y, 1, 1, GL_RGB, GL_FLOAT, & amp; PixelInfo);



Code structure roughly as shown above. The last GL_COLOR_ATTACHMENT1 to query the contents of the buffer, found not frag_color1 set in color, but frag_color0 colors.

I tried to apply for additional FBO to do it, is ok. But not a changed the default FBO. Additional application FBO, but will need to draw two model, can affect the performance. The intention of this with the MRT technology do not seem to conform to.

Hope to have who can help to reassure, thank you ~
  • Related