11011110110011011001100110011001000110011001100111010001011

December 23, 2006

Get suitable PixelFormat

Filed under: Uncategorized

in LWJGL binding, i choose pixelformat as follow:


    private static PixelFormat getPixelFormat()
    {
        if(m_pixelformat == null)
        {
            int sample = 4; //The number of samples to use in anti-aliasing
	
            while(true)
            {
                try
                {
                    PixelFormat pff = new PixelFormat(24, 0, 24, 0, sample);
                    Pbuffer pb = new Pbuffer( 1, 1, pff, null, null );
                    pb.destroy();
                    m_pixelformat = pff;
                    break;
                }
                catch(Exception e)
                {
                    sample >>= 1;
                }
            }
        }
        return m_pixelformat;
    }
	
    public void bindTarget(Object target)
    {
        ……
        m_pbuffer = new Pbuffer( width, height, getPixelFormat(), null, null );
        ……
    }

but new Pbuffer() may cost a few milliseconds delay depends on the graphics card.

on my laptop with ATI X700, it’s ok, fast enough. but, on the nVidia 6600, it costs much in this step…

 

so i call the getPixelFormat() in the constructor to prefetch the suitable pixelformat,

as expected, it makes the graphics binding more fast on nVidia 6600,

then i back to the ATI X700, … i catch a exception at new Pubffer() in bindTarget.

 

i get an answer from the LWJ sources, says that the Pbuffer class is thread-safe.

it’s ture that the prefetch and the binding are in different threads. But why it works on nVidia 6600?

Maybe there is some real reasons i didn’t catch. anyone knows??