I'm having trouble using floating-point pbuffers under linux. I'm trying to use the code from the NVSDK example in my own app, but something in my setup must be wrong as it's not working.
I set it up like so:
// Try making a float pbuffer
if ( !pbuf.create( 256, 256 ) )
cerr << "Could not create pbuffer!" << endl;
else
cerr << "Created pbuffer successfully!" << endl;
pbuf.activate();
ResizeFunc()(256, 256);
glClearColor(0.5, 0.6, 0.7, 1.0);
pbuf.deactivate();
// make a float texture rect to hold it
glGenTextures(1, &fptexture);
glBindTexture(GL_TEXTURE_RECTANGLE_NV, fptexture);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGBA_NV, 256, 256, 0, GL_RGBA, GL_FLOAT, NULL);
// Fragment programs to write and read it
const char readTexRect[] =
"!!FP1.0\n"
"TEX o[COLR], f[TEX0].xyxx, TEX0, RECT;\n"
"END\n";
glGenProgramsNV(1, &readTextureRECT);
glBindProgramNV(GL_FRAGMENT_PROGRAM_NV, readTextureRECT);
glLoadProgramNV(GL_FRAGMENT_PROGRAM_NV, readTextureRECT, strlen(readTexRect), (const GLubyte *)readTexRect);
const char readTex2D[] =
"!!FP1.0\n"
"TEX R0, f[TEX0].xyxx, TEX0, 2D;\n"
"MUL o[COLR], f[COL0], R0;\n"
"END\n";
glGenProgramsNV(1, &readTexture2D);
glBindProgramNV(GL_FRAGMENT_PROGRAM_NV, readTexture2D);
glLoadProgramNV(GL_FRAGMENT_PROGRAM_NV, readTexture2D, strlen(readTex2D), (const GLubyte *)readTex2D);
which all goes just fine. Then in my display loop I try to draw into the buffer, then copy it to the floating-point texture. I get an error back from GL when I try to bind the float texture after drawing. The error I get is #1282(invalid operation)
pbuf.activate();
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
// +++++++++++++++++++++++++++++++++++++++++++++++
// DRAW SOME STUFF
glEnable( GL_TEXTURE_2D );
// copy contents of pbuffer to a texture
// +++++++++++++++++++++++++++++++++++++++++++
// +++++ FAILS ON THIS LINE ++++++++++++++++++++
glBindTexture(GL_TEXTURE_RECTANGLE_NV, fptexture);
glCopyTexSubImage2D(GL_TEXTURE_RECTANGLE_NV, 0, 0, 0, 0, 0, width, height);
pbuf.deactivate();
CHECK_GL_ERROR();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// draw a single quad with the texture containing a snapshot of the
// floating point pbuffer
glEnable(GL_FRAGMENT_PROGRAM_NV);
glBindProgramNV(GL_FRAGMENT_PROGRAM_NV, readTextureRECT);
glBindTexture(GL_TEXTURE_RECTANGLE_NV, fptexture);
CHECK_GL_ERROR();
glTranslatef(-0.5, -0.5,-0.9);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0);
glTexCoord2f(width, 0.0); glVertex2f(1.0, 0.0);
glTexCoord2f(width, height); glVertex2f(1.0, 1.0);
glTexCoord2f(0.0, height); glVertex2f(0.0, 1.0);
glEnd();
glDisable(GL_FRAGMENT_PROGRAM_NV);
Binding the texture worked fine in the initialization process, so why not in the display loop. Can anyone see what I'm doing wrong?