BsCorePrerequisites.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsPrerequisitesUtil.h"
  5. /** @defgroup Core Core
  6. * Second lowest layer that provides some very game-specific modules tied into a coherent whole, but it tries to be very
  7. * generic and offer something that every engine might need instead of focusing on very specialized techniques.
  8. * @{
  9. */
  10. /** @defgroup CoreThread Core thread
  11. * Functionality for dealing with core objects and interaction with the core thread.
  12. */
  13. /** @defgroup Importer Importer
  14. * Functionality for dealing with import of resources into engine friendly format.
  15. */
  16. /** @defgroup Input Input
  17. * Functionality for dealing with input (mouse, keyboard, gamepad, etc.).
  18. */
  19. /** @defgroup Localization Localization
  20. * Functionality for dealing with GUI localization.
  21. */
  22. /** @defgroup Material Material
  23. * Functionality for dealing with materials, shaders, and in general how objects are rendered.
  24. */
  25. /** @defgroup Platform Platform
  26. * Functionality specific for some platform (e.g. Windows, Mac).
  27. */
  28. /** @defgroup Profiling Profiling
  29. * Functionality for measuring CPU and GPU execution times and memory usage.
  30. */
  31. /** @defgroup RenderAPI RenderAPI
  32. * Functionality for interacting with underlying render API (e.g. DirectX, OpenGL).
  33. */
  34. /** @defgroup Renderer Renderer
  35. * Abstract interface and helper functionality for rendering scene objects.
  36. */
  37. /** @defgroup Resources Resources
  38. * Contains core resource types and resource management functionality (loading, saving, etc.).
  39. */
  40. /** @defgroup RTTI-Impl-Core RTTI types
  41. * Types containing RTTI for specific classes.
  42. */
  43. /** @defgroup Scene Scene
  44. * Functionality for managing scene objects and their hierarchy.
  45. */
  46. /** @defgroup Text Text
  47. * Functionality for rendering text.
  48. */
  49. /** @defgroup Utility-Core Utility
  50. * Various utility methods and types used by the core layer.
  51. */
  52. /** @defgroup Platform-Core Platform
  53. * Platform specific functionality.
  54. */
  55. /** @defgroup Application-Core Application
  56. * Entry point into the application.
  57. */
  58. /** @} */
  59. #define BS_MAX_MULTIPLE_RENDER_TARGETS 8
  60. #define BS_FORCE_SINGLETHREADED_RENDERING 0
  61. // Windows Settings
  62. #if BS_PLATFORM == BS_PLATFORM_WIN32
  63. // If we're not including this from a client build, specify that the stuff
  64. // should get exported. Otherwise, import it.
  65. # if defined(BS_STATIC_LIB)
  66. // Linux compilers don't have symbol import/export directives.
  67. # define BS_CORE_EXPORT
  68. # else
  69. # if defined(BS_CORE_EXPORTS)
  70. # define BS_CORE_EXPORT __declspec( dllexport )
  71. # else
  72. # if defined( __MINGW32__ )
  73. # define BS_CORE_EXPORT
  74. # else
  75. # define BS_CORE_EXPORT __declspec( dllimport )
  76. # endif
  77. # endif
  78. # endif
  79. // Win32 compilers use _DEBUG for specifying debug builds.
  80. // for MinGW, we set DEBUG
  81. # if defined(_DEBUG) || defined(DEBUG)
  82. # define BS_DEBUG_MODE 1
  83. # else
  84. # define BS_DEBUG_MODE 0
  85. # endif
  86. #endif
  87. // Linux/Apple Settings
  88. #if BS_PLATFORM == BS_PLATFORM_LINUX || BS_PLATFORM == BS_PLATFORM_APPLE
  89. // Enable GCC symbol visibility
  90. # if defined( BS_GCC_VISIBILITY )
  91. # define BS_CORE_EXPORT __attribute__ ((visibility("default")))
  92. # define BS_HIDDEN __attribute__ ((visibility("hidden")))
  93. # else
  94. # define BS_CORE_EXPORT
  95. # define BS_HIDDEN
  96. # endif
  97. // A quick define to overcome different names for the same function
  98. # define stricmp strcasecmp
  99. # ifdef DEBUG
  100. # define BS_DEBUG_MODE 1
  101. # else
  102. # define BS_DEBUG_MODE 0
  103. # endif
  104. #endif
  105. #if BS_DEBUG_MODE
  106. #define BS_DEBUG_ONLY(x) x
  107. #define BS_ASSERT(x) assert(x)
  108. #else
  109. #define BS_DEBUG_ONLY(x)
  110. #define BS_ASSERT(x)
  111. #endif
  112. #include "BsHString.h"
  113. namespace BansheeEngine
  114. {
  115. static const StringID RenderAPIAny = "AnyRenderAPI";
  116. static const StringID RendererAny = "AnyRenderer";
  117. class Color;
  118. class GpuProgram;
  119. class GpuProgramManager;
  120. class IndexBuffer;
  121. class IndexBufferCore;
  122. class OcclusionQuery;
  123. class VertexBuffer;
  124. class VertexBufferCore;
  125. class PixelBuffer;
  126. class GpuBuffer;
  127. class HighLevelGpuProgram;
  128. class GpuProgramManager;
  129. class GpuProgramFactory;
  130. class IndexData;
  131. class Pass;
  132. class Technique;
  133. class Shader;
  134. class Material;
  135. class RenderAPICore;
  136. class RenderAPICapabilities;
  137. class RenderTarget;
  138. class RenderTargetCore;
  139. class RenderTexture;
  140. class RenderTextureCore;
  141. class MultiRenderTexture;
  142. class MultiRenderTextureCore;
  143. class RenderWindow;
  144. class RenderWindowCore;
  145. class RenderTargetProperties;
  146. struct RenderOpMesh;
  147. class StringInterface;
  148. class SamplerState;
  149. class SamplerStateCore;
  150. class TextureManager;
  151. class Viewport;
  152. class VertexData;
  153. class VertexDeclaration;
  154. class Input;
  155. struct PointerEvent;
  156. class RawInputHandler;
  157. class CoreRenderer;
  158. class RendererFactory;
  159. class AsyncOp;
  160. class HardwareBufferManager;
  161. class FontManager;
  162. class DepthStencilState;
  163. class DepthStencilStateCore;
  164. class RenderStateManager;
  165. class RasterizerState;
  166. class RasterizerStateCore;
  167. class BlendState;
  168. class BlendStateCore;
  169. class GpuParamBlock;
  170. class GpuParamBlockBuffer;
  171. class GpuParams;
  172. struct GpuParamDesc;
  173. struct GpuParamDataDesc;
  174. struct GpuParamObjectDesc;
  175. struct GpuParamBlockDesc;
  176. class ShaderInclude;
  177. class TextureView;
  178. class CoreObject;
  179. class CoreObjectCore;
  180. class ImportOptions;
  181. class TextureImportOptions;
  182. class FontImportOptions;
  183. class GpuProgramImportOptions;
  184. class MeshImportOptions;
  185. struct FontBitmap;
  186. class GameObject;
  187. class GpuResourceData;
  188. struct RenderOperation;
  189. class RenderQueue;
  190. struct ProfilerReport;
  191. class VertexDataDesc;
  192. class EventQuery;
  193. class TimerQuery;
  194. class OcclusionQuery;
  195. class FrameAlloc;
  196. class FolderMonitor;
  197. class VideoMode;
  198. class VideoOutputInfo;
  199. class VideoModeInfo;
  200. class RenderableElement;
  201. class CameraCore;
  202. class MeshCoreBase;
  203. class MeshCore;
  204. struct SubMesh;
  205. class TransientMeshCore;
  206. class TextureCore;
  207. class MeshHeapCore;
  208. class VertexDeclarationCore;
  209. class GpuBufferCore;
  210. class GpuParamBlockBufferCore;
  211. class GpuParamsCore;
  212. class ShaderCore;
  213. class ViewportCore;
  214. class PassCore;
  215. class PassParametersCore;
  216. class TechniqueCore;
  217. class MaterialCore;
  218. class GpuProgramCore;
  219. class IResourceListener;
  220. class TextureProperties;
  221. class IShaderIncludeHandler;
  222. class Prefab;
  223. class PrefabDiff;
  224. class RendererMeshData;
  225. class LightCore;
  226. class Light;
  227. class Win32Window;
  228. class RenderAPIFactory;
  229. // Asset import
  230. class SpecificImporter;
  231. class Importer;
  232. // Resources
  233. class Resource;
  234. class Resources;
  235. class ResourceManifest;
  236. class Texture;
  237. class Mesh;
  238. class MeshBase;
  239. class TransientMesh;
  240. class MeshHeap;
  241. class Font;
  242. class ResourceMetaData;
  243. class OSDropTarget;
  244. class StringTable;
  245. // Scene
  246. class SceneObject;
  247. class Component;
  248. class SceneManager;
  249. // RTTI
  250. class MeshRTTI;
  251. // Desc structs
  252. struct SAMPLER_STATE_DESC;
  253. struct DEPTH_STENCIL_STATE_DESC;
  254. struct RASTERIZER_STATE_DESC;
  255. struct BLEND_STATE_DESC;
  256. struct RENDER_TARGET_BLEND_STATE_DESC;
  257. struct RENDER_TEXTURE_DESC;
  258. struct RENDER_WINDOW_DESC;
  259. struct FONT_DESC;
  260. template<class T>
  261. class CoreThreadAccessor;
  262. class CommandQueueNoSync;
  263. class CommandQueueSync;
  264. }
  265. /************************************************************************/
  266. /* Shared pointer typedefs */
  267. /************************************************************************/
  268. namespace BansheeEngine
  269. {
  270. typedef std::shared_ptr<RenderAPICore> RenderAPIPtr;
  271. typedef std::shared_ptr<GpuProgram> GpuProgramPtr;
  272. typedef std::shared_ptr<PixelBuffer> PixelBufferPtr;
  273. typedef std::shared_ptr<VertexBuffer> VertexBufferPtr;
  274. typedef std::shared_ptr<IndexBuffer> IndexBufferPtr;
  275. typedef std::shared_ptr<GpuBuffer> GpuBufferPtr;
  276. typedef std::shared_ptr<VertexDeclaration> VertexDeclarationPtr;
  277. typedef std::shared_ptr<Mesh> MeshPtr;
  278. typedef std::shared_ptr<MeshBase> MeshBasePtr;
  279. typedef std::shared_ptr<MeshHeap> MeshHeapPtr;
  280. typedef std::shared_ptr<TransientMesh> TransientMeshPtr;
  281. typedef std::shared_ptr<Texture> TexturePtr;
  282. typedef std::shared_ptr<Resource> ResourcePtr;
  283. typedef std::shared_ptr<Technique> TechniquePtr;
  284. typedef std::shared_ptr<Pass> PassPtr;
  285. typedef std::shared_ptr<Shader> ShaderPtr;
  286. typedef std::shared_ptr<Material> MaterialPtr;
  287. typedef std::shared_ptr<CoreRenderer> CoreRendererPtr;
  288. typedef std::shared_ptr<RendererFactory> RendererFactoryPtr;
  289. typedef std::shared_ptr<Component> ComponentPtr;
  290. typedef std::shared_ptr<GameObject> GameObjectPtr;
  291. typedef std::shared_ptr<SceneObject> SceneObjectPtr;
  292. typedef std::shared_ptr<SamplerState> SamplerStatePtr;
  293. typedef std::shared_ptr<DepthStencilState> DepthStencilStatePtr;
  294. typedef std::shared_ptr<RasterizerState> RasterizerStatePtr;
  295. typedef std::shared_ptr<BlendState> BlendStatePtr;
  296. typedef std::shared_ptr<RenderWindow> RenderWindowPtr;
  297. typedef std::shared_ptr<RenderTarget> RenderTargetPtr;
  298. typedef std::shared_ptr<RenderTexture> RenderTexturePtr;
  299. typedef std::shared_ptr<MultiRenderTexture> MultiRenderTexturePtr;
  300. typedef std::shared_ptr<GpuParamBlockBuffer> GpuParamBlockBufferPtr;
  301. typedef std::shared_ptr<GpuParams> GpuParamsPtr;
  302. typedef std::shared_ptr<TextureView> TextureViewPtr;
  303. typedef std::shared_ptr<Viewport> ViewportPtr;
  304. typedef std::shared_ptr<ShaderInclude> ShaderIncludePtr;
  305. typedef std::shared_ptr<ImportOptions> ImportOptionsPtr;
  306. typedef std::shared_ptr<const ImportOptions> ConstImportOptionsPtr;
  307. typedef std::shared_ptr<Font> FontPtr;
  308. typedef std::shared_ptr<VertexDataDesc> VertexDataDescPtr;
  309. typedef CoreThreadAccessor<CommandQueueNoSync> CoreAccessor;
  310. typedef CoreThreadAccessor<CommandQueueSync> SyncedCoreAccessor;
  311. typedef std::shared_ptr<CoreThreadAccessor<CommandQueueNoSync>> CoreAccessorPtr;
  312. typedef std::shared_ptr<CoreThreadAccessor<CommandQueueSync>> SyncedCoreAccessorPtr;
  313. typedef std::shared_ptr<EventQuery> EventQueryPtr;
  314. typedef std::shared_ptr<TimerQuery> TimerQueryPtr;
  315. typedef std::shared_ptr<OcclusionQuery> OcclusionQueryPtr;
  316. typedef std::shared_ptr<ResourceManifest> ResourceManifestPtr;
  317. typedef std::shared_ptr<VideoModeInfo> VideoModeInfoPtr;
  318. typedef std::shared_ptr<RenderQueue> RenderQueuePtr;
  319. typedef std::shared_ptr<GpuParamDesc> GpuParamDescPtr;
  320. typedef std::shared_ptr<ResourceMetaData> ResourceMetaDataPtr;
  321. typedef std::shared_ptr<IShaderIncludeHandler> ShaderIncludeHandlerPtr;
  322. typedef std::shared_ptr<Prefab> PrefabPtr;
  323. typedef std::shared_ptr<PrefabDiff> PrefabDiffPtr;
  324. typedef std::shared_ptr<RendererMeshData> RendererMeshDataPtr;
  325. typedef std::shared_ptr<RenderAPIFactory> RenderAPIFactoryPtr;
  326. }
  327. /************************************************************************/
  328. /* RTTI */
  329. /************************************************************************/
  330. namespace BansheeEngine
  331. {
  332. enum TypeID_Core
  333. {
  334. TID_Texture = 1001,
  335. TID_Mesh = 1002,
  336. TID_MeshData = 1003,
  337. TID_VertexDeclaration = 1004,
  338. TID_VertexElementData = 1005,
  339. TID_Component = 1006,
  340. TID_ResourceHandle = 1009,
  341. TID_GpuProgram = 1010,
  342. TID_ResourceHandleData = 1011,
  343. TID_CgProgram = 1012,
  344. TID_Pass = 1014,
  345. TID_Technique = 1015,
  346. TID_Shader = 1016,
  347. TID_Material = 1017,
  348. TID_SamplerState = 1021,
  349. TID_BlendState = 1023,
  350. TID_RasterizerState = 1024,
  351. TID_DepthStencilState = 1025,
  352. TID_BLEND_STATE_DESC = 1034,
  353. TID_SHADER_DATA_PARAM_DESC = 1035,
  354. TID_SHADER_OBJECT_PARAM_DESC = 1036,
  355. TID_SHADER_PARAM_BLOCK_DESC = 1047,
  356. TID_ImportOptions = 1048,
  357. TID_Font = 1051,
  358. TID_FONT_DESC = 1052,
  359. TID_CHAR_DESC = 1053,
  360. TID_FontImportOptions = 1056,
  361. TID_FontBitmap = 1057,
  362. TID_SceneObject = 1059,
  363. TID_GameObject = 1060,
  364. TID_PixelData = 1062,
  365. TID_GpuResourceData = 1063,
  366. TID_VertexDataDesc = 1064,
  367. TID_MeshBase = 1065,
  368. TID_GameObjectHandleBase = 1066,
  369. TID_ResourceManifest = 1067,
  370. TID_ResourceManifestEntry = 1068,
  371. TID_EmulatedParamBlock = 1069,
  372. TID_TextureImportOptions = 1070,
  373. TID_ResourceMetaData = 1071,
  374. TID_ShaderInclude = 1072,
  375. TID_Viewport = 1073,
  376. TID_ResourceDependencies = 1074,
  377. TID_ShaderMetaData = 1075,
  378. TID_MeshImportOptions = 1076,
  379. TID_Prefab = 1077,
  380. TID_PrefabDiff = 1078,
  381. TID_PrefabObjectDiff = 1079,
  382. TID_PrefabComponentDiff = 1080,
  383. TID_CGUIWidget = 1081,
  384. TID_ProfilerOverlay = 1082,
  385. TID_StringTable = 1083,
  386. TID_LanguageData = 1084,
  387. TID_LocalizedStringData = 1085,
  388. TID_MaterialParamColor = 1086,
  389. TID_WeakResourceHandle = 1087,
  390. TID_TextureParamData = 1088,
  391. TID_StructParamData = 1089,
  392. TID_MaterialParams = 1090,
  393. TID_MaterialRTTIParam = 1091
  394. };
  395. }
  396. /************************************************************************/
  397. /* Resource references */
  398. /************************************************************************/
  399. #include "BsResourceHandle.h"
  400. namespace BansheeEngine
  401. {
  402. // Resource handles
  403. typedef ResourceHandle<Resource> HResource;
  404. typedef ResourceHandle<Texture> HTexture;
  405. typedef ResourceHandle<Mesh> HMesh;
  406. typedef ResourceHandle<Material> HMaterial;
  407. typedef ResourceHandle<ShaderInclude> HShaderInclude;
  408. typedef ResourceHandle<Font> HFont;
  409. typedef ResourceHandle<Shader> HShader;
  410. typedef ResourceHandle<Prefab> HPrefab;
  411. typedef ResourceHandle<StringTable> HStringTable;
  412. }
  413. namespace BansheeEngine
  414. {
  415. /**
  416. * @brief Defers function execution until the next frame. If this function is called
  417. * within another deferred call, then it will be executed the same frame,
  418. * but only after all existing deferred calls are done.
  419. *
  420. * @note This method can be used for breaking dependencies among other things. If a class
  421. * A depends on class B having something done, but class B also depends in some way on class A,
  422. * you can break up the initialization into two separate steps, queuing the second step
  423. * using this method.
  424. *
  425. * Similar situation can happen if you have multiple classes being initialized in an undefined order
  426. * but some of them depend on others. Using this method you can defer the dependent step until next frame,
  427. * which will ensure everything was initialized.
  428. *
  429. * @param callback The callback.
  430. */
  431. void BS_CORE_EXPORT deferredCall(std::function<void()> callback);
  432. // Special types for use by profilers
  433. typedef std::basic_string<char, std::char_traits<char>, StdAlloc<char, ProfilerAlloc>> ProfilerString;
  434. template <typename T, typename A = StdAlloc<T, ProfilerAlloc>>
  435. using ProfilerVector = std::vector<T, A>;
  436. template <typename T, typename A = StdAlloc<T, ProfilerAlloc>>
  437. using ProfilerStack = std::stack<T, std::deque<T, A>>;
  438. /**
  439. * @brief Banshee thread policy that performs special startup/shutdown on threads
  440. * managed by thread pool.
  441. */
  442. class BS_CORE_EXPORT ThreadBansheePolicy
  443. {
  444. public:
  445. static void onThreadStarted(const String& name)
  446. {
  447. MemStack::beginThread();
  448. }
  449. static void onThreadEnded(const String& name)
  450. {
  451. MemStack::endThread();
  452. }
  453. };
  454. }
  455. #include "BsCommonTypes.h"