From d1254645336a07ba7fd8d1eaf2a211867f708bff Mon Sep 17 00:00:00 2001 From: Mads Buvik Sandvei Date: Thu, 10 Dec 2020 21:30:54 +0100 Subject: [PATCH] Uninitialized data bugs. --- apps/openmw/mwrender/vismask.hpp | 17 +++--- apps/openmw/mwvr/openxrmanagerimpl.cpp | 6 +-- apps/openmw/mwvr/vrviewer.cpp | 71 ++++++++++++++------------ 3 files changed, 50 insertions(+), 44 deletions(-) diff --git a/apps/openmw/mwrender/vismask.hpp b/apps/openmw/mwrender/vismask.hpp index f9f9dc74c..b512efaf6 100644 --- a/apps/openmw/mwrender/vismask.hpp +++ b/apps/openmw/mwrender/vismask.hpp @@ -35,25 +35,26 @@ namespace MWRender Mask_FirstPerson = (1<<9), Mask_Object = (1<<10), Mask_Static = (1<<11), + Mask_3DGUI= (1<<12), // child of Sky - Mask_Sun = (1<<12), - Mask_WeatherParticles = (1<<13), + Mask_Sun = (1<<13), + Mask_WeatherParticles = (1<<14), // top level masks - Mask_Scene = (1<<14), - Mask_GUI = (1<<15), + Mask_Scene = (1<<15), + Mask_GUI = (1<<16), // Set on a ParticleSystem Drawable - Mask_ParticleSystem = (1<<16), + Mask_ParticleSystem = (1<<17), // Set on cameras within the main scene graph - Mask_RenderToTexture = (1<<17), + Mask_RenderToTexture = (1<<18), - Mask_PreCompile = (1<<18), + Mask_PreCompile = (1<<19), // Set on a camera's cull mask to enable the LightManager - Mask_Lighting = (1<<19) + Mask_Lighting = (1<<20) }; } diff --git a/apps/openmw/mwvr/openxrmanagerimpl.cpp b/apps/openmw/mwvr/openxrmanagerimpl.cpp index 8f990e249..8de79215a 100644 --- a/apps/openmw/mwvr/openxrmanagerimpl.cpp +++ b/apps/openmw/mwvr/openxrmanagerimpl.cpp @@ -452,10 +452,10 @@ namespace MWVR void OpenXRManagerImpl::LogReferenceSpaces() { - uint32_t spaceCount; - xrEnumerateReferenceSpaces(mSession, 0, &spaceCount, nullptr); + uint32_t spaceCount = 0; + CHECK_XRCMD(xrEnumerateReferenceSpaces(mSession, 0, &spaceCount, nullptr)); std::vector spaces(spaceCount); - xrEnumerateReferenceSpaces(mSession, spaceCount, &spaceCount, spaces.data()); + CHECK_XRCMD(xrEnumerateReferenceSpaces(mSession, spaceCount, &spaceCount, spaces.data())); std::stringstream ss; ss << "Available reference spaces=" << spaceCount << std::endl; diff --git a/apps/openmw/mwvr/vrviewer.cpp b/apps/openmw/mwvr/vrviewer.cpp index 70b0ceac7..0f6037f7b 100644 --- a/apps/openmw/mwvr/vrviewer.cpp +++ b/apps/openmw/mwvr/vrviewer.cpp @@ -92,9 +92,7 @@ namespace MWVR void VRViewer::InitialDrawCallback::operator()(osg::RenderInfo& renderInfo) const { - const auto& name = renderInfo.getCurrentCamera()->getName(); - if (name == "LeftEye") - Environment::get().getSession()->beginPhase(VRSession::FramePhase::Draw); + Environment::get().getSession()->beginPhase(VRSession::FramePhase::Draw); osg::GraphicsOperation* graphicsOperation = renderInfo.getCurrentCamera()->getRenderer(); osgViewer::Renderer* renderer = dynamic_cast(graphicsOperation); @@ -169,12 +167,12 @@ namespace MWVR if (i > 0) { mSubImages[i].x = mSubImages[i - 1].x + mSubImages[i - 1].width; - mSubImages[i].y = mSubImages[i - 1].y + mSubImages[i - 1].height; } else { - mSubImages[i].x = mSubImages[i].y = 0; + mSubImages[i].x = 0; } + mSubImages[i].y = 0; } mSwapchainConfig.name = "Main"; @@ -247,46 +245,52 @@ namespace MWVR void VRViewer::blitEyesToMirrorTexture(osg::GraphicsContext* gc) { - //if (mMirrorTextureShouldBeCleanedUp) - //{ - // mMirrorTexture.reset(nullptr); - // mMsaaResolveMirrorTexture.clear(); - // mMirrorTextureShouldBeCleanedUp = false; - //} - //if (!mMirrorTextureEnabled) - // return; - //if (!mMirrorTexture) - //{ - // mMirrorTexture.reset(new VRFramebuffer(gc->getState(), mCameras["MainCamera"]->getViewport()->width(), mCameras["MainCamera"]->getViewport()->height(), 0)); - //} + if (mMirrorTextureShouldBeCleanedUp) + { + mMirrorTexture = nullptr; + mMsaaResolveMirrorTexture = nullptr; + mMirrorTextureShouldBeCleanedUp = false; + } + if (!mMirrorTextureEnabled) + return; + + auto* camera = mViewer->getCamera(); + int screenWidth = camera->getGraphicsContext()->getTraits()->width; + int screenHeight = camera->getGraphicsContext()->getTraits()->height; + if (!mMirrorTexture) + { + ; + mMirrorTexture.reset(new VRFramebuffer(gc->getState(), + screenWidth, + screenHeight, + 0)); + mMsaaResolveMirrorTexture.reset(new VRFramebuffer(gc->getState(), + mSwapchain->width(), + mSwapchain->height(), + 0)); + } auto* state = gc->getState(); auto* gl = osg::GLExtensions::Get(state->getContextID(), false); - //auto mainCamera = mViewer->getCamera(); - //int screenWidth = mainCamera->getViewport()->width(); - //int mirrorWidth = screenWidth / mMirrorTextureViews.size(); - //int screenHeight = mainCamera->getViewport()->height(); + int mirrorWidth = screenWidth / mMirrorTextureViews.size(); //// Since OpenXR does not include native support for mirror textures, we have to generate them ourselves //// which means resolving msaa twice. + mMsaaResolveMirrorTexture->bindFramebuffer(gc, GL_FRAMEBUFFER_EXT); + mSwapchain->renderBuffer()->blit(gc, 0, 0, mSwapchain->width(), mSwapchain->height()); + mMirrorTexture->bindFramebuffer(gc, GL_FRAMEBUFFER_EXT); + mMsaaResolveMirrorTexture->blit(gc, 0, 0, screenWidth, screenHeight); //for (unsigned i = 0; i < mMirrorTextureViews.size(); i++) //{ - // if(!mMsaaResolveMirrorTexture) - // mMsaaResolveMirrorTexture.reset(new VRFramebuffer(gc->getState(), - // mSwapchain->width(), - // mSwapchain->height(), - // 0)); - - // auto& resolveTexture = *mMsaaResolveMirrorTexture[mMirrorTextureViews[i]]; - // resolveTexture.bindFramebuffer(gc, GL_FRAMEBUFFER_EXT); - // view->swapchain().renderBuffer()->blit(gc, 0, 0, resolveTexture.width(), resolveTexture.height()); - // mMirrorTexture->bindFramebuffer(gc, GL_FRAMEBUFFER_EXT); - // resolveTexture.blit(gc, i * mirrorWidth, 0, (i + 1) * mirrorWidth, screenHeight); + // mMsaaResolveMirrorTexture->blit(gc, ); + // mMsaaResolveMirrorTexture->bindFramebuffer(gc, GL_READ_FRAMEBUFFER_EXT); + // gl->glBlitFramebuffer(0, 0, mWidth, mHeight, i * mirrorWidth, 0, (i + 1) * mirrorWidth, screenHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR); + // gl->glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, 0); //} gl->glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); - //mMirrorTexture->blit(gc, 0, 0, screenWidth, screenHeight); + mMirrorTexture->blit(gc, 0, 0, screenWidth, screenHeight); mSwapchain->endFrame(gc); } @@ -316,6 +320,7 @@ namespace MWVR { if(Environment::get().getSession()->getFrame(VRSession::FramePhase::Draw)->mShouldRender) mSwapchain->beginFrame(info.getState()->getGraphicsContext()); + mViewer->getCamera()->setViewport(0, 0, mSwapchainConfig.selectedWidth, mSwapchainConfig.selectedHeight); } void VRViewer::postDrawCallback(osg::RenderInfo& info)