1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: SmCommandUtility.cpp
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: 1 $
14 *---------------------------------------------------------------------------*/
15 #include <nn/os.h>
16
17 #include <nw/types.h>
18 #include <nw/ut.h>
19
20 #include "../include/SmCommandUtility.h"
21
22 GLuint SmStaticCommandCache::m_StaticCommandList = 0;
23
24 SmStaticCommandCache* s_StaticCmdCache = NULL;
25
26 namespace
27 {
28
29 //----------------------------------------
30 // コンストラクタ
SmStaticCommandCache()31 SmStaticCommandCache::SmStaticCommandCache()
32 {
33 #define STATIC_CMD_BUFFER_SIZE 0x50000
34
35 NW_ASSERT( !s_StaticCmdCache );
36
37 // 現在バインドされているコマンドリスト
38 GLint currentCmdList;
39 nngxGetCmdlistParameteri( NN_GX_CMDLIST_BINDING, ¤tCmdList );
40
41 // コマンドリストを生成
42 nngxGenCmdlists( 1, &m_StaticCommandList );
43 nngxBindCmdlist( m_StaticCommandList );
44 nngxCmdlistStorage( STATIC_CMD_BUFFER_SIZE, 256 );
45 nngxSetCmdlistParameteri(NN_GX_CMDLIST_RUN_MODE, NN_GX_CMDLIST_SERIAL_RUN);
46
47 // 戻す
48 nngxBindCmdlist( currentCmdList );
49
50 s_StaticCmdCache = this;
51 }
52
53
54 //----------------------------------------
55 // デストラクタ
~SmStaticCommandCache()56 SmStaticCommandCache::~SmStaticCommandCache()
57 {
58 nngxDeleteCmdlists( 1, &m_StaticCommandList );
59
60 s_StaticCmdCache = NULL;
61 }
62
63
64 //----------------------------------------
65 //
StartStaticCmdCache(SmCommandReuser & cmdReuser)66 void SmStaticCommandCache::StartStaticCmdCache( SmCommandReuser& cmdReuser )
67 {
68 cmdReuser.StartCaching( m_StaticCommandList );
69 NW_GL_ASSERT();
70 }
71
72
73 //----------------------------------------
74 //
EndStaticCmdCache(SmCommandReuser & cmdReuser)75 void SmStaticCommandCache::EndStaticCmdCache( SmCommandReuser& cmdReuser )
76 {
77 cmdReuser.EndCaching();
78 NW_GL_ASSERT();
79 }
80
81
82
83
84 //----------------------------------------
85 //
CreateCopiedCmdCache(CopiedCmdCache & cmdCacheCopied)86 void SmStaticCommandCache::CreateCopiedCmdCache( CopiedCmdCache& cmdCacheCopied )
87 {
88 GLsizei buffSize;
89 GLsizei reqSize;
90 GLsizei copiedBuffSize;
91
92 // 現在バインドされているコマンドリストをストア
93 GLint currentCmdList;
94 nngxGetCmdlistParameteri( NN_GX_CMDLIST_BINDING, ¤tCmdList );
95 nngxBindCmdlist( m_StaticCommandList );
96
97 nngxGetCmdlistParameteri( NN_GX_CMDLIST_USED_BUFSIZE, &buffSize );
98 nngxGetCmdlistParameteri( NN_GX_CMDLIST_USED_REQCOUNT, &reqSize );
99
100 copiedBuffSize = nngxExportCmdlist( m_StaticCommandList,
101 0,
102 buffSize,
103 0,
104 reqSize,
105 0,
106 0 );
107 NW_GL_ASSERT();
108
109 if ( !cmdCacheCopied.cmdBuff )
110 {
111 cmdCacheCopied.cmdBuff = m_Allocator->Alloc( copiedBuffSize );
112 cmdCacheCopied.cmdBuffSize = copiedBuffSize;
113
114 nngxExportCmdlist( m_StaticCommandList,
115 0,
116 buffSize,
117 0,
118 reqSize,
119 copiedBuffSize,
120 cmdCacheCopied.cmdBuff );
121 }
122
123
124 // 戻す
125 nngxBindCmdlist( currentCmdList );
126
127 NW_GL_ASSERT();
128 }
129
130
131 //----------------------------------------
132 //
DestroyCopiedCmdCache(CopiedCmdCache & cmdCacheCopied)133 void SmStaticCommandCache::DestroyCopiedCmdCache( CopiedCmdCache& cmdCacheCopied )
134 {
135 nw::os::SafeFree( cmdCacheCopied.cmdBuff, m_Allocator );
136 }
137
138 //----------------------------------------
139 //
UseCopiedCmdCache(CopiedCmdCache & cmdCacheCopied)140 void SmStaticCommandCache::UseCopiedCmdCache( CopiedCmdCache& cmdCacheCopied )
141 {
142 // 現在バインドされているコマンドリストをストア
143 GLint currentCmdList;
144 nngxGetCmdlistParameteri( NN_GX_CMDLIST_BINDING, ¤tCmdList );
145
146 // インポート
147 nngxImportCmdlist( currentCmdList, cmdCacheCopied.cmdBuff, cmdCacheCopied.cmdBuffSize );
148 NW_GL_ASSERT();
149 }
150
151
152
153 } // namespace
154
155
156