kovitch
Registered: 09/28/09
Posts: 15
|
Wednesday, January 27 2010 @ 06:37 AM EST |
|
Hi,
I have an application that uses Delta3D. The map is correctly loaded, and everyting seems to work fine. However, I have a problem: Some textures are only loaded when the camera poits at them.
Is there a way to load every textures before starting to navigate in a virutal environment?
Best regards,
Alex. |
|
|
|
|
ufk

Registered: 02/07/07
Posts: 82
|
Wednesday, January 27 2010 @ 08:43 AM EST |
|
you have to compile all the object in the scene at the beginning of the program if you dont want any compilation on viewing...
i will give you the code we use in our programs:
class CompileGLObjectsCallback : public osg::Operation
{
public:
CompileGLObjectsCallback(osg::Node* node):
osg::Operation("CompileStateCallback", false),
_scene(node) {}
virtual void operator () (osg::Object* object)
{
osg::GraphicsContext* context = dynamic_cast<osg::GraphicsContext*>(object);
if (!context) return;
if (_scene)
{
compileTextureObjects(_scene, context->getState());
osgUtil::GLObjectsVisitor compile;
compile.setMode(osgUtil::GLObjectsVisitor::Mode(osgUtil::GLObjectsVisitor::COMPILE_DISPLAY_LISTS |
osgUtil::GLObjectsVisitor::COMPILE_STATE_ATTRIBUTES |
osgUtil::GLObjectsVisitor::SWITCH_ON_DISPLAY_LISTS |
osgUtil::GLObjectsVisitor::SWITCH_ON_VERTEX_BUFFER_OBJECTS |
osgUtil::GLObjectsVisitor::CHECK_BLACK_LISTED_MODES ));
compile.setState(context->getState());
compile.apply(*_scene);
}
}
void compileTextureObjects(osg::Node* node, osg::State* state)
{
osg::ref_ptr<osg::Geode> geode = dynamic_cast<osg::Geode*>(node);
if ( geode != NULL )
{
for(unsigned int j = 0; j < geode->getNumDrawables(); j++)
{
for(unsigned int i = 0; i < 8; i++)
{
osg::Texture2D* textureAttribute = static_cast<osg::Texture2D*>geode->
getOrCreateStateSet()->getTextureAttribute(i, osg::StateAttribute::TEXTURE));
if (textureAttribute != NULL)
{
textureAttribute->compileGLObjects(*state);
}
}
}
}
osg::ref_ptr<osg::Group> group = dynamic_cast<osg::Group*>(node);
if ( group != NULL )
{
for (unsigned int i = 0; i < group->getNumChildren(); i++)
{
compileTextureObjects(group->getChild(i), state);
}
}
}
osg::Node* _scene;
};
in application we use like:
void Application::compileGLObjects(osg::Node* node)
{
CompileGLObjectsCallback* compile = new CompileGLObjectsCallback(node);
osgViewer::CompositeViewer* viewer = GetCompositeViewer();
for (unsigned int i = 0; i < viewer->getNumViews(); i++)
{
osg::View* view = viewer->getView(i);
if (view->getCamera()->getNodeMask() != 0)
{
view->getCamera()->getGraphicsContext()->add(compile);
}
}
}
sorry, since i use the code a little different, i have to change for you. it may not work directly but i gave the main idea...
here we give sceneNode to compileGLObjects than there is no loading textures after starting the frame. |
|
|
|
|
kovitch
Registered: 09/28/09
Posts: 15
|
Monday, February 08 2010 @ 09:06 PM EST |
|
Is there a way to use these functions by converting a dtCore::Object into a osg::Node? That's because I'm loading the osg map into a dtCore::Object, and I believe that it converts all osg nodes into dtCore nodes.
...Or is there another solution?
Regards. |
|
|
|
|
ufk

Registered: 02/07/07
Posts: 82
|
Tuesday, February 09 2010 @ 02:56 AM EST |
|
all dtCore::Object stores an osg::Node inside.
dtCore::Drawable => it has a member osg::Node
^
|
dtCore::Transformable
^
|
dtCore::Object
you can just call GetOSGNode() function on dtCore::Object to get osg::Node |
|
|
|
|