Jump to content

[SOLVED] Save/Restore render state (not RenderState)


photo

Recommended Posts

Hi All,

I'm currently implementing a custom fisheye viewport since the panoramic rendering is not open enough for our needs.

As described in other posts I'm disabling various screen space effects. However, there might be other viewports that still can have the SS effekts enabled.

So in in my FisheyeViewport::render() I want to disable and later reenable the render settings.
Currently the Code looks like this:

void FisheyeViewport::render() {

    // ...

    // save current render settings
//    Unigine::BlobPtr render_settings_blob = Unigine::Blob::create();
//    Unigine::Render::saveState(render_settings_blob);
    Unigine::XmlPtr render_settings = Unigine::Xml::create();
    Unigine::Render::saveWorld(render_settings);

    Unigine::Render::setTAA(false);
    Unigine::Render::setSSAO(false);
    Unigine::Render::setSSR(false);
    Unigine::Render::setWhiteBalance(false);
    Unigine::Render::setExposureMode(Unigine::Render::EXPOSURE_DISABLED);
    Unigine::Render::setExposure(2);
    Unigine::Render::setBloom(false);
    Unigine::Render::setFilmic(false);
    Unigine::Render::setLightsLensFlares(false);

    // do the fisheye rendering
    // ...

    // restore render settings
//    Unigine::Render::restoreState(render_settings_blob);
    Unigine::Render::loadWorld(render_settings);
}

The Render::restoreState() function is marked as deprecated (although it still exists in 2.12). The Render::saveState() function is not marked as deprecated which irritates me as I don't see how to use it without Render::restoreState(). Also using Render::restoreState() as described above results in an Exception:

terminate called after throwing an instance of 'char const*'
Signal: SIGABRT (Aborted)

which is why I switched to using an XML node. This works, but feels more like a workaround.
Whats the intended workflow for saving and restoring the state?

Thanks and greetings!

Link to comment

ipg_jallmenroeder

It looks like a bug in documentation, restoreState() is not deprecated, you can use it. We will update docs ASAP.

The crash you are getting is more likely caused by incorrect work with blob, you need to reset it before accessing:

if (render_settings_blob.getSize()) {
	render_settings_blob.SeekSet(0);
}

Unigine::Render::restoreState(render_settings_blob);

If you plan to re-use this blob later, don't forget to clear it before saving a new state:

render_settings_blob->clear()
Unigine::Render::saveState(render_settings_blob);

Thanks!
 

  • Like 1

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

Thanks, works like a charm now!

There's a tiny but evil mistake in your code: render_settings_blob is a BlobPtr so you need to call render_settings_blob->clear() instead of render_settings_blob.clear() (This is obvious from context most of the time, however Unigine::Ptr has a clear() function as well which causes a segmentation fault here. Maybe you could update your answer)

It would be neat to have something like RenderState::saveState() and RenderState::restoreState() where you dont have to manage the stream yourself, maybe as an improvement.

Thanks for your help!

Greetings

Link to comment
Quote

There's a tiny but evil mistake in your code: render_settings_blob is a BlobPtr so you need to call render_settings_blob->clear() instead of render_settings_blob.clear() (This is obvious from context most of the time, however Unigine::Ptr has a clear() function as well which causes a segmentation fault here. Maybe you could update your answer)

Yep, my bad :) Updated original answer.

 

 

Quote

It would be neat to have something like RenderState::saveState() and RenderState::restoreState() where you dont have to manage the stream yourself, maybe as an improvement.

Do you mean Render::saveState() not RenderState? That would be indeed good addition, but will require a lot of modifications of the engine itself (because not only Render class have save / restore state functionality). So, right now the stream management is mandatory.

Anyway, I will add this feature with a minor priority to our internal to-do list. Can't say the exact ETA for this.

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

Yes, I mean a Render::saveState() that works like RenderState::saveState() (naming is a bit confusing here)

Okay thanks, its not important, just a nice to have.

Link to comment
  • silent changed the title to [SOLVED] Save/Restore render state (not RenderState)
×
×
  • Create New...