comparison src/video/win32/SDL_d3drender.c @ 3527:444cb12cadb6

Fixed to use the correct display adapter
author Sam Lantinga <slouken@libsdl.org>
date Sun, 06 Dec 2009 06:21:39 +0000
parents 83518f8fcd61
children 0267b8b1595c
comparison
equal deleted inserted replaced
3526:e6f2f312780f 3527:444cb12cadb6
104 104
105 typedef struct 105 typedef struct
106 { 106 {
107 IDirect3D9 *d3d; 107 IDirect3D9 *d3d;
108 IDirect3DDevice9 *device; 108 IDirect3DDevice9 *device;
109 UINT adapter;
109 D3DPRESENT_PARAMETERS pparams; 110 D3DPRESENT_PARAMETERS pparams;
110 SDL_bool beginScene; 111 SDL_bool beginScene;
111 } D3D_RenderData; 112 } D3D_RenderData;
112 113
113 typedef struct 114 typedef struct
239 default: 240 default:
240 return D3DFMT_UNKNOWN; 241 return D3DFMT_UNKNOWN;
241 } 242 }
242 } 243 }
243 244
245 static UINT D3D_FindAdapter(IDirect3D9 * d3d, SDL_VideoDisplay * display)
246 {
247 SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
248 UINT adapter, count;
249
250 count = IDirect3D9_GetAdapterCount(d3d);
251 for (adapter = 0; adapter < count; ++adapter) {
252 HRESULT result;
253 D3DADAPTER_IDENTIFIER9 info;
254 char *name;
255
256 result = IDirect3D9_GetAdapterIdentifier(d3d, adapter, 0, &info);
257 if (FAILED(result)) {
258 continue;
259 }
260 name = WIN_StringToUTF8(displaydata->DeviceName);
261 if (SDL_strcmp(name, info.DeviceName) == 0) {
262 SDL_free(name);
263 return adapter;
264 }
265 SDL_free(name);
266 }
267
268 /* This should never happen, but just in case... */
269 return D3DADAPTER_DEFAULT;
270 }
271
244 static SDL_bool 272 static SDL_bool
245 D3D_IsTextureFormatAvailable(IDirect3D9 * d3d, Uint32 display_format, 273 D3D_IsTextureFormatAvailable(IDirect3D9 * d3d, UINT adapter,
274 Uint32 display_format,
246 Uint32 texture_format) 275 Uint32 texture_format)
247 { 276 {
248 HRESULT result; 277 HRESULT result;
249 278
250 result = IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, /* FIXME */ 279 result = IDirect3D9_CheckDeviceFormat(d3d, adapter,
251 D3DDEVTYPE_HAL, 280 D3DDEVTYPE_HAL,
252 PixelFormatToD3DFMT(display_format), 281 PixelFormatToD3DFMT(display_format),
253 0, 282 0,
254 D3DRTYPE_TEXTURE, 283 D3DRTYPE_TEXTURE,
255 PixelFormatToD3DFMT 284 PixelFormatToD3DFMT
290 void 319 void
291 D3D_AddRenderDriver(_THIS) 320 D3D_AddRenderDriver(_THIS)
292 { 321 {
293 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; 322 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
294 SDL_RendererInfo *info = &D3D_RenderDriver.info; 323 SDL_RendererInfo *info = &D3D_RenderDriver.info;
295 SDL_DisplayMode *mode = &SDL_CurrentDisplay.desktop_mode;
296 324
297 if (data->d3d) { 325 if (data->d3d) {
298 int i; 326 int i, j;
299 int formats[] = { 327 int formats[] = {
300 SDL_PIXELFORMAT_INDEX8, 328 SDL_PIXELFORMAT_INDEX8,
301 SDL_PIXELFORMAT_RGB332, 329 SDL_PIXELFORMAT_RGB332,
302 SDL_PIXELFORMAT_RGB444, 330 SDL_PIXELFORMAT_RGB444,
303 SDL_PIXELFORMAT_RGB555, 331 SDL_PIXELFORMAT_RGB555,
307 SDL_PIXELFORMAT_RGB888, 335 SDL_PIXELFORMAT_RGB888,
308 SDL_PIXELFORMAT_ARGB8888, 336 SDL_PIXELFORMAT_ARGB8888,
309 SDL_PIXELFORMAT_ARGB2101010, 337 SDL_PIXELFORMAT_ARGB2101010,
310 }; 338 };
311 339
312 for (i = 0; i < SDL_arraysize(formats); ++i) { 340 for (i = 0; i < _this->num_displays; ++i) {
313 if (D3D_IsTextureFormatAvailable 341 SDL_VideoDisplay *display = &_this->displays[i];
314 (data->d3d, mode->format, formats[i])) { 342 SDL_DisplayMode *mode = &display->desktop_mode;
315 info->texture_formats[info->num_texture_formats++] = 343 UINT adapter = D3D_FindAdapter(data->d3d, display);
316 formats[i]; 344
345 /* Get the matching D3D adapter for this display */
346 info->num_texture_formats = 0;
347 for (j = 0; j < SDL_arraysize(formats); ++j) {
348 if (D3D_IsTextureFormatAvailable
349 (data->d3d, adapter, mode->format, formats[j])) {
350 info->texture_formats[info->num_texture_formats++] =
351 formats[j];
352 }
317 } 353 }
318 } 354 info->texture_formats[info->num_texture_formats++] =
319 info->texture_formats[info->num_texture_formats++] = 355 SDL_PIXELFORMAT_YV12;
320 SDL_PIXELFORMAT_YV12; 356 info->texture_formats[info->num_texture_formats++] =
321 info->texture_formats[info->num_texture_formats++] = 357 SDL_PIXELFORMAT_IYUV;
322 SDL_PIXELFORMAT_IYUV; 358 info->texture_formats[info->num_texture_formats++] =
323 info->texture_formats[info->num_texture_formats++] = 359 SDL_PIXELFORMAT_YUY2;
324 SDL_PIXELFORMAT_YUY2; 360 info->texture_formats[info->num_texture_formats++] =
325 info->texture_formats[info->num_texture_formats++] = 361 SDL_PIXELFORMAT_UYVY;
326 SDL_PIXELFORMAT_UYVY; 362 info->texture_formats[info->num_texture_formats++] =
327 info->texture_formats[info->num_texture_formats++] = 363 SDL_PIXELFORMAT_YVYU;
328 SDL_PIXELFORMAT_YVYU; 364
329 365 SDL_AddRenderDriver(display, &D3D_RenderDriver);
330 for (i = 0; i < _this->num_displays; ++i) {
331 SDL_AddRenderDriver(&_this->displays[i], &D3D_RenderDriver);
332 } 366 }
333 } 367 }
334 } 368 }
335 369
336 SDL_Renderer * 370 SDL_Renderer *
422 pparams.PresentationInterval = D3DPRESENT_INTERVAL_ONE; 456 pparams.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
423 } else { 457 } else {
424 pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; 458 pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
425 } 459 }
426 460
427 IDirect3D9_GetDeviceCaps(videodata->d3d, D3DADAPTER_DEFAULT, 461 data->adapter = D3D_FindAdapter(videodata->d3d, display);
462 IDirect3D9_GetDeviceCaps(videodata->d3d, data->adapter,
428 D3DDEVTYPE_HAL, &caps); 463 D3DDEVTYPE_HAL, &caps);
429 464
430 result = IDirect3D9_CreateDevice(videodata->d3d, D3DADAPTER_DEFAULT, /* FIXME */ 465 result = IDirect3D9_CreateDevice(videodata->d3d, data->adapter,
431 D3DDEVTYPE_HAL, 466 D3DDEVTYPE_HAL,
432 windowdata->hwnd, 467 windowdata->hwnd,
433 (caps. 468 (caps.
434 DevCaps & 469 DevCaps &
435 D3DDEVCAPS_HWTRANSFORMANDLIGHT) ? 470 D3DDEVCAPS_HWTRANSFORMANDLIGHT) ?
577 612
578 texture->driverdata = data; 613 texture->driverdata = data;
579 614
580 if (SDL_ISPIXELFORMAT_FOURCC(texture->format) && 615 if (SDL_ISPIXELFORMAT_FOURCC(texture->format) &&
581 (texture->format != SDL_PIXELFORMAT_YUY2 || 616 (texture->format != SDL_PIXELFORMAT_YUY2 ||
582 !D3D_IsTextureFormatAvailable(renderdata->d3d, display_format, 617 !D3D_IsTextureFormatAvailable(renderdata->d3d, renderdata->adapter,
583 texture->format)) 618 display_format, texture->format))
584 && (texture->format != SDL_PIXELFORMAT_YVYU 619 && (texture->format != SDL_PIXELFORMAT_YVYU
585 || !D3D_IsTextureFormatAvailable(renderdata->d3d, display_format, 620 || !D3D_IsTextureFormatAvailable(renderdata->d3d, renderdata->adapter,
586 texture->format))) { 621 display_format, texture->format))) {
587 data->yuv = 622 data->yuv =
588 SDL_SW_CreateYUVTexture(texture->format, texture->w, texture->h); 623 SDL_SW_CreateYUVTexture(texture->format, texture->w, texture->h);
589 if (!data->yuv) { 624 if (!data->yuv) {
590 return -1; 625 return -1;
591 } 626 }