1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     SmCommandReuser.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_REUSER_H_
17 #define SM_COMMAND_REUSER_H_
18 
19 #include <nn/gx.h>
20 
21 //---------------------------------------------------------------------------
22 // コマンドを作って再利用するクラスです。
23 class SmCommandReuser
24 {
25 public:
SmCommandReuser()26     SmCommandReuser()
27     : m_StoreCommandListId(0),
28       m_CommandListId(0),
29       m_BufferOffset(0),
30       m_BufferSize(0),
31       m_RequestId(0),
32       m_RequestSize(0)
33     {}
34 
35     // キャッシュ作成を開始します。
StartCaching(GLuint cachingCommandListId)36     void StartCaching(GLuint cachingCommandListId)
37     {
38         // 現在バインドされているコマンドリストをストア
39         nngxGetCmdlistParameteri( NN_GX_CMDLIST_BINDING, &m_StoreCommandListId );
40 
41         // キャッシュ用のコマンドリストへ切り替え
42         m_CommandListId = cachingCommandListId;
43         nngxBindCmdlist(cachingCommandListId);
44         nngxClearCmdlist();
45         nngxStartCmdlistSave();
46         NW_GL_ASSERT();
47     }
48 
49     // キャッシュ作成を終了します。
EndCaching()50     void EndCaching()
51     {
52         nngxSplitDrawCmdlist();
53         NW_GL_ASSERT();
54 
55         nngxStopCmdlistSave(
56             &this->m_BufferOffset,
57             &this->m_BufferSize,
58             &this->m_RequestId,
59             &this->m_RequestSize);
60         NW_GL_ASSERT();
61 
62         nngxBindCmdlist( m_StoreCommandListId );
63     }
64 
65     // キャッシュしたコマンドを使用します。
UseCommand(bool isCopyBuffer)66     void UseCommand( bool isCopyBuffer )
67     {
68         GLboolean copyBuffer = isCopyBuffer ? GL_TRUE : GL_FALSE;
69         nngxUseSavedCmdlist(
70             this->m_CommandListId,
71             this->m_BufferOffset,
72             this->m_BufferSize,
73             this->m_RequestId,
74             this->m_RequestSize,
75             0,
76             copyBuffer);
77         NW_GL_ASSERT();
78     }
79 
80     // キャッシュされているか?
IsCach()81     bool IsCach()
82     {
83         if( m_BufferSize > 0 )
84         {
85             return true;
86         }
87         else
88         {
89             return false;
90         }
91     }
92 
93 private:
94     GLint       m_StoreCommandListId;
95     GLuint      m_CommandListId;
96     GLuint      m_BufferOffset;
97     GLsizei     m_BufferSize;
98     GLuint      m_RequestId;
99     GLsizei     m_RequestSize;
100 };
101 
102 
103 
104 //---------------------------------------------------------------------------
105 // 静的なコマンドキャッシュ領域を確保し、コマンドを登録します。
106 class SmStaticCommandCach
107 {
108 public:
109 
110     // コンストラクタ
SmStaticCommandCach()111     SmStaticCommandCach()
112     {
113         nngxGenCmdlists(1, &(m_CachingCommandList));
114         nngxBindCmdlist(m_CachingCommandList);
115         nngxCmdlistStorage(description.cachingCommandBufferSize, description.cachingRequestCount);
116         nngxSetCmdlistParameteri(NN_GX_CMDLIST_RUN_MODE, NN_GX_CMDLIST_SERIAL_RUN);
117     }
118 
119 
120 };
121 
122 #endif // SM_COMMAND_REUSER_H_
123