CmApplication.h 3.0 KB

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