src/osd/windows/drawd3d.c
| r11645 | r11646 | |
| 87 | 87 | |
| 88 | 88 | #define ENABLE_BORDER_PIX (1) |
| 89 | 89 | |
| 90 | | #define VERTEX_BASE_FORMAT (D3DFVF_DIFFUSE | D3DFVF_TEX1 | D3DFVF_TEX2) |
| 91 | | #define VERTEX_BUFFER_SIZE (2048*6+6) |
| 90 | #define VERTEX_BASE_FORMAT (D3DFVF_DIFFUSE | D3DFVF_TEX1) |
| 91 | #define VERTEX_BUFFER_SIZE (2048*4+4) |
| 92 | 92 | |
| 93 | 93 | enum |
| 94 | 94 | { |
| r11645 | r11646 | |
| 167 | 167 | float rhw; // RHW when no HLSL, padding when HLSL |
| 168 | 168 | D3DCOLOR color; // diffuse color |
| 169 | 169 | float u0, v0; // texture stage 0 coordinates |
| 170 | | float uv_stretch, pad; // UV stretch (used by HLSL) |
| 171 | 170 | }; |
| 172 | 171 | |
| 173 | 172 | |
| r11645 | r11646 | |
| 799 | 798 | { |
| 800 | 799 | d3d->last_texture = texture; |
| 801 | 800 | d3d->last_texture_flags = (texture == NULL ? 0 : texture->flags); |
| 802 | | result = (*d3dintf->device.set_texture)(d3d->device, 0, (texture == NULL) ? NULL : texture->d3dfinaltex); |
| 801 | result = (*d3dintf->device.set_texture)(d3d->device, 0, (texture == NULL) ? d3d->default_texture->d3dfinaltex : texture->d3dfinaltex); |
| 803 | 802 | if(d3d->hlsl_enable && d3d->effect != NULL) |
| 804 | 803 | { |
| 805 | | (*d3dintf->effect.set_texture)(d3d->effect, "Diffuse", (texture == NULL) ? NULL : texture->d3dfinaltex); |
| 804 | (*d3dintf->effect.set_texture)(d3d->effect, "Diffuse", (texture == NULL) ? d3d->default_texture->d3dfinaltex : texture->d3dfinaltex); |
| 806 | 805 | if(d3d->yiq_enable) |
| 807 | 806 | { |
| 808 | | (*d3dintf->effect.set_texture)(d3d->yiq_encode_effect, "Diffuse", (texture == NULL) ? NULL : texture->d3dfinaltex); |
| 807 | (*d3dintf->effect.set_texture)(d3d->yiq_encode_effect, "Diffuse", (texture == NULL) ? d3d->default_texture->d3dfinaltex : texture->d3dfinaltex); |
| 809 | 808 | } |
| 810 | 809 | else |
| 811 | 810 | { |
| 812 | | (*d3dintf->effect.set_texture)(d3d->color_effect, "Diffuse", (texture == NULL) ? NULL : texture->d3dfinaltex); |
| 811 | (*d3dintf->effect.set_texture)(d3d->color_effect, "Diffuse", (texture == NULL) ? d3d->default_texture->d3dfinaltex : texture->d3dfinaltex); |
| 813 | 812 | } |
| 814 | | (*d3dintf->effect.set_texture)(d3d->pincushion_effect, "Diffuse", (texture == NULL) ? NULL : texture->d3dfinaltex); |
| 813 | (*d3dintf->effect.set_texture)(d3d->pincushion_effect, "Diffuse", (texture == NULL) ? d3d->default_texture->d3dfinaltex : texture->d3dfinaltex); |
| 815 | 814 | } |
| 816 | 815 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture call\n", (int)result); |
| 817 | 816 | } |
| r11645 | r11646 | |
| 1162 | 1161 | } |
| 1163 | 1162 | |
| 1164 | 1163 | mtlog_add("drawd3d_window_draw: begin"); |
| 1165 | | |
| 1166 | 1164 | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1167 | | if(result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 1165 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 1168 | 1166 | |
| 1169 | 1167 | // first update any textures |
| 1170 | 1168 | window->primlist->acquire_lock(); |
| r11645 | r11646 | |
| 1309 | 1307 | |
| 1310 | 1308 | // create the D3D device |
| 1311 | 1309 | result = (*d3dintf->d3d.create_device)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, win_window_list->hwnd, |
| 1312 | | D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &d3d->presentation, &d3d->device); |
| 1310 | D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &d3d->presentation, &d3d->device); |
| 1313 | 1311 | if (result != D3D_OK) |
| 1314 | 1312 | { |
| 1315 | 1313 | // if we got a "DEVICELOST" error, it may be transitory; count it and only fail if |
| r11645 | r11646 | |
| 1507 | 1505 | // allocate a vertex buffer to use |
| 1508 | 1506 | result = (*d3dintf->device.create_vertex_buffer)(d3d->device, |
| 1509 | 1507 | sizeof(d3d_vertex) * VERTEX_BUFFER_SIZE, |
| 1510 | | D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, |
| 1508 | D3DUSAGE_DYNAMIC | D3DUSAGE_SOFTWAREPROCESSING | D3DUSAGE_WRITEONLY, |
| 1511 | 1509 | VERTEX_BASE_FORMAT | ((d3d->hlsl_enable && d3dintf->post_fx_available) ? D3DFVF_XYZW : D3DFVF_XYZRHW), D3DPOOL_DEFAULT, &d3d->vertexbuf); |
| 1512 | 1510 | if (result != D3D_OK) |
| 1513 | 1511 | { |
| r11645 | r11646 | |
| 1552 | 1550 | reset_render_states(d3d); |
| 1553 | 1551 | |
| 1554 | 1552 | // clear the buffer |
| 1555 | | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255,0,0,0), 0, 0); |
| 1553 | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1556 | 1554 | result = (*d3dintf->device.present)(d3d->device, NULL, NULL, NULL, NULL, 0); |
| 1557 | 1555 | |
| 1558 | 1556 | // experimental: if we have a vector bitmap, create a texture for it |
| r11645 | r11646 | |
| 1572 | 1570 | d3d->vector_texture = texture_create(d3d, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32)); |
| 1573 | 1571 | } |
| 1574 | 1572 | |
| 1575 | | // experimental: initialize some more things if we're using HLSL |
| 1576 | | if(d3d->hlsl_enable && d3dintf->post_fx_available) |
| 1573 | // experimental: create a default bitmap for our shader |
| 1574 | if (d3d->default_bitmap != NULL) |
| 1577 | 1575 | { |
| 1578 | | // experimental: create a default bitmap for our shader |
| 1579 | | if (d3d->default_bitmap != NULL) |
| 1580 | | { |
| 1581 | | render_texinfo texture; |
| 1576 | render_texinfo texture; |
| 1582 | 1577 | |
| 1583 | | // fake in the basic data so it looks like it came from render.c |
| 1584 | | texture.base = d3d->default_bitmap->base; |
| 1585 | | texture.rowpixels = d3d->default_bitmap->rowpixels; |
| 1586 | | texture.width = d3d->default_bitmap->width; |
| 1587 | | texture.height = d3d->default_bitmap->height; |
| 1588 | | texture.palette = NULL; |
| 1589 | | texture.seqid = 0; |
| 1578 | // fake in the basic data so it looks like it came from render.c |
| 1579 | texture.base = d3d->default_bitmap->base; |
| 1580 | texture.rowpixels = d3d->default_bitmap->rowpixels; |
| 1581 | texture.width = d3d->default_bitmap->width; |
| 1582 | texture.height = d3d->default_bitmap->height; |
| 1583 | texture.palette = NULL; |
| 1584 | texture.seqid = 0; |
| 1590 | 1585 | |
| 1591 | | // now create it |
| 1592 | | d3d->default_texture = texture_create(d3d, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32)); |
| 1593 | | } |
| 1586 | // now create it |
| 1587 | d3d->default_texture = texture_create(d3d, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32)); |
| 1588 | } |
| 1594 | 1589 | |
| 1590 | // experimental: initialize some more things if we're using HLSL |
| 1591 | if(d3d->hlsl_enable && d3dintf->post_fx_available) |
| 1592 | { |
| 1595 | 1593 | windows_options &options = downcast<windows_options &>(d3d->window->machine().options()); |
| 1596 | 1594 | |
| 1597 | 1595 | // experimental: load a PNG to use for vector rendering; it is treated |
| r11645 | r11646 | |
| 2352 | 2350 | |
| 2353 | 2351 | vertex[3].u0 = d3d->vector_texture->ustop; |
| 2354 | 2352 | vertex[3].v0 = d3d->vector_texture->vstop; |
| 2355 | | |
| 2356 | | vertex[0].uv_stretch = 1.0f; |
| 2357 | | vertex[1].uv_stretch = 1.0f; |
| 2358 | | vertex[2].uv_stretch = 1.0f; |
| 2359 | | vertex[3].uv_stretch = 1.0f; |
| 2360 | 2353 | } |
| 2361 | 2354 | else if(d3d->default_texture != NULL) |
| 2362 | 2355 | { |
| r11645 | r11646 | |
| 2371 | 2364 | |
| 2372 | 2365 | vertex[3].u0 = d3d->default_texture->ustart; |
| 2373 | 2366 | vertex[3].v0 = d3d->default_texture->vstart; |
| 2374 | | |
| 2375 | | vertex[0].uv_stretch = 0.0f; |
| 2376 | | vertex[1].uv_stretch = 0.0f; |
| 2377 | | vertex[2].uv_stretch = 0.0f; |
| 2378 | | vertex[3].uv_stretch = 0.0f; |
| 2379 | 2367 | } |
| 2380 | | else |
| 2381 | | { |
| 2382 | | vertex[0].uv_stretch = 0.0f; |
| 2383 | | vertex[1].uv_stretch = 0.0f; |
| 2384 | | vertex[2].uv_stretch = 0.0f; |
| 2385 | | vertex[3].uv_stretch = 0.0f; |
| 2386 | | } |
| 2387 | 2368 | |
| 2388 | 2369 | // set the color, Z parameters to standard values |
| 2389 | 2370 | for (i = 0; i < 4; i++) |
| r11645 | r11646 | |
| 2422 | 2403 | texture = texture != NULL ? texture : d3d->default_texture; |
| 2423 | 2404 | |
| 2424 | 2405 | // get a pointer to the vertex buffer |
| 2425 | | vertex = primitive_alloc(d3d, 6); |
| 2406 | vertex = primitive_alloc(d3d, 4); |
| 2426 | 2407 | if (vertex == NULL) |
| 2427 | 2408 | return; |
| 2428 | 2409 | |
| r11645 | r11646 | |
| 2433 | 2414 | vertex[1].y = prim->bounds.y0 - 0.5f; |
| 2434 | 2415 | vertex[2].x = prim->bounds.x0 - 0.5f; |
| 2435 | 2416 | vertex[2].y = prim->bounds.y1 - 0.5f; |
| 2417 | vertex[3].x = prim->bounds.x1 - 0.5f; |
| 2418 | vertex[3].y = prim->bounds.y1 - 0.5f; |
| 2436 | 2419 | |
| 2437 | | vertex[3].x = vertex[1].x; |
| 2438 | | vertex[3].y = vertex[1].y; |
| 2439 | | vertex[4].x = vertex[2].x; |
| 2440 | | vertex[4].y = vertex[2].y; |
| 2441 | | vertex[5].x = prim->bounds.x1 - 0.5f; |
| 2442 | | vertex[5].y = prim->bounds.y1 - 0.5f; |
| 2443 | | |
| 2444 | 2420 | // set the texture coordinates |
| 2445 | 2421 | if(texture != NULL) |
| 2446 | 2422 | { |
| r11645 | r11646 | |
| 2452 | 2428 | vertex[1].v0 = texture->vstart + dv * prim->texcoords.tr.v; |
| 2453 | 2429 | vertex[2].u0 = texture->ustart + du * prim->texcoords.bl.u; |
| 2454 | 2430 | vertex[2].v0 = texture->vstart + dv * prim->texcoords.bl.v; |
| 2455 | | |
| 2456 | | vertex[3].u0 = texture->ustart + du * prim->texcoords.tr.u; |
| 2457 | | vertex[3].v0 = texture->vstart + dv * prim->texcoords.tr.v; |
| 2458 | | vertex[4].u0 = texture->ustart + du * prim->texcoords.bl.u; |
| 2459 | | vertex[4].v0 = texture->vstart + dv * prim->texcoords.bl.v; |
| 2460 | | vertex[5].u0 = texture->ustart + du * prim->texcoords.br.u; |
| 2461 | | vertex[5].v0 = texture->vstart + dv * prim->texcoords.br.v; |
| 2462 | | |
| 2463 | | vertex[0].uv_stretch = 1.0f; |
| 2464 | | vertex[1].uv_stretch = 1.0f; |
| 2465 | | vertex[2].uv_stretch = 1.0f; |
| 2466 | | vertex[3].uv_stretch = 1.0f; |
| 2467 | | vertex[4].uv_stretch = 1.0f; |
| 2468 | | vertex[5].uv_stretch = 1.0f; |
| 2431 | vertex[3].u0 = texture->ustart + du * prim->texcoords.br.u; |
| 2432 | vertex[3].v0 = texture->vstart + dv * prim->texcoords.br.v; |
| 2469 | 2433 | } |
| 2470 | | else |
| 2471 | | { |
| 2472 | | vertex[0].uv_stretch = 1.0f; |
| 2473 | | vertex[1].uv_stretch = 1.0f; |
| 2474 | | vertex[2].uv_stretch = 1.0f; |
| 2475 | | vertex[3].uv_stretch = 1.0f; |
| 2476 | | vertex[4].uv_stretch = 1.0f; |
| 2477 | | vertex[5].uv_stretch = 1.0f; |
| 2478 | | } |
| 2479 | 2434 | |
| 2480 | 2435 | // determine the color, allowing for over modulation |
| 2481 | 2436 | r = (INT32)(prim->color.r * 255.0f); |
| r11645 | r11646 | |
| 2506 | 2461 | color = D3DCOLOR_ARGB(a, r, g, b); |
| 2507 | 2462 | |
| 2508 | 2463 | // set the color, Z parameters to standard values |
| 2509 | | for (i = 0; i < 6; i++) |
| 2464 | for (i = 0; i < 4; i++) |
| 2510 | 2465 | { |
| 2511 | 2466 | vertex[i].z = 0.0f; |
| 2512 | 2467 | vertex[i].rhw = 1.0f; |
| r11645 | r11646 | |
| 2515 | 2470 | |
| 2516 | 2471 | // now add a polygon entry |
| 2517 | 2472 | poly = &d3d->poly[d3d->numpolys++]; |
| 2518 | | poly->type = D3DPT_TRIANGLELIST; |
| 2473 | poly->type = D3DPT_TRIANGLESTRIP; |
| 2519 | 2474 | poly->count = 2; |
| 2520 | | poly->numverts = 6; |
| 2475 | poly->numverts = 4; |
| 2521 | 2476 | poly->flags = prim->flags; |
| 2522 | 2477 | poly->modmode = modmode; |
| 2523 | 2478 | poly->texture = texture; |
| r11645 | r11646 | |
| 2532 | 2487 | static void init_fsfx_quad(d3d_info *d3d) |
| 2533 | 2488 | { |
| 2534 | 2489 | // get a pointer to the vertex buffer |
| 2535 | | d3d->fsfx_vertices = primitive_alloc(d3d, 6); |
| 2490 | d3d->fsfx_vertices = primitive_alloc(d3d, 4); |
| 2536 | 2491 | if (d3d->fsfx_vertices == NULL) |
| 2537 | 2492 | return; |
| 2538 | 2493 | |
| r11645 | r11646 | |
| 2547 | 2502 | d3d->fsfx_vertices[1].y = 0.0f; |
| 2548 | 2503 | d3d->fsfx_vertices[2].x = (d3d->width * (scale_bottom * 0.5f - 0.5f)); |
| 2549 | 2504 | d3d->fsfx_vertices[2].y = d3d->height; |
| 2550 | | d3d->fsfx_vertices[3].x = d3d->width - (d3d->width * (scale_top * 0.5f - 0.5f)); |
| 2551 | | d3d->fsfx_vertices[3].y = 0.0f; |
| 2552 | | d3d->fsfx_vertices[4].x = (d3d->width * (scale_bottom * 0.5f - 0.5f)); |
| 2553 | | d3d->fsfx_vertices[4].y = d3d->height; |
| 2554 | | d3d->fsfx_vertices[5].x = d3d->width - (d3d->width * (scale_bottom * 0.5f - 0.5f)); |
| 2555 | | d3d->fsfx_vertices[5].y = d3d->height; |
| 2505 | d3d->fsfx_vertices[3].x = d3d->width - (d3d->width * (scale_bottom * 0.5f - 0.5f)); |
| 2506 | d3d->fsfx_vertices[3].y = d3d->height; |
| 2556 | 2507 | |
| 2557 | 2508 | d3d->fsfx_vertices[0].u0 = 0.0f; |
| 2558 | 2509 | d3d->fsfx_vertices[0].v0 = 0.0f; |
| r11645 | r11646 | |
| 2561 | 2512 | d3d->fsfx_vertices[2].u0 = 0.0f; |
| 2562 | 2513 | d3d->fsfx_vertices[2].v0 = 1.0f; |
| 2563 | 2514 | d3d->fsfx_vertices[3].u0 = 1.0f; |
| 2564 | | d3d->fsfx_vertices[3].v0 = 0.0f; |
| 2565 | | d3d->fsfx_vertices[4].u0 = 0.0f; |
| 2566 | | d3d->fsfx_vertices[4].v0 = 1.0f; |
| 2567 | | d3d->fsfx_vertices[5].u0 = 1.0f; |
| 2568 | | d3d->fsfx_vertices[5].v0 = 1.0f; |
| 2515 | d3d->fsfx_vertices[3].v0 = 1.0f; |
| 2569 | 2516 | |
| 2570 | 2517 | // set the color, Z parameters to standard values |
| 2571 | | for (int i = 0; i < 6; i++) |
| 2518 | for (int i = 0; i < 4; i++) |
| 2572 | 2519 | { |
| 2573 | 2520 | d3d->fsfx_vertices[i].z = 0.0f; |
| 2574 | 2521 | d3d->fsfx_vertices[i].rhw = 1.0f; |
| r11645 | r11646 | |
| 2656 | 2603 | { |
| 2657 | 2604 | result = (*d3dintf->device.get_render_target)(d3d->device, 0, &backbuffer); |
| 2658 | 2605 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device get_render_target call\n", (int)result); |
| 2659 | | vertnum = 6; |
| 2606 | vertnum = 4; |
| 2660 | 2607 | } |
| 2661 | 2608 | else |
| 2662 | 2609 | { |