برنامه نویسی Direct3D در ویژوال بیسیک (قسمت دوم)
1. شمارش تعداد آداپتورهای گرافیکی یک سیستم
فرض کنید متغیر nAdapters متغیری از نوع Long باشد. همچنین شی D3DADAPTER_IDENTIFIER8 یک ساختار است که اطلاعات مربوط به آداپتور را نگه می دارد. در اینصورت روتین EnumerateAdapters بصورت زیر خواهد بود:
کد:
برای بدست آوردن جزئیات آداپتورها بصورت زیر عمل می کنیم:کد:Dim AdapterInfo As D3DADAPTER_IDENTIFIER8 Private Sub EnumerateAdapters Dim i As Integer nAdapters = D3D.GetAdapterCount
کد:
نام آداپتور بصورت لیستی از کدهای اسکی است که بایستی آنها را درون یک String قرار دهیم:کد:For i = 0 To nAdapters - 1 D3D.GetAdapterIdentifier i, 0, AdapterInfo
کد:
بنابراین در متغیر Name نام آداپتور قرار خواهد گرفت.کد:Name = "" For J = 0 To 511 Name = Name & Chr$(AdapterInfo.Description(J)) Next J Name = Replace(sTemp, Chr$(0), " ") Next i End Sub
2. مشخص کردن نوع Rendering
فرض کنید شی D3DCAPS8 توانایی Rendering آداپتور را نشان دهد. در اینصورت روتین EnumerateDevices بصورت زیر خواهد بود:
کد:
اگر آداپتور امکان رندر سخت افزاری نداشته باشد در اینصورت:کد:Private Sub EnumerateDevices() On Local Error Resume Next Dim Caps As D3DCAPS8 Dim deviceindex As Long deviceindex = 0 'For Example D3D.GetDeviceCaps deviceindex, D3DDEVTYPE_HAL, Caps If Err.Number = D3DERR_NOTAVAILABLE Then MsgBox("Reference Rasterizer (REF)")
کد:
3. شمارش تعداد Mode نمایشی آداپتورکد:Else MsgBox("Hardware Acceleration (HAL) + Reference Rasterizer (REF)") End If End Sub
فرض کنید در صورت REF بودن امکان رندر، متغیر r=2 و در غیراینصورت r=1 باشد . همچنین شی D3DDISPLAYMODE اطلاعات مدهای نمایشی را در خود داشته باشد و متغیر nModes از نوع Long باشد. در اینصورت روتین EnumerateDispModes بصورت زیر خواهد بود:
کد:
ابتدا Modeها را به دو گروه ۱۶ بیتی و ۳۲ بیتی تقسیم می کنیم:کد:Private Sub EnumerateDispModes(r As Long) Dim i As Integer Dim mode_tmp As D3DDISPLAYMODE Dim deviceindex As Long deviceindex=0 'For Example nModes = D3D.GetAdapterModeCount(deviceindex) For i = 0 to nModes - 1 D3D.EnumAdapterModes(deviceindex, i, mode_tmp)
کد:
حال چک می کنیم که Device قابل پذیرش و معتبر است یا نه:کد:If mode_tmp.Format = D3DFMT_R8G8B8 Or mode_tmp.Format = D3DFMT_X8R8G8B8 Or mode_tmp.Format = D3DFMT_A8R8G8B8 Then
کد:
4. مشخص کردن توانایی های آداپتور گرافیکیکد:If D3D.CheckDeviceType(deviceindex, r, mode_tmp.Format, mode_tmp.Format, Flase) >= 0 Then MsgBox(mode_tmp.Width & "X" & mode_tmp.Height & "32 Bit [FMT:" & mode_tmp.Format & "]" End If Else If D3D.CheckDeviceType(deviceindex, r, mode_tmp.Format, mode_tmp.Format, Flase) >=0 Then MsgBox(mode_tmp.Width & "X" & mode_tmp.Height & "16 Bit [FMT:" & mode_tmp.Format & "]" End If End If Next i End Sub
فرض کنید در صورت REF بودن امکان رندر، متغیر r=2 و در غیراینصورت r=1 باشد:
کد:
کد:Private Sub EnumerateHardware(r as long) Dim caps As D3DCAPS8 Dim deviceindex As Long deviceindex=0 'For Example D3D.Getdevicecaps deviceindex, r, caps If Caps.MaxActiveLights = -1 Then MsgBox "Maximum Active Lights: Unlimited" Else MsgBox "Maximum Active Lights: " & Caps.MaxActiveLights End If MsgBox "Maximum Point Vertex size: " & Caps.MaxPointSize MsgBox "Maximum Texture Size: " & Caps.MaxTextureWidth & "X" & Caps.MaxTextureHeight MsgBox "Maximum Primatives in one call: " & Caps.MaxPrimitiveCount If Caps.TextureCaps And D3DPTEXTURECAPS_SQUAREONLY Then MsgBox "Textures must always be square" End If If Caps.TextureCaps And D3DPTEXTURECAPS_CUBEMAP Then MsgBox "Device Supports Cube Mapping" End If If Caps.TextureCaps And D3DPTEXTURECAPS_VOLUMEMAP Then MsgBox "Device Supports Volume Mapping" End If If Caps.DevCaps And D3DDEVCAPS_PUREDEVICE Then MsgBox "Device supports the Pure Device Option" End If If Caps.DevCaps And D3DDEVCAPS_HWTRANSFORMANDLIGHT Then MsgBox "Device supports hardware transform and lighting" End If If Caps.DevCaps And D3DDEVCAPS_HWRASTERIZATION Then MsgBox "Device can use Hardware Rasterization" End If If Caps.Caps2 And D3DCAPS2_CANCALIBRATEGAMMA Then MsgBox "Device can Calibrate Gamma" End If If Caps.Caps2 And D3DCAPS2_CANRENDERWINDOWED Then MsgBox "Device can Render in Windowed Mode" End If If Caps.Caps2 And D3DCAPS2_FULLSCREENGAMMA Then MsgBox "Device can calibrate gamma in fullscreen mode" End If If Caps.RasterCaps And D3DPRASTERCAPS_FOGRANGE Then MsgBox "Device supports range based fog calculations" End If If Caps.RasterCaps And D3DPRASTERCAPS_ANISOTROPY Then MsgBox "Device supports Anisotropic Filtering" End If If Caps.RasterCaps And D3DPRASTERCAPS_ZBUFFERLESSHSR Then MsgBox "Device does not require a Z-Buffer/Depth Buffer" End If End Sub




نمي كنيد
پاسخ با نقل قول
