BsCamera.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "BsIReflectable.h"
  6. #include "BsMatrix4.h"
  7. #include "BsVector3.h"
  8. #include "BsVector2.h"
  9. #include "BsVector2I.h"
  10. #include "BsAABox.h"
  11. #include "BsQuaternion.h"
  12. #include "BsRay.h"
  13. #include "BsCoreObject.h"
  14. #include "BsConvexVolume.h"
  15. #include "BsPostProcessSettings.h"
  16. namespace bs
  17. {
  18. /** @addtogroup Renderer-Internal
  19. * @{
  20. */
  21. /** Signals which portion of a Camera is dirty. */
  22. enum class CameraDirtyFlag
  23. {
  24. Transform = 1<<0,
  25. Everything = 1<<1,
  26. PostProcess = 1<<2
  27. };
  28. /** Projection type to use by the camera. */
  29. enum ProjectionType
  30. {
  31. PT_ORTHOGRAPHIC, /**< Projection type where object size remains constant and parallel lines remain parallel. */
  32. PT_PERSPECTIVE /**< Projection type that emulates human vision. Objects farther away appear smaller. */
  33. };
  34. /** Clip planes that form the camera frustum (visible area). */
  35. enum FrustumPlane
  36. {
  37. FRUSTUM_PLANE_NEAR = 0,
  38. FRUSTUM_PLANE_FAR = 1,
  39. FRUSTUM_PLANE_LEFT = 2,
  40. FRUSTUM_PLANE_RIGHT = 3,
  41. FRUSTUM_PLANE_TOP = 4,
  42. FRUSTUM_PLANE_BOTTOM = 5
  43. };
  44. /** Flags that describe a camera. */
  45. enum class CameraFlag
  46. {
  47. /**
  48. * This flag is a signal to the renderer that his camera will only render overlays and doesn't require depth
  49. * buffer or multi-sampled render targets. Such cameras will not render any scene objects. This can improve
  50. * performance and memory usage.
  51. */
  52. Overlay = 1,
  53. /**
  54. * High dynamic range allows light intensity to be more correctly recorded when rendering by allowing for a larger
  55. * range of values. The stored light is then converted into visible color range using exposure and a tone mapping
  56. * operator.
  57. */
  58. HDR = 2
  59. };
  60. typedef Flags<CameraFlag> CameraFlags;
  61. BS_FLAGS_OPERATORS(CameraFlag);
  62. /** @} */
  63. /** @addtogroup Implementation
  64. * @{
  65. */
  66. /**
  67. * Camera determines how is world geometry projected onto a 2D surface. You may position and orient it in space, set
  68. * options like aspect ratio and field or view and it outputs view and projection matrices required for rendering.
  69. *
  70. * This class contains funcionality common to both core and non-core versions of the camera.
  71. */
  72. class BS_CORE_EXPORT CameraBase
  73. {
  74. public:
  75. virtual ~CameraBase() { }
  76. /**
  77. * Sets the camera horizontal field of view. This determines how wide the camera viewing angle is along the
  78. * horizontal axis. Vertical FOV is calculated from the horizontal FOV and the aspect ratio.
  79. */
  80. virtual void setHorzFOV(const Radian& fovy);
  81. /** Retrieves the camera horizontal field of view. */
  82. virtual const Radian& getHorzFOV() const;
  83. /**
  84. * Sets the distance from the frustum to the near clipping plane. Anything closer than the near clipping plane will
  85. * not be rendered. Decreasing this value decreases depth buffer precision.
  86. */
  87. virtual void setNearClipDistance(float nearDist);
  88. /**
  89. * Retrieves the distance from the frustum to the near clipping plane. Anything closer than the near clipping plane
  90. * will not be rendered. Decreasing this value decreases depth buffer precision.
  91. */
  92. virtual float getNearClipDistance() const;
  93. /**
  94. * Sets the distance from the frustum to the far clipping plane. Anything farther than the far clipping plane will
  95. * not be rendered. Increasing this value decreases depth buffer precision.
  96. */
  97. virtual void setFarClipDistance(float farDist);
  98. /**
  99. * Retrieves the distance from the frustum to the far clipping plane. Anything farther than the far clipping plane
  100. * will not be rendered. Increasing this value decreases depth buffer precision.
  101. */
  102. virtual float getFarClipDistance() const;
  103. /** Sets the current viewport aspect ratio (width / height). */
  104. virtual void setAspectRatio(float ratio);
  105. /** Returns current viewport aspect ratio (width / height). */
  106. virtual float getAspectRatio() const;
  107. /** Sets camera world space position. */
  108. virtual void setPosition(const Vector3& position);
  109. /** Retrieves camera world space position. */
  110. virtual Vector3 getPosition() const { return mPosition; }
  111. /** Sets should the camera be rendered to or not. */
  112. void setIsActive(bool active) { mIsActive = active; _markCoreDirty(); }
  113. /** Gets whether the camera be rendered to or not. */
  114. bool getIsActive() const { return mIsActive; }
  115. /**
  116. * Gets the Z (forward) axis of the object, in world space.
  117. *
  118. * @return Forward axis of the object.
  119. */
  120. Vector3 getForward() const { return getRotation().rotate(-Vector3::UNIT_Z); }
  121. /** Sets camera world space rotation. */
  122. virtual void setRotation(const Quaternion& rotation);
  123. /** Retrieves camera world space rotation. */
  124. virtual Quaternion getRotation() const { return mRotation; }
  125. /** Manually set the extents of the frustum that will be used when calculating the projection matrix. This will
  126. * prevents extents for being automatically calculated from aspect and near plane so it is up to the caller to keep
  127. * these values accurate.
  128. *
  129. * @param[in] left The position where the left clip plane intersect the near clip plane, in view space.
  130. * @param[in] right The position where the right clip plane intersect the near clip plane, in view space.
  131. * @param[in] top The position where the top clip plane intersect the near clip plane, in view space.
  132. * @param[in] bottom The position where the bottom clip plane intersect the near clip plane, in view space.
  133. */
  134. virtual void setFrustumExtents(float left, float right, float top, float bottom);
  135. /**
  136. * Resets frustum extents so they are automatically derived from other values. This is only relevant if you have
  137. * previously set custom extents.
  138. */
  139. virtual void resetFrustumExtents();
  140. /** Returns the extents of the frustum in view space at the near plane. */
  141. virtual void getFrustumExtents(float& outleft, float& outright, float& outtop, float& outbottom) const;
  142. /**
  143. * Returns the standard projection matrix that determines how are 3D points projected to two dimensions. The layout
  144. * of this matrix depends on currently used render system.
  145. *
  146. * @note
  147. * You should use this matrix when sending the matrix to the render system to make sure everything works
  148. * consistently when other render systems are used.
  149. */
  150. virtual const Matrix4& getProjectionMatrixRS() const;
  151. /**
  152. * Returns the inverse of the render-system specific projection matrix.
  153. *
  154. * @see getProjectionMatrixRS
  155. */
  156. virtual const Matrix4& getProjectionMatrixRSInv() const;
  157. /**
  158. * Returns the standard projection matrix that determines how are 3D points projected to two dimensions. Returned
  159. * matrix is standard following right-hand rules and depth range of [-1, 1].
  160. *
  161. * @note
  162. * Different render systems will expect different projection matrix layouts, in which case use
  163. * getProjectionMatrixRS().
  164. */
  165. virtual const Matrix4& getProjectionMatrix() const;
  166. /**
  167. * Returns the inverse of the projection matrix.
  168. *
  169. * @see getProjectionMatrix
  170. */
  171. virtual const Matrix4& getProjectionMatrixInv() const;
  172. /** Gets the camera view matrix. Used for positioning/orienting the camera. */
  173. virtual const Matrix4& getViewMatrix() const;
  174. /**
  175. * Returns the inverse of the view matrix.
  176. *
  177. * @see getViewMatrix
  178. */
  179. virtual const Matrix4& getViewMatrixInv() const;
  180. /**
  181. * Sets whether the camera should use the custom view matrix. When this is enabled camera will no longer calculate
  182. * its view matrix based on position/orientation and caller will be resonsible to keep the view matrix up to date.
  183. */
  184. virtual void setCustomViewMatrix(bool enable, const Matrix4& viewMatrix = Matrix4::IDENTITY);
  185. /** Returns true if a custom view matrix is used. */
  186. virtual bool isCustomViewMatrixEnabled() const { return mCustomViewMatrix; }
  187. /**
  188. * Sets whether the camera should use the custom projection matrix. When this is enabled camera will no longer
  189. * calculate its projection matrix based on field of view, aspect and other parameters and caller will be resonsible
  190. * to keep the projection matrix up to date.
  191. */
  192. virtual void setCustomProjectionMatrix(bool enable, const Matrix4& projectionMatrix = Matrix4::IDENTITY);
  193. /** Returns true if a custom projection matrix is used. */
  194. virtual bool isCustomProjectionMatrixEnabled() const { return mCustomProjMatrix; }
  195. /** Returns a convex volume representing the visible area of the camera, in local space. */
  196. virtual const ConvexVolume& getFrustum() const;
  197. /** Returns a convex volume representing the visible area of the camera, in world space. */
  198. virtual ConvexVolume getWorldFrustum() const;
  199. /** Returns the bounding of the frustum. */
  200. const AABox& getBoundingBox() const;
  201. /**
  202. * Sets the type of projection used by the camera. Projection type controls how is 3D geometry projected onto a
  203. * 2D plane.
  204. */
  205. virtual void setProjectionType(ProjectionType pt);
  206. /**
  207. * Returns the type of projection used by the camera. Projection type controls how is 3D geometry projected onto a
  208. * 2D plane.
  209. */
  210. virtual ProjectionType getProjectionType() const;
  211. /**
  212. * Sets the orthographic window height, for use with orthographic rendering only.
  213. *
  214. * @param[in] w Width of the window in world units.
  215. * @param[in] h Height of the window in world units.
  216. *
  217. * @note
  218. * Calling this method will recalculate the aspect ratio, use setOrthoWindowHeight() or setOrthoWindowWidth() alone
  219. * if you wish to preserve the aspect ratio but just fit one or other dimension to a particular size.
  220. */
  221. virtual void setOrthoWindow(float w, float h);
  222. /**
  223. * Sets the orthographic window height, for use with orthographic rendering only.
  224. *
  225. * @param[in] h Height of the window in world units.
  226. *
  227. * @note The width of the window will be calculated from the aspect ratio.
  228. */
  229. virtual void setOrthoWindowHeight(float h);
  230. /**
  231. * Sets the orthographic window width, for use with orthographic rendering only.
  232. *
  233. * @param[in] w Width of the window in world units.
  234. *
  235. * @note The height of the window will be calculated from the aspect ratio.
  236. */
  237. virtual void setOrthoWindowWidth(float w);
  238. /** Gets the orthographic window width in world units, for use with orthographic rendering only. */
  239. virtual float getOrthoWindowHeight() const;
  240. /**
  241. * Gets the orthographic window width in world units, for use with orthographic rendering only.
  242. *
  243. * @note This is calculated from the orthographic height and the aspect ratio.
  244. */
  245. virtual float getOrthoWindowWidth() const;
  246. /**
  247. * Gets a priority that determines in which orders the cameras are rendered. This only applies to cameras rendering
  248. * to the same render target.
  249. */
  250. INT32 getPriority() const { return mPriority; }
  251. /**
  252. * Sets a priority that determines in which orders the cameras are rendered. This only applies to cameras rendering
  253. * to the same render target.
  254. *
  255. * @param[in] priority The priority. Higher value means the camera will be rendered sooner.
  256. */
  257. void setPriority(INT32 priority) { mPriority = priority; _markCoreDirty(); }
  258. /** Retrieves layer bitfield that is used when determining which object should the camera render. */
  259. UINT64 getLayers() const { return mLayers; }
  260. /** Sets layer bitfield that is used when determining which object should the camera render. */
  261. void setLayers(UINT64 layers) { mLayers = layers; _markCoreDirty(); }
  262. /** Returns number of samples if the camera uses multiple samples per pixel. */
  263. UINT32 getMSAACount() const { return mMSAA; }
  264. /**
  265. * Enables or disables multi-sampled anti-aliasing. Set to zero or one to disable, or to the required number of
  266. * samples to enable.
  267. */
  268. void setMSAACount(UINT32 count) { mMSAA = count; _markCoreDirty(); }
  269. /** Returns settings that are used for controling post-process operations like tonemapping. */
  270. const SPtr<PostProcessSettings>& getPostProcessSettings() const { return mPPSettings; }
  271. /** Sets settings that are used for controling post-process operations like tonemapping. */
  272. void setPostProcessSettings(const SPtr<PostProcessSettings>& settings) { mPPSettings = settings; _markCoreDirty(CameraDirtyFlag::PostProcess); }
  273. /** Retrieves flags that define the camera. */
  274. CameraFlags getFlags() const { return mCameraFlags; }
  275. /** Enables or disables flags that define the camera's behaviour. */
  276. void setFlag(const CameraFlag& flag, bool enable);
  277. /**
  278. * Converts a point in world space to screen coordinates (in pixels corresponding to the render target attached to
  279. * the camera).
  280. */
  281. Vector2I worldToScreenPoint(const Vector3& worldPoint) const;
  282. /** Converts a point in world space to normalized device coordinates (in [-1, 1] range). */
  283. Vector2 worldToNdcPoint(const Vector3& worldPoint) const;
  284. /** Converts a point in world space to point relative to camera's coordinate system (view space). */
  285. Vector3 worldToViewPoint(const Vector3& worldPoint) const;
  286. /**
  287. * Converts a point in screen space (pixels corresponding to render target attached to the camera) to a point in
  288. * world space.
  289. *
  290. * @param[in] screenPoint Point to transform.
  291. * @param[in] depth Depth to place the world point at, in world coordinates. The depth is applied to the
  292. * vector going from camera origin to the point on the near plane.
  293. */
  294. Vector3 screenToWorldPoint(const Vector2I& screenPoint, float depth = 0.5f) const;
  295. /**
  296. * Converts a point in screen space (pixels corresponding to render target attached to the camera) to a point in
  297. * world space.
  298. *
  299. * @param[in] screenPoint Point to transform.
  300. * @param[in] deviceDepth Depth to place the world point at, in normalized device coordinates.
  301. */
  302. Vector3 screenToWorldPointDeviceDepth(const Vector2I& screenPoint, float deviceDepth = 0.5f) const;
  303. /**
  304. * Converts a point in screen space (pixels corresponding to render target attached to the camera) to a point
  305. * relative to camera's coordinate system (view space).
  306. *
  307. * @param[in] screenPoint Point to transform.
  308. * @param[in] depth Depth to place the world point at. The depth is applied to the vector going from camera
  309. * origin to the point on the near plane.
  310. */
  311. Vector3 screenToViewPoint(const Vector2I& screenPoint, float depth = 0.5f) const;
  312. /**
  313. * Converts a point in screen space (pixels corresponding to render target attached to the camera) to normalized
  314. * device coordinates (in [-1, 1] range).
  315. */
  316. Vector2 screenToNdcPoint(const Vector2I& screenPoint) const;
  317. /** Converts a point relative to camera's coordinate system (view space) into a point in world space. */
  318. Vector3 viewToWorldPoint(const Vector3& viewPoint) const;
  319. /**
  320. * Converts a point relative to camera's coordinate system (view space) into a point in screen space (pixels
  321. * corresponding to render target attached to the camera).
  322. */
  323. Vector2I viewToScreenPoint(const Vector3& viewPoint) const;
  324. /**
  325. * Converts a point relative to camera's coordinate system (view space) into normalized device coordinates
  326. * (in [-1, 1] range).
  327. */
  328. Vector2 viewToNdcPoint(const Vector3& viewPoint) const;
  329. /**
  330. * Converts a point in normalized device coordinates ([-1, 1] range) to a point in world space.
  331. *
  332. * @param[in] ndcPoint Point to transform.
  333. * @param[in] depth Depth to place the world point at. The depth is applied to the vector going from camera
  334. * origin to the point on the near plane.
  335. */
  336. Vector3 ndcToWorldPoint(const Vector2& ndcPoint, float depth = 0.5f) const;
  337. /**
  338. * Converts a point in normalized device coordinates ([-1, 1] range) to a point relative to camera's coordinate system
  339. * (view space).
  340. *
  341. * @param[in] ndcPoint Point to transform.
  342. * @param[in] depth Depth to place the world point at. The depth is applied to the vector going from camera
  343. * origin to the point on the near plane.
  344. */
  345. Vector3 ndcToViewPoint(const Vector2& ndcPoint, float depth = 0.5f) const;
  346. /**
  347. * Converts a point in normalized device coordinates ([-1, 1] range) to a point in screen space (pixels corresponding
  348. * to render target attached to the camera).
  349. */
  350. Vector2I ndcToScreenPoint(const Vector2& ndcPoint) const;
  351. /**
  352. * Converts a point in screen space (pixels corresponding to render target attached to the camera) to a ray in world
  353. * space originating at the selected point on the camera near plane.
  354. */
  355. Ray screenPointToRay(const Vector2I& screenPoint) const;
  356. /** Projects a point from view to normalized device space. */
  357. Vector3 projectPoint(const Vector3& point) const;
  358. /** Un-projects a point in normalized device space to view space. */
  359. Vector3 unprojectPoint(const Vector3& point) const;
  360. static const float INFINITE_FAR_PLANE_ADJUST; /**< Small constant used to reduce far plane projection to avoid inaccuracies. */
  361. protected:
  362. CameraBase();
  363. /** Calculate projection parameters that are used when constructing the projection matrix. */
  364. virtual void calcProjectionParameters(float& left, float& right, float& bottom, float& top) const;
  365. /** Recalculate frustum if dirty. */
  366. virtual void updateFrustum() const;
  367. /** Recalculate frustum planes if dirty. */
  368. virtual void updateFrustumPlanes() const;
  369. /**
  370. * Update view matrix from parent position/orientation.
  371. *
  372. * @note Does nothing when custom view matrix is set.
  373. */
  374. virtual void updateView() const;
  375. /** Checks if the frustum requires updating. */
  376. virtual bool isFrustumOutOfDate() const;
  377. /** Notify camera that the frustum requires to be updated. */
  378. virtual void invalidateFrustum() const;
  379. /** Returns a rectangle that defines the viewport position and size, in pixels. */
  380. virtual Rect2I getViewportRect() const = 0;
  381. /**
  382. * Marks the simulation thread object as dirty and notifies the system its data should be synced with its core
  383. * thread counterpart.
  384. */
  385. virtual void _markCoreDirty(CameraDirtyFlag flag = CameraDirtyFlag::Everything) { }
  386. protected:
  387. UINT64 mLayers; /**< Bitfield that can be used for filtering what objects the camera sees. */
  388. CameraFlags mCameraFlags; /**< Flags that further determine type of camera. */
  389. Vector3 mPosition; /**< World space position. */
  390. Quaternion mRotation; /**< World space rotation. */
  391. bool mIsActive; /**< Is camera being rendered to. */
  392. ProjectionType mProjType; /**< Type of camera projection. */
  393. Radian mHorzFOV; /**< Horizontal field of view represents how wide is the camera angle. */
  394. float mFarDist; /**< Clip any objects further than this. Larger value decreases depth precision at smaller depths. */
  395. float mNearDist; /**< Clip any objects close than this. Smaller value decreases depth precision at larger depths. */
  396. float mAspect; /**< Width/height viewport ratio. */
  397. float mOrthoHeight; /**< Height in world units used for orthographic cameras. */
  398. INT32 mPriority; /**< Determines in what order will the camera be rendered. Higher priority means the camera will be rendered sooner. */
  399. bool mCustomViewMatrix; /**< Is custom view matrix set. */
  400. bool mCustomProjMatrix; /**< Is custom projection matrix set. */
  401. UINT8 mMSAA; /**< Number of samples to render the scene with. */
  402. SPtr<PostProcessSettings> mPPSettings; /**< Settings used to control post-process operations. */
  403. bool mFrustumExtentsManuallySet; /**< Are frustum extents manually set. */
  404. mutable Matrix4 mProjMatrixRS; /**< Cached render-system specific projection matrix. */
  405. mutable Matrix4 mProjMatrix; /**< Cached projection matrix that determines how are 3D points projected to a 2D viewport. */
  406. mutable Matrix4 mViewMatrix; /**< Cached view matrix that determines camera position/orientation. */
  407. mutable Matrix4 mProjMatrixRSInv;
  408. mutable Matrix4 mProjMatrixInv;
  409. mutable Matrix4 mViewMatrixInv;
  410. mutable ConvexVolume mFrustum; /**< Main clipping planes describing cameras visible area. */
  411. mutable bool mRecalcFrustum : 1; /**< Should frustum be recalculated. */
  412. mutable bool mRecalcFrustumPlanes : 1; /**< Should frustum planes be recalculated. */
  413. mutable bool mRecalcView : 1; /**< Should view matrix be recalculated. */
  414. mutable float mLeft, mRight, mTop, mBottom; /**< Frustum extents. */
  415. mutable AABox mBoundingBox; /**< Frustum bounding box. */
  416. };
  417. /** @copydoc CameraBase */
  418. template<bool Core>
  419. class TCamera : public CameraBase
  420. {
  421. public:
  422. typedef typename TTextureType<Core>::Type TextureType;
  423. /**
  424. * Sets a texture that will be used for rendering areas of the camera's render target not covered by any geometry.
  425. * If not set a clear color will be used instead.
  426. */
  427. void setSkybox(const TextureType& texture) { mSkyTexture = texture; _markCoreDirty(); }
  428. /** @see setSkybox() */
  429. TextureType getSkybox() const { return mSkyTexture; }
  430. protected:
  431. TextureType mSkyTexture;
  432. };
  433. /** @} */
  434. /** @addtogroup Renderer-Engine-Internal
  435. * @{
  436. */
  437. /** @copydoc CameraBase */
  438. class BS_CORE_EXPORT Camera : public IReflectable, public CoreObject, public TCamera<false>
  439. {
  440. public:
  441. /** Returns the viewport used by the camera. */
  442. SPtr<Viewport> getViewport() const { return mViewport; }
  443. /**
  444. * Determines whether this is the main application camera. Main camera controls the final render surface that is
  445. * displayed to the user.
  446. */
  447. bool isMain() const { return mMain; }
  448. /**
  449. * Marks or unmarks this camera as the main application camera. Main camera controls the final render surface that
  450. * is displayed to the user.
  451. */
  452. void setMain(bool main) { mMain = main; }
  453. /** Retrieves an implementation of a camera handler usable only from the core thread. */
  454. SPtr<ct::Camera> getCore() const;
  455. /** Creates a new camera that renders to the specified portion of the provided render target. */
  456. static SPtr<Camera> create(SPtr<RenderTarget> target = nullptr,
  457. float left = 0.0f, float top = 0.0f, float width = 1.0f, float height = 1.0f);
  458. /** @name Internal
  459. * @{
  460. */
  461. /** Returns the hash value that can be used to identify if the internal data needs an update. */
  462. UINT32 _getLastModifiedHash() const { return mLastUpdateHash; }
  463. /** Sets the hash value that can be used to identify if the internal data needs an update. */
  464. void _setLastModifiedHash(UINT32 hash) { mLastUpdateHash = hash; }
  465. /** @} */
  466. protected:
  467. Camera(SPtr<RenderTarget> target = nullptr,
  468. float left = 0.0f, float top = 0.0f, float width = 1.0f, float height = 1.0f);
  469. /** @copydoc CameraBase */
  470. Rect2I getViewportRect() const override;
  471. /** @copydoc CoreObject::createCore */
  472. SPtr<ct::CoreObject> createCore() const override;
  473. /** @copydoc CameraBase::_markCoreDirty */
  474. void _markCoreDirty(CameraDirtyFlag flag = CameraDirtyFlag::Everything) override;
  475. /** @copydoc CoreObject::syncToCore */
  476. CoreSyncData syncToCore(FrameAlloc* allocator) override;
  477. /** @copydoc CoreObject::getCoreDependencies */
  478. void getCoreDependencies(Vector<CoreObject*>& dependencies) override;
  479. /** Creates a new camera without initializing it. */
  480. static SPtr<Camera> createEmpty();
  481. SPtr<Viewport> mViewport; /**< Viewport that describes 2D rendering surface. */
  482. bool mMain;
  483. UINT32 mLastUpdateHash;
  484. /************************************************************************/
  485. /* RTTI */
  486. /************************************************************************/
  487. public:
  488. friend class CameraRTTI;
  489. static RTTITypeBase* getRTTIStatic();
  490. RTTITypeBase* getRTTI() const override;
  491. };
  492. namespace ct
  493. {
  494. /** @copydoc CameraBase */
  495. class BS_CORE_EXPORT Camera : public CoreObject, public TCamera<true>
  496. {
  497. public:
  498. ~Camera();
  499. /** Returns the viewport used by the camera. */
  500. SPtr<Viewport> getViewport() const { return mViewport; }
  501. protected:
  502. friend class bs::Camera;
  503. Camera(SPtr<RenderTarget> target = nullptr,
  504. float left = 0.0f, float top = 0.0f, float width = 1.0f, float height = 1.0f);
  505. Camera(const SPtr<Viewport>& viewport);
  506. /** @copydoc CoreObject::initialize */
  507. void initialize() override;
  508. /** @copydoc CameraBase */
  509. Rect2I getViewportRect() const override;
  510. /** @copydoc CoreObject::syncToCore */
  511. void syncToCore(const CoreSyncData& data) override;
  512. SPtr<Viewport> mViewport;
  513. };
  514. }
  515. /** @} */
  516. }