/*---------------------------------------------------------------------------* Project: NintendoWare File: gfx_GraphicsDevice.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 $ *---------------------------------------------------------------------------*/ #include "precompiled.h" #include #include #include namespace nw { namespace gfx { enum { REG_BUFFER_CACHE_CLEAR = 0x110, REG_BUFFER_CACHE_TAG_CLEAR = 0x111, REG_BUFFER_MASK_BASE = 0x112 }; uint GraphicsDevice::s_LutIsAbs = 0; uint GraphicsDevice::s_LutInput = 0; uint GraphicsDevice::s_LutScale = 0; u32 GraphicsDevice::s_DepthFormat = RENDER_DEPTH_FORMAT_24_STENCIL8; u32 GraphicsDevice::s_WScale24 = 0; f32 GraphicsDevice::s_DepthRangeNear = 0.0f; f32 GraphicsDevice::s_DepthRangeFar = 1.0f; u32 GraphicsDevice::s_DepthRange24 = ut::Float24::Float32ToBits24( -1.0f ); bool GraphicsDevice::s_PolygonOffsetEnabled = false; f32 GraphicsDevice::s_PolygonOffsetUnit = 0.0f; ResImageLookupTable GraphicsDevice::m_LutTargets[LUT_TARGET_COUNT]; u32 GraphicsDevice::s_LightPositionW = 0; u32 GraphicsDevice::s_LightShadowed = 0xFF; u32 GraphicsDevice::s_LightSpotEnabled = 0xFF; u32 GraphicsDevice::s_LightDistanceAttnEnabled = 0xFF; ResFragmentOperation::FragmentOperationMode GraphicsDevice::s_FragOperationMode = ResFragmentOperation::FRAGMENT_OPERATION_MODE_GL; bool GraphicsDevice::s_IsFrameBufferUpdated = true; // 初期値を true にしないと初回時に更新されない。 bool GraphicsDevice::s_BlendEnabled = true; bool GraphicsDevice::s_DepthTestEnabled = true; bool GraphicsDevice::s_StencilTestEnabled = false; bool GraphicsDevice::s_DepthMask = true; u8 GraphicsDevice::s_StencilMask = 0xFF; u32 GraphicsDevice::s_ColorMask = 0xF; u32 GraphicsDevice::s_RenderBufferWidth = 400; u32 GraphicsDevice::s_RenderBufferHeight = 240; u32 GraphicsDevice::s_FrameBufferCommand[10] = { 1, internal::MakeCommandHeader(REG_BUFFER_CACHE_TAG_CLEAR, 1, false, 0xF), 1, internal::MakeCommandHeader(REG_BUFFER_CACHE_CLEAR, 1, false, 0xF), 0, internal::MakeCommandHeader(REG_BUFFER_MASK_BASE, 4, true, 0xF), 0, 0, 0, 0 }; //---------------------------------------- void GraphicsDevice::ActivateLookupTable(ResImageLookupTable lookupTable, LutTarget target) { NW_ASSERT(lookupTable.IsValid()); NW_MINMAXLT_ASSERT(target, LUT_TARGET_D0, LUT_TARGET_COUNT); if (m_LutTargets[target] != lookupTable) { m_LutTargets[target] = lookupTable; ActivateLutLoadSetting(target); internal::NWUseCmdlist( lookupTable.GetCommandCache(), lookupTable.GetCommandCacheCount() ); } } //---------------------------------------- void GraphicsDevice::InvalidateLookupTable(ResImageLookupTable lookupTable) { NW_ASSERT(lookupTable.IsValid()); for (int target = 0; target < LUT_TARGET_COUNT; ++target) { if (m_LutTargets[target] == lookupTable) { m_LutTargets[target] = ResImageLookupTable(NULL); } } } //---------------------------------------- void GraphicsDevice::InvalidateAllLookupTables() { for (int target = 0; target < LUT_TARGET_COUNT; ++target) { m_LutTargets[target] = ResImageLookupTable(NULL); } } //---------------------------------------- void GraphicsDevice::Report() { #if !defined(NW_RELEASE) NW_LOG("\n<>\n"); NW_LOG("[RenderBufferWidth]\n"); NW_LOG(" 0x%x\n", s_RenderBufferWidth); NW_LOG("[RenderBufferHeight]\n"); NW_LOG(" 0x%x\n", s_RenderBufferHeight); NW_LOG("[DepthFormat]\n"); NW_LOG(" 0x%x\n", s_DepthFormat); NW_LOG("[WScale24]\n"); NW_LOG(" 0x%x\n", s_WScale24); NW_LOG("[DepthRangeNear]\n"); NW_LOG(" %f\n", s_DepthRangeNear); NW_LOG("[DepthRangeFar]\n"); NW_LOG(" %f\n", s_DepthRangeFar); NW_LOG("[DepthRange24]\n"); NW_LOG(" 0x%x\n", s_DepthRange24); NW_LOG("\n<>\n"); NW_LOG("[FragOperationMode]\n"); { static const char* table[] = { " FRAGMENT_OPERATION_MODE_GL", " FRAGMENT_OPERATION_MODE_GAS", " FRAGMENT_OPERATION_MODE_SHADOW" }; NW_LOG(" %s\n", table[s_FragOperationMode]); } NW_LOG("[BlendEnabled]\n"); NW_LOG(s_BlendEnabled ? " True\n" : " False\n"); NW_LOG("[DepthTestEnabled]\n"); NW_LOG(s_DepthTestEnabled ? " True\n" : " False\n"); NW_LOG("[StencilTestEnabled]\n"); NW_LOG(s_StencilTestEnabled ? " True\n" : " False\n"); NW_LOG("[DepthMask]\n"); NW_LOG(s_DepthMask ? " True\n" : " False\n"); NW_LOG("[StencilMask]\n"); NW_LOG(" 0x%x\n", s_StencilMask); NW_LOG("[ColorMask]\n"); NW_LOG(" 0x%x\n", s_ColorMask); NW_LOG("\n<>\n"); NW_LOG("[IsFrameBufferUpdated]\n"); NW_LOG(s_IsFrameBufferUpdated ? " True\n" : " False\n"); NW_LOG("[FrameBufferCommand]\n"); for (int i = 0; i < FRAME_BUFFER_COMMAND_COUNT; ++i) { NW_LOG(" 0x%x\n", s_FrameBufferCommand[i]); } NW_LOG("[PolygonOffsetEnabled]\n"); NW_LOG(" 0x%x\n", s_PolygonOffsetEnabled); NW_LOG("[PolygonOffsetUnit]\n"); NW_LOG(" %f\n", s_PolygonOffsetUnit); NW_LOG("\n<>\n"); NW_LOG("[LightPositionW]\n"); NW_LOG(" 0x%x\n", s_LightPositionW); NW_LOG("[LightShadowed]\n"); NW_LOG(" 0x%x\n", s_LightShadowed); NW_LOG("[LightSpotEnabled]\n"); NW_LOG(" 0x%x\n", s_LightSpotEnabled); NW_LOG("[LightDistanceAttnEnabled]\n"); NW_LOG(" 0x%x\n", s_LightDistanceAttnEnabled); NW_LOG("\n<>\n"); NW_LOG("[LutIsAbs]\n"); NW_LOG(" 0x%x\n", s_LutIsAbs); NW_LOG("[LutInput]\n"); NW_LOG(" 0x%x\n", s_LutInput); NW_LOG("[LutScale]\n"); NW_LOG(" 0x%x\n", s_LutScale); NW_LOG("[LookupTableCache]\n"); NW_LOG(" attr : address : name\n"); for (int target = 0; target < LUT_TARGET_COUNT; ++target) { static const char* table[] = { "D0", "D1", "SP", "FR", "RB", "RG", "RR", "SP0", "SP1", "SP2", "SP3", "SP4", "SP5", "SP6", "SP7", "DA0", "DA1", "DA2", "DA3", "DA4", "DA5", "DA6", "DA7", "FOG" }; NW_LOG( "%5s : 0x%8x : %s\n", table[target], m_LutTargets[target].ptr(), m_LutTargets[target].IsValid() && m_LutTargets[target].GetName() != NULL ? m_LutTargets[target].GetName() : "NA"); } #endif } } // namespace gfx } // namespace nw