BsRendererObject.h 3.7 KB

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