Horde3D http://horde3d.org/forums/ |
|
[SOLVED]Background Resource Loading http://horde3d.org/forums/viewtopic.php?f=2&t=2272 |
Page 1 of 1 |
Author: | aesylwinn [ 19.12.2014, 22:55 ] |
Post subject: | [SOLVED]Background Resource Loading |
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. |
Author: | Siavash [ 20.12.2014, 15:22 ] |
Post subject: | Re: Background Resource Loading |
There is probably something wrong with the way you load materials and/or set their attributes. |
Author: | aesylwinn [ 20.12.2014, 22:29 ] |
Post subject: | Re: Background Resource Loading |
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] ---- |
Author: | Irdis [ 26.12.2014, 19:28 ] |
Post subject: | Re: Background Resource Loading |
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. |
Author: | aesylwinn [ 30.12.2014, 04:58 ] |
Post subject: | Re: Background Resource Loading |
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. |
Page 1 of 1 | All times are UTC + 1 hour |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |