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