PDA

View Full Version : Help! Drawing to pbuffer causes 1282 invalid operation?



playmesumch00ns
05-15-2005, 11:26 PM
I'm trying to incorporate pbuffers into my renderer. I'm using the CFPBuffer code from the NVSDK, which works in their example application.

However, in mine, doing anything more than clearing the pbuffer causes an error 1282 (invalid operation).

An empty glBeing/End air is fine, but doing anything like drawing vertices, or modifying the transform stack, causes the error. I can't for the life of me figure out what I might be doing wrong. Since the nvidia example works, it's got to be something in my initialization, but I don't know where to start looking!


int width = pbuf.getWidth();
int height = pbuf.getHeight();

pbuf.activate();

CHECK_GL_ERROR();

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glMatrixMode( GL_MODELVIEW );
glLoadIdentity();

glBegin( GL_TRIANGLES );
glVertex3f( 0, 0, 0 ); // <----------- THIS ERRORS!
CHECK_GL_ERROR();
glVertex3f( 1, 0, 0 );
CHECK_GL_ERROR();
glVertex3f( .5, 0, .5 );
glEnd();




// copy contents of pbuffer to a texture
glBindTexture(GL_TEXTURE_RECTANGLE_NV, fptexture);
CHECK_GL_ERROR();
glCopyTexSubImage2D(GL_TEXTURE_RECTANGLE_NV, 0, 0, 0, 0, 0, width, height);
CHECK_GL_ERROR();
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);

CHECK_GL_ERROR();

glutSwapBuffers();

sqrt[-1]
05-16-2005, 12:10 AM
For a start, don't call glGetError between glBegin/glEnd. It is invalid to do so.

playmesumch00ns
05-16-2005, 12:17 AM
Thanks for the tip. If I take it down to calling
glutSolidTeapot(1);
CHECK_GL_ERROR();I get the error. Doesn't seem I can do anything at all. I've been through the nvidia example and tried to match their setup exactly, but I can't see what's different any more.

Are there any general rules to follow when setting up and using pbuffers that might give this sort of behaviour?

playmesumch00ns
05-16-2005, 07:23 AM
Ok so I tracked down the problem by stripping everything out...

Turns out I have to have a fragment shader (any fragment shader) attached in order for it to work.

At least it draws now, but it looks like my normals are reversed. Any ideas? Is this documented anywhere?

jra101
05-16-2005, 10:59 AM
From the GL_NV_float_buffer extension specification:


What happens when rendering to an floating-point color buffer if fragment
program mode is disabled? Or when fragment program mode is enabled, but
no program is loaded?

RESOLVED: Fragment programs are required to use floating-point color
buffers. An INVALID_OPERATION error is generated by any GL command
that generates fragments if FRAGMENT_PROGRAM_NV is disabled. The same
behavior already exists for conventional frame buffers if
FRAGMENT_PROGRAM_NV is enabled but the bound fragment program is
invalid.

ScottManDeath
05-16-2005, 12:13 PM
Hehe :D , some days ago I also trapped into this. I use NV_float_buffer with ARB_texture_rectangle and EXT_framebuffer_object. Without fragment shaders (NV_fragment_program or GLSL fragment shader) drawing resulted in GL_INVALID_OPERATION. After checking the specs, NV_float_buffer beeing the last ;) I found my mistake. Now everything is fine. :cool:

playmesumch00ns
05-16-2005, 11:00 PM
Ahaa that'll teach me to read the specs!

The weird normals thing was actually due to my not specifically enabling GL_DEPTH_TEST...

As far as I was aware, this is enabled by default in a glut window? Do I have to explicitly set up the state for a pbuffer then?

How do you guys manage this for many buffers? Do you just set the stuff you need, or do you use a sort of state-management class which sets all the state variables when you create a buffer?