/*---------------------------------------------------------------------------* Project: NintendoWare File: SmCommandUtility.cpp Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Revision: 1 $ *---------------------------------------------------------------------------*/ #include #include #include #include "../include/SmCommandUtility.h" GLuint SmStaticCommandCache::m_StaticCommandList = 0; SmStaticCommandCache* s_StaticCmdCache = NULL; namespace { //---------------------------------------- // コンストラクタ SmStaticCommandCache::SmStaticCommandCache() { #define STATIC_CMD_BUFFER_SIZE 0x50000 NW_ASSERT( !s_StaticCmdCache ); // 現在バインドされているコマンドリスト GLint currentCmdList; nngxGetCmdlistParameteri( NN_GX_CMDLIST_BINDING, ¤tCmdList ); // コマンドリストを生成 nngxGenCmdlists( 1, &m_StaticCommandList ); nngxBindCmdlist( m_StaticCommandList ); nngxCmdlistStorage( STATIC_CMD_BUFFER_SIZE, 256 ); nngxSetCmdlistParameteri(NN_GX_CMDLIST_RUN_MODE, NN_GX_CMDLIST_SERIAL_RUN); // 戻す nngxBindCmdlist( currentCmdList ); s_StaticCmdCache = this; } //---------------------------------------- // デストラクタ SmStaticCommandCache::~SmStaticCommandCache() { nngxDeleteCmdlists( 1, &m_StaticCommandList ); s_StaticCmdCache = NULL; } //---------------------------------------- // void SmStaticCommandCache::StartStaticCmdCache( SmCommandReuser& cmdReuser ) { cmdReuser.StartCaching( m_StaticCommandList ); NW_GL_ASSERT(); } //---------------------------------------- // void SmStaticCommandCache::EndStaticCmdCache( SmCommandReuser& cmdReuser ) { cmdReuser.EndCaching(); NW_GL_ASSERT(); } //---------------------------------------- // void SmStaticCommandCache::CreateCopiedCmdCache( CopiedCmdCache& cmdCacheCopied ) { GLsizei buffSize; GLsizei reqSize; GLsizei copiedBuffSize; // 現在バインドされているコマンドリストをストア GLint currentCmdList; nngxGetCmdlistParameteri( NN_GX_CMDLIST_BINDING, ¤tCmdList ); nngxBindCmdlist( m_StaticCommandList ); nngxGetCmdlistParameteri( NN_GX_CMDLIST_USED_BUFSIZE, &buffSize ); nngxGetCmdlistParameteri( NN_GX_CMDLIST_USED_REQCOUNT, &reqSize ); copiedBuffSize = nngxExportCmdlist( m_StaticCommandList, 0, buffSize, 0, reqSize, 0, 0 ); NW_GL_ASSERT(); if ( !cmdCacheCopied.cmdBuff ) { cmdCacheCopied.cmdBuff = m_Allocator->Alloc( copiedBuffSize ); cmdCacheCopied.cmdBuffSize = copiedBuffSize; nngxExportCmdlist( m_StaticCommandList, 0, buffSize, 0, reqSize, copiedBuffSize, cmdCacheCopied.cmdBuff ); } // 戻す nngxBindCmdlist( currentCmdList ); NW_GL_ASSERT(); } //---------------------------------------- // void SmStaticCommandCache::DestroyCopiedCmdCache( CopiedCmdCache& cmdCacheCopied ) { nw::os::SafeFree( cmdCacheCopied.cmdBuff, m_Allocator ); } //---------------------------------------- // void SmStaticCommandCache::UseCopiedCmdCache( CopiedCmdCache& cmdCacheCopied ) { // 現在バインドされているコマンドリストをストア GLint currentCmdList; nngxGetCmdlistParameteri( NN_GX_CMDLIST_BINDING, ¤tCmdList ); // インポート nngxImportCmdlist( currentCmdList, cmdCacheCopied.cmdBuff, cmdCacheCopied.cmdBuffSize ); NW_GL_ASSERT(); } } // namespace