/*---------------------------------------------------------------------------* Project: NintendoWare File: gfx_Common.h Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Revision: 25626 $ *---------------------------------------------------------------------------*/ #ifndef NW_GFX_COMMON_H_ #define NW_GFX_COMMON_H_ #include #include #include #include #include #include namespace nw { namespace gfx { namespace res {} using namespace ::nw::gfx::res; //! @brief プラットフォーム依存の定数定義です。 enum PlatformConstants { VERTEX_ATTRIBUTE_COUNT = 12, COMBINER_COUNT = 6, COMBINER_AVAILABLE_COUNT = COMBINER_COUNT, PIXELBASED_TEXTURE_UNIT_COUNT = 3, LOOKUP_TABLE_COUNT = 32, LIGHT_COUNT = 8, TEXTURE_COORDINATE_COUNT = 3, FOG_TABLE_SIZE = 256 }; #define NW_ENSURE_MEMORY_ENABLED #if defined (NW_ENSURE_MEMORY_ENABLED) #define NW_ENSURE_AND_RETURN(result) \ if ( result.IsFailure() ) { return result; } #else #define NW_ENSURE_AND_RETURN(result) \ NW_ASSERT( result.IsSuccess() ); #endif //! @brief 処理結果などを返すためのクラスです。 //! //! @sa ResourceResult //! @sa InitializeResult //! @sa BindResult class Result { typedef Result self_type; //!< 自分の型です。 public: //! コンストラクタです。 Result() : m_Code(0) {} Result(u32 code) : m_Code(code) {} //! @brief 成功か失敗したかを表すビットです。 static const bit32 MASK_FAIL_BIT = 0x80000000; //! @brief エラー内容を表すビットです。 static const bit32 MASK_DESCRIPTION = 0x0000ffff; //! ビットを代入します。 self_type operator = (u32 code) { m_Code = code; return *this; } //! 論理和を行い代入します。 self_type operator |= (u32 code) { m_Code |= code; return *this; } //! 論理積を行い代入します。 self_type operator &= (u32 code) { m_Code &= code; return *this; } //! ビットを代入します。 self_type operator = (self_type result) { m_Code = result.GetCode(); return *this; } //! 論理和を行い代入します。 self_type operator |= (self_type result) { m_Code |= result.GetCode(); return *this; } //! 論理積を行い代入します。 self_type operator &= (self_type result) { m_Code &= result.GetCode(); return *this; } //! @brief エラーコードを表す値を取得します。 u32 GetCode() const { return m_Code; } //! @brief 処理の結果が失敗なら true を、成功なら false を返します。 bool IsFailure() const { return (m_Code & MASK_FAIL_BIT) != 0; } //! @brief 処理の結果が成功なら true を、失敗なら false を返します。 bool IsSuccess() const { return !IsFailure(); } //! @brief エラー内容を取得します。 int GetDescription() const { return static_cast( m_Code & MASK_DESCRIPTION ); } private: u32 m_Code; }; //! @brief リソースの Setup 結果の定義です。 Result クラス用です。 enum ResourceResult { RESOURCE_RESULT_OK = 0, //!< Setup が成功したことを表します。 RESOURCE_RESULT_NOT_FOUND_TEXTURE = 1 << 0, //!< テクスチャ参照解決が失敗したことを表します。 RESOURCE_RESULT_NOT_FOUND_SHADER = 1 << 1, //!< シェーダーの参照解決が失敗したことを表します。 RESOURCE_RESULT_NOT_FOUND_LUT = 1 << 2, //!< 参照テーブルの参照解決が失敗したことを表します。 RESOURCE_RESULT_IRRELEVANT_LOCATION_LUT = 1 << 3, //!< 参照テーブルの有効フラグと実際に参照テーブルが一致しないことを表します。 RESOURCE_RESULT_IRRELEVANT_LOCATION_SHADER_SYMBOL = 1 << 4 //!< シェーダーシンボルがシェーダーバイナリに存在しないことを表します。 }; //! @brief インスタンスの Initialize 結果の定義です。 Result クラス用です。 enum InitializeResult { INITIALIZE_RESULT_OK = 0 //!< Initialize が成功したことを表します。 }; //! @brief アニメーションのバインド結果の定義です。 Result クラス用です。 enum BindResult { BIND_RESULT_OK = 0, //!< バインドが成功し、すべてのメンバがバインドされたことを表します。 BIND_RESULT_NOT_ALL_ANIM_MEMBER_BOUND = 1 << 0, //!< バインドは成功したが、バインドされていないアニメメンバがあることを表します。 BIND_RESULT_NO_MEMBER_BOUND = 1 << 1 //!< バインドされたメンバが無いことを表します。 }; // nw::gfx::ResXXX は nw::ut::ResCommon を継承している為、Koenig Lookup が働き // ut と gfx の決定ができない。using で ut から gfx に引き込む形にしておけば問題ないはず。 using nw::ut::ResStaticCast; using nw::ut::ResDynamicCast; using nw::os::AllocateAndFill; using nw::os::AllocateAndFillN; using nw::os::AllocateAndAssignN; using nw::os::AllocateAndCopyString; namespace internal { //--------------------------------------------------------------------------- //! @brief リソースのリビジョンチェックをおこないます。 //! //! @tparam TRes リソースクラスの型です。 //! @param[in] res リビジョンをチェックするリソースです。 //! //! @return ライブラリが実行可能なリビジョンであれば true、 //! 実行不能であれば false を返します。 //! null の場合にも false を返します。 //--------------------------------------------------------------------------- template NW_INLINE bool ResCheckRevision(const TRes res ) { if (!res.IsValid()) { return false; } return nw::ut::internal::CheckRevision( res.GetRevision(), TRes::BINARY_REVISION ); } } // namespace internal } // namespace gfx } // namespace nw #endif // NW_GFX_COMMON_H_