I am using depth multisampled textures. I have 2 attachments to FBO: 1. Depth-stencil attachment of a texture 2. Color attachment of render buffer. I am rendering a cube on non default FBO with attachment mentioned above and applying this FBO as a texture to a each face of the cube on default FBO. But i am getting corruption with this code. while rendering on non default FBO i am clearing stencil buffer by glclear() call. here is my code:

Code :
     *target11=GL_TEXTURE_2D_MULTISAMPLE;
      *samples=1;
 
 
      glGenTextures(1, &id1);
      nResult |= GL_ERROR_CHECK((GL_NO_ERROR, "glGenTextures(1, &id1);"));
 
      glBindTexture(*target11, id1);
      nResult |= GL_ERROR_CHECK((GL_NO_ERROR, "glBindTexture(*target11, id1);"));
 
      glGenFramebuffers(1, &Fboid);
      nResult |= GL_ERROR_CHECK((GL_NO_ERROR, "glGenFramebuffers(1, &Fboid);"));
 
      GLint framebuffer;
 
      glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING,&framebuffer);
      nResult |= GL_ERROR_CHECK((GL_NO_ERROR,"glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING,&framebuffer);"));
 
      glGenRenderbuffers(1, &depth);
      nResult |= GL_ERROR_CHECK((GL_NO_ERROR, "glGenRenderbuffers(1, &depth);"));
 
      glPixelStorei(GL_UNPACK_ALIGNMENT,1);
      nResult |= GL_ERROR_CHECK((GL_NO_ERROR, "glPixelStorei(GL_UNPACK_ALIGNMENT,1);"));
 
      glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, *samples,GL_DEPTH32F_STENCIL8, 32, 32,true);  
      nResult |= GL_ERROR_CHECK((GL_NO_ERROR, "glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4 ,GL_RGBA, 32, 32,true);"));         
 
      glBindFramebuffer(GL_FRAMEBUFFER, Fboid);
      nResult |= GL_ERROR_CHECK((GL_NO_ERROR, "glBindFramebuffer(GL_FRAMEBUFFER, Fboid);"));
 
      glBindRenderbuffer(GL_RENDERBUFFER, depth);
      nResult |= GL_ERROR_CHECK((GL_NO_ERROR, "glBindFramebuffer(GL_FRAMEBUFFER, Fboid);"));
 
      glRenderbufferStorageMultisample(GL_RENDERBUFFER,*samples, GL_RGBA, 32, 32);
      nResult |= GL_ERROR_CHECK((GL_NO_ERROR, "glBindRenderbuffer(GL_RENDERBUFFER, depth);"));
 
      glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, depth);
      nResult |= GL_ERROR_CHECK((GL_NO_ERROR, "glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth);"));
 
      glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,*target11,id1,0);
      nResult |= GL_ERROR_CHECK((GL_NO_ERROR, "glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,*target11,id1,0);"));
 
      glEnable(GL_MULTISAMPLE);
      nResult |= GL_ERROR_CHECK((GL_NO_ERROR, "glEnable(GL_MULTISAMPLE);"));              
 
      draw_cube(0);
 
glDisable(GL_MULTISAMPLE);    
      nResult |= GL_ERROR_CHECK((GL_NO_ERROR, "glDisable(GL_MULTISAMPLE);"));
 
      status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
      switch(status)
      {
            case GL_FRAMEBUFFER_COMPLETE:                       tdkPrintf("GL_FRAMEBUFFER_COMPLETE\n");                        break;
            case 0x8CDB:                                        tdkPrintf("GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER\n");          break;
            case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:          tdkPrintf("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT\n");           break;
            case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:  tdkPrintf("GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT\n");   break;        
            case GL_FRAMEBUFFER_UNSUPPORTED:                    tdkPrintf("GL_FRAMEBUFFER_UNSUPPORTED\n");                     break;  
            default:                                            tdkPrintf("Unknown issue (%X).\n",status);                     break;
      }
 
      glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
      nResult |= GL_ERROR_CHECK((GL_NO_ERROR, "glBindFramebuffer(GL_FRAMEBUFFER, 0);"));
      draw_geometry();

Frag shader:
Code :
 
Frag shader:
 
 uniform sampler2DMS tk_diffuseMap;
in vec3 ps_texCoord;
out vec4 fragColor;
uniform int samples;
 
void main(void)
{
 
    vec2 iTmp = textureSize(tk_diffuseMap);
    vec2 tmp =floor(iTmp * ps_texCoord.xy);
 
    vec4 color;
    for(int i = 0; i < samples; ++i)
    {
        color= color+texelFetch(tk_diffuseMap, ivec2(tmp), i);
 
    }
 
    fragColor = vec4(color/samples);
}