Binding pbuffer with different pixel format(Linux)


I am completely new to OpenGL programming. What I am trying to achieve is to get multiple output support under Linux for BrookGPU (a GPGPU language). So, I hacked into the source code and found the problem is located ina function called “bindPBuffer”.

The related code can be browsed at the following URL (there are two bindPBuffer, the 1st is for windows, the second is for Linux):…838&view=markup

Obviously, the original code disabled this feature. I removed the “if (numOutputs > 1) {…}” bit and recompiled the code, I found when the output format is different from float4, which is the default format defined in initPBuffer(), the program will crash with

 X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  143 (GLX)
  Minor opcode of failed request:  5 (X_GLXMakeCurrent)
  Serial number of failed request:  51
  Current serial number in output stream:  51

Following some examples, I modified the code a little bit (attached at the end), but when I re-ran my program, it crashed right after the successful return from bindPBuffer:

 GL: glGetError returned GL_INVALID_VALUE on line 654 of oglkernel.cpp

does anyone have experience how to do pbuffer rebinding under Linux? I would be very grateful if you can share some of your experience or point out the problems in my modification.

thanks a lot.

OGLWindow::bindPbuffer(unsigned int width,
                       unsigned int height,
                       unsigned int numOutputs,
                       unsigned int numComponents) {

  /* Sadly, Linux doesn't seem to like rebinding a
  ** context to a different format pbuffer. 

  if (width > PBUFFER_WIDTH ||
      height > PBUFFER_HEIGHT) {
    fprintf (stderr, "Pbuffer not big enough
    fprintf (stderr, "User requested %d x %d
             width, height);

  static const int pbAttribList[] =
      GLX_PBUFFER_WIDTH, 2048,

  // if the requested pixel format is identical to the current, skip
  if (currentPbufferComponents == numComponents)
    return 0;

  assert (numComponents > 0 &&
          numComponents <= 4);

  // now, rebind the pixel format

  glXDestroyPbuffer(pDisplay, glxPbuffer);

  glxPbuffer = glXCreatePbuffer(pDisplay,

  if (glxPbuffer == 0) {
    fprintf (stderr, "Error: Could not create float%d pbuffer.

  // create a new context (is this necessary?)
  glxContext = glXCreateNewContext(pDisplay,
                                   0, GL_TRUE);
  if (!glxContext) {
    fprintf(stderr, "bindPbuffer: glXCreateContextWithConfig() failed
    exit (1);

  if (!glXMakeCurrent(pDisplay, glxPbuffer, glxContext)) {
    fprintf (stderr, "bindPbuffer: glXMakeCurrent Failed


  currentPbufferComponents = numComponents;

  return 0;

I haven’t used p-buffers in a few years so I don’t remember all the intracacies.
The best thing to do is move over to FBO which has become the new standard for about 6 years.

thanks, I just realized yesterday, there was a branch of BrookGPU with the latest code, in this branch, the bindPBuffer was upgraded to bindFBO, which is what you recommended.…885&view=markup