/*---------------------------------------------------------------------------* Project: NintendoWare File: gfx_ResVertex.h Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo and/or its licensed developers and are protected by national and international copyright laws. 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. The content herein is highly confidential and should be handled accordingly. $Revision: $ *---------------------------------------------------------------------------*/ #ifndef NW_GFX_RESVERTEX_H_ #define NW_GFX_RESVERTEX_H_ #include #include #include #include #include #include namespace nw { namespace gfx { namespace res { //! @details :private struct ResVertexAttributeData { // TODO: こちらの定義は削除予定。 enum VertexType { FLAG_VERTEX_PARAM = 0x1, FLAG_INTERLEAVE = 0x2 }; nw::ut::ResTypeInfo typeInfo; nw::ut::ResS32 m_Usage; nw::ut::ResU32 m_Flags; }; class ResVertexStream; class ResVertexParamAttribute; //-------------------------------------------------------------------------- //! @brief 頂点属性を表すバイナリリソースの基底クラスです。 //--------------------------------------------------------------------------- class ResVertexAttribute : public nw::ut::ResCommon< ResVertexAttributeData > { public: enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResVertexAttribute) }; enum { SIGNATURE = NW_RES_SIGNATURE32('VATR') }; enum VertexType { FLAG_VERTEX_PARAM = 0x1, FLAG_INTERLEAVE = 0x2 }; enum VertexAttributeUsage { USAGE_POSITION, USAGE_NORMAL, USAGE_TANGENT, USAGE_COLOR, USAGE_TEXTURECOODINATE0, USAGE_TEXTURECOODINATE1, USAGE_TEXTURECOODINATE2, USAGE_BONEINDEX, USAGE_BONEWEIGHT, USAGE_USERATTRIBUTE0, USAGE_USERATTRIBUTE1, USAGE_USERATTRIBUTE2, USAGE_USERATTRIBUTE3, USAGE_USERATTRIBUTE4, USAGE_USERATTRIBUTE5, USAGE_USERATTRIBUTE6, USAGE_USERATTRIBUTE7, USAGE_USERATTRIBUTE8, USAGE_USERATTRIBUTE9, USAGE_USERATTRIBUTE10, USAGE_USERATTRIBUTE11, USAGE_INTERLEAVE, USAGE_QUANTITY, USAGE_NONE }; NW_RES_CTOR( ResVertexAttribute ) //--------------------------------------------------------------------------- //! @fn void SetUsage(s32 value) //! @brief 頂点属性の用途を設定します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetFlags(u32 value) //! @brief フラグの値を設定します。 //! 設定されなかったフラグは無効になります。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void EnableFlags(u32 value) //! @brief 指定された Flag の値を有効にします。 //! 設定されなかったフラグは変更されません。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void DisableFlags(u32 value) //! @brief 指定された Flag の値を無効にします。 //! 設定されなかったフラグは変更されません。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetUsage() const //! @brief 頂点属性の用途を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn u32 GetFlags() const //! @brief フラグの値を取得します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL( s32, Usage ) // GetUsage(), SetUsage() NW_RES_FIELD_FLAGS_DECL( u32, Flags ) // GetFlags(), SetFlags(), EnableFlags(), DisableFlags() //! @brief 頂点属性の初期化処理をおこないます。 void Setup(); //! @brief 頂点属性の後始末をおこないます。 void Cleanup(); //! @brief 頂点数を取得します。 //! //! ResVertexParamAttribute だった場合は 0 を返します。 u32 GetVertexCount(); //--------------------------------------------------------------------------- //! @brief インスタンスの型情報を取得します。 //! //! @return 型情報です。 //--------------------------------------------------------------------------- nw::ut::ResTypeInfo GetTypeInfo() const { return ref().typeInfo; } }; typedef nw::ut::ResArrayClass::type ResVertexAttributeArray; //! @details :private struct ResVertexParamAttributeData : public ResVertexAttributeData { nw::ut::ResU32 m_FormatType; nw::ut::ResU8 m_Dimension; u8 _padding_0[3]; nw::ut::ResF32 m_Scale; nw::ut::Offset m_AttributeTableCount; nw::ut::Offset toAttributeTable; }; //-------------------------------------------------------------------------- //! @brief パラメータによる頂点属性を表すバイナリリソースクラスです。 //--------------------------------------------------------------------------- class ResVertexParamAttribute : public ResVertexAttribute { public: enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResVertexParamAttribute) }; enum { SIGNATURE = NW_RES_SIGNATURE32('VAPM') }; NW_RES_CTOR_INHERIT( ResVertexParamAttribute, ResVertexAttribute ) //--------------------------------------------------------------------------- //! @fn void SetScale(f32 value) //! @brief スケール値を設定します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetFormatType(u32 value) //! @brief フォーマットの種類を設定します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetDimension(u8 value) //! @brief 次元数を設定します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetAttribute(int idx, f32 value) //! @brief 属性のリストに要素を設定します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn f32 GetScale() const //! @brief スケール値を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn u32 GetFormatType() const //! @brief フォーマットの種類を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn u8 GetDimension() const //! @brief 次元数を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetAttributeCount() const //! @brief 属性の要素数を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn f32 GetAttribute(int idx) const //! @brief 属性を取得します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL( u32, FormatType ) // GetFormatType(), SetFormatType() NW_RES_FIELD_PRIMITIVE_DECL( u8, Dimension ) // GetDimension(), SetDimension() NW_RES_FIELD_PRIMITIVE_DECL( f32, Scale ) // GetScale(), SetScale() NW_RES_FIELD_PRIMITIVE_LIST_DECL( f32, Attribute ) // GetAttribute(), GetAttribute(int idx), GetAttributeCount() //! @brief 頂点属性の初期化処理をおこないます。 void Setup(); //! @brief 頂点属性の後始末をおこないます。 void Cleanup(); }; typedef nw::ut::ResArrayClass::type ResVertexParamAttributeArray; struct ResVertexStreamBaseData : public ResVertexAttributeData { enum { AREA_NO_MALLOC = 0, AREA_FCRAM = NN_GX_MEM_FCRAM, AREA_VRAMA = NN_GX_MEM_VRAMA, AREA_VRAMB = NN_GX_MEM_VRAMB }; nw::ut::ResU32 m_BufferObject; nw::ut::ResU32 m_LocationFlag; nw::ut::ResS32 m_StreamTableCount; nw::ut::Offset toStreamTable; u32 m_LocationAddress; u32 m_MemoryArea; }; //! @details :private struct ResVertexStreamData : public ResVertexStreamBaseData { nw::ut::ResU32 m_FormatType; nw::ut::ResU8 m_Dimension; u8 _padding_0[3]; nw::ut::ResF32 m_Scale; nw::ut::ResU32 m_Offset; }; struct ResInterleavedVertexStreamData : public ResVertexStreamBaseData { nw::ut::ResU32 m_Stride; nw::ut::ResS32 m_VertexStreamsTableCount; nw::ut::Offset toVertexStreamsTable; }; //-------------------------------------------------------------------------- //! @brief 頂点ストリームによる頂点属性を表すバイナリのベースクラスです。 //--------------------------------------------------------------------------- class ResVertexStreamBase : public ResVertexAttribute { public: enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResVertexStreamBase) }; enum { SIGNATURE = NW_RES_SIGNATURE32('VSTB') }; NW_RES_CTOR_INHERIT( ResVertexStreamBase, ResVertexAttribute ) //--------------------------------------------------------------------------- //! @fn void SetBufferObject(u32 value) //! @brief バッファオブジェクトを設定します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn u32 GetBufferObject() const //! @brief バッファオブジェクトを取得します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL( u32, BufferObject ) // GetBufferObject(), SetBufferObject() //--------------------------------------------------------------------------- //! @fn u32 GetLocationFlag() const //! @brief ロケーションフラグを取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetLocationFlag(u32 value) //! @brief ロケーションフラグを設定します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL( u32, LocationFlag ) // GetLocationFlag(), SetLocationFlag() //--------------------------------------------------------------------------- //! @fn s32 GetStreamCount() const //! @brief ストリームのバイト数を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn const u8* GetStream() const //! @brief ストリームを取得します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_LIST_DECL( u8, Stream ) // GetStream(), GetStream(int idx), GetStreamCount() //--------------------------------------------------------------------------- //! @brief コピーされた頂点バッファのアドレスを取得します。 //! //! @return コピーされた頂点バッファの論理アドレスです。 //--------------------------------------------------------------------------- u32 GetLocationAddress() const { return ref().m_LocationAddress; } //--------------------------------------------------------------------------- //! @brief コピーされた頂点バッファのアドレスを設定します。 //! //! @param[in] address コピーされた頂点バッファの論理アドレスです。 //--------------------------------------------------------------------------- void SetLocationAddress(u32 address) { ref().m_LocationAddress = address; } void SetLocationAddress(const void* address) { ref().m_LocationAddress = reinterpret_cast(address); } //--------------------------------------------------------------------------- //! @brief GPU から参照されるイメージのアドレスを取得します。 //! //! @details LocationAddess が設定されている場合はそのアドレスを使用し、 //! LocationAddess が NULL の場合には、Stream のアドレスを直接 GPU から参照します。 //! //! @return GPU から参照されるイメージのアドレスです。 //--------------------------------------------------------------------------- u32 GetImageAddress() const { u32 locationAddress = this->GetLocationAddress(); if ( locationAddress ) { return locationAddress; } else { return reinterpret_cast( this->GetStream() ); } } }; //-------------------------------------------------------------------------- //! @brief 頂点ストリームによる頂点属性を表すバイナリリソースクラスです。 //--------------------------------------------------------------------------- class ResVertexStream : public ResVertexStreamBase { public: enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResVertexStream) }; enum { SIGNATURE = NW_RES_SIGNATURE32('VSTM') }; NW_RES_CTOR_INHERIT( ResVertexStream, ResVertexStreamBase ) //--------------------------------------------------------------------------- //! @fn void SetFormatType(u32 value) //! @brief フォーマットの種類を設定します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn u32 GetFormatType() const //! @brief フォーマットの種類を取得します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL( u32, FormatType ) // GetFormatType(), SetFormatType() //--------------------------------------------------------------------------- //! @fn u8 GetDimension() const //! @brief 次元数を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetDimension(u8 value) //! @brief 次元数を設定します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL( u8, Dimension ) // GetDimension(), SetDimension() //--------------------------------------------------------------------------- //! @fn void SetScale(f32 value) //! @brief スケール値を設定します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn f32 GetScale() const //! @brief スケール値を取得します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL( f32, Scale ) // GetScale(), SetScale() //--------------------------------------------------------------------------- //! @fn void SetOffset(u32 value) //! @brief インターリーブ形式の場合のオフセット情報を設定します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn u32 GetOffset() const //! @brief インターリーブ形式の場合のオフセット情報を取得します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL( u32, Offset ) //! @brief 頂点ストリームの初期化処理をおこないます。 void Setup(); //! @brief 頂点属性の後始末をおこないます。 void Cleanup(); }; typedef nw::ut::ResArrayClass::type ResVertexStreamArray; //-------------------------------------------------------------------------- //! @brief インターリーブ形式の頂点ストリームを表すバイナリリソースクラスです。 //--------------------------------------------------------------------------- class ResInterleavedVertexStream : public ResVertexStreamBase { public: NW_RES_CTOR_INHERIT( ResInterleavedVertexStream, ResVertexStreamBase ) //--------------------------------------------------------------------------- //! @fn u32 GetStride() const //! @brief インターリーブ形式の1頂点あたりの頂点サイズを取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetStride(u32 value) //! @brief インターリーブ形式の1頂点あたりの頂点サイズを設定します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL( u32, Stride ) //--------------------------------------------------------------------------- //! @fn s32 GetVertexStreamsCount() const //! @brief インターリーブを構成する頂点属性の集合の要素数を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn ResVertexStream GetVertexStreams(int idx) //! @brief インターリーブを構成する頂点属性の集合を取得します。 //--------------------------------------------------------------------------- NW_RES_FIELD_CLASS_LIST_DECL( ResVertexStream, VertexStreams ) //! @brief 頂点ストリームの初期化処理をおこないます。 void Setup(); //! @brief 頂点属性の後始末をおこないます。 void Cleanup(); }; //! @details :private struct ResIndexStreamData { enum { AREA_NO_MALLOC = 0, AREA_FCRAM = NN_GX_MEM_FCRAM, AREA_VRAMA = NN_GX_MEM_VRAMA, AREA_VRAMB = NN_GX_MEM_VRAMB }; nw::ut::ResU32 m_FormatType; nw::ut::ResU8 m_PrimitiveMode; bool m_IsVisible; u8 _padding_0[2]; nw::ut::ResS32 m_StreamTableCount; nw::ut::Offset toStreamTable; nw::ut::ResU32 m_BufferObject; nw::ut::ResU32 m_LocationFlag; void* m_CommandCache; s32 m_CommandCacheSize; u32 m_LocationAddress; u32 m_MemoryArea; nw::ut::Offset toBoundingVolume; }; //-------------------------------------------------------------------------- //! @brief 頂点インデックスストリームを表すバイナリリソースクラスです。 //--------------------------------------------------------------------------- class ResIndexStream : public nw::ut::ResCommon< ResIndexStreamData > { public: NW_RES_CTOR( ResIndexStream ) //--------------------------------------------------------------------------- //! @fn u32 GetFormatType() const //! @brief フォーマットの種類を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetFormatType(u32 value) //! @brief フォーマットの種類を設定します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL( u32, FormatType ) // GetFormatType(), SetFormatType() //--------------------------------------------------------------------------- //! @fn u8 GetPrimitiveMode() const //! @brief プリミティブのモードを取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetPrimitiveMode(u8 value) //! @brief プリミティブのモードを設定します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL( u8, PrimitiveMode ) // GetPrimitiveMode(), SetPrimitiveMode() //--------------------------------------------------------------------------- //! @fn s32 GetStreamCount() const //! @brief ストリームの要素数を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn u8 GetStream(int idx) const //! @brief ストリームを取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetStream(int idx, u8 value) //! @brief ストリームのリストに要素を設定します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_LIST_DECL( u8, Stream ) // GetStream(), GetStream(int idx), GetStreamCount() //--------------------------------------------------------------------------- //! @fn u32 GetBufferObject() const //! @brief バッファオブジェクトを取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetBufferObject(u32 value) //! @brief バッファオブジェクトを設定します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL( u32, BufferObject ) // GetBufferObject(), SetBufferObject() //--------------------------------------------------------------------------- //! @fn u32 GetLocationFlag() const //! @brief ロケーションフラグを取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetLocationFlag(u32 value) //! @brief ロケーションフラグを設定します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL( u32, LocationFlag ) // GetLocationFlag(), SetLocationFlag() //--------------------------------------------------------------------------- //! @fn nw::ut::ResBoundingVolume GetBoundingVolume() //! @brief この機能は現状では実験仕様となります。将来的に仕様が変更になる可能性があります。 //! 境界情報を取得します。 //--------------------------------------------------------------------------- NW_RES_FIELD_CLASS_DECL( nw::ut::ResBoundingVolume, BoundingVolume ) // GetBoundingVolume() //--------------------------------------------------------------------------- //! @brief コピーされた頂点バッファのアドレスを取得します。 //! //! @return コピーされた頂点バッファの論理アドレスです。 //--------------------------------------------------------------------------- u32 GetLocationAddress() const { return ref().m_LocationAddress; } //--------------------------------------------------------------------------- //! @brief コピーされた頂点バッファのアドレスを設定します。 //! //! @param[in] address コピーされた頂点バッファの論理アドレスです。 //--------------------------------------------------------------------------- void SetLocationAddress(u32 address) { ref().m_LocationAddress = address; } void SetLocationAddress(const void* address) { ref().m_LocationAddress = reinterpret_cast(address); } //--------------------------------------------------------------------------- //! @brief GPU から参照されるイメージのアドレスを取得します。 //! //! @details LocationAddess が設定されている場合はそのアドレスを使用し、 //! LocationAddess が NULL の場合には、Stream のアドレスを直接 GPU から参照します。 //! //! @return GPU から参照されるイメージのアドレスです。 //--------------------------------------------------------------------------- u32 GetImageAddress() const { u32 locationAddress = this->GetLocationAddress(); if ( locationAddress ) { return locationAddress; } else { return reinterpret_cast( this->GetStream() ); } } //--------------------------------------------------------------------------- //! @fn void SetVisible(bool value) //! @brief この機能は現状では実験仕様となります。将来的に仕様が変更になる可能性があります。 //! 表示するかどうかのフラグを設定します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn bool IsVisible() const //! @brief この機能は現状では実験仕様となります。将来的に仕様が変更になる可能性があります。 //! 表示するかどうかのフラグを取得します。 //--------------------------------------------------------------------------- NW_RES_FIELD_BOOL_PRIMITIVE_DECL( Visible ) // IsVisible(), SetVisible() //! @brief 頂点数を取得します。 u32 GetVertexCount(); }; typedef nw::ut::ResArrayClass::type ResIndexStreamArray; } // namespace res } // namespace gfx } // namespace nw #endif // NW_GFX_RESVERTEX_H_