Horde3D

Next-Generation Graphics Engine
It is currently 19.03.2024, 05:47

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: 19.12.2014, 22:55 
Offline

Joined: 19.12.2014, 01:30
Posts: 3
Hello!
I'm using Horde3D in my project and have run into some issues with loading resources on a background thread. My resource loader loads a file into memory, then on the main thread I give it to horde to use (only one file is transferred to horde between render calls). Unfortunately, this is causing some graphical errors. I am using the knight scene in the example projects to test this. Also, I am isolating the background loading to the sphere.scene.xml and its dependent resources by loading everything else beforehand.
The result:
-the sphere seems to have an incorrect bounding box because it disappears unless its center is almost on screen
-the sphere has no lighting or shadows, though it is still textured

I think there are two ways I could solve this, but I'm not sure how to go about doing it with Horde3D.
1. Wait for the dependencies of the sphere.scene.xml to load ( I think I might be able to do this using the h3dGetResParam function, though I'm not sure what to look up)
2. Update the internal state of the sphere geometry

Any insight on this is appreciated. :mrgreen:


Last edited by aesylwinn on 30.12.2014, 05:35, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: 20.12.2014, 15:22 
Offline

Joined: 21.08.2008, 11:44
Posts: 354
There is probably something wrong with the way you load materials and/or set their attributes.


Top
 Profile  
Reply with quote  
PostPosted: 20.12.2014, 22:29 
Offline

Joined: 19.12.2014, 01:30
Posts: 3
Well, I'll try to post all the relevant code about resource loading.

edit: These are the only options I am manually setting. Any material settings and such are set when they are loaded, and it works fine if I force it to load all at once.
Code:
h3dSetOption(H3DOptions::LoadTextures, 1);
h3dSetOption(H3DOptions::TexCompression, 0);
h3dSetOption(H3DOptions::FastAnimation, 0);
h3dSetOption(H3DOptions::MaxAnisotropy, 4);
h3dSetOption(H3DOptions::ShadowMapSize, 2048);


Code:
// Resource addition
void ModelAttachment::init(){
    _resHandle = h3dAddResource(H3DResTypes::SceneGraph, _resName.c_str(), 0);
   ...
}

// Task addition - runs on main thread
void ResourceManager::FinalizeResource(){
    ...
    loadedTask->Finalize()
    ...
    if (loadNextHordeRes){
        H3DRes res = h3dQueryUnloadedResource(0);
        if (res != 0){
            HordeResPtr r_ptr = new HordeResPtr(new HordeRes(res));
            HordeResTaskPtr t_ptr = new HordeResTaskPtr(new HordeResTask(r_ptr));
            AddResourceTask(t_ptr);
        }
    }
}

// Runs on a separate thread
void HordeResTask::Load(){
    _dataSize = 0;
    _data = 0;

    std::fstream in;
    in.open(_resource->getFileName(), std::ios::in | std::ios::binary);
    if (in.is_open()){
        in.seekg(0, in.end);
        _dataSize = in.tellg();
        in.seekg(0, in.beg);
        if (_dataSize > 0){
            _data = new char[_dataSize];
            in.read(_data, _dataSize);
        }
        else {
            _resource->_loadFailed = true;
        }
    }
    else {
        _resource->_loadFailed = true;
    }
}

// Runs on main thread
void HordeResTask::Finalize(){
    if (h3dLoadResource(_resource->_resHandle, _data, _dataSize) && !_resource->_loadFailed)
        _resource->_isLoaded = true;
    else
        _resource->_loadFailed = true;

    if (_dataSize > 0){
        delete[] _data;
        _dataSize = 0;
    }
}

// Check before using a resource
bool ModelAttachment::isReady(){
    if (!_ready){
        if (h3dIsResLoaded(_resHandle)){
            _node = h3dAddNodes(H3DRootNode, _resHandle);
            _ready = true;
        }
    }
    return _ready;
}


Some log output if it helps.
Code:
Initializing GL2 backend using OpenGL driver '4.4.0 NVIDIA 344.75' by 'NVIDIA Corporation' on 'GeForce GTX 760/PCIe/SSE2'
Loading resource 'models/knight/knight.scene.xml'
Loading resource 'animations/knight_order.anim'
Loading resource 'animations/knight_attack.anim'
Loading resource 'particles/particleSys1/particleSys1.scene.xml'
Loading resource 'models/knight/knight.geo'
Loading resource 'models/knight/knight.material.xml'
Loading resource 'particles/particleSys1/particle1.material.xml'
Loading resource 'particles/particleSys1/particle1.particle.xml'
Loading resource 'particles/particleSys1/particle2.material.xml'
Loading resource 'particles/particleSys1/particle2.particle.xml'
Loading resource 'shaders/model.shader'
Loading resource 'models/knight/knight.jpg'
Loading resource 'models/skybox/skybox.dds'
Loading resource 'shaders/particle.shader'
Loading resource 'textures/particles/particle1.tga'
Loading resource 'overlays/logo.tga'
Loading resource 'shaders/utilityLib/vertCommon.glsl'
Loading resource 'shaders/utilityLib/vertSkinning.glsl'
---- C O M P I L I N G  . S H A D E R . shaders/model.shader@SHADOWMAP[1] ----
Loading resource 'shaders/utilityLib/fragDeferredWrite.glsl'
---- C O M P I L I N G  . S H A D E R . shaders/model.shader@ATTRIBPASS[1] ----
Loading resource 'shaders/utilityLib/fragLighting.glsl'
---- C O M P I L I N G  . S H A D E R . shaders/model.shader@LIGHTING[1] ----
---- C O M P I L I N G  . S H A D E R . shaders/model.shader@AMBIENT[9] ----
Loading resource 'textures/common/white.tga'
Loading resource 'textures/common/defnorm.tga'
Loading resource 'shaders/utilityLib/vertParticle.glsl'
---- C O M P I L I N G  . S H A D E R . shaders/particle.shader@TRANSLUCENT[0] ----
Loading resource 'models/sphere/sphere.scene.xml'
Loading resource 'pipelines/forward.pipeline.xml'
Loading resource 'pipelines/hdr.pipeline.xml'
Loading resource 'models/sphere/stones.material.xml'
---- C O M P I L I N G  . S H A D E R . shaders/model.shader@ATTRIBPASS[4] ----
---- C O M P I L I N G  . S H A D E R . shaders/model.shader@SHADOWMAP[0] ----
---- C O M P I L I N G  . S H A D E R . shaders/model.shader@LIGHTING[4] ----
---- C O M P I L I N G  . S H A D E R . shaders/model.shader@AMBIENT[4] ----
Loading resource 'pipelines/globalSettings.material.xml'
Loading resource 'pipelines/postHDR.material.xml'
Loading resource 'models/sphere/sphere.geo'
Loading resource 'textures/models/layingrock.jpg'
Loading resource 'textures/ambientMap.dds'
Loading resource 'shaders/postHDR.shader'
---- C O M P I L I N G  . S H A D E R . shaders/postHDR.shader@FINALPASS[0] ----
Loading resource 'textures/models/layingrockBump.tga'
Loading resource 'shaders/utilityLib/fragPostProcess.glsl'
---- C O M P I L I N G  . S H A D E R . shaders/postHDR.shader@BRIGHTPASS[0] ----
---- C O M P I L I N G  . S H A D E R . shaders/postHDR.shader@BLUR[0] ----


Top
 Profile  
Reply with quote  
PostPosted: 26.12.2014, 19:28 
Offline

Joined: 17.11.2009, 17:00
Posts: 205
Location: Russia, Moscow
You should probably load pipeline files and standard shader files before you load the scene. Judging from the log the pipeline is loaded after the scenegraph file. Maybe horde does not handle some parameters correctly in this situation.


Top
 Profile  
Reply with quote  
PostPosted: 30.12.2014, 04:58 
Offline

Joined: 19.12.2014, 01:30
Posts: 3
Thank you for the response. I will attempt this and post my results.

edit:
I discovered that the problem was with the way I was checking if a resource was loaded. It seems horde recognizes a scene xml file as loaded even if the resources it references aren't. A quick fix was to check if the referenced resources were loaded. This fixed shadows as well as the bounding box issues.
Code:
// Previously
if (h3dIsResLoaded(_sceneRes)){
  // The resource may be unloaded still
}

// Quick fix for sphere geo
if (h3dIsResLoaded(_geoRes) && h3dIsResLoaded(_matRes) && h3dIsResLoaded(_sceneRes)){
  // The resource is actually loaded
}


Thank you for the help. :)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group