2
0

BsCamera.h 24 KB

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