1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: SmCommandUtility.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: 18422 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef SM_COMMAND_UTILITY_H_ 17 #define SM_COMMAND_UTILITY_H_ 18 19 #include <nn/gx.h> 20 #include "../include/SmBase.h" 21 22 class SmStaticCommandCache; 23 24 //--------------------------------------------------------------------------- 25 // コマンドを作って再利用するクラスです。 26 class SmCommandReuser 27 { 28 friend class SmStaticCommandCache; 29 30 public: SmCommandReuser()31 SmCommandReuser() 32 : m_StoreCommandListId(0), 33 m_CommandListId(0), 34 m_BufferOffset(0), 35 m_BufferSize(0), 36 m_RequestId(0), 37 m_RequestSize(0) 38 {} 39 40 // キャッシュ作成を開始します。 41 void StartCaching(GLuint cachingCommandListId, bool clearCmdCache = true) 42 { 43 // 現在バインドされているコマンドリストをストア 44 nngxGetCmdlistParameteri( NN_GX_CMDLIST_BINDING, &m_StoreCommandListId ); 45 46 // キャッシュ用のコマンドリストへ切り替え 47 m_CommandListId = cachingCommandListId; 48 nngxBindCmdlist(cachingCommandListId); 49 50 if ( clearCmdCache ) 51 { 52 nngxClearCmdlist(); 53 } 54 nngxStartCmdlistSave(); 55 NW_GL_ASSERT(); 56 } 57 58 // キャッシュ作成を終了します。 EndCaching()59 void EndCaching() 60 { 61 // nngxSplitDrawCmdlist(); 62 NW_GL_ASSERT(); 63 64 nngxStopCmdlistSave( 65 &this->m_BufferOffset, 66 &this->m_BufferSize, 67 &this->m_RequestId, 68 &this->m_RequestSize); 69 NW_GL_ASSERT(); 70 71 nngxBindCmdlist( m_StoreCommandListId ); 72 } 73 74 // キャッシュしたコマンドを使用します。 UseCommand(bool isCopyBuffer)75 void UseCommand( bool isCopyBuffer ) 76 { 77 GLboolean copyBuffer = isCopyBuffer ? GL_TRUE : GL_FALSE; 78 nngxUseSavedCmdlist( 79 this->m_CommandListId, 80 this->m_BufferOffset, 81 this->m_BufferSize, 82 this->m_RequestId, 83 this->m_RequestSize, 84 0, 85 copyBuffer); 86 NW_GL_ASSERT(); 87 } 88 89 // キャッシュされているか? IsCache()90 bool IsCache() 91 { 92 if ( m_BufferSize > 0 ) 93 { 94 return true; 95 } 96 else 97 { 98 return false; 99 } 100 } 101 102 // キャッシュしたサイズを取得する GetCacheSize()103 GLsizei GetCacheSize() 104 { 105 return m_BufferSize; 106 } 107 108 private: 109 110 111 GLint m_StoreCommandListId; 112 GLuint m_CommandListId; 113 GLuint m_BufferOffset; 114 GLsizei m_BufferSize; 115 GLuint m_RequestId; 116 GLsizei m_RequestSize; 117 }; 118 119 120 //--------------------------------------------------------------------------- 121 // 静的なコマンドキャッシュ領域を生成し、 122 // そこから領域を切り出してコマンドの再利用が行えるクラスです。 123 class SmStaticCommandCache : public SmBase 124 { 125 public: 126 struct CopiedCmdCache 127 { 128 GLvoid* cmdBuff; 129 GLsizei cmdBuffSize; 130 IsCopiedCopiedCmdCache131 bool IsCopied() 132 { 133 if ( cmdBuffSize ) 134 { 135 return true; 136 } 137 138 return false; 139 } 140 InitCopiedCmdCache141 void Init() 142 { 143 cmdBuff = NULL; 144 cmdBuffSize = 0; 145 } 146 }; 147 148 // コンストラクタ 149 SmStaticCommandCache(); 150 151 // デストラクタ 152 ~SmStaticCommandCache(); 153 154 static void StartStaticCmdCache( SmCommandReuser& cmdReuser ); 155 static void EndStaticCmdCache( SmCommandReuser& cmdReuser ); 156 157 static void CreateCopiedCmdCache( CopiedCmdCache& cmdCacheCopied ); 158 static void DestroyCopiedCmdCache( CopiedCmdCache& cmdCacheCopied ); 159 static void UseCopiedCmdCache( CopiedCmdCache& cmdCacheCopied ); 160 161 private: 162 static GLuint m_StaticCommandList; 163 }; 164 165 166 #endif // SM_COMMAND_UTILITY_H_ 167