bjornblissing / osgoculusviewer

An OsgViewer with support for the Oculus Rift
Other
106 stars 67 forks source link

Support 0.6.0.1 version of Oculus SDK #46

Closed bjornblissing closed 9 years ago

bjornblissing commented 9 years ago

The new version of the Oculus SDK requires some reworking. Only SDK based distortion rendering is supported. So the client distortion rendering code have to be removed.

Oculus have also paused all support for Linux and Mac, so this version will be for Windows only.

bjornblissing commented 9 years ago

An experimental branch is setup which tries to solve this. But as of yet is not complete, since it throws a lot of error messages and have serious flickring. Branch can be found here: https://github.com/bjornblissing/osgoculusviewer/tree/sdk-v0.6

danjo133 commented 9 years ago

Will you leave a branch for the previous sdk so that it can continue being used on Linux?

bjornblissing commented 9 years ago

@danjo133 Yes, I will probably do a 0.5.0.1 branch before merging the development for the 0.6.0.0 branch.

bjornblissing commented 9 years ago

User @JeffBail have started investigating why we are getting these error messages and the flickering: https://forums.oculus.com/viewtopic.php?f=39&t=1885&start=20#p275142

AlexandraMercier commented 9 years ago

It seems like User @JeffBail found a solution for the flickering. Unfortunatly, when I tried to implement it to the code, the flickering got worse and I got a new error message.

bjornblissing commented 9 years ago

Fixed mirror texture with: fb574a357dbd1aed23baab737a7b5c531525d586

This makes the SDK 0.6.0.1 support complete.

ChrisDenham commented 9 years ago

Is there a way to get the OSG StatsHandler to show the stats HUD? Does it need merging with the mirror texture? It doesn't seem to work since this update.

bjornblissing commented 9 years ago

The stats handler is normally shown on the main camera view. But right now this view is replaced with the mirror texture from the Oculus SDK.

bjornblissing commented 9 years ago

Best would of course be if we could move the osg stats view into a HUD texture to use with the Oculus SDK layer compositor.

ChrisDenham commented 9 years ago

Aha. I just noticed that I can see the bit of the stats hud I need on the main camera if I maximize the mirror window. Looks weird, but does the job :-)

bjornblissing commented 9 years ago

The mirror texture should actually be replaced each time the mirror window is resized. But that is yet another feature for the future.

ChrisDenham commented 9 years ago

BTW. on a related note, do we actually need to render the main camera? I ask because presumably in single threaded mode, we only have a max of around 4.4ms to render each of the three cameras at 75FPS. It seems like it might help if we only rendered the two slave cameras (thus giving us up to about 6.6ms to render frame) ? I've noticed some of my scenes are hitting this limit, which makes the oculus runtime halve its frame rate down to 37.5FPS.

[Edit: I think I can resolve this in my own application simply by setting node mask to zero on the main camera]

ChrisDenham commented 9 years ago

Another question. Since updating to support the 0.6.0.1 SDK, I've noticed that my scenes seem to be being rendered without antialiasing. Any ideas how to enable it again? The two pictures attached show the difference between rendering the same scene with the the two versions (first one from 0.5.0.1 SDK version, second one from 0.6.0.1 SDK version, both running on the 0.6.0.1 runtime).

0_5_0_1 0_6_0_1

bjornblissing commented 9 years ago

On you first question regarding rendering the main camera even though it is not visible: This is a bug which has propagated since an update I made in the 0.5 branch.

Regarding the aliasing/multisample problem, FBO's which 0.6 uses must be initialized with osg::Texture2DMultisample instead of osg::Texture2D to use MSAA.

ChrisDenham commented 9 years ago

Thank you. I'll try the texture2dmultisample tomorrow. If i implement it as an option, would you like me to submit it as a pull request?

ChrisDenham commented 9 years ago

I tried changing the OculusTextureBuffer class to handle the multisample case, but it seems to make no difference to the anti aliasing and I also get OSG reporting OpenGL invalid operation 0x0502. I then also tried making sure the depth buffer was created with multisample too, but that then just gives a stream of errors:

RenderStage::drawInner(,) FBO status = 0x8d56

Which I think equates to error: GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT So, I'm presuming there must be something extra I need to do? But feeling way out my depth now.

/* Public functions */
OculusTextureBuffer::OculusTextureBuffer(const ovrHmd& hmd, osg::ref_ptr<osg::State> state, const ovrSizei& size, unsigned int numMultiSamples) : m_hmdDevice(hmd), m_textureSet(0),
    m_texture(0), 
    m_textureSize(osg::Vec2i(size.w, size.h)), 
    m_contextId(0), 
    m_fboId(0), 
    m_fboIdInitialized(false) 
{
    m_textureSize.set(size.w, size.h);
    if (ovrHmd_CreateSwapTextureSetGL(m_hmdDevice, GL_RGBA, size.w, size.h, &m_textureSet) == ovrSuccess) {
        // Assign textures to OSG textures
        for (int i = 0; i < m_textureSet->TextureCount; ++i)
        {
            ovrGLTexture* tex = (ovrGLTexture*)&m_textureSet->Textures[i];

            GLuint handle = tex->OGL.TexId;

            int width = tex->Texture.Header.TextureSize.w;
            int height = tex->Texture.Header.TextureSize.h;

            if (numMultiSamples > 1)
            {
                osg::Texture2DMultisample* texture2DMS = new osg::Texture2DMultisample(numMultiSamples, GL_FALSE);
                texture2DMS->setTextureSize(width, height);
                m_texture = texture2DMS;
            }
            else
            {
                osg::Texture2D* texture2D = new osg::Texture2D();
                texture2D->setTextureSize(width, height);
                m_texture = texture2D;
            }

            osg::ref_ptr<osg::Texture::TextureObject> textureObject = new osg::Texture::TextureObject(m_texture.get(), handle, m_texture->getTextureTarget());

            textureObject->setAllocated(true);

            m_texture->setTextureObject(state->getContextID(), textureObject.get());

            m_texture->apply(*state.get());

            m_texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
            m_texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
            m_texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
            m_texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);

            m_texture->setSourceFormat(GL_RGBA);
            m_texture->apply(*state.get());
            m_contextId = state->getContextID();

            osg::notify(osg::DEBUG_INFO) << "Successfully created the swap texture!" << std::endl;
        }
    }
    else {
        osg::notify(osg::WARN) << "Warning: Unable to create swap texture set! " << std::endl;
        return;
    }
}
bjornblissing commented 9 years ago

Well, both the color buffer and the depth buffer must have the same dimensions and number of multi-samples. Otherwise you will get GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT

ChrisDenham commented 9 years ago

Well, both the color buffer and the depth buffer must have the same dimensions and number of multi-samples. Otherwise you will get GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT

Yes, checked that, still no joy. I'm currently musing whether OculusDepthBuffer::setRenderSurface might need a call to glBindFramebuffer like OculusTextureBuffer::setRenderSurface. And whether the argument to glFramebufferTexture2D should be GL_TEXTURE_2D_MULTISAMPLE instead of GL_TEXTURE_2D.

bjornblissing commented 9 years ago

The previously mentioned bug regarding the main camera needlessly rendering has been assigned the a new issue: #54

The issue of the lack of support for antialiasing has been assigned to the new issue: #55