BsRendererCamera.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsRenderBeastPrerequisites.h"
  5. #include "BsPostProcessing.h"
  6. #include "BsObjectRendering.h"
  7. #include "BsRenderQueue.h"
  8. #include "BsRendererObject.h"
  9. #include "BsBounds.h"
  10. namespace BansheeEngine
  11. {
  12. /** @addtogroup RenderBeast
  13. * @{
  14. */
  15. /** Contains information about a Camera, used by the Renderer. */
  16. class RendererCamera
  17. {
  18. public:
  19. RendererCamera();
  20. RendererCamera(const CameraCore* camera, StateReduction reductionMode);
  21. /** Updates the internal camera data, usually called after source camera changes. */
  22. void update(StateReduction reductionMode);
  23. /** Updates the internal camera post-processing data. */
  24. void updatePP();
  25. /**
  26. * Prepares camera render targets for rendering. When done call endRendering().
  27. *
  28. * @param[in] useRenderTargets If using the internal render targets containing the GBuffer (retrieved via
  29. * getRenderTargets()) while rendering you must set this to true.
  30. */
  31. void beginRendering(bool useRenderTargets);
  32. /** Ends rendering and frees any acquired resources. */
  33. void endRendering();
  34. /** Returns the camera's renderTargets. Only valid if called in-between beginRendering() and endRendering() calls. */
  35. SPtr<RenderTargets> getRenderTargets() const { return mRenderTargets; }
  36. /**
  37. * Returns a render queue containing all opaque objects. Make sure to call determineVisible() beforehand if camera
  38. * or object transforms changed since the last time it was called.
  39. */
  40. const SPtr<RenderQueue>& getOpaqueQueue() const { return mOpaqueQueue; }
  41. /**
  42. * Returns a render queue containing all transparent objects. Make sure to call determineVisible() beforehand if
  43. * camera or object transforms changed since the last time it was called.
  44. */
  45. const SPtr<RenderQueue>& getTransparentQueue() const { return mTransparentQueue; }
  46. /**
  47. * Populates camera render queues by determining visible renderable objects.
  48. *
  49. * @param[in] renderables A set of renderable objects to iterate over and determine visibility for.
  50. * @param[in] renderableBounds A set of world bounds for the provided renderable objects. Must be the same size
  51. * as the @p renderables array.
  52. * @param[in] visibility Output parameter that will have the true bit set for any visible renderable
  53. * object. If the bit for an object is already set to true, the method will never
  54. * change it to false which allows the same bitfield to be provided to multiple
  55. * renderer cameras. Must be the same size as the @p renderables array.
  56. */
  57. void determineVisible(Vector<RendererObject>& renderables, const Vector<Bounds>& renderableBounds,
  58. Vector<bool>& visibility);
  59. /**
  60. * Returns a structure containing information about post-processing effects. This structure will be modified and
  61. * maintained by the post-processing system.
  62. */
  63. PostProcessInfo& getPPInfo() { return mPostProcessInfo; }
  64. /** Returns an object with camera's information, used for populating per-camera parameter buffers. */
  65. CameraShaderData getShaderData();
  66. private:
  67. /**
  68. * Extracts the necessary values from the projection matrix that allow you to transform device Z value into
  69. * world Z value.
  70. *
  71. * @param[in] projMatrix Projection matrix that was used to create the device Z value to transform.
  72. * @return Returns two values that can be used to transform device z to world z using this formula:
  73. * z = (deviceZ + y) * x.
  74. */
  75. Vector2 getDeviceZTransform(const Matrix4& projMatrix) const;
  76. const CameraCore* mCamera;
  77. SPtr<RenderQueue> mOpaqueQueue;
  78. SPtr<RenderQueue> mTransparentQueue;
  79. SPtr<RenderTargets> mRenderTargets;
  80. PostProcessInfo mPostProcessInfo;
  81. bool mUsingRenderTargets;
  82. };
  83. /** @} */
  84. }