Main.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include <windows.h>
  4. // Engine includes
  5. #include "BsApplication.h"
  6. #include "Resources/BsResources.h"
  7. #include "Resources/BsBuiltinResources.h"
  8. #include "Importer/BsImporter.h"
  9. #include "Importer/BsTextureImportOptions.h"
  10. #include "Importer/BsMeshImportOptions.h"
  11. #include "Material/BsMaterial.h"
  12. #include "Material/BsShader.h"
  13. #include "Input/BsVirtualInput.h"
  14. #include "Components/BsCCamera.h"
  15. #include "Components/BsCRenderable.h"
  16. #include "Components/BsCLight.h"
  17. #include "GUI/BsCGUIWidget.h"
  18. #include "GUI/BsGUILayoutX.h"
  19. #include "GUI/BsGUILayoutY.h"
  20. #include "GUI/BsGUIPanel.h"
  21. #include "GUI/BsGUISpace.h"
  22. #include "GUI/BsGUILabel.h"
  23. #include "GUI/BsGUIButton.h"
  24. #include "GUI/BsGUIListBox.h"
  25. #include "GUI/BsProfilerOverlay.h"
  26. #include "RenderAPI/BsRenderAPI.h"
  27. #include "RenderAPI/BsRenderWindow.h"
  28. #include "Scene/BsSceneObject.h"
  29. #include "BsEngineConfig.h"
  30. // Example includes
  31. #include "CameraFlyer.h"
  32. namespace bs
  33. {
  34. UINT32 windowResWidth = 1280;
  35. UINT32 windowResHeight = 720;
  36. /** Imports all of our assets and prepares GameObject that handle the example logic. */
  37. void setUpExample();
  38. /** Import mesh/texture/GPU programs used by the example. */
  39. void loadAssets(HMesh& model, HTexture& texture, HShader& shader);
  40. /** Create a material used by our example model. */
  41. HMaterial createMaterial(const HTexture& texture, const HShader& shader);
  42. /** Set up example scene objects. */
  43. void setUp3DScene(const HMesh& mesh, const HMaterial& material);
  44. /** Set up example GUI. */
  45. void setUpGUI();
  46. /** Set up input configuration and callbacks. */
  47. void setUpInput();
  48. /** Toggles the primary window between full-screen and windowed mode. */
  49. void toggleFullscreen();
  50. /** Called whenever the main render window is resized. */
  51. void renderWindowResized();
  52. /** Called when the selected video mode changes in the video mode list box. */
  53. void videoModeChanged(UINT32 idx, bool enabled);
  54. /** Triggered whenever a virtual button is released. */
  55. void buttonUp(const VirtualButton& button, UINT32 deviceIdx);
  56. }
  57. using namespace bs;
  58. /** Main entry point into the application. */
  59. int CALLBACK WinMain(
  60. _In_ HINSTANCE hInstance,
  61. _In_ HINSTANCE hPrevInstance,
  62. _In_ LPSTR lpCmdLine,
  63. _In_ int nCmdShow
  64. )
  65. {
  66. // Ensure all errors are reported properly
  67. CrashHandler::startUp();
  68. // Descriptor used for initializing the engine
  69. START_UP_DESC startUpDesc;
  70. // Use default values as specified by the build system
  71. startUpDesc.renderAPI = BS_RENDER_API_MODULE;
  72. startUpDesc.renderer = BS_RENDERER_MODULE;
  73. startUpDesc.audio = BS_AUDIO_MODULE;
  74. startUpDesc.physics = BS_PHYSICS_MODULE;
  75. startUpDesc.input = BS_INPUT_MODULE;
  76. // Descriptor used for initializing the primary application window.
  77. startUpDesc.primaryWindowDesc.videoMode = VideoMode(windowResWidth, windowResHeight);
  78. startUpDesc.primaryWindowDesc.title = "Banshee Example App";
  79. startUpDesc.primaryWindowDesc.fullscreen = false;
  80. startUpDesc.primaryWindowDesc.depthBuffer = false;
  81. // List of importer plugins we plan on using for importing various resources
  82. startUpDesc.importers.push_back("BansheeFreeImgImporter"); // For importing textures
  83. startUpDesc.importers.push_back("BansheeFBXImporter"); // For importing meshes
  84. startUpDesc.importers.push_back("BansheeFontImporter"); // For importing fonts
  85. startUpDesc.importers.push_back("BansheeSL"); // For importing shaders
  86. // Initializes the application with systems and primary window as defined above
  87. Application::startUp(startUpDesc);
  88. // Imports all of ours assets and prepares GameObjects that handle the example logic.
  89. setUpExample();
  90. // Runs the main loop that does most of the work. This method will exit when user closes the main
  91. // window or exits in some other way.
  92. Application::instance().runMainLoop();
  93. Application::shutDown();
  94. CrashHandler::shutDown();
  95. return 0;
  96. }
  97. namespace bs
  98. {
  99. Path dataPath = Paths::getRuntimeDataPath();
  100. Path exampleModelPath = dataPath + "Examples\\Dragon.fbx";
  101. Path exampleTexturePath = dataPath + "Examples\\Dragon.tga";
  102. Path exampleShaderPath = dataPath + "Examples\\Example.bsl";
  103. GUIButton* toggleFullscreenButton = nullptr;
  104. bool fullscreen = false;
  105. const VideoMode* selectedVideoMode = nullptr;
  106. Vector<const VideoMode*> videoModes;
  107. HCamera sceneCamera;
  108. HProfilerOverlay profilerOverlay;
  109. VirtualButton toggleCPUProfilerBtn;
  110. VirtualButton toggleGPUProfilerBtn;
  111. bool cpuProfilerActive = false;
  112. bool gpuProfilerActive = false;
  113. void setUpExample()
  114. {
  115. HMesh exampleModel;
  116. HTexture exampleTexture;
  117. HShader exampleShader;
  118. loadAssets(exampleModel, exampleTexture, exampleShader);
  119. HMaterial exampleMaterial = createMaterial(exampleTexture, exampleShader);
  120. setUp3DScene(exampleModel, exampleMaterial);
  121. setUpGUI();
  122. setUpInput();
  123. }
  124. /**
  125. * Load the required resources. First try to load a pre-processed version of the resources. If they don't exist import
  126. * resources from the source formats into engine format, and save them for next time.
  127. */
  128. void loadAssets(HMesh& model, HTexture& texture, HShader& shader)
  129. {
  130. // Set up paths to pre-processed versions of example resources.
  131. Path exampleModelAssetPath = exampleModelPath;
  132. Path exampleTextureAssetPath = exampleTexturePath;
  133. Path exampleShaderAssetPath = exampleShaderPath;
  134. exampleModelAssetPath.setExtension(exampleModelAssetPath.getExtension() + ".asset");
  135. exampleTextureAssetPath.setExtension(exampleTextureAssetPath.getExtension() + ".asset");
  136. exampleShaderAssetPath.setExtension(exampleShaderAssetPath.getExtension() + ".asset");
  137. // Load an FBX mesh.
  138. model = gResources().load<Mesh>(exampleModelAssetPath);
  139. if(model == nullptr) // Mesh file doesn't exist, import from the source file.
  140. {
  141. // When importing you may specify optional import options that control how is the asset imported.
  142. SPtr<ImportOptions> meshImportOptions = Importer::instance().createImportOptions(exampleModelPath);
  143. // rtti_is_of_type checks if the import options are of valid type, in case the provided path is pointing to a
  144. // non-mesh resource. This is similar to dynamic_cast but uses Banshee internal RTTI system for type checking.
  145. if (rtti_is_of_type<MeshImportOptions>(meshImportOptions))
  146. {
  147. MeshImportOptions* importOptions = static_cast<MeshImportOptions*>(meshImportOptions.get());
  148. // Ensures we can save the mesh contents
  149. importOptions->setCPUCached(true);
  150. }
  151. model = gImporter().import<Mesh>(exampleModelPath, meshImportOptions);
  152. // Save for later use, so we don't have to import on the next run.
  153. gResources().save(model, exampleModelAssetPath, true);
  154. }
  155. // Load an TGA texture.
  156. texture = gResources().load<Texture>(exampleTextureAssetPath);
  157. if (texture == nullptr) // Texture file doesn't exist, import from the source file.
  158. {
  159. // When importing you may specify optional import options that control how is the asset imported.
  160. SPtr<ImportOptions> textureImportOptions = Importer::instance().createImportOptions(exampleTexturePath);
  161. // rtti_is_of_type checks if the import options are of valid type, in case the provided path is pointing to a
  162. // non-texture resource. This is similar to dynamic_cast but uses Banshee internal RTTI system for type checking.
  163. if (rtti_is_of_type<TextureImportOptions>(textureImportOptions))
  164. {
  165. TextureImportOptions* importOptions = static_cast<TextureImportOptions*>(textureImportOptions.get());
  166. // We want maximum number of mipmaps to be generated
  167. importOptions->setGenerateMipmaps(true);
  168. // The texture is in sRGB space
  169. importOptions->setSRGB(true);
  170. // Ensures we can save the texture contents
  171. importOptions->setCPUCached(true);
  172. }
  173. // Import texture with specified import options
  174. texture = gImporter().import<Texture>(exampleTexturePath, textureImportOptions);
  175. // Save for later use, so we don't have to import on the next run.
  176. gResources().save(texture, exampleTextureAssetPath, true);
  177. }
  178. // Load a shader.
  179. shader = gResources().load<Shader>(exampleShaderAssetPath);
  180. if (shader == nullptr) // Mesh file doesn't exist, import from the source file.
  181. {
  182. shader = gImporter().import<Shader>(exampleShaderPath);
  183. // Save for later use, so we don't have to import on the next run.
  184. gResources().save(shader, exampleShaderAssetPath, true);
  185. }
  186. }
  187. /** Create a material using the provided shader, and assign the provided texture to it. */
  188. HMaterial createMaterial(const HTexture& texture, const HShader& shader)
  189. {
  190. // Create a material with the provided shader.
  191. HMaterial exampleMaterial = Material::create(shader);
  192. // And set the texture to be used by the "tex" shader parameter. We leave the "samp"
  193. // parameter at its defaults. These parameters are defined in the shader (.bsl) file.
  194. exampleMaterial->setTexture("tex", texture);
  195. return exampleMaterial;
  196. }
  197. /** Set up the 3D object used by the example, and the camera to view the world through. */
  198. void setUp3DScene(const HMesh& mesh, const HMaterial& material)
  199. {
  200. /************************************************************************/
  201. /* SCENE OBJECT */
  202. /************************************************************************/
  203. // Now we create a scene object that has a position, orientation, scale and optionally
  204. // components to govern its logic. In this particular case we are creating a SceneObject
  205. // with a Renderable component which will render a mesh at the position of the scene object
  206. // with the provided material.
  207. // Create new scene object at (0, 0, 0)
  208. HSceneObject dragonSO = SceneObject::create("Dragon");
  209. // Attach the Renderable component and hook up the mesh we imported earlier,
  210. // and the material we created in the previous section.
  211. HRenderable renderable = dragonSO->addComponent<CRenderable>();
  212. renderable->setMesh(mesh);
  213. renderable->setMaterial(material);
  214. /************************************************************************/
  215. /* LIGHTS */
  216. /************************************************************************/
  217. // Add a couple of lights so that our object isn't completely in the dark.
  218. HSceneObject lightASO = SceneObject::create("Light A");
  219. HSceneObject lightBSO = SceneObject::create("Light B");
  220. lightASO->setPosition(Vector3(0, 50, 0));
  221. lightBSO->setPosition(Vector3(-130, 140, 450));
  222. HLight lightA = lightASO->addComponent<CLight>();
  223. HLight lightB = lightBSO->addComponent<CLight>();
  224. // Disable physically based attentuation because we want to set our own range
  225. lightA->setUseAutoAttenuation(false);
  226. lightB->setUseAutoAttenuation(false);
  227. lightA->setAttenuationRadius(500.0f);
  228. lightB->setAttenuationRadius(300.0f);
  229. lightA->setIntensity(10000.0f);
  230. lightB->setIntensity(10000.0f);
  231. /************************************************************************/
  232. /* CAMERA */
  233. /************************************************************************/
  234. // In order something to render on screen we need at least one camera.
  235. // Like before, we create a new scene object at (0, 0, 0).
  236. HSceneObject sceneCameraSO = SceneObject::create("SceneCamera");
  237. // Get the primary render window we need for creating the camera. Additionally
  238. // hook up a callback so we are notified when user resizes the window.
  239. SPtr<RenderWindow> window = gApplication().getPrimaryWindow();
  240. window->onResized.connect(&renderWindowResized);
  241. // Add a Camera component that will output whatever it sees into that window
  242. // (You could also use a render texture or another window you created).
  243. sceneCamera = sceneCameraSO->addComponent<CCamera>(window);
  244. // Set up camera component properties
  245. // Priority determines in what order are cameras rendered in case multiple cameras render to the same render target.
  246. // We raise the priority slightly because later in code we have defined a GUI camera that we want to render second.
  247. sceneCamera->setPriority(1);
  248. // Set closest distance that is visible. Anything below that is clipped.
  249. sceneCamera->setNearClipDistance(5);
  250. // Set farthest distance that is visible. Anything above that is clipped.
  251. sceneCamera->setFarClipDistance(10000);
  252. // Set aspect ratio depending on the current resolution
  253. sceneCamera->setAspectRatio(windowResWidth / (float)windowResHeight);
  254. // Add a CameraFlyer component that allows us to move the camera. See CameraFlyer for more information.
  255. sceneCameraSO->addComponent<CameraFlyer>();
  256. // Position and orient the camera scene object
  257. sceneCameraSO->setPosition(Vector3(-130.0f, 140.0f, 650.0f));
  258. sceneCameraSO->lookAt(Vector3(0, 0, 0));
  259. }
  260. /** Register mouse and keyboard inputs that will be used for controlling the camera. */
  261. void setUpInput()
  262. {
  263. // Register input configuration
  264. // Banshee allows you to use VirtualInput system which will map input device buttons
  265. // and axes to arbitrary names, which allows you to change input buttons without affecting
  266. // the code that uses it, since the code is only aware of the virtual names.
  267. // If you want more direct input, see Input class.
  268. auto inputConfig = VirtualInput::instance().getConfiguration();
  269. // Camera controls for buttons (digital 0-1 input, e.g. keyboard or gamepad button)
  270. inputConfig->registerButton("Forward", BC_W);
  271. inputConfig->registerButton("Back", BC_S);
  272. inputConfig->registerButton("Left", BC_A);
  273. inputConfig->registerButton("Right", BC_D);
  274. inputConfig->registerButton("Forward", BC_UP);
  275. inputConfig->registerButton("Back", BC_BACK);
  276. inputConfig->registerButton("Left", BC_LEFT);
  277. inputConfig->registerButton("Right", BC_RIGHT);
  278. inputConfig->registerButton("FastMove", BC_LSHIFT);
  279. inputConfig->registerButton("RotateCam", BC_MOUSE_RIGHT);
  280. // Camera controls for axes (analog input, e.g. mouse or gamepad thumbstick)
  281. // These return values in [-1.0, 1.0] range.
  282. inputConfig->registerAxis("Horizontal", VIRTUAL_AXIS_DESC((UINT32)InputAxis::MouseX));
  283. inputConfig->registerAxis("Vertical", VIRTUAL_AXIS_DESC((UINT32)InputAxis::MouseY));
  284. // Controls that toggle the profiler overlays
  285. inputConfig->registerButton("CPUProfilerOverlay", BC_F1);
  286. inputConfig->registerButton("GPUProfilerOverlay", BC_F2);
  287. // Cache the profiler overlay buttons so when a button is pressed we can quickly
  288. // use these to determine its the one we want
  289. toggleCPUProfilerBtn = VirtualButton("CPUProfilerOverlay");
  290. toggleGPUProfilerBtn = VirtualButton("GPUProfilerOverlay");
  291. // Hook up a callback that gets triggered whenever a virtual button is released
  292. VirtualInput::instance().onButtonUp.connect(&buttonUp);
  293. }
  294. /** Set up graphical user interface used by the example. */
  295. void setUpGUI()
  296. {
  297. // Create a scene object that will contain GUI components
  298. HSceneObject guiSO = SceneObject::create("Example");
  299. // Get the primary render window we need for creating the camera.
  300. SPtr<RenderWindow> window = gApplication().getPrimaryWindow();
  301. // First we want another camera that is responsible for rendering GUI
  302. HCamera guiCamera = guiSO->addComponent<CCamera>(window);
  303. // Notify the renderer that the camera will only be used for overlays (e.g. GUI) so it can optimize its usage
  304. SPtr<RenderSettings> settings = guiCamera->getRenderSettings();
  305. settings->overlayOnly = true;
  306. // Set up GUI camera properties.
  307. // We don't care about aspect ratio for GUI camera.
  308. guiCamera->setAspectRatio(1.0f);
  309. // This camera should ignore any Renderable objects in the scene
  310. guiCamera->setLayers(0);
  311. // Don't clear this camera as that would clear anything the main camera has rendered.
  312. guiCamera->getViewport()->setRequiresClear(false, false, false);
  313. // Add a GUIWidget, the top-level GUI component, parent to all GUI elements. GUI widgets
  314. // require you to specify a viewport that they will output rendered GUI elements to.
  315. HGUIWidget gui = guiSO->addComponent<CGUIWidget>(guiCamera);
  316. // Depth allows you to control how is a GUI widget rendered in relation to other widgets
  317. // Lower depth means the widget will be rendered in front of those with higher. In this case we just
  318. // make the depth mid-range as there are no other widgets.
  319. gui->setDepth(128);
  320. // GUI skin defines how are all child elements of the GUI widget renderered. It contains all their styles
  321. // and default layout properties. We use the default skin that comes built into Banshee.
  322. gui->setSkin(BuiltinResources::instance().getGUISkin());
  323. // Get the primary GUI panel that stretches over the entire window and add to it a vertical layout
  324. // that will be using for vertically positioning messages about toggling profiler overlay.
  325. GUILayout* bottomLayout = gui->getPanel()->addNewElement<GUILayoutY>();
  326. // Add a flexible space that fills up any remaining area in the layout, making the two labels above be aligned
  327. // to the bottom of the GUI widget (and the screen).
  328. bottomLayout->addNewElement<GUIFlexibleSpace>();
  329. // Add a couple of labels to the layout with the needed messages. Labels expect a HString object that
  330. // maps into a string table and allows for easily localization.
  331. bottomLayout->addElement(GUILabel::create(HString(L"Press F1 to toggle CPU profiler overlay")));
  332. bottomLayout->addElement(GUILabel::create(HString(L"Press F2 to toggle GPU profiler overlay")));
  333. // Create a GUI panel that is used for displaying resolution and fullscreen options.
  334. GUILayout* rightLayout = gui->getPanel()->addNewElement<GUILayoutX>();
  335. // We want all the GUI elements be right aligned, so we add a flexible space first.
  336. rightLayout->addNewElement<GUIFlexibleSpace>();
  337. // And we want the elements to be vertically placed, top to bottom
  338. GUILayout* elemLayout = rightLayout->addNewElement<GUILayoutY>();
  339. // Leave 30 pixels to the right free
  340. rightLayout->addNewElement<GUIFixedSpace>(30);
  341. // Add a button that will trigger a callback when clicked
  342. toggleFullscreenButton = GUIButton::create(HString(L"Toggle fullscreen"));
  343. toggleFullscreenButton->onClick.connect(&toggleFullscreen);
  344. elemLayout->addElement(toggleFullscreenButton);
  345. // Add a profiler overlay object that is responsible for displaying CPU and GPU profiling GUI
  346. profilerOverlay = guiSO->addComponent<CProfilerOverlay>(guiCamera->_getCamera());
  347. // Set up video mode list box
  348. // First get a list of output devices
  349. const VideoModeInfo& videoModeInfo = RenderAPI::getVideoModeInfo();
  350. // Get video mode info for the primary monitor
  351. const VideoOutputInfo& primaryMonitorInfo = videoModeInfo.getOutputInfo(0);
  352. // Make the current desktop mode the default video mode
  353. selectedVideoMode = &primaryMonitorInfo.getDesktopVideoMode();
  354. // Create list box elements for each available video mode
  355. UINT32 numVideoModes = primaryMonitorInfo.getNumVideoModes();
  356. Vector<HString> videoModeLabels(numVideoModes);
  357. UINT32 selectedVideoModeIdx = 0;
  358. for (UINT32 i = 0; i < numVideoModes; i++)
  359. {
  360. const VideoMode& curVideoMode = primaryMonitorInfo.getVideoMode(i);
  361. HString videoModeLabel(L"{0} x {1} at {2}Hz");
  362. videoModeLabel.setParameter(0, toWString(curVideoMode.getWidth()));
  363. videoModeLabel.setParameter(1, toWString(curVideoMode.getHeight()));
  364. videoModeLabel.setParameter(2, toWString(Math::roundToInt(curVideoMode.getRefreshRate())));
  365. videoModeLabels[i] = videoModeLabel;
  366. videoModes.push_back(&curVideoMode);
  367. if (curVideoMode == *selectedVideoMode)
  368. selectedVideoModeIdx = i;
  369. }
  370. // Create the list box
  371. GUIListBox* videoModeListBox = GUIListBox::create(videoModeLabels);
  372. elemLayout->addElement(videoModeListBox);
  373. // Select the default (desktop) video mode
  374. videoModeListBox->selectElement(selectedVideoModeIdx);
  375. // Set up a callback to be notified when video mode changes
  376. videoModeListBox->onSelectionToggled.connect(&videoModeChanged);
  377. }
  378. /** Callback method that toggles between fullscreen and windowed modes. */
  379. void toggleFullscreen()
  380. {
  381. SPtr<RenderWindow> window = gApplication().getPrimaryWindow();
  382. if (fullscreen)
  383. window->setWindowed(windowResWidth, windowResHeight);
  384. else
  385. window->setFullscreen(*selectedVideoMode);
  386. fullscreen = !fullscreen;
  387. }
  388. /** Callback triggered wheneve the user resizes the example window. */
  389. void renderWindowResized()
  390. {
  391. SPtr<RenderWindow> window = gApplication().getPrimaryWindow();
  392. const RenderWindowProperties& rwProps = window->getProperties();
  393. if (!fullscreen)
  394. {
  395. windowResWidth = rwProps.getWidth();
  396. windowResHeight = rwProps.getHeight();
  397. }
  398. sceneCamera->setAspectRatio(rwProps.getWidth() / (float)rwProps.getHeight());
  399. }
  400. /** Callback triggered when the user selects a new video mode from the GUI drop down element. */
  401. void videoModeChanged(UINT32 idx, bool enabled)
  402. {
  403. if (!enabled)
  404. return;
  405. selectedVideoMode = videoModes[idx];
  406. if (fullscreen)
  407. {
  408. SPtr<RenderWindow> window = gApplication().getPrimaryWindow();
  409. window->setFullscreen(*selectedVideoMode);
  410. }
  411. }
  412. /** Callback triggered when a user hits a button. */
  413. void buttonUp(const VirtualButton& button, UINT32 deviceIdx)
  414. {
  415. // Check if the pressed button is one of the either buttons we defined in "setUpExample", and toggle profiler
  416. // overlays accordingly. Device index is ignored for now, as it is assumed the user is using a single keyboard,
  417. // but if you wanted support for multiple gamepads you would check deviceIdx.
  418. if (button == toggleCPUProfilerBtn)
  419. {
  420. if (cpuProfilerActive)
  421. {
  422. profilerOverlay->hide();
  423. cpuProfilerActive = false;
  424. }
  425. else
  426. {
  427. profilerOverlay->show(ProfilerOverlayType::CPUSamples);
  428. cpuProfilerActive = true;
  429. gpuProfilerActive = false;
  430. }
  431. }
  432. else if (button == toggleGPUProfilerBtn)
  433. {
  434. if (gpuProfilerActive)
  435. {
  436. profilerOverlay->hide();
  437. gpuProfilerActive = false;
  438. }
  439. else
  440. {
  441. profilerOverlay->show(ProfilerOverlayType::GPUSamples);
  442. gpuProfilerActive = true;
  443. cpuProfilerActive = false;
  444. }
  445. }
  446. }
  447. }