/*---------------------------------------------------------------------------* Project: NintendoWare File: demo_SimpleApp.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: 23844 $ *---------------------------------------------------------------------------*/ #include #include namespace nw { namespace demo { SimpleApp* SimpleApp::s_pInstance = NULL; //---------------------------------------- void SimpleApp::Initialize() { m_CurrentDisplay = DISPLAY_MAX; nw::demo::InitializeGraphicsSystem(&m_DeviceAllocator); nw::demo::PadFactory::Initialize(&m_DeviceAllocator); nw::demo::RenderSystem::Description renderDesc; nw::demo::DisplayBufferSwapper::Description& upperScreenDesc = renderDesc.upperScreenDescription; nw::demo::DisplayBufferSwapper::Description& lowerScreenDesc = renderDesc.lowerScreenDescription; m_pRenderSystem = nw::demo::RenderSystem::Create( &m_DeviceAllocator, renderDesc); NW_NULL_ASSERT(m_pRenderSystem); m_pRenderTargetUpper = nw::gfx::IRenderTarget::Builder() .BufferSize(upperScreenDesc.height, upperScreenDesc.width) .ColorFormat(renderDesc.renderColorFormat) .Create(&m_DeviceAllocator); NW_NULL_ASSERT(m_pRenderTargetUpper); m_pRenderTargetLower = nw::gfx::IRenderTarget::Builder() .BufferSize(lowerScreenDesc.height, lowerScreenDesc.width) .ColorFormat(renderDesc.renderColorFormat) .Create(&m_DeviceAllocator); NW_NULL_ASSERT(m_pRenderTargetLower); NW_GL_ASSERT(); } //---------------------------------------- void SimpleApp::Finalize() { nw::demo::PadFactory::Finalize(); nw::gfx::SafeDestroy(m_pRenderSystem); nw::gfx::SafeDestroy(m_pRenderTargetUpper); nw::gfx::SafeDestroy(m_pRenderTargetLower); } //---------------------------------------- void SimpleApp::TransferBuffer() { switch (m_CurrentDisplay) { case DISPLAY0: m_pRenderSystem->TransferBuffer(nw::demo::UPPER_SCREEN); break; case DISPLAY1: m_pRenderSystem->TransferBuffer(nw::demo::LOWER_SCREEN); break; default: break; } } //---------------------------------------- void SimpleApp::SetRenderingTarget(Display display) { NW_ASSERT(display == DISPLAY0 || display == DISPLAY1); this->TransferBuffer(); switch (display) { case DISPLAY0: m_pRenderSystem->SetRenderTarget(m_pRenderTargetUpper); m_CurrentDisplay = DISPLAY0; break; case DISPLAY1: m_pRenderSystem->SetRenderTarget(m_pRenderTargetLower); m_CurrentDisplay = DISPLAY1; break; default: break; } } //---------------------------------------- const gfx::FrameBufferObject& SimpleApp::GetFrameBufferObject() const { return m_pRenderSystem->GetRenderContext()->GetRenderTarget()->GetBufferObject(); } //---------------------------------------- void SimpleApp::SwapBuffer(Display display) { this->TransferBuffer(); m_CurrentDisplay = DISPLAY_MAX; s32 screenKind = 0; switch (display) { case DISPLAY0: screenKind = nw::demo::UPPER_SCREEN; break; case DISPLAY1: screenKind = nw::demo::LOWER_SCREEN; break; case DISPLAY_BOTH: screenKind = nw::demo::UPPER_SCREEN | nw::demo::LOWER_SCREEN; break; default: return; } m_pRenderSystem->PresentBuffer(screenKind); NW_GL_ASSERT(); } //---------------------------------------- void* SimpleApp::Allocate(size_t size, u8 alignment) { return nw::demo::Alloc(size, alignment); } //---------------------------------------- void* SimpleApp::AllocateDeviceMemory(size_t size, u8 alignment) { return nw::demo::Alloc(size, alignment); } //---------------------------------------- void SimpleApp::Free(void* ptr) { nw::demo::Free(ptr); } } /* namespace demo */ } /* namespace nw */