BsRendererObject.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. /** Shader variation that controls the type of vertex input that is provided. */
  53. const ShaderVariation* vertexInputVariation = nullptr;
  54. /** Binding indices representing where should the per-camera param block buffer be bound to. */
  55. GpuParamBinding perCameraBindings[GPT_COUNT];
  56. /** Binding indices representing where should lights param block buffer be bound to. */
  57. GpuParamBinding gridParamsBindings[GPT_COUNT];
  58. /**
  59. * Parameter to which to bind a buffer containing light grid offsets and size, per grid cell. Used for forward
  60. * rendering.
  61. */
  62. GpuParamBuffer gridLightOffsetsAndSizeParam;
  63. /** Parameter to which to bind a buffer containing all light indices, as mapped by grid offsets & size. */
  64. GpuParamBuffer gridLightIndicesParam;
  65. /** Parameter to which to bind light buffer used for forward rendering. */
  66. GpuParamBuffer lightsBufferParam;
  67. /**
  68. * Parameter to which to bind a buffer containing reflection probe grid offsets and size, per grid cell. Used for
  69. * forward rendering.
  70. */
  71. GpuParamBuffer gridProbeOffsetsAndSizeParam;
  72. /** Collection of parameters used for image based lighting. */
  73. ImageBasedLightingParams imageBasedParams;
  74. /** GPU buffer containing element's bone matrices, if it requires any. */
  75. SPtr<GpuBuffer> boneMatrixBuffer;
  76. /** Vertex buffer containing element's morph shape vertices, if it has any. */
  77. SPtr<VertexBuffer> morphShapeBuffer;
  78. /** Vertex declaration used for rendering meshes containing morph shape information. */
  79. SPtr<VertexDeclaration> morphVertexDeclaration;
  80. /** Version of the morph shape vertices in the buffer. */
  81. mutable UINT32 morphShapeVersion;
  82. };
  83. /** Contains information about a Renderable, used by the Renderer. */
  84. struct RendererObject
  85. {
  86. RendererObject();
  87. /** Updates the per-object GPU buffer according to the currently set properties. */
  88. void updatePerObjectBuffer();
  89. /**
  90. * Updates the per-call GPU buffer according to the provided parameters.
  91. *
  92. * @param[in] viewProj Combined view-projection matrix of the current camera.
  93. * @param[in] flush True if the buffer contents should be immediately flushed to the GPU.
  94. */
  95. void updatePerCallBuffer(const Matrix4& viewProj, bool flush = true);
  96. Renderable* renderable;
  97. Vector<BeastRenderableElement> elements;
  98. SPtr<GpuParamBlockBuffer> perObjectParamBuffer;
  99. SPtr<GpuParamBlockBuffer> perCallParamBuffer;
  100. };
  101. /** @} */
  102. }}