Re: [osg-users] DrawCallback only once

2010-01-11 Thread Robert Osfield
Hi Dominc,

The best way to do a single GL test at startup is to attach a custom
osg::GraphicsOperation as a RealizeOperation to the viewer, and this
gets called once the viewer's graphics contexts get realized.

Have a look at the osgcatch, osgshaderterrrain and osgvolume examples
to see examples of the above in action.

Robert.

On Fri, Jan 8, 2010 at 8:50 PM, Dominic Stalder
dominic.stal...@bluewin.ch wrote:
 Hi there

 I would like to read the OpenGL extensions with isGLExtensionSupported(),
 but for this I need a draw context. I registred a DrawCallback Class, see
 below. I need to call the operator() method only once, but because this
 method is const, I cannot write to the member variable bool first. How can I
 resolve this problem?

        class GameViewOSGDrawCallback : public osg::Camera::DrawCallback
        {
        private:
            GameViewOSG *parent;
            bool first;

        public:
            GameViewOSGDrawCallback(GameViewOSG* parent=0);

            virtual void operator()(const osg::Camera) const;
        };

 Thanks a lot
 Dominic
 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] DrawCallback only once

2010-01-11 Thread Dominic Stalder

Hi Robert

thanks a lot, at the moment it works fine the way I made it. But I will 
try this solution as soon as possible.


Am 11.01.10 11:41, schrieb Robert Osfield:

The best way to do a single GL test at startup is to attach a custom
osg::GraphicsOperation as a RealizeOperation to the viewer, and this
gets called once the viewer's graphics contexts get realized.

Have a look at the osgcatch, osgshaderterrrain and osgvolume examples
to see examples of the above in action.
   


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] DrawCallback only once

2010-01-09 Thread Dominic Stalder

Hi Dj and Tim

thanks for the answers, I made a little hack, but it works for me ;-) In 
the operator() method I just set the pre draw callback of the camera to 
zero, so the method never gets called again later.


void GameViewOSG::GameViewOSGDrawCallback::operator()(const Camera) const
{
parent-osgCamera-setPreDrawCallback(NULL);
}

Regards
Dominic

Am 09.01.10 00:55, schrieb Tim Moore:



On Fri, Jan 8, 2010 at 9:50 PM, Dominic Stalder 
dominic.stal...@bluewin.ch mailto:dominic.stal...@bluewin.ch wrote:


Hi there

I would like to read the OpenGL extensions with
isGLExtensionSupported(), but for this I need a draw context. I
registred a DrawCallback Class, see below. I need to call the
operator() method only once, but because this method is const, I
cannot write to the member variable bool first. How can I resolve
this problem?

   class GameViewOSGDrawCallback : public
osg::Camera::DrawCallback
   {
   private:
   GameViewOSG *parent;
   bool first;

   public:
   GameViewOSGDrawCallback(GameViewOSG* parent=0);

   virtual void operator()(const osg::Camera) const;
   };

You might look at using an Operation on the graphics context, which 
has a one-shot mode that is more convenient and efficient than a 
boolean in a callback. Take a look at the Operation class in 
osg/OperationThread and osg::GraphicsContext::add(Operation*).


Tim


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
   


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] DrawCallback only once

2010-01-08 Thread Dominic Stalder

Hi there

I would like to read the OpenGL extensions with 
isGLExtensionSupported(), but for this I need a draw context. I 
registred a DrawCallback Class, see below. I need to call the operator() 
method only once, but because this method is const, I cannot write to 
the member variable bool first. How can I resolve this problem?


class GameViewOSGDrawCallback : public osg::Camera::DrawCallback
{
private:
GameViewOSG *parent;
bool first;

public:
GameViewOSGDrawCallback(GameViewOSG* parent=0);

virtual void operator()(const osg::Camera) const;
};

Thanks a lot
Dominic
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] DrawCallback only once

2010-01-08 Thread D.J. Caldwell
Hi, Dominic.

I'm not sure this method is the best option for what you want, but I
don't have any ready alternatives myself, so I'll just answer your
question and move on.

I would recommend reading the following FAQ:

http://www.parashift.com/c++-faq-lite/const-correctness.html

In that context, I might recommend changing your declaration:

// begin code
bool first;
// end code

to this:

// begin code
mutable bool first;
// end code

In the event that your compiler doesn't support keyword mutable, you
can fake it with a member pointer that you have to initialize in your
constructor and cleanup in your destructor, but that is a little
clunky, and I would avoid it if I could.  You would change this:

// begin code
bool first;
// end code

to this:

// begin code
bool* first;
// end code

and then do the appropriate initialization and cleanup.

I hope this helps...

D.J.


On Fri, Jan 8, 2010 at 3:50 PM, Dominic Stalder
dominic.stal...@bluewin.ch wrote:
 Hi there

 I would like to read the OpenGL extensions with isGLExtensionSupported(),
 but for this I need a draw context. I registred a DrawCallback Class, see
 below. I need to call the operator() method only once, but because this
 method is const, I cannot write to the member variable bool first. How can I
 resolve this problem?

        class GameViewOSGDrawCallback : public osg::Camera::DrawCallback
        {
        private:
            GameViewOSG *parent;
            bool first;

        public:
            GameViewOSGDrawCallback(GameViewOSG* parent=0);

            virtual void operator()(const osg::Camera) const;
        };

 Thanks a lot
 Dominic
 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] DrawCallback only once

2010-01-08 Thread Tim Moore
On Fri, Jan 8, 2010 at 9:50 PM, Dominic Stalder
dominic.stal...@bluewin.chwrote:

 Hi there

 I would like to read the OpenGL extensions with isGLExtensionSupported(),
 but for this I need a draw context. I registred a DrawCallback Class, see
 below. I need to call the operator() method only once, but because this
 method is const, I cannot write to the member variable bool first. How can I
 resolve this problem?

class GameViewOSGDrawCallback : public osg::Camera::DrawCallback
{
private:
GameViewOSG *parent;
bool first;

public:
GameViewOSGDrawCallback(GameViewOSG* parent=0);

virtual void operator()(const osg::Camera) const;
};

 You might look at using an Operation on the graphics context, which has a
one-shot mode that is more convenient and efficient than a boolean in a
callback. Take a look at the Operation class in osg/OperationThread and
osg::GraphicsContext::add(Operation*).

Tim
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org