1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-23 17:53:56 +00:00
openmw-tes3mp/apps/openmw/mwvr/vrframebuffer.hpp

71 lines
2.2 KiB
C++
Raw Normal View History

#ifndef MWVR_OPENRXTEXTURE_H
#define MWVR_OPENRXTEXTURE_H
#include <memory>
#include <osg/Group>
#include <osg/Camera>
#include <osgViewer/Viewer>
#include "openxrmanager.hpp"
namespace MWVR
{
2020-06-28 09:33:01 +00:00
/// \brief Manages an opengl framebuffer
///
/// Intended for managing the vr swapchain, but is also use to manage the mirror texture as a convenience.
2020-12-30 14:03:40 +00:00
class VRFramebuffer
{
2020-12-30 14:03:40 +00:00
private:
struct Texture
{
uint32_t mImage = 0;
bool mOwner = false;
void delet();
void setTexture(uint32_t image, bool owner);
};
public:
2020-12-30 14:03:40 +00:00
VRFramebuffer(osg::ref_ptr<osg::State> state, std::size_t width, std::size_t height, uint32_t msaaSamples);
2020-06-28 09:33:01 +00:00
~VRFramebuffer();
void destroy(osg::State* state);
auto width() const { return mWidth; }
auto height() const { return mHeight; }
auto msaaSamples() const { return mSamples; }
2020-06-28 09:33:01 +00:00
void bindFramebuffer(osg::GraphicsContext* gc, uint32_t target);
2020-12-30 14:03:40 +00:00
void setColorBuffer(osg::GraphicsContext* gc, uint32_t colorBuffer, bool takeOwnership);
void setDepthBuffer(osg::GraphicsContext* gc, uint32_t depthBuffer, bool takeOwnership);
void createColorBuffer(osg::GraphicsContext* gc);
void createDepthBuffer(osg::GraphicsContext* gc);
//! ref glBlitFramebuffer
void blit(osg::GraphicsContext* gc, int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, uint32_t bits, uint32_t filter = GL_LINEAR);
2020-12-30 14:03:40 +00:00
uint32_t colorBuffer() const { return mColorBuffer.mImage; };
uint32_t depthBuffer() const { return mDepthBuffer.mImage; };
private:
2020-12-30 14:03:40 +00:00
uint32_t createImage(osg::GraphicsContext* gc, uint32_t formatInternal, uint32_t format);
// Set aside a weak pointer to the constructor state to use when freeing FBOs, if no state is given to destroy()
osg::observer_ptr<osg::State> mState;
// Metadata
std::size_t mWidth = 0;
std::size_t mHeight = 0;
// Render Target
uint32_t mFBO = 0;
2020-12-30 14:03:40 +00:00
Texture mDepthBuffer;
Texture mColorBuffer;
uint32_t mSamples = 0;
uint32_t mTextureTarget = 0;
};
}
#endif