PDA

View Full Version : fragment program & switching pbuffer context



Guido
10-27-2004, 12:28 AM
I have a single fragment shader that must write in the same frame, with an if on uniform bool variable, a different color on two different p-buffers.

I would want to write something like this in particular i would want to bind the shader program and the drawing context only once in the init function:




Pbuffer p1;
Pbuffer p2;

GLhandleARB prog;

SetUniform(prog,string,val)
{
GLint hvar;
if ((hvar = glGetUniformLocationARB(prog,var.c_str())) == -1)
{
//ERROR HANDLING
}
glUniform1fARB(hvar,val);
}

init()
{
p1.makeActiveRenderSurface();
glUseProgramObjectARB(prog);
p2.makeActiveRenderSurface();
glUseProgramObjectARB(prog);
};

display()
{
p1.makeActiveRenderSurface();
SetUniform(prog,"UseFirstBuffer",true);
//display something
p2.makeActiveRenderSurface();
SetUniform(prog,"UseFirstBuffer",false);
if ( (er = glGetError()) != 0)
Utility::ReportError(er);
//display something other
}

main()
{
init()
glutDisplayFunc(display);
glutMainLoop()
}...but if I do this the second invocation at SetUniform give me a glGetError and the applicantion's output is linked at the standard OpenGL pipeline and not at my fragment shader...

Otherwise if I bind the context and the fragment program at every display's calling all seems good


display()
{
p1.makeActiveRenderSurface();
glUseProgramObjectARB(prog);
SetUniform(prog,"UseFirstBuffer",true);
// display something
p2.makeActiveRenderSurface();
glUseProgramObjectARB(prog);
SetUniform(prog,"UseFirstBuffer",false);
if ( (er = glGetError()) != 0) Utility::ReportError(er);
//display something other
}WHY???????? And how much may it cost to me in terms of FPS????