1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: gfx_Common.h
4
5 Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Revision: 25626 $
14 *---------------------------------------------------------------------------*/
15
16 #ifndef NW_GFX_COMMON_H_
17 #define NW_GFX_COMMON_H_
18
19 #include <nw/types.h>
20 #include <nw/os/os_Memory.h>
21 #include <nw/ut/ut_RuntimeTypeInfo.h>
22 #include <nw/ut/ut_ResUtil.h>
23 #include <nw/gfx/gfx_Config.h>
24
25 #include <algorithm>
26
27 namespace nw {
28 namespace gfx {
29
30 namespace res {}
31 using namespace ::nw::gfx::res;
32
33 //! @brief プラットフォーム依存の定数定義です。
34 enum PlatformConstants
35 {
36 VERTEX_ATTRIBUTE_COUNT = 12,
37 COMBINER_COUNT = 6,
38 COMBINER_AVAILABLE_COUNT = COMBINER_COUNT,
39 PIXELBASED_TEXTURE_UNIT_COUNT = 3,
40 LOOKUP_TABLE_COUNT = 32,
41 LIGHT_COUNT = 8,
42 TEXTURE_COORDINATE_COUNT = 3,
43 FOG_TABLE_SIZE = 256
44 };
45
46 #define NW_ENSURE_MEMORY_ENABLED
47
48 #if defined (NW_ENSURE_MEMORY_ENABLED)
49
50 #define NW_ENSURE_AND_RETURN(result) \
51 if ( result.IsFailure() ) { return result; }
52
53 #else
54
55 #define NW_ENSURE_AND_RETURN(result) \
56 NW_ASSERT( result.IsSuccess() );
57
58 #endif
59
60 //! @brief 処理結果などを返すためのクラスです。
61 //!
62 //! @sa ResourceResult
63 //! @sa InitializeResult
64 //! @sa BindResult
65 class Result
66 {
67 typedef Result self_type; //!< 自分の型です。
68 public:
69 //! コンストラクタです。
Result()70 Result() : m_Code(0)
71 {}
72
Result(u32 code)73 Result(u32 code) : m_Code(code)
74 {}
75
76 //! @brief 成功か失敗したかを表すビットです。
77 static const bit32 MASK_FAIL_BIT = 0x80000000;
78 //! @brief エラー内容を表すビットです。
79 static const bit32 MASK_DESCRIPTION = 0x0000ffff;
80
81 //! ビットを代入します。
82 self_type operator = (u32 code) { m_Code = code; return *this; }
83 //! 論理和を行い代入します。
84 self_type operator |= (u32 code) { m_Code |= code; return *this; }
85 //! 論理積を行い代入します。
86 self_type operator &= (u32 code) { m_Code &= code; return *this; }
87 //! ビットを代入します。
88 self_type operator = (self_type result) { m_Code = result.GetCode(); return *this; }
89 //! 論理和を行い代入します。
90 self_type operator |= (self_type result) { m_Code |= result.GetCode(); return *this; }
91 //! 論理積を行い代入します。
92 self_type operator &= (self_type result) { m_Code &= result.GetCode(); return *this; }
93
94 //! @brief エラーコードを表す値を取得します。
GetCode()95 u32 GetCode() const
96 {
97 return m_Code;
98 }
99
100 //! @brief 処理の結果が失敗なら true を、成功なら false を返します。
IsFailure()101 bool IsFailure() const
102 {
103 return (m_Code & MASK_FAIL_BIT) != 0;
104 }
105
106 //! @brief 処理の結果が成功なら true を、失敗なら false を返します。
IsSuccess()107 bool IsSuccess() const
108 {
109 return !IsFailure();
110 }
111
112 //! @brief エラー内容を取得します。
GetDescription()113 int GetDescription() const
114 {
115 return static_cast<int>( m_Code & MASK_DESCRIPTION );
116 }
117
118 private:
119 u32 m_Code;
120 };
121
122 //! @brief リソースの Setup 結果の定義です。 Result クラス用です。
123 enum ResourceResult
124 {
125 RESOURCE_RESULT_OK = 0, //!< Setup が成功したことを表します。
126 RESOURCE_RESULT_NOT_FOUND_TEXTURE = 1 << 0, //!< テクスチャ参照解決が失敗したことを表します。
127 RESOURCE_RESULT_NOT_FOUND_SHADER = 1 << 1, //!< シェーダーの参照解決が失敗したことを表します。
128 RESOURCE_RESULT_NOT_FOUND_LUT = 1 << 2, //!< 参照テーブルの参照解決が失敗したことを表します。
129 RESOURCE_RESULT_IRRELEVANT_LOCATION_LUT = 1 << 3, //!< 参照テーブルの有効フラグと実際に参照テーブルが一致しないことを表します。
130 RESOURCE_RESULT_IRRELEVANT_LOCATION_SHADER_SYMBOL = 1 << 4 //!< シェーダーシンボルがシェーダーバイナリに存在しないことを表します。
131 };
132
133 //! @brief インスタンスの Initialize 結果の定義です。 Result クラス用です。
134 enum InitializeResult
135 {
136 INITIALIZE_RESULT_OK = 0 //!< Initialize が成功したことを表します。
137 };
138
139 //! @brief アニメーションのバインド結果の定義です。 Result クラス用です。
140 enum BindResult
141 {
142 BIND_RESULT_OK = 0, //!< バインドが成功し、すべてのメンバがバインドされたことを表します。
143 BIND_RESULT_NOT_ALL_ANIM_MEMBER_BOUND = 1 << 0, //!< バインドは成功したが、バインドされていないアニメメンバがあることを表します。
144 BIND_RESULT_NO_MEMBER_BOUND = 1 << 1 //!< バインドされたメンバが無いことを表します。
145 };
146
147 // nw::gfx::ResXXX は nw::ut::ResCommon を継承している為、Koenig Lookup が働き
148 // ut と gfx の決定ができない。using で ut から gfx に引き込む形にしておけば問題ないはず。
149
150 using nw::ut::ResStaticCast;
151 using nw::ut::ResDynamicCast;
152
153 using nw::os::AllocateAndFill;
154 using nw::os::AllocateAndFillN;
155 using nw::os::AllocateAndAssignN;
156 using nw::os::AllocateAndCopyString;
157
158 namespace internal {
159
160 //---------------------------------------------------------------------------
161 //! @brief リソースのリビジョンチェックをおこないます。
162 //!
163 //! @tparam TRes リソースクラスの型です。
164 //! @param[in] res リビジョンをチェックするリソースです。
165 //!
166 //! @return ライブラリが実行可能なリビジョンであれば true、
167 //! 実行不能であれば false を返します。
168 //! null の場合にも false を返します。
169 //---------------------------------------------------------------------------
170 template<typename TRes>
171 NW_INLINE bool
ResCheckRevision(const TRes res)172 ResCheckRevision(const TRes res )
173 {
174 if (!res.IsValid()) { return false; }
175
176 return nw::ut::internal::CheckRevision( res.GetRevision(), TRes::BINARY_REVISION );
177 }
178
179 } // namespace internal
180 } // namespace gfx
181 } // namespace nw
182
183 #endif // NW_GFX_COMMON_H_
184
185