Hi,

I have wrote a framework that handle hierachic occlusion culling. It work well 
but because of lack of performance of waiting asynchronous occlusion query I 
wrote a OpenThread::Thread that handle all occlusion query

Code:
class ThreadOccQueries :
        public OpenThreads::Thread , public osg::Referenced
    {
    private:
        /// Constructor
        ThreadOccQueries();    
        osg::Drawable::Extensions* ext;

    public:
        /// The ThreadOccQueries is a singleton
        static ThreadOccQueries &Get();

        //setup extension context
        void setupExtension(osg::Drawable::Extensions* sext){ext=sext;}

        void addOccRequest(myTestResult i){
            _mutexin.lock();
            mapin.push_back(i);
            _mutexin.unlock();
        }

        int getResult(unsigned int rqt){
            int ret=-1;
            _mutexout.lock();
            if(mapout[rqt]._active){
                //back to default
                mapout[rqt]._active=false;
                ret=mapout[rqt]._numPixels;
            }
            _mutexout.unlock();
            return ret;
        }

        /// does the ThreadOccQueries run  ?
        bool isRunning() { 
            bool t; _mutex.lock();
        t= m_isRunning;
        _mutex.unlock();
        return t;
        }



    protected:
       //in occlusion request
        std::list<myTestResult> mapin;

//out result
        std::vector<myTestResult> mapout;

        /// main loop, handle events and trigger callback
        virtual void run();
        /// Destructor
        virtual ~ThreadOccQueries();
#ifndef SAFE_SINGLETON
        /// store the instance
        static osg::ref_ptr<ThreadOccQueries> sInstance;

        /// protecting access on Get() will avoid multiple instance creation in 
xthreaded app
        static OpenThreads::Mutex sMutex;
#endif
        OpenThreads::Mutex _mutexin,_mutexout,_mutex;
        bool m_isRunning;
    };

}
#endif




and i the run() method I wrote 

Code:


void ThreadOccQueries::run()
{
        _mutex.lock();
        m_isRunning=true;
        _mutex.unlock();

        while(!mapin.empty()){
                        this->microSleep(20000);
                //get the next request
                _mutexin.lock();

                myTestResult rqt;
                rqt=(mapin.back());
                        mapin.pop_back();
                        _mutexin.unlock();

                GLint ready( 0 );
                rqt._ext->glGetQueryObjectiv( rqt._id, 
GL_QUERY_RESULT_AVAILABLE_ARB, &ready );
                if(ready){
                        nbdone++;
                        rqt._ext->glGetQueryObjectuiv(rqt._id, 
GL_QUERY_RESULT_ARB, &(rqt._numPixels) );

                        //change default
                        rqt._active=true;
                        _mutexout.lock();
                        mapout[rqt._id]=rqt;
                        _mutexout.unlock();
                
                }else{
                        _mutexin.lock();
                        mapin.push_back(rqt);
                        _mutexin.unlock();
                }
                
        }
        _mutex.lock();
        m_isRunning=false;
        _mutex.unlock();




}





I debug the program and all ext and queryid are good but the method
                rqt._ext->glGetQueryObjectiv( rqt._id, 
GL_QUERY_RESULT_AVAILABLE_ARB, &ready );
never return true in ready;

What Am I doing wrong?

To be sure to retrieve valid extensions  I intialize rqt._ext at each occlusion 
query in an osg::Geometry::drawimplementation(..) method.
Is there a better way to getExtension before the draw ?

Thank you!

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=32470#32470





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to