Another pbuffer thread

Hi,

I just tried to create a simple pbuffer (for later use in shadow-mapping) and I just can’t get it to work, this is how I set it up:


supported = drawable.canCreateOffscreenDrawable();
            if(!supported) {
                  System.err.println("PBuffers not supported, shadow mapping not available");
                  return;
            }
            
            GLCapabilities caps = new GLCapabilities();
            caps.setDoubleBuffered(false);
            //caps.setDepthBits(24);
            //caps.setOffscreenRenderToTexture(true);
            
            GLPbuffer pbuffer = drawable.createOffscreenDrawable(caps, 512, 512);
            pbuffer.addGLEventListener(this);
            System.err.println("Pbuffer created");

that code runs perfectly and everything, except that the EventListener’s init() method never gets called.

Did I miss something?
My current setup is a Geforce 3 with the most current drivers, so pbuffers should be supported.

Thanks for any help.

Jan

Ah, the “interesting” pbuffer initialisation.

Firstly, what code are you running - the public 5 Sept release, or a daily build? The 5 Sept release is bugged and pbuffers don’t work at all. You’ll have to grab one of the dailies or build it yourself.

After that, you will need to call display on it at least once before the init is actually called. Calling display() on it at just a random point in time does not seem to work either. The only time I’ve managed to get it to correctly initialise is if I call display on it which in the display loop of the parent canvas that it was generated from. Even then, it has always been on the second call to display() that the init is actually run. I’m trying to track down why it has such oddball behaviour as it is making some of our code that only wants a single render to be done on the pbuffer have a lot issues. It’s going slowly though…

Hi,

Thanks for the help so far.
Calling the pbuffers display-method from the “creator’s” display-method resulted in the pbuffer’s init-method being called.

But on the second frame, I get the following exception:


net.java.games.jogl.GLException: Surface already unlocked
      at net.java.games.jogl.impl.windows.WindowsOnscreenGLContext.unlockSurface(WindowsOnscreenGLContext.java:192)
      at net.java.games.jogl.impl.windows.WindowsOnscreenGLContext.free(WindowsOnscreenGLContext.java:134)
      at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:265)
      at om.uiServices.OmCanvas.display(OmCanvas.java:302)
      at om.sceneToolkit.MultiDrawableAnimator$1.run(MultiDrawableAnimator.java:96)
      at java.lang.Thread.run(Thread.java:534)

After playing around a bit, I noticed that when I start calling the pbuffer’s display()-method, after a couple hundred frames have already been displayed for the main-drawable, I get the error immediatly, even before it gets to the pbuffer’s init().

Any further ideas?

Jan

Still stuck with this problem ???

Nobody out there who could give me a hint?

Jan

I threw together a very simple pbuffer test (i’ve never worked with the pbuffers with jogl so i’m not sure how write it is) but it seems to work fine. not sure if it will help, but i’ll post the code below

import net.java.games.jogl.;
import javax.swing.
;

public class PBufferTestApp implements GLEventListener
{
private GL gl;
private GLU glu;
private GLDrawable gldrawable;

  private int textureHandle;
  private JFrame frame;
  private final Animator animator;
  GLPbuffer pbuffer;
  
  private class PBufferEventListener implements GLEventListener {
        private float counter = 0;
        private float r=0;
        private float g=0;
        private float b=0;
        
        public void init(GLDrawable drawable) {
              System.out.println("+PBUFFER INIT");
        }
        public void display(GLDrawable drawable) {
              //System.out.println("+PBUFFER DISPLAY "+counter);
              r = (float) Math.sin( (counter % 100) * 0.01f * 2.0f *3.1415f) ;
              g = (float) Math.cos( (counter % 100) * 0.01f * 2.0f *3.1415f) ;
              b= (float) Math.tan( (counter % 100) * 0.01f * 2.0f *3.1415f) ;
              
              counter+=0.1f;
              
              //clamp from [0,1]
              r += 1.0f;
              r *= 0.5f;
              
              g += 1.0f;
              g *= 0.5f;
              
              b += 1.0f;
              b *= 0.5f;
              gl.glClearColor(r,g,b, 1);
              gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
              gl.glFlush();
        }
        
        public void reshape(GLDrawable drawable, int x, int y, int width, int height) 
        {
              System.out.println("+PBUFFER RESHAPE");
              float h = (float)height / (float)width;
            gl.glViewport(0,0,width,height);
            gl.glMatrixMode(GL.GL_PROJECTION);
  
              gl.glLoadIdentity();
              glu.gluOrtho2D(0,0,1,1);
           
              gl.glMatrixMode(GL.GL_MODELVIEW);
              gl.glLoadIdentity();    
        }
        public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
          
  }
        
  public static void main(String args[])
  {
        PBufferTestApp remoteRenderer = new PBufferTestApp();
  }
  
  PBufferTestApp()
  {
      frame = new JFrame("Bah");
      GLCapabilities attributes = new GLCapabilities();
      GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(attributes);
      
      canvas.addGLEventListener(this);

      frame.setFocusable(true);
      frame.getContentPane().add(canvas);

      animator = new Animator(canvas);
      frame.show();
        System.out.println("Initalized GUI");
        animator.start();
      frame.setSize(300, 300);
  }
  
  public void init(GLDrawable drawable) 
  {
        gl = drawable.getGL();
        glu = drawable.getGLU();
        
        this.gldrawable = drawable;
        System.err.println("INIT GL IS: " + gl.getClass().getName());


        if (gl.isExtensionAvailable("WGL_ARB_pbuffer"))
        {
              System.out.println("PBUFFER SUPPORTED");
        }
        else
        {
              System.out.println("PBUFFER NOT SUPPORT");
        }
      
      boolean supported = drawable.canCreateOffscreenDrawable();
      GLCapabilities caps = new GLCapabilities();
      caps.setOffscreenRenderToTexture(true);
      caps.setDoubleBuffered(false); 
      
      
      if(!supported) 
      {
            System.err.println("PBuffers not supported, shadow mapping not available");
            return;
      }

      
      pbuffer = drawable.createOffscreenDrawable(caps, 512, 512);
      pbuffer.addGLEventListener(new  PBufferEventListener());
      System.err.println("Pbuffer created"); 
      

        pbuffer.display();
        
        
      int temp[] = new int[1];
      gl.glGenTextures(1, temp);
      

      
      
      textureHandle =temp[0];
      
      gl.glBindTexture(GL.GL_TEXTURE_2D, textureHandle);
      pbuffer.bindTexture();
      gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
      gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);

      gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
      gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);

// gl.glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
}

public void reshape(GLDrawable drawable, int x, int y, int width, int height)
{
float h = (float)height / (float)width;
gl.glViewport(0,0,width,height);
System.out.println("WINDOW SIZE " + width + " " + width);
gl.glMatrixMode(GL.GL_PROJECTION);

  gl.glLoadIdentity();
  glu.gluPerspective(45.0f, 1.0f, 0.1f, 1000.0f);


  gl.glMatrixMode(GL.GL_MODELVIEW);
  gl.glLoadIdentity();    

}

public void display(GLDrawable drawable)
{
pbuffer.display();
gl.glClearColor(0,0,0,1);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

  gl.glPushMatrix();
  //loadCamera()

  
  gl.glEnable(GL.GL_TEXTURE_2D);
  gl.glBindTexture(GL.GL_TEXTURE_2D, textureHandle);
  pbuffer.bindTexture();
  gl.glBegin(GL.GL_QUADS);
  gl.glColor3f(1,1,1);
  gl.glTexCoord2f(0,0);
  gl.glVertex3i(-5, -5, -15);
  gl.glTexCoord2f(1,0);
  gl.glVertex3i( 5, -5, -15);
  gl.glTexCoord2f(1,1);
  gl.glVertex3i( 5,  5, -15);
  gl.glTexCoord2f(0,1);
  gl.glVertex3i(-5,  5, -15);
  gl.glEnd();
  gl.glDisable(GL.GL_TEXTURE_2D);
  
  
  gl.glPopMatrix();

}

public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged) {}

}

I just tried to run your program, but it threw me an exception.
This is the output:

Initalized GUI
INIT GL IS: net.java.games.jogl.impl.windows.WindowsGLImpl
PBUFFER SUPPORTED
Pbuffer created
net.java.games.jogl.GLException: Shouldn’t try to bind a pbuffer to a texture if
render-to-texture hasn’t been specified in its GLCapabilities
at net.java.games.jogl.impl.windows.WindowsPbufferGLContext.bindPbufferT
oTexture(WindowsPbufferGLContext.java:92)
at net.java.games.jogl.impl.GLPbufferImpl.bindTexture(GLPbufferImpl.java
:140)
[…]

What’s wrong?

"net.java.games.jogl.GLException: Shouldn’t try to bind a pbuffer to a texture if
render-to-texture hasn’t been specified in its GLCapabilities "

shouldn’t “setOffscreenRenderToTexture(true)” specify to enable render-to-texture??

Sorry I haven’t used pbuffer that much so i’m at a loss too. But the code seems to work on my machine here. The app just clears the offscreen buffer to some color. The onscreen buffer then takes the offscreen one and uses it as a texture. on a quad that is in the center of the screen.

Whats weirder is that when i set setOffscreenRenderToTexture(false) it still works. I’m running a mac with os x 10.3 and pixel buffers should be support through GL_APPLE_pixel_buffer?

This is a case of JOGL giving wrong error messages for the situation. Basically what has happened is the code is attempting to bind the pBuffer (using bindTexture()) before the texture has been initialised. What the code needs to do is protect against the bindTexture() call by first asking if it’s initialised - ie use GLPBuffer.isInitialized() method.

Just got home and tried the code. At work pbuffer code i posted worked fine without the “isInitialized” check but when i ran it a home i got the same extension using the isInitialized fixed the problem.

if (pbuffer.isInitialized())
{
pbuffer.bindTexture();
}

But this isn’t the problem jeickmann was having. I ran my pbuffer code through several hundred itterations and it seems stable. Maybe you could post source (if its not that much)?

Hi,

thanks for all the replies so far. The code is quite deeply inside a much bigger chunk, so it’s hard to get it out.
But somehow, after I put my Radeon 9800 back in (I was using the Geforce 3 for compatibility tests) it now runs like a charm.
Maybe the drivers where not installed properly, etc.
So for now, I’ll just play around and hopefully new new render_target-extension gets out soon, that should make render-to-texture that much easier.

Jan

I get this error:


Initalized GUI
INIT GL IS: net.java.games.jogl.impl.windows.WindowsGLImpl
PBUFFER SUPPORTED
Pbuffer created
net.java.games.jogl.GLException: pbuffer creation error: wglChoosePixelFormatARB
() failed

Is it a Matrox Parhelia driver problem ??

Drivers version 1.6.0.99 for win2k/xp

Mik

Has this ever been resolved? I also tested the code posted above and got a similar exception as others have:


Initalized GUI
INIT GL IS: net.java.games.jogl.impl.windows.WindowsGLImpl
PBUFFER SUPPORTED
Pbuffer created
net.java.games.jogl.GLException: Shouldn't try to bind a pbuffer to a texture if
 render-to-texture hasn't been specified in its GLCapabilities
        at net.java.games.jogl.impl.windows.WindowsPbufferGLContext.bindPbufferT
oTexture(WindowsPbufferGLContext.java:92)
        at net.java.games.jogl.impl.GLPbufferImpl.bindTexture(GLPbufferImpl.java
:152)
        at com.adamant.tuti.JOGLTest.init(Unknown Source)
        at net.java.games.jogl.impl.GLDrawableHelper.init(GLDrawableHelper.java:
68)
        at net.java.games.jogl.GLCanvas$InitAction.run(GLCanvas.java:191)
        at net.java.games.jogl.impl.windows.WindowsGLContext.makeCurrent(Windows
GLContext.java:160)
        at net.java.games.jogl.impl.windows.WindowsOnscreenGLContext.makeCurrent
(WindowsOnscreenGLContext.java:110)
        at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:232)
        at net.java.games.jogl.GLCanvas.displayImpl(GLCanvas.java:186)
        at net.java.games.jogl.GLCanvas.display(GLCanvas.java:74)
        at net.java.games.jogl.Animator$1.run(Animator.java:104)
        at java.lang.Thread.run(Unknown Source)