Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

# GraphicsDeviceSelector.cpp

Go to the documentation of this file.

    00001 //------------------------------------------------------------------------------
    00002 // Lamp : Open source game middleware
    00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
    00004 //
    00005 // This library is free software; you can redistribute it and/or
    00006 // modify it under the terms of the GNU Lesser General Public
    00007 // License as published by the Free Software Foundation; either
    00008 // version 2.1 of the License, or (at your option) any later version.
    00009 //
    00010 // This library is distributed in the hope that it will be useful,
    00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013 // Lesser General Public License for more details.
    00014 //
    00015 // You should have received a copy of the GNU Lesser General Public
    00016 // License along with this library; if not, write to the Free Software
    00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00018 //------------------------------------------------------------------------------
    00019
    00020 /** @file
    00021  * 実装
    00022  * @author Junpee
    00023  */
    00024
    00025 #include "LampBasic.h"
    00026 #include "Graphics/DeviceSelector/GraphicsDeviceSelector.h"
    00027 #include "Graphics/System/GraphicsDeviceSettings.h"
    00028 #include "Graphics/Enumeration/GraphicsDeviceEnumeration.h"
    00029
    00030 namespace Lamp{
    00031
    00032 //------------------------------------------------------------------------------
    00033 // デバイス設定の選択
    00034 bool GraphicsDeviceSelector::chooseDeviceSettings(
    00035     HWND windowHandle, bool startFullscreen){
    00036     GraphicsDeviceSettings* settings = GraphicsDeviceSettings::getInstance();
    00037     bool foundWindowed = findBestWindowedMode(windowHandle, false, false);
    00038     bool foundFullscreen = findBestFullscreenMode(windowHandle, false, false);
    00039     // デフォルトはウィンドウモード
    00040     settings->setWindowed(true);
    00041     // フルスクリーンを要求されればフルスクリーン
    00042     if(startFullscreen && foundFullscreen){ settings->setWindowed(false); }
    00043     // フルスクリーンしか見つからなければフルスクリーン
    00044     if((!foundWindowed) && foundFullscreen){ settings->setWindowed(false); }
    00045     // 両方見つからなければ失敗
    00046     if((!foundWindowed) && (!foundFullscreen)){ return false; }
    00047     return true;
    00048 }
    00049 //------------------------------------------------------------------------------
    00050 // ウインドウモード設定の構築
    00051 void GraphicsDeviceSelector::buildWindowModeSettings(
    00052     HWND windowHandle, const D3DDISPLAYMODE& displayMode,
    00053     GraphicsAdapterInformation* bestAdapter,
    00054     GraphicsDeviceInformation* bestDevice,
    00055     GraphicsDeviceComboInformation* bestDeviceCombo){
    00056     // 設定にコピーする
    00057     GraphicsDeviceEnumeration* enumeration =
    00058         GraphicsDeviceEnumeration::getInstance();
    00059     GraphicsDeviceSettings* settings = GraphicsDeviceSettings::getInstance();
    00060     settings->setWindowed(true);
    00061     settings->setAdapterInformation(bestAdapter);
    00062     settings->setDeviceInformation(bestDevice);
    00063     settings->setDeviceComboInformation(bestDeviceCombo);
    00064     settings->setDisplayMode(displayMode);
    00065     if(enumeration->getUsesDepthStencilBuffer()){
    00066         // 列挙で制限していなければ、主にD3DFMT_D16が使用される。
    00067         settings->setDepthStencilFormat(
    00068             bestDeviceCombo->getDepthStencilFormat(0));
    00069     }
    00070     // マルチサンプルモードはD3DMULTISAMPLE_NONEがデフォルト
    00071     settings->setMultiSampleType(bestDeviceCombo->getMultiSampleType(0));
    00072     settings->setMultiSampleQuality(0);
    00073     // Pure Hardware Mixed Softwareの順で使用できるものが使用される。
    00074     settings->setVertexProcessingType(
    00075         bestDeviceCombo->getVertexProcessingType(0));
    00076     // プレゼンテーション間隔はD3DPRESENT_INTERVAL_IMMEDIATEがデフォルト
    00077     settings->setPresentationInterval(
    00078         bestDeviceCombo->getPresentationInterval(0));
    00079     // ウィンドウサイズ設定
    00080     RECT windowRect;
    00081     ::GetClientRect(windowHandle, &windowRect);
    00082     DimensionI windowSize(windowRect.right - windowRect.left,
    00083         windowRect.bottom - windowRect.top);
    00084     settings->setWindowSize(windowSize);
    00085
    00086 DebugOut("BestWindow %s %s\n%s\n",
    00087     bestAdapter->toString().getBytes(),
    00088     bestDevice->toString().getBytes(),
    00089     bestDeviceCombo->toString().getBytes());
    00090 DebugOut("( %d x %d ) %dHz window (%d x %d)\n\n",
    00091     displayMode.Width, displayMode.Height,
    00092     displayMode.RefreshRate, windowSize.width, windowSize.height);
    00093
    00094 }
    00095 //------------------------------------------------------------------------------
    00096 // フルスクリーンモード設定の構築
    00097 void GraphicsDeviceSelector::buildFullscreenModeSettings(
    00098     const D3DDISPLAYMODE& displayMode,
    00099     GraphicsAdapterInformation* bestAdapter,
    00100     GraphicsDeviceInformation* bestDevice,
    00101     GraphicsDeviceComboInformation* bestDeviceCombo){
    00102     // 設定にコピーする
    00103     GraphicsDeviceEnumeration* enumeration =
    00104         GraphicsDeviceEnumeration::getInstance();
    00105     GraphicsDeviceSettings* settings = GraphicsDeviceSettings::getInstance();
    00106     settings->setWindowed(false);
    00107     settings->setAdapterInformation(bestAdapter);
    00108     settings->setDeviceInformation(bestDevice);
    00109     settings->setDeviceComboInformation(bestDeviceCombo);
    00110     settings->setDisplayMode(displayMode);
    00111     if(enumeration->getUsesDepthStencilBuffer()){
    00112         // 列挙で制限していなければ、主にD3DFMT_D16が使用される。
    00113         settings->setDepthStencilFormat(
    00114             bestDeviceCombo->getDepthStencilFormat(0));
    00115     }
    00116     // マルチサンプルモードはD3DMULTISAMPLE_NONEがデフォルト
    00117     settings->setMultiSampleType(bestDeviceCombo->getMultiSampleType(0));
    00118     settings->setMultiSampleQuality(0);
    00119     // Pure Hardware Mixed Softwareの順で使用できるものが使用される。
    00120     settings->setVertexProcessingType(
    00121         bestDeviceCombo->getVertexProcessingType(0));
    00122     // プレゼンテーション間隔はD3DPRESENT_INTERVAL_IMMEDIATEがデフォルト
    00123     settings->setPresentationInterval(
    00124         bestDeviceCombo->getPresentationInterval(0));
    00125
    00126 DebugOut("BestFullscreen %s %s\n%s\n",
    00127     bestAdapter->toString().getBytes(),
    00128     bestDevice->toString().getBytes(),
    00129     bestDeviceCombo->toString().getBytes());
    00130 DebugOut("( %d x %d ) %dHz\n\n",
    00131     displayMode.Width, displayMode.Height,
    00132     displayMode.RefreshRate);
    00133 }
    00134 //------------------------------------------------------------------------------
    00135 } // End of namespace Lamp
    00136 //------------------------------------------------------------------------------