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

GraphicsAdapterInformation.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/Enumeration/GraphicsAdapterInformation.h"
00027 #include "Graphics/Enumeration/GraphicsDeviceEnumeration.h"
00028 #include "Graphics/System/LampGraphics.h"
00029 #include "Graphics/Primitive/GraphicsBufferFormat.h"
00030 
00031 namespace Lamp{
00032 
00033 //------------------------------------------------------------------------------
00034 // ディスプレイモード比較
00035 static int displayModeCompare(
00036     const D3DDISPLAYMODE* left, const D3DDISPLAYMODE* right){
00037     if(left->Width > right->Width){ return 1; }
00038     if(left->Width < right->Width){ return -1; }
00039     if(left->Height > right->Height){ return 1; }
00040     if(left->Height < right->Height){ return -1; }
00041     if(left->Format > right->Format){ return 1; }
00042     if(left->Format < right->Format){ return -1; }
00043     if(left->RefreshRate > right->RefreshRate){ return 1; }
00044     if(left->RefreshRate < right->RefreshRate){ return -1; }
00045     return 0;
00046 }
00047 //------------------------------------------------------------------------------
00048 // コンストラクタ
00049 GraphicsAdapterInformation::GraphicsAdapterInformation(int adapterOrdinal) :
00050     adapterOrdinal_(adapterOrdinal){
00051 }
00052 //------------------------------------------------------------------------------
00053 // デストラクタ
00054 GraphicsAdapterInformation::~GraphicsAdapterInformation(){
00055     // デバイスの削除
00056     for(int i = getDeviceCount() - 1; i >= 0; i--){
00057         delete getDevice(i);
00058     }
00059 }
00060 //------------------------------------------------------------------------------
00061 // 列挙
00062 void GraphicsAdapterInformation::enumerate(
00063     GraphicsDeviceEnumeration* enumeration){
00064     // アダプタ識別子の取得
00065     Direct3D* direct3D = LampGraphics::getDirect3D();
00066     direct3D->GetAdapterIdentifier(adapterOrdinal_, 0, &identifier_);
00067     name_ = identifier_.Description;
00068     driverName_ = identifier_.Driver;
00069     u_int minimumWidth = enumeration->getMinimumFullscreenWidth();
00070     u_int minimumHeight = enumeration->getMinimumFullscreenHeight();
00071     u_int minimumColorBits = enumeration->getMinimumAdapterColorChannelBits();
00072     // 許可フォーマットによるディスプレイモードの列挙
00073     int allowedFormatCount = enumeration->getAllowedFormatCount();
00074     for(int i = 0; i < allowedFormatCount; i++){
00075         D3DFORMAT allowedFormat = enumeration->getAllowedFormat(i);
00076         GraphicsBufferFormat bufferFormat(allowedFormat);
00077         u_int adapterModesCount =
00078             direct3D->GetAdapterModeCount(adapterOrdinal_, allowedFormat);
00079         for(u_int j = 0; j < adapterModesCount; j++){
00080             D3DDISPLAYMODE displayMode;
00081             direct3D->EnumAdapterModes(
00082                 adapterOrdinal_, allowedFormat, j, &displayMode);
00083             // 条件に合わないディスプレイモードは無視
00084             if(displayMode.Width < minimumWidth ||
00085                 displayMode.Height < minimumHeight ||
00086                 bufferFormat.getColorChannelBits() < minimumColorBits){
00087                 continue;
00088             }
00089             // ディスプレイモードの格納
00090             displayModes_.add(displayMode);
00091             if(adapterFormats_.indexOf(displayMode.Format) == -1){
00092                 adapterFormats_.add(displayMode.Format);
00093             }
00094         }
00095     }
00096     // ディスプレイモードのソート
00097     displayModes_.sort(displayModeCompare);
00098     // 全てのデバイスタイプ
00099     // D3DDEVTYPE_SWを有効にしていると以下のワーニングが出る場合がある
00100     // No SW device has been registered. GetAdapterCaps fails.
00101     const D3DDEVTYPE deviceTypes[] = {
00102         D3DDEVTYPE_HAL,
00103         D3DDEVTYPE_SW,
00104         D3DDEVTYPE_REF
00105     };
00106     const u_int deviceTypesCount = sizeof(deviceTypes) / sizeof(deviceTypes[0]);
00107     for(int i = 0; i < deviceTypesCount; i++){
00108         GraphicsDeviceInformation* device = new GraphicsDeviceInformation();
00109         bool result = device->enumerate(enumeration, this, deviceTypes[i]);
00110         // 列挙失敗かデバイスコンボが0なら削除
00111         if((!result) || (device->getDeviceComboCount() == 0)){
00112             delete device;
00113             continue;
00114         }
00115         devices_.add(device);
00116     }
00117 }
00118 //------------------------------------------------------------------------------
00119 // 文字列への変換
00120 String GraphicsAdapterInformation::toString(){
00121     String result;
00122     result.format("%s %d", name_.getBytes(), adapterOrdinal_);
00123 /*
00124     for(int i = 0; i < getDisplayModeCount(); i++){
00125         D3DDISPLAYMODE displayMode = getDisplayMode(i);
00126         GraphicsBufferFormat bufferFormat(displayMode.Format);
00127         String displayModeString;
00128         displayModeString.format("\t%s ( %d x %d ) %dHz\n",
00129             bufferFormat.getName().getBytes(), displayMode.Width, displayMode.Height,
00130             displayMode.RefreshRate);
00131         result += displayModeString;
00132     }
00133 */
00134     return result;
00135 }
00136 //------------------------------------------------------------------------------
00137 } // End of namespace Lamp
00138 //------------------------------------------------------------------------------

Generated on Wed Mar 16 10:29:30 2005 for Lamp by doxygen 1.3.2