You're right, my test wasn't correct.
I've made a new one (see below), and it doesn't work on any OSG version...
:/ It crash everywhere on glGetString because the makeCurrent failed on the
PixelBuffer.
I'll try to work on it tomorrow, any idea on where to look ? :) Are
PixelBuffer not working at all under Windows or just having troubles with
the CompileContext ?
Here is my new test :
class CustomOperation : public osg::Operation
{
public:
CustomOperation() : osg::Operation("CustomOperation", true) {}
void operator()(osg::Object *object)
{
osgViewer::Viewer *viewer = dynamic_cast<osgViewer::Viewer
*>(object);
// Do my task
if (viewer == NULL && _node == NULL)
{
osg::Image *image = osgDB::readImageFile("test.jpg");
osg::StateSet *stateset = new osg::StateSet();
osg::Texture2D *texture = new osg::Texture2D();
texture->setImage(image);
texture->setUnRefImageDataAfterApply(true);
texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT5_COMPRESSION);
stateset->setTextureAttributeAndModes(0, texture,
osg::StateAttribute::ON);
stateset->compileGLObjects(*osg::GraphicsContext::getCompileContext(0)->getState());
if (texture->getImage() == NULL)
{
osg::notify(osg::NOTICE) << "Image successfully applied !"
<< std::endl;
}
_node = createTexturedQuad(osg::Vec2(), 100, 100, stateset);
}
// Update the scene
else if (_node != NULL &&
viewer->getSceneData()->asGroup()->getNumChildren() == 0)
{
osg::notify(osg::NOTICE) << "Node merged to the graph !" <<
std::endl;
viewer->getSceneData()->asGroup()->addChild(_node.get());
}
}
private:
osg::ref_ptr<osg::Node> _node;
};
int main(int ac, char **av)
{
osgViewer::Viewer viewer;
viewer.setThreadingModel(osgViewer::ViewerBase::SingleThreaded);
osg::DisplaySettings::instance()->setCompileContextsHint(true);
osg::DisplaySettings::instance()->setMaxNumberOfGraphicsContexts(1);
viewer.setUpViewInWindow(100, 100, 800, 600);
viewer.setCameraManipulator(new osgGA::TrackballManipulator());
viewer.setSceneData(new osg::Group());
viewer.realize();
if (osg::GraphicsContext::getCompileContext(0) != NULL &&
osg::GraphicsContext::getCompileContext(0)->getGraphicsThread() !=
NULL)
{
CustomOperation *operation = new CustomOperation();
osg::GraphicsContext::getCompileContext(0)->getGraphicsThread()->add(operation);
viewer.addUpdateOperation(operation);
osg::notify(osg::NOTICE) << "Operation successfully added !" <<
std::endl;
}
viewer.run();
}
On Mon, Aug 4, 2008 at 6:22 PM, Robert Osfield <[EMAIL PROTECTED]>wrote:
> Hi Serge,
>
> The code looks to be a bit suspect to me. The problem is that the
> CompileContextHint will tell osgViewer to try and create a compile
> context for each window it creates, and then start a thread for each
> of these compile context, this thread will have the a makeCurrent()
> internally and then assume that this thread has the context.
> However, with your code you go ahead a do a
> makeCurrent()/releaseContext() in the main thread so that the compile
> contexts graphics thread will no longer have the context current and
> any further OpenGL calls in that thread will fail. The fact that
> this ever worked is surprising...
>
> If you do want to do a precompile in the way you are doing it'd be
> best to manually create the compile context, use it, then start the
> thread on it, or just then discard the context.
>
> Robert.
>
> On Mon, Aug 4, 2008 at 4:31 PM, Serge Lages <[EMAIL PROTECTED]> wrote:
> > Hi all,
> >
> > I've made some investigations. First of all, I've tested several OSG
> > versions with the following code :
> >
> > osgViewer::Viewer viewer;
> >
> > viewer.setThreadingModel(osgViewer::ViewerBase::SingleThreaded);
> > osg::DisplaySettings::instance()->setCompileContextsHint(true);
> > osg::DisplaySettings::instance()->setMaxNumberOfGraphicsContexts(1);
> > viewer.setUpViewInWindow(100, 100, 800, 600);
> > viewer.setCameraManipulator(new osgGA::TrackballManipulator());
> > viewer.realize();
> > if (osg::GraphicsContext::getCompileContext(0) != NULL)
> > {
> > osg::Image *image = osgDB::readImageFile("test.jpg");
> > osg::StateSet *stateset = new osg::StateSet();
> > osg::Texture2D *texture = new osg::Texture2D();
> >
> > texture->setImage(image);
> > texture->setUnRefImageDataAfterApply(true);
> >
> > texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT5_COMPRESSION);
> > stateset->setTextureAttributeAndModes(0, texture,
> > osg::StateAttribute::ON);
> >
> > osg::GraphicsContext::getCompileContext(0)->makeCurrent();
> >
> >
> stateset->compileGLObjects(*osg::GraphicsContext::getCompileContext(0)->getState());
> > osg::GraphicsContext::getCompileContext(0)->releaseContext();
> > if (texture->getImage() == NULL)
> > {
> > osg::notify(osg::NOTICE) << "Texture successfully applied !"
> <<
> > std::endl;
> > }
> > viewer.setSceneData(createTexturedQuad(0, 0, 100, 100,
> stateset));
> > }
> > viewer.run();
> >
> > (the createTexturedQuad function just returns a geode with a quad and the
> > texture applied on it).
> >
> > Here are my results :
> >
> > - OSG 2.2 and OSG 2.4 : it seems to work, I have the "Texture
> successfully
> > applied !" message and my quad have the texture on it. Note : if I don't
> > specify the setMaxNumberOfGraphicsContexts, my image is not unref but it
> > still works.
> >
> > - Latest SVN : If setMaxNumberOfGraphicsContexts is not set to 1, it
> crash.
> > If it's set, I got the "Texture successfully applied !" message but my
> quad
> > has no texture applied on it.
> >
> > Robert, have you any hint on where to look next ? You told it works on
> > Linux, so do you think it will be usefull to start looking at the
> > modifications on the Win32 implementation of osgViewer since OSG 2.4 ?
> >
> > On Mon, Aug 4, 2008 at 2:14 PM, Serge Lages <[EMAIL PROTECTED]>
> wrote:
> >>
> >> Some time ago it worked for me (the same time when we were able to make
> >> glGetString calls outside a draw callbacks).
> >>
> >> I'll try to make some tests this afternoon and let you know how it goes.
> >>
> >> On Mon, Aug 4, 2008 at 1:56 PM, Glenn Waldron <[EMAIL PROTECTED]>
> wrote:
> >>>
> >>> FWIW I have never been able to get compile contexts to work on Windows
> >>> since the feature was introduced. So I believe the issue goes back a
> ways
> >>> (i.e., is not particular to 2.6).
> >>>
> >>> HTH- Glenn
> >>>
> >>> On Mon, Aug 4, 2008 at 6:17 AM, Adrian Egli OpenSceneGraph (3D)
> >>> <[EMAIL PROTECTED]> wrote:
> >>>>
> >>>> Hi Robert,
> >>>>
> >>>> i just come tested under windows vista, same as problem as Serge
> >>>> reported :-(
> >>>>
> >>>> PixelBufferWin32::makeCurrentImplementation, wglMakeCurrent error: The
> >>>> requested resource is in use.
> >>>>
> >>>>
> >>>> 2008/8/4 Robert Osfield <[EMAIL PROTECTED]>
> >>>>>
> >>>>> Hi Serge,
> >>>>>
> >>>>> I've been doing testing the compile context support using osgviewer
> on
> >>>>> paged database I have and it all works without error so far. I'm
> >>>>> using Kubuntu 7.10 and 7800GT. I enable compile contexts via:
> >>>>>
> >>>>> export OSG_COMPILE_CONTEXTS=ON
> >>>>> osgviewer pagedmodel.ive --SingleThreaded
> >>>>>
> >>>>> I tried the whole range of threading models without incident.
> >>>>>
> >>>>> So this problem looks to be a Windows issue. My guess is that the
> >>>>> error report of about a problem with make current is what is the
> early
> >>>>> warning of something not working quite right. I'm afraid I can't do
> >>>>> much to investigate this myself though as I have no Windows box to
> >>>>> test against.
> >>>>>
> >>>>> Robert.
> >>>>>
> >>>>>
> >>>>> On Thu, Jul 31, 2008 at 9:44 AM, Serge Lages <[EMAIL PROTECTED]>
> >>>>> wrote:
> >>>>> > Hi all,
> >>>>> >
> >>>>> > I am currently trying to use CompileContexts on my application, but
> >>>>> > just
> >>>>> > doing this :
> >>>>> >
> >>>>> > osgViewer::Viewer viewer;
> >>>>> >
> >>>>> > viewer.setThreadingModel(osgViewer::ViewerBase::SingleThreaded);
> >>>>> > osg::DisplaySettings::instance()->setCompileContextsHint(true);
> >>>>> > return (viewer.run());
> >>>>> >
> >>>>> > The application crash into glExtensions.cpp line 46 (trying to get
> >>>>> > the GL
> >>>>> > version with glGetString( GL_VERSION )).
> >>>>> > Before the crash I have this error message :
> >>>>> >
> >>>>> > PixelBufferWin32::makeCurrentImplementation, wglMakeCurrent error:
> La
> >>>>> > ressource demandé est en cours d'utilisation.
> >>>>> > or in english something like that :
> >>>>> > PixelBufferWin32::makeCurrentImplementation, wglMakeCurrent error:
> >>>>> > the
> >>>>> > wanted resource is already being used.
> >>>>> >
> >>>>> > Any idea on what's happening ?
> >>>>> > My system : WinXP with SVN head, VS 8 Express, NVIDIA 8600GTS
> >>>>> >
> >>>>> > Thanks in advance !
> >>>>> >
> >>>>> > --
> >>>>> > Serge Lages
> >>>>> > http://www.tharsis-software.com
> >>>>> >
> >>>>> > _______________________________________________
> >>>>> > osg-users mailing list
> >>>>> > [email protected]
> >>>>> >
> >>>>> >
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >>>>> >
> >>>>> >
> >>>>> _______________________________________________
> >>>>> osg-users mailing list
> >>>>> [email protected]
> >>>>>
> >>>>>
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >>>>
> >>>>
> >>>>
> >>>> --
> >>>> ********************************************
> >>>> Adrian Egli
> >>>>
> >>>> _______________________________________________
> >>>> osg-users mailing list
> >>>> [email protected]
> >>>>
> >>>>
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >>>>
> >>>
> >>>
> >>>
> >>> --
> >>> Glenn Waldron : Pelican Mapping : http://pelicanmapping.com :
> >>> +1.703.652.4791
> >>>
> >>> _______________________________________________
> >>> osg-users mailing list
> >>> [email protected]
> >>>
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >>>
> >>
> >>
> >>
> >> --
> >> Serge Lages
> >> http://www.tharsis-software.com
> >
> >
> >
> > --
> > Serge Lages
> > http://www.tharsis-software.com
> >
> > _______________________________________________
> > osg-users mailing list
> > [email protected]
> >
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >
> >
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
--
Serge Lages
http://www.tharsis-software.com
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org