#ifndef OPENMW_MWRENDER_PINGPONGCANVAS_H #define OPENMW_MWRENDER_PINGPONGCANVAS_H #include #include #include #include #include #include #include "luminancecalculator.hpp" namespace Shader { class ShaderManager; } namespace MWRender { class PingPongCanvas : public osg::Geometry { public: PingPongCanvas(Shader::ShaderManager& shaderManager); void drawImplementation(osg::RenderInfo& renderInfo) const override; void dirty(size_t frameId) { mBufferData[frameId].dirty = true; } const fx::DispatchArray& getCurrentFrameData(size_t frame) { return mBufferData[frame % 2].data; } // Sets current frame pass data and stores copy of dispatch array to apply to next frame data void setCurrentFrameData(size_t frameId, fx::DispatchArray&& data); void setMask(size_t frameId, bool underwater, bool exterior); void setSceneTexture(size_t frameId, osg::ref_ptr tex) { mBufferData[frameId].sceneTex = tex; } void setLDRSceneTexture(size_t frameId, osg::ref_ptr tex) { mBufferData[frameId].sceneTexLDR = tex; } void setDepthTexture(size_t frameId, osg::ref_ptr tex) { mBufferData[frameId].depthTex = tex; } void setNormalsTexture(size_t frameId, osg::ref_ptr tex) { mBufferData[frameId].normalsTex = tex; } void setHDR(size_t frameId, bool hdr) { mBufferData[frameId].hdr = hdr; } void setPostProcessing(size_t frameId, bool postprocessing) { mBufferData[frameId].postprocessing = postprocessing; } const osg::ref_ptr& getSceneTexture(size_t frameId) const { return mBufferData[frameId].sceneTex; } void drawGeometry(osg::RenderInfo& renderInfo) const; private: void copyNewFrameData(size_t frameId) const; mutable LuminanceCalculator mLuminanceCalculator; osg::ref_ptr mFallbackProgram; osg::ref_ptr mMultiviewResolveProgram; osg::ref_ptr mFallbackStateSet; osg::ref_ptr mMultiviewResolveStateSet; mutable osg::ref_ptr mMultiviewResolveFramebuffer; struct BufferData { bool dirty = false; bool hdr = false; bool postprocessing = true; fx::DispatchArray data; fx::FlagsType mask; osg::ref_ptr destination; osg::ref_ptr sceneTex; osg::ref_ptr depthTex; osg::ref_ptr sceneTexLDR; osg::ref_ptr normalsTex; }; mutable std::array mBufferData; mutable std::array, 3> mFbos; mutable osg::ref_ptr mRenderViewport; }; } #endif