Re: [osg-users] Sharing vertex and normal buffer with another library

2011-02-22 Thread Dženan Zukić
Hi,

That file only contains function prototypes (of functions which exist in cpp 
files).

Cheers,
Dženan

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





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


Re: [osg-users] Sharing vertex and normal buffer with another library

2011-02-22 Thread Nan WANG
Hi,

Sorry, may I ask where is marchingGPU.h header file?
Thank you!

Cheers,
Nan

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





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


Re: [osg-users] Sharing vertex and normal buffer with another library

2010-05-05 Thread Dženan Zukić
Hi,

Thank you for taking interest in my problem.

a) Of course I add geodes to the tree, I just thought that is not an 
interesting part of the code.
[code]rest=marchingCubesGPU(visualizing, highTh, lowTh);
osg::ref_ptr grp=new osg::Group;
grp->addChild(rest); //isosurface
grp->addChild(vert); //interesting parts
mainForm.vis->setSceneData(grp);
mainForm.vis->frame();
//rest->getDrawable(0)->setDrawCallback(0); //causes exceptions
//rest->getDrawable(1)->setDrawCallback(0); //causes exceptions[/code]

b) It is done the same way in the currently working code, and the only possible 
problem is memory leaking. This is a research project, not a production level 
code, and my 12GB of RAM balance out any memory leaks :D

I know I have memory leaks, and I tried once to eliminate them - at least the 
large ones, like leaking the entire 3D image (I narrowed it down to osgVolume, 
but could not do much about it). But my leak finding attempts failed after 
having spent a few days on them. One of the things I tried was compiling it on 
Linux and using Valgrind, but that turned out to be unfeasible, because just 
opening the "Open file dialog" takes 5 minutes when running the program under 
Valgrind, and it floods the output with "definitely leaked 4 byes here and 
possibly 70 bytes there" even while executing only QT code, thus completely 
killing my enthusiasm.

If you find reduced code disadvantageous for pinpointing problem, I attach here 
the whole file - both the currently working version and the attempt to do away 
with copying arrays needlessly. Since it links to HMPC, this code is also under 
GPL, if anyone finds it interesting.

Cheers,
Dženan

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




Attachments: 
http://forum.openscenegraph.org//files/marchinggpu_not_working_137.cpp
http://forum.openscenegraph.org//files/marchinggpu_139.cpp


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


Re: [osg-users] Sharing vertex and normal buffer with another library

2010-05-04 Thread David Spilling
Hi Dženan,

It's very hard to tell from the limited amount of code you have posted,
since it seems to be missing so much, but - and apologies if I'm pointing
out the obvious :

a) You don't ever seem to attach your geode to the scene anywhere

b) The scope of the osg::Geometry* geom in mcHelper looks suspect as it goes
out of scope outside mcHelper. Can I suggest liberaly use of ref_ptr's?

Regards,

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


[osg-users] Sharing vertex and normal buffer with another library

2010-04-30 Thread Dženan Zukić
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