enumeration problem

enumeration problem

Post by Cengi » Tue, 09 Sep 1997 04:00:00



I am having problems finding proper driver for full screen application.
I have Monster3D vodoo chip. I first enumerate DirectDraw to find D3D
compatible DirectDraw
driver (Hal) . I think this part works.

Then initialize DirectDraw and enumerate Drivers to find proper device
(Hal) for Retained mode.
If you have checked flip3d example in SDK samples this is exactly what I
want to do.
The reason I didn't use this sample because the guys preparing those
samples have unique talent
make their examples  understandable .I couldn't get a clue how he finds the
device in this sample.

Can any body recommend or send me enumeration function or CallBack for this
purpose
which might inspire me.

I am also giving the code I am using so some one might tell me the point I
am missing.

Thanks

//////////////////////////////////////////////////////////////////////
//
//Check to see is there any ddraw device installed.
//If so use it
BOOL FAR PASCAL DDEnumCallback(GUID FAR* lpGUID, LPSTR lpDriverDesc, LPSTR
lpDriverName, LPVOID lpContext)
{
        HRESULT r;

    DDCAPS DriverCaps, HELCaps;

        // Make sure the guid is valid
    if (lpGUID)
    {          

        // Try to create a DirectDraw object
        r=DirectDrawCreate(lpGUID, &lpDD, NULL);
        if(r!=DD_OK)
                D3DError("DirectDrawCreate(lpGUID, &lpDD, NULL) failed");

        // Get the DirectDraw capabilities
        memset(&DriverCaps, 0, sizeof(DDCAPS));
        DriverCaps.dwSize = sizeof(DDCAPS);

        memset(&HELCaps, 0, sizeof(DDCAPS));
        HELCaps.dwSize = sizeof(DDCAPS);

        r=lpDD->GetCaps(&DriverCaps, &HELCaps);
                if(r!=DD_OK)D3DError("lpDD->GetCaps(&DriverCaps, &HELCaps); failed");
        // Does this driver have 3D hardware capabilites?
        if (DriverCaps.dwCaps & DDCAPS_3D)
        {
                        // yep, use it and stop looking
            *(LPDIRECTDRAW*)lpContext = lpDD;
                        return DDENUMRET_CANCEL;
        }

        *(LPDIRECTDRAW*)lpContext = NULL;
        lpDD->Release();
                lpDD=NULL;
    }

    return DDENUMRET_OK;

Quote:}

////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////
//Initialize DDRAW
void CDdraw::InitDDraw(HWND hwndd,int ScreenW,int ScreenH,
                           int colordepth)
{

        HRESULT r;
        //copy windos handle ,screen resolution and color depth
        m_hwnd=hwndd;
        m_ScreenW=ScreenW;
        m_ScreenH=ScreenH;
        m_BPP=colordepth;

        r=DirectDrawEnumerate(DDEnumCallback, &lpDD);
        if( r != DD_OK )D3DError("DirectDrawEnumerate(DDEnumCallback, &lpDD)
failed");                          

        if(lpDD==NULL)
        {
                //if lpDD==NULL no harware capabilities
                r = DirectDrawCreate( NULL, &lpDD, NULL );                          
                if( r != DD_OK )D3DError("DirectDrawCreate( NULL, &lpDD, NULL );
failed");                                                                  

        }

        r= lpDD->SetCooperativeLevel( m_hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN |
DDSCL_ALLOWMODEX);
                if( r != DD_OK )D3DError("SetCooperativeLevel Failed");                  

        r= lpDD->QueryInterface(IID_IDirectDraw2,(LPVOID *)&lpDD2);
        if(r != DD_OK)D3DError("pDD->QueryInterface(IID_IDirectDraw2,(LPVOID
*)&lpDD); Failed");    

    r = lpDD->SetDisplayMode( m_ScreenW, m_ScreenH, m_BPP);                

                if( r != DD_OK )D3DError("SetDisplayMode Failed");                      

Quote:}

////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
///////////////

//////////////////////////////////////
//
// Finds a suitable device
LPGUID CDdraw::FindDevice(D3DCOLORMODEL cm)
{

    LPDIRECT3D lpD3D;
    D3DFINDDEVICESEARCH search;
    static D3DFINDDEVICERESULT result;
    HRESULT r;

    r=lpDD->QueryInterface(IID_IDirect3D, (void**) &lpD3D);
        if(r!=DD_OK)
          D3DError("lpDD->QueryInterface(IID_IDirect3D, (void**) &lpD3D) failed
");

    memset(&search, 0, sizeof search);
    search.dwSize = sizeof search;
    search.dwFlags = D3DFDS_COLORMODEL |D3DFDS_HARDWARE;
    search.dcmColorModel = (cm == D3DCOLOR_MONO) ? D3DCOLOR_MONO :
D3DCOLOR_RGB;
        search.bHardware=TRUE;

    memset(&result, 0, sizeof result);
    result.dwSize = sizeof result;

    r = lpD3D->FindDevice(&search, &result);
        if(r!=D3D_OK )
          D3DError("lpD3D->FindDevice(&search, &result) failed ");

    if (r == D3D_OK) {

         //If the device found is hardware but cannot support the current
         //bit depth, then fall back to software rendering.

        if (result.ddHwDesc.dwFlags
            && !(result.ddHwDesc.dwDeviceRenderBitDepth &
BPPToDDBD(m_BPP))) {

            search.dwFlags |= D3DFDS_HARDWARE;
            search.bHardware = FALSE;
            memset(&result, 0, sizeof result);
            result.dwSize = sizeof result;
            r = lpD3D->FindDevice(&search, &result);
                        if(r!=D3D_OK )
                        D3DError("lpD3D->---FindDevice(&search, &result); failed ");

        }
    }

    lpD3D->Release();
        lpD3D=NULL;

        return &result.guid;

Quote:}

and I call like this

m_pDD->InitDDraw(m_hwnd,m_ScreenW,m_ScreenH, m_BPP);
m_pDD->InitSurfaces();
m_pDD->GetSystemPalette();
m_pDD->InitZBuffer();
r =d3drm->CreateDeviceFromSurface(m_pDD->FindDevice(m_ColorModel), lpDD,
lpDDBack,&device);

cengiz

 
 
 

enumeration problem

Post by Mark Hul » Wed, 10 Sep 1997 04:00:00


Quote:>     r = lpD3D->FindDevice(&search, &result);

Hi,

        I had problems with FindDevice, basically it didn't find anything!.
        Use DirectDrawEnumerate that seems to work more reliably.

                        Mark

 
 
 

1. D3D device enumeration question.....

Hello all,

I've been getting into some D3D IM stuff lately and have found it pretty
easy to work with.  I've got a nice little DrawPrimitive demo that uses
directinput stuff to move an object around - pretty basic.  I also have hw
acceleration working and the demo is detecting my Matrox card and using it.
Seems good so far, but I have a question regarding actual device
detection...

The other day I took my demo to my friend's house to show.  He has a D3D
supported ATI card and a Voodoo based card.  My demo detects the ATI card
first (I assume because it is the primary display device) and uses it.  Say
I want to search for a specific device (the Voodoo based board, in this
example), how exactly would I go about doing that?  Right now I am just
filling in a D3DDEVICESEARCH structure with the appropriate values and
calling FindDevice();.  Now I am sure I am going to need to enumerate the
available devices, but once that is done what do I do to find a device I
want?

To put it another way, if I enumerate the devices on my friend's system, how
do I tell the difference between the ATI card and the Voodoo card?  How
would I recognize the Voodoo card so as to give the user a choice of cards?

Thanks in advance to anyone that can help,
Peter

2. Do parallel port scanners work in OS/2?

3. Problems with windows in fullscreen DirectX modes & Taskbar problem

4. Problem binding socket to IP address

5. EOF problems

6. The Spontaneous Intention Narrative

7. Mouse problem with windows/directX

8. IBM Stock Flies!

9. DirectDraw Screen Blt/Flip problem

10. PMODE problem!!!

11. Problem with sound code

12. VESA Problem

13. Problem Starting out Direct X with Visual C++ 5.0