Results 1 to 2 of 2

Thread: Rock-Solid dxGraphics Enumeration in VB

  1. #1

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134

    Rock-Solid dxGraphics Enumeration in VB

    I've compiled a series of functions to return the best 3D card's index based on maximum resolution, rendering layer (hal and ref), and device (puredevice, hardware_vertexprocessing, and software_vertexprocessing). I thought everyone can benefit from my hour's worth of work if I posted it here.

    Enjoy!

    VB Code:
    1. Function RetRenderer(Adapter As Long) As Long
    2. On Local Error Resume Next
    3. Dim DevCaps As D3DCAPS8
    4.  
    5. D3D.GetDeviceCaps Adapter, D3DDEVTYPE_HAL, DevCaps
    6.  
    7. 'If (DevCaps.DevCaps And D3DDEVCAPS_PUREDEVICE) Then
    8. '    RetRenderer = D3DCREATE_PUREDEVICE
    9. '    Exit Function
    10. 'Else
    11. 'End If
    12.  
    13. If (DevCaps.DevCaps And D3DDEVCAPS_HWTRANSFORMANDLIGHT) Then
    14.     RetRenderer = D3DCREATE_HARDWARE_VERTEXPROCESSING
    15.     Exit Function
    16. Else
    17. End If
    18.  
    19. If Err.Number = D3DERR_INVALIDDEVICE Or D3DERR_NOTAVAILABLE Then
    20.     RetRenderer = D3DCREATE_SOFTWARE_VERTEXPROCESSING
    21. End If
    22. End Function
    23.  
    24. Function RetLayer(Adapter As Long) As CONST_D3DDEVTYPE
    25. On Local Error Resume Next
    26. Dim DevCaps As D3DCAPS8
    27.  
    28. D3D.GetDeviceCaps Adapter, D3DDEVTYPE_HAL, DevCaps
    29.  
    30. If Err.Number = D3DERR_INVALIDDEVICE Or Err.Number = D3DERR_NOTAVAILABLE Then
    31.     RetLayer = D3DDEVTYPE_REF
    32.     Exit Function
    33. End If
    34.  
    35. RetLayer = D3DDEVTYPE_HAL
    36. End Function
    37.  
    38. Function RetLargeMode(Layer As CONST_D3DDEVTYPE, Adapter As Long) As D3DDISPLAYMODE
    39. Dim I As Integer, ModeTemp As D3DDISPLAYMODE, LastModeTemp As D3DDISPLAYMODE
    40.  
    41. nModes = D3D.GetAdapterModeCount(Adapter)
    42.  
    43. LastModeTemp.Height = 1
    44. LastModeTemp.Width = 1
    45. LastModeTemp.Format = D3DFMT_A8R3G3B2
    46. LastModeTemp.RefreshRate = 0
    47.  
    48. For I = 0 To nModes - 1
    49.     Call D3D.EnumAdapterModes(Adapter, I, ModeTemp)
    50.    
    51.     If ModeTemp.Format = D3DFMT_R8G8B8 Or ModeTemp.Format = D3DFMT_X8R8G8B8 Or ModeTemp.Format = D3DFMT_A8R8G8B8 Then
    52.         If D3D.CheckDeviceType(Adapter, Layer, ModeTemp.Format, ModeTemp.Format, False) >= 0 Then
    53.             If LargerBPP(ModeTemp, LastModeTemp) Then
    54.                 If ModeTemp.Width >= LastModeTemp.Width Then
    55.                     If ModeTemp.Height >= LastModeTemp.Height Then
    56.                         If ModeTemp.RefreshRate >= LastModeTemp.RefreshRate Then
    57.                             LastModeTemp = ModeTemp
    58.                         End If
    59.                     End If
    60.                 End If
    61.             End If
    62.         End If
    63.     Else
    64.         If D3D.CheckDeviceType(Adapter, Layer, ModeTemp.Format, ModeTemp.Format, False) >= 0 Then
    65.             If LargerBPP(ModeTemp, LastModeTemp) Then
    66.                 If ModeTemp.Width >= LastModeTemp.Width Then
    67.                     If ModeTemp.Height >= LastModeTemp.Height Then
    68.                         If ModeTemp.RefreshRate >= LastModeTemp.RefreshRate Then
    69.                             LastModeTemp = ModeTemp
    70.                         End If
    71.                     End If
    72.                 End If
    73.             End If
    74.         End If
    75.     End If
    76.    
    77. Next I
    78.  
    79. RetLargeMode = LastModeTemp
    80.  
    81. End Function
    82.  
    83. Public Function GetBest3DAdapter() As Long
    84. Dim nAdapters As Long
    85. Dim I As Long
    86. Dim cLayer() As CONST_D3DDEVTYPE
    87. Dim cRenderer() As Long
    88. Dim cLargeMode() As D3DDISPLAYMODE
    89. Dim BestAdapter As Long
    90. Dim BetterFlag As Boolean
    91.  
    92.     nAdapters = D3D.GetAdapterCount
    93.     If nAdapters = 1 Then
    94.         GetBest3DAdapter = 0
    95.         Exit Function
    96.     End If
    97.    
    98.     ReDim cLayer(nAdapters) As CONST_D3DDEVTYPE
    99.     ReDim cRenderer(nAdapters) As Long
    100.     ReDim cLargeMode(nAdapters) As D3DDISPLAYMODE
    101.    
    102.     For I = 0 To nAdapters - 1
    103.         cLayer(I) = RetLayer(I)
    104.         cRenderer(I) = RetRenderer(I)
    105.         cLargeMode(I) = RetLargeMode(cLayer(I), I)
    106.     Next I
    107.  
    108.     BestAdapter = 0
    109.  
    110.     For I = 1 To nAdapters - 1
    111.         BetterFlag = False
    112.         If cLayer(I) = D3DDEVTYPE_HAL And cLayer(BestAdapter) <> D3DDEVTYPE_HAL Then
    113.             BetterFlag = True
    114.         Else
    115.             If cRenderer(I) = D3DCREATE_PUREDEVICE And cLayer(BestAdapter) <> D3DCREATE_PUREDEVICE Then
    116.                 BetterFlag = True
    117.             ElseIf cRenderer(I) = D3DCREATE_HARDWARE_VERTEXPROCESSING And cRenderer(BestAdapter) = D3DCREATE_SOFTWARE_VERTEXPROCESSING Then
    118.                 BetterFlag = True
    119.             Else
    120.                 If cLargeMode(I).Width * cLargeMode(I).Height > cLargeMode(BestAdapter).Width * cLargeMode(BestAdapter).Height Then
    121.                     BetterFlag = True
    122.                 Else
    123.                     If LargerBPP(cLargeMode(I), cLargeMode(BestAdapter)) Then
    124.                         BetterFlag = True
    125.                     Else
    126.                     End If
    127.                 End If
    128.             End If
    129.         End If
    130.         If BetterFlag Then BestAdapter = I
    131.     Next I
    132.    
    133.     GetBest3DAdapter = BestAdapter
    134. End Function
    135.  
    136.  
    137. Function LargerBPP(ByRef This As D3DDISPLAYMODE, ByRef Last As D3DDISPLAYMODE) As Boolean
    138. Dim ThisBPP As Long
    139. Dim LastBPP As Long
    140.    
    141.     If This.Format = D3DFMT_A8R8G8B8 Or This.Format = D3DFMT_R8G8B8 Or This.Format = D3DFMT_X8R8G8B8 Then ThisBPP = 32 Else ThisBPP = 16
    142.     If Last.Format = D3DFMT_A8R8G8B8 Or Last.Format = D3DFMT_R8G8B8 Or Last.Format = D3DFMT_X8R8G8B8 Then LastBPP = 32 Else LastBPP = 16
    143.     If ThisBPP >= LastBPP Then LargerBPP = True
    144.  
    145. End Function
    146.  
    147. Public Sub Render()
    148.  
    149. D3DDevice.Clear 0, ByVal 0, D3DCLEAR_TARGET, &HFFCC00, 1#, 0
    150. D3DDevice.BeginScene
    151. '<------------------
    152.  
    153. '<------------------
    154. D3DDevice.EndScene
    155. D3DDevice.Present ByVal 0, ByVal 0, 0, ByVal 0
    156. End Sub
    157.  
    158. Function GetFullScreen(W As Long, H As Long, B As Long, Adapter As Long) As D3DPRESENT_PARAMETERS
    159. Dim D3DWindow As D3DPRESENT_PARAMETERS
    160. Dim DispMode As D3DDISPLAYMODE
    161.  
    162.     D3D.GetAdapterDisplayMode BestAdapter, DispMode
    163.  
    164.     D3DWindow.hDeviceWindow = View.hWnd
    165.    
    166.     If B = 32 Then D3DWindow.BackBufferFormat = D3DFMT_A8R8G8B8
    167.     If B = 24 Then D3DWindow.BackBufferFormat = D3DFMT_R8G8B8
    168.     If B = 16 Then D3DWindow.BackBufferFormat = D3DFMT_R5G6B5
    169.     If B = 8 Then D3DWindow.BackBufferFormat = D3DFMT_R3G3B2
    170.     If B <> 8 And B <> 16 And B <> 24 And B <> 32 Then D3DWindow.BackBufferFormat = D3DFMT_R8G8B8
    171.    
    172.     D3DWindow.BackBufferWidth = W
    173.     D3DWindow.BackBufferHeight = H
    174.    
    175.     If D3D.CheckDeviceFormat(Adapter, RetLayer(Adapter), DispMode.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D32) = D3D_OK Then
    176.       D3DWindow.AutoDepthStencilFormat = D3DFMT_D32
    177.       D3DWindow.EnableAutoDepthStencil = 1
    178.     Else
    179.    
    180.       If D3D.CheckDeviceFormat(Adapter, RetLayer(Adapter), DispMode.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24X8) = D3D_OK Then
    181.         D3DWindow.AutoDepthStencilFormat = D3DFMT_D24X8
    182.         D3DWindow.EnableAutoDepthStencil = 1
    183.       Else
    184.         If D3D.CheckDeviceFormat(Adapter, RetLayer(Adapter), DispMode.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D16) = D3D_OK Then
    185.           D3DWindow.AutoDepthStencilFormat = D3DFMT_D16
    186.           D3DWindow.EnableAutoDepthStencil = 1
    187.         Else
    188.           D3DWindow.EnableAutoDepthStencil = 0
    189.         End If
    190.       End If
    191.     End If
    192.    
    193.     D3DWindow.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC
    194.     D3DWindow.BackBufferCount = 1
    195.    
    196.     GetFullScreen = D3DWindow
    197. End Function

    Edited for Miscellaneous VB Errors
    Edited for Errors and New Function
    Edited for Serious Errors


    It all works now, except it sometimes says that you have PUREDEVICE when you really don't. I've edited that part out, maybe someone can find a fix.
    Last edited by Sastraxi; Jul 3rd, 2001 at 10:15 PM.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  2. #2
    Addicted Member DigitalMyth's Avatar
    Join Date
    Nov 2002
    Location
    England..
    Posts
    169
    Anyone know the answer to this fake PUREDEVICE detection, i have the same problem with my DX project?

    If you run this code on a Mid-High Geforce4 Cards and the low FX cards it detects PURE but PURE isn't supported.

    Thanks
    Digi

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width