1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     gfx_ResMesh.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: $
16  *---------------------------------------------------------------------------*/
17 
18 #ifndef NW_GFX_RESMESH_H_
19 #define NW_GFX_RESMESH_H_
20 
21 #include <nw/ut/ut_ResUtil.h>
22 #include <nw/ut/ut_ResDictionary.h>
23 #include <nw/gfx/res/gfx_ResSceneObject.h>
24 #include <nw/gfx/res/gfx_ResShape.h>
25 #include <nw/gfx/res/gfx_ResMaterial.h>
26 
27 namespace nw {
28 namespace gfx {
29 namespace res {
30 
31 //! @details :private
32 struct ResMeshData : public ResSceneObjectData
33 {
34     enum { IR_SCALE_COMMAND_SIZE = 2 + 1 + 2 * 4 + 1 };
35 
36     nw::ut::ResS32 m_ShapeIndex;
37     nw::ut::ResS32 m_MaterialIndex;
38     nw::ut::Offset toOwnerModel;
39     nw::ut::ResBool m_IsVisible;
40     nw::ut::ResU8 m_RenderPriority;
41     nw::ut::ResS16 m_MeshNodeVisibilityIndex;
42     nw::ut::ResS32 m_CurrentPrimitiveIndex;
43     nw::ut::ResU32 m_Flags;
44     nw::ut::ResU32 m_IrScaleCommand[ IR_SCALE_COMMAND_SIZE ];
45     void*          m_ActivateCommandCache;
46     s32            m_ActivateCommandCacheSize;
47     void*          m_DeactivateCommandCache;
48     s32            m_DeactivateCommandCacheSize;
49     nw::ut::BinString toMeshNodeName;
50     u64            m_RenderKeyCache;
51     nw::os::IAllocator* m_CommandAllocator;
52 };
53 
54 //--------------------------------------------------------------------------
55 //! @brief  メッシュを表すバイナリリソースクラスです。
56 //---------------------------------------------------------------------------
57 class ResMesh : public ResSceneObject
58 {
59 public:
60     enum Flag
61     {
62         FLAG_HAS_VERTEX_ALPHA  = 0x1,
63         FLAG_HAS_BONE_WEIGHT_W = 0x1 << 1,
64         FLAG_VALID_RENDER_KEY_CACHE = 0x1 << 2,
65         FLAG_HAS_BEEN_SETUP = 0x1 << 3
66     };
67 
NW_RES_CTOR_INHERIT(ResMesh,ResSceneObject)68     NW_RES_CTOR_INHERIT( ResMesh, ResSceneObject )
69 
70     //---------------------------------------------------------------------------
71     //! @fn           void SetVisible(bool value)
72     //! @brief        表示されるかどうかのフラグを設定します。
73     //---------------------------------------------------------------------------
74     //---------------------------------------------------------------------------
75     //! @fn           void SetShapeIndex(s32 value)
76     //! @brief        使用するシェイプのインデックスを設定します。
77     //---------------------------------------------------------------------------
78     //---------------------------------------------------------------------------
79     //! @fn           void SetRenderPriority(u8 value)
80     //! @brief        描画優先度を設定します。
81     //---------------------------------------------------------------------------
82     //---------------------------------------------------------------------------
83     //! @fn           void SetMaterialIndex(s32 value)
84     //! @brief        使用するマテリアルのインデックスを設定します。
85     //---------------------------------------------------------------------------
86     //---------------------------------------------------------------------------
87     //! @fn           void SetFlags(u32 value)
88     //! @brief        フラグの値を設定します。
89     //!               設定されなかったフラグは無効になります。
90     //---------------------------------------------------------------------------
91     //---------------------------------------------------------------------------
92     //! @fn           void EnableFlags(u32 value)
93     //! @brief        指定された Flag の値を有効にします。
94     //!               設定されなかったフラグは変更されません。
95     //---------------------------------------------------------------------------
96     //---------------------------------------------------------------------------
97     //! @fn           void DisableFlags(u32 value)
98     //! @brief        指定された Flag の値を無効にします。
99     //!               設定されなかったフラグは変更されません。
100     //---------------------------------------------------------------------------
101     //---------------------------------------------------------------------------
102     //! @fn           void SetCurrentPrimitiveIndex(s32 value)
103     //! @brief        現在有効なプリミティブのインデックス番号を設定します。
104     //---------------------------------------------------------------------------
105     //---------------------------------------------------------------------------
106     //! @fn           bool IsVisible() const
107     //! @brief        表示されるかどうかのフラグを取得します。
108     //---------------------------------------------------------------------------
109     //---------------------------------------------------------------------------
110     //! @fn           s32 GetShapeIndex() const
111     //! @brief        使用するシェイプのインデックスを取得します。
112     //---------------------------------------------------------------------------
113     //---------------------------------------------------------------------------
114     //! @fn           u8 GetRenderPriority() const
115     //! @brief        描画優先度を取得します。
116     //---------------------------------------------------------------------------
117     //---------------------------------------------------------------------------
118     //! @fn           ResTransformNode GetOwnerModel()
119     //! @brief        親モデルへを取得します。
120     //---------------------------------------------------------------------------
121     //---------------------------------------------------------------------------
122     //! @fn           s32 GetMaterialIndex() const
123     //! @brief        使用するマテリアルのインデックスを取得します。
124     //---------------------------------------------------------------------------
125     //---------------------------------------------------------------------------
126     //! @fn           u32 GetFlags() const
127     //! @brief        フラグの値を取得します。
128     //---------------------------------------------------------------------------
129     //---------------------------------------------------------------------------
130     //! @fn           s32 GetCurrentPrimitiveIndex() const
131     //! @brief        現在有効なプリミティブのインデックス番号を取得します。
132     //---------------------------------------------------------------------------
133     //---------------------------------------------------------------------------
134     //! @fn           const char * GetMeshNodeName() const
135     //! @brief        DCC 上でのノード名を取得します。
136     //---------------------------------------------------------------------------
137     //---------------------------------------------------------------------------
138     //! @fn           void GetMeshNodeVisibilityIndex(s32 value)
139     //! @brief        親モデルが持つビジビリティテーブルのインデックス番号を取得します。
140     //---------------------------------------------------------------------------
141     NW_RES_FIELD_PRIMITIVE_DECL( s32, ShapeIndex )            // GetShapeIndex(), SetShapeIndex()
142     NW_RES_FIELD_PRIMITIVE_DECL( s32, MaterialIndex )         // GetMaterialIndex(), SetMaterialIndex()
143     NW_RES_FIELD_CLASS_DECL( ResTransformNode, OwnerModel )   // GetOwnerModel()
144     NW_RES_FIELD_BOOL_PRIMITIVE_DECL( Visible )               // IsVisible(), SetVisible()
145     NW_RES_FIELD_PRIMITIVE_DECL( u8, RenderPriority )         // GetRenderPriority(), SetRenderPriority()
146     NW_RES_FIELD_PRIMITIVE_DECL( s32, CurrentPrimitiveIndex ) // GetCurrentPrimitiveIndex(), SetCurrentPrimitiveIndex()
147     NW_RES_FIELD_FLAGS_DECL( u32, Flags )                     // GetFlags(), SetFlags(), EnableFlags(), DisableFlags()
148     // TODO: Name が取れないのを修正する。
149     // NW_RES_FIELD_STRING_DECL( MeshNodeName )              // GetMeshNodeName()
150     NW_RES_FIELD_PRIMITIVE_DECL( s32, MeshNodeVisibilityIndex )   // GetMeshNodeVisibilityIndex(), SetMeshNodeVisibilityIndex()
151 
152     //---------------------------------------------------------------------------
153     //! @brief        キャッシュされたレンダーキーの値を取得します。
154     //!
155     //! @return       レンダーキーの値です。
156     //---------------------------------------------------------------------------
157     u64 GetRenderKeyCache() const { return ref().m_RenderKeyCache; }
158 
159     //---------------------------------------------------------------------------
160     //! @brief        レンダーキーの値をキャッシュに保存します。
161     //!
162     //! @param[in]    renderKey レンダーキーの値です。
163     //---------------------------------------------------------------------------
SetRenderKeyCache(u64 renderKey)164     void SetRenderKeyCache(u64 renderKey) { ref().m_RenderKeyCache = renderKey; }
165 
166 
167     //---------------------------------------------------------------------------
168     //! @brief        リソースのセットアップをおこないます。
169     //!
170     //! @param[in]    owner 所有者となるモデルリソースです。
171     //! @param[in]    allocator アロケータです。
172     //! @param[in]    graphicsFile グラフィックスリソースです。
173     //---------------------------------------------------------------------------
174     Result Setup(ResModel owner, os::IAllocator* allocator, ResGraphicsFile graphicsFile);
175 
176     //---------------------------------------------------------------------------
177     //! @brief        リソースの後始末をおこないます。
178     //---------------------------------------------------------------------------
179     void Cleanup();
180 };
181 
182 typedef nw::ut::ResArrayClass<ResMesh>::type  ResMeshArray;
183 
184 } // namespace res
185 } // namespace gfx
186 } // namespace nw
187 
188 #endif // NW_GFX_RESMESH_H_
189