BsRendererObject.h 4.1 KB

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