1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     gfx_SceneUpdater.h
4 
5   Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain proprietary
8   information of Nintendo and/or its licensed developers and are protected by
9   national and international copyright laws. They may not be disclosed to third
10   parties or copied or duplicated in any form, in whole or in part, without the
11   prior written consent of Nintendo.
12 
13   The content herein is highly confidential and should be handled accordingly.
14 
15   $Revision: 31311 $
16  *---------------------------------------------------------------------------*/
17 
18 #ifndef NW_GFX_SCENEUPDATER_H_
19 #define NW_GFX_SCENEUPDATER_H_
20 
21 #include <nw/gfx/gfx_ISceneUpdater.h>
22 #include <nw/gfx/gfx_RenderQueue.h>
23 
24 namespace nw
25 {
26 namespace gfx
27 {
28 
29 class SkeletonUpdater;
30 class WorldMatrixUpdater;
31 class BillboardUpdater;
32 
33 class SceneContext;
34 
35 //---------------------------------------------------------------------------
36 //! @brief        シーンの更新を行うためのクラスです。
37 //---------------------------------------------------------------------------
38 class SceneUpdater  : public ISceneUpdater
39 {
40 private:
41     NW_DISALLOW_COPY_AND_ASSIGN(SceneUpdater);
42 
43 public:
44     NW_UT_RUNTIME_TYPEINFO;
45 
46     //----------------------------------------
47     //! @name 作成
48     //@{
49 
50     //! シーンアップデータクラスを構築するためのクラスです。
51     class Builder
52     {
53     public:
Builder()54         Builder() {}
55 
56         //! @brief スケルトンアップデータを設定します。
57         //!        所有権が移動しますので SceneUpdater を破棄する際に一緒に破棄されます。
SkeletonUpdaterPtr(SkeletonUpdater * skeletonUpdater)58         Builder& SkeletonUpdaterPtr(SkeletonUpdater* skeletonUpdater)
59         {
60             m_SkeletonUpdater.Reset(skeletonUpdater);
61             return *this;
62         }
63 
64         //! @brief ワールドマトリクスアップデータを設定します。
65         //!        所有権が移動しますので SceneUpdater を破棄する際に一緒に破棄されます。
WorldMatrixUpdaterPtr(WorldMatrixUpdater * worldMatrixUpdater)66         Builder& WorldMatrixUpdaterPtr(WorldMatrixUpdater* worldMatrixUpdater)
67         {
68             m_WorldMatrixUpdater.Reset(worldMatrixUpdater);
69             return *this;
70         }
71 
72         //! @brief ビルボードアップデータを設定します。
73         //!        所有権が移動しますので SceneUpdater を破棄する際に一緒に破棄されます。
BillboardUpdaterPtr(BillboardUpdater * billboardUpdater)74         Builder& BillboardUpdaterPtr(BillboardUpdater* billboardUpdater)
75         {
76             m_BillboardUpdater.Reset(billboardUpdater);
77             return *this;
78         }
79 
80         //! @brief        シーンアップデータを生成します。
81         //!
82         //! @param[in]    allocator
83         //!
84         //! @return       生成したシーンアップデータを返します。
85         //!
86         SceneUpdater* Create(os::IAllocator* allocator);
87 
88     private:
89         GfxPtr<SkeletonUpdater> m_SkeletonUpdater;
90         GfxPtr<WorldMatrixUpdater> m_WorldMatrixUpdater;
91         GfxPtr<BillboardUpdater> m_BillboardUpdater;
92     };
93 
94     //@}
95 
96     //----------------------------------------
97     //! @name 取得/設定
98     //@{
99 
100     //! @brief 深度ソートモードを取得します。
GetDepthSortMode()101     virtual DepthSortMode GetDepthSortMode() const { return m_DepthSortMode; }
102 
103     //! @brief 深度ソートモードを設定します。
SetDepthSortMode(DepthSortMode depthSortMode)104     virtual void SetDepthSortMode(DepthSortMode depthSortMode)
105     {
106         m_DepthSortMode = depthSortMode;
107     }
108 
109     //@}
110 
111     //----------------------------------------
112     //! @name 更新
113     //@{
114 
115     //! @brief        シーンを更新します。アニメーションの更新も同時に行います。
116     //!
117     //! 下記のメソッドを個別に呼び出す場合は UpdateAll を用いないようにしてください。
118     //!
119     //! ・UpdateTransformNode@n
120     //! ・UpdateSkeletalModel@n
121     //! ・UpdateAnim@n
122     //! ・EvaluateAnim@n
123     //!
124     //! @param[in]    sceneContext 更新対象です。
125     //!
126     //! @sa UpdateTransformNode
127     //! @sa UpdateSkeletalModel
128     //! @sa UpdateAnim
129     //! @sa EvaluateAnim
130     //!
131     virtual void UpdateAll(SceneContext* sceneContext);
132 
133     //! @brief        トランスフォームノードのワールドマトリクスを更新します。
134     //!
135     //! @param[in]    sceneContext 更新対象です。
136     //!
137     void UpdateTransformNode(SceneContext* sceneContext) const;
138 
139     //! @brief        スケルタルモデルのワールドマトリクスを更新します。
140     //!
141     //! SkeletalModel::GetFullBakedAnimEnabled が true の場合は、更新が省略されます。
142     //!
143     //! @param[in]    sceneContext 更新対象です。
144     //!
145     void UpdateSkeletalModel(SceneContext* sceneContext) const;
146 
147     //! @brief        アニメーションフレームを進めます。
148     //!
149     //! @param[in]    sceneContext 更新対象です。
150     //!
151     void UpdateAnim(SceneContext* sceneContext) const;
152 
153     //! @brief        アニメーションを評価します。
154     //!
155     //! @param[in]    sceneContext 更新対象です。
156     //! @param[in]    timing アニメーションの評価タイミングです。
157     //!                      タイミングが一致するアニメーションのみが評価されます。
158     //!
159     void EvaluateAnim(SceneContext* sceneContext, anim::ResGraphicsAnimGroup::EvaluationTiming timing) const;
160 
161     //@}
162 
163     //----------------------------------------
164     //! @name カメラによる更新
165     //@{
166 
167     //! @brief        カメラの視界に基づいてシーンを更新し、描画キューを構築します。
168     //!
169     //! @param[in]    renderQueue 描画対象となる要素を集めたキューです。
170     //! @param[in]    sceneContext シーンコンテキストです。
171     //! @param[in]    camera カメラです。
172     //! @param[in]    layerId 描画要素のソート時に最優先に区分される ID です。レイヤーやビューポートの描画を制御するのに用います。
173     //! @param[in]    renderSortMode 描画ソートモードです。
174     //!
175     virtual void SubmitView(
176         RenderQueue* renderQueue,
177         SceneContext* sceneContext,
178         const Camera& camera,
179         u8 layerId,
180         RenderSortMode renderSortMode = ALL_MESH_BASE_SORT);
181 
182     //! @brief        カメラの視界に基づいてシーンを更新し、描画キューを構築します。
183     //!
184     //! パーティクルを別レイヤーで描画するための SubmitView です。
185     //!
186     //! @param[in]    renderQueue 描画対象となる要素を集めたキューです。
187     //! @param[in]    sceneContext シーンコンテキストです。
188     //! @param[in]    camera カメラです。
189     //! @param[in]    layerId 描画要素のソート時に最優先に区分される ID です。レイヤーやビューポートの描画を制御するのに用います。
190     //! @param[in]    particleLayerId パーティクル描画用の layerId です。
191     //! @param[in]    renderSortMode 描画ソートモードです。
192     //!
193     virtual void SubmitView(
194         RenderQueue* renderQueue,
195         SceneContext* sceneContext,
196         const Camera& camera,
197         u8 layerId,
198         u8 particleLayerId,
199         RenderSortMode renderSortMode = ALL_MESH_BASE_SORT);
200 
201     //! @brief        カメラの視界に基づいてシーンを更新し、描画キューを構築します。
202     //!
203     //! パーティクルを別レイヤーで描画するための SubmitView です。
204     //!
205     //! @param[in]    renderQueue 描画対象となる要素を集めたキューです。
206     //! @param[in]    sceneContext シーンコンテキストです。
207     //! @param[in]    camera カメラです。
208     //! @param[in]    layerId 描画要素のソート時に最優先に区分される ID です。レイヤーやビューポートの描画を制御するのに用います。
209     //! @param[in]    particleLayerId パーティクル描画用の layerId です。
210     //! @param[in]    isVisibleModel 表示するモデルを識別するための関数オブジェクトです。
211     //! @param[in]    renderSortMode 描画ソートモードです。
212     //!
213     virtual void SubmitView(
214         RenderQueue* renderQueue,
215         SceneContext* sceneContext,
216         const Camera& camera,
217         u8 layerId,
218         u8 particleLayerId,
219         IsVisibleModelFunctor* isVisibleModel,
220         RenderSortMode renderSortMode = ALL_MESH_BASE_SORT);
221 
222     //@}
223 
224 protected:
225     //----------------------------------------
226     //! @name コンストラクタ/デストラクタ
227     //@{
228 
229     //! コンストラクタです。
SceneUpdater(os::IAllocator * allocator,GfxPtr<SkeletonUpdater> skeletonUpdater,GfxPtr<WorldMatrixUpdater> worldMatrixUpdater,GfxPtr<BillboardUpdater> billboardUpdater)230     SceneUpdater(os::IAllocator* allocator,
231                  GfxPtr<SkeletonUpdater> skeletonUpdater,
232                  GfxPtr<WorldMatrixUpdater> worldMatrixUpdater,
233                  GfxPtr<BillboardUpdater> billboardUpdater)
234     : ISceneUpdater(allocator),
235       m_SkeletonUpdater(skeletonUpdater),
236       m_WorldMatrixUpdater(worldMatrixUpdater),
237       m_BillboardUpdater(billboardUpdater),
238       m_DepthSortMode(SORT_DEPTH_OF_ALL_MESH)
239     {}
240 
241     //! デストラクタです。
~SceneUpdater()242     virtual ~SceneUpdater() {}
243 
244     //@}
245 
246     GfxPtr<SkeletonUpdater> m_SkeletonUpdater;
247     GfxPtr<WorldMatrixUpdater> m_WorldMatrixUpdater;
248     GfxPtr<BillboardUpdater> m_BillboardUpdater;
249     DepthSortMode m_DepthSortMode;
250 };
251 
252 } // namespace gfx
253 } // namespace nw
254 
255 #endif // NW_GFX_SCENEUPDATER_H_
256