[osg-users] Invalid GL buffer object

62 views
Skip to first unread message

Sajjadul Islam

unread,
Oct 14, 2013, 3:35:21 AM10/14/13
to osg-...@lists.openscenegraph.org
Hi forum,

I am getting the invalid buffer object with the following source snippet:


Code:

.......................
.......................

osg::VertexBufferObject* vbo = _m_clGeomRef->getOrCreateVertexBufferObject();

if(!vbo)
{
osg::notify(osg::FATAL)
<< __FUNCTION__ <<": " << __LINE__ << ": "
<< _m_clGeomRef->getName() << ": no buffer object found."
<< std::endl;

return false;
} // END OF - !vbo

//get the context id
unsigned int contextID = osgCompute::GLMemory::getContext()->getState()->getContextID();

//compile vertex buffer
osg::GLBufferObject *glBO = vbo->getOrCreateGLBufferObject( contextID );

if( !glBO )
{
osg::notify(osg::FATAL)
<< __FUNCTION__ <<": " << __LINE__ << ": "
<< _m_clGeomRef->getName() << ": no GL buffer object found."
<< std::endl;

return false;
} // END OF - !glBO

if( glBO->isDirty())
{
osg::GLBufferObject::Extensions* ext = osg::GLBufferObject::getExtensions( osgCompute::GLMemory::getContext()->getState()->getContextID(),true);

if(!ext)
{
osg::notify(osg::FATAL)
<< __FUNCTION__ <<": " << __FUNCTION__ << ": "
<< _m_clGeomRef->getName() << ": cannot find required extensions to compile buffer object."
<< std::endl;

return false;
}

//the following function call the glBufferData()
glBO->compileBuffer();

//unbind the buffer objects
ext->glBindBuffer(GL_ARRAY_BUFFER_ARB,0);
ext->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,0);

} // END OF - glBO->isDirty()

//avoid copy operation during osgCompute::MAP_HOST
memory._m_clLastModifiedCount.clear();

for( unsigned int d = 0; d < vbo->getNumBufferData(); ++d )
memory._m_clLastModifiedCount.push_back( vbo->getBufferData(d)->getModifiedCount());

GLuint objectid = glBO->getGLObjectID();

//create the vertex buffer from the gl buffer object
(memory._m_clDevBuffer) = clCreateFromGLBuffer(cxt->_m_clContext, // the valid opencl context
CL_MEM_READ_WRITE, // the memory has both the read and write access
objectid,
&errNum);

if( errNum != CL_SUCCESS )
{
osg::notify(osg::FATAL)
<< __FUNCTION__ <<": " << __LINE__ << ": "
<< _m_clGeomRef->getName() << ": unable to create opencl buffer object (clCreateFromGLBuffer): "
<< cxt->getErrorString(errNum) <<"."
<< std::endl;

return false;
}

.......................
.......................




As you can see that there is also one line of OpenCL code snippet where i am trying to create an OpenCL buffer from the OpenGL buffer object. But the buffer creation is not successful because the error string is telling that the
Code:
GLuint objectid = glBO->getGLObjectID();

is not returning the valid GL buffer object id or GL buffer object does not have an existing data store. I guess that i have to make it sure on the OSG side. AND this is where i seek your help.

Could you provide me with some hint to make sure that i got the valid GL buffer object and GL buffer object do have the existing data store. Please make some time to go through the code i have pasted above and let me know if i have missed something or at least where to look into.

Thank you!

Regards,
Sajjadul

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=56774#56774





_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Sajjadul Islam

unread,
Oct 17, 2013, 6:40:33 PM10/17/13
to osg-...@lists.openscenegraph.org
Hi Forum,

It has been a while and i did not get any feed-back over my last post. I realized that i was not clear enough in my explanation. Let me try again.

I store the current graphics context and part of the code snippet shows that the current context is stored:


Code:

void Context::operator() (osg::GraphicsContext *gc)
{
if(gc->getState() == NULL)
{
osg::notify(osg::FATAL) << __FUNCTION__ << ": "
<< "osg::GraphicsContext must have a valid state. "
<< std::endl;
exit(EXIT_FAILURE);
}

//make this context current if not the current context
if(!gc->isCurrent())
gc->makeCurrent();

.................................

..................................

// Bind context to osgCompute::GLMemory
if( osgCompute::GLMemory::getContext() == NULL )
osgCompute::GLMemory::bindToContext( *gc );

.................................

.................................
}




As you can see that inside the realize operation i store the current context for later reference.

Now i use this context reference id to create the buffer object as follows:


Code:


......................
......................
//get or create a vertex buffer object from the geometry
osg::VertexBufferObject *vbo = _m_clGeomRef->getOrCreateVertexBufferObject();

//make sure that we have the vertex buffer object
//AND i checked the vbo creation is successful
if(!vbo)
return NULL;

......................................
......................................

//get the buffer object
// I HAVE THE PROBLEM WITH THE FOLLOWING STATEMENT.
// event though i get a valid pointer to glBO, i checked though the debugger that
//glGenBuffers is generating a buffer id with 0 value
osg::GLBufferObject *glBO = vbo->getOrCreateGLBufferObject(osgCompute::GLMemory::getContext()->getState()->getContextID());

//make sure that we have the buffer object
if(!glBO)
return NULL;






I have no idea why am i getting 0 value for the buffer id with glGenBuffers(..) call inside the constructor of GLBufferObject() - the class that came along with the repository.

I am using the context id that i have stored inside the realize operation.

Any hint on what might have went wrong ? Where should i look into ?

I shall be eagerly looking forward to your hint over this issue.

Thanks,
Sajjadul

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=56839#56839

Sajjadul Islam

unread,
Oct 17, 2013, 6:46:32 PM10/17/13
to osg-...@lists.openscenegraph.org
Hi Forum,

I forgot to mention that i get a valid glBO pointer even though i have 0 buffer object id with
glGenBuffers(..)

Thank you!

Cheers,
Sajjadul

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=56840#56840

Robert Osfield

unread,
Oct 18, 2013, 1:48:52 AM10/18/13
to OpenSceneGraph Users
Hi Sajjadul,

I really don't know specifically what might be wrong with what you are doing, I can't make sense of the code snippets, it's the wider context that would probably illustrate what is going wrong.

The best I can do is mention that importance of only doing OpenGL calls from a thread with a valid graphics context, if you don't they you are likely to get errors or crashes simply because OpenGL requires the valid graphics context to be current.

Robert.

Sajjadul Islam

unread,
Oct 18, 2013, 2:53:40 AM10/18/13
to osg-...@lists.openscenegraph.org
Thanks Robert,

I am not calling glGenBuffers() in my code. I am calling the following :


Code:

osg::GLBufferObject *glBO = vbo->getOrCreateGLBufferObject(osgCompute::GLMemory::getContext()->getState()->getContextID());




Since i am getting undefined behavior, i used the debugger to get inside the above statement and found that i am having the issue inside the GLBufferObject constructor.


Code:

GLBufferObject::GLBufferObject(unsigned int contextID, BufferObject* bufferObject, unsigned int glObjectID):
_contextID(contextID),
_glObjectID(glObjectID),
_profile(0,0,0),
_allocatedSize(0),
_dirty(true),
_bufferObject(0),
_set(0),
_previous(0),
_next(0),
_frameLastUsed(0),
_extensions(0)
{
assign(bufferObject);

_extensions = GLBufferObject::getExtensions(contextID, true);

if (glObjectID==0)
{
_extensions->glGenBuffers(1, &_glObjectID);
}

// OSG_NOTICE<<"Constucting BufferObject "<<this<<std::endl;
}




The immediate above snippet is from the BufferObject file that came along with the API.

And i found that _glObjectID is carrying the value 0 even after call:


Code:

_extensions->glGenBuffers(1, &_glObjectID);




I believe that 0 is not a valid value here.

Any more thoughts ?

Regards,
Sajjadul

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=56844#56844

Robert Osfield

unread,
Oct 18, 2013, 4:50:48 AM10/18/13
to OpenSceneGraph Users
Hi Sajjadul,

As I said I don't know what is going amiss in your code. Debugging this type of thing really requires a proper overview of all the code and ideally testable code.  This level of support is something I can provide.

Perhaps if you can't manage the wiring up of OpenCL and the OSG yourself you should look for 3rd party example codes that do it.  I haven't personally implemented OpenCL and OSG integation so can't help directly.

Robert.
Reply all
Reply to author
Forward
0 new messages