src/osd/windows/d3dhlsl.h
| r12956 | r12957 | |
| 137 | 137 | slider_state *init_slider_list(); |
| 138 | 138 | |
| 139 | 139 | private: |
| 140 | void enumerate_screens(); |
| 141 | |
| 140 | 142 | void end_avi_recording(); |
| 141 | 143 | void begin_avi_recording(const char *name); |
| 142 | 144 | |
| r12956 | r12957 | |
| 146 | 148 | win_window_info * window; // D3D window info |
| 147 | 149 | |
| 148 | 150 | bool master_enable; // overall enable flag |
| 151 | bool paused; // whether or not rendering is currently paused |
| 152 | int num_screens; // number of emulated physical screens |
| 153 | int lastidx; // index of the last-encountered target |
| 149 | 154 | bool write_ini; // enable external ini saving |
| 150 | 155 | bool read_ini; // enable external ini loading |
| 151 | 156 | int prescale_force_x; // prescale force x |
| r12956 | r12957 | |
| 156 | 161 | bitmap_t * shadow_bitmap; // shadow mask bitmap for post-processing shader |
| 157 | 162 | d3d_texture_info * shadow_texture; // shadow mask texture for post-processing shader |
| 158 | 163 | int registered_targets; // number of registered HLSL targets (i.e., screens) |
| 164 | int cyclic_target_idx; // cyclic index of next HLSL target slot |
| 159 | 165 | hlsl_options * options; // current uniform state |
| 160 | 166 | avi_file * avi_output_file; // AVI file |
| 161 | 167 | bitmap_t * avi_snap; // AVI snapshot |
| r12956 | r12957 | |
| 191 | 197 | d3d_vertex * fsfx_vertices; // pointer to our full-screen-quad object |
| 192 | 198 | |
| 193 | 199 | // render targets |
| 200 | int raw_target_idx[9]; // Number of targets currently in use |
| 194 | 201 | int target_use_count[9]; // Whether or not a target has been used yet |
| 195 | 202 | d3d_texture_info * target_in_use[9]; // Target texture that is currently in use |
| 196 | 203 | int target_width[9]; // Render target width |
src/osd/windows/d3dhlsl.c
| r12956 | r12957 | |
| 66 | 66 | #include "emuopts.h" |
| 67 | 67 | #include "aviio.h" |
| 68 | 68 | #include "png.h" |
| 69 | #include "screen.h" |
| 69 | 70 | |
| 70 | 71 | // MAMEOS headers |
| 71 | 72 | #include "d3dintf.h" |
| r12956 | r12957 | |
| 198 | 199 | shadow_bitmap = NULL; |
| 199 | 200 | shadow_texture = NULL; |
| 200 | 201 | registered_targets = 0; |
| 202 | cyclic_target_idx = 0; |
| 201 | 203 | options = NULL; |
| 204 | paused = true; |
| 205 | lastidx = -1; |
| 202 | 206 | } |
| 203 | 207 | |
| 204 | 208 | |
| r12956 | r12957 | |
| 599 | 603 | |
| 600 | 604 | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 601 | 605 | |
| 606 | if(texture != NULL) |
| 607 | { |
| 608 | if(texture->prev_frame == texture->cur_frame) |
| 609 | { |
| 610 | //printf("Paused\n"); |
| 611 | paused = true; |
| 612 | } |
| 613 | else |
| 614 | { |
| 615 | //printf("Not paused\n"); |
| 616 | paused = false; |
| 617 | } |
| 618 | |
| 619 | texture->prev_frame = texture->cur_frame; |
| 620 | //printf("%08x cur_frame is %d\n", (UINT32)(UINT64)texture, texture->cur_frame); |
| 621 | } |
| 622 | |
| 602 | 623 | (*d3dintf->effect.set_texture)(effect, "Diffuse", (texture == NULL) ? d3d->default_texture->d3dfinaltex : texture->d3dfinaltex); |
| 603 | 624 | if (options->yiq_enable) |
| 604 | 625 | (*d3dintf->effect.set_texture)(yiq_encode_effect, "Diffuse", (texture == NULL) ? d3d->default_texture->d3dfinaltex : texture->d3dfinaltex); |
| r12956 | r12957 | |
| 1229 | 1250 | |
| 1230 | 1251 | if(PRIMFLAG_GET_SCREENTEX(d3d->last_texture_flags) && poly->texture != NULL) |
| 1231 | 1252 | { |
| 1232 | | int targetidx = poly->texture->target_index; |
| 1253 | int rawidx = poly->texture->target_index; |
| 1254 | int targetidx = rawidx % 9; |
| 1255 | int minidx = cyclic_target_idx - (num_screens * 2); |
| 1256 | int wrappedidx = (minidx + ((rawidx - minidx) % num_screens) + num_screens) % 9; |
| 1257 | //printf("rendering %d %d %d %d %d %d %d %d %d %f %f\n", poly->texture->target_index, rawidx, targetidx, minidx, wrappedidx, poly->texture->rawwidth, poly->texture->rawheight, d3d->width, d3d->height, (float)(poly->texture->ustop - poly->texture->ustart), (float)(poly->texture->vstop - poly->texture->vstart)); |
| 1258 | |
| 1233 | 1259 | screen_encountered[targetidx] = true; |
| 1234 | 1260 | target_in_use[targetidx] = poly->texture; |
| 1235 | 1261 | |
| r12956 | r12957 | |
| 1504 | 1530 | // Simulate phosphorescence. This should happen after the shadow/scanline pass, but since |
| 1505 | 1531 | // the phosphors are a direct result of the incoming texture, might as well just change the |
| 1506 | 1532 | // input texture. |
| 1507 | | int num_screens = registered_targets / 2; |
| 1508 | 1533 | curr_effect = phosphor_effect; |
| 1534 | //printf("num_screens %d\n", num_screens); |
| 1509 | 1535 | |
| 1510 | 1536 | if(options->params_dirty) |
| 1511 | 1537 | { |
| r12956 | r12957 | |
| 1522 | 1548 | (*d3dintf->effect.set_float)(curr_effect, "Passthrough", 0.0f); |
| 1523 | 1549 | |
| 1524 | 1550 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", focus_enable ? texture1[targetidx] : texture2[targetidx]); |
| 1525 | | (*d3dintf->effect.set_texture)(curr_effect, "LastPass", last_texture[num_screens > 0 ? (targetidx % num_screens) : targetidx]); // Avoid changing targets due to page flipping |
| 1551 | (*d3dintf->effect.set_texture)(curr_effect, "LastPass", last_texture[wrappedidx]); // Avoid changing targets due to page flipping |
| 1526 | 1552 | |
| 1527 | 1553 | result = (*d3dintf->device.set_render_target)(d3d->device, 0, target0[targetidx]); |
| 1528 | 1554 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 4\n", (int)result); |
| r12956 | r12957 | |
| 1549 | 1575 | (*d3dintf->effect.set_texture)(curr_effect, "LastPass", texture0[targetidx]); |
| 1550 | 1576 | (*d3dintf->effect.set_float)(curr_effect, "Passthrough", 1.0f); |
| 1551 | 1577 | |
| 1552 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, last_target[num_screens > 0 ? (targetidx % num_screens) : targetidx]); // Avoid changing targets due to page flipping |
| 1578 | result = (*d3dintf->device.set_render_target)(d3d->device, 0, last_target[wrappedidx]); // Avoid changing targets due to page flipping |
| 1553 | 1579 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 5\n", (int)result); |
| 1554 | 1580 | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1555 | 1581 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| r12956 | r12957 | |
| 1683 | 1709 | |
| 1684 | 1710 | (*d3dintf->surface.release)(backbuffer); |
| 1685 | 1711 | |
| 1712 | //printf("registered_targets %d\n", registered_targets); |
| 1713 | |
| 1714 | // Don't check de-registration if we're paused. |
| 1715 | if(paused) |
| 1716 | { |
| 1717 | return; |
| 1718 | } |
| 1719 | |
| 1686 | 1720 | // Unregister any registered targets we didn't traverse in the past frame. A resolution change must |
| 1687 | 1721 | // have occurred. |
| 1688 | | for(int index = 0; index < 9 && master_enable && d3dintf->post_fx_available; index++) |
| 1722 | for(int index = 0; index < 9; index++) |
| 1689 | 1723 | { |
| 1690 | 1724 | if(!screen_encountered[index] && smalltarget0[index] != NULL) |
| 1691 | 1725 | { |
| r12956 | r12957 | |
| 1695 | 1729 | } |
| 1696 | 1730 | else |
| 1697 | 1731 | { |
| 1732 | //printf("deregging %d\n", index); |
| 1698 | 1733 | // free all textures |
| 1699 | 1734 | if(target_in_use[index] != NULL) |
| 1700 | 1735 | { |
| r12956 | r12957 | |
| 1810 | 1845 | last_target[index] = NULL; |
| 1811 | 1846 | } |
| 1812 | 1847 | target_use_count[index] = 0; |
| 1848 | registered_targets--; |
| 1813 | 1849 | } |
| 1814 | 1850 | } |
| 1815 | 1851 | } |
| r12956 | r12957 | |
| 1827 | 1863 | |
| 1828 | 1864 | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 1829 | 1865 | |
| 1830 | | int idx = registered_targets; |
| 1866 | //printf("registering prescaled texture, seqid %d\n", texture->texinfo.seqid); |
| 1831 | 1867 | |
| 1868 | int idx = cyclic_target_idx % 9; |
| 1869 | |
| 1832 | 1870 | // Find the nearest prescale factor that is over our screen size |
| 1833 | 1871 | int hlsl_prescale_x = prescale_force_x ? prescale_force_x : 1; |
| 1834 | 1872 | if(!prescale_force_x) |
| r12956 | r12957 | |
| 1884 | 1922 | return 1; |
| 1885 | 1923 | (*d3dintf->texture.get_surface_level)(last_texture[idx], 0, &last_target[idx]); |
| 1886 | 1924 | |
| 1887 | | texture->target_index = registered_targets; |
| 1925 | texture->target_index = cyclic_target_idx; |
| 1888 | 1926 | target_width[idx] = scwidth * hlsl_prescale_x; |
| 1889 | 1927 | target_height[idx] = scheight * hlsl_prescale_y; |
| 1890 | | target_use_count[texture->target_index] = 60; |
| 1891 | | target_in_use[texture->target_index] = texture; |
| 1928 | target_use_count[idx] = 60; |
| 1929 | target_in_use[idx] = texture; |
| 1930 | raw_target_idx[idx] = cyclic_target_idx; |
| 1892 | 1931 | registered_targets++; |
| 1893 | | registered_targets %= 9; |
| 1932 | cyclic_target_idx++; |
| 1894 | 1933 | |
| 1934 | options->params_dirty = true; |
| 1935 | |
| 1936 | enumerate_screens(); |
| 1937 | |
| 1895 | 1938 | return 0; |
| 1896 | 1939 | } |
| 1897 | 1940 | |
| 1898 | 1941 | //============================================================ |
| 1942 | // hlsl_info::enumerate_screens |
| 1943 | //============================================================ |
| 1944 | void hlsl_info::enumerate_screens() |
| 1945 | { |
| 1946 | screen_device *screen = window->machine().first_screen(); |
| 1947 | num_screens = 0; |
| 1948 | while(screen != NULL) |
| 1949 | { |
| 1950 | num_screens++; |
| 1951 | screen = screen->next_screen(); |
| 1952 | //printf("Encountered %d screens\n", num_screens); |
| 1953 | } |
| 1954 | } |
| 1955 | |
| 1956 | //============================================================ |
| 1899 | 1957 | // hlsl_info::register_texture |
| 1900 | 1958 | //============================================================ |
| 1901 | 1959 | |
| r12956 | r12957 | |
| 1906 | 1964 | |
| 1907 | 1965 | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 1908 | 1966 | |
| 1909 | | int idx = registered_targets; |
| 1967 | //printf("registering unscaled texture, seqid %d\n", texture->texinfo.seqid); |
| 1910 | 1968 | |
| 1969 | int idx = cyclic_target_idx % 9; |
| 1970 | |
| 1911 | 1971 | // Find the nearest prescale factor that is over our screen size |
| 1912 | 1972 | int hlsl_prescale_x = prescale_force_x ? prescale_force_x : 1; |
| 1913 | 1973 | if(!prescale_force_x) |
| r12956 | r12957 | |
| 1963 | 2023 | return 1; |
| 1964 | 2024 | (*d3dintf->texture.get_surface_level)(last_texture[idx], 0, &last_target[idx]); |
| 1965 | 2025 | |
| 1966 | | texture->target_index = registered_targets; |
| 2026 | texture->target_index = cyclic_target_idx; |
| 1967 | 2027 | target_width[idx] = texture->rawwidth * hlsl_prescale_x; |
| 1968 | 2028 | target_height[idx] = texture->rawheight * hlsl_prescale_y; |
| 1969 | | target_use_count[texture->target_index] = 60; |
| 1970 | | target_in_use[texture->target_index] = texture; |
| 2029 | target_use_count[idx] = 60; |
| 2030 | target_in_use[idx] = texture; |
| 2031 | raw_target_idx[idx] = cyclic_target_idx; |
| 1971 | 2032 | registered_targets++; |
| 1972 | | registered_targets %= 9; |
| 2033 | cyclic_target_idx++; |
| 1973 | 2034 | |
| 2035 | options->params_dirty = true; |
| 2036 | |
| 2037 | enumerate_screens(); |
| 2038 | |
| 1974 | 2039 | return 0; |
| 1975 | 2040 | } |
| 1976 | 2041 | |