1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#pragma once
4
5#include "BsRenderBeastPrerequisites.h"
6#include "Renderer/BsRenderElement.h"
7#include "Renderer/BsRenderable.h"
8#include "Renderer/BsParamBlocks.h"
9#include "Material/BsMaterialParam.h"
10#include "RenderAPI/BsGpuPipelineParamInfo.h"
11#include "BsRendererReflectionProbe.h"
12
13namespace bs { namespace ct
14{
15 /** @addtogroup RenderBeast
16 * @{
17 */
18
19 BS_PARAM_BLOCK_BEGIN(PerObjectParamDef)
20 BS_PARAM_BLOCK_ENTRY(Matrix4, gMatWorld)
21 BS_PARAM_BLOCK_ENTRY(Matrix4, gMatInvWorld)
22 BS_PARAM_BLOCK_ENTRY(Matrix4, gMatWorldNoScale)
23 BS_PARAM_BLOCK_ENTRY(Matrix4, gMatInvWorldNoScale)
24 BS_PARAM_BLOCK_ENTRY(float, gWorldDeterminantSign)
25 BS_PARAM_BLOCK_ENTRY(INT32, gLayer)
26 BS_PARAM_BLOCK_END
27
28 extern PerObjectParamDef gPerObjectParamDef;
29
30 BS_PARAM_BLOCK_BEGIN(PerCallParamDef)
31 BS_PARAM_BLOCK_ENTRY(Matrix4, gMatWorldViewProj)
32 BS_PARAM_BLOCK_END
33
34 extern PerCallParamDef gPerCallParamDef;
35
36 /** Helper class used for manipulating the PerObject parameter buffer. */
37 class PerObjectBuffer
38 {
39 public:
40 /** Updates the provided buffer with the data from the provided matrices. */
41 static void update(SPtr<GpuParamBlockBuffer>& buffer, const Matrix4& tfrm, const Matrix4& tfrmNoScale,
42 UINT32 layer);
43 };
44
45 struct MaterialSamplerOverrides;
46
47 /**
48 * Contains information required for rendering a single Renderable sub-mesh, representing a generic static or animated
49 * 3D model.
50 */
51 class RenderableElement final : public RenderElement
52 {
53 public:
54 /**
55 * Optional overrides for material sampler states. Used when renderer wants to override certain sampling properties
56 * on a global scale (for example filtering most commonly).
57 */
58 MaterialSamplerOverrides* samplerOverrides;
59
60 /** Identifier of the animation running on the renderable's mesh. -1 if no animation. */
61 UINT64 animationId;
62
63 /** Type of animation applied to this element, if any. */
64 RenderableAnimType animType;
65
66 /** Binding indices representing where should the per-camera param block buffer be bound to. */
67 GpuParamBinding perCameraBindings[GPT_COUNT];
68
69 /** Collection of parameters used for direct lighting using the forward rendering path. */
70 ForwardLightingParams forwardLightingParams;
71
72 /** Collection of parameters used for image based lighting. */
73 ImageBasedLightingParams imageBasedParams;
74
75 /** GPU buffer containing element's bone matrices, if it requires any. */
76 SPtr<GpuBuffer> boneMatrixBuffer;
77
78 /** Vertex buffer containing element's morph shape vertices, if it has any. */
79 SPtr<VertexBuffer> morphShapeBuffer;
80
81 /** Vertex declaration used for rendering meshes containing morph shape information. */
82 SPtr<VertexDeclaration> morphVertexDeclaration;
83
84 /** Time to used for evaluating material animation. */
85 float materialAnimationTime = 0.0f;
86
87 /** Version of the morph shape vertices in the buffer. */
88 mutable UINT32 morphShapeVersion;
89
90 /** @copydoc RenderElement::draw */
91 void draw() const override;
92 };
93
94 /** Contains information about a Renderable, used by the Renderer. */
95 struct RendererRenderable
96 {
97 RendererRenderable();
98
99 /** Updates the per-object GPU buffer according to the currently set properties. */
100 void updatePerObjectBuffer();
101
102 /**
103 * Updates the per-call GPU buffer according to the provided parameters.
104 *
105 * @param[in] viewProj Combined view-projection matrix of the current camera.
106 * @param[in] flush True if the buffer contents should be immediately flushed to the GPU.
107 */
108 void updatePerCallBuffer(const Matrix4& viewProj, bool flush = true);
109
110 Renderable* renderable;
111 Vector<RenderableElement> elements;
112
113 SPtr<GpuParamBlockBuffer> perObjectParamBuffer;
114 SPtr<GpuParamBlockBuffer> perCallParamBuffer;
115 };
116
117 /** @} */
118}}
119