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