From ee227aaf9cad281846d3874ae38597b06df3ae2a Mon Sep 17 00:00:00 2001 From: kaetemi Date: Thu, 4 Jul 2013 22:18:19 +0200 Subject: [PATCH] Refactor fulldetail override --- .../src/interface_v3/action_handler_misc.cpp | 2 +- code/ryzom/client/src/landscape_poly_drawer.h | 6 +- code/ryzom/client/src/main_loop.cpp | 93 ++++++++++++------- code/ryzom/client/src/main_loop.h | 3 +- 4 files changed, 66 insertions(+), 38 deletions(-) diff --git a/code/ryzom/client/src/interface_v3/action_handler_misc.cpp b/code/ryzom/client/src/interface_v3/action_handler_misc.cpp index 6a21858f5..7a68f7872 100644 --- a/code/ryzom/client/src/interface_v3/action_handler_misc.cpp +++ b/code/ryzom/client/src/interface_v3/action_handler_misc.cpp @@ -542,7 +542,7 @@ void renderSceneScreenShot (uint left, uint right, uint top, uint bottom, uint s CCameraBackup cbScene = setupCameraForScreenshot(*Scene, left, right, top, bottom, screenShotWidth, screenShotHeight); CCameraBackup cbCanopy = setupCameraForScreenshot(*SceneRoot, left, right, top, bottom, screenShotWidth, screenShotHeight); // sky setup are copied from main scene before rendering so no setup done here - renderAll(ClientCfg.ScreenShotFullDetail); + renderScene(ClientCfg.ScreenShotFullDetail); restoreCamera(*Scene, cbScene); restoreCamera(*SceneRoot, cbCanopy); } diff --git a/code/ryzom/client/src/landscape_poly_drawer.h b/code/ryzom/client/src/landscape_poly_drawer.h index 0012b5dcb..73d7fcadc 100644 --- a/code/ryzom/client/src/landscape_poly_drawer.h +++ b/code/ryzom/client/src/landscape_poly_drawer.h @@ -95,11 +95,11 @@ public: private: - // renderAll is called in main loop. It can called beginRenderLandscapePolyPart and renderLandscapePolyPart + // renderScene is called in main loop. It can called beginRenderLandscapePolyPart and renderLandscapePolyPart // methods. - friend void renderAll(bool); + friend void renderScene(); - // Enable stencil test and initialize function and operation of stencil at the beginning of renderAll method, + // Enable stencil test and initialize function and operation of stencil at the beginning of renderScene method, // before opaque render of canopy and main scene parts. // The eighth bit will be written with a 0 during next render to mark stencil buffer parts which will // support Shadow Volume algorithm. diff --git a/code/ryzom/client/src/main_loop.cpp b/code/ryzom/client/src/main_loop.cpp index 7338493c1..6e11d3a2a 100644 --- a/code/ryzom/client/src/main_loop.cpp +++ b/code/ryzom/client/src/main_loop.cpp @@ -487,10 +487,55 @@ static void renderSkyPart(UScene::TRenderPart renderPart, TSkyMode skyMode) #endif } +struct CForceFullDetail +{ +public: + void backup() + { + maxFullDetailChar = Scene->getMaxSkeletonsInNotCLodForm(); + oldBalancingMode = Scene->getPolygonBalancingMode(); + oldSkyBalancingMode = UScene::PolygonBalancingOff; + UScene *skyScene = getSkyScene(); + if (skyScene) oldSkyBalancingMode = skyScene->getPolygonBalancingMode(); + } + void set() + { + Scene->setMaxSkeletonsInNotCLodForm(1000000); + Scene->setPolygonBalancingMode(UScene::PolygonBalancingOff); + UScene *skyScene = getSkyScene(); + if (skyScene) skyScene->setPolygonBalancingMode(UScene::PolygonBalancingOff); + } + void restore() + { + Scene->setMaxSkeletonsInNotCLodForm(maxFullDetailChar); + Scene->setPolygonBalancingMode(oldBalancingMode); + UScene *skyScene = getSkyScene(); + if (skyScene) skyScene->setPolygonBalancingMode(oldSkyBalancingMode); + } +private: + uint maxFullDetailChar; + UScene::TPolygonBalancingMode oldBalancingMode; + UScene::TPolygonBalancingMode oldSkyBalancingMode; +}; +static CForceFullDetail s_ForceFullDetail; + +void renderScene(bool forceFullDetail) +{ + if (forceFullDetail) + { + s_ForceFullDetail.backup(); + s_ForceFullDetail.set(); + } + renderScene(); + if (forceFullDetail) + { + s_ForceFullDetail.restore(); + } +} // *************************************************************************************************************************** // Render all scenes -void renderAll(bool forceFullDetail) +void renderScene() { if (ClientCfg.Bloom) { @@ -501,26 +546,6 @@ void renderAll(bool forceFullDetail) CBloomEffect::getInstance().initBloom(); } - // backup old balancing mode - uint maxFullDetailChar = Scene->getMaxSkeletonsInNotCLodForm(); - UScene *skyScene = getSkyScene(); - UScene::TPolygonBalancingMode oldBalancingMode = Scene->getPolygonBalancingMode(); - UScene::TPolygonBalancingMode oldSkyBalancingMode = UScene::PolygonBalancingOff; - if (skyScene) - { - oldSkyBalancingMode = skyScene->getPolygonBalancingMode(); - } - // disable load balancing for that frame only if asked - if (forceFullDetail) - { - Scene->setMaxSkeletonsInNotCLodForm(1000000); - Scene->setPolygonBalancingMode(UScene::PolygonBalancingOff); - if (skyScene) - { - skyScene->setPolygonBalancingMode(UScene::PolygonBalancingOff); - } - } - { H_AUTO_USE ( RZ_Client_Main_Loop_Sky_And_Weather ) @@ -649,17 +674,6 @@ void renderAll(bool forceFullDetail) // reset depth range Driver->setDepthRange(0.f, CANOPY_DEPTH_RANGE_START); - // restore load balancing mode - if (forceFullDetail) - { - Scene->setMaxSkeletonsInNotCLodForm(maxFullDetailChar); - Scene->setPolygonBalancingMode(oldBalancingMode); - if (skyScene) - { - skyScene->setPolygonBalancingMode(oldSkyBalancingMode); - } - } - // apply bloom effect if (ClientCfg.Bloom) CBloomEffect::getInstance().endBloom(); @@ -1524,7 +1538,20 @@ bool mainLoop() Scene->updateWaterEnvMaps(TimeInSec - FirstTimeInSec); } #endif - renderAll(ScreenshotRequest != ScreenshotRequestNone && ClientCfg.ScreenShotFullDetail); // nb : force full detail if a screenshot is asked + + // nb : force full detail if a screenshot is asked + // todo : move outside render code + bool fullDetail = ScreenshotRequest != ScreenshotRequestNone && ClientCfg.ScreenShotFullDetail; + if (fullDetail) + { + s_ForceFullDetail.backup(); + s_ForceFullDetail.set(); + } + renderScene(); + if (fullDetail) + { + s_ForceFullDetail.restore(); + } // for that frame and // tmp : display height grid diff --git a/code/ryzom/client/src/main_loop.h b/code/ryzom/client/src/main_loop.h index c8cd0af5a..f2f650b3e 100644 --- a/code/ryzom/client/src/main_loop.h +++ b/code/ryzom/client/src/main_loop.h @@ -29,7 +29,8 @@ const uint NUM_MISSION_OPTIONS = 8; bool mainLoop(); // render all -void renderAll(bool forceFullDetail = false); +void renderScene(); +void renderScene(bool forceFullDetail); void setDefaultChatWindow(CChatWindow *defaultChatWindow); void updateDayNightCycleHour();