CmApplication.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmDeferredRenderContext.h"
  4. #include "CmHighLevelGpuProgram.h"
  5. #include "CmRenderWindow.h"
  6. #include "boost/signal.hpp"
  7. namespace CamelotFramework
  8. {
  9. class RenderWindow;
  10. class Viewport;
  11. class HighLevelGpuProgramManager;
  12. }
  13. namespace CamelotFramework
  14. {
  15. struct START_UP_DESC
  16. {
  17. String renderSystem;
  18. String renderer;
  19. String input;
  20. String sceneManager;
  21. RENDER_WINDOW_DESC primaryWindowDesc;
  22. vector<String>::type importers;
  23. String resourceCacheDirectory;
  24. };
  25. class CM_EXPORT Application
  26. {
  27. public:
  28. Application();
  29. /**
  30. * @brief Starts the application using the specified options.
  31. * This is how you start the engine.
  32. */
  33. void startUp(START_UP_DESC& desc);
  34. /**
  35. * @brief Executes the main loop. This will cause actually rendering to be performed
  36. * and simulation to be run. Usually called immediately after startUp().
  37. *
  38. * This will run infinitely until stopMainLoop is called (usually from another thread or internally).
  39. */
  40. void runMainLoop();
  41. /**
  42. * @brief Stops a (infinite) main loop from running. The loop will complete its current cycle before stopping.
  43. * You may call this from other threads.
  44. */
  45. void stopMainLoop();
  46. /**
  47. * @brief Frees up all resources allocated during startUp, and while the application was running.
  48. */
  49. void shutDown();
  50. UINT64 getAppWindowId();
  51. RenderWindowPtr getPrimaryWindow() const { return mPrimaryWindow; }
  52. /**
  53. * @brief Loads a plugin.
  54. *
  55. * @param pluginName Name of the plugin to load, without extension.
  56. */
  57. void* loadPlugin(const String& pluginName);
  58. /**
  59. * @brief Called every frame by the main loop, after scene update and before rendering.
  60. */
  61. boost::signal<void()> mainLoopCallback;
  62. private:
  63. friend CM_EXPORT RenderContext& gMainRC();
  64. friend CM_EXPORT SyncedRenderContext& gMainSyncedRC();
  65. RenderWindowPtr mPrimaryWindow;
  66. RenderContextPtr mPrimaryRenderContext;
  67. SyncedRenderContext* mPrimarySyncedRenderContext;
  68. bool mIsFrameRenderingFinished;
  69. CM_MUTEX(mFrameRenderingFinishedMutex);
  70. volatile bool mRunMainLoop;
  71. /**
  72. * @brief Runs the OS specific message pump.
  73. */
  74. void updateMessagePump();
  75. /**
  76. * @brief Called when the frame finishes rendering.
  77. */
  78. void frameRenderingFinishedCallback();
  79. };
  80. CM_EXPORT Application& gApplication();
  81. /**
  82. * @brief A shortcut for accessing the primary render context. This render context may only be accessed safely
  83. * from the main thread.
  84. */
  85. CM_EXPORT RenderContext& gMainRC();
  86. /**
  87. * @brief A shortcut for accessing the primary synchronized render context. This context may be accessed
  88. * from all threads except the render thread. All operations from this context will be executed after
  89. * non-synchronized primary context has finished executing.
  90. *
  91. * @note It is more efficient to create your own non-synchronized render context if you plan on often using the render context from
  92. * threads other than main.
  93. */
  94. CM_EXPORT SyncedRenderContext& gMainSyncedRC();
  95. }