int MaxCard=8;
int i = 0, j = 0;
DISPLAY_DEVICE Dd[MaxCard];
HDC hDc[MaxCard];
DEVMODE CardMode[MaxCard];
HGLRC CardRc[MaxCard];
PIXELFORMATDESCRIPTOR pfd[MaxCard];
for(i=0;i<MaxCard;++i)
{
Dd[i].cb=sizeof(DISPLAY_DEVICE);
}
//Get GPU Name
i=0;
while (EnumDisplayDevices(NULL, i, &(Dd[j]), 0))
{
//GPU Name
if(Dd[j].StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)
{
++j;
}
++i;
}
for(int CardId=0;CardId<j;++CardId)
{
EnumDisplaySettingsEx(Dd[CardId].DeviceName, ENUM_CURRENT_SETTINGS, &CardMode[CardId], 0);
//Create DC by GPU Name
hDc[CardId] = CreateDC(Dd[CardId].DeviceName, 0, NULL, &CardMode[CardId]);
//Set pfd parameters
……
unsigned int PixelFormat=ChoosePixelFormat(hDc[CardId],&(pfd[CardId]));
SetPixelFormat(hDc[CardId],PixelFormat,&pfd);
CardRc[CardId]=wglCreateContext(hDc[CardId]);
}
//abover ok
//other initial work
……
//when you want some shaders execute in the i GPU Card
wglMakeCurrent(hDc[i],CardRc[i]); //??????? this operation fail, the return message is invalid operation. why? how resolve this error???????
//execute some shader
shader.enable();
……
shader.disable();
//other work
……