BsRendererObject.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. /**
  73. * Binding for a parameter block containing a list of lights influencing this object. Only used when standard
  74. * (non-clustered) forward rendering is used.
  75. */
  76. GpuParamBinding lightsParamBlockBinding;
  77. /**
  78. * Binding for a parameter block that contains the number of lights and reflection probes in the light/refl. probe
  79. * parameter blocks. Only used when standard (non-clustered) forward rendering is used.
  80. */
  81. GpuParamBinding lightAndReflProbeParamsParamBlockBinding;
  82. /** GPU buffer containing element's bone matrices, if it requires any. */
  83. SPtr<GpuBuffer> boneMatrixBuffer;
  84. /** Vertex buffer containing element's morph shape vertices, if it has any. */
  85. SPtr<VertexBuffer> morphShapeBuffer;
  86. /** Vertex declaration used for rendering meshes containing morph shape information. */
  87. SPtr<VertexDeclaration> morphVertexDeclaration;
  88. /** Version of the morph shape vertices in the buffer. */
  89. mutable UINT32 morphShapeVersion;
  90. };
  91. /** Contains information about a Renderable, used by the Renderer. */
  92. struct RendererObject
  93. {
  94. RendererObject();
  95. /** Updates the per-object GPU buffer according to the currently set properties. */
  96. void updatePerObjectBuffer();
  97. /**
  98. * Updates the per-call GPU buffer according to the provided parameters.
  99. *
  100. * @param[in] viewProj Combined view-projection matrix of the current camera.
  101. * @param[in] flush True if the buffer contents should be immediately flushed to the GPU.
  102. */
  103. void updatePerCallBuffer(const Matrix4& viewProj, bool flush = true);
  104. Renderable* renderable;
  105. Vector<BeastRenderableElement> elements;
  106. SPtr<GpuParamBlockBuffer> perObjectParamBuffer;
  107. SPtr<GpuParamBlockBuffer> perCallParamBuffer;
  108. };
  109. /** @} */
  110. }}