/*---------------------------------------------------------------------------* Project: NintendoWare File: SmCommandUtility.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: 18422 $ *---------------------------------------------------------------------------*/ #ifndef SM_COMMAND_UTILITY_H_ #define SM_COMMAND_UTILITY_H_ #include #include "../include/SmBase.h" class SmStaticCommandCache; //--------------------------------------------------------------------------- // コマンドを作って再利用するクラスです。 class SmCommandReuser { friend class SmStaticCommandCache; public: SmCommandReuser() : m_StoreCommandListId(0), m_CommandListId(0), m_BufferOffset(0), m_BufferSize(0), m_RequestId(0), m_RequestSize(0) {} // キャッシュ作成を開始します。 void StartCaching(GLuint cachingCommandListId, bool clearCmdCache = true) { // 現在バインドされているコマンドリストをストア nngxGetCmdlistParameteri( NN_GX_CMDLIST_BINDING, &m_StoreCommandListId ); // キャッシュ用のコマンドリストへ切り替え m_CommandListId = cachingCommandListId; nngxBindCmdlist(cachingCommandListId); if ( clearCmdCache ) { nngxClearCmdlist(); } nngxStartCmdlistSave(); NW_GL_ASSERT(); } // キャッシュ作成を終了します。 void EndCaching() { // nngxSplitDrawCmdlist(); NW_GL_ASSERT(); nngxStopCmdlistSave( &this->m_BufferOffset, &this->m_BufferSize, &this->m_RequestId, &this->m_RequestSize); NW_GL_ASSERT(); nngxBindCmdlist( m_StoreCommandListId ); } // キャッシュしたコマンドを使用します。 void UseCommand( bool isCopyBuffer ) { GLboolean copyBuffer = isCopyBuffer ? GL_TRUE : GL_FALSE; nngxUseSavedCmdlist( this->m_CommandListId, this->m_BufferOffset, this->m_BufferSize, this->m_RequestId, this->m_RequestSize, 0, copyBuffer); NW_GL_ASSERT(); } // キャッシュされているか? bool IsCache() { if ( m_BufferSize > 0 ) { return true; } else { return false; } } // キャッシュしたサイズを取得する GLsizei GetCacheSize() { return m_BufferSize; } private: GLint m_StoreCommandListId; GLuint m_CommandListId; GLuint m_BufferOffset; GLsizei m_BufferSize; GLuint m_RequestId; GLsizei m_RequestSize; }; //--------------------------------------------------------------------------- // 静的なコマンドキャッシュ領域を生成し、 // そこから領域を切り出してコマンドの再利用が行えるクラスです。 class SmStaticCommandCache : public SmBase { public: struct CopiedCmdCache { GLvoid* cmdBuff; GLsizei cmdBuffSize; bool IsCopied() { if ( cmdBuffSize ) { return true; } return false; } void Init() { cmdBuff = NULL; cmdBuffSize = 0; } }; // コンストラクタ SmStaticCommandCache(); // デストラクタ ~SmStaticCommandCache(); static void StartStaticCmdCache( SmCommandReuser& cmdReuser ); static void EndStaticCmdCache( SmCommandReuser& cmdReuser ); static void CreateCopiedCmdCache( CopiedCmdCache& cmdCacheCopied ); static void DestroyCopiedCmdCache( CopiedCmdCache& cmdCacheCopied ); static void UseCopiedCmdCache( CopiedCmdCache& cmdCacheCopied ); private: static GLuint m_StaticCommandList; }; #endif // SM_COMMAND_UTILITY_H_