Hi,
I am using HPMC library
(http://www.sintef.no/Projectweb/Heterogeneous-Computing/Research-Topics/Marching-Cubes-using-Histogram-Pyramids/)
to do isosurface extraction. Currently I do it like this:
1)create buffers for vertices and normals
2)have this lib fill it with data (lib is meant to display it, but I record it
using TransformFeedback)
3)copy it into osg arrays (which are used in drawable)
4)delete buffers
To avoid copying back and forth, I tried restructuring the code this way:
1)query number of vertices/normals
2)create osg arrays (for vertices and normals) of this size
3)install draw callback for drawable
4)try to access buffer associated with vertex and normal arrays
5)give those ids to MC library
But it doesn't work - there is no visible surface as a result.
Old code:
Code:
GLuint N = HPMCacquireNumberOfVertices( hp );
glBindBuffer( GL_ARRAY_BUFFER, mc_tri_vbo );
glBufferData( GL_ARRAY_BUFFER, 3*N*sizeof(GLfloat), NULL, GL_DYNAMIC_READ
);//xyz of vec3
//set up transform feedback
glBindBufferBase( GL_TRANSFORM_FEEDBACK_BUFFER, 0, mc_normal_vbo );
glBindBufferBase( GL_TRANSFORM_FEEDBACK_BUFFER, 1, mc_tri_vbo );
HPMCextractVerticesTransformFeedback(th, flipNormals);
//create geometry
glBindBuffer( GL_ARRAY_BUFFER, mc_tri_vbo );
GLfloat *vert=(GLfloat *)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY);
memcpy(&tris->at(0), vert, N*3*sizeof(GLfloat));
New code (does not work):
Code:
class myDrawCallback : public osg::Drawable::DrawCallback
{
public:
void drawImplementation(osg::RenderInfo& ri, const osg::Drawable* dr)
const
{
const osg::Geometry* geomConst = dynamic_cast(dr);
osg::Geometry* geom = const_cast(geomConst);
osg::VertexBufferObject *vbuf =
geom->getNormalArray()->getVertexBufferObject();
osg::VertexBufferObject *nbuf =
geom->getVertexArray()->getVertexBufferObject();
vbuf->compileBuffer( *ri.getState() );
nbuf->compileBuffer( *ri.getState() );
glBindBufferBase( GL_TRANSFORM_FEEDBACK_BUFFER, 0,
nbuf->buffer(ri.getContextID()) );
glBindBufferBase( GL_TRANSFORM_FEEDBACK_BUFFER, 1,
vbuf->buffer(ri.getContextID()) );
HPMCextractVerticesTransformFeedbackNV(...);
geom->drawImplementation(ri);
geom->setUseVertexBufferObjects(false);
}
} cb;
osg::Geometry* mcHelper(int isolevel)
{
N = HPMCacquireNumberOfVertices( hp );
osg::Geometry* geom = new osg::Geometry();
osg::Vec3Array* tris = new osg::Vec3Array;
osg::Vec3Array* normals = new osg::Vec3Array;
tris->resize(N);
normals->resize(N);
geom->setVertexArray(tris);
geom->setNormalArray(normals);
geom->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
geom->addPrimitiveSet(new
osg::DrawArrays(osg::PrimitiveSet::TRIANGLES,0,tris->size()));
cb.refCount++;
geom->setDrawCallback(&cb);
geom->setUseVertexBufferObjects(true);
return geom;
}
void marchingCubes()
{
glewInit();
//set up transform feedback
geode->addChild(mcHelper(isolevel1));
geode->addChild(mcHelper(isolevel2));
viewer.frame(); //execute callbacks once
}
Do you know what I am doing wrong? I have been trying to see whether MC lib and
osg run in same GL context, but I have not been able to find a way to see (in
debugger) what is the value of current context handle in the callback
procedure. I browsed through RenderInfo members and sub-members of different
levels, but could not find an instance of _hglrc variable, because that is
comparable to return value of wglGetCurrentContext (which returns 65537).
Thank you!
Cheers,
Dženan
--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=27468#27468
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org