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: 28253 $
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 #define NW_ENSURE_AND_RETURN(result) \
55 NW_ASSERT( result.IsSuccess() );
56
57 #endif
58
59
60 #if defined( NW_ASSERTION_ENABLE )
61 #define NW_ENSURE_AND_ASSERT(exp) \
62 do { \
63 Result result = exp; \
64 NW_ASSERT( result.IsSuccess() ); \
65 } while (0)
66 #else
67 #define NW_ENSURE_AND_ASSERT(exp) exp
68 #endif
69
70
71 //! @brief 処理結果などを返すためのクラスです。
72 //!
73 //! @sa ResourceResult
74 //! @sa InitializeResult
75 //! @sa BindResult
76 class Result
77 {
78 typedef Result self_type; //!< 自分の型です。
79 public:
80 //! コンストラクタです。
Result()81 Result() : m_Code(0)
82 {}
83
Result(u32 code)84 Result(u32 code) : m_Code(code)
85 {}
86
87 //! @brief 成功か失敗したかを表すビットです。
88 static const bit32 MASK_FAIL_BIT = 0x80000000;
89 //! @brief エラー内容を表すビットです。
90 static const bit32 MASK_DESCRIPTION = 0x0000ffff;
91
92 //! ビットを代入します。
93 self_type operator = (u32 code) { m_Code = code; return *this; }
94 //! 論理和を行い代入します。
95 self_type operator |= (u32 code) { m_Code |= code; return *this; }
96 //! 論理積を行い代入します。
97 self_type operator &= (u32 code) { m_Code &= code; return *this; }
98 //! ビットを代入します。
99 self_type operator = (self_type result) { m_Code = result.GetCode(); return *this; }
100 //! 論理和を行い代入します。
101 self_type operator |= (self_type result) { m_Code |= result.GetCode(); return *this; }
102 //! 論理積を行い代入します。
103 self_type operator &= (self_type result) { m_Code &= result.GetCode(); return *this; }
104
105 //! @brief エラーコードを表す値を取得します。
GetCode()106 u32 GetCode() const
107 {
108 return m_Code;
109 }
110
111 //! @brief 処理の結果が失敗なら true を、成功なら false を返します。
IsFailure()112 bool IsFailure() const
113 {
114 return (m_Code & MASK_FAIL_BIT) != 0;
115 }
116
117 //! @brief 処理の結果が成功なら true を、失敗なら false を返します。
IsSuccess()118 bool IsSuccess() const
119 {
120 return !IsFailure();
121 }
122
123 //! @brief エラー内容を取得します。
GetDescription()124 int GetDescription() const
125 {
126 return static_cast<int>( m_Code & MASK_DESCRIPTION );
127 }
128
129 private:
130 u32 m_Code;
131 };
132
133 //! @brief リソースの Setup 結果の定義です。 Result クラス用です。
134 enum ResourceResult
135 {
136 RESOURCE_RESULT_OK = 0, //!< Setup が成功したことを表します。
137 RESOURCE_RESULT_NOT_FOUND_TEXTURE = 1 << 0, //!< テクスチャ参照解決が失敗したことを表します。
138 RESOURCE_RESULT_NOT_FOUND_SHADER = 1 << 1, //!< シェーダーの参照解決が失敗したことを表します。
139 RESOURCE_RESULT_NOT_FOUND_LUT = 1 << 2, //!< 参照テーブルの参照解決が失敗したことを表します。
140 RESOURCE_RESULT_IRRELEVANT_LOCATION_LUT = 1 << 3, //!< 参照テーブルの有効フラグと実際に参照テーブルが一致しないことを表します。
141 RESOURCE_RESULT_IRRELEVANT_LOCATION_SHADER_SYMBOL = 1 << 4, //!< シェーダーシンボルがシェーダーバイナリに存在しないことを表します。
142 RESOURCE_RESULT_IRRELEVANT_TEXTURE_MAPPING_METHOD = 1 << 5 //!< カメラキューブ座標のマッピング方法でキューブテクスチャが存在しないことを表します。
143 };
144
145 //! @brief インスタンスの Initialize 結果の定義です。 Result クラス用です。
146 enum InitializeResult
147 {
148 INITIALIZE_RESULT_OK = 0 //!< Initialize が成功したことを表します。
149 };
150
151 //! @brief アニメーションのバインド結果の定義です。 Result クラス用です。
152 enum BindResult
153 {
154 BIND_RESULT_OK = 0, //!< バインドが成功し、すべてのメンバがバインドされたことを表します。
155 BIND_RESULT_NOT_ALL_ANIM_MEMBER_BOUND = 1 << 0, //!< バインドは成功したが、バインドされていないアニメメンバがあることを表します。
156 BIND_RESULT_NO_MEMBER_BOUND = 1 << 1 //!< バインドされたメンバが無いことを表します。
157 };
158
159 // nw::gfx::ResXXX は nw::ut::ResCommon を継承している為、Koenig Lookup が働き
160 // ut と gfx の決定ができない。using で ut から gfx に引き込む形にしておけば問題ないはず。
161
162 using nw::ut::ResStaticCast;
163 using nw::ut::ResDynamicCast;
164
165 using nw::os::AllocateAndFill;
166 using nw::os::AllocateAndFillN;
167 using nw::os::AllocateAndAssignN;
168 using nw::os::AllocateAndCopyString;
169
170 namespace internal {
171
172 //---------------------------------------------------------------------------
173 //! @brief リソースのリビジョンチェックをおこないます。
174 //!
175 //! @tparam TRes リソースクラスの型です。
176 //! @param[in] res リビジョンをチェックするリソースです。
177 //!
178 //! @return ライブラリが実行可能なリビジョンであれば true、
179 //! 実行不能であれば false を返します。
180 //! null の場合にも false を返します。
181 //---------------------------------------------------------------------------
182 template<typename TRes>
183 NW_INLINE bool
ResCheckRevision(const TRes res)184 ResCheckRevision(const TRes res )
185 {
186 if (!res.IsValid()) { return false; }
187
188 return nw::ut::internal::CheckRevision( res.GetRevision(), TRes::BINARY_REVISION );
189 }
190
191 } // namespace internal
192 } // namespace gfx
193 } // namespace nw
194
195 #endif // NW_GFX_COMMON_H_
196
197