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