Multisample pBuffer?

Hi,

does anybody know if it is possible to create a multisampled pBuffer? More specific: a multisample pBuffer with render-to-texture-rectangle active?
I tried it this way:

HDC hDC=wglGetCurrentDC(); 
HGLRC hglRC=wglGetCurrentContext(); 

GLenum target=GL_TEXTURE_RECTANGLE_NV; 
if(hDC && hglRC) 
{ 
glGenTextures(1,&m_index);// generate a texture-Object 
glBindTexture(target, m_index); 
// set the filtering 
glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 

glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 
glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 
             
int iAttributes[50]; 
unsigned int currentAttr=0; 

for(unsigned int i=0; i<50; ++i) 
   iAttributes[i]=0;´ 

   iAttributes[currentAttr++]=WGL_SUPPORT_OPENGL_ARB; 
   iAttributes[currentAttr++]=GL_TRUE; 
   iAttributes[currentAttr++]=WGL_DOUBLE_BUFFER_ARB; 
   iAttributes[currentAttr++]=GL_FALSE; 

   iAttributes[currentAttr++]=WGL_DRAW_TO_PBUFFER_ARB; 
   iAttributes[currentAttr++]=GL_TRUE; 

   iAttributes[currentAttr++]=WGL_ACCELERATION_ARB; 
   iAttributes[currentAttr++]=WGL_FULL_ACCELERATION_ARB; 

   iAttributes[currentAttr++]=WGL_RED_BITS_ARB; 
   iAttributes[currentAttr++]=8; 

   iAttributes[currentAttr++]=WGL_GREEN_BITS_ARB; 
   iAttributes[currentAttr++]=8; 

   iAttributes[currentAttr++]=WGL_BLUE_BITS_ARB; 
   iAttributes[currentAttr++]=8; 

   iAttributes[currentAttr++]=WGL_ALPHA_BITS_ARB; 
   iAttributes[currentAttr++]=8; 

   iAttributes[currentAttr++]=WGL_STENCIL_BITS_ARB; 
   iAttributes[currentAttr++]=8; 

   iAttributes[currentAttr++]=WGL_DEPTH_BITS_ARB; 
   iAttributes[currentAttr++]=24; 

   iAttributes[currentAttr++]=WGL_SAMPLE_BUFFERS_ARB; 
   iAttributes[currentAttr++]=GL_TRUE; 
    
                iAttributes[currentAttr++]=WGL_SAMPLES_ARB; 
   iAttributes[currentAttr++]=4; 
   iAttributes[currentAttr++]=WGL_BIND_TO_TEXTURE_RECTANGLE_RGBA_NV; 
   iAttributes[currentAttr++]=GL_TRUE; 
   float fAttributes[] = {0, 0}; 
// try to find a suitable Pixelformat 
   int status; // status variable 
   UINT  numFormats; // saves the number of suitable formats 
   int   pixelFormat; // saves the best fitting format 

status = wglChoosePixelFormatARB(hDC,iAttributes,fAttributes, 
            1, &pixelFormat, &numFormats); 
   if(status && numFormats) 
   { 
   int iPBufferAttr[20]; 
   int iPBufferCurrentAttr=0; 

   for(unsigned int i=0; i<20; ++i) 
      iPBufferAttr[i]=0; 

iPBufferAttr[iPBufferCurrentAttr++]=WGL_DEPTH_TEXTURE_FORMAT_NV; 
iPBufferAttr[iPBufferCurrentAttr++]=WGL_TEXTURE_DEPTH_COMPONENT_NV; 
iPBufferAttr[iPBufferCurrentAttr++]=WGL_TEXTURE_FORMAT_ARB; 
iPBufferAttr[iPBufferCurrentAttr++]=WGL_TEXTURE_RGBA_ARB; 
iPBufferAttr[iPBufferCurrentAttr++]=WGL_MIPMAP_TEXTURE_ARB; 
iPBufferAttr[iPBufferCurrentAttr++]=0; 
iPBufferAttr[iPBufferCurrentAttr++]=WGL_TEXTURE_TARGET_ARB; 
iPBufferAttr[iPBufferCurrentAttr++]=WGL_TEXTURE_RECTANGLE_NV; 

   m_pBuffer=NULL; 
   m_pBufferDC=NULL; 
   m_pBufferRC=NULL; 
   // Create the pBuffer 
            m_pBuffer=wglCreatePbufferARB(hDC, pixelFormat, _width, _height,iPBufferAttr); 
} 

This only tells me, that there is no pixelformat available. However, if I use the exact same code without the multisampling lines, everything works fine.

So is it simply not possible to do antialiasing in a pBuffer or did I miss something important for it?

Case

I can’t say what exactly is wrong in your case. Probably depends on your hw. But I am able to do it myself. One thing to consider is getting all formats with any multi sample level (so only setting AGL_SAMPLE_BUFFERS_ARB and not setting AGL_SAMPLES_ARB) and then querying each of the formats for their sampling level using
wglGetPixelFormatAttribivARB. If you don’t get any formats even without setting AGL_SAMPLES_ARB you may have to experiment with your other settings. In that case you’re probably being too specific, and should add code to use wglGetPixelFormatAttribivARB to find formats with the minimal requirements you need.

I find this utility particularly useful NVPixelFormat .

Also I did wonder if you would require double buffering for AA pixel formats.

Matt

Thanks for your answers, but it seems to be impossible. I have narrowed the problem down a littlebit and it looks like the problem occurs when I use the render-to-texture extension. Without that I can create an antialiased pBuffer without problems. Problem is: I need to use the pBuffer as a Texture and the glRead-glCopy Method is simply to slow.

By the way: I am using a GeforceFX 5600

Any other ideas?

Case

Current hardware cannot do the filtering necessary to texture directly from a multi-sampled buffer. The only solution currently is to create a multisampled buffer without render-to-texture, and then do copies from it to texture. The copy implicitly performs the necessary downfiltering.

Originally posted by CaseMillennium:
[b]Thanks for your answers, but it seems to be impossible. I have narrowed the problem down a littlebit and it looks like the problem occurs when I use the render-to-texture extension. Without that I can create an antialiased pBuffer without problems. Problem is: I need to use the pBuffer as a Texture and the glRead-glCopy Method is simply to slow.

By the way: I am using a GeforceFX 5600

Any other ideas?

Case[/b]

CaseMillennium you do realize you want to use glCopyTexSubImage (leaves texture on card) not glReadPixel (pulls it into system memory)