void ClientApplication::run() { Ogre::Root* root = mGraphicsManager->getRoot(); Ogre::RenderWindow* window = mGraphicsManager->getWindow(); root->getRenderSystem()->_initRenderTargets(); root->clearEventTimes(); boost::timer timer; while( !mShutdown ) { if( mShutdownRequested ) { mStateMachine->popTo( 0 ); mShutdown = true; } const Real elapsed = timer.elapsed(); timer.restart(); mEarlyUpdateSignal(); mEarlyFrameSignal( elapsed ); mUpdateSignal(); mFrameSignal( elapsed ); mLateUpdateSignal(); mLateFrameSignal( elapsed ); Ogre::WindowEventUtilities::messagePump(); // Render even when the window is inactive. if( window->isActive() ) { root->renderOneFrame(); } else if( window->isVisible() ) { root->renderOneFrame(); window->update(); #if DIVERSIA_PLATFORM == DIVERSIA_PLATFORM_WIN32 Sleep( ( 1.0 / 60.0 ) * 1000.0 ); #else usleep( ( 1.0 / 60.0 ) * 1000000.0 ); #endif } else if( !window->isActive() && !window->isVisible() ) { #if DIVERSIA_PLATFORM == DIVERSIA_PLATFORM_WIN32 Sleep( ( 1.0 / 60.0 ) * 1000.0 ); #else usleep( ( 1.0 / 60.0 ) * 1000000.0 ); #endif } } }
//--------------------------------------------------------------------- unsigned long renderThreadApp(Ogre::ThreadHandle* threadHandle) { LeDernierMorkid::LeDernierMorkidThreadData* threadData = reinterpret_cast<LeDernierMorkid::LeDernierMorkidThreadData*>(threadHandle->getUserParam()); GraphicsSystem* graphicsSystem = threadData->graphicsSystem; Ogre::Barrier* barrier = threadData->barrier; graphicsSystem->initialize("Le Dernier Morkid"); graphicsSystem->getInputHandler()->setGrabMousePointer(true); graphicsSystem->getInputHandler()->setMouseVisible(false); barrier->sync(); if (graphicsSystem->getQuit()) { graphicsSystem->deinitialize(); return 0; // User cancelled config } graphicsSystem->createScene(); barrier->sync(); Ogre::RenderWindow* renderWindow = graphicsSystem->getRenderWindow(); Ogre::Timer timer; unsigned long startTime = timer.getMicroseconds(); double timeSinceLast = 1.0 / 60.0; while (!graphicsSystem->getQuit()) { graphicsSystem->beginFrameParallel(); graphicsSystem->update(timeSinceLast); graphicsSystem->finishFrameParallel(); if (!renderWindow->isVisible()) { // Don't burn CPU cycles unnecessary when we're minimized. Ogre::Threads::Sleep(500); } unsigned long endTime = timer.getMicroseconds(); timeSinceLast = (endTime - startTime) / 1000000.0; timeSinceLast = std::min(1.0, timeSinceLast); // Prevent from going haywire. startTime = endTime; } barrier->sync(); graphicsSystem->destroyScene(); barrier->sync(); graphicsSystem->deinitialize(); barrier->sync(); return 0; }
int main(int argc, const char *argv[]) { //GameState *graphicsGameState = 0; //GraphicsSystem *graphicsSystem = 0; //GameState *logicGameState = 0; OGraphics::LogicSystem *logicSystem = 0; #if USE_F3D 1 OGraphics::Forward3DGameState *graphicsGameState = new OGraphics::Forward3DGameState( "Forward3D & Clustered are techniques capable of rendering many lights. It is required in order\n" "to render non-shadow casting non-directional lights with the PBS implementation.\n" "Deferred shading has a lot of problems (transparency, antialiasing, multiple BDRF). Besides,\n" "it uses a lot of bandwidth. Forward+/Forward2.5 is great, but requires DX11 HW (needs UAV) and\n" "a Z-Prepass. This Z-prepass is often a turn off for many (even though in some cases it may\n" "improve performance, i.e. if you’re heavily pixel shader or ROP [Raster OPeration] bound).\n" "It’s not superior on all accounts, but it can work on DX10 hardware and doesn’t require a\n" "Z-prepass. The result is a nice generic algorithm that can run on a lot of hardware and can\n" "handle a lot of lights. Whether it performs better or worse than Deferred or Forward+ depends\n" "on the scene.\n" "\n\n" "Like its alternatives Defered & Forward+, it works best with many small lights, or few big\n" "lights.\n" "Forward3D & Clustered have many parameters, and this demo shows different presets that often\n" "trade quality for speed; but sometimes some presets work better on some scenarios than others.\n" "This demo stresses the implementation, showing you both its strengths and limitations\n" " 1. Increase the number of lights to show the artifacts.\n" " 2. Decrease the lights' radius to alleviate the artifacts.\n" " 3. Switch profiles to see the differences. Often profile 0 & 5 work best.\n" " 4. Repeat steps 1 through 3 using a High threshold.\n" " 5. It may be better to have fewer but bigger lights in outdoor scenes\n" " 6. Lights are 'lodded' based on distance to camera as a side effect of how the algorithm works\n" "It is quite unrealistic that all lights to have the same parameters. Heterogenous\n" "light parameters will give you better results.\n" "Also avoid keeping too many lights tight in the same place. If we increase the distance\n" "between each light in this sample, the artifacts begin to disappear.\n" "Light's size has a direct impact on quality. Theoretically all lights have an unlimited\n" "range. However we cut it off after certain threshold for performance reasons. Very low\n" "thresholds stress the F3D system, but very high thresholds will cut the light too early.\n" "\n" "Forward+ and Deferred as alternative implementations are planned in the future.\n" "\n" "This sample depends on the media files:\n" " * Samples/Media/2.0/scripts/Compositors/ShadowMapDebugging.compositor"); OGraphics::Forward3DGraphicsSystem *graphicsSystem = new OGraphics::Forward3DGraphicsSystem(graphicsGameState); #endif #if USE_TERRIAN 1 OGraphics::Tutorial_TerrainGameState *graphicsGameState = new OGraphics::Tutorial_TerrainGameState( "--- !!! NOTE: THIS SAMPLE IS A WORK IN PROGRESS !!! ---\n" "This is an advanced tutorial that shows several things working together:\n" " * Own Hlms implementation to render the terrain\n" " * Vertex buffer-less rendering: The terrain is generated purely using SV_VertexID " "tricks and a heightmap texture\n" " * Hlms customizations to PBS to make terrain shadows affect regular objects\n" " * Compute Shaders to generate terrain shadows every frame\n" " * Common terrain functionality such as loading the heightmap, generating normals, LOD.\n" "The Terrain system is called 'Terra' and has been isolated under the Terra folder like\n" "a component for easier copy-pasting into your own projects.\n\n" "Because every project has its own needs regarding terrain rendering, we're not providing\n" "Terra as an official Component, but rather as a tutorial; where users can copy paste our\n" "implementation and use it as is, or make their own tweaks or enhancements.\n\n" "This sample depends on the media files:\n" " * Samples/Media/2.0/scripts/Compositors/Tutorial_Terrain.compositor\n" " * Samples/Media/2.0/materials/Tutorial_Terrain/*.*\n" " * Samples/Media/2.0/materials/Common/GLSL/GaussianBlurBase_cs.glsl\n" " * Samples/Media/2.0/materials/Common/HLSL/GaussianBlurBase_cs.hlsl\n" " * Samples/Media/Hlms/Terra/*.*\n"); OGraphics::Tutorial_TerrainGraphicsSystem *graphicsSystem = new OGraphics::Tutorial_TerrainGraphicsSystem(graphicsGameState); #endif graphicsGameState->_notifyGraphicsSystem(graphicsSystem); graphicsSystem->initialize(OGraphics::getWindowTitle()); if (logicSystem) logicSystem->initialize(); if (graphicsSystem->getQuit()) { if (logicSystem) logicSystem->deinitialize(); graphicsSystem->deinitialize(); if (graphicsSystem) delete graphicsSystem; if (graphicsGameState) delete graphicsGameState; return 0; //User cancelled config } Ogre::RenderWindow *renderWindow = graphicsSystem->getRenderWindow(); graphicsSystem->createScene01(); if (logicSystem) logicSystem->createScene01(); graphicsSystem->createScene02(); if (logicSystem) logicSystem->createScene02(); #if OGRE_USE_SDL2 //Do this after creating the scene for easier the debugging (the mouse doesn't hide itself) OGraphics::SdlInputHandler *inputHandler = graphicsSystem->getInputHandler(); inputHandler->setGrabMousePointer(true); inputHandler->setMouseVisible(false); #endif Ogre::Timer timer; #if KYLE_TUTORIAL_GAME_LOOP 1 unsigned long startTime = timer.getMicroseconds(); double accumulator = OGraphics::FRAMETIME; double timeSinceLast = OGraphics::FRAMETIME; while (!graphicsSystem->getQuit()) { while (accumulator >= OGraphics::FRAMETIME && logicSystem) { logicSystem->beginFrameParallel(); logicSystem->update(static_cast<float>(OGraphics::FRAMETIME)); logicSystem->finishFrameParallel(); logicSystem->finishFrame(); graphicsSystem->finishFrame(); accumulator -= OGraphics::FRAMETIME; } graphicsSystem->beginFrameParallel(); graphicsSystem->update(static_cast<float>(timeSinceLast)); graphicsSystem->finishFrameParallel(); if (!logicSystem) graphicsSystem->finishFrame(); if (!renderWindow->isVisible()) { //Don't burn CPU cycles unnecessary when we're minimized. Ogre::Threads::Sleep(500); } unsigned long endTime = timer.getMicroseconds(); timeSinceLast = (endTime - startTime) / 1000000.0; // Presumably puts it in milliseconds timeSinceLast = std::min(1.0, timeSinceLast); //Prevent from going haywire. accumulator += timeSinceLast; startTime = endTime; } #else double dt = OGraphics::FRAMETIME; unsigned long startTime = timer.getMicroseconds(); unsigned long nowTime = 0; while (!graphicsSystem->getQuit()) { graphicsSystem->beginFrameParallel(); graphicsSystem->update(static_cast<float>(dt)); graphicsSystem->finishFrameParallel(); // KYLE :: WHAT THE HELL IS THIS? if (!logicSystem) graphicsSystem->finishFrame(); do { nowTime = timer.getMicroseconds(); dt = ((nowTime - startTime) / 1000000.0); dt = std::min(1.0, dt); } while (dt < OGraphics::FRAMETIME); startTime = nowTime; } #endif graphicsSystem->destroyScene(); if (logicSystem) { logicSystem->destroyScene(); logicSystem->deinitialize(); } graphicsSystem->deinitialize(); if (graphicsSystem) delete graphicsSystem; if (graphicsGameState) delete graphicsGameState; return 0; }
int mainApp() #endif { PbsMaterialsGameState pbsMaterialsGameState( "Shows how to use the PBS material system. There's nothing really fancy,\n" "it's just programmer art. The PBS materials can be setup from script or\n" "code. This sample does both. At the time being, not all settings from the\n" "PBS implementation can be tweaked with scripts. See PbsDatablock::PbsDatablock\n" "constructor documentation. Also see the Hlms section of the porting guide in\n" "the Docs/2.0 folder.\n" "\n" "The sphere palette shows what happens when tweaking the roughness around the\n" "X axis; and the fresnel term around the Z axis.\n" "The scene is being lit by a white directional light (3-split PSSM) and two spot\n" "lights, one of warm colour, one cold. Both are also shadowed." "\n" "Of all the features supported by the PBS implementation, perhaps the hardest to\n" "to understand is the Detail Weight Map. It allows you to 'paint' the detail maps\n" "over the mesh, by controlling weight of each of the 4 maps via the RGBA channels\n" "of the weight map. 'R' controls the detail map 0, 'G' the detail map 1,\n" "'B' the detail map 2, and 'A' the detail map 3.\n" "\n" "This sample depends on the media files:\n" " * Samples/Media/2.0/scripts/Compositors/PbsMaterials.compositor\n" " * Samples/Media/2.0/materials/PbsMaterials/PbsMaterials.material\n" "\n" "Known issues:\n" " * Non shadow casting point & spot lights require Forward3D to be enabled (on desktop).\n" " This is by design (more implementations will come: Forward+ & Deferred; for now the\n" " only one working is F3D).\n" " * Shadow casting point lights don't work or work poorly. (feature not implemented yet)\n" " * If PSSM shadow casting enabled, the system requires at least one shadow-casting\n" " directional light (bug)\n" " * Mobile version only supports forward lighting.\n" "\n" "LEGAL: Uses Saint Peter's Basilica (C) by Emil Persson under CC Attrib 3.0 Unported\n" "See Samples/Media/materials/textures/Cubemaps/License.txt for more information."); PbsMaterialsGraphicsSystem graphicsSystem( &pbsMaterialsGameState ); pbsMaterialsGameState._notifyGraphicsSystem( &graphicsSystem ); graphicsSystem.initialize( "PBS Materials Sample" ); if( graphicsSystem.getQuit() ) { graphicsSystem.deinitialize(); return 0; //User cancelled config } Ogre::RenderWindow *renderWindow = graphicsSystem.getRenderWindow(); graphicsSystem.createScene01(); graphicsSystem.createScene02(); graphicsSystem.SetUpCustomContent(); // create my custom contents //Do this after creating the scene for easier the debugging (the mouse doesn't hide itself) SdlInputHandler *inputHandler = graphicsSystem.getInputHandler(); inputHandler->setGrabMousePointer( true ); inputHandler->setMouseVisible( false ); Ogre::Timer timer; unsigned long startTime = timer.getMicroseconds(); double timeSinceLast = 1.0 / 60.0; while( !graphicsSystem.getQuit() ) { graphicsSystem.CustomUpdate(); // update my custom rtts graphicsSystem.beginFrameParallel(); graphicsSystem.update( static_cast<float>( timeSinceLast ) ); graphicsSystem.finishFrameParallel(); graphicsSystem.finishFrame(); if( !renderWindow->isVisible() ) { //Don't burn CPU cycles unnecessary when we're minimized. Ogre::Threads::Sleep( 500 ); } unsigned long endTime = timer.getMicroseconds(); timeSinceLast = (endTime - startTime) / 1000000.0; timeSinceLast = std::min( 1.0, timeSinceLast ); //Prevent from going haywire. startTime = endTime; } graphicsSystem.destroyScene(); graphicsSystem.deinitialize(); return 0; }
void Main::EnterMainLoop() { /* Setup 3D engine */ OgreSubsystem* ror_ogre_subsystem = RoR::Application::GetOgreSubsystem(); assert(ror_ogre_subsystem != nullptr); m_viewport = ror_ogre_subsystem->GetRenderWindow()->addViewport(nullptr); int viewport_width = m_viewport->getActualWidth(); m_viewport->setBackgroundColour(m_config->viewport_background_color); m_camera->setAspectRatio(m_viewport->getActualHeight() / viewport_width); m_viewport->setCamera(m_camera); InitializeOrRestoreGui(); /* Setup input */ RoR::Application::GetInputEngine()->SetKeyboardListener(m_input_handler); RoR::Application::GetInputEngine()->SetMouseListener(m_input_handler); /* Show debug box */ m_debug_box->setVisible(true); while (! m_exit_loop_requested) { UpdateMainLoop(); Ogre::RenderWindow* rw = RoR::Application::GetOgreSubsystem()->GetRenderWindow(); if (rw->isClosed()) { RoR::Application::GetMainThreadLogic()->RequestShutdown(); break; } /* Render */ RoR::Application::GetOgreSubsystem()->GetOgreRoot()->renderOneFrame(); if (!rw->isActive() && rw->isVisible()) { rw->update(); // update even when in background ! } } /* Hide GUI */ m_gui_menubar->Hide(); if (m_gui_open_save_file_dialog->isModal()) { m_gui_open_save_file_dialog->endModal(); // Hides the dialog } m_gui_delete_menu->Hide(); // Supress node/beam panels (if visible) m_nodes_panel ->HideTemporarily(); m_beams_panel ->HideTemporarily(); m_hydros_panel ->HideTemporarily(); m_commands2_panel->HideTemporarily(); m_shocks_panel ->HideTemporarily(); m_shocks2_panel ->HideTemporarily(); m_meshwheels2_panel ->HideTemporarily(); m_flexbodywheels_panel ->HideTemporarily(); /* Hide debug box */ m_debug_box->setVisible(false); m_exit_loop_requested = false; }