BsRendererObject.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 "Renderer/BsRenderableElement.h"
  6. #include "Renderer/BsRenderable.h"
  7. #include "Renderer/BsParamBlocks.h"
  8. #include "Material/BsMaterialParam.h"
  9. #include "RenderAPI/BsGpuPipelineParamInfo.h"
  10. #include "BsImageBasedLighting.h"
  11. namespace bs { namespace ct
  12. {
  13. /** @addtogroup RenderBeast
  14. * @{
  15. */
  16. BS_PARAM_BLOCK_BEGIN(PerObjectParamDef)
  17. BS_PARAM_BLOCK_ENTRY(Matrix4, gMatWorld)
  18. BS_PARAM_BLOCK_ENTRY(Matrix4, gMatInvWorld)
  19. BS_PARAM_BLOCK_ENTRY(Matrix4, gMatWorldNoScale)
  20. BS_PARAM_BLOCK_ENTRY(Matrix4, gMatInvWorldNoScale)
  21. BS_PARAM_BLOCK_ENTRY(float, gWorldDeterminantSign)
  22. BS_PARAM_BLOCK_END
  23. extern PerObjectParamDef gPerObjectParamDef;
  24. BS_PARAM_BLOCK_BEGIN(PerCallParamDef)
  25. BS_PARAM_BLOCK_ENTRY(Matrix4, gMatWorldViewProj)
  26. BS_PARAM_BLOCK_END
  27. extern PerCallParamDef gPerCallParamDef;
  28. struct MaterialSamplerOverrides;
  29. /**
  30. * @copydoc RenderableElement
  31. *
  32. * Contains additional data specific to RenderBeast renderer.
  33. */
  34. class BeastRenderableElement : public RenderableElement
  35. {
  36. public:
  37. /**
  38. * Optional overrides for material sampler states. Used when renderer wants to override certain sampling properties
  39. * on a global scale (for example filtering most commonly).
  40. */
  41. MaterialSamplerOverrides* samplerOverrides;
  42. /** All GPU parameters from the material used by the renderable. */
  43. SPtr<GpuParamsSet> params;
  44. /** Identifier of the owner renderable. */
  45. UINT32 renderableId;
  46. /** Identifier of the animation running on the renderable's mesh. -1 if no animation. */
  47. UINT64 animationId;
  48. /** Type of animation applied to this element, if any. */
  49. RenderableAnimType animType;
  50. /** Index of the technique in the material to render the element with. */
  51. UINT32 techniqueIdx;
  52. /** Binding indices representing where should the per-camera param block buffer be bound to. */
  53. GpuParamBinding perCameraBindings[GPT_COUNT];
  54. /** Binding indices representing where should lights param block buffer be bound to. */
  55. GpuParamBinding gridParamsBindings[GPT_COUNT];
  56. /**
  57. * Parameter to which to bind a buffer containing light grid offsets and size, per grid cell. Used for forward
  58. * rendering.
  59. */
  60. GpuParamBuffer gridLightOffsetsAndSizeParam;
  61. /** Parameter to which to bind a buffer containing all light indices, as mapped by grid offsets & size. */
  62. GpuParamBuffer gridLightIndicesParam;
  63. /** Parameter to which to bind light buffer used for forward rendering. */
  64. GpuParamBuffer lightsBufferParam;
  65. /**
  66. * Parameter to which to bind a buffer containing reflection probe grid offsets and size, per grid cell. Used for
  67. * forward rendering.
  68. */
  69. GpuParamBuffer gridProbeOffsetsAndSizeParam;
  70. /** Collection of parameters used for image based lighting. */
  71. ImageBasedLightingParams imageBasedParams;
  72. /** GPU buffer containing element's bone matrices, if it requires any. */
  73. SPtr<GpuBuffer> boneMatrixBuffer;
  74. /** Vertex buffer containing element's morph shape vertices, if it has any. */
  75. SPtr<VertexBuffer> morphShapeBuffer;
  76. /** Vertex declaration used for rendering meshes containing morph shape information. */
  77. SPtr<VertexDeclaration> morphVertexDeclaration;
  78. /** Version of the morph shape vertices in the buffer. */
  79. mutable UINT32 morphShapeVersion;
  80. };
  81. /** Contains information about a Renderable, used by the Renderer. */
  82. struct RendererObject
  83. {
  84. RendererObject();
  85. /** Updates the per-object GPU buffer according to the currently set properties. */
  86. void updatePerObjectBuffer();
  87. /**
  88. * Updates the per-call GPU buffer according to the provided parameters.
  89. *
  90. * @param[in] viewProj Combined view-projection matrix of the current camera.
  91. * @param[in] flush True if the buffer contents should be immediately flushed to the GPU.
  92. */
  93. void updatePerCallBuffer(const Matrix4& viewProj, bool flush = true);
  94. Renderable* renderable;
  95. Vector<BeastRenderableElement> elements;
  96. SPtr<GpuParamBlockBuffer> perObjectParamBuffer;
  97. SPtr<GpuParamBlockBuffer> perCallParamBuffer;
  98. };
  99. /** @} */
  100. }}