trunk/src/osd/windows/d3dhlsl.c
| r0 | r23475 | |
| 1 | //============================================================ |
| 2 | // |
| 3 | // d3dhlsl.c - Win32 Direct3D HLSL implementation |
| 4 | // |
| 5 | //============================================================ |
| 6 | // |
| 7 | // Copyright Aaron Giles |
| 8 | // All rights reserved. |
| 9 | // |
| 10 | // Redistribution and use in source and binary forms, with or |
| 11 | // without modification, are permitted provided that the |
| 12 | // following conditions are met: |
| 13 | // |
| 14 | // * Redistributions of source code must retain the above |
| 15 | // copyright notice, this list of conditions and the |
| 16 | // following disclaimer. |
| 17 | // * Redistributions in binary form must reproduce the |
| 18 | // above copyright notice, this list of conditions and |
| 19 | // the following disclaimer in the documentation and/or |
| 20 | // other materials provided with the distribution. |
| 21 | // * Neither the name 'MAME' nor the names of its |
| 22 | // contributors may be used to endorse or promote |
| 23 | // products derived from this software without specific |
| 24 | // prior written permission. |
| 25 | // |
| 26 | // THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND |
| 27 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 28 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 29 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 30 | // EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT, |
| 31 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 32 | // DAMAGE (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 33 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 34 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 35 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 37 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 38 | // IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 39 | // |
| 40 | //============================================================ |
| 41 | |
| 42 | // Useful info: |
| 43 | // Windows XP/2003 shipped with DirectX 8.1 |
| 44 | // Windows 2000 shipped with DirectX 7a |
| 45 | // Windows 98SE shipped with DirectX 6.1a |
| 46 | // Windows 98 shipped with DirectX 5 |
| 47 | // Windows NT shipped with DirectX 3.0a |
| 48 | // Windows 95 shipped with DirectX 2 |
| 49 | |
| 50 | // standard windows headers |
| 51 | #define WIN32_LEAN_AND_MEAN |
| 52 | #include <windows.h> |
| 53 | #include <tchar.h> |
| 54 | #include <mmsystem.h> |
| 55 | #include <d3d9.h> |
| 56 | #include <d3dx9.h> |
| 57 | #include <math.h> |
| 58 | #undef interface |
| 59 | |
| 60 | // MAME headers |
| 61 | #include "emu.h" |
| 62 | #include "render.h" |
| 63 | #include "ui.h" |
| 64 | #include "rendutil.h" |
| 65 | #include "options.h" |
| 66 | #include "emuopts.h" |
| 67 | #include "aviio.h" |
| 68 | #include "png.h" |
| 69 | #include "screen.h" |
| 70 | |
| 71 | // MAMEOS headers |
| 72 | #include "d3dintf.h" |
| 73 | #include "winmain.h" |
| 74 | #include "window.h" |
| 75 | #include "config.h" |
| 76 | #include "strconv.h" |
| 77 | #include "d3dcomm.h" |
| 78 | #include "drawd3d.h" |
| 79 | |
| 80 | |
| 81 | |
| 82 | //============================================================ |
| 83 | // GLOBALS |
| 84 | //============================================================ |
| 85 | |
| 86 | static slider_state *g_slider_list; |
| 87 | static file_error open_next(d3d::renderer *d3d, emu_file &file, const char *templ, const char *extension, int idx); |
| 88 | |
| 89 | namespace d3d |
| 90 | { |
| 91 | |
| 92 | hlsl_options shaders::s_hlsl_presets[4] = |
| 93 | { |
| 94 | { // 25% Shadow mask, 50% Scanlines, 3% Pincushion, 0 defocus, No Tint, 0.9 Exponent, 5% Floor, 25% Phosphor Return, 120% Saturation |
| 95 | true, |
| 96 | 0.25f, { "aperture.png" }, 320, 240, 0.09375f, 0.109375f, |
| 97 | 0.03f, 0.03f, |
| 98 | 0.5f, 1.0f, 0.5f, 1.0f, 0.0f, 0.0f, |
| 99 | { 0.0f, 0.0f, 0.0f, 0.0f }, |
| 100 | { 0.0f, 0.0f, 0.0f }, |
| 101 | { 0.0f, 0.0f, 0.0f }, |
| 102 | { 0.0f, 0.0f, 0.0f }, |
| 103 | { 0.0f, 0.0f, 0.0f }, |
| 104 | { 1.0f, 0.0f, 0.0f }, |
| 105 | { 0.0f, 1.0f, 0.0f }, |
| 106 | { 0.0f, 0.0f, 1.0f }, |
| 107 | { 0.0f, 0.0f, 0.0f }, |
| 108 | { 1.0f, 1.0f, 1.0f }, |
| 109 | { 0.9f, 0.9f, 0.9f }, |
| 110 | { 0.05f,0.05f,0.05f}, |
| 111 | { 0.25f,0.25f,0.25f}, |
| 112 | 1.2f, |
| 113 | false, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, |
| 114 | 0.9f, 4.0f, |
| 115 | 1.0f, 0.21f, 0.19f, 0.17f, 0.15f, 0.14f, 0.13f, 0.12f, 0.11f, 0.10f, 0.09f |
| 116 | }, |
| 117 | { // 25% Shadow mask, 0% Scanlines, 3% Pincushion, 0 defocus, No Tint, 0.9 Exponent, 5% Floor, 25% Phosphor Return, 120% Saturation |
| 118 | true, |
| 119 | 0.25f, { "aperture.png" }, 320, 240, 0.09375f, 0.109375f, |
| 120 | 0.03f, 0.03f, |
| 121 | 0.0f, 1.0f, 0.5f, 1.0f, 0.0f, 0.0f, |
| 122 | { 0.0f, 0.0f, 0.0f, 0.0f }, |
| 123 | { 0.0f, 0.0f, 0.0f }, |
| 124 | { 0.0f, 0.0f, 0.0f }, |
| 125 | { 0.0f, 0.0f, 0.0f }, |
| 126 | { 0.0f, 0.0f, 0.0f }, |
| 127 | { 1.0f, 0.0f, 0.0f }, |
| 128 | { 0.0f, 1.0f, 0.0f }, |
| 129 | { 0.0f, 0.0f, 1.0f }, |
| 130 | { 0.0f, 0.0f, 0.0f }, |
| 131 | { 1.0f, 1.0f, 1.0f }, |
| 132 | { 0.9f, 0.9f, 0.9f }, |
| 133 | { 0.05f,0.05f,0.05f}, |
| 134 | { 0.25f,0.25f,0.25f}, |
| 135 | 1.2f, |
| 136 | false, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, |
| 137 | 0.9f, 4.0f, |
| 138 | 1.0f, 0.21f, 0.19f, 0.17f, 0.15f, 0.14f, 0.13f, 0.12f, 0.11f, 0.10f, 0.09f |
| 139 | }, |
| 140 | { // 25% Shadow mask, 0% Scanlines, 0% Pincushion, 0 defocus, No Tint, 0.9 Exponent, 5% Floor, 25% Phosphor Return, 120% Saturation |
| 141 | true, |
| 142 | 0.25f, { "aperture.png" }, 320, 240, 0.09375f, 0.109375f, |
| 143 | 0.0f, 0.0f, |
| 144 | 0.0f, 1.0f, 0.5f, 1.0f, 0.0f, 0.0f, |
| 145 | { 0.0f, 0.0f, 0.0f, 0.0f }, |
| 146 | { 0.0f, 0.0f, 0.0f }, |
| 147 | { 0.0f, 0.0f, 0.0f }, |
| 148 | { 0.0f, 0.0f, 0.0f }, |
| 149 | { 0.0f, 0.0f, 0.0f }, |
| 150 | { 1.0f, 0.0f, 0.0f }, |
| 151 | { 0.0f, 1.0f, 0.0f }, |
| 152 | { 0.0f, 0.0f, 1.0f }, |
| 153 | { 0.0f, 0.0f, 0.0f }, |
| 154 | { 1.0f, 1.0f, 1.0f }, |
| 155 | { 0.9f, 0.9f, 0.9f }, |
| 156 | { 0.05f,0.05f,0.05f}, |
| 157 | { 0.25f,0.25f,0.25f}, |
| 158 | 1.2f, |
| 159 | false, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, |
| 160 | 0.9f, 4.0f, |
| 161 | 1.0f, 0.21f, 0.19f, 0.17f, 0.15f, 0.14f, 0.13f, 0.12f, 0.11f, 0.10f, 0.09f |
| 162 | }, |
| 163 | { // 25% Shadow mask, 100% Scanlines, 15% Pincushion, 3 defocus, 24-degree Tint Out, 1.5 Exponent, 5% Floor, 70% Phosphor Return, 80% Saturation, Bad Convergence |
| 164 | true, |
| 165 | 0.25f, { "aperture.png" }, 320, 240, 0.09375f, 0.109375f, |
| 166 | 0.15f, 0.15f, |
| 167 | 1.0f, 1.0f, 0.5f, 1.0f, 0.0f, 0.5f, |
| 168 | { 3.0f, 3.0f, 3.0f, 3.0f }, |
| 169 | { 0.5f,-0.33f,0.7f }, |
| 170 | { 0.0f,-1.0f, 0.5f }, |
| 171 | { 0.0f, 0.2f, 0.3f }, |
| 172 | { 0.0f, 0.2f, 0.0f }, |
| 173 | { 0.8f, 0.2f, 0.0f }, |
| 174 | { 0.0f, 0.8f, 0.2f}, |
| 175 | { 0.2f, 0.0f, 0.8f}, |
| 176 | { 0.0f, 0.0f, 0.0f }, |
| 177 | { 1.0f, 1.0f, 1.0f }, |
| 178 | { 1.5f, 1.5f, 1.5f }, |
| 179 | { 0.05f,0.05f,0.05f}, |
| 180 | { 0.7f, 0.7f, 0.7f}, |
| 181 | 0.8f, |
| 182 | false, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, |
| 183 | 0.9f, 4.0f, |
| 184 | 1.0f, 0.21f, 0.19f, 0.17f, 0.15f, 0.14f, 0.13f, 0.12f, 0.11f, 0.10f, 0.09f |
| 185 | }, |
| 186 | }; |
| 187 | |
| 188 | //============================================================ |
| 189 | // PROTOTYPES |
| 190 | //============================================================ |
| 191 | |
| 192 | static void get_vector(const char *data, int count, float *out, int report_error); |
| 193 | |
| 194 | |
| 195 | |
| 196 | //============================================================ |
| 197 | // shader manager constructor |
| 198 | //============================================================ |
| 199 | |
| 200 | shaders::shaders() |
| 201 | { |
| 202 | master_enable = false; |
| 203 | vector_enable = true; |
| 204 | prescale_size_x = 1; |
| 205 | prescale_size_y = 1; |
| 206 | prescale_force_x = 0; |
| 207 | prescale_force_y = 0; |
| 208 | preset = -1; |
| 209 | shadow_texture = NULL; |
| 210 | options = NULL; |
| 211 | paused = true; |
| 212 | lastidx = -1; |
| 213 | targethead = NULL; |
| 214 | cachehead = NULL; |
| 215 | initialized = false; |
| 216 | } |
| 217 | |
| 218 | |
| 219 | |
| 220 | //============================================================ |
| 221 | // shaders destructor |
| 222 | //============================================================ |
| 223 | |
| 224 | shaders::~shaders() |
| 225 | { |
| 226 | global_free(options); |
| 227 | cache_target *currcache = cachehead; |
| 228 | while(cachehead != NULL) |
| 229 | { |
| 230 | cachehead = currcache->next; |
| 231 | global_free(currcache); |
| 232 | currcache = cachehead; |
| 233 | } |
| 234 | |
| 235 | render_target *currtarget = targethead; |
| 236 | while(targethead != NULL) |
| 237 | { |
| 238 | targethead = currtarget->next; |
| 239 | global_free(currtarget); |
| 240 | currtarget = targethead; |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | |
| 245 | |
| 246 | //============================================================ |
| 247 | // shaders::window_save |
| 248 | //============================================================ |
| 249 | |
| 250 | void shaders::window_save() |
| 251 | { |
| 252 | if (!master_enable || !d3dintf->post_fx_available) |
| 253 | return; |
| 254 | |
| 255 | renderer *d3d = (renderer *)window->drawdata; |
| 256 | |
| 257 | HRESULT result = (*d3dintf->device.create_texture)(d3d->get_device(), snap_width, snap_height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &snap_copy_texture); |
| 258 | if (result != D3D_OK) |
| 259 | { |
| 260 | mame_printf_verbose("Direct3D: Unable to init system-memory target for HLSL snapshot (%08x), bailing\n", (UINT32)result); |
| 261 | return; |
| 262 | } |
| 263 | (*d3dintf->texture.get_surface_level)(snap_copy_texture, 0, &snap_copy_target); |
| 264 | |
| 265 | result = (*d3dintf->device.create_texture)(d3d->get_device(), snap_width, snap_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &snap_texture); |
| 266 | if (result != D3D_OK) |
| 267 | { |
| 268 | mame_printf_verbose("Direct3D: Unable to init video-memory target for HLSL snapshot (%08x), bailing\n", (UINT32)result); |
| 269 | return; |
| 270 | } |
| 271 | (*d3dintf->texture.get_surface_level)(snap_texture, 0, &snap_target); |
| 272 | |
| 273 | render_snap = true; |
| 274 | snap_rendered = false; |
| 275 | } |
| 276 | |
| 277 | |
| 278 | |
| 279 | //============================================================ |
| 280 | // shaders::window_record |
| 281 | //============================================================ |
| 282 | |
| 283 | void shaders::window_record() |
| 284 | { |
| 285 | if (!master_enable || !d3dintf->post_fx_available) |
| 286 | return; |
| 287 | |
| 288 | windows_options &options = downcast<windows_options &>(window->machine().options()); |
| 289 | const char *filename = options.d3d_hlsl_write(); |
| 290 | |
| 291 | if (avi_output_file != NULL) |
| 292 | end_avi_recording(); |
| 293 | else if (filename[0] != 0) |
| 294 | begin_avi_recording(filename); |
| 295 | } |
| 296 | |
| 297 | |
| 298 | //============================================================ |
| 299 | // shaders::avi_update_snap |
| 300 | //============================================================ |
| 301 | |
| 302 | void shaders::avi_update_snap(surface *surface) |
| 303 | { |
| 304 | if (!master_enable || !d3dintf->post_fx_available) |
| 305 | return; |
| 306 | |
| 307 | renderer *d3d = (renderer *)window->drawdata; |
| 308 | |
| 309 | D3DLOCKED_RECT rect; |
| 310 | |
| 311 | // if we don't have a bitmap, or if it's not the right size, allocate a new one |
| 312 | if (!avi_snap.valid() || (int)snap_width != avi_snap.width() || (int)snap_height != avi_snap.height()) |
| 313 | { |
| 314 | avi_snap.allocate((int)snap_width, (int)snap_height); |
| 315 | } |
| 316 | |
| 317 | // copy the texture |
| 318 | HRESULT result = (*d3dintf->device.get_render_target_data)(d3d->get_device(), surface, avi_copy_surface); |
| 319 | if (result != D3D_OK) |
| 320 | { |
| 321 | return; |
| 322 | } |
| 323 | |
| 324 | // lock the texture |
| 325 | result = (*d3dintf->surface.lock_rect)(avi_copy_surface, &rect, NULL, D3DLOCK_DISCARD); |
| 326 | if (result != D3D_OK) |
| 327 | { |
| 328 | return; |
| 329 | } |
| 330 | |
| 331 | // loop over Y |
| 332 | for (int srcy = 0; srcy < (int)snap_height; srcy++) |
| 333 | { |
| 334 | DWORD *src = (DWORD *)((BYTE *)rect.pBits + srcy * rect.Pitch); |
| 335 | UINT32 *dst = &avi_snap.pix32(srcy); |
| 336 | |
| 337 | for(int x = 0; x < snap_width; x++) |
| 338 | *dst++ = *src++; |
| 339 | } |
| 340 | |
| 341 | // unlock |
| 342 | result = (*d3dintf->surface.unlock_rect)(avi_copy_surface); |
| 343 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during texture unlock_rect call\n", (int)result); |
| 344 | } |
| 345 | |
| 346 | |
| 347 | |
| 348 | //============================================================ |
| 349 | // hlsl_render_snapshot |
| 350 | //============================================================ |
| 351 | |
| 352 | void shaders::render_snapshot(surface *surface) |
| 353 | { |
| 354 | if (!master_enable || !d3dintf->post_fx_available) |
| 355 | return; |
| 356 | |
| 357 | renderer *d3d = (renderer *)window->drawdata; |
| 358 | |
| 359 | D3DLOCKED_RECT rect; |
| 360 | |
| 361 | render_snap = false; |
| 362 | |
| 363 | // if we don't have a bitmap, or if it's not the right size, allocate a new one |
| 364 | if (!avi_snap.valid() || snap_width != (avi_snap.width() / 2) || snap_height != (avi_snap.height() / 2)) |
| 365 | { |
| 366 | avi_snap.allocate(snap_width / 2, snap_height / 2); |
| 367 | } |
| 368 | |
| 369 | // copy the texture |
| 370 | HRESULT result = (*d3dintf->device.get_render_target_data)(d3d->get_device(), surface, snap_copy_target); |
| 371 | if (result != D3D_OK) |
| 372 | { |
| 373 | return; |
| 374 | } |
| 375 | |
| 376 | // lock the texture |
| 377 | result = (*d3dintf->surface.lock_rect)(snap_copy_target, &rect, NULL, D3DLOCK_DISCARD); |
| 378 | if (result != D3D_OK) |
| 379 | { |
| 380 | return; |
| 381 | } |
| 382 | |
| 383 | for(int cy = 0; cy < 2; cy++) |
| 384 | { |
| 385 | for(int cx = 0; cx < 2; cx++) |
| 386 | { |
| 387 | // loop over Y |
| 388 | for (int srcy = 0; srcy < snap_height / 2; srcy++) |
| 389 | { |
| 390 | int toty = (srcy + cy * (snap_height / 2)); |
| 391 | int totx = cx * (snap_width / 2); |
| 392 | DWORD *src = (DWORD *)((BYTE *)rect.pBits + toty * rect.Pitch + totx * 4); |
| 393 | UINT32 *dst = &avi_snap.pix32(srcy); |
| 394 | |
| 395 | for(int x = 0; x < snap_width / 2; x++) |
| 396 | *dst++ = *src++; |
| 397 | } |
| 398 | |
| 399 | int idx = cy * 2 + cx; |
| 400 | |
| 401 | emu_file file(window->machine().options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); |
| 402 | file_error filerr = open_next(d3d, file, NULL, "png", idx); |
| 403 | if (filerr != FILERR_NONE) |
| 404 | return; |
| 405 | |
| 406 | // add two text entries describing the image |
| 407 | astring text1(emulator_info::get_appname(), " ", build_version); |
| 408 | astring text2(window->machine().system().manufacturer, " ", window->machine().system().description); |
| 409 | png_info pnginfo = { 0 }; |
| 410 | png_add_text(&pnginfo, "Software", text1); |
| 411 | png_add_text(&pnginfo, "System", text2); |
| 412 | |
| 413 | // now do the actual work |
| 414 | png_error error = png_write_bitmap(file, &pnginfo, avi_snap, 1 << 24, NULL); |
| 415 | if (error != PNGERR_NONE) |
| 416 | mame_printf_error("Error generating PNG for HLSL snapshot: png_error = %d\n", error); |
| 417 | |
| 418 | // free any data allocated |
| 419 | png_free(&pnginfo); |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | // unlock |
| 424 | result = (*d3dintf->surface.unlock_rect)(snap_copy_target); |
| 425 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during texture unlock_rect call\n", (int)result); |
| 426 | |
| 427 | if(snap_texture != NULL) |
| 428 | { |
| 429 | (*d3dintf->texture.release)(snap_texture); |
| 430 | snap_texture = NULL; |
| 431 | } |
| 432 | |
| 433 | if(snap_target != NULL) |
| 434 | { |
| 435 | (*d3dintf->surface.release)(snap_target); |
| 436 | snap_target = NULL; |
| 437 | } |
| 438 | |
| 439 | if(snap_copy_texture != NULL) |
| 440 | { |
| 441 | (*d3dintf->texture.release)(snap_copy_texture); |
| 442 | snap_copy_texture = NULL; |
| 443 | } |
| 444 | |
| 445 | if(snap_copy_target != NULL) |
| 446 | { |
| 447 | (*d3dintf->surface.release)(snap_copy_target); |
| 448 | snap_copy_target = NULL; |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | |
| 453 | //============================================================ |
| 454 | // shaders::record_texture |
| 455 | //============================================================ |
| 456 | |
| 457 | void shaders::record_texture() |
| 458 | { |
| 459 | if (!master_enable || !d3dintf->post_fx_available) |
| 460 | return; |
| 461 | |
| 462 | surface *surface = avi_final_target; |
| 463 | |
| 464 | // ignore if nothing to do |
| 465 | if (avi_output_file == NULL || surface == NULL) |
| 466 | return; |
| 467 | |
| 468 | // get the current time |
| 469 | attotime curtime = window->machine().time(); |
| 470 | |
| 471 | avi_update_snap(surface); |
| 472 | |
| 473 | // loop until we hit the right time |
| 474 | while (avi_next_frame_time <= curtime) |
| 475 | { |
| 476 | // handle an AVI recording |
| 477 | // write the next frame |
| 478 | avi_error avierr = avi_append_video_frame(avi_output_file, avi_snap); |
| 479 | if (avierr != AVIERR_NONE) |
| 480 | { |
| 481 | end_avi_recording(); |
| 482 | return; |
| 483 | } |
| 484 | |
| 485 | // advance time |
| 486 | avi_next_frame_time += avi_frame_period; |
| 487 | avi_frame++; |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | |
| 492 | //============================================================ |
| 493 | // shaders::end_hlsl_avi_recording |
| 494 | //============================================================ |
| 495 | |
| 496 | void shaders::end_avi_recording() |
| 497 | { |
| 498 | if (!master_enable || !d3dintf->post_fx_available) |
| 499 | return; |
| 500 | |
| 501 | if (avi_output_file != NULL) |
| 502 | avi_close(avi_output_file); |
| 503 | |
| 504 | avi_output_file = NULL; |
| 505 | avi_frame = 0; |
| 506 | } |
| 507 | |
| 508 | |
| 509 | //============================================================ |
| 510 | // shaders::set_texture |
| 511 | //============================================================ |
| 512 | |
| 513 | void shaders::toggle() |
| 514 | { |
| 515 | if (master_enable) |
| 516 | { |
| 517 | if (initialized) |
| 518 | { |
| 519 | delete_resources(false); |
| 520 | } |
| 521 | master_enable = !master_enable; |
| 522 | } |
| 523 | else |
| 524 | { |
| 525 | if (!initialized) |
| 526 | { |
| 527 | master_enable = !master_enable; |
| 528 | bool failed = create_resources(false); |
| 529 | if (failed) |
| 530 | { |
| 531 | master_enable = false; |
| 532 | } |
| 533 | } |
| 534 | else |
| 535 | { |
| 536 | master_enable = !master_enable; |
| 537 | } |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | //============================================================ |
| 542 | // shaders::begin_avi_recording |
| 543 | //============================================================ |
| 544 | |
| 545 | void shaders::begin_avi_recording(const char *name) |
| 546 | { |
| 547 | if (!master_enable || !d3dintf->post_fx_available) |
| 548 | return; |
| 549 | |
| 550 | renderer *d3d = (renderer *)window->drawdata; |
| 551 | |
| 552 | // stop any existing recording |
| 553 | end_avi_recording(); |
| 554 | |
| 555 | // reset the state |
| 556 | avi_frame = 0; |
| 557 | avi_next_frame_time = window->machine().time(); |
| 558 | |
| 559 | // build up information about this new movie |
| 560 | avi_movie_info info; |
| 561 | info.video_format = 0; |
| 562 | info.video_timescale = 1000 * ((window->machine().primary_screen != NULL) ? ATTOSECONDS_TO_HZ(window->machine().primary_screen->frame_period().attoseconds) : screen_device::DEFAULT_FRAME_RATE); |
| 563 | info.video_sampletime = 1000; |
| 564 | info.video_numsamples = 0; |
| 565 | info.video_width = snap_width; |
| 566 | info.video_height = snap_height; |
| 567 | info.video_depth = 24; |
| 568 | |
| 569 | info.audio_format = 0; |
| 570 | info.audio_timescale = window->machine().sample_rate(); |
| 571 | info.audio_sampletime = 1; |
| 572 | info.audio_numsamples = 0; |
| 573 | info.audio_channels = 2; |
| 574 | info.audio_samplebits = 16; |
| 575 | info.audio_samplerate = window->machine().sample_rate(); |
| 576 | |
| 577 | // create a new temporary movie file |
| 578 | file_error filerr; |
| 579 | astring fullpath; |
| 580 | { |
| 581 | emu_file tempfile(window->machine().options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); |
| 582 | if (name != NULL) |
| 583 | { |
| 584 | filerr = tempfile.open(name); |
| 585 | } |
| 586 | else |
| 587 | { |
| 588 | filerr = open_next(d3d, tempfile, NULL, "avi", 0); |
| 589 | } |
| 590 | |
| 591 | // compute the frame time |
| 592 | { |
| 593 | avi_frame_period = attotime::from_seconds(1000) / info.video_timescale; |
| 594 | } |
| 595 | |
| 596 | // if we succeeded, make a copy of the name and create the real file over top |
| 597 | if (filerr == FILERR_NONE) |
| 598 | { |
| 599 | fullpath = tempfile.fullpath(); |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | if (filerr == FILERR_NONE) |
| 604 | { |
| 605 | // create the file and free the string |
| 606 | avi_error avierr = avi_create(fullpath, &info, &avi_output_file); |
| 607 | if (avierr != AVIERR_NONE) |
| 608 | { |
| 609 | mame_printf_error("Error creating AVI: %s\n", avi_error_string(avierr)); |
| 610 | } |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | |
| 615 | //============================================================ |
| 616 | // remove_cache_target - remove an active cache target when |
| 617 | // refcount hits zero |
| 618 | //============================================================ |
| 619 | |
| 620 | void shaders::remove_cache_target(cache_target *cache) |
| 621 | { |
| 622 | if (cache != NULL) |
| 623 | { |
| 624 | if (cache == cachehead) |
| 625 | { |
| 626 | cachehead = cachehead->next; |
| 627 | } |
| 628 | |
| 629 | if (cache->prev != NULL) |
| 630 | { |
| 631 | cache->prev->next = cache->next; |
| 632 | } |
| 633 | |
| 634 | if (cache->next != NULL) |
| 635 | { |
| 636 | cache->next->prev = cache->prev; |
| 637 | } |
| 638 | |
| 639 | global_free(cache); |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | |
| 644 | //============================================================ |
| 645 | // remove_render_target - remove an active target |
| 646 | //============================================================ |
| 647 | |
| 648 | void shaders::remove_render_target(texture_info *texture) |
| 649 | { |
| 650 | remove_render_target(find_render_target(texture)); |
| 651 | } |
| 652 | |
| 653 | void shaders::remove_render_target(int width, int height, UINT32 screen_index, UINT32 page_index) |
| 654 | { |
| 655 | render_target *target = find_render_target(width, height, screen_index, page_index); |
| 656 | if (target != NULL) |
| 657 | { |
| 658 | remove_render_target(target); |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | void shaders::remove_render_target(render_target *rt) |
| 663 | { |
| 664 | if (rt != NULL) |
| 665 | { |
| 666 | if (rt == targethead) |
| 667 | { |
| 668 | targethead = targethead->next; |
| 669 | } |
| 670 | |
| 671 | if (rt->prev != NULL) |
| 672 | { |
| 673 | rt->prev->next = rt->next; |
| 674 | } |
| 675 | |
| 676 | if (rt->next != NULL) |
| 677 | { |
| 678 | rt->next->prev = rt->prev; |
| 679 | } |
| 680 | |
| 681 | cache_target *cache = find_cache_target(rt->screen_index, rt->width, rt->height); |
| 682 | if (cache != NULL) |
| 683 | { |
| 684 | remove_cache_target(cache); |
| 685 | } |
| 686 | |
| 687 | int screen_index = rt->screen_index; |
| 688 | int other_page = 1 - rt->page_index; |
| 689 | int width = rt->width; |
| 690 | int height = rt->height; |
| 691 | |
| 692 | global_free(rt); |
| 693 | |
| 694 | // Remove other double-buffered page (if it exists) |
| 695 | remove_render_target(width, height, screen_index, other_page); |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | |
| 700 | //============================================================ |
| 701 | // shaders::set_texture |
| 702 | //============================================================ |
| 703 | |
| 704 | void shaders::set_texture(texture_info *texture) |
| 705 | { |
| 706 | if (!master_enable || !d3dintf->post_fx_available) |
| 707 | return; |
| 708 | |
| 709 | renderer *d3d = (renderer *)window->drawdata; |
| 710 | |
| 711 | if(texture != NULL) |
| 712 | { |
| 713 | paused = texture->paused(); |
| 714 | texture->advance_frame(); |
| 715 | } |
| 716 | |
| 717 | texture_info *default_texture = d3d->get_default_texture(); |
| 718 | (*d3dintf->effect.set_texture)(default_effect, "Diffuse", (texture == NULL) ? default_texture->get_finaltex() : texture->get_finaltex()); |
| 719 | if (options->yiq_enable) |
| 720 | (*d3dintf->effect.set_texture)(yiq_encode_effect, "Diffuse", (texture == NULL) ? default_texture->get_finaltex() : texture->get_finaltex()); |
| 721 | else |
| 722 | (*d3dintf->effect.set_texture)(color_effect, "Diffuse", (texture == NULL) ? default_texture->get_finaltex() : texture->get_finaltex()); |
| 723 | (*d3dintf->effect.set_texture)(pincushion_effect, "Diffuse", (texture == NULL) ? default_texture->get_finaltex() : texture->get_finaltex()); |
| 724 | } |
| 725 | |
| 726 | |
| 727 | //============================================================ |
| 728 | // shaders::init |
| 729 | //============================================================ |
| 730 | |
| 731 | void shaders::init(base *d3dintf, win_window_info *window) |
| 732 | { |
| 733 | if (!d3dintf->post_fx_available) |
| 734 | return; |
| 735 | |
| 736 | this->d3dintf = d3dintf; |
| 737 | this->window = window; |
| 738 | |
| 739 | master_enable = downcast<windows_options &>(window->machine().options()).d3d_hlsl_enable(); |
| 740 | prescale_size_x = 1; |
| 741 | prescale_size_y = 1; |
| 742 | preset = downcast<windows_options &>(window->machine().options()).d3d_hlsl_preset(); |
| 743 | if (preset < -1 || preset > 3) |
| 744 | { |
| 745 | preset = -1; |
| 746 | } |
| 747 | |
| 748 | snap_width = downcast<windows_options &>(window->machine().options()).d3d_snap_width(); |
| 749 | snap_height = downcast<windows_options &>(window->machine().options()).d3d_snap_height(); |
| 750 | prescale_force_x = 0; |
| 751 | prescale_force_y = 0; |
| 752 | |
| 753 | windows_options &winoptions = downcast<windows_options &>(window->machine().options()); |
| 754 | |
| 755 | options = (hlsl_options*)global_alloc_clear(hlsl_options); |
| 756 | |
| 757 | options->params_dirty = true; |
| 758 | strcpy(options->shadow_mask_texture, downcast<windows_options &>(window->machine().options()).screen_shadow_mask_texture()); // unsafe |
| 759 | |
| 760 | write_ini = downcast<windows_options &>(window->machine().options()).hlsl_write_ini(); |
| 761 | read_ini = downcast<windows_options &>(window->machine().options()).hlsl_read_ini(); |
| 762 | |
| 763 | if(read_ini) |
| 764 | { |
| 765 | emu_file ini_file(downcast<windows_options &>(window->machine().options()).screen_post_fx_dir(), OPEN_FLAG_READ | OPEN_FLAG_CREATE_PATHS); |
| 766 | file_error filerr = open_next((renderer*)window->drawdata, ini_file, downcast<windows_options &>(window->machine().options()).hlsl_ini_name(), "ini", 0); |
| 767 | |
| 768 | read_ini = false; |
| 769 | if (filerr == FILERR_NONE) |
| 770 | { |
| 771 | ini_file.seek(0, SEEK_END); |
| 772 | if (ini_file.tell() >= 1000) |
| 773 | { |
| 774 | read_ini = true; |
| 775 | ini_file.seek(0, SEEK_SET); |
| 776 | |
| 777 | int en = 0; |
| 778 | char buf[1024]; |
| 779 | ini_file.gets(buf, 1024); |
| 780 | sscanf(buf, "hlsl_enable %d\n", &en); |
| 781 | master_enable = en == 1; |
| 782 | |
| 783 | ini_file.gets(buf, 1024); |
| 784 | sscanf(buf, "hlsl_prescale_x %d\n", &prescale_force_x); |
| 785 | |
| 786 | ini_file.gets(buf, 1024); |
| 787 | sscanf(buf, "hlsl_prescale_y %d\n", &prescale_force_y); |
| 788 | |
| 789 | ini_file.gets(buf, 1024); |
| 790 | sscanf(buf, "hlsl_preset %d\n", &preset); |
| 791 | |
| 792 | ini_file.gets(buf, 1024); |
| 793 | sscanf(buf, "hlsl_snap_width %d\n", &snap_width); |
| 794 | |
| 795 | ini_file.gets(buf, 1024); |
| 796 | sscanf(buf, "hlsl_snap_height %d\n", &snap_height); |
| 797 | |
| 798 | ini_file.gets(buf, 1024); |
| 799 | sscanf(buf, "shadow_mask_alpha %f\n", &options->shadow_mask_alpha); |
| 800 | |
| 801 | ini_file.gets(buf, 1024); |
| 802 | sscanf(buf, "shadow_mask_texture %s\n", options->shadow_mask_texture); |
| 803 | |
| 804 | ini_file.gets(buf, 1024); |
| 805 | sscanf(buf, "shadow_mask_x_count %d\n", &options->shadow_mask_count_x); |
| 806 | |
| 807 | ini_file.gets(buf, 1024); |
| 808 | sscanf(buf, "shadow_mask_y_count %d\n", &options->shadow_mask_count_y); |
| 809 | |
| 810 | ini_file.gets(buf, 1024); |
| 811 | sscanf(buf, "shadow_mask_usize %f\n", &options->shadow_mask_u_size); |
| 812 | |
| 813 | ini_file.gets(buf, 1024); |
| 814 | sscanf(buf, "shadow_mask_vsize %f\n", &options->shadow_mask_v_size); |
| 815 | |
| 816 | ini_file.gets(buf, 1024); |
| 817 | sscanf(buf, "curvature %f\n", &options->curvature); |
| 818 | |
| 819 | ini_file.gets(buf, 1024); |
| 820 | sscanf(buf, "pincushion %f\n", &options->pincushion); |
| 821 | |
| 822 | ini_file.gets(buf, 1024); |
| 823 | sscanf(buf, "scanline_alpha %f\n", &options->scanline_alpha); |
| 824 | |
| 825 | ini_file.gets(buf, 1024); |
| 826 | sscanf(buf, "scanline_size %f\n", &options->scanline_scale); |
| 827 | |
| 828 | ini_file.gets(buf, 1024); |
| 829 | sscanf(buf, "scanline_height %f\n", &options->scanline_height); |
| 830 | |
| 831 | ini_file.gets(buf, 1024); |
| 832 | sscanf(buf, "scanline_bright_scale %f\n", &options->scanline_bright_scale); |
| 833 | |
| 834 | ini_file.gets(buf, 1024); |
| 835 | sscanf(buf, "scanline_bright_offset %f\n", &options->scanline_bright_offset); |
| 836 | |
| 837 | ini_file.gets(buf, 1024); |
| 838 | sscanf(buf, "scanline_jitter %f\n", &options->scanline_offset); |
| 839 | |
| 840 | ini_file.gets(buf, 1024); |
| 841 | for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' '; |
| 842 | sscanf(buf, "defocus %f %f\n", &options->defocus[0], &options->defocus[1]); |
| 843 | |
| 844 | ini_file.gets(buf, 1024); |
| 845 | for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' '; |
| 846 | sscanf(buf, "converge_x %f %f %f\n", &options->converge_x[0], &options->converge_x[1], &options->converge_x[2]); |
| 847 | |
| 848 | ini_file.gets(buf, 1024); |
| 849 | for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' '; |
| 850 | sscanf(buf, "converge_y %f %f %f\n", &options->converge_y[0], &options->converge_y[1], &options->converge_y[2]); |
| 851 | |
| 852 | ini_file.gets(buf, 1024); |
| 853 | for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' '; |
| 854 | sscanf(buf, "radial_converge_x %f %f %f\n", &options->radial_converge_x[0], &options->radial_converge_x[1], &options->radial_converge_x[2]); |
| 855 | |
| 856 | ini_file.gets(buf, 1024); |
| 857 | for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' '; |
| 858 | sscanf(buf, "radial_converge_y %f %f %f\n", &options->radial_converge_y[0], &options->radial_converge_y[1], &options->radial_converge_y[2]); |
| 859 | |
| 860 | ini_file.gets(buf, 1024); |
| 861 | for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' '; |
| 862 | sscanf(buf, "red_ratio %f %f %f\n", &options->red_ratio[0], &options->red_ratio[1], &options->red_ratio[2]); |
| 863 | |
| 864 | ini_file.gets(buf, 1024); |
| 865 | for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' '; |
| 866 | sscanf(buf, "grn_ratio %f %f %f\n", &options->grn_ratio[0], &options->grn_ratio[1], &options->grn_ratio[2]); |
| 867 | |
| 868 | ini_file.gets(buf, 1024); |
| 869 | for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' '; |
| 870 | sscanf(buf, "blu_ratio %f %f %f\n", &options->blu_ratio[0], &options->blu_ratio[1], &options->blu_ratio[2]); |
| 871 | |
| 872 | ini_file.gets(buf, 1024); |
| 873 | sscanf(buf, "saturation %f\n", &options->saturation); |
| 874 | |
| 875 | ini_file.gets(buf, 1024); |
| 876 | for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' '; |
| 877 | sscanf(buf, "offset %f %f %f\n", &options->offset[0], &options->offset[1], &options->offset[2]); |
| 878 | |
| 879 | ini_file.gets(buf, 1024); |
| 880 | for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' '; |
| 881 | sscanf(buf, "scale %f %f %f\n", &options->scale[0], &options->scale[1], &options->scale[2]); |
| 882 | |
| 883 | ini_file.gets(buf, 1024); |
| 884 | for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' '; |
| 885 | sscanf(buf, "power %f %f %f\n", &options->power[0], &options->power[1], &options->power[2]); |
| 886 | |
| 887 | ini_file.gets(buf, 1024); |
| 888 | for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' '; |
| 889 | sscanf(buf, "floor %f %f %f\n", &options->floor[0], &options->floor[1], &options->floor[2]); |
| 890 | |
| 891 | ini_file.gets(buf, 1024); |
| 892 | for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' '; |
| 893 | sscanf(buf, "phosphor_life %f %f %f\n", &options->phosphor[0], &options->phosphor[1], &options->phosphor[2]); |
| 894 | |
| 895 | ini_file.gets(buf, 1024); |
| 896 | sscanf(buf, "yiq_enable %d\n", &en); |
| 897 | options->yiq_enable = en == 1; |
| 898 | |
| 899 | ini_file.gets(buf, 1024); |
| 900 | sscanf(buf, "yiq_cc %f\n", &options->yiq_cc); |
| 901 | |
| 902 | ini_file.gets(buf, 1024); |
| 903 | sscanf(buf, "yiq_a %f\n", &options->yiq_a); |
| 904 | |
| 905 | ini_file.gets(buf, 1024); |
| 906 | sscanf(buf, "yiq_b %f\n", &options->yiq_b); |
| 907 | |
| 908 | ini_file.gets(buf, 1024); |
| 909 | sscanf(buf, "yiq_o %f\n", &options->yiq_o); |
| 910 | |
| 911 | ini_file.gets(buf, 1024); |
| 912 | sscanf(buf, "yiq_p %f\n", &options->yiq_p); |
| 913 | |
| 914 | ini_file.gets(buf, 1024); |
| 915 | sscanf(buf, "yiq_n %f\n", &options->yiq_n); |
| 916 | |
| 917 | ini_file.gets(buf, 1024); |
| 918 | sscanf(buf, "yiq_y %f\n", &options->yiq_y); |
| 919 | |
| 920 | ini_file.gets(buf, 1024); |
| 921 | sscanf(buf, "yiq_i %f\n", &options->yiq_i); |
| 922 | |
| 923 | ini_file.gets(buf, 1024); |
| 924 | sscanf(buf, "yiq_q %f\n", &options->yiq_q); |
| 925 | |
| 926 | ini_file.gets(buf, 1024); |
| 927 | sscanf(buf, "yiq_scan_time %f\n", &options->yiq_scan_time); |
| 928 | |
| 929 | ini_file.gets(buf, 1024); |
| 930 | sscanf(buf, "yiq_phase_count %d\n", &options->yiq_phase_count); |
| 931 | |
| 932 | ini_file.gets(buf, 1024); |
| 933 | sscanf(buf, "vector_length_scale %f\n", &options->vector_length_scale); |
| 934 | |
| 935 | ini_file.gets(buf, 1024); |
| 936 | sscanf(buf, "vector_length_ratio %f\n", &options->vector_length_ratio); |
| 937 | } |
| 938 | } |
| 939 | } |
| 940 | else |
| 941 | { |
| 942 | prescale_force_x = winoptions.d3d_hlsl_prescale_x(); |
| 943 | prescale_force_y = winoptions.d3d_hlsl_prescale_y(); |
| 944 | if(preset == -1) |
| 945 | { |
| 946 | options->shadow_mask_alpha = winoptions.screen_shadow_mask_alpha(); |
| 947 | options->shadow_mask_count_x = winoptions.screen_shadow_mask_count_x(); |
| 948 | options->shadow_mask_count_y = winoptions.screen_shadow_mask_count_y(); |
| 949 | options->shadow_mask_u_size = winoptions.screen_shadow_mask_u_size(); |
| 950 | options->shadow_mask_v_size = winoptions.screen_shadow_mask_v_size(); |
| 951 | options->curvature = winoptions.screen_curvature(); |
| 952 | options->pincushion = winoptions.screen_pincushion(); |
| 953 | options->scanline_alpha = winoptions.screen_scanline_amount(); |
| 954 | options->scanline_scale = winoptions.screen_scanline_scale(); |
| 955 | options->scanline_height = winoptions.screen_scanline_height(); |
| 956 | options->scanline_bright_scale = winoptions.screen_scanline_bright_scale(); |
| 957 | options->scanline_bright_offset = winoptions.screen_scanline_bright_offset(); |
| 958 | options->scanline_offset = winoptions.screen_scanline_offset(); |
| 959 | get_vector(winoptions.screen_defocus(), 2, options->defocus, TRUE); |
| 960 | get_vector(winoptions.screen_converge_x(), 3, options->converge_x, TRUE); |
| 961 | get_vector(winoptions.screen_converge_y(), 3, options->converge_y, TRUE); |
| 962 | get_vector(winoptions.screen_radial_converge_x(), 3, options->radial_converge_x, TRUE); |
| 963 | get_vector(winoptions.screen_radial_converge_y(), 3, options->radial_converge_y, TRUE); |
| 964 | get_vector(winoptions.screen_red_ratio(), 3, options->red_ratio, TRUE); |
| 965 | get_vector(winoptions.screen_grn_ratio(), 3, options->grn_ratio, TRUE); |
| 966 | get_vector(winoptions.screen_blu_ratio(), 3, options->blu_ratio, TRUE); |
| 967 | get_vector(winoptions.screen_offset(), 3, options->offset, TRUE); |
| 968 | get_vector(winoptions.screen_scale(), 3, options->scale, TRUE); |
| 969 | get_vector(winoptions.screen_power(), 3, options->power, TRUE); |
| 970 | get_vector(winoptions.screen_floor(), 3, options->floor, TRUE); |
| 971 | get_vector(winoptions.screen_phosphor(), 3, options->phosphor, TRUE); |
| 972 | options->saturation = winoptions.screen_saturation(); |
| 973 | } |
| 974 | else |
| 975 | { |
| 976 | options = &s_hlsl_presets[preset]; |
| 977 | } |
| 978 | |
| 979 | options->yiq_enable = winoptions.screen_yiq_enable(); |
| 980 | options->yiq_cc = winoptions.screen_yiq_cc(); |
| 981 | options->yiq_a = winoptions.screen_yiq_a(); |
| 982 | options->yiq_b = winoptions.screen_yiq_b(); |
| 983 | options->yiq_o = winoptions.screen_yiq_o(); |
| 984 | options->yiq_p = winoptions.screen_yiq_p(); |
| 985 | options->yiq_n = winoptions.screen_yiq_n(); |
| 986 | options->yiq_y = winoptions.screen_yiq_y(); |
| 987 | options->yiq_i = winoptions.screen_yiq_i(); |
| 988 | options->yiq_q = winoptions.screen_yiq_q(); |
| 989 | options->yiq_scan_time = winoptions.screen_yiq_scan_time(); |
| 990 | options->yiq_phase_count = winoptions.screen_yiq_phase_count(); |
| 991 | options->vector_length_scale = winoptions.screen_vector_length_scale(); |
| 992 | options->vector_length_ratio = winoptions.screen_vector_length_ratio(); |
| 993 | options->vector_bloom_scale = winoptions.screen_vector_bloom_scale(); |
| 994 | options->raster_bloom_scale = winoptions.screen_raster_bloom_scale(); |
| 995 | options->bloom_level0_weight = winoptions.screen_bloom_lvl0_weight(); |
| 996 | options->bloom_level1_weight = winoptions.screen_bloom_lvl1_weight(); |
| 997 | options->bloom_level2_weight = winoptions.screen_bloom_lvl2_weight(); |
| 998 | options->bloom_level3_weight = winoptions.screen_bloom_lvl3_weight(); |
| 999 | options->bloom_level4_weight = winoptions.screen_bloom_lvl4_weight(); |
| 1000 | options->bloom_level5_weight = winoptions.screen_bloom_lvl5_weight(); |
| 1001 | options->bloom_level6_weight = winoptions.screen_bloom_lvl6_weight(); |
| 1002 | options->bloom_level7_weight = winoptions.screen_bloom_lvl7_weight(); |
| 1003 | options->bloom_level8_weight = winoptions.screen_bloom_lvl8_weight(); |
| 1004 | options->bloom_level9_weight = winoptions.screen_bloom_lvl9_weight(); |
| 1005 | options->bloom_level10_weight = winoptions.screen_bloom_lvl10_weight(); |
| 1006 | } |
| 1007 | |
| 1008 | options->params_dirty = true; |
| 1009 | // experimental: load a PNG to use for vector rendering; it is treated |
| 1010 | // as a brightness map |
| 1011 | emu_file file(window->machine().options().art_path(), OPEN_FLAG_READ); |
| 1012 | |
| 1013 | render_load_png(shadow_bitmap, file, NULL, options->shadow_mask_texture); |
| 1014 | |
| 1015 | g_slider_list = init_slider_list(); |
| 1016 | } |
| 1017 | |
| 1018 | |
| 1019 | |
| 1020 | //============================================================ |
| 1021 | // shaders::init_fsfx_quad |
| 1022 | //============================================================ |
| 1023 | |
| 1024 | void shaders::init_fsfx_quad(void *vertbuf) |
| 1025 | { |
| 1026 | // Called at the start of each frame by the D3D code in order to reserve two triangles |
| 1027 | // that are guaranteed to be at a fixed position so as to simply use D3DPT_TRIANGLELIST, 0, 2 |
| 1028 | // instead of having to do bookkeeping about a specific screen quad |
| 1029 | if (!master_enable || !d3dintf->post_fx_available) |
| 1030 | return; |
| 1031 | |
| 1032 | renderer *d3d = (renderer *)window->drawdata; |
| 1033 | |
| 1034 | // get a pointer to the vertex buffer |
| 1035 | fsfx_vertices = (vertex *)vertbuf; |
| 1036 | if (fsfx_vertices == NULL) |
| 1037 | return; |
| 1038 | |
| 1039 | // fill in the vertexes clockwise |
| 1040 | fsfx_vertices[0].x = 0.0f; |
| 1041 | fsfx_vertices[0].y = 0.0f; |
| 1042 | fsfx_vertices[1].x = d3d->get_width(); |
| 1043 | fsfx_vertices[1].y = 0.0f; |
| 1044 | fsfx_vertices[2].x = 0.0f; |
| 1045 | fsfx_vertices[2].y = d3d->get_height(); |
| 1046 | fsfx_vertices[3].x = d3d->get_width(); |
| 1047 | fsfx_vertices[3].y = 0.0f; |
| 1048 | fsfx_vertices[4].x = 0.0f; |
| 1049 | fsfx_vertices[4].y = d3d->get_height(); |
| 1050 | fsfx_vertices[5].x = d3d->get_width(); |
| 1051 | fsfx_vertices[5].y = d3d->get_height(); |
| 1052 | |
| 1053 | fsfx_vertices[0].u0 = 0.0f; |
| 1054 | fsfx_vertices[0].v0 = 0.0f; |
| 1055 | |
| 1056 | fsfx_vertices[1].u0 = 1.0f; |
| 1057 | fsfx_vertices[1].v0 = 0.0f; |
| 1058 | |
| 1059 | fsfx_vertices[2].u0 = 0.0f; |
| 1060 | fsfx_vertices[2].v0 = 1.0f; |
| 1061 | |
| 1062 | fsfx_vertices[3].u0 = 1.0f; |
| 1063 | fsfx_vertices[3].v0 = 0.0f; |
| 1064 | |
| 1065 | fsfx_vertices[4].u0 = 0.0f; |
| 1066 | fsfx_vertices[4].v0 = 1.0f; |
| 1067 | |
| 1068 | fsfx_vertices[5].u0 = 1.0f; |
| 1069 | fsfx_vertices[5].v0 = 1.0f; |
| 1070 | |
| 1071 | fsfx_vertices[0].u1 = 0.0f; |
| 1072 | fsfx_vertices[0].v1 = 0.0f; |
| 1073 | fsfx_vertices[1].u1 = 0.0f; |
| 1074 | fsfx_vertices[1].v1 = 0.0f; |
| 1075 | fsfx_vertices[2].u1 = 0.0f; |
| 1076 | fsfx_vertices[2].v1 = 0.0f; |
| 1077 | fsfx_vertices[3].u1 = 0.0f; |
| 1078 | fsfx_vertices[3].v1 = 0.0f; |
| 1079 | fsfx_vertices[4].u1 = 0.0f; |
| 1080 | fsfx_vertices[4].v1 = 0.0f; |
| 1081 | fsfx_vertices[5].u1 = 0.0f; |
| 1082 | fsfx_vertices[5].v1 = 0.0f; |
| 1083 | |
| 1084 | // set the color, Z parameters to standard values |
| 1085 | for (int i = 0; i < 6; i++) |
| 1086 | { |
| 1087 | fsfx_vertices[i].z = 0.0f; |
| 1088 | fsfx_vertices[i].rhw = 1.0f; |
| 1089 | fsfx_vertices[i].color = D3DCOLOR_ARGB(255, 255, 255, 255); |
| 1090 | } |
| 1091 | } |
| 1092 | |
| 1093 | |
| 1094 | |
| 1095 | //============================================================ |
| 1096 | // shaders::create_resources |
| 1097 | //============================================================ |
| 1098 | |
| 1099 | int shaders::create_resources(bool reset) |
| 1100 | { |
| 1101 | if (!master_enable || !d3dintf->post_fx_available) |
| 1102 | return 0; |
| 1103 | |
| 1104 | renderer *d3d = (renderer *)window->drawdata; |
| 1105 | |
| 1106 | HRESULT result = (*d3dintf->device.get_render_target)(d3d->get_device(), 0, &backbuffer); |
| 1107 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device get_render_target call\n", (int)result); |
| 1108 | |
| 1109 | result = (*d3dintf->device.create_texture)(d3d->get_device(), 4, 4, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &black_texture); |
| 1110 | if (result != D3D_OK) |
| 1111 | { |
| 1112 | mame_printf_verbose("Direct3D: Unable to init video-memory target for black texture (%08x)\n", (UINT32)result); |
| 1113 | return 1; |
| 1114 | } |
| 1115 | (*d3dintf->texture.get_surface_level)(black_texture, 0, &black_surface); |
| 1116 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, black_surface); |
| 1117 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 1118 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1119 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 1120 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, backbuffer); |
| 1121 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 1122 | |
| 1123 | result = (*d3dintf->device.create_texture)(d3d->get_device(), (int)snap_width, (int)snap_height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &avi_copy_texture); |
| 1124 | if (result != D3D_OK) |
| 1125 | { |
| 1126 | mame_printf_verbose("Direct3D: Unable to init system-memory target for HLSL AVI dumping (%08x)\n", (UINT32)result); |
| 1127 | return 1; |
| 1128 | } |
| 1129 | (*d3dintf->texture.get_surface_level)(avi_copy_texture, 0, &avi_copy_surface); |
| 1130 | |
| 1131 | result = (*d3dintf->device.create_texture)(d3d->get_device(), (int)snap_width, (int)snap_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &avi_final_texture); |
| 1132 | if (result != D3D_OK) |
| 1133 | { |
| 1134 | mame_printf_verbose("Direct3D: Unable to init video-memory target for HLSL AVI dumping (%08x)\n", (UINT32)result); |
| 1135 | return 1; |
| 1136 | } |
| 1137 | (*d3dintf->texture.get_surface_level)(avi_final_texture, 0, &avi_final_target); |
| 1138 | |
| 1139 | // experimental: if we have a shadow bitmap, create a texture for it |
| 1140 | if (shadow_bitmap.valid()) |
| 1141 | { |
| 1142 | render_texinfo texture; |
| 1143 | |
| 1144 | // fake in the basic data so it looks like it came from render.c |
| 1145 | texture.base = shadow_bitmap.raw_pixptr(0); |
| 1146 | texture.rowpixels = shadow_bitmap.rowpixels(); |
| 1147 | texture.width = shadow_bitmap.width(); |
| 1148 | texture.height = shadow_bitmap.height(); |
| 1149 | texture.palette = NULL; |
| 1150 | texture.seqid = 0; |
| 1151 | |
| 1152 | // now create it |
| 1153 | shadow_texture = new texture_info(d3d->get_texture_manager(), &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32)); |
| 1154 | } |
| 1155 | |
| 1156 | const char *fx_dir = downcast<windows_options &>(window->machine().options()).screen_post_fx_dir(); |
| 1157 | |
| 1158 | // Replace all this garbage with a proper data-driven system |
| 1159 | char primary_name_cstr[1024]; |
| 1160 | sprintf(primary_name_cstr, "%s\\primary.fx", fx_dir); |
| 1161 | TCHAR *primary_name = tstring_from_utf8(primary_name_cstr); |
| 1162 | |
| 1163 | char post_name_cstr[1024]; |
| 1164 | sprintf(post_name_cstr, "%s\\post.fx", fx_dir); |
| 1165 | TCHAR *post_name = tstring_from_utf8(post_name_cstr); |
| 1166 | |
| 1167 | char prescale_name_cstr[1024]; |
| 1168 | sprintf(prescale_name_cstr, "%s\\prescale.fx", fx_dir); |
| 1169 | TCHAR *prescale_name = tstring_from_utf8(prescale_name_cstr); |
| 1170 | |
| 1171 | char pincushion_name_cstr[1024]; |
| 1172 | sprintf(pincushion_name_cstr, "%s\\pincushion.fx", fx_dir); |
| 1173 | TCHAR *pincushion_name = tstring_from_utf8(pincushion_name_cstr); |
| 1174 | |
| 1175 | char phosphor_name_cstr[1024]; |
| 1176 | sprintf(phosphor_name_cstr, "%s\\phosphor.fx", fx_dir); |
| 1177 | TCHAR *phosphor_name = tstring_from_utf8(phosphor_name_cstr); |
| 1178 | |
| 1179 | char focus_name_cstr[1024]; |
| 1180 | sprintf(focus_name_cstr, "%s\\focus.fx", fx_dir); |
| 1181 | TCHAR *focus_name = tstring_from_utf8(focus_name_cstr); |
| 1182 | |
| 1183 | char deconverge_name_cstr[1024]; |
| 1184 | sprintf(deconverge_name_cstr, "%s\\deconverge.fx", fx_dir); |
| 1185 | TCHAR *deconverge_name = tstring_from_utf8(deconverge_name_cstr); |
| 1186 | |
| 1187 | char color_name_cstr[1024]; |
| 1188 | sprintf(color_name_cstr, "%s\\color.fx", fx_dir); |
| 1189 | TCHAR *color_name = tstring_from_utf8(color_name_cstr); |
| 1190 | |
| 1191 | char yiq_encode_name_cstr[1024]; |
| 1192 | sprintf(yiq_encode_name_cstr, "%s\\yiq_encode.fx", fx_dir); |
| 1193 | TCHAR *yiq_encode_name = tstring_from_utf8(yiq_encode_name_cstr); |
| 1194 | |
| 1195 | char yiq_decode_name_cstr[1024]; |
| 1196 | sprintf(yiq_decode_name_cstr, "%s\\yiq_decode.fx", fx_dir); |
| 1197 | TCHAR *yiq_decode_name = tstring_from_utf8(yiq_decode_name_cstr); |
| 1198 | |
| 1199 | // create the regular shader |
| 1200 | result = (*d3dintf->device.create_effect)(d3d->get_device(), primary_name, &default_effect); |
| 1201 | if(result != D3D_OK) |
| 1202 | { |
| 1203 | mame_printf_verbose("Direct3D: Unable to load primary.fx\n"); |
| 1204 | return 1; |
| 1205 | } |
| 1206 | |
| 1207 | // create the post-processing shader |
| 1208 | result = (*d3dintf->device.create_effect)(d3d->get_device(), post_name, &post_effect); |
| 1209 | if(result != D3D_OK) |
| 1210 | { |
| 1211 | mame_printf_verbose("Direct3D: Unable to load post.fx\n"); |
| 1212 | return 1; |
| 1213 | } |
| 1214 | |
| 1215 | // create the prescaling shader |
| 1216 | result = (*d3dintf->device.create_effect)(d3d->get_device(), prescale_name, &prescale_effect); |
| 1217 | if(result != D3D_OK) |
| 1218 | { |
| 1219 | mame_printf_verbose("Direct3D: Unable to load prescale.fx\n"); |
| 1220 | return 1; |
| 1221 | } |
| 1222 | |
| 1223 | // create the pincushion shader |
| 1224 | result = (*d3dintf->device.create_effect)(d3d->get_device(), pincushion_name, &pincushion_effect); |
| 1225 | if(result != D3D_OK) |
| 1226 | { |
| 1227 | mame_printf_verbose("Direct3D: Unable to load pincushion.fx\n"); |
| 1228 | return 1; |
| 1229 | } |
| 1230 | |
| 1231 | // create the phosphor shader |
| 1232 | result = (*d3dintf->device.create_effect)(d3d->get_device(), phosphor_name, &phosphor_effect); |
| 1233 | if(result != D3D_OK) |
| 1234 | { |
| 1235 | mame_printf_verbose("Direct3D: Unable to load phosphor.fx\n"); |
| 1236 | return 1; |
| 1237 | } |
| 1238 | |
| 1239 | // create the focus shader |
| 1240 | result = (*d3dintf->device.create_effect)(d3d->get_device(), focus_name, &focus_effect); |
| 1241 | if(result != D3D_OK) |
| 1242 | { |
| 1243 | mame_printf_verbose("Direct3D: Unable to load focus.fx\n"); |
| 1244 | return 1; |
| 1245 | } |
| 1246 | |
| 1247 | // create the deconvergence shader |
| 1248 | result = (*d3dintf->device.create_effect)(d3d->get_device(), deconverge_name, &deconverge_effect); |
| 1249 | if(result != D3D_OK) |
| 1250 | { |
| 1251 | mame_printf_verbose("Direct3D: Unable to load deconverge.fx\n"); |
| 1252 | return 1; |
| 1253 | } |
| 1254 | |
| 1255 | // create the color convolution shader |
| 1256 | result = (*d3dintf->device.create_effect)(d3d->get_device(), color_name, &color_effect); |
| 1257 | if(result != D3D_OK) |
| 1258 | { |
| 1259 | mame_printf_verbose("Direct3D: Unable to load color.fx\n"); |
| 1260 | return 1; |
| 1261 | } |
| 1262 | |
| 1263 | // create the YIQ modulation shader |
| 1264 | result = (*d3dintf->device.create_effect)(d3d->get_device(), yiq_encode_name, &yiq_encode_effect); |
| 1265 | if(result != D3D_OK) |
| 1266 | { |
| 1267 | mame_printf_verbose("Direct3D: Unable to load yiq_encode.fx\n"); |
| 1268 | return 1; |
| 1269 | } |
| 1270 | |
| 1271 | // create the YIQ demodulation shader |
| 1272 | result = (*d3dintf->device.create_effect)(d3d->get_device(), yiq_decode_name, &yiq_decode_effect); |
| 1273 | if(result != D3D_OK) |
| 1274 | { |
| 1275 | mame_printf_verbose("Direct3D: Unable to load yiq_decode.fx\n"); |
| 1276 | return 1; |
| 1277 | } |
| 1278 | |
| 1279 | #if HLSL_VECTOR || CRT_BLOOM |
| 1280 | char bloom_cstr[1024]; |
| 1281 | sprintf(bloom_cstr, "%s\\bloom.fx", fx_dir); |
| 1282 | TCHAR *bloom_name = tstring_from_utf8(bloom_cstr); |
| 1283 | |
| 1284 | result = (*d3dintf->device.create_effect)(d3d->get_device(), bloom_name, &bloom_effect); |
| 1285 | if(result != D3D_OK) |
| 1286 | { |
| 1287 | mame_printf_verbose("Direct3D: Unable to load bloom.fx\n"); |
| 1288 | return 1; |
| 1289 | } |
| 1290 | if (bloom_name) |
| 1291 | osd_free(bloom_name); |
| 1292 | |
| 1293 | char downsample_cstr[1024]; |
| 1294 | sprintf(downsample_cstr, "%s\\downsample.fx", fx_dir); |
| 1295 | TCHAR *downsample_name = tstring_from_utf8(downsample_cstr); |
| 1296 | |
| 1297 | result = (*d3dintf->device.create_effect)(d3d->get_device(), downsample_name, &downsample_effect); |
| 1298 | if(result != D3D_OK) |
| 1299 | { |
| 1300 | mame_printf_verbose("Direct3D: Unable to load downsample.fx\n"); |
| 1301 | return 1; |
| 1302 | } |
| 1303 | if (downsample_name) |
| 1304 | osd_free(downsample_name); |
| 1305 | #endif |
| 1306 | #if HLSL_VECTOR |
| 1307 | // create the vector shader |
| 1308 | char vector_cstr[1024]; |
| 1309 | sprintf(vector_cstr, "%s\\vector.fx", fx_dir); |
| 1310 | TCHAR *vector_name = tstring_from_utf8(vector_cstr); |
| 1311 | |
| 1312 | result = (*d3dintf->device.create_effect)(d3d->get_device(), vector_name, &vector_effect); |
| 1313 | if(result != D3D_OK) |
| 1314 | { |
| 1315 | mame_printf_verbose("Direct3D: Unable to load vector.fx\n"); |
| 1316 | return 1; |
| 1317 | } |
| 1318 | if (vector_name) |
| 1319 | osd_free(vector_name); |
| 1320 | #endif |
| 1321 | |
| 1322 | if (primary_name) |
| 1323 | osd_free(primary_name); |
| 1324 | if (post_name) |
| 1325 | osd_free(post_name); |
| 1326 | if (prescale_name) |
| 1327 | osd_free(prescale_name); |
| 1328 | if (pincushion_name) |
| 1329 | osd_free(pincushion_name); |
| 1330 | if (phosphor_name) |
| 1331 | osd_free(phosphor_name); |
| 1332 | if (focus_name) |
| 1333 | osd_free(focus_name); |
| 1334 | if (deconverge_name) |
| 1335 | osd_free(deconverge_name); |
| 1336 | if (color_name) |
| 1337 | osd_free(color_name); |
| 1338 | if (yiq_encode_name) |
| 1339 | osd_free(yiq_encode_name); |
| 1340 | if (yiq_decode_name) |
| 1341 | osd_free(yiq_decode_name); |
| 1342 | |
| 1343 | initialized = true; |
| 1344 | |
| 1345 | return 0; |
| 1346 | } |
| 1347 | |
| 1348 | |
| 1349 | //============================================================ |
| 1350 | // shaders::begin_draw |
| 1351 | //============================================================ |
| 1352 | |
| 1353 | void shaders::begin_draw() |
| 1354 | { |
| 1355 | if (!master_enable || !d3dintf->post_fx_available) |
| 1356 | return; |
| 1357 | |
| 1358 | renderer *d3d = (renderer *)window->drawdata; |
| 1359 | |
| 1360 | curr_effect = default_effect; |
| 1361 | |
| 1362 | (*d3dintf->effect.set_technique)(default_effect, "TestTechnique"); |
| 1363 | (*d3dintf->effect.set_technique)(post_effect, "ScanMaskTechnique"); |
| 1364 | (*d3dintf->effect.set_technique)(pincushion_effect, "TestTechnique"); |
| 1365 | (*d3dintf->effect.set_technique)(phosphor_effect, "TestTechnique"); |
| 1366 | (*d3dintf->effect.set_technique)(focus_effect, "TestTechnique"); |
| 1367 | (*d3dintf->effect.set_technique)(deconverge_effect, "DeconvergeTechnique"); |
| 1368 | (*d3dintf->effect.set_technique)(color_effect, "ColorTechnique"); |
| 1369 | (*d3dintf->effect.set_technique)(yiq_encode_effect, "EncodeTechnique"); |
| 1370 | (*d3dintf->effect.set_technique)(yiq_decode_effect, "DecodeTechnique"); |
| 1371 | |
| 1372 | HRESULT result = (*d3dintf->device.get_render_target)(d3d->get_device(), 0, &backbuffer); |
| 1373 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device get_render_target call\n", (int)result); |
| 1374 | } |
| 1375 | |
| 1376 | |
| 1377 | //============================================================ |
| 1378 | // shaders::begin_frame |
| 1379 | //============================================================ |
| 1380 | |
| 1381 | void shaders::begin_frame() |
| 1382 | { |
| 1383 | record_texture(); |
| 1384 | } |
| 1385 | |
| 1386 | |
| 1387 | //============================================================ |
| 1388 | // shaders::blit |
| 1389 | //============================================================ |
| 1390 | |
| 1391 | void shaders::blit(surface *dst, texture *src, surface *new_dst, D3DPRIMITIVETYPE prim_type, |
| 1392 | UINT32 prim_index, UINT32 prim_count, int dstw, int dsth) |
| 1393 | { |
| 1394 | renderer *d3d = (renderer *)window->drawdata; |
| 1395 | |
| 1396 | HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, dst); |
| 1397 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 1398 | |
| 1399 | curr_effect = default_effect; |
| 1400 | |
| 1401 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", src); |
| 1402 | |
| 1403 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)dstw); |
| 1404 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)dsth); |
| 1405 | (*d3dintf->effect.set_float)(curr_effect, "PostPass", 1.0f); |
| 1406 | (*d3dintf->effect.set_float)(curr_effect, "PincushionAmount", options->pincushion); |
| 1407 | (*d3dintf->effect.set_float)(curr_effect, "Brighten", 0.0f); |
| 1408 | |
| 1409 | unsigned int num_passes = 0; |
| 1410 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 1411 | |
| 1412 | for (UINT pass = 0; pass < num_passes; pass++) |
| 1413 | { |
| 1414 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 1415 | // add the primitives |
| 1416 | HRESULT result = (*d3dintf->device.draw_primitive)(d3d->get_device(), prim_type, prim_index, prim_count); |
| 1417 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 1418 | (*d3dintf->effect.end_pass)(curr_effect); |
| 1419 | } |
| 1420 | |
| 1421 | (*d3dintf->effect.end)(curr_effect); |
| 1422 | |
| 1423 | if (new_dst) |
| 1424 | { |
| 1425 | HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, new_dst); |
| 1426 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 1427 | } |
| 1428 | } |
| 1429 | |
| 1430 | |
| 1431 | |
| 1432 | //============================================================ |
| 1433 | // shaders::blit |
| 1434 | //============================================================ |
| 1435 | |
| 1436 | void shaders::blit(surface *dst, texture *src, surface *new_dst, D3DPRIMITIVETYPE prim_type, |
| 1437 | UINT32 prim_index, UINT32 prim_count) |
| 1438 | { |
| 1439 | renderer *d3d = (renderer *)window->drawdata; |
| 1440 | |
| 1441 | HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, dst); |
| 1442 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 1443 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(1,0,0,0), 0, 0); |
| 1444 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 1445 | |
| 1446 | curr_effect = default_effect; |
| 1447 | |
| 1448 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", src); |
| 1449 | |
| 1450 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 1451 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 1452 | (*d3dintf->effect.set_float)(curr_effect, "ScreenWidth", (float)d3d->get_width()); |
| 1453 | (*d3dintf->effect.set_float)(curr_effect, "ScreenHeight", (float)d3d->get_height()); |
| 1454 | (*d3dintf->effect.set_float)(curr_effect, "PostPass", 1.0f); |
| 1455 | (*d3dintf->effect.set_float)(curr_effect, "PincushionAmount", options->pincushion); |
| 1456 | (*d3dintf->effect.set_float)(curr_effect, "Brighten", 1.0f); |
| 1457 | |
| 1458 | unsigned int num_passes = 0; |
| 1459 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 1460 | |
| 1461 | for (UINT pass = 0; pass < num_passes; pass++) |
| 1462 | { |
| 1463 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 1464 | // add the primitives |
| 1465 | HRESULT result = (*d3dintf->device.draw_primitive)(d3d->get_device(), prim_type, prim_index, prim_count); |
| 1466 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 1467 | (*d3dintf->effect.end_pass)(curr_effect); |
| 1468 | } |
| 1469 | |
| 1470 | (*d3dintf->effect.end)(curr_effect); |
| 1471 | |
| 1472 | (*d3dintf->effect.set_float)(curr_effect, "Brighten", 0.0f); |
| 1473 | |
| 1474 | if (new_dst) |
| 1475 | { |
| 1476 | HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, new_dst); |
| 1477 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 1478 | } |
| 1479 | } |
| 1480 | |
| 1481 | //============================================================ |
| 1482 | // shaders::end_frame |
| 1483 | //============================================================ |
| 1484 | |
| 1485 | void shaders::end_frame() |
| 1486 | { |
| 1487 | if (!master_enable || !d3dintf->post_fx_available) |
| 1488 | return; |
| 1489 | |
| 1490 | if(render_snap && snap_rendered) |
| 1491 | { |
| 1492 | render_snapshot(snap_target); |
| 1493 | } |
| 1494 | |
| 1495 | if (!lines_pending) |
| 1496 | return; |
| 1497 | |
| 1498 | lines_pending = false; |
| 1499 | |
| 1500 | /*render_target *rt = find_render_target(d3d->get_width(), d3d->get_height(), 0, 0); |
| 1501 | if (rt == NULL) |
| 1502 | { |
| 1503 | return; |
| 1504 | } |
| 1505 | |
| 1506 | blit(backbuffer, rt->render_texture[1], NULL, vecbuf_type, vecbuf_index, vecbuf_count); |
| 1507 | |
| 1508 | HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[1]); |
| 1509 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 1510 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1511 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 1512 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, backbuffer); |
| 1513 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);*/ |
| 1514 | } |
| 1515 | |
| 1516 | |
| 1517 | //============================================================ |
| 1518 | // shaders::init_effect_info |
| 1519 | //============================================================ |
| 1520 | |
| 1521 | void shaders::init_effect_info(poly_info *poly) |
| 1522 | { |
| 1523 | if (!master_enable || !d3dintf->post_fx_available) |
| 1524 | return; |
| 1525 | |
| 1526 | renderer *d3d = (renderer *)window->drawdata; |
| 1527 | texture_info *texture = poly->get_texture(); |
| 1528 | |
| 1529 | vec2f shadow_dims; |
| 1530 | |
| 1531 | if (shadow_texture) |
| 1532 | { |
| 1533 | shadow_dims = shadow_texture->get_rawdims(); |
| 1534 | } |
| 1535 | else |
| 1536 | { |
| 1537 | shadow_dims.c.x = 1.0f; |
| 1538 | shadow_dims.c.y = 1.0f; |
| 1539 | } |
| 1540 | |
| 1541 | if(PRIMFLAG_GET_TEXSHADE(d3d->get_last_texture_flags())) |
| 1542 | { |
| 1543 | curr_effect = pincushion_effect; |
| 1544 | } |
| 1545 | else if(PRIMFLAG_GET_SCREENTEX(d3d->get_last_texture_flags()) && texture != NULL) |
| 1546 | { |
| 1547 | // Plug in all of the shader settings we're going to need |
| 1548 | // This is extremely slow, but we're not rendering models here, |
| 1549 | // just post-processing. |
| 1550 | curr_effect = post_effect; |
| 1551 | |
| 1552 | (*d3dintf->effect.set_float)(curr_effect, "ScanlineOffset", (texture->get_cur_frame() == 0) ? 0.0f : options->scanline_offset); |
| 1553 | |
| 1554 | if(options->params_dirty) |
| 1555 | { |
| 1556 | vec2f delta = texture->get_uvstop() - texture->get_uvstart(); |
| 1557 | (*d3dintf->effect.set_vector)(curr_effect, "RawDims", 2, &texture->get_rawdims().c.x); |
| 1558 | (*d3dintf->effect.set_vector)(curr_effect, "SizeRatio", 2, &delta.c.x); |
| 1559 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", d3d->get_width()); |
| 1560 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", d3d->get_height()); |
| 1561 | (*d3dintf->effect.set_vector)(curr_effect, "Floor", 3, options->floor); |
| 1562 | (*d3dintf->effect.set_float)(curr_effect, "SnapX", snap_width); |
| 1563 | (*d3dintf->effect.set_float)(curr_effect, "SnapY", snap_height); |
| 1564 | (*d3dintf->effect.set_float)(curr_effect, "PincushionAmount", options->pincushion); |
| 1565 | (*d3dintf->effect.set_float)(curr_effect, "CurvatureAmount", options->curvature); |
| 1566 | (*d3dintf->effect.set_float)(curr_effect, "UseShadow", shadow_texture == NULL ? 0.0f : 1.0f); |
| 1567 | (*d3dintf->effect.set_texture)(curr_effect, "Shadow", shadow_texture == NULL ? NULL : shadow_texture->get_finaltex()); |
| 1568 | (*d3dintf->effect.set_float)(curr_effect, "ShadowBrightness", options->shadow_mask_alpha); |
| 1569 | (*d3dintf->effect.set_float)(curr_effect, "ShadowMaskSizeX", (float)options->shadow_mask_count_x); |
| 1570 | (*d3dintf->effect.set_float)(curr_effect, "ShadowMaskSizeY", (float)options->shadow_mask_count_y); |
| 1571 | (*d3dintf->effect.set_float)(curr_effect, "ShadowU", options->shadow_mask_u_size); |
| 1572 | (*d3dintf->effect.set_float)(curr_effect, "ShadowV", options->shadow_mask_v_size); |
| 1573 | |
| 1574 | (*d3dintf->effect.set_vector)(curr_effect, "ShadowDims", 2, &shadow_dims.c.x); |
| 1575 | (*d3dintf->effect.set_float)(curr_effect, "ScanlineAmount", options->scanline_alpha); |
| 1576 | (*d3dintf->effect.set_float)(curr_effect, "ScanlineScale", options->scanline_scale); |
| 1577 | (*d3dintf->effect.set_float)(curr_effect, "ScanlineHeight", options->scanline_height); |
| 1578 | (*d3dintf->effect.set_float)(curr_effect, "ScanlineBrightScale", options->scanline_bright_scale); |
| 1579 | (*d3dintf->effect.set_float)(curr_effect, "ScanlineBrightOffset", options->scanline_bright_offset); |
| 1580 | //(*d3dintf->effect.set_float)(curr_effect, "ScanlineOffset", (texture->get_cur_frame() == 0) ? 0.0f : options->scanline_offset); |
| 1581 | (*d3dintf->effect.set_vector)(curr_effect, "Power", 3, options->power); |
| 1582 | } |
| 1583 | } |
| 1584 | else |
| 1585 | { |
| 1586 | curr_effect = default_effect; |
| 1587 | |
| 1588 | (*d3dintf->effect.set_float)(curr_effect, "FixedAlpha", 1.0f); |
| 1589 | } |
| 1590 | } |
| 1591 | |
| 1592 | |
| 1593 | //============================================================ |
| 1594 | // shaders::find_render_target |
| 1595 | //============================================================ |
| 1596 | |
| 1597 | render_target* shaders::find_render_target(texture_info *info) |
| 1598 | { |
| 1599 | render_target *curr = targethead; |
| 1600 | UINT32 screen_index_data = (UINT32)info->get_texinfo().osddata; |
| 1601 | UINT32 screen_index = screen_index_data >> 1; |
| 1602 | UINT32 page_index = screen_index_data & 1; |
| 1603 | |
| 1604 | while (curr != NULL && (curr->screen_index != screen_index || curr->page_index != page_index || |
| 1605 | curr->width != info->get_texinfo().width || curr->height != info->get_texinfo().height)) |
| 1606 | { |
| 1607 | curr = curr->next; |
| 1608 | } |
| 1609 | |
| 1610 | return curr; |
| 1611 | } |
| 1612 | |
| 1613 | |
| 1614 | //============================================================ |
| 1615 | // shaders::find_render_target |
| 1616 | //============================================================ |
| 1617 | |
| 1618 | render_target* shaders::find_render_target(int width, int height, UINT32 screen_index, UINT32 page_index) |
| 1619 | { |
| 1620 | render_target *curr = targethead; |
| 1621 | |
| 1622 | while (curr != NULL && (curr->width != width || curr->height != height || curr->screen_index != screen_index || curr->page_index != page_index)) |
| 1623 | { |
| 1624 | curr = curr->next; |
| 1625 | } |
| 1626 | |
| 1627 | return curr; |
| 1628 | } |
| 1629 | |
| 1630 | |
| 1631 | //============================================================ |
| 1632 | // shaders::find_cache_target |
| 1633 | //============================================================ |
| 1634 | |
| 1635 | cache_target* shaders::find_cache_target(UINT32 screen_index, int width, int height) |
| 1636 | { |
| 1637 | cache_target *curr = cachehead; |
| 1638 | |
| 1639 | while (curr != NULL && (curr->screen_index != screen_index || curr->width != width || curr->height != height)) |
| 1640 | { |
| 1641 | curr = curr->next; |
| 1642 | } |
| 1643 | |
| 1644 | return curr; |
| 1645 | } |
| 1646 | |
| 1647 | |
| 1648 | //============================================================ |
| 1649 | // shaders::render_quad |
| 1650 | //============================================================ |
| 1651 | |
| 1652 | void shaders::render_quad(poly_info *poly, int vertnum) |
| 1653 | { |
| 1654 | if (!master_enable || !d3dintf->post_fx_available) |
| 1655 | return; |
| 1656 | |
| 1657 | UINT num_passes = 0; |
| 1658 | renderer *d3d = (renderer *)window->drawdata; |
| 1659 | texture_info *texture = poly->get_texture(); |
| 1660 | |
| 1661 | if(PRIMFLAG_GET_SCREENTEX(d3d->get_last_texture_flags()) && texture != NULL) |
| 1662 | { |
| 1663 | render_target *rt = find_render_target(texture); |
| 1664 | if (rt == NULL) |
| 1665 | { |
| 1666 | return; |
| 1667 | } |
| 1668 | cache_target *ct = find_cache_target(rt->screen_index, texture->get_texinfo().width, texture->get_texinfo().height); |
| 1669 | |
| 1670 | vec2f& rawdims = texture->get_rawdims(); |
| 1671 | vec2f delta = texture->get_uvstop() - texture->get_uvstart(); |
| 1672 | |
| 1673 | if(options->yiq_enable) |
| 1674 | { |
| 1675 | // Convert our signal into YIQ |
| 1676 | curr_effect = yiq_encode_effect; |
| 1677 | |
| 1678 | if(options->params_dirty) |
| 1679 | { |
| 1680 | (*d3dintf->effect.set_vector)(curr_effect, "RawDims", 2, &rawdims.c.x); |
| 1681 | (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / delta.c.x); |
| 1682 | (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / delta.c.y); |
| 1683 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 1684 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 1685 | (*d3dintf->effect.set_float)(curr_effect, "CCValue", options->yiq_cc); |
| 1686 | (*d3dintf->effect.set_float)(curr_effect, "AValue", options->yiq_a); |
| 1687 | (*d3dintf->effect.set_float)(curr_effect, "BValue", (texture->get_cur_frame() == 2) ? 0.0f : ((float)texture->get_cur_frame() * options->yiq_b)); |
| 1688 | (*d3dintf->effect.set_float)(curr_effect, "PValue", options->yiq_p); |
| 1689 | (*d3dintf->effect.set_float)(curr_effect, "NotchHalfWidth", options->yiq_n); |
| 1690 | (*d3dintf->effect.set_float)(curr_effect, "YFreqResponse", options->yiq_y); |
| 1691 | (*d3dintf->effect.set_float)(curr_effect, "IFreqResponse", options->yiq_i); |
| 1692 | (*d3dintf->effect.set_float)(curr_effect, "QFreqResponse", options->yiq_q); |
| 1693 | (*d3dintf->effect.set_float)(curr_effect, "ScanTime", options->yiq_scan_time); |
| 1694 | } |
| 1695 | |
| 1696 | HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[4]); |
| 1697 | |
| 1698 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 1699 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1700 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 1701 | |
| 1702 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 1703 | |
| 1704 | for (UINT pass = 0; pass < num_passes; pass++) |
| 1705 | { |
| 1706 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 1707 | // add the primitives |
| 1708 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2); |
| 1709 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 1710 | (*d3dintf->effect.end_pass)(curr_effect); |
| 1711 | } |
| 1712 | |
| 1713 | (*d3dintf->effect.end)(curr_effect); |
| 1714 | |
| 1715 | // Convert our signal from YIQ |
| 1716 | curr_effect = yiq_decode_effect; |
| 1717 | |
| 1718 | (*d3dintf->effect.set_texture)(curr_effect, "Composite", rt->render_texture[4]); |
| 1719 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", texture->get_finaltex()); |
| 1720 | if(true)//options->params_dirty) |
| 1721 | { |
| 1722 | (*d3dintf->effect.set_float)(curr_effect, "RawWidth", rawdims.c.x); |
| 1723 | (*d3dintf->effect.set_float)(curr_effect, "RawHeight", rawdims.c.y); |
| 1724 | (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / delta.c.x); |
| 1725 | (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / delta.c.y); |
| 1726 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 1727 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 1728 | (*d3dintf->effect.set_float)(curr_effect, "CCValue", options->yiq_cc); |
| 1729 | (*d3dintf->effect.set_float)(curr_effect, "AValue", options->yiq_a); |
| 1730 | (*d3dintf->effect.set_float)(curr_effect, "BValue", (texture->get_cur_frame() == 2) ? 0.0f : ((float)texture->get_cur_frame() * options->yiq_b)); |
| 1731 | (*d3dintf->effect.set_float)(curr_effect, "OValue", options->yiq_o); |
| 1732 | (*d3dintf->effect.set_float)(curr_effect, "PValue", options->yiq_p); |
| 1733 | (*d3dintf->effect.set_float)(curr_effect, "NotchHalfWidth", options->yiq_n); |
| 1734 | (*d3dintf->effect.set_float)(curr_effect, "YFreqResponse", options->yiq_y); |
| 1735 | (*d3dintf->effect.set_float)(curr_effect, "IFreqResponse", options->yiq_i); |
| 1736 | (*d3dintf->effect.set_float)(curr_effect, "QFreqResponse", options->yiq_q); |
| 1737 | (*d3dintf->effect.set_float)(curr_effect, "ScanTime", options->yiq_scan_time); |
| 1738 | } |
| 1739 | |
| 1740 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[3]); |
| 1741 | |
| 1742 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 1743 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1744 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 1745 | |
| 1746 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 1747 | |
| 1748 | for (UINT pass = 0; pass < num_passes; pass++) |
| 1749 | { |
| 1750 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 1751 | // add the primitives |
| 1752 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2); |
| 1753 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 1754 | (*d3dintf->effect.end_pass)(curr_effect); |
| 1755 | } |
| 1756 | |
| 1757 | (*d3dintf->effect.end)(curr_effect); |
| 1758 | |
| 1759 | curr_effect = color_effect; |
| 1760 | |
| 1761 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[3]); |
| 1762 | } |
| 1763 | |
| 1764 | curr_effect = color_effect; |
| 1765 | |
| 1766 | // Render the initial color-convolution pass |
| 1767 | if(options->params_dirty) |
| 1768 | { |
| 1769 | (*d3dintf->effect.set_vector)(curr_effect, "RawDims", 2, &rawdims.c.x); |
| 1770 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 1771 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 1772 | (*d3dintf->effect.set_float)(curr_effect, "YIQEnable", options->yiq_enable ? 1.0f : 0.0f); |
| 1773 | (*d3dintf->effect.set_vector)(curr_effect, "RedRatios", 3, options->red_ratio); |
| 1774 | (*d3dintf->effect.set_vector)(curr_effect, "GrnRatios", 3, options->grn_ratio); |
| 1775 | (*d3dintf->effect.set_vector)(curr_effect, "BluRatios", 3, options->blu_ratio); |
| 1776 | (*d3dintf->effect.set_vector)(curr_effect, "Offset", 3, options->offset); |
| 1777 | (*d3dintf->effect.set_vector)(curr_effect, "Scale", 3, options->scale); |
| 1778 | (*d3dintf->effect.set_float)(curr_effect, "Saturation", options->saturation); |
| 1779 | } |
| 1780 | |
| 1781 | HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->smalltarget); |
| 1782 | |
| 1783 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 1784 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1785 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 1786 | |
| 1787 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 1788 | |
| 1789 | for (UINT pass = 0; pass < num_passes; pass++) |
| 1790 | { |
| 1791 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 1792 | // add the primitives |
| 1793 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2); |
| 1794 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 1795 | (*d3dintf->effect.end_pass)(curr_effect); |
| 1796 | } |
| 1797 | |
| 1798 | (*d3dintf->effect.end)(curr_effect); |
| 1799 | |
| 1800 | // Pre-scaling pass |
| 1801 | curr_effect = prescale_effect; |
| 1802 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->smalltexture); |
| 1803 | |
| 1804 | if(options->params_dirty) |
| 1805 | { |
| 1806 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 1807 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 1808 | (*d3dintf->effect.set_vector)(curr_effect, "RawDims", 2, &rawdims.c.x); |
| 1809 | } |
| 1810 | |
| 1811 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 1812 | |
| 1813 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->prescaletarget); |
| 1814 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 1815 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1816 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 1817 | |
| 1818 | for (UINT pass = 0; pass < num_passes; pass++) |
| 1819 | { |
| 1820 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 1821 | // add the primitives |
| 1822 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2); |
| 1823 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 1824 | (*d3dintf->effect.end_pass)(curr_effect); |
| 1825 | } |
| 1826 | |
| 1827 | (*d3dintf->effect.end)(curr_effect); |
| 1828 | |
| 1829 | // Deconverge pass |
| 1830 | curr_effect = deconverge_effect; |
| 1831 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->prescaletexture); |
| 1832 | |
| 1833 | if(options->params_dirty) |
| 1834 | { |
| 1835 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 1836 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 1837 | (*d3dintf->effect.set_vector)(curr_effect, "RawDims", 2, &rawdims.c.x); |
| 1838 | (*d3dintf->effect.set_vector)(curr_effect, "SizeRatio", 2, &delta.c.x); |
| 1839 | (*d3dintf->effect.set_vector)(curr_effect, "ConvergeX", 3, options->converge_x); |
| 1840 | (*d3dintf->effect.set_vector)(curr_effect, "ConvergeY", 3, options->converge_y); |
| 1841 | (*d3dintf->effect.set_vector)(curr_effect, "RadialConvergeX", 3, options->radial_converge_x); |
| 1842 | (*d3dintf->effect.set_vector)(curr_effect, "RadialConvergeY", 3, options->radial_converge_y); |
| 1843 | } |
| 1844 | |
| 1845 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 1846 | |
| 1847 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[2]); |
| 1848 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 6\n", (int)result); |
| 1849 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1850 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 1851 | |
| 1852 | for (UINT pass = 0; pass < num_passes; pass++) |
| 1853 | { |
| 1854 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 1855 | // add the primitives |
| 1856 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2); |
| 1857 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 1858 | (*d3dintf->effect.end_pass)(curr_effect); |
| 1859 | } |
| 1860 | |
| 1861 | (*d3dintf->effect.end)(curr_effect); |
| 1862 | |
| 1863 | float defocus_x = options->defocus[0]; |
| 1864 | float defocus_y = options->defocus[1]; |
| 1865 | bool focus_enable = defocus_x != 0.0f || defocus_y != 0.0f; |
| 1866 | if(focus_enable) |
| 1867 | { |
| 1868 | // Defocus pass 1 |
| 1869 | curr_effect = focus_effect; |
| 1870 | |
| 1871 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[2]); |
| 1872 | |
| 1873 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 1874 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 1875 | (*d3dintf->effect.set_vector)(curr_effect, "Defocus", 2, &options->defocus[0]); |
| 1876 | |
| 1877 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 1878 | |
| 1879 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[0]); |
| 1880 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 6\n", (int)result); |
| 1881 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1882 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 1883 | |
| 1884 | for (UINT pass = 0; pass < num_passes; pass++) |
| 1885 | { |
| 1886 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 1887 | // add the primitives |
| 1888 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2); |
| 1889 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 1890 | (*d3dintf->effect.end_pass)(curr_effect); |
| 1891 | } |
| 1892 | |
| 1893 | (*d3dintf->effect.end)(curr_effect); |
| 1894 | |
| 1895 | // Defocus pass 2 |
| 1896 | |
| 1897 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[0]); |
| 1898 | |
| 1899 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 1900 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 1901 | (*d3dintf->effect.set_vector)(curr_effect, "Defocus", 2, &options->defocus[1]); |
| 1902 | |
| 1903 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 1904 | |
| 1905 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[1]); |
| 1906 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 7\n", (int)result); |
| 1907 | |
| 1908 | for (UINT pass = 0; pass < num_passes; pass++) |
| 1909 | { |
| 1910 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 1911 | // add the primitives |
| 1912 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2); |
| 1913 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 1914 | (*d3dintf->effect.end_pass)(curr_effect); |
| 1915 | } |
| 1916 | |
| 1917 | (*d3dintf->effect.end)(curr_effect); |
| 1918 | } |
| 1919 | |
| 1920 | // Simulate phosphorescence. This should happen after the shadow/scanline pass, but since |
| 1921 | // the phosphors are a direct result of the incoming texture, might as well just change the |
| 1922 | // input texture. |
| 1923 | curr_effect = phosphor_effect; |
| 1924 | |
| 1925 | if(options->params_dirty) |
| 1926 | { |
| 1927 | //(*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)rt->target_width); |
| 1928 | //(*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)rt->target_height); |
| 1929 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 1930 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 1931 | (*d3dintf->effect.set_vector)(curr_effect, "Phosphor", 3, options->phosphor); |
| 1932 | } |
| 1933 | (*d3dintf->effect.set_float)(curr_effect, "TextureWidth", (float)rt->target_width); |
| 1934 | (*d3dintf->effect.set_float)(curr_effect, "TextureHeight", (float)rt->target_height); |
| 1935 | (*d3dintf->effect.set_float)(curr_effect, "Passthrough", 0.0f); |
| 1936 | |
| 1937 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", focus_enable ? rt->render_texture[1] : rt->render_texture[2]); |
| 1938 | (*d3dintf->effect.set_texture)(curr_effect, "LastPass", ct->last_texture); |
| 1939 | |
| 1940 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[0]); |
| 1941 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 4\n", (int)result); |
| 1942 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1943 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 1944 | |
| 1945 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 1946 | |
| 1947 | for (UINT pass = 0; pass < num_passes; pass++) |
| 1948 | { |
| 1949 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 1950 | // add the primitives |
| 1951 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2); |
| 1952 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 1953 | (*d3dintf->effect.end_pass)(curr_effect); |
| 1954 | } |
| 1955 | |
| 1956 | (*d3dintf->effect.end)(curr_effect); |
| 1957 | |
| 1958 | // Pass along our phosphor'd screen |
| 1959 | curr_effect = phosphor_effect; |
| 1960 | |
| 1961 | //(*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 1962 | //(*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 1963 | //(*d3dintf->effect.set_float)(curr_effect, "TextureWidth", (float)d3d->get_width()); |
| 1964 | //(*d3dintf->effect.set_float)(curr_effect, "TextureHeight", (float)d3d->get_height()); |
| 1965 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[0]); |
| 1966 | (*d3dintf->effect.set_texture)(curr_effect, "LastPass", rt->render_texture[0]); |
| 1967 | (*d3dintf->effect.set_float)(curr_effect, "Passthrough", 1.0f); |
| 1968 | |
| 1969 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, ct->last_target); // Avoid changing targets due to page flipping |
| 1970 | //result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, backbuffer); // Avoid changing targets due to page flipping |
| 1971 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 5\n", (int)result); |
| 1972 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1973 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 1974 | |
| 1975 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 1976 | |
| 1977 | for (UINT pass = 0; pass < num_passes; pass++) |
| 1978 | { |
| 1979 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 1980 | // add the primitives |
| 1981 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2); |
| 1982 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 1983 | (*d3dintf->effect.end_pass)(curr_effect); |
| 1984 | } |
| 1985 | |
| 1986 | (*d3dintf->effect.end)(curr_effect); |
| 1987 | |
| 1988 | curr_effect = post_effect; |
| 1989 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 1990 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 1991 | |
| 1992 | // Scanlines and shadow mask, at high res for AVI logging |
| 1993 | if(avi_output_file != NULL) |
| 1994 | { |
| 1995 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[0]); |
| 1996 | |
| 1997 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, avi_final_target); |
| 1998 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 1999 | |
| 2000 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2001 | |
| 2002 | for (UINT pass = 0; pass < num_passes; pass++) |
| 2003 | { |
| 2004 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 2005 | // add the primitives |
| 2006 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count()); |
| 2007 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 2008 | (*d3dintf->effect.end_pass)(curr_effect); |
| 2009 | } |
| 2010 | |
| 2011 | (*d3dintf->effect.end)(curr_effect); |
| 2012 | } |
| 2013 | |
| 2014 | if(render_snap) |
| 2015 | { |
| 2016 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[0]); |
| 2017 | |
| 2018 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, snap_target); |
| 2019 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 2020 | |
| 2021 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2022 | |
| 2023 | for (UINT pass = 0; pass < num_passes; pass++) |
| 2024 | { |
| 2025 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 2026 | // add the primitives |
| 2027 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count()); |
| 2028 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 2029 | (*d3dintf->effect.end_pass)(curr_effect); |
| 2030 | } |
| 2031 | |
| 2032 | (*d3dintf->effect.end)(curr_effect); |
| 2033 | |
| 2034 | snap_rendered = true; |
| 2035 | } |
| 2036 | |
| 2037 | // Scanlines and shadow mask |
| 2038 | curr_effect = post_effect; |
| 2039 | |
| 2040 | //float raw_dims[2] = { d3d->get_width(), d3d->get_height() }; |
| 2041 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[0]); |
| 2042 | (*d3dintf->effect.set_vector)(curr_effect, "RawDims", 2, &rawdims.c.x); |
| 2043 | (*d3dintf->effect.set_vector)(curr_effect, "SizeRatio", 2, &delta.c.x); |
| 2044 | |
| 2045 | d3d->set_wrap(D3DTADDRESS_MIRROR); |
| 2046 | |
| 2047 | #if CRT_BLOOM |
| 2048 | //(*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)rt->target_width); |
| 2049 | //(*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)rt->target_height); |
| 2050 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 2051 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 2052 | |
| 2053 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[2]); |
| 2054 | |
| 2055 | d3d->set_wrap(D3DTADDRESS_MIRROR); |
| 2056 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(1,0,0,0), 0, 0); |
| 2057 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 2058 | #else |
| 2059 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 2060 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 2061 | |
| 2062 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, backbuffer); |
| 2063 | #endif |
| 2064 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 2065 | |
| 2066 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2067 | |
| 2068 | for (UINT pass = 0; pass < num_passes; pass++) |
| 2069 | { |
| 2070 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 2071 | // add the primitives |
| 2072 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count()); |
| 2073 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 2074 | (*d3dintf->effect.end_pass)(curr_effect); |
| 2075 | } |
| 2076 | |
| 2077 | (*d3dintf->effect.end)(curr_effect); |
| 2078 | |
| 2079 | d3d->set_wrap(PRIMFLAG_GET_TEXWRAP(poly->get_texture()->get_flags()) ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP); |
| 2080 | |
| 2081 | #if CRT_BLOOM |
| 2082 | // Bloom |
| 2083 | curr_effect = downsample_effect; |
| 2084 | |
| 2085 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[2]); |
| 2086 | (*d3dintf->effect.set_float)(curr_effect, "BloomRescale", options->raster_bloom_scale); |
| 2087 | |
| 2088 | float bloom_size = (d3d->get_width() < d3d->get_height()) ? d3d->get_width() : d3d->get_height(); |
| 2089 | int bloom_index = 0; |
| 2090 | float bloom_width = rt->target_width; |
| 2091 | float bloom_height = rt->target_height; |
| 2092 | float prim_width = poly->get_prim_width(); |
| 2093 | float prim_height = poly->get_prim_height(); |
| 2094 | float prim_ratio[2] = { prim_width / bloom_width, prim_height / bloom_height }; |
| 2095 | float screen_size[2] = { d3d->get_width(), d3d->get_height() }; |
| 2096 | //float target_size[2] = { bloom_width * 0.5f, bloom_height * 0.5f }; |
| 2097 | (*d3dintf->effect.set_vector)(curr_effect, "ScreenSize", 2, screen_size); |
| 2098 | for(; bloom_size >= 2.0f && bloom_index < 11; bloom_size *= 0.5f) |
| 2099 | { |
| 2100 | float target_size[2] = { bloom_width, bloom_height }; |
| 2101 | float source_size[2] = { bloom_width * 0.5f, bloom_height * 0.5f }; |
| 2102 | (*d3dintf->effect.set_vector)(curr_effect, "TargetSize", 2, target_size); |
| 2103 | (*d3dintf->effect.set_vector)(curr_effect, "SourceSize", 2, source_size); |
| 2104 | (*d3dintf->effect.set_vector)(curr_effect, "PrimRatio", 2, prim_ratio); |
| 2105 | |
| 2106 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2107 | |
| 2108 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", (bloom_index == 0) ? rt->render_texture[2] : rt->bloom_texture[bloom_index - 1]); |
| 2109 | |
| 2110 | HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->bloom_target[bloom_index]); |
| 2111 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 6\n", (int)result); |
| 2112 | //result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2113 | //if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 2114 | |
| 2115 | for (UINT pass = 0; pass < num_passes; pass++) |
| 2116 | { |
| 2117 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 2118 | // add the primitives |
| 2119 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2); |
| 2120 | //result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count()); |
| 2121 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 2122 | (*d3dintf->effect.end_pass)(curr_effect); |
| 2123 | } |
| 2124 | |
| 2125 | (*d3dintf->effect.end)(curr_effect); |
| 2126 | |
| 2127 | bloom_index++; |
| 2128 | bloom_width *= 0.5f; |
| 2129 | bloom_height *= 0.5f; |
| 2130 | } |
| 2131 | |
| 2132 | // Bloom composite pass |
| 2133 | curr_effect = bloom_effect; |
| 2134 | |
| 2135 | float target_size[2] = { d3d->get_width(), d3d->get_height() }; |
| 2136 | (*d3dintf->effect.set_vector)(curr_effect, "TargetSize", 2, target_size); |
| 2137 | float weight0123[4] = { options->bloom_level0_weight, options->bloom_level1_weight, |
| 2138 | options->bloom_level2_weight, options->bloom_level3_weight }; |
| 2139 | float weight4567[4] = { options->bloom_level4_weight, options->bloom_level5_weight, |
| 2140 | options->bloom_level6_weight, options->bloom_level7_weight }; |
| 2141 | float weight89A[3] = { options->bloom_level8_weight, options->bloom_level9_weight, |
| 2142 | options->bloom_level10_weight }; |
| 2143 | (*d3dintf->effect.set_vector)(curr_effect, "Level0123Weight", 4, weight0123); |
| 2144 | (*d3dintf->effect.set_vector)(curr_effect, "Level4567Weight", 4, weight4567); |
| 2145 | (*d3dintf->effect.set_vector)(curr_effect, "Level89AWeight", 3, weight89A); |
| 2146 | (*d3dintf->effect.set_vector)(curr_effect, "TargetSize", 2, target_size); |
| 2147 | |
| 2148 | (*d3dintf->effect.set_texture)(curr_effect, "DiffuseA", rt->render_texture[2]); |
| 2149 | (*d3dintf->effect.set_float)(curr_effect, "DiffuseScaleA", 1.0f); |
| 2150 | |
| 2151 | char name[9] = "Diffuse*"; |
| 2152 | char scale[14] = "DiffuseScale*"; |
| 2153 | for(int index = 1; index < bloom_index; index++) |
| 2154 | { |
| 2155 | name[7] = 'A' + index; |
| 2156 | scale[12] = 'A' + index; |
| 2157 | (*d3dintf->effect.set_texture)(curr_effect, name, rt->bloom_texture[index - 1]); |
| 2158 | (*d3dintf->effect.set_float)(curr_effect, scale, 1.0f); |
| 2159 | } |
| 2160 | for(int index = bloom_index; index < 11; index++) |
| 2161 | { |
| 2162 | name[7] = 'A' + index; |
| 2163 | scale[12] = 'A' + index; |
| 2164 | (*d3dintf->effect.set_texture)(curr_effect, name, black_texture); |
| 2165 | (*d3dintf->effect.set_float)(curr_effect, scale, 0.0f); |
| 2166 | } |
| 2167 | |
| 2168 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2169 | |
| 2170 | //HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[1]); |
| 2171 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, backbuffer); |
| 2172 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 6\n", (int)result); |
| 2173 | //result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2174 | //if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 2175 | |
| 2176 | for (UINT pass = 0; pass < num_passes; pass++) |
| 2177 | { |
| 2178 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 2179 | // add the primitives |
| 2180 | //result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2); |
| 2181 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count()); |
| 2182 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 2183 | (*d3dintf->effect.end_pass)(curr_effect); |
| 2184 | } |
| 2185 | |
| 2186 | (*d3dintf->effect.end)(curr_effect); |
| 2187 | #endif |
| 2188 | texture->increment_frame_count(); |
| 2189 | texture->mask_frame_count(options->yiq_phase_count); |
| 2190 | |
| 2191 | options->params_dirty = false; |
| 2192 | |
| 2193 | } |
| 2194 | #if HLSL_VECTOR |
| 2195 | else if(PRIMFLAG_GET_VECTOR(poly->get_flags()) && vector_enable) |
| 2196 | { |
| 2197 | render_target *rt = find_render_target(d3d->get_width(), d3d->get_height(), 0, 0); |
| 2198 | if (rt == NULL) |
| 2199 | { |
| 2200 | return; |
| 2201 | } |
| 2202 | |
| 2203 | lines_pending = true; |
| 2204 | |
| 2205 | curr_effect = vector_effect; |
| 2206 | |
| 2207 | if(options->params_dirty) |
| 2208 | { |
| 2209 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 2210 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 2211 | } |
| 2212 | |
| 2213 | float time_params[2] = { 0.0f, 0.0f }; |
| 2214 | float length_params[3] = { poly->get_line_length(), options->vector_length_scale, options->vector_length_ratio }; |
| 2215 | (*d3dintf->effect.set_vector)(curr_effect, "TimeParams", 2, time_params); |
| 2216 | (*d3dintf->effect.set_vector)(curr_effect, "LengthParams", 3, length_params); |
| 2217 | |
| 2218 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2219 | |
| 2220 | HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[0]); |
| 2221 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 2222 | |
| 2223 | for (UINT pass = 0; pass < num_passes; pass++) |
| 2224 | { |
| 2225 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 2226 | // add the primitives |
| 2227 | HRESULT result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count()); |
| 2228 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 2229 | (*d3dintf->effect.end_pass)(curr_effect); |
| 2230 | } |
| 2231 | |
| 2232 | (*d3dintf->effect.end)(curr_effect); |
| 2233 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, backbuffer); |
| 2234 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 2235 | |
| 2236 | curr_effect = default_effect; |
| 2237 | |
| 2238 | (*d3dintf->effect.set_float)(curr_effect, "FixedAlpha", 1.0f); |
| 2239 | } |
| 2240 | else if (PRIMFLAG_GET_VECTORBUF(poly->get_flags()) && vector_enable) |
| 2241 | { |
| 2242 | //if (!lines_pending) |
| 2243 | //return; |
| 2244 | //lines_pending = false; |
| 2245 | |
| 2246 | renderer *d3d = (renderer *)window->drawdata; |
| 2247 | |
| 2248 | render_target *rt = find_render_target(d3d->get_width(), d3d->get_height(), 0, 0); |
| 2249 | if (rt == NULL) |
| 2250 | { |
| 2251 | return; |
| 2252 | } |
| 2253 | |
| 2254 | /* Bloom */ |
| 2255 | curr_effect = downsample_effect; |
| 2256 | |
| 2257 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[0]); |
| 2258 | (*d3dintf->effect.set_float)(curr_effect, "BloomRescale", options->vector_bloom_scale); |
| 2259 | |
| 2260 | float bloom_size = (d3d->get_width() < d3d->get_height()) ? d3d->get_width() : d3d->get_height(); |
| 2261 | int bloom_index = 0; |
| 2262 | float bloom_width = rt->target_width; |
| 2263 | float bloom_height = rt->target_height; |
| 2264 | float prim_width = poly->get_prim_width(); |
| 2265 | float prim_height = poly->get_prim_height(); |
| 2266 | float prim_ratio[2] = { prim_width / bloom_width, prim_height / bloom_height }; |
| 2267 | float screen_size[2] = { d3d->get_width(), d3d->get_height() }; |
| 2268 | //float target_size[2] = { bloom_width * 0.5f, bloom_height * 0.5f }; |
| 2269 | (*d3dintf->effect.set_vector)(curr_effect, "ScreenSize", 2, screen_size); |
| 2270 | for(; bloom_size >= 2.0f && bloom_index < 11; bloom_size *= 0.5f) |
| 2271 | { |
| 2272 | float target_size[2] = { bloom_width, bloom_height }; |
| 2273 | float source_size[2] = { bloom_width * 0.5f, bloom_height * 0.5f }; |
| 2274 | (*d3dintf->effect.set_vector)(curr_effect, "TargetSize", 2, target_size); |
| 2275 | (*d3dintf->effect.set_vector)(curr_effect, "SourceSize", 2, source_size); |
| 2276 | (*d3dintf->effect.set_vector)(curr_effect, "PrimRatio", 2, prim_ratio); |
| 2277 | |
| 2278 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2279 | |
| 2280 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", (bloom_index == 0) ? rt->render_texture[0] : rt->bloom_texture[bloom_index - 1]); |
| 2281 | |
| 2282 | HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->bloom_target[bloom_index]); |
| 2283 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 6\n", (int)result); |
| 2284 | //result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2285 | //if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 2286 | |
| 2287 | for (UINT pass = 0; pass < num_passes; pass++) |
| 2288 | { |
| 2289 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 2290 | // add the primitives |
| 2291 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count()); |
| 2292 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 2293 | (*d3dintf->effect.end_pass)(curr_effect); |
| 2294 | } |
| 2295 | |
| 2296 | (*d3dintf->effect.end)(curr_effect); |
| 2297 | |
| 2298 | bloom_index++; |
| 2299 | bloom_width *= 0.5f; |
| 2300 | bloom_height *= 0.5f; |
| 2301 | } |
| 2302 | |
| 2303 | // Bloom composite pass |
| 2304 | curr_effect = bloom_effect; |
| 2305 | |
| 2306 | float target_size[2] = { d3d->get_width(), d3d->get_height() }; |
| 2307 | (*d3dintf->effect.set_vector)(curr_effect, "TargetSize", 2, target_size); |
| 2308 | float weight0123[4] = { options->bloom_level0_weight, options->bloom_level1_weight, |
| 2309 | options->bloom_level2_weight, options->bloom_level3_weight }; |
| 2310 | float weight4567[4] = { options->bloom_level4_weight, options->bloom_level5_weight, |
| 2311 | options->bloom_level6_weight, options->bloom_level7_weight }; |
| 2312 | float weight89A[3] = { options->bloom_level8_weight, options->bloom_level9_weight, |
| 2313 | options->bloom_level10_weight }; |
| 2314 | (*d3dintf->effect.set_vector)(curr_effect, "Level0123Weight", 4, weight0123); |
| 2315 | (*d3dintf->effect.set_vector)(curr_effect, "Level4567Weight", 4, weight4567); |
| 2316 | (*d3dintf->effect.set_vector)(curr_effect, "Level89AWeight", 3, weight89A); |
| 2317 | |
| 2318 | (*d3dintf->effect.set_texture)(curr_effect, "DiffuseA", rt->render_texture[0]); |
| 2319 | (*d3dintf->effect.set_float)(curr_effect, "DiffuseScaleA", 1.0f); |
| 2320 | |
| 2321 | char name[9] = "Diffuse*"; |
| 2322 | char scale[14] = "DiffuseScale*"; |
| 2323 | for(int index = 1; index < bloom_index; index++) |
| 2324 | { |
| 2325 | name[7] = 'A' + index; |
| 2326 | scale[12] = 'A' + index; |
| 2327 | (*d3dintf->effect.set_texture)(curr_effect, name, rt->bloom_texture[index - 1]); |
| 2328 | (*d3dintf->effect.set_float)(curr_effect, scale, 1.0f); |
| 2329 | } |
| 2330 | for(int index = bloom_index; index < 11; index++) |
| 2331 | { |
| 2332 | name[7] = 'A' + index; |
| 2333 | scale[12] = 'A' + index; |
| 2334 | (*d3dintf->effect.set_texture)(curr_effect, name, black_texture); |
| 2335 | (*d3dintf->effect.set_float)(curr_effect, scale, 0.0f); |
| 2336 | } |
| 2337 | |
| 2338 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2339 | |
| 2340 | HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[1]); |
| 2341 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 6\n", (int)result); |
| 2342 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2343 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 2344 | |
| 2345 | for (UINT pass = 0; pass < num_passes; pass++) |
| 2346 | { |
| 2347 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 2348 | // add the primitives |
| 2349 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count()); |
| 2350 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 2351 | (*d3dintf->effect.end_pass)(curr_effect); |
| 2352 | } |
| 2353 | |
| 2354 | (*d3dintf->effect.end)(curr_effect); |
| 2355 | |
| 2356 | /* Phosphor */ |
| 2357 | curr_effect = phosphor_effect; |
| 2358 | |
| 2359 | if(options->params_dirty) |
| 2360 | { |
| 2361 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 2362 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 2363 | (*d3dintf->effect.set_vector)(curr_effect, "Phosphor", 3, options->phosphor); |
| 2364 | } |
| 2365 | (*d3dintf->effect.set_float)(curr_effect, "TextureWidth", (float)d3d->get_width()); |
| 2366 | (*d3dintf->effect.set_float)(curr_effect, "TextureHeight", (float)d3d->get_height()); |
| 2367 | (*d3dintf->effect.set_float)(curr_effect, "Passthrough", 0.0f); |
| 2368 | |
| 2369 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[1]); |
| 2370 | (*d3dintf->effect.set_texture)(curr_effect, "LastPass", rt->render_texture[2]); |
| 2371 | |
| 2372 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[3]); |
| 2373 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 4\n", (int)result); |
| 2374 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2375 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 2376 | |
| 2377 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2378 | |
| 2379 | for (UINT pass = 0; pass < num_passes; pass++) |
| 2380 | { |
| 2381 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 2382 | // add the primitives |
| 2383 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2); |
| 2384 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 2385 | (*d3dintf->effect.end_pass)(curr_effect); |
| 2386 | } |
| 2387 | |
| 2388 | (*d3dintf->effect.end)(curr_effect); |
| 2389 | |
| 2390 | blit(rt->target[2], rt->render_texture[3], NULL, poly->get_type(), vertnum, poly->get_count()); |
| 2391 | blit(backbuffer, rt->render_texture[3], backbuffer, poly->get_type(), vertnum, poly->get_count()); |
| 2392 | |
| 2393 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[0]); |
| 2394 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 2395 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2396 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 2397 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, backbuffer); |
| 2398 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 2399 | |
| 2400 | lines_pending = false; |
| 2401 | } |
| 2402 | #else |
| 2403 | else if (PRIMFLAG_GET_VECTORBUF(poly->get_flags()) && vector_enable) |
| 2404 | { |
| 2405 | // Do nothing |
| 2406 | } |
| 2407 | #endif |
| 2408 | else |
| 2409 | { |
| 2410 | curr_effect = default_effect; |
| 2411 | |
| 2412 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 2413 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 2414 | (*d3dintf->effect.set_float)(curr_effect, "PostPass", 0.0f); |
| 2415 | |
| 2416 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2417 | |
| 2418 | for (UINT pass = 0; pass < num_passes; pass++) |
| 2419 | { |
| 2420 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 2421 | // add the primitives |
| 2422 | HRESULT result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count()); |
| 2423 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 2424 | (*d3dintf->effect.end_pass)(curr_effect); |
| 2425 | } |
| 2426 | |
| 2427 | (*d3dintf->effect.end)(curr_effect); |
| 2428 | } |
| 2429 | } |
| 2430 | |
| 2431 | |
| 2432 | |
| 2433 | //============================================================ |
| 2434 | // shaders::end_draw |
| 2435 | //============================================================ |
| 2436 | |
| 2437 | void shaders::end_draw() |
| 2438 | { |
| 2439 | if (!master_enable || !d3dintf->post_fx_available) |
| 2440 | return; |
| 2441 | |
| 2442 | (*d3dintf->surface.release)(backbuffer); |
| 2443 | } |
| 2444 | |
| 2445 | |
| 2446 | //============================================================ |
| 2447 | // shaders::register_prescaled_texture |
| 2448 | //============================================================ |
| 2449 | |
| 2450 | bool shaders::register_prescaled_texture(texture_info *texture) |
| 2451 | { |
| 2452 | return register_texture(texture); |
| 2453 | } |
| 2454 | |
| 2455 | |
| 2456 | //============================================================ |
| 2457 | // shaders::add_cache_target - register a cache target |
| 2458 | //============================================================ |
| 2459 | bool shaders::add_cache_target(renderer* d3d, texture_info* info, int width, int height, int xprescale, int yprescale, int screen_index) |
| 2460 | { |
| 2461 | cache_target* target = (cache_target*)global_alloc_clear(cache_target); |
| 2462 | |
| 2463 | if (!target->init(d3d, d3dintf, width, height, xprescale, yprescale)) |
| 2464 | { |
| 2465 | global_free(target); |
| 2466 | return false; |
| 2467 | } |
| 2468 | |
| 2469 | if (info != NULL) |
| 2470 | { |
| 2471 | target->width = info->get_texinfo().width; |
| 2472 | target->height = info->get_texinfo().height; |
| 2473 | } |
| 2474 | else |
| 2475 | { |
| 2476 | target->width = d3d->get_width(); |
| 2477 | target->height = d3d->get_height(); |
| 2478 | } |
| 2479 | |
| 2480 | target->next = cachehead; |
| 2481 | target->prev = NULL; |
| 2482 | |
| 2483 | target->screen_index = screen_index; |
| 2484 | |
| 2485 | if (cachehead != NULL) |
| 2486 | { |
| 2487 | cachehead->prev = target; |
| 2488 | } |
| 2489 | cachehead = target; |
| 2490 | |
| 2491 | return true; |
| 2492 | } |
| 2493 | |
| 2494 | render_target* shaders::get_vector_target() |
| 2495 | { |
| 2496 | #if HLSL_VECTOR |
| 2497 | if (!vector_enable) |
| 2498 | { |
| 2499 | return NULL; |
| 2500 | } |
| 2501 | |
| 2502 | renderer *d3d = (renderer *)window->drawdata; |
| 2503 | |
| 2504 | return find_render_target(d3d->get_width(), d3d->get_height(), 0, 0); |
| 2505 | #else |
| 2506 | return NULL; |
| 2507 | #endif |
| 2508 | } |
| 2509 | |
| 2510 | void shaders::create_vector_target(render_primitive *prim) |
| 2511 | { |
| 2512 | #if HLSL_VECTOR |
| 2513 | renderer *d3d = (renderer *)window->drawdata; |
| 2514 | if (!add_render_target(d3d, NULL, d3d->get_width(), d3d->get_height(), 1, 1)) |
| 2515 | { |
| 2516 | vector_enable = false; |
| 2517 | } |
| 2518 | #endif |
| 2519 | } |
| 2520 | |
| 2521 | //============================================================ |
| 2522 | // shaders::add_render_target - register a render target |
| 2523 | //============================================================ |
| 2524 | |
| 2525 | bool shaders::add_render_target(renderer* d3d, texture_info* info, int width, int height, int xprescale, int yprescale) |
| 2526 | { |
| 2527 | UINT32 screen_index = 0; |
| 2528 | UINT32 page_index = 0; |
| 2529 | if (info != NULL) |
| 2530 | { |
| 2531 | render_target *existing_target = find_render_target(info); |
| 2532 | if (existing_target != NULL) |
| 2533 | { |
| 2534 | remove_render_target(existing_target); |
| 2535 | } |
| 2536 | |
| 2537 | UINT32 screen_index_data = (UINT32)info->get_texinfo().osddata; |
| 2538 | screen_index = screen_index_data >> 1; |
| 2539 | page_index = screen_index_data & 1; |
| 2540 | } |
| 2541 | else |
| 2542 | { |
| 2543 | render_target *existing_target = find_render_target(d3d->get_width(), d3d->get_height(), 0, 0); |
| 2544 | if (existing_target != NULL) |
| 2545 | { |
| 2546 | remove_render_target(existing_target); |
| 2547 | } |
| 2548 | } |
| 2549 | |
| 2550 | render_target* target = (render_target*)global_alloc_clear(render_target); |
| 2551 | |
| 2552 | if (!target->init(d3d, d3dintf, width, height, xprescale, yprescale)) |
| 2553 | { |
| 2554 | global_free(target); |
| 2555 | return false; |
| 2556 | } |
| 2557 | |
| 2558 | if (info != NULL) |
| 2559 | { |
| 2560 | target->width = info->get_texinfo().width; |
| 2561 | target->height = info->get_texinfo().height; |
| 2562 | } |
| 2563 | else |
| 2564 | { |
| 2565 | target->width = d3d->get_width(); |
| 2566 | target->height = d3d->get_height(); |
| 2567 | } |
| 2568 | |
| 2569 | HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, target->target[0]); |
| 2570 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 2571 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2572 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 2573 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, backbuffer); |
| 2574 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 2575 | |
| 2576 | target->screen_index = screen_index; |
| 2577 | target->page_index = page_index; |
| 2578 | |
| 2579 | cache_target* cache = find_cache_target(target->screen_index, target->width, target->height); |
| 2580 | if (cache == NULL) |
| 2581 | { |
| 2582 | if (!add_cache_target(d3d, info, width, height, xprescale, yprescale, target->screen_index)) |
| 2583 | { |
| 2584 | global_free(target); |
| 2585 | return false; |
| 2586 | } |
| 2587 | } |
| 2588 | |
| 2589 | target->next = targethead; |
| 2590 | target->prev = NULL; |
| 2591 | |
| 2592 | if (targethead != NULL) |
| 2593 | { |
| 2594 | targethead->prev = target; |
| 2595 | } |
| 2596 | targethead = target; |
| 2597 | |
| 2598 | return true; |
| 2599 | } |
| 2600 | |
| 2601 | //============================================================ |
| 2602 | // shaders::enumerate_screens |
| 2603 | //============================================================ |
| 2604 | void shaders::enumerate_screens() |
| 2605 | { |
| 2606 | screen_device_iterator iter(window->machine().root_device()); |
| 2607 | num_screens = iter.count(); |
| 2608 | } |
| 2609 | |
| 2610 | |
| 2611 | //============================================================ |
| 2612 | // shaders::register_texture(texture::info) |
| 2613 | //============================================================ |
| 2614 | |
| 2615 | bool shaders::register_texture(texture_info *texture) |
| 2616 | { |
| 2617 | int width = texture->get_width(); |
| 2618 | int height = texture->get_height(); |
| 2619 | int xscale = texture->get_xscale(); |
| 2620 | int yscale = texture->get_yscale(); |
| 2621 | |
| 2622 | if (!master_enable || !d3dintf->post_fx_available) |
| 2623 | { |
| 2624 | return false; |
| 2625 | } |
| 2626 | |
| 2627 | enumerate_screens(); |
| 2628 | |
| 2629 | renderer *d3d = (renderer *)window->drawdata; |
| 2630 | |
| 2631 | int hlsl_prescale_x = prescale_force_x; |
| 2632 | int hlsl_prescale_y = prescale_force_y; |
| 2633 | |
| 2634 | // Find the nearest prescale factor that is over our screen size |
| 2635 | if (hlsl_prescale_x == 0) |
| 2636 | { |
| 2637 | hlsl_prescale_x = 1; |
| 2638 | while (width * xscale * hlsl_prescale_x <= d3d->get_width()) |
| 2639 | { |
| 2640 | hlsl_prescale_x++; |
| 2641 | } |
| 2642 | hlsl_prescale_x--; |
| 2643 | } |
| 2644 | |
| 2645 | if (hlsl_prescale_y == 0) |
| 2646 | { |
| 2647 | hlsl_prescale_y = 1; |
| 2648 | while (height * yscale * hlsl_prescale_y <= d3d->get_height()) |
| 2649 | { |
| 2650 | hlsl_prescale_y++; |
| 2651 | } |
| 2652 | hlsl_prescale_y--; |
| 2653 | } |
| 2654 | |
| 2655 | hlsl_prescale_x = ((hlsl_prescale_x == 0) ? 1 : hlsl_prescale_x); |
| 2656 | hlsl_prescale_y = ((hlsl_prescale_y == 0) ? 1 : hlsl_prescale_y); |
| 2657 | |
| 2658 | if (!add_render_target(d3d, texture, width, height, xscale * hlsl_prescale_x, yscale * hlsl_prescale_y)) |
| 2659 | return false; |
| 2660 | |
| 2661 | options->params_dirty = true; |
| 2662 | |
| 2663 | return true; |
| 2664 | } |
| 2665 | |
| 2666 | //============================================================ |
| 2667 | // shaders::delete_resources |
| 2668 | //============================================================ |
| 2669 | |
| 2670 | void shaders::delete_resources(bool reset) |
| 2671 | { |
| 2672 | if (!master_enable || !d3dintf->post_fx_available) |
| 2673 | return; |
| 2674 | |
| 2675 | initialized = false; |
| 2676 | |
| 2677 | if(write_ini && !reset) |
| 2678 | { |
| 2679 | emu_file file(downcast<windows_options &>(window->machine().options()).screen_post_fx_dir(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); |
| 2680 | file_error filerr = open_next((renderer*)window->drawdata, file, downcast<windows_options &>(window->machine().options()).hlsl_ini_name(), "ini", 0); |
| 2681 | |
| 2682 | if (filerr != FILERR_NONE) |
| 2683 | return; |
| 2684 | |
| 2685 | file.printf("hlsl_enable %d\n", master_enable ? 1 : 0); |
| 2686 | file.printf("hlsl_prescale_x %d\n", prescale_force_x); |
| 2687 | file.printf("hlsl_prescale_y %d\n", prescale_force_y); |
| 2688 | file.printf("hlsl_preset %d\n", preset); |
| 2689 | file.printf("hlsl_snap_width %d\n", snap_width); |
| 2690 | file.printf("hlsl_snap_height %d\n", snap_height); |
| 2691 | file.printf("shadow_mask_alpha %f\n", options->shadow_mask_alpha); |
| 2692 | file.printf("shadow_mask_texture %s\n", options->shadow_mask_texture); |
| 2693 | file.printf("shadow_mask_x_count %d\n", options->shadow_mask_count_x); |
| 2694 | file.printf("shadow_mask_y_count %d\n", options->shadow_mask_count_y); |
| 2695 | file.printf("shadow_mask_usize %f\n", options->shadow_mask_u_size); |
| 2696 | file.printf("shadow_mask_vsize %f\n", options->shadow_mask_v_size); |
| 2697 | file.printf("curvature %f\n", options->curvature); |
| 2698 | file.printf("pincushion %f\n", options->pincushion); |
| 2699 | file.printf("scanline_alpha %f\n", options->scanline_alpha); |
| 2700 | file.printf("scanline_size %f\n", options->scanline_scale); |
| 2701 | file.printf("scanline_height %f\n", options->scanline_height); |
| 2702 | file.printf("scanline_bright_scale %f\n", options->scanline_bright_scale); |
| 2703 | file.printf("scanline_bright_offset %f\n", options->scanline_bright_offset); |
| 2704 | file.printf("scanline_jitter %f\n", options->scanline_offset); |
| 2705 | file.printf("defocus %f,%f\n", options->defocus[0], options->defocus[1]); |
| 2706 | file.printf("converge_x %f,%f,%f\n", options->converge_x[0], options->converge_x[1], options->converge_x[2]); |
| 2707 | file.printf("converge_y %f,%f,%f\n", options->converge_y[0], options->converge_y[1], options->converge_y[2]); |
| 2708 | file.printf("radial_converge_x %f,%f,%f\n", options->radial_converge_x[0], options->radial_converge_x[1], options->radial_converge_x[2]); |
| 2709 | file.printf("radial_converge_y %f,%f,%f\n", options->radial_converge_y[0], options->radial_converge_y[1], options->radial_converge_y[2]); |
| 2710 | file.printf("red_ratio %f,%f,%f\n", options->red_ratio[0], options->red_ratio[1], options->red_ratio[2]); |
| 2711 | file.printf("grn_ratio %f,%f,%f\n", options->grn_ratio[0], options->grn_ratio[1], options->grn_ratio[2]); |
| 2712 | file.printf("blu_ratio %f,%f,%f\n", options->blu_ratio[0], options->blu_ratio[1], options->blu_ratio[2]); |
| 2713 | file.printf("saturation %f\n", options->saturation); |
| 2714 | file.printf("offset %f,%f,%f\n", options->offset[0], options->offset[1], options->offset[2]); |
| 2715 | file.printf("scale %f,%f,%f\n", options->scale[0], options->scale[1], options->scale[2]); |
| 2716 | file.printf("power %f,%f,%f\n", options->power[0], options->power[1], options->power[2]); |
| 2717 | file.printf("floor %f,%f,%f\n", options->floor[0], options->floor[1], options->floor[2]); |
| 2718 | file.printf("phosphor_life %f,%f,%f\n", options->phosphor[0], options->phosphor[1], options->phosphor[2]); |
| 2719 | file.printf("yiq_enable %d\n", options->yiq_enable ? 1 : 0); |
| 2720 | file.printf("yiq_cc %f\n", options->yiq_cc); |
| 2721 | file.printf("yiq_a %f\n", options->yiq_a); |
| 2722 | file.printf("yiq_b %f\n", options->yiq_b); |
| 2723 | file.printf("yiq_o %f\n", options->yiq_o); |
| 2724 | file.printf("yiq_p %f\n", options->yiq_p); |
| 2725 | file.printf("yiq_n %f\n", options->yiq_n); |
| 2726 | file.printf("yiq_y %f\n", options->yiq_y); |
| 2727 | file.printf("yiq_i %f\n", options->yiq_i); |
| 2728 | file.printf("yiq_q %f\n", options->yiq_q); |
| 2729 | file.printf("yiq_scan_time %f\n", options->yiq_scan_time); |
| 2730 | file.printf("yiq_phase_count %d\n", options->yiq_phase_count); |
| 2731 | file.printf("vector_length_scale %f\n", options->vector_length_scale); |
| 2732 | file.printf("vector_length_ratio %f\n", options->vector_length_ratio); |
| 2733 | } |
| 2734 | |
| 2735 | while (targethead != NULL) |
| 2736 | { |
| 2737 | remove_render_target(targethead); |
| 2738 | } |
| 2739 | |
| 2740 | #if (HLSL_VECTOR || CRT_BLOOM) |
| 2741 | if (downsample_effect != NULL) |
| 2742 | { |
| 2743 | (*d3dintf->effect.release)(downsample_effect); |
| 2744 | downsample_effect = NULL; |
| 2745 | } |
| 2746 | if (bloom_effect != NULL) |
| 2747 | { |
| 2748 | (*d3dintf->effect.release)(bloom_effect); |
| 2749 | bloom_effect = NULL; |
| 2750 | } |
| 2751 | #endif |
| 2752 | if (default_effect != NULL) |
| 2753 | { |
| 2754 | (*d3dintf->effect.release)(default_effect); |
| 2755 | default_effect = NULL; |
| 2756 | } |
| 2757 | if (post_effect != NULL) |
| 2758 | { |
| 2759 | (*d3dintf->effect.release)(post_effect); |
| 2760 | post_effect = NULL; |
| 2761 | } |
| 2762 | if (prescale_effect != NULL) |
| 2763 | { |
| 2764 | (*d3dintf->effect.release)(prescale_effect); |
| 2765 | prescale_effect = NULL; |
| 2766 | } |
| 2767 | if (pincushion_effect != NULL) |
| 2768 | { |
| 2769 | (*d3dintf->effect.release)(pincushion_effect); |
| 2770 | pincushion_effect = NULL; |
| 2771 | } |
| 2772 | if (phosphor_effect != NULL) |
| 2773 | { |
| 2774 | (*d3dintf->effect.release)(phosphor_effect); |
| 2775 | phosphor_effect = NULL; |
| 2776 | } |
| 2777 | if (focus_effect != NULL) |
| 2778 | { |
| 2779 | (*d3dintf->effect.release)(focus_effect); |
| 2780 | focus_effect = NULL; |
| 2781 | } |
| 2782 | if (deconverge_effect != NULL) |
| 2783 | { |
| 2784 | (*d3dintf->effect.release)(deconverge_effect); |
| 2785 | deconverge_effect = NULL; |
| 2786 | } |
| 2787 | if (color_effect != NULL) |
| 2788 | { |
| 2789 | (*d3dintf->effect.release)(color_effect); |
| 2790 | color_effect = NULL; |
| 2791 | } |
| 2792 | if (yiq_encode_effect != NULL) |
| 2793 | { |
| 2794 | (*d3dintf->effect.release)(yiq_encode_effect); |
| 2795 | yiq_encode_effect = NULL; |
| 2796 | } |
| 2797 | if (yiq_decode_effect != NULL) |
| 2798 | { |
| 2799 | (*d3dintf->effect.release)(yiq_decode_effect); |
| 2800 | yiq_decode_effect = NULL; |
| 2801 | } |
| 2802 | |
| 2803 | if (black_texture != NULL) |
| 2804 | { |
| 2805 | (*d3dintf->texture.release)(black_texture); |
| 2806 | black_texture = NULL; |
| 2807 | } |
| 2808 | |
| 2809 | if (avi_copy_texture != NULL) |
| 2810 | { |
| 2811 | (*d3dintf->texture.release)(avi_copy_texture); |
| 2812 | avi_copy_texture = NULL; |
| 2813 | } |
| 2814 | |
| 2815 | if (avi_copy_surface != NULL) |
| 2816 | { |
| 2817 | (*d3dintf->surface.release)(avi_copy_surface); |
| 2818 | avi_copy_surface = NULL; |
| 2819 | } |
| 2820 | |
| 2821 | if (avi_final_texture != NULL) |
| 2822 | { |
| 2823 | (*d3dintf->texture.release)(avi_final_texture); |
| 2824 | avi_final_texture = NULL; |
| 2825 | } |
| 2826 | |
| 2827 | if (avi_final_target != NULL) |
| 2828 | { |
| 2829 | (*d3dintf->surface.release)(avi_final_target); |
| 2830 | avi_final_target = NULL; |
| 2831 | } |
| 2832 | |
| 2833 | shadow_bitmap.reset(); |
| 2834 | } |
| 2835 | |
| 2836 | |
| 2837 | //============================================================ |
| 2838 | // get_vector |
| 2839 | //============================================================ |
| 2840 | |
| 2841 | static void get_vector(const char *data, int count, float *out, int report_error) |
| 2842 | { |
| 2843 | if (count > 3) |
| 2844 | { |
| 2845 | if (sscanf(data, "%f,%f,%f,%f", &out[0], &out[1], &out[2], &out[3]) < 4 && report_error) |
| 2846 | mame_printf_error("Illegal quad vector value = %s\n", data); |
| 2847 | } |
| 2848 | else if(count > 2) |
| 2849 | { |
| 2850 | if (sscanf(data, "%f,%f,%f", &out[0], &out[1], &out[2]) < 3 && report_error) |
| 2851 | mame_printf_error("Illegal triple vector value = %s\n", data); |
| 2852 | } |
| 2853 | else if(count > 1) |
| 2854 | { |
| 2855 | if (sscanf(data, "%f,%f", &out[0], &out[1]) < 2 && report_error) |
| 2856 | mame_printf_error("Illegal double vector value = %s\n", data); |
| 2857 | } |
| 2858 | else if(count > 0) |
| 2859 | { |
| 2860 | if (sscanf(data, "%f", &out[0]) < 1 && report_error) |
| 2861 | mame_printf_error("Illegal single vector value = %s\n", data); |
| 2862 | } |
| 2863 | } |
| 2864 | |
| 2865 | |
| 2866 | /*------------------------------------------------- |
| 2867 | slider_alloc - allocate a new slider entry |
| 2868 | currently duplicated from ui.c, this could |
| 2869 | be done in a more ideal way. |
| 2870 | -------------------------------------------------*/ |
| 2871 | |
| 2872 | static slider_state *slider_alloc(running_machine &machine, const char *title, INT32 minval, INT32 defval, INT32 maxval, INT32 incval, slider_update update, void *arg) |
| 2873 | { |
| 2874 | int size = sizeof(slider_state) + strlen(title); |
| 2875 | slider_state *state = (slider_state *)auto_alloc_array_clear(machine, UINT8, size); |
| 2876 | |
| 2877 | state->minval = minval; |
| 2878 | state->defval = defval; |
| 2879 | state->maxval = maxval; |
| 2880 | state->incval = incval; |
| 2881 | state->update = update; |
| 2882 | state->arg = arg; |
| 2883 | strcpy(state->description, title); |
| 2884 | |
| 2885 | return state; |
| 2886 | } |
| 2887 | |
| 2888 | |
| 2889 | //============================================================ |
| 2890 | // assorted global slider accessors |
| 2891 | //============================================================ |
| 2892 | |
| 2893 | static INT32 slider_set(float *option, float scale, const char *fmt, astring *string, INT32 newval) |
| 2894 | { |
| 2895 | if (option != NULL && newval != SLIDER_NOCHANGE) *option = (float)newval * scale; |
| 2896 | if (string != NULL) string->printf(fmt, *option); |
| 2897 | return floor(*option / scale + 0.5f); |
| 2898 | } |
| 2899 | |
| 2900 | static INT32 slider_shadow_mask_alpha(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 2901 | { |
| 2902 | return slider_set(&(((hlsl_options*)arg)->shadow_mask_alpha), 0.01f, "%2.2f", string, newval); |
| 2903 | } |
| 2904 | |
| 2905 | static INT32 slider_shadow_mask_x_count(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 2906 | { |
| 2907 | hlsl_options *options = (hlsl_options*)arg; |
| 2908 | if (newval != SLIDER_NOCHANGE) options->shadow_mask_count_x = newval; |
| 2909 | if (string != NULL) string->printf("%d", options->shadow_mask_count_x); |
| 2910 | options->params_dirty = true; |
| 2911 | return options->shadow_mask_count_x; |
| 2912 | } |
| 2913 | |
| 2914 | static INT32 slider_shadow_mask_y_count(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 2915 | { |
| 2916 | hlsl_options *options = (hlsl_options*)arg; |
| 2917 | if (newval != SLIDER_NOCHANGE) options->shadow_mask_count_y = newval; |
| 2918 | if (string != NULL) string->printf("%d", options->shadow_mask_count_y); |
| 2919 | options->params_dirty = true; |
| 2920 | return options->shadow_mask_count_y; |
| 2921 | } |
| 2922 | |
| 2923 | static INT32 slider_shadow_mask_usize(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 2924 | { |
| 2925 | ((hlsl_options*)arg)->params_dirty = true; |
| 2926 | return slider_set(&(((hlsl_options*)arg)->shadow_mask_u_size), 1.0f / 32.0f, "%2.5f", string, newval); |
| 2927 | } |
| 2928 | |
| 2929 | static INT32 slider_shadow_mask_vsize(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 2930 | { |
| 2931 | ((hlsl_options*)arg)->params_dirty = true; |
| 2932 | return slider_set(&(((hlsl_options*)arg)->shadow_mask_v_size), 1.0f / 32.0f, "%2.5f", string, newval); |
| 2933 | } |
| 2934 | |
| 2935 | static INT32 slider_curvature(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 2936 | { |
| 2937 | ((hlsl_options*)arg)->params_dirty = true; |
| 2938 | return slider_set(&(((hlsl_options*)arg)->curvature), 0.01f, "%2.2f", string, newval); |
| 2939 | } |
| 2940 | |
| 2941 | static INT32 slider_pincushion(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 2942 | { |
| 2943 | ((hlsl_options*)arg)->params_dirty = true; |
| 2944 | return slider_set(&(((hlsl_options*)arg)->pincushion), 0.01f, "%2.2f", string, newval); |
| 2945 | } |
| 2946 | |
| 2947 | static INT32 slider_scanline_alpha(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 2948 | { |
| 2949 | ((hlsl_options*)arg)->params_dirty = true; |
| 2950 | return slider_set(&(((hlsl_options*)arg)->scanline_alpha), 0.01f, "%2.2f", string, newval); |
| 2951 | } |
| 2952 | |
| 2953 | static INT32 slider_scanline_scale(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 2954 | { |
| 2955 | ((hlsl_options*)arg)->params_dirty = true; |
| 2956 | return slider_set(&(((hlsl_options*)arg)->scanline_scale), 0.05f, "%2.2f", string, newval); |
| 2957 | } |
| 2958 | |
| 2959 | static INT32 slider_scanline_height(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 2960 | { |
| 2961 | ((hlsl_options*)arg)->params_dirty = true; |
| 2962 | return slider_set(&(((hlsl_options*)arg)->scanline_height), 0.05f, "%2.2f", string, newval); |
| 2963 | } |
| 2964 | |
| 2965 | static INT32 slider_scanline_bright_scale(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 2966 | { |
| 2967 | ((hlsl_options*)arg)->params_dirty = true; |
| 2968 | return slider_set(&(((hlsl_options*)arg)->scanline_bright_scale), 0.05f, "%2.2f", string, newval); |
| 2969 | } |
| 2970 | |
| 2971 | static INT32 slider_scanline_bright_offset(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 2972 | { |
| 2973 | ((hlsl_options*)arg)->params_dirty = true; |
| 2974 | return slider_set(&(((hlsl_options*)arg)->scanline_bright_offset), 0.05f, "%2.2f", string, newval); |
| 2975 | } |
| 2976 | |
| 2977 | static INT32 slider_scanline_offset(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 2978 | { |
| 2979 | ((hlsl_options*)arg)->params_dirty = true; |
| 2980 | return slider_set(&(((hlsl_options*)arg)->scanline_offset), 0.05f, "%2.2f", string, newval); |
| 2981 | } |
| 2982 | |
| 2983 | static INT32 slider_defocus_x(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 2984 | { |
| 2985 | ((hlsl_options*)arg)->params_dirty = true; |
| 2986 | return slider_set(&(((hlsl_options*)arg)->defocus[0]), 0.5f, "%2.1f", string, newval); |
| 2987 | } |
| 2988 | |
| 2989 | static INT32 slider_defocus_y(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 2990 | { |
| 2991 | ((hlsl_options*)arg)->params_dirty = true; |
| 2992 | return slider_set(&(((hlsl_options*)arg)->defocus[1]), 0.5f, "%2.1f", string, newval); |
| 2993 | } |
| 2994 | |
| 2995 | static INT32 slider_red_converge_x(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 2996 | { |
| 2997 | ((hlsl_options*)arg)->params_dirty = true; |
| 2998 | return slider_set(&(((hlsl_options*)arg)->converge_x[0]), 0.1f, "%3.1f", string, newval); |
| 2999 | } |
| 3000 | |
| 3001 | static INT32 slider_red_converge_y(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3002 | { |
| 3003 | ((hlsl_options*)arg)->params_dirty = true; |
| 3004 | return slider_set(&(((hlsl_options*)arg)->converge_y[0]), 0.1f, "%3.1f", string, newval); |
| 3005 | } |
| 3006 | |
| 3007 | static INT32 slider_green_converge_x(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3008 | { |
| 3009 | ((hlsl_options*)arg)->params_dirty = true; |
| 3010 | return slider_set(&(((hlsl_options*)arg)->converge_x[1]), 0.1f, "%3.1f", string, newval); |
| 3011 | } |
| 3012 | |
| 3013 | static INT32 slider_green_converge_y(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3014 | { |
| 3015 | ((hlsl_options*)arg)->params_dirty = true; |
| 3016 | return slider_set(&(((hlsl_options*)arg)->converge_y[1]), 0.1f, "%3.1f", string, newval); |
| 3017 | } |
| 3018 | |
| 3019 | static INT32 slider_blue_converge_x(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3020 | { |
| 3021 | ((hlsl_options*)arg)->params_dirty = true; |
| 3022 | return slider_set(&(((hlsl_options*)arg)->converge_x[2]), 0.1f, "%3.1f", string, newval); |
| 3023 | } |
| 3024 | |
| 3025 | static INT32 slider_blue_converge_y(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3026 | { |
| 3027 | ((hlsl_options*)arg)->params_dirty = true; |
| 3028 | return slider_set(&(((hlsl_options*)arg)->converge_y[2]), 0.1f, "%3.1f", string, newval); |
| 3029 | } |
| 3030 | |
| 3031 | static INT32 slider_red_radial_converge_x(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3032 | { |
| 3033 | ((hlsl_options*)arg)->params_dirty = true; |
| 3034 | return slider_set(&(((hlsl_options*)arg)->radial_converge_x[0]), 0.1f, "%3.1f", string, newval); |
| 3035 | } |
| 3036 | |
| 3037 | static INT32 slider_red_radial_converge_y(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3038 | { |
| 3039 | ((hlsl_options*)arg)->params_dirty = true; |
| 3040 | return slider_set(&(((hlsl_options*)arg)->radial_converge_y[0]), 0.1f, "%3.1f", string, newval); |
| 3041 | } |
| 3042 | |
| 3043 | static INT32 slider_green_radial_converge_x(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3044 | { |
| 3045 | ((hlsl_options*)arg)->params_dirty = true; |
| 3046 | return slider_set(&(((hlsl_options*)arg)->radial_converge_x[1]), 0.1f, "%3.1f", string, newval); |
| 3047 | } |
| 3048 | |
| 3049 | static INT32 slider_green_radial_converge_y(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3050 | { |
| 3051 | ((hlsl_options*)arg)->params_dirty = true; |
| 3052 | return slider_set(&(((hlsl_options*)arg)->radial_converge_y[1]), 0.1f, "%3.1f", string, newval); |
| 3053 | } |
| 3054 | |
| 3055 | static INT32 slider_blue_radial_converge_x(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3056 | { |
| 3057 | ((hlsl_options*)arg)->params_dirty = true; |
| 3058 | return slider_set(&(((hlsl_options*)arg)->radial_converge_x[2]), 0.1f, "%3.1f", string, newval); |
| 3059 | } |
| 3060 | |
| 3061 | static INT32 slider_blue_radial_converge_y(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3062 | { |
| 3063 | ((hlsl_options*)arg)->params_dirty = true; |
| 3064 | return slider_set(&(((hlsl_options*)arg)->radial_converge_y[2]), 0.1f, "%3.1f", string, newval); |
| 3065 | } |
| 3066 | |
| 3067 | static INT32 slider_red_from_r(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3068 | { |
| 3069 | ((hlsl_options*)arg)->params_dirty = true; |
| 3070 | return slider_set(&(((hlsl_options*)arg)->red_ratio[0]), 0.005f, "%2.3f", string, newval); |
| 3071 | } |
| 3072 | |
| 3073 | static INT32 slider_red_from_g(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3074 | { |
| 3075 | ((hlsl_options*)arg)->params_dirty = true; |
| 3076 | return slider_set(&(((hlsl_options*)arg)->red_ratio[1]), 0.005f, "%2.3f", string, newval); |
| 3077 | } |
| 3078 | |
| 3079 | static INT32 slider_red_from_b(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3080 | { |
| 3081 | ((hlsl_options*)arg)->params_dirty = true; |
| 3082 | return slider_set(&(((hlsl_options*)arg)->red_ratio[2]), 0.005f, "%2.3f", string, newval); |
| 3083 | } |
| 3084 | |
| 3085 | static INT32 slider_green_from_r(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3086 | { |
| 3087 | ((hlsl_options*)arg)->params_dirty = true; |
| 3088 | return slider_set(&(((hlsl_options*)arg)->grn_ratio[0]), 0.005f, "%2.3f", string, newval); |
| 3089 | } |
| 3090 | |
| 3091 | static INT32 slider_green_from_g(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3092 | { |
| 3093 | ((hlsl_options*)arg)->params_dirty = true; |
| 3094 | return slider_set(&(((hlsl_options*)arg)->grn_ratio[1]), 0.005f, "%2.3f", string, newval); |
| 3095 | } |
| 3096 | |
| 3097 | static INT32 slider_green_from_b(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3098 | { |
| 3099 | ((hlsl_options*)arg)->params_dirty = true; |
| 3100 | return slider_set(&(((hlsl_options*)arg)->grn_ratio[2]), 0.005f, "%2.3f", string, newval); |
| 3101 | } |
| 3102 | |
| 3103 | static INT32 slider_blue_from_r(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3104 | { |
| 3105 | ((hlsl_options*)arg)->params_dirty = true; |
| 3106 | return slider_set(&(((hlsl_options*)arg)->blu_ratio[0]), 0.005f, "%2.3f", string, newval); |
| 3107 | } |
| 3108 | |
| 3109 | static INT32 slider_blue_from_g(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3110 | { |
| 3111 | ((hlsl_options*)arg)->params_dirty = true; |
| 3112 | return slider_set(&(((hlsl_options*)arg)->blu_ratio[1]), 0.005f, "%2.3f", string, newval); |
| 3113 | } |
| 3114 | |
| 3115 | static INT32 slider_blue_from_b(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3116 | { |
| 3117 | ((hlsl_options*)arg)->params_dirty = true; |
| 3118 | return slider_set(&(((hlsl_options*)arg)->blu_ratio[2]), 0.005f, "%2.3f", string, newval); |
| 3119 | } |
| 3120 | |
| 3121 | static INT32 slider_red_offset(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3122 | { |
| 3123 | ((hlsl_options*)arg)->params_dirty = true; |
| 3124 | return slider_set(&(((hlsl_options*)arg)->offset[0]), 0.01f, "%2.2f", string, newval); |
| 3125 | } |
| 3126 | |
| 3127 | static INT32 slider_green_offset(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3128 | { |
| 3129 | ((hlsl_options*)arg)->params_dirty = true; |
| 3130 | return slider_set(&(((hlsl_options*)arg)->offset[1]), 0.01f, "%2.2f", string, newval); |
| 3131 | } |
| 3132 | |
| 3133 | static INT32 slider_blue_offset(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3134 | { |
| 3135 | ((hlsl_options*)arg)->params_dirty = true; |
| 3136 | return slider_set(&(((hlsl_options*)arg)->offset[2]), 0.01f, "%2.2f", string, newval); |
| 3137 | } |
| 3138 | |
| 3139 | static INT32 slider_red_scale(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3140 | { |
| 3141 | ((hlsl_options*)arg)->params_dirty = true; |
| 3142 | return slider_set(&(((hlsl_options*)arg)->scale[0]), 0.01f, "%2.2f", string, newval); |
| 3143 | } |
| 3144 | |
| 3145 | static INT32 slider_green_scale(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3146 | { |
| 3147 | ((hlsl_options*)arg)->params_dirty = true; |
| 3148 | return slider_set(&(((hlsl_options*)arg)->scale[1]), 0.01f, "%2.2f", string, newval); |
| 3149 | } |
| 3150 | |
| 3151 | static INT32 slider_blue_scale(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3152 | { |
| 3153 | ((hlsl_options*)arg)->params_dirty = true; |
| 3154 | return slider_set(&(((hlsl_options*)arg)->scale[2]), 0.01f, "%2.2f", string, newval); |
| 3155 | } |
| 3156 | |
| 3157 | static INT32 slider_red_power(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3158 | { |
| 3159 | ((hlsl_options*)arg)->params_dirty = true; |
| 3160 | return slider_set(&(((hlsl_options*)arg)->power[0]), 0.05f, "%2.2f", string, newval); |
| 3161 | } |
| 3162 | |
| 3163 | static INT32 slider_green_power(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3164 | { |
| 3165 | ((hlsl_options*)arg)->params_dirty = true; |
| 3166 | return slider_set(&(((hlsl_options*)arg)->power[1]), 0.05f, "%2.2f", string, newval); |
| 3167 | } |
| 3168 | |
| 3169 | static INT32 slider_blue_power(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3170 | { |
| 3171 | ((hlsl_options*)arg)->params_dirty = true; |
| 3172 | return slider_set(&(((hlsl_options*)arg)->power[2]), 0.05f, "%2.2f", string, newval); |
| 3173 | } |
| 3174 | |
| 3175 | static INT32 slider_red_floor(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3176 | { |
| 3177 | ((hlsl_options*)arg)->params_dirty = true; |
| 3178 | return slider_set(&(((hlsl_options*)arg)->floor[0]), 0.01f, "%2.2f", string, newval); |
| 3179 | } |
| 3180 | |
| 3181 | static INT32 slider_green_floor(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3182 | { |
| 3183 | ((hlsl_options*)arg)->params_dirty = true; |
| 3184 | return slider_set(&(((hlsl_options*)arg)->floor[1]), 0.01f, "%2.2f", string, newval); |
| 3185 | } |
| 3186 | |
| 3187 | static INT32 slider_blue_floor(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3188 | { |
| 3189 | ((hlsl_options*)arg)->params_dirty = true; |
| 3190 | return slider_set(&(((hlsl_options*)arg)->floor[2]), 0.01f, "%2.2f", string, newval); |
| 3191 | } |
| 3192 | |
| 3193 | static INT32 slider_red_phosphor_life(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3194 | { |
| 3195 | ((hlsl_options*)arg)->params_dirty = true; |
| 3196 | return slider_set(&(((hlsl_options*)arg)->phosphor[0]), 0.01f, "%2.2f", string, newval); |
| 3197 | } |
| 3198 | |
| 3199 | static INT32 slider_green_phosphor_life(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3200 | { |
| 3201 | ((hlsl_options*)arg)->params_dirty = true; |
| 3202 | return slider_set(&(((hlsl_options*)arg)->phosphor[1]), 0.01f, "%2.2f", string, newval); |
| 3203 | } |
| 3204 | |
| 3205 | static INT32 slider_blue_phosphor_life(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3206 | { |
| 3207 | ((hlsl_options*)arg)->params_dirty = true; |
| 3208 | return slider_set(&(((hlsl_options*)arg)->phosphor[2]), 0.01f, "%2.2f", string, newval); |
| 3209 | } |
| 3210 | |
| 3211 | static INT32 slider_saturation(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3212 | { |
| 3213 | ((hlsl_options*)arg)->params_dirty = true; |
| 3214 | return slider_set(&(((hlsl_options*)arg)->saturation), 0.01f, "%2.2f", string, newval); |
| 3215 | } |
| 3216 | |
| 3217 | static INT32 slider_vector_attenuation(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3218 | { |
| 3219 | ((hlsl_options*)arg)->params_dirty = true; |
| 3220 | return slider_set(&(((hlsl_options*)arg)->vector_length_scale), 0.01f, "%1.2f", string, newval); |
| 3221 | } |
| 3222 | |
| 3223 | static INT32 slider_vector_length_max(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3224 | { |
| 3225 | ((hlsl_options*)arg)->params_dirty = true; |
| 3226 | return slider_set(&(((hlsl_options*)arg)->vector_length_ratio), 1.0f, "%4f", string, newval); |
| 3227 | } |
| 3228 | |
| 3229 | static INT32 slider_vector_bloom_scale(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3230 | { |
| 3231 | ((hlsl_options*)arg)->params_dirty = true; |
| 3232 | return slider_set(&(((hlsl_options*)arg)->vector_bloom_scale), 0.001f, "%1.3f", string, newval); |
| 3233 | } |
| 3234 | |
| 3235 | static INT32 slider_raster_bloom_scale(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3236 | { |
| 3237 | ((hlsl_options*)arg)->params_dirty = true; |
| 3238 | return slider_set(&(((hlsl_options*)arg)->raster_bloom_scale), 0.001f, "%1.3f", string, newval); |
| 3239 | } |
| 3240 | |
| 3241 | static INT32 slider_bloom_lvl0_scale(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3242 | { |
| 3243 | ((hlsl_options*)arg)->params_dirty = true; |
| 3244 | return slider_set(&(((hlsl_options*)arg)->bloom_level0_weight), 0.01f, "%1.2f", string, newval); |
| 3245 | } |
| 3246 | |
| 3247 | static INT32 slider_bloom_lvl1_scale(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3248 | { |
| 3249 | ((hlsl_options*)arg)->params_dirty = true; |
| 3250 | return slider_set(&(((hlsl_options*)arg)->bloom_level1_weight), 0.01f, "%1.2f", string, newval); |
| 3251 | } |
| 3252 | |
| 3253 | static INT32 slider_bloom_lvl2_scale(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3254 | { |
| 3255 | ((hlsl_options*)arg)->params_dirty = true; |
| 3256 | return slider_set(&(((hlsl_options*)arg)->bloom_level2_weight), 0.01f, "%1.2f", string, newval); |
| 3257 | } |
| 3258 | |
| 3259 | static INT32 slider_bloom_lvl3_scale(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3260 | { |
| 3261 | ((hlsl_options*)arg)->params_dirty = true; |
| 3262 | return slider_set(&(((hlsl_options*)arg)->bloom_level3_weight), 0.01f, "%1.2f", string, newval); |
| 3263 | } |
| 3264 | |
| 3265 | static INT32 slider_bloom_lvl4_scale(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3266 | { |
| 3267 | ((hlsl_options*)arg)->params_dirty = true; |
| 3268 | return slider_set(&(((hlsl_options*)arg)->bloom_level4_weight), 0.01f, "%1.2f", string, newval); |
| 3269 | } |
| 3270 | |
| 3271 | static INT32 slider_bloom_lvl5_scale(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3272 | { |
| 3273 | ((hlsl_options*)arg)->params_dirty = true; |
| 3274 | return slider_set(&(((hlsl_options*)arg)->bloom_level5_weight), 0.01f, "%1.2f", string, newval); |
| 3275 | } |
| 3276 | |
| 3277 | static INT32 slider_bloom_lvl6_scale(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3278 | { |
| 3279 | ((hlsl_options*)arg)->params_dirty = true; |
| 3280 | return slider_set(&(((hlsl_options*)arg)->bloom_level6_weight), 0.01f, "%1.2f", string, newval); |
| 3281 | } |
| 3282 | |
| 3283 | static INT32 slider_bloom_lvl7_scale(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3284 | { |
| 3285 | ((hlsl_options*)arg)->params_dirty = true; |
| 3286 | return slider_set(&(((hlsl_options*)arg)->bloom_level7_weight), 0.01f, "%1.2f", string, newval); |
| 3287 | } |
| 3288 | |
| 3289 | static INT32 slider_bloom_lvl8_scale(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3290 | { |
| 3291 | ((hlsl_options*)arg)->params_dirty = true; |
| 3292 | return slider_set(&(((hlsl_options*)arg)->bloom_level8_weight), 0.01f, "%1.2f", string, newval); |
| 3293 | } |
| 3294 | |
| 3295 | static INT32 slider_bloom_lvl9_scale(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3296 | { |
| 3297 | ((hlsl_options*)arg)->params_dirty = true; |
| 3298 | return slider_set(&(((hlsl_options*)arg)->bloom_level9_weight), 0.01f, "%1.2f", string, newval); |
| 3299 | } |
| 3300 | |
| 3301 | static INT32 slider_bloom_lvl10_scale(running_machine &machine, void *arg, astring *string, INT32 newval) |
| 3302 | { |
| 3303 | ((hlsl_options*)arg)->params_dirty = true; |
| 3304 | return slider_set(&(((hlsl_options*)arg)->bloom_level10_weight), 0.01f, "%1.2f", string, newval); |
| 3305 | } |
| 3306 | |
| 3307 | //============================================================ |
| 3308 | // init_slider_list |
| 3309 | //============================================================ |
| 3310 | |
| 3311 | shaders::slider_desc shaders::s_sliders[] = |
| 3312 | { |
| 3313 | { "Shadow Mask Darkness", 0, 0, 100, 1, slider_shadow_mask_alpha }, |
| 3314 | { "Shadow Mask X Count", 1, 320, 1024, 1, slider_shadow_mask_x_count }, |
| 3315 | { "Shadow Mask Y Count", 1, 240, 1024, 1, slider_shadow_mask_y_count }, |
| 3316 | { "Shadow Mask Pixel Count X", 1, 6, 64, 1, slider_shadow_mask_usize }, |
| 3317 | { "Shadow Mask Pixel Count Y", 1, 7, 64, 1, slider_shadow_mask_vsize }, |
| 3318 | { "Shadow Mask Pixel Count Y", 1, 7, 64, 1, slider_shadow_mask_vsize }, |
| 3319 | { "Shadow Mask Pixel Count Y", 1, 7, 64, 1, slider_shadow_mask_vsize }, |
| 3320 | { "Shadow Mask Pixel Count Y", 1, 7, 64, 1, slider_shadow_mask_vsize }, |
| 3321 | { "Screen Curvature", 0, 3, 100, 1, slider_curvature }, |
| 3322 | { "Image Pincushion", 0, 3, 100, 1, slider_pincushion }, |
| 3323 | { "Scanline Darkness", 0, 100, 100, 1, slider_scanline_alpha }, |
| 3324 | { "Scanline Screen Height", 1, 20, 80, 1, slider_scanline_scale }, |
| 3325 | { "Scanline Indiv. Height", 1, 20, 80, 1, slider_scanline_height }, |
| 3326 | { "Scanline Brightness", 0, 20, 40, 1, slider_scanline_bright_scale }, |
| 3327 | { "Scanline Brightness Overdrive", 0, 0, 20, 1, slider_scanline_bright_offset }, |
| 3328 | { "Scanline Jitter", 0, 0, 40, 1, slider_scanline_offset }, |
| 3329 | { "Defocus X", 0, 0, 64, 1, slider_defocus_x }, |
| 3330 | { "Defocus Y", 0, 0, 64, 1, slider_defocus_y }, |
| 3331 | { "Red Position Offset X", -1500, 3, 1500, 1, slider_red_converge_x }, |
| 3332 | { "Red Position Offset Y", -1500, 0, 1500, 1, slider_red_converge_y }, |
| 3333 | { "Green Position Offset X", -1500, 0, 1500, 1, slider_green_converge_x }, |
| 3334 | { "Green Position Offset Y", -1500, 3, 1500, 1, slider_green_converge_y }, |
| 3335 | { "Blue Position Offset X", -1500, 3, 1500, 1, slider_blue_converge_x }, |
| 3336 | { "Blue Position Offset Y", -1500, 3, 1500, 1, slider_blue_converge_y }, |
| 3337 | { "Red Convergence X", -1500, 0, 1500, 1, slider_red_radial_converge_x }, |
| 3338 | { "Red Convergence Y", -1500, 0, 1500, 1, slider_red_radial_converge_y }, |
| 3339 | { "Green Convergence X", -1500, 0, 1500, 1, slider_green_radial_converge_x }, |
| 3340 | { "Green Convergence Y", -1500, 0, 1500, 1, slider_green_radial_converge_y }, |
| 3341 | { "Blue Convergence X", -1500, 0, 1500, 1, slider_blue_radial_converge_x }, |
| 3342 | { "Blue Convergence Y", -1500, 0, 1500, 1, slider_blue_radial_converge_y }, |
| 3343 | { "Red Output from Red Input", -400, 0, 400, 5, slider_red_from_r }, |
| 3344 | { "Red Output from Green Input", -400, 0, 400, 5, slider_red_from_g }, |
| 3345 | { "Red Output from Blue Input", -400, 0, 400, 5, slider_red_from_b }, |
| 3346 | { "Green Output from Red Input", -400, 0, 400, 5, slider_green_from_r }, |
| 3347 | { "Green Output from Green Input", -400, 0, 400, 5, slider_green_from_g }, |
| 3348 | { "Green Output from Blue Input", -400, 0, 400, 5, slider_green_from_b }, |
| 3349 | { "Blue Output from Red Input", -400, 0, 400, 5, slider_blue_from_r }, |
| 3350 | { "Blue Output from Green Input", -400, 0, 400, 5, slider_blue_from_g }, |
| 3351 | { "Blue Output from Blue Input", -400, 0, 400, 5, slider_blue_from_b }, |
| 3352 | { "Saturation", 0, 140, 400, 1, slider_saturation }, |
| 3353 | { "Red DC Offset", -100, 0, 100, 1, slider_red_offset }, |
| 3354 | { "Green DC Offset", -100, 0, 100, 1, slider_green_offset }, |
| 3355 | { "Blue DC Offset", -100, 0, 100, 1, slider_blue_offset }, |
| 3356 | { "Red Scale", -200, 95, 200, 1, slider_red_scale }, |
| 3357 | { "Green Scale", -200, 95, 200, 1, slider_green_scale }, |
| 3358 | { "Blue Scale", -200, 95, 200, 1, slider_blue_scale }, |
| 3359 | { "Red Gamma", -80, 16, 80, 1, slider_red_power }, |
| 3360 | { "Green Gamma", -80, 16, 80, 1, slider_green_power }, |
| 3361 | { "Blue Gamma", -80, 16, 80, 1, slider_blue_power }, |
| 3362 | { "Red Floor", 0, 5, 100, 1, slider_red_floor }, |
| 3363 | { "Green Floor", 0, 5, 100, 1, slider_green_floor }, |
| 3364 | { "Blue Floor", 0, 5, 100, 1, slider_blue_floor }, |
| 3365 | { "Red Phosphor Life", 0, 40, 100, 1, slider_red_phosphor_life }, |
| 3366 | { "Green Phosphor Life", 0, 40, 100, 1, slider_green_phosphor_life }, |
| 3367 | { "Blue Phosphor Life", 0, 40, 100, 1, slider_blue_phosphor_life }, |
| 3368 | { "Vector Length Attenuation", 0, 80, 100, 1, slider_vector_attenuation }, |
| 3369 | { "Vector Attenuation Length Limit", 1, 500, 1000, 1, slider_vector_length_max }, |
| 3370 | { "Vector Bloom Scale", 0, 300, 1000, 5, slider_vector_bloom_scale }, |
| 3371 | { "Raster Bloom Scale", 0, 225, 1000, 5, slider_raster_bloom_scale }, |
| 3372 | { "Bloom Level 0 Scale", 0, 100, 100, 1, slider_bloom_lvl0_scale }, |
| 3373 | { "Bloom Level 1 Scale", 0, 21, 100, 1, slider_bloom_lvl1_scale }, |
| 3374 | { "Bloom Level 2 Scale", 0, 19, 100, 1, slider_bloom_lvl2_scale }, |
| 3375 | { "Bloom Level 3 Scale", 0, 17, 100, 1, slider_bloom_lvl3_scale }, |
| 3376 | { "Bloom Level 4 Scale", 0, 15, 100, 1, slider_bloom_lvl4_scale }, |
| 3377 | { "Bloom Level 5 Scale", 0, 14, 100, 1, slider_bloom_lvl5_scale }, |
| 3378 | { "Bloom Level 6 Scale", 0, 13, 100, 1, slider_bloom_lvl6_scale }, |
| 3379 | { "Bloom Level 7 Scale", 0, 12, 100, 1, slider_bloom_lvl7_scale }, |
| 3380 | { "Bloom Level 8 Scale", 0, 11, 100, 1, slider_bloom_lvl8_scale }, |
| 3381 | { "Bloom Level 9 Scale", 0, 10, 100, 1, slider_bloom_lvl9_scale }, |
| 3382 | { "Bloom Level 10 Scale", 0, 9, 100, 1, slider_bloom_lvl10_scale }, |
| 3383 | { NULL, 0, 0, 0, 0, NULL }, |
| 3384 | }; |
| 3385 | |
| 3386 | slider_state *shaders::init_slider_list() |
| 3387 | { |
| 3388 | if (!master_enable || !d3dintf->post_fx_available) |
| 3389 | { |
| 3390 | g_slider_list = NULL; |
| 3391 | return NULL; |
| 3392 | } |
| 3393 | |
| 3394 | slider_state *listhead = NULL; |
| 3395 | slider_state **tailptr = &listhead; |
| 3396 | |
| 3397 | for (int index = 0; s_sliders[index].name != NULL; index++) |
| 3398 | { |
| 3399 | slider_desc *slider = &s_sliders[index]; |
| 3400 | *tailptr = slider_alloc(window->machine(), slider->name, slider->minval, slider->defval, slider->maxval, slider->step, slider->adjustor, (void*)options); |
| 3401 | tailptr = &(*tailptr)->next; |
| 3402 | } |
| 3403 | |
| 3404 | return listhead; |
| 3405 | } |
| 3406 | |
| 3407 | }; |
| 3408 | |
| 3409 | //============================================================ |
| 3410 | // get_slider_list |
| 3411 | //============================================================ |
| 3412 | |
| 3413 | void *windows_osd_interface::get_slider_list() |
| 3414 | { |
| 3415 | return (void*)g_slider_list; |
| 3416 | } |
| 3417 | |
| 3418 | |
| 3419 | |
| 3420 | // NOTE: The function below is taken directly from src/emu/video.c and should likely be moved into a global helper function. |
| 3421 | //------------------------------------------------- |
| 3422 | // open_next - open the next non-existing file of |
| 3423 | // type filetype according to our numbering |
| 3424 | // scheme |
| 3425 | //------------------------------------------------- |
| 3426 | |
| 3427 | static file_error open_next(d3d::renderer *d3d, emu_file &file, const char *templ, const char *extension, int idx) |
| 3428 | { |
| 3429 | UINT32 origflags = file.openflags(); |
| 3430 | |
| 3431 | // handle defaults |
| 3432 | const char *snapname = templ ? templ : d3d->get_window()->machine().options().snap_name(); |
| 3433 | |
| 3434 | if (snapname == NULL || snapname[0] == 0) |
| 3435 | snapname = "%g/%i"; |
| 3436 | astring snapstr(snapname); |
| 3437 | |
| 3438 | // strip any extension in the provided name |
| 3439 | int index = snapstr.rchr(0, '.'); |
| 3440 | if (index != -1) |
| 3441 | snapstr.substr(0, index); |
| 3442 | |
| 3443 | // handle %d in the template (for image devices) |
| 3444 | astring snapdev("%d_"); |
| 3445 | int pos = snapstr.find(0, snapdev); |
| 3446 | |
| 3447 | if (pos != -1) |
| 3448 | { |
| 3449 | // if more %d are found, revert to default and ignore them all |
| 3450 | if (snapstr.find(pos + 3, snapdev) != -1) |
| 3451 | snapstr.cpy("%g/%i"); |
| 3452 | // else if there is a single %d, try to create the correct snapname |
| 3453 | else |
| 3454 | { |
| 3455 | int name_found = 0; |
| 3456 | |
| 3457 | // find length of the device name |
| 3458 | int end1 = snapstr.find(pos + 3, "/"); |
| 3459 | int end2 = snapstr.find(pos + 3, "%"); |
| 3460 | int end = -1; |
| 3461 | |
| 3462 | if ((end1 != -1) && (end2 != -1)) |
| 3463 | end = MIN(end1, end2); |
| 3464 | else if (end1 != -1) |
| 3465 | end = end1; |
| 3466 | else if (end2 != -1) |
| 3467 | end = end2; |
| 3468 | else |
| 3469 | end = snapstr.len(); |
| 3470 | |
| 3471 | if (end - pos < 3) |
| 3472 | fatalerror("Something very wrong is going on!!!\n"); |
| 3473 | |
| 3474 | // copy the device name to an astring |
| 3475 | astring snapdevname; |
| 3476 | snapdevname.cpysubstr(snapstr, pos + 3, end - pos - 3); |
| 3477 | |
| 3478 | // verify that there is such a device for this system |
| 3479 | image_interface_iterator iter(d3d->get_window()->machine().root_device()); |
| 3480 | for (device_image_interface *image = iter.first(); image != NULL; iter.next()) |
| 3481 | { |
| 3482 | // get the device name |
| 3483 | astring tempdevname(image->brief_instance_name()); |
| 3484 | |
| 3485 | if (snapdevname.cmp(tempdevname) == 0) |
| 3486 | { |
| 3487 | // verify that such a device has an image mounted |
| 3488 | if (image->basename() != NULL) |
| 3489 | { |
| 3490 | astring filename(image->basename()); |
| 3491 | |
| 3492 | // strip extension |
| 3493 | filename.substr(0, filename.rchr(0, '.')); |
| 3494 | |
| 3495 | // setup snapname and remove the %d_ |
| 3496 | snapstr.replace(0, snapdevname, filename); |
| 3497 | snapstr.del(pos, 3); |
| 3498 | |
| 3499 | name_found = 1; |
| 3500 | } |
| 3501 | } |
| 3502 | } |
| 3503 | |
| 3504 | // or fallback to default |
| 3505 | if (name_found == 0) |
| 3506 | snapstr.cpy("%g/%i"); |
| 3507 | } |
| 3508 | } |
| 3509 | |
| 3510 | // add our own index |
| 3511 | // add our own extension |
| 3512 | snapstr.cat(".").cat(extension); |
| 3513 | |
| 3514 | // substitute path and gamename up front |
| 3515 | snapstr.replace(0, "/", PATH_SEPARATOR); |
| 3516 | snapstr.replace(0, "%g", d3d->get_window()->machine().basename()); |
| 3517 | |
| 3518 | // determine if the template has an index; if not, we always use the same name |
| 3519 | astring fname; |
| 3520 | if (snapstr.find(0, "%i") == -1) |
| 3521 | fname.cpy(snapstr); |
| 3522 | |
| 3523 | // otherwise, we scan for the next available filename |
| 3524 | else |
| 3525 | { |
| 3526 | // try until we succeed |
| 3527 | astring seqtext; |
| 3528 | file.set_openflags(OPEN_FLAG_READ); |
| 3529 | for (int seq = 0; ; seq++) |
| 3530 | { |
| 3531 | // build up the filename |
| 3532 | fname.cpy(snapstr).replace(0, "%i", seqtext.format("%04d_%d", seq, idx).cstr()); |
| 3533 | |
| 3534 | // try to open the file; stop when we fail |
| 3535 | file_error filerr = file.open(fname); |
| 3536 | if (filerr != FILERR_NONE) |
| 3537 | break; |
| 3538 | } |
| 3539 | } |
| 3540 | |
| 3541 | // create the final file |
| 3542 | file.set_openflags(origflags); |
| 3543 | return file.open(fname); |
| 3544 | } |