2016-05-25 147 views
1

我試圖在同一時間渲染多采樣和單採樣紋理(drawcall)。 我爲什麼要這樣?因爲多重採樣紋理使用抗鋸齒,而單採樣紋理用於選色。 兩個紋理(nRenderTargetTexture和nColorPickingTexture)具有相同的大小。 如果我運行下面的代碼,它在GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE的情況下失敗。 可以同時渲染多重採樣和單採樣紋理嗎?在framebuffer中渲染多重採樣和單採樣紋理

順便說一句:我還使用glGetError(),但它返回GL_NO_ERROR

// Enable multisampling 
glEnable(GL_MULTISAMPLE); 

glGenFramebuffers(1, pFramebufferID); 
glBindFramebuffer(GL_FRAMEBUFFER, *pFramebufferID); 

// Create color render buffer 
glGenRenderbuffers(1, &nColorBuffer); 
glBindRenderbuffer(GL_RENDERBUFFER, nColorBuffer); 
glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_RGBA8, nWidth, nHeight); 
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, nColorBuffer); 

// Create depth render buffer 
glGenRenderbuffers(1, &nDepthBuffer); 
glBindRenderbuffer(GL_RENDERBUFFER, nDepthBuffer); 
glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH24_STENCIL8, nWidth, nHeight); 

//Attach the multisampled textures 
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, nDepthBuffer); 
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, nDepthBuffer); 
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, nRenderTargetTexture, 0); 
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, nColorPickingTexture, 0); 
const GLenum draw_buffers[] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}; 

glDrawBuffers(2, draw_buffers); 

GLenum eFramebufferOk = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER); 

bool bResult = false; 
switch (eFramebufferOk) 
{ 
    case GL_FRAMEBUFFER_UNDEFINED: 
    { 
     DebugAssertOnce(CREATE_FRAME_BUFFER_FAILED); 
    } 
    break; 
    case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: 
    { 
     DebugAssertOnce(CREATE_FRAME_BUFFER_FAILED); 
    } 
    break; 
    case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: 
    { 
     DebugAssertOnce(CREATE_FRAME_BUFFER_FAILED); 
    } 
    break; 
    case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: 
    { 
     DebugAssertOnce(CREATE_FRAME_BUFFER_FAILED); 
    } 
    break; 
    case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: 
    { 
     DebugAssertOnce(CREATE_FRAME_BUFFER_FAILED); 
    } 
    break; 
    case GL_FRAMEBUFFER_UNSUPPORTED: 
    { 
     DebugAssertOnce(CREATE_FRAME_BUFFER_FAILED); 
    } 
    break; 
    case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: 
    { 
     DebugAssertOnce(CREATE_FRAME_BUFFER_FAILED); 
    } 
    break; 
    case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS: 
    { 
     DebugAssertOnce(CREATE_FRAME_BUFFER_FAILED); 
    } 
    break; 
    case GL_FRAMEBUFFER_COMPLETE: 
    { 
     bResult = true; 
    } 
    break; 
    default: 
    { 
     DebugAssertOnce(CREATE_FRAME_BUFFER_FAILED); 
    } 
    break; 
} 

非常感謝!

回答

1

是否可以同時渲染爲多采樣和單採樣紋理?

否。附加到幀緩衝區的所有圖像必須具有相同的採樣計數。否則,你會得到GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE

0

btw:在同一着色器調用中使用抗鋸齒和拾取,我使用多采樣拾取紋理。 後,我渲染我的場景我做了第二renderstepp(2個三角形在屏幕上)和fragmentshader裏面我用:

texelFetch(pickingTexture,ivec2(position),0); //0 sample 

它給我回不antialiasied採摘質感。 我寫了這篇文章,因爲也許有人正在嘗試相同的。