2

I am using the Ogre3d engine supporting OpenGL mode.

I have an object called Chunk which creates an Ogre::ManualObject. Because the creation of the ManualObject takes a bit of time I put the task onto a new thread.

Unfortunately, after threading the creation of the ManualObject I am now getting the following OgreException:

"Cannot create GL vertex buffer in GLHardwareVertexBuffer::GLHardwareVertexBuffer"

I looked into the code and it is failing at this stage:

glGenBuffersARB( 1, &mBufferId );

if (!mBufferId)
{
    OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
        "Cannot create GL vertex buffer",
        "GLHardwareVertexBuffer::
}

This suggests that glGenBuffersARB() is not properly populating mBufferId.

I can't figure out what is causing this, any suggestions?

Razor Storm
  • 12,167
  • 20
  • 88
  • 148

1 Answers1

7

Because the creation of the ManualObject takes a bit of time I put the task onto a new thread.

That's your problem right there. An OpenGL context can be active in only one thread at a time. If you call OpenGL commands from a thread which doesn't have an OpenGL context bound, all you get are errors.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • Ah thank you! So from this it seems that the best course of action is to have one thread dedicated to graphical tasks. What's the proper way to specify which thread should bind the OpenGL context through Ogre? – Razor Storm Apr 11 '13 at 22:12
  • @RazorStorm: Sorry I never used the Ogre engine, so I'd have to dig through documentation first, too. – datenwolf Apr 11 '13 at 22:36
  • Ok, no problem! I'll look into the documentation/source and see if I can find something. – Razor Storm Apr 11 '13 at 22:39