PDA

View Full Version : Forcing OpenGL not to use available hardware?



bridger
11-03-2000, 10:36 AM
Does anybody know how I can force my OpenGL program to use software paths on Windows rather than the hardware accceleration? I've seen a number of application have buttons which allow you to force the app to only use software OGL paths and I was wondering how that was done. Surely I don't have to write a wrapper around every one of my OpenGL calls. Any advice appreciated.

Eric
11-05-2000, 11:31 PM
You have to create your own ChoosePixelFormat by enumerating all pixelformats (DescribePixelFormat is the one to use). Then, you must pick up a pixel format that features PFD_GENERIC_FORMAT in the flags.

Here is part of the code I use for that... It is not clean neither clear but it works !

class ComparePixelFormat
{

public:

bool bSameAccelerated;
bool bSameDoubleBuffer;
bool bSameDrawToWindow;
bool bSameDrawToBitmap;
bool bSameColorBits;
bool bSameDepthBits;
bool bSameStencilBits;
int iStencilBits;
int iColorBits;
int iDepthBits;

ComparePixelFormat();
int Score(void);
bool IsBetter(ComparePixelFormat *pCPF);

};

ComparePixelFormat::ComparePixelFormat()
{

bSameAccelerated=false;
bSameDoubleBuffer=false;
bSameDrawToWindow=false;
bSameDrawToBitmap=false;
bSameColorBits=false;
bSameDepthBits=false;
bSameStencilBits=false;
iColorBits=32;
iDepthBits=32;
iStencilBits=32;

}

int ComparePixelFormat::Score(void)
{

int Score=0;

if (!bSameAccelerated)
Score+=256;
if (!bSameDoubleBuffer)
Score+=256;
if (!bSameDrawToWindow)
Score+=256;
if (!bSameDrawToBitmap)
Score+=256;
if ((!bSameColorBits)&&(iColorBits>0))
Score+=iColorBits*4;
if ((!bSameDepthBits)&&(iDepthBits>0))
Score+=iDepthBits*2;
if ((!bSameStencilBits)&&(iStencilBits>0))
Score+=iStencilBits;
return(Score);

}

bool ComparePixelFormat::IsBetter(ComparePixelFormat *pCPF)
{

int Score1=Score();
int Score2=pCPF->Score();
if (Score1<Score2)
return(true);
return(false);

}

//************************************************** ************************************************** *******//
//* Procedure Name : C_GLViewParameters::FindPixelFormat *//
//* Parameters ... : HDC hdc ; PIXELFORMATDESCRIPTOR *ppfd *//
//* Value ........ : int *//
//* Role ......... : *//
//************************************************** ************************************************** *******//

int C_GLViewParameters::FindPixelFormat(HDC hdc,PIXELFORMATDESCRIPTOR *ppfd)
{

PIXELFORMATDESCRIPTOR CurrentPFD;
ComparePixelFormat CurrentCompare;
PIXELFORMATDESCRIPTOR UsedPFD;
ComparePixelFormat UsedCompare;
int iUsedPFD=0;
int i;

int iNPixelFormats=DescribePixelFormat(hdc,0,0,NULL);
for (i=1;i<=iNPixelFormats;i++)
{
DescribePixelFormat(hdc,i,sizeof(CurrentPFD),&CurrentPFD);
CurrentCompare.bSameAccelerated=((CurrentPFD.dwFla gs&PFD_GENERIC_FORMAT)==(ppfd->dwFlags&PFD_GENERIC_FORMAT));
CurrentCompare.bSameDoubleBuffer=((CurrentPFD.dwFl ags&PFD_DOUBLEBUFFER)==(ppfd->dwFlags&PFD_DOUBLEBUFFER));
if (ppfd->dwFlags&PFD_DRAW_TO_WINDOW)
CurrentCompare.bSameDrawToWindow=(CurrentPFD.dwFla gs&PFD_DRAW_TO_WINDOW);
else
CurrentCompare.bSameDrawToWindow=true;
if (ppfd->dwFlags&PFD_DRAW_TO_BITMAP)
CurrentCompare.bSameDrawToBitmap=(CurrentPFD.dwFla gs&PFD_DRAW_TO_BITMAP);
else
CurrentCompare.bSameDrawToBitmap=true;
CurrentCompare.bSameColorBits=(ppfd->cColorBits==CurrentPFD.cColorBits);
CurrentCompare.bSameDepthBits=(ppfd->cDepthBits==CurrentPFD.cDepthBits);
CurrentCompare.bSameStencilBits=(ppfd->cStencilBits==CurrentPFD.cStencilBits);
CurrentCompare.iColorBits=ppfd->cColorBits-CurrentPFD.cColorBits;
CurrentCompare.iDepthBits=ppfd->cDepthBits-CurrentPFD.cDepthBits;
CurrentCompare.iStencilBits=ppfd->cStencilBits-CurrentPFD.cStencilBits;
if (CurrentCompare.IsBetter(&UsedCompare))
{
UsedPFD=CurrentPFD;
UsedCompare=CurrentCompare;
iUsedPFD=i;
}
}

PIXELFORMATDESCRIPTOR UsedPFD2;
int iUsedPFD2=ChoosePixelFormat(hdc,ppfd);
DescribePixelFormat(hdc,iUsedPFD2,sizeof(UsedPFD2) ,&UsedPFD2);

return(iUsedPFD);

}

//************************************************** ************************************************** *******//
//* Procedure Name : C_GLViewParameters::SetupPixelFormat *//
//* Parameters ... : DWORD PixelFormatFlags *//
//* Value ........ : bool *//
//* Role ......... : *//
//************************************************** ************************************************** *******//

bool C_GLViewParameters::SetupPixelFormat(DWORD PixelFormatFlags)
{

CGLFrameApp *pApp=(CGLFrameApp*) AfxGetApp();
if (!pApp->m_bUseHWAcceleration)
PixelFormatFlags|=PFD_GENERIC_FORMAT;

PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR),// size of this pfd
1, // version number
PixelFormatFlags,
PFD_TYPE_RGBA, // RGBA type
m_iNColorBits, // Color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
m_iNDepthBits, // Z-buffer depth
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};

int pixelformat;
PIXELFORMATDESCRIPTOR *pPFD=&pfd;

if ((pixelformat=FindPixelFormat(m_pDC->GetSafeHdc(),pPFD))==0)
{
AfxMessageBox("FindPixelFormat failed.");
return false;
}
if (SetPixelFormat(m_pDC->GetSafeHdc(),pixelformat,pPFD)==FALSE)
{
AfxMessageBox("SetPixelFormat failed.");
return false;
}
PIXELFORMATDESCRIPTOR PFD;
DescribePixelFormat(m_pDC->GetSafeHdc(),pixelformat,sizeof(PFD),&PFD);
m_iNColorBits=PFD.cColorBits;
m_iNDepthBits=PFD.cDepthBits;
return true;

}

Ask if you have any question !

Regards.

Eric