Files
Bret Curtis 28b8274aee Own work queue items with std::shared_ptr instead of osg::Referenced
SceneUtil::WorkQueue is a thread pool with no scene graph in it, so neither it
nor WorkItem needs an OSG base class to be reference counted; both now use
std::shared_ptr and workqueue.hpp, workqueue.cpp and generatenavmeshtile.hpp
end up with no reference to osg at all. Because osg::ref_ptr can re-adopt a raw
pointer and std::shared_ptr cannot without minting a second control block, the
places that passed the queue around as WorkQueue* now pass const
std::shared_ptr<WorkQueue>& instead, which is RenderingManager::getWorkQueue
and the World, WindowManager, MapWindow and GlobalMap constructors. The
non-owning WorkQueue& parameters in UnrefQueue, WorkThread and navmeshtool are
unchanged, and WorkItem gains the virtual destructor it used to inherit.
2026-09-20 12:33:25 +02:00

61 lines
1.8 KiB
C++

#ifndef OPENMW_COMPONENTS_SCENEUTIL_SCREENCAPTURE_H
#define OPENMW_COMPONENTS_SCENEUTIL_SCREENCAPTURE_H
#include <components/misc/guarded.hpp>
#include <osg/ref_ptr>
#include <osgViewer/ViewerEventHandlers>
#include <filesystem>
#include <memory>
#include <string>
#include <vector>
namespace osg
{
class Image;
}
namespace SceneUtil
{
class WorkQueue;
class WorkItem;
std::filesystem::path writeScreenshotToFile(
const std::filesystem::path& screenshotPath, const std::string& screenshotFormat, const osg::Image& image);
class WriteScreenshotToFileOperation : public osgViewer::ScreenCaptureHandler::CaptureOperation
{
public:
WriteScreenshotToFileOperation(const std::filesystem::path& screenshotPath, const std::string& screenshotFormat,
std::function<void(std::string)> callback);
void operator()(const osg::Image& image, unsigned int contextId) override;
private:
const std::filesystem::path mScreenshotPath;
const std::string mScreenshotFormat;
const std::function<void(std::string)> mCallback;
};
class AsyncScreenCaptureOperation : public osgViewer::ScreenCaptureHandler::CaptureOperation
{
public:
AsyncScreenCaptureOperation(std::shared_ptr<SceneUtil::WorkQueue> queue,
osg::ref_ptr<osgViewer::ScreenCaptureHandler::CaptureOperation> impl);
~AsyncScreenCaptureOperation();
void stop();
void operator()(const osg::Image& image, unsigned int contextId) override;
private:
const std::shared_ptr<SceneUtil::WorkQueue> mQueue;
const osg::ref_ptr<osgViewer::ScreenCaptureHandler::CaptureOperation> mImpl;
Misc::ScopeGuarded<std::vector<std::shared_ptr<SceneUtil::WorkItem>>> mWorkItems;
};
}
#endif