00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00100
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
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
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 return result;
00135 }
00136
00137 }
00138