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