The 3rd parameter is to select the sample. If for example you wanted to save each sample in a separate texture buffer, you could loop in your cpu code calling a whole screen render and set a uniform to say which sample to fetch. If you just want to merge the samples into a single texture you can use glBlitFramebuffer or do it manually in a shader by fetching all the samples and averaging them.

The 3rd parameter is to select the sample. If for example you wanted to save each sample in a separate texture buffer, you could loop in your cpu code calling a whole screen render and set a uniform to say which sample to fetch. If you just want to merge the samples into a single texture you can use glBlitFramebuffer or do it manually in a shader by fetching all the samples and averaging them.

Now, if i choose to do it manually in shader with 4 samples, my shader will be:

You logic outputs the sum of the samples not the average. To average you need to divide the colour by the number of samples. This is of course the simplest thing you can do. You could convert the rgb to a better colour space to do the averaging.

You logic outputs the sum of the samples not the average. To average you need to divide the colour by the number of samples. This is of course the simplest thing you can do. You could convert the rgb to a better colour space to do the averaging.

ohh. Thanks for pointing out.

Now, i am rendering white cube with green background in non default FBO and attaching the created multisampled texture to this FBO.
When i render a cube in default FBO using above texture, it gives corruption in texture.

I am rendering a cube on non default FBO and creating a multisampled texture attached to this FBO. Now, i am applying this multisampled texture on a cube rendered on default FBO. I am using "render to texture" concept here.

I am getting diagonally half of one of 6 faces green. and rest of the faces black...

I would look at the uv values you are using to render the cube. Also have you dumped the texture out as an image to be sure your texture is ok since I assume you have created it programmatically. Also why are using a mutlisample for a texture on the cube rather than a mipmap.

I would look at the uv values you are using to render the cube. Also have you dumped the texture out as an image to be sure your texture is ok since I assume you have created it programmatically. Also why are using a mutlisample for a texture on the cube rather than a mipmap.