Re: [osg-users] Hidden Viewer

2010-12-02 Thread Oliver Neumann
Hello Jean-Sébastien,

Thanks for your reply, 


Skylark wrote:
 Hello Oliver,
 Hmmm, seems you are tripping over something else on your hardware... I 
 just remembered you had mentioned in another post that setting the 
 threading model to SingleThreaded didn't work for you either, but in my 
 case it did... So that indicates something else is going on for you.
 


The code works for me as well if I set the threading model to SingleThreaded! I 
think it is the osg lib, as I have used the official build libs and no custom 
builds. I will update the nVidia driver but I think the difference between our 
two systems is the osg version. I will try to get the current osg trunk to 
work. In the mean time, could you test out your altered pbuffertest.cpp with 
the offical 2.8.3 libs (VS2005) to verify if this is the problem? You can find 
them here: 
http://www.openscenegraph.org/downloads/stable_releases/OpenSceneGraph-2.8.3/binaries/Windows/VisualStudio8/.

@ Robert:
If I get the dev build to work, I will check the two solutions you mentioned.

Greetings,
Oliver

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





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


Re: [osg-users] Hidden Viewer

2010-12-02 Thread Robert Osfield
Hi All,

I have now checked in the removal of the makeCurrentImplememtation()
from the PixelBufferWin32.cpp's realizeImplementation() method, rather
the go for the earlier suggestion of adding a releaseContext().

I asked J-S to test this out the removal of the
makeCurrentImplementation(), using both osgscreencapture and
osgprerender --pbuffer yesterday and he reported that it worked fine
so I have checked the change in.

Could members of the community do an svn update and do the tests again
to see how things fair.

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


Re: [osg-users] Hidden Viewer

2010-12-02 Thread Jean-Sébastien Guay

Hello Oliver,


but I think the difference between our two systems is the osg version. I will 
try to get the current osg trunk to work. In the mean time, could you test out 
your altered pbuffertest.cpp with the offical 2.8.3 libs (VS2005) to verify if 
this is the problem? You can find them here: 
http://www.openscenegraph.org/downloads/stable_releases/OpenSceneGraph-2.8.3/binaries/Windows/VisualStudio8/.


The fix has been checked in to SVN so if you can try with the SVN trunk 
it would help eliminate another possibility.


But the viewer.stopThreading(), gc-releaseContext(), 
viewer.startThreading() workaround I posted yesterday worked for me on 
OSG 2.8.3 (our own applications use that version so I was able to test 
pbuffertest with it easily). That's why I say there must be something 
else going on with your hardware.


Getting OSG built is not too hard, and you'll be able to build release 
and debug, so once you have SVN trunk built and verified if the fix 
works for you, you'll also be able to debug into the OSG source (put 
breakpoints and trace through the execution) as I described in my 
previous post.


Hope this helps,

J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Hidden Viewer

2010-12-02 Thread Oliver Neumann
Hi,

I have successfully build the current svn trunk version:
-Just before Robert checked in the Bugfix:
As before with 2.8.3 I get

Code:

PixelBufferWin32::makeCurrentImplementation, wglMakeCurrent error: Die angeforde
rte Ressource wird bereits verwendet.

Frame : 0
Test completed!!!



Now I think I understand that J-S meant with pbuffertest example works that 
the application is not crashing and terminates successfully. Sorry I think I 
misunderstood you, seeing the initial error was enough for my bug senses to cry 
out ;)

After updating to the latest version (including the bug fix), the error message 
has vanished! I removed J-S bug fix in pbuffertest itself and lo and behold: 
The errors are gone too!

For the time being I will build 2.8.3 with the single change to be compatible 
with the rest of my application and work with that. 

So thanks to you all for your great help, I really appreciate it!

On small last thing (not related to the bugs but to the hidden viewer approach):

With the pbuffer active, my WindowCaptureCallback is not called anymore. I used 
osgscreencapture to create an image grabber derived from WindowCaptureCallback 
but it looks like I have to use another approach with pbuffer (as done in the 
example code). I was curious if I could activate the WindowCaptureCallback even 
though using a pbuffer so that I use only one code for both cases?

Greetings,
Oliver



Cheers,
Oliver

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





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


Re: [osg-users] Hidden Viewer

2010-12-02 Thread Jean-Sébastien Guay

Hello Oliver,


With the pbuffer active, my WindowCaptureCallback is not called anymore. I used 
osgscreencapture to create an image grabber derived from WindowCaptureCallback 
but it looks like I have to use another approach with pbuffer (as done in the 
example code). I was curious if I could activate the WindowCaptureCallback even 
though using a pbuffer so that I use only one code for both cases?


The ScreenCaptureHandler in OSG 2.8.3 only looped through 
GraphicsWindow-derived contexts, which means contexts that are in a 
window. A pbuffer is derived from GraphicsContext, i.e. a context that 
might have a window but not necessarily (and indeed a pbuffer is meant 
not to spawn a window).


I submitted a change to this (in November 2009, so before the 
OpenSceneGraph-2.9.6 tag... geez it's been a while since the last trunk 
release ;-) ) so in the SVN version your callback should be called even 
for pbuffers. If you want this to work for pbuffers in 2.8.3, you can 
copy the code from SVN. It's in include/osgViewer/ViewerEventHandlers 
and src/osgViewer/ScreenCaptureHandler.cpp, the relevant method is 
called findAppropriateCameraForCallback(..).


I have made a few other similar submissions over the past year or so, 
since we've been using pbuffers for some things too. For example in the 
SVN version the StatsHandler will be displayed even in a pbuffer if 
there's no GraphicsWindow at all.


Hope this helps,

J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Hidden Viewer

2010-12-02 Thread Oliver Neumann
Hi J-S,

Great! You solved my problems before they appeared ;), I will try to get it to 
work in 2.8.3. Thank you!

Cheers,
Oliver

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





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


Re: [osg-users] Hidden Viewer

2010-12-02 Thread Jean-Sébastien Guay

Hi Oliver,


Great! You solved my problems before they appeared ;), I will try to get it to 
work in 2.8.3. Thank you!


Hah, I'm just happy because it proves that what I wanted to do is not so 
weird as it appeared to be when I did it :-)


Glad I could help,

J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Hidden Viewer [solved]

2010-12-02 Thread Oliver Neumann
Hi Jean-Sebastien,

I included the changes in my 2.8.3 build and it is now working as I had 
originally intended. I removed the mentioned one line in 
osgViewer::PixelBufferWin32 and changed the code of my own ScreenCaptureHandler 
derivative just like you did (use context and not windows).

So thanks again to all of you, I changed the title to [solved].

Cheers,
Oliver

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





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


Re: [osg-users] Hidden Viewer

2010-12-01 Thread Oliver Neumann
Hi Juan,

Thanks for your insight,

 
 As Robert already answered, it should be possible.
 The best explanation that I have for your problem is that some thread 
 fails to do wglMakeCurrent (after that call fails anything that follows 
 is just garbage) beacuse another thread is holding the context 
 (according to 
 http://www.opengl.org/sdk/docs/man/xhtml/glXMakeCurrent.xml, that's a 
 programming error in GLX, so I guess the same applies in WGL). All 
 OpenGL calls from that thread are going to fail after that.
 
 If the sample code that I sent you also complains with the error message:
 PixelBufferWin32::makeCurrentImplementation, wglMakeCurrent error: Die 
 angeforderte Ressource wird bereits verwendet
 then, there is a threading error somewhere. However I can't spot it the 
 code I sent you and I'm afraid that's beyond my knowledge of OSG's guts. 
 Robert may be more insightful here.
 
 You can try commenting the line that changes the threading model and 
 replacing frame() by run() to see if it also fails.
 


It results in the same error if I comment out the setThreadingModel call, no 
matter if I use frame() or run(). Btw, I'm using osg v2.8.3.
I compile Juan's code using the official libraries from 
http://www.openscenegraph.org/downloads/stable_releases/OpenSceneGraph-2.8.3/binaries/Windows/VisualStudio8/
and as Robert said, it's working thread safe in a standard graphics window.

If Robert is still reading this thread, is this a known issue with a solution 
or do I have to write a bug report?

Greetings,
Oliver

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





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


Re: [osg-users] Hidden Viewer

2010-12-01 Thread Robert Osfield
Hi Oliver,

On Wed, Dec 1, 2010 at 8:57 AM, Oliver Neumann z0...@yahoo.com wrote:
 It results in the same error if I comment out the setThreadingModel call, no 
 matter if I use frame() or run(). Btw, I'm using osg v2.8.3.
 I compile Juan's code using the official libraries from 
 http://www.openscenegraph.org/downloads/stable_releases/OpenSceneGraph-2.8.3/binaries/Windows/VisualStudio8/
 and as Robert said, it's working thread safe in a standard graphics window.

I would suggest that perhaps it might appear to be working safe with a
standard graphics window, but could still be thread unsafe, you just
haven't hit the problem timing.

 If Robert is still reading this thread, is this a known issue with a solution 
 or do I have to write a bug report?

Well the problem is most likely in the way you are using the OSG, or
perhaps using an OpenGL driver that doesn't support pbuffers, if you
want to write a bug report for your own app for you own purposes then
fine.  As things stand it doesn't sound likely that it's an OSG bug.

If you really do think you've come across an OSG bug then the thing to
do is to write a small example, or modify one of the existing OSG
examples to reproduce the problem then post this.  Then others can
test the problem out first hand.  It could still be a bug in the what
you are trying to do, but others will be able to spot this and point
you at the problem.

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


Re: [osg-users] Hidden Viewer

2010-12-01 Thread Juan Hernando

Hi Robert,

If Robert is still reading this thread, is this a known issue with a solution 
or do I have to write a bug report?


Well the problem is most likely in the way you are using the OSG, or
perhaps using an OpenGL driver that doesn't support pbuffers, if you
want to write a bug report for your own app for you own purposes then
fine.  As things stand it doesn't sound likely that it's an OSG bug.
I agree that a probable cause is that his driver or hardware does not 
support pbuffers. However, what is a bit odd to me is this message in 
his trace:
PixelBufferWin32::makeCurrentImplementation, wglMakeCurrent error: Die 
angeforderte Ressource wird bereits verwendet.
In english (using an on-line german to english translator) the message 
is: The requested resource is already in use which seems to be related 
to a threading issue.



If you really do think you've come across an OSG bug then the thing to
do is to write a small example, or modify one of the existing OSG
examples to reproduce the problem then post this.  Then others can
test the problem out first hand.  It could still be a bug in the what
you are trying to do, but others will be able to spot this and point
you at the problem.

As Oliver said, he has the same problem using the very simple an 
self-contained example program that I sent him in my second mail. I 
can't figure out where the problem is, overall considering that this 
type of code hasn't ever failed to me (now I'm curious to know if I've 
being doing something wrong for a long time). The program is very short, 
so you may want to take a look.
For your convenience, I reproduce the code here with the modifications 
that reproduce his problem :


#include osg/Geode
#include osg/ShapeDrawable
#include osgViewer/Viewer
#include osgGA/TrackballManipulator
#include osgDB/WriteFile

int main(int argc, char *argv[])
{
osg::ArgumentParser args(argc, argv);
osgViewer::Viewer viewer(args);
osg::Camera *camera = viewer.getCamera();

osg::ref_ptrosg::GraphicsContext::Traits traits = new
osg::GraphicsContext::Traits;
traits-width = 512;
traits-height = 512;
traits-pbuffer = true;
traits-readDISPLAY();
osg::GraphicsContext *gc =
osg::GraphicsContext::createGraphicsContext(traits.get());
camera-setGraphicsContext(gc);
camera-setDrawBuffer(GL_FRONT);
camera-setProjectionMatrixAsPerspective(22, 1, 0.1, 1000);
camera-setViewport(new osg::Viewport(0, 0, 512, 512));

osg::Geode *scene = new osg::Geode();
osg::Shape *sphere = new osg::Sphere(osg::Vec3(), 1);
scene-addDrawable(new osg::ShapeDrawable(sphere));
viewer.setSceneData(scene);

viewer.setCameraManipulator(new osgGA::TrackballManipulator());

osg::Image *image = new osg::Image();
camera-attach(osg::Camera::COLOR_BUFFER0, image);

viewer.realize();
viewer.run();
}

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


Re: [osg-users] Hidden Viewer

2010-12-01 Thread Juan Hernando



I have tested under Kubuntu 9.04 + ATI 4670 and the driver doesn't
support pbuffer but the fallback opens up a full screen window and it
works fine.

I have also tested under Kubuntu 10.10 + ATI 4670 and the driver does
support pbuffer and the app runs correctly.

In Ubuntu 9.10 with a Nvidia GTX 280 with driver version 190.53 it works 
fine.


Oliver, maybe you should try a low level pbuffer example to discard it 
as the problem. First, you can use an OpenGL extension checker and 
search for WGL_ARB_pbuffer, I think GPU-Z does the job.


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


Re: [osg-users] Hidden Viewer

2010-12-01 Thread Oliver Neumann
Hi Juan and Robert,

Thanks for the help, I compiled the pbuffertest code, I had to add this to the 
header section to make it work (i'm using osg 2.8.3)


Code:

#include osg/Notify
#define OSG_NOTICE OSG_NOTIFY_1(osg::NOTICE)
#define OSG_NOTIFY_1(level) if (osg::isNotifyEnabled(level)) osg::notify(level)




pbuffertest -w 
works and makes 100 frames (the viewer window is shortly visible).

pbuffertest -f 1
doesn't work and produces the known error:


Code:

Frame : PixelBufferWin32::makeCurrentImplementation, wglMakeCurrent error: 0Die
angeforderte Ressource wird bereits verwendet.

Test Ecrormoprl:e Otpeedn.
GL version test failed, requires valid graphics context.





(btw, exchanging the OSG_NOTICE with printf gives the correct Test 
completed.\nError: OpenGL version test failed, requires valid graphics 
context. instead of Test Ecrormoprl:e Otpeedn for pbuffertest.exe -f 1)

I installed GPU-Z but couldn't find the OpenGL Extension Information. I 
installed the OpenGL Extensions Viewer 
(http://www.realtech-vr.com/glview/download.html). It confirms that among others

WGL_ARB_pbuffer
WGL_ARB_pixel_format
WGL_ARB_pixel_format

are supported by my nVidia Quadro FX 580 (see screenshot).
Because it sounded like a possible fix, I defined the environment variable
OSG_WIN32_NV_MULTIMON_MULTITHREAD_WORKAROUND to ON, but that changed nothing.

As far as my little knowledge goes, I think that the bug is in the osg code. 

Cheers,
Oliver

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




Attachments: 
http://forum.openscenegraph.org//files/clip1_203.jpg


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


Re: [osg-users] Hidden Viewer

2010-12-01 Thread Juan Hernando

WGL_ARB_pbuffer
WGL_ARB_pixel_format
WGL_ARB_pixel_format

are supported by my nVidia Quadro FX 580 (see screenshot).
Because it sounded like a possible fix, I defined the environment variable
OSG_WIN32_NV_MULTIMON_MULTITHREAD_WORKAROUND to ON, but that changed nothing.

As far as my little knowledge goes, I think that the bug is in the osg code. 


The first step to discard a driver bug should be testing a pbuffer 
example that only uses OpenGL and WGL.


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


Re: [osg-users] Hidden Viewer

2010-12-01 Thread Jean-Sébastien Guay

Hello Robert,


I tested your example and adapted it a little to add command line
options, and a CMakeLists.txt file to compile it.  Zip file attached
so that others can test it out easily.


You need to add ${OSGGA_LIBRARY} to the TARGET_LINK_LIBRARIES line. Also 
it was missing some things to make it link to the debug libraries when 
compiling in debug, which is required on Windows. Here is the changed 
file if anyone else wants to test on Windows.



To test run with a pbuffer if supported, with the app running for 100 frames:

   pbuffertest

If pbuffer isn't supported by your driver/hardware the OSG will
fallback to using a normal graphics window in the Viewer::realize()
method.


On my system it gives the following output:

Frame : 0
PixelBufferWin32::makeCurrentImplementation, wglMakeCurrent error: The 
requested resource is in use.


Warning: detected OpenGL error 'invalid operation' at Before 
Renderer::compile
Warning: detected OpenGL error 'invalid operation' at After 
Renderer::compile

Frame : 1
Frame : 1

and then it crashes.

I also tried to compile against OSG 2.8.3 (replacing OSG_NOTICE with 
osg::notify(osg::NOTICE) ), there I get:


Frame : 0
PixelBufferWin32::makeCurrentImplementation, wglMakeCurrent error: The 
requested

 resource is in use.

Frame : E1r
ror: OpenGL version test failed, requires valid graphics context.

This sounds very similar to what Olivier is getting.

I have just tested the osgscreencapture example on svn trunk, with the 
command:


osgscreencapture.exe axes.osg --pbuffer-only 640 480

as given in another thread, and it gives the same result. I remember 
this example working in the not too distant past, so it may be that 
something has been broken in nVidia's Windows drivers. I am using the 
most recent version (260.99), what version are you using Olivier?


With the -w argument it works fine (with a window coming up on the 
screen of course).


So I'll investigate a bit more as to why pbuffer is failing. We've not 
ruled out a driver bug or an OSG bug here as far as I can see, it could 
still be both, since all the OSG pbuffer examples I've tried have failed 
in the same way.


Thanks,

J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
cmake_minimum_required(VERSION 2.6)

PROJECT(pbuffertest)

SET(CMAKE_MODULE_PATH 
${osggroudsim_SOURCE_DIR}/../CMakeModules;${CMAKE_MODULE_PATH})

FIND_PACKAGE(OpenThreads)
FIND_PACKAGE(osg)
FIND_PACKAGE(osgUtil)
FIND_PACKAGE(osgGA)
FIND_PACKAGE(osgDB)
FIND_PACKAGE(osgViewer)

SET(SOURCES
pbuffertest.cpp
)

INCLUDE_DIRECTORIES(${OPENTHREADS_INCLUDE_DIR} ${OSG_INCLUDE_DIR})
LINK_DIRECTORIES(${OSG_LIB_DIR})
ADD_EXECUTABLE(${CMAKE_PROJECT_NAME} ${SOURCES})
TARGET_LINK_LIBRARIES(${CMAKE_PROJECT_NAME} 
optimized ${OSG_LIBRARY} 
debug ${OSG_LIBRARY_DEBUG} 
optimized ${OSGVIEWER_LIBRARY} 
debug ${OSGVIEWER_LIBRARY_DEBUG}
optimized ${OSGGA_LIBRARY}
debug ${OSGGA_LIBRARY_DEBUG}
optimized ${OPENTHREADS_LIBRARY} 
debug ${OPENTHREADS_LIBRARY_DEBUG} 
)
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Hidden Viewer

2010-12-01 Thread Jean-Sébastien Guay

Hi again,


So I'll investigate a bit more as to why pbuffer is failing. We've not
ruled out a driver bug or an OSG bug here as far as I can see, it could
still be both, since all the OSG pbuffer examples I've tried have failed
in the same way.


I've tried an example that uses straight WGL_ARB_pbuffer code and it 
works fine. I found the example on the web, see here:


http://www.codesampler.com/oglsrc/oglsrc_7.htm

See the example Off-screen Rendering Using Pixel Buffers and I used 
version #1.


However this still doesn't prove it isn't a driver bug, since this 
example is single threaded and if I make the pbuffertest example single 
threaded (by adding 
viewer.setThreadingModel(osgViewer::ViewerBase::SingleThreaded); after 
the viewer creation) it works too.


I've debugged what happens, and roughly the sequence is this:

1. main(): createGraphicsContext(traits.get())
   --- PixelBufferWin32 is created successfully

2. main(): viewer.realize()
   --- PixelBufferWin32::makeCurrentImplementation() is called, and 
succeeds.


3. GraphicsThread::run()
   --- PixelBufferWin32::makeCurrentImplementation() is called, and 
fails with The requested resource is in use.


I don't know why the second makeCurrentImplementation would fail, but 
going from Juan's hunch that it was failing because some other thread 
was holding on to it (the main thread in this case), I added the 
following code after viewer.realize(); :


viewer.stopThreading();
gc-releaseContext();
viewer.startThreading();

This made it work.

This is obviously not a solution. It worked as-is before on Linux, so 
perhaps on Windows the makeCurrent() call makes the context exclusive 
to the thread on which it was called, whereas on Linux a subsequent 
makeCurrent() will still succeed and just remove the context from the 
previous thread that had it current silently?


Just theorizing here.

Any other ideas?

J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Hidden Viewer

2010-12-01 Thread Juan Hernando

Hi,

I've debugged what happens, and roughly the sequence is this:

1. main(): createGraphicsContext(traits.get())
   --- PixelBufferWin32 is created successfully

2. main(): viewer.realize()
   --- PixelBufferWin32::makeCurrentImplementation() is called, and 
succeeds.


3. GraphicsThread::run()
   --- PixelBufferWin32::makeCurrentImplementation() is called, and 
fails with The requested resource is in use.
I don't know why the second makeCurrentImplementation would fail, but 
going from Juan's hunch that it was failing because some other thread 
was holding on to it (the main thread in this case), 

Good tracking here.
According to the glxMakeCurrent specification making a context current 
on one thread while another one is holding it is also a mistake and 	a 
BadAccess error should be generated.


I added the 
following code after viewer.realize(); :


viewer.stopThreading();
gc-releaseContext();
viewer.startThreading();

This made it work.
This basically means that the context needs to be released at the end of 
createGraphicsContext or some other point.


This is obviously not a solution. It worked as-is before on Linux, so 
perhaps on Windows the makeCurrent() call makes the context exclusive 
to the thread on which it was called, whereas on Linux a subsequent 
makeCurrent() will still succeed and just remove the context from the 
previous thread that had it current silently?
If your trace is correct and it's the same for Linux then I think that 
it has been a matter of luck that a Linux driver didn't complain before.
However, I've taking a look at the code searching for how contexts are 
handled and I've found a fundamental difference between the X11 and 
Win32 implementations of PixelBufferXYZ::realizeImplementation. In Win32 
makeCurrentImplementation is called but not in X11. Maybe adding a 
releaseContextImplementation(); at the end of that function solves the 
problem.


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


Re: [osg-users] Hidden Viewer

2010-12-01 Thread Jean-Sébastien Guay

Hello Juan,


However, I've taking a look at the code searching for how contexts are
handled and I've found a fundamental difference between the X11 and
Win32 implementations of PixelBufferXYZ::realizeImplementation. In Win32
makeCurrentImplementation is called but not in X11. Maybe adding a
releaseContextImplementation(); at the end of that function solves the
problem.


I think that's the crux of the problem and yes, adding 
releaseContextImplementation() at the end of realizeImplementation() 
solves the problem. I'll submit the changed file to Robert.


It also solves the problem for osgscreencapture, which now works.

This will only fix Olivier's problem if he can compile and use the SVN 
version of OSG, but he could use the workaround I posted in my previous 
message for now I guess.


Thanks for the help Juan,

J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Hidden Viewer

2010-12-01 Thread Oliver Neumann
Hi,

Wow, you guys are great! Thanks for your help! Maybe we can solve this bug.
@Jean-Sébastien:
I had to additionally include the osgGA.lib to make it work in Win32.
My nVidia driver version is 6.14.12.5849 which should be 258 in your 
nomenclature.

Cheers,
Oliver

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





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


Re: [osg-users] Hidden Viewer

2010-12-01 Thread Jean-Sébastien Guay

On Hello Oliver,


I had to additionally include the osgGA.lib to make it work in Win32.


Yes, that was fixed by adding ${OSGGA_LIBRARY} in the CMakeLists.txt 
file, I had included it in a previous e-mail.



My nVidia driver version is 6.14.12.5849 which should be 258 in your 
nomenclature.


OK, but Juan and I have established it's not a driver bug, but something 
that was done in a questionable way in OSG's PixelBufferWin32 class. 
It's possible that previously this did not cause an error and that newer 
driver versions have made it give the error we saw, but it was clearly 
not very good OpenGL usage so the fix I submitted to OSG should clear it up.


In the mean time, have you tried the workaround I suggested? You could add

viewer.stopThreading();
gc-releaseContext();
viewer.startThreading();

right after viewer.realize(); and it should work (at least the 
pbuffertest example works then, so if your program does things in the 
same way it should work too).


Hope this helps,

J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Hidden Viewer

2010-12-01 Thread Robert Osfield
Hi Guys,

I've just reviewed J-S's submission that added a
releaseContextImplementation() call at the end of the
PixelBufferWin32::realizeImplementation().  Reviewing the method in
question I am curious why there is the makeCurrentImplementation()
call, the only need for it would be if wglShareLists(..) required the
context to be current, but having quickly looked online for docs on
wglShareLists(..) I can't spot any mention of need a context current.

Since wglShareLists(..) takes the two contexts to be shared as
parameters it would seem to me neither of these contexts should need
to be made current before calling wglShareLists(..).  MS's do have put
in some funny little quirks so perhaps wglShareLists() does require
the context to be first make current, if this is the case then J-S's
submission is correct.   If the makeCurrent() isn't required then the
right thing to do is remove the redundant makeCurrentImplementation().

I don't have a window system to test out this change so have to defer
to Windows users to go tweak the code and test it out.  Could you
please try out a PixelBufferWin32::realizeImplementation() with the
makeCurrentImplementation() commented out and no additional
releaseContextImplementation() call either.  If this works then we
should just go with this sans makeCurrentImplentation version.

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


Re: [osg-users] Hidden Viewer

2010-12-01 Thread Oliver Neumann
Hi,

I added to the pbuffertest.cpp directly after viewer.realize();

Code:

viewer.stopThreading();
gc-releaseContext();
viewer.startThreading(); 



but I still have the same behaviour (-1 works, -f 1 gives the wglMakeCurrent 
error)

Cheers,
Oliver

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





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


Re: [osg-users] Hidden Viewer

2010-12-01 Thread Jean-Sébastien Guay

Hello Oliver,


I added to the pbuffertest.cpp directly after viewer.realize();
but I still have the same behaviour (-1 works, -f 1 gives the wglMakeCurrent 
error)


Hmmm, seems you are tripping over something else on your hardware... I 
just remembered you had mentioned in another post that setting the 
threading model to SingleThreaded didn't work for you either, but in my 
case it did... So that indicates something else is going on for you.


You've already confirmed that pbuffers are supported by your card and 
driver, but there may still be a bug in your driver that makes them not 
work correctly in OSG's usage (which is valid in general except for that 
thing that I submitted a fix for). Your driver is recent but perhaps 
there was an obscure bug that was fixed in the latest version, so 
updating to the most recent would be a first step to at least eliminate 
that one difference between your machine and mine (other than the card 
itself of course, but with the same driver the behavior should be similar).


At this point I can't suggest much more than to try to put breakpoints 
in the OSG code and see what's going on. We don't have your hardware and 
driver so we can only help so much... You'll need to have a debug build 
of OSG and the sources of the same version to be able to do this.


In my case, I put a breakpoint in pbuffertest.cpp at the 
createGraphicsContext() line, stepped into that (F11) which eventually 
got me to the new PixelBufferWin32 call.


Then I put a breakpoint in PixelBufferWin32::realizeImplementation(), 
makeCurrentImplementation() and releaseContextImplementation() and 
looked at what was going on there, if any errors occured, and the call 
stack at the point where those functions were called. Looking at the 
call stack will tell you from which thread the methods are called 
(either they have main() in them or GraphicsThread or something else).


Hope this helps,

J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Hidden Viewer

2010-11-30 Thread Oliver Neumann
Hi,

I'm trying to render scenes into a buffer (e.g. an osg::Image). There are 
multiple demos and examples about this (e.g. example_osgscreencapture) but they 
all require some sort of visible viewer to work. I'd like a console application 
that does not display any windows. 

Is there a class/working example that allows this? 

I tried the osgViewer::setUpViewerAsEmbeddedInWindow method but calling 
viewer.frame() produces many errors. It seems as OpenGL is not initialized here 
at all.

Thank you!

Cheers,
Oliver

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





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


Re: [osg-users] Hidden Viewer

2010-11-30 Thread Juan Hernando

Hi Oliver,

I'm trying to render scenes into a buffer (e.g. an osg::Image). There
are multiple demos and examples about this (e.g.
example_osgscreencapture) but they all require some sort of visible
viewer to work. I'd like a console application that does not display
any windows.

Is there a class/working example that allows this?
Probably there's a simpler way, but you can create an off-screen viewer 
with this code:


int witdth = ...;
int height = ...;
osgViewer::Viewer viewer;
osg::Camera *camera = viewer.getCamera();
osg::ref_ptrosg::GraphicsContext::Traits traits =
new osg::GraphicsContext::Traits;
traits-x = 0;
traits-y = 0;
traits-width = width;
traits-height = height;
traits-doubleBuffer = false;
traits-sharedContext = 0;
traits-pbuffer = true;
traits-readDISPLAY();
osg::GraphicsContext *gc =
osg::GraphicsContext::createGraphicsContext(traits.get());
camera-setGraphicsContext(gc);
camera-setDrawBuffer(GL_FRONT);
camera-setReadBuffer(GL_FRONT);
camera-setViewport(new osg::Viewport(0, 0, width, height));
double fovy, aspectRatio, near, far;
camera-getProjectionMatrixAsPerspective(fovy, aspectRatio, near, far);
double newAspectRatio = double(traits-width) / double(traits-height);
double aspectRatioChange = newAspectRatio / aspectRatio;
if (aspectRatioChange != 1.0)
camera-getProjectionMatrix() *=
osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0);

// Viewer stuff like handlers, setting scene data, etc. Don't call any
// of the setUpXYZ functions.
// And don't forget to attach the image to the camera.

viewer.realize();
viewer.run();

In windows I don't know how it works but in *NIX, note that you still 
need access to the display server.


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


Re: [osg-users] Hidden Viewer

2010-11-30 Thread Robert Osfield
Hi Oliver,

Juan provides an example of how to do it, but doesn't specifically say
how it works - the key is creating a pbuffer graphics context to
assign to the viewer so it can use this for render.  A pbuffer is an
off screen Pixel Buffer that can be used in place of a conventional on
screen window.

Robert.

On Tue, Nov 30, 2010 at 10:25 AM, Oliver Neumann z0...@yahoo.com wrote:
 Hi,

 I'm trying to render scenes into a buffer (e.g. an osg::Image). There are 
 multiple demos and examples about this (e.g. example_osgscreencapture) but 
 they all require some sort of visible viewer to work. I'd like a console 
 application that does not display any windows.

 Is there a class/working example that allows this?

 I tried the osgViewer::setUpViewerAsEmbeddedInWindow method but calling 
 viewer.frame() produces many errors. It seems as OpenGL is not initialized 
 here at all.

 Thank you!

 Cheers,
 Oliver

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





 ___
 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] Hidden Viewer

2010-11-30 Thread Oliver Neumann
Dear Juan and Robert,

Thanks for the quick reply! I tried the code supplied by Juan but I'm still 
getting the Error: OpenGL version test failed, requires valid graphics 
context. and subsequent errors (many invalid operation). 

As a second test I copied the complete osgViewer::setUpViewInWindow and just 
added the line

Code:

traits-pbuffer = true; 



to the Traits creation part. Without the line the code works but displays a 
window, with the line I get the OpenGL errors.  For the second case I get these 
Errors:


Code:

PixelBufferWin32::makeCurrentImplementation, wglMakeCurrent error: Die 
angeforderte Ressource wird bereits verwendet.

Error: In Texture::Extensions::setupGLExtensions(..) OpenGL version test 
failed, requires valid graphics context.
Scaling image from (256,256) to (0,0)

(Die angeforderte Ressource wird bereits verwendet. is german for The 
Requested Resource Is in Use.)




Is this a Win32 related problem or am I missing something?

Cheers,
Oliver[/code]

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





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


Re: [osg-users] Hidden Viewer

2010-11-30 Thread Juan Hernando

Dear Oliver,
Seeing that error my impression is that there is something wrong with
your OpenGL installation. However I seldom use Windows, so I may be wrong.
Can you check the program below with and without commenting the line
that enables the pbuffer and give the whole output?
The program should write a file called screenshot.png in the working
directory. That output image should be a white sphere over the default
background.

#include osg/Geode
#include osg/ShapeDrawable
#include osgViewer/Viewer
#include osgGA/TrackballManipulator
#include osgDB/WriteFile

int main(int argc, char *argv[])
{
osg::ArgumentParser args(argc, argv);
osgViewer::Viewer viewer(args);
osg::Camera *camera = viewer.getCamera();

osg::ref_ptrosg::GraphicsContext::Traits traits = new
osg::GraphicsContext::Traits;
traits-width = 512;
traits-height = 512;
traits-pbuffer = true;
traits-readDISPLAY();
osg::GraphicsContext *gc =
osg::GraphicsContext::createGraphicsContext(traits.get());
camera-setGraphicsContext(gc);
camera-setDrawBuffer(GL_FRONT);
camera-setProjectionMatrixAsPerspective(22, 1, 0.1, 1000);
camera-setViewport(new osg::Viewport(0, 0, 512, 512));

osg::Geode *scene = new osg::Geode();
osg::Shape *sphere = new osg::Sphere(osg::Vec3(), 1);
scene-addDrawable(new osg::ShapeDrawable(sphere));
viewer.setSceneData(scene);

viewer.setCameraManipulator(new osgGA::TrackballManipulator());

osg::Image *image = new osg::Image();
camera-attach(osg::Camera::COLOR_BUFFER0, image);

viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);
viewer.realize();
viewer.frame();

osgDB::writeImageFile(*image, screenshot.png);
}

Regards,
Juan


Dear Juan and Robert,

Thanks for the quick reply! I tried the code supplied by Juan but I'm
still getting the Error: OpenGL version test failed, requires valid
graphics context. and subsequent errors (many invalid operation).


As a second test I copied the complete osgViewer::setUpViewInWindow
and just added the line

Code:

traits-pbuffer = true;

to the Traits creation part. Without the line the code works but
displays a window, with the line I get the OpenGL errors.  For the
second case I get these Errors:

Code:

PixelBufferWin32::makeCurrentImplementation, wglMakeCurrent error:
Die angeforderte Ressource wird bereits verwendet.

Error: In Texture::Extensions::setupGLExtensions(..) OpenGL version
test failed, requires valid graphics context. Scaling image from
(256,256) to (0,0)

(Die angeforderte Ressource wird bereits verwendet. is german for
The Requested Resource Is in Use.)


Is this a Win32 related problem or am I missing something?

Cheers, Oliver[/code]

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


Re: [osg-users] Hidden Viewer

2010-11-30 Thread Oliver Neumann
Hi Juan,

Thanks for the demo code. It runs without a problem. I found the critical line:

viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);

If i comment it out, the demo code crashes with the same error text as above. 
Very weird... 
I tried to add this line to my code, but I still have some minor bugs to fix. 
Appart from that, is it possible to run a hidden viewer in a multithreaded 
fashion?

Greetings,
Oliver

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





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


Re: [osg-users] Hidden Viewer

2010-11-30 Thread Robert Osfield
Hi Oliver,

A pbuffer is like any other graphics context, it shouldn't be a
problem to run the application multi-threaded with pbuffer if it is
already working thread safe with a standard graphics window.  However,
your own code might not be using the OSG in a safe way.

Robert.

On Tue, Nov 30, 2010 at 4:55 PM, Oliver Neumann z0...@yahoo.com wrote:
 Hi Juan,

 Thanks for the demo code. It runs without a problem. I found the critical 
 line:

 viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);

 If i comment it out, the demo code crashes with the same error text as above. 
 Very weird...
 I tried to add this line to my code, but I still have some minor bugs to fix. 
 Appart from that, is it possible to run a hidden viewer in a multithreaded 
 fashion?

 Greetings,
 Oliver

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





 ___
 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] Hidden Viewer

2010-11-30 Thread Juan Hernando

Oliver Neumann wrote:

Hi Juan,

Thanks for the demo code. It runs without a problem. I found the
critical line:

viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);

If i comment it out, the demo code crashes with the same error text
as above. Very weird... 
Indeed, I added that line because in other threading models the 
viewer.frame() function returns inmediately. In that case 
osgDB::writeImageFile will be most probably accessing an invalid image 
object (not allocated or not rendered) and will fail. However the error 
I get if I remove that line is quite different.


 I tried to add this line to my code, but I
 still have some minor bugs to fix. Appart from that, is it possible
 to run a hidden viewer in a multithreaded fashion

As Robert already answered, it should be possible.
The best explanation that I have for your problem is that some thread 
fails to do wglMakeCurrent (after that call fails anything that follows 
is just garbage) beacuse another thread is holding the context 
(according to 
http://www.opengl.org/sdk/docs/man/xhtml/glXMakeCurrent.xml, that's a 
programming error in GLX, so I guess the same applies in WGL). All 
OpenGL calls from that thread are going to fail after that.


If the sample code that I sent you also complains with the error message:
PixelBufferWin32::makeCurrentImplementation, wglMakeCurrent error: Die 
angeforderte Ressource wird bereits verwendet
then, there is a threading error somewhere. However I can't spot it the 
code I sent you and I'm afraid that's beyond my knowledge of OSG's guts. 
Robert may be more insightful here.


You can try commenting the line that changes the threading model and 
replacing frame() by run() to see if it also fails.


Hope that helps,
Juan




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