Can renderOneFrame() running in background thread?

Problems building or running the engine, queries about how to use features etc.
Post Reply
Whisperd130
Halfling
Posts: 77
Joined: Wed Feb 01, 2017 4:02 pm
x 1

Can renderOneFrame() running in background thread?

Post by Whisperd130 »

Ogre Version: :1.10.7:
Operating System: :windows7:
Render System: :opengl&dx9:

Code: Select all

Ogre: GLHardwareVertexBuffer::lock - Error: failed to Discard the buffer. Try to recreate the buffer
Hi guys
Actually I want to render in another thread. And when I try to create a new thread to do so. I got error in OgreGLHardwareVertexBuffer.cpp.
It seems like the memory can not lock automatically. Does anyone get some advice?
Also I got another idea to put all ogre system into the new thread. I will try it and hope it works. :wink:
Whisperd130
Halfling
Posts: 77
Joined: Wed Feb 01, 2017 4:02 pm
x 1

Re: Can renderOneFrame() running in background thread?

Post by Whisperd130 »

Thank you for reply.
I have try to use the startup sequence both in opengl and dx9 systems.

Code: Select all

1. [Main thread] Call preExtraThreadsStarted()
2. [Main thread] Start other thread, wait
3. [Other thread] Call registerThread(), notify main thread & continue
4. [Main thread] Wake up & call postExtraThreadsStarted()
When using dx9 system, it works nice!
But in opengl system it still crashes.

Code: Select all

            void* pBufferData = 0;

            if(mCurrentCapabilities->hasCapability(RSC_VBO))
            {
                mStateCacheManager->bindGLBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,
                                static_cast<GLHardwareIndexBuffer*>(
                                    op.indexData->indexBuffer.get())->getGLBufferId());

                pBufferData = VBO_BUFFER_OFFSET(
                    op.indexData->indexStart * op.indexData->indexBuffer->getIndexSize());
            }
...
...
            GLenum indexType = (op.indexData->indexBuffer->getType() == HardwareIndexBuffer::IT_16BIT) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;

            do
            {
                // Update derived depth bias
                if (mDerivedDepthBias && mCurrentPassIterationNum > 0)
                {
                    _setDepthBias(mDerivedDepthBiasBase +
                                  mDerivedDepthBiasMultiplier * mCurrentPassIterationNum,
                                  mDerivedDepthBiasSlopeScale);
                }
                if(hasInstanceData)
                {
                    glDrawElementsInstancedARB(primType, op.indexData->indexCount, indexType, pBufferData, numberOfInstances);
                }
                else
                {
                    glDrawElements(primType, op.indexData->indexCount, indexType, pBufferData);
                }
            } while (updatePassIterationRenderState());
Here crashed on glDrawElements(primType, op.indexData->indexCount, indexType, pBufferData).

Code: Select all

Access Conflict Occurs at 0xC0000005: Read Location 0x00000
I'm not sure what happened here.
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: Can renderOneFrame() running in background thread?

Post by paroj »

there were important bugfixes related to background GL rendering in 1.10.9. Please update to at least 1.10.12.
Whisperd130
Halfling
Posts: 77
Joined: Wed Feb 01, 2017 4:02 pm
x 1

Re: Can renderOneFrame() running in background thread?

Post by Whisperd130 »

Sure, I'm now updating to 1.10.12.
And do I needed to using macro OGRE_THREAD_SUPPORT? Because my renderoneframe() is working on background thread.
Whisperd130
Halfling
Posts: 77
Joined: Wed Feb 01, 2017 4:02 pm
x 1

Re: Can renderOneFrame() running in background thread?

Post by Whisperd130 »

One more question is that I found the OGRE SampleBrowser Code shows the thread will start by function join().

Code: Select all

        // all our threads should have been woken now, so join
        for (WorkerThreadList::iterator i = mWorkers.begin(); i != mWorkers.end(); ++i)
        {
            (*i)->join();
            OGRE_THREAD_DESTROY(*i);
        }
Does the main thread will stop and wait when background thread get a request?
Do both threads work well if I set background thread to detach()?
Post Reply