From Jean-Sebastien Guay, "Changes attached so that the CaptureOperation is passed in the constructor of the ScreenCaptureHandler (default 0 = default CaptureOperation). This way, you can do:

viewer.addEventHandler(new osgViewer::ScreenCaptureHandler(
   new osgViewer::WriteToFileCaptureOperation("filename", "jpg")));

and the filename will be what you want. The WriteToFileCaptureOperation will add the context ID and the file number (if in SEQUENTIAL_NUMBER mode) to the file name.

(The attached also clarifies some notify messages, and corrects the comment when adding the handler in osgviewer.cpp)

I also remembered, the current architecture could allow a different CaptureOperation for each context, but currently the API only allows setting one CaptureOperation for all contexts. This could be improved if need be.

"
This commit is contained in:
Robert Osfield
2008-07-21 21:28:48 +00:00
parent 5e80c3856f
commit cad2f6d4fc
3 changed files with 49 additions and 85 deletions

View File

@@ -355,6 +355,7 @@ class OSGVIEWER_EXPORT WindowCaptureCallback : public osg::Camera::DrawCallback
void updateTimings(osg::Timer_t tick_start,
osg::Timer_t tick_afterReadPixels,
osg::Timer_t tick_afterMemCpy,
osg::Timer_t tick_afterCaptureOperation,
unsigned int dataSize);
void read();
@@ -384,8 +385,10 @@ class OSGVIEWER_EXPORT WindowCaptureCallback : public osg::Camera::DrawCallback
unsigned int _reportTimingFrequency;
unsigned int _numTimeValuesRecorded;
double _timeForReadPixels;
double _timeForFullCopy;
double _timeForMemCpy;
double _timeForCaptureOperation;
double _timeForFullCopy;
double _timeForFullCopyAndOperation;
osg::Timer_t _previousFrameTick;
osg::ref_ptr<CaptureOperation> _captureOperation;
@@ -411,13 +414,14 @@ class OSGVIEWER_EXPORT WindowCaptureCallback : public osg::Camera::DrawCallback
mutable OpenThreads::Mutex _mutex;
mutable ContextDataMap _contextDataMap;
osg::ref_ptr<CaptureOperation> _defaultCaptureOperation;
};
/** Event handler that will capture the screen on key press. */
class OSGVIEWER_EXPORT ScreenCaptureHandler : public osgGA::GUIEventHandler
{
public:
ScreenCaptureHandler();
ScreenCaptureHandler(CaptureOperation* defaultOperation = 0);
void setKeyEventTakeScreenShot(int key) { _keyEventTakeScreenShot = key; }
int getKeyEventTakeScreenShot() const { return _keyEventTakeScreenShot; }