/*---------------------------------------------------------------------------* Project: NintendoWare File: DynamicMaterialDemo.cpp Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo and/or its licensed developers and are protected by national and international copyright laws. 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. The content herein is highly confidential and should be handled accordingly. $Revision: 31311 $ *---------------------------------------------------------------------------*/ #define NW_DEBUG_CHECK_MEMORY_LEAK #include #include #include #include #include #include #include #include namespace { //---------------------------------------- // マテリアル関係 // マテリアルの状態を表す UserFlag です enum UserFlags { MATERIAL_DEFAULT_SHIFT, MATERIAL_CHANGE_SHIFT, MATERIAL_DEFAULT = 0x1 << MATERIAL_DEFAULT_SHIFT, MATERIAL_CHANGE = 0x1 << MATERIAL_CHANGE_SHIFT }; // Material の default が指定されたモデルのみを描画要素に加える関数オブジェクトです。 class IsMaterialDefaultModelFunctor : public nw::gfx::ISceneUpdater::IsVisibleModelFunctor { public: virtual bool IsVisible(const nw::gfx::Model* model) { return nw::ut::CheckFlag(model->GetUserParameter(), MATERIAL_DEFAULT); } }; // Material の change が指定されたモデルのみを描画要素に加える関数オブジェクトです。 class IsMaterialChangeModelFunctor : public nw::gfx::ISceneUpdater::IsVisibleModelFunctor { public: virtual bool IsVisible(const nw::gfx::Model* model) { return nw::ut::CheckFlag(model->GetUserParameter(), MATERIAL_CHANGE); } }; IsMaterialDefaultModelFunctor s_MaterialDefaultModel; IsMaterialChangeModelFunctor s_MaterialChangeModel; // マテリアルの差し替え設定を行うレンダーコマンドです。 class StartMaterialChangeRenderCommand : public nw::gfx::RenderCommand { NW_DISALLOW_COPY_AND_ASSIGN(StartMaterialChangeRenderCommand); public: StartMaterialChangeRenderCommand(nw::gfx::Material* changeMaterial) : m_ChangeMaterial(changeMaterial) {} virtual ~StartMaterialChangeRenderCommand() {} virtual void Invoke(nw::gfx::RenderContext* renderContext) { // マテリアルを差し替えます。 renderContext->SetMaterial(m_ChangeMaterial); renderContext->ActivateContext(); // RENDERMODE_IGNORE_MATERIAL を用いて以降のマテリアル設定を行いません。 renderContext->SetRenderMode(nw::gfx::RenderContext::RENDERMODE_IGNORE_MATERIAL); } private: nw::gfx::Material* m_ChangeMaterial; }; // マテリアルの差し替えの後処理を行うレンダーコマンドです。 class EndMaterialChangeRenderCommand : public nw::gfx::RenderCommand { NW_DISALLOW_COPY_AND_ASSIGN(EndMaterialChangeRenderCommand); public: EndMaterialChangeRenderCommand() {} virtual ~EndMaterialChangeRenderCommand() {} virtual void Invoke(nw::gfx::RenderContext* renderContext) { renderContext->SetRenderMode(nw::gfx::RenderContext::RENDERMODE_DEFAULT); } }; StartMaterialChangeRenderCommand* s_StartMaterialChangeRenderCommand = NULL; EndMaterialChangeRenderCommand* s_EndMaterialChangeRenderCommand = NULL; //---------------------------------------- // メモリ関係 // デバイスメモリを確保するためのアロケータです。 nw::demo::DemoAllocator s_DeviceAllocator; //---------------------------------------- // ファイル名の定義です。 const wchar_t* SKY_SPHERE_FILE_NAME = NW_DEMO_FILE_PATH(L"SkySphere.bcmdl"); const wchar_t* MODEL_RESOURCE_FILES[] = { NW_DEMO_FILE_PATH(L"DynamicMaterial.bcmdl"), NW_DEMO_FILE_PATH(L"SceneEnvironmentSetting.bcenv"), NW_DEMO_FILE_PATH(L"FragmentLight.bcenv"), }; //---------------------------------------- // 描画関係 const int RENDER_TARGET_COUNT = 1; typedef nw::ut::FixedSizeArray RenderTargetArray; RenderTargetArray s_RenderTargets; nw::demo::SceneSystem* s_SceneSystem = NULL; nw::demo::RenderSystem* s_RenderSystem = NULL; nw::demo::GraphicsDrawing s_GraphicsDrawing; //---------------------------------------- // リソース関係 nw::demo::ResourceArray s_Resources; nw::demo::ResourceSet s_LutResource; nw::demo::ResourceSet s_TextureResource; static const wchar_t* LUT_RESOURCE_FILE = NW_DEMO_FILE_PATH(L"Lutset.bclts"); static const wchar_t* TEXTURE_RESOURCE_FILE = NW_DEMO_FILE_PATH(L"Texture2.bctex"); //---------------------------------------- // シーン関係 const int SCENE_NODE_COUNT = 7; nw::gfx::SceneNode* s_SceneRoot = NULL; nw::gfx::SceneNode* s_ModelRoot = NULL; s32 s_FrameCount = 0; s32 s_ChangeFrameCount = 0; const s32 s_ChangeFrame = 100; bool s_ChangeMaterial = false; nw::gfx::Camera* s_BaseCamera = NULL; nw::gfx::Camera* s_LeftCamera = NULL; nw::gfx::Camera* s_RightCamera = NULL; const f32 s_fNearPlane = 0.1f; f32 s_TorusTranslate = 0.0f; nw::gfx::Model* s_BufferTorus = NULL; nw::gfx::Model* s_LutTorus = NULL; nw::gfx::Model* s_TextureTorus = NULL; nw::gfx::Material* s_EdgeMaterial = NULL; nw::gfx::res::ResTexture s_ChangedTexture; nw::gfx::res::ResLookupTable s_ChangedLut; nw::ut::FloatColor s_DiffuseColor(1.0f, 0.0f, 0.0f, 1.0f); //---------------------------------------- // シーン環境関係 const s32 ENVIRONMENT_SETTINGS_COUNT = 1; typedef nw::ut::FixedSizeArray SceneEnvironmentSettingArray; SceneEnvironmentSettingArray s_SceneEnvironmentSettings; const s32 s_BaseCameraIndex = 0; /*!--------------------------------------------------------------------------* @brief グラフィックス関連の初期化を行います。 *---------------------------------------------------------------------------*/ void InitializeGraphics() { nw::gfx::CommandCacheManager::SetAllocator( &s_DeviceAllocator ); // renderDescriptionへステレオの設定を行います。 nw::demo::RenderSystem::Description renderDescription; renderDescription.reusableCommandBufferSize = 0x100000; renderDescription.reusableCommandRequestCount = 512; renderDescription.upperScreenMode = nw::demo::UPPER_SCREEN_MODE_STEREO; s_RenderSystem = nw::demo::RenderSystem::Create(&s_DeviceAllocator, renderDescription); s_GraphicsDrawing.SetScreenSize( renderDescription.lowerScreenDescription.width, renderDescription.lowerScreenDescription.height ); nw::demo::Utility::InitializeGraphicsDrawing(&s_DeviceAllocator, s_GraphicsDrawing); s_RenderTargets.push_back( nw::demo::Utility::CreateUpperScreenBuffer(&s_DeviceAllocator, renderDescription) ); NW_ASSERT(!s_RenderTargets.empty()); s_RenderSystem->GetRenderContext()->SetRenderTarget(s_RenderTargets.front()); // sceneDescriptionへの標準的な設定はコンストラクタで行われています。 nw::demo::SceneSystem::Description sceneDescription; sceneDescription.isFixedSizeMemory = true; s_SceneSystem = nw::demo::SceneSystem::Create(&s_DeviceAllocator, sceneDescription); // デモ用の最遠景モデルをレンダリングシステムに設定します。 // gfx のデモでは glClear などを用いずに背景で塗りつぶしを行います。 s_RenderSystem->LoadSkyModel(SKY_SPHERE_FILE_NAME); NW_GL_ASSERT(); } /*!--------------------------------------------------------------------------* @brief グラフィックス関連の後始末をします。 *---------------------------------------------------------------------------*/ void TerminateGraphics() { nw::gfx::SafeDestroy(s_LeftCamera); nw::gfx::SafeDestroy(s_RightCamera); nw::gfx::SafeDestroy(s_SceneSystem); nw::gfx::SafeDestroyAll(s_RenderTargets); s_GraphicsDrawing.Finalize(); nw::gfx::SafeDestroy(s_RenderSystem); NW_GL_ASSERT(); } /*!--------------------------------------------------------------------------* @brief ルートノード関連の構築をします。 *---------------------------------------------------------------------------*/ void BuildRootNodes() { NW_ASSERT(s_SceneRoot == NULL); s_SceneRoot = nw::gfx::TransformNode::DynamicBuilder() .Create(&s_DeviceAllocator); NW_NULL_ASSERT(s_SceneRoot); NW_ASSERT(s_ModelRoot == NULL); s_ModelRoot = nw::gfx::TransformNode::DynamicBuilder() .Create(&s_DeviceAllocator); s_SceneRoot->AttachChild(s_ModelRoot); NW_NULL_ASSERT(s_ModelRoot); } /*!--------------------------------------------------------------------------* @brief カメラ関連の構築をします。 *---------------------------------------------------------------------------*/ void BuildCameras() { nw::demo::Utility::CreateStereoCameras( &s_BaseCamera, &s_LeftCamera, &s_RightCamera, &s_DeviceAllocator, nw::math::VEC3(0.0f, 2.25f, 10.0f), nw::math::VEC3(0.0f, 2.25f, 0.0f), s_fNearPlane ); s_SceneRoot->AttachChild(s_BaseCamera); s_SceneSystem->GetCameraController()->Register(s_BaseCamera); } /*!--------------------------------------------------------------------------* @brief リソース関連の構築をします。 *---------------------------------------------------------------------------*/ void BuildResources(nw::demo::ResourceSet* resourceSet) { resourceSet->resource.ForeachTexture(nw::gfx::LocationFlagSetter(NN_GX_MEM_VRAMA | GL_NO_COPY_FCRAM_DMP)); resourceSet->resource.ForeachIndexStream(nw::gfx::LocationFlagSetter(NN_GX_MEM_VRAMB | GL_NO_COPY_FCRAM_DMP)); resourceSet->resource.ForeachVertexStream(nw::gfx::LocationFlagSetter(NN_GX_MEM_VRAMB | GL_NO_COPY_FCRAM_DMP)); nw::gfx::Result result = resourceSet->resource.Setup(&s_DeviceAllocator); if (result.IsFailure()) { if (result.GetDescription() & nw::gfx::RESOURCE_RESULT_NOT_FOUND_LUT) { // 参照テーブルが見つからなかったときは、外部ファイルを指定して再びセットアップします。 result = resourceSet->resource.Setup(&s_DeviceAllocator, s_LutResource.resource); } if (result.IsFailure()) { NW_FATAL_ERROR("Fail to set up model. A result code is 0x%x", result.GetCode()); } } nw::ut::MoveArray sceneNodeArray(SCENE_NODE_COUNT, &s_DeviceAllocator); nw::gfx::ResModelArray models = resourceSet->resource.GetModels(); nw::gfx::ResModelArray::iterator modelsEnd = models.end(); for (nw::gfx::ResModelArray::iterator modelResource = models.begin(); modelResource != modelsEnd; ++modelResource) { nw::gfx::SceneNode* node = nw::demo::Utility::CreateSceneNode( &s_DeviceAllocator, (*modelResource), false ); NW_NULL_ASSERT(node); nw::gfx::Model* model = nw::ut::DynamicCast(node); NW_NULL_ASSERT(model); if (::std::strcmp(model->GetName(), "Edge") == 0) { model->SetVisible(false); s_EdgeMaterial = model->GetMaterial(0); } else if(::std::strcmp(model->GetName(), "LutTorus") == 0) { model->Transform().SetTranslate(0.0f, s_TorusTranslate, 0.0f); model->SetUserParameter(MATERIAL_DEFAULT); s_TorusTranslate += 1.5f; s_LutTorus = model; } else if(::std::strcmp(model->GetName(), "TextureTorus") == 0) { model->Transform().SetTranslate(0.0f, s_TorusTranslate, 0.0f); model->SetUserParameter(MATERIAL_DEFAULT); s_TorusTranslate += 1.5f; s_TextureTorus = model; } else if(::std::strcmp(model->GetName(), "Torus") == 0) { nw::gfx::Model* changeModel = nw::ut::DynamicCast(node); NW_NULL_ASSERT(changeModel); changeModel->Transform().SetTranslate(0.0f, s_TorusTranslate, 0.0f); s_TorusTranslate += 1.5f; changeModel->SetUserParameter(MATERIAL_CHANGE); // バッファオプションを指定してモデルを生成します。 nw::gfx::SceneNode* bufferNode = nw::demo::Utility::CreateSceneNode( &s_DeviceAllocator, (*modelResource), false, nw::gfx::Model::FLAG_BUFFER_MATERIAL_COLOR ); NW_NULL_ASSERT(bufferNode); nw::gfx::Model* bufferModel = nw::ut::DynamicCast(bufferNode); NW_NULL_ASSERT(bufferModel); bufferModel->Transform().SetTranslate(0.0f, s_TorusTranslate, 0.0f); s_TorusTranslate += 1.5f; s_BufferTorus = bufferModel; bufferModel->SetUserParameter(MATERIAL_DEFAULT); sceneNodeArray.push_back(bufferNode); } sceneNodeArray.push_back(node); } nw::gfx::ResLightArray lights = resourceSet->resource.GetLights(); nw::gfx::ResLightArray::iterator lightsEnd = lights.end(); for (nw::gfx::ResLightArray::iterator lightResource = lights.begin(); lightResource != lightsEnd; ++lightResource) { nw::gfx::SceneNode* node = nw::demo::Utility::CreateSceneNode( &s_DeviceAllocator, (*lightResource) ); NW_NULL_ASSERT(node); sceneNodeArray.push_back(node); } // 親子付け参照関係を解決 nw::gfx::SceneHelper::ResolveReference(sceneNodeArray); // モデルをシーンに追加 nw::gfx::SceneHelper::ForeachRootNodes( sceneNodeArray.Begin(), sceneNodeArray.End(), nw::gfx::AttachNode(s_ModelRoot) ); nw::gfx::ResSceneEnvironmentSettingArray settings = resourceSet->resource.GetSceneEnvironmentSettings(); nw::gfx::ResSceneEnvironmentSettingArray::iterator settingsEnd = settings.end(); for (nw::gfx::ResSceneEnvironmentSettingArray::iterator settingResource = settings.begin(); settingResource != settingsEnd; ++settingResource) { nw::gfx::SceneObject* sceneObject = nw::gfx::SceneBuilder() .Resource(*settingResource) .CreateObject(&s_DeviceAllocator, &s_DeviceAllocator); nw::gfx::SceneEnvironmentSetting* sceneEnvironmentSetting = nw::ut::DynamicCast(sceneObject); NW_NULL_ASSERT(sceneEnvironmentSetting); s_SceneEnvironmentSettings.push_back(sceneEnvironmentSetting); } } /*!--------------------------------------------------------------------------* @brief シーンを初期化します。 *---------------------------------------------------------------------------*/ void InitializeScenes() { // ファイルから LUT Set を読み込みます。 s_LutResource.buffer = nw::demo::Utility::LoadFile(&s_DeviceAllocator , LUT_RESOURCE_FILE); NW_NULL_ASSERT(s_LutResource.buffer); s_LutResource.resource = nw::gfx::ResGraphicsFile(&(s_LutResource.buffer.front())); s_LutResource.resource.Setup(&s_DeviceAllocator); s_ChangedLut = s_LutResource.resource.GetLutSets(0).GetSamplers("toon_reflectance"); s_TextureResource.buffer = nw::demo::Utility::LoadFile(&s_DeviceAllocator, TEXTURE_RESOURCE_FILE); NW_NULL_ASSERT(s_TextureResource.buffer); s_TextureResource.resource = nw::gfx::ResGraphicsFile(&(s_TextureResource.buffer.front())); s_TextureResource.resource.ForeachTexture(nw::gfx::LocationFlagSetter(NN_GX_MEM_VRAMA | GL_NO_COPY_FCRAM_DMP)); s_TextureResource.resource.Setup(&s_DeviceAllocator); s_ChangedTexture = s_TextureResource.resource.GetTextures(0); BuildRootNodes(); BuildCameras(); s_TorusTranslate = 0.0f; NW_FOREACH(const wchar_t* name, MODEL_RESOURCE_FILES) { BuildResources(nw::demo::Utility::LoadResources(s_Resources, name, &s_DeviceAllocator)); } // シーンツリーを巡回して初期化を行います。 s_SceneSystem->InitializeScene(s_SceneRoot); s_SceneSystem->UpdateScene(); // シーン環境の参照解決を行い設定します。 s_RenderSystem->SetSceneEnvironmentSettings(s_SceneSystem, &s_SceneEnvironmentSettings); // カメラを設定します。 nw::gfx::SceneEnvironment& sceneEnvironment = s_RenderSystem->GetSceneEnvironment(); sceneEnvironment.SetCamera(s_BaseCameraIndex, s_BaseCamera); nw::demo::Utility::SetCameraAspectRatio(s_BaseCamera, s_RenderTargets[0]); // レンダーコマンドを作成します。 void* startMaterialChangeCommandMemory = s_DeviceAllocator.Alloc(sizeof(StartMaterialChangeRenderCommand)); NW_NULL_ASSERT(startMaterialChangeCommandMemory); s_StartMaterialChangeRenderCommand = new(startMaterialChangeCommandMemory) StartMaterialChangeRenderCommand(s_EdgeMaterial); void* endMaterialChangeCommandMemory = s_DeviceAllocator.Alloc(sizeof(EndMaterialChangeRenderCommand)); NW_NULL_ASSERT(endMaterialChangeCommandMemory); s_EndMaterialChangeRenderCommand = new(endMaterialChangeCommandMemory) EndMaterialChangeRenderCommand(); NW_GL_ASSERT(); s_FrameCount = 0; } /*!--------------------------------------------------------------------------* @brief シーン関連の後始末をします。 *---------------------------------------------------------------------------*/ void TerminateScenes() { s_DeviceAllocator.Free(s_EndMaterialChangeRenderCommand); s_EndMaterialChangeRenderCommand = NULL; s_DeviceAllocator.Free(s_StartMaterialChangeRenderCommand); s_StartMaterialChangeRenderCommand = NULL; s_LutTorus = NULL; s_TextureTorus = NULL; s_EdgeMaterial = NULL; s_BufferTorus = NULL; nw::gfx::SafeDestroyBranch(s_SceneRoot); nw::demo::SafeCleanupResources(s_Resources); nw::ut::SafeDestroyAll(s_SceneEnvironmentSettings); nw::ut::SafeCleanup(s_TextureResource.resource); nw::ut::SafeCleanup(s_LutResource.resource); NW_GL_ASSERT(); s_TextureResource.buffer = nw::ut::MoveArray(); s_LutResource.buffer = nw::ut::MoveArray(); s_Resources.clear(); s_SceneEnvironmentSettings.clear(); s_ModelRoot = NULL; } /*!--------------------------------------------------------------------------* @brief シーンを更新します。 それぞのモデルのマテリアルの変更を行います。 *---------------------------------------------------------------------------*/ void ChangeMaterial() { if (s_ChangeFrameCount > s_ChangeFrame) { // torus のマテリアルカラーを変更します。 // マテリアルバッファを用いているためにベースとなる torus の色は変更されません。 { nw::gfx::res::ResMaterial resTorusMaterial = s_BufferTorus->GetMaterial(0)->GetMaterialColorResMaterial(); NW_ASSERT(resTorusMaterial.IsValid()); nw::gfx::res::ResMaterialColor resMaterialColor = resTorusMaterial.GetMaterialColor(); nw::ut::FloatColor floatColor = resMaterialColor.GetDiffuse(); resMaterialColor.SetDiffuse(s_DiffuseColor); s_DiffuseColor = floatColor; // NOTE: マテリアルバッファはハッシュが無効になっていますので、0x0 を設定する必要はありません。 // resTorusMaterial.SetMaterialColorHash(0x0); } // texture_torus のテクスチャを差し替えます。 { nw::gfx::res::ResMaterial resTorusMaterial = s_TextureTorus->GetMaterial(0)->GetTextureMapperResMaterial(); NW_ASSERT(resTorusMaterial.IsValid()); nw::gfx::res::ResTextureMapper resTextureMapper = resTorusMaterial.GetTextureMappers(0); nw::gfx::res::ResTexture resTexture = resTextureMapper.GetTexture().Dereference(); resTextureMapper.SetTexture(s_ChangedTexture); s_ChangedTexture = resTexture; // テクスチャを変更した場合はテクスチャマッパーのハッシュを0に設定します。 resTorusMaterial.SetTextureMappersHash(0x0); } // lut_torus の参照テーブルを差し替えます。 { nw::gfx::res::ResMaterial resTorusMaterial = s_LutTorus->GetMaterial(0)->GetFragmentLightingTableResMaterial(); NW_ASSERT(resTorusMaterial.IsValid()); nw::gfx::res::ResFragmentLightingTable resFragmentLightingLut = resTorusMaterial.GetFragmentShader().GetFragmentLightingTable(); nw::gfx::res::ResLightingLookupTable resLightingLut = resFragmentLightingLut.GetReflectanceRSampler(); nw::gfx::res::ResLookupTable resLut = resLightingLut.GetSampler().Dereference(); resLightingLut.SetSampler(s_ChangedLut); s_ChangedLut = resLut; // 参照テーブルを変更した場合はフラグメントライティングテーブルのハッシュを0に設定します。 resTorusMaterial.SetFragmentLightingTableHash(0x0); } } } /*!--------------------------------------------------------------------------* @brief レンダーキューにモデルの追加を行います。 独自マテリアルでの描画を行うためにコールバックの設定をします。 *---------------------------------------------------------------------------*/ void SubmitView() { nw::gfx::RenderContext* renderContext = s_RenderSystem->GetRenderContext(); nw::gfx::SceneEnvironment& sceneEnvironment = renderContext->GetSceneEnvironment(); nw::gfx::SceneContext* sceneContext = s_SceneSystem->GetSceneContext(); nw::gfx::RenderQueue* renderQueue = s_RenderSystem->GetRenderQueue(); renderQueue->Reset(); s_SceneSystem->GetSceneUpdater()->SubmitView( renderQueue, sceneContext, *s_BaseCamera, 0, 1, &s_MaterialDefaultModel, s_RenderSystem->GetRenderSortMode()); if (s_ChangeMaterial) { // マテリアルの変更を行うコマンドをレイヤー1の後に実行するコールバックに追加します。 s_RenderSystem->EnqueueRenderCommand( s_StartMaterialChangeRenderCommand, nw::gfx::res::ResMaterial::TRANSLUCENCY_KIND_OPAQUE, 0, 1); } s_SceneSystem->GetSceneUpdater()->SubmitView( renderQueue, sceneContext, *s_BaseCamera, 2, 2, &s_MaterialChangeModel, s_RenderSystem->GetRenderSortMode()); if (s_ChangeMaterial) { // マテリアルの変更の後処理行うコマンドをレイヤー2の後に実行するコールバックに追加します。 s_RenderSystem->EnqueueRenderCommand( s_EndMaterialChangeRenderCommand, nw::gfx::res::ResMaterial::TRANSLUCENCY_KIND_OPAQUE, 0, 2); } // レンダーキューをソートします。 // RenderElementCompare() やレンダーキーファクトリーをカスタマイズすることで // 描画順を変更することができます。 // 詳しくは最適化TIPSを参照してください。 std::sort( renderQueue->Begin(), renderQueue->End(), nw::gfx::RenderElementCompare()); } /*!--------------------------------------------------------------------------* @brief シーンを更新します。 *---------------------------------------------------------------------------*/ void UpdateScene() { s_SceneSystem->GetCameraController()->Update(); s_SceneSystem->UpdateScene(); s_BaseCamera->UpdateCameraMatrix(); s_RenderSystem->CalcStereoCamera(s_LeftCamera, s_RightCamera, s_BaseCamera, s_fNearPlane + 5.0f); ++s_FrameCount; } /*!--------------------------------------------------------------------------* @brief 負荷表示やテスト機能の処理をおこないます。 *---------------------------------------------------------------------------*/ void ReportDemo() { NW_PROFILE("ReportDemo"); // 負荷表示からはこれらの負荷は除きます。 s_RenderSystem->SuspendLoadMeter(); nw::demo::DebugUtility::CalcLoadMeter(s_RenderSystem); s_GraphicsDrawing.BeginDrawingShape(); nw::demo::DebugUtility::DrawLoadMeter( s_RenderSystem, &s_GraphicsDrawing ); s_GraphicsDrawing.EndDrawingShape(); s_GraphicsDrawing.BeginDrawingString(); nw::demo::DebugUtility::DrawLoadMeterText( s_RenderSystem, &s_GraphicsDrawing ); s_GraphicsDrawing.EndDrawingString(); s_RenderSystem->ResumeLoadMeter(); } /*!--------------------------------------------------------------------------* @brief シーンをデモンストレーションします。 *---------------------------------------------------------------------------*/ void DemoScene() { NW_ASSERT(!s_RenderTargets.empty()); nw::gfx::RenderContext* renderContext = s_RenderSystem->GetRenderContext(); InitializeScenes(); nw::demo::DebugUtility::PostInitializeScenes(); bool isContinuing = true; while ( isContinuing ) { nw::demo::DebugUtility::AdvanceAutoTestFrame(); nw::demo::PadFactory::GetPad()->Update(); UpdateScene(); // マテリアルの変更を行います。 ChangeMaterial(); renderContext->SetActiveCamera(s_BaseCameraIndex); // レンダーキューへのモデルの追加を行います。 // 独自マテリアルでの描画を行うためにカスタマイズします。 SubmitView(); s_RenderSystem->SetRenderTarget(s_RenderTargets[0]); s_RenderSystem->RenderStereoScene(s_LeftCamera, s_RightCamera); s_RenderSystem->ClearBySkyModel(s_BaseCamera); ReportDemo(); s_RenderSystem->TransferBuffer(nw::demo::LOWER_SCREEN); s_RenderSystem->PresentBuffer(nw::demo::UPPER_SCREEN | nw::demo::LOWER_SCREEN | nw::demo::EXTENSION_SCREEN); renderContext->ResetState(); if (nw::demo::Utility::IsTerminating()) { isContinuing = false; } if (s_ChangeFrameCount > s_ChangeFrame) { s_ChangeMaterial = !s_ChangeMaterial; s_ChangeFrameCount = 0; } ++s_ChangeFrameCount; } nw::demo::DebugUtility::PreTerminateScenes(); TerminateScenes(); } } // namespace /*!--------------------------------------------------------------------------* @brief メイン関数です。 *---------------------------------------------------------------------------*/ void nnMain() { nw::demo::InitializeGraphicsSystem(&s_DeviceAllocator); nw::demo::PadFactory::Initialize(&s_DeviceAllocator); NW_DEMO_TEST_LOOP(&s_DeviceAllocator, NULL, &s_RenderSystem) { InitializeGraphics(); DemoScene(); TerminateGraphics(); } nw::demo::PadFactory::Finalize(); nw::demo::FinalizeGraphicsSystem(); }